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;
248 ep->intermediate_checksum = 0;
250 ep->checksum = -checksum(start, 0x10);
252 ep->intermediate_checksum = -checksum(start + 0x10, ep->length - 0x10);
255 /* Type 0 -- BIOS Information */
256 #define RELEASE_DATE_STR "01/01/2007"
258 smbios_type_0_init(void *start)
260 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
263 p->header.length = sizeof(struct smbios_type_0);
264 p->header.handle = 0;
267 p->bios_version_str = 1;
268 p->bios_starting_address_segment = 0xe800;
269 p->bios_release_date_str = 2;
270 p->bios_rom_size = 0; /* FIXME */
272 memset(p->bios_characteristics, 0, sizeof(p->bios_characteristics));
273 p->bios_characteristics[0] = 0x08; /* BIOS characteristics not supported */
274 p->bios_characteristics_extension_bytes[0] = 0;
275 p->bios_characteristics_extension_bytes[1] = 0;
277 p->system_bios_major_release = 1;
278 p->system_bios_minor_release = 0;
279 p->embedded_controller_major_release = 0xff;
280 p->embedded_controller_minor_release = 0xff;
282 start += sizeof(struct smbios_type_0);
283 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
284 start += sizeof(CONFIG_APPNAME);
285 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
286 start += sizeof(RELEASE_DATE_STR);
292 /* Type 1 -- System Information */
294 smbios_type_1_init(void *start)
296 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
298 p->header.length = sizeof(struct smbios_type_1);
299 p->header.handle = 0x100;
301 p->manufacturer_str = 0;
302 p->product_name_str = 0;
304 p->serial_number_str = 0;
308 p->wake_up_type = 0x06; /* power switch */
309 p->sku_number_str = 0;
312 start += sizeof(struct smbios_type_1);
318 /* Type 3 -- System Enclosure */
320 smbios_type_3_init(void *start)
322 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
325 p->header.length = sizeof(struct smbios_type_3);
326 p->header.handle = 0x300;
328 p->manufacturer_str = 0;
329 p->type = 0x01; /* other */
331 p->serial_number_str = 0;
332 p->asset_tag_number_str = 0;
333 p->boot_up_state = 0x03; /* safe */
334 p->power_supply_state = 0x03; /* safe */
335 p->thermal_state = 0x03; /* safe */
336 p->security_status = 0x02; /* unknown */
339 p->number_of_power_cords = 0;
340 p->contained_element_count = 0;
342 start += sizeof(struct smbios_type_3);
348 /* Type 4 -- Processor Information */
350 smbios_type_4_init(void *start, unsigned int cpu_number)
352 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
355 p->header.length = sizeof(struct smbios_type_4);
356 p->header.handle = 0x400 + cpu_number;
358 p->socket_designation_str = 1;
359 p->processor_type = 0x03; /* CPU */
360 p->processor_family = 0x01; /* other */
361 p->processor_manufacturer_str = 0;
363 u32 cpuid_signature, ebx, ecx, cpuid_features;
364 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
365 p->processor_id[0] = cpuid_signature;
366 p->processor_id[1] = cpuid_features;
368 p->processor_version_str = 0;
370 p->external_clock = 0;
372 p->max_speed = 0; /* unknown */
373 p->current_speed = 0; /* unknown */
375 p->status = 0x41; /* socket populated, CPU enabled */
376 p->processor_upgrade = 0x01; /* other */
378 p->l1_cache_handle = 0xffff; /* cache information structure not provided */
379 p->l2_cache_handle = 0xffff;
380 p->l3_cache_handle = 0xffff;
382 start += sizeof(struct smbios_type_4);
384 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
385 ((char *)start)[4] = cpu_number + '0';
390 /* Type 16 -- Physical Memory Array */
392 smbios_type_16_init(void *start)
394 struct smbios_type_16 *p = (struct smbios_type_16*)start;
397 p->header.length = sizeof(struct smbios_type_16);
398 p->header.handle = 0x1000;
400 p->location = 0x01; /* other */
401 p->use = 0x03; /* system memory */
402 p->error_correction = 0x01; /* other */
403 u64 memsize = RamSize + RamSizeOver4G;
404 p->maximum_capacity = memsize / 1024;
405 p->memory_error_information_handle = 0xfffe; /* none provided */
406 p->number_of_memory_devices = 1;
408 start += sizeof(struct smbios_type_16);
414 /* Type 17 -- Memory Device */
416 smbios_type_17_init(void *start)
418 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
421 p->header.length = sizeof(struct smbios_type_17);
422 p->header.handle = 0x1100;
424 p->physical_memory_array_handle = 0x1000;
427 /* truncate memory_size_mb to 16 bits and clear most significant
428 bit [indicates size in MB] */
429 u64 memsize = RamSize + RamSizeOver4G;
430 p->size = (u16) (memsize / (1024*1024)) & 0x7fff;
431 p->form_factor = 0x09; /* DIMM */
433 p->device_locator_str = 1;
434 p->bank_locator_str = 0;
435 p->memory_type = 0x07; /* RAM */
438 start += sizeof(struct smbios_type_17);
439 memcpy((char *)start, "DIMM 1", 7);
446 /* Type 19 -- Memory Array Mapped Address */
448 smbios_type_19_init(void *start)
450 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
453 p->header.length = sizeof(struct smbios_type_19);
454 p->header.handle = 0x1300;
456 p->starting_address = 0;
457 u64 memsize = RamSizeOver4G;
459 memsize += 0x100000000ull;
462 p->ending_address = memsize / 1024 - 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_type_20_init(void *start)
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;
482 p->starting_address = 0;
483 u64 memsize = RamSizeOver4G;
485 memsize += 0x100000000ull;
488 p->ending_address = memsize / 1024 - 1;
489 p->memory_device_handle = 0x1100;
490 p->memory_array_mapped_address_handle = 0x1300;
491 p->partition_row_position = 1;
492 p->interleave_position = 0;
493 p->interleaved_data_depth = 0;
495 start += sizeof(struct smbios_type_20);
501 /* Type 32 -- System Boot Information */
503 smbios_type_32_init(void *start)
505 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
508 p->header.length = sizeof(struct smbios_type_32);
509 p->header.handle = 0x2000;
510 memset(p->reserved, 0, 6);
511 p->boot_status = 0; /* no errors detected */
513 start += sizeof(struct smbios_type_32);
519 /* Type 127 -- End of Table */
521 smbios_type_127_init(void *start)
523 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
525 p->header.type = 127;
526 p->header.length = sizeof(struct smbios_type_127);
527 p->header.handle = 0x7f00;
529 start += sizeof(struct smbios_type_127);
541 dprintf(3, "init SMBIOS tables\n");
543 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
546 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
547 start = (void *)(bios_table_cur_addr);
549 p = (char *)start + sizeof(struct smbios_entry_point);
551 #define add_struct(fn) { \
554 if ((q - p) > max_struct_size) \
555 max_struct_size = q - p; \
559 add_struct(smbios_type_0_init(p));
560 add_struct(smbios_type_1_init(p));
561 add_struct(smbios_type_3_init(p));
562 int smp_cpus = smp_probe();
563 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
564 add_struct(smbios_type_4_init(p, cpu_num));
565 add_struct(smbios_type_16_init(p));
566 add_struct(smbios_type_17_init(p));
567 add_struct(smbios_type_19_init(p));
568 add_struct(smbios_type_20_init(p));
569 add_struct(smbios_type_32_init(p));
570 add_struct(smbios_type_127_init(p));
574 smbios_entry_point_init(
575 start, max_struct_size,
576 (p - (char *)start) - sizeof(struct smbios_entry_point),
577 (u32)(start + sizeof(struct smbios_entry_point)),
580 bios_table_cur_addr += (p - (char *)start);
582 dprintf(1, "SMBIOS table addr=0x%08lx\n", (unsigned long)start);