bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH libpciaccess 1/2] common_init: Sort pci devices by B/D/F


From: Damien Zammit
Subject: [PATCH libpciaccess 1/2] common_init: Sort pci devices by B/D/F
Date: Sun, 7 Mar 2021 10:41:00 +1100

---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]