From 2f83a232899ffe20f9df8cf2583fb9598de21c86 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 25 Oct 2024 16:34:38 -0300 Subject: [PATCH] clib: Generate dummy PCI bus numbers for 9x --- clib/clib_pci.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/clib/clib_pci.c b/clib/clib_pci.c index 81839f7..f047a66 100644 --- a/clib/clib_pci.c +++ b/clib/clib_pci.c @@ -34,6 +34,7 @@ struct pci_access *pacc; static struct pci_dev *pdev = NULL; # if defined(_WIN32) && (PCI_LIB_VERSION >= 0x030800) # define DUMMY_CONFIG_SPACE +static struct pci_dev *dummy_buses[256] = {0}; static const char win_notice[] = "NOTICE: These are dummy configuration registers generated by libpci, as it cannot access the real ones under Windows. It does not reflect the device's actual configuration."; # endif #endif @@ -139,6 +140,7 @@ static void pci_init_dev(uint8_t bus, uint8_t dev, uint8_t func) { struct pci_dev *other; + int i; if (!pdev || (pdev->bus != bus) || (pdev->dev != dev) || (pdev->func != func)) { if (!pacc->devices) { libpci_scan_bus(pacc); @@ -170,6 +172,24 @@ pci_init_dev(uint8_t bus, uint8_t dev, uint8_t func) } } + /* Generate dummy bus numbers for 9x where the actual number cannot be obtained from cfgmgr32. */ + if (pdev->parent) { + if (!pdev->bus) { + for (i = 1; i < (sizeof(dummy_buses) / sizeof(dummy_buses[0])); i++) { + if (dummy_buses[i] == pdev->parent) /* found bus */ + break; + if (!dummy_buses[i]) { /* create new bus here */ + dummy_buses[i] = pdev->parent; + break; + } + } + pdev->bus = i; + } else { + /* Flag this bus as taken, in the unlikely case that not all bus number lookups fail. */ + dummy_buses[i] = pdev->parent; + } + } + /* Set secondary bus number and cascade subordinate bus number to parents. */ other = pdev; while (other->parent) {