[Skiboot] [RFC 11/12] astbmc/slots: Add ST_PHB_ENTRY helper

Oliver O'Halloran oohall at gmail.com
Tue Aug 1 23:00:06 AEST 2017


The PHB slot tables are very verbose and mostly the same. Add a macro to
with the three actual paramaters (chip id, phb and slots) to highlight
the actual differences and remove the boilerplate.
---
 platforms/astbmc/astbmc.h      | 10 ++++++
 platforms/astbmc/barreleye.c   | 38 +++++----------------
 platforms/astbmc/firestone.c   | 32 ++++--------------
 platforms/astbmc/garrison.c    | 50 ++++++---------------------
 platforms/astbmc/habanero.c    | 19 +++--------
 platforms/astbmc/p8dnu.c       | 50 ++++++---------------------
 platforms/astbmc/p8dtu.c       | 76 +++++++++---------------------------------
 platforms/astbmc/palmetto.c    | 19 +++--------
 platforms/astbmc/witherspoon.c | 56 ++++++-------------------------
 9 files changed, 80 insertions(+), 270 deletions(-)

diff --git a/platforms/astbmc/astbmc.h b/platforms/astbmc/astbmc.h
index e094e2506d76..c1236ae22bf0 100644
--- a/platforms/astbmc/astbmc.h
+++ b/platforms/astbmc/astbmc.h
@@ -37,6 +37,16 @@
 #define ST_LOC_NPU_TARGET(chip_id, group_id) \
 	(ST_LOC_NVLINK_VALID | ((chip_id) << 16) | (group_id))
 
+/*
+ * Helper to reduce the noise in the PHB table
+ */
+#define ST_PHB_ENTRY(chip_id, phb_id, child_table) \
+{ \
+	.etype = st_phb, \
+	.location = ST_LOC_PHB(chip_id, phb_id), \
+	.children = child_table \
+}
+
 struct slot_table_entry {
 	enum slot_table_etype {
 		st_end,		/* End of list */
diff --git a/platforms/astbmc/barreleye.c b/platforms/astbmc/barreleye.c
index f8c77e3b00d3..9c116a977867 100644
--- a/platforms/astbmc/barreleye.c
+++ b/platforms/astbmc/barreleye.c
@@ -112,36 +112,14 @@ static const struct slot_table_entry barreleye_phb8_2_slot[] = {
 };
 
 static const struct slot_table_entry barreleye_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = barreleye_phb0_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = barreleye_phb0_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = barreleye_phb0_2_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,0),
-		.children = barreleye_phb8_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,1),
-		.children = barreleye_phb8_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,2),
-		.children = barreleye_phb8_2_slot,
-	},
+	ST_PHB_ENTRY(0, 0, barreleye_phb0_0_slot),
+	ST_PHB_ENTRY(0, 1, barreleye_phb0_1_slot),
+	ST_PHB_ENTRY(0, 2, barreleye_phb0_2_slot),
+
+	ST_PHB_ENTRY(8, 0, barreleye_phb8_0_slot),
+	ST_PHB_ENTRY(8, 1, barreleye_phb8_1_slot),
+	ST_PHB_ENTRY(8, 2, barreleye_phb8_2_slot),
+
 	{ .etype = st_end },
 };
 
diff --git a/platforms/astbmc/firestone.c b/platforms/astbmc/firestone.c
index 7434a4802fc5..401a9d07a26c 100644
--- a/platforms/astbmc/firestone.c
+++ b/platforms/astbmc/firestone.c
@@ -103,31 +103,13 @@ static const struct slot_table_entry firestone_phb8_2_slot[] = {
 };
 
 static const struct slot_table_entry firestone_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = firestone_phb0_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = firestone_phb0_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,0),
-		.children = firestone_phb8_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,1),
-		.children = firestone_phb8_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,2),
-		.children = firestone_phb8_2_slot,
-	},
+	ST_PHB_ENTRY(0, 0, firestone_phb0_0_slot),
+	ST_PHB_ENTRY(0, 1, firestone_phb0_1_slot),
+
+	ST_PHB_ENTRY(8, 0, firestone_phb8_0_slot),
+	ST_PHB_ENTRY(8, 1, firestone_phb8_1_slot),
+	ST_PHB_ENTRY(8, 2, firestone_phb8_2_slot),
+
 	{ .etype = st_end },
 };
 
