[Skiboot] [RFC PATCH 1/5] pci/fsp: Cleanup slot_info

Benjamin Herrenschmidt benh at kernel.crashing.org
Thu Aug 20 11:29:26 AEST 2015


This moves some fields that are specific to the LXVPD mechanism out
of the generic pci_slot_info into a private wrapper. Additionally,
most fields in pci_slot_info are made signed integers in order to
allow them to be set to "-1" which indicates that the field doesn't
have a meaningful value, and inhibits creation of the corresponding
device-tree property.

Signed-off-by: Benjamin Herrenschmidt <benh at kernel.crashing.org>
---
 core/pci.c                | 21 +++++++----
 include/pci.h             | 21 +++++------
 platforms/ibm-fsp/lxvpd.c | 89 +++++++++++++++++++++++++----------------------
 3 files changed, 71 insertions(+), 60 deletions(-)

diff --git a/core/pci.c b/core/pci.c
index 2d5906a..479c435 100644
--- a/core/pci.c
+++ b/core/pci.c
@@ -1142,14 +1142,21 @@ static void pci_add_slot_properties(struct phb *phb, struct pci_slot_info *info,
 	/* Add other slot information */
 	dt_add_property_cells(np, "ibm,slot-pluggable", info->pluggable);
 	dt_add_property_cells(np, "ibm,slot-power-ctl", info->power_ctl);
-	dt_add_property_cells(np, "ibm,slot-wired-lanes", info->wired_lanes);
+	if (info->wired_lanes >= 0)
+		dt_add_property_cells(np, "ibm,slot-wired-lanes", info->wired_lanes);
 	/*dt_add_property(np, "ibm,slot-bus-clock", &pd->slot_info->bus_clock, sizeof(uint8_t));*/
-	dt_add_property_cells(np, "ibm,slot-connector-type", info->connector_type);
-	dt_add_property_cells(np, "ibm,slot-card-desc", info->card_desc);
-	dt_add_property_cells(np, "ibm,slot-card-mech", info->card_mech);
-	dt_add_property_cells(np, "ibm,slot-pwr-led-ctl", info->pwr_led_ctl);
-	dt_add_property_cells(np, "ibm,slot-attn-led-ctl", info->attn_led_ctl);
-	dt_add_property_string(np, "ibm,slot-label", info->label);
+	if (info->connector_type >= 0)
+		dt_add_property_cells(np, "ibm,slot-connector-type", info->connector_type);
+	if (info->card_desc >= 0)
+		dt_add_property_cells(np, "ibm,slot-card-desc", info->card_desc);
+	if (info->card_mech >= 0)
+		dt_add_property_cells(np, "ibm,slot-card-mech", info->card_mech);
+	if (info->pwr_led_ctl >= 0)
+		dt_add_property_cells(np, "ibm,slot-pwr-led-ctl", info->pwr_led_ctl);
+	if (info->attn_led_ctl >= 0)
+		dt_add_property_cells(np, "ibm,slot-attn-led-ctl", info->attn_led_ctl);
+	if (strlen(info->label) > 0)
+		dt_add_property_string(np, "ibm,slot-label", info->label);
 }
 
 static void pci_add_loc_code(struct dt_node *np, struct pci_device *pd)
diff --git a/include/pci.h b/include/pci.h
index 6b3a228..2385163 100644
--- a/include/pci.h
+++ b/include/pci.h
@@ -77,20 +77,17 @@
 
 /* PCI Slot Entry Information */
 struct pci_slot_info {
-	uint8_t    switch_id;
-	uint8_t    vswitch_id;
-	uint8_t    dev_id;
-	char       label[9];
+	char       label[16];
 	bool       pluggable;
 	bool       power_ctl;
-	uint8_t    wired_lanes;
-	uint8_t    bus_clock;
-	uint8_t    connector_type;
-	uint8_t    card_desc;
-	uint8_t    card_mech;
-	uint8_t    pwr_led_ctl;
-	uint8_t    attn_led_ctl;
-	uint8_t    slot_index;
+	int        wired_lanes;
+	int        bus_clock;
+	int        connector_type;
+	int        card_desc;
+	int        card_mech;
+	int        pwr_led_ctl;
+	int        attn_led_ctl;
+	int	   slot_index;
 };
 
 /*
diff --git a/platforms/ibm-fsp/lxvpd.c b/platforms/ibm-fsp/lxvpd.c
index 43a1c5e..92c2760 100644
--- a/platforms/ibm-fsp/lxvpd.c
+++ b/platforms/ibm-fsp/lxvpd.c
@@ -27,13 +27,20 @@
 
 #include "lxvpd.h"
 
+struct lxvpd_slot_info {
+	uint8_t    switch_id;
+	uint8_t    vswitch_id;
+	uint8_t    dev_id;
+	struct pci_slot_info	ps;
+};
+
 /*
  * XXX TODO: Add 1006 maps to add function loc codes and loc code maps
  * (ie. -Tn part of the location code) 
  */
 struct lxvpd_slot_info_data {
 	uint8_t			num_slots;
-	struct pci_slot_info	info[];
+	struct lxvpd_slot_info	info[];
 };
 
 static bool lxvpd_supported_slot(struct phb *phb, struct pci_device *pd)
