]>
Commit | Line | Data |
---|---|---|
b6f6e3d3 AL |
1 | /* |
2 | * SMBIOS Support | |
3 | * | |
4 | * Copyright (C) 2009 Hewlett-Packard Development Company, L.P. | |
4f953d2f | 5 | * Copyright (C) 2013 Red Hat, Inc. |
b6f6e3d3 AL |
6 | * |
7 | * Authors: | |
8 | * Alex Williamson <[email protected]> | |
4f953d2f | 9 | * Markus Armbruster <[email protected]> |
b6f6e3d3 AL |
10 | * |
11 | * This work is licensed under the terms of the GNU GPL, version 2. See | |
12 | * the COPYING file in the top-level directory. | |
13 | * | |
6b620ca3 PB |
14 | * Contributions after 2012-01-13 are licensed under the terms of the |
15 | * GNU GPL, version 2 or (at your option) any later version. | |
b6f6e3d3 AL |
16 | */ |
17 | ||
0430891c | 18 | #include "qemu/osdep.h" |
da34e65c | 19 | #include "qapi/error.h" |
4f953d2f | 20 | #include "qemu/config-file.h" |
5bb95e41 | 21 | #include "qemu/error-report.h" |
9c17d615 | 22 | #include "sysemu/sysemu.h" |
c97294ec | 23 | #include "sysemu/cpus.h" |
60d8f328 | 24 | #include "hw/smbios/smbios.h" |
83c9f4ca | 25 | #include "hw/loader.h" |
60d8f328 | 26 | #include "exec/cpu-common.h" |
0517cc98 | 27 | #include "smbios_build.h" |
35658f6e | 28 | #include "hw/smbios/ipmi.h" |
e6667f71 GS |
29 | |
30 | /* legacy structures and constants for <= 2.0 machines */ | |
b6f6e3d3 AL |
31 | struct smbios_header { |
32 | uint16_t length; | |
33 | uint8_t type; | |
541dc0d4 | 34 | } QEMU_PACKED; |
b6f6e3d3 AL |
35 | |
36 | struct smbios_field { | |
37 | struct smbios_header header; | |
38 | uint8_t type; | |
39 | uint16_t offset; | |
40 | uint8_t data[]; | |
541dc0d4 | 41 | } QEMU_PACKED; |
b6f6e3d3 AL |
42 | |
43 | struct smbios_table { | |
44 | struct smbios_header header; | |
45 | uint8_t data[]; | |
541dc0d4 | 46 | } QEMU_PACKED; |
b6f6e3d3 AL |
47 | |
48 | #define SMBIOS_FIELD_ENTRY 0 | |
49 | #define SMBIOS_TABLE_ENTRY 1 | |
50 | ||
b6f6e3d3 AL |
51 | static uint8_t *smbios_entries; |
52 | static size_t smbios_entries_len; | |
c97294ec | 53 | static bool smbios_legacy = true; |
caad057b | 54 | static bool smbios_uuid_encoded = true; |
e6667f71 GS |
55 | /* end: legacy structures & constants for <= 2.0 machines */ |
56 | ||
57 | ||
0517cc98 CM |
58 | uint8_t *smbios_tables; |
59 | size_t smbios_tables_len; | |
60 | unsigned smbios_table_max; | |
61 | unsigned smbios_table_cnt; | |
86299120 WH |
62 | static SmbiosEntryPointType smbios_ep_type = SMBIOS_ENTRY_POINT_21; |
63 | ||
64 | static SmbiosEntryPoint ep; | |
c97294ec | 65 | |
09c0848e | 66 | static int smbios_type4_count = 0; |
fc3b3295 | 67 | static bool smbios_immutable; |
c97294ec GS |
68 | static bool smbios_have_defaults; |
69 | static uint32_t smbios_cpuid_version, smbios_cpuid_features, smbios_smp_sockets; | |
09c0848e | 70 | |
2e6e8d7a GS |
71 | static DECLARE_BITMAP(have_binfile_bitmap, SMBIOS_MAX_TYPE+1); |
72 | static DECLARE_BITMAP(have_fields_bitmap, SMBIOS_MAX_TYPE+1); | |
ec2df8c1 | 73 | |
fc3b3295 MA |
74 | static struct { |
75 | const char *vendor, *version, *date; | |
84351843 | 76 | bool have_major_minor, uefi; |
fc3b3295 MA |
77 | uint8_t major, minor; |
78 | } type0; | |
79 | ||
80 | static struct { | |
81 | const char *manufacturer, *product, *version, *serial, *sku, *family; | |
82 | /* uuid is in qemu_uuid[] */ | |
83 | } type1; | |
84 | ||
c97294ec GS |
85 | static struct { |
86 | const char *manufacturer, *product, *version, *serial, *asset, *location; | |
87 | } type2; | |
88 | ||
89 | static struct { | |
90 | const char *manufacturer, *version, *serial, *asset, *sku; | |
91 | } type3; | |
92 | ||
93 | static struct { | |
94 | const char *sock_pfx, *manufacturer, *version, *serial, *asset, *part; | |
95 | } type4; | |
96 | ||
97 | static struct { | |
98 | const char *loc_pfx, *bank, *manufacturer, *serial, *asset, *part; | |
3ebd6cc8 | 99 | uint16_t speed; |
c97294ec GS |
100 | } type17; |
101 | ||
4f953d2f MA |
102 | static QemuOptsList qemu_smbios_opts = { |
103 | .name = "smbios", | |
104 | .head = QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts.head), | |
105 | .desc = { | |
106 | /* | |
107 | * no elements => accept any params | |
108 | * validation will happen later | |
109 | */ | |
110 | { /* end of list */ } | |
111 | } | |
112 | }; | |
113 | ||
114 | static const QemuOptDesc qemu_smbios_file_opts[] = { | |
115 | { | |
116 | .name = "file", | |
117 | .type = QEMU_OPT_STRING, | |
118 | .help = "binary file containing an SMBIOS element", | |
119 | }, | |
120 | { /* end of list */ } | |
121 | }; | |
122 | ||
123 | static const QemuOptDesc qemu_smbios_type0_opts[] = { | |
124 | { | |
125 | .name = "type", | |
126 | .type = QEMU_OPT_NUMBER, | |
127 | .help = "SMBIOS element type", | |
128 | },{ | |
129 | .name = "vendor", | |
130 | .type = QEMU_OPT_STRING, | |
131 | .help = "vendor name", | |
132 | },{ | |
133 | .name = "version", | |
134 | .type = QEMU_OPT_STRING, | |
135 | .help = "version number", | |
136 | },{ | |
137 | .name = "date", | |
138 | .type = QEMU_OPT_STRING, | |
139 | .help = "release date", | |
140 | },{ | |
141 | .name = "release", | |
142 | .type = QEMU_OPT_STRING, | |
143 | .help = "revision number", | |
84351843 GS |
144 | },{ |
145 | .name = "uefi", | |
146 | .type = QEMU_OPT_BOOL, | |
147 | .help = "uefi support", | |
4f953d2f MA |
148 | }, |
149 | { /* end of list */ } | |
150 | }; | |
151 | ||
152 | static const QemuOptDesc qemu_smbios_type1_opts[] = { | |
153 | { | |
154 | .name = "type", | |
155 | .type = QEMU_OPT_NUMBER, | |
156 | .help = "SMBIOS element type", | |
157 | },{ | |
158 | .name = "manufacturer", | |
159 | .type = QEMU_OPT_STRING, | |
160 | .help = "manufacturer name", | |
161 | },{ | |
162 | .name = "product", | |
163 | .type = QEMU_OPT_STRING, | |
164 | .help = "product name", | |
165 | },{ | |
166 | .name = "version", | |
167 | .type = QEMU_OPT_STRING, | |
168 | .help = "version number", | |
169 | },{ | |
170 | .name = "serial", | |
171 | .type = QEMU_OPT_STRING, | |
172 | .help = "serial number", | |
173 | },{ | |
174 | .name = "uuid", | |
175 | .type = QEMU_OPT_STRING, | |
176 | .help = "UUID", | |
177 | },{ | |
178 | .name = "sku", | |
179 | .type = QEMU_OPT_STRING, | |
180 | .help = "SKU number", | |
181 | },{ | |
182 | .name = "family", | |
183 | .type = QEMU_OPT_STRING, | |
184 | .help = "family name", | |
185 | }, | |
186 | { /* end of list */ } | |
187 | }; | |
188 | ||
c97294ec GS |
189 | static const QemuOptDesc qemu_smbios_type2_opts[] = { |
190 | { | |
191 | .name = "type", | |
192 | .type = QEMU_OPT_NUMBER, | |
193 | .help = "SMBIOS element type", | |
194 | },{ | |
195 | .name = "manufacturer", | |
196 | .type = QEMU_OPT_STRING, | |
197 | .help = "manufacturer name", | |
198 | },{ | |
199 | .name = "product", | |
200 | .type = QEMU_OPT_STRING, | |
201 | .help = "product name", | |
202 | },{ | |
203 | .name = "version", | |
204 | .type = QEMU_OPT_STRING, | |
205 | .help = "version number", | |
206 | },{ | |
207 | .name = "serial", | |
208 | .type = QEMU_OPT_STRING, | |
209 | .help = "serial number", | |
210 | },{ | |
211 | .name = "asset", | |
212 | .type = QEMU_OPT_STRING, | |
213 | .help = "asset tag number", | |
214 | },{ | |
215 | .name = "location", | |
216 | .type = QEMU_OPT_STRING, | |
217 | .help = "location in chassis", | |
218 | }, | |
219 | { /* end of list */ } | |
220 | }; | |
221 | ||
222 | static const QemuOptDesc qemu_smbios_type3_opts[] = { | |
223 | { | |
224 | .name = "type", | |
225 | .type = QEMU_OPT_NUMBER, | |
226 | .help = "SMBIOS element type", | |
227 | },{ | |
228 | .name = "manufacturer", | |
229 | .type = QEMU_OPT_STRING, | |
230 | .help = "manufacturer name", | |
231 | },{ | |
232 | .name = "version", | |
233 | .type = QEMU_OPT_STRING, | |
234 | .help = "version number", | |
235 | },{ | |
236 | .name = "serial", | |
237 | .type = QEMU_OPT_STRING, | |
238 | .help = "serial number", | |
239 | },{ | |
240 | .name = "asset", | |
241 | .type = QEMU_OPT_STRING, | |
242 | .help = "asset tag number", | |
243 | },{ | |
244 | .name = "sku", | |
245 | .type = QEMU_OPT_STRING, | |
246 | .help = "SKU number", | |
247 | }, | |
248 | { /* end of list */ } | |
249 | }; | |
250 | ||
251 | static const QemuOptDesc qemu_smbios_type4_opts[] = { | |
252 | { | |
253 | .name = "type", | |
254 | .type = QEMU_OPT_NUMBER, | |
255 | .help = "SMBIOS element type", | |
256 | },{ | |
257 | .name = "sock_pfx", | |
258 | .type = QEMU_OPT_STRING, | |
259 | .help = "socket designation string prefix", | |
260 | },{ | |
261 | .name = "manufacturer", | |
262 | .type = QEMU_OPT_STRING, | |
263 | .help = "manufacturer name", | |
264 | },{ | |
265 | .name = "version", | |
266 | .type = QEMU_OPT_STRING, | |
267 | .help = "version number", | |
268 | },{ | |
269 | .name = "serial", | |
270 | .type = QEMU_OPT_STRING, | |
271 | .help = "serial number", | |
272 | },{ | |
273 | .name = "asset", | |
274 | .type = QEMU_OPT_STRING, | |
275 | .help = "asset tag number", | |
276 | },{ | |
277 | .name = "part", | |
278 | .type = QEMU_OPT_STRING, | |
279 | .help = "part number", | |
280 | }, | |
281 | { /* end of list */ } | |
282 | }; | |
283 | ||
284 | static const QemuOptDesc qemu_smbios_type17_opts[] = { | |
285 | { | |
286 | .name = "type", | |
287 | .type = QEMU_OPT_NUMBER, | |
288 | .help = "SMBIOS element type", | |
289 | },{ | |
290 | .name = "loc_pfx", | |
291 | .type = QEMU_OPT_STRING, | |
292 | .help = "device locator string prefix", | |
293 | },{ | |
294 | .name = "bank", | |
295 | .type = QEMU_OPT_STRING, | |
296 | .help = "bank locator string", | |
297 | },{ | |
298 | .name = "manufacturer", | |
299 | .type = QEMU_OPT_STRING, | |
300 | .help = "manufacturer name", | |
301 | },{ | |
302 | .name = "serial", | |
303 | .type = QEMU_OPT_STRING, | |
304 | .help = "serial number", | |
305 | },{ | |
306 | .name = "asset", | |
307 | .type = QEMU_OPT_STRING, | |
308 | .help = "asset tag number", | |
309 | },{ | |
310 | .name = "part", | |
311 | .type = QEMU_OPT_STRING, | |
312 | .help = "part number", | |
3ebd6cc8 GS |
313 | },{ |
314 | .name = "speed", | |
315 | .type = QEMU_OPT_NUMBER, | |
316 | .help = "maximum capable speed", | |
c97294ec GS |
317 | }, |
318 | { /* end of list */ } | |
319 | }; | |
320 | ||
4f953d2f MA |
321 | static void smbios_register_config(void) |
322 | { | |
323 | qemu_add_opts(&qemu_smbios_opts); | |
324 | } | |
325 | ||
34294e2f | 326 | opts_init(smbios_register_config); |
4f953d2f | 327 | |
09c0848e BK |
328 | static void smbios_validate_table(void) |
329 | { | |
c97294ec GS |
330 | uint32_t expect_t4_count = smbios_legacy ? smp_cpus : smbios_smp_sockets; |
331 | ||
332 | if (smbios_type4_count && smbios_type4_count != expect_t4_count) { | |
333 | error_report("Expected %d SMBIOS Type 4 tables, got %d instead", | |
334 | expect_t4_count, smbios_type4_count); | |
09c0848e BK |
335 | exit(1); |
336 | } | |
337 | } | |
b6f6e3d3 | 338 | |
e6667f71 GS |
339 | |
340 | /* legacy setup functions for <= 2.0 machines */ | |
fc3b3295 | 341 | static void smbios_add_field(int type, int offset, const void *data, size_t len) |
b6f6e3d3 AL |
342 | { |
343 | struct smbios_field *field; | |
344 | ||
b6f6e3d3 AL |
345 | if (!smbios_entries) { |
346 | smbios_entries_len = sizeof(uint16_t); | |
7267c094 | 347 | smbios_entries = g_malloc0(smbios_entries_len); |
b6f6e3d3 | 348 | } |
7267c094 | 349 | smbios_entries = g_realloc(smbios_entries, smbios_entries_len + |
b6f6e3d3 AL |
350 | sizeof(*field) + len); |
351 | field = (struct smbios_field *)(smbios_entries + smbios_entries_len); | |
352 | field->header.type = SMBIOS_FIELD_ENTRY; | |
353 | field->header.length = cpu_to_le16(sizeof(*field) + len); | |
354 | ||
355 | field->type = type; | |
356 | field->offset = cpu_to_le16(offset); | |
357 | memcpy(field->data, data, len); | |
358 | ||
359 | smbios_entries_len += sizeof(*field) + len; | |
360 | (*(uint16_t *)smbios_entries) = | |
361 | cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1); | |
362 | } | |
363 | ||
e26d3e73 | 364 | static void smbios_maybe_add_str(int type, int offset, const char *data) |
b6f6e3d3 | 365 | { |
e26d3e73 MA |
366 | if (data) { |
367 | smbios_add_field(type, offset, data, strlen(data) + 1); | |
4f953d2f | 368 | } |
e26d3e73 MA |
369 | } |
370 | ||
371 | static void smbios_build_type_0_fields(void) | |
372 | { | |
373 | smbios_maybe_add_str(0, offsetof(struct smbios_type_0, vendor_str), | |
374 | type0.vendor); | |
375 | smbios_maybe_add_str(0, offsetof(struct smbios_type_0, bios_version_str), | |
376 | type0.version); | |
377 | smbios_maybe_add_str(0, offsetof(struct smbios_type_0, | |
b6f6e3d3 | 378 | bios_release_date_str), |
e26d3e73 | 379 | type0.date); |
fc3b3295 | 380 | if (type0.have_major_minor) { |
b6f6e3d3 | 381 | smbios_add_field(0, offsetof(struct smbios_type_0, |
ebc85e3f | 382 | system_bios_major_release), |
fc3b3295 | 383 | &type0.major, 1); |
b6f6e3d3 | 384 | smbios_add_field(0, offsetof(struct smbios_type_0, |
ebc85e3f | 385 | system_bios_minor_release), |
fc3b3295 | 386 | &type0.minor, 1); |
b6f6e3d3 AL |
387 | } |
388 | } | |
389 | ||
fc3b3295 | 390 | static void smbios_build_type_1_fields(void) |
b6f6e3d3 | 391 | { |
e26d3e73 MA |
392 | smbios_maybe_add_str(1, offsetof(struct smbios_type_1, manufacturer_str), |
393 | type1.manufacturer); | |
394 | smbios_maybe_add_str(1, offsetof(struct smbios_type_1, product_name_str), | |
395 | type1.product); | |
396 | smbios_maybe_add_str(1, offsetof(struct smbios_type_1, version_str), | |
397 | type1.version); | |
398 | smbios_maybe_add_str(1, offsetof(struct smbios_type_1, serial_number_str), | |
399 | type1.serial); | |
400 | smbios_maybe_add_str(1, offsetof(struct smbios_type_1, sku_number_str), | |
401 | type1.sku); | |
402 | smbios_maybe_add_str(1, offsetof(struct smbios_type_1, family_str), | |
403 | type1.family); | |
fc3b3295 | 404 | if (qemu_uuid_set) { |
caad057b EH |
405 | /* We don't encode the UUID in the "wire format" here because this |
406 | * function is for legacy mode and needs to keep the guest ABI, and | |
407 | * because we don't know what's the SMBIOS version advertised by the | |
408 | * BIOS. | |
409 | */ | |
fc3b3295 MA |
410 | smbios_add_field(1, offsetof(struct smbios_type_1, uuid), |
411 | qemu_uuid, 16); | |
412 | } | |
413 | } | |
414 | ||
e6667f71 | 415 | uint8_t *smbios_get_table_legacy(size_t *length) |
fc3b3295 | 416 | { |
c97294ec GS |
417 | if (!smbios_legacy) { |
418 | *length = 0; | |
419 | return NULL; | |
420 | } | |
421 | ||
fc3b3295 MA |
422 | if (!smbios_immutable) { |
423 | smbios_build_type_0_fields(); | |
424 | smbios_build_type_1_fields(); | |
425 | smbios_validate_table(); | |
426 | smbios_immutable = true; | |
427 | } | |
428 | *length = smbios_entries_len; | |
429 | return smbios_entries; | |
430 | } | |
e6667f71 GS |
431 | /* end: legacy setup functions for <= 2.0 machines */ |
432 | ||
fc3b3295 | 433 | |
0517cc98 | 434 | bool smbios_skip_table(uint8_t type, bool required_table) |
c97294ec GS |
435 | { |
436 | if (test_bit(type, have_binfile_bitmap)) { | |
437 | return true; /* user provided their own binary blob(s) */ | |
438 | } | |
439 | if (test_bit(type, have_fields_bitmap)) { | |
440 | return false; /* user provided fields via command line */ | |
441 | } | |
442 | if (smbios_have_defaults && required_table) { | |
443 | return false; /* we're building tables, and this one's required */ | |
444 | } | |
445 | return true; | |
446 | } | |
447 | ||
c97294ec GS |
448 | static void smbios_build_type_0_table(void) |
449 | { | |
450 | SMBIOS_BUILD_TABLE_PRE(0, 0x000, false); /* optional, leave up to BIOS */ | |
451 | ||
452 | SMBIOS_TABLE_SET_STR(0, vendor_str, type0.vendor); | |
453 | SMBIOS_TABLE_SET_STR(0, bios_version_str, type0.version); | |
454 | ||
fb5be2e8 | 455 | t->bios_starting_address_segment = cpu_to_le16(0xE800); /* from SeaBIOS */ |
c97294ec GS |
456 | |
457 | SMBIOS_TABLE_SET_STR(0, bios_release_date_str, type0.date); | |
458 | ||
459 | t->bios_rom_size = 0; /* hardcoded in SeaBIOS with FIXME comment */ | |
460 | ||
84351843 | 461 | t->bios_characteristics = cpu_to_le64(0x08); /* Not supported */ |
c97294ec | 462 | t->bios_characteristics_extension_bytes[0] = 0; |
84351843 GS |
463 | t->bios_characteristics_extension_bytes[1] = 0x14; /* TCD/SVVP | VM */ |
464 | if (type0.uefi) { | |
465 | t->bios_characteristics_extension_bytes[1] |= 0x08; /* |= UEFI */ | |
466 | } | |
c97294ec GS |
467 | |
468 | if (type0.have_major_minor) { | |
469 | t->system_bios_major_release = type0.major; | |
470 | t->system_bios_minor_release = type0.minor; | |
471 | } else { | |
472 | t->system_bios_major_release = 0; | |
473 | t->system_bios_minor_release = 0; | |
474 | } | |
475 | ||
476 | /* hardcoded in SeaBIOS */ | |
477 | t->embedded_controller_major_release = 0xFF; | |
478 | t->embedded_controller_minor_release = 0xFF; | |
479 | ||
480 | SMBIOS_BUILD_TABLE_POST; | |
481 | } | |
482 | ||
caad057b EH |
483 | /* Encode UUID from the big endian encoding described on RFC4122 to the wire |
484 | * format specified by SMBIOS version 2.6. | |
485 | */ | |
486 | static void smbios_encode_uuid(struct smbios_uuid *uuid, const uint8_t *buf) | |
487 | { | |
488 | memcpy(uuid, buf, 16); | |
489 | if (smbios_uuid_encoded) { | |
490 | uuid->time_low = bswap32(uuid->time_low); | |
491 | uuid->time_mid = bswap16(uuid->time_mid); | |
492 | uuid->time_hi_and_version = bswap16(uuid->time_hi_and_version); | |
493 | } | |
494 | } | |
495 | ||
c97294ec GS |
496 | static void smbios_build_type_1_table(void) |
497 | { | |
498 | SMBIOS_BUILD_TABLE_PRE(1, 0x100, true); /* required */ | |
499 | ||
500 | SMBIOS_TABLE_SET_STR(1, manufacturer_str, type1.manufacturer); | |
501 | SMBIOS_TABLE_SET_STR(1, product_name_str, type1.product); | |
502 | SMBIOS_TABLE_SET_STR(1, version_str, type1.version); | |
503 | SMBIOS_TABLE_SET_STR(1, serial_number_str, type1.serial); | |
504 | if (qemu_uuid_set) { | |
caad057b | 505 | smbios_encode_uuid(&t->uuid, qemu_uuid); |
c97294ec | 506 | } else { |
caad057b | 507 | memset(&t->uuid, 0, 16); |
c97294ec GS |
508 | } |
509 | t->wake_up_type = 0x06; /* power switch */ | |
510 | SMBIOS_TABLE_SET_STR(1, sku_number_str, type1.sku); | |
511 | SMBIOS_TABLE_SET_STR(1, family_str, type1.family); | |
512 | ||
513 | SMBIOS_BUILD_TABLE_POST; | |
514 | } | |
515 | ||
516 | static void smbios_build_type_2_table(void) | |
517 | { | |
518 | SMBIOS_BUILD_TABLE_PRE(2, 0x200, false); /* optional */ | |
519 | ||
520 | SMBIOS_TABLE_SET_STR(2, manufacturer_str, type2.manufacturer); | |
521 | SMBIOS_TABLE_SET_STR(2, product_str, type2.product); | |
522 | SMBIOS_TABLE_SET_STR(2, version_str, type2.version); | |
523 | SMBIOS_TABLE_SET_STR(2, serial_number_str, type2.serial); | |
524 | SMBIOS_TABLE_SET_STR(2, asset_tag_number_str, type2.asset); | |
525 | t->feature_flags = 0x01; /* Motherboard */ | |
526 | SMBIOS_TABLE_SET_STR(2, location_str, type2.location); | |
fb5be2e8 | 527 | t->chassis_handle = cpu_to_le16(0x300); /* Type 3 (System enclosure) */ |
c97294ec GS |
528 | t->board_type = 0x0A; /* Motherboard */ |
529 | t->contained_element_count = 0; | |
530 | ||
531 | SMBIOS_BUILD_TABLE_POST; | |
532 | } | |
533 | ||
534 | static void smbios_build_type_3_table(void) | |
535 | { | |
536 | SMBIOS_BUILD_TABLE_PRE(3, 0x300, true); /* required */ | |
537 | ||
538 | SMBIOS_TABLE_SET_STR(3, manufacturer_str, type3.manufacturer); | |
539 | t->type = 0x01; /* Other */ | |
540 | SMBIOS_TABLE_SET_STR(3, version_str, type3.version); | |
541 | SMBIOS_TABLE_SET_STR(3, serial_number_str, type3.serial); | |
542 | SMBIOS_TABLE_SET_STR(3, asset_tag_number_str, type3.asset); | |
543 | t->boot_up_state = 0x03; /* Safe */ | |
544 | t->power_supply_state = 0x03; /* Safe */ | |
545 | t->thermal_state = 0x03; /* Safe */ | |
546 | t->security_status = 0x02; /* Unknown */ | |
fb5be2e8 | 547 | t->oem_defined = cpu_to_le32(0); |
c97294ec GS |
548 | t->height = 0; |
549 | t->number_of_power_cords = 0; | |
550 | t->contained_element_count = 0; | |
551 | SMBIOS_TABLE_SET_STR(3, sku_number_str, type3.sku); | |
552 | ||
553 | SMBIOS_BUILD_TABLE_POST; | |
554 | } | |
555 | ||
556 | static void smbios_build_type_4_table(unsigned instance) | |
557 | { | |
558 | char sock_str[128]; | |
559 | ||
560 | SMBIOS_BUILD_TABLE_PRE(4, 0x400 + instance, true); /* required */ | |
561 | ||
562 | snprintf(sock_str, sizeof(sock_str), "%s%2x", type4.sock_pfx, instance); | |
563 | SMBIOS_TABLE_SET_STR(4, socket_designation_str, sock_str); | |
564 | t->processor_type = 0x03; /* CPU */ | |
fb5be2e8 | 565 | t->processor_family = 0x01; /* Other */ |
c97294ec | 566 | SMBIOS_TABLE_SET_STR(4, processor_manufacturer_str, type4.manufacturer); |
fb5be2e8 GS |
567 | t->processor_id[0] = cpu_to_le32(smbios_cpuid_version); |
568 | t->processor_id[1] = cpu_to_le32(smbios_cpuid_features); | |
c97294ec GS |
569 | SMBIOS_TABLE_SET_STR(4, processor_version_str, type4.version); |
570 | t->voltage = 0; | |
fb5be2e8 | 571 | t->external_clock = cpu_to_le16(0); /* Unknown */ |
07d01c9c EH |
572 | /* SVVP requires max_speed and current_speed to not be unknown. */ |
573 | t->max_speed = cpu_to_le16(2000); /* 2000 MHz */ | |
574 | t->current_speed = cpu_to_le16(2000); /* 2000 MHz */ | |
c97294ec GS |
575 | t->status = 0x41; /* Socket populated, CPU enabled */ |
576 | t->processor_upgrade = 0x01; /* Other */ | |
fb5be2e8 GS |
577 | t->l1_cache_handle = cpu_to_le16(0xFFFF); /* N/A */ |
578 | t->l2_cache_handle = cpu_to_le16(0xFFFF); /* N/A */ | |
579 | t->l3_cache_handle = cpu_to_le16(0xFFFF); /* N/A */ | |
c97294ec GS |
580 | SMBIOS_TABLE_SET_STR(4, serial_number_str, type4.serial); |
581 | SMBIOS_TABLE_SET_STR(4, asset_tag_number_str, type4.asset); | |
582 | SMBIOS_TABLE_SET_STR(4, part_number_str, type4.part); | |
583 | t->core_count = t->core_enabled = smp_cores; | |
584 | t->thread_count = smp_threads; | |
fb5be2e8 GS |
585 | t->processor_characteristics = cpu_to_le16(0x02); /* Unknown */ |
586 | t->processor_family2 = cpu_to_le16(0x01); /* Other */ | |
c97294ec GS |
587 | |
588 | SMBIOS_BUILD_TABLE_POST; | |
589 | smbios_type4_count++; | |
590 | } | |
591 | ||
592 | #define ONE_KB ((ram_addr_t)1 << 10) | |
593 | #define ONE_MB ((ram_addr_t)1 << 20) | |
594 | #define ONE_GB ((ram_addr_t)1 << 30) | |
595 | ||
596 | #define MAX_T16_STD_SZ 0x80000000 /* 2T in Kilobytes */ | |
597 | ||
598 | static void smbios_build_type_16_table(unsigned dimm_cnt) | |
599 | { | |
f4ec5cd2 | 600 | uint64_t size_kb; |
c97294ec GS |
601 | |
602 | SMBIOS_BUILD_TABLE_PRE(16, 0x1000, true); /* required */ | |
603 | ||
604 | t->location = 0x01; /* Other */ | |
605 | t->use = 0x03; /* System memory */ | |
606 | t->error_correction = 0x06; /* Multi-bit ECC (for Microsoft, per SeaBIOS) */ | |
607 | size_kb = QEMU_ALIGN_UP(ram_size, ONE_KB) / ONE_KB; | |
608 | if (size_kb < MAX_T16_STD_SZ) { | |
fb5be2e8 GS |
609 | t->maximum_capacity = cpu_to_le32(size_kb); |
610 | t->extended_maximum_capacity = cpu_to_le64(0); | |
c97294ec | 611 | } else { |
fb5be2e8 GS |
612 | t->maximum_capacity = cpu_to_le32(MAX_T16_STD_SZ); |
613 | t->extended_maximum_capacity = cpu_to_le64(ram_size); | |
c97294ec | 614 | } |
fb5be2e8 GS |
615 | t->memory_error_information_handle = cpu_to_le16(0xFFFE); /* Not provided */ |
616 | t->number_of_memory_devices = cpu_to_le16(dimm_cnt); | |
c97294ec GS |
617 | |
618 | SMBIOS_BUILD_TABLE_POST; | |
619 | } | |
620 | ||
621 | #define MAX_T17_STD_SZ 0x7FFF /* (32G - 1M), in Megabytes */ | |
622 | #define MAX_T17_EXT_SZ 0x80000000 /* 2P, in Megabytes */ | |
623 | ||
f4ec5cd2 | 624 | static void smbios_build_type_17_table(unsigned instance, uint64_t size) |
c97294ec GS |
625 | { |
626 | char loc_str[128]; | |
f4ec5cd2 | 627 | uint64_t size_mb; |
c97294ec GS |
628 | |
629 | SMBIOS_BUILD_TABLE_PRE(17, 0x1100 + instance, true); /* required */ | |
630 | ||
fb5be2e8 GS |
631 | t->physical_memory_array_handle = cpu_to_le16(0x1000); /* Type 16 above */ |
632 | t->memory_error_information_handle = cpu_to_le16(0xFFFE); /* Not provided */ | |
633 | t->total_width = cpu_to_le16(0xFFFF); /* Unknown */ | |
634 | t->data_width = cpu_to_le16(0xFFFF); /* Unknown */ | |
c97294ec GS |
635 | size_mb = QEMU_ALIGN_UP(size, ONE_MB) / ONE_MB; |
636 | if (size_mb < MAX_T17_STD_SZ) { | |
fb5be2e8 GS |
637 | t->size = cpu_to_le16(size_mb); |
638 | t->extended_size = cpu_to_le32(0); | |
c97294ec GS |
639 | } else { |
640 | assert(size_mb < MAX_T17_EXT_SZ); | |
fb5be2e8 GS |
641 | t->size = cpu_to_le16(MAX_T17_STD_SZ); |
642 | t->extended_size = cpu_to_le32(size_mb); | |
c97294ec GS |
643 | } |
644 | t->form_factor = 0x09; /* DIMM */ | |
645 | t->device_set = 0; /* Not in a set */ | |
646 | snprintf(loc_str, sizeof(loc_str), "%s %d", type17.loc_pfx, instance); | |
647 | SMBIOS_TABLE_SET_STR(17, device_locator_str, loc_str); | |
648 | SMBIOS_TABLE_SET_STR(17, bank_locator_str, type17.bank); | |
649 | t->memory_type = 0x07; /* RAM */ | |
fb5be2e8 | 650 | t->type_detail = cpu_to_le16(0x02); /* Other */ |
3ebd6cc8 | 651 | t->speed = cpu_to_le16(type17.speed); |
c97294ec GS |
652 | SMBIOS_TABLE_SET_STR(17, manufacturer_str, type17.manufacturer); |
653 | SMBIOS_TABLE_SET_STR(17, serial_number_str, type17.serial); | |
654 | SMBIOS_TABLE_SET_STR(17, asset_tag_number_str, type17.asset); | |
655 | SMBIOS_TABLE_SET_STR(17, part_number_str, type17.part); | |
656 | t->attributes = 0; /* Unknown */ | |
3ebd6cc8 | 657 | t->configured_clock_speed = t->speed; /* reuse value for max speed */ |
0d73394a GS |
658 | t->minimum_voltage = cpu_to_le16(0); /* Unknown */ |
659 | t->maximum_voltage = cpu_to_le16(0); /* Unknown */ | |
660 | t->configured_voltage = cpu_to_le16(0); /* Unknown */ | |
c97294ec GS |
661 | |
662 | SMBIOS_BUILD_TABLE_POST; | |
663 | } | |
664 | ||
665 | static void smbios_build_type_19_table(unsigned instance, | |
f4ec5cd2 | 666 | uint64_t start, uint64_t size) |
c97294ec | 667 | { |
f4ec5cd2 | 668 | uint64_t end, start_kb, end_kb; |
c97294ec GS |
669 | |
670 | SMBIOS_BUILD_TABLE_PRE(19, 0x1300 + instance, true); /* required */ | |
671 | ||
672 | end = start + size - 1; | |
673 | assert(end > start); | |
674 | start_kb = start / ONE_KB; | |
675 | end_kb = end / ONE_KB; | |
676 | if (start_kb < UINT32_MAX && end_kb < UINT32_MAX) { | |
fb5be2e8 GS |
677 | t->starting_address = cpu_to_le32(start_kb); |
678 | t->ending_address = cpu_to_le32(end_kb); | |
679 | t->extended_starting_address = | |
680 | t->extended_ending_address = cpu_to_le64(0); | |
c97294ec | 681 | } else { |
fb5be2e8 GS |
682 | t->starting_address = t->ending_address = cpu_to_le32(UINT32_MAX); |
683 | t->extended_starting_address = cpu_to_le64(start); | |
684 | t->extended_ending_address = cpu_to_le64(end); | |
c97294ec | 685 | } |
fb5be2e8 | 686 | t->memory_array_handle = cpu_to_le16(0x1000); /* Type 16 above */ |
c97294ec GS |
687 | t->partition_width = 1; /* One device per row */ |
688 | ||
689 | SMBIOS_BUILD_TABLE_POST; | |
690 | } | |
691 | ||
692 | static void smbios_build_type_32_table(void) | |
693 | { | |
694 | SMBIOS_BUILD_TABLE_PRE(32, 0x2000, true); /* required */ | |
695 | ||
696 | memset(t->reserved, 0, 6); | |
697 | t->boot_status = 0; /* No errors detected */ | |
698 | ||
699 | SMBIOS_BUILD_TABLE_POST; | |
700 | } | |
701 | ||
702 | static void smbios_build_type_127_table(void) | |
703 | { | |
704 | SMBIOS_BUILD_TABLE_PRE(127, 0x7F00, true); /* required */ | |
705 | SMBIOS_BUILD_TABLE_POST; | |
706 | } | |
707 | ||
708 | void smbios_set_cpuid(uint32_t version, uint32_t features) | |
709 | { | |
710 | smbios_cpuid_version = version; | |
711 | smbios_cpuid_features = features; | |
712 | } | |
713 | ||
cb36acb6 GS |
714 | #define SMBIOS_SET_DEFAULT(field, value) \ |
715 | if (!field) { \ | |
716 | field = value; \ | |
717 | } | |
718 | ||
719 | void smbios_set_defaults(const char *manufacturer, const char *product, | |
caad057b | 720 | const char *version, bool legacy_mode, |
86299120 | 721 | bool uuid_encoded, SmbiosEntryPointType ep_type) |
cb36acb6 | 722 | { |
c97294ec GS |
723 | smbios_have_defaults = true; |
724 | smbios_legacy = legacy_mode; | |
caad057b | 725 | smbios_uuid_encoded = uuid_encoded; |
86299120 | 726 | smbios_ep_type = ep_type; |
c97294ec GS |
727 | |
728 | /* drop unwanted version of command-line file blob(s) */ | |
729 | if (smbios_legacy) { | |
a10678b0 | 730 | g_free(smbios_tables); |
c97294ec GS |
731 | /* in legacy mode, also complain if fields were given for types > 1 */ |
732 | if (find_next_bit(have_fields_bitmap, | |
733 | SMBIOS_MAX_TYPE+1, 2) < SMBIOS_MAX_TYPE+1) { | |
734 | error_report("can't process fields for smbios " | |
735 | "types > 1 on machine versions < 2.1!"); | |
736 | exit(1); | |
737 | } | |
738 | } else { | |
a10678b0 | 739 | g_free(smbios_entries); |
c97294ec GS |
740 | } |
741 | ||
cb36acb6 GS |
742 | SMBIOS_SET_DEFAULT(type1.manufacturer, manufacturer); |
743 | SMBIOS_SET_DEFAULT(type1.product, product); | |
744 | SMBIOS_SET_DEFAULT(type1.version, version); | |
c97294ec GS |
745 | SMBIOS_SET_DEFAULT(type2.manufacturer, manufacturer); |
746 | SMBIOS_SET_DEFAULT(type2.product, product); | |
747 | SMBIOS_SET_DEFAULT(type2.version, version); | |
748 | SMBIOS_SET_DEFAULT(type3.manufacturer, manufacturer); | |
749 | SMBIOS_SET_DEFAULT(type3.version, version); | |
750 | SMBIOS_SET_DEFAULT(type4.sock_pfx, "CPU"); | |
751 | SMBIOS_SET_DEFAULT(type4.manufacturer, manufacturer); | |
752 | SMBIOS_SET_DEFAULT(type4.version, version); | |
753 | SMBIOS_SET_DEFAULT(type17.loc_pfx, "DIMM"); | |
754 | SMBIOS_SET_DEFAULT(type17.manufacturer, manufacturer); | |
755 | } | |
756 | ||
757 | static void smbios_entry_point_setup(void) | |
758 | { | |
86299120 WH |
759 | switch (smbios_ep_type) { |
760 | case SMBIOS_ENTRY_POINT_21: | |
761 | memcpy(ep.ep21.anchor_string, "_SM_", 4); | |
762 | memcpy(ep.ep21.intermediate_anchor_string, "_DMI_", 5); | |
763 | ep.ep21.length = sizeof(struct smbios_21_entry_point); | |
764 | ep.ep21.entry_point_revision = 0; /* formatted_area reserved */ | |
765 | memset(ep.ep21.formatted_area, 0, 5); | |
766 | ||
767 | /* compliant with smbios spec v2.8 */ | |
768 | ep.ep21.smbios_major_version = 2; | |
769 | ep.ep21.smbios_minor_version = 8; | |
770 | ep.ep21.smbios_bcd_revision = 0x28; | |
771 | ||
772 | /* set during table construction, but BIOS may override: */ | |
773 | ep.ep21.structure_table_length = cpu_to_le16(smbios_tables_len); | |
774 | ep.ep21.max_structure_size = cpu_to_le16(smbios_table_max); | |
775 | ep.ep21.number_of_structures = cpu_to_le16(smbios_table_cnt); | |
776 | ||
777 | /* BIOS must recalculate */ | |
778 | ep.ep21.checksum = 0; | |
779 | ep.ep21.intermediate_checksum = 0; | |
780 | ep.ep21.structure_table_address = cpu_to_le32(0); | |
781 | ||
782 | break; | |
783 | case SMBIOS_ENTRY_POINT_30: | |
784 | memcpy(ep.ep30.anchor_string, "_SM3_", 5); | |
785 | ep.ep30.length = sizeof(struct smbios_30_entry_point); | |
786 | ep.ep30.entry_point_revision = 1; | |
787 | ep.ep30.reserved = 0; | |
788 | ||
789 | /* compliant with smbios spec 3.0 */ | |
790 | ep.ep30.smbios_major_version = 3; | |
791 | ep.ep30.smbios_minor_version = 0; | |
792 | ep.ep30.smbios_doc_rev = 0; | |
793 | ||
794 | /* set during table construct, but BIOS might override */ | |
795 | ep.ep30.structure_table_max_size = cpu_to_le32(smbios_tables_len); | |
796 | ||
797 | /* BIOS must recalculate */ | |
798 | ep.ep30.checksum = 0; | |
799 | ep.ep30.structure_table_address = cpu_to_le64(0); | |
800 | ||
801 | break; | |
802 | default: | |
803 | abort(); | |
804 | break; | |
805 | } | |
c97294ec GS |
806 | } |
807 | ||
89cc4a27 WH |
808 | void smbios_get_tables(const struct smbios_phys_mem_area *mem_array, |
809 | const unsigned int mem_array_size, | |
810 | uint8_t **tables, size_t *tables_len, | |
c97294ec GS |
811 | uint8_t **anchor, size_t *anchor_len) |
812 | { | |
89cc4a27 | 813 | unsigned i, dimm_cnt; |
c97294ec GS |
814 | |
815 | if (smbios_legacy) { | |
816 | *tables = *anchor = NULL; | |
817 | *tables_len = *anchor_len = 0; | |
818 | return; | |
819 | } | |
820 | ||
821 | if (!smbios_immutable) { | |
822 | smbios_build_type_0_table(); | |
823 | smbios_build_type_1_table(); | |
824 | smbios_build_type_2_table(); | |
825 | smbios_build_type_3_table(); | |
826 | ||
7dfddd7f | 827 | smbios_smp_sockets = DIV_ROUND_UP(smp_cpus, smp_cores * smp_threads); |
c97294ec GS |
828 | assert(smbios_smp_sockets >= 1); |
829 | ||
830 | for (i = 0; i < smbios_smp_sockets; i++) { | |
831 | smbios_build_type_4_table(i); | |
832 | } | |
833 | ||
834 | #define MAX_DIMM_SZ (16ll * ONE_GB) | |
744c6d47 EH |
835 | #define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ \ |
836 | : ((ram_size - 1) % MAX_DIMM_SZ) + 1) | |
c97294ec GS |
837 | |
838 | dimm_cnt = QEMU_ALIGN_UP(ram_size, MAX_DIMM_SZ) / MAX_DIMM_SZ; | |
839 | ||
840 | smbios_build_type_16_table(dimm_cnt); | |
841 | ||
842 | for (i = 0; i < dimm_cnt; i++) { | |
843 | smbios_build_type_17_table(i, GET_DIMM_SZ); | |
844 | } | |
845 | ||
89cc4a27 WH |
846 | for (i = 0; i < mem_array_size; i++) { |
847 | smbios_build_type_19_table(i, mem_array[i].address, | |
848 | mem_array[i].length); | |
c97294ec GS |
849 | } |
850 | ||
851 | smbios_build_type_32_table(); | |
35658f6e | 852 | smbios_build_type_38_table(); |
c97294ec GS |
853 | smbios_build_type_127_table(); |
854 | ||
855 | smbios_validate_table(); | |
856 | smbios_entry_point_setup(); | |
857 | smbios_immutable = true; | |
858 | } | |
859 | ||
860 | /* return tables blob and entry point (anchor), and their sizes */ | |
861 | *tables = smbios_tables; | |
862 | *tables_len = smbios_tables_len; | |
863 | *anchor = (uint8_t *)&ep; | |
86299120 WH |
864 | |
865 | /* calculate length based on anchor string */ | |
866 | if (!strncmp((char *)&ep, "_SM_", 4)) { | |
867 | *anchor_len = sizeof(struct smbios_21_entry_point); | |
868 | } else if (!strncmp((char *)&ep, "_SM3_", 5)) { | |
869 | *anchor_len = sizeof(struct smbios_30_entry_point); | |
870 | } else { | |
871 | abort(); | |
872 | } | |
cb36acb6 GS |
873 | } |
874 | ||
fc3b3295 MA |
875 | static void save_opt(const char **dest, QemuOpts *opts, const char *name) |
876 | { | |
877 | const char *val = qemu_opt_get(opts, name); | |
878 | ||
879 | if (val) { | |
880 | *dest = val; | |
4f953d2f | 881 | } |
b6f6e3d3 AL |
882 | } |
883 | ||
4f953d2f | 884 | void smbios_entry_add(QemuOpts *opts) |
b6f6e3d3 | 885 | { |
4f953d2f | 886 | const char *val; |
b6f6e3d3 | 887 | |
fc3b3295 | 888 | assert(!smbios_immutable); |
c97294ec | 889 | |
4f953d2f MA |
890 | val = qemu_opt_get(opts, "file"); |
891 | if (val) { | |
b6f6e3d3 | 892 | struct smbios_structure_header *header; |
4f953d2f | 893 | int size; |
c97294ec | 894 | struct smbios_table *table; /* legacy mode only */ |
4f953d2f | 895 | |
007b0657 | 896 | qemu_opts_validate(opts, qemu_smbios_file_opts, &error_fatal); |
b6f6e3d3 | 897 | |
4f953d2f | 898 | size = get_image_size(val); |
09c0848e | 899 | if (size == -1 || size < sizeof(struct smbios_structure_header)) { |
4f953d2f | 900 | error_report("Cannot read SMBIOS file %s", val); |
b6f6e3d3 AL |
901 | exit(1); |
902 | } | |
903 | ||
c97294ec GS |
904 | /* |
905 | * NOTE: standard double '\0' terminator expected, per smbios spec. | |
906 | * (except in legacy mode, where the second '\0' is implicit and | |
907 | * will be inserted by the BIOS). | |
908 | */ | |
909 | smbios_tables = g_realloc(smbios_tables, smbios_tables_len + size); | |
910 | header = (struct smbios_structure_header *)(smbios_tables + | |
911 | smbios_tables_len); | |
b6f6e3d3 | 912 | |
c97294ec | 913 | if (load_image(val, (uint8_t *)header) != size) { |
4f953d2f | 914 | error_report("Failed to load SMBIOS file %s", val); |
b6f6e3d3 AL |
915 | exit(1); |
916 | } | |
917 | ||
2e6e8d7a GS |
918 | if (test_bit(header->type, have_fields_bitmap)) { |
919 | error_report("can't load type %d struct, fields already specified!", | |
920 | header->type); | |
921 | exit(1); | |
922 | } | |
923 | set_bit(header->type, have_binfile_bitmap); | |
924 | ||
09c0848e BK |
925 | if (header->type == 4) { |
926 | smbios_type4_count++; | |
927 | } | |
b6f6e3d3 | 928 | |
c97294ec GS |
929 | smbios_tables_len += size; |
930 | if (size > smbios_table_max) { | |
931 | smbios_table_max = size; | |
932 | } | |
933 | smbios_table_cnt++; | |
934 | ||
935 | /* add a copy of the newly loaded blob to legacy smbios_entries */ | |
936 | /* NOTE: This code runs before smbios_set_defaults(), so we don't | |
937 | * yet know which mode (legacy vs. aggregate-table) will be | |
938 | * required. We therefore add the binary blob to both legacy | |
939 | * (smbios_entries) and aggregate (smbios_tables) tables, and | |
940 | * delete the one we don't need from smbios_set_defaults(), | |
941 | * once we know which machine version has been requested. | |
942 | */ | |
943 | if (!smbios_entries) { | |
944 | smbios_entries_len = sizeof(uint16_t); | |
945 | smbios_entries = g_malloc0(smbios_entries_len); | |
946 | } | |
947 | smbios_entries = g_realloc(smbios_entries, smbios_entries_len + | |
948 | size + sizeof(*table)); | |
949 | table = (struct smbios_table *)(smbios_entries + smbios_entries_len); | |
950 | table->header.type = SMBIOS_TABLE_ENTRY; | |
951 | table->header.length = cpu_to_le16(sizeof(*table) + size); | |
952 | memcpy(table->data, header, size); | |
b6f6e3d3 AL |
953 | smbios_entries_len += sizeof(*table) + size; |
954 | (*(uint16_t *)smbios_entries) = | |
955 | cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries) + 1); | |
c97294ec GS |
956 | /* end: add a copy of the newly loaded blob to legacy smbios_entries */ |
957 | ||
351a6a73 | 958 | return; |
b6f6e3d3 AL |
959 | } |
960 | ||
4f953d2f MA |
961 | val = qemu_opt_get(opts, "type"); |
962 | if (val) { | |
963 | unsigned long type = strtoul(val, NULL, 0); | |
964 | ||
2e6e8d7a GS |
965 | if (type > SMBIOS_MAX_TYPE) { |
966 | error_report("out of range!"); | |
967 | exit(1); | |
968 | } | |
969 | ||
970 | if (test_bit(type, have_binfile_bitmap)) { | |
971 | error_report("can't add fields, binary file already loaded!"); | |
972 | exit(1); | |
973 | } | |
974 | set_bit(type, have_fields_bitmap); | |
fc3b3295 | 975 | |
b6f6e3d3 AL |
976 | switch (type) { |
977 | case 0: | |
007b0657 | 978 | qemu_opts_validate(opts, qemu_smbios_type0_opts, &error_fatal); |
fc3b3295 MA |
979 | save_opt(&type0.vendor, opts, "vendor"); |
980 | save_opt(&type0.version, opts, "version"); | |
981 | save_opt(&type0.date, opts, "date"); | |
84351843 | 982 | type0.uefi = qemu_opt_get_bool(opts, "uefi", false); |
fc3b3295 MA |
983 | |
984 | val = qemu_opt_get(opts, "release"); | |
985 | if (val) { | |
986 | if (sscanf(val, "%hhu.%hhu", &type0.major, &type0.minor) != 2) { | |
987 | error_report("Invalid release"); | |
988 | exit(1); | |
989 | } | |
990 | type0.have_major_minor = true; | |
991 | } | |
351a6a73 | 992 | return; |
b6f6e3d3 | 993 | case 1: |
007b0657 | 994 | qemu_opts_validate(opts, qemu_smbios_type1_opts, &error_fatal); |
fc3b3295 MA |
995 | save_opt(&type1.manufacturer, opts, "manufacturer"); |
996 | save_opt(&type1.product, opts, "product"); | |
997 | save_opt(&type1.version, opts, "version"); | |
998 | save_opt(&type1.serial, opts, "serial"); | |
999 | save_opt(&type1.sku, opts, "sku"); | |
1000 | save_opt(&type1.family, opts, "family"); | |
1001 | ||
1002 | val = qemu_opt_get(opts, "uuid"); | |
1003 | if (val) { | |
1004 | if (qemu_uuid_parse(val, qemu_uuid) != 0) { | |
1005 | error_report("Invalid UUID"); | |
1006 | exit(1); | |
1007 | } | |
1008 | qemu_uuid_set = true; | |
1009 | } | |
351a6a73 | 1010 | return; |
c97294ec | 1011 | case 2: |
007b0657 | 1012 | qemu_opts_validate(opts, qemu_smbios_type2_opts, &error_fatal); |
c97294ec GS |
1013 | save_opt(&type2.manufacturer, opts, "manufacturer"); |
1014 | save_opt(&type2.product, opts, "product"); | |
1015 | save_opt(&type2.version, opts, "version"); | |
1016 | save_opt(&type2.serial, opts, "serial"); | |
1017 | save_opt(&type2.asset, opts, "asset"); | |
1018 | save_opt(&type2.location, opts, "location"); | |
1019 | return; | |
1020 | case 3: | |
007b0657 | 1021 | qemu_opts_validate(opts, qemu_smbios_type3_opts, &error_fatal); |
c97294ec GS |
1022 | save_opt(&type3.manufacturer, opts, "manufacturer"); |
1023 | save_opt(&type3.version, opts, "version"); | |
1024 | save_opt(&type3.serial, opts, "serial"); | |
1025 | save_opt(&type3.asset, opts, "asset"); | |
1026 | save_opt(&type3.sku, opts, "sku"); | |
1027 | return; | |
1028 | case 4: | |
007b0657 | 1029 | qemu_opts_validate(opts, qemu_smbios_type4_opts, &error_fatal); |
c97294ec GS |
1030 | save_opt(&type4.sock_pfx, opts, "sock_pfx"); |
1031 | save_opt(&type4.manufacturer, opts, "manufacturer"); | |
1032 | save_opt(&type4.version, opts, "version"); | |
1033 | save_opt(&type4.serial, opts, "serial"); | |
1034 | save_opt(&type4.asset, opts, "asset"); | |
1035 | save_opt(&type4.part, opts, "part"); | |
1036 | return; | |
1037 | case 17: | |
007b0657 | 1038 | qemu_opts_validate(opts, qemu_smbios_type17_opts, &error_fatal); |
c97294ec GS |
1039 | save_opt(&type17.loc_pfx, opts, "loc_pfx"); |
1040 | save_opt(&type17.bank, opts, "bank"); | |
1041 | save_opt(&type17.manufacturer, opts, "manufacturer"); | |
1042 | save_opt(&type17.serial, opts, "serial"); | |
1043 | save_opt(&type17.asset, opts, "asset"); | |
1044 | save_opt(&type17.part, opts, "part"); | |
3ebd6cc8 | 1045 | type17.speed = qemu_opt_get_number(opts, "speed", 0); |
c97294ec | 1046 | return; |
b6f6e3d3 | 1047 | default: |
5bb95e41 MA |
1048 | error_report("Don't know how to build fields for SMBIOS type %ld", |
1049 | type); | |
b6f6e3d3 AL |
1050 | exit(1); |
1051 | } | |
1052 | } | |
1053 | ||
5bb95e41 | 1054 | error_report("Must specify type= or file="); |
351a6a73 | 1055 | exit(1); |
b6f6e3d3 | 1056 | } |