summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDamien Zammit <damien@zamaudio.com>2021-04-07 18:29:13 +1000
committerDamien Zammit <damien@zamaudio.com>2021-04-13 19:52:45 +1000
commit9c01fdd7c02d8b9b5003e659ebca0b3643bd47c4 (patch)
tree9ea9ef8a7d11f774c08affed3b646c18412d77a6 /src
parent50e7de7a81be35bb4e5799cb5562d18683c05ade (diff)
x86: Sort devices by B/D/F due to recursive scan
Diffstat (limited to 'src')
-rw-r--r--src/x86_pci.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/x86_pci.c b/src/x86_pci.c
index 03864e6..565dbc8 100644
--- a/src/x86_pci.c
+++ b/src/x86_pci.c
@@ -211,6 +211,28 @@ outl(uint32_t value, uint16_t port)
#endif
+static int cmp_devices(const void *dev1, const void *dev2)
+{
+ const struct pci_device *d1 = dev1;
+ const struct pci_device *d2 = dev2;
+
+ if (d1->bus != d2->bus) {
+ return (d1->bus > d2->bus) ? 1 : -1;
+ }
+
+ if (d1->dev != d2->dev) {
+ return (d1->dev > d2->dev) ? 1 : -1;
+ }
+
+ return (d1->func > d2->func) ? 1 : -1;
+}
+
+static void
+sort_devices(void)
+{
+ qsort(pci_sys->devices, pci_sys->num_devices,
+ sizeof (pci_sys->devices[0]), &cmp_devices);
+}
#if defined(__GNU__)
#include <mach.h>
@@ -1202,10 +1224,15 @@ pci_system_x86_create(void)
if (err)
{
x86_disable_io ();
+ if (pci_sys->num_devices)
+ {
+ free (pci_sys->devices);
+ }
free (pci_sys);
pci_sys = NULL;
return err;
}
+ sort_devices ();
return 0;
}