]> xenbits.xensource.com Git - seabios.git/commitdiff
Rename foreachbdf_in_bus to foreachbdf and simplify it.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 2 Jul 2011 18:49:41 +0000 (14:49 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 3 Jul 2011 03:38:36 +0000 (23:38 -0400)
Now that all callers of foreachbdf have been converted to
foreachbdf_in_bus, simplify the pci_next() code - it no longer needs
to track PCI bridges.

Also, rename the remaining users of foreachbdf_in_bus to foreachbdf.

src/pci.c
src/pci.h
src/pcibios.c
src/pciinit.c
src/shadow.c
src/usb-ehci.c

index ebc6f91b71c8f84ecb849dba34e99fa2123c1b6f..0de8ec5feeac4b2bc463f7b2d6bc27b5de02d7c7 100644 (file)
--- a/src/pci.c
+++ b/src/pci.c
@@ -59,48 +59,30 @@ pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on)
 
 // Helper function for foreachbdf() macro - return next device
 int
-pci_next(int bdf, int *pmax)
+pci_next(int bdf, int bus)
 {
-    if (pci_bdf_to_fn(bdf) == 1
-        && (pci_config_readb(bdf-1, PCI_HEADER_TYPE) & 0x80) == 0)
+    if (pci_bdf_to_fn(bdf) == 0
+        && (pci_config_readb(bdf, PCI_HEADER_TYPE) & 0x80) == 0)
         // Last found device wasn't a multi-function device - skip to
         // the next device.
-        bdf += 7;
+        bdf += 8;
+    else
+        bdf += 1;
 
-    int max = *pmax;
     for (;;) {
-        if (bdf >= max) {
-            if (CONFIG_PCI_ROOT1 && bdf <= (CONFIG_PCI_ROOT1 << 8))
-                bdf = CONFIG_PCI_ROOT1 << 8;
-            else if (CONFIG_PCI_ROOT2 && bdf <= (CONFIG_PCI_ROOT2 << 8))
-                bdf = CONFIG_PCI_ROOT2 << 8;
-            else
-               return -1;
-            *pmax = max = bdf + 0x0100;
-        }
+        if (pci_bdf_to_bus(bdf) != bus)
+            return -1;
 
         u16 v = pci_config_readw(bdf, PCI_VENDOR_ID);
         if (v != 0x0000 && v != 0xffff)
             // Device is present.
-            break;
+            return bdf;
 
         if (pci_bdf_to_fn(bdf) == 0)
             bdf += 8;
         else
             bdf += 1;
     }
-
-    // Check if found device is a bridge.
-    u32 v = pci_config_readb(bdf, PCI_HEADER_TYPE);
-    v &= 0x7f;
-    if (v == PCI_HEADER_TYPE_BRIDGE || v == PCI_HEADER_TYPE_CARDBUS) {
-        v = pci_config_readl(bdf, PCI_PRIMARY_BUS);
-        int newmax = (v & 0xff00) + 0x0100;
-        if (newmax > max)
-            *pmax = newmax;
-    }
-
-    return bdf;
 }
 
 struct pci_device *PCIDevices;
