Skip to content

Commit a9f15f3

Browse files
ozbenhstewartsmith
authored andcommitted
hdat: Rework parsing of system VPD for Open Power
Handle the OSYS record on OPP machines in stead of VSYS Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
1 parent c1f07c3 commit a9f15f3

File tree

2 files changed

+64
-50
lines changed

2 files changed

+64
-50
lines changed

core/vpd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ const void *vpd_find_record(const void *vpd, size_t vpd_size,
113113
/* Find record name */
114114
rec_name = vpd_find_keyword(p, rec_sz, "RT", &namesz);
115115
if (rec_name && strncmp(record, rec_name, namesz) == 0) {
116-
*sz = rec_sz;
116+
if (sz)
117+
*sz = rec_sz;
117118
return p;
118119
}
119120

hdata/vpd.c

Lines changed: 62 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -631,13 +631,66 @@ static void dt_add_model_name(char *model)
631631
dt_add_property_string(dt_root, "model-name", model_name);
632632
}
633633

634-
static void sysvpd_parse(void)
634+
static void vpd_add_property_string(struct dt_node *n, const char *name,
635+
const void *vpd, unsigned int sz)
636+
{
637+
char *str = zalloc(sz + 1);
638+
if (!str)
639+
return;
640+
memcpy(str, vpd, sz);
641+
dt_add_property_string(n, name, str);
642+
free(str);
643+
}
644+
645+
static void sysvpd_parse_opp(const void *sysvpd, unsigned int sysvpd_sz)
646+
{
647+
const char *v;
648+
uint8_t sz;
649+
650+
v = vpd_find(sysvpd, sysvpd_sz, "OSYS", "MM", &sz);
651+
if (v)
652+
vpd_add_property_string(dt_root, "model", v, sz);
653+
v = vpd_find(sysvpd, sysvpd_sz, "OSYS", "SS", &sz);
654+
if (v)
655+
vpd_add_property_string(dt_root, "system-id", v, sz);
656+
}
657+
658+
659+
static void sysvpd_parse_legacy(const void *sysvpd, unsigned int sysvpd_sz)
635660
{
636661
const char *model;
637662
const char *system_id;
638663
const char *brand;
639664
char *str;
640665
uint8_t sz;
666+
667+
model = vpd_find(sysvpd, sysvpd_sz, "VSYS", "TM", &sz);
668+
if (model) {
669+
str = zalloc(sz + 1);
670+
if (str) {
671+
memcpy(str, model, sz);
672+
dt_add_property_string(dt_root, "model", str);
673+
dt_add_model_name(str);
674+
free(str);
675+
}
676+
} else
677+
dt_add_property_string(dt_root, "model", "Unknown");
678+
679+
system_id = vpd_find(sysvpd, sysvpd_sz, "VSYS", "SE", &sz);
680+
if (system_id)
681+
vpd_add_property_string(dt_root, "system-id", system_id, sz);
682+
else
683+
dt_add_property_string(dt_root, "system-id", "Unknown");
684+
685+
brand = vpd_find(sysvpd, sysvpd_sz, "VSYS", "BR", &sz);
686+
if (brand)
687+
vpd_add_property_string(dt_root, "system-brand", brand, sz);
688+
else
689+
dt_add_property_string(dt_root, "brand", "Unknown");
690+
}
691+
692+
static void sysvpd_parse(void)
693+
{
641694
const void *sysvpd;
642695
unsigned int sysvpd_sz;
643696
unsigned int fru_id_sz;
@@ -647,15 +700,15 @@ static void sysvpd_parse(void)
647700

648701
sysvpd_hdr = get_hdif(&spira.ntuples.system_vpd, SYSVPD_HDIF_SIG);
649702
if (!sysvpd_hdr)
650-
goto no_sysvpd;
703+
return;
651704

652705
fru_id = HDIF_get_idata(sysvpd_hdr, SYSVPD_IDATA_FRU_ID, &fru_id_sz);
653706
if (!fru_id)
654-
goto no_sysvpd;;
707+
return;
655708

656709
sysvpd = HDIF_get_idata(sysvpd_hdr, SYSVPD_IDATA_KW_VPD, &sysvpd_sz);
657710
if (!CHECK_SPPTR(sysvpd))
658-
goto no_sysvpd;
711+
return;
659712

660713
/* Add system VPD */
661714
dt_vpd = dt_find_by_path(dt_root, "/vpd");
@@ -664,51 +717,11 @@ static void sysvpd_parse(void)
664717
slca_vpd_add_loc_code(dt_vpd, be16_to_cpu(fru_id->slca_index));
665718
}
666719

667-
model = vpd_find(sysvpd, sysvpd_sz, "VSYS", "TM", &sz);
668-
if (!model)
669-
goto no_sysvpd;
670-
str = zalloc(sz + 1);
671-
if (!str)
672-
goto no_sysvpd;
673-
memcpy(str, model, sz);
674-
dt_add_property_string(dt_root, "model", str);
675-
676-
dt_add_model_name(str);
677-
678-
free(str);
679-
680-
system_id = vpd_find(sysvpd, sysvpd_sz, "VSYS", "SE", &sz);
681-
if (!system_id)
682-
goto no_sysid;
683-
str = zalloc(sz + 1);
684-
if (!str)
685-
goto no_sysid;
686-
memcpy(str, system_id, sz);
687-
dt_add_property_string(dt_root, "system-id", str);
688-
free(str);
689-
690-
brand = vpd_find(sysvpd, sysvpd_sz, "VSYS", "BR", &sz);
691-
if (!brand)
692-
goto no_brand;
693-
str = zalloc(sz + 1);
694-
if (!str)
695-
goto no_brand;
696-
memcpy(str, brand, sz);
697-
dt_add_property_string(dt_root, "system-brand", str);
698-
free(str);
699-
700-
return;
701-
702-
no_brand:
703-
dt_add_property_string(dt_root, "system-brand", "Unknown");
704-
return;
705-
706-
no_sysid:
707-
dt_add_property_string(dt_root, "system-id", "Unknown");
708-
return;
709-
710-
no_sysvpd:
711-
dt_add_property_string(dt_root, "model", "Unknown");
720+
/* Look for the new OpenPower "OSYS" first */
721+
if (vpd_find_record(sysvpd, sysvpd_sz, "OSYS", NULL))
722+
sysvpd_parse_opp(sysvpd, sysvpd_sz);
723+
else
724+
sysvpd_parse_legacy(sysvpd, sysvpd_sz);
712725
}
713726

714727
static void iokid_vpd_parse(const struct HDIF_common_hdr *iohub_hdr)

0 commit comments

Comments
 (0)