diff mbox

[1/3] pci: add pci_find_capability() helper

Message ID baa686194d4802c96dd995a88bd1aea001914c5e.1296774883.git.eduard.munteanu@linux360.ro (mailing list archive)
State New, archived
Headers show

Commit Message

Eduard - Gabriel Munteanu Feb. 3, 2011, 11:24 p.m. UTC
None
diff mbox

Patch

diff --git a/src/pci.c b/src/pci.c
index 944a393..57caba6 100644
--- a/src/pci.c
+++ b/src/pci.c
@@ -185,6 +185,21 @@  pci_find_class(u16 classid)
     return -1;
 }
 
+int pci_find_capability(int bdf, u8 capid)
+{
+    int ptr, cap;
+
+    ptr = PCI_CAPABILITY_LIST;
+    do {
+        cap = pci_config_readb(bdf, ptr);
+        if (pci_config_readb(bdf, cap) == capid)
+            return cap;
+        ptr = cap + PCI_CAP_LIST_NEXT;
+    } while (cap);
+
+    return -1;
+}
+
 int *PCIpaths;
 
 // Build the PCI path designations.
diff --git a/src/pci.h b/src/pci.h
index 9869a26..bf0d1b8 100644
--- a/src/pci.h
+++ b/src/pci.h
@@ -46,6 +46,7 @@  void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on);
 int pci_find_vga(void);
 int pci_find_device(u16 vendid, u16 devid);
 int pci_find_class(u16 classid);
+int pci_find_capability(int bdf, u8 capid);
 
 #define PP_ROOT      (1<<17)
 #define PP_PCIBRIDGE (1<<18)