aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/pci-slot.c30
-rw-r--r--include/pci-slot.h3
-rw-r--r--platforms/astbmc/slots.c34
3 files changed, 35 insertions, 32 deletions
diff --git a/core/pci-slot.c b/core/pci-slot.c
index 69bdb86..6d3ed6c 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 0524652..1d323aa 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 92d52f7..5de5120 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)