blob: 8df0f2da49f5b7efade00081bdb66868f08f8c81 [file] [log] [blame]
Kevin O'Connor0525d292008-07-04 06:18:30 -04001// smbios table generation (on emulators)
Kevin O'Connora4d35762008-03-08 15:43:03 -05002//
Kevin O'Connor2929c352009-07-25 13:48:27 -04003// Copyright (C) 2008,2009 Kevin O'Connor <kevin@koconnor.net>
Kevin O'Connor0525d292008-07-04 06:18:30 -04004// Copyright (C) 2006 Fabrice Bellard
Kevin O'Connora4d35762008-03-08 15:43:03 -05005//
Kevin O'Connorb1b7c2a2009-01-15 20:52:58 -05006// This file may be distributed under the terms of the GNU LGPLv3 license.
Kevin O'Connora4d35762008-03-08 15:43:03 -05007
Kevin O'Connorac8df8c2008-05-24 23:46:33 -04008#include "util.h" // dprintf
Kevin O'Connor9521e262008-07-04 13:04:29 -04009#include "biosvar.h" // GET_EBDA
Kevin O'Connor01a85202009-10-18 09:49:59 -040010#include "paravirt.h" // qemu_cfg_smbios_load_field
11#include "smbios.h" // struct smbios_entry_point
Kevin O'Connor0525d292008-07-04 06:18:30 -040012
Kevin O'Connora4d35762008-03-08 15:43:03 -050013static void
Kevin O'Connor2929c352009-07-25 13:48:27 -040014smbios_entry_point_init(u16 max_structure_size,
Kevin O'Connore51313d2008-03-12 21:19:34 -040015 u16 structure_table_length,
Kevin O'Connor2929c352009-07-25 13:48:27 -040016 void *structure_table_address,
Kevin O'Connore51313d2008-03-12 21:19:34 -040017 u16 number_of_structures)
Kevin O'Connora4d35762008-03-08 15:43:03 -050018{
Kevin O'Connor2929c352009-07-25 13:48:27 -040019 struct smbios_entry_point *ep = malloc_fseg(sizeof(*ep));
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -050020 void *finaltable = malloc_high(structure_table_length);
21 if (!ep || !finaltable) {
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -050022 warn_noalloc();
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -050023 free(ep);
24 free(finaltable);
Kevin O'Connor2929c352009-07-25 13:48:27 -040025 return;
26 }
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -050027 memcpy(finaltable, structure_table_address, structure_table_length);
Kevin O'Connora4d35762008-03-08 15:43:03 -050028
29 memcpy(ep->anchor_string, "_SM_", 4);
30 ep->length = 0x1f;
31 ep->smbios_major_version = 2;
32 ep->smbios_minor_version = 4;
33 ep->max_structure_size = max_structure_size;
34 ep->entry_point_revision = 0;
35 memset(ep->formatted_area, 0, 5);
36 memcpy(ep->intermediate_anchor_string, "_DMI_", 5);
37
38 ep->structure_table_length = structure_table_length;
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -050039 ep->structure_table_address = (u32)finaltable;
Kevin O'Connora4d35762008-03-08 15:43:03 -050040 ep->number_of_structures = number_of_structures;
41 ep->smbios_bcd_revision = 0x24;
42
Kevin O'Connor2929c352009-07-25 13:48:27 -040043 ep->checksum -= checksum(ep, 0x10);
Kevin O'Connora4d35762008-03-08 15:43:03 -050044
Kevin O'Connor2929c352009-07-25 13:48:27 -040045 ep->intermediate_checksum -= checksum((void*)ep + 0x10, ep->length - 0x10);
46
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -050047 dprintf(1, "SMBIOS ptr=%p table=%p\n", ep, finaltable);
Kevin O'Connor2e7ab8b2008-03-29 14:29:35 -040048}
Kevin O'Connora4d35762008-03-08 15:43:03 -050049
Kevin O'Connor4e4b4102009-10-08 21:21:59 -040050#define load_str_field_with_default(type, field, def) \
51 do { \
52 size = qemu_cfg_smbios_load_field(type, \
53 offsetof(struct smbios_type_##type, \
54 field), end); \
55 if (size > 0) { \
56 end += size; \
57 } else { \
58 memcpy(end, def, sizeof(def)); \
59 end += sizeof(def); \
60 } \
61 p->field = ++str_index; \
62 } while (0)
63
Alex Williamson17d3e462010-06-21 09:46:19 -060064#define load_str_field_or_skip(type, field) \
Kevin O'Connor4e4b4102009-10-08 21:21:59 -040065 do { \
66 size = qemu_cfg_smbios_load_field(type, \
67 offsetof(struct smbios_type_##type, \
68 field), end); \
69 if (size > 0) { \
70 end += size; \
71 p->field = ++str_index; \
72 } else { \
73 p->field = 0; \
74 } \
75 } while (0)
76
Alex Williamson17d3e462010-06-21 09:46:19 -060077#define set_field_with_default(type, field, def) \
78 do { \
79 if (!qemu_cfg_smbios_load_field(type, \
80 offsetof(struct smbios_type_##type, \
81 field), &p->field)) { \
82 p->field = def; \
83 } \
84 } while (0)
85
Kevin O'Connora4d35762008-03-08 15:43:03 -050086/* Type 0 -- BIOS Information */
87#define RELEASE_DATE_STR "01/01/2007"
88static void *
Kevin O'Connor4e4b4102009-10-08 21:21:59 -040089smbios_init_type_0(void *start)
Kevin O'Connora4d35762008-03-08 15:43:03 -050090{
91 struct smbios_type_0 *p = (struct smbios_type_0 *)start;
Kevin O'Connor4e4b4102009-10-08 21:21:59 -040092 char *end = (char *)start + sizeof(struct smbios_type_0);
93 size_t size;
94 int str_index = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -050095
96 p->header.type = 0;
97 p->header.length = sizeof(struct smbios_type_0);
98 p->header.handle = 0;
99
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400100 load_str_field_with_default(0, vendor_str, CONFIG_APPNAME);
101 load_str_field_with_default(0, bios_version_str, CONFIG_APPNAME);
102
Kevin O'Connora4d35762008-03-08 15:43:03 -0500103 p->bios_starting_address_segment = 0xe800;
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400104
105 load_str_field_with_default(0, bios_release_date_str, RELEASE_DATE_STR);
106
Kevin O'Connora4d35762008-03-08 15:43:03 -0500107 p->bios_rom_size = 0; /* FIXME */
108
Alex Williamson17d3e462010-06-21 09:46:19 -0600109 if (!qemu_cfg_smbios_load_field(0, offsetof(struct smbios_type_0,
110 bios_characteristics),
111 &p->bios_characteristics)) {
112 memset(p->bios_characteristics, 0, 8);
113 /* BIOS characteristics not supported */
114 p->bios_characteristics[0] = 0x08;
115 }
Kevin O'Connora4d35762008-03-08 15:43:03 -0500116
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400117 if (!qemu_cfg_smbios_load_field(0, offsetof(struct smbios_type_0,
Alex Williamson17d3e462010-06-21 09:46:19 -0600118 bios_characteristics_extension_bytes),
119 &p->bios_characteristics_extension_bytes)) {
120 p->bios_characteristics_extension_bytes[0] = 0;
121 /* Enable targeted content distribution. Needed for SVVP */
122 p->bios_characteristics_extension_bytes[1] = 4;
123 }
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400124
Alex Williamson17d3e462010-06-21 09:46:19 -0600125 set_field_with_default(0, system_bios_major_release, 1);
126 set_field_with_default(0, system_bios_minor_release, 0);
127 set_field_with_default(0, embedded_controller_major_release, 0xff);
128 set_field_with_default(0, embedded_controller_minor_release, 0xff);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500129
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400130 *end = 0;
131 end++;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500132
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400133 return end;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500134}
135
136/* Type 1 -- System Information */
137static void *
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400138smbios_init_type_1(void *start)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500139{
140 struct smbios_type_1 *p = (struct smbios_type_1 *)start;
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400141 char *end = (char *)start + sizeof(struct smbios_type_1);
142 size_t size;
143 int str_index = 0;
144
Kevin O'Connora4d35762008-03-08 15:43:03 -0500145 p->header.type = 1;
146 p->header.length = sizeof(struct smbios_type_1);
147 p->header.handle = 0x100;
148
Kevin O'Connorcf2affa2009-12-10 20:13:57 -0500149 load_str_field_with_default(1, manufacturer_str, CONFIG_APPNAME);
150 load_str_field_with_default(1, product_name_str, CONFIG_APPNAME);
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400151 load_str_field_or_skip(1, version_str);
152 load_str_field_or_skip(1, serial_number_str);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500153
Alex Williamson17d3e462010-06-21 09:46:19 -0600154 if (!qemu_cfg_smbios_load_field(1, offsetof(struct smbios_type_1,
155 uuid), &p->uuid)) {
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400156 memset(p->uuid, 0, 16);
Alex Williamson17d3e462010-06-21 09:46:19 -0600157 }
Kevin O'Connora4d35762008-03-08 15:43:03 -0500158
Alex Williamson17d3e462010-06-21 09:46:19 -0600159 set_field_with_default(1, wake_up_type, 0x06); /* power switch */
Kevin O'Connora4d35762008-03-08 15:43:03 -0500160
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400161 load_str_field_or_skip(1, sku_number_str);
162 load_str_field_or_skip(1, family_str);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500163
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400164 *end = 0;
165 end++;
166 if (!str_index) {
167 *end = 0;
168 end++;
169 }
170
171 return end;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500172}
173
174/* Type 3 -- System Enclosure */
175static void *
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400176smbios_init_type_3(void *start)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500177{
178 struct smbios_type_3 *p = (struct smbios_type_3 *)start;
Alex Williamson17d3e462010-06-21 09:46:19 -0600179 char *end = (char *)start + sizeof(struct smbios_type_3);
180 size_t size;
181 int str_index = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500182
183 p->header.type = 3;
184 p->header.length = sizeof(struct smbios_type_3);
185 p->header.handle = 0x300;
186
Alex Williamson17d3e462010-06-21 09:46:19 -0600187 load_str_field_with_default(3, manufacturer_str, CONFIG_APPNAME);
188 set_field_with_default(3, type, 0x01); /* other */
Kevin O'Connora4d35762008-03-08 15:43:03 -0500189
Alex Williamson17d3e462010-06-21 09:46:19 -0600190 load_str_field_or_skip(3, version_str);
191 load_str_field_or_skip(3, serial_number_str);
192 load_str_field_or_skip(3, asset_tag_number_str);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500193
Alex Williamson17d3e462010-06-21 09:46:19 -0600194 set_field_with_default(3, boot_up_state, 0x03); /* safe */
195 set_field_with_default(3, power_supply_state, 0x03); /* safe */
196 set_field_with_default(3, thermal_state, 0x03); /* safe */
197 set_field_with_default(3, security_status, 0x02); /* unknown */
198
199 set_field_with_default(3, oem_defined, 0);
200 set_field_with_default(3, height, 0);
201 set_field_with_default(3, number_of_power_cords, 0);
202 set_field_with_default(3, contained_element_count, 0);
203
204 *end = 0;
205 end++;
206 if (!str_index) {
207 *end = 0;
208 end++;
209 }
210
211 return end;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500212}
213
214/* Type 4 -- Processor Information */
215static void *
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400216smbios_init_type_4(void *start, unsigned int cpu_number)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500217{
218 struct smbios_type_4 *p = (struct smbios_type_4 *)start;
Alex Williamson17d3e462010-06-21 09:46:19 -0600219 char *end = (char *)start + sizeof(struct smbios_type_4);
220 size_t size;
221 int str_index = 0;
222 char name[1024];
Kevin O'Connora4d35762008-03-08 15:43:03 -0500223
224 p->header.type = 4;
225 p->header.length = sizeof(struct smbios_type_4);
226 p->header.handle = 0x400 + cpu_number;
227
Alex Williamson17d3e462010-06-21 09:46:19 -0600228 size = qemu_cfg_smbios_load_field(4, offsetof(struct smbios_type_4,
229 socket_designation_str),
230 name);
231 if (size)
232 snprintf(name + size - 1, sizeof(name) - size, "%2x", cpu_number);
233 else
234 snprintf(name, sizeof(name), "CPU%2x", cpu_number);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500235
Alex Williamson17d3e462010-06-21 09:46:19 -0600236 memcpy(end, name, strlen(name) + 1);
237 end += strlen(name) + 1;
238 p->socket_designation_str = ++str_index;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500239
Alex Williamson17d3e462010-06-21 09:46:19 -0600240 set_field_with_default(4, processor_type, 0x03); /* CPU */
241 set_field_with_default(4, processor_family, 0x01); /* other */
Kevin O'Connora4d35762008-03-08 15:43:03 -0500242
Alex Williamson17d3e462010-06-21 09:46:19 -0600243 load_str_field_with_default(4, processor_manufacturer_str, CONFIG_APPNAME);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500244
Alex Williamson17d3e462010-06-21 09:46:19 -0600245 if (!qemu_cfg_smbios_load_field(4, offsetof(struct smbios_type_4,
246 processor_id), p->processor_id)) {
247 u32 cpuid_signature, ebx, ecx, cpuid_features;
248 cpuid(1, &cpuid_signature, &ebx, &ecx, &cpuid_features);
249 p->processor_id[0] = cpuid_signature;
250 p->processor_id[1] = cpuid_features;
251 }
Kevin O'Connora4d35762008-03-08 15:43:03 -0500252
Alex Williamson17d3e462010-06-21 09:46:19 -0600253 load_str_field_or_skip(4, processor_version_str);
254 set_field_with_default(4, voltage, 0);
255 set_field_with_default(4, external_clock, 0);
Kevin O'Connorf2ce1912008-10-25 15:23:53 -0400256
Alex Williamson17d3e462010-06-21 09:46:19 -0600257 set_field_with_default(4, max_speed, 2000);
258 set_field_with_default(4, current_speed, 2000);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500259
Alex Williamson17d3e462010-06-21 09:46:19 -0600260 set_field_with_default(4, status, 0x41); /* socket populated, CPU enabled */
261 set_field_with_default(4, processor_upgrade, 0x01); /* other */
Kevin O'Connora4d35762008-03-08 15:43:03 -0500262
Alex Williamson17d3e462010-06-21 09:46:19 -0600263 /* cache information structure not provided */
264 p->l1_cache_handle = 0xffff;
265 p->l2_cache_handle = 0xffff;
266 p->l3_cache_handle = 0xffff;
267
268 *end = 0;
269 end++;
270 if (!str_index) {
271 *end = 0;
272 end++;
273 }
274
275 return end;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500276}
277
278/* Type 16 -- Physical Memory Array */
279static void *
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400280smbios_init_type_16(void *start, u32 memory_size_mb, int nr_mem_devs)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500281{
282 struct smbios_type_16 *p = (struct smbios_type_16*)start;
283
284 p->header.type = 16;
285 p->header.length = sizeof(struct smbios_type_16);
286 p->header.handle = 0x1000;
287
Alex Williamson17d3e462010-06-21 09:46:19 -0600288 set_field_with_default(16, location, 0x01); /* other */
289 set_field_with_default(16, use, 0x03); /* system memory */
290 /* Multi-bit ECC to make Microsoft happy */
291 set_field_with_default(16, error_correction, 0x06);
Alex Williamson6d663162010-05-07 13:38:55 -0600292 /* 0x80000000 = unknown, accept sizes < 2TB - TODO multiple arrays */
293 p->maximum_capacity = memory_size_mb < 2 << 20 ?
294 memory_size_mb << 10 : 0x80000000;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500295 p->memory_error_information_handle = 0xfffe; /* none provided */
Kevin O'Connor2a3dfea2009-10-07 19:44:23 -0400296 p->number_of_memory_devices = nr_mem_devs;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500297
298 start += sizeof(struct smbios_type_16);
Kevin O'Connore51313d2008-03-12 21:19:34 -0400299 *((u16 *)start) = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500300
301 return start + 2;
302}
303
304/* Type 17 -- Memory Device */
305static void *
Alex Williamson6d663162010-05-07 13:38:55 -0600306smbios_init_type_17(void *start, u32 size_mb, int instance)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500307{
308 struct smbios_type_17 *p = (struct smbios_type_17 *)start;
Alex Williamson17d3e462010-06-21 09:46:19 -0600309 char *end = (char *)start + sizeof(struct smbios_type_17);
310 size_t size;
311 int str_index = 0;
312 char name[1024];
Kevin O'Connora4d35762008-03-08 15:43:03 -0500313
314 p->header.type = 17;
315 p->header.length = sizeof(struct smbios_type_17);
Kevin O'Connor2a3dfea2009-10-07 19:44:23 -0400316 p->header.handle = 0x1100 + instance;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500317
318 p->physical_memory_array_handle = 0x1000;
Alex Williamson17d3e462010-06-21 09:46:19 -0600319 set_field_with_default(17, total_width, 64);
320 set_field_with_default(17, data_width, 64);
Kevin O'Connor2a3dfea2009-10-07 19:44:23 -0400321/* TODO: should assert in case something is wrong ASSERT((memory_size_mb & ~0x7fff) == 0); */
Alex Williamson6d663162010-05-07 13:38:55 -0600322 p->size = size_mb;
Alex Williamson17d3e462010-06-21 09:46:19 -0600323 set_field_with_default(17, form_factor, 0x09); /* DIMM */
Kevin O'Connora4d35762008-03-08 15:43:03 -0500324 p->device_set = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500325
Alex Williamson17d3e462010-06-21 09:46:19 -0600326 size = qemu_cfg_smbios_load_field(17, offsetof(struct smbios_type_17,
327 device_locator_str),
328 name);
329 if (size)
330 snprintf(name + size - 1, sizeof(name) - size, "%d", instance);
331 else
332 snprintf(name, sizeof(name), "DIMM %d", instance);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500333
Alex Williamson17d3e462010-06-21 09:46:19 -0600334 memcpy(end, name, strlen(name) + 1);
335 end += strlen(name) + 1;
336 p->device_locator_str = ++str_index;
337
338 load_str_field_or_skip(17, bank_locator_str);
339 set_field_with_default(17, memory_type, 0x07); /* RAM */
340 set_field_with_default(17, type_detail, 0);
341
342 *end = 0;
343 end++;
344 if (!str_index) {
345 *end = 0;
346 end++;
347 }
348
349 return end;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500350}
351
352/* Type 19 -- Memory Array Mapped Address */
353static void *
Alex Williamson6d663162010-05-07 13:38:55 -0600354smbios_init_type_19(void *start, u32 start_mb, u32 size_mb, int instance)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500355{
356 struct smbios_type_19 *p = (struct smbios_type_19 *)start;
357
358 p->header.type = 19;
359 p->header.length = sizeof(struct smbios_type_19);
Kevin O'Connor2a3dfea2009-10-07 19:44:23 -0400360 p->header.handle = 0x1300 + instance;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500361
Alex Williamson6d663162010-05-07 13:38:55 -0600362 p->starting_address = start_mb << 10;
363 p->ending_address = p->starting_address + (size_mb << 10) - 1;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500364 p->memory_array_handle = 0x1000;
365 p->partition_width = 1;
366
367 start += sizeof(struct smbios_type_19);
Kevin O'Connore51313d2008-03-12 21:19:34 -0400368 *((u16 *)start) = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500369
370 return start + 2;
371}
372
373/* Type 20 -- Memory Device Mapped Address */
374static void *
Alex Williamson6d663162010-05-07 13:38:55 -0600375smbios_init_type_20(void *start, u32 start_mb, u32 size_mb, int instance,
376 int dev_handle, int array_handle)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500377{
378 struct smbios_type_20 *p = (struct smbios_type_20 *)start;
379
380 p->header.type = 20;
381 p->header.length = sizeof(struct smbios_type_20);
Kevin O'Connor2a3dfea2009-10-07 19:44:23 -0400382 p->header.handle = 0x1400 + instance;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500383
Alex Williamson6d663162010-05-07 13:38:55 -0600384 p->starting_address = start_mb << 10;
385 p->ending_address = p->starting_address + (size_mb << 10) - 1;
386 p->memory_device_handle = 0x1100 + dev_handle;
387 p->memory_array_mapped_address_handle = 0x1300 + array_handle;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500388 p->partition_row_position = 1;
389 p->interleave_position = 0;
390 p->interleaved_data_depth = 0;
391
392 start += sizeof(struct smbios_type_20);
393
Kevin O'Connore51313d2008-03-12 21:19:34 -0400394 *((u16 *)start) = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500395 return start+2;
396}
397
398/* Type 32 -- System Boot Information */
399static void *
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400400smbios_init_type_32(void *start)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500401{
402 struct smbios_type_32 *p = (struct smbios_type_32 *)start;
403
404 p->header.type = 32;
405 p->header.length = sizeof(struct smbios_type_32);
406 p->header.handle = 0x2000;
407 memset(p->reserved, 0, 6);
Alex Williamson17d3e462010-06-21 09:46:19 -0600408 set_field_with_default(32, boot_status, 0); /* no errors detected */
Kevin O'Connora4d35762008-03-08 15:43:03 -0500409
410 start += sizeof(struct smbios_type_32);
Kevin O'Connore51313d2008-03-12 21:19:34 -0400411 *((u16 *)start) = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500412
413 return start+2;
414}
415
416/* Type 127 -- End of Table */
417static void *
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400418smbios_init_type_127(void *start)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500419{
420 struct smbios_type_127 *p = (struct smbios_type_127 *)start;
421
422 p->header.type = 127;
423 p->header.length = sizeof(struct smbios_type_127);
424 p->header.handle = 0x7f00;
425
426 start += sizeof(struct smbios_type_127);
Kevin O'Connore51313d2008-03-12 21:19:34 -0400427 *((u16 *)start) = 0;
Kevin O'Connora4d35762008-03-08 15:43:03 -0500428
429 return start + 2;
430}
431
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -0500432#define TEMPSMBIOSSIZE (32 * 1024)
433
Kevin O'Connor0525d292008-07-04 06:18:30 -0400434void
435smbios_init(void)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500436{
Kevin O'Connor6cb8ba92008-08-17 11:03:24 -0400437 if (! CONFIG_SMBIOS)
438 return;
439
Kevin O'Connor7b49cd92008-11-08 10:35:26 -0500440 dprintf(3, "init SMBIOS tables\n");
441
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -0500442 char *start = malloc_tmphigh(TEMPSMBIOSSIZE);
Kevin O'Connor2929c352009-07-25 13:48:27 -0400443 if (! start) {
Kevin O'Connorcfdc13f2010-02-14 13:07:54 -0500444 warn_noalloc();
Kevin O'Connor2929c352009-07-25 13:48:27 -0400445 return;
446 }
Kevin O'Connora4d35762008-03-08 15:43:03 -0500447
Kevin O'Connor2929c352009-07-25 13:48:27 -0400448 u32 nr_structs = 0, max_struct_size = 0;
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -0500449 char *q, *p = start;
450 char *end = start + TEMPSMBIOSSIZE - sizeof(struct smbios_type_127);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500451
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400452#define add_struct(type, args...) \
453 do { \
454 if (!qemu_cfg_smbios_load_external(type, &p, &nr_structs, \
455 &max_struct_size, end)) { \
456 q = smbios_init_type_##type(args); \
457 nr_structs++; \
458 if ((q - p) > max_struct_size) \
459 max_struct_size = q - p; \
460 p = q; \
461 } \
462 } while (0)
Kevin O'Connora4d35762008-03-08 15:43:03 -0500463
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400464 add_struct(0, p);
465 add_struct(1, p);
466 add_struct(3, p);
467
Kevin O'Connora26df9b2009-10-09 09:42:11 -0400468 int cpu_num;
469 for (cpu_num = 1; cpu_num <= MaxCountCPUs; cpu_num++)
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400470 add_struct(4, p, cpu_num);
Alex Williamson6d663162010-05-07 13:38:55 -0600471
472 int ram_mb = (RamSize + RamSizeOver4G) >> 20;
473 int nr_mem_devs = (ram_mb + 0x3fff) >> 14;
474 add_struct(16, p, ram_mb, nr_mem_devs);
475
476 int i, j;
Kevin O'Connor2a3dfea2009-10-07 19:44:23 -0400477 for (i = 0; i < nr_mem_devs; i++) {
Alex Williamson6d663162010-05-07 13:38:55 -0600478 u32 dev_mb = ((i == (nr_mem_devs - 1))
479 ? (((ram_mb - 1) & 0x3fff) + 1)
480 : 16384);
481 add_struct(17, p, dev_mb, i);
482 }
Kevin O'Connor7d09d0e2010-05-10 21:51:38 -0400483
Alex Williamson6d663162010-05-07 13:38:55 -0600484 add_struct(19, p, 0, RamSize >> 20, 0);
485 if (RamSizeOver4G)
486 add_struct(19, p, 4096, RamSizeOver4G >> 20, 1);
487
488 add_struct(20, p, 0, RamSize >> 20, 0, 0, 0);
489 if (RamSizeOver4G) {
490 u32 start_mb = 4096;
491 for (j = 1, i = 0; i < nr_mem_devs; i++, j++) {
492 u32 dev_mb = ((i == (nr_mem_devs - 1))
493 ? (((ram_mb - 1) & 0x3fff) + 1)
494 : 16384);
495 if (i == 0)
496 dev_mb -= RamSize >> 20;
497
498 add_struct(20, p, start_mb, dev_mb, j, i, 1);
499 start_mb += dev_mb;
500 }
Kevin O'Connor2a3dfea2009-10-07 19:44:23 -0400501 }
Kevin O'Connor4e4b4102009-10-08 21:21:59 -0400502
503 add_struct(32, p);
504 /* Add any remaining provided entries before the end marker */
505 for (i = 0; i < 256; i++)
506 qemu_cfg_smbios_load_external(i, &p, &nr_structs, &max_struct_size,
507 end);
508 add_struct(127, p);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500509
510#undef add_struct
511
Kevin O'Connor2929c352009-07-25 13:48:27 -0400512 smbios_entry_point_init(max_struct_size, p - start, start, nr_structs);
Kevin O'Connorfe2c3ee2009-12-26 23:26:44 -0500513 free(start);
Kevin O'Connora4d35762008-03-08 15:43:03 -0500514}