4 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
5 * Copyright (C) 2013 Red Hat, Inc.
8 * Alex Williamson <alex.williamson@hp.com>
9 * Markus Armbruster <armbru@redhat.com>
11 * This work is licensed under the terms of the GNU GPL, version 2. See
12 * the COPYING file in the top-level directory.
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.
18 #include "qemu/osdep.h"
19 #include "qemu/units.h"
20 #include "qapi/error.h"
21 #include "qemu/config-file.h"
22 #include "qemu/error-report.h"
23 #include "qemu/module.h"
24 #include "qemu/option.h"
25 #include "sysemu/sysemu.h"
26 #include "qemu/uuid.h"
27 #include "hw/firmware/smbios.h"
28 #include "hw/loader.h"
29 #include "hw/boards.h"
30 #include "hw/pci/pci_bus.h"
31 #include "hw/pci/pci_device.h"
32 #include "smbios_build.h"
34 /* legacy structures and constants for <= 2.0 machines */
35 struct smbios_header
{
41 struct smbios_header header
;
48 struct smbios_header header
;
52 #define SMBIOS_FIELD_ENTRY 0
53 #define SMBIOS_TABLE_ENTRY 1
55 static uint8_t *smbios_entries
;
56 static size_t smbios_entries_len
;
57 static bool smbios_legacy
= true;
58 static bool smbios_uuid_encoded
= true;
59 /* end: legacy structures & constants for <= 2.0 machines */
62 uint8_t *smbios_tables
;
63 size_t smbios_tables_len
;
64 unsigned smbios_table_max
;
65 unsigned smbios_table_cnt
;
66 static SmbiosEntryPointType smbios_ep_type
= SMBIOS_ENTRY_POINT_TYPE_32
;
68 static SmbiosEntryPoint ep
;
70 static int smbios_type4_count
= 0;
71 static bool smbios_immutable
;
72 static bool smbios_have_defaults
;
73 static uint32_t smbios_cpuid_version
, smbios_cpuid_features
, smbios_smp_sockets
;
75 static DECLARE_BITMAP(have_binfile_bitmap
, SMBIOS_MAX_TYPE
+1);
76 static DECLARE_BITMAP(have_fields_bitmap
, SMBIOS_MAX_TYPE
+1);
79 const char *vendor
, *version
, *date
;
80 bool have_major_minor
, uefi
;
85 const char *manufacturer
, *product
, *version
, *serial
, *sku
, *family
;
86 /* uuid is in qemu_uuid */
90 const char *manufacturer
, *product
, *version
, *serial
, *asset
, *location
;
94 const char *manufacturer
, *version
, *serial
, *asset
, *sku
;
98 * SVVP requires max_speed and current_speed to be set and not being
99 * 0 which counts as unknown (SMBIOS 3.1.0/Table 21). Set the
100 * default value to 2000MHz as we did before.
102 #define DEFAULT_CPU_SPEED 2000
105 uint16_t processor_family
;
106 const char *sock_pfx
, *manufacturer
, *version
, *serial
, *asset
, *part
;
108 uint64_t current_speed
;
109 uint64_t processor_id
;
111 .max_speed
= DEFAULT_CPU_SPEED
,
112 .current_speed
= DEFAULT_CPU_SPEED
,
114 .processor_family
= 0x01, /* Other */
117 struct type8_instance
{
118 const char *internal_reference
, *external_reference
;
119 uint8_t connector_type
, port_type
;
120 QTAILQ_ENTRY(type8_instance
) next
;
122 static QTAILQ_HEAD(, type8_instance
) type8
= QTAILQ_HEAD_INITIALIZER(type8
);
130 const char *loc_pfx
, *bank
, *manufacturer
, *serial
, *asset
, *part
;
134 static QEnumLookup type41_kind_lookup
= {
135 .array
= (const char *const[]) {
149 struct type41_instance
{
150 const char *designation
, *pcidev
;
151 uint8_t instance
, kind
;
152 QTAILQ_ENTRY(type41_instance
) next
;
154 static QTAILQ_HEAD(, type41_instance
) type41
= QTAILQ_HEAD_INITIALIZER(type41
);
156 static QemuOptsList qemu_smbios_opts
= {
158 .head
= QTAILQ_HEAD_INITIALIZER(qemu_smbios_opts
.head
),
161 * no elements => accept any params
162 * validation will happen later
164 { /* end of list */ }
168 static const QemuOptDesc qemu_smbios_file_opts
[] = {
171 .type
= QEMU_OPT_STRING
,
172 .help
= "binary file containing an SMBIOS element",
174 { /* end of list */ }
177 static const QemuOptDesc qemu_smbios_type0_opts
[] = {
180 .type
= QEMU_OPT_NUMBER
,
181 .help
= "SMBIOS element type",
184 .type
= QEMU_OPT_STRING
,
185 .help
= "vendor name",
188 .type
= QEMU_OPT_STRING
,
189 .help
= "version number",
192 .type
= QEMU_OPT_STRING
,
193 .help
= "release date",
196 .type
= QEMU_OPT_STRING
,
197 .help
= "revision number",
200 .type
= QEMU_OPT_BOOL
,
201 .help
= "uefi support",
203 { /* end of list */ }
206 static const QemuOptDesc qemu_smbios_type1_opts
[] = {
209 .type
= QEMU_OPT_NUMBER
,
210 .help
= "SMBIOS element type",
212 .name
= "manufacturer",
213 .type
= QEMU_OPT_STRING
,
214 .help
= "manufacturer name",
217 .type
= QEMU_OPT_STRING
,
218 .help
= "product name",
221 .type
= QEMU_OPT_STRING
,
222 .help
= "version number",
225 .type
= QEMU_OPT_STRING
,
226 .help
= "serial number",
229 .type
= QEMU_OPT_STRING
,
233 .type
= QEMU_OPT_STRING
,
234 .help
= "SKU number",
237 .type
= QEMU_OPT_STRING
,
238 .help
= "family name",
240 { /* end of list */ }
243 static const QemuOptDesc qemu_smbios_type2_opts
[] = {
246 .type
= QEMU_OPT_NUMBER
,
247 .help
= "SMBIOS element type",
249 .name
= "manufacturer",
250 .type
= QEMU_OPT_STRING
,
251 .help
= "manufacturer name",
254 .type
= QEMU_OPT_STRING
,
255 .help
= "product name",
258 .type
= QEMU_OPT_STRING
,
259 .help
= "version number",
262 .type
= QEMU_OPT_STRING
,
263 .help
= "serial number",
266 .type
= QEMU_OPT_STRING
,
267 .help
= "asset tag number",
270 .type
= QEMU_OPT_STRING
,
271 .help
= "location in chassis",
273 { /* end of list */ }
276 static const QemuOptDesc qemu_smbios_type3_opts
[] = {
279 .type
= QEMU_OPT_NUMBER
,
280 .help
= "SMBIOS element type",
282 .name
= "manufacturer",
283 .type
= QEMU_OPT_STRING
,
284 .help
= "manufacturer name",
287 .type
= QEMU_OPT_STRING
,
288 .help
= "version number",
291 .type
= QEMU_OPT_STRING
,
292 .help
= "serial number",
295 .type
= QEMU_OPT_STRING
,
296 .help
= "asset tag number",
299 .type
= QEMU_OPT_STRING
,
300 .help
= "SKU number",
302 { /* end of list */ }
305 static const QemuOptDesc qemu_smbios_type4_opts
[] = {
308 .type
= QEMU_OPT_NUMBER
,
309 .help
= "SMBIOS element type",
312 .type
= QEMU_OPT_STRING
,
313 .help
= "socket designation string prefix",
315 .name
= "manufacturer",
316 .type
= QEMU_OPT_STRING
,
317 .help
= "manufacturer name",
320 .type
= QEMU_OPT_STRING
,
321 .help
= "version number",
324 .type
= QEMU_OPT_NUMBER
,
325 .help
= "max speed in MHz",
327 .name
= "current-speed",
328 .type
= QEMU_OPT_NUMBER
,
329 .help
= "speed at system boot in MHz",
332 .type
= QEMU_OPT_STRING
,
333 .help
= "serial number",
336 .type
= QEMU_OPT_STRING
,
337 .help
= "asset tag number",
340 .type
= QEMU_OPT_STRING
,
341 .help
= "part number",
343 .name
= "processor-family",
344 .type
= QEMU_OPT_NUMBER
,
345 .help
= "processor family",
347 .name
= "processor-id",
348 .type
= QEMU_OPT_NUMBER
,
349 .help
= "processor id",
351 { /* end of list */ }
354 static const QemuOptDesc qemu_smbios_type8_opts
[] = {
357 .type
= QEMU_OPT_NUMBER
,
358 .help
= "SMBIOS element type",
361 .name
= "internal_reference",
362 .type
= QEMU_OPT_STRING
,
363 .help
= "internal reference designator",
366 .name
= "external_reference",
367 .type
= QEMU_OPT_STRING
,
368 .help
= "external reference designator",
371 .name
= "connector_type",
372 .type
= QEMU_OPT_NUMBER
,
373 .help
= "connector type",
377 .type
= QEMU_OPT_NUMBER
,
380 { /* end of list */ }
383 static const QemuOptDesc qemu_smbios_type11_opts
[] = {
386 .type
= QEMU_OPT_NUMBER
,
387 .help
= "SMBIOS element type",
391 .type
= QEMU_OPT_STRING
,
392 .help
= "OEM string data",
396 .type
= QEMU_OPT_STRING
,
397 .help
= "OEM string data from file",
399 { /* end of list */ }
402 static const QemuOptDesc qemu_smbios_type17_opts
[] = {
405 .type
= QEMU_OPT_NUMBER
,
406 .help
= "SMBIOS element type",
409 .type
= QEMU_OPT_STRING
,
410 .help
= "device locator string prefix",
413 .type
= QEMU_OPT_STRING
,
414 .help
= "bank locator string",
416 .name
= "manufacturer",
417 .type
= QEMU_OPT_STRING
,
418 .help
= "manufacturer name",
421 .type
= QEMU_OPT_STRING
,
422 .help
= "serial number",
425 .type
= QEMU_OPT_STRING
,
426 .help
= "asset tag number",
429 .type
= QEMU_OPT_STRING
,
430 .help
= "part number",
433 .type
= QEMU_OPT_NUMBER
,
434 .help
= "maximum capable speed",
436 { /* end of list */ }
439 static const QemuOptDesc qemu_smbios_type41_opts
[] = {
442 .type
= QEMU_OPT_NUMBER
,
443 .help
= "SMBIOS element type",
445 .name
= "designation",
446 .type
= QEMU_OPT_STRING
,
447 .help
= "reference designation string",
450 .type
= QEMU_OPT_STRING
,
451 .help
= "device type",
452 .def_value_str
= "other",
455 .type
= QEMU_OPT_NUMBER
,
456 .help
= "device type instance",
459 .type
= QEMU_OPT_STRING
,
460 .help
= "PCI device",
462 { /* end of list */ }
465 static void smbios_register_config(void)
467 qemu_add_opts(&qemu_smbios_opts
);
470 opts_init(smbios_register_config
);
473 * The SMBIOS 2.1 "structure table length" field in the
474 * entry point uses a 16-bit integer, so we're limited
475 * in total table size
477 #define SMBIOS_21_MAX_TABLES_LEN 0xffff
479 static void smbios_validate_table(MachineState
*ms
)
481 uint32_t expect_t4_count
= smbios_legacy
?
482 ms
->smp
.cpus
: smbios_smp_sockets
;
484 if (smbios_type4_count
&& smbios_type4_count
!= expect_t4_count
) {
485 error_report("Expected %d SMBIOS Type 4 tables, got %d instead",
486 expect_t4_count
, smbios_type4_count
);
490 if (smbios_ep_type
== SMBIOS_ENTRY_POINT_TYPE_32
&&
491 smbios_tables_len
> SMBIOS_21_MAX_TABLES_LEN
) {
492 error_report("SMBIOS 2.1 table length %zu exceeds %d",
493 smbios_tables_len
, SMBIOS_21_MAX_TABLES_LEN
);
499 /* legacy setup functions for <= 2.0 machines */
500 static void smbios_add_field(int type
, int offset
, const void *data
, size_t len
)
502 struct smbios_field
*field
;
504 if (!smbios_entries
) {
505 smbios_entries_len
= sizeof(uint16_t);
506 smbios_entries
= g_malloc0(smbios_entries_len
);
508 smbios_entries
= g_realloc(smbios_entries
, smbios_entries_len
+
509 sizeof(*field
) + len
);
510 field
= (struct smbios_field
*)(smbios_entries
+ smbios_entries_len
);
511 field
->header
.type
= SMBIOS_FIELD_ENTRY
;
512 field
->header
.length
= cpu_to_le16(sizeof(*field
) + len
);
515 field
->offset
= cpu_to_le16(offset
);
516 memcpy(field
->data
, data
, len
);
518 smbios_entries_len
+= sizeof(*field
) + len
;
519 (*(uint16_t *)smbios_entries
) =
520 cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries
) + 1);
523 static void smbios_maybe_add_str(int type
, int offset
, const char *data
)
526 smbios_add_field(type
, offset
, data
, strlen(data
) + 1);
530 static void smbios_build_type_0_fields(void)
532 smbios_maybe_add_str(0, offsetof(struct smbios_type_0
, vendor_str
),
534 smbios_maybe_add_str(0, offsetof(struct smbios_type_0
, bios_version_str
),
536 smbios_maybe_add_str(0, offsetof(struct smbios_type_0
,
537 bios_release_date_str
),
539 if (type0
.have_major_minor
) {
540 smbios_add_field(0, offsetof(struct smbios_type_0
,
541 system_bios_major_release
),
543 smbios_add_field(0, offsetof(struct smbios_type_0
,
544 system_bios_minor_release
),
549 static void smbios_build_type_1_fields(void)
551 smbios_maybe_add_str(1, offsetof(struct smbios_type_1
, manufacturer_str
),
553 smbios_maybe_add_str(1, offsetof(struct smbios_type_1
, product_name_str
),
555 smbios_maybe_add_str(1, offsetof(struct smbios_type_1
, version_str
),
557 smbios_maybe_add_str(1, offsetof(struct smbios_type_1
, serial_number_str
),
559 smbios_maybe_add_str(1, offsetof(struct smbios_type_1
, sku_number_str
),
561 smbios_maybe_add_str(1, offsetof(struct smbios_type_1
, family_str
),
564 /* We don't encode the UUID in the "wire format" here because this
565 * function is for legacy mode and needs to keep the guest ABI, and
566 * because we don't know what's the SMBIOS version advertised by the
569 smbios_add_field(1, offsetof(struct smbios_type_1
, uuid
),
574 uint8_t *smbios_get_table_legacy(MachineState
*ms
, size_t *length
)
576 if (!smbios_legacy
) {
581 if (!smbios_immutable
) {
582 smbios_build_type_0_fields();
583 smbios_build_type_1_fields();
584 smbios_validate_table(ms
);
585 smbios_immutable
= true;
587 *length
= smbios_entries_len
;
588 return smbios_entries
;
590 /* end: legacy setup functions for <= 2.0 machines */
593 bool smbios_skip_table(uint8_t type
, bool required_table
)
595 if (test_bit(type
, have_binfile_bitmap
)) {
596 return true; /* user provided their own binary blob(s) */
598 if (test_bit(type
, have_fields_bitmap
)) {
599 return false; /* user provided fields via command line */
601 if (smbios_have_defaults
&& required_table
) {
602 return false; /* we're building tables, and this one's required */
607 #define T0_BASE 0x000
608 #define T1_BASE 0x100
609 #define T2_BASE 0x200
610 #define T3_BASE 0x300
611 #define T4_BASE 0x400
612 #define T11_BASE 0xe00
614 #define T16_BASE 0x1000
615 #define T17_BASE 0x1100
616 #define T19_BASE 0x1300
617 #define T32_BASE 0x2000
618 #define T41_BASE 0x2900
619 #define T127_BASE 0x7F00
621 static void smbios_build_type_0_table(void)
623 SMBIOS_BUILD_TABLE_PRE(0, T0_BASE
, false); /* optional, leave up to BIOS */
625 SMBIOS_TABLE_SET_STR(0, vendor_str
, type0
.vendor
);
626 SMBIOS_TABLE_SET_STR(0, bios_version_str
, type0
.version
);
628 t
->bios_starting_address_segment
= cpu_to_le16(0xE800); /* from SeaBIOS */
630 SMBIOS_TABLE_SET_STR(0, bios_release_date_str
, type0
.date
);
632 t
->bios_rom_size
= 0; /* hardcoded in SeaBIOS with FIXME comment */
634 t
->bios_characteristics
= cpu_to_le64(0x08); /* Not supported */
635 t
->bios_characteristics_extension_bytes
[0] = 0;
636 t
->bios_characteristics_extension_bytes
[1] = 0x14; /* TCD/SVVP | VM */
638 t
->bios_characteristics_extension_bytes
[1] |= 0x08; /* |= UEFI */
641 if (type0
.have_major_minor
) {
642 t
->system_bios_major_release
= type0
.major
;
643 t
->system_bios_minor_release
= type0
.minor
;
645 t
->system_bios_major_release
= 0;
646 t
->system_bios_minor_release
= 0;
649 /* hardcoded in SeaBIOS */
650 t
->embedded_controller_major_release
= 0xFF;
651 t
->embedded_controller_minor_release
= 0xFF;
653 SMBIOS_BUILD_TABLE_POST
;
656 /* Encode UUID from the big endian encoding described on RFC4122 to the wire
657 * format specified by SMBIOS version 2.6.
659 static void smbios_encode_uuid(struct smbios_uuid
*uuid
, QemuUUID
*in
)
661 memcpy(uuid
, in
, 16);
662 if (smbios_uuid_encoded
) {
663 uuid
->time_low
= bswap32(uuid
->time_low
);
664 uuid
->time_mid
= bswap16(uuid
->time_mid
);
665 uuid
->time_hi_and_version
= bswap16(uuid
->time_hi_and_version
);
669 static void smbios_build_type_1_table(void)
671 SMBIOS_BUILD_TABLE_PRE(1, T1_BASE
, true); /* required */
673 SMBIOS_TABLE_SET_STR(1, manufacturer_str
, type1
.manufacturer
);
674 SMBIOS_TABLE_SET_STR(1, product_name_str
, type1
.product
);
675 SMBIOS_TABLE_SET_STR(1, version_str
, type1
.version
);
676 SMBIOS_TABLE_SET_STR(1, serial_number_str
, type1
.serial
);
678 smbios_encode_uuid(&t
->uuid
, &qemu_uuid
);
680 memset(&t
->uuid
, 0, 16);
682 t
->wake_up_type
= 0x06; /* power switch */
683 SMBIOS_TABLE_SET_STR(1, sku_number_str
, type1
.sku
);
684 SMBIOS_TABLE_SET_STR(1, family_str
, type1
.family
);
686 SMBIOS_BUILD_TABLE_POST
;
689 static void smbios_build_type_2_table(void)
691 SMBIOS_BUILD_TABLE_PRE(2, T2_BASE
, false); /* optional */
693 SMBIOS_TABLE_SET_STR(2, manufacturer_str
, type2
.manufacturer
);
694 SMBIOS_TABLE_SET_STR(2, product_str
, type2
.product
);
695 SMBIOS_TABLE_SET_STR(2, version_str
, type2
.version
);
696 SMBIOS_TABLE_SET_STR(2, serial_number_str
, type2
.serial
);
697 SMBIOS_TABLE_SET_STR(2, asset_tag_number_str
, type2
.asset
);
698 t
->feature_flags
= 0x01; /* Motherboard */
699 SMBIOS_TABLE_SET_STR(2, location_str
, type2
.location
);
700 t
->chassis_handle
= cpu_to_le16(0x300); /* Type 3 (System enclosure) */
701 t
->board_type
= 0x0A; /* Motherboard */
702 t
->contained_element_count
= 0;
704 SMBIOS_BUILD_TABLE_POST
;
707 static void smbios_build_type_3_table(void)
709 SMBIOS_BUILD_TABLE_PRE(3, T3_BASE
, true); /* required */
711 SMBIOS_TABLE_SET_STR(3, manufacturer_str
, type3
.manufacturer
);
712 t
->type
= 0x01; /* Other */
713 SMBIOS_TABLE_SET_STR(3, version_str
, type3
.version
);
714 SMBIOS_TABLE_SET_STR(3, serial_number_str
, type3
.serial
);
715 SMBIOS_TABLE_SET_STR(3, asset_tag_number_str
, type3
.asset
);
716 t
->boot_up_state
= 0x03; /* Safe */
717 t
->power_supply_state
= 0x03; /* Safe */
718 t
->thermal_state
= 0x03; /* Safe */
719 t
->security_status
= 0x02; /* Unknown */
720 t
->oem_defined
= cpu_to_le32(0);
722 t
->number_of_power_cords
= 0;
723 t
->contained_element_count
= 0;
724 t
->contained_element_record_length
= 0;
725 SMBIOS_TABLE_SET_STR(3, sku_number_str
, type3
.sku
);
727 SMBIOS_BUILD_TABLE_POST
;
730 static void smbios_build_type_4_table(MachineState
*ms
, unsigned instance
)
733 size_t tbl_len
= SMBIOS_TYPE_4_LEN_V28
;
734 unsigned threads_per_socket
;
735 unsigned cores_per_socket
;
737 if (smbios_ep_type
== SMBIOS_ENTRY_POINT_TYPE_64
) {
738 tbl_len
= SMBIOS_TYPE_4_LEN_V30
;
741 SMBIOS_BUILD_TABLE_PRE_SIZE(4, T4_BASE
+ instance
,
742 true, tbl_len
); /* required */
744 snprintf(sock_str
, sizeof(sock_str
), "%s%2x", type4
.sock_pfx
, instance
);
745 SMBIOS_TABLE_SET_STR(4, socket_designation_str
, sock_str
);
746 t
->processor_type
= 0x03; /* CPU */
747 t
->processor_family
= 0xfe; /* use Processor Family 2 field */
748 SMBIOS_TABLE_SET_STR(4, processor_manufacturer_str
, type4
.manufacturer
);
749 if (type4
.processor_id
== 0) {
750 t
->processor_id
[0] = cpu_to_le32(smbios_cpuid_version
);
751 t
->processor_id
[1] = cpu_to_le32(smbios_cpuid_features
);
753 t
->processor_id
[0] = cpu_to_le32((uint32_t)type4
.processor_id
);
754 t
->processor_id
[1] = cpu_to_le32(type4
.processor_id
>> 32);
756 SMBIOS_TABLE_SET_STR(4, processor_version_str
, type4
.version
);
758 t
->external_clock
= cpu_to_le16(0); /* Unknown */
759 t
->max_speed
= cpu_to_le16(type4
.max_speed
);
760 t
->current_speed
= cpu_to_le16(type4
.current_speed
);
761 t
->status
= 0x41; /* Socket populated, CPU enabled */
762 t
->processor_upgrade
= 0x01; /* Other */
763 t
->l1_cache_handle
= cpu_to_le16(0xFFFF); /* N/A */
764 t
->l2_cache_handle
= cpu_to_le16(0xFFFF); /* N/A */
765 t
->l3_cache_handle
= cpu_to_le16(0xFFFF); /* N/A */
766 SMBIOS_TABLE_SET_STR(4, serial_number_str
, type4
.serial
);
767 SMBIOS_TABLE_SET_STR(4, asset_tag_number_str
, type4
.asset
);
768 SMBIOS_TABLE_SET_STR(4, part_number_str
, type4
.part
);
770 threads_per_socket
= machine_topo_get_threads_per_socket(ms
);
771 cores_per_socket
= machine_topo_get_cores_per_socket(ms
);
773 t
->core_count
= (cores_per_socket
> 255) ? 0xFF : cores_per_socket
;
774 t
->core_enabled
= t
->core_count
;
776 t
->thread_count
= (threads_per_socket
> 255) ? 0xFF : threads_per_socket
;
778 t
->processor_characteristics
= cpu_to_le16(0x02); /* Unknown */
779 t
->processor_family2
= cpu_to_le16(type4
.processor_family
);
781 if (tbl_len
== SMBIOS_TYPE_4_LEN_V30
) {
782 t
->core_count2
= t
->core_enabled2
= cpu_to_le16(cores_per_socket
);
783 t
->thread_count2
= cpu_to_le16(threads_per_socket
);
786 SMBIOS_BUILD_TABLE_POST
;
787 smbios_type4_count
++;
790 static void smbios_build_type_8_table(void)
792 unsigned instance
= 0;
793 struct type8_instance
*t8
;
795 QTAILQ_FOREACH(t8
, &type8
, next
) {
796 SMBIOS_BUILD_TABLE_PRE(8, T0_BASE
+ instance
, true);
798 SMBIOS_TABLE_SET_STR(8, internal_reference_str
, t8
->internal_reference
);
799 SMBIOS_TABLE_SET_STR(8, external_reference_str
, t8
->external_reference
);
800 /* most vendors seem to set this to None */
801 t
->internal_connector_type
= 0x0;
802 t
->external_connector_type
= t8
->connector_type
;
803 t
->port_type
= t8
->port_type
;
805 SMBIOS_BUILD_TABLE_POST
;
810 static void smbios_build_type_11_table(void)
815 if (type11
.nvalues
== 0) {
819 SMBIOS_BUILD_TABLE_PRE(11, T11_BASE
, true); /* required */
821 snprintf(count_str
, sizeof(count_str
), "%zu", type11
.nvalues
);
822 t
->count
= type11
.nvalues
;
824 for (i
= 0; i
< type11
.nvalues
; i
++) {
825 SMBIOS_TABLE_SET_STR_LIST(11, type11
.values
[i
]);
826 g_free(type11
.values
[i
]);
827 type11
.values
[i
] = NULL
;
830 SMBIOS_BUILD_TABLE_POST
;
833 #define MAX_T16_STD_SZ 0x80000000 /* 2T in Kilobytes */
835 static void smbios_build_type_16_table(unsigned dimm_cnt
)
839 SMBIOS_BUILD_TABLE_PRE(16, T16_BASE
, true); /* required */
841 t
->location
= 0x01; /* Other */
842 t
->use
= 0x03; /* System memory */
843 t
->error_correction
= 0x06; /* Multi-bit ECC (for Microsoft, per SeaBIOS) */
844 size_kb
= QEMU_ALIGN_UP(current_machine
->ram_size
, KiB
) / KiB
;
845 if (size_kb
< MAX_T16_STD_SZ
) {
846 t
->maximum_capacity
= cpu_to_le32(size_kb
);
847 t
->extended_maximum_capacity
= cpu_to_le64(0);
849 t
->maximum_capacity
= cpu_to_le32(MAX_T16_STD_SZ
);
850 t
->extended_maximum_capacity
= cpu_to_le64(current_machine
->ram_size
);
852 t
->memory_error_information_handle
= cpu_to_le16(0xFFFE); /* Not provided */
853 t
->number_of_memory_devices
= cpu_to_le16(dimm_cnt
);
855 SMBIOS_BUILD_TABLE_POST
;
858 #define MAX_T17_STD_SZ 0x7FFF /* (32G - 1M), in Megabytes */
859 #define MAX_T17_EXT_SZ 0x80000000 /* 2P, in Megabytes */
861 static void smbios_build_type_17_table(unsigned instance
, uint64_t size
)
866 SMBIOS_BUILD_TABLE_PRE(17, T17_BASE
+ instance
, true); /* required */
868 t
->physical_memory_array_handle
= cpu_to_le16(0x1000); /* Type 16 above */
869 t
->memory_error_information_handle
= cpu_to_le16(0xFFFE); /* Not provided */
870 t
->total_width
= cpu_to_le16(0xFFFF); /* Unknown */
871 t
->data_width
= cpu_to_le16(0xFFFF); /* Unknown */
872 size_mb
= QEMU_ALIGN_UP(size
, MiB
) / MiB
;
873 if (size_mb
< MAX_T17_STD_SZ
) {
874 t
->size
= cpu_to_le16(size_mb
);
875 t
->extended_size
= cpu_to_le32(0);
877 assert(size_mb
< MAX_T17_EXT_SZ
);
878 t
->size
= cpu_to_le16(MAX_T17_STD_SZ
);
879 t
->extended_size
= cpu_to_le32(size_mb
);
881 t
->form_factor
= 0x09; /* DIMM */
882 t
->device_set
= 0; /* Not in a set */
883 snprintf(loc_str
, sizeof(loc_str
), "%s %d", type17
.loc_pfx
, instance
);
884 SMBIOS_TABLE_SET_STR(17, device_locator_str
, loc_str
);
885 SMBIOS_TABLE_SET_STR(17, bank_locator_str
, type17
.bank
);
886 t
->memory_type
= 0x07; /* RAM */
887 t
->type_detail
= cpu_to_le16(0x02); /* Other */
888 t
->speed
= cpu_to_le16(type17
.speed
);
889 SMBIOS_TABLE_SET_STR(17, manufacturer_str
, type17
.manufacturer
);
890 SMBIOS_TABLE_SET_STR(17, serial_number_str
, type17
.serial
);
891 SMBIOS_TABLE_SET_STR(17, asset_tag_number_str
, type17
.asset
);
892 SMBIOS_TABLE_SET_STR(17, part_number_str
, type17
.part
);
893 t
->attributes
= 0; /* Unknown */
894 t
->configured_clock_speed
= t
->speed
; /* reuse value for max speed */
895 t
->minimum_voltage
= cpu_to_le16(0); /* Unknown */
896 t
->maximum_voltage
= cpu_to_le16(0); /* Unknown */
897 t
->configured_voltage
= cpu_to_le16(0); /* Unknown */
899 SMBIOS_BUILD_TABLE_POST
;
902 static void smbios_build_type_19_table(unsigned instance
, unsigned offset
,
903 uint64_t start
, uint64_t size
)
905 uint64_t end
, start_kb
, end_kb
;
907 SMBIOS_BUILD_TABLE_PRE(19, T19_BASE
+ offset
+ instance
,
908 true); /* required */
910 end
= start
+ size
- 1;
912 start_kb
= start
/ KiB
;
914 if (start_kb
< UINT32_MAX
&& end_kb
< UINT32_MAX
) {
915 t
->starting_address
= cpu_to_le32(start_kb
);
916 t
->ending_address
= cpu_to_le32(end_kb
);
917 t
->extended_starting_address
=
918 t
->extended_ending_address
= cpu_to_le64(0);
920 t
->starting_address
= t
->ending_address
= cpu_to_le32(UINT32_MAX
);
921 t
->extended_starting_address
= cpu_to_le64(start
);
922 t
->extended_ending_address
= cpu_to_le64(end
);
924 t
->memory_array_handle
= cpu_to_le16(0x1000); /* Type 16 above */
925 t
->partition_width
= 1; /* One device per row */
927 SMBIOS_BUILD_TABLE_POST
;
930 static void smbios_build_type_32_table(void)
932 SMBIOS_BUILD_TABLE_PRE(32, T32_BASE
, true); /* required */
934 memset(t
->reserved
, 0, 6);
935 t
->boot_status
= 0; /* No errors detected */
937 SMBIOS_BUILD_TABLE_POST
;
940 static void smbios_build_type_41_table(Error
**errp
)
942 unsigned instance
= 0;
943 struct type41_instance
*t41
;
945 QTAILQ_FOREACH(t41
, &type41
, next
) {
946 SMBIOS_BUILD_TABLE_PRE(41, T41_BASE
+ instance
, true);
948 SMBIOS_TABLE_SET_STR(41, reference_designation_str
, t41
->designation
);
949 t
->device_type
= t41
->kind
;
950 t
->device_type_instance
= t41
->instance
;
951 t
->segment_group_number
= cpu_to_le16(0);
953 t
->device_number
= 0;
956 PCIDevice
*pdev
= NULL
;
957 int rc
= pci_qdev_find_device(t41
->pcidev
, &pdev
);
960 "No PCI device %s for SMBIOS type 41 entry %s",
961 t41
->pcidev
, t41
->designation
);
965 * We only handle the case were the device is attached to
966 * the PCI root bus. The general case is more complex as
967 * bridges are enumerated later and the table would need
968 * to be updated at this moment.
970 if (!pci_bus_is_root(pci_get_bus(pdev
))) {
972 "Cannot create type 41 entry for PCI device %s: "
973 "not attached to the root bus",
977 t
->segment_group_number
= cpu_to_le16(0);
978 t
->bus_number
= pci_dev_bus_num(pdev
);
979 t
->device_number
= pdev
->devfn
;
982 SMBIOS_BUILD_TABLE_POST
;
987 static void smbios_build_type_127_table(void)
989 SMBIOS_BUILD_TABLE_PRE(127, T127_BASE
, true); /* required */
990 SMBIOS_BUILD_TABLE_POST
;
993 void smbios_set_cpuid(uint32_t version
, uint32_t features
)
995 smbios_cpuid_version
= version
;
996 smbios_cpuid_features
= features
;
999 #define SMBIOS_SET_DEFAULT(field, value) \
1004 void smbios_set_default_processor_family(uint16_t processor_family
)
1006 if (type4
.processor_family
<= 0x01) {
1007 type4
.processor_family
= processor_family
;
1011 void smbios_set_defaults(const char *manufacturer
, const char *product
,
1012 const char *version
, bool legacy_mode
,
1013 bool uuid_encoded
, SmbiosEntryPointType ep_type
)
1015 smbios_have_defaults
= true;
1016 smbios_legacy
= legacy_mode
;
1017 smbios_uuid_encoded
= uuid_encoded
;
1018 smbios_ep_type
= ep_type
;
1020 /* drop unwanted version of command-line file blob(s) */
1021 if (smbios_legacy
) {
1022 g_free(smbios_tables
);
1023 /* in legacy mode, also complain if fields were given for types > 1 */
1024 if (find_next_bit(have_fields_bitmap
,
1025 SMBIOS_MAX_TYPE
+1, 2) < SMBIOS_MAX_TYPE
+1) {
1026 error_report("can't process fields for smbios "
1027 "types > 1 on machine versions < 2.1!");
1031 g_free(smbios_entries
);
1034 SMBIOS_SET_DEFAULT(type1
.manufacturer
, manufacturer
);
1035 SMBIOS_SET_DEFAULT(type1
.product
, product
);
1036 SMBIOS_SET_DEFAULT(type1
.version
, version
);
1037 SMBIOS_SET_DEFAULT(type2
.manufacturer
, manufacturer
);
1038 SMBIOS_SET_DEFAULT(type2
.product
, product
);
1039 SMBIOS_SET_DEFAULT(type2
.version
, version
);
1040 SMBIOS_SET_DEFAULT(type3
.manufacturer
, manufacturer
);
1041 SMBIOS_SET_DEFAULT(type3
.version
, version
);
1042 SMBIOS_SET_DEFAULT(type4
.sock_pfx
, "CPU");
1043 SMBIOS_SET_DEFAULT(type4
.manufacturer
, manufacturer
);
1044 SMBIOS_SET_DEFAULT(type4
.version
, version
);
1045 SMBIOS_SET_DEFAULT(type17
.loc_pfx
, "DIMM");
1046 SMBIOS_SET_DEFAULT(type17
.manufacturer
, manufacturer
);
1049 static void smbios_entry_point_setup(void)
1051 switch (smbios_ep_type
) {
1052 case SMBIOS_ENTRY_POINT_TYPE_32
:
1053 memcpy(ep
.ep21
.anchor_string
, "_SM_", 4);
1054 memcpy(ep
.ep21
.intermediate_anchor_string
, "_DMI_", 5);
1055 ep
.ep21
.length
= sizeof(struct smbios_21_entry_point
);
1056 ep
.ep21
.entry_point_revision
= 0; /* formatted_area reserved */
1057 memset(ep
.ep21
.formatted_area
, 0, 5);
1059 /* compliant with smbios spec v2.8 */
1060 ep
.ep21
.smbios_major_version
= 2;
1061 ep
.ep21
.smbios_minor_version
= 8;
1062 ep
.ep21
.smbios_bcd_revision
= 0x28;
1064 /* set during table construction, but BIOS may override: */
1065 ep
.ep21
.structure_table_length
= cpu_to_le16(smbios_tables_len
);
1066 ep
.ep21
.max_structure_size
= cpu_to_le16(smbios_table_max
);
1067 ep
.ep21
.number_of_structures
= cpu_to_le16(smbios_table_cnt
);
1069 /* BIOS must recalculate */
1070 ep
.ep21
.checksum
= 0;
1071 ep
.ep21
.intermediate_checksum
= 0;
1072 ep
.ep21
.structure_table_address
= cpu_to_le32(0);
1075 case SMBIOS_ENTRY_POINT_TYPE_64
:
1076 memcpy(ep
.ep30
.anchor_string
, "_SM3_", 5);
1077 ep
.ep30
.length
= sizeof(struct smbios_30_entry_point
);
1078 ep
.ep30
.entry_point_revision
= 1;
1079 ep
.ep30
.reserved
= 0;
1081 /* compliant with smbios spec 3.0 */
1082 ep
.ep30
.smbios_major_version
= 3;
1083 ep
.ep30
.smbios_minor_version
= 0;
1084 ep
.ep30
.smbios_doc_rev
= 0;
1086 /* set during table construct, but BIOS might override */
1087 ep
.ep30
.structure_table_max_size
= cpu_to_le32(smbios_tables_len
);
1089 /* BIOS must recalculate */
1090 ep
.ep30
.checksum
= 0;
1091 ep
.ep30
.structure_table_address
= cpu_to_le64(0);
1100 void smbios_get_tables(MachineState
*ms
,
1101 const struct smbios_phys_mem_area
*mem_array
,
1102 const unsigned int mem_array_size
,
1103 uint8_t **tables
, size_t *tables_len
,
1104 uint8_t **anchor
, size_t *anchor_len
,
1107 unsigned i
, dimm_cnt
, offset
;
1109 if (smbios_legacy
) {
1110 *tables
= *anchor
= NULL
;
1111 *tables_len
= *anchor_len
= 0;
1115 if (!smbios_immutable
) {
1116 smbios_build_type_0_table();
1117 smbios_build_type_1_table();
1118 smbios_build_type_2_table();
1119 smbios_build_type_3_table();
1121 smbios_smp_sockets
= ms
->smp
.sockets
;
1122 assert(smbios_smp_sockets
>= 1);
1124 for (i
= 0; i
< smbios_smp_sockets
; i
++) {
1125 smbios_build_type_4_table(ms
, i
);
1128 smbios_build_type_8_table();
1129 smbios_build_type_11_table();
1131 #define MAX_DIMM_SZ (16 * GiB)
1132 #define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ \
1133 : ((current_machine->ram_size - 1) % MAX_DIMM_SZ) + 1)
1135 dimm_cnt
= QEMU_ALIGN_UP(current_machine
->ram_size
, MAX_DIMM_SZ
) / MAX_DIMM_SZ
;
1138 * The offset determines if we need to keep additional space between
1139 * table 17 and table 19 header handle numbers so that they do
1140 * not overlap. For example, for a VM with larger than 8 TB guest
1141 * memory and DIMM like chunks of 16 GiB, the default space between
1142 * the two tables (T19_BASE - T17_BASE = 512) is not enough.
1144 offset
= (dimm_cnt
> (T19_BASE
- T17_BASE
)) ? \
1145 dimm_cnt
- (T19_BASE
- T17_BASE
) : 0;
1147 smbios_build_type_16_table(dimm_cnt
);
1149 for (i
= 0; i
< dimm_cnt
; i
++) {
1150 smbios_build_type_17_table(i
, GET_DIMM_SZ
);
1153 for (i
= 0; i
< mem_array_size
; i
++) {
1154 smbios_build_type_19_table(i
, offset
, mem_array
[i
].address
,
1155 mem_array
[i
].length
);
1159 * make sure 16 bit handle numbers in the headers of tables 19
1160 * and 32 do not overlap.
1162 assert((mem_array_size
+ offset
) < (T32_BASE
- T19_BASE
));
1164 smbios_build_type_32_table();
1165 smbios_build_type_38_table();
1166 smbios_build_type_41_table(errp
);
1167 smbios_build_type_127_table();
1169 smbios_validate_table(ms
);
1170 smbios_entry_point_setup();
1171 smbios_immutable
= true;
1174 /* return tables blob and entry point (anchor), and their sizes */
1175 *tables
= smbios_tables
;
1176 *tables_len
= smbios_tables_len
;
1177 *anchor
= (uint8_t *)&ep
;
1179 /* calculate length based on anchor string */
1180 if (!strncmp((char *)&ep
, "_SM_", 4)) {
1181 *anchor_len
= sizeof(struct smbios_21_entry_point
);
1182 } else if (!strncmp((char *)&ep
, "_SM3_", 5)) {
1183 *anchor_len
= sizeof(struct smbios_30_entry_point
);
1189 static void save_opt(const char **dest
, QemuOpts
*opts
, const char *name
)
1191 const char *val
= qemu_opt_get(opts
, name
);
1204 static int save_opt_one(void *opaque
,
1205 const char *name
, const char *value
,
1208 struct opt_list
*opt
= opaque
;
1210 if (g_str_equal(name
, "path")) {
1211 g_autoptr(GByteArray
) data
= g_byte_array_new();
1212 g_autofree
char *buf
= g_new(char, 4096);
1214 int fd
= qemu_open(value
, O_RDONLY
, errp
);
1220 ret
= read(fd
, buf
, 4096);
1225 error_setg(errp
, "Unable to read from %s: %s",
1226 value
, strerror(errno
));
1230 if (memchr(buf
, '\0', ret
)) {
1231 error_setg(errp
, "NUL in OEM strings value in %s", value
);
1235 g_byte_array_append(data
, (guint8
*)buf
, ret
);
1240 *opt
->dest
= g_renew(char *, *opt
->dest
, (*opt
->ndest
) + 1);
1241 (*opt
->dest
)[*opt
->ndest
] = (char *)g_byte_array_free(data
, FALSE
);
1244 } else if (g_str_equal(name
, "value")) {
1245 *opt
->dest
= g_renew(char *, *opt
->dest
, (*opt
->ndest
) + 1);
1246 (*opt
->dest
)[*opt
->ndest
] = g_strdup(value
);
1248 } else if (!g_str_equal(name
, "type")) {
1249 error_setg(errp
, "Unexpected option %s", name
);
1256 static bool save_opt_list(size_t *ndest
, char ***dest
, QemuOpts
*opts
,
1259 struct opt_list opt
= {
1262 if (!qemu_opt_foreach(opts
, save_opt_one
, &opt
, errp
)) {
1268 void smbios_entry_add(QemuOpts
*opts
, Error
**errp
)
1272 assert(!smbios_immutable
);
1274 val
= qemu_opt_get(opts
, "file");
1276 struct smbios_structure_header
*header
;
1278 struct smbios_table
*table
; /* legacy mode only */
1280 if (!qemu_opts_validate(opts
, qemu_smbios_file_opts
, errp
)) {
1284 size
= get_image_size(val
);
1285 if (size
== -1 || size
< sizeof(struct smbios_structure_header
)) {
1286 error_setg(errp
, "Cannot read SMBIOS file %s", val
);
1291 * NOTE: standard double '\0' terminator expected, per smbios spec.
1292 * (except in legacy mode, where the second '\0' is implicit and
1293 * will be inserted by the BIOS).
1295 smbios_tables
= g_realloc(smbios_tables
, smbios_tables_len
+ size
);
1296 header
= (struct smbios_structure_header
*)(smbios_tables
+
1299 if (load_image_size(val
, (uint8_t *)header
, size
) != size
) {
1300 error_setg(errp
, "Failed to load SMBIOS file %s", val
);
1304 if (header
->type
<= SMBIOS_MAX_TYPE
) {
1305 if (test_bit(header
->type
, have_fields_bitmap
)) {
1307 "can't load type %d struct, fields already specified!",
1311 set_bit(header
->type
, have_binfile_bitmap
);
1314 if (header
->type
== 4) {
1315 smbios_type4_count
++;
1318 smbios_tables_len
+= size
;
1319 if (size
> smbios_table_max
) {
1320 smbios_table_max
= size
;
1324 /* add a copy of the newly loaded blob to legacy smbios_entries */
1325 /* NOTE: This code runs before smbios_set_defaults(), so we don't
1326 * yet know which mode (legacy vs. aggregate-table) will be
1327 * required. We therefore add the binary blob to both legacy
1328 * (smbios_entries) and aggregate (smbios_tables) tables, and
1329 * delete the one we don't need from smbios_set_defaults(),
1330 * once we know which machine version has been requested.
1332 if (!smbios_entries
) {
1333 smbios_entries_len
= sizeof(uint16_t);
1334 smbios_entries
= g_malloc0(smbios_entries_len
);
1336 smbios_entries
= g_realloc(smbios_entries
, smbios_entries_len
+
1337 size
+ sizeof(*table
));
1338 table
= (struct smbios_table
*)(smbios_entries
+ smbios_entries_len
);
1339 table
->header
.type
= SMBIOS_TABLE_ENTRY
;
1340 table
->header
.length
= cpu_to_le16(sizeof(*table
) + size
);
1341 memcpy(table
->data
, header
, size
);
1342 smbios_entries_len
+= sizeof(*table
) + size
;
1343 (*(uint16_t *)smbios_entries
) =
1344 cpu_to_le16(le16_to_cpu(*(uint16_t *)smbios_entries
) + 1);
1345 /* end: add a copy of the newly loaded blob to legacy smbios_entries */
1350 val
= qemu_opt_get(opts
, "type");
1352 unsigned long type
= strtoul(val
, NULL
, 0);
1354 if (type
> SMBIOS_MAX_TYPE
) {
1355 error_setg(errp
, "out of range!");
1359 if (test_bit(type
, have_binfile_bitmap
)) {
1360 error_setg(errp
, "can't add fields, binary file already loaded!");
1363 set_bit(type
, have_fields_bitmap
);
1367 if (!qemu_opts_validate(opts
, qemu_smbios_type0_opts
, errp
)) {
1370 save_opt(&type0
.vendor
, opts
, "vendor");
1371 save_opt(&type0
.version
, opts
, "version");
1372 save_opt(&type0
.date
, opts
, "date");
1373 type0
.uefi
= qemu_opt_get_bool(opts
, "uefi", false);
1375 val
= qemu_opt_get(opts
, "release");
1377 if (sscanf(val
, "%hhu.%hhu", &type0
.major
, &type0
.minor
) != 2) {
1378 error_setg(errp
, "Invalid release");
1381 type0
.have_major_minor
= true;
1385 if (!qemu_opts_validate(opts
, qemu_smbios_type1_opts
, errp
)) {
1388 save_opt(&type1
.manufacturer
, opts
, "manufacturer");
1389 save_opt(&type1
.product
, opts
, "product");
1390 save_opt(&type1
.version
, opts
, "version");
1391 save_opt(&type1
.serial
, opts
, "serial");
1392 save_opt(&type1
.sku
, opts
, "sku");
1393 save_opt(&type1
.family
, opts
, "family");
1395 val
= qemu_opt_get(opts
, "uuid");
1397 if (qemu_uuid_parse(val
, &qemu_uuid
) != 0) {
1398 error_setg(errp
, "Invalid UUID");
1401 qemu_uuid_set
= true;
1405 if (!qemu_opts_validate(opts
, qemu_smbios_type2_opts
, errp
)) {
1408 save_opt(&type2
.manufacturer
, opts
, "manufacturer");
1409 save_opt(&type2
.product
, opts
, "product");
1410 save_opt(&type2
.version
, opts
, "version");
1411 save_opt(&type2
.serial
, opts
, "serial");
1412 save_opt(&type2
.asset
, opts
, "asset");
1413 save_opt(&type2
.location
, opts
, "location");
1416 if (!qemu_opts_validate(opts
, qemu_smbios_type3_opts
, errp
)) {
1419 save_opt(&type3
.manufacturer
, opts
, "manufacturer");
1420 save_opt(&type3
.version
, opts
, "version");
1421 save_opt(&type3
.serial
, opts
, "serial");
1422 save_opt(&type3
.asset
, opts
, "asset");
1423 save_opt(&type3
.sku
, opts
, "sku");
1426 if (!qemu_opts_validate(opts
, qemu_smbios_type4_opts
, errp
)) {
1429 save_opt(&type4
.sock_pfx
, opts
, "sock_pfx");
1430 type4
.processor_family
= qemu_opt_get_number(opts
,
1433 save_opt(&type4
.manufacturer
, opts
, "manufacturer");
1434 save_opt(&type4
.version
, opts
, "version");
1435 save_opt(&type4
.serial
, opts
, "serial");
1436 save_opt(&type4
.asset
, opts
, "asset");
1437 save_opt(&type4
.part
, opts
, "part");
1438 /* If the value is 0, it will take the value from the CPU model. */
1439 type4
.processor_id
= qemu_opt_get_number(opts
, "processor-id", 0);
1440 type4
.max_speed
= qemu_opt_get_number(opts
, "max-speed",
1442 type4
.current_speed
= qemu_opt_get_number(opts
, "current-speed",
1444 if (type4
.max_speed
> UINT16_MAX
||
1445 type4
.current_speed
> UINT16_MAX
) {
1446 error_setg(errp
, "SMBIOS CPU speed is too large (> %d)",
1451 if (!qemu_opts_validate(opts
, qemu_smbios_type8_opts
, errp
)) {
1454 struct type8_instance
*t8_i
;
1455 t8_i
= g_new0(struct type8_instance
, 1);
1456 save_opt(&t8_i
->internal_reference
, opts
, "internal_reference");
1457 save_opt(&t8_i
->external_reference
, opts
, "external_reference");
1458 t8_i
->connector_type
= qemu_opt_get_number(opts
,
1459 "connector_type", 0);
1460 t8_i
->port_type
= qemu_opt_get_number(opts
, "port_type", 0);
1461 QTAILQ_INSERT_TAIL(&type8
, t8_i
, next
);
1464 if (!qemu_opts_validate(opts
, qemu_smbios_type11_opts
, errp
)) {
1467 if (!save_opt_list(&type11
.nvalues
, &type11
.values
, opts
, errp
)) {
1472 if (!qemu_opts_validate(opts
, qemu_smbios_type17_opts
, errp
)) {
1475 save_opt(&type17
.loc_pfx
, opts
, "loc_pfx");
1476 save_opt(&type17
.bank
, opts
, "bank");
1477 save_opt(&type17
.manufacturer
, opts
, "manufacturer");
1478 save_opt(&type17
.serial
, opts
, "serial");
1479 save_opt(&type17
.asset
, opts
, "asset");
1480 save_opt(&type17
.part
, opts
, "part");
1481 type17
.speed
= qemu_opt_get_number(opts
, "speed", 0);
1484 struct type41_instance
*t41_i
;
1485 Error
*local_err
= NULL
;
1487 if (!qemu_opts_validate(opts
, qemu_smbios_type41_opts
, errp
)) {
1490 t41_i
= g_new0(struct type41_instance
, 1);
1491 save_opt(&t41_i
->designation
, opts
, "designation");
1492 t41_i
->kind
= qapi_enum_parse(&type41_kind_lookup
,
1493 qemu_opt_get(opts
, "kind"),
1495 t41_i
->kind
|= 0x80; /* enabled */
1496 if (local_err
!= NULL
) {
1497 error_propagate(errp
, local_err
);
1501 t41_i
->instance
= qemu_opt_get_number(opts
, "instance", 1);
1502 save_opt(&t41_i
->pcidev
, opts
, "pcidev");
1504 QTAILQ_INSERT_TAIL(&type41
, t41_i
, next
);
1509 "Don't know how to build fields for SMBIOS type %ld",
1515 error_setg(errp
, "Must specify type= or file=");