Skip to contentSkip to conversation

Implement all missing SMBIOS types required by distro tooling

PATCH In review Raymond Mao 3 participants 10 messages Feb 13 – Feb 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v6 cover Implement all missing SMBIOS types required by distro tooling

From: Raymond Mao <[email protected]>

This series finish the last missing puzzle of required SMBIOS types by:
1) Fixing duplicated handles when multiple instances exist in one type;
2) Implementing the rest of required types 9/16/17/19;
3) Adding version control when printing properties for all types.

Type 9/16/17/19 are generally DT-based, the idea is to write these tables using a hybrid approach:
Explicit DT definitions under existing '/smbios/smbios' take precedence, with fallback to scan and interpret values from the entire DT.

Moreover, all below APIs:
smbios_get_val_si()
smbios_get_u64_si()
smbios_add_prop_si()
are on top of sysinfo, thus allow vendors to get values from other subsystems by implementing their own sysinfo driver if needed.

Raymond Mao (6):
smbios: Fix duplicated smbios handles
smbios: add support for dynamic generation of Type 9 system slot
tables
smbios: add support for dynamic generation of Type 16 table
smbios: add support for dynamic generation of Type 17 table
smbios: add support for dynamic generation of Type 19 table
smbios: print the properties only when they exist in a specified
version of spec

 arch/arm/dts/smbios_generic.dtsi |   12 +
 cmd/smbios.c                     |  365 +++++++++-
 drivers/sysinfo/smbios.c         |    5 +
 include/smbios.h                 |  151 ++++
 include/smbios_def.h             |  250 +++++++
 include/sysinfo.h                |    4 +
 lib/smbios.c                     | 1151 +++++++++++++++++++++++++++++-
 7 files changed, 1905 insertions(+), 33 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH v6 1/6 smbios: Fix duplicated smbios handles

Some smbios types can have multiple instances (e.g. Type 7, 9, 16, 17, 19), thus the 'handle' argument should be a pointer so that the value can be accumulated when writing all the instances.
This also fix the observed duplicated Type 7 handles.

Fixes bcf456dd369e ("smbios: add detailed smbios information")

---
Changes in v3:
- Initial patch.
Changes in v4:
- None.
Changes in v5:
- None.
Changes in v6:
- None.

 lib/smbios.c | 42 +++++++++++++++++++++++-------------------
 1 file changed, 23 insertions(+), 19 deletions(-)
