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 ****************************************************************/
17 uuid_probe(u8 *bios_uuid)
19 // Default to UUID not set
20 memset(bios_uuid, 0, 16);
22 if (! CONFIG_UUID_BACKDOOR)
27 qemu_cfg_get_uuid(bios_uuid);
31 /****************************************************************
33 ****************************************************************/
35 /* SMBIOS entry point -- must be written to a 16-bit aligned address
36 between 0xf0000 and 0xfffff.
38 struct smbios_entry_point {
39 char anchor_string[4];
42 u8 smbios_major_version;
43 u8 smbios_minor_version;
44 u16 max_structure_size;
45 u8 entry_point_revision;
47 char intermediate_anchor_string[5];
48 u8 intermediate_checksum;
49 u16 structure_table_length;
50 u32 structure_table_address;
51 u16 number_of_structures;
52 u8 smbios_bcd_revision;
55 /* This goes at the beginning of every SMBIOS structure. */
56 struct smbios_structure_header {
62 /* SMBIOS type 0 - BIOS Information */
63 struct smbios_type_0 {
64 struct smbios_structure_header header;
67 u16 bios_starting_address_segment;
68 u8 bios_release_date_str;
70 u8 bios_characteristics[8];
71 u8 bios_characteristics_extension_bytes[2];
72 u8 system_bios_major_release;
73 u8 system_bios_minor_release;
74 u8 embedded_controller_major_release;
75 u8 embedded_controller_minor_release;
78 /* SMBIOS type 1 - System Information */
79 struct smbios_type_1 {
80 struct smbios_structure_header header;
91 /* SMBIOS type 3 - System Enclosure (v2.3) */
92 struct smbios_type_3 {
93 struct smbios_structure_header header;
98 u8 asset_tag_number_str;
100 u8 power_supply_state;
105 u8 number_of_power_cords;
106 u8 contained_element_count;
107 // contained elements follow
110 /* SMBIOS type 4 - Processor Information (v2.0) */
111 struct smbios_type_4 {
112 struct smbios_structure_header header;
113 u8 socket_designation_str;
116 u8 processor_manufacturer_str;
118 u8 processor_version_str;
124 u8 processor_upgrade;
130 /* SMBIOS type 16 - Physical Memory Array
131 * Associated with one type 17 (Memory Device).
133 struct smbios_type_16 {
134 struct smbios_structure_header header;
138 u32 maximum_capacity;
139 u16 memory_error_information_handle;
140 u16 number_of_memory_devices;
143 /* SMBIOS type 17 - Memory Device
144 * Associated with one type 19
146 struct smbios_type_17 {
147 struct smbios_structure_header header;
148 u16 physical_memory_array_handle;
149 u16 memory_error_information_handle;
155 u8 device_locator_str;
161 /* SMBIOS type 19 - Memory Array Mapped Address */
162 struct smbios_type_19 {
163 struct smbios_structure_header header;
164 u32 starting_address;
166 u16 memory_array_handle;
170 /* SMBIOS type 20 - Memory Device Mapped Address */
171 struct smbios_type_20 {
172 struct smbios_structure_header header;
173 u32 starting_address;
175 u16 memory_device_handle;
176 u16 memory_array_mapped_address_handle;
177 u8 partition_row_position;
178 u8 interleave_position;
179 u8 interleaved_data_depth;
182 /* SMBIOS type 32 - System Boot Information */
183 struct smbios_type_32 {
184 struct smbios_structure_header header;
189 /* SMBIOS type 127 -- End-of-table */
190 struct smbios_type_127 {
191 struct smbios_structure_header header;
195 /****************************************************************
197 ****************************************************************/
200 smbios_entry_point_init(u16 max_structure_size,
201 u16 structure_table_length,
202 void *structure_table_address,
203 u16 number_of_structures)
205 struct smbios_entry_point *ep = malloc_fseg(sizeof(*ep));
207 dprintf(1, "No space for smbios entry table!\n");
211 memcpy(ep->anchor_string, "_SM_", 4);
213 ep->smbios_major_version = 2;
214 ep->smbios_minor_version = 4;
215 ep->max_structure_size = max_structure_size;
216 ep->entry_point_revision = 0;
217 memset(ep->formatted_area, 0, 5);
218 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
220 ep->structure_table_length = structure_table_length;
221 ep->structure_table_address = (u32)structure_table_address;
222 ep->number_of_structures = number_of_structures;
223 ep->smbios_bcd_revision = 0x24;
225 ep->checksum -= checksum(ep, 0x10);
227 ep->intermediate_checksum -= checksum((void*)ep + 0x10, ep->length - 0x10);
229 dprintf(1, "SMBIOS ptr=%p table=%p\n", ep, structure_table_address);
232 /* Type 0 -- BIOS Information */
233 #define RELEASE_DATE_STR "01/01/2007"
235 smbios_type_0_init(void *start)
237 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
240 p->header.length = sizeof(struct smbios_type_0);
241 p->header.handle = 0;
244 p->bios_version_str = 1;
245 p->bios_starting_address_segment = 0xe800;
246 p->bios_release_date_str = 2;
247 p->bios_rom_size = 0; /* FIXME */
249 memset(p->bios_characteristics, 0, sizeof(p->bios_characteristics));
250 p->bios_characteristics[0] = 0x08; /* BIOS characteristics not supported */
251 p->bios_characteristics_extension_bytes[0] = 0;
252 p->bios_characteristics_extension_bytes[1] = 0;
254 p->system_bios_major_release = 1;
255 p->system_bios_minor_release = 0;
256 p->embedded_controller_major_release = 0xff;
257 p->embedded_controller_minor_release = 0xff;
259 start += sizeof(struct smbios_type_0);
260 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
261 start += sizeof(CONFIG_APPNAME);
262 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
263 start += sizeof(RELEASE_DATE_STR);
269 /* Type 1 -- System Information */
271 smbios_type_1_init(void *start)
273 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
275 p->header.length = sizeof(struct smbios_type_1);
276 p->header.handle = 0x100;
278 p->manufacturer_str = 0;
279 p->product_name_str = 0;
281 p->serial_number_str = 0;
285 p->wake_up_type = 0x06; /* power switch */
286 p->sku_number_str = 0;
289 start += sizeof(struct smbios_type_1);
295 /* Type 3 -- System Enclosure */
297 smbios_type_3_init(void *start)
299 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
302 p->header.length = sizeof(struct smbios_type_3);
303 p->header.handle = 0x300;
305 p->manufacturer_str = 0;
306 p->type = 0x01; /* other */
308 p->serial_number_str = 0;
309 p->asset_tag_number_str = 0;
310 p->boot_up_state = 0x03; /* safe */
311 p->power_supply_state = 0x03; /* safe */
312 p->thermal_state = 0x03; /* safe */
313 p->security_status = 0x02; /* unknown */
316 p->number_of_power_cords = 0;
317 p->contained_element_count = 0;
319 start += sizeof(struct smbios_type_3);
325 /* Type 4 -- Processor Information */
327 smbios_type_4_init(void *start, unsigned int cpu_number)
329 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
332 p->header.length = sizeof(struct smbios_type_4);
333 p->header.handle = 0x400 + cpu_number;
335 p->socket_designation_str = 1;
336 p->processor_type = 0x03; /* CPU */
337 p->processor_family = 0x01; /* other */
338 p->processor_manufacturer_str = 0;
340 u32 cpuid_signature, ebx, ecx, cpuid_features;
341 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
342 p->processor_id[0] = cpuid_signature;
343 p->processor_id[1] = cpuid_features;
345 p->processor_version_str = 0;
347 p->external_clock = 0;
349 p->max_speed = 0; /* unknown */
350 p->current_speed = 0; /* unknown */
352 p->status = 0x41; /* socket populated, CPU enabled */
353 p->processor_upgrade = 0x01; /* other */
355 p->l1_cache_handle = 0xffff; /* cache information structure not provided */
356 p->l2_cache_handle = 0xffff;
357 p->l3_cache_handle = 0xffff;
359 start += sizeof(struct smbios_type_4);
361 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
362 ((char *)start)[4] = cpu_number + '0';
367 /* Type 16 -- Physical Memory Array */
369 smbios_type_16_init(void *start)
371 struct smbios_type_16 *p = (struct smbios_type_16*)start;
374 p->header.length = sizeof(struct smbios_type_16);
375 p->header.handle = 0x1000;
377 p->location = 0x01; /* other */
378 p->use = 0x03; /* system memory */
379 p->error_correction = 0x01; /* other */
380 u64 memsize = RamSize + RamSizeOver4G;
381 p->maximum_capacity = memsize / 1024;
382 p->memory_error_information_handle = 0xfffe; /* none provided */
383 p->number_of_memory_devices = 1;
385 start += sizeof(struct smbios_type_16);
391 /* Type 17 -- Memory Device */
393 smbios_type_17_init(void *start)
395 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
398 p->header.length = sizeof(struct smbios_type_17);
399 p->header.handle = 0x1100;
401 p->physical_memory_array_handle = 0x1000;
404 /* truncate memory_size_mb to 16 bits and clear most significant
405 bit [indicates size in MB] */
406 u64 memsize = RamSize + RamSizeOver4G;
407 p->size = (u16) (memsize / (1024*1024)) & 0x7fff;
408 p->form_factor = 0x09; /* DIMM */
410 p->device_locator_str = 1;
411 p->bank_locator_str = 0;
412 p->memory_type = 0x07; /* RAM */
415 start += sizeof(struct smbios_type_17);
416 memcpy((char *)start, "DIMM 1", 7);
423 /* Type 19 -- Memory Array Mapped Address */
425 smbios_type_19_init(void *start)
427 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
430 p->header.length = sizeof(struct smbios_type_19);
431 p->header.handle = 0x1300;
433 p->starting_address = 0;
434 u64 memsize = RamSizeOver4G;
436 memsize += 0x100000000ull;
439 p->ending_address = memsize / 1024 - 1;
440 p->memory_array_handle = 0x1000;
441 p->partition_width = 1;
443 start += sizeof(struct smbios_type_19);
449 /* Type 20 -- Memory Device Mapped Address */
451 smbios_type_20_init(void *start)
453 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
456 p->header.length = sizeof(struct smbios_type_20);
457 p->header.handle = 0x1400;
459 p->starting_address = 0;
460 u64 memsize = RamSizeOver4G;
462 memsize += 0x100000000ull;
465 p->ending_address = memsize / 1024 - 1;
466 p->memory_device_handle = 0x1100;
467 p->memory_array_mapped_address_handle = 0x1300;
468 p->partition_row_position = 1;
469 p->interleave_position = 0;
470 p->interleaved_data_depth = 0;
472 start += sizeof(struct smbios_type_20);
478 /* Type 32 -- System Boot Information */
480 smbios_type_32_init(void *start)
482 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
485 p->header.length = sizeof(struct smbios_type_32);
486 p->header.handle = 0x2000;
487 memset(p->reserved, 0, 6);
488 p->boot_status = 0; /* no errors detected */
490 start += sizeof(struct smbios_type_32);
496 /* Type 127 -- End of Table */
498 smbios_type_127_init(void *start)
500 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
502 p->header.type = 127;
503 p->header.length = sizeof(struct smbios_type_127);
504 p->header.handle = 0x7f00;
506 start += sizeof(struct smbios_type_127);
518 dprintf(3, "init SMBIOS tables\n");
520 char *start = malloc_high(2048); // XXX - determine real size
522 dprintf(1, "No memory for smbios tables\n");
526 u32 nr_structs = 0, max_struct_size = 0;
529 #define add_struct(fn) { \
532 if ((q - p) > max_struct_size) \
533 max_struct_size = q - p; \
537 add_struct(smbios_type_0_init(p));
538 add_struct(smbios_type_1_init(p));
539 add_struct(smbios_type_3_init(p));
540 int cpu_num, smp_cpus = CountCPUs;
541 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
542 add_struct(smbios_type_4_init(p, cpu_num));
543 add_struct(smbios_type_16_init(p));
544 add_struct(smbios_type_17_init(p));
545 add_struct(smbios_type_19_init(p));
546 add_struct(smbios_type_20_init(p));
547 add_struct(smbios_type_32_init(p));
548 add_struct(smbios_type_127_init(p));
552 smbios_entry_point_init(max_struct_size, p - start, start, nr_structs);