clib: Generate dummy PCI bus numbers for 9x

This commit is contained in:
RichardG867
2024-10-25 16:34:38 -03:00
parent be6d0e648b
commit 2f83a23289

View File

@@ -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) {