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