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