Skip to content

Commit 079214e

Browse files
committed
Merge patch series "SMBIOS improvements"
Raymond Mao <raymond.mao@linaro.org> says: Motivations for changes: Current SMBIOS library and command-line tool is not fully matching with the requirements: 1. Missing support for other mandatory types (u-boot#7, u-boot#9, u-boot#16, u-boot#17, u-boot#19). 2. Only a few platforms support SMBIOS node from the device tree. 3. Values of some fields are hardcoded in the library other than fetching from the device hardware. 4. Embedded data with dynamic length is not supported (E.g. Contained Object Handles in Type #2 and Contained Elements in Type #3) Changes: 1. Refactor the SMBIOS library and command-line tool to better align with the SMBIOS spec. 2. Create an arch-specific driver for all aarch64-based platforms to fetch SMBIOS private data from the device hardware (processor and cache). 3. Create a sysinfo driver to poppulate platform SMBIOS private data. 4. Add generic SMBIOS DTS file for arm64 platforms for those common strings and values which cannot be retrieved from the system registers. Vendors can create their own SMBIOS node using this as an example. For those boards without SMBIOS nodes, this DTS file can be included to have a generic SMBIOS information of the system. 5. Add support for Type u-boot#7 (Cache Information) and link its handles to Type #4. 6. To minimize size-growth for those platforms which have not sufficient ROM spaces or the platforms which don't need detailed SMBIOS information, new added fields are only being built when kconfig GENERATE_SMBIOS_TABLE_VERBOSE is selected. Once this patch is acceptted, subsequent patch sets will add other missing types (u-boot#9, u-boot#16, u-boot#17, u-boot#19). Tests: To test this with QEMU arm64, please follow the guide on dt_qemu.rst to get a merged DT to run with. ``` qemu-system-aarch64 -machine virt -machine dumpdtb=qemu.dtb cat <(dtc -I dtb qemu.dtb) <(dtc -I dtb ./dts/dt.dtb | grep -v /dts-v1/) \ | dtc - -o merged.dtb qemu-system-aarch64 -machine virt -nographic -bios u-boot.bin \ -dtb merged.dtb ``` Link: https://lore.kernel.org/r/20241206225438.13866-1-raymond.mao@linaro.org
2 parents e17be5a + 0af16b3 commit 079214e

File tree

19 files changed

+1863
-169
lines changed

19 files changed

+1863
-169
lines changed

arch/arm/cpu/armv8/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,5 @@ obj-$(CONFIG_TARGET_BCMNS3) += bcmns3/
4646
obj-$(CONFIG_XEN) += xen/
4747
obj-$(CONFIG_ARMV8_CE_SHA1) += sha1_ce_glue.o sha1_ce_core.o
4848
obj-$(CONFIG_ARMV8_CE_SHA256) += sha256_ce_glue.o sha256_ce_core.o
49+
50+
obj-$(CONFIG_SYSINFO_SMBIOS) += sysinfo.o

arch/arm/cpu/armv8/sysinfo.c

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Copyright (c) 2024 Linaro Limited
4+
* Author: Raymond Mao <raymond.mao@linaro.org>
5+
*/
6+
#include <dm.h>
7+
#include <smbios_plat.h>
8+
#include <stdio.h>
9+
#include <sysinfo.h>
10+
11+
union ccsidr_el1 {
12+
struct {
13+
u64 linesize:3;
14+
u64 associativity:10;
15+
u64 numsets:15;
16+
u64 unknown:4;
17+
u64 reserved:32;
18+
} no_ccidx;
19+
struct {
20+
u64 linesize:3;
21+
u64 associativity:21;
22+
u64 reserved1:8;
23+
u64 numsets:24;
24+
u64 reserved2:8;
25+
} ccidx_aarch64;
26+
struct {
27+
u64 linesize:3;
28+
u64 associativity:21;
29+
u64 reserved:8;
30+
u64 unallocated:32;
31+
} ccidx_aarch32;
32+
u64 data;
33+
};
34+
35+
union midr_el1 {
36+
struct {
37+
u64 revision:4;
38+
u64 partnum:12;
39+
u64 architecture:4;
40+
u64 variant:4;
41+
u64 implementer:8;
42+
u64 reserved:32;
43+
} fields;
44+
u64 data;
45+
};
46+
47+
enum {
48+
CACHE_NONE,
49+
CACHE_INST_ONLY,
50+
CACHE_DATA_ONLY,
51+
CACHE_INST_WITH_DATA,
52+
CACHE_UNIFIED,
53+
};
54+
55+
enum {
56+
CACHE_ASSOC_DIRECT_MAPPED = 1,
57+
CACHE_ASSOC_2WAY = 2,
58+
CACHE_ASSOC_4WAY = 4,
59+
CACHE_ASSOC_8WAY = 8,
60+
CACHE_ASSOC_16WAY = 16,
61+
CACHE_ASSOC_12WAY = 12,
62+
CACHE_ASSOC_24WAY = 24,
63+
CACHE_ASSOC_32WAY = 32,
64+
CACHE_ASSOC_48WAY = 48,
65+
CACHE_ASSOC_64WAY = 64,
66+
CACHE_ASSOC_20WAY = 20,
67+
};
68+
69+
enum {
70+
VENDOR_RESERVED = 0,
71+
VENDOR_ARM = 0x41,
72+
VENDOR_BROADCOM = 0x42,
73+
VENDOR_CAVIUM = 0x43,
74+
VENDOR_DEC = 0x44,
75+
VENDOR_FUJITSU = 0x46,
76+
VENDOR_INFINEON = 0x49,
77+
VENDOR_FREESCALE = 0x4d,
78+
VENDOR_NVIDIA = 0x4e,
79+
VENDOR_AMCC = 0x50,
80+
VENDOR_QUALCOMM = 0x51,
81+
VENDOR_MARVELL = 0x56,
82+
VENDOR_INTEL = 0x69,
83+
VENDOR_AMPERE = 0xc0,
84+
};
85+
86+
/*
87+
* TODO:
88+
* To support ARMv8.3, we need to read "CCIDX, bits [23:20]" from
89+
* ID_AA64MMFR2_EL1 to get the format of CCSIDR_EL1:
90+
*
91+
* 0b0000 - 32-bit format implemented for all levels of the CCSIDR_EL1.
92+
* 0b0001 - 64-bit format implemented for all levels of the CCSIDR_EL1.
93+
*
94+
* Here we assume to use CCSIDR_EL1 in no CCIDX layout:
95+
* NumSets, bits [27:13]: (Number of sets in cache) - 1
96+
* Associativity, bits [12:3]: (Associativity of cache) - 1
97+
* LineSize, bits [2:0]: (Log2(Number of bytes in cache line)) - 4
98+
*/
99+
int sysinfo_get_cache_info(u8 level, struct cache_info *cinfo)
100+
{
101+
u64 clidr_el1;
102+
u32 csselr_el1;
103+
u32 num_sets;
104+
union ccsidr_el1 creg;
105+
int cache_type;
106+
107+
sysinfo_cache_info_default(cinfo);
108+
109+
/* Read CLIDR_EL1 */
110+
asm volatile("mrs %0, clidr_el1" : "=r" (clidr_el1));
111+
debug("CLIDR_EL1: 0x%llx\n", clidr_el1);
112+
113+
cache_type = (clidr_el1 >> (3 * level)) & 0x7;
114+
if (cache_type == CACHE_NONE) /* level does not exist */
115+
return -1;
116+
117+
switch (cache_type) {
118+
case CACHE_INST_ONLY:
119+
cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_INST;
120+
break;
121+
case CACHE_DATA_ONLY:
122+
cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_DATA;
123+
break;
124+
case CACHE_UNIFIED:
125+
cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_UNIFIED;
126+
break;
127+
case CACHE_INST_WITH_DATA:
128+
cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_OTHER;
129+
break;
130+
default:
131+
cinfo->cache_type = SMBIOS_CACHE_SYSCACHE_TYPE_UNKNOWN;
132+
break;
133+
}
134+
135+
/* Select cache level */
136+
csselr_el1 = (level << 1);
137+
asm volatile("msr csselr_el1, %0" : : "r" (csselr_el1));
138+
139+
/* Read CCSIDR_EL1 */
140+
asm volatile("mrs %0, ccsidr_el1" : "=r" (creg.data));
141+
debug("CCSIDR_EL1 (Level %d): 0x%llx\n", level + 1, creg.data);
142+
143+
/* Extract cache size and associativity */
144+
cinfo->line_size = 1 << (creg.no_ccidx.linesize + 4);
145+
146+
/* Map the associativity value */
147+
switch (creg.no_ccidx.associativity + 1) {
148+
case CACHE_ASSOC_DIRECT_MAPPED:
149+
cinfo->associativity = SMBIOS_CACHE_ASSOC_DMAPPED;
150+
break;
151+
case CACHE_ASSOC_2WAY:
152+
cinfo->associativity = SMBIOS_CACHE_ASSOC_2WAY;
153+
break;
154+
case CACHE_ASSOC_4WAY:
155+
cinfo->associativity = SMBIOS_CACHE_ASSOC_4WAY;
156+
break;
157+
case CACHE_ASSOC_8WAY:
158+
cinfo->associativity = SMBIOS_CACHE_ASSOC_8WAY;
159+
break;
160+
case CACHE_ASSOC_16WAY:
161+
cinfo->associativity = SMBIOS_CACHE_ASSOC_16WAY;
162+
break;
163+
case CACHE_ASSOC_12WAY:
164+
cinfo->associativity = SMBIOS_CACHE_ASSOC_12WAY;
165+
break;
166+
case CACHE_ASSOC_24WAY:
167+
cinfo->associativity = SMBIOS_CACHE_ASSOC_24WAY;
168+
break;
169+
case CACHE_ASSOC_32WAY:
170+
cinfo->associativity = SMBIOS_CACHE_ASSOC_32WAY;
171+
break;
172+
case CACHE_ASSOC_48WAY:
173+
cinfo->associativity = SMBIOS_CACHE_ASSOC_48WAY;
174+
break;
175+
case CACHE_ASSOC_64WAY:
176+
cinfo->associativity = SMBIOS_CACHE_ASSOC_64WAY;
177+
break;
178+
case CACHE_ASSOC_20WAY:
179+
cinfo->associativity = SMBIOS_CACHE_ASSOC_20WAY;
180+
break;
181+
default:
182+
cinfo->associativity = SMBIOS_CACHE_ASSOC_UNKNOWN;
183+
break;
184+
}
185+
186+
num_sets = creg.no_ccidx.numsets + 1;
187+
/* Size in KB */
188+
cinfo->max_size = (cinfo->associativity * num_sets * cinfo->line_size) /
189+
1024;
190+
191+
debug("L%d Cache:\n", level + 1);
192+
debug("Number of bytes in cache line:%u\n", cinfo->line_size);
193+
debug("Associativity of cache:%u\n", cinfo->associativity);
194+
debug("Number of sets in cache:%u\n", num_sets);
195+
debug("Cache size in KB:%u\n", cinfo->max_size);
196+
197+
cinfo->inst_size = cinfo->max_size;
198+
199+
/*
200+
* Below fields with common values are placed under DT smbios node
201+
* socket-design, config
202+
* Other fields are typically specific to the implementation of the ARM
203+
* processor by the silicon vendor:
204+
* supp_sram_type, curr_sram_type, speed, err_corr_type
205+
*/
206+
207+
return 0;
208+
}
209+
210+
int sysinfo_get_processor_info(struct processor_info *pinfo)
211+
{
212+
u64 mpidr, core_count;
213+
union midr_el1 midr;
214+
215+
/* Read the MIDR_EL1 register */
216+
asm volatile("mrs %0, MIDR_EL1" : "=r"(midr.data));
217+
/* Read the MPIDR_EL1 register */
218+
asm volatile("mrs %0, MPIDR_EL1" : "=r"(mpidr));
219+
220+
debug("MIDR: 0x%016llx\n", midr.data);
221+
debug("MPIDR: 0x%016llx\n", mpidr);
222+
debug("CPU Implementer: 0x%02x\n", midr.fields.implementer);
223+
224+
switch (midr.fields.implementer) {
225+
case VENDOR_ARM:
226+
pinfo->manufacturer = "ARM Limited";
227+
break;
228+
case VENDOR_BROADCOM:
229+
pinfo->manufacturer = "Broadcom Corporation";
230+
break;
231+
case VENDOR_CAVIUM:
232+
pinfo->manufacturer = "Cavium Inc";
233+
break;
234+
case VENDOR_DEC:
235+
pinfo->manufacturer = "Digital Equipment Corporation";
236+
break;
237+
case VENDOR_FUJITSU:
238+
pinfo->manufacturer = "Fujitsu Ltd";
239+
break;
240+
case VENDOR_INFINEON:
241+
pinfo->manufacturer = "Infineon Technologies AG";
242+
break;
243+
case VENDOR_FREESCALE:
244+
pinfo->manufacturer = "Freescale Semiconductor Inc";
245+
break;
246+
case VENDOR_NVIDIA:
247+
pinfo->manufacturer = "NVIDIA Corporation";
248+
break;
249+
case VENDOR_AMCC:
250+
pinfo->manufacturer =
251+
"Applied Micro Circuits Corporation";
252+
break;
253+
case VENDOR_QUALCOMM:
254+
pinfo->manufacturer = "Qualcomm Inc";
255+
break;
256+
case VENDOR_MARVELL:
257+
pinfo->manufacturer = "Marvell International Ltd";
258+
break;
259+
case VENDOR_INTEL:
260+
pinfo->manufacturer = "Intel Corporation";
261+
break;
262+
case VENDOR_AMPERE:
263+
pinfo->manufacturer = "Ampere Computing";
264+
break;
265+
default:
266+
pinfo->manufacturer = "Unknown";
267+
break;
268+
}
269+
debug("CPU part number: 0x%x\n", midr.fields.partnum);
270+
debug("CPU revision: 0x%x\n", midr.fields.revision);
271+
debug("CPU architecture: 0x%x\n", midr.fields.architecture);
272+
debug("CPU variant: 0x%x\n", midr.fields.variant);
273+
274+
/* Extract number of cores */
275+
core_count = (mpidr >> 0) & 0xFF;
276+
pinfo->core_count = core_count + 1;
277+
debug("CPU Core Count: %d\n", pinfo->core_count);
278+
279+
pinfo->core_enabled = pinfo->core_count;
280+
pinfo->characteristics = SMBIOS_PROCESSOR_64BIT |
281+
SMBIOS_PROCESSOR_ARM64_SOCID;
282+
if (pinfo->core_count > 1)
283+
pinfo->characteristics |= SMBIOS_PROCESSOR_MULTICORE;
284+
285+
/*
286+
* Below fields with common values are placed under DT smbios node
287+
* version, processor-type, processor-status, upgrade, family2,
288+
* socket-design, serial, asset-tag, part-number
289+
*/
290+
291+
return 0;
292+
}

arch/arm/dts/qemu-arm64.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,9 @@
77

88
/dts-v1/;
99

10+
#if defined(CONFIG_SYSINFO_SMBIOS) && !defined(QFW_SMBIOS)
11+
#include "smbios_generic.dtsi"
12+
#endif
13+
1014
/ {
1115
};

arch/arm/dts/smbios_generic.dtsi

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// SPDX-License-Identifier: GPL-2.0+
2+
/*
3+
* Default SMBIOS information for Arm64 platforms
4+
*
5+
* Copyright (c) 2024 Linaro Limited
6+
* Author: Raymond Mao <raymond.mao@linaro.org>
7+
*/
8+
#include <config.h>
9+
#include <smbios_def.h>
10+
11+
/ {
12+
smbios {
13+
compatible = "u-boot,sysinfo-smbios";
14+
15+
smbios {
16+
system {
17+
manufacturer = CONFIG_SYS_VENDOR;
18+
product = CONFIG_SYS_BOARD;
19+
version = "";
20+
serial = "";
21+
wakeup-type = <SMBIOS_WAKEUP_TYPE_UNKNOWN>;
22+
sku = "";
23+
family = "armv8";
24+
};
25+
26+
baseboard {
27+
manufacturer = CONFIG_SYS_VENDOR;
28+
product = CONFIG_SYS_BOARD;
29+
version = "";
30+
serial = "";
31+
asset-tag = "";
32+
chassis-location = "";
33+
feature-flags = <SMBIOS_BOARD_FEAT_HOST_BOARD>;
34+
board-type = <SMBIOS_BOARD_TYPE_MOTHERBOARD>;
35+
};
36+
37+
chassis {
38+
manufacturer = CONFIG_SYS_VENDOR;
39+
version = "";
40+
serial = "";
41+
asset-tag = "";
42+
chassis-type = <SMBIOS_ENCLOSURE_DESKTOP>;
43+
bootup-state = <SMBIOS_STATE_SAFE>;
44+
power-supply-state = <SMBIOS_STATE_SAFE>;
45+
thermal-state = <SMBIOS_STATE_SAFE>;
46+
security-status = <SMBIOS_SECURITY_NONE>;
47+
oem-defined = <SMBIOS_ENCLOSURE_OEM_UND>;
48+
height = <SMBIOS_ENCLOSURE_HEIGHT_UND>;
49+
number-of-power-cords = <SMBIOS_POWCORD_NUM_UND>;
50+
};
51+
52+
processor {
53+
version = "";
54+
processor-type = <SMBIOS_PROCESSOR_TYPE_CENTRAL>;
55+
processor-status = <SMBIOS_PROCESSOR_STATUS_ENABLED>;
56+
upgrade = <SMBIOS_PROCESSOR_UPGRADE_NONE>;
57+
family = <SMBIOS_PROCESSOR_FAMILY_EXT>;
58+
family2 = <SMBIOS_PROCESSOR_FAMILY_ARMV8>;
59+
socket-design = "";
60+
serial = "";
61+
asset-tag = "";
62+
part-number = "";
63+
};
64+
65+
cache {
66+
l1-cache {
67+
socket-design = "";
68+
config = <(SMBIOS_CACHE_LEVEL_1 |
69+
SMBIOS_CACHE_ENABLED |
70+
SMBIOS_CACHE_OP_WB)>;
71+
};
72+
73+
l2-cache {
74+
socket-design = "";
75+
config = <(SMBIOS_CACHE_LEVEL_2 |
76+
SMBIOS_CACHE_ENABLED |
77+
SMBIOS_CACHE_OP_WB)>;
78+
};
79+
};
80+
};
81+
};
82+
};

0 commit comments

Comments
 (0)