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
--- changes v1 -> v2: - simplified according to Kevin's suggestion. --- src/pci.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/src/pci.h b/src/pci.h index 8a21c06..e40e116 100644 --- 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);