]> xenbits.xensource.com Git - seabios.git/commitdiff
Rename pci_find_class() to pci_find_classprog(), and add new functions.
authorKevin O'Connor <kevin@koconnor.net>
Sun, 31 Aug 2008 15:06:27 +0000 (11:06 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 31 Aug 2008 15:06:27 +0000 (11:06 -0400)
New pci_find_class() searches by just class, not class and prog-if.
Add some new pci config space definitions.
Add inline functions for converting to/from bus/dev/fn to bdf to PCIDevice.

src/pci.c
src/pci.h
src/pcibios.c

index 7ed83008317f4fc023fef97561243cb631d1670d..1f11ee3b978a71f409169c57dced1e8c1f08b6c0 100644 (file)
--- a/src/pci.c
+++ b/src/pci.c
@@ -60,7 +60,7 @@ pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev)
     for (bus=0; bus < CONFIG_PCI_BUS_COUNT; bus++) {
         for (devfn=0; devfn<0x100; devfn++) {
             PCIDevice d = pci_bd(bus, devfn);
-            u32 v = pci_config_readl(d, 0x00);
+            u32 v = pci_config_readl(d, PCI_VENDOR_ID);
             if (v != id)
                 continue;
             if (index) {
@@ -75,15 +75,39 @@ pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev)
     return -1;
 }
 
+// Search for a device with the specified class id and prog-if.
 int
-pci_find_class(u32 classid, int index, PCIDevice *dev)
+pci_find_classprog(u32 classprog, int index, PCIDevice *dev)
 {
     int devfn, bus;
     for (bus=0; bus < CONFIG_PCI_BUS_COUNT; bus++) {
         for (devfn=0; devfn<0x100; devfn++) {
             PCIDevice d = pci_bd(bus, devfn);
             u32 v = pci_config_readl(d, 0x08);
-            if ((v>>8) != classid)
+            if ((v>>8) != classprog)
+                continue;
+            if (index) {
+                index--;
+                continue;
+            }
+            // Found it.
+            *dev = d;
+            return 0;
+        }
+    }
+    return -1;
+}
+
+// Search for a device with the specified class id.
+int
+pci_find_class(u16 classid, int index, PCIDevice *dev)
+{
+    int devfn, bus;
+    for (bus=0; bus < CONFIG_PCI_BUS_COUNT; bus++) {
+        for (devfn=0; devfn<0x100; devfn++) {
+            PCIDevice d = pci_bd(bus, devfn);
+            u16 v = pci_config_readw(d, PCI_CLASS_DEVICE);
+            if (v != classid)
                 continue;
             if (index) {
                 index--;
index e37326d93691886b220edd3463a6ad55d4f12dae..1179911b395384db242571351ca46b03da746bbd 100644 (file)
--- a/src/pci.h
+++ b/src/pci.h
@@ -8,12 +8,22 @@ typedef struct PCIDevice {
     u8 devfn;
 } PCIDevice;
 
-static inline PCIDevice
-pci_bd(u8 bus, u8 devfn)
-{
+static inline PCIDevice pci_bd(u8 bus, u8 devfn) {
     struct PCIDevice d = {bus, devfn};
     return d;
 }
+static inline u16 pci_to_bdf(PCIDevice d) {
+    return (d.bus << 8) | d.devfn;
+}
+static inline u8 pci_bdf_to_bus(u16 bdf) {
+    return bdf >> 8;
+}
+static inline u8 pci_bdf_to_dev(u16 bdf) {
+    return (bdf >> 3) & 0x1f;
+}
+static inline u8 pci_bdf_to_fn(u16 bdf) {
+    return bdf & 0x07;
+}
 
 void pci_config_writel(PCIDevice d, u32 addr, u32 val);
 void pci_config_writew(PCIDevice d, u32 addr, u16 val);
@@ -23,7 +33,8 @@ u16 pci_config_readw(PCIDevice d, u32 addr);
 u8 pci_config_readb(PCIDevice d, u32 addr);
 
 int pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev);
-int pci_find_class(u32 classid, int index, PCIDevice *dev);
+int pci_find_classprog(u32 classprog, int index, PCIDevice *dev);
+int pci_find_class(u16 classid, int index, PCIDevice *dev);
 
 // pirtable.c
 void create_pirtable();
@@ -38,7 +49,14 @@ void create_pirtable();
 #define PCI_COMMAND            0x04    /* 16 bits */
 #define  PCI_COMMAND_IO                0x1     /* Enable response in I/O space */
 #define  PCI_COMMAND_MEMORY    0x2     /* Enable response in Memory space */
+#define PCI_CLASS_PROG          0x09
 #define PCI_CLASS_DEVICE        0x0a    /* Device class */
+#define PCI_BASE_ADDR_0         0x10
+#define PCI_BASE_ADDR_1         0x14
+#define PCI_BASE_ADDR_2         0x18
+#define PCI_BASE_ADDR_3         0x1c
+#define PCI_BASE_ADDR_4         0x20
+#define PCI_BASE_ADDR_5         0x24
 #define PCI_INTERRUPT_LINE     0x3c    /* 8 bits */
 #define PCI_INTERRUPT_PIN      0x3d    /* 8 bits */
 #define PCI_MIN_GNT            0x3e    /* 8 bits */
index 4e29a43129741fecc9d08afdb0d348f8cbaf4c4e..b189f0bf0c4b09ca09837268c2f0ba64d17ffde8 100644 (file)
@@ -49,7 +49,7 @@ static void
 handle_1ab103(struct bregs *regs)
 {
     PCIDevice d;
-    int ret = pci_find_class(regs->ecx, regs->si, &d);
+    int ret = pci_find_classprog(regs->ecx, regs->si, &d);
     if (ret) {
         set_code_fail(regs, RET_DEVICE_NOT_FOUND);
         return;