cdown / rpms / util-linux

Forked from rpms/util-linux 2 years ago
Clone

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

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