Skip to content

Commit

Permalink
clib: Move PCI bus number generator away from the dummy config space …
Browse files Browse the repository at this point in the history
…part as 9x does have raw access
  • Loading branch information
richardg867 committed Oct 25, 2024
1 parent 937e1db commit 29b7b6e
Showing 1 changed file with 41 additions and 35 deletions.
76 changes: 41 additions & 35 deletions clib/clib_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,42 +139,20 @@ pci_printf(char *msg, ...)
static void
pci_init_dev(uint8_t bus, uint8_t dev, uint8_t func)
{
struct pci_dev *other;
int i;
struct pci_dev *other;
if (!pdev || (pdev->bus != bus) || (pdev->dev != dev) || (pdev->func != func)) {
if (!pacc->devices) {
libpci_scan_bus(pacc);

# ifdef DUMMY_CONFIG_SPACE
/* Generate additional configuration values not generated by
libpci's emulated configuration space code on Windows. */
if ((pacc->method == PCI_ACCESS_WIN32_CFGMGR32) && !pacc->backend_data) { /* backend_data is NULL if no usable raw access method was found */
/* Create cache and read generated values for every device. */
/* Special handling for libpci's Windows cfgmgr32 access method. */
if (pacc->method == PCI_ACCESS_WIN32_CFGMGR32) {
/* Generate dummy bus numbers for 9x where the actual
bus numbers cannot be obtained from PnP by cfgmgr32. */
for (pdev = pacc->devices; pdev; pdev = pdev->next) {
pdev->cache = malloc(0x40 + sizeof(win_notice));
pci_setup_cache(pdev, pdev->cache, 0x40 + sizeof(win_notice));
pci_read_block(pdev, 0, pdev->cache, 64);
if (pdev->cache[0x0e] & 0x7f) {
/* Set unknown secondary/subordinate bus numbers for now. */
pdev->cache[0x19] = -1;
pdev->cache[0x1a] = pdev->bus;
}
strcpy(&pdev->cache[0x40], win_notice);
}

/* Perform scan to fill in some values. */
for (pdev = pacc->devices; pdev; pdev = pdev->next) {
/* Perform recursive scan to set multi-function bit if another function is present. */
for (other = pacc->devices; other; other = other->next) {
if (!pdev->func && (other->domain == pdev->domain) && (other->bus == pdev->bus) && (other->dev == pdev->dev) && other->func) {
pdev->cache[0x0e] |= 0x80;
break;
}
}

/* Generate dummy bus numbers for 9x where the actual number cannot be obtained from cfgmgr32. */
if (pdev->parent) {
if (!pdev->bus) {
if (!pdev->bus) { /* have parent but bus number couldn't be populated */
for (i = 1; i < (sizeof(dummy_buses) / sizeof(dummy_buses[0])); i++) {
if (dummy_buses[i] == pdev->parent) /* found bus */
break;
Expand All @@ -189,14 +167,42 @@ pci_init_dev(uint8_t bus, uint8_t dev, uint8_t func)
dummy_buses[i] = pdev->parent;
}
}
}

/* Generate additional configuration values not generated by
libpci's configuration space emulation in non-raw mode. */
if (!pacc->backend_data) { /* backend_data is NULL if no usable raw access method was found */
/* Create cache and read generated values for every device. */
for (pdev = pacc->devices; pdev; pdev = pdev->next) {
pdev->cache = malloc(0x40 + sizeof(win_notice));
pci_setup_cache(pdev, pdev->cache, 0x40 + sizeof(win_notice));
pci_read_block(pdev, 0, pdev->cache, 64);
if (pdev->cache[0x0e] & 0x7f) {
/* Set unknown secondary/subordinate bus numbers for now. */
pdev->cache[0x19] = -1;
pdev->cache[0x1a] = pdev->bus;
}
strcpy(&pdev->cache[0x40], win_notice);
}

/* Set secondary bus number and cascade subordinate bus number to parents. */
other = pdev;
while (other->parent) {
other->parent->cache[0x19] = other->bus;
if (other->parent->cache[0x1a] < pdev->bus)
other->parent->cache[0x1a] = pdev->bus;
other = other->parent;
/* Perform scan to fill in some values. */
for (pdev = pacc->devices; pdev; pdev = pdev->next) {
/* Perform recursive scan to set multi-function bit if another function is present. */
for (other = pacc->devices; other; other = other->next) {
if (!pdev->func && (other->domain == pdev->domain) && (other->bus == pdev->bus) && (other->dev == pdev->dev) && other->func) {
pdev->cache[0x0e] |= 0x80;
break;
}
}

/* Set secondary bus number and cascade subordinate bus number to parents. */
other = pdev;
while (other->parent) {
other->parent->cache[0x19] = other->bus;
if (other->parent->cache[0x1a] < pdev->bus)
other->parent->cache[0x1a] = pdev->bus;
other = other->parent;
}
}
}
}
Expand Down

0 comments on commit 29b7b6e

Please sign in to comment.