lib/smbios.c +23 -19
index b8c2846277a..85508c06547 100644
@@ -103,7 +103,7 @@ struct smbios_ctx {
  * @ctx:	context for writing the tables
  * Return:	size of the structure
  */
-typedef int (*smbios_write_type)(ulong *addr, int handle,
+typedef int (*smbios_write_type)(ulong *addr, int *handle,
 				 struct smbios_ctx *ctx);
 
 /**
@@ -364,7 +364,7 @@ static int smbios_string_table_len(const struct smbios_ctx *ctx)
 	return (ctx->next_ptr + 1) - ctx->eos;
 }
 
-static int smbios_write_type0(ulong *current, int handle,
+static int smbios_write_type0(ulong *current, int *handle,
 			      struct smbios_ctx *ctx)
 {
 	struct smbios_type0 *t;
@@ -372,7 +372,7 @@ static int smbios_write_type0(ulong *current, int handle,
 
 	t = map_sysmem(*current, len);
 	memset(t, 0, len);
-	fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle);
+	fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, *handle);
 	smbios_set_eos(ctx, t->eos);
 	t->vendor = smbios_add_prop_si(ctx, NULL, SYSID_SM_BIOS_VENDOR,
 				       "U-Boot");
@@ -423,7 +423,7 @@ static int smbios_write_type0(ulong *current, int handle,
 	return len;
 }
 
-static int smbios_write_type1(ulong *current, int handle,
+static int smbios_write_type1(ulong *current, int *handle,
 			      struct smbios_ctx *ctx)
 {
 	struct smbios_type1 *t;
@@ -434,7 +434,7 @@ static int smbios_write_type1(ulong *current, int handle,
 
 	t = map_sysmem(*current, len);
 	memset(t, 0, len);
-	fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
+	fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, *handle);
 	smbios_set_eos(ctx, t->eos);
 
 	t->manufacturer = smbios_add_prop_si(ctx, "manufacturer",
@@ -471,7 +471,7 @@ static int smbios_write_type1(ulong *current, int handle,
 	return len;
 }
 
-static int smbios_write_type2(ulong *current, int handle,
+static int smbios_write_type2(ulong *current, int *handle,
 			      struct smbios_ctx *ctx)
 {
 	struct smbios_type2 *t;
@@ -485,7 +485,7 @@ static int smbios_write_type2(ulong *current, int handle,
 	 */
 	t = map_sysmem(*current, len);
 	memset(t, 0, len);
-	fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
+	fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, *handle);
 
 	/* eos is at the end of the structure */
 	eos_addr = (u8 *)t + len - sizeof(t->eos);
@@ -519,7 +519,7 @@ static int smbios_write_type2(ulong *current, int handle,
 	 * t->number_contained_objects = <obj_handle_num>;
 	 */
 
-	t->chassis_handle = handle + 1;
+	t->chassis_handle = *handle + 1;
 
 	len = t->hdr.length + smbios_string_table_len(ctx);
 	*current += len;
@@ -528,7 +528,7 @@ static int smbios_write_type2(ulong *current, int handle,
 	return len;
 }
 
-static int smbios_write_type3(ulong *current, int handle,
+static int smbios_write_type3(ulong *current, int *handle,
 			      struct smbios_ctx *ctx)
 {
 	struct smbios_type3 *t;
@@ -548,7 +548,7 @@ static int smbios_write_type3(ulong *current, int handle,
 
 	t = map_sysmem(*current, len);
 	memset(t, 0, len);
-	fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
+	fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, *handle);
 #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE)
 	elem_addr = (u8 *)t + offsetof(struct smbios_type3, sku_number);
 	sku_num_addr = elem_addr + elem_size;
@@ -669,7 +669,7 @@ static void smbios_write_type4_dm(struct smbios_type4 *t,
 #endif
 }
 
-static int smbios_write_type4(ulong *current, int handle,
+static int smbios_write_type4(ulong *current, int *handle,
 			      struct smbios_ctx *ctx)
 {
 	struct smbios_type4 *t;
@@ -679,7 +679,7 @@ static int smbios_write_type4(ulong *current, int handle,
 
 	t = map_sysmem(*current, len);
 	memset(t, 0, len);
-	fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
+	fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, *handle);
 	smbios_set_eos(ctx, t->eos);
 	t->socket_design = smbios_add_prop_si(ctx, "socket-design",
 					      SYSID_SM_PROCESSOR_SOCKET, NULL);
@@ -828,13 +828,14 @@ static int smbios_write_type7_1level(ulong *current, int handle,
 	return len;
 }
 
-static int smbios_write_type7(ulong *current, int handle,
+static int smbios_write_type7(ulong *current, int *handle,
 			      struct smbios_ctx *ctx)
 {
 	int len = 0;
 	int i, level;
 	ofnode parent = ctx->node;
 	struct smbios_ctx ctx_bak;
+	int hdl_base = *handle;
 
 	memcpy(&ctx_bak, ctx, sizeof(ctx_bak));
 
@@ -850,15 +851,17 @@ static int smbios_write_type7(ulong *current, int handle,
 			return 0;
 		ctx->subnode_name = buf;
 		ctx->node = ofnode_find_subnode(parent, ctx->subnode_name);
-		len += smbios_write_type7_1level(current, handle++, ctx, i);
+		*handle = hdl_base + i;
+		len += smbios_write_type7_1level(current, *handle, ctx, i);
 		memcpy(ctx, &ctx_bak, sizeof(*ctx));
 	}
+
 	return len;
 }
 
 #endif /* #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE) */
 
-static int smbios_write_type32(ulong *current, int handle,
+static int smbios_write_type32(ulong *current, int *handle,
 			       struct smbios_ctx *ctx)
 {
 	struct smbios_type32 *t;
@@ -866,7 +869,7 @@ static int smbios_write_type32(ulong *current, int handle,
 
 	t = map_sysmem(*current, len);
 	memset(t, 0, len);
-	fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle);
+	fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, *handle);
 	smbios_set_eos(ctx, t->eos);
 
 	*current += len;
@@ -875,7 +878,7 @@ static int smbios_write_type32(ulong *current, int handle,
 	return len;
 }
 
-static int smbios_write_type127(ulong *current, int handle,
+static int smbios_write_type127(ulong *current, int *handle,
 				struct smbios_ctx *ctx)
 {
 	struct smbios_type127 *t;
@@ -883,7 +886,7 @@ static int smbios_write_type127(ulong *current, int handle,
 
 	t = map_sysmem(*current, len);
 	memset(t, 0, len);
-	fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle);
+	fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, *handle);
 
 	*current += len;
 	unmap_sysmem(t);
@@ -954,7 +957,8 @@ ulong write_smbios_table(ulong addr)
 				ctx.node = ofnode_find_subnode(parent_node,
 							       method->subnode_name);
 		}
-		len += method->write((ulong *)&addr, handle++, &ctx);
+		len += method->write((ulong *)&addr, &handle, &ctx);
+		handle++;
 	}
 
 	/*
Signature · 1 line
2.25.1
#2 lore raw

PATCH v6 2/6 smbios: add support for dynamic generation of Type 9 system slot tables

In reply to Raymond Mao

This commit introduces support for generating SMBIOS Type 9 (System Slot) tables using a hybrid approach:

1. Explicit Device Tree definitions:
Child node under '/smbios/smbios/system-slot' will be interpreted as individual slot definitions.
- Each child represents a slot (e.g., isa, pcmcia, etc.).
- Properties follow the SMBIOS specification using lowercase hyphen-separated names such as 'slot-type', 'slot-id', 'segment-group-number', 'bus-number', 'slot-information', etc.
- This approach allows full customization of each system slot and is especially suitable for platforms with well-defined slot topology.

2. Automatic detection fallback:
If child node under '/smbios/smbios/system-slot' does not exist, the implementation will scan the entire device tree for nodes whose 'device_type' matches known slot-related types ("pci", "isa", "pcmcia", etc.).
- When a match is found, default values or heuristics are applied to populate to the System Slot table.
- This mode is useful for platforms that lack explicit SMBIOS nodes but still expose slot topology via standard DT conventions.

Together, two approaches ensure that SMBIOS Type 9 entries are available whether explicitly described or automatically derived.

---
Changes in v2:
- Reuse sysinfo_to_dt and convert_sysinfo_to_dt() for mapping SMBIOS properties to DT. Changes in v3:
- Update subject and commit message.
- Abstract helper functions and add callback for writing subnodes. Changes in v4:
- Refine the commit message.
Changes in v5:
- None.
Changes in v6:
- None.

 arch/arm/dts/smbios_generic.dtsi |   3 +
 cmd/smbios.c                     | 114 ++++++++++++
 include/smbios.h                 |  45 +++++
 include/smbios_def.h             |  89 +++++++++
 lib/smbios.c                     | 301 ++++++++++++++++++++++++++++++-
 5 files changed, 549 insertions(+), 3 deletions(-)
arch/arm/dts/smbios_generic.dtsi +3 -0
index fc168317c9e..4463dade217 100644
@@ -77,6 +77,9 @@
 						   SMBIOS_CACHE_OP_WB)>;
 				};
 			};
+
+			system-slot {
+			};
 		};
 	};
 };
cmd/smbios.c +114 -0

132 lines not on this page · raw message

include/smbios.h +45 -0

51 lines not on this page · raw message

include/smbios_def.h +89 -0

93 lines not on this page · raw message

lib/smbios.c +298 -3

339 lines not on this page · raw message

Signature · 1 line
2.25.1
#3 lore raw

PATCH v6 3/6 smbios: add support for dynamic generation of Type 16 table

In reply to Raymond Mao

This commit implements SMBIOS Type 16 (Physical Memory Array) generation with a hybrid approach supporting both:

1. Explicit definition via Device Tree 'smbios' node:
Child node under '/smbios/smbios/memory-array' will be used to populate as individual Type 16 structure directly.
- Properties follow SMBIOS field names with lowercase letters and hyphen-separated words (e.g., 'memory-error-correction', 'maximum-capacity', 'extended-maximum-capacity', etc.).
- This method supports precise platform-defined overrides and system descriptions.

2. Fallback to automatic DT-based discovery:
If child node under '/smbios/smbios/memory-array' does not exist, the implementation will:
- Scan all top-level 'memory@' nodes to populate Type 16 structure with inferred size and location data.
- Scan nodes named or marked as 'memory-controller' and parse associated 'dimm@' subnodes (if present) to extract DIMM sizes and map them accordingly.

This dual-mode support enables flexible firmware SMBIOS reporting while aligning with spec-compliant naming and runtime-detected memory topology.

Type 16 support is under GENERATE_SMBIOS_TABLE_VERBOSE to avoid increasing rom size for those platforms which only require basic SMBIOS support.

---
Changes in v4:
- Initial patch.
Changes in v5:
- None.
Changes in v6:
- None.

 arch/arm/dts/smbios_generic.dtsi |   3 +
 cmd/smbios.c                     |  46 +++++
 drivers/sysinfo/smbios.c         |   5 +
 include/smbios.h                 |  18 ++
 include/smbios_def.h             |  29 ++++
 include/sysinfo.h                |   4 +
 lib/smbios.c                     | 282 +++++++++++++++++++++++++++++++
 7 files changed, 387 insertions(+)
arch/arm/dts/smbios_generic.dtsi +3 -0
index 4463dade217..1a9adfaa409 100644
@@ -80,6 +80,9 @@
 
 			system-slot {
 			};
+
+			memory-array {
+			};
 		};
 	};
 };
cmd/smbios.c +46 -0

64 lines not on this page · raw message

drivers/sysinfo/smbios.c +5 -0
index 99104274f72..ff5873c940e 100644
@@ -24,6 +24,7 @@ struct sysinfo_plat_priv {
 	struct smbios_type7 t7[SYSINFO_CACHE_LVL_MAX];
 	u16 cache_handles[SYSINFO_CACHE_LVL_MAX];
 	u8 cache_level;
+	u16 marray_handles[SYSINFO_MEM_HANDLE_MAX];
 };
 
 static void smbios_cache_info_dump(struct smbios_type7 *cache_info)
@@ -165,6 +166,10 @@ static int sysinfo_plat_get_data(struct udevice *dev, int id, void **buf,
 		*buf = &priv->cache_handles[0];
 		*size = sizeof(priv->cache_handles);
 		break;
+	case SYSID_SM_MEMARRAY_HANDLE:
+		*buf = &priv->marray_handles[0];
+		*size = sizeof(priv->marray_handles);
+		break;
 	default:
 		return -EOPNOTSUPP;
 	}
include/smbios.h +18 -0
index 752a25250d3..293d6795cf3 100644
@@ -309,6 +309,24 @@ struct __packed smbios_type9 {
 	char eos[SMBIOS_STRUCT_EOS_BYTES];
 };
 
+enum {
+	SMBIOS_MEM_NONE = 0,
+	SMBIOS_MEM_CUSTOM = 1,
+	SMBIOS_MEM_FDT_MEM_NODE = 2,
+	SMBIOS_MEM_FDT_MEMCON_NODE = 3
+};
+
+struct __packed smbios_type16 {
+	struct smbios_header hdr;
+	u8 location;
+	u8 use;
+	u8 mem_err_corr;
+	u32 max_cap;
+	u16 mem_err_info_hdl;
+	u16 num_of_mem_dev;
+	u64 ext_max_cap;
+	char eos[SMBIOS_STRUCT_EOS_BYTES];
+};
 struct __packed smbios_type32 {
 	u8 type;
 	u8 length;
include/smbios_def.h +29 -0
index ef9cb02ed25..c6850a5d6f5 100644
@@ -280,4 +280,33 @@
 /* Slot segment group number */
 #define SMBIOS_SYSSLOT_SGGNUM_UND	0
 
+/* Physical Memory Array */
+
+/* Location */
+#define SMBIOS_MA_LOCATION_OTHER	1
+#define SMBIOS_MA_LOCATION_UNKNOWN	2
+#define SMBIOS_MA_LOCATION_MOTHERBOARD	3
+
+/* Use */
+#define SMBIOS_MA_USE_OTHER		1
+#define SMBIOS_MA_USE_UNKNOWN		2
+#define SMBIOS_MA_USE_SYSTEM		3
+#define SMBIOS_MA_USE_VIDEO		4
+#define SMBIOS_MA_USE_FLASH		5
+#define SMBIOS_MA_USE_NVRAM		6
+#define SMBIOS_MA_USE_CACHE		7
+
+/* Error Correction Type */
+#define SMBIOS_MA_ERRCORR_OTHER		1
+#define SMBIOS_MA_ERRCORR_UNKNOWN	2
+#define SMBIOS_MA_ERRCORR_NONE		3
+#define SMBIOS_MA_ERRCORR_PARITY	4
+#define SMBIOS_MA_ERRCORR_SBITECC	5
+#define SMBIOS_MA_ERRCORR_MBITECC	6
+#define SMBIOS_MA_ERRCORR_CRC		7
+
+/* Error Information Handle */
+#define SMBIOS_MA_ERRINFO_NONE		0xFFFE
+#define SMBIOS_MA_ERRINFO_NOERR		0xFFFF
+
 #endif /* _SMBIOS_DEF_H_ */
include/sysinfo.h +4 -0
index e87cf969fcd..54eb64a204a 100644
@@ -12,6 +12,7 @@
 struct udevice;
 
 #define SYSINFO_CACHE_LVL_MAX 3
+#define SYSINFO_MEM_HANDLE_MAX 8
 
 /*
  * This uclass encapsulates hardware methods to gather information about a
@@ -149,6 +150,9 @@ enum sysinfo_id {
 	SYSID_SM_CACHE_INFO_END =
 		SYSID_SM_CACHE_INST_SIZE2 + SYSINFO_CACHE_LVL_MAX - 1,
 
+	/* Memory Array (Type 16) */
+	SYSID_SM_MEMARRAY_HANDLE,
+
 	/* For show_board_info() */
 	SYSID_BOARD_MODEL,
 	SYSID_BOARD_MANUFACTURER,
lib/smbios.c +282 -0

300 lines not on this page · raw message

Signature · 1 line
2.25.1
#4 lore raw

PATCH v6 4/6 smbios: add support for dynamic generation of Type 17 table

In reply to Raymond Mao

This commit implements SMBIOS Type 17 (Memory Device) generation with a hybrid approach supporting both:

1. Explicit definition via Device Tree 'smbios' node:
Child node under '/smbios/smbios/memory-device' will be used to populate as individual Type 17 structure directly.
- Properties follow SMBIOS field names with lowercase letters and hyphen-separated words (e.g., 'physical-memory-array-handle', ' memory-error-information-handle', 'configured-memory-speed', etc.).
- This method supports precise platform-defined overrides and system descriptions.

2. Fallback to automatic DT-based discovery:
If child node under '/smbios/smbios/memory-device' does not exist, the implementation will:
- Scan all top-level 'memory@' nodes to populate Type 17 structure with inferred size and location data.
- Scan nodes named or marked as 'memory-controller' and parse associated 'dimm@' subnodes (if present) to extract DIMM sizes and map them accordingly.

This dual-mode support enables flexible firmware SMBIOS reporting while aligning with spec-compliant naming and runtime-detected memory topology.

Type 17 support is under GENERATE_SMBIOS_TABLE_VERBOSE to avoid increasing rom size for those platforms which only require basic SMBIOS support.

---
Changes in v4:
- Initial patch.
Changes in v5:
- None.
Changes in v6:
- Fixed mis-aligned type17 structure.
- Remove a duplicated line of setting type17 data width.

 arch/arm/dts/smbios_generic.dtsi |   3 +
 cmd/smbios.c                     | 126 +++++++++++
 include/smbios.h                 |  45 ++++
 include/smbios_def.h             | 127 +++++++++++
 lib/smbios.c                     | 376 +++++++++++++++++++++++++++++++
 5 files changed, 677 insertions(+)
arch/arm/dts/smbios_generic.dtsi +3 -0
index 1a9adfaa409..fd2df8d02e0 100644
@@ -83,6 +83,9 @@
 
 			memory-array {
 			};
+
+			memory-device {
+			};
 		};
 	};
 };
cmd/smbios.c +126 -0

144 lines not on this page · raw message

include/smbios.h +45 -0

51 lines not on this page · raw message

include/smbios_def.h +127 -0

131 lines not on this page · raw message

lib/smbios.c +376 -0

394 lines not on this page · raw message

Signature · 1 line
2.25.1
#5 lore raw

PATCH v6 5/6 smbios: add support for dynamic generation of Type 19 table

In reply to Raymond Mao

This commit implements SMBIOS Type 19 (Memory Array Mapped Address) generation with a hybrid approach supporting both:

1. Explicit definition via Device Tree 'smbios' node:
Child node under '/smbios/smbios/memory-array-mapped-address' will be used to populate as individual Type 19 structure directly.
- Properties follow SMBIOS field names with lowercase letters and hyphen-separated words (e.g., 'starting-address', 'ending-address', 'partition-width', etc.).
- This method supports precise platform-defined overrides and system descriptions.

2. Fallback to automatic DT-based discovery:
If child node under '/smbios/smbios/memory-array-mapped-address' does not exist, the implementation will:
- Scan all top-level 'memory@' nodes to populate Type 19 structure with inferred size and location data.
- Scan nodes named or marked as 'memory-controller' and parse associated 'dimm@' subnodes (if present) to extract DIMM sizes and map them accordingly.

This dual-mode support enables flexible firmware SMBIOS reporting while aligning with spec-compliant naming and runtime-detected memory topology.

Type 19 support is under GENERATE_SMBIOS_TABLE_VERBOSE to avoid increasing rom size for those platforms which only require basic SMBIOS support.

---
Changes in v4:
- Initial patch.
Changes in v5:
- None.
Changes in v6:
- None.

 arch/arm/dts/smbios_generic.dtsi |   3 +
 cmd/smbios.c                     |  14 +++
 include/smbios.h                 |  11 +++
 include/smbios_def.h             |   5 ++
 lib/smbios.c                     | 150 +++++++++++++++++++++++++++++++
 5 files changed, 183 insertions(+)
arch/arm/dts/smbios_generic.dtsi +3 -0
index fd2df8d02e0..fe16037fc20 100644
@@ -86,6 +86,9 @@
 
 			memory-device {
 			};
+
+			memory-array-mapped-address {
+			};
 		};
 	};
 };
cmd/smbios.c +14 -0
index 39c9c44a28e..671c14e05b5 100644
@@ -680,6 +680,17 @@ static void smbios_print_type17(struct smbios_type17 *table)
 	printf("\tRCD Revision Number: 0x%04x\n", table->rcd_rev_num);
 }
 
