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 #define QEMU_CFG_SIGNATURE 0x00
17 #define QEMU_CFG_ID 0x01
18 #define QEMU_CFG_UUID 0x02
21 qemu_cfg_read(u8 *buf, u16 f, int len)
23 outw(f, PORT_QEMU_CFG_CTL);
25 *(buf++) = inb(PORT_QEMU_CFG_DATA);
33 qemu_cfg_read(buf, QEMU_CFG_SIGNATURE, 4);
34 return *(u32*)buf == *(u32*)sig;
38 uuid_probe(u8 *bios_uuid)
40 // Default to UUID not set
41 memset(bios_uuid, 0, 16);
43 if (! CONFIG_UUID_BACKDOOR)
47 if (! qemu_cfg_port_probe())
48 // Feature not available
51 qemu_cfg_read(bios_uuid, QEMU_CFG_UUID, 16);
55 /****************************************************************
57 ****************************************************************/
59 /* SMBIOS entry point -- must be written to a 16-bit aligned address
60 between 0xf0000 and 0xfffff.
62 struct smbios_entry_point {
63 char anchor_string[4];
66 u8 smbios_major_version;
67 u8 smbios_minor_version;
68 u16 max_structure_size;
69 u8 entry_point_revision;
71 char intermediate_anchor_string[5];
72 u8 intermediate_checksum;
73 u16 structure_table_length;
74 u32 structure_table_address;
75 u16 number_of_structures;
76 u8 smbios_bcd_revision;
79 /* This goes at the beginning of every SMBIOS structure. */
80 struct smbios_structure_header {
86 /* SMBIOS type 0 - BIOS Information */
87 struct smbios_type_0 {
88 struct smbios_structure_header header;
91 u16 bios_starting_address_segment;
92 u8 bios_release_date_str;
94 u8 bios_characteristics[8];
95 u8 bios_characteristics_extension_bytes[2];
96 u8 system_bios_major_release;
97 u8 system_bios_minor_release;
98 u8 embedded_controller_major_release;
99 u8 embedded_controller_minor_release;
102 /* SMBIOS type 1 - System Information */
103 struct smbios_type_1 {
104 struct smbios_structure_header header;
108 u8 serial_number_str;
115 /* SMBIOS type 3 - System Enclosure (v2.3) */
116 struct smbios_type_3 {
117 struct smbios_structure_header header;
121 u8 serial_number_str;
122 u8 asset_tag_number_str;
124 u8 power_supply_state;
129 u8 number_of_power_cords;
130 u8 contained_element_count;
131 // contained elements follow
134 /* SMBIOS type 4 - Processor Information (v2.0) */
135 struct smbios_type_4 {
136 struct smbios_structure_header header;
137 u8 socket_designation_str;
140 u8 processor_manufacturer_str;
142 u8 processor_version_str;
148 u8 processor_upgrade;
154 /* SMBIOS type 16 - Physical Memory Array
155 * Associated with one type 17 (Memory Device).
157 struct smbios_type_16 {
158 struct smbios_structure_header header;
162 u32 maximum_capacity;
163 u16 memory_error_information_handle;
164 u16 number_of_memory_devices;
167 /* SMBIOS type 17 - Memory Device
168 * Associated with one type 19
170 struct smbios_type_17 {
171 struct smbios_structure_header header;
172 u16 physical_memory_array_handle;
173 u16 memory_error_information_handle;
179 u8 device_locator_str;
185 /* SMBIOS type 19 - Memory Array Mapped Address */
186 struct smbios_type_19 {
187 struct smbios_structure_header header;
188 u32 starting_address;
190 u16 memory_array_handle;
194 /* SMBIOS type 20 - Memory Device Mapped Address */
195 struct smbios_type_20 {
196 struct smbios_structure_header header;
197 u32 starting_address;
199 u16 memory_device_handle;
200 u16 memory_array_mapped_address_handle;
201 u8 partition_row_position;
202 u8 interleave_position;
203 u8 interleaved_data_depth;
206 /* SMBIOS type 32 - System Boot Information */
207 struct smbios_type_32 {
208 struct smbios_structure_header header;
213 /* SMBIOS type 127 -- End-of-table */
214 struct smbios_type_127 {
215 struct smbios_structure_header header;
219 /****************************************************************
221 ****************************************************************/
224 smbios_entry_point_init(u16 max_structure_size,
225 u16 structure_table_length,
226 void *structure_table_address,
227 u16 number_of_structures)
229 struct smbios_entry_point *ep = malloc_fseg(sizeof(*ep));
231 dprintf(1, "No space for smbios entry table!\n");
235 memcpy(ep->anchor_string, "_SM_", 4);
237 ep->smbios_major_version = 2;
238 ep->smbios_minor_version = 4;
239 ep->max_structure_size = max_structure_size;
240 ep->entry_point_revision = 0;
241 memset(ep->formatted_area, 0, 5);
242 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
244 ep->structure_table_length = structure_table_length;
245 ep->structure_table_address = (u32)structure_table_address;
246 ep->number_of_structures = number_of_structures;
247 ep->smbios_bcd_revision = 0x24;
249 ep->checksum -= checksum(ep, 0x10);
251 ep->intermediate_checksum -= checksum((void*)ep + 0x10, ep->length - 0x10);
253 dprintf(1, "SMBIOS ptr=%p table=%p\n", ep, structure_table_address);
256 /* Type 0 -- BIOS Information */
257 #define RELEASE_DATE_STR "01/01/2007"
259 smbios_type_0_init(void *start)
261 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
264 p->header.length = sizeof(struct smbios_type_0);
265 p->header.handle = 0;
268 p->bios_version_str = 1;
269 p->bios_starting_address_segment = 0xe800;
270 p->bios_release_date_str = 2;
271 p->bios_rom_size = 0; /* FIXME */
273 memset(p->bios_characteristics, 0, sizeof(p->bios_characteristics));
274 p->bios_characteristics[0] = 0x08; /* BIOS characteristics not supported */
275 p->bios_characteristics_extension_bytes[0] = 0;
276 p->bios_characteristics_extension_bytes[1] = 0;
278 p->system_bios_major_release = 1;
279 p->system_bios_minor_release = 0;
280 p->embedded_controller_major_release = 0xff;
281 p->embedded_controller_minor_release = 0xff;
283 start += sizeof(struct smbios_type_0);
284 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
285 start += sizeof(CONFIG_APPNAME);
286 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
287 start += sizeof(RELEASE_DATE_STR);
293 /* Type 1 -- System Information */
295 smbios_type_1_init(void *start)
297 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
299 p->header.length = sizeof(struct smbios_type_1);
300 p->header.handle = 0x100;
302 p->manufacturer_str = 0;
303 p->product_name_str = 0;
305 p->serial_number_str = 0;
309 p->wake_up_type = 0x06; /* power switch */
310 p->sku_number_str = 0;
313 start += sizeof(struct smbios_type_1);
319 /* Type 3 -- System Enclosure */
321 smbios_type_3_init(void *start)
323 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
326 p->header.length = sizeof(struct smbios_type_3);
327 p->header.handle = 0x300;
329 p->manufacturer_str = 0;
330 p->type = 0x01; /* other */
332 p->serial_number_str = 0;
333 p->asset_tag_number_str = 0;
334 p->boot_up_state = 0x03; /* safe */
335 p->power_supply_state = 0x03; /* safe */
336 p->thermal_state = 0x03; /* safe */
337 p->security_status = 0x02; /* unknown */
340 p->number_of_power_cords = 0;
341 p->contained_element_count = 0;
343 start += sizeof(struct smbios_type_3);
349 /* Type 4 -- Processor Information */
351 smbios_type_4_init(void *start, unsigned int cpu_number)
353 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
356 p->header.length = sizeof(struct smbios_type_4);
357 p->header.handle = 0x400 + cpu_number;
359 p->socket_designation_str = 1;
360 p->processor_type = 0x03; /* CPU */
361 p->processor_family = 0x01; /* other */
362 p->processor_manufacturer_str = 0;
364 u32 cpuid_signature, ebx, ecx, cpuid_features;
365 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
366 p->processor_id[0] = cpuid_signature;
367 p->processor_id[1] = cpuid_features;
369 p->processor_version_str = 0;
371 p->external_clock = 0;
373 p->max_speed = 0; /* unknown */
374 p->current_speed = 0; /* unknown */
376 p->status = 0x41; /* socket populated, CPU enabled */
377 p->processor_upgrade = 0x01; /* other */
379 p->l1_cache_handle = 0xffff; /* cache information structure not provided */
380 p->l2_cache_handle = 0xffff;
381 p->l3_cache_handle = 0xffff;
383 start += sizeof(struct smbios_type_4);
385 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
386 ((char *)start)[4] = cpu_number + '0';
391 /* Type 16 -- Physical Memory Array */
393 smbios_type_16_init(void *start)
395 struct smbios_type_16 *p = (struct smbios_type_16*)start;
398 p->header.length = sizeof(struct smbios_type_16);
399 p->header.handle = 0x1000;
401 p->location = 0x01; /* other */
402 p->use = 0x03; /* system memory */
403 p->error_correction = 0x01; /* other */
404 u64 memsize = RamSize + RamSizeOver4G;
405 p->maximum_capacity = memsize / 1024;
406 p->memory_error_information_handle = 0xfffe; /* none provided */
407 p->number_of_memory_devices = 1;
409 start += sizeof(struct smbios_type_16);
415 /* Type 17 -- Memory Device */
417 smbios_type_17_init(void *start)
419 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
422 p->header.length = sizeof(struct smbios_type_17);
423 p->header.handle = 0x1100;
425 p->physical_memory_array_handle = 0x1000;
428 /* truncate memory_size_mb to 16 bits and clear most significant
429 bit [indicates size in MB] */
430 u64 memsize = RamSize + RamSizeOver4G;
431 p->size = (u16) (memsize / (1024*1024)) & 0x7fff;
432 p->form_factor = 0x09; /* DIMM */
434 p->device_locator_str = 1;
435 p->bank_locator_str = 0;
436 p->memory_type = 0x07; /* RAM */
439 start += sizeof(struct smbios_type_17);
440 memcpy((char *)start, "DIMM 1", 7);
447 /* Type 19 -- Memory Array Mapped Address */
449 smbios_type_19_init(void *start)
451 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
454 p->header.length = sizeof(struct smbios_type_19);
455 p->header.handle = 0x1300;
457 p->starting_address = 0;
458 u64 memsize = RamSizeOver4G;
460 memsize += 0x100000000ull;
463 p->ending_address = memsize / 1024 - 1;
464 p->memory_array_handle = 0x1000;
465 p->partition_width = 1;
467 start += sizeof(struct smbios_type_19);
473 /* Type 20 -- Memory Device Mapped Address */
475 smbios_type_20_init(void *start)
477 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
480 p->header.length = sizeof(struct smbios_type_20);
481 p->header.handle = 0x1400;
483 p->starting_address = 0;
484 u64 memsize = RamSizeOver4G;
486 memsize += 0x100000000ull;
489 p->ending_address = memsize / 1024 - 1;
490 p->memory_device_handle = 0x1100;
491 p->memory_array_mapped_address_handle = 0x1300;
492 p->partition_row_position = 1;
493 p->interleave_position = 0;
494 p->interleaved_data_depth = 0;
496 start += sizeof(struct smbios_type_20);
502 /* Type 32 -- System Boot Information */
504 smbios_type_32_init(void *start)
506 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
509 p->header.length = sizeof(struct smbios_type_32);
510 p->header.handle = 0x2000;
511 memset(p->reserved, 0, 6);
512 p->boot_status = 0; /* no errors detected */
514 start += sizeof(struct smbios_type_32);
520 /* Type 127 -- End of Table */
522 smbios_type_127_init(void *start)
524 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
526 p->header.type = 127;
527 p->header.length = sizeof(struct smbios_type_127);
528 p->header.handle = 0x7f00;
530 start += sizeof(struct smbios_type_127);
542 dprintf(3, "init SMBIOS tables\n");
544 char *start = malloc_high(2048); // XXX - determine real size
546 dprintf(1, "No memory for smbios tables\n");
550 u32 nr_structs = 0, max_struct_size = 0;
553 #define add_struct(fn) { \
556 if ((q - p) > max_struct_size) \
557 max_struct_size = q - p; \
561 add_struct(smbios_type_0_init(p));
562 add_struct(smbios_type_1_init(p));
563 add_struct(smbios_type_3_init(p));
564 int cpu_num, smp_cpus = CountCPUs;
565 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
566 add_struct(smbios_type_4_init(p, cpu_num));
567 add_struct(smbios_type_16_init(p));
568 add_struct(smbios_type_17_init(p));
569 add_struct(smbios_type_19_init(p));
570 add_struct(smbios_type_20_init(p));
571 add_struct(smbios_type_32_init(p));
572 add_struct(smbios_type_127_init(p));
576 smbios_entry_point_init(max_struct_size, p - start, start, nr_structs);