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 #ifdef CONFIG_ROM_SIZE
87 t->bios_rom_size = (CONFIG_ROM_SIZE / 65536) - 1;
89 t->bios_characteristics = BIOS_CHARACTERISTICS_PCI_SUPPORTED |
90 BIOS_CHARACTERISTICS_SELECTABLE_BOOT |
91 BIOS_CHARACTERISTICS_UPGRADEABLE;
92 #ifdef CONFIG_GENERATE_ACPI_TABLE
93 t->bios_characteristics_ext1 = BIOS_CHARACTERISTICS_EXT1_ACPI;
95 #ifdef CONFIG_EFI_LOADER
96 t->bios_characteristics_ext1 |= BIOS_CHARACTERISTICS_EXT1_UEFI;
98 t->bios_characteristics_ext2 = BIOS_CHARACTERISTICS_EXT2_TARGET;
100 t->bios_major_release = 0xff;
101 t->bios_minor_release = 0xff;
102 t->ec_major_release = 0xff;
103 t->ec_minor_release = 0xff;
105 len = t->length + smbios_string_table_len(t->eos);
111 static int smbios_write_type1(uintptr_t *current, int handle)
113 struct smbios_type1 *t = (struct smbios_type1 *)*current;
114 int len = sizeof(struct smbios_type1);
116 memset(t, 0, sizeof(struct smbios_type1));
117 fill_smbios_header(t, SMBIOS_SYSTEM_INFORMATION, len, handle);
118 t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
119 t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME);
121 len = t->length + smbios_string_table_len(t->eos);
127 static int smbios_write_type2(uintptr_t *current, int handle)
129 struct smbios_type2 *t = (struct smbios_type2 *)*current;
130 int len = sizeof(struct smbios_type2);
132 memset(t, 0, sizeof(struct smbios_type2));
133 fill_smbios_header(t, SMBIOS_BOARD_INFORMATION, len, handle);
134 t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
135 t->product_name = smbios_add_string(t->eos, CONFIG_SMBIOS_PRODUCT_NAME);
136 t->feature_flags = SMBIOS_BOARD_FEATURE_HOSTING;
137 t->board_type = SMBIOS_BOARD_MOTHERBOARD;
139 len = t->length + smbios_string_table_len(t->eos);
145 static int smbios_write_type3(uintptr_t *current, int handle)
147 struct smbios_type3 *t = (struct smbios_type3 *)*current;
148 int len = sizeof(struct smbios_type3);
150 memset(t, 0, sizeof(struct smbios_type3));
151 fill_smbios_header(t, SMBIOS_SYSTEM_ENCLOSURE, len, handle);
152 t->manufacturer = smbios_add_string(t->eos, CONFIG_SMBIOS_MANUFACTURER);
153 t->chassis_type = SMBIOS_ENCLOSURE_DESKTOP;
154 t->bootup_state = SMBIOS_STATE_SAFE;
155 t->power_supply_state = SMBIOS_STATE_SAFE;
156 t->thermal_state = SMBIOS_STATE_SAFE;
157 t->security_status = SMBIOS_SECURITY_NONE;
159 len = t->length + smbios_string_table_len(t->eos);
165 static void smbios_write_type4_dm(struct smbios_type4 *t)
167 u16 processor_family = SMBIOS_PROCESSOR_FAMILY_UNKNOWN;
168 const char *vendor = "Unknown";
169 const char *name = "Unknown";
172 char processor_name[49];
173 char vendor_name[49];
174 struct udevice *dev = NULL;
176 uclass_find_first_device(UCLASS_CPU, &dev);
178 struct cpu_platdata *plat = dev_get_parent_platdata(dev);
181 processor_family = plat->family;
182 t->processor_id[0] = plat->id[0];
183 t->processor_id[1] = plat->id[1];
185 if (!cpu_get_vendor(dev, vendor_name, sizeof(vendor_name)))
186 vendor = vendor_name;
187 if (!cpu_get_desc(dev, processor_name, sizeof(processor_name)))
188 name = processor_name;
192 t->processor_family = processor_family;
193 t->processor_manufacturer = smbios_add_string(t->eos, vendor);
194 t->processor_version = smbios_add_string(t->eos, name);
197 static int smbios_write_type4(uintptr_t *current, int handle)
199 struct smbios_type4 *t = (struct smbios_type4 *)*current;
200 int len = sizeof(struct smbios_type4);
202 memset(t, 0, sizeof(struct smbios_type4));
203 fill_smbios_header(t, SMBIOS_PROCESSOR_INFORMATION, len, handle);
204 t->processor_type = SMBIOS_PROCESSOR_TYPE_CENTRAL;
205 smbios_write_type4_dm(t);
206 t->status = SMBIOS_PROCESSOR_STATUS_ENABLED;
207 t->processor_upgrade = SMBIOS_PROCESSOR_UPGRADE_NONE;
208 t->l1_cache_handle = 0xffff;
209 t->l2_cache_handle = 0xffff;
210 t->l3_cache_handle = 0xffff;
211 t->processor_family2 = t->processor_family;
213 len = t->length + smbios_string_table_len(t->eos);
219 static int smbios_write_type32(uintptr_t *current, int handle)
221 struct smbios_type32 *t = (struct smbios_type32 *)*current;
222 int len = sizeof(struct smbios_type32);
224 memset(t, 0, sizeof(struct smbios_type32));
225 fill_smbios_header(t, SMBIOS_SYSTEM_BOOT_INFORMATION, len, handle);
232 static int smbios_write_type127(uintptr_t *current, int handle)
234 struct smbios_type127 *t = (struct smbios_type127 *)*current;
235 int len = sizeof(struct smbios_type127);
237 memset(t, 0, sizeof(struct smbios_type127));
238 fill_smbios_header(t, SMBIOS_END_OF_TABLE, len, handle);
245 static smbios_write_type smbios_write_funcs[] = {
255 uintptr_t write_smbios_table(uintptr_t addr)
257 struct smbios_entry *se;
260 int max_struct_size = 0;
266 /* 16 byte align the table address */
267 addr = ALIGN(addr, 16);
269 se = (struct smbios_entry *)addr;
270 memset(se, 0, sizeof(struct smbios_entry));
272 addr += sizeof(struct smbios_entry);
273 addr = ALIGN(addr, 16);
276 /* populate minimum required tables */
277 for (i = 0; i < ARRAY_SIZE(smbios_write_funcs); i++) {
278 int tmp = smbios_write_funcs[i](&addr, handle++);
279 max_struct_size = max(max_struct_size, tmp);
283 memcpy(se->anchor, "_SM_", 4);
284 se->length = sizeof(struct smbios_entry);
285 se->major_ver = SMBIOS_MAJOR_VER;
286 se->minor_ver = SMBIOS_MINOR_VER;
287 se->max_struct_size = max_struct_size;
288 memcpy(se->intermediate_anchor, "_DMI_", 5);
289 se->struct_table_length = len;
290 se->struct_table_address = tables;
291 se->struct_count = handle;
293 /* calculate checksums */
294 istart = (char *)se + SMBIOS_INTERMEDIATE_OFFSET;
295 isize = sizeof(struct smbios_entry) - SMBIOS_INTERMEDIATE_OFFSET;
296 se->intermediate_checksum = table_compute_checksum(istart, isize);
297 se->checksum = table_compute_checksum(se, sizeof(struct smbios_entry));