+static void smbios_print_type19(struct smbios_type19 *table)
+{
+	printf("Memory Array Mapped Address:\n");
+	printf("\tStarting Address: 0x%08x\n", table->start_addr);
+	printf("\tEnding Address: 0x%08x\n", table->end_addr);
+	printf("\tMemory Array Handle: 0x%04x\n", table->mem_array_hdl);
+	printf("\tPartition Width: 0x%04x\n", table->partition_wid);
+	printf("\tExtended Starting Address: 0x%016llx\n", table->ext_start_addr);
+	printf("\tExtended Ending Address: 0x%016llx\n", table->ext_end_addr);
+}
+
 static void smbios_print_type127(struct smbios_type127 *table)
 {
 	printf("End Of Table\n");
@@ -768,6 +779,9 @@ static int do_smbios(struct cmd_tbl *cmdtp, int flag, int argc,
 		case SMBIOS_MEMORY_DEVICE:
 			smbios_print_type17((struct smbios_type17 *)pos);
 			break;
+		case SMBIOS_MEMORY_ARRAY_MAPPED_ADDRESS:
+			smbios_print_type19((struct smbios_type19 *)pos);
+			break;
 		case SMBIOS_END_OF_TABLE:
 			smbios_print_type127((struct smbios_type127 *)pos);
 			break;
include/smbios.h +11 -0
index 2deafea9aa1..e4b5ff314d9 100644
@@ -372,6 +372,17 @@ struct __packed smbios_type17 {
 	char eos[SMBIOS_STRUCT_EOS_BYTES];
 };
 
+struct __packed smbios_type19 {
+	struct smbios_header hdr;
+	u32 start_addr;
+	u32 end_addr;
+	u16 mem_array_hdl;
+	u8 partition_wid;
+	u64 ext_start_addr;
+	u64 ext_end_addr;
+	char eos[SMBIOS_STRUCT_EOS_BYTES];
+};
+
 struct __packed smbios_type32 {
 	u8 type;
 	u8 length;
include/smbios_def.h +5 -0
index ce913f2f32a..ae50e1a808e 100644
@@ -436,4 +436,9 @@
 #define SMBIOS_MD_ERRINFO_NONE		0xFFFE
 #define SMBIOS_MD_ERRINFO_NOERR		0xFFFF
 
+/* Memory Array Mapped Address */
+
+/* Partition Width */
+#define SMBIOS_MAMA_PW_DEF	1 /* not partitioned */
+
 #endif /* _SMBIOS_DEF_H_ */
lib/smbios.c +150 -0

162 lines not on this page · raw message

Signature · 1 line
2.25.1
#6 lore raw

PATCH v6 6/6 smbios: print the properties only when they exist in a specified version of spec

In reply to Raymond Mao

By checking the payload length, we can know the version of the spec and skip the ones which are not expected to exist.

---
Changes in v5:
- Initial patch.
Changes in v6:
- None.

 cmd/smbios.c     | 65 ++++++++++++++++++++++++++++++++++++++++--------
 include/smbios.h | 32 ++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 11 deletions(-)
cmd/smbios.c +54 -11
index 671c14e05b5..3fafa46d0a5 100644
@@ -348,6 +348,8 @@ static void smbios_print_type0(struct smbios_type0 *table)
 	printf("\tBIOS ROM Size: 0x%02x\n", table->bios_rom_size);
 	printf("\tBIOS Characteristics: 0x%016llx\n",
 	       table->bios_characteristics);
+	if (table->hdr.length < SMBIOS_TYPE0_LENGTH_V24)
+		return;
 	printf("\tBIOS Characteristics Extension Byte 1: 0x%02x\n",
 	       table->bios_characteristics_ext1);
 	printf("\tBIOS Characteristics Extension Byte 2: 0x%02x\n",
@@ -360,6 +362,8 @@ static void smbios_print_type0(struct smbios_type0 *table)
 	       table->ec_major_release);
 	printf("\tEmbedded Controller Firmware Minor Release: 0x%02x\n",
 	       table->ec_minor_release);
+	if (table->hdr.length < SMBIOS_TYPE0_LENGTH_V31)
+		return;
 	printf("\tExtended BIOS ROM Size: 0x%04x\n",
 	       table->extended_bios_rom_size);
 }
@@ -371,17 +375,16 @@ static void smbios_print_type1(struct smbios_type1 *table)
 	smbios_print_str("Product Name", table, table->product_name);
 	smbios_print_str("Version", table, table->version);
 	smbios_print_str("Serial Number", table, table->serial_number);
-	if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V21) {
-		printf("\tUUID: %pUl\n", table->uuid);
-		smbios_print_lookup_str(wakeup_type_strings,
-					table->wakeup_type,
-					ARRAY_SIZE(wakeup_type_strings),
-					"Wake-up Type");
-	}
-	if (table->hdr.length >= SMBIOS_TYPE1_LENGTH_V24) {
-		smbios_print_str("SKU Number", table, table->sku_number);
-		smbios_print_str("Family", table, table->family);
-	}
+	if (table->hdr.length < SMBIOS_TYPE1_LENGTH_V21)
+		return;
+	printf("\tUUID: %pUl\n", table->uuid);
+	smbios_print_lookup_str(wakeup_type_strings, table->wakeup_type,
+				ARRAY_SIZE(wakeup_type_strings),
+				"Wake-up Type");
+	if (table->hdr.length < SMBIOS_TYPE1_LENGTH_V24)
+		return;
+	smbios_print_str("SKU Number", table, table->sku_number);
+	smbios_print_str("Family", table, table->family);
 }
 
 static void smbios_print_type2(struct smbios_type2 *table)
