diff mbox

[1/5] chip: Factor out chip inititialisation

Message ID 1496926461-15876-1-git-send-email-mpe@ellerman.id.au
State Accepted
Headers show

Commit Message

Michael Ellerman June 8, 2017, 12:54 p.m. UTC
Move the chip initialisation logic into a function, so we can call it from
elsewhere in future.

Only change to the logic is that we don't insert the chip into chips[] until
we've finished initialising it.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 core/chip.c | 50 +++++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 21 deletions(-)

Comments

Stewart Smith June 15, 2017, 4:05 a.m. UTC | #1
Michael Ellerman <mpe@ellerman.id.au> writes:
> Move the chip initialisation logic into a function, so we can call it from
> elsewhere in future.
>
> Only change to the logic is that we don't insert the chip into chips[] until
> we've finished initialising it.
>
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>  core/chip.c | 50 +++++++++++++++++++++++++++++---------------------
>  1 file changed, 29 insertions(+), 21 deletions(-)

Series merged to master as of 38434fc13e82fbba31bbb9783d212a8cc15b9b11
with one fixup to fix 'make check', which was just adding
enable_mambo_console as a NOOP_STUB for hdata/test/hdat_to_dt
diff mbox

Patch

diff --git a/core/chip.c b/core/chip.c
index 7765545e9938..3550804383dc 100644
--- a/core/chip.c
+++ b/core/chip.c
@@ -71,9 +71,35 @@  struct proc_chip *get_chip(uint32_t chip_id)
 	return chips[chip_id];
 }
 
-void init_chips(void)
+static void init_chip(struct dt_node *dn)
 {
 	struct proc_chip *chip;
+	uint32_t id;
+
+	id = dt_get_chip_id(dn);
+	assert(id < MAX_CHIPS);
+
+	chip = zalloc(sizeof(struct proc_chip));
+	assert(chip);
+
+	chip->id = id;
+	chip->devnode = dn;
+
+	chip->dbob_id = dt_prop_get_u32_def(dn, "ibm,dbob-id", 0xffffffff);
+	chip->pcid = dt_prop_get_u32_def(dn, "ibm,proc-chip-id", 0xffffffff);
+
+	if (dt_prop_get_u32_def(dn, "ibm,occ-functional-state", 0))
+		chip->occ_functional = true;
+	else
+		chip->occ_functional = false;
+
+	list_head_init(&chip->i2cms);
+
+	chips[id] = chip;
+}
+
+void init_chips(void)
+{
 	struct dt_node *xn;
 
 	/* Detect mambo chip */
@@ -106,24 +132,6 @@  void init_chips(void)
 
 	/* We walk the chips based on xscom nodes in the tree */
 	dt_for_each_compatible(dt_root, xn, "ibm,xscom") {
-		uint32_t id = dt_get_chip_id(xn);
-
-		assert(id < MAX_CHIPS);
-
-		chip = zalloc(sizeof(struct proc_chip));
-		assert(chip);
-		chip->id = id;
-		chip->devnode = xn;
-		chips[id] = chip;
-		chip->dbob_id = dt_prop_get_u32_def(xn, "ibm,dbob-id",
-						    0xffffffff);
-		chip->pcid = dt_prop_get_u32_def(xn, "ibm,proc-chip-id",
-						 0xffffffff);
-		if (dt_prop_get_u32_def(xn, "ibm,occ-functional-state", 0))
-			chip->occ_functional = true;
-		else
-			chip->occ_functional = false;
-
-		list_head_init(&chip->i2cms);
-	};
+		init_chip(xn);
+	}
 }