1 // smbios table generation (on emulators)
3 // Copyright (C) 2008 Kevin O'Connor <kevin@koconnor.net>
4 // Copyright (C) 2006 Fabrice Bellard
6 // This file may be distributed under the terms of the GNU LGPLv3 license.
8 #include "util.h" // dprintf
9 #include "memmap.h" // bios_table_cur_addr
10 #include "biosvar.h" // GET_EBDA
13 /****************************************************************
15 ****************************************************************/
17 #define QEMU_CFG_SIGNATURE 0x00
18 #define QEMU_CFG_ID 0x01
19 #define QEMU_CFG_UUID 0x02
22 qemu_cfg_read(u8 *buf, u16 f, int len)
24 outw(f, PORT_QEMU_CFG_CTL);
26 *(buf++) = inb(PORT_QEMU_CFG_DATA);
34 qemu_cfg_read(buf, QEMU_CFG_SIGNATURE, 4);
35 return *(u32*)buf == *(u32*)sig;
39 uuid_probe(u8 *bios_uuid)
41 // Default to UUID not set
42 memset(bios_uuid, 0, 16);
44 if (! CONFIG_UUID_BACKDOOR)
48 if (! qemu_cfg_port_probe())
49 // Feature not available
52 qemu_cfg_read(bios_uuid, QEMU_CFG_UUID, 16);
56 /****************************************************************
58 ****************************************************************/
60 /* SMBIOS entry point -- must be written to a 16-bit aligned address
61 between 0xf0000 and 0xfffff.
63 struct smbios_entry_point {
64 char anchor_string[4];
67 u8 smbios_major_version;
68 u8 smbios_minor_version;
69 u16 max_structure_size;
70 u8 entry_point_revision;
72 char intermediate_anchor_string[5];
73 u8 intermediate_checksum;
74 u16 structure_table_length;
75 u32 structure_table_address;
76 u16 number_of_structures;
77 u8 smbios_bcd_revision;
80 /* This goes at the beginning of every SMBIOS structure. */
81 struct smbios_structure_header {
87 /* SMBIOS type 0 - BIOS Information */
88 struct smbios_type_0 {
89 struct smbios_structure_header header;
92 u16 bios_starting_address_segment;
93 u8 bios_release_date_str;
95 u8 bios_characteristics[8];
96 u8 bios_characteristics_extension_bytes[2];
97 u8 system_bios_major_release;
98 u8 system_bios_minor_release;
99 u8 embedded_controller_major_release;
100 u8 embedded_controller_minor_release;
103 /* SMBIOS type 1 - System Information */
104 struct smbios_type_1 {
105 struct smbios_structure_header header;
109 u8 serial_number_str;
116 /* SMBIOS type 3 - System Enclosure (v2.3) */
117 struct smbios_type_3 {
118 struct smbios_structure_header header;
122 u8 serial_number_str;
123 u8 asset_tag_number_str;
125 u8 power_supply_state;
130 u8 number_of_power_cords;
131 u8 contained_element_count;
132 // contained elements follow
135 /* SMBIOS type 4 - Processor Information (v2.0) */
136 struct smbios_type_4 {
137 struct smbios_structure_header header;
138 u8 socket_designation_str;
141 u8 processor_manufacturer_str;
143 u8 processor_version_str;
149 u8 processor_upgrade;
155 /* SMBIOS type 16 - Physical Memory Array
156 * Associated with one type 17 (Memory Device).
158 struct smbios_type_16 {
159 struct smbios_structure_header header;
163 u32 maximum_capacity;
164 u16 memory_error_information_handle;
165 u16 number_of_memory_devices;
168 /* SMBIOS type 17 - Memory Device
169 * Associated with one type 19
171 struct smbios_type_17 {
172 struct smbios_structure_header header;
173 u16 physical_memory_array_handle;
174 u16 memory_error_information_handle;
180 u8 device_locator_str;
186 /* SMBIOS type 19 - Memory Array Mapped Address */
187 struct smbios_type_19 {
188 struct smbios_structure_header header;
189 u32 starting_address;
191 u16 memory_array_handle;
195 /* SMBIOS type 20 - Memory Device Mapped Address */
196 struct smbios_type_20 {
197 struct smbios_structure_header header;
198 u32 starting_address;
200 u16 memory_device_handle;
201 u16 memory_array_mapped_address_handle;
202 u8 partition_row_position;
203 u8 interleave_position;
204 u8 interleaved_data_depth;
207 /* SMBIOS type 32 - System Boot Information */
208 struct smbios_type_32 {
209 struct smbios_structure_header header;
214 /* SMBIOS type 127 -- End-of-table */
215 struct smbios_type_127 {
216 struct smbios_structure_header header;
220 /****************************************************************
222 ****************************************************************/
225 smbios_entry_point_init(void *start,
226 u16 max_structure_size,
227 u16 structure_table_length,
228 u32 structure_table_address,
229 u16 number_of_structures)
231 struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
233 memcpy(ep->anchor_string, "_SM_", 4);
235 ep->smbios_major_version = 2;
236 ep->smbios_minor_version = 4;
237 ep->max_structure_size = max_structure_size;
238 ep->entry_point_revision = 0;
239 memset(ep->formatted_area, 0, 5);
240 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
242 ep->structure_table_length = structure_table_length;
243 ep->structure_table_address = structure_table_address;
244 ep->number_of_structures = number_of_structures;
245 ep->smbios_bcd_revision = 0x24;
247 ep->checksum -= checksum(start, 0x10);
249 ep->intermediate_checksum -= checksum(start + 0x10, ep->length - 0x10);
252 /* Type 0 -- BIOS Information */
253 #define RELEASE_DATE_STR "01/01/2007"
255 smbios_type_0_init(void *start)
257 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
260 p->header.length = sizeof(struct smbios_type_0);
261 p->header.handle = 0;
264 p->bios_version_str = 1;
265 p->bios_starting_address_segment = 0xe800;
266 p->bios_release_date_str = 2;
267 p->bios_rom_size = 0; /* FIXME */
269 memset(p->bios_characteristics, 0, sizeof(p->bios_characteristics));
270 p->bios_characteristics[0] = 0x08; /* BIOS characteristics not supported */
271 p->bios_characteristics_extension_bytes[0] = 0;
272 p->bios_characteristics_extension_bytes[1] = 0;
274 p->system_bios_major_release = 1;
275 p->system_bios_minor_release = 0;
276 p->embedded_controller_major_release = 0xff;
277 p->embedded_controller_minor_release = 0xff;
279 start += sizeof(struct smbios_type_0);
280 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
281 start += sizeof(CONFIG_APPNAME);
282 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
283 start += sizeof(RELEASE_DATE_STR);
289 /* Type 1 -- System Information */
291 smbios_type_1_init(void *start)
293 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
295 p->header.length = sizeof(struct smbios_type_1);
296 p->header.handle = 0x100;
298 p->manufacturer_str = 0;
299 p->product_name_str = 0;
301 p->serial_number_str = 0;
305 p->wake_up_type = 0x06; /* power switch */
306 p->sku_number_str = 0;
309 start += sizeof(struct smbios_type_1);
315 /* Type 3 -- System Enclosure */
317 smbios_type_3_init(void *start)
319 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
322 p->header.length = sizeof(struct smbios_type_3);
323 p->header.handle = 0x300;
325 p->manufacturer_str = 0;
326 p->type = 0x01; /* other */
328 p->serial_number_str = 0;
329 p->asset_tag_number_str = 0;
330 p->boot_up_state = 0x03; /* safe */
331 p->power_supply_state = 0x03; /* safe */
332 p->thermal_state = 0x03; /* safe */
333 p->security_status = 0x02; /* unknown */
336 p->number_of_power_cords = 0;
337 p->contained_element_count = 0;
339 start += sizeof(struct smbios_type_3);
345 /* Type 4 -- Processor Information */
347 smbios_type_4_init(void *start, unsigned int cpu_number)
349 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
352 p->header.length = sizeof(struct smbios_type_4);
353 p->header.handle = 0x400 + cpu_number;
355 p->socket_designation_str = 1;
356 p->processor_type = 0x03; /* CPU */
357 p->processor_family = 0x01; /* other */
358 p->processor_manufacturer_str = 0;
360 u32 cpuid_signature, ebx, ecx, cpuid_features;
361 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
362 p->processor_id[0] = cpuid_signature;
363 p->processor_id[1] = cpuid_features;
365 p->processor_version_str = 0;
367 p->external_clock = 0;
369 p->max_speed = 0; /* unknown */
370 p->current_speed = 0; /* unknown */
372 p->status = 0x41; /* socket populated, CPU enabled */
373 p->processor_upgrade = 0x01; /* other */
375 p->l1_cache_handle = 0xffff; /* cache information structure not provided */
376 p->l2_cache_handle = 0xffff;
377 p->l3_cache_handle = 0xffff;
379 start += sizeof(struct smbios_type_4);
381 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
382 ((char *)start)[4] = cpu_number + '0';
387 /* Type 16 -- Physical Memory Array */
389 smbios_type_16_init(void *start)
391 struct smbios_type_16 *p = (struct smbios_type_16*)start;
394 p->header.length = sizeof(struct smbios_type_16);
395 p->header.handle = 0x1000;
397 p->location = 0x01; /* other */
398 p->use = 0x03; /* system memory */
399 p->error_correction = 0x01; /* other */
400 u64 memsize = RamSize + RamSizeOver4G;
401 p->maximum_capacity = memsize / 1024;
402 p->memory_error_information_handle = 0xfffe; /* none provided */
403 p->number_of_memory_devices = 1;
405 start += sizeof(struct smbios_type_16);
411 /* Type 17 -- Memory Device */
413 smbios_type_17_init(void *start)
415 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
418 p->header.length = sizeof(struct smbios_type_17);
419 p->header.handle = 0x1100;
421 p->physical_memory_array_handle = 0x1000;
424 /* truncate memory_size_mb to 16 bits and clear most significant
425 bit [indicates size in MB] */
426 u64 memsize = RamSize + RamSizeOver4G;
427 p->size = (u16) (memsize / (1024*1024)) & 0x7fff;
428 p->form_factor = 0x09; /* DIMM */
430 p->device_locator_str = 1;
431 p->bank_locator_str = 0;
432 p->memory_type = 0x07; /* RAM */
435 start += sizeof(struct smbios_type_17);
436 memcpy((char *)start, "DIMM 1", 7);
443 /* Type 19 -- Memory Array Mapped Address */
445 smbios_type_19_init(void *start)
447 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
450 p->header.length = sizeof(struct smbios_type_19);
451 p->header.handle = 0x1300;
453 p->starting_address = 0;
454 u64 memsize = RamSizeOver4G;
456 memsize += 0x100000000ull;
459 p->ending_address = memsize / 1024 - 1;
460 p->memory_array_handle = 0x1000;
461 p->partition_width = 1;
463 start += sizeof(struct smbios_type_19);
469 /* Type 20 -- Memory Device Mapped Address */
471 smbios_type_20_init(void *start)
473 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
476 p->header.length = sizeof(struct smbios_type_20);
477 p->header.handle = 0x1400;
479 p->starting_address = 0;
480 u64 memsize = RamSizeOver4G;
482 memsize += 0x100000000ull;
485 p->ending_address = memsize / 1024 - 1;
486 p->memory_device_handle = 0x1100;
487 p->memory_array_mapped_address_handle = 0x1300;
488 p->partition_row_position = 1;
489 p->interleave_position = 0;
490 p->interleaved_data_depth = 0;
492 start += sizeof(struct smbios_type_20);
498 /* Type 32 -- System Boot Information */
500 smbios_type_32_init(void *start)
502 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
505 p->header.length = sizeof(struct smbios_type_32);
506 p->header.handle = 0x2000;
507 memset(p->reserved, 0, 6);
508 p->boot_status = 0; /* no errors detected */
510 start += sizeof(struct smbios_type_32);
516 /* Type 127 -- End of Table */
518 smbios_type_127_init(void *start)
520 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
522 p->header.type = 127;
523 p->header.length = sizeof(struct smbios_type_127);
524 p->header.handle = 0x7f00;
526 start += sizeof(struct smbios_type_127);
538 dprintf(3, "init SMBIOS tables\n");
540 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
543 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
544 start = (void *)(bios_table_cur_addr);
546 p = (char *)start + sizeof(struct smbios_entry_point);
548 #define add_struct(fn) { \
551 if ((q - p) > max_struct_size) \
552 max_struct_size = q - p; \
556 add_struct(smbios_type_0_init(p));
557 add_struct(smbios_type_1_init(p));
558 add_struct(smbios_type_3_init(p));
559 int smp_cpus = CountCPUs;
560 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
561 add_struct(smbios_type_4_init(p, cpu_num));
562 add_struct(smbios_type_16_init(p));
563 add_struct(smbios_type_17_init(p));
564 add_struct(smbios_type_19_init(p));
565 add_struct(smbios_type_20_init(p));
566 add_struct(smbios_type_32_init(p));
567 add_struct(smbios_type_127_init(p));
571 smbios_entry_point_init(
572 start, max_struct_size,
573 (p - (char *)start) - sizeof(struct smbios_entry_point),
574 (u32)(start + sizeof(struct smbios_entry_point)),
577 bios_table_cur_addr += (p - (char *)start);
579 dprintf(1, "SMBIOS table addr=0x%08lx\n", (unsigned long)start);