[SeaBIOS] [PATCH 8/8] Convert PCIDevices list to use standard list manipultion code.

Kevin O'Connor kevin at koconnor.net
Sun Jun 9 04:23:26 CEST 2013


Signed-off-by: Kevin O'Connor <kevin at koconnor.net>
---
 src/ata.c      | 2 +-
 src/mptable.c  | 2 +-
 src/pci.c      | 7 +++----
 src/pci.h      | 9 +++++----
 src/usb-ehci.c | 2 +-
 src/usb.c      | 8 ++++----
 6 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/ata.c b/src/ata.c
index 59ae765..55bfa9a 100644
--- a/src/ata.c
+++ b/src/ata.c
@@ -1008,7 +1008,7 @@ static const struct pci_device_id pci_ata_tbl[] = {
 static void
 ata_scan(void)
 {
-    if (CONFIG_QEMU && !PCIDevices) {
+    if (CONFIG_QEMU && hlist_empty(&PCIDevices)) {
         // No PCI devices found - probably a QEMU "-M isapc" machine.
         // Try using ISA ports for ATA controllers.
         init_controller(NULL, IRQ_ATA1
diff --git a/src/mptable.c b/src/mptable.c
index 7d485eb..0413063 100644
--- a/src/mptable.c
+++ b/src/mptable.c
@@ -67,7 +67,7 @@ mptable_setup(void)
 
     // PCI bus
     struct mpt_bus *buses = (void*)cpu, *bus = buses;
-    if (PCIDevices) {
+    if (!hlist_empty(&PCIDevices)) {
         memset(bus, 0, sizeof(*bus));
         bus->type = MPT_TYPE_BUS;
         bus->busid = 0;
diff --git a/src/pci.c b/src/pci.c
index a92fb9b..6163a29 100644
--- a/src/pci.c
+++ b/src/pci.c
@@ -85,7 +85,7 @@ pci_next(int bdf, int bus)
     }
 }
 
-struct pci_device *PCIDevices VARVERIFY32INIT;
+struct hlist_head PCIDevices VARVERIFY32INIT;
 int MaxPCIBus VARFSEG;
 
 // Check if PCI is available at all
@@ -107,7 +107,7 @@ pci_probe_devices(void)
     dprintf(3, "PCI probe\n");
     struct pci_device *busdevs[256];
     memset(busdevs, 0, sizeof(busdevs));
-    struct pci_device **pprev = &PCIDevices;
+    struct hlist_node **pprev = &PCIDevices.first;
     int extraroots = romfile_loadint("etc/extra-pci-roots", 0);
     int bus = -1, lastbus = 0, rootbuses = 0, count=0;
     while (bus < 0xff && (bus < MaxPCIBus || rootbuses < extraroots)) {
@@ -121,8 +121,7 @@ pci_probe_devices(void)
                 return;
             }
             memset(dev, 0, sizeof(*dev));
-            *pprev = dev;
-            pprev = &dev->next;
+            hlist_add(&dev->node, pprev);
             count++;
 
             // Find parent device.
diff --git a/src/pci.h b/src/pci.h
index aa54dd7..7760d21 100644
--- a/src/pci.h
+++ b/src/pci.h
@@ -2,6 +2,7 @@
 #define __PCI_H
 
 #include "types.h" // u32
+#include "list.h" // hlist_node
 
 #define PCI_ROM_SLOT 6
 #define PCI_NUM_REGIONS 7
@@ -43,7 +44,7 @@ struct pci_device *pci_find_class(u16 classid);
 struct pci_device {
     u16 bdf;
     u8 rootbus;
-    struct pci_device *next;
+    struct hlist_node node;
     struct pci_device *parent;
 
     // Configuration space device information
@@ -58,7 +59,7 @@ struct pci_device {
 };
 extern u64 pcimem_start, pcimem_end;
 extern u64 pcimem64_start, pcimem64_end;
-extern struct pci_device *PCIDevices;
+extern struct hlist_head PCIDevices;
 extern int MaxPCIBus;
 int pci_probe_host(void);
 void pci_probe_devices(void);
@@ -66,8 +67,8 @@ static inline u32 pci_classprog(struct pci_device *pci) {
     return (pci->class << 8) | pci->prog_if;
 }
 
-#define foreachpci(PCI)                         \
-    for (PCI=PCIDevices; PCI; PCI=PCI->next)
+#define foreachpci(PCI)                                 \
+    hlist_for_each_entry(PCI, &PCIDevices, node)
 
 int pci_next(int bdf, int bus);
 #define foreachbdf(BDF, BUS)                                    \
diff --git a/src/usb-ehci.c b/src/usb-ehci.c
index 69a9194..144dec4 100644
--- a/src/usb-ehci.c
+++ b/src/usb-ehci.c
@@ -368,7 +368,7 @@ ehci_setup(struct pci_device *pci, int busid, struct pci_device *comppci)
             cntl->companion[count++] = comppci;
         else if (pci_classprog(comppci) == PCI_CLASS_SERIAL_USB_OHCI)
             cntl->companion[count++] = comppci;
-        comppci = comppci->next;
+        comppci = container_of(comppci->node.next, struct pci_device, node);
     }
 
     run_thread(configure_ehci, cntl);
diff --git a/src/usb.c b/src/usb.c
index 6e43f13..ecccd75 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -422,13 +422,12 @@ usb_setup(void)
 
     // Look for USB controllers
     int count = 0;
-    struct pci_device *ehcipci = PCIDevices;
-    struct pci_device *pci;
+    struct pci_device *pci, *ehcipci = NULL;
     foreachpci(pci) {
         if (pci->class != PCI_CLASS_SERIAL_USB)
             continue;
 
-        if (pci->bdf >= ehcipci->bdf) {
+        if (!ehcipci || pci->bdf >= ehcipci->bdf) {
             // Check to see if this device has an ehci controller
             int found = 0;
             ehcipci = pci;
@@ -445,7 +444,8 @@ usb_setup(void)
                 }
                 if (ehcipci->class == PCI_CLASS_SERIAL_USB)
                     found++;
-                ehcipci = ehcipci->next;
+                ehcipci = container_of(
+                    ehcipci->node.next, struct pci_device, node);
                 if (!ehcipci || (pci_bdf_to_busdev(ehcipci->bdf)
                                  != pci_bdf_to_busdev(pci->bdf)))
                     // No ehci controller found.
-- 
1.7.11.7




More information about the SeaBIOS mailing list