@@ -97,7 +104,7 @@ void lxvpd_get_slot_info(struct phb *phb, struct pci_device * pd)
 
 	/* Iterate the slot map */
 	for (idx = 0; idx <= sdata->num_slots; idx++) {
-		struct pci_slot_info *info = &sdata->info[idx];
+		struct lxvpd_slot_info *info = &sdata->info[idx];
 		uint8_t pd_dev = (pd->bdfn >> 3) & 0x1f;
 
 		/* Match PHB with switch_id == 0 */
@@ -114,7 +121,7 @@ void lxvpd_get_slot_info(struct phb *phb, struct pci_device * pd)
 	}
 
 	if (entry_found) {
-		pd->slot_info = &sdata->info[idx];
+		pd->slot_info = &sdata->info[idx].ps;
 		prlog(PR_TRACE, "PCI: PCIE Slot Info: \n"
 		      "       Label       %s\n"
 		      "       Pluggable   0x%x\n"
@@ -135,12 +142,12 @@ void lxvpd_get_slot_info(struct phb *phb, struct pci_device * pd)
 	}
 }
 
-static struct pci_slot_info *lxvpd_alloc_slot_info(struct phb *phb, int count)
+static struct lxvpd_slot_info *lxvpd_alloc_slot_info(struct phb *phb, int count)
 {
 	struct lxvpd_slot_info_data *data;
 
 	data = zalloc(sizeof(struct lxvpd_slot_info_data) *
-		      count * sizeof(struct pci_slot_info));
+		      count * sizeof(struct lxvpd_slot_info));
 	assert(data);
 	data->num_slots = count;
 	phb->platform_data = data;
@@ -151,7 +158,7 @@ static struct pci_slot_info *lxvpd_alloc_slot_info(struct phb *phb, int count)
 static void lxvpd_parse_1004_map(struct phb *phb, const uint8_t *sm, uint8_t sz)
 {
 	const struct pci_slot_entry_1004 *entry = NULL;
-	struct pci_slot_info *slot_info, *info;
+	struct lxvpd_slot_info *slot_info, *info;
 	uint8_t num_slots, slot, idx;
 
 	num_slots = (sz / sizeof(struct pci_slot_entry_1004));
@@ -167,32 +174,32 @@ static void lxvpd_parse_1004_map(struct phb *phb, const uint8_t *sm, uint8_t sz)
 		info->vswitch_id = entry->pba &0xf;
 		info->dev_id = entry->sba;
 		for (idx = 0; idx < 3; idx++)
-			info->label[idx] = entry->label[idx];
-		info->label[3] = 0;
-		info->pluggable = ((entry->p0.byte & 0x20) == 0);
-		info->power_ctl = ((entry->p0.power_ctl & 0x40) == 1);
+			info->ps.label[idx] = entry->label[idx];
+		info->ps.label[3] = 0;
+		info->ps.pluggable = ((entry->p0.byte & 0x20) == 0);
+		info->ps.power_ctl = ((entry->p0.power_ctl & 0x40) == 1);
 		switch(entry->p1.wired_lanes) {
-		case 1: info->wired_lanes = PCI_SLOT_WIRED_LANES_PCIX_32; break;
+		case 1: info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_PCIX_32; break;
 		case 2: /* fall through */
-		case 3: info->wired_lanes = PCI_SLOT_WIRED_LANES_PCIX_64; break;
-		case 4: info->wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X1; break;
-		case 5: info->wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X4; break;
-		case 6: info->wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X8; break;
-		case 7: info->wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X16; break;
+		case 3: info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_PCIX_64; break;
+		case 4: info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X1; break;
+		case 5: info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X4; break;
+		case 6: info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X8; break;
+		case 7: info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_PCIE_X16; break;
 		default:
-			info->wired_lanes = PCI_SLOT_WIRED_LANES_UNKNOWN;
+			info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_UNKNOWN;
 		}
-		info->wired_lanes = (entry->p1.wired_lanes - 3);
-		info->bus_clock = (entry->p2.bus_clock - 4);
-		info->connector_type = (entry->p2.connector_type - 5);
+		info->ps.wired_lanes = (entry->p1.wired_lanes - 3);
+		info->ps.bus_clock = (entry->p2.bus_clock - 4);
+		info->ps.connector_type = (entry->p2.connector_type - 5);
 		if (entry->p3.byte < 0xC0)
-			info->card_desc = ((entry->p3.byte >> 6) - 4) ;
+			info->ps.card_desc = ((entry->p3.byte >> 6) - 4) ;
 		else
-			info->card_desc = (entry->p3.byte >> 6);
-		info->card_mech = ((entry->p3.byte >> 4) & 0x3);
-		info->pwr_led_ctl = ((entry->p3.byte & 0xF) >> 2);
-		info->attn_led_ctl = (entry->p3.byte & 0x3);
-		info->slot_index = entry->slot_index;
+			info->ps.card_desc = (entry->p3.byte >> 6);
+		info->ps.card_mech = ((entry->p3.byte >> 4) & 0x3);
+		info->ps.pwr_led_ctl = ((entry->p3.byte & 0xF) >> 2);
+		info->ps.attn_led_ctl = (entry->p3.byte & 0x3);
+		info->ps.slot_index = entry->slot_index;
 		entry++;
 	}
 }
