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
12 /****************************************************************
14 ****************************************************************/
17 uuid_probe(u8 *bios_uuid)
19 // Default to UUID not set
20 memset(bios_uuid, 0, 16);
25 // check if backdoor port exists
26 u32 eax, ebx, ecx, edx;
27 asm volatile ("outl %%eax, %%dx"
28 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
29 : "a" (0x564d5868), "c" (0xa), "d" (0x5658));
30 if (ebx != 0x564d5868)
33 u32 *uuid_ptr = (u32 *)bios_uuid;
35 asm volatile ("outl %%eax, %%dx"
36 : "=a" (eax), "=b" (ebx), "=c" (ecx), "=d" (edx)
37 : "a" (0x564d5868), "c" (0x13), "d" (0x5658));
45 /****************************************************************
47 ****************************************************************/
49 /* SMBIOS entry point -- must be written to a 16-bit aligned address
50 between 0xf0000 and 0xfffff.
52 struct smbios_entry_point {
53 char anchor_string[4];
56 u8 smbios_major_version;
57 u8 smbios_minor_version;
58 u16 max_structure_size;
59 u8 entry_point_revision;
61 char intermediate_anchor_string[5];
62 u8 intermediate_checksum;
63 u16 structure_table_length;
64 u32 structure_table_address;
65 u16 number_of_structures;
66 u8 smbios_bcd_revision;
67 } __attribute__((__packed__));
69 /* This goes at the beginning of every SMBIOS structure. */
70 struct smbios_structure_header {
74 } __attribute__((__packed__));
76 /* SMBIOS type 0 - BIOS Information */
77 struct smbios_type_0 {
78 struct smbios_structure_header header;
81 u16 bios_starting_address_segment;
82 u8 bios_release_date_str;
84 u8 bios_characteristics[8];
85 u8 bios_characteristics_extension_bytes[2];
86 u8 system_bios_major_release;
87 u8 system_bios_minor_release;
88 u8 embedded_controller_major_release;
89 u8 embedded_controller_minor_release;
90 } __attribute__((__packed__));
92 /* SMBIOS type 1 - System Information */
93 struct smbios_type_1 {
94 struct smbios_structure_header header;
103 } __attribute__((__packed__));
105 /* SMBIOS type 3 - System Enclosure (v2.3) */
106 struct smbios_type_3 {
107 struct smbios_structure_header header;
111 u8 serial_number_str;
112 u8 asset_tag_number_str;
114 u8 power_supply_state;
119 u8 number_of_power_cords;
120 u8 contained_element_count;
121 // contained elements follow
122 } __attribute__((__packed__));
124 /* SMBIOS type 4 - Processor Information (v2.0) */
125 struct smbios_type_4 {
126 struct smbios_structure_header header;
127 u8 socket_designation_str;
130 u8 processor_manufacturer_str;
132 u8 processor_version_str;
138 u8 processor_upgrade;
139 } __attribute__((__packed__));
141 /* SMBIOS type 16 - Physical Memory Array
142 * Associated with one type 17 (Memory Device).
144 struct smbios_type_16 {
145 struct smbios_structure_header header;
149 u32 maximum_capacity;
150 u16 memory_error_information_handle;
151 u16 number_of_memory_devices;
152 } __attribute__((__packed__));
154 /* SMBIOS type 17 - Memory Device
155 * Associated with one type 19
157 struct smbios_type_17 {
158 struct smbios_structure_header header;
159 u16 physical_memory_array_handle;
160 u16 memory_error_information_handle;
166 u8 device_locator_str;
170 } __attribute__((__packed__));
172 /* SMBIOS type 19 - Memory Array Mapped Address */
173 struct smbios_type_19 {
174 struct smbios_structure_header header;
175 u32 starting_address;
177 u16 memory_array_handle;
179 } __attribute__((__packed__));
181 /* SMBIOS type 20 - Memory Device Mapped Address */
182 struct smbios_type_20 {
183 struct smbios_structure_header header;
184 u32 starting_address;
186 u16 memory_device_handle;
187 u16 memory_array_mapped_address_handle;
188 u8 partition_row_position;
189 u8 interleave_position;
190 u8 interleaved_data_depth;
191 } __attribute__((__packed__));
193 /* SMBIOS type 32 - System Boot Information */
194 struct smbios_type_32 {
195 struct smbios_structure_header header;
198 } __attribute__((__packed__));
200 /* SMBIOS type 127 -- End-of-table */
201 struct smbios_type_127 {
202 struct smbios_structure_header header;
203 } __attribute__((__packed__));
206 /****************************************************************
208 ****************************************************************/
211 smbios_entry_point_init(void *start,
212 u16 max_structure_size,
213 u16 structure_table_length,
214 u32 structure_table_address,
215 u16 number_of_structures)
217 struct smbios_entry_point *ep = (struct smbios_entry_point *)start;
219 memcpy(ep->anchor_string, "_SM_", 4);
221 ep->smbios_major_version = 2;
222 ep->smbios_minor_version = 4;
223 ep->max_structure_size = max_structure_size;
224 ep->entry_point_revision = 0;
225 memset(ep->formatted_area, 0, 5);
226 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
228 ep->structure_table_length = structure_table_length;
229 ep->structure_table_address = structure_table_address;
230 ep->number_of_structures = number_of_structures;
231 ep->smbios_bcd_revision = 0x24;
234 ep->intermediate_checksum = 0;
236 ep->checksum = -checksum(start, 0x10);
238 ep->intermediate_checksum = -checksum(start + 0x10, ep->length - 0x10);
241 /* Type 0 -- BIOS Information */
242 #define RELEASE_DATE_STR "01/01/2007"
244 smbios_type_0_init(void *start)
246 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
249 p->header.length = sizeof(struct smbios_type_0);
250 p->header.handle = 0;
253 p->bios_version_str = 1;
254 p->bios_starting_address_segment = 0xe800;
255 p->bios_release_date_str = 2;
256 p->bios_rom_size = 0; /* FIXME */
258 memset(p->bios_characteristics, 0, 7);
259 p->bios_characteristics[7] = 0x08; /* BIOS characteristics not supported */
260 p->bios_characteristics_extension_bytes[0] = 0;
261 p->bios_characteristics_extension_bytes[1] = 0;
263 p->system_bios_major_release = 1;
264 p->system_bios_minor_release = 0;
265 p->embedded_controller_major_release = 0xff;
266 p->embedded_controller_minor_release = 0xff;
268 start += sizeof(struct smbios_type_0);
269 memcpy((char *)start, CONFIG_APPNAME, sizeof(CONFIG_APPNAME));
270 start += sizeof(CONFIG_APPNAME);
271 memcpy((char *)start, RELEASE_DATE_STR, sizeof(RELEASE_DATE_STR));
272 start += sizeof(RELEASE_DATE_STR);
278 /* Type 1 -- System Information */
280 smbios_type_1_init(void *start)
282 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
284 p->header.length = sizeof(struct smbios_type_1);
285 p->header.handle = 0x100;
287 p->manufacturer_str = 0;
288 p->product_name_str = 0;
290 p->serial_number_str = 0;
294 p->wake_up_type = 0x06; /* power switch */
295 p->sku_number_str = 0;
298 start += sizeof(struct smbios_type_1);
304 /* Type 3 -- System Enclosure */
306 smbios_type_3_init(void *start)
308 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
311 p->header.length = sizeof(struct smbios_type_3);
312 p->header.handle = 0x300;
314 p->manufacturer_str = 0;
315 p->type = 0x01; /* other */
317 p->serial_number_str = 0;
318 p->asset_tag_number_str = 0;
319 p->boot_up_state = 0x03; /* safe */
320 p->power_supply_state = 0x03; /* safe */
321 p->thermal_state = 0x03; /* safe */
322 p->security_status = 0x02; /* unknown */
325 p->number_of_power_cords = 0;
326 p->contained_element_count = 0;
328 start += sizeof(struct smbios_type_3);
334 /* Type 4 -- Processor Information */
336 smbios_type_4_init(void *start, unsigned int cpu_number)
338 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
341 p->header.length = sizeof(struct smbios_type_4);
342 p->header.handle = 0x400 + cpu_number;
344 p->socket_designation_str = 1;
345 p->processor_type = 0x03; /* CPU */
346 p->processor_family = 0x01; /* other */
347 p->processor_manufacturer_str = 0;
349 u32 cpuid_signature, ebx, ecx, cpuid_features;
350 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
351 p->processor_id[0] = cpuid_signature;
352 p->processor_id[1] = cpuid_features;
354 p->processor_version_str = 0;
356 p->external_clock = 0;
358 p->max_speed = 0; /* unknown */
359 p->current_speed = 0; /* unknown */
361 p->status = 0x41; /* socket populated, CPU enabled */
362 p->processor_upgrade = 0x01; /* other */
364 start += sizeof(struct smbios_type_4);
366 memcpy((char *)start, "CPU " "\0" "" "\0" "", 7);
367 ((char *)start)[4] = cpu_number + '0';
372 /* Type 16 -- Physical Memory Array */
374 smbios_type_16_init(void *start, u32 memsize)
376 struct smbios_type_16 *p = (struct smbios_type_16*)start;
379 p->header.length = sizeof(struct smbios_type_16);
380 p->header.handle = 0x1000;
382 p->location = 0x01; /* other */
383 p->use = 0x03; /* system memory */
384 p->error_correction = 0x01; /* other */
385 p->maximum_capacity = memsize * 1024;
386 p->memory_error_information_handle = 0xfffe; /* none provided */
387 p->number_of_memory_devices = 1;
389 start += sizeof(struct smbios_type_16);
395 /* Type 17 -- Memory Device */
397 smbios_type_17_init(void *start, u32 memory_size_mb)
399 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
402 p->header.length = sizeof(struct smbios_type_17);
403 p->header.handle = 0x1100;
405 p->physical_memory_array_handle = 0x1000;
408 /* truncate memory_size_mb to 16 bits and clear most significant
409 bit [indicates size in MB] */
410 p->size = (u16) memory_size_mb & 0x7fff;
411 p->form_factor = 0x09; /* DIMM */
413 p->device_locator_str = 1;
414 p->bank_locator_str = 0;
415 p->memory_type = 0x07; /* RAM */
418 start += sizeof(struct smbios_type_17);
419 memcpy((char *)start, "DIMM 1", 7);
426 /* Type 19 -- Memory Array Mapped Address */
428 smbios_type_19_init(void *start, u32 memory_size_mb)
430 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
433 p->header.length = sizeof(struct smbios_type_19);
434 p->header.handle = 0x1300;
436 p->starting_address = 0;
437 p->ending_address = (memory_size_mb-1) * 1024;
438 p->memory_array_handle = 0x1000;
439 p->partition_width = 1;
441 start += sizeof(struct smbios_type_19);
447 /* Type 20 -- Memory Device Mapped Address */
449 smbios_type_20_init(void *start, u32 memory_size_mb)
451 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
454 p->header.length = sizeof(struct smbios_type_20);
455 p->header.handle = 0x1400;
457 p->starting_address = 0;
458 p->ending_address = (memory_size_mb-1)*1024;
459 p->memory_device_handle = 0x1100;
460 p->memory_array_mapped_address_handle = 0x1300;
461 p->partition_row_position = 1;
462 p->interleave_position = 0;
463 p->interleaved_data_depth = 0;
465 start += sizeof(struct smbios_type_20);
471 /* Type 32 -- System Boot Information */
473 smbios_type_32_init(void *start)
475 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
478 p->header.length = sizeof(struct smbios_type_32);
479 p->header.handle = 0x2000;
480 memset(p->reserved, 0, 6);
481 p->boot_status = 0; /* no errors detected */
483 start += sizeof(struct smbios_type_32);
489 /* Type 127 -- End of Table */
491 smbios_type_127_init(void *start)
493 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
495 p->header.type = 127;
496 p->header.length = sizeof(struct smbios_type_127);
497 p->header.handle = 0x7f00;
499 start += sizeof(struct smbios_type_127);
508 unsigned cpu_num, nr_structs = 0, max_struct_size = 0;
510 int memsize = GET_EBDA(ram_size) / (1024 * 1024);
512 bios_table_cur_addr = ALIGN(bios_table_cur_addr, 16);
513 start = (void *)(bios_table_cur_addr);
515 p = (char *)start + sizeof(struct smbios_entry_point);
517 #define add_struct(fn) { \
520 if ((q - p) > max_struct_size) \
521 max_struct_size = q - p; \
525 add_struct(smbios_type_0_init(p));
526 add_struct(smbios_type_1_init(p));
527 add_struct(smbios_type_3_init(p));
528 int smp_cpus = smp_probe();
529 for (cpu_num = 1; cpu_num <= smp_cpus; cpu_num++)
530 add_struct(smbios_type_4_init(p, cpu_num));
531 add_struct(smbios_type_16_init(p, memsize));
532 add_struct(smbios_type_17_init(p, memsize));
533 add_struct(smbios_type_19_init(p, memsize));
534 add_struct(smbios_type_20_init(p, memsize));
535 add_struct(smbios_type_32_init(p));
536 add_struct(smbios_type_127_init(p));
540 smbios_entry_point_init(
541 start, max_struct_size,
542 (p - (char *)start) - sizeof(struct smbios_entry_point),
543 (u32)(start + sizeof(struct smbios_entry_point)),
546 bios_table_cur_addr += (p - (char *)start);
548 dprintf(1, "SMBIOS table addr=0x%08lx\n", (unsigned long)start);