--- src/common_init.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+)
diff --git a/src/common_init.c b/src/common_init.c index 1940cff..14f0c6b 100644 --- a/src/common_init.c +++ b/src/common_init.c @@ -40,6 +40,40 @@ _pci_hidden struct pci_system * pci_sys; +static int +sort_devices(void) +{ + int bus, dev, func; + struct pci_device_private *sorted; + struct pci_device_private *device; + struct pci_device_private *tmpdev; + + sorted = calloc(pci_sys->num_devices, sizeof(struct pci_device_private)); + if (!sorted) { + return ENOMEM; + } + + tmpdev = sorted; + + for (bus = 0; bus < 256; bus++) { + for (dev = 0; dev < 32; dev++) { + for (func = 0; func < 8; func++) { + device = (struct pci_device_private *) + pci_device_find_by_slot(0, bus, dev, func); + if (device) { + *tmpdev = *device; + tmpdev++; + } + } + } + } + if (pci_sys->devices) { + free(pci_sys->devices); + pci_sys->devices = sorted; + } + return 0; +} + /** * Initialize the PCI subsystem for access. * @@ -72,6 +106,9 @@ pci_system_init( void ) #else # error "Unsupported OS" #endif + if (!err) { + err = sort_devices(); + } return err; } -- 2.30.1