@@ -501,21 +504,31 @@ static void smbios_print_type4(struct smbios_type4 *table)
 	printf("\tL1 Cache Handle: 0x%04x\n", table->l1_cache_handle);
 	printf("\tL2 Cache Handle: 0x%04x\n", table->l2_cache_handle);
 	printf("\tL3 Cache Handle: 0x%04x\n", table->l3_cache_handle);
+	if (table->hdr.length < SMBIOS_TYPE4_LENGTH_V23)
+		return;
 	smbios_print_str("Serial Number", table, table->serial_number);
 	smbios_print_str("Asset Tag", table, table->asset_tag);
 	smbios_print_str("Part Number", table, table->part_number);
+	if (table->hdr.length < SMBIOS_TYPE4_LENGTH_V25)
+		return;
 	printf("\tCore Count: 0x%02x\n", table->core_count);
 	printf("\tCore Enabled: 0x%02x\n", table->core_enabled);
 	printf("\tThread Count: 0x%02x\n", table->thread_count);
 	printf("\tProcessor Characteristics: 0x%04x\n",
 	       table->processor_characteristics);
+	if (table->hdr.length < SMBIOS_TYPE4_LENGTH_V26)
+		return;
 	smbios_print_lookup_str(processor_family_strings,
 				table->processor_family2,
 				ARRAY_SIZE(processor_family_strings),
 				"Processor Family 2");
