All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v2 12/12] smbios: Allow a few values to come from sysinfo
Date: Wed, 20 Jan 2021 19:06:42 -0700	[thread overview]
Message-ID: <20210121020642.551093-5-sjg@chromium.org> (raw)
In-Reply-To: <20210121020642.551093-1-sjg@chromium.org>

While static configuration is useful it cannot cover every case. Sometimes
board revisions are encoded in resistor straps and must be read at
runtime.

The easiest way to provide this information is via sysinfo, since the
board can then provide a driver to read whatever is needed.

Add some standard sysinfo options for this, and use them to obtain the
required information.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 include/sysinfo.h | 11 +++++++++++
 lib/smbios.c      | 32 +++++++++++++++++++++++++++++---
 2 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/include/sysinfo.h b/include/sysinfo.h
index 6e021253524..743f3554659 100644
--- a/include/sysinfo.h
+++ b/include/sysinfo.h
@@ -31,6 +31,17 @@
  * to read the serial number.
  */
 
+/** enum sysinfo_id - Standard IDs defined by U-Boot */
+enum sysinfo_id {
+	SYSINFO_ID_NONE,
+
+	SYSINFO_ID_SMBIOS_SYSTEM_VERSION,
+	SYSINFO_ID_SMBIOS_BASEBOARD_VERSION,
+
+	/* First value available for downstream/board used */
+	SYSINFO_ID_USER = 0x1000,
+};
+
 struct sysinfo_ops {
 	/**
 	 * detect() - Run the hardware info detection procedure for this
diff --git a/lib/smbios.c b/lib/smbios.c
index d46569b09f4..9bdde0b953f 100644
--- a/lib/smbios.c
+++ b/lib/smbios.c
@@ -10,6 +10,7 @@
 #include <env.h>
 #include <mapmem.h>
 #include <smbios.h>
+#include <sysinfo.h>
 #include <tables_csum.h>
 #include <version.h>
 #ifdef CONFIG_CPU
@@ -106,15 +107,26 @@ static int smbios_add_string(struct smbios_ctx *ctx, const char *str)
 }
 
 /**
- * smbios_add_prop() - Add a property from the device tree
+ * smbios_add_prop_si() - Add a property from the devicetree or sysinfo
+ *
+ * Sysinfo is used if available, with a fallback to devicetree
  *
  * @start:	string area start address
  * @node:	node containing the information to write (ofnode_null() if none)
  * @prop:	property to write
  * @return 0 if not found, else SMBIOS string number (1 or more)
  */
-static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)
+static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop,
+			      int sysinfo_id)
 {
+	if (sysinfo_id && ctx->dev) {
+		char val[80];
+		int ret;
+
+		ret = sysinfo_get_str(ctx->dev, sysinfo_id, sizeof(val), val);
+		if (!ret)
+			return smbios_add_string(ctx, val);
+	}
 	if (IS_ENABLED(CONFIG_OF_CONTROL)) {
 		const char *str;
 
@@ -126,6 +138,17 @@ static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)
 	return 0;
 }
 
+/**
+ * smbios_add_prop() - Add a property from the devicetree
+ *
+ * @prop:	property to write
+ * @return 0 if not found, else SMBIOS string number (1 or more)
+ */
+static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop)
+{
+	return smbios_add_prop_si(ctx, prop, SYSINFO_ID_NONE);
+}
+
 static void set_eos(struct smbios_ctx *ctx, char *eos)
 {
 	ctx->eos = eos;
@@ -239,7 +262,8 @@ static int smbios_write_type1(ulong *current, int handle,
 	set_eos(ctx, t->eos);
 	t->manufacturer = smbios_add_prop(ctx, "manufacturer");
 	t->product_name = smbios_add_prop(ctx, "product");
-	t->version = smbios_add_prop(ctx, "version");
+	t->version = smbios_add_prop_si(ctx, "version",
+					SYSINFO_ID_SMBIOS_SYSTEM_VERSION);
 	if (serial_str) {
 		t->serial_number = smbios_add_string(ctx, serial_str);
 		strncpy((char *)t->uuid, serial_str, sizeof(t->uuid));
@@ -268,6 +292,8 @@ static int smbios_write_type2(ulong *current, int handle,
 	set_eos(ctx, t->eos);
 	t->manufacturer = smbios_add_prop(ctx, "manufacturer");
 	t->product_name = smbios_add_prop(ctx, "product");
+	t->version = smbios_add_prop_si(ctx, "version",
+					SYSINFO_ID_SMBIOS_BASEBOARD_VERSION);
 	t->asset_tag_number = smbios_add_prop(ctx, "asset-tag");
 	t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING;
 	t->board_type = SMBIOS_BOARD_MOTHERBOARD;
-- 
2.30.0.296.g2bfb1c46d8-goog

  parent reply	other threads:[~2021-01-21  2:06 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-21  2:06 [PATCH v2 00/12] smbios: Enhancements for more flexibility Simon Glass
2021-01-21  2:06 ` [PATCH v2 01/12] README: Add doumentation for version information Simon Glass
2021-01-21  5:52   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 02/12] Makefile: Provide numeric versions Simon Glass
2021-01-21  5:54   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 03/12] smbios: Move smbios_write_type to the C file Simon Glass
2021-01-21  5:55   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 04/12] smbios: Use char consistently for the eos member Simon Glass
2021-01-21  5:56   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 05/12] smbios: Set BIOS release version Simon Glass
2021-01-21  6:37   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 06/12] smbios: Use a struct to keep track of context Simon Glass
2021-01-21  6:37   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 07/12] smbios: Drop the eos parameter Simon Glass
2021-01-21  6:37   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 08/12] smbios: Track the end of the string table Simon Glass
2021-01-21  6:37   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 09/12] smbios: Add more options for the BIOS version string Simon Glass
2021-01-21  6:54   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 10/12] sysinfo: Move #ifdef so that operations are always defined Simon Glass
2021-01-21  6:54   ` Bin Meng
2021-01-21  2:06 ` [PATCH v2 11/12] x86: coral: Add sysinfo ops Simon Glass
2021-01-21  6:54   ` Bin Meng
2021-01-21 17:32     ` Simon Glass
2021-01-21  2:06 ` Simon Glass [this message]
2021-01-21  6:54   ` [PATCH v2 12/12] smbios: Allow a few values to come from sysinfo Bin Meng
2021-01-21 17:32     ` Simon Glass

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=20210121020642.551093-5-sjg@chromium.org \
    --to=sjg@chromium.org \
    --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.