diff mbox

[V2,2/7] pci: Add for_each_phb macro for PHB traversal

Message ID 1458522006-8846-3-git-send-email-ruscur@russell.cc
State Accepted
Headers show

Commit Message

Russell Currey March 21, 2016, 1 a.m. UTC
Similar to for_each_cpu, adding a for_each_phb makes PHB traversal easy.

Suggested-by: Alistair Popple <alistair@popple.id.au>
Signed-off-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
---
 core/pci.c    |  3 +++
 include/pci.h | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

Comments

Andrew Donnellan March 21, 2016, 3:13 a.m. UTC | #1
On 21/03/16 12:00, Russell Currey wrote:
> Similar to for_each_cpu, adding a for_each_phb makes PHB traversal easy.
>
> Suggested-by: Alistair Popple <alistair@popple.id.au>
> Signed-off-by: Russell Currey <ruscur@russell.cc>
> Signed-off-by: Oliver O'Halloran <oohall@gmail.com>

Reviewed-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

> @@ -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);

Extraneous whitespace, please submit V3 ;)
diff mbox

Patch

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,