2 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
4 * Adapted from coreboot src/arch/x86/smbios.c
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <tables_csum.h>
16 #include <dm/uclass-internal.h>
19 DECLARE_GLOBAL_DATA_PTR;
22 * smbios_add_string() - add a string to the string area
24 * This adds a string to the string area which is appended directly after
25 * the formatted portion of an SMBIOS structure.
27 * @start: string area start address
29 * @return: string number in the string area
31 static int smbios_add_string(char *start, const char *str)
55 * smbios_string_table_len() - compute the string area size
57 * This computes the size of the string area including the string terminator.
59 * @start: string area start address
60 * @return: string area size
62 static int smbios_string_table_len(char *start)
76 static int smbios_write_type0(uintptr_t *current, int handle)
78 struct smbios_type0 *t = (struct smbios_type0 *)*current;
79 int len = sizeof(struct smbios_type0);
81 memset(t, 0, sizeof(struct smbios_type0));
82 fill_smbios_header(t, SMBIOS_BIOS_INFORMATION, len, handle);
83 t->vendor = smbios_add_string(t->eos, "U-Boot");
84 t->bios_ver = smbios_add_string(t->eos, PLAIN_VERSION);
85 t->bios_release_date = smbios_add_string(t->eos, U_BOOT_DMI_DATE);
86 t->bios_rom_size = (CONFIG_ROM_SIZE / 65536) - 1;
87 t->bios_characteristics = BIOS_CHARACTERISTICS_PCI_SUPPORTED |
88 BIOS_CHARACTERISTICS_SELECTABLE_BOOT |
89 BIOS_CHARACTERISTICS_UPGRADEABLE;
90 #ifdef CONFIG_GENERATE_ACPI_TABLE
91 t->bios_characteristics_ext1 = BIOS_CHARACTERISTICS_EXT1_ACPI;
93 t->bios_characteristics_ext2 = BIOS_CHARACTERISTICS_EXT2_TARGET;
94 t->bios_major_release = 0xff;
95 t->bios_minor_release = 0xff;
96 t->ec_major_release = 0xff;
97 t->ec_minor_release = 0xff;
99 len = t->length + smbios_string_table_len(t->eos);
105 static int smbios_write_type1(uintptr_t *current, int handle)
107 struct smbios_type1 *t = (struct smbios_type1 *)*current;
108 int len = sizeof(struct smbios_type1);
110 memset(t, 0, sizeof(struct smbios_type1));
111 fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
112 t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
113 t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME);
115 len = t->length + smbios_string_table_len(t->eos);
121 static int smbios_write_type2(uintptr_t *current, int handle)
123 struct smbios_type2 *t = (struct smbios_type2 *)*current;
124 int len = sizeof(struct smbios_type2);
126 memset(t, 0, sizeof(struct smbios_type2));
127 fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
128 t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
129 t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME);
130 t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING;
131 t->board_type = SMBIOS_BOARD_MOTHERBOARD;
133 len = t->length + smbios_string_table_len(t->eos);
139 static int smbios_write_type3(uintptr_t *current, int handle)
141 struct smbios_type3 *t = (struct smbios_type3 *)*current;
142 int len = sizeof(struct smbios_type3);
144 memset(t, 0, sizeof(struct smbios_type3));
145 fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
146 t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
147 t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP;
148 t->bootup_state = SMBIOS_STATE_SAFE;
149 t->power_supply_state = SMBIOS_STATE_SAFE;
150 t->thermal_state = SMBIOS_STATE_SAFE;
151 t->security_status = SMBIOS_SECURITY_NONE;
153 len = t->length + smbios_string_table_len(t->eos);
159 static void smbios_write_type4_dm(struct smbios_type4 *t)
161 u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
162 const char *vendor = "Unknown";
163 const char *name = "Unknown";
166 char processor_name[49];
167 char vendor_name[49];
168 struct udevice *dev = NULL;
170 uclass_find_first_device(UCLASS_CPU, &dev);
172 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
175 processor_family = plat->family;
176 t->processor_id[0] = plat->id[0];
177 t->processor_id[1] = plat->id[1];
179 if (!cpu_get_vendor(dev, vendor_name, sizeof(vendor_name)))
180 vendor = vendor_name;
181 if (!cpu_get_desc(dev, processor_name, sizeof(processor_name)))
182 name = processor_name;
186 t->processor_family = processor_family;
187 t->processor_manufacturer = smbios_add_string(t->eos, vendor);
188 t->processor_version = smbios_add_string(t->eos, name);
191 static int smbios_write_type4(uintptr_t *current, int handle)
193 struct smbios_type4 *t = (struct smbios_type4 *)*current;
194 int len = sizeof(struct smbios_type4);
196 memset(t, 0, sizeof(struct smbios_type4));
197 fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
198 t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL;
199 smbios_write_type4_dm(t);
200 t->status = SMBIOS_PROCESSOR_STATUS_ENABLED;
201 t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE;
202 t->l1_cache_handle = 0xffff;
203 t->l2_cache_handle = 0xffff;
204 t->l3_cache_handle = 0xffff;
205 t->processor_family2 = t->processor_family;
207 len = t->length + smbios_string_table_len(t->eos);
213 static int smbios_write_type32(uintptr_t *current, int handle)
215 struct smbios_type32 *t = (struct smbios_type32 *)*current;
216 int len = sizeof(struct smbios_type32);
218 memset(t, 0, sizeof(struct smbios_type32));
219 fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle);
226 static int smbios_write_type127(uintptr_t *current, int handle)
228 struct smbios_type127 *t = (struct smbios_type127 *)*current;
229 int len = sizeof(struct smbios_type127);
231 memset(t, 0, sizeof(struct smbios_type127));
232 fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle);
239 static smbios_write_type smbios_write_funcs[] = {
249 uintptr_t write_smbios_table(uintptr_t addr)
251 struct smbios_entry *se;
254 int max_struct_size = 0;
260 /* 16 byte align the table address */
261 addr = ALIGN(addr, 16);
263 se = (struct smbios_entry *)addr;
264 memset(se, 0, sizeof(struct smbios_entry));
266 addr += sizeof(struct smbios_entry);
267 addr = ALIGN(addr, 16);
270 /* populate minimum required tables */
271 for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) {
272 int tmp = smbios_write_funcs[i](&addr, handle++);
273 max_struct_size = max(max_struct_size, tmp);
277 memcpy(se->anchor, "_SM_", 4);
278 se->length = sizeof(struct smbios_entry);
279 se->major_ver = SMBIOS_MAJOR_VER;
280 se->minor_ver = SMBIOS_MINOR_VER;
281 se->max_struct_size = max_struct_size;
282 memcpy(se->intermediate_anchor, "_DMI_", 5);
283 se->struct_table_length = len;
284 se->struct_table_address = tables;
285 se->struct_count = handle;
287 /* calculate checksums */
288 istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
289 isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET;
290 se->intermediate_checksum = table_compute_checksum(istart, isize);
291 se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry));