Skip to content

Commit

Permalink
core/pci-slots: Move slot-label construction to a helper
Browse files Browse the repository at this point in the history
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@gmail.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Sep 15, 2017
1 parent cc41ce9 commit 6d67361
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
30 changes: 30 additions & 0 deletions core/pci-slot.c
Expand Up @@ -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));
}
3 changes: 3 additions & 0 deletions include/pci-slot.h
Expand Up @@ -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;
Expand Down
34 changes: 2 additions & 32 deletions platforms/astbmc/slots.c
Expand Up @@ -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)
Expand Down

0 comments on commit 6d67361

Please sign in to comment.