2 * qdev property parsing
3 * (parts specific for qemu-system-*)
5 * This file is based on code from hw/qdev-properties.c from
6 * commit 074a86fccd185616469dfcdc0e157f438aebba18,
7 * Copyright (c) Gerd Hoffmann <kraxel@redhat.com> and other contributors.
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "hw/qdev-properties.h"
15 #include "hw/qdev-properties-system.h"
16 #include "qapi/error.h"
17 #include "qapi/visitor.h"
18 #include "qapi/qapi-types-block.h"
19 #include "qapi/qapi-types-machine.h"
20 #include "qapi/qapi-types-migration.h"
21 #include "qapi/qmp/qerror.h"
22 #include "qemu/ctype.h"
23 #include "qemu/cutils.h"
24 #include "qemu/units.h"
25 #include "qemu/uuid.h"
26 #include "qemu/error-report.h"
27 #include "qdev-prop-internal.h"
29 #include "audio/audio.h"
30 #include "chardev/char-fe.h"
31 #include "sysemu/block-backend.h"
32 #include "sysemu/blockdev.h"
34 #include "hw/pci/pci.h"
35 #include "util/block-helpers.h"
37 static bool check_prop_still_unset(Object
*obj
, const char *name
,
38 const void *old_val
, const char *new_val
,
39 bool allow_override
, Error
**errp
)
41 const GlobalProperty
*prop
= qdev_find_global_prop(obj
, name
);
43 if (!old_val
|| (!prop
&& allow_override
)) {
48 error_setg(errp
, "-global %s.%s=... conflicts with %s=%s",
49 prop
->driver
, prop
->property
, name
, new_val
);
51 /* Error message is vague, but a better one would be hard */
52 error_setg(errp
, "%s=%s conflicts, and override is not implemented",
61 static void get_drive(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
64 Property
*prop
= opaque
;
65 void **ptr
= object_field_prop_ptr(obj
, prop
);
70 value
= blk_name(*ptr
);
72 BlockDriverState
*bs
= blk_bs(*ptr
);
74 value
= bdrv_get_node_name(bs
);
82 visit_type_str(v
, name
, &p
, errp
);
86 static void set_drive_helper(Object
*obj
, Visitor
*v
, const char *name
,
87 void *opaque
, bool iothread
, Error
**errp
)
89 DeviceState
*dev
= DEVICE(obj
);
90 Property
*prop
= opaque
;
91 void **ptr
= object_field_prop_ptr(obj
, prop
);
94 bool blk_created
= false;
99 if (!visit_type_str(v
, name
, &str
, errp
)) {
103 if (!check_prop_still_unset(obj
, name
, *ptr
, str
, true, errp
)) {
108 /* BlockBackend alread exists. So, we want to change attached node */
110 ctx
= blk_get_aio_context(blk
);
111 bs
= bdrv_lookup_bs(NULL
, str
, errp
);
116 if (ctx
!= bdrv_get_aio_context(bs
)) {
117 error_setg(errp
, "Different aio context is not supported for new "
121 aio_context_acquire(ctx
);
122 blk_replace_bs(blk
, bs
, errp
);
123 aio_context_release(ctx
);
133 blk
= blk_by_name(str
);
135 bs
= bdrv_lookup_bs(NULL
, str
, NULL
);
138 * If the device supports iothreads, it will make sure to move the
139 * block node to the right AioContext if necessary (or fail if this
140 * isn't possible because of other users). Devices that are not
141 * aware of iothreads require their BlockBackends to be in the main
144 ctx
= iothread
? bdrv_get_aio_context(bs
) : qemu_get_aio_context();
145 blk
= blk_new(ctx
, 0, BLK_PERM_ALL
);
148 ret
= blk_insert_bs(blk
, bs
, errp
);
155 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
156 object_get_typename(OBJECT(dev
)), name
, str
);
159 if (blk_attach_dev(blk
, dev
) < 0) {
160 DriveInfo
*dinfo
= blk_legacy_dinfo(blk
);
162 if (dinfo
&& dinfo
->type
!= IF_NONE
) {
163 error_setg(errp
, "Drive '%s' is already in use because "
164 "it has been automatically connected to another "
165 "device (did you need 'if=none' in the drive options?)",
168 error_setg(errp
, "Drive '%s' is already in use by another device",
178 /* If we need to keep a reference, blk_attach_dev() took it */
185 static void set_drive(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
188 set_drive_helper(obj
, v
, name
, opaque
, false, errp
);
191 static void set_drive_iothread(Object
*obj
, Visitor
*v
, const char *name
,
192 void *opaque
, Error
**errp
)
194 set_drive_helper(obj
, v
, name
, opaque
, true, errp
);
197 static void release_drive(Object
*obj
, const char *name
, void *opaque
)
199 DeviceState
*dev
= DEVICE(obj
);
200 Property
*prop
= opaque
;
201 BlockBackend
**ptr
= object_field_prop_ptr(obj
, prop
);
204 AioContext
*ctx
= blk_get_aio_context(*ptr
);
206 aio_context_acquire(ctx
);
207 blockdev_auto_del(*ptr
);
208 blk_detach_dev(*ptr
, dev
);
209 aio_context_release(ctx
);
213 const PropertyInfo qdev_prop_drive
= {
215 .description
= "Node name or ID of a block device to use as a backend",
216 .realized_set_allowed
= true,
219 .release
= release_drive
,
222 const PropertyInfo qdev_prop_drive_iothread
= {
224 .description
= "Node name or ID of a block device to use as a backend",
225 .realized_set_allowed
= true,
227 .set
= set_drive_iothread
,
228 .release
= release_drive
,
231 /* --- character device --- */
233 static void get_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
236 CharBackend
*be
= object_field_prop_ptr(obj
, opaque
);
239 p
= g_strdup(be
->chr
&& be
->chr
->label
? be
->chr
->label
: "");
240 visit_type_str(v
, name
, &p
, errp
);
244 static void set_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
247 Property
*prop
= opaque
;
248 CharBackend
*be
= object_field_prop_ptr(obj
, prop
);
252 if (!visit_type_str(v
, name
, &str
, errp
)) {
257 * TODO Should this really be an error? If no, the old value
258 * needs to be released before we store the new one.
260 if (!check_prop_still_unset(obj
, name
, be
->chr
, str
, false, errp
)) {
270 s
= qemu_chr_find(str
);
272 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
273 object_get_typename(obj
), name
, str
);
274 } else if (!qemu_chr_fe_init(be
, s
, errp
)) {
275 error_prepend(errp
, "Property '%s.%s' can't take value '%s': ",
276 object_get_typename(obj
), name
, str
);
281 static void release_chr(Object
*obj
, const char *name
, void *opaque
)
283 Property
*prop
= opaque
;
284 CharBackend
*be
= object_field_prop_ptr(obj
, prop
);
286 qemu_chr_fe_deinit(be
, false);
289 const PropertyInfo qdev_prop_chr
= {
291 .description
= "ID of a chardev to use as a backend",
294 .release
= release_chr
,
297 /* --- mac address --- */
300 * accepted syntax versions:
304 static void get_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
307 Property
*prop
= opaque
;
308 MACAddr
*mac
= object_field_prop_ptr(obj
, prop
);
309 char buffer
[2 * 6 + 5 + 1];
312 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
313 mac
->a
[0], mac
->a
[1], mac
->a
[2],
314 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
316 visit_type_str(v
, name
, &p
, errp
);
319 static void set_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
322 Property
*prop
= opaque
;
323 MACAddr
*mac
= object_field_prop_ptr(obj
, prop
);
328 if (!visit_type_str(v
, name
, &str
, errp
)) {
332 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
335 if (!qemu_isxdigit(str
[pos
])) {
338 if (!qemu_isxdigit(str
[pos
+ 1])) {
342 if (str
[pos
+ 2] != '\0') {
346 if (str
[pos
+ 2] != ':' && str
[pos
+ 2] != '-') {
350 if (qemu_strtol(str
+ pos
, &p
, 16, &val
) < 0 || val
> 0xff) {
359 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
363 const PropertyInfo qdev_prop_macaddr
= {
365 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
370 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
,
371 const uint8_t *value
)
373 char str
[2 * 6 + 5 + 1];
374 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
375 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
377 object_property_set_str(OBJECT(dev
), name
, str
, &error_abort
);
380 /* --- netdev device --- */
381 static void get_netdev(Object
*obj
, Visitor
*v
, const char *name
,
382 void *opaque
, Error
**errp
)
384 Property
*prop
= opaque
;
385 NICPeers
*peers_ptr
= object_field_prop_ptr(obj
, prop
);
386 char *p
= g_strdup(peers_ptr
->ncs
[0] ? peers_ptr
->ncs
[0]->name
: "");
388 visit_type_str(v
, name
, &p
, errp
);
392 static void set_netdev(Object
*obj
, Visitor
*v
, const char *name
,
393 void *opaque
, Error
**errp
)
395 Property
*prop
= opaque
;
396 NICPeers
*peers_ptr
= object_field_prop_ptr(obj
, prop
);
397 NetClientState
**ncs
= peers_ptr
->ncs
;
398 NetClientState
*peers
[MAX_QUEUE_NUM
];
399 int queues
, err
= 0, i
= 0;
402 if (!visit_type_str(v
, name
, &str
, errp
)) {
406 queues
= qemu_find_net_clients_except(str
, peers
,
407 NET_CLIENT_DRIVER_NIC
,
414 if (queues
> MAX_QUEUE_NUM
) {
415 error_setg(errp
, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
416 str
, queues
, MAX_QUEUE_NUM
);
420 for (i
= 0; i
< queues
; i
++) {
421 if (peers
[i
]->peer
) {
427 * TODO Should this really be an error? If no, the old value
428 * needs to be released before we store the new one.
430 if (!check_prop_still_unset(obj
, name
, ncs
[i
], str
, false, errp
)) {
435 ncs
[i
]->queue_index
= i
;
438 peers_ptr
->queues
= queues
;
441 error_set_from_qdev_prop_error(errp
, err
, obj
, name
, str
);
445 const PropertyInfo qdev_prop_netdev
= {
447 .description
= "ID of a netdev to use as a backend",
453 /* --- audiodev --- */
454 static void get_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
455 void *opaque
, Error
**errp
)
457 Property
*prop
= opaque
;
458 QEMUSoundCard
*card
= object_field_prop_ptr(obj
, prop
);
459 char *p
= g_strdup(audio_get_id(card
));
461 visit_type_str(v
, name
, &p
, errp
);
465 static void set_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
466 void *opaque
, Error
**errp
)
468 Property
*prop
= opaque
;
469 QEMUSoundCard
*card
= object_field_prop_ptr(obj
, prop
);
474 if (!visit_type_str(v
, name
, &str
, errp
)) {
478 state
= audio_state_by_name(str
);
487 error_set_from_qdev_prop_error(errp
, err
, obj
, name
, str
);
491 const PropertyInfo qdev_prop_audiodev
= {
493 .description
= "ID of an audiodev to use as a backend",
494 /* release done on shutdown */
499 bool qdev_prop_set_drive_err(DeviceState
*dev
, const char *name
,
500 BlockBackend
*value
, Error
**errp
)
502 const char *ref
= "";
505 ref
= blk_name(value
);
507 const BlockDriverState
*bs
= blk_bs(value
);
509 ref
= bdrv_get_node_name(bs
);
514 return object_property_set_str(OBJECT(dev
), name
, ref
, errp
);
517 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
520 qdev_prop_set_drive_err(dev
, name
, value
, &error_abort
);
523 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
,
526 assert(!value
|| value
->label
);
527 object_property_set_str(OBJECT(dev
), name
, value
? value
->label
: "",
531 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
,
532 NetClientState
*value
)
534 assert(!value
|| value
->name
);
535 object_property_set_str(OBJECT(dev
), name
, value
? value
->name
: "",
539 void qdev_set_nic_properties(DeviceState
*dev
, NICInfo
*nd
)
541 qdev_prop_set_macaddr(dev
, "mac", nd
->macaddr
.a
);
543 qdev_prop_set_netdev(dev
, "netdev", nd
->netdev
);
545 if (nd
->nvectors
!= DEV_NVECTORS_UNSPECIFIED
&&
546 object_property_find(OBJECT(dev
), "vectors")) {
547 qdev_prop_set_uint32(dev
, "vectors", nd
->nvectors
);
549 nd
->instantiated
= 1;
552 /* --- lost tick policy --- */
554 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
556 const PropertyInfo qdev_prop_losttickpolicy
= {
557 .name
= "LostTickPolicy",
558 .enum_table
= &LostTickPolicy_lookup
,
559 .get
= qdev_propinfo_get_enum
,
560 .set
= qdev_propinfo_set_enum
,
561 .set_default_value
= qdev_propinfo_set_default_value_enum
,
564 /* --- blocksize --- */
566 static void set_blocksize(Object
*obj
, Visitor
*v
, const char *name
,
567 void *opaque
, Error
**errp
)
569 DeviceState
*dev
= DEVICE(obj
);
570 Property
*prop
= opaque
;
571 uint32_t *ptr
= object_field_prop_ptr(obj
, prop
);
573 Error
*local_err
= NULL
;
575 if (!visit_type_size(v
, name
, &value
, errp
)) {
578 check_block_size(dev
->id
? : "", name
, value
, &local_err
);
580 error_propagate(errp
, local_err
);
586 const PropertyInfo qdev_prop_blocksize
= {
588 .description
= "A power of two between " MIN_BLOCK_SIZE_STR
589 " and " MAX_BLOCK_SIZE_STR
,
590 .get
= qdev_propinfo_get_size32
,
591 .set
= set_blocksize
,
592 .set_default_value
= qdev_propinfo_set_default_value_uint
,
595 /* --- Block device error handling policy --- */
597 QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError
) != sizeof(int));
599 const PropertyInfo qdev_prop_blockdev_on_error
= {
600 .name
= "BlockdevOnError",
601 .description
= "Error handling policy, "
602 "report/ignore/enospc/stop/auto",
603 .enum_table
= &BlockdevOnError_lookup
,
604 .get
= qdev_propinfo_get_enum
,
605 .set
= qdev_propinfo_set_enum
,
606 .set_default_value
= qdev_propinfo_set_default_value_enum
,
609 /* --- BIOS CHS translation */
611 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
613 const PropertyInfo qdev_prop_bios_chs_trans
= {
614 .name
= "BiosAtaTranslation",
615 .description
= "Logical CHS translation algorithm, "
616 "auto/none/lba/large/rechs",
617 .enum_table
= &BiosAtaTranslation_lookup
,
618 .get
= qdev_propinfo_get_enum
,
619 .set
= qdev_propinfo_set_enum
,
620 .set_default_value
= qdev_propinfo_set_default_value_enum
,
623 /* --- FDC default drive types */
625 const PropertyInfo qdev_prop_fdc_drive_type
= {
626 .name
= "FdcDriveType",
627 .description
= "FDC drive type, "
628 "144/288/120/none/auto",
629 .enum_table
= &FloppyDriveType_lookup
,
630 .get
= qdev_propinfo_get_enum
,
631 .set
= qdev_propinfo_set_enum
,
632 .set_default_value
= qdev_propinfo_set_default_value_enum
,
635 /* --- MultiFDCompression --- */
637 const PropertyInfo qdev_prop_multifd_compression
= {
638 .name
= "MultiFDCompression",
639 .description
= "multifd_compression values, "
641 .enum_table
= &MultiFDCompression_lookup
,
642 .get
= qdev_propinfo_get_enum
,
643 .set
= qdev_propinfo_set_enum
,
644 .set_default_value
= qdev_propinfo_set_default_value_enum
,
647 /* --- Reserved Region --- */
651 * <low address>:<high address>:<type>
652 * where low/high addresses are uint64_t in hexadecimal
653 * and type is a non-negative decimal integer
655 static void get_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
656 void *opaque
, Error
**errp
)
658 Property
*prop
= opaque
;
659 ReservedRegion
*rr
= object_field_prop_ptr(obj
, prop
);
664 rc
= snprintf(buffer
, sizeof(buffer
), "0x%"PRIx64
":0x%"PRIx64
":%u",
665 rr
->low
, rr
->high
, rr
->type
);
666 assert(rc
< sizeof(buffer
));
668 visit_type_str(v
, name
, &p
, errp
);
671 static void set_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
672 void *opaque
, Error
**errp
)
674 Property
*prop
= opaque
;
675 ReservedRegion
*rr
= object_field_prop_ptr(obj
, prop
);
676 Error
*local_err
= NULL
;
681 visit_type_str(v
, name
, &str
, &local_err
);
683 error_propagate(errp
, local_err
);
687 ret
= qemu_strtou64(str
, &endptr
, 16, &rr
->low
);
689 error_setg(errp
, "start address of '%s'"
690 " must be a hexadecimal integer", name
);
693 if (*endptr
!= ':') {
694 goto separator_error
;
697 ret
= qemu_strtou64(endptr
+ 1, &endptr
, 16, &rr
->high
);
699 error_setg(errp
, "end address of '%s'"
700 " must be a hexadecimal integer", name
);
703 if (*endptr
!= ':') {
704 goto separator_error
;
707 ret
= qemu_strtoui(endptr
+ 1, &endptr
, 10, &rr
->type
);
709 error_setg(errp
, "type of '%s'"
710 " must be a non-negative decimal integer", name
);
715 error_setg(errp
, "reserved region fields must be separated with ':'");
721 const PropertyInfo qdev_prop_reserved_region
= {
722 .name
= "reserved_region",
723 .description
= "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0",
724 .get
= get_reserved_region
,
725 .set
= set_reserved_region
,
728 /* --- pci address --- */
731 * bus-local address, i.e. "$slot" or "$slot.$fn"
733 static void set_pci_devfn(Object
*obj
, Visitor
*v
, const char *name
,
734 void *opaque
, Error
**errp
)
736 Property
*prop
= opaque
;
737 int32_t value
, *ptr
= object_field_prop_ptr(obj
, prop
);
738 unsigned int slot
, fn
, n
;
741 if (!visit_type_str(v
, name
, &str
, NULL
)) {
742 if (!visit_type_int32(v
, name
, &value
, errp
)) {
745 if (value
< -1 || value
> 255) {
746 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
747 name
? name
: "null", "a value between -1 and 255");
754 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
756 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
760 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
763 *ptr
= slot
<< 3 | fn
;
768 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
772 static int print_pci_devfn(Object
*obj
, Property
*prop
, char *dest
,
775 int32_t *ptr
= object_field_prop_ptr(obj
, prop
);
778 return snprintf(dest
, len
, "<unset>");
780 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
784 const PropertyInfo qdev_prop_pci_devfn
= {
786 .description
= "Slot and optional function number, example: 06.0 or 06",
787 .print
= print_pci_devfn
,
788 .get
= qdev_propinfo_get_int32
,
789 .set
= set_pci_devfn
,
790 .set_default_value
= qdev_propinfo_set_default_value_int
,
793 /* --- pci host address --- */
795 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
796 void *opaque
, Error
**errp
)
798 Property
*prop
= opaque
;
799 PCIHostDeviceAddress
*addr
= object_field_prop_ptr(obj
, prop
);
800 char buffer
[] = "ffff:ff:ff.f";
805 * Catch "invalid" device reference from vfio-pci and allow the
806 * default buffer representing the non-existent device to be used.
808 if (~addr
->domain
|| ~addr
->bus
|| ~addr
->slot
|| ~addr
->function
) {
809 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%0d",
810 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
811 assert(rc
== sizeof(buffer
) - 1);
814 visit_type_str(v
, name
, &p
, errp
);
818 * Parse [<domain>:]<bus>:<slot>.<func>
819 * if <domain> is not supplied, it's assumed to be 0.
821 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
822 void *opaque
, Error
**errp
)
824 Property
*prop
= opaque
;
825 PCIHostDeviceAddress
*addr
= object_field_prop_ptr(obj
, prop
);
829 unsigned long dom
= 0, bus
= 0;
830 unsigned int slot
= 0, func
= 0;
832 if (!visit_type_str(v
, name
, &str
, errp
)) {
837 val
= strtoul(p
, &e
, 16);
838 if (e
== p
|| *e
!= ':') {
844 val
= strtoul(p
, &e
, 16);
852 val
= strtoul(p
, &e
, 16);
863 val
= strtoul(p
, &e
, 10);
869 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
880 addr
->function
= func
;
886 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
890 const PropertyInfo qdev_prop_pci_host_devaddr
= {
892 .description
= "Address (bus/device/function) of "
893 "the host device, example: 04:10.0",
894 .get
= get_pci_host_devaddr
,
895 .set
= set_pci_host_devaddr
,
898 /* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */
900 const PropertyInfo qdev_prop_off_auto_pcibar
= {
901 .name
= "OffAutoPCIBAR",
902 .description
= "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
903 .enum_table
= &OffAutoPCIBAR_lookup
,
904 .get
= qdev_propinfo_get_enum
,
905 .set
= qdev_propinfo_set_enum
,
906 .set_default_value
= qdev_propinfo_set_default_value_enum
,
909 /* --- PCIELinkSpeed 2_5/5/8/16 -- */
911 static void get_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
912 void *opaque
, Error
**errp
)
914 Property
*prop
= opaque
;
915 PCIExpLinkSpeed
*p
= object_field_prop_ptr(obj
, prop
);
919 case QEMU_PCI_EXP_LNK_2_5GT
:
920 speed
= PCIE_LINK_SPEED_2_5
;
922 case QEMU_PCI_EXP_LNK_5GT
:
923 speed
= PCIE_LINK_SPEED_5
;
925 case QEMU_PCI_EXP_LNK_8GT
:
926 speed
= PCIE_LINK_SPEED_8
;
928 case QEMU_PCI_EXP_LNK_16GT
:
929 speed
= PCIE_LINK_SPEED_16
;
936 visit_type_enum(v
, name
, &speed
, prop
->info
->enum_table
, errp
);
939 static void set_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
940 void *opaque
, Error
**errp
)
942 Property
*prop
= opaque
;
943 PCIExpLinkSpeed
*p
= object_field_prop_ptr(obj
, prop
);
946 if (!visit_type_enum(v
, name
, &speed
, prop
->info
->enum_table
,
952 case PCIE_LINK_SPEED_2_5
:
953 *p
= QEMU_PCI_EXP_LNK_2_5GT
;
955 case PCIE_LINK_SPEED_5
:
956 *p
= QEMU_PCI_EXP_LNK_5GT
;
958 case PCIE_LINK_SPEED_8
:
959 *p
= QEMU_PCI_EXP_LNK_8GT
;
961 case PCIE_LINK_SPEED_16
:
962 *p
= QEMU_PCI_EXP_LNK_16GT
;
970 const PropertyInfo qdev_prop_pcie_link_speed
= {
971 .name
= "PCIELinkSpeed",
972 .description
= "2_5/5/8/16",
973 .enum_table
= &PCIELinkSpeed_lookup
,
974 .get
= get_prop_pcielinkspeed
,
975 .set
= set_prop_pcielinkspeed
,
976 .set_default_value
= qdev_propinfo_set_default_value_enum
,
979 /* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
981 static void get_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
982 void *opaque
, Error
**errp
)
984 Property
*prop
= opaque
;
985 PCIExpLinkWidth
*p
= object_field_prop_ptr(obj
, prop
);
989 case QEMU_PCI_EXP_LNK_X1
:
990 width
= PCIE_LINK_WIDTH_1
;
992 case QEMU_PCI_EXP_LNK_X2
:
993 width
= PCIE_LINK_WIDTH_2
;
995 case QEMU_PCI_EXP_LNK_X4
:
996 width
= PCIE_LINK_WIDTH_4
;
998 case QEMU_PCI_EXP_LNK_X8
:
999 width
= PCIE_LINK_WIDTH_8
;
1001 case QEMU_PCI_EXP_LNK_X12
:
1002 width
= PCIE_LINK_WIDTH_12
;
1004 case QEMU_PCI_EXP_LNK_X16
:
1005 width
= PCIE_LINK_WIDTH_16
;
1007 case QEMU_PCI_EXP_LNK_X32
:
1008 width
= PCIE_LINK_WIDTH_32
;
1015 visit_type_enum(v
, name
, &width
, prop
->info
->enum_table
, errp
);
1018 static void set_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
1019 void *opaque
, Error
**errp
)
1021 Property
*prop
= opaque
;
1022 PCIExpLinkWidth
*p
= object_field_prop_ptr(obj
, prop
);
1025 if (!visit_type_enum(v
, name
, &width
, prop
->info
->enum_table
,
1031 case PCIE_LINK_WIDTH_1
:
1032 *p
= QEMU_PCI_EXP_LNK_X1
;
1034 case PCIE_LINK_WIDTH_2
:
1035 *p
= QEMU_PCI_EXP_LNK_X2
;
1037 case PCIE_LINK_WIDTH_4
:
1038 *p
= QEMU_PCI_EXP_LNK_X4
;
1040 case PCIE_LINK_WIDTH_8
:
1041 *p
= QEMU_PCI_EXP_LNK_X8
;
1043 case PCIE_LINK_WIDTH_12
:
1044 *p
= QEMU_PCI_EXP_LNK_X12
;
1046 case PCIE_LINK_WIDTH_16
:
1047 *p
= QEMU_PCI_EXP_LNK_X16
;
1049 case PCIE_LINK_WIDTH_32
:
1050 *p
= QEMU_PCI_EXP_LNK_X32
;
1058 const PropertyInfo qdev_prop_pcie_link_width
= {
1059 .name
= "PCIELinkWidth",
1060 .description
= "1/2/4/8/12/16/32",
1061 .enum_table
= &PCIELinkWidth_lookup
,
1062 .get
= get_prop_pcielinkwidth
,
1063 .set
= set_prop_pcielinkwidth
,
1064 .set_default_value
= qdev_propinfo_set_default_value_enum
,
1069 static void get_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1072 Property
*prop
= opaque
;
1073 QemuUUID
*uuid
= object_field_prop_ptr(obj
, prop
);
1074 char buffer
[UUID_FMT_LEN
+ 1];
1077 qemu_uuid_unparse(uuid
, buffer
);
1079 visit_type_str(v
, name
, &p
, errp
);
1082 #define UUID_VALUE_AUTO "auto"
1084 static void set_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1087 Property
*prop
= opaque
;
1088 QemuUUID
*uuid
= object_field_prop_ptr(obj
, prop
);
1091 if (!visit_type_str(v
, name
, &str
, errp
)) {
1095 if (!strcmp(str
, UUID_VALUE_AUTO
)) {
1096 qemu_uuid_generate(uuid
);
1097 } else if (qemu_uuid_parse(str
, uuid
) < 0) {
1098 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
1103 static void set_default_uuid_auto(ObjectProperty
*op
, const Property
*prop
)
1105 object_property_set_default_str(op
, UUID_VALUE_AUTO
);
1108 const PropertyInfo qdev_prop_uuid
= {
1110 .description
= "UUID (aka GUID) or \"" UUID_VALUE_AUTO
1111 "\" for random value (default)",
1114 .set_default_value
= set_default_uuid_auto
,