[Skiboot] [PATCH 03/14] core/pci-slots: Move slot-label construction to a helper

Oliver O'Halloran oohall at gmail.com
Fri Sep 15 15:40:48 AEST 2017


Move this out of the astbmc specific part into a generic helper. This
allows us to use it more commonly.

Signed-off-by: Oliver O'Halloran <oohall at gmail.com>
---
 core/pci-slot.c          | 30 ++++++++++++++++++++++++++++++
 include/pci-slot.h       |  3 +++
 platforms/astbmc/slots.c | 34 ++--------------------------------
 3 files changed, 35 insertions(+), 32 deletions(-)

diff --git a/core/pci-slot.c b/core/pci-slot.c
index 69bdb86abaeb..6d3ed6cb9cb7 100644
--- a/core/pci-slot.c
+++ b/core/pci-slot.c
@@ -212,3 +212,33 @@ struct pci_slot *pci_slot_find(uint64_t id)
 	slot = pd ? pd->slot : NULL;
 	return slot;
 }
+
+void pci_slot_add_loc(struct pci_slot *slot,
+			struct dt_node *np, const char *label)
+{
+	char tmp[8], loc_code[LOC_CODE_SIZE];
+	struct pci_device *pd = slot->pd;
+	struct phb *phb = slot->phb;
+
+	if (!np)
+		return;
+
+	/* didn't get a real slot label? generate one! */
+	if (!label) {
+		snprintf(tmp, sizeof(tmp), "S%04x%02x", phb->opal_id,
+			pd->secondary_bus);
+		label = tmp;
+	}
+
+	/* Make a <PHB_LOC_CODE>-<LABEL> pair if we have a PHB loc code */
+	if (phb->base_loc_code) {
+		snprintf(loc_code, sizeof(loc_code), "%s-%s",
+			phb->base_loc_code, label);
+	} else {
+		strncpy(loc_code, label, sizeof(loc_code));
+	}
+
+	dt_add_property_string(np, "ibm,slot-label", label);
+	dt_add_property_nstr(np, "ibm,slot-location-code", loc_code,
+				sizeof(loc_code));
+}
diff --git a/include/pci-slot.h b/include/pci-slot.h
index 0524652b3142..1d323aa72bce 100644
--- a/include/pci-slot.h
+++ b/include/pci-slot.h
@@ -259,6 +259,9 @@ extern void pci_slot_add_dt_properties(struct pci_slot *slot,
 				       struct dt_node *np);
 extern struct pci_slot *pci_slot_find(uint64_t id);
 
+extern void pci_slot_add_loc(struct pci_slot *slot,
+			struct dt_node *np, const char *label);
+
 /* DT based slot map */
 
 extern struct dt_node *dt_slots;
diff --git a/platforms/astbmc/slots.c b/platforms/astbmc/slots.c
index 92d52f7b5587..5de51209ed59 100644
--- a/platforms/astbmc/slots.c
+++ b/platforms/astbmc/slots.c
@@ -88,42 +88,12 @@ static const struct slot_table_entry *match_slot_dev_entry(struct phb *phb,
 static void slot_table_add_properties(struct pci_slot *slot,
 				struct dt_node *np)
 {
-	struct phb *phb = slot->phb;
-	struct pci_device *pd = slot->pd;
 	struct slot_table_entry *ent = slot->data;
-	size_t base_loc_code_len, slot_label_len;
-	char label[8], loc_code[LOC_CODE_SIZE];
-
-	if (!np)
-		return;
-
-	if (ent) {
-		dt_add_property_string(np, "ibm,slot-label", ent->name);
-		slot_label_len = strlen(ent->name);
-	} else {
-		snprintf(label, 8, "S%04x%02x", phb->opal_id, pd->secondary_bus);
-		dt_add_property_string(np, "ibm,slot-label", label);
-		slot_label_len = strlen(label);
-	}
-
-	base_loc_code_len = phb->base_loc_code ? strlen(phb->base_loc_code) : 0;
-	if ((base_loc_code_len + slot_label_len + 1) >= LOC_CODE_SIZE)
-		return;
-
-	/* Location code */
-	if (phb->base_loc_code) {
-		strcpy(loc_code, phb->base_loc_code);
-		strcat(loc_code, "-");
-	} else {
-		loc_code[0] = '\0';
-	}
 
 	if (ent)
-		strcat(loc_code, ent->name);
+		pci_slot_add_loc(slot, np, ent->name);
 	else
-		strcat(loc_code, label);
-	dt_add_property(np, "ibm,slot-location-code",
-			loc_code, strlen(loc_code) + 1);
+		pci_slot_add_loc(slot, np, NULL);
 }
 
 void slot_table_get_slot_info(struct phb *phb, struct pci_device *pd)
-- 
2.9.5



More information about the Skiboot mailing list