Module Name: src Committed By: riastradh Date: Mon Mar 3 19:38:26 UTC 2025
Modified Files: src/sys/dev/acpi: acpi_mcfg.c Log Message: acpimcfg(4): Use bus ranges set in _CRS if available. Use the MCFG bus range only as a fallback. The _CRS should tell us what ranges are available for us to use, which may not even be contiguous (which pci_resource(9) currently doesn't handle but we'll deal with that in a separate commit). ok jmcneill@ PR port-amd64/59118: Thinkpad T495s - iwm PCI BAR is zero To generate a diff of this commit: cvs rdiff -u -r1.31 -r1.32 src/sys/dev/acpi/acpi_mcfg.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/acpi/acpi_mcfg.c diff -u src/sys/dev/acpi/acpi_mcfg.c:1.31 src/sys/dev/acpi/acpi_mcfg.c:1.32 --- src/sys/dev/acpi/acpi_mcfg.c:1.31 Mon Mar 3 19:02:30 2025 +++ src/sys/dev/acpi/acpi_mcfg.c Mon Mar 3 19:38:26 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_mcfg.c,v 1.31 2025/03/03 19:02:30 riastradh Exp $ */ +/* $NetBSD: acpi_mcfg.c,v 1.32 2025/03/03 19:38:26 riastradh Exp $ */ /*- * Copyright (C) 2015 NONAKA Kimihiro <non...@netbsd.org> @@ -28,7 +28,7 @@ #include "opt_pci.h" #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.31 2025/03/03 19:02:30 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.32 2025/03/03 19:38:26 riastradh Exp $"); #include <sys/param.h> #include <sys/device.h> @@ -683,10 +683,16 @@ out: } #ifdef PCI_RESOURCE +struct acpimcfg_configure_bus_context { + struct pci_resource_info pciinfo; + bool bus_found; +}; + ACPI_STATUS acpimcfg_configure_bus_cb(ACPI_RESOURCE *res, void *ctx) { - struct pci_resource_info *pciinfo = ctx; + struct acpimcfg_configure_bus_context *C = ctx; + struct pci_resource_info *pciinfo = &C->pciinfo; bus_addr_t addr; bus_size_t size; int type; @@ -756,6 +762,8 @@ acpimcfg_configure_bus_cb(ACPI_RESOURCE if (size > 0) { pci_resource_add_range(pciinfo, type, addr, addr + size - 1); + if (type == PCI_RANGE_BUS) + C->bus_found = true; } return AE_OK; @@ -765,7 +773,7 @@ int acpimcfg_configure_bus(device_t self, pci_chipset_tag_t pc, ACPI_HANDLE handle, int bus, bool mapcfgspace) { - struct pci_resource_info pciinfo; + struct acpimcfg_configure_bus_context context, *C = &context; struct mcfg_segment *seg; struct mcfg_bus *mb; bus_space_handle_t bsh[256]; @@ -821,20 +829,32 @@ acpimcfg_configure_bus(device_t self, pc endbus = 255; } - memset(&pciinfo, 0, sizeof(pciinfo)); - pciinfo.pc = pc; - pci_resource_add_range(&pciinfo, PCI_RANGE_BUS, bus, endbus); + memset(C, 0, sizeof(*C)); + C->pciinfo.pc = pc; rv = AcpiWalkResources(handle, "_CRS", acpimcfg_configure_bus_cb, - &pciinfo); + &C->pciinfo); if (ACPI_FAILURE(rv)) { aprint_debug_dev(acpi_sc->sc_dev, "MCFG: Walk _CRS: %ld\n", (long)rv); error = ENXIO; goto cleanup; } + + /* + * Paranoia: In case _CRS didn't list any bus ranges, guess + * from the MCFG. + */ + if (!C->bus_found) { + aprint_error_dev(acpi_sc->sc_dev, + "no PCI bus range in _CRS, guessing %d-%d from MCFG\n", + bus, endbus); + pci_resource_add_range(&C->pciinfo, PCI_RANGE_BUS, + bus, endbus); + } + error = 0; - pci_resource_init(&pciinfo); + pci_resource_init(&C->pciinfo); cleanup: if (mapcfgspace) {