+	if (table->hdr.length < SMBIOS_TYPE4_LENGTH_V30)
+		return;
 	printf("\tCore Count 2: 0x%04x\n", table->core_count2);
 	printf("\tCore Enabled 2: 0x%04x\n", table->core_enabled2);
 	printf("\tThread Count 2: 0x%04x\n", table->thread_count2);
+	if (table->hdr.length < SMBIOS_TYPE4_LENGTH_V36)
+		return;
 	printf("\tThread Enabled: 0x%04x\n", table->thread_enabled);
 }
 
@@ -529,6 +542,8 @@ static void smbios_print_type7(struct smbios_type7 *table)
 	printf("\tInstalled Size: 0x%04x\n", table->inst_size.data);
 	printf("\tSupported SRAM Type: 0x%04x\n", table->supp_sram_type.data);
 	printf("\tCurrent SRAM Type: 0x%04x\n", table->curr_sram_type.data);
+	if (table->hdr.length < SMBIOS_TYPE7_LENGTH_V21)
+		return;
 	printf("\tCache Speed: 0x%02x\n", table->speed);
 	smbios_print_lookup_str(err_corr_type_strings,
 				table->err_corr_type,
@@ -542,6 +557,8 @@ static void smbios_print_type7(struct smbios_type7 *table)
 				table->associativity,
 				ARRAY_SIZE(associativity_strings),
 				"Associativity");
