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 "qapi/error.h"
16 #include "qapi/visitor.h"
17 #include "qapi/qapi-types-block.h"
18 #include "qapi/qapi-types-machine.h"
19 #include "qapi/qapi-types-migration.h"
20 #include "qapi/qmp/qerror.h"
21 #include "qemu/ctype.h"
22 #include "qemu/cutils.h"
23 #include "qemu/units.h"
24 #include "qemu/uuid.h"
25 #include "qemu/error-report.h"
26 #include "qdev-prop-internal.h"
28 #include "audio/audio.h"
29 #include "chardev/char-fe.h"
30 #include "sysemu/block-backend.h"
31 #include "sysemu/blockdev.h"
33 #include "hw/pci/pci.h"
34 #include "util/block-helpers.h"
36 static bool check_prop_still_unset(Object
*obj
, const char *name
,
37 const void *old_val
, const char *new_val
,
40 const GlobalProperty
*prop
= qdev_find_global_prop(obj
, name
);
47 error_setg(errp
, "-global %s.%s=... conflicts with %s=%s",
48 prop
->driver
, prop
->property
, name
, new_val
);
50 /* Error message is vague, but a better one would be hard */
51 error_setg(errp
, "%s=%s conflicts, and override is not implemented",
60 static void get_drive(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
63 Property
*prop
= opaque
;
64 void **ptr
= qdev_get_prop_ptr(obj
, prop
);
69 value
= blk_name(*ptr
);
71 BlockDriverState
*bs
= blk_bs(*ptr
);
73 value
= bdrv_get_node_name(bs
);
81 visit_type_str(v
, name
, &p
, errp
);
85 static void set_drive_helper(Object
*obj
, Visitor
*v
, const char *name
,
86 void *opaque
, bool iothread
, Error
**errp
)
88 DeviceState
*dev
= DEVICE(obj
);
89 Property
*prop
= opaque
;
90 void **ptr
= qdev_get_prop_ptr(obj
, prop
);
93 bool blk_created
= false;
97 qdev_prop_set_after_realize(dev
, name
, errp
);
101 if (!visit_type_str(v
, name
, &str
, errp
)) {
106 * TODO Should this really be an error? If no, the old value
107 * needs to be released before we store the new one.
109 if (!check_prop_still_unset(obj
, name
, *ptr
, str
, errp
)) {
119 blk
= blk_by_name(str
);
121 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, str
, NULL
);
124 * If the device supports iothreads, it will make sure to move the
125 * block node to the right AioContext if necessary (or fail if this
126 * isn't possible because of other users). Devices that are not
127 * aware of iothreads require their BlockBackends to be in the main
130 AioContext
*ctx
= iothread
? bdrv_get_aio_context(bs
) :
131 qemu_get_aio_context();
132 blk
= blk_new(ctx
, 0, BLK_PERM_ALL
);
135 ret
= blk_insert_bs(blk
, bs
, errp
);
142 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
143 object_get_typename(OBJECT(dev
)), prop
->name
, str
);
146 if (blk_attach_dev(blk
, dev
) < 0) {
147 DriveInfo
*dinfo
= blk_legacy_dinfo(blk
);
149 if (dinfo
&& dinfo
->type
!= IF_NONE
) {
150 error_setg(errp
, "Drive '%s' is already in use because "
151 "it has been automatically connected to another "
152 "device (did you need 'if=none' in the drive options?)",
155 error_setg(errp
, "Drive '%s' is already in use by another device",
165 /* If we need to keep a reference, blk_attach_dev() took it */
172 static void set_drive(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
175 set_drive_helper(obj
, v
, name
, opaque
, false, errp
);
178 static void set_drive_iothread(Object
*obj
, Visitor
*v
, const char *name
,
179 void *opaque
, Error
**errp
)
181 set_drive_helper(obj
, v
, name
, opaque
, true, errp
);
184 static void release_drive(Object
*obj
, const char *name
, void *opaque
)
186 DeviceState
*dev
= DEVICE(obj
);
187 Property
*prop
= opaque
;
188 BlockBackend
**ptr
= qdev_get_prop_ptr(obj
, prop
);
191 AioContext
*ctx
= blk_get_aio_context(*ptr
);
193 aio_context_acquire(ctx
);
194 blockdev_auto_del(*ptr
);
195 blk_detach_dev(*ptr
, dev
);
196 aio_context_release(ctx
);
200 const PropertyInfo qdev_prop_drive
= {
202 .description
= "Node name or ID of a block device to use as a backend",
205 .release
= release_drive
,
208 const PropertyInfo qdev_prop_drive_iothread
= {
210 .description
= "Node name or ID of a block device to use as a backend",
212 .set
= set_drive_iothread
,
213 .release
= release_drive
,
216 /* --- character device --- */
218 static void get_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
221 CharBackend
*be
= qdev_get_prop_ptr(obj
, opaque
);
224 p
= g_strdup(be
->chr
&& be
->chr
->label
? be
->chr
->label
: "");
225 visit_type_str(v
, name
, &p
, errp
);
229 static void set_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
232 DeviceState
*dev
= DEVICE(obj
);
233 Property
*prop
= opaque
;
234 CharBackend
*be
= qdev_get_prop_ptr(obj
, prop
);
239 qdev_prop_set_after_realize(dev
, name
, errp
);
243 if (!visit_type_str(v
, name
, &str
, errp
)) {
248 * TODO Should this really be an error? If no, the old value
249 * needs to be released before we store the new one.
251 if (!check_prop_still_unset(obj
, name
, be
->chr
, str
, errp
)) {
261 s
= qemu_chr_find(str
);
263 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
264 object_get_typename(obj
), prop
->name
, str
);
265 } else if (!qemu_chr_fe_init(be
, s
, errp
)) {
266 error_prepend(errp
, "Property '%s.%s' can't take value '%s': ",
267 object_get_typename(obj
), prop
->name
, str
);
272 static void release_chr(Object
*obj
, const char *name
, void *opaque
)
274 Property
*prop
= opaque
;
275 CharBackend
*be
= qdev_get_prop_ptr(obj
, prop
);
277 qemu_chr_fe_deinit(be
, false);
280 const PropertyInfo qdev_prop_chr
= {
282 .description
= "ID of a chardev to use as a backend",
285 .release
= release_chr
,
288 /* --- mac address --- */
291 * accepted syntax versions:
295 static void get_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
298 Property
*prop
= opaque
;
299 MACAddr
*mac
= qdev_get_prop_ptr(obj
, prop
);
300 char buffer
[2 * 6 + 5 + 1];
303 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
304 mac
->a
[0], mac
->a
[1], mac
->a
[2],
305 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
307 visit_type_str(v
, name
, &p
, errp
);
310 static void set_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
313 DeviceState
*dev
= DEVICE(obj
);
314 Property
*prop
= opaque
;
315 MACAddr
*mac
= qdev_get_prop_ptr(obj
, prop
);
321 qdev_prop_set_after_realize(dev
, name
, errp
);
325 if (!visit_type_str(v
, name
, &str
, errp
)) {
329 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
332 if (!qemu_isxdigit(str
[pos
])) {
335 if (!qemu_isxdigit(str
[pos
+ 1])) {
339 if (str
[pos
+ 2] != '\0') {
343 if (str
[pos
+ 2] != ':' && str
[pos
+ 2] != '-') {
347 if (qemu_strtol(str
+ pos
, &p
, 16, &val
) < 0 || val
> 0xff) {
356 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, prop
, str
);
360 const PropertyInfo qdev_prop_macaddr
= {
362 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
367 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
,
368 const uint8_t *value
)
370 char str
[2 * 6 + 5 + 1];
371 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
372 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
374 object_property_set_str(OBJECT(dev
), name
, str
, &error_abort
);
377 /* --- netdev device --- */
378 static void get_netdev(Object
*obj
, Visitor
*v
, const char *name
,
379 void *opaque
, Error
**errp
)
381 Property
*prop
= opaque
;
382 NICPeers
*peers_ptr
= qdev_get_prop_ptr(obj
, prop
);
383 char *p
= g_strdup(peers_ptr
->ncs
[0] ? peers_ptr
->ncs
[0]->name
: "");
385 visit_type_str(v
, name
, &p
, errp
);
389 static void set_netdev(Object
*obj
, Visitor
*v
, const char *name
,
390 void *opaque
, Error
**errp
)
392 DeviceState
*dev
= DEVICE(obj
);
393 Property
*prop
= opaque
;
394 NICPeers
*peers_ptr
= qdev_get_prop_ptr(obj
, prop
);
395 NetClientState
**ncs
= peers_ptr
->ncs
;
396 NetClientState
*peers
[MAX_QUEUE_NUM
];
397 int queues
, err
= 0, i
= 0;
401 qdev_prop_set_after_realize(dev
, name
, errp
);
405 if (!visit_type_str(v
, name
, &str
, errp
)) {
409 queues
= qemu_find_net_clients_except(str
, peers
,
410 NET_CLIENT_DRIVER_NIC
,
417 if (queues
> MAX_QUEUE_NUM
) {
418 error_setg(errp
, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
419 str
, queues
, MAX_QUEUE_NUM
);
423 for (i
= 0; i
< queues
; i
++) {
424 if (peers
[i
]->peer
) {
430 * TODO Should this really be an error? If no, the old value
431 * needs to be released before we store the new one.
433 if (!check_prop_still_unset(obj
, name
, ncs
[i
], str
, errp
)) {
438 ncs
[i
]->queue_index
= i
;
441 peers_ptr
->queues
= queues
;
444 error_set_from_qdev_prop_error(errp
, err
, obj
, prop
, str
);
448 const PropertyInfo qdev_prop_netdev
= {
450 .description
= "ID of a netdev to use as a backend",
456 /* --- audiodev --- */
457 static void get_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
458 void *opaque
, Error
**errp
)
460 Property
*prop
= opaque
;
461 QEMUSoundCard
*card
= qdev_get_prop_ptr(obj
, prop
);
462 char *p
= g_strdup(audio_get_id(card
));
464 visit_type_str(v
, name
, &p
, errp
);
468 static void set_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
469 void *opaque
, Error
**errp
)
471 DeviceState
*dev
= DEVICE(obj
);
472 Property
*prop
= opaque
;
473 QEMUSoundCard
*card
= qdev_get_prop_ptr(obj
, prop
);
479 qdev_prop_set_after_realize(dev
, name
, errp
);
483 if (!visit_type_str(v
, name
, &str
, errp
)) {
487 state
= audio_state_by_name(str
);
496 error_set_from_qdev_prop_error(errp
, err
, obj
, prop
, str
);
500 const PropertyInfo qdev_prop_audiodev
= {
502 .description
= "ID of an audiodev to use as a backend",
503 /* release done on shutdown */
508 bool qdev_prop_set_drive_err(DeviceState
*dev
, const char *name
,
509 BlockBackend
*value
, Error
**errp
)
511 const char *ref
= "";
514 ref
= blk_name(value
);
516 const BlockDriverState
*bs
= blk_bs(value
);
518 ref
= bdrv_get_node_name(bs
);
523 return object_property_set_str(OBJECT(dev
), name
, ref
, errp
);
526 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
529 qdev_prop_set_drive_err(dev
, name
, value
, &error_abort
);
532 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
,
535 assert(!value
|| value
->label
);
536 object_property_set_str(OBJECT(dev
), name
, value
? value
->label
: "",
540 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
,
541 NetClientState
*value
)
543 assert(!value
|| value
->name
);
544 object_property_set_str(OBJECT(dev
), name
, value
? value
->name
: "",
548 void qdev_set_nic_properties(DeviceState
*dev
, NICInfo
*nd
)
550 qdev_prop_set_macaddr(dev
, "mac", nd
->macaddr
.a
);
552 qdev_prop_set_netdev(dev
, "netdev", nd
->netdev
);
554 if (nd
->nvectors
!= DEV_NVECTORS_UNSPECIFIED
&&
555 object_property_find(OBJECT(dev
), "vectors")) {
556 qdev_prop_set_uint32(dev
, "vectors", nd
->nvectors
);
558 nd
->instantiated
= 1;
561 /* --- lost tick policy --- */
563 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
565 const PropertyInfo qdev_prop_losttickpolicy
= {
566 .name
= "LostTickPolicy",
567 .enum_table
= &LostTickPolicy_lookup
,
568 .get
= qdev_propinfo_get_enum
,
569 .set
= qdev_propinfo_set_enum
,
570 .set_default_value
= qdev_propinfo_set_default_value_enum
,
573 /* --- blocksize --- */
575 static void set_blocksize(Object
*obj
, Visitor
*v
, const char *name
,
576 void *opaque
, Error
**errp
)
578 DeviceState
*dev
= DEVICE(obj
);
579 Property
*prop
= opaque
;
580 uint32_t *ptr
= qdev_get_prop_ptr(obj
, prop
);
582 Error
*local_err
= NULL
;
585 qdev_prop_set_after_realize(dev
, name
, errp
);
589 if (!visit_type_size(v
, name
, &value
, errp
)) {
592 check_block_size(dev
->id
? : "", name
, value
, &local_err
);
594 error_propagate(errp
, local_err
);
600 const PropertyInfo qdev_prop_blocksize
= {
602 .description
= "A power of two between " MIN_BLOCK_SIZE_STR
603 " and " MAX_BLOCK_SIZE_STR
,
604 .get
= qdev_propinfo_get_size32
,
605 .set
= set_blocksize
,
606 .set_default_value
= qdev_propinfo_set_default_value_uint
,
609 /* --- Block device error handling policy --- */
611 QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError
) != sizeof(int));
613 const PropertyInfo qdev_prop_blockdev_on_error
= {
614 .name
= "BlockdevOnError",
615 .description
= "Error handling policy, "
616 "report/ignore/enospc/stop/auto",
617 .enum_table
= &BlockdevOnError_lookup
,
618 .get
= qdev_propinfo_get_enum
,
619 .set
= qdev_propinfo_set_enum
,
620 .set_default_value
= qdev_propinfo_set_default_value_enum
,
623 /* --- BIOS CHS translation */
625 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
627 const PropertyInfo qdev_prop_bios_chs_trans
= {
628 .name
= "BiosAtaTranslation",
629 .description
= "Logical CHS translation algorithm, "
630 "auto/none/lba/large/rechs",
631 .enum_table
= &BiosAtaTranslation_lookup
,
632 .get
= qdev_propinfo_get_enum
,
633 .set
= qdev_propinfo_set_enum
,
634 .set_default_value
= qdev_propinfo_set_default_value_enum
,
637 /* --- FDC default drive types */
639 const PropertyInfo qdev_prop_fdc_drive_type
= {
640 .name
= "FdcDriveType",
641 .description
= "FDC drive type, "
642 "144/288/120/none/auto",
643 .enum_table
= &FloppyDriveType_lookup
,
644 .get
= qdev_propinfo_get_enum
,
645 .set
= qdev_propinfo_set_enum
,
646 .set_default_value
= qdev_propinfo_set_default_value_enum
,
649 /* --- MultiFDCompression --- */
651 const PropertyInfo qdev_prop_multifd_compression
= {
652 .name
= "MultiFDCompression",
653 .description
= "multifd_compression values, "
655 .enum_table
= &MultiFDCompression_lookup
,
656 .get
= qdev_propinfo_get_enum
,
657 .set
= qdev_propinfo_set_enum
,
658 .set_default_value
= qdev_propinfo_set_default_value_enum
,
661 /* --- Reserved Region --- */
665 * <low address>:<high address>:<type>
666 * where low/high addresses are uint64_t in hexadecimal
667 * and type is a non-negative decimal integer
669 static void get_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
670 void *opaque
, Error
**errp
)
672 Property
*prop
= opaque
;
673 ReservedRegion
*rr
= qdev_get_prop_ptr(obj
, prop
);
678 rc
= snprintf(buffer
, sizeof(buffer
), "0x%"PRIx64
":0x%"PRIx64
":%u",
679 rr
->low
, rr
->high
, rr
->type
);
680 assert(rc
< sizeof(buffer
));
682 visit_type_str(v
, name
, &p
, errp
);
685 static void set_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
686 void *opaque
, Error
**errp
)
688 DeviceState
*dev
= DEVICE(obj
);
689 Property
*prop
= opaque
;
690 ReservedRegion
*rr
= qdev_get_prop_ptr(obj
, prop
);
691 Error
*local_err
= NULL
;
697 qdev_prop_set_after_realize(dev
, name
, errp
);
701 visit_type_str(v
, name
, &str
, &local_err
);
703 error_propagate(errp
, local_err
);
707 ret
= qemu_strtou64(str
, &endptr
, 16, &rr
->low
);
709 error_setg(errp
, "start address of '%s'"
710 " must be a hexadecimal integer", name
);
713 if (*endptr
!= ':') {
714 goto separator_error
;
717 ret
= qemu_strtou64(endptr
+ 1, &endptr
, 16, &rr
->high
);
719 error_setg(errp
, "end address of '%s'"
720 " must be a hexadecimal integer", name
);
723 if (*endptr
!= ':') {
724 goto separator_error
;
727 ret
= qemu_strtoui(endptr
+ 1, &endptr
, 10, &rr
->type
);
729 error_setg(errp
, "type of '%s'"
730 " must be a non-negative decimal integer", name
);
735 error_setg(errp
, "reserved region fields must be separated with ':'");
741 const PropertyInfo qdev_prop_reserved_region
= {
742 .name
= "reserved_region",
743 .description
= "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0",
744 .get
= get_reserved_region
,
745 .set
= set_reserved_region
,
748 /* --- pci address --- */
751 * bus-local address, i.e. "$slot" or "$slot.$fn"
753 static void set_pci_devfn(Object
*obj
, Visitor
*v
, const char *name
,
754 void *opaque
, Error
**errp
)
756 DeviceState
*dev
= DEVICE(obj
);
757 Property
*prop
= opaque
;
758 int32_t value
, *ptr
= qdev_get_prop_ptr(obj
, prop
);
759 unsigned int slot
, fn
, n
;
763 qdev_prop_set_after_realize(dev
, name
, errp
);
767 if (!visit_type_str(v
, name
, &str
, NULL
)) {
768 if (!visit_type_int32(v
, name
, &value
, errp
)) {
771 if (value
< -1 || value
> 255) {
772 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
773 name
? name
: "null", "a value between -1 and 255");
780 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
782 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
786 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
789 *ptr
= slot
<< 3 | fn
;
794 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, prop
, str
);
798 static int print_pci_devfn(Object
*obj
, Property
*prop
, char *dest
,
801 int32_t *ptr
= qdev_get_prop_ptr(obj
, prop
);
804 return snprintf(dest
, len
, "<unset>");
806 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
810 const PropertyInfo qdev_prop_pci_devfn
= {
812 .description
= "Slot and optional function number, example: 06.0 or 06",
813 .print
= print_pci_devfn
,
814 .get
= qdev_propinfo_get_int32
,
815 .set
= set_pci_devfn
,
816 .set_default_value
= qdev_propinfo_set_default_value_int
,
819 /* --- pci host address --- */
821 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
822 void *opaque
, Error
**errp
)
824 Property
*prop
= opaque
;
825 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(obj
, prop
);
826 char buffer
[] = "ffff:ff:ff.f";
831 * Catch "invalid" device reference from vfio-pci and allow the
832 * default buffer representing the non-existent device to be used.
834 if (~addr
->domain
|| ~addr
->bus
|| ~addr
->slot
|| ~addr
->function
) {
835 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%0d",
836 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
837 assert(rc
== sizeof(buffer
) - 1);
840 visit_type_str(v
, name
, &p
, errp
);
844 * Parse [<domain>:]<bus>:<slot>.<func>
845 * if <domain> is not supplied, it's assumed to be 0.
847 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
848 void *opaque
, Error
**errp
)
850 DeviceState
*dev
= DEVICE(obj
);
851 Property
*prop
= opaque
;
852 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(obj
, prop
);
856 unsigned long dom
= 0, bus
= 0;
857 unsigned int slot
= 0, func
= 0;
860 qdev_prop_set_after_realize(dev
, name
, errp
);
864 if (!visit_type_str(v
, name
, &str
, errp
)) {
869 val
= strtoul(p
, &e
, 16);
870 if (e
== p
|| *e
!= ':') {
876 val
= strtoul(p
, &e
, 16);
884 val
= strtoul(p
, &e
, 16);
895 val
= strtoul(p
, &e
, 10);
901 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
912 addr
->function
= func
;
918 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, prop
, str
);
922 const PropertyInfo qdev_prop_pci_host_devaddr
= {
924 .description
= "Address (bus/device/function) of "
925 "the host device, example: 04:10.0",
926 .get
= get_pci_host_devaddr
,
927 .set
= set_pci_host_devaddr
,
930 /* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */
932 const PropertyInfo qdev_prop_off_auto_pcibar
= {
933 .name
= "OffAutoPCIBAR",
934 .description
= "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
935 .enum_table
= &OffAutoPCIBAR_lookup
,
936 .get
= qdev_propinfo_get_enum
,
937 .set
= qdev_propinfo_set_enum
,
938 .set_default_value
= qdev_propinfo_set_default_value_enum
,
941 /* --- PCIELinkSpeed 2_5/5/8/16 -- */
943 static void get_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
944 void *opaque
, Error
**errp
)
946 Property
*prop
= opaque
;
947 PCIExpLinkSpeed
*p
= qdev_get_prop_ptr(obj
, prop
);
951 case QEMU_PCI_EXP_LNK_2_5GT
:
952 speed
= PCIE_LINK_SPEED_2_5
;
954 case QEMU_PCI_EXP_LNK_5GT
:
955 speed
= PCIE_LINK_SPEED_5
;
957 case QEMU_PCI_EXP_LNK_8GT
:
958 speed
= PCIE_LINK_SPEED_8
;
960 case QEMU_PCI_EXP_LNK_16GT
:
961 speed
= PCIE_LINK_SPEED_16
;
968 visit_type_enum(v
, prop
->name
, &speed
, prop
->info
->enum_table
, errp
);
971 static void set_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
972 void *opaque
, Error
**errp
)
974 DeviceState
*dev
= DEVICE(obj
);
975 Property
*prop
= opaque
;
976 PCIExpLinkSpeed
*p
= qdev_get_prop_ptr(obj
, prop
);
980 qdev_prop_set_after_realize(dev
, name
, errp
);
984 if (!visit_type_enum(v
, prop
->name
, &speed
, prop
->info
->enum_table
,
990 case PCIE_LINK_SPEED_2_5
:
991 *p
= QEMU_PCI_EXP_LNK_2_5GT
;
993 case PCIE_LINK_SPEED_5
:
994 *p
= QEMU_PCI_EXP_LNK_5GT
;
996 case PCIE_LINK_SPEED_8
:
997 *p
= QEMU_PCI_EXP_LNK_8GT
;
999 case PCIE_LINK_SPEED_16
:
1000 *p
= QEMU_PCI_EXP_LNK_16GT
;
1008 const PropertyInfo qdev_prop_pcie_link_speed
= {
1009 .name
= "PCIELinkSpeed",
1010 .description
= "2_5/5/8/16",
1011 .enum_table
= &PCIELinkSpeed_lookup
,
1012 .get
= get_prop_pcielinkspeed
,
1013 .set
= set_prop_pcielinkspeed
,
1014 .set_default_value
= qdev_propinfo_set_default_value_enum
,
1017 /* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
1019 static void get_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
1020 void *opaque
, Error
**errp
)
1022 Property
*prop
= opaque
;
1023 PCIExpLinkWidth
*p
= qdev_get_prop_ptr(obj
, prop
);
1027 case QEMU_PCI_EXP_LNK_X1
:
1028 width
= PCIE_LINK_WIDTH_1
;
1030 case QEMU_PCI_EXP_LNK_X2
:
1031 width
= PCIE_LINK_WIDTH_2
;
1033 case QEMU_PCI_EXP_LNK_X4
:
1034 width
= PCIE_LINK_WIDTH_4
;
1036 case QEMU_PCI_EXP_LNK_X8
:
1037 width
= PCIE_LINK_WIDTH_8
;
1039 case QEMU_PCI_EXP_LNK_X12
:
1040 width
= PCIE_LINK_WIDTH_12
;
1042 case QEMU_PCI_EXP_LNK_X16
:
1043 width
= PCIE_LINK_WIDTH_16
;
1045 case QEMU_PCI_EXP_LNK_X32
:
1046 width
= PCIE_LINK_WIDTH_32
;
1053 visit_type_enum(v
, prop
->name
, &width
, prop
->info
->enum_table
, errp
);
1056 static void set_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
1057 void *opaque
, Error
**errp
)
1059 DeviceState
*dev
= DEVICE(obj
);
1060 Property
*prop
= opaque
;
1061 PCIExpLinkWidth
*p
= qdev_get_prop_ptr(obj
, prop
);
1064 if (dev
->realized
) {
1065 qdev_prop_set_after_realize(dev
, name
, errp
);
1069 if (!visit_type_enum(v
, prop
->name
, &width
, prop
->info
->enum_table
,
1075 case PCIE_LINK_WIDTH_1
:
1076 *p
= QEMU_PCI_EXP_LNK_X1
;
1078 case PCIE_LINK_WIDTH_2
:
1079 *p
= QEMU_PCI_EXP_LNK_X2
;
1081 case PCIE_LINK_WIDTH_4
:
1082 *p
= QEMU_PCI_EXP_LNK_X4
;
1084 case PCIE_LINK_WIDTH_8
:
1085 *p
= QEMU_PCI_EXP_LNK_X8
;
1087 case PCIE_LINK_WIDTH_12
:
1088 *p
= QEMU_PCI_EXP_LNK_X12
;
1090 case PCIE_LINK_WIDTH_16
:
1091 *p
= QEMU_PCI_EXP_LNK_X16
;
1093 case PCIE_LINK_WIDTH_32
:
1094 *p
= QEMU_PCI_EXP_LNK_X32
;
1102 const PropertyInfo qdev_prop_pcie_link_width
= {
1103 .name
= "PCIELinkWidth",
1104 .description
= "1/2/4/8/12/16/32",
1105 .enum_table
= &PCIELinkWidth_lookup
,
1106 .get
= get_prop_pcielinkwidth
,
1107 .set
= set_prop_pcielinkwidth
,
1108 .set_default_value
= qdev_propinfo_set_default_value_enum
,
1113 static void get_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1116 Property
*prop
= opaque
;
1117 QemuUUID
*uuid
= qdev_get_prop_ptr(obj
, prop
);
1118 char buffer
[UUID_FMT_LEN
+ 1];
1121 qemu_uuid_unparse(uuid
, buffer
);
1123 visit_type_str(v
, name
, &p
, errp
);
1126 #define UUID_VALUE_AUTO "auto"
1128 static void set_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1131 DeviceState
*dev
= DEVICE(obj
);
1132 Property
*prop
= opaque
;
1133 QemuUUID
*uuid
= qdev_get_prop_ptr(obj
, prop
);
1136 if (dev
->realized
) {
1137 qdev_prop_set_after_realize(dev
, name
, errp
);
1141 if (!visit_type_str(v
, name
, &str
, errp
)) {
1145 if (!strcmp(str
, UUID_VALUE_AUTO
)) {
1146 qemu_uuid_generate(uuid
);
1147 } else if (qemu_uuid_parse(str
, uuid
) < 0) {
1148 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, prop
, str
);
1153 static void set_default_uuid_auto(ObjectProperty
*op
, const Property
*prop
)
1155 object_property_set_default_str(op
, UUID_VALUE_AUTO
);
1158 const PropertyInfo qdev_prop_uuid
= {
1160 .description
= "UUID (aka GUID) or \"" UUID_VALUE_AUTO
1161 "\" for random value (default)",
1164 .set_default_value
= set_default_uuid_auto
,