[Skiboot] [PATCH V2 2/7] pci: Add for_each_phb macro for PHB traversal
Russell Currey
ruscur at russell.cc
Mon Mar 21 12:00:01 AEDT 2016
Similar to for_each_cpu, adding a for_each_phb makes PHB traversal easy.
Suggested-by: Alistair Popple <alistair at popple.id.au>
Signed-off-by: Russell Currey <ruscur at russell.cc>
Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
core/pci.c | 3 +++
include/pci.h | 14 ++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/core/pci.c b/core/pci.c
index c51c838..e2fe287 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -24,6 +24,7 @@
#define MAX_PHB_ID 256
static struct phb *phbs[MAX_PHB_ID];
+int last_phb_id = 0;
#define PCITRACE(_p, _bdfn, fmt, a...) \
prlog(PR_TRACE, "PHB#%04x:%02x:%02x.%x " fmt, \
@@ -818,6 +819,8 @@ int64_t pci_register_phb(struct phb *phb, int opal_id)
phbs[opal_id] = phb;
phb->opal_id = opal_id;
+ if (opal_id > last_phb_id)
+ last_phb_id = opal_id;
dt_add_property_cells(phb->dt_node, "ibm,opal-phbid", 0, phb->opal_id);
PCIDBG(phb, 0, "PCI: Registered PHB\n");
diff --git a/include/pci.h b/include/pci.h
index 4640dda..7b9d088 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -228,6 +228,7 @@ struct pci_lsi_state {
*/
struct phb;
+extern int last_phb_id;
struct phb_ops {
/*
@@ -513,6 +514,7 @@ static inline int64_t pci_cfg_write32(struct phb *phb, uint32_t bdfn,
}
/* Utilities */
+
extern int64_t pci_find_cap(struct phb *phb, uint16_t bdfn, uint8_t cap);
extern int64_t pci_find_ecap(struct phb *phb, uint16_t bdfn, uint16_t cap,
uint8_t *version);
@@ -537,6 +539,18 @@ extern int64_t pci_unregister_phb(struct phb *phb);
extern struct phb *pci_get_phb(uint64_t phb_id);
static inline void pci_put_phb(struct phb *phb __unused) { }
+static inline struct phb *__pci_next_phb_idx(uint64_t *phb_id) {
+ struct phb *phb = NULL;
+ while (phb == NULL && *phb_id <= last_phb_id) {
+ phb = pci_get_phb((*phb_id)++);
+ }
+ return phb;
+}
+
+#define for_each_phb(phb) \
+ for (uint64_t __phb_idx = 0; \
+ (phb = __pci_next_phb_idx(&__phb_idx)) ; )
+
/* Device tree */
extern void pci_std_swizzle_irq_map(struct dt_node *dt_node,
struct pci_device *pd,
--
2.7.3
More information about the Skiboot
mailing list