Move pir table offset from ebda to a global variable.
[seabios.git] / src / pci.h
index cb3b786843ec6b2b6cf45fe97feaa92b6c6e4aed..ab7cb9e619b1c5fd6ff70ded53ab5eae08e8ba01 100644 (file)
--- a/src/pci.h
+++ b/src/pci.h
@@ -3,21 +3,12 @@
 
 #include "types.h" // u32
 
-typedef struct PCIDevice {
-    u8 bus;
-    u8 devfn;
-} PCIDevice;
-
-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_devfn(u16 bdf) {
+    return bdf & 0xff;
+}
 static inline u8 pci_bdf_to_dev(u16 bdf) {
     return (bdf >> 3) & 0x1f;
 }
@@ -25,16 +16,21 @@ 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);
-void pci_config_writeb(PCIDevice d, u32 addr, u8 val);
-u32 pci_config_readl(PCIDevice d, u32 addr);
-u16 pci_config_readw(PCIDevice d, u32 addr);
-u8 pci_config_readb(PCIDevice d, u32 addr);
+void pci_config_writel(u16 bdf, u32 addr, u32 val);
+void pci_config_writew(u16 bdf, u32 addr, u16 val);
+void pci_config_writeb(u16 bdf, u32 addr, u8 val);
+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 pci_find_class(u16 classid);
 
-int pci_find_device(u16 vendid, u16 devid, int index, PCIDevice *dev);
-int pci_find_classprog(u32 classprog, int index, PCIDevice *dev);
-int pci_find_class(u16 classid, int index, PCIDevice *dev);
+int pci_next(int bdf, int *pmax);
+#define foreachpci(BDF, MAX)                    \
+    for (MAX=0x0100, BDF=pci_next(0, &MAX)      \
+         ; BDF >= 0                             \
+         ; BDF=pci_next(BDF+1, &MAX))
 
 // pirtable.c
 void create_pirtable();
@@ -44,6 +40,8 @@ void create_pirtable();
  * PIR table
  ****************************************************************/
 
+extern u16 PirOffset;
+
 struct link_info {
     u8 link;
     u16 bitmap;