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 GPLv3 license.
8 #include "util.h" // dprintf
9 #include "memmap.h" // bios_table_cur_addr
10 #include "biosvar.h" // GET_EBDA
13 /****************************************************************
15 ****************************************************************/
18 uuid_probe(u8 *bios_uuid)
20 // Default to UUID not set
21 memset(bios_uuid, 0, 16);
23 if (! CONFIG_UUID_BACKDOOR)
28 // check if backdoor port exists
29 u32 eax, ebx, ecx, edx;
30 asm volatile ("outl %%eax, %%dx"
31 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
32 : "a" (0x564d5868), "b" (0), "c" (0xa), "d" (0x5658));
33 if (ebx != 0x564d5868)
36 u32 *uuid_ptr = (u32 *)bios_uuid;
38 asm volatile ("outl %%eax, %%dx"
39 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
40 : "a" (0x564d5868), "c" (0x13), "d" (0x5658));
48 /****************************************************************
50 ****************************************************************/
52 /* SMBIOS entry point -- must be written to a 16-bit aligned address
53 between 0xf0000 and 0xfffff.
55 struct smbios_entry_point {
56 char anchor_string[4];
59 u8 smbios_major_version;
60 u8 smbios_minor_version;
61 u16 max_structure_size;
62 u8 entry_point_revision;
64 char intermediate_anchor_string[5];
65 u8 intermediate_checksum;
66 u16 structure_table_length;
67 u32 structure_table_address;
68 u16 number_of_structures;
69 u8 smbios_bcd_revision;
72 /* This goes at the beginning of every SMBIOS structure. */
73 struct smbios_structure_header {
79 /* SMBIOS type 0 - BIOS Information */
80 struct smbios_type_0 {
81 struct smbios_structure_header header;
84 u16 bios_starting_address_segment;
85 u8 bios_release_date_str;
87 u8 bios_characteristics[8];
88 u8 bios_characteristics_extension_bytes[2];
89 u8 system_bios_major_release;
90 u8 system_bios_minor_release;
91 u8 embedded_controller_major_release;
92 u8 embedded_controller_minor_release;
95 /* SMBIOS type 1 - System Information */
96 struct smbios_type_1 {
97 struct smbios_structure_header header;
101 u8 serial_number_str;
108 /* SMBIOS type 3 - System Enclosure (v2.3) */
109 struct smbios_type_3 {
110 struct smbios_structure_header header;
114 u8 serial_number_str;
115 u8 asset_tag_number_str;
117 u8 power_supply_state;
122 u8 number_of_power_cords;
123 u8 contained_element_count;
124 // contained elements follow
127 /* SMBIOS type 4 - Processor Information (v2.0) */
128 struct smbios_type_4 {
129 struct smbios_structure_header header;
130 u8 socket_designation_str;
133 u8 processor_manufacturer_str;
135 u8 processor_version_str;
141 u8 processor_upgrade;
147 /* SMBIOS type 16 - Physical Memory Array
148 * Associated with one type 17 (Memory Device).
150 struct smbios_type_16 {
151 struct smbios_structure_header header;
155 u32 maximum_capacity;
156 u16 memory_error_information_handle;
157 u16 number_of_memory_devices;
160 /* SMBIOS type 17 - Memory Device
161 * Associated with one type 19
163 struct smbios_type_17 {
164 struct smbios_structure_header header;
165 u16 physical_memory_array_handle;
166 u16 memory_error_information_handle;
172 u8 device_locator_str;
178 /* SMBIOS type 19 - Memory Array Mapped Address */
179 struct smbios_type_19 {
180 struct smbios_structure_header header;
181 u32 starting_address;
183 u16 memory_array_handle;
187 /* SMBIOS type 20 - Memory Device Mapped Address */
188 struct smbios_type_20 {
189 struct smbios_structure_header header;
190 u32 starting_address;
192 u16 memory_device_handle;
193 u16 memory_array_mapped_address_handle;
194 u8 partition_row_position;
195 u8 interleave_position;
196 u8 interleaved_data_depth;
199 /* SMBIOS type 32 - System Boot Information */
200 struct smbios_type_32 {
201 struct smbios_structure_header header;
206 /* SMBIOS type 127 -- End-of-table */
207 struct smbios_type_127 {
208 struct smbios_structure_header header;
212 /****************************************************************
214 ****************************************************************/
217 smbios_entry_point_init(void *start,
218 u16 max_structure_size,
219 u16 structure_table_length,
220 u32 structure_table_address,
221 u16 number_of_structures)
223 struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
225 memcpy(ep->anchor_string, "_SM_", 4);
227 ep->smbios_major_version = 2;
228 ep->smbios_minor_version = 4;
229 ep->max_structure_size = max_structure_size;
230 ep->entry_point_revision = 0;
231 memset(ep->formatted_area, 0, 5);
232 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
234 ep->structure_table_length = structure_table_length;
235 ep->structure_table_address = structure_table_address;
236 ep->number_of_structures = number_of_structures;
237 ep->smbios_bcd_revision = 0x24;
240 ep->intermediate_checksum = 0;
242 ep->checksum = -checksum(start, 0x10);
244 ep->intermediate_checksum = -checksum(start + 0x10, ep->length - 0x10);
247 /* Type 0 -- BIOS Information */
248 #define RELEASE_DATE_STR "01/01/2007"
250 smbios_type_0_init(void *start)
252 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
255 p->header.length = sizeof(struct smbios_type_0);
256 p->header.handle = 0;
259 p->bios_version_str = 1;
260 p->bios_starting_address_segment = 0xe800;
261 p->bios_release_date_str = 2;
262 p->bios_rom_size = 0; /* FIXME */
264 memset(p->bios_characteristics, 0, sizeof(p->bios_characteristics));
265 p->bios_characteristics[0] = 0x08; /* BIOS characteristics not supported */
266 p->bios_characteristics_extension_bytes[0] = 0;
267 p->bios_characteristics_extension_bytes[1] = 0;
269 p->system_bios_major_release = 1;
270 p->system_bios_minor_release = 0;
271 p->embedded_controller_major_release = 0xff;
272 p->embedded_controller_minor_release = 0xff;
274 start += sizeof(struct smbios_type_0);
275 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
276 start += sizeof(CONFIG_APPNAME);
277 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
278 start += sizeof(RELEASE_DATE_STR);
284 /* Type 1 -- System Information */
286 smbios_type_1_init(void *start)
288 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
290 p->header.length = sizeof(struct smbios_type_1);
291 p->header.handle = 0x100;
293 p->manufacturer_str = 0;
294 p->product_name_str = 0;
296 p->serial_number_str = 0;
300 p->wake_up_type = 0x06; /* power switch */
301 p->sku_number_str = 0;
304 start += sizeof(struct smbios_type_1);
310 /* Type 3 -- System Enclosure */
312 smbios_type_3_init(void *start)
314 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
317 p->header.length = sizeof(struct smbios_type_3);
318 p->header.handle = 0x300;
320 p->manufacturer_str = 0;
321 p->type = 0x01; /* other */
323 p->serial_number_str = 0;
324 p->asset_tag_number_str = 0;
325 p->boot_up_state = 0x03; /* safe */
326 p->power_supply_state = 0x03; /* safe */
327 p->thermal_state = 0x03; /* safe */
328 p->security_status = 0x02; /* unknown */
331 p->number_of_power_cords = 0;
332 p->contained_element_count = 0;
334 start += sizeof(struct smbios_type_3);
340 /* Type 4 -- Processor Information */
342 smbios_type_4_init(void *start, unsigned int cpu_number)
344 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
347 p->header.length = sizeof(struct smbios_type_4);
348 p->header.handle = 0x400 + cpu_number;
350 p->socket_designation_str = 1;
351 p->processor_type = 0x03; /* CPU */
352 p->processor_family = 0x01; /* other */
353 p->processor_manufacturer_str = 0;
355 u32 cpuid_signature, ebx, ecx, cpuid_features;
356 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
357 p->processor_id[0] = cpuid_signature;
358 p->processor_id[1] = cpuid_features;
360 p->processor_version_str = 0;
362 p->external_clock = 0;
364 p->max_speed = 0; /* unknown */
365 p->current_speed = 0; /* unknown */
367 p->status = 0x41; /* socket populated, CPU enabled */
368 p->processor_upgrade = 0x01; /* other */
370 p->l1_cache_handle = 0xffff; /* cache information structure not provided */
371 p->l2_cache_handle = 0xffff;
372 p->l3_cache_handle = 0xffff;
374 start += sizeof(struct smbios_type_4);
376 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
377 ((char *)start)[4] = cpu_number + '0';
382 /* Type 16 -- Physical Memory Array */
384 smbios_type_16_init(void *start, u32 memsize)
386 struct smbios_type_16 *p = (struct smbios_type_16*)start;
389 p->header.length = sizeof(struct smbios_type_16);
390 p->header.handle = 0x1000;
392 p->location = 0x01; /* other */
393 p->use = 0x03; /* system memory */
394 p->error_correction = 0x01; /* other */
395 p->maximum_capacity = memsize * 1024;
396 p->memory_error_information_handle = 0xfffe; /* none provided */
397 p->number_of_memory_devices = 1;
399 start += sizeof(struct smbios_type_16);
405 /* Type 17 -- Memory Device */
407 smbios_type_17_init(void *start, u32 memory_size_mb)
409 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
412 p->header.length = sizeof(struct smbios_type_17);
413 p->header.handle = 0x1100;
415 p->physical_memory_array_handle = 0x1000;
418 /* truncate memory_size_mb to 16 bits and clear most significant
419 bit [indicates size in MB] */
420 p->size = (u16) memory_size_mb & 0x7fff;
421 p->form_factor = 0x09; /* DIMM */
423 p->device_locator_str = 1;
424 p->bank_locator_str = 0;
425 p->memory_type = 0x07; /* RAM */
428 start += sizeof(struct smbios_type_17);
429 memcpy((char *)start, "DIMM 1", 7);
436 /* Type 19 -- Memory Array Mapped Address */
438 smbios_type_19_init(void *start, u32 memory_size_mb)
440 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
443 p->header.length = sizeof(struct smbios_type_19);
444 p->header.handle = 0x1300;
446 p->starting_address = 0;
447 p->ending_address = (memory_size_mb-1) * 1024;
448 p->memory_array_handle = 0x1000;
449 p->partition_width = 1;
451 start += sizeof(struct smbios_type_19);
457 /* Type 20 -- Memory Device Mapped Address */
459 smbios_type_20_init(void *start, u32 memory_size_mb)
461 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
464 p->header.length = sizeof(struct smbios_type_20);
465 p->header.handle = 0x1400;
467 p->starting_address = 0;
468 p->ending_address = (memory_size_mb-1)*1024;
469 p->memory_device_handle = 0x1100;
470 p->memory_array_mapped_address_handle = 0x1300;
471 p->partition_row_position = 1;
472 p->interleave_position = 0;
473 p->interleaved_data_depth = 0;
475 start += sizeof(struct smbios_type_20);
481 /* Type 32 -- System Boot Information */
483 smbios_type_32_init(void *start)
485 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
488 p->header.length = sizeof(struct smbios_type_32);
489 p->header.handle = 0x2000;
490 memset(p->reserved, 0, 6);
491 p->boot_status = 0; /* no errors detected */
493 start += sizeof(struct smbios_type_32);
499 /* Type 127 -- End of Table */
501 smbios_type_127_init(void *start)
503 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
505 p->header.type = 127;
506 p->header.length = sizeof(struct smbios_type_127);
507 p->header.handle = 0x7f00;
509 start += sizeof(struct smbios_type_127);
521 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
523 int memsize = GET_EBDA(ram_size) / (1024 * 1024);
525 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
526 start = (void *)(bios_table_cur_addr);
528 p = (char *)start + sizeof(struct smbios_entry_point);
530 #define add_struct(fn) { \
533 if ((q - p) > max_struct_size) \
534 max_struct_size = q - p; \
538 add_struct(smbios_type_0_init(p));
539 add_struct(smbios_type_1_init(p));
540 add_struct(smbios_type_3_init(p));
541 int smp_cpus = smp_probe();
542 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
543 add_struct(smbios_type_4_init(p, cpu_num));
544 add_struct(smbios_type_16_init(p, memsize));
545 add_struct(smbios_type_17_init(p, memsize));
546 add_struct(smbios_type_19_init(p, memsize));
547 add_struct(smbios_type_20_init(p, memsize));
548 add_struct(smbios_type_32_init(p));
549 add_struct(smbios_type_127_init(p));
553 smbios_entry_point_init(
554 start, max_struct_size,
555 (p - (char *)start) - sizeof(struct smbios_entry_point),
556 (u32)(start + sizeof(struct smbios_entry_point)),
559 bios_table_cur_addr += (p - (char *)start);
561 dprintf(1, "SMBIOS table addr=0x%08lx\n", (unsigned long)start);