diff --git a/platforms/astbmc/garrison.c b/platforms/astbmc/garrison.c
index a467672ea7a0..3f2725e2515b 100644
--- a/platforms/astbmc/garrison.c
+++ b/platforms/astbmc/garrison.c
@@ -131,46 +131,16 @@ static const struct slot_table_entry garrison_phb1_3_slot[] = {
 };
 
 static const struct slot_table_entry garrison_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = garrison_phb0_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = garrison_phb0_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = garrison_phb0_2_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,3),
-		.children = garrison_phb0_3_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,0),
-		.children = garrison_phb1_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,1),
-		.children = garrison_phb1_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,2),
-		.children = garrison_phb1_2_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,3),
-		.children = garrison_phb1_3_slot,
-	},
+	ST_PHB_ENTRY(0, 0, garrison_phb0_0_slot),
+	ST_PHB_ENTRY(0, 1, garrison_phb0_1_slot),
+	ST_PHB_ENTRY(0, 2, garrison_phb0_2_slot),
+	ST_PHB_ENTRY(0, 3, garrison_phb0_3_slot),
+
+	ST_PHB_ENTRY(1, 0, garrison_phb1_0_slot),
+	ST_PHB_ENTRY(1, 1, garrison_phb1_1_slot),
+	ST_PHB_ENTRY(1, 2, garrison_phb1_2_slot),
+	ST_PHB_ENTRY(1, 3, garrison_phb1_3_slot),
+
 	{ .etype = st_end },
 };
 
diff --git a/platforms/astbmc/habanero.c b/platforms/astbmc/habanero.c
index 2ff1a7eeee79..545a5372209a 100644
--- a/platforms/astbmc/habanero.c
+++ b/platforms/astbmc/habanero.c
@@ -95,21 +95,10 @@ static const struct slot_table_entry habanero_phb2_slot[] = {
 };
 
 static const struct slot_table_entry habanero_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = habanero_phb0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = habanero_phb1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = habanero_phb2_slot,
-	},
+	ST_PHB_ENTRY(0, 0, habanero_phb0_slot),
+	ST_PHB_ENTRY(0, 1, habanero_phb1_slot),
+	ST_PHB_ENTRY(0, 2, habanero_phb2_slot),
+
 	{ .etype = st_end },
 };
 
diff --git a/platforms/astbmc/p8dnu.c b/platforms/astbmc/p8dnu.c
index 5502af86bdaf..b25ebc73601d 100644
--- a/platforms/astbmc/p8dnu.c
+++ b/platforms/astbmc/p8dnu.c
@@ -173,46 +173,16 @@ static const struct slot_table_entry p8dnu_phb1_3_slot[] = {
 };
 
 static const struct slot_table_entry p8dnu_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = p8dnu_phb0_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = p8dnu_phb0_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = p8dnu_phb0_2_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,3),
-		.children = p8dnu_phb0_3_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,0),
-		.children = p8dnu_phb1_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,1),
-		.children = p8dnu_phb1_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,2),
-		.children = p8dnu_phb1_2_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(1,3),
-		.children = p8dnu_phb1_3_slot,
-	},
+	ST_PHB_ENTRY(0, 0, p8dnu_phb0_0_slot),
+	ST_PHB_ENTRY(0, 1, p8dnu_phb0_1_slot),
+	ST_PHB_ENTRY(0, 2, p8dnu_phb0_2_slot),
+	ST_PHB_ENTRY(0, 3, p8dnu_phb0_3_slot),
+
+	ST_PHB_ENTRY(1, 0, p8dnu_phb1_0_slot),
+	ST_PHB_ENTRY(1, 1, p8dnu_phb1_1_slot),
+	ST_PHB_ENTRY(1, 2, p8dnu_phb1_2_slot),
+	ST_PHB_ENTRY(1, 3, p8dnu_phb1_3_slot),
+
 	{ .etype = st_end },
 };
 
diff --git a/platforms/astbmc/p8dtu.c b/platforms/astbmc/p8dtu.c
index 7c3b41b71680..f607b8ee687d 100644
--- a/platforms/astbmc/p8dtu.c
+++ b/platforms/astbmc/p8dtu.c
@@ -136,70 +136,26 @@ static const struct slot_table_entry p8dtu1u_phb8_2_slot[] = {
 };
 
 static const struct slot_table_entry p8dtu2u_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = p8dtu_phb0_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = p8dtu_phb0_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = p8dtu_phb0_2_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,0),
