PCI fixes
authorKevin O'Connor <kevin@koconnor.net>
Sat, 21 Jun 2008 15:55:29 +0000 (11:55 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 21 Jun 2008 15:55:29 +0000 (11:55 -0400)
Only set the PIR table signature and checksum in the init function -
    that way, if it is disabled at runtime (eg, due to coreboot) then
    it wont be found by the OS.
Fix parameter swap bug in handle_1ab102.
Add support for more than one bus in pci scanning code (but only have
    1 bus for now).

src/pci.c
src/pcibios.c
src/pirtable.c

index c688dace313f12fb124f8b0c3b3e7e5cdc2328b9..e704444cf6ee9205bd0cf8bbdf1aa92493c5897c 100644 (file)
--- a/src/pci.c
+++ b/src/pci.c
@@ -7,6 +7,9 @@
 
 #include "pci.h" // PCIDevice
 #include "ioport.h" // outl
+#include "util.h" // dprintf
+
+#define MAX_BUS 1
 
 void pci_config_writel(PCIDevice d, u32 addr, u32 val)
 {
@@ -53,20 +56,22 @@ u8 pci_config_readb(PCIDevice d, u32 addr)
 int
 pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev)
 {
-    int devfn;
+    int devfn, bus;
     u32 id = (devid << 16) | vendid;
-    for (devfn=0; devfn<0x100; devfn++) {
-        PCIDevice d = pci_bd(0, devfn);
-        u32 v = pci_config_readl(d, 0x00);
-        if (v != id)
-            continue;
-        if (index) {
-            index--;
-            continue;
+    for (bus=0; bus < MAX_BUS; bus++) {
+        for (devfn=0; devfn<0x100; devfn++) {
+            PCIDevice d = pci_bd(bus, devfn);
+            u32 v = pci_config_readl(d, 0x00);
+            if (v != id)
+                continue;
+            if (index) {
+                index--;
+                continue;
+            }
+            // Found it.
+            *dev = d;
+            return 0;
         }
-        // Found it.
-        *dev = d;
-        return 0;
     }
     return -1;
 }
@@ -74,20 +79,22 @@ pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev)
 int
 pci_find_class(u32 classid, int index, PCIDevice *dev)
 {
-    int devfn;
+    int devfn, bus;
     u32 id = classid << 8;
-    for (devfn=0; devfn<0x100; devfn++) {
-        PCIDevice d = pci_bd(0, devfn);
-        u32 v = pci_config_readl(d, 0x08);
-        if (v != id)
-            continue;
-        if (index) {
-            index--;
-            continue;
+    for (bus=0; bus < MAX_BUS; bus++) {
+        for (devfn=0; devfn<0x100; devfn++) {
+            PCIDevice d = pci_bd(bus, devfn);
+            u32 v = pci_config_readl(d, 0x08);
+            if (v != id)
+                continue;
+            if (index) {
+                index--;
+                continue;
+            }
+            // Found it.
+            *dev = d;
+            return 0;
         }
-        // Found it.
-        *dev = d;
-        return 0;
     }
     return -1;
 }
index 1ab72f4c3ba1fea81ca847c8962e0792ea764942..436c106b50b9d2f933ea2bd08b0aa703ac8b12c9 100644 (file)
@@ -32,7 +32,7 @@ static void
 handle_1ab102(struct bregs *regs)
 {
     PCIDevice d;
-    int ret = pci_find_device(regs->cx, regs->dx, regs->si, &d);
+    int ret = pci_find_device(regs->dx, regs->cx, regs->si, &d);
     if (ret) {
         set_code_fail(regs, RET_DEVICE_NOT_FOUND);
         return;
index c20a169f7867a86f4879c3ddbbea8e9827ffad6a..433b889ce63efea7dca2a4f59f8f40c5708ca5d6 100644 (file)
 struct pir_table {
     struct pir_header pir;
     struct pir_slot slots[6];
-} PACKED PIR_TABLE VISIBLE16 __attribute__((aligned(16))) = {
+} PACKED PIR_TABLE __attribute__((aligned(16))) = {
 #if CONFIG_PIRTABLE
     .pir = {
-        .signature = PIR_SIGNATURE,
         .version = 0x0100,
         .size = sizeof(struct pir_table),
         .router_devfunc = 0x08,
         .compatible_devid = 0x122e8086,
-        .checksum = 0x37, // XXX - should auto calculate
     },
     .slots = {
         {
@@ -93,6 +91,7 @@ create_pirtable()
     if (! CONFIG_PIRTABLE)
         return;
 
+    PIR_TABLE.pir.signature = PIR_SIGNATURE;
     PIR_TABLE.pir.checksum = -checksum((u8*)&PIR_TABLE, sizeof(PIR_TABLE));
     SET_EBDA(pir_loc, (u32)&PIR_TABLE);
 }