public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] lscpu-arm: Allow externally sourced model name.
@ 2025-07-11 21:16 Paul Benoit
  2025-07-11 21:16 ` [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part Paul Benoit
                   ` (2 more replies)
  0 siblings, 3 replies; 13+ messages in thread
From: Paul Benoit @ 2025-07-11 21:16 UTC (permalink / raw)
  To: util-linux; +Cc: Paul Benoit

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@os.amperecomputing.com>
---
 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


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-02-11 21:23 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-11 21:16 [PATCH 1/2] lscpu-arm: Allow externally sourced model name Paul Benoit
2025-07-11 21:16 ` [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part Paul Benoit
2025-07-14 12:16   ` Karel Zak
2025-07-14 20:48     ` Jeremy Linton
2025-07-14 22:22       ` Paul Benoit
2025-07-15  9:19       ` Karel Zak
2025-11-07 21:26         ` Paul Benoit
2025-11-07 20:48       ` Paul Benoit
2026-02-11 21:23         ` [PATCH v2 1/2] lscpu-arm: Include the ARM SMC CC SOC_ID name Paul Benoit
2026-02-11 21:23         ` [PATCH v2 2/2] lscpu-arm: Correct Ampere part name strings Paul Benoit
2025-07-11 22:22 ` [PATCH 1/2] lscpu-arm: Allow externally sourced model name Jeremy Linton
2025-11-07 21:45   ` Paul Benoit
2025-07-14 12:11 ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox