seabios: pci: introduce foreachpci_in_bus() helper macro.
authorIsaku Yamahata <yamahata@valinux.co.jp>
Tue, 22 Jun 2010 08:57:46 +0000 (17:57 +0900)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 4 Jul 2010 12:51:39 +0000 (08:51 -0400)
This patch introduces foreachpci_in_bus() helper macro for
depth first recursion. foreachpci() is for width first recursion.
The macro will be used later to initialize pci bridge
that requires depth first recursion.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
src/pci.h

index 8a21c06b76898b8aaba6d9b977854771837fab80..e40e116922bb81e87eedfd3a81964f95ebfe848e 100644 (file)
--- a/src/pci.h
+++ b/src/pci.h
@@ -21,6 +21,9 @@ static inline u8 pci_bdf_to_fn(u16 bdf) {
 static inline u16 pci_to_bdf(int bus, int dev, int fn) {
     return (bus<<8) | (dev<<3) | fn;
 }
+static inline u16 pci_bus_devfn_to_bdf(int bus, u16 devfn) {
+    return (bus << 8) | devfn;
+}
 
 static inline u32 pci_vd(u16 vendor, u16 device) {
     return (device << 16) | vendor;
@@ -50,6 +53,13 @@ int pci_next(int bdf, int *pmax);
          ; BDF >= 0                             \
          ; BDF=pci_next(BDF+1, &MAX))
 
+#define foreachpci_in_bus(BDF, MAX, BUS)                                \
+    for (MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100,                   \
+         BDF = pci_next(pci_bus_devfn_to_bdf(BUS, 0), &MAX)             \
+         ; BDF >= 0 && BDF < pci_bus_devfn_to_bdf(BUS, 0) + 0x0100      \
+         ; MAX = pci_bus_devfn_to_bdf(BUS, 0) + 0x0100,                 \
+           BDF = pci_next(BDF + 1, &MAX))
+
 // pirtable.c
 void create_pirtable(void);