+	if (table->hdr.length < SMBIOS_TYPE7_LENGTH_V31)
+		return;
 	printf("\tMaximum Cache Size 2: 0x%08x\n", table->max_size2.data);
 	printf("\tInstalled Cache Size 2: 0x%08x\n", table->inst_size2.data);
 }
@@ -574,8 +591,12 @@ static void smbios_print_type9(struct smbios_type9 *table)
 	printf("\tSlot ID: 0x%04x\n", table->slot_id);
 	printf("\tSlot Characteristics 1: 0x%04x\n",
 	       table->slot_characteristics_1);
+	if (table->hdr.length < SMBIOS_TYPE9_LENGTH_V21)
+		return;
 	printf("\tSlot Characteristics 2: 0x%04x\n",
 	       table->slot_characteristics_2);
+	if (table->hdr.length < SMBIOS_TYPE9_LENGTH_V26)
+		return;
 	printf("\tSegment Group Number (Base): 0x%04x\n",
 	       table->segment_group_number);
 	printf("\tBus Number (Base): 0x%04x\n", table->bus_number);
@@ -611,6 +632,8 @@ static void smbios_print_type9(struct smbios_type9 *table)
 static void smbios_print_type16(struct smbios_type16 *table)
 {
 	printf("Physical Memory Array:\n");
+	if (table->hdr.length < SMBIOS_TYPE16_LENGTH_V21)
+		return;
 	smbios_print_lookup_str(ma_location_strings, table->location,
 				ARRAY_SIZE(ma_location_strings), "Location");
 	smbios_print_lookup_str(ma_use_strings, table->use,
@@ -622,12 +645,16 @@ static void smbios_print_type16(struct smbios_type16 *table)
 	printf("\tMemory Error Information Handle: 0x%04x\n",
 	       table->mem_err_info_hdl);
 	printf("\tNumber of Memory Devices: 0x%04x\n", table->num_of_mem_dev);
+	if (table->hdr.length < SMBIOS_TYPE16_LENGTH_V27)
+		return;
 	printf("\tExtended Maximum Capacity: 0x%016llx\n", table->ext_max_cap);
 }
 
 static void smbios_print_type17(struct smbios_type17 *table)
 {
 	printf("Memory Device:\n");
+	if (table->hdr.length < SMBIOS_TYPE17_LENGTH_V21)
+		return;
 	printf("\tPhysical Memory Array Handle: 0x%04x\n",
 	       table->phy_mem_array_hdl);
 	printf("\tMemory Error Information Handle: 0x%04x\n",
@@ -644,17 +671,27 @@ static void smbios_print_type17(struct smbios_type17 *table)
 	smbios_print_lookup_str(md_type_strings, table->mem_type,
 				ARRAY_SIZE(md_type_strings), "Memory Type");
 	printf("\tType Detail: 0x%04x\n", table->type_detail);
+	if (table->hdr.length < SMBIOS_TYPE17_LENGTH_V23)
+		return;
 	printf("\tSpeed: 0x%04x\n", table->speed);
 	smbios_print_str("Manufacturer", table, table->manufacturer);
 	smbios_print_str("Serial Number", table, table->serial_number);
 	smbios_print_str("Asset Tag", table, table->asset_tag);
 	smbios_print_str("Part Number", table, table->part_number);
+	if (table->hdr.length < SMBIOS_TYPE17_LENGTH_V26)
+		return;
 	printf("\tAttributes: 0x%04x\n", table->attributes);
+	if (table->hdr.length < SMBIOS_TYPE17_LENGTH_V27)
+		return;
 	printf("\tExtended Size: 0x%08x\n", table->ext_size);
 	printf("\tConfigured Memory Speed: 0x%04x\n", table->config_mem_speed);
+	if (table->hdr.length < SMBIOS_TYPE17_LENGTH_V28)
+		return;
 	printf("\tMinimum voltage: 0x%04x\n", table->min_voltage);
 	printf("\tMaximum voltage: 0x%04x\n", table->max_voltage);
 	printf("\tConfigured voltage: 0x%04x\n", table->config_voltage);
+	if (table->hdr.length < SMBIOS_TYPE17_LENGTH_V32)
+		return;
 	smbios_print_lookup_str(md_tech_strings, table->mem_tech,
 				ARRAY_SIZE(md_tech_strings),
 				"Memory Technology");
@@ -671,6 +708,8 @@ static void smbios_print_type17(struct smbios_type17 *table)
 	printf("\tVolatile Size: 0x%016llx\n", table->volatile_size);
 	printf("\tCache Size: 0x%016llx\n", table->cache_size);
 	printf("\tLogical Size: 0x%016llx\n", table->logical_size);
+	if (table->hdr.length < SMBIOS_TYPE17_LENGTH_V33)
+		return;
 	printf("\tExtended Speed: 0x%04x\n", table->ext_speed);
 	printf("\tExtended Configured Memory Speed: 0x%04x\n",
 	       table->ext_config_mem_speed);
@@ -683,10 +722,14 @@ static void smbios_print_type17(struct smbios_type17 *table)
 static void smbios_print_type19(struct smbios_type19 *table)
 {
 	printf("Memory Array Mapped Address:\n");
+	if (table->hdr.length < SMBIOS_TYPE19_LENGTH_V21)
+		return;
 	printf("\tStarting Address: 0x%08x\n", table->start_addr);
 	printf("\tEnding Address: 0x%08x\n", table->end_addr);
 	printf("\tMemory Array Handle: 0x%04x\n", table->mem_array_hdl);
 	printf("\tPartition Width: 0x%04x\n", table->partition_wid);
+	if (table->hdr.length < SMBIOS_TYPE19_LENGTH_V27)
+		return;
 	printf("\tExtended Starting Address: 0x%016llx\n", table->ext_start_addr);
 	printf("\tExtended Ending Address: 0x%016llx\n", table->ext_end_addr);
 }
include/smbios.h +32 -0
index e4b5ff314d9..39090d3ba18 100644
@@ -110,10 +110,42 @@ struct __packed smbios_type0 {
 	char eos[SMBIOS_STRUCT_EOS_BYTES];
 };
 
+#define SMBIOS_TYPE0_LENGTH_V24		0x18
+#define SMBIOS_TYPE0_LENGTH_V31		0x1a
+
 #define SMBIOS_TYPE1_LENGTH_V20		0x08
 #define SMBIOS_TYPE1_LENGTH_V21		0x19
 #define SMBIOS_TYPE1_LENGTH_V24		0x1b
 
+#define SMBIOS_TYPE4_LENGTH_V20		0x1a
+#define SMBIOS_TYPE4_LENGTH_V23		0x23
+#define SMBIOS_TYPE4_LENGTH_V25		0x28
+#define SMBIOS_TYPE4_LENGTH_V26		0x2a
+#define SMBIOS_TYPE4_LENGTH_V30		0x30
+#define SMBIOS_TYPE4_LENGTH_V36		0x32
+
+#define SMBIOS_TYPE7_LENGTH_V20		0x0f
+#define SMBIOS_TYPE7_LENGTH_V21		0x13
+#define SMBIOS_TYPE7_LENGTH_V31		0x1b
+
+#define SMBIOS_TYPE9_LENGTH_V20		0x0c
+#define SMBIOS_TYPE9_LENGTH_V21		0x0d
+#define SMBIOS_TYPE9_LENGTH_V26		0x11
+
+#define SMBIOS_TYPE16_LENGTH_V21	0x0f
+#define SMBIOS_TYPE16_LENGTH_V27	0x17
+
+#define SMBIOS_TYPE17_LENGTH_V21	0x15
+#define SMBIOS_TYPE17_LENGTH_V23	0x1b
+#define SMBIOS_TYPE17_LENGTH_V26	0x1c
+#define SMBIOS_TYPE17_LENGTH_V27	0x22
+#define SMBIOS_TYPE17_LENGTH_V28	0x28
+#define SMBIOS_TYPE17_LENGTH_V32	0x54
+#define SMBIOS_TYPE17_LENGTH_V33	0x5c
+
+#define SMBIOS_TYPE19_LENGTH_V21	0x0f
+#define SMBIOS_TYPE19_LENGTH_V27	0x1f
+
 struct __packed smbios_type1 {
 	struct smbios_header hdr;
 	u8 manufacturer;
Signature · 1 line
2.25.1
Tested-by on the v6 series
#7 lore raw
In reply to Raymond Mao

Tom, Raymond

I tested the patches and they now work properly in linux. Unfortunately I don't have time to review them depth, but I think we can pull them in since they improve the SMBIOS reporting overall

For the series

Quoted 42 lines · Raymond Mao

From: Raymond Mao <[email protected]>

This series finish the last missing puzzle of required SMBIOS types by:
1) Fixing duplicated handles when multiple instances exist in one type;
2) Implementing the rest of required types 9/16/17/19;
3) Adding version control when printing properties for all types.

Type 9/16/17/19 are generally DT-based, the idea is to write these tables using a hybrid approach:
Explicit DT definitions under existing '/smbios/smbios' take precedence, with fallback to scan and interpret values from the entire DT.

Moreover, all below APIs:
smbios_get_val_si()
smbios_get_u64_si()
smbios_add_prop_si()
are on top of sysinfo, thus allow vendors to get values from other subsystems by implementing their own sysinfo driver if needed.

Raymond Mao (6):
smbios: Fix duplicated smbios handles
smbios: add support for dynamic generation of Type 9 system slot
tables
smbios: add support for dynamic generation of Type 16 table
smbios: add support for dynamic generation of Type 17 table
smbios: add support for dynamic generation of Type 19 table
smbios: print the properties only when they exist in a specified
version of spec

 arch/arm/dts/smbios_generic.dtsi |   12 +
 cmd/smbios.c                     |  365 +++++++++-
 drivers/sysinfo/smbios.c         |    5 +
 include/smbios.h                 |  151 ++++
 include/smbios_def.h             |  250 +++++++
 include/sysinfo.h                |    4 +
 lib/smbios.c                     | 1151 +++++++++++++++++++++++++++++-
 7 files changed, 1905 insertions(+), 33 deletions(-)

--
2.25.1

#8 lore raw

Hi Ilias,

Quoted 11 lines · Ilias Apalodimas

Tom, Raymond

I tested the patches and they now work properly in linux. Unfortunately I don't have time to review them depth, but I think we can pull them in since they improve the SMBIOS reporting overall

For the series

Thank you so much for spending the time to test.

Regards
Raymons

Quoted 43 lines · Raymond Mao
Quoted 42 lines

From: Raymond Mao <[email protected]>

This series finish the last missing puzzle of required SMBIOS types by:
1) Fixing duplicated handles when multiple instances exist in one type;
2) Implementing the rest of required types 9/16/17/19;
3) Adding version control when printing properties for all types.

