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