blob: e8089e91523063184644039e9d0ec88b0d5f837e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Bin Mengae5bedb2015-10-12 05:23:41 -07002/*
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 *
5 * Adapted from coreboot src/arch/x86/smbios.c
Bin Mengae5bedb2015-10-12 05:23:41 -07006 */
7
Simon Glassbd5515d2024-06-23 14:30:33 -06008#define LOG_CATEGORY LOGC_BOARD
9
Simon Glass0dd7ca22020-11-05 06:32:07 -070010#include <dm.h>
Simon Glass0af6e2d2019-08-01 09:46:52 -060011#include <env.h>
Pali Rohárebe9fd82021-04-22 18:09:57 +020012#include <linux/stringify.h>
Ilias Apalodimasada83d92023-12-07 11:18:50 +020013#include <linux/string.h>
Simon Glass2d93add2018-11-22 13:46:37 -070014#include <mapmem.h>
Alexander Graffb228082016-08-19 01:23:23 +020015#include <smbios.h>
Simon Glasscf67d6d2021-02-04 21:17:23 -070016#include <sysinfo.h>
Alexander Graffb228082016-08-19 01:23:23 +020017#include <tables_csum.h>
Bin Mengae5bedb2015-10-12 05:23:41 -070018#include <version.h>
Ilias Apalodimasada83d92023-12-07 11:18:50 +020019#include <malloc.h>
20#include <dm/ofnode.h>
Alexander Grafe44b3c02016-08-19 01:23:28 +020021#ifdef CONFIG_CPU
22#include <cpu.h>
Alexander Grafe44b3c02016-08-19 01:23:28 +020023#include <dm/uclass-internal.h>
24#endif
Heinrich Schuchardtbfeb45f2024-07-23 16:44:23 +020025#include <linux/sizes.h>
Bin Mengae5bedb2015-10-12 05:23:41 -070026
Pali Rohárebe9fd82021-04-22 18:09:57 +020027/* Safeguard for checking that U_BOOT_VERSION_NUM macros are compatible with U_BOOT_DMI */
28#if U_BOOT_VERSION_NUM < 2000 || U_BOOT_VERSION_NUM > 2099 || \
29 U_BOOT_VERSION_NUM_PATCH < 1 || U_BOOT_VERSION_NUM_PATCH > 12
30#error U_BOOT_VERSION_NUM macros are not compatible with DMI, fix U_BOOT_DMI macros
31#endif
32
33/*
34 * U_BOOT_DMI_DATE contains BIOS Release Date in format mm/dd/yyyy.
35 * BIOS Release Date is calculated from U-Boot version and fixed day 01.
36 * So for U-Boot version 2021.04 it is calculated as "04/01/2021".
37 * BIOS Release Date should contain date when code was released
38 * and not when it was built or compiled.
39 */
40#if U_BOOT_VERSION_NUM_PATCH < 10
41#define U_BOOT_DMI_MONTH "0" __stringify(U_BOOT_VERSION_NUM_PATCH)
42#else
43#define U_BOOT_DMI_MONTH __stringify(U_BOOT_VERSION_NUM_PATCH)
44#endif
45#define U_BOOT_DMI_DAY "01"
46#define U_BOOT_DMI_YEAR __stringify(U_BOOT_VERSION_NUM)
47#define U_BOOT_DMI_DATE U_BOOT_DMI_MONTH "/" U_BOOT_DMI_DAY "/" U_BOOT_DMI_YEAR
48
Simon Glassa05eb042021-02-04 21:17:20 -070049DECLARE_GLOBAL_DATA_PTR;
50
Bin Mengae5bedb2015-10-12 05:23:41 -070051/**
Ilias Apalodimasada83d92023-12-07 11:18:50 +020052 * struct map_sysinfo - Mapping of sysinfo strings to DT
53 *
Ilias Apalodimas3adf8a62024-01-11 16:39:35 +020054 * @si_str: sysinfo string
Ilias Apalodimasada83d92023-12-07 11:18:50 +020055 * @dt_str: DT string
56 * @max: Max index of the tokenized string to pick. Counting starts from 0
57 *
58 */
59struct map_sysinfo {
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +020060 const char *si_node;
Ilias Apalodimas3adf8a62024-01-11 16:39:35 +020061 const char *si_str;
Ilias Apalodimasada83d92023-12-07 11:18:50 +020062 const char *dt_str;
63 int max;
64};
65
66static const struct map_sysinfo sysinfo_to_dt[] = {
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +020067 { .si_node = "system", .si_str = "product", .dt_str = "model", 2 },
68 { .si_node = "system", .si_str = "manufacturer", .dt_str = "compatible", 1 },
69 { .si_node = "baseboard", .si_str = "product", .dt_str = "model", 2 },
70 { .si_node = "baseboard", .si_str = "manufacturer", .dt_str = "compatible", 1 },
Ilias Apalodimasada83d92023-12-07 11:18:50 +020071};
72
73/**
Simon Glass8e5ddb02021-02-04 21:17:17 -070074 * struct smbios_ctx - context for writing SMBIOS tables
75 *
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +020076 * @node: node containing the information to write (ofnode_null()
77 * if none)
78 * @dev: sysinfo device to use (NULL if none)
79 * @subnode_name: sysinfo subnode_name. Used for DT fallback
80 * @eos: end-of-string pointer for the table being processed.
81 * This is set up when we start processing a table
82 * @next_ptr: pointer to the start of the next string to be added.
83 * When the table is not empty, this points to the byte
84 * after the \0 of the previous string.
85 * @last_str: points to the last string that was written to the table,
86 * or NULL if none
Simon Glass8e5ddb02021-02-04 21:17:17 -070087 */
88struct smbios_ctx {
89 ofnode node;
90 struct udevice *dev;
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +020091 const char *subnode_name;
Simon Glassdff4e862021-02-04 21:17:18 -070092 char *eos;
Simon Glass721b4662021-02-04 21:17:19 -070093 char *next_ptr;
Simon Glassa05eb042021-02-04 21:17:20 -070094 char *last_str;
Simon Glass8e5ddb02021-02-04 21:17:17 -070095};
96
97/**
Simon Glass099d3ae2021-02-04 21:17:14 -070098 * Function prototype to write a specific type of SMBIOS structure
99 *
100 * @addr: start address to write the structure
101 * @handle: the structure's handle, a unique 16-bit number
Simon Glass8e5ddb02021-02-04 21:17:17 -0700102 * @ctx: context for writing the tables
Heinrich Schuchardt9809bcc2021-06-10 12:13:52 +0200103 * Return: size of the structure
Simon Glass099d3ae2021-02-04 21:17:14 -0700104 */
Simon Glass8e5ddb02021-02-04 21:17:17 -0700105typedef int (*smbios_write_type)(ulong *addr, int handle,
106 struct smbios_ctx *ctx);
Simon Glass099d3ae2021-02-04 21:17:14 -0700107
108/**
Simon Glass6f3332a2020-11-05 06:32:08 -0700109 * struct smbios_write_method - Information about a table-writing function
110 *
111 * @write: Function to call
112 * @subnode_name: Name of subnode which has the information for this function,
113 * NULL if none
114 */
115struct smbios_write_method {
116 smbios_write_type write;
117 const char *subnode_name;
118};
119
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +0200120static const struct map_sysinfo *convert_sysinfo_to_dt(const char *node, const char *si)
Ilias Apalodimasada83d92023-12-07 11:18:50 +0200121{
122 int i;
123
124 for (i = 0; i < ARRAY_SIZE(sysinfo_to_dt); i++) {
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +0200125 if (node && !strcmp(node, sysinfo_to_dt[i].si_node) &&
126 !strcmp(si, sysinfo_to_dt[i].si_str))
Ilias Apalodimasada83d92023-12-07 11:18:50 +0200127 return &sysinfo_to_dt[i];
128 }
129
130 return NULL;
131}
132
Simon Glass6f3332a2020-11-05 06:32:08 -0700133/**
Bin Mengae5bedb2015-10-12 05:23:41 -0700134 * smbios_add_string() - add a string to the string area
135 *
136 * This adds a string to the string area which is appended directly after
137 * the formatted portion of an SMBIOS structure.
138 *
Simon Glassdff4e862021-02-04 21:17:18 -0700139 * @ctx: SMBIOS context
Bin Mengae5bedb2015-10-12 05:23:41 -0700140 * @str: string to add
Heinrich Schuchardte952b822024-01-29 14:09:36 +0100141 * Return: string number in the string area. 0 if str is NULL.
Bin Mengae5bedb2015-10-12 05:23:41 -0700142 */
Simon Glassdff4e862021-02-04 21:17:18 -0700143static int smbios_add_string(struct smbios_ctx *ctx, const char *str)
Bin Mengae5bedb2015-10-12 05:23:41 -0700144{
145 int i = 1;
Simon Glassdff4e862021-02-04 21:17:18 -0700146 char *p = ctx->eos;
147
Heinrich Schuchardte952b822024-01-29 14:09:36 +0100148 if (!str)
149 return 0;
150
Bin Mengae5bedb2015-10-12 05:23:41 -0700151 for (;;) {
152 if (!*p) {
Simon Glassa05eb042021-02-04 21:17:20 -0700153 ctx->last_str = p;
Bin Mengae5bedb2015-10-12 05:23:41 -0700154 strcpy(p, str);
155 p += strlen(str);
156 *p++ = '\0';
Simon Glass721b4662021-02-04 21:17:19 -0700157 ctx->next_ptr = p;
Bin Mengae5bedb2015-10-12 05:23:41 -0700158 *p++ = '\0';
159
160 return i;
161 }
162
Simon Glassa05eb042021-02-04 21:17:20 -0700163 if (!strcmp(p, str)) {
164 ctx->last_str = p;
Bin Mengae5bedb2015-10-12 05:23:41 -0700165 return i;
Simon Glassa05eb042021-02-04 21:17:20 -0700166 }
Bin Mengae5bedb2015-10-12 05:23:41 -0700167
168 p += strlen(p) + 1;
169 i++;
170 }
171}
172
173/**
Ilias Apalodimasada83d92023-12-07 11:18:50 +0200174 * get_str_from_dt - Get a substring from a DT property.
175 * After finding the property in the DT, the function
176 * will parse comma-separated values and return the value.
177 * If nprop->max exceeds the number of comma-separated
178 * elements, the last non NULL value will be returned.
179 * Counting starts from zero.
180 *
181 * @nprop: sysinfo property to use
182 * @str: pointer to fill with data
183 * @size: str buffer length
184 */
185static
186void get_str_from_dt(const struct map_sysinfo *nprop, char *str, size_t size)
187{
188 const char *dt_str;
189 int cnt = 0;
190 char *token;
191
192 memset(str, 0, size);
193 if (!nprop || !nprop->max)
194 return;
195
196 dt_str = ofnode_read_string(ofnode_root(), nprop->dt_str);
197 if (!dt_str)
198 return;
199
200 memcpy(str, dt_str, size);
201 token = strtok(str, ",");
202 while (token && cnt < nprop->max) {
203 strlcpy(str, token, strlen(token) + 1);
204 token = strtok(NULL, ",");
205 cnt++;
206 }
207}
208
209/**
Raymond Maoa28ef802024-12-06 14:54:22 -0800210 * smbios_get_val_si() - Get value from the devicetree or sysinfo
211 *
212 * @ctx: context of SMBIOS
213 * @prop: property to read
214 * @sysinfo_id: unique identifier for the value to be read
215 * @val_def: Default value
216 * Return: Valid value from sysinfo or device tree, otherwise val_def.
217 */
218static int smbios_get_val_si(struct smbios_ctx * __maybe_unused ctx,
219 const char * __maybe_unused prop,
220 int __maybe_unused sysinfo_id, int val_def)
221{
222#if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLE_VERBOSE)
223 int val;
224
225 if (!ctx->dev)
226 return val_def;
227
228 if (!sysinfo_get_int(ctx->dev, sysinfo_id, &val))
229 return val;
230
231 if (!IS_ENABLED(CONFIG_OF_CONTROL) || !prop)
232 return val_def;
233
234 if (ofnode_valid(ctx->node) && !ofnode_read_u32(ctx->node, prop, &val))
235 return val;
236
237 /*
238 * If the node or property is not valid fallback and try the root
239 */
240 if (!ofnode_read_u32(ofnode_root(), prop, &val))
241 return val;
242#endif
243 return val_def;
244}
245
246/**
Simon Glasscf67d6d2021-02-04 21:17:23 -0700247 * smbios_add_prop_si() - Add a property from the devicetree or sysinfo
248 *
249 * Sysinfo is used if available, with a fallback to devicetree
Simon Glass6f3332a2020-11-05 06:32:08 -0700250 *
Simon Glass8e5ddb02021-02-04 21:17:17 -0700251 * @ctx: context for writing the tables
Simon Glass6f3332a2020-11-05 06:32:08 -0700252 * @prop: property to write
Heinrich Schuchardtda0428c2024-01-29 13:58:18 +0100253 * @sysinfo_id: unique identifier for the string value to be read
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200254 * @dval: Default value to use if the string is not found or is empty
Heinrich Schuchardt9809bcc2021-06-10 12:13:52 +0200255 * Return: 0 if not found, else SMBIOS string number (1 or more)
Simon Glass6f3332a2020-11-05 06:32:08 -0700256 */
Simon Glasscf67d6d2021-02-04 21:17:23 -0700257static int smbios_add_prop_si(struct smbios_ctx *ctx, const char *prop,
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200258 int sysinfo_id, const char *dval)
Simon Glass6f3332a2020-11-05 06:32:08 -0700259{
Ilias Apalodimasada83d92023-12-07 11:18:50 +0200260 int ret;
261
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200262 if (!dval || !*dval)
Heinrich Schuchardte952b822024-01-29 14:09:36 +0100263 dval = NULL;
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200264
Simon Glasscf67d6d2021-02-04 21:17:23 -0700265 if (sysinfo_id && ctx->dev) {
266 char val[SMBIOS_STR_MAX];
Simon Glasscf67d6d2021-02-04 21:17:23 -0700267
268 ret = sysinfo_get_str(ctx->dev, sysinfo_id, sizeof(val), val);
269 if (!ret)
270 return smbios_add_string(ctx, val);
271 }
Raymond Maoa28ef802024-12-06 14:54:22 -0800272 if (!prop)
273 return smbios_add_string(ctx, dval);
274
Simon Glass95f47082020-11-05 06:32:18 -0700275 if (IS_ENABLED(CONFIG_OF_CONTROL)) {
Ilias Apalodimasada83d92023-12-07 11:18:50 +0200276 const char *str = NULL;
277 char str_dt[128] = { 0 };
278 /*
279 * If the node is not valid fallback and try the entire DT
280 * so we can at least fill in manufacturer and board type
281 */
282 if (ofnode_valid(ctx->node)) {
283 str = ofnode_read_string(ctx->node, prop);
284 } else {
285 const struct map_sysinfo *nprop;
Simon Glass95f47082020-11-05 06:32:18 -0700286
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +0200287 nprop = convert_sysinfo_to_dt(ctx->subnode_name, prop);
Ilias Apalodimasada83d92023-12-07 11:18:50 +0200288 get_str_from_dt(nprop, str_dt, sizeof(str_dt));
289 str = (const char *)str_dt;
290 }
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200291
Ilias Apalodimasada83d92023-12-07 11:18:50 +0200292 ret = smbios_add_string(ctx, str && *str ? str : dval);
293 return ret;
Simon Glass95f47082020-11-05 06:32:18 -0700294 }
Simon Glass6f3332a2020-11-05 06:32:08 -0700295
296 return 0;
297}
298
Simon Glasscf67d6d2021-02-04 21:17:23 -0700299/**
300 * smbios_add_prop() - Add a property from the devicetree
301 *
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200302 * @prop: property to write. The default string will be written if
303 * prop is NULL
304 * @dval: Default value to use if the string is not found or is empty
Heinrich Schuchardt9809bcc2021-06-10 12:13:52 +0200305 * Return: 0 if not found, else SMBIOS string number (1 or more)
Simon Glasscf67d6d2021-02-04 21:17:23 -0700306 */
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200307static int smbios_add_prop(struct smbios_ctx *ctx, const char *prop,
308 const char *dval)
Simon Glasscf67d6d2021-02-04 21:17:23 -0700309{
Simon Glassff3edc22024-10-31 18:50:23 +0100310 return smbios_add_prop_si(ctx, prop, SYSID_NONE, dval);
Simon Glasscf67d6d2021-02-04 21:17:23 -0700311}
312
Simon Glassdff4e862021-02-04 21:17:18 -0700313static void smbios_set_eos(struct smbios_ctx *ctx, char *eos)
314{
315 ctx->eos = eos;
Simon Glass721b4662021-02-04 21:17:19 -0700316 ctx->next_ptr = eos;
Simon Glassa05eb042021-02-04 21:17:20 -0700317 ctx->last_str = NULL;
Simon Glassdff4e862021-02-04 21:17:18 -0700318}
319
Simon Glassa05eb042021-02-04 21:17:20 -0700320int smbios_update_version(const char *version)
321{
322 char *ptr = gd->smbios_version;
323 uint old_len, len;
324
325 if (!ptr)
326 return log_ret(-ENOENT);
327
328 /*
329 * This string is supposed to have at least enough bytes and is
330 * padded with spaces. Update it, taking care not to move the
331 * \0 terminator, so that other strings in the string table
332 * are not disturbed. See smbios_add_string()
333 */
334 old_len = strnlen(ptr, SMBIOS_STR_MAX);
335 len = strnlen(version, SMBIOS_STR_MAX);
336 if (len > old_len)
337 return log_ret(-ENOSPC);
338
339 log_debug("Replacing SMBIOS type 0 version string '%s'\n", ptr);
340 memcpy(ptr, version, len);
341#ifdef LOG_DEBUG
342 print_buffer((ulong)ptr, ptr, 1, old_len + 1, 0);
343#endif
344
345 return 0;
346}
347
Simon Glass6f3332a2020-11-05 06:32:08 -0700348/**
Bin Mengae5bedb2015-10-12 05:23:41 -0700349 * smbios_string_table_len() - compute the string area size
350 *
351 * This computes the size of the string area including the string terminator.
352 *
Simon Glass721b4662021-02-04 21:17:19 -0700353 * @ctx: SMBIOS context
Heinrich Schuchardt9809bcc2021-06-10 12:13:52 +0200354 * Return: string area size
Bin Mengae5bedb2015-10-12 05:23:41 -0700355 */
Simon Glass721b4662021-02-04 21:17:19 -0700356static int smbios_string_table_len(const struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700357{
Matthias Bruggere01fa9f2021-04-06 11:04:35 +0200358 /* In case no string is defined we have to return two \0 */
359 if (ctx->next_ptr == ctx->eos)
360 return 2;
361
Simon Glass721b4662021-02-04 21:17:19 -0700362 /* Allow for the final \0 after all strings */
363 return (ctx->next_ptr + 1) - ctx->eos;
Bin Mengae5bedb2015-10-12 05:23:41 -0700364}
365
Simon Glass8e5ddb02021-02-04 21:17:17 -0700366static int smbios_write_type0(ulong *current, int handle,
367 struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700368{
Simon Glass2d93add2018-11-22 13:46:37 -0700369 struct smbios_type0 *t;
Raymond Maof4b933d2024-12-06 14:54:18 -0800370 int len = sizeof(*t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700371
Simon Glass2d93add2018-11-22 13:46:37 -0700372 t = map_sysmem(*current, len);
Raymond Maof4b933d2024-12-06 14:54:18 -0800373 memset(t, 0, len);
Bin Mengae5bedb2015-10-12 05:23:41 -0700374 fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle);
Simon Glassdff4e862021-02-04 21:17:18 -0700375 smbios_set_eos(ctx, t->eos);
Raymond Maoa28ef802024-12-06 14:54:22 -0800376 t->vendor = smbios_add_prop_si(ctx, NULL, SYSID_SM_BIOS_VENDOR,
377 "U-Boot");
Simon Glassa05eb042021-02-04 21:17:20 -0700378
Raymond Maoa28ef802024-12-06 14:54:22 -0800379 t->bios_ver = smbios_add_prop_si(ctx, "version", SYSID_SM_BIOS_VER,
380 PLAIN_VERSION);
Simon Glassa05eb042021-02-04 21:17:20 -0700381 if (t->bios_ver)
382 gd->smbios_version = ctx->last_str;
383 log_debug("smbios_version = %p: '%s'\n", gd->smbios_version,
384 gd->smbios_version);
385#ifdef LOG_DEBUG
386 print_buffer((ulong)gd->smbios_version, gd->smbios_version,
387 1, strlen(gd->smbios_version) + 1, 0);
388#endif
Raymond Maoa28ef802024-12-06 14:54:22 -0800389 t->bios_release_date = smbios_add_prop_si(ctx, NULL,
390 SYSID_SM_BIOS_REL_DATE,
391 U_BOOT_DMI_DATE);
Alexander Graf66f96e12016-08-19 01:23:29 +0200392#ifdef CONFIG_ROM_SIZE
Heinrich Schuchardtbfeb45f2024-07-23 16:44:23 +0200393 if (CONFIG_ROM_SIZE < SZ_16M) {
394 t->bios_rom_size = (CONFIG_ROM_SIZE / 65536) - 1;
395 } else {
396 /* CONFIG_ROM_SIZE < 8 GiB */
397 t->bios_rom_size = 0xff;
398 t->extended_bios_rom_size = CONFIG_ROM_SIZE >> 20;
399 }
Alexander Graf66f96e12016-08-19 01:23:29 +0200400#endif
Bin Mengae5bedb2015-10-12 05:23:41 -0700401 t->bios_characteristics = BIOS_CHARACTERISTICS_PCI_SUPPORTED |
402 BIOS_CHARACTERISTICS_SELECTABLE_BOOT |
403 BIOS_CHARACTERISTICS_UPGRADEABLE;
404#ifdef CONFIG_GENERATE_ACPI_TABLE
405 t->bios_characteristics_ext1 = BIOS_CHARACTERISTICS_EXT1_ACPI;
406#endif
Alexander Graf66f96e12016-08-19 01:23:29 +0200407#ifdef CONFIG_EFI_LOADER
Ilias Apalodimas15578bc2021-06-09 18:14:47 +0300408 t->bios_characteristics_ext2 |= BIOS_CHARACTERISTICS_EXT2_UEFI;
Alexander Graf66f96e12016-08-19 01:23:29 +0200409#endif
Ilias Apalodimas15578bc2021-06-09 18:14:47 +0300410 t->bios_characteristics_ext2 |= BIOS_CHARACTERISTICS_EXT2_TARGET;
Alexander Graf66f96e12016-08-19 01:23:29 +0200411
Simon Glassd7d16822021-02-04 21:17:16 -0700412 /* bios_major_release has only one byte, so drop century */
413 t->bios_major_release = U_BOOT_VERSION_NUM % 100;
414 t->bios_minor_release = U_BOOT_VERSION_NUM_PATCH;
Bin Mengae5bedb2015-10-12 05:23:41 -0700415 t->ec_major_release = 0xff;
416 t->ec_minor_release = 0xff;
417
Raymond Maof4b933d2024-12-06 14:54:18 -0800418 len = t->hdr.length + smbios_string_table_len(ctx);
Bin Mengae5bedb2015-10-12 05:23:41 -0700419 *current += len;
Simon Glass2d93add2018-11-22 13:46:37 -0700420 unmap_sysmem(t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700421
422 return len;
423}
424
Simon Glass8e5ddb02021-02-04 21:17:17 -0700425static int smbios_write_type1(ulong *current, int handle,
426 struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700427{
Simon Glass2d93add2018-11-22 13:46:37 -0700428 struct smbios_type1 *t;
Raymond Maof4b933d2024-12-06 14:54:18 -0800429 int len = sizeof(*t);
Simon Glass64b723f2017-08-03 12:22:12 -0600430 char *serial_str = env_get("serial#");
Bin Mengae5bedb2015-10-12 05:23:41 -0700431
Simon Glass2d93add2018-11-22 13:46:37 -0700432 t = map_sysmem(*current, len);
Raymond Maof4b933d2024-12-06 14:54:18 -0800433 memset(t, 0, len);
Bin Mengae5bedb2015-10-12 05:23:41 -0700434 fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
Simon Glassdff4e862021-02-04 21:17:18 -0700435 smbios_set_eos(ctx, t->eos);
Raymond Maoa28ef802024-12-06 14:54:22 -0800436
Michal Simeka7aa3952024-04-26 15:38:13 +0200437 t->manufacturer = smbios_add_prop_si(ctx, "manufacturer",
Simon Glassff3edc22024-10-31 18:50:23 +0100438 SYSID_SM_SYSTEM_MANUFACTURER,
Michal Simeka7aa3952024-04-26 15:38:13 +0200439 NULL);
440 t->product_name = smbios_add_prop_si(ctx, "product",
Raymond Maoa28ef802024-12-06 14:54:22 -0800441 SYSID_SM_SYSTEM_PRODUCT, NULL);
442 t->version = smbios_add_prop_si(ctx, "version", SYSID_SM_SYSTEM_VERSION,
Heinrich Schuchardte952b822024-01-29 14:09:36 +0100443 NULL);
Alexander Graf9a3e3e22016-08-19 01:23:31 +0200444 if (serial_str) {
Ilias Apalodimas07f3eba2023-12-07 11:18:49 +0200445 t->serial_number = smbios_add_prop(ctx, NULL, serial_str);
Raymond Maof4b933d2024-12-06 14:54:18 -0800446 strlcpy((char *)t->uuid, serial_str, sizeof(t->uuid));
Simon Glass6f3332a2020-11-05 06:32:08 -0700447 } else {
Michal Simeka7aa3952024-04-26 15:38:13 +0200448 t->serial_number = smbios_add_prop_si(ctx, "serial",
Simon Glassff3edc22024-10-31 18:50:23 +0100449 SYSID_SM_SYSTEM_SERIAL,
Michal Simeka7aa3952024-04-26 15:38:13 +0200450 NULL);
Alexander Graf9a3e3e22016-08-19 01:23:31 +0200451 }
Raymond Maoa28ef802024-12-06 14:54:22 -0800452 t->wakeup_type = smbios_get_val_si(ctx, "wakeup-type",
453 SYSID_SM_SYSTEM_WAKEUP,
454 SMBIOS_WAKEUP_TYPE_UNKNOWN);
455 t->sku_number = smbios_add_prop_si(ctx, "sku", SYSID_SM_SYSTEM_SKU,
456 NULL);
457 t->family = smbios_add_prop_si(ctx, "family", SYSID_SM_SYSTEM_FAMILY,
458 NULL);
Bin Mengae5bedb2015-10-12 05:23:41 -0700459
Raymond Maof4b933d2024-12-06 14:54:18 -0800460 len = t->hdr.length + smbios_string_table_len(ctx);
Bin Mengae5bedb2015-10-12 05:23:41 -0700461 *current += len;
Simon Glass2d93add2018-11-22 13:46:37 -0700462 unmap_sysmem(t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700463
464 return len;
465}
466
Simon Glass8e5ddb02021-02-04 21:17:17 -0700467static int smbios_write_type2(ulong *current, int handle,
468 struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700469{
Simon Glass2d93add2018-11-22 13:46:37 -0700470 struct smbios_type2 *t;
Raymond Maof4b933d2024-12-06 14:54:18 -0800471 int len = sizeof(*t);
Raymond Maoa28ef802024-12-06 14:54:22 -0800472 u8 *eos_addr;
Bin Mengae5bedb2015-10-12 05:23:41 -0700473
Raymond Maoa28ef802024-12-06 14:54:22 -0800474 /*
475 * reserve the space for the dynamic bytes of contained object handles.
476 * TODO: len += <obj_handle_num> * SMBIOS_TYPE2_CON_OBJ_HANDLE_SIZE
477 * obj_handle_num can be from DT node "baseboard" or sysinfo driver.
478 */
Simon Glass2d93add2018-11-22 13:46:37 -0700479 t = map_sysmem(*current, len);
Raymond Maof4b933d2024-12-06 14:54:18 -0800480 memset(t, 0, len);
Bin Mengae5bedb2015-10-12 05:23:41 -0700481 fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
Raymond Maoa28ef802024-12-06 14:54:22 -0800482
483 /* eos is at the end of the structure */
484 eos_addr = (u8 *)t + len - sizeof(t->eos);
485 smbios_set_eos(ctx, eos_addr);
486
Michal Simeka7aa3952024-04-26 15:38:13 +0200487 t->manufacturer = smbios_add_prop_si(ctx, "manufacturer",
Simon Glassff3edc22024-10-31 18:50:23 +0100488 SYSID_SM_BASEBOARD_MANUFACTURER,
Michal Simeka7aa3952024-04-26 15:38:13 +0200489 NULL);
490 t->product_name = smbios_add_prop_si(ctx, "product",
Raymond Maoa28ef802024-12-06 14:54:22 -0800491 SYSID_SM_BASEBOARD_PRODUCT, NULL);
Simon Glasscf67d6d2021-02-04 21:17:23 -0700492 t->version = smbios_add_prop_si(ctx, "version",
Raymond Maoa28ef802024-12-06 14:54:22 -0800493 SYSID_SM_BASEBOARD_VERSION, NULL);
Michal Simeka7aa3952024-04-26 15:38:13 +0200494 t->serial_number = smbios_add_prop_si(ctx, "serial",
Raymond Maoa28ef802024-12-06 14:54:22 -0800495 SYSID_SM_BASEBOARD_SERIAL, NULL);
Michal Simeka7aa3952024-04-26 15:38:13 +0200496 t->asset_tag_number = smbios_add_prop_si(ctx, "asset-tag",
Simon Glassff3edc22024-10-31 18:50:23 +0100497 SYSID_SM_BASEBOARD_ASSET_TAG,
Michal Simeka7aa3952024-04-26 15:38:13 +0200498 NULL);
Raymond Maoa28ef802024-12-06 14:54:22 -0800499 t->feature_flags = smbios_get_val_si(ctx, "feature-flags",
500 SYSID_SM_BASEBOARD_FEATURE, 0);
501
502 t->chassis_location =
503 smbios_add_prop_si(ctx, "chassis-location",
504 SYSID_SM_BASEBOARD_CHASSIS_LOCAT, NULL);
505 t->board_type = smbios_get_val_si(ctx, "board-type",
506 SYSID_SM_BASEBOARD_TYPE,
507 SMBIOS_BOARD_TYPE_UNKNOWN);
508
509 /*
510 * TODO:
511 * Populate the Contained Object Handles if they exist
512 * t->number_contained_objects = <obj_handle_num>;
513 */
514
Heinrich Schuchardtab8f4c82024-01-29 18:32:58 +0100515 t->chassis_handle = handle + 1;
Bin Mengae5bedb2015-10-12 05:23:41 -0700516
Raymond Maof4b933d2024-12-06 14:54:18 -0800517 len = t->hdr.length + smbios_string_table_len(ctx);
Bin Mengae5bedb2015-10-12 05:23:41 -0700518 *current += len;
Simon Glass2d93add2018-11-22 13:46:37 -0700519 unmap_sysmem(t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700520
521 return len;
522}
523
Simon Glass8e5ddb02021-02-04 21:17:17 -0700524static int smbios_write_type3(ulong *current, int handle,
525 struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700526{
Simon Glass2d93add2018-11-22 13:46:37 -0700527 struct smbios_type3 *t;
Raymond Maof4b933d2024-12-06 14:54:18 -0800528 int len = sizeof(*t);
Raymond Maoa28ef802024-12-06 14:54:22 -0800529 u8 *eos_addr;
530 size_t elem_size = 0;
531
532 /*
533 * reserve the space for the dynamic bytes of contained elements.
534 * TODO: elem_size = <element_count> * <element_record_length>
535 * element_count and element_record_length can be from DT node
536 * "chassis" or sysinfo driver.
537 */
538 len += elem_size;
Bin Mengae5bedb2015-10-12 05:23:41 -0700539
Simon Glass2d93add2018-11-22 13:46:37 -0700540 t = map_sysmem(*current, len);
Raymond Maof4b933d2024-12-06 14:54:18 -0800541 memset(t, 0, len);
Bin Mengae5bedb2015-10-12 05:23:41 -0700542 fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
Raymond Maoa28ef802024-12-06 14:54:22 -0800543
544 /* eos is at the end of the structure */
545 eos_addr = (u8 *)t + len - sizeof(t->eos);
546 smbios_set_eos(ctx, eos_addr);
547
548 t->manufacturer = smbios_add_prop_si(ctx, "manufacturer",
549 SYSID_SM_ENCLOSURE_MANUFACTURER,
550 NULL);
551 t->chassis_type = smbios_get_val_si(ctx, "chassis-type",
552 SYSID_SM_ENCLOSURE_TYPE,
553 SMBIOS_ENCLOSURE_UNKNOWN);
554 t->bootup_state = smbios_get_val_si(ctx, "bootup-state",
555 SYSID_SM_ENCLOSURE_BOOTUP,
556 SMBIOS_STATE_UNKNOWN);
557 t->power_supply_state = smbios_get_val_si(ctx, "power-supply-state",
558 SYSID_SM_ENCLOSURE_POW,
559 SMBIOS_STATE_UNKNOWN);
560 t->thermal_state = smbios_get_val_si(ctx, "thermal-state",
561 SYSID_SM_ENCLOSURE_THERMAL,
562 SMBIOS_STATE_UNKNOWN);
563 t->security_status = smbios_get_val_si(ctx, "security-status",
564 SYSID_SM_ENCLOSURE_SECURITY,
565 SMBIOS_SECURITY_UNKNOWN);
Bin Mengae5bedb2015-10-12 05:23:41 -0700566
Raymond Maof4b933d2024-12-06 14:54:18 -0800567 len = t->hdr.length + smbios_string_table_len(ctx);
Bin Mengae5bedb2015-10-12 05:23:41 -0700568 *current += len;
Simon Glass2d93add2018-11-22 13:46:37 -0700569 unmap_sysmem(t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700570
571 return len;
572}
573
Simon Glass8e5ddb02021-02-04 21:17:17 -0700574static void smbios_write_type4_dm(struct smbios_type4 *t,
575 struct smbios_ctx *ctx)
Alexander Grafe44b3c02016-08-19 01:23:28 +0200576{
577 u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
Heinrich Schuchardte952b822024-01-29 14:09:36 +0100578 const char *vendor = NULL;
579 const char *name = NULL;
Alexander Grafe44b3c02016-08-19 01:23:28 +0200580
581#ifdef CONFIG_CPU
582 char processor_name[49];
583 char vendor_name[49];
Simon Glass0dd7ca22020-11-05 06:32:07 -0700584 struct udevice *cpu = NULL;
Alexander Grafe44b3c02016-08-19 01:23:28 +0200585
Simon Glass0dd7ca22020-11-05 06:32:07 -0700586 uclass_find_first_device(UCLASS_CPU, &cpu);
587 if (cpu) {
Simon Glassb75b15b2020-12-03 16:55:23 -0700588 struct cpu_plat *plat = dev_get_parent_plat(cpu);
Alexander Grafe44b3c02016-08-19 01:23:28 +0200589
590 if (plat->family)
591 processor_family = plat->family;
592 t->processor_id[0] = plat->id[0];
593 t->processor_id[1] = plat->id[1];
594
Simon Glass0dd7ca22020-11-05 06:32:07 -0700595 if (!cpu_get_vendor(cpu, vendor_name, sizeof(vendor_name)))
Alexander Grafe44b3c02016-08-19 01:23:28 +0200596 vendor = vendor_name;
Simon Glass0dd7ca22020-11-05 06:32:07 -0700597 if (!cpu_get_desc(cpu, processor_name, sizeof(processor_name)))
Alexander Grafe44b3c02016-08-19 01:23:28 +0200598 name = processor_name;
599 }
600#endif
Raymond Maoa28ef802024-12-06 14:54:22 -0800601 if (processor_family == SMBIOS_PROCESSOR_FAMILY_UNKNOWN)
602 processor_family =
603 smbios_get_val_si(ctx, "family",
604 SYSID_SM_PROCESSOR_FAMILY,
605 SMBIOS_PROCESSOR_FAMILY_UNKNOWN);
Alexander Grafe44b3c02016-08-19 01:23:28 +0200606
Raymond Maoa28ef802024-12-06 14:54:22 -0800607 if (processor_family == SMBIOS_PROCESSOR_FAMILY_EXT)
608 t->processor_family2 =
609 smbios_get_val_si(ctx, "family2",
610 SYSID_SM_PROCESSOR_FAMILY2,
611 SMBIOS_PROCESSOR_FAMILY_UNKNOWN);
612
613 t->processor_family = processor_family;
614 t->processor_manufacturer =
615 smbios_add_prop_si(ctx, "manufacturer",
616 SYSID_SM_PROCESSOR_MANUFACT, vendor);
617 t->processor_version = smbios_add_prop_si(ctx, "version",
618 SYSID_SM_PROCESSOR_VERSION,
619 name);
Alexander Grafe44b3c02016-08-19 01:23:28 +0200620}
621
Simon Glass8e5ddb02021-02-04 21:17:17 -0700622static int smbios_write_type4(ulong *current, int handle,
623 struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700624{
Simon Glass2d93add2018-11-22 13:46:37 -0700625 struct smbios_type4 *t;
Raymond Maof4b933d2024-12-06 14:54:18 -0800626 int len = sizeof(*t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700627
Simon Glass2d93add2018-11-22 13:46:37 -0700628 t = map_sysmem(*current, len);
Raymond Maof4b933d2024-12-06 14:54:18 -0800629 memset(t, 0, len);
Bin Mengae5bedb2015-10-12 05:23:41 -0700630 fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
Simon Glassdff4e862021-02-04 21:17:18 -0700631 smbios_set_eos(ctx, t->eos);
Raymond Maoa28ef802024-12-06 14:54:22 -0800632 t->socket_design = smbios_add_prop_si(ctx, "socket-design",
633 SYSID_SM_PROCESSOR_SOCKET, NULL);
634 t->processor_type = smbios_get_val_si(ctx, "processor-type",
635 SYSID_SM_PROCESSOR_TYPE,
636 SMBIOS_PROCESSOR_TYPE_UNKNOWN);
Simon Glass8e5ddb02021-02-04 21:17:17 -0700637 smbios_write_type4_dm(t, ctx);
Raymond Maoa28ef802024-12-06 14:54:22 -0800638
639 t->status = smbios_get_val_si(ctx, "processor-status",
640 SYSID_SM_PROCESSOR_STATUS,
641 SMBIOS_PROCESSOR_STATUS_UNKNOWN);
642 t->processor_upgrade =
643 smbios_get_val_si(ctx, "upgrade", SYSID_SM_PROCESSOR_UPGRADE,
644 SMBIOS_PROCESSOR_UPGRADE_UNKNOWN);
645
646 t->l1_cache_handle = SMBIOS_CACHE_HANDLE_NONE;
647 t->l2_cache_handle = SMBIOS_CACHE_HANDLE_NONE;
648 t->l3_cache_handle = SMBIOS_CACHE_HANDLE_NONE;
Bin Mengae5bedb2015-10-12 05:23:41 -0700649
Raymond Maof4b933d2024-12-06 14:54:18 -0800650 len = t->hdr.length + smbios_string_table_len(ctx);
Bin Mengae5bedb2015-10-12 05:23:41 -0700651 *current += len;
Simon Glass2d93add2018-11-22 13:46:37 -0700652 unmap_sysmem(t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700653
654 return len;
655}
656
Simon Glass8e5ddb02021-02-04 21:17:17 -0700657static int smbios_write_type32(ulong *current, int handle,
658 struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700659{
Simon Glass2d93add2018-11-22 13:46:37 -0700660 struct smbios_type32 *t;
Raymond Maof4b933d2024-12-06 14:54:18 -0800661 int len = sizeof(*t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700662
Simon Glass2d93add2018-11-22 13:46:37 -0700663 t = map_sysmem(*current, len);
Raymond Maof4b933d2024-12-06 14:54:18 -0800664 memset(t, 0, len);
Bin Mengae5bedb2015-10-12 05:23:41 -0700665 fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle);
Simon Glassdff4e862021-02-04 21:17:18 -0700666 smbios_set_eos(ctx, t->eos);
Bin Mengae5bedb2015-10-12 05:23:41 -0700667
668 *current += len;
Simon Glass2d93add2018-11-22 13:46:37 -0700669 unmap_sysmem(t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700670
671 return len;
672}
673
Simon Glass8e5ddb02021-02-04 21:17:17 -0700674static int smbios_write_type127(ulong *current, int handle,
675 struct smbios_ctx *ctx)
Bin Mengae5bedb2015-10-12 05:23:41 -0700676{
Simon Glass2d93add2018-11-22 13:46:37 -0700677 struct smbios_type127 *t;
Raymond Maof4b933d2024-12-06 14:54:18 -0800678 int len = sizeof(*t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700679
Simon Glass2d93add2018-11-22 13:46:37 -0700680 t = map_sysmem(*current, len);
Raymond Maof4b933d2024-12-06 14:54:18 -0800681 memset(t, 0, len);
Bin Mengae5bedb2015-10-12 05:23:41 -0700682 fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle);
683
684 *current += len;
Simon Glass2d93add2018-11-22 13:46:37 -0700685 unmap_sysmem(t);
Bin Mengae5bedb2015-10-12 05:23:41 -0700686
687 return len;
688}
689
Simon Glass6f3332a2020-11-05 06:32:08 -0700690static struct smbios_write_method smbios_write_funcs[] = {
Simon Glassa05eb042021-02-04 21:17:20 -0700691 { smbios_write_type0, "bios", },
Simon Glass6f3332a2020-11-05 06:32:08 -0700692 { smbios_write_type1, "system", },
693 { smbios_write_type2, "baseboard", },
Heinrich Schuchardtab8f4c82024-01-29 18:32:58 +0100694 /* Type 3 must immediately follow type 2 due to chassis handle. */
Simon Glass6f3332a2020-11-05 06:32:08 -0700695 { smbios_write_type3, "chassis", },
Raymond Maoa28ef802024-12-06 14:54:22 -0800696 { smbios_write_type4, "processor"},
Simon Glass6f3332a2020-11-05 06:32:08 -0700697 { smbios_write_type32, },
698 { smbios_write_type127 },
Bin Mengae5bedb2015-10-12 05:23:41 -0700699};
700
Simon Glassca37a392017-01-16 07:03:35 -0700701ulong write_smbios_table(ulong addr)
Bin Mengae5bedb2015-10-12 05:23:41 -0700702{
Simon Glass6f3332a2020-11-05 06:32:08 -0700703 ofnode parent_node = ofnode_null();
Simon Glass3905e922023-12-31 08:25:45 -0700704 ulong table_addr, start_addr;
Simon Glassfc4b5522023-12-31 08:25:51 -0700705 struct smbios3_entry *se;
Simon Glass8e5ddb02021-02-04 21:17:17 -0700706 struct smbios_ctx ctx;
Simon Glassca37a392017-01-16 07:03:35 -0700707 ulong tables;
Bin Mengae5bedb2015-10-12 05:23:41 -0700708 int len = 0;
Bin Mengae5bedb2015-10-12 05:23:41 -0700709 int handle = 0;
Bin Mengae5bedb2015-10-12 05:23:41 -0700710 int i;
711
Simon Glass8e5ddb02021-02-04 21:17:17 -0700712 ctx.node = ofnode_null();
Raymond Maoa28ef802024-12-06 14:54:22 -0800713 if (CONFIG_IS_ENABLED(SYSINFO)) {
Simon Glass8e5ddb02021-02-04 21:17:17 -0700714 uclass_first_device(UCLASS_SYSINFO, &ctx.dev);
Michal Simek7d955002024-04-26 15:38:12 +0200715 if (ctx.dev) {
716 int ret;
717
Simon Glass8e5ddb02021-02-04 21:17:17 -0700718 parent_node = dev_read_subnode(ctx.dev, "smbios");
Michal Simek7d955002024-04-26 15:38:12 +0200719 ret = sysinfo_detect(ctx.dev);
Simon Glassbd5515d2024-06-23 14:30:33 -0600720
721 /*
722 * ignore the error since many boards don't implement
723 * this and we can still use the info in the devicetree
724 */
725 ret = log_msg_ret("sys", ret);
Michal Simek7d955002024-04-26 15:38:12 +0200726 }
Simon Glass8e5ddb02021-02-04 21:17:17 -0700727 } else {
728 ctx.dev = NULL;
Simon Glass0dd7ca22020-11-05 06:32:07 -0700729 }
730
Simon Glass3905e922023-12-31 08:25:45 -0700731 start_addr = addr;
Bin Mengae5bedb2015-10-12 05:23:41 -0700732
Simon Glassfc4b5522023-12-31 08:25:51 -0700733 /* move past the (so-far-unwritten) header to start writing structs */
734 addr = ALIGN(addr + sizeof(struct smbios3_entry), 16);
Bin Mengae5bedb2015-10-12 05:23:41 -0700735 tables = addr;
736
737 /* populate minimum required tables */
738 for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) {
Simon Glass6f3332a2020-11-05 06:32:08 -0700739 const struct smbios_write_method *method;
Simon Glass6f3332a2020-11-05 06:32:08 -0700740
741 method = &smbios_write_funcs[i];
Ilias Apalodimas5ae2d5c2024-01-11 16:39:36 +0200742 ctx.subnode_name = NULL;
743 if (method->subnode_name) {
744 ctx.subnode_name = method->subnode_name;
745 if (IS_ENABLED(CONFIG_OF_CONTROL))
746 ctx.node = ofnode_find_subnode(parent_node,
747 method->subnode_name);
748 }
Heinrich Schuchardt91f875a2024-01-31 23:42:35 +0100749 len += method->write((ulong *)&addr, handle++, &ctx);
Bin Mengae5bedb2015-10-12 05:23:41 -0700750 }
751
Simon Glass2d93add2018-11-22 13:46:37 -0700752 /*
753 * We must use a pointer here so things work correctly on sandbox. The
754 * user of this table is not aware of the mapping of addresses to
755 * sandbox's DRAM buffer.
756 */
757 table_addr = (ulong)map_sysmem(tables, 0);
Simon Glass2d93add2018-11-22 13:46:37 -0700758
Simon Glassfc4b5522023-12-31 08:25:51 -0700759 /* now go back and write the SMBIOS3 header */
Heinrich Schuchardt494d0722024-01-11 07:34:08 +0100760 se = map_sysmem(start_addr, sizeof(struct smbios3_entry));
761 memset(se, '\0', sizeof(struct smbios3_entry));
Simon Glassfc4b5522023-12-31 08:25:51 -0700762 memcpy(se->anchor, "_SM3_", 5);
763 se->length = sizeof(struct smbios3_entry);
764 se->major_ver = SMBIOS_MAJOR_VER;
765 se->minor_ver = SMBIOS_MINOR_VER;
766 se->doc_rev = 0;
767 se->entry_point_rev = 1;
Heinrich Schuchardt68e948a2024-01-31 23:49:34 +0100768 se->table_maximum_size = len;
Simon Glassfc4b5522023-12-31 08:25:51 -0700769 se->struct_table_address = table_addr;
770 se->checksum = table_compute_checksum(se, sizeof(struct smbios3_entry));
771 unmap_sysmem(se);
Bin Mengae5bedb2015-10-12 05:23:41 -0700772
773 return addr;
774}