Type 9/16/17/19 are generally DT-based, the idea is to write these tables using a hybrid approach:
Explicit DT definitions under existing '/smbios/smbios' take precedence, with fallback to scan and interpret values from the entire DT.

Moreover, all below APIs:
smbios_get_val_si()
smbios_get_u64_si()
smbios_add_prop_si()
are on top of sysinfo, thus allow vendors to get values from other subsystems by implementing their own sysinfo driver if needed.

Raymond Mao (6):
smbios: Fix duplicated smbios handles
smbios: add support for dynamic generation of Type 9 system slot
tables
smbios: add support for dynamic generation of Type 16 table
smbios: add support for dynamic generation of Type 17 table
smbios: add support for dynamic generation of Type 19 table
smbios: print the properties only when they exist in a specified
version of spec

 arch/arm/dts/smbios_generic.dtsi |   12 +
 cmd/smbios.c                     |  365 +++++++++-
 drivers/sysinfo/smbios.c         |    5 +
 include/smbios.h                 |  151 ++++
 include/smbios_def.h             |  250 +++++++
 include/sysinfo.h                |    4 +
 lib/smbios.c                     | 1151 +++++++++++++++++++++++++++++-
 7 files changed, 1905 insertions(+), 33 deletions(-)

--
2.25.1