@@ -122,8 +104,8 @@ pci_probe(void)
     int bus = -1, lastbus = 0, rootbuses = 0, count=0;
     while (bus < MaxPCIBus) {
         bus++;
-        int bdf, max;
-        foreachbdf_in_bus(bdf, max, bus) {
+        int bdf;
+        foreachbdf(bdf, bus) {
             // Create new pci_device struct and add to list.
             struct pci_device *dev = malloc_tmp(sizeof(*dev));
             if (!dev) {
index cde72dcd1de6e64ee2cc1c40ca544719b061bd03..c34e348ffebd5f5a22ab91a33ad87a3593632405 100644 (file)
--- a/src/pci.h
+++ b/src/pci.h
@@ -62,18 +62,11 @@ static inline u32 pci_classprog(struct pci_device *pci) {
 #define foreachpci(PCI)                         \
     for (PCI=PCIDevices; PCI; PCI=PCI->next)
 
-int pci_next(int bdf, int *pmax);
-#define foreachbdf(BDF, MAX)                    \
-    for (MAX=0x0100, BDF=pci_next(0, &MAX)      \
-         ; BDF >= 0                             \
-         ; BDF=pci_next(BDF+1, &MAX))
-
-#define foreachbdf_in_bus(BDF, MAX, BUS)                                \
-    for (MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100,                   \
-         BDF = pci_next(pci_bus_devfn_to_bdf(BUS, 0), &MAX)             \
-         ; BDF >= 0 && BDF < pci_bus_devfn_to_bdf(BUS, 0) + 0x0100      \
-         ; MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100,                 \
-           BDF = pci_next(BDF + 1, &MAX))
+int pci_next(int bdf, int bus);
+#define foreachbdf(BDF, BUS)                                    \
+    for (BDF=pci_next(pci_bus_devfn_to_bdf((BUS), 0)-1, (BUS))  \
+         ; BDF >= 0                                             \
+         ; BDF=pci_next(BDF, (BUS)))
 
 #define PCI_ANY_ID      (~0)
 struct pci_device_id {
index ca91c156a6d773ae76e3fb9a2cddc9ac9d485897..31ca37e5caa64a802989371a3f6f7516ffe995c7 100644 (file)
@@ -42,8 +42,8 @@ handle_1ab102(struct bregs *regs)
     int bus = -1;
     while (bus < GET_GLOBAL(MaxPCIBus)) {
         bus++;
-        int bdf, max;
-        foreachbdf_in_bus(bdf, max, bus) {
+        int bdf;
+        foreachbdf(bdf, bus) {
             u32 v = pci_config_readl(bdf, PCI_VENDOR_ID);
             if (v != id)
                 continue;
@@ -66,8 +66,8 @@ handle_1ab103(struct bregs *regs)
     int bus = -1;
     while (bus < GET_GLOBAL(MaxPCIBus)) {
         bus++;
-        int bdf, max;
-        foreachbdf_in_bus(bdf, max, bus) {
+        int bdf;
+        foreachbdf(bdf, bus) {
             u32 v = pci_config_readl(bdf, PCI_CLASS_REVISION);
             if ((v>>8) != classprog)
                 continue;
index bfff3db3742a851212397b3616341f2ae0cabf56..57747c006f07b24d6a9eef5d7a70347d7e163928 100644 (file)
@@ -377,13 +377,13 @@ static void pci_bios_init_device_in_bus(int bus)
 static void
 pci_bios_init_bus_rec(int bus, u8 *pci_bus)
 {
-    int bdf, max;
+    int bdf;
     u16 class;
 
     dprintf(1, "PCI: %s bus = 0x%x\n", __func__, bus);
 
     /* prevent accidental access to unintended devices */
-    foreachbdf_in_bus(bdf, max, bus) {
+    foreachbdf(bdf, bus) {
         class = pci_config_readw(bdf, PCI_CLASS_DEVICE);
         if (class == PCI_CLASS_BRIDGE_PCI) {
             pci_config_writeb(bdf, PCI_SECONDARY_BUS, 255);
@@ -391,7 +391,7 @@ pci_bios_init_bus_rec(int bus, u8 *pci_bus)
         }
     }
 
-    foreachbdf_in_bus(bdf, max, bus) {
+    foreachbdf(bdf, bus) {
         class = pci_config_readw(bdf, PCI_CLASS_DEVICE);
         if (class != PCI_CLASS_BRIDGE_PCI) {
             continue;
index ece7d97d522005ffa2e93d538e6b5b54aeb81944..c0c8cc21151d225d7a8e2daffedfca78e7f7c7f3 100644 (file)
@@ -117,8 +117,8 @@ make_bios_writable(void)
 
     // At this point, statically allocated variables can't be written,
     // so do this search manually.
-    int bdf, max;
-    foreachbdf_in_bus(bdf, max, 0) {
+    int bdf;
+    foreachbdf(bdf, 0) {
         u32 vendev = pci_config_readl(bdf, PCI_VENDOR_ID);
         u16 vendor = vendev & 0xffff, device = vendev >> 16;
         if (vendor == PCI_VENDOR_ID_INTEL
index f11924afcf91725bb3c46b7d62d87aeb022c6c91..5a0eb3eaacb64a7c44bbf8ed151586ed6597666a 100644 (file)
@@ -280,7 +280,6 @@ ehci_init(u16 bdf, int busid, int compbdf)
 
     // Find companion controllers.
     int count = 0;
-    int max = pci_to_bdf(pci_bdf_to_bus(bdf) + 1, 0, 0);
     for (;;) {
         if (compbdf < 0 || compbdf >= bdf)
             break;
@@ -294,7 +293,7 @@ ehci_init(u16 bdf, int busid, int compbdf)
             cntl->companion[count].type = USB_TYPE_OHCI;
             count++;
         }
-        compbdf = pci_next(compbdf+1, &max);
+        compbdf = pci_next(compbdf+1, pci_bdf_to_bus(compbdf));
     }
 
     run_thread(configure_ehci, cntl);