-		.children = p8dtu_phb8_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,1),
-		.children = p8dtu2u_phb8_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,2),
-		.children = p8dtu2u_phb8_2_slot,
-	},
+	ST_PHB_ENTRY(0, 0, p8dtu_phb0_0_slot),
+	ST_PHB_ENTRY(0, 1, p8dtu_phb0_1_slot),
+	ST_PHB_ENTRY(0, 2, p8dtu_phb0_2_slot),
+
+	ST_PHB_ENTRY(8, 0, p8dtu_phb8_0_slot),
+	ST_PHB_ENTRY(8, 1, p8dtu2u_phb8_1_slot),
+	ST_PHB_ENTRY(8, 2, p8dtu2u_phb8_2_slot),
+
 	{ .etype = st_end },
 };
 
 static const struct slot_table_entry p8dtu1u_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = p8dtu_phb0_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = p8dtu_phb0_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = p8dtu_phb0_2_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,0),
-		.children = p8dtu_phb8_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,1),
-		.children = p8dtu1u_phb8_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,2),
-		.children = p8dtu1u_phb8_2_slot,
-	},
+	ST_PHB_ENTRY(0, 0, p8dtu_phb0_0_slot),
+	ST_PHB_ENTRY(0, 1, p8dtu_phb0_1_slot),
+	ST_PHB_ENTRY(0, 2, p8dtu_phb0_2_slot),
+
+	ST_PHB_ENTRY(8, 0, p8dtu_phb8_0_slot),
+	ST_PHB_ENTRY(8, 1, p8dtu1u_phb8_1_slot),
+	ST_PHB_ENTRY(8, 2, p8dtu1u_phb8_2_slot),
+
 	{ .etype = st_end },
 };
 
diff --git a/platforms/astbmc/palmetto.c b/platforms/astbmc/palmetto.c
index fb115dc31f29..0521ac105f4f 100644
--- a/platforms/astbmc/palmetto.c
+++ b/platforms/astbmc/palmetto.c
@@ -85,21 +85,10 @@ static const struct slot_table_entry palmetto_phb0_2_slot[] = {
 };
 
 static const struct slot_table_entry palmetto_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = palmetto_phb0_0_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,1),
-		.children = palmetto_phb0_1_slot,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = palmetto_phb0_2_slot,
-	},
+	ST_PHB_ENTRY(0, 0, palmetto_phb0_0_slot),
+	ST_PHB_ENTRY(0, 1, palmetto_phb0_1_slot),
+	ST_PHB_ENTRY(0, 2, palmetto_phb0_2_slot),
+
 	{ .etype = st_end },
 };
 
diff --git a/platforms/astbmc/witherspoon.c b/platforms/astbmc/witherspoon.c
index f05eaede51b9..bba2350ccfaa 100644
--- a/platforms/astbmc/witherspoon.c
+++ b/platforms/astbmc/witherspoon.c
@@ -201,51 +201,17 @@ static const struct slot_table_entry witherspoon_net_phb[] = {
  */
 
 static const struct slot_table_entry witherspoon_phb_table[] = {
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,0),
-		.children = witherspoon_slot4, /* XXX: Might be slot 3 */
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,2),
-		.children = witherspoon_bmc_phb, /* BMC */
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,3),
-		.children = witherspoon_slot2_shared, /* shared */
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,4),
-		.children = witherspoon_plx0_phb, /* chip 1 PLX connection */
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(0,5),
-		.children = witherspoon_net_phb, /* builtin ethernet */
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,0),
-		.children = witherspoon_slot3, /* XXX: might be slot 4 */
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,3),
-		.children = witherspoon_slot2_shared, /* shared slot */
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,4),
-		.children = witherspoon_slot1,
-	},
-	{
-		.etype = st_phb,
-		.location = ST_LOC_PHB(8,5),
-		.children = witherspoon_plx1_phb, /* Chip 2 PLX up */
-	},
+	ST_PHB_ENTRY(0, 0, witherspoon_slot4), /* XXX: might be slot3 */
+	ST_PHB_ENTRY(0, 2, witherspoon_bmc_phb), 	/* BMC */
+	ST_PHB_ENTRY(0, 3, witherspoon_slot2_shared),	/* shared */
+	ST_PHB_ENTRY(0, 4, witherspoon_plx0_phb),
+	ST_PHB_ENTRY(0, 5, witherspoon_net_phb),
+
+	ST_PHB_ENTRY(8, 0, witherspoon_slot3), /* XXX: might be swapped with 4 */
+	ST_PHB_ENTRY(8, 3, witherspoon_slot2_shared),
+	ST_PHB_ENTRY(8, 4, witherspoon_slot1),
+	ST_PHB_ENTRY(8, 5, witherspoon_plx1_phb),
+
 	{ .etype = st_end },
 };
 
-- 
2.9.4



More information about the Skiboot mailing list