When there isn't an entry for the model name in the id_part table(s), attempt to get the machine name from /sys/bus/soc/devices/soc0/machine to use as the model name. This mechanism allows lscpu to use the model/machine name provided via the ARM SMC support code rather than via hard-coded lscpu tables. This code was tested by removing the "Ampere-1a" entry from the ampere-part table and verifying that lscpu displayed the correct machine name obtained via the ARM SMC interface to Trusted Firmware. The "Ampere-1a" entry will be permanently removed by a separate patch. Signed-off-by: Paul Benoit <paul@xxxxxxxxxxxxxxxxxxxxxx> --- sys-utils/lscpu-arm.c | 35 ++++++++++++++++++++++++++++++++--- sys-utils/lscpu.h | 1 + 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c index 8745599d4..a46106bcb 100644 --- a/sys-utils/lscpu-arm.c +++ b/sys-utils/lscpu-arm.c @@ -388,7 +388,10 @@ int is_arm(struct lscpu_cxt *cxt) static int arm_ids_decode(struct lscpu_cputype *ct) { int impl, part, j; + unsigned int i; const struct id_part *parts = NULL; + FILE *fd; + char machinename[BUFSIZ] = ""; impl = parse_implementer_id(ct); if (impl <= 0) @@ -406,11 +409,11 @@ static int arm_ids_decode(struct lscpu_cputype *ct) /* decode model */ if (!parts) - goto done; + goto try_machinename; part = parse_model_id(ct); if (part <= 0) - goto done; + goto try_machinename; for (j = 0; parts[j].id != -1; j++) { if (parts[j].id == part) { @@ -419,7 +422,33 @@ static int arm_ids_decode(struct lscpu_cputype *ct) break; } } -done: + +try_machinename: + + /* + * If the Model name was not found in the lscpu 'id_part' tables, see + * if there is a Machine name associated with the SOC. This name may + * have been set via either SOC specific support code, or obtained + * via an ARM SMC CC call into Trusted Firmware. + */ + if (!ct->modelname) { + fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME); + if (fd) { + if (!fgets(machinename, sizeof(machinename), fd)) + machinename[0] = '\0'; + fclose(fd); + + /* Replace newline with string terminator */ + for (i = 0; i < strlen(machinename); i++) { + if (machinename[i] == '\n') + machinename[i] = '\0'; + } + + if (strnlen(machinename, sizeof(machinename))) + ct->modelname = xstrdup(machinename); + } + } + return 0; } diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h index bd7b64cc5..581602f70 100644 --- a/sys-utils/lscpu.h +++ b/sys-utils/lscpu.h @@ -46,6 +46,7 @@ UL_DEBUG_DECLARE_MASK(lscpu); #define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node" #define _PATH_SYS_DMI "/sys/firmware/dmi/tables/DMI" #define _PATH_ACPI_PPTT "/sys/firmware/acpi/tables/PPTT" +#define _PATH_SOC_MACHINENAME "/sys/bus/soc/devices/soc0/machine" struct lscpu_cache { int id; /* unique identifier */ -- 2.48.1