From owner-svn-src-stable-12@freebsd.org Sun Aug 23 17:34:21 2020 Return-Path: Delivered-To: svn-src-stable-12@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id F172E3C2E98; Sun, 23 Aug 2020 17:34:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4BZMnT65V1z3cwN; Sun, 23 Aug 2020 17:34:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id B4757ABBD; Sun, 23 Aug 2020 17:34:21 +0000 (UTC) (envelope-from markj@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 07NHYL7v094388; Sun, 23 Aug 2020 17:34:21 GMT (envelope-from markj@FreeBSD.org) Received: (from markj@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 07NHYLrs094387; Sun, 23 Aug 2020 17:34:21 GMT (envelope-from markj@FreeBSD.org) Message-Id: <202008231734.07NHYLrs094387@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: markj set sender to markj@FreeBSD.org using -f From: Mark Johnston Date: Sun, 23 Aug 2020 17:34:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r364501 - in stable/12/sys: amd64/acpica i386/acpica X-SVN-Group: stable-12 X-SVN-Commit-Author: markj X-SVN-Commit-Paths: in stable/12/sys: amd64/acpica i386/acpica X-SVN-Commit-Revision: 364501 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-12@freebsd.org X-Mailman-Version: 2.1.33 Precedence: list List-Id: SVN commit messages for only the 12-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Aug 2020 17:34:22 -0000 Author: markj Date: Sun Aug 23 17:34:21 2020 New Revision: 364501 URL: https://svnweb.freebsd.org/changeset/base/364501 Log: MFC r364411: Use pmap_mapbios() to map ACPI tables on amd64 and i386. PR: 248746 Modified: stable/12/sys/amd64/acpica/acpi_machdep.c stable/12/sys/i386/acpica/acpi_machdep.c Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/amd64/acpica/acpi_machdep.c ============================================================================== --- stable/12/sys/amd64/acpica/acpi_machdep.c Sun Aug 23 11:06:59 2020 (r364500) +++ stable/12/sys/amd64/acpica/acpi_machdep.c Sun Aug 23 17:34:21 2020 (r364501) @@ -91,91 +91,29 @@ acpi_machdep_quirks(int *quirks) } /* - * Support for mapping ACPI tables during early boot. Currently this - * uses the crashdump map to map each table. However, the crashdump - * map is created in pmap_bootstrap() right after the direct map, so - * we should be able to just use pmap_mapbios() here instead. - * - * This makes the following assumptions about how we use this KVA: - * pages 0 and 1 are used to map in the header of each table found via - * the RSDT or XSDT and pages 2 to n are used to map in the RSDT or - * XSDT. This has to use 2 pages for the table headers in case a - * header spans a page boundary. - * - * XXX: We don't ensure the table fits in the available address space - * in the crashdump map. + * Map a table. First map the header to determine the table length and then map + * the entire table. */ - -/* - * Map some memory using the crashdump map. 'offset' is an offset in - * pages into the crashdump map to use for the start of the mapping. - */ static void * -table_map(vm_paddr_t pa, int offset, vm_offset_t length) +map_table(vm_paddr_t pa, const char *sig) { - vm_offset_t va, off; - void *data; - - off = pa & PAGE_MASK; - length = round_page(length + off); - pa = pa & PG_FRAME; - va = (vm_offset_t)pmap_kenter_temporary(pa, offset) + - (offset * PAGE_SIZE); - data = (void *)(va + off); - length -= PAGE_SIZE; - while (length > 0) { - va += PAGE_SIZE; - pa += PAGE_SIZE; - length -= PAGE_SIZE; - pmap_kenter(va, pa); - invlpg(va); - } - return (data); -} - -/* Unmap memory previously mapped with table_map(). */ -static void -table_unmap(void *data, vm_offset_t length) -{ - vm_offset_t va, off; - - va = (vm_offset_t)data; - off = va & PAGE_MASK; - length = round_page(length + off); - va &= ~PAGE_MASK; - while (length > 0) { - pmap_kremove(va); - invlpg(va); - va += PAGE_SIZE; - length -= PAGE_SIZE; - } -} - -/* - * Map a table at a given offset into the crashdump map. It first - * maps the header to determine the table length and then maps the - * entire table. - */ -static void * -map_table(vm_paddr_t pa, int offset, const char *sig) -{ ACPI_TABLE_HEADER *header; vm_offset_t length; void *table; - header = table_map(pa, offset, sizeof(ACPI_TABLE_HEADER)); + header = pmap_mapbios(pa, sizeof(ACPI_TABLE_HEADER)); if (strncmp(header->Signature, sig, ACPI_NAMESEG_SIZE) != 0) { - table_unmap(header, sizeof(ACPI_TABLE_HEADER)); + pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER)); return (NULL); } length = header->Length; - table_unmap(header, sizeof(ACPI_TABLE_HEADER)); - table = table_map(pa, offset, length); + pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER)); + table = pmap_mapbios(pa, length); if (ACPI_FAILURE(AcpiTbChecksum(table, length))) { if (bootverbose) printf("ACPI: Failed checksum for table %s\n", sig); #if (ACPI_CHECKSUM_ABORT) - table_unmap(table, length); + pmap_unmapbios((vm_offset_t)table, length); return (NULL); #endif } @@ -190,24 +128,15 @@ static int probe_table(vm_paddr_t address, const char *sig) { ACPI_TABLE_HEADER *table; + int ret; - table = table_map(address, 0, sizeof(ACPI_TABLE_HEADER)); - if (table == NULL) { - if (bootverbose) - printf("ACPI: Failed to map table at 0x%jx\n", - (uintmax_t)address); - return (0); - } + table = pmap_mapbios(address, sizeof(ACPI_TABLE_HEADER)); + ret = strncmp(table->Signature, sig, ACPI_NAMESEG_SIZE) == 0; if (bootverbose) printf("Table '%.4s' at 0x%jx\n", table->Signature, (uintmax_t)address); - - if (strncmp(table->Signature, sig, ACPI_NAMESEG_SIZE) != 0) { - table_unmap(table, sizeof(ACPI_TABLE_HEADER)); - return (0); - } - table_unmap(table, sizeof(ACPI_TABLE_HEADER)); - return (1); + pmap_unmapbios((vm_offset_t)table, sizeof(ACPI_TABLE_HEADER)); + return (ret); } /* @@ -218,7 +147,7 @@ void * acpi_map_table(vm_paddr_t pa, const char *sig) { - return (map_table(pa, 0, sig)); + return (map_table(pa, sig)); } /* Unmap a table previously mapped via acpi_map_table(). */ @@ -228,7 +157,7 @@ acpi_unmap_table(void *table) ACPI_TABLE_HEADER *header; header = (ACPI_TABLE_HEADER *)table; - table_unmap(table, header->Length); + pmap_unmapbios((vm_offset_t)table, header->Length); } /* @@ -265,9 +194,7 @@ acpi_find_table(const char *sig) /* * For ACPI >= 2.0, use the XSDT if it is available. - * Otherwise, use the RSDT. We map the XSDT or RSDT at page 2 - * in the crashdump area. Pages 0 and 1 are used to map in the - * headers of candidate ACPI tables. + * Otherwise, use the RSDT. */ addr = 0; if (rsdp->Revision >= 2 && rsdp->XsdtPhysicalAddress != 0) { @@ -281,7 +208,7 @@ acpi_find_table(const char *sig) printf("ACPI: RSDP failed extended checksum\n"); return (0); } - xsdt = map_table(rsdp->XsdtPhysicalAddress, 2, ACPI_SIG_XSDT); + xsdt = map_table(rsdp->XsdtPhysicalAddress, ACPI_SIG_XSDT); if (xsdt == NULL) { if (bootverbose) printf("ACPI: Failed to map XSDT\n"); @@ -296,7 +223,7 @@ acpi_find_table(const char *sig) } acpi_unmap_table(xsdt); } else { - rsdt = map_table(rsdp->RsdtPhysicalAddress, 2, ACPI_SIG_RSDT); + rsdt = map_table(rsdp->RsdtPhysicalAddress, ACPI_SIG_RSDT); if (rsdt == NULL) { if (bootverbose) printf("ACPI: Failed to map RSDT\n"); @@ -324,7 +251,7 @@ acpi_find_table(const char *sig) * Verify that we can map the full table and that its checksum is * correct, etc. */ - table = map_table(addr, 0, sig); + table = map_table(addr, sig); if (table == NULL) return (0); acpi_unmap_table(table); Modified: stable/12/sys/i386/acpica/acpi_machdep.c ============================================================================== --- stable/12/sys/i386/acpica/acpi_machdep.c Sun Aug 23 11:06:59 2020 (r364500) +++ stable/12/sys/i386/acpica/acpi_machdep.c Sun Aug 23 17:34:21 2020 (r364501) @@ -109,89 +109,29 @@ acpi_machdep_quirks(int *quirks) } /* - * Support for mapping ACPI tables during early boot. This abuses the - * crashdump map because the kernel cannot allocate KVA in - * pmap_mapbios() when this is used. This makes the following - * assumptions about how we use this KVA: pages 0 and 1 are used to - * map in the header of each table found via the RSDT or XSDT and - * pages 2 to n are used to map in the RSDT or XSDT. This has to use - * 2 pages for the table headers in case a header spans a page - * boundary. - * - * XXX: We don't ensure the table fits in the available address space - * in the crashdump map. + * Map a table. First map the header to determine the table length and then map + * the entire table. */ - -/* - * Map some memory using the crashdump map. 'offset' is an offset in - * pages into the crashdump map to use for the start of the mapping. - */ static void * -table_map(vm_paddr_t pa, int offset, vm_offset_t length) +map_table(vm_paddr_t pa, const char *sig) { - vm_offset_t va, off; - void *data; - - off = pa & PAGE_MASK; - length = round_page(length + off); - pa = pa & PG_FRAME; - va = (vm_offset_t)pmap_kenter_temporary(pa, offset) + - (offset * PAGE_SIZE); - data = (void *)(va + off); - length -= PAGE_SIZE; - while (length > 0) { - va += PAGE_SIZE; - pa += PAGE_SIZE; - length -= PAGE_SIZE; - pmap_kenter(va, pa); - invlpg(va); - } - return (data); -} - -/* Unmap memory previously mapped with table_map(). */ -static void -table_unmap(void *data, vm_offset_t length) -{ - vm_offset_t va, off; - - va = (vm_offset_t)data; - off = va & PAGE_MASK; - length = round_page(length + off); - va &= ~PAGE_MASK; - while (length > 0) { - pmap_kremove(va); - invlpg(va); - va += PAGE_SIZE; - length -= PAGE_SIZE; - } -} - -/* - * Map a table at a given offset into the crashdump map. It first - * maps the header to determine the table length and then maps the - * entire table. - */ -static void * -map_table(vm_paddr_t pa, int offset, const char *sig) -{ ACPI_TABLE_HEADER *header; vm_offset_t length; void *table; - header = table_map(pa, offset, sizeof(ACPI_TABLE_HEADER)); + header = pmap_mapbios(pa, sizeof(ACPI_TABLE_HEADER)); if (strncmp(header->Signature, sig, ACPI_NAMESEG_SIZE) != 0) { - table_unmap(header, sizeof(ACPI_TABLE_HEADER)); + pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER)); return (NULL); } length = header->Length; - table_unmap(header, sizeof(ACPI_TABLE_HEADER)); - table = table_map(pa, offset, length); + pmap_unmapbios((vm_offset_t)header, sizeof(ACPI_TABLE_HEADER)); + table = pmap_mapbios(pa, length); if (ACPI_FAILURE(AcpiTbChecksum(table, length))) { if (bootverbose) printf("ACPI: Failed checksum for table %s\n", sig); #if (ACPI_CHECKSUM_ABORT) - table_unmap(table, length); + pmap_unmapbios((vm_offset_t)table, length); return (NULL); #endif } @@ -206,24 +146,15 @@ static int probe_table(vm_paddr_t address, const char *sig) { ACPI_TABLE_HEADER *table; + int ret; - table = table_map(address, 0, sizeof(ACPI_TABLE_HEADER)); - if (table == NULL) { - if (bootverbose) - printf("ACPI: Failed to map table at 0x%jx\n", - (uintmax_t)address); - return (0); - } + table = pmap_mapbios(address, sizeof(ACPI_TABLE_HEADER)); if (bootverbose) printf("Table '%.4s' at 0x%jx\n", table->Signature, (uintmax_t)address); - - if (strncmp(table->Signature, sig, ACPI_NAMESEG_SIZE) != 0) { - table_unmap(table, sizeof(ACPI_TABLE_HEADER)); - return (0); - } - table_unmap(table, sizeof(ACPI_TABLE_HEADER)); - return (1); + ret = strncmp(table->Signature, sig, ACPI_NAMESEG_SIZE) == 0; + pmap_unmapbios((vm_offset_t)table, sizeof(ACPI_TABLE_HEADER)); + return (ret); } /* @@ -234,7 +165,7 @@ void * acpi_map_table(vm_paddr_t pa, const char *sig) { - return (map_table(pa, 0, sig)); + return (map_table(pa, sig)); } /* Unmap a table previously mapped via acpi_map_table(). */ @@ -244,7 +175,7 @@ acpi_unmap_table(void *table) ACPI_TABLE_HEADER *header; header = (ACPI_TABLE_HEADER *)table; - table_unmap(table, header->Length); + pmap_unmapbios((vm_offset_t)table, header->Length); } /* @@ -281,9 +212,7 @@ acpi_find_table(const char *sig) /* * For ACPI >= 2.0, use the XSDT if it is available. - * Otherwise, use the RSDT. We map the XSDT or RSDT at page 2 - * in the crashdump area. Pages 0 and 1 are used to map in the - * headers of candidate ACPI tables. + * Otherwise, use the RSDT. */ addr = 0; if (rsdp->Revision >= 2 && rsdp->XsdtPhysicalAddress != 0) { @@ -297,7 +226,7 @@ acpi_find_table(const char *sig) printf("ACPI: RSDP failed extended checksum\n"); return (0); } - xsdt = map_table(rsdp->XsdtPhysicalAddress, 2, ACPI_SIG_XSDT); + xsdt = map_table(rsdp->XsdtPhysicalAddress, ACPI_SIG_XSDT); if (xsdt == NULL) { if (bootverbose) printf("ACPI: Failed to map XSDT\n"); @@ -312,7 +241,7 @@ acpi_find_table(const char *sig) } acpi_unmap_table(xsdt); } else { - rsdt = map_table(rsdp->RsdtPhysicalAddress, 2, ACPI_SIG_RSDT); + rsdt = map_table(rsdp->RsdtPhysicalAddress, ACPI_SIG_RSDT); if (rsdt == NULL) { if (bootverbose) printf("ACPI: Failed to map RSDT\n"); @@ -340,7 +269,7 @@ acpi_find_table(const char *sig) * Verify that we can map the full table and that its checksum is * correct, etc. */ - table = map_table(addr, 0, sig); + table = map_table(addr, sig); if (table == NULL) return (0); acpi_unmap_table(table);