All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v6 07/10] smbios: Generate type 4 on non-x86 systems
Date: Fri, 19 Aug 2016 01:23:28 +0200	[thread overview]
Message-ID: <1471562611-93794-9-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1471562611-93794-1-git-send-email-agraf@suse.de>

The type 4 table generation code is very x86 centric today. Refactor things
out into the device model cpu class to allow the tables to get generated for
other architectures as well.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v3 -> v4:

  - Use device model

v4 -> v5:

  - s/get_info/get_vendor/ typo
  - s/smbios_write_type4_arch/smbios_write_type4_dm/

v5 -> v6:

  - Split cpu hunks into separate patches
---
 include/smbios.h |  3 +++
 lib/smbios.c     | 51 ++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/include/smbios.h b/include/smbios.h
index 5962d4c..3cbc687 100644
--- a/include/smbios.h
+++ b/include/smbios.h
@@ -139,6 +139,9 @@ struct __packed smbios_type3 {
 #define SMBIOS_PROCESSOR_STATUS_ENABLED	1
 #define SMBIOS_PROCESSOR_UPGRADE_NONE	6
 
+#define SMBIOS_PROCESSOR_FAMILY_OTHER	1
+#define SMBIOS_PROCESSOR_FAMILY_UNKNOWN	2
+
 struct __packed smbios_type4 {
 	u8 type;
 	u8 length;
diff --git a/lib/smbios.c b/lib/smbios.c
index 8dfd486..09a90ca 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -10,7 +10,11 @@
 #include <smbios.h>
 #include <tables_csum.h>
 #include <version.h>
-#include <asm/cpu.h>
+#ifdef CONFIG_CPU
+#include <cpu.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
+#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -152,26 +156,47 @@ static int smbios_write_type3(uintptr_t *current, int handle)
 	return len;
 }
 
+static void smbios_write_type4_dm(struct smbios_type4 *t)
+{
+	u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
+	const char *vendor = "Unknown";
+	const char *name = "Unknown";
+
+#ifdef CONFIG_CPU
+	char processor_name[49];
+	char vendor_name[49];
+	struct udevice *dev = NULL;
+
+	uclass_find_first_device(UCLASS_CPU, &dev);
+	if (dev) {
+		struct cpu_platdata *plat = dev_get_parent_platdata(dev);
+
+		if (plat->family)
+			processor_family = plat->family;
+		t->processor_id[0] = plat->id[0];
+		t->processor_id[1] = plat->id[1];
+
+		if (!cpu_get_vendor(dev, vendor_name, sizeof(vendor_name)))
+			vendor = vendor_name;
+		if (!cpu_get_desc(dev, processor_name, sizeof(processor_name)))
+			name = processor_name;
+	}
+#endif
+
+	t->processor_family = processor_family;
+	t->processor_manufacturer = smbios_add_string(t->eos, vendor);
+	t->processor_version = smbios_add_string(t->eos, name);
+}
+
 static int smbios_write_type4(uintptr_t *current, int handle)
 {
 	struct smbios_type4 *t = (struct smbios_type4 *)*current;
 	int len = sizeof(struct smbios_type4);
-	const char *vendor;
-	char *name;
-	char processor_name[CPU_MAX_NAME_LEN];
-	struct cpuid_result res;
 
 	memset(t, 0, sizeof(struct smbios_type4));
 	fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
 	t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL;
-	t->processor_family = gd->arch.x86;
-	vendor = cpu_vendor_name(gd->arch.x86_vendor);
-	t->processor_manufacturer = smbios_add_string(t->eos, vendor);
-	res = cpuid(1);
-	t->processor_id[0] = res.eax;
-	t->processor_id[1] = res.edx;
-	name = cpu_get_name(processor_name);
-	t->processor_version = smbios_add_string(t->eos, name);
+	smbios_write_type4_dm(t);
 	t->status = SMBIOS_PROCESSOR_STATUS_ENABLED;
 	t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE;
 	t->l1_cache_handle = 0xffff;
-- 
1.8.5.6

  parent reply	other threads:[~2016-08-18 23:23 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 23:23 [U-Boot] [PATCH v6 00/10] efi_loader: Expose SMBIOS table Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 01/10] x86: Move table csum into separate file Alexander Graf
2016-08-20 23:52   ` Simon Glass
2016-09-07  1:58   ` Bin Meng
2016-10-13 14:34   ` [U-Boot] [U-Boot, v6, " Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 01/10] x86: Move table csum into separate header Alexander Graf
2016-10-18  3:00   ` Bin Meng
2016-08-18 23:23 ` [U-Boot] [PATCH v6 02/10] x86: Move smbios generation into arch independent directory Alexander Graf
2016-08-20 23:52   ` Simon Glass
2016-10-13 14:35   ` [U-Boot] [U-Boot, v6, " Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 03/10] efi_loader: Expose efi_install_configuration_table Alexander Graf
2016-10-13 14:34   ` [U-Boot] [U-Boot, v6, " Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 04/10] smbios: Allow compilation on 64bit systems Alexander Graf
2016-10-13 14:34   ` [U-Boot] [U-Boot, v6, " Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 05/10] cpu: Add DMTF id and family fields Alexander Graf
2016-08-20 23:52   ` Simon Glass
2016-09-07  2:00   ` Bin Meng
2016-10-13 14:34   ` [U-Boot] [U-Boot,v6,05/10] " Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 06/10] cpu: Add get_vendor callback Alexander Graf
2016-08-20 23:52   ` Simon Glass
2016-09-07  2:02   ` Bin Meng
2016-10-13 14:35   ` [U-Boot] [U-Boot,v6,06/10] " Alexander Graf
2016-08-18 23:23 ` Alexander Graf [this message]
2016-08-20 23:52   ` [U-Boot] [PATCH v6 07/10] smbios: Generate type 4 on non-x86 systems Simon Glass
2016-09-07  2:04   ` Bin Meng
2016-10-13 14:35   ` [U-Boot] [U-Boot, v6, " Alexander Graf
2016-10-14  1:50     ` Bin Meng
2016-10-14  5:13       ` Alexander Graf
2016-10-14  5:21         ` Bin Meng
2016-10-14  7:03           ` Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 08/10] smbios: Expose in efi_loader as table Alexander Graf
2016-08-20 23:52   ` Simon Glass
2016-10-13 14:34   ` [U-Boot] [U-Boot, v6, " Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 09/10] efi_loader: Fix efi_install_configuration_table Alexander Graf
2016-10-13 14:34   ` [U-Boot] [U-Boot, v6, " Alexander Graf
2016-08-18 23:23 ` [U-Boot] [PATCH v6 10/10] smbios: Provide serial number Alexander Graf
2016-10-13 14:34   ` [U-Boot] [U-Boot,v6,10/10] " Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471562611-93794-9-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.