@@ -200,7 +207,7 @@ static void lxvpd_parse_1004_map(struct phb *phb, const uint8_t *sm, uint8_t sz)
 static void lxvpd_parse_1005_map(struct phb *phb, const uint8_t *sm, uint8_t sz)
 {
 	const struct pci_slot_entry_1005 *entry = NULL;
-	struct pci_slot_info *slot_info, *info;
+	struct lxvpd_slot_info *slot_info, *info;
 	uint8_t num_slots, slot, idx;
 
 	num_slots = (sz / sizeof(struct pci_slot_entry_1005));
@@ -216,20 +223,20 @@ static void lxvpd_parse_1005_map(struct phb *phb, const uint8_t *sm, uint8_t sz)
 		info->vswitch_id = entry->pba &0xf;
 		info->dev_id = entry->switch_device_id;
 		for (idx = 0; idx < 8; idx++)
-			info->label[idx] = entry->label[idx];
-		info->label[8] = 0;
-		info->pluggable = (entry->p0.pluggable == 0);
-		info->power_ctl = entry->p0.power_ctl;
-		info->wired_lanes = entry->p1.wired_lanes;
-		if (info->wired_lanes > PCI_SLOT_WIRED_LANES_PCIE_X32)
-			info->wired_lanes = PCI_SLOT_WIRED_LANES_UNKNOWN;
-		info->bus_clock = entry->p2.bus_clock;
-		info->connector_type = entry->p2.connector_type;
-		info->card_desc = (entry->p3.byte >> 6);
-		info->card_mech = ((entry->p3.byte >> 4) & 0x3);
-		info->pwr_led_ctl = ((entry->p3.byte & 0xF) >> 2);
-		info->attn_led_ctl = (entry->p3.byte & 0x3);
-		info->slot_index = entry->slot_index;
+			info->ps.label[idx] = entry->label[idx];
+		info->ps.label[8] = 0;
+		info->ps.pluggable = (entry->p0.pluggable == 0);
+		info->ps.power_ctl = entry->p0.power_ctl;
+		info->ps.wired_lanes = entry->p1.wired_lanes;
+		if (info->ps.wired_lanes > PCI_SLOT_WIRED_LANES_PCIE_X32)
+			info->ps.wired_lanes = PCI_SLOT_WIRED_LANES_UNKNOWN;
+		info->ps.bus_clock = entry->p2.bus_clock;
+		info->ps.connector_type = entry->p2.connector_type;
+		info->ps.card_desc = (entry->p3.byte >> 6);
+		info->ps.card_mech = ((entry->p3.byte >> 4) & 0x3);
+		info->ps.pwr_led_ctl = ((entry->p3.byte & 0xF) >> 2);
+		info->ps.attn_led_ctl = (entry->p3.byte & 0x3);
+		info->ps.slot_index = entry->slot_index;
 		entry++;
 	}
 }
-- 
2.4.3



More information about the Skiboot mailing list