1 // smbios table generation (on emulators)
3 // Copyright (C) 2008,2009 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 "biosvar.h" // GET_EBDA
12 /****************************************************************
14 ****************************************************************/
16 /* SMBIOS entry point -- must be written to a 16-bit aligned address
17 between 0xf0000 and 0xfffff.
19 struct smbios_entry_point {
20 char anchor_string[4];
23 u8 smbios_major_version;
24 u8 smbios_minor_version;
25 u16 max_structure_size;
26 u8 entry_point_revision;
28 char intermediate_anchor_string[5];
29 u8 intermediate_checksum;
30 u16 structure_table_length;
31 u32 structure_table_address;
32 u16 number_of_structures;
33 u8 smbios_bcd_revision;
36 /* This goes at the beginning of every SMBIOS structure. */
37 struct smbios_structure_header {
43 /* SMBIOS type 0 - BIOS Information */
44 struct smbios_type_0 {
45 struct smbios_structure_header header;
48 u16 bios_starting_address_segment;
49 u8 bios_release_date_str;
51 u8 bios_characteristics[8];
52 u8 bios_characteristics_extension_bytes[2];
53 u8 system_bios_major_release;
54 u8 system_bios_minor_release;
55 u8 embedded_controller_major_release;
56 u8 embedded_controller_minor_release;
59 /* SMBIOS type 1 - System Information */
60 struct smbios_type_1 {
61 struct smbios_structure_header header;
72 /* SMBIOS type 3 - System Enclosure (v2.3) */
73 struct smbios_type_3 {
74 struct smbios_structure_header header;
79 u8 asset_tag_number_str;
81 u8 power_supply_state;
86 u8 number_of_power_cords;
87 u8 contained_element_count;
88 // contained elements follow
91 /* SMBIOS type 4 - Processor Information (v2.0) */
92 struct smbios_type_4 {
93 struct smbios_structure_header header;
94 u8 socket_designation_str;
97 u8 processor_manufacturer_str;
99 u8 processor_version_str;
105 u8 processor_upgrade;
111 /* SMBIOS type 16 - Physical Memory Array
112 * Associated with one type 17 (Memory Device).
114 struct smbios_type_16 {
115 struct smbios_structure_header header;
119 u32 maximum_capacity;
120 u16 memory_error_information_handle;
121 u16 number_of_memory_devices;
124 /* SMBIOS type 17 - Memory Device
125 * Associated with one type 19
127 struct smbios_type_17 {
128 struct smbios_structure_header header;
129 u16 physical_memory_array_handle;
130 u16 memory_error_information_handle;
136 u8 device_locator_str;
142 /* SMBIOS type 19 - Memory Array Mapped Address */
143 struct smbios_type_19 {
144 struct smbios_structure_header header;
145 u32 starting_address;
147 u16 memory_array_handle;
151 /* SMBIOS type 20 - Memory Device Mapped Address */
152 struct smbios_type_20 {
153 struct smbios_structure_header header;
154 u32 starting_address;
156 u16 memory_device_handle;
157 u16 memory_array_mapped_address_handle;
158 u8 partition_row_position;
159 u8 interleave_position;
160 u8 interleaved_data_depth;
163 /* SMBIOS type 32 - System Boot Information */
164 struct smbios_type_32 {
165 struct smbios_structure_header header;
170 /* SMBIOS type 127 -- End-of-table */
171 struct smbios_type_127 {
172 struct smbios_structure_header header;
176 /****************************************************************
178 ****************************************************************/
181 smbios_entry_point_init(u16 max_structure_size,
182 u16 structure_table_length,
183 void *structure_table_address,
184 u16 number_of_structures)
186 struct smbios_entry_point *ep = malloc_fseg(sizeof(*ep));
188 dprintf(1, "No space for smbios entry table!\n");
192 memcpy(ep->anchor_string, "_SM_", 4);
194 ep->smbios_major_version = 2;
195 ep->smbios_minor_version = 4;
196 ep->max_structure_size = max_structure_size;
197 ep->entry_point_revision = 0;
198 memset(ep->formatted_area, 0, 5);
199 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
201 ep->structure_table_length = structure_table_length;
202 ep->structure_table_address = (u32)structure_table_address;
203 ep->number_of_structures = number_of_structures;
204 ep->smbios_bcd_revision = 0x24;
206 ep->checksum -= checksum(ep, 0x10);
208 ep->intermediate_checksum -= checksum((void*)ep + 0x10, ep->length - 0x10);
210 dprintf(1, "SMBIOS ptr=%p table=%p\n", ep, structure_table_address);
213 #define load_str_field_with_default(type, field, def) \
215 size = qemu_cfg_smbios_load_field(type, \
216 offsetof(struct smbios_type_##type, \
221 memcpy(end, def, sizeof(def)); \
222 end += sizeof(def); \
224 p->field = ++str_index; \
227 #define load_str_field_or_skip(type, field) \
229 size = qemu_cfg_smbios_load_field(type, \
230 offsetof(struct smbios_type_##type, \
234 p->field = ++str_index; \
240 /* Type 0 -- BIOS Information */
241 #define RELEASE_DATE_STR "01/01/2007"
243 smbios_init_type_0(void *start)
245 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
246 char *end = (char *)start + sizeof(struct smbios_type_0);
251 p->header.length = sizeof(struct smbios_type_0);
252 p->header.handle = 0;
254 load_str_field_with_default(0, vendor_str, CONFIG_APPNAME);
255 load_str_field_with_default(0, bios_version_str, CONFIG_APPNAME);
257 p->bios_starting_address_segment = 0xe800;
259 load_str_field_with_default(0, bios_release_date_str, RELEASE_DATE_STR);
261 p->bios_rom_size = 0; /* FIXME */
263 memset(p->bios_characteristics, 0, 8);
264 p->bios_characteristics[0] = 0x08; /* BIOS characteristics not supported */
265 p->bios_characteristics_extension_bytes[0] = 0;
266 p->bios_characteristics_extension_bytes[1] = 0;
268 if (!qemu_cfg_smbios_load_field(0, offsetof(struct smbios_type_0,
269 system_bios_major_release),
270 &p->system_bios_major_release))
271 p->system_bios_major_release = 1;
273 if (!qemu_cfg_smbios_load_field(0, offsetof(struct smbios_type_0,
274 system_bios_minor_release),
275 &p->system_bios_minor_release))
276 p->system_bios_minor_release = 0;
278 p->embedded_controller_major_release = 0xff;
279 p->embedded_controller_minor_release = 0xff;
287 /* Type 1 -- System Information */
289 smbios_init_type_1(void *start)
291 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
292 char *end = (char *)start + sizeof(struct smbios_type_1);
297 p->header.length = sizeof(struct smbios_type_1);
298 p->header.handle = 0x100;
300 load_str_field_or_skip(1, manufacturer_str);
301 load_str_field_or_skip(1, product_name_str);
302 load_str_field_or_skip(1, version_str);
303 load_str_field_or_skip(1, serial_number_str);
305 size = qemu_cfg_smbios_load_field(1, offsetof(struct smbios_type_1,
308 memset(p->uuid, 0, 16);
310 p->wake_up_type = 0x06; /* power switch */
312 load_str_field_or_skip(1, sku_number_str);
313 load_str_field_or_skip(1, family_str);
325 /* Type 3 -- System Enclosure */
327 smbios_init_type_3(void *start)
329 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
332 p->header.length = sizeof(struct smbios_type_3);
333 p->header.handle = 0x300;
335 p->manufacturer_str = 0;
336 p->type = 0x01; /* other */
338 p->serial_number_str = 0;
339 p->asset_tag_number_str = 0;
340 p->boot_up_state = 0x03; /* safe */
341 p->power_supply_state = 0x03; /* safe */
342 p->thermal_state = 0x03; /* safe */
343 p->security_status = 0x02; /* unknown */
346 p->number_of_power_cords = 0;
347 p->contained_element_count = 0;
349 start += sizeof(struct smbios_type_3);
355 /* Type 4 -- Processor Information */
357 smbios_init_type_4(void *start, unsigned int cpu_number)
359 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
362 p->header.length = sizeof(struct smbios_type_4);
363 p->header.handle = 0x400 + cpu_number;
365 p->socket_designation_str = 1;
366 p->processor_type = 0x03; /* CPU */
367 p->processor_family = 0x01; /* other */
368 p->processor_manufacturer_str = 0;
370 u32 cpuid_signature, ebx, ecx, cpuid_features;
371 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
372 p->processor_id[0] = cpuid_signature;
373 p->processor_id[1] = cpuid_features;
375 p->processor_version_str = 0;
377 p->external_clock = 0;
379 p->max_speed = 0; /* unknown */
380 p->current_speed = 0; /* unknown */
382 p->status = 0x41; /* socket populated, CPU enabled */
383 p->processor_upgrade = 0x01; /* other */
385 p->l1_cache_handle = 0xffff; /* cache information structure not provided */
386 p->l2_cache_handle = 0xffff;
387 p->l3_cache_handle = 0xffff;
389 start += sizeof(struct smbios_type_4);
391 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
392 ((char *)start)[4] = cpu_number + '0';
397 /* Type 16 -- Physical Memory Array */
399 smbios_init_type_16(void *start, u32 memory_size_mb, int nr_mem_devs)
401 struct smbios_type_16 *p = (struct smbios_type_16*)start;
404 p->header.length = sizeof(struct smbios_type_16);
405 p->header.handle = 0x1000;
407 p->location = 0x01; /* other */
408 p->use = 0x03; /* system memory */
409 p->error_correction = 0x01; /* other */
410 p->maximum_capacity = memory_size_mb * 1024;
411 p->memory_error_information_handle = 0xfffe; /* none provided */
412 p->number_of_memory_devices = nr_mem_devs;
414 start += sizeof(struct smbios_type_16);
420 /* Type 17 -- Memory Device */
422 smbios_init_type_17(void *start, u32 memory_size_mb, int instance)
424 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
427 p->header.length = sizeof(struct smbios_type_17);
428 p->header.handle = 0x1100 + instance;
430 p->physical_memory_array_handle = 0x1000;
433 /* TODO: should assert in case something is wrong ASSERT((memory_size_mb & ~0x7fff) == 0); */
434 p->size = memory_size_mb;
435 p->form_factor = 0x09; /* DIMM */
437 p->device_locator_str = 1;
438 p->bank_locator_str = 0;
439 p->memory_type = 0x07; /* RAM */
442 start += sizeof(struct smbios_type_17);
443 memcpy((char *)start, "DIMM 0", 7);
444 ((char*)start)[5] += instance;
451 /* Type 19 -- Memory Array Mapped Address */
453 smbios_init_type_19(void *start, u32 memory_size_mb, int instance)
455 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
458 p->header.length = sizeof(struct smbios_type_19);
459 p->header.handle = 0x1300 + instance;
461 p->starting_address = instance << 24;
462 p->ending_address = p->starting_address + (memory_size_mb << 10) - 1;
463 p->memory_array_handle = 0x1000;
464 p->partition_width = 1;
466 start += sizeof(struct smbios_type_19);
472 /* Type 20 -- Memory Device Mapped Address */
474 smbios_init_type_20(void *start, u32 memory_size_mb, int instance)
476 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
479 p->header.length = sizeof(struct smbios_type_20);
480 p->header.handle = 0x1400 + instance;
482 p->starting_address = instance << 24;
483 p->ending_address = p->starting_address + (memory_size_mb << 10) - 1;
484 p->memory_device_handle = 0x1100 + instance;
485 p->memory_array_mapped_address_handle = 0x1300 + instance;
486 p->partition_row_position = 1;
487 p->interleave_position = 0;
488 p->interleaved_data_depth = 0;
490 start += sizeof(struct smbios_type_20);
496 /* Type 32 -- System Boot Information */
498 smbios_init_type_32(void *start)
500 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
503 p->header.length = sizeof(struct smbios_type_32);
504 p->header.handle = 0x2000;
505 memset(p->reserved, 0, 6);
506 p->boot_status = 0; /* no errors detected */
508 start += sizeof(struct smbios_type_32);
514 /* Type 127 -- End of Table */
516 smbios_init_type_127(void *start)
518 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
520 p->header.type = 127;
521 p->header.length = sizeof(struct smbios_type_127);
522 p->header.handle = 0x7f00;
524 start += sizeof(struct smbios_type_127);
536 dprintf(3, "init SMBIOS tables\n");
538 char *start = malloc_high(2048); // XXX - determine real size
540 dprintf(1, "No memory for smbios tables\n");
544 u32 nr_structs = 0, max_struct_size = 0;
545 char *q, *p = start, *end = start + 2048 - sizeof(struct smbios_type_127);
547 #define add_struct(type, args...) \
549 if (!qemu_cfg_smbios_load_external(type, &p, &nr_structs, \
550 &max_struct_size, end)) { \
551 q = smbios_init_type_##type(args); \
553 if ((q - p) > max_struct_size) \
554 max_struct_size = q - p; \
563 int cpu_num, smp_cpus = CountCPUs;
564 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
565 add_struct(4, p, cpu_num);
566 u64 memsize = RamSizeOver4G;
568 memsize += 0x100000000ull;
571 memsize = memsize / (1024 * 1024);
572 int nr_mem_devs = (memsize + 0x3fff) >> 14;
573 add_struct(16, p, memsize, nr_mem_devs);
575 for (i = 0; i < nr_mem_devs; i++) {
576 u32 dev_memsize = ((i == (nr_mem_devs - 1))
577 ? (((memsize-1) & 0x3fff)+1) : 0x4000);
578 add_struct(17, p, dev_memsize, i);
579 add_struct(19, p, dev_memsize, i);
580 add_struct(20, p, dev_memsize, i);
584 /* Add any remaining provided entries before the end marker */
585 for (i = 0; i < 256; i++)
586 qemu_cfg_smbios_load_external(i, &p, &nr_structs, &max_struct_size,
592 smbios_entry_point_init(max_struct_size, p - start, start, nr_structs);