Blame SOURCES/0055-lscpu-arm-read-vendor-and-model-from-BIOS.patch

439b44
From 7089a63d03b35743de533686906c451b917d0909 Mon Sep 17 00:00:00 2001
439b44
From: Karel Zak <kzak@redhat.com>
439b44
Date: Wed, 16 Dec 2020 13:08:51 +0100
439b44
Subject: [PATCH 55/56] lscpu: (arm) read vendor and model from BIOS
439b44
439b44
This patch backports the current upstream code to read CPU vendor and
439b44
model name from BIOS.
439b44
439b44
Upstream: http://github.com/karelzak/util-linux/commit/8014104bea78f6f82cb82e16329b562e60ecdc87
439b44
Upstream: http://github.com/karelzak/util-linux/commit/367c85c472869b75eaf770d4be0b360e30710b95
439b44
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1883056
439b44
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1882740
439b44
Signed-off-by: Karel Zak <kzak@redhat.com>
439b44
---
439b44
 sys-utils/lscpu-dmi.c | 44 +++++++++++++++++++++++++++++++++++++++++++
439b44
 sys-utils/lscpu.c     |  7 +++++++
439b44
 sys-utils/lscpu.h     |  3 +++
439b44
 3 files changed, 54 insertions(+)
439b44
439b44
diff --git a/sys-utils/lscpu-dmi.c b/sys-utils/lscpu-dmi.c
439b44
index 31127f48a..3bdd7dcb2 100644
439b44
--- a/sys-utils/lscpu-dmi.c
439b44
+++ b/sys-utils/lscpu-dmi.c
439b44
@@ -28,6 +28,7 @@
439b44
 #include <stdio.h>
439b44
 
439b44
 #include "lscpu.h"
439b44
+#include "all-io.h"
439b44
 
439b44
 #define _PATH_SYS_DMI	 "/sys/firmware/dmi/tables/DMI"
439b44
 
439b44
@@ -353,3 +354,46 @@ int get_number_of_physical_sockets_from_dmi(void)
439b44
 	else
439b44
 		return di.sockets;
439b44
 }
439b44
+
439b44
+
439b44
+#define _PATH_SYS_DMI_TYPE4   "/sys/firmware/dmi/entries/4-0/raw"
439b44
+#define PROC_MFR_OFFSET		0x07
439b44
+#define PROC_VERSION_OFFSET	0x10
439b44
+
439b44
+/*
439b44
+ * Use firmware to get human readable names
439b44
+ */
439b44
+int arm_smbios_decode(struct lscpu_desc *desc)
439b44
+{
439b44
+	uint8_t data[8192];
439b44
+	char buf[128], *str;
439b44
+	struct dmi_header h;
439b44
+	int fd;
439b44
+	ssize_t rs;
439b44
+
439b44
+	fd = open(_PATH_SYS_DMI_TYPE4, O_RDONLY);
439b44
+	if (fd < 0)
439b44
+		return fd;
439b44
+
439b44
+	rs = read_all(fd, (char *) data, 8192);
439b44
+	close(fd);
439b44
+
439b44
+	if (rs == -1)
439b44
+		return -1;
439b44
+
439b44
+	to_dmi_header(&h, data);
439b44
+
439b44
+	str = dmi_string(&h, data[PROC_MFR_OFFSET]);
439b44
+	if (str) {
439b44
+		xstrncpy(buf, str, 127);
439b44
+		desc->bios_vendor = xstrdup(buf);
439b44
+	}
439b44
+
439b44
+	str = dmi_string(&h, data[PROC_VERSION_OFFSET]);
439b44
+	if (str) {
439b44
+		xstrncpy(buf, str, 127);
439b44
+		desc->bios_modelname = xstrdup(buf);
439b44
+	}
439b44
+
439b44
+	return 0;
439b44
+}
439b44
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
439b44
index dc6dc97c3..70a797dd6 100644
439b44
--- a/sys-utils/lscpu.c
439b44
+++ b/sys-utils/lscpu.c
439b44
@@ -1868,6 +1868,8 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
439b44
 		add_summary_n(tb, _("NUMA node(s):"), desc->nnodes);
439b44
 	if (desc->vendor)
439b44
 		add_summary_s(tb, _("Vendor ID:"), desc->vendor);
439b44
+	if (desc->bios_vendor)
439b44
+		add_summary_s(tb, _("BIOS Vendor ID:"), desc->bios_vendor);
439b44
 	if (desc->machinetype)
439b44
 		add_summary_s(tb, _("Machine type:"), desc->machinetype);
439b44
 	if (desc->family)
439b44
@@ -1876,6 +1878,8 @@ print_summary(struct lscpu_desc *desc, struct lscpu_modifier *mod)
439b44
 		add_summary_s(tb, _("Model:"), desc->revision ? desc->revision : desc->model);
439b44
 	if (desc->modelname || desc->cpu)
439b44
 		add_summary_s(tb, _("Model name:"), desc->cpu ? desc->cpu : desc->modelname);
439b44
+	if (desc->bios_modelname)
439b44
+		add_summary_s(tb, _("BIOS Model name:"), desc->bios_modelname);
439b44
 	if (desc->stepping)
439b44
 		add_summary_s(tb, _("Stepping:"), desc->stepping);
439b44
 	if (desc->mhz)
439b44
@@ -2109,6 +2113,9 @@ int main(int argc, char *argv[])
439b44
 
439b44
 	read_nodes(desc);
439b44
 	read_hypervisor(desc, mod);
439b44
+
439b44
+	if (mod->system == SYSTEM_LIVE)
439b44
+		arm_smbios_decode(desc);
439b44
 	arm_cpu_decode(desc);
439b44
 
439b44
 
439b44
diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
439b44
index 1aef8202d..802719eeb 100644
439b44
--- a/sys-utils/lscpu.h
439b44
+++ b/sys-utils/lscpu.h
439b44
@@ -79,10 +79,12 @@ struct polarization_modes {
439b44
 struct lscpu_desc {
439b44
 	char	*arch;
439b44
 	char	*vendor;
439b44
+	char	*bios_vendor;	/* aarch64 */
439b44
 	char	*machinetype;	/* s390 */
439b44
 	char	*family;
439b44
 	char	*model;
439b44
 	char	*modelname;
439b44
+	char	*bios_modelname; /* aarch64 */
439b44
 	char	*revision;  /* alternative for model (ppc) */
439b44
 	char	*cpu;       /* alternative for modelname (ppc, sparc) */
439b44
 	char	*virtflag;	/* virtualization flag (vmx, svm) */
439b44
@@ -187,5 +189,6 @@ struct lscpu_modifier {
439b44
 extern int read_hypervisor_dmi(void);
439b44
 extern int get_number_of_physical_sockets_from_dmi(void);
439b44
 extern void arm_cpu_decode(struct lscpu_desc *desc);
439b44
+extern int arm_smbios_decode(struct lscpu_desc *desc);
439b44
 
439b44
 #endif /* LSCPU_H */
439b44
-- 
439b44
2.29.2
439b44