1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015, Bin Meng <bmeng.cn@gmail.com>
5 * Adapted from coreboot src/arch/x86/smbios.c
11 #include <tables_csum.h>
16 #include <dm/uclass-internal.h>
20 * smbios_add_string() - add a string to the string area
22 * This adds a string to the string area which is appended directly after
23 * the formatted portion of an SMBIOS structure.
25 * @start: string area start address
27 * @return: string number in the string area
29 static int smbios_add_string(char *start
, const char *str
)
53 * smbios_string_table_len() - compute the string area size
55 * This computes the size of the string area including the string terminator.
57 * @start: string area start address
58 * @return: string area size
60 static int smbios_string_table_len(char *start
)
74 static int smbios_write_type0(ulong
*current
, int handle
)
76 struct smbios_type0
*t
;
77 int len
= sizeof(struct smbios_type0
);
79 t
= map_sysmem(*current
, len
);
80 memset(t
, 0, sizeof(struct smbios_type0
));
81 fill_smbios_header(t
, SMBIOS_BIOS_INFORMATION
, len
, handle
);
82 t
->vendor
= smbios_add_string(t
->eos
, "U-Boot");
83 t
->bios_ver
= smbios_add_string(t
->eos
, PLAIN_VERSION
);
84 t
->bios_release_date
= smbios_add_string(t
->eos
, U_BOOT_DMI_DATE
);
85 #ifdef CONFIG_ROM_SIZE
86 t
->bios_rom_size
= (CONFIG_ROM_SIZE
/ 65536) - 1;
88 t
->bios_characteristics
= BIOS_CHARACTERISTICS_PCI_SUPPORTED
|
89 BIOS_CHARACTERISTICS_SELECTABLE_BOOT
|
90 BIOS_CHARACTERISTICS_UPGRADEABLE
;
91 #ifdef CONFIG_GENERATE_ACPI_TABLE
92 t
->bios_characteristics_ext1
= BIOS_CHARACTERISTICS_EXT1_ACPI
;
94 #ifdef CONFIG_EFI_LOADER
95 t
->bios_characteristics_ext1
|= BIOS_CHARACTERISTICS_EXT1_UEFI
;
97 t
->bios_characteristics_ext2
= BIOS_CHARACTERISTICS_EXT2_TARGET
;
99 t
->bios_major_release
= 0xff;
100 t
->bios_minor_release
= 0xff;
101 t
->ec_major_release
= 0xff;
102 t
->ec_minor_release
= 0xff;
104 len
= t
->length
+ smbios_string_table_len(t
->eos
);
111 static int smbios_write_type1(ulong
*current
, int handle
)
113 struct smbios_type1
*t
;
114 int len
= sizeof(struct smbios_type1
);
115 char *serial_str
= env_get("serial#");
117 t
= map_sysmem(*current
, len
);
118 memset(t
, 0, sizeof(struct smbios_type1
));
119 fill_smbios_header(t
, SMBIOS_SYSTEM_INFORMATION
, len
, handle
);
120 t
->manufacturer
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_MANUFACTURER
);
121 t
->product_name
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_PRODUCT_NAME
);
123 strncpy((char *)t
->uuid
, serial_str
, sizeof(t
->uuid
));
124 t
->serial_number
= smbios_add_string(t
->eos
, serial_str
);
127 len
= t
->length
+ smbios_string_table_len(t
->eos
);
134 static int smbios_write_type2(ulong
*current
, int handle
)
136 struct smbios_type2
*t
;
137 int len
= sizeof(struct smbios_type2
);
139 t
= map_sysmem(*current
, len
);
140 memset(t
, 0, sizeof(struct smbios_type2
));
141 fill_smbios_header(t
, SMBIOS_BOARD_INFORMATION
, len
, handle
);
142 t
->manufacturer
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_MANUFACTURER
);
143 t
->product_name
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_PRODUCT_NAME
);
144 t
->feature_flags
= SMBIOS_BOARD_FEATURE_HOSTING
;
145 t
->board_type
= SMBIOS_BOARD_MOTHERBOARD
;
147 len
= t
->length
+ smbios_string_table_len(t
->eos
);
154 static int smbios_write_type3(ulong
*current
, int handle
)
156 struct smbios_type3
*t
;
157 int len
= sizeof(struct smbios_type3
);
159 t
= map_sysmem(*current
, len
);
160 memset(t
, 0, sizeof(struct smbios_type3
));
161 fill_smbios_header(t
, SMBIOS_SYSTEM_ENCLOSURE
, len
, handle
);
162 t
->manufacturer
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_MANUFACTURER
);
163 t
->chassis_type
= SMBIOS_ENCLOSURE_DESKTOP
;
164 t
->bootup_state
= SMBIOS_STATE_SAFE
;
165 t
->power_supply_state
= SMBIOS_STATE_SAFE
;
166 t
->thermal_state
= SMBIOS_STATE_SAFE
;
167 t
->security_status
= SMBIOS_SECURITY_NONE
;
169 len
= t
->length
+ smbios_string_table_len(t
->eos
);
176 static void smbios_write_type4_dm(struct smbios_type4
*t
)
178 u16 processor_family
= SMBIOS_PROCESSOR_FAMILY_UNKNOWN
;
179 const char *vendor
= "Unknown";
180 const char *name
= "Unknown";
183 char processor_name
[49];
184 char vendor_name
[49];
185 struct udevice
*dev
= NULL
;
187 uclass_find_first_device(UCLASS_CPU
, &dev
);
189 struct cpu_platdata
*plat
= dev_get_parent_platdata(dev
);
192 processor_family
= plat
->family
;
193 t
->processor_id
[0] = plat
->id
[0];
194 t
->processor_id
[1] = plat
->id
[1];
196 if (!cpu_get_vendor(dev
, vendor_name
, sizeof(vendor_name
)))
197 vendor
= vendor_name
;
198 if (!cpu_get_desc(dev
, processor_name
, sizeof(processor_name
)))
199 name
= processor_name
;
203 t
->processor_family
= processor_family
;
204 t
->processor_manufacturer
= smbios_add_string(t
->eos
, vendor
);
205 t
->processor_version
= smbios_add_string(t
->eos
, name
);
208 static int smbios_write_type4(ulong
*current
, int handle
)
210 struct smbios_type4
*t
;
211 int len
= sizeof(struct smbios_type4
);
213 t
= map_sysmem(*current
, len
);
214 memset(t
, 0, sizeof(struct smbios_type4
));
215 fill_smbios_header(t
, SMBIOS_PROCESSOR_INFORMATION
, len
, handle
);
216 t
->processor_type
= SMBIOS_PROCESSOR_TYPE_CENTRAL
;
217 smbios_write_type4_dm(t
);
218 t
->status
= SMBIOS_PROCESSOR_STATUS_ENABLED
;
219 t
->processor_upgrade
= SMBIOS_PROCESSOR_UPGRADE_NONE
;
220 t
->l1_cache_handle
= 0xffff;
221 t
->l2_cache_handle
= 0xffff;
222 t
->l3_cache_handle
= 0xffff;
223 t
->processor_family2
= t
->processor_family
;
225 len
= t
->length
+ smbios_string_table_len(t
->eos
);
232 static int smbios_write_type32(ulong
*current
, int handle
)
234 struct smbios_type32
*t
;
235 int len
= sizeof(struct smbios_type32
);
237 t
= map_sysmem(*current
, len
);
238 memset(t
, 0, sizeof(struct smbios_type32
));
239 fill_smbios_header(t
, SMBIOS_SYSTEM_BOOT_INFORMATION
, len
, handle
);
247 static int smbios_write_type127(ulong
*current
, int handle
)
249 struct smbios_type127
*t
;
250 int len
= sizeof(struct smbios_type127
);
252 t
= map_sysmem(*current
, len
);
253 memset(t
, 0, sizeof(struct smbios_type127
));
254 fill_smbios_header(t
, SMBIOS_END_OF_TABLE
, len
, handle
);
262 static smbios_write_type smbios_write_funcs
[] = {
272 ulong
write_smbios_table(ulong addr
)
274 struct smbios_entry
*se
;
278 int max_struct_size
= 0;
284 /* 16 byte align the table address */
285 addr
= ALIGN(addr
, 16);
287 se
= map_sysmem(addr
, sizeof(struct smbios_entry
));
288 memset(se
, 0, sizeof(struct smbios_entry
));
290 addr
+= sizeof(struct smbios_entry
);
291 addr
= ALIGN(addr
, 16);
294 /* populate minimum required tables */
295 for (i
= 0; i
< ARRAY_SIZE(smbios_write_funcs
); i
++) {
296 int tmp
= smbios_write_funcs
[i
]((ulong
*)&addr
, handle
++);
298 max_struct_size
= max(max_struct_size
, tmp
);
302 memcpy(se
->anchor
, "_SM_", 4);
303 se
->length
= sizeof(struct smbios_entry
);
304 se
->major_ver
= SMBIOS_MAJOR_VER
;
305 se
->minor_ver
= SMBIOS_MINOR_VER
;
306 se
->max_struct_size
= max_struct_size
;
307 memcpy(se
->intermediate_anchor
, "_DMI_", 5);
308 se
->struct_table_length
= len
;
311 * We must use a pointer here so things work correctly on sandbox. The
312 * user of this table is not aware of the mapping of addresses to
313 * sandbox's DRAM buffer.
315 table_addr
= (ulong
)map_sysmem(tables
, 0);
316 if (sizeof(table_addr
) > sizeof(u32
) && table_addr
> (ulong
)UINT_MAX
) {
318 * We need to put this >32-bit pointer into the table but the
319 * field is only 32 bits wide.
321 printf("WARNING: SMBIOS table_address overflow %llx\n",
322 (unsigned long long)table_addr
);
325 se
->struct_table_address
= table_addr
;
327 se
->struct_count
= handle
;
329 /* calculate checksums */
330 istart
= (char *)se
+ SMBIOS_INTERMEDIATE_OFFSET
;
331 isize
= sizeof(struct smbios_entry
) - SMBIOS_INTERMEDIATE_OFFSET
;
332 se
->intermediate_checksum
= table_compute_checksum(istart
, isize
);
333 se
->checksum
= table_compute_checksum(se
, sizeof(struct smbios_entry
));