clib: Improve current PCI device detection

This commit is contained in:
RichardG867
2024-10-25 15:37:45 -03:00
parent 6cb42625ae
commit 4d4a29b936

View File

@@ -31,8 +31,7 @@
uint8_t pci_mechanism = 0, pci_device_count = 0;
#ifdef PCI_LIB_VERSION
static struct pci_access *pacc;
static struct pci_dev *pdev;
static uint32_t last_addr = -1;
static struct pci_dev *pdev = NULL;
# ifdef _WIN32
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
@@ -139,10 +138,7 @@ static void
pci_init_dev(uint8_t bus, uint8_t dev, uint8_t func)
{
struct pci_dev *other;
uint32_t addr = (bus << 16) | (dev << 8) | func;
if (addr != last_addr) {
last_addr = addr;
if (!pdev || (pdev->bus != bus) || (pdev->dev != dev) || (pdev->func != func)) {
if (!pacc->devices) {
libpci_scan_bus(pacc);
@@ -450,7 +446,7 @@ pci_scan_bus(uint8_t bus,
{
#ifdef PCI_LIB_VERSION
if (!pacc->devices)
libpci_scan_bus(pacc);
pci_init_dev(0, 0, 0); /* initiate scan */
for (pdev = pacc->devices; pdev; pdev = pdev->next) {
if (pdev->domain || (pdev->bus != bus))
continue;