From 29b7b6e262198b0909b30492cc5c81589af874fb Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Fri, 25 Oct 2024 16:59:01 -0300 Subject: [PATCH] clib: Move PCI bus number generator away from the dummy config space part as 9x does have raw access --- clib/clib_pci.c | 76 ++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/clib/clib_pci.c b/clib/clib_pci.c index f047a66..1e8caf2 100644 --- a/clib/clib_pci.c +++ b/clib/clib_pci.c @@ -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; @@ -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; + } } } }