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;
144 /* SMBIOS type 16 - Physical Memory Array
145 * Associated with one type 17 (Memory Device).
147 struct smbios_type_16 {
148 struct smbios_structure_header header;
152 u32 maximum_capacity;
153 u16 memory_error_information_handle;
154 u16 number_of_memory_devices;
157 /* SMBIOS type 17 - Memory Device
158 * Associated with one type 19
160 struct smbios_type_17 {
161 struct smbios_structure_header header;
162 u16 physical_memory_array_handle;
163 u16 memory_error_information_handle;
169 u8 device_locator_str;
175 /* SMBIOS type 19 - Memory Array Mapped Address */
176 struct smbios_type_19 {
177 struct smbios_structure_header header;
178 u32 starting_address;
180 u16 memory_array_handle;
184 /* SMBIOS type 20 - Memory Device Mapped Address */
185 struct smbios_type_20 {
186 struct smbios_structure_header header;
187 u32 starting_address;
189 u16 memory_device_handle;
190 u16 memory_array_mapped_address_handle;
191 u8 partition_row_position;
192 u8 interleave_position;
193 u8 interleaved_data_depth;
196 /* SMBIOS type 32 - System Boot Information */
197 struct smbios_type_32 {
198 struct smbios_structure_header header;
203 /* SMBIOS type 127 -- End-of-table */
204 struct smbios_type_127 {
205 struct smbios_structure_header header;
209 /****************************************************************
211 ****************************************************************/
214 smbios_entry_point_init(void *start,
215 u16 max_structure_size,
216 u16 structure_table_length,
217 u32 structure_table_address,
218 u16 number_of_structures)
220 struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
222 memcpy(ep->anchor_string, "_SM_", 4);
224 ep->smbios_major_version = 2;
225 ep->smbios_minor_version = 4;
226 ep->max_structure_size = max_structure_size;
227 ep->entry_point_revision = 0;
228 memset(ep->formatted_area, 0, 5);
229 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
231 ep->structure_table_length = structure_table_length;
232 ep->structure_table_address = structure_table_address;
233 ep->number_of_structures = number_of_structures;
234 ep->smbios_bcd_revision = 0x24;
237 ep->intermediate_checksum = 0;
239 ep->checksum = -checksum(start, 0x10);
241 ep->intermediate_checksum = -checksum(start + 0x10, ep->length - 0x10);
244 /* Type 0 -- BIOS Information */
245 #define RELEASE_DATE_STR "01/01/2007"
247 smbios_type_0_init(void *start)
249 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
252 p->header.length = sizeof(struct smbios_type_0);
253 p->header.handle = 0;
256 p->bios_version_str = 1;
257 p->bios_starting_address_segment = 0xe800;
258 p->bios_release_date_str = 2;
259 p->bios_rom_size = 0; /* FIXME */
261 memset(p->bios_characteristics, 0, 7);
262 p->bios_characteristics[7] = 0x08; /* BIOS characteristics not supported */
263 p->bios_characteristics_extension_bytes[0] = 0;
264 p->bios_characteristics_extension_bytes[1] = 0;
266 p->system_bios_major_release = 1;
267 p->system_bios_minor_release = 0;
268 p->embedded_controller_major_release = 0xff;
269 p->embedded_controller_minor_release = 0xff;
271 start += sizeof(struct smbios_type_0);
272 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
273 start += sizeof(CONFIG_APPNAME);
274 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
275 start += sizeof(RELEASE_DATE_STR);
281 /* Type 1 -- System Information */
283 smbios_type_1_init(void *start)
285 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
287 p->header.length = sizeof(struct smbios_type_1);
288 p->header.handle = 0x100;
290 p->manufacturer_str = 0;
291 p->product_name_str = 0;
293 p->serial_number_str = 0;
297 p->wake_up_type = 0x06; /* power switch */
298 p->sku_number_str = 0;
301 start += sizeof(struct smbios_type_1);
307 /* Type 3 -- System Enclosure */
309 smbios_type_3_init(void *start)
311 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
314 p->header.length = sizeof(struct smbios_type_3);
315 p->header.handle = 0x300;
317 p->manufacturer_str = 0;
318 p->type = 0x01; /* other */
320 p->serial_number_str = 0;
321 p->asset_tag_number_str = 0;
322 p->boot_up_state = 0x03; /* safe */
323 p->power_supply_state = 0x03; /* safe */
324 p->thermal_state = 0x03; /* safe */
325 p->security_status = 0x02; /* unknown */
328 p->number_of_power_cords = 0;
329 p->contained_element_count = 0;
331 start += sizeof(struct smbios_type_3);
337 /* Type 4 -- Processor Information */
339 smbios_type_4_init(void *start, unsigned int cpu_number)
341 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
344 p->header.length = sizeof(struct smbios_type_4);
345 p->header.handle = 0x400 + cpu_number;
347 p->socket_designation_str = 1;
348 p->processor_type = 0x03; /* CPU */
349 p->processor_family = 0x01; /* other */
350 p->processor_manufacturer_str = 0;
352 u32 cpuid_signature, ebx, ecx, cpuid_features;
353 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
354 p->processor_id[0] = cpuid_signature;
355 p->processor_id[1] = cpuid_features;
357 p->processor_version_str = 0;
359 p->external_clock = 0;
361 p->max_speed = 0; /* unknown */
362 p->current_speed = 0; /* unknown */
364 p->status = 0x41; /* socket populated, CPU enabled */
365 p->processor_upgrade = 0x01; /* other */
367 start += sizeof(struct smbios_type_4);
369 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
370 ((char *)start)[4] = cpu_number + '0';
375 /* Type 16 -- Physical Memory Array */
377 smbios_type_16_init(void *start, u32 memsize)
379 struct smbios_type_16 *p = (struct smbios_type_16*)start;
382 p->header.length = sizeof(struct smbios_type_16);
383 p->header.handle = 0x1000;
385 p->location = 0x01; /* other */
386 p->use = 0x03; /* system memory */
387 p->error_correction = 0x01; /* other */
388 p->maximum_capacity = memsize * 1024;
389 p->memory_error_information_handle = 0xfffe; /* none provided */
390 p->number_of_memory_devices = 1;
392 start += sizeof(struct smbios_type_16);
398 /* Type 17 -- Memory Device */
400 smbios_type_17_init(void *start, u32 memory_size_mb)
402 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
405 p->header.length = sizeof(struct smbios_type_17);
406 p->header.handle = 0x1100;
408 p->physical_memory_array_handle = 0x1000;
411 /* truncate memory_size_mb to 16 bits and clear most significant
412 bit [indicates size in MB] */
413 p->size = (u16) memory_size_mb & 0x7fff;
414 p->form_factor = 0x09; /* DIMM */
416 p->device_locator_str = 1;
417 p->bank_locator_str = 0;
418 p->memory_type = 0x07; /* RAM */
421 start += sizeof(struct smbios_type_17);
422 memcpy((char *)start, "DIMM 1", 7);
429 /* Type 19 -- Memory Array Mapped Address */
431 smbios_type_19_init(void *start, u32 memory_size_mb)
433 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
436 p->header.length = sizeof(struct smbios_type_19);
437 p->header.handle = 0x1300;
439 p->starting_address = 0;
440 p->ending_address = (memory_size_mb-1) * 1024;
441 p->memory_array_handle = 0x1000;
442 p->partition_width = 1;
444 start += sizeof(struct smbios_type_19);
450 /* Type 20 -- Memory Device Mapped Address */
452 smbios_type_20_init(void *start, u32 memory_size_mb)
454 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
457 p->header.length = sizeof(struct smbios_type_20);
458 p->header.handle = 0x1400;
460 p->starting_address = 0;
461 p->ending_address = (memory_size_mb-1)*1024;
462 p->memory_device_handle = 0x1100;
463 p->memory_array_mapped_address_handle = 0x1300;
464 p->partition_row_position = 1;
465 p->interleave_position = 0;
466 p->interleaved_data_depth = 0;
468 start += sizeof(struct smbios_type_20);
474 /* Type 32 -- System Boot Information */
476 smbios_type_32_init(void *start)
478 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
481 p->header.length = sizeof(struct smbios_type_32);
482 p->header.handle = 0x2000;
483 memset(p->reserved, 0, 6);
484 p->boot_status = 0; /* no errors detected */
486 start += sizeof(struct smbios_type_32);
492 /* Type 127 -- End of Table */
494 smbios_type_127_init(void *start)
496 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
498 p->header.type = 127;
499 p->header.length = sizeof(struct smbios_type_127);
500 p->header.handle = 0x7f00;
502 start += sizeof(struct smbios_type_127);
514 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
516 int memsize = GET_EBDA(ram_size) / (1024 * 1024);
518 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
519 start = (void *)(bios_table_cur_addr);
521 p = (char *)start + sizeof(struct smbios_entry_point);
523 #define add_struct(fn) { \
526 if ((q - p) > max_struct_size) \
527 max_struct_size = q - p; \
531 add_struct(smbios_type_0_init(p));
532 add_struct(smbios_type_1_init(p));
533 add_struct(smbios_type_3_init(p));
534 int smp_cpus = smp_probe();
535 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
536 add_struct(smbios_type_4_init(p, cpu_num));
537 add_struct(smbios_type_16_init(p, memsize));
538 add_struct(smbios_type_17_init(p, memsize));
539 add_struct(smbios_type_19_init(p, memsize));
540 add_struct(smbios_type_20_init(p, memsize));
541 add_struct(smbios_type_32_init(p));
542 add_struct(smbios_type_127_init(p));
546 smbios_entry_point_init(
547 start, max_struct_size,
548 (p - (char *)start) - sizeof(struct smbios_entry_point),
549 (u32)(start + sizeof(struct smbios_entry_point)),
552 bios_table_cur_addr += (p - (char *)start);
554 dprintf(1, "SMBIOS table addr=0x%08lx\n", (unsigned long)start);