Don't allow start_bdf with new auto max bus detection code.
authorKevin O'Connor <kevin@koconnor.net>
Fri, 5 Dec 2008 00:39:10 +0000 (19:39 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 5 Dec 2008 00:39:10 +0000 (19:39 -0500)
It's not valid to set a "start bdf" when search for a device now,
    because we wont be able to properly detect the maximum bus unless
    we start at the beginning.
Change callers that need to resume a search to use foreachpci() macro.
Update all callers so that they don't pass in the now unused start_bdf.

src/acpi.c
src/ata.c
src/optionroms.c
src/pci.c
src/pci.h
src/pcibios.c
src/pciinit.c
src/shadow.c
src/smm.c

index a1c8b8288003c672d8967d482ca52728d8e38494..46aff4a8c695b1b47c68988fd5f2684d33796cea 100644 (file)
@@ -282,8 +282,8 @@ void acpi_bios_init(void)
     dprintf(3, "init ACPI tables\n");
 
     // This code is hardcoded for PIIX4 Power Management device.
-    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3
-                              , 0);
+    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL
+                              , PCI_DEVICE_ID_INTEL_82371AB_3);
     if (bdf < 0)
         // Device not found
         return;
index a33b83052d6b9f9e5ff437c99450717f4ee3b92b..77f5e340c9757031a0086ec3679ac15c014f6eab 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -895,7 +895,7 @@ ata_init()
     // Scan PCI bus for ATA adapters
     int count=0;
     int bdf, max;
