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);
26 // check if backdoor port exists
27 u32 eax, ebx, ecx, edx;
28 asm volatile ("outl %%eax, %%dx"
29 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
30 : "a" (0x564d5868), "c" (0xa), "d" (0x5658));
31 if (ebx != 0x564d5868)
34 u32 *uuid_ptr = (u32 *)bios_uuid;
36 asm volatile ("outl %%eax, %%dx"
37 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
38 : "a" (0x564d5868), "c" (0x13), "d" (0x5658));
46 /****************************************************************
48 ****************************************************************/
50 /* SMBIOS entry point -- must be written to a 16-bit aligned address
51 between 0xf0000 and 0xfffff.
53 struct smbios_entry_point {
54 char anchor_string[4];
57 u8 smbios_major_version;
58 u8 smbios_minor_version;
59 u16 max_structure_size;
60 u8 entry_point_revision;
62 char intermediate_anchor_string[5];
63 u8 intermediate_checksum;
64 u16 structure_table_length;
65 u32 structure_table_address;
66 u16 number_of_structures;
67 u8 smbios_bcd_revision;
68 } __attribute__((__packed__));
70 /* This goes at the beginning of every SMBIOS structure. */
71 struct smbios_structure_header {
75 } __attribute__((__packed__));
77 /* SMBIOS type 0 - BIOS Information */
78 struct smbios_type_0 {
79 struct smbios_structure_header header;
82 u16 bios_starting_address_segment;
83 u8 bios_release_date_str;
85 u8 bios_characteristics[8];
86 u8 bios_characteristics_extension_bytes[2];
87 u8 system_bios_major_release;
88 u8 system_bios_minor_release;
89 u8 embedded_controller_major_release;
90 u8 embedded_controller_minor_release;
91 } __attribute__((__packed__));
93 /* SMBIOS type 1 - System Information */
94 struct smbios_type_1 {
95 struct smbios_structure_header header;
104 } __attribute__((__packed__));
106 /* SMBIOS type 3 - System Enclosure (v2.3) */
107 struct smbios_type_3 {
108 struct smbios_structure_header header;
112 u8 serial_number_str;
113 u8 asset_tag_number_str;
115 u8 power_supply_state;
120 u8 number_of_power_cords;
121 u8 contained_element_count;
122 // contained elements follow
123 } __attribute__((__packed__));
125 /* SMBIOS type 4 - Processor Information (v2.0) */
126 struct smbios_type_4 {
127 struct smbios_structure_header header;
128 u8 socket_designation_str;
131 u8 processor_manufacturer_str;
133 u8 processor_version_str;
139 u8 processor_upgrade;
140 } __attribute__((__packed__));
142 /* SMBIOS type 16 - Physical Memory Array
143 * Associated with one type 17 (Memory Device).
145 struct smbios_type_16 {
146 struct smbios_structure_header header;
150 u32 maximum_capacity;
151 u16 memory_error_information_handle;
152 u16 number_of_memory_devices;
153 } __attribute__((__packed__));
155 /* SMBIOS type 17 - Memory Device
156 * Associated with one type 19
158 struct smbios_type_17 {
159 struct smbios_structure_header header;
160 u16 physical_memory_array_handle;
161 u16 memory_error_information_handle;
167 u8 device_locator_str;
171 } __attribute__((__packed__));
173 /* SMBIOS type 19 - Memory Array Mapped Address */
174 struct smbios_type_19 {
175 struct smbios_structure_header header;
176 u32 starting_address;
178 u16 memory_array_handle;
180 } __attribute__((__packed__));
182 /* SMBIOS type 20 - Memory Device Mapped Address */
183 struct smbios_type_20 {
184 struct smbios_structure_header header;
185 u32 starting_address;
187 u16 memory_device_handle;
188 u16 memory_array_mapped_address_handle;
189 u8 partition_row_position;
190 u8 interleave_position;
191 u8 interleaved_data_depth;
192 } __attribute__((__packed__));
194 /* SMBIOS type 32 - System Boot Information */
195 struct smbios_type_32 {
196 struct smbios_structure_header header;
199 } __attribute__((__packed__));
201 /* SMBIOS type 127 -- End-of-table */
202 struct smbios_type_127 {
203 struct smbios_structure_header header;
204 } __attribute__((__packed__));
207 /****************************************************************
209 ****************************************************************/
212 smbios_entry_point_init(void *start,
213 u16 max_structure_size,
214 u16 structure_table_length,
215 u32 structure_table_address,
216 u16 number_of_structures)
218 struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
220 memcpy(ep->anchor_string, "_SM_", 4);
222 ep->smbios_major_version = 2;
223 ep->smbios_minor_version = 4;
224 ep->max_structure_size = max_structure_size;
225 ep->entry_point_revision = 0;
226 memset(ep->formatted_area, 0, 5);
227 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
229 ep->structure_table_length = structure_table_length;
230 ep->structure_table_address = structure_table_address;
231 ep->number_of_structures = number_of_structures;
232 ep->smbios_bcd_revision = 0x24;
235 ep->intermediate_checksum = 0;
237 ep->checksum = -checksum(start, 0x10);
239 ep->intermediate_checksum = -checksum(start + 0x10, ep->length - 0x10);
242 /* Type 0 -- BIOS Information */
243 #define RELEASE_DATE_STR "01/01/2007"
245 smbios_type_0_init(void *start)
247 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
250 p->header.length = sizeof(struct smbios_type_0);
251 p->header.handle = 0;
254 p->bios_version_str = 1;
255 p->bios_starting_address_segment = 0xe800;
256 p->bios_release_date_str = 2;
257 p->bios_rom_size = 0; /* FIXME */
259 memset(p->bios_characteristics, 0, 7);
260 p->bios_characteristics[7] = 0x08; /* BIOS characteristics not supported */
261 p->bios_characteristics_extension_bytes[0] = 0;
262 p->bios_characteristics_extension_bytes[1] = 0;
264 p->system_bios_major_release = 1;
265 p->system_bios_minor_release = 0;
266 p->embedded_controller_major_release = 0xff;
267 p->embedded_controller_minor_release = 0xff;
269 start += sizeof(struct smbios_type_0);
270 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
271 start += sizeof(CONFIG_APPNAME);
272 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
273 start += sizeof(RELEASE_DATE_STR);
279 /* Type 1 -- System Information */
281 smbios_type_1_init(void *start)
283 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
285 p->header.length = sizeof(struct smbios_type_1);
286 p->header.handle = 0x100;
288 p->manufacturer_str = 0;
289 p->product_name_str = 0;
291 p->serial_number_str = 0;
295 p->wake_up_type = 0x06; /* power switch */
296 p->sku_number_str = 0;
299 start += sizeof(struct smbios_type_1);
305 /* Type 3 -- System Enclosure */
307 smbios_type_3_init(void *start)
309 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
312 p->header.length = sizeof(struct smbios_type_3);
313 p->header.handle = 0x300;
315 p->manufacturer_str = 0;
316 p->type = 0x01; /* other */
318 p->serial_number_str = 0;
319 p->asset_tag_number_str = 0;
320 p->boot_up_state = 0x03; /* safe */
321 p->power_supply_state = 0x03; /* safe */
322 p->thermal_state = 0x03; /* safe */
323 p->security_status = 0x02; /* unknown */
326 p->number_of_power_cords = 0;
327 p->contained_element_count = 0;
329 start += sizeof(struct smbios_type_3);
335 /* Type 4 -- Processor Information */
337 smbios_type_4_init(void *start, unsigned int cpu_number)
339 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
342 p->header.length = sizeof(struct smbios_type_4);
343 p->header.handle = 0x400 + cpu_number;
345 p->socket_designation_str = 1;
346 p->processor_type = 0x03; /* CPU */
347 p->processor_family = 0x01; /* other */
348 p->processor_manufacturer_str = 0;
350 u32 cpuid_signature, ebx, ecx, cpuid_features;
351 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
352 p->processor_id[0] = cpuid_signature;
353 p->processor_id[1] = cpuid_features;
355 p->processor_version_str = 0;
357 p->external_clock = 0;
359 p->max_speed = 0; /* unknown */
360 p->current_speed = 0; /* unknown */
362 p->status = 0x41; /* socket populated, CPU enabled */
363 p->processor_upgrade = 0x01; /* other */
365 start += sizeof(struct smbios_type_4);
367 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
368 ((char *)start)[4] = cpu_number + '0';
373 /* Type 16 -- Physical Memory Array */
375 smbios_type_16_init(void *start, u32 memsize)
377 struct smbios_type_16 *p = (struct smbios_type_16*)start;
380 p->header.length = sizeof(struct smbios_type_16);
381 p->header.handle = 0x1000;
383 p->location = 0x01; /* other */
384 p->use = 0x03; /* system memory */
385 p->error_correction = 0x01; /* other */
386 p->maximum_capacity = memsize * 1024;
387 p->memory_error_information_handle = 0xfffe; /* none provided */
388 p->number_of_memory_devices = 1;
390 start += sizeof(struct smbios_type_16);
396 /* Type 17 -- Memory Device */
398 smbios_type_17_init(void *start, u32 memory_size_mb)
400 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
403 p->header.length = sizeof(struct smbios_type_17);
404 p->header.handle = 0x1100;
406 p->physical_memory_array_handle = 0x1000;
409 /* truncate memory_size_mb to 16 bits and clear most significant
410 bit [indicates size in MB] */
411 p->size = (u16) memory_size_mb & 0x7fff;
412 p->form_factor = 0x09; /* DIMM */
414 p->device_locator_str = 1;
415 p->bank_locator_str = 0;
416 p->memory_type = 0x07; /* RAM */
419 start += sizeof(struct smbios_type_17);
420 memcpy((char *)start, "DIMM 1", 7);
427 /* Type 19 -- Memory Array Mapped Address */
429 smbios_type_19_init(void *start, u32 memory_size_mb)
431 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
434 p->header.length = sizeof(struct smbios_type_19);
435 p->header.handle = 0x1300;
437 p->starting_address = 0;
438 p->ending_address = (memory_size_mb-1) * 1024;
439 p->memory_array_handle = 0x1000;
440 p->partition_width = 1;
442 start += sizeof(struct smbios_type_19);
448 /* Type 20 -- Memory Device Mapped Address */
450 smbios_type_20_init(void *start, u32 memory_size_mb)
452 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
455 p->header.length = sizeof(struct smbios_type_20);
456 p->header.handle = 0x1400;
458 p->starting_address = 0;
459 p->ending_address = (memory_size_mb-1)*1024;
460 p->memory_device_handle = 0x1100;
461 p->memory_array_mapped_address_handle = 0x1300;
462 p->partition_row_position = 1;
463 p->interleave_position = 0;
464 p->interleaved_data_depth = 0;
466 start += sizeof(struct smbios_type_20);
472 /* Type 32 -- System Boot Information */
474 smbios_type_32_init(void *start)
476 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
479 p->header.length = sizeof(struct smbios_type_32);
480 p->header.handle = 0x2000;
481 memset(p->reserved, 0, 6);
482 p->boot_status = 0; /* no errors detected */
484 start += sizeof(struct smbios_type_32);
490 /* Type 127 -- End of Table */
492 smbios_type_127_init(void *start)
494 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
496 p->header.type = 127;
497 p->header.length = sizeof(struct smbios_type_127);
498 p->header.handle = 0x7f00;
500 start += sizeof(struct smbios_type_127);
509 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
511 int memsize = GET_EBDA(ram_size) / (1024 * 1024);
513 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
514 start = (void *)(bios_table_cur_addr);
516 p = (char *)start + sizeof(struct smbios_entry_point);
518 #define add_struct(fn) { \
521 if ((q - p) > max_struct_size) \
522 max_struct_size = q - p; \
526 add_struct(smbios_type_0_init(p));
527 add_struct(smbios_type_1_init(p));
528 add_struct(smbios_type_3_init(p));
529 int smp_cpus = smp_probe();
530 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
531 add_struct(smbios_type_4_init(p, cpu_num));
532 add_struct(smbios_type_16_init(p, memsize));
533 add_struct(smbios_type_17_init(p, memsize));
534 add_struct(smbios_type_19_init(p, memsize));
535 add_struct(smbios_type_20_init(p, memsize));
536 add_struct(smbios_type_32_init(p));
537 add_struct(smbios_type_127_init(p));
541 smbios_entry_point_init(
542 start, max_struct_size,
543 (p - (char *)start) - sizeof(struct smbios_entry_point),
544 (u32)(start + sizeof(struct smbios_entry_point)),
547 bios_table_cur_addr += (p - (char *)start);
549 dprintf(1, "SMBIOS table addr=0x%08lx\n", (unsigned long)start);