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(ulong
*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(ulong
*current
, int handle
)
113 struct smbios_type1
*t
= (struct smbios_type1
*)*current
;
114 int len
= sizeof(struct smbios_type1
);
115 char *serial_str
= getenv("serial#");
117 memset(t
, 0, sizeof(struct smbios_type1
));
118 fill_smbios_header(t
, SMBIOS_SYSTEM_INFORMATION
, len
, handle
);
119 t
->manufacturer
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_MANUFACTURER
);
120 t
->product_name
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_PRODUCT_NAME
);
122 strncpy((char*)t
->uuid
, serial_str
, sizeof(t
->uuid
));
123 t
->serial_number
= smbios_add_string(t
->eos
, serial_str
);
126 len
= t
->length
+ smbios_string_table_len(t
->eos
);
132 static int smbios_write_type2(ulong
*current
, int handle
)
134 struct smbios_type2
*t
= (struct smbios_type2
*)*current
;
135 int len
= sizeof(struct smbios_type2
);
137 memset(t
, 0, sizeof(struct smbios_type2
));
138 fill_smbios_header(t
, SMBIOS_BOARD_INFORMATION
, len
, handle
);
139 t
->manufacturer
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_MANUFACTURER
);
140 t
->product_name
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_PRODUCT_NAME
);
141 t
->feature_flags
= SMBIOS_BOARD_FEATURE_HOSTING
;
142 t
->board_type
= SMBIOS_BOARD_MOTHERBOARD
;
144 len
= t
->length
+ smbios_string_table_len(t
->eos
);
150 static int smbios_write_type3(ulong
*current
, int handle
)
152 struct smbios_type3
*t
= (struct smbios_type3
*)*current
;
153 int len
= sizeof(struct smbios_type3
);
155 memset(t
, 0, sizeof(struct smbios_type3
));
156 fill_smbios_header(t
, SMBIOS_SYSTEM_ENCLOSURE
, len
, handle
);
157 t
->manufacturer
= smbios_add_string(t
->eos
, CONFIG_SMBIOS_MANUFACTURER
);
158 t
->chassis_type
= SMBIOS_ENCLOSURE_DESKTOP
;
159 t
->bootup_state
= SMBIOS_STATE_SAFE
;
160 t
->power_supply_state
= SMBIOS_STATE_SAFE
;
161 t
->thermal_state
= SMBIOS_STATE_SAFE
;
162 t
->security_status
= SMBIOS_SECURITY_NONE
;
164 len
= t
->length
+ smbios_string_table_len(t
->eos
);
170 static void smbios_write_type4_dm(struct smbios_type4
*t
)
172 u16 processor_family
= SMBIOS_PROCESSOR_FAMILY_UNKNOWN
;
173 const char *vendor
= "Unknown";
174 const char *name
= "Unknown";
177 char processor_name
[49];
178 char vendor_name
[49];
179 struct udevice
*dev
= NULL
;
181 uclass_find_first_device(UCLASS_CPU
, &dev
);
183 struct cpu_platdata
*plat
= dev_get_parent_platdata(dev
);
186 processor_family
= plat
->family
;
187 t
->processor_id
[0] = plat
->id
[0];
188 t
->processor_id
[1] = plat
->id
[1];
190 if (!cpu_get_vendor(dev
, vendor_name
, sizeof(vendor_name
)))
191 vendor
= vendor_name
;
192 if (!cpu_get_desc(dev
, processor_name
, sizeof(processor_name
)))
193 name
= processor_name
;
197 t
->processor_family
= processor_family
;
198 t
->processor_manufacturer
= smbios_add_string(t
->eos
, vendor
);
199 t
->processor_version
= smbios_add_string(t
->eos
, name
);
202 static int smbios_write_type4(ulong
*current
, int handle
)
204 struct smbios_type4
*t
= (struct smbios_type4
*)*current
;
205 int len
= sizeof(struct smbios_type4
);
207 memset(t
, 0, sizeof(struct smbios_type4
));
208 fill_smbios_header(t
, SMBIOS_PROCESSOR_INFORMATION
, len
, handle
);
209 t
->processor_type
= SMBIOS_PROCESSOR_TYPE_CENTRAL
;
210 smbios_write_type4_dm(t
);
211 t
->status
= SMBIOS_PROCESSOR_STATUS_ENABLED
;
212 t
->processor_upgrade
= SMBIOS_PROCESSOR_UPGRADE_NONE
;
213 t
->l1_cache_handle
= 0xffff;
214 t
->l2_cache_handle
= 0xffff;
215 t
->l3_cache_handle
= 0xffff;
216 t
->processor_family2
= t
->processor_family
;
218 len
= t
->length
+ smbios_string_table_len(t
->eos
);
224 static int smbios_write_type32(ulong
*current
, int handle
)
226 struct smbios_type32
*t
= (struct smbios_type32
*)*current
;
227 int len
= sizeof(struct smbios_type32
);
229 memset(t
, 0, sizeof(struct smbios_type32
));
230 fill_smbios_header(t
, SMBIOS_SYSTEM_BOOT_INFORMATION
, len
, handle
);
237 static int smbios_write_type127(ulong
*current
, int handle
)
239 struct smbios_type127
*t
= (struct smbios_type127
*)*current
;
240 int len
= sizeof(struct smbios_type127
);
242 memset(t
, 0, sizeof(struct smbios_type127
));
243 fill_smbios_header(t
, SMBIOS_END_OF_TABLE
, len
, handle
);
250 static smbios_write_type smbios_write_funcs
[] = {
260 ulong
write_smbios_table(ulong addr
)
262 struct smbios_entry
*se
;
265 int max_struct_size
= 0;
271 /* 16 byte align the table address */
272 addr
= ALIGN(addr
, 16);
274 se
= (struct smbios_entry
*)(uintptr_t)addr
;
275 memset(se
, 0, sizeof(struct smbios_entry
));
277 addr
+= sizeof(struct smbios_entry
);
278 addr
= ALIGN(addr
, 16);
281 /* populate minimum required tables */
282 for (i
= 0; i
< ARRAY_SIZE(smbios_write_funcs
); i
++) {
283 int tmp
= smbios_write_funcs
[i
]((ulong
*)&addr
, handle
++);
284 max_struct_size
= max(max_struct_size
, tmp
);
288 memcpy(se
->anchor
, "_SM_", 4);
289 se
->length
= sizeof(struct smbios_entry
);
290 se
->major_ver
= SMBIOS_MAJOR_VER
;
291 se
->minor_ver
= SMBIOS_MINOR_VER
;
292 se
->max_struct_size
= max_struct_size
;
293 memcpy(se
->intermediate_anchor
, "_DMI_", 5);
294 se
->struct_table_length
= len
;
295 se
->struct_table_address
= tables
;
296 se
->struct_count
= handle
;
298 /* calculate checksums */
299 istart
= (char *)se
+ SMBIOS_INTERMEDIATE_OFFSET
;
300 isize
= sizeof(struct smbios_entry
) - SMBIOS_INTERMEDIATE_OFFSET
;
301 se
->intermediate_checksum
= table_compute_checksum(istart
, isize
);
302 se
->checksum
= table_compute_checksum(se
, sizeof(struct smbios_entry
));