Skip to content

Commit

Permalink
clib: Generate dummy PCI bus numbers for 9x
Browse files Browse the repository at this point in the history
  • Loading branch information
richardg867 committed Oct 25, 2024
1 parent be6d0e6 commit 2f83a23
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions clib/clib_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 2f83a23

Please sign in to comment.