-    foreachpci(bdf, max, 0) {
+    foreachpci(bdf, max) {
         if (pci_config_readw(bdf, PCI_CLASS_DEVICE) != PCI_CLASS_STORAGE_IDE)
             continue;
 
index 8888aa524fda11a962c8808b5d6d9aefba614600..32a1f95bbe11fb7b6073023b2e6d9276ac1663ca 100644 (file)
@@ -303,7 +303,7 @@ optionrom_setup()
     } else {
         // Find and deploy PCI roms.
         int bdf, max;
-        foreachpci(bdf, max, 0) {
+        foreachpci(bdf, max) {
             u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE);
             if (v == 0x0000 || v == 0xffff || v == PCI_CLASS_DISPLAY_VGA)
                 continue;
@@ -361,7 +361,7 @@ vga_setup()
         next_rom += ALIGN(rom->size * 512, OPTION_ROM_ALIGN);
     } else {
         // Find and deploy PCI VGA rom.
-        int bdf = pci_find_class(PCI_CLASS_DISPLAY_VGA, 0);
+        int bdf = pci_find_class(PCI_CLASS_DISPLAY_VGA);
         if (bdf < 0)
             // Device not found
             return;
index 20838bffba66d2f1811d5808b10bd6126f6520d8..5e8d7bbf05a7828045aa05de0de135bdc438daf6 100644 (file)
--- a/src/pci.c
+++ b/src/pci.c
@@ -88,11 +88,11 @@ pci_next(int bdf, int *pmax)
 
 // Search for a device with the specified vendor and device ids.
 int
-pci_find_device(u16 vendid, u16 devid, int start_bdf)
+pci_find_device(u16 vendid, u16 devid)
 {
     u32 id = (devid << 16) | vendid;
     int bdf, max;
-    foreachpci(bdf, max, start_bdf) {
+    foreachpci(bdf, max) {
         u32 v = pci_config_readl(bdf, PCI_VENDOR_ID);
         if (v != id)
             continue;
@@ -102,27 +102,12 @@ pci_find_device(u16 vendid, u16 devid, int start_bdf)
     return -1;
 }
 
-// Search for a device with the specified class id and prog-if.
-int
-pci_find_classprog(u32 classprog, int start_bdf)
-{
-    int bdf, max;
-    foreachpci(bdf, max, start_bdf) {
-        u32 v = pci_config_readl(bdf, PCI_CLASS_REVISION);
-        if ((v>>8) != classprog)
-            continue;
-        // Found it.
-        return bdf;
-    }
-    return -1;
-}
-
 // Search for a device with the specified class id.
 int
-pci_find_class(u16 classid, int start_bdf)
+pci_find_class(u16 classid)
 {
     int bdf, max;
-    foreachpci(bdf, max, start_bdf) {
+    foreachpci(bdf, max) {
         u16 v = pci_config_readw(bdf, PCI_CLASS_DEVICE);
         if (v != classid)
             continue;
index fc39fa0fed3dc249d9fd1244448db18cf2d94e3d..6623fd93675951209ccd45532739d24ed380a7ea 100644 (file)
--- a/src/pci.h
+++ b/src/pci.h
@@ -23,14 +23,13 @@ u32 pci_config_readl(u16 bdf, u32 addr);
 u16 pci_config_readw(u16 bdf, u32 addr);
 u8 pci_config_readb(u16 bdf, u32 addr);
 
-int pci_find_device(u16 vendid, u16 devid, int start_bdf);
-int pci_find_classprog(u32 classprog, int start_bdf);
-int pci_find_class(u16 classid, int start_bdf);
+int pci_find_device(u16 vendid, u16 devid);
+int pci_find_class(u16 classid);
 
 int pci_next(int bdf, int *pmax);
-#define foreachpci(BDF, MAX, START)                     \
-    for (MAX=0x0100, BDF=pci_next((START), &MAX)        \
-         ; BDF >= 0                                     \
+#define foreachpci(BDF, MAX)                    \
+    for (MAX=0x0100, BDF=pci_next(0, &MAX)      \
+         ; BDF >= 0                             \
          ; BDF=pci_next(BDF+1, &MAX))
 
 // pirtable.c
index 93cdc46238e98de5fc316776752fc853d132a7d9..e310b189eff0b2a519d417c97a1ff875b9695253 100644 (file)
@@ -10,6 +10,7 @@
 #include "pci.h" // pci_config_readl
 #include "bregs.h" // struct bregs
 #include "biosvar.h" // GET_EBDA
+#include "pci_regs.h" // PCI_VENDOR_ID
 
 #define RET_FUNC_NOT_SUPPORTED 0x81
 #define RET_BAD_VENDOR_ID      0x83
@@ -22,7 +23,7 @@ handle_1ab101(struct bregs *regs)
 {
     // Find max bus.
     int bdf, max;
-    foreachpci(bdf, max, 0) {
+    foreachpci(bdf, max) {
     }
 
     regs->al = 0x01; // Flags - "Config Mechanism #1" supported.
@@ -38,36 +39,40 @@ handle_1ab101(struct bregs *regs)
 static void
 handle_1ab102(struct bregs *regs)
 {
-    int bdf = -1;
+    u32 id = (regs->cx << 16) | regs->dx;
     int count = regs->si;
-    do {
-        bdf = pci_find_device(regs->dx, regs->cx, bdf+1);
-        if (bdf < 0) {
-            set_code_fail(regs, RET_DEVICE_NOT_FOUND);
-            return;
-        }
-    } while (count--);
-
-    regs->bx = bdf;
-    set_code_success(regs);
+    int bdf, max;
+    foreachpci(bdf, max) {
+        u32 v = pci_config_readl(bdf, PCI_VENDOR_ID);
+        if (v != id)
+            continue;
+        if (count--)
+            continue;
+        regs->bx = bdf;
+        set_code_success(regs);
+        return;
+    }
+    set_code_fail(regs, RET_DEVICE_NOT_FOUND);
 }
 
 // find class code
 static void
 handle_1ab103(struct bregs *regs)
 {
-    int bdf = -1;
     int count = regs->si;
-    do {
-        bdf = pci_find_classprog(regs->ecx, bdf+1);
-        if (bdf < 0) {
-            set_code_fail(regs, RET_DEVICE_NOT_FOUND);
-            return;
-        }
-    } while (count--);
-
-    regs->bx = bdf;
-    set_code_success(regs);
+    u32 classprog = regs->ecx;
+    int bdf, max;
+    foreachpci(bdf, max) {
+        u32 v = pci_config_readl(bdf, PCI_CLASS_REVISION);
+        if ((v>>8) != classprog)
+            continue;
+        if (count--)
+            continue;
+        regs->bx = bdf;
+        set_code_success(regs);
+        return;
+    }
+    set_code_fail(regs, RET_DEVICE_NOT_FOUND);
 }
 
 // read configuration byte
index 28bee74ff6ddef5aff77acaded9d528278f8173e..643e027f96e2b97899f64d9dfe8bc945c6bc45e5 100644 (file)
@@ -203,10 +203,10 @@ pci_bios_setup(void)
         pci_bios_bigmem_addr = 0x90000000;
 
     int bdf, max;
-    foreachpci(bdf, max, 0) {
+    foreachpci(bdf, max) {
         pci_bios_init_bridges(bdf);
     }
-    foreachpci(bdf, max, 0) {
+    foreachpci(bdf, max) {
         pci_bios_init_device(bdf);
     }
 }
index 1631954534a2f20863e70e298ecebe97020e52c4..4e13922d05b79868594ef6a7d3c244b0d4c89b6a 100644 (file)
@@ -39,7 +39,7 @@ make_bios_writable()
     dprintf(3, "enabling shadow ram\n");
 
     // Locate chip controlling ram shadowing.
-    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, 0);
+    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441);
     if (bdf < 0) {
         dprintf(1, "Unable to unlock ram - bridge not found\n");
         return;
@@ -74,7 +74,7 @@ make_bios_readonly()
 
     dprintf(3, "locking shadow ram\n");
 
-    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, 0);
+    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441);
     if (bdf < 0) {
         dprintf(1, "Unable to lock ram - bridge not found\n");
         return;
index b2140b4a787eb181df2b757c3b6df54a0b101c83..dda8d5d1374d9a943a4590a3b60b5d72a09c7940 100644 (file)
--- a/src/smm.c
+++ b/src/smm.c
@@ -83,13 +83,13 @@ smm_init()
     dprintf(3, "init smm\n");
 
     // This code is hardcoded for PIIX4 Power Management device.
-    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3
-                              , 0);
+    int bdf = pci_find_device(PCI_VENDOR_ID_INTEL
+                              , PCI_DEVICE_ID_INTEL_82371AB_3);
     if (bdf < 0)
         // Device not found
         return;
-    int i440_bdf = pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441
-                                   , 0);
+    int i440_bdf = pci_find_device(PCI_VENDOR_ID_INTEL
+                                   , PCI_DEVICE_ID_INTEL_82441);
     if (i440_bdf < 0)
         return;