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
,
41 const GlobalProperty
*prop
= qdev_find_global_prop(obj
, name
);
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;
97 if (!visit_type_str(v
, name
, &str
, errp
)) {
102 * TODO Should this really be an error? If no, the old value
103 * needs to be released before we store the new one.
105 if (!check_prop_still_unset(obj
, name
, *ptr
, str
, errp
)) {
115 blk
= blk_by_name(str
);
117 BlockDriverState
*bs
= bdrv_lookup_bs(NULL
, str
, NULL
);
120 * If the device supports iothreads, it will make sure to move the
121 * block node to the right AioContext if necessary (or fail if this
122 * isn't possible because of other users). Devices that are not
123 * aware of iothreads require their BlockBackends to be in the main
126 AioContext
*ctx
= iothread
? bdrv_get_aio_context(bs
) :
127 qemu_get_aio_context();
128 blk
= blk_new(ctx
, 0, BLK_PERM_ALL
);
131 ret
= blk_insert_bs(blk
, bs
, errp
);
138 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
139 object_get_typename(OBJECT(dev
)), name
, str
);
142 if (blk_attach_dev(blk
, dev
) < 0) {
143 DriveInfo
*dinfo
= blk_legacy_dinfo(blk
);
145 if (dinfo
&& dinfo
->type
!= IF_NONE
) {
146 error_setg(errp
, "Drive '%s' is already in use because "
147 "it has been automatically connected to another "
148 "device (did you need 'if=none' in the drive options?)",
151 error_setg(errp
, "Drive '%s' is already in use by another device",
161 /* If we need to keep a reference, blk_attach_dev() took it */
168 static void set_drive(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
171 set_drive_helper(obj
, v
, name
, opaque
, false, errp
);
174 static void set_drive_iothread(Object
*obj
, Visitor
*v
, const char *name
,
175 void *opaque
, Error
**errp
)
177 set_drive_helper(obj
, v
, name
, opaque
, true, errp
);
180 static void release_drive(Object
*obj
, const char *name
, void *opaque
)
182 DeviceState
*dev
= DEVICE(obj
);
183 Property
*prop
= opaque
;
184 BlockBackend
**ptr
= object_field_prop_ptr(obj
, prop
);
187 AioContext
*ctx
= blk_get_aio_context(*ptr
);
189 aio_context_acquire(ctx
);
190 blockdev_auto_del(*ptr
);
191 blk_detach_dev(*ptr
, dev
);
192 aio_context_release(ctx
);
196 const PropertyInfo qdev_prop_drive
= {
198 .description
= "Node name or ID of a block device to use as a backend",
201 .release
= release_drive
,
204 const PropertyInfo qdev_prop_drive_iothread
= {
206 .description
= "Node name or ID of a block device to use as a backend",
208 .set
= set_drive_iothread
,
209 .release
= release_drive
,
212 /* --- character device --- */
214 static void get_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
217 CharBackend
*be
= object_field_prop_ptr(obj
, opaque
);
220 p
= g_strdup(be
->chr
&& be
->chr
->label
? be
->chr
->label
: "");
221 visit_type_str(v
, name
, &p
, errp
);
225 static void set_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
228 Property
*prop
= opaque
;
229 CharBackend
*be
= object_field_prop_ptr(obj
, prop
);
233 if (!visit_type_str(v
, name
, &str
, errp
)) {
238 * TODO Should this really be an error? If no, the old value
239 * needs to be released before we store the new one.
241 if (!check_prop_still_unset(obj
, name
, be
->chr
, str
, errp
)) {
251 s
= qemu_chr_find(str
);
253 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
254 object_get_typename(obj
), name
, str
);
255 } else if (!qemu_chr_fe_init(be
, s
, errp
)) {
256 error_prepend(errp
, "Property '%s.%s' can't take value '%s': ",
257 object_get_typename(obj
), name
, str
);
262 static void release_chr(Object
*obj
, const char *name
, void *opaque
)
264 Property
*prop
= opaque
;
265 CharBackend
*be
= object_field_prop_ptr(obj
, prop
);
267 qemu_chr_fe_deinit(be
, false);
270 const PropertyInfo qdev_prop_chr
= {
272 .description
= "ID of a chardev to use as a backend",
275 .release
= release_chr
,
278 /* --- mac address --- */
281 * accepted syntax versions:
285 static void get_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
288 Property
*prop
= opaque
;
289 MACAddr
*mac
= object_field_prop_ptr(obj
, prop
);
290 char buffer
[2 * 6 + 5 + 1];
293 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
294 mac
->a
[0], mac
->a
[1], mac
->a
[2],
295 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
297 visit_type_str(v
, name
, &p
, errp
);
300 static void set_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
303 Property
*prop
= opaque
;
304 MACAddr
*mac
= object_field_prop_ptr(obj
, prop
);
309 if (!visit_type_str(v
, name
, &str
, errp
)) {
313 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
316 if (!qemu_isxdigit(str
[pos
])) {
319 if (!qemu_isxdigit(str
[pos
+ 1])) {
323 if (str
[pos
+ 2] != '\0') {
327 if (str
[pos
+ 2] != ':' && str
[pos
+ 2] != '-') {
331 if (qemu_strtol(str
+ pos
, &p
, 16, &val
) < 0 || val
> 0xff) {
340 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
344 const PropertyInfo qdev_prop_macaddr
= {
346 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
351 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
,
352 const uint8_t *value
)
354 char str
[2 * 6 + 5 + 1];
355 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
356 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
358 object_property_set_str(OBJECT(dev
), name
, str
, &error_abort
);
361 /* --- netdev device --- */
362 static void get_netdev(Object
*obj
, Visitor
*v
, const char *name
,
363 void *opaque
, Error
**errp
)
365 Property
*prop
= opaque
;
366 NICPeers
*peers_ptr
= object_field_prop_ptr(obj
, prop
);
367 char *p
= g_strdup(peers_ptr
->ncs
[0] ? peers_ptr
->ncs
[0]->name
: "");
369 visit_type_str(v
, name
, &p
, errp
);
373 static void set_netdev(Object
*obj
, Visitor
*v
, const char *name
,
374 void *opaque
, Error
**errp
)
376 Property
*prop
= opaque
;
377 NICPeers
*peers_ptr
= object_field_prop_ptr(obj
, prop
);
378 NetClientState
**ncs
= peers_ptr
->ncs
;
379 NetClientState
*peers
[MAX_QUEUE_NUM
];
380 int queues
, err
= 0, i
= 0;
383 if (!visit_type_str(v
, name
, &str
, errp
)) {
387 queues
= qemu_find_net_clients_except(str
, peers
,
388 NET_CLIENT_DRIVER_NIC
,
395 if (queues
> MAX_QUEUE_NUM
) {
396 error_setg(errp
, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
397 str
, queues
, MAX_QUEUE_NUM
);
401 for (i
= 0; i
< queues
; i
++) {
402 if (peers
[i
]->peer
) {
408 * TODO Should this really be an error? If no, the old value
409 * needs to be released before we store the new one.
411 if (!check_prop_still_unset(obj
, name
, ncs
[i
], str
, errp
)) {
416 ncs
[i
]->queue_index
= i
;
419 peers_ptr
->queues
= queues
;
422 error_set_from_qdev_prop_error(errp
, err
, obj
, name
, str
);
426 const PropertyInfo qdev_prop_netdev
= {
428 .description
= "ID of a netdev to use as a backend",
434 /* --- audiodev --- */
435 static void get_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
436 void *opaque
, Error
**errp
)
438 Property
*prop
= opaque
;
439 QEMUSoundCard
*card
= object_field_prop_ptr(obj
, prop
);
440 char *p
= g_strdup(audio_get_id(card
));
442 visit_type_str(v
, name
, &p
, errp
);
446 static void set_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
447 void *opaque
, Error
**errp
)
449 Property
*prop
= opaque
;
450 QEMUSoundCard
*card
= object_field_prop_ptr(obj
, prop
);
455 if (!visit_type_str(v
, name
, &str
, errp
)) {
459 state
= audio_state_by_name(str
);
468 error_set_from_qdev_prop_error(errp
, err
, obj
, name
, str
);
472 const PropertyInfo qdev_prop_audiodev
= {
474 .description
= "ID of an audiodev to use as a backend",
475 /* release done on shutdown */
480 bool qdev_prop_set_drive_err(DeviceState
*dev
, const char *name
,
481 BlockBackend
*value
, Error
**errp
)
483 const char *ref
= "";
486 ref
= blk_name(value
);
488 const BlockDriverState
*bs
= blk_bs(value
);
490 ref
= bdrv_get_node_name(bs
);
495 return object_property_set_str(OBJECT(dev
), name
, ref
, errp
);
498 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
501 qdev_prop_set_drive_err(dev
, name
, value
, &error_abort
);
504 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
,
507 assert(!value
|| value
->label
);
508 object_property_set_str(OBJECT(dev
), name
, value
? value
->label
: "",
512 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
,
513 NetClientState
*value
)
515 assert(!value
|| value
->name
);
516 object_property_set_str(OBJECT(dev
), name
, value
? value
->name
: "",
520 void qdev_set_nic_properties(DeviceState
*dev
, NICInfo
*nd
)
522 qdev_prop_set_macaddr(dev
, "mac", nd
->macaddr
.a
);
524 qdev_prop_set_netdev(dev
, "netdev", nd
->netdev
);
526 if (nd
->nvectors
!= DEV_NVECTORS_UNSPECIFIED
&&
527 object_property_find(OBJECT(dev
), "vectors")) {
528 qdev_prop_set_uint32(dev
, "vectors", nd
->nvectors
);
530 nd
->instantiated
= 1;
533 /* --- lost tick policy --- */
535 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
537 const PropertyInfo qdev_prop_losttickpolicy
= {
538 .name
= "LostTickPolicy",
539 .enum_table
= &LostTickPolicy_lookup
,
540 .get
= qdev_propinfo_get_enum
,
541 .set
= qdev_propinfo_set_enum
,
542 .set_default_value
= qdev_propinfo_set_default_value_enum
,
545 /* --- blocksize --- */
547 static void set_blocksize(Object
*obj
, Visitor
*v
, const char *name
,
548 void *opaque
, Error
**errp
)
550 DeviceState
*dev
= DEVICE(obj
);
551 Property
*prop
= opaque
;
552 uint32_t *ptr
= object_field_prop_ptr(obj
, prop
);
554 Error
*local_err
= NULL
;
556 if (!visit_type_size(v
, name
, &value
, errp
)) {
559 check_block_size(dev
->id
? : "", name
, value
, &local_err
);
561 error_propagate(errp
, local_err
);
567 const PropertyInfo qdev_prop_blocksize
= {
569 .description
= "A power of two between " MIN_BLOCK_SIZE_STR
570 " and " MAX_BLOCK_SIZE_STR
,
571 .get
= qdev_propinfo_get_size32
,
572 .set
= set_blocksize
,
573 .set_default_value
= qdev_propinfo_set_default_value_uint
,
576 /* --- Block device error handling policy --- */
578 QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError
) != sizeof(int));
580 const PropertyInfo qdev_prop_blockdev_on_error
= {
581 .name
= "BlockdevOnError",
582 .description
= "Error handling policy, "
583 "report/ignore/enospc/stop/auto",
584 .enum_table
= &BlockdevOnError_lookup
,
585 .get
= qdev_propinfo_get_enum
,
586 .set
= qdev_propinfo_set_enum
,
587 .set_default_value
= qdev_propinfo_set_default_value_enum
,
590 /* --- BIOS CHS translation */
592 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
594 const PropertyInfo qdev_prop_bios_chs_trans
= {
595 .name
= "BiosAtaTranslation",
596 .description
= "Logical CHS translation algorithm, "
597 "auto/none/lba/large/rechs",
598 .enum_table
= &BiosAtaTranslation_lookup
,
599 .get
= qdev_propinfo_get_enum
,
600 .set
= qdev_propinfo_set_enum
,
601 .set_default_value
= qdev_propinfo_set_default_value_enum
,
604 /* --- FDC default drive types */
606 const PropertyInfo qdev_prop_fdc_drive_type
= {
607 .name
= "FdcDriveType",
608 .description
= "FDC drive type, "
609 "144/288/120/none/auto",
610 .enum_table
= &FloppyDriveType_lookup
,
611 .get
= qdev_propinfo_get_enum
,
612 .set
= qdev_propinfo_set_enum
,
613 .set_default_value
= qdev_propinfo_set_default_value_enum
,
616 /* --- MultiFDCompression --- */
618 const PropertyInfo qdev_prop_multifd_compression
= {
619 .name
= "MultiFDCompression",
620 .description
= "multifd_compression values, "
622 .enum_table
= &MultiFDCompression_lookup
,
623 .get
= qdev_propinfo_get_enum
,
624 .set
= qdev_propinfo_set_enum
,
625 .set_default_value
= qdev_propinfo_set_default_value_enum
,
628 /* --- Reserved Region --- */
632 * <low address>:<high address>:<type>
633 * where low/high addresses are uint64_t in hexadecimal
634 * and type is a non-negative decimal integer
636 static void get_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
637 void *opaque
, Error
**errp
)
639 Property
*prop
= opaque
;
640 ReservedRegion
*rr
= object_field_prop_ptr(obj
, prop
);
645 rc
= snprintf(buffer
, sizeof(buffer
), "0x%"PRIx64
":0x%"PRIx64
":%u",
646 rr
->low
, rr
->high
, rr
->type
);
647 assert(rc
< sizeof(buffer
));
649 visit_type_str(v
, name
, &p
, errp
);
652 static void set_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
653 void *opaque
, Error
**errp
)
655 Property
*prop
= opaque
;
656 ReservedRegion
*rr
= object_field_prop_ptr(obj
, prop
);
657 Error
*local_err
= NULL
;
662 visit_type_str(v
, name
, &str
, &local_err
);
664 error_propagate(errp
, local_err
);
668 ret
= qemu_strtou64(str
, &endptr
, 16, &rr
->low
);
670 error_setg(errp
, "start address of '%s'"
671 " must be a hexadecimal integer", name
);
674 if (*endptr
!= ':') {
675 goto separator_error
;
678 ret
= qemu_strtou64(endptr
+ 1, &endptr
, 16, &rr
->high
);
680 error_setg(errp
, "end address of '%s'"
681 " must be a hexadecimal integer", name
);
684 if (*endptr
!= ':') {
685 goto separator_error
;
688 ret
= qemu_strtoui(endptr
+ 1, &endptr
, 10, &rr
->type
);
690 error_setg(errp
, "type of '%s'"
691 " must be a non-negative decimal integer", name
);
696 error_setg(errp
, "reserved region fields must be separated with ':'");
702 const PropertyInfo qdev_prop_reserved_region
= {
703 .name
= "reserved_region",
704 .description
= "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0",
705 .get
= get_reserved_region
,
706 .set
= set_reserved_region
,
709 /* --- pci address --- */
712 * bus-local address, i.e. "$slot" or "$slot.$fn"
714 static void set_pci_devfn(Object
*obj
, Visitor
*v
, const char *name
,
715 void *opaque
, Error
**errp
)
717 Property
*prop
= opaque
;
718 int32_t value
, *ptr
= object_field_prop_ptr(obj
, prop
);
719 unsigned int slot
, fn
, n
;
722 if (!visit_type_str(v
, name
, &str
, NULL
)) {
723 if (!visit_type_int32(v
, name
, &value
, errp
)) {
726 if (value
< -1 || value
> 255) {
727 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
728 name
? name
: "null", "a value between -1 and 255");
735 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
737 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
741 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
744 *ptr
= slot
<< 3 | fn
;
749 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
753 static int print_pci_devfn(Object
*obj
, Property
*prop
, char *dest
,
756 int32_t *ptr
= object_field_prop_ptr(obj
, prop
);
759 return snprintf(dest
, len
, "<unset>");
761 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
765 const PropertyInfo qdev_prop_pci_devfn
= {
767 .description
= "Slot and optional function number, example: 06.0 or 06",
768 .print
= print_pci_devfn
,
769 .get
= qdev_propinfo_get_int32
,
770 .set
= set_pci_devfn
,
771 .set_default_value
= qdev_propinfo_set_default_value_int
,
774 /* --- pci host address --- */
776 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
777 void *opaque
, Error
**errp
)
779 Property
*prop
= opaque
;
780 PCIHostDeviceAddress
*addr
= object_field_prop_ptr(obj
, prop
);
781 char buffer
[] = "ffff:ff:ff.f";
786 * Catch "invalid" device reference from vfio-pci and allow the
787 * default buffer representing the non-existent device to be used.
789 if (~addr
->domain
|| ~addr
->bus
|| ~addr
->slot
|| ~addr
->function
) {
790 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%0d",
791 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
792 assert(rc
== sizeof(buffer
) - 1);
795 visit_type_str(v
, name
, &p
, errp
);
799 * Parse [<domain>:]<bus>:<slot>.<func>
800 * if <domain> is not supplied, it's assumed to be 0.
802 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
803 void *opaque
, Error
**errp
)
805 Property
*prop
= opaque
;
806 PCIHostDeviceAddress
*addr
= object_field_prop_ptr(obj
, prop
);
810 unsigned long dom
= 0, bus
= 0;
811 unsigned int slot
= 0, func
= 0;
813 if (!visit_type_str(v
, name
, &str
, errp
)) {
818 val
= strtoul(p
, &e
, 16);
819 if (e
== p
|| *e
!= ':') {
825 val
= strtoul(p
, &e
, 16);
833 val
= strtoul(p
, &e
, 16);
844 val
= strtoul(p
, &e
, 10);
850 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
861 addr
->function
= func
;
867 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
871 const PropertyInfo qdev_prop_pci_host_devaddr
= {
873 .description
= "Address (bus/device/function) of "
874 "the host device, example: 04:10.0",
875 .get
= get_pci_host_devaddr
,
876 .set
= set_pci_host_devaddr
,
879 /* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */
881 const PropertyInfo qdev_prop_off_auto_pcibar
= {
882 .name
= "OffAutoPCIBAR",
883 .description
= "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
884 .enum_table
= &OffAutoPCIBAR_lookup
,
885 .get
= qdev_propinfo_get_enum
,
886 .set
= qdev_propinfo_set_enum
,
887 .set_default_value
= qdev_propinfo_set_default_value_enum
,
890 /* --- PCIELinkSpeed 2_5/5/8/16 -- */
892 static void get_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
893 void *opaque
, Error
**errp
)
895 Property
*prop
= opaque
;
896 PCIExpLinkSpeed
*p
= object_field_prop_ptr(obj
, prop
);
900 case QEMU_PCI_EXP_LNK_2_5GT
:
901 speed
= PCIE_LINK_SPEED_2_5
;
903 case QEMU_PCI_EXP_LNK_5GT
:
904 speed
= PCIE_LINK_SPEED_5
;
906 case QEMU_PCI_EXP_LNK_8GT
:
907 speed
= PCIE_LINK_SPEED_8
;
909 case QEMU_PCI_EXP_LNK_16GT
:
910 speed
= PCIE_LINK_SPEED_16
;
917 visit_type_enum(v
, name
, &speed
, prop
->info
->enum_table
, errp
);
920 static void set_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
921 void *opaque
, Error
**errp
)
923 Property
*prop
= opaque
;
924 PCIExpLinkSpeed
*p
= object_field_prop_ptr(obj
, prop
);
927 if (!visit_type_enum(v
, name
, &speed
, prop
->info
->enum_table
,
933 case PCIE_LINK_SPEED_2_5
:
934 *p
= QEMU_PCI_EXP_LNK_2_5GT
;
936 case PCIE_LINK_SPEED_5
:
937 *p
= QEMU_PCI_EXP_LNK_5GT
;
939 case PCIE_LINK_SPEED_8
:
940 *p
= QEMU_PCI_EXP_LNK_8GT
;
942 case PCIE_LINK_SPEED_16
:
943 *p
= QEMU_PCI_EXP_LNK_16GT
;
951 const PropertyInfo qdev_prop_pcie_link_speed
= {
952 .name
= "PCIELinkSpeed",
953 .description
= "2_5/5/8/16",
954 .enum_table
= &PCIELinkSpeed_lookup
,
955 .get
= get_prop_pcielinkspeed
,
956 .set
= set_prop_pcielinkspeed
,
957 .set_default_value
= qdev_propinfo_set_default_value_enum
,
960 /* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
962 static void get_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
963 void *opaque
, Error
**errp
)
965 Property
*prop
= opaque
;
966 PCIExpLinkWidth
*p
= object_field_prop_ptr(obj
, prop
);
970 case QEMU_PCI_EXP_LNK_X1
:
971 width
= PCIE_LINK_WIDTH_1
;
973 case QEMU_PCI_EXP_LNK_X2
:
974 width
= PCIE_LINK_WIDTH_2
;
976 case QEMU_PCI_EXP_LNK_X4
:
977 width
= PCIE_LINK_WIDTH_4
;
979 case QEMU_PCI_EXP_LNK_X8
:
980 width
= PCIE_LINK_WIDTH_8
;
982 case QEMU_PCI_EXP_LNK_X12
:
983 width
= PCIE_LINK_WIDTH_12
;
985 case QEMU_PCI_EXP_LNK_X16
:
986 width
= PCIE_LINK_WIDTH_16
;
988 case QEMU_PCI_EXP_LNK_X32
:
989 width
= PCIE_LINK_WIDTH_32
;
996 visit_type_enum(v
, name
, &width
, prop
->info
->enum_table
, errp
);
999 static void set_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
1000 void *opaque
, Error
**errp
)
1002 Property
*prop
= opaque
;
1003 PCIExpLinkWidth
*p
= object_field_prop_ptr(obj
, prop
);
1006 if (!visit_type_enum(v
, name
, &width
, prop
->info
->enum_table
,
1012 case PCIE_LINK_WIDTH_1
:
1013 *p
= QEMU_PCI_EXP_LNK_X1
;
1015 case PCIE_LINK_WIDTH_2
:
1016 *p
= QEMU_PCI_EXP_LNK_X2
;
1018 case PCIE_LINK_WIDTH_4
:
1019 *p
= QEMU_PCI_EXP_LNK_X4
;
1021 case PCIE_LINK_WIDTH_8
:
1022 *p
= QEMU_PCI_EXP_LNK_X8
;
1024 case PCIE_LINK_WIDTH_12
:
1025 *p
= QEMU_PCI_EXP_LNK_X12
;
1027 case PCIE_LINK_WIDTH_16
:
1028 *p
= QEMU_PCI_EXP_LNK_X16
;
1030 case PCIE_LINK_WIDTH_32
:
1031 *p
= QEMU_PCI_EXP_LNK_X32
;
1039 const PropertyInfo qdev_prop_pcie_link_width
= {
1040 .name
= "PCIELinkWidth",
1041 .description
= "1/2/4/8/12/16/32",
1042 .enum_table
= &PCIELinkWidth_lookup
,
1043 .get
= get_prop_pcielinkwidth
,
1044 .set
= set_prop_pcielinkwidth
,
1045 .set_default_value
= qdev_propinfo_set_default_value_enum
,
1050 static void get_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1053 Property
*prop
= opaque
;
1054 QemuUUID
*uuid
= object_field_prop_ptr(obj
, prop
);
1055 char buffer
[UUID_FMT_LEN
+ 1];
1058 qemu_uuid_unparse(uuid
, buffer
);
1060 visit_type_str(v
, name
, &p
, errp
);
1063 #define UUID_VALUE_AUTO "auto"
1065 static void set_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1068 Property
*prop
= opaque
;
1069 QemuUUID
*uuid
= object_field_prop_ptr(obj
, prop
);
1072 if (!visit_type_str(v
, name
, &str
, errp
)) {
1076 if (!strcmp(str
, UUID_VALUE_AUTO
)) {
1077 qemu_uuid_generate(uuid
);
1078 } else if (qemu_uuid_parse(str
, uuid
) < 0) {
1079 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
1084 static void set_default_uuid_auto(ObjectProperty
*op
, const Property
*prop
)
1086 object_property_set_default_str(op
, UUID_VALUE_AUTO
);
1089 const PropertyInfo qdev_prop_uuid
= {
1091 .description
= "UUID (aka GUID) or \"" UUID_VALUE_AUTO
1092 "\" for random value (default)",
1095 .set_default_value
= set_default_uuid_auto
,