#9 lore raw
In reply to Raymond Mao
Quoted 8 lines · Raymond Mao

From: Raymond Mao <[email protected]>

This series finish the last missing puzzle of required SMBIOS types by:
1) Fixing duplicated handles when multiple instances exist in one type;
2) Implementing the rest of required types 9/16/17/19;
3) Adding version control when printing properties for all types.

[...]

Applied to u-boot/next, thanks!

[1/6] smbios: Fix duplicated smbios handles

      commit: 87f8a143da550a2de39dd5b30d3547bc8dfd7174
[2/6] smbios: add support for dynamic generation of Type 9 system slot tables
      commit: 83b28b55d74f884a30c47238dc8bdf9fbe6e495c
[3/6] smbios: add support for dynamic generation of Type 16 table
      commit: 374896158b435843d8ecf2c04c9985b0321295e0
[4/6] smbios: add support for dynamic generation of Type 17 table
      commit: 23674dee60240393dd17836c05df5b4f4aa01e5c
[5/6] smbios: add support for dynamic generation of Type 19 table
      commit: 41b7a09d24d878f748eba87ae85575043224148b
[6/6] smbios: print the properties only when they exist in a specified version of spec
      commit: 4c816ddbadb1bd8bfe09a457538d4f518151fd6d
Signature · 1 line
Tom