pci: add pci_for_each_func3() which produces an address
authorH. Peter Anvin <hpa@linux.intel.com>
Tue, 14 Apr 2009 20:45:33 +0000 (13:45 -0700)
committerH. Peter Anvin <hpa@linux.intel.com>
Wed, 15 Apr 2009 23:23:56 +0000 (16:23 -0700)
Add pci_for_each_func3() iterator, which produces an address in
addition to the device pointer.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
com32/include/sys/pci.h

index 2e1871e..b44db62 100644 (file)
@@ -80,6 +80,16 @@ struct pci_domain {
            if (((funcp) = (domain)->bus[__pci_bus]->slot[__pci_slot]-> \
                 func[__pci_func]))
 
+#define for_each_pci_func3(funcp, domain, addr) \
+  for (int __pci_bus = 0; __pci_bus < MAX_PCI_BUSES; __pci_bus++) \
+    if ((domain)->bus[__pci_bus]) \
+      for (int __pci_slot = 0; __pci_slot < MAX_PCI_DEVICES; __pci_slot++) \
+       if ((domain)->bus[__pci_bus]->slot[__pci_slot]) \
+         for (int __pci_func = 0; __pci_func < MAX_PCI_FUNC; __pci_func++) \
+           if (((addr) = pci_mkaddr(__pci_bus, __pci_slot, __pci_func, 0)), \
+               ((funcp) = (domain)->bus[__pci_bus]->slot[__pci_slot]-> \
+                func[__pci_func]))
+
 struct match {
   struct match *next;
   uint32_t did;