]> xenbits.xensource.com Git - seabios.git/commitdiff
Convert PCIDevices list to use standard list manipultion code.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 9 Jun 2013 01:53:36 +0000 (21:53 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 9 Jun 2013 02:13:52 +0000 (22:13 -0400)
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
src/ata.c
src/mptable.c
src/pci.c
src/pci.h
src/usb-ehci.c
src/usb.c

index 59ae765435a685564fc4005b45aca74b87774bd3..55bfa9a3f54e4f735f8afb0d3c4a482b6acee101 100644 (file)
--- 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
index 7d485eb61a5799849eeccfc20a0ff24bcffc8142..0413063db7ba95103446cb6a607542246062e359 100644 (file)
@@ -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;
index a92fb9b671bc4677569726c76ae2be03a3a8d73a..6163a2923636fcd0fa90b4b3fc1e89cb6230f447 100644 (file)
--- 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.
index aa54dd73e615da47d625b3afb2ecb9b82ca2dab5..7760d2123a44c213a5f5481e46347efa7fcaf248 100644 (file)
--- 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)                                    \
index 69a9194e20ca0927bb75d4fdba2b4f3c1e52f7fc..144dec45926643ed49819f9327292eb6217da8d4 100644 (file)
@@ -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);
index 6e43f134d62598ce1cf07da5f493b70a8caf62e9..ecccd758b636812b535d033547927390cb38fb20 100644 (file)
--- 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.