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 "hw/pci/pcie.h"
36 #include "hw/i386/x86.h"
37 #include "util/block-helpers.h"
39 static bool check_prop_still_unset(Object
*obj
, const char *name
,
40 const void *old_val
, const char *new_val
,
41 bool allow_override
, Error
**errp
)
43 const GlobalProperty
*prop
= qdev_find_global_prop(obj
, name
);
45 if (!old_val
|| (!prop
&& allow_override
)) {
50 error_setg(errp
, "-global %s.%s=... conflicts with %s=%s",
51 prop
->driver
, prop
->property
, name
, new_val
);
53 /* Error message is vague, but a better one would be hard */
54 error_setg(errp
, "%s=%s conflicts, and override is not implemented",
63 static void get_drive(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
66 Property
*prop
= opaque
;
67 void **ptr
= object_field_prop_ptr(obj
, prop
);
72 value
= blk_name(*ptr
);
74 BlockDriverState
*bs
= blk_bs(*ptr
);
76 value
= bdrv_get_node_name(bs
);
84 visit_type_str(v
, name
, &p
, errp
);
88 static void set_drive_helper(Object
*obj
, Visitor
*v
, const char *name
,
89 void *opaque
, bool iothread
, Error
**errp
)
91 DeviceState
*dev
= DEVICE(obj
);
92 Property
*prop
= opaque
;
93 void **ptr
= object_field_prop_ptr(obj
, prop
);
96 bool blk_created
= false;
101 if (!visit_type_str(v
, name
, &str
, errp
)) {
105 if (!check_prop_still_unset(obj
, name
, *ptr
, str
, true, errp
)) {
110 /* BlockBackend alread exists. So, we want to change attached node */
112 ctx
= blk_get_aio_context(blk
);
113 bs
= bdrv_lookup_bs(NULL
, str
, errp
);
118 if (ctx
!= bdrv_get_aio_context(bs
)) {
119 error_setg(errp
, "Different aio context is not supported for new "
123 aio_context_acquire(ctx
);
124 blk_replace_bs(blk
, bs
, errp
);
125 aio_context_release(ctx
);
135 blk
= blk_by_name(str
);
137 bs
= bdrv_lookup_bs(NULL
, str
, NULL
);
140 * If the device supports iothreads, it will make sure to move the
141 * block node to the right AioContext if necessary (or fail if this
142 * isn't possible because of other users). Devices that are not
143 * aware of iothreads require their BlockBackends to be in the main
146 ctx
= iothread
? bdrv_get_aio_context(bs
) : qemu_get_aio_context();
147 blk
= blk_new(ctx
, 0, BLK_PERM_ALL
);
150 ret
= blk_insert_bs(blk
, bs
, errp
);
157 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
158 object_get_typename(OBJECT(dev
)), name
, str
);
161 if (blk_attach_dev(blk
, dev
) < 0) {
162 DriveInfo
*dinfo
= blk_legacy_dinfo(blk
);
164 if (dinfo
&& dinfo
->type
!= IF_NONE
) {
165 error_setg(errp
, "Drive '%s' is already in use because "
166 "it has been automatically connected to another "
167 "device (did you need 'if=none' in the drive options?)",
170 error_setg(errp
, "Drive '%s' is already in use by another device",
180 /* If we need to keep a reference, blk_attach_dev() took it */
187 static void set_drive(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
190 set_drive_helper(obj
, v
, name
, opaque
, false, errp
);
193 static void set_drive_iothread(Object
*obj
, Visitor
*v
, const char *name
,
194 void *opaque
, Error
**errp
)
196 set_drive_helper(obj
, v
, name
, opaque
, true, errp
);
199 static void release_drive(Object
*obj
, const char *name
, void *opaque
)
201 DeviceState
*dev
= DEVICE(obj
);
202 Property
*prop
= opaque
;
203 BlockBackend
**ptr
= object_field_prop_ptr(obj
, prop
);
206 AioContext
*ctx
= blk_get_aio_context(*ptr
);
208 aio_context_acquire(ctx
);
209 blockdev_auto_del(*ptr
);
210 blk_detach_dev(*ptr
, dev
);
211 aio_context_release(ctx
);
215 const PropertyInfo qdev_prop_drive
= {
217 .description
= "Node name or ID of a block device to use as a backend",
218 .realized_set_allowed
= true,
221 .release
= release_drive
,
224 const PropertyInfo qdev_prop_drive_iothread
= {
226 .description
= "Node name or ID of a block device to use as a backend",
227 .realized_set_allowed
= true,
229 .set
= set_drive_iothread
,
230 .release
= release_drive
,
233 /* --- character device --- */
235 static void get_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
238 CharBackend
*be
= object_field_prop_ptr(obj
, opaque
);
241 p
= g_strdup(be
->chr
&& be
->chr
->label
? be
->chr
->label
: "");
242 visit_type_str(v
, name
, &p
, errp
);
246 static void set_chr(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
249 Property
*prop
= opaque
;
250 CharBackend
*be
= object_field_prop_ptr(obj
, prop
);
254 if (!visit_type_str(v
, name
, &str
, errp
)) {
259 * TODO Should this really be an error? If no, the old value
260 * needs to be released before we store the new one.
262 if (!check_prop_still_unset(obj
, name
, be
->chr
, str
, false, errp
)) {
272 s
= qemu_chr_find(str
);
274 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
275 object_get_typename(obj
), name
, str
);
276 } else if (!qemu_chr_fe_init(be
, s
, errp
)) {
277 error_prepend(errp
, "Property '%s.%s' can't take value '%s': ",
278 object_get_typename(obj
), name
, str
);
283 static void release_chr(Object
*obj
, const char *name
, void *opaque
)
285 Property
*prop
= opaque
;
286 CharBackend
*be
= object_field_prop_ptr(obj
, prop
);
288 qemu_chr_fe_deinit(be
, false);
291 const PropertyInfo qdev_prop_chr
= {
293 .description
= "ID of a chardev to use as a backend",
296 .release
= release_chr
,
299 /* --- mac address --- */
302 * accepted syntax versions:
306 static void get_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
309 Property
*prop
= opaque
;
310 MACAddr
*mac
= object_field_prop_ptr(obj
, prop
);
311 char buffer
[2 * 6 + 5 + 1];
314 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
315 mac
->a
[0], mac
->a
[1], mac
->a
[2],
316 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
318 visit_type_str(v
, name
, &p
, errp
);
321 static void set_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
324 Property
*prop
= opaque
;
325 MACAddr
*mac
= object_field_prop_ptr(obj
, prop
);
330 if (!visit_type_str(v
, name
, &str
, errp
)) {
334 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
337 if (!qemu_isxdigit(str
[pos
])) {
340 if (!qemu_isxdigit(str
[pos
+ 1])) {
344 if (str
[pos
+ 2] != '\0') {
348 if (str
[pos
+ 2] != ':' && str
[pos
+ 2] != '-') {
352 if (qemu_strtol(str
+ pos
, &p
, 16, &val
) < 0 || val
> 0xff) {
361 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
365 const PropertyInfo qdev_prop_macaddr
= {
367 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
372 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
,
373 const uint8_t *value
)
375 char str
[2 * 6 + 5 + 1];
376 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
377 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
379 object_property_set_str(OBJECT(dev
), name
, str
, &error_abort
);
382 /* --- netdev device --- */
383 static void get_netdev(Object
*obj
, Visitor
*v
, const char *name
,
384 void *opaque
, Error
**errp
)
386 Property
*prop
= opaque
;
387 NICPeers
*peers_ptr
= object_field_prop_ptr(obj
, prop
);
388 char *p
= g_strdup(peers_ptr
->ncs
[0] ? peers_ptr
->ncs
[0]->name
: "");
390 visit_type_str(v
, name
, &p
, errp
);
394 static void set_netdev(Object
*obj
, Visitor
*v
, const char *name
,
395 void *opaque
, Error
**errp
)
397 Property
*prop
= opaque
;
398 NICPeers
*peers_ptr
= object_field_prop_ptr(obj
, prop
);
399 NetClientState
**ncs
= peers_ptr
->ncs
;
400 NetClientState
*peers
[MAX_QUEUE_NUM
];
401 int queues
, err
= 0, i
= 0;
404 if (!visit_type_str(v
, name
, &str
, errp
)) {
408 queues
= qemu_find_net_clients_except(str
, peers
,
409 NET_CLIENT_DRIVER_NIC
,
416 if (queues
> MAX_QUEUE_NUM
) {
417 error_setg(errp
, "queues of backend '%s'(%d) exceeds QEMU limitation(%d)",
418 str
, queues
, MAX_QUEUE_NUM
);
422 for (i
= 0; i
< queues
; i
++) {
423 if (peers
[i
]->peer
) {
429 * TODO Should this really be an error? If no, the old value
430 * needs to be released before we store the new one.
432 if (!check_prop_still_unset(obj
, name
, ncs
[i
], str
, false, errp
)) {
436 if (peers
[i
]->info
->check_peer_type
) {
437 if (!peers
[i
]->info
->check_peer_type(peers
[i
], obj
->class, errp
)) {
443 ncs
[i
]->queue_index
= i
;
446 peers_ptr
->queues
= queues
;
449 error_set_from_qdev_prop_error(errp
, err
, obj
, name
, str
);
453 const PropertyInfo qdev_prop_netdev
= {
455 .description
= "ID of a netdev to use as a backend",
461 /* --- audiodev --- */
462 static void get_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
463 void *opaque
, Error
**errp
)
465 Property
*prop
= opaque
;
466 QEMUSoundCard
*card
= object_field_prop_ptr(obj
, prop
);
467 char *p
= g_strdup(audio_get_id(card
));
469 visit_type_str(v
, name
, &p
, errp
);
473 static void set_audiodev(Object
*obj
, Visitor
*v
, const char* name
,
474 void *opaque
, Error
**errp
)
476 Property
*prop
= opaque
;
477 QEMUSoundCard
*card
= object_field_prop_ptr(obj
, prop
);
482 if (!visit_type_str(v
, name
, &str
, errp
)) {
486 state
= audio_state_by_name(str
);
495 error_set_from_qdev_prop_error(errp
, err
, obj
, name
, str
);
499 const PropertyInfo qdev_prop_audiodev
= {
501 .description
= "ID of an audiodev to use as a backend",
502 /* release done on shutdown */
507 bool qdev_prop_set_drive_err(DeviceState
*dev
, const char *name
,
508 BlockBackend
*value
, Error
**errp
)
510 const char *ref
= "";
513 ref
= blk_name(value
);
515 const BlockDriverState
*bs
= blk_bs(value
);
517 ref
= bdrv_get_node_name(bs
);
522 return object_property_set_str(OBJECT(dev
), name
, ref
, errp
);
525 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
528 qdev_prop_set_drive_err(dev
, name
, value
, &error_abort
);
531 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
,
534 assert(!value
|| value
->label
);
535 object_property_set_str(OBJECT(dev
), name
, value
? value
->label
: "",
539 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
,
540 NetClientState
*value
)
542 assert(!value
|| value
->name
);
543 object_property_set_str(OBJECT(dev
), name
, value
? value
->name
: "",
547 void qdev_set_nic_properties(DeviceState
*dev
, NICInfo
*nd
)
549 qdev_prop_set_macaddr(dev
, "mac", nd
->macaddr
.a
);
551 qdev_prop_set_netdev(dev
, "netdev", nd
->netdev
);
553 if (nd
->nvectors
!= DEV_NVECTORS_UNSPECIFIED
&&
554 object_property_find(OBJECT(dev
), "vectors")) {
555 qdev_prop_set_uint32(dev
, "vectors", nd
->nvectors
);
557 nd
->instantiated
= 1;
560 /* --- lost tick policy --- */
562 static void qdev_propinfo_set_losttickpolicy(Object
*obj
, Visitor
*v
,
563 const char *name
, void *opaque
,
566 Property
*prop
= opaque
;
567 int *ptr
= object_field_prop_ptr(obj
, prop
);
570 if (!visit_type_enum(v
, name
, &value
, prop
->info
->enum_table
, errp
)) {
574 if (value
== LOST_TICK_POLICY_SLEW
) {
575 MachineState
*ms
= MACHINE(qdev_get_machine());
577 if (!object_dynamic_cast(OBJECT(ms
), TYPE_X86_MACHINE
)) {
579 "the 'slew' policy is only available for x86 machines");
587 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
589 const PropertyInfo qdev_prop_losttickpolicy
= {
590 .name
= "LostTickPolicy",
591 .enum_table
= &LostTickPolicy_lookup
,
592 .get
= qdev_propinfo_get_enum
,
593 .set
= qdev_propinfo_set_losttickpolicy
,
594 .set_default_value
= qdev_propinfo_set_default_value_enum
,
597 /* --- blocksize --- */
599 static void set_blocksize(Object
*obj
, Visitor
*v
, const char *name
,
600 void *opaque
, Error
**errp
)
602 DeviceState
*dev
= DEVICE(obj
);
603 Property
*prop
= opaque
;
604 uint32_t *ptr
= object_field_prop_ptr(obj
, prop
);
606 Error
*local_err
= NULL
;
608 if (!visit_type_size(v
, name
, &value
, errp
)) {
611 check_block_size(dev
->id
? : "", name
, value
, &local_err
);
613 error_propagate(errp
, local_err
);
619 const PropertyInfo qdev_prop_blocksize
= {
621 .description
= "A power of two between " MIN_BLOCK_SIZE_STR
622 " and " MAX_BLOCK_SIZE_STR
,
623 .get
= qdev_propinfo_get_size32
,
624 .set
= set_blocksize
,
625 .set_default_value
= qdev_propinfo_set_default_value_uint
,
628 /* --- Block device error handling policy --- */
630 QEMU_BUILD_BUG_ON(sizeof(BlockdevOnError
) != sizeof(int));
632 const PropertyInfo qdev_prop_blockdev_on_error
= {
633 .name
= "BlockdevOnError",
634 .description
= "Error handling policy, "
635 "report/ignore/enospc/stop/auto",
636 .enum_table
= &BlockdevOnError_lookup
,
637 .get
= qdev_propinfo_get_enum
,
638 .set
= qdev_propinfo_set_enum
,
639 .set_default_value
= qdev_propinfo_set_default_value_enum
,
642 /* --- BIOS CHS translation */
644 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
646 const PropertyInfo qdev_prop_bios_chs_trans
= {
647 .name
= "BiosAtaTranslation",
648 .description
= "Logical CHS translation algorithm, "
649 "auto/none/lba/large/rechs",
650 .enum_table
= &BiosAtaTranslation_lookup
,
651 .get
= qdev_propinfo_get_enum
,
652 .set
= qdev_propinfo_set_enum
,
653 .set_default_value
= qdev_propinfo_set_default_value_enum
,
656 /* --- FDC default drive types */
658 const PropertyInfo qdev_prop_fdc_drive_type
= {
659 .name
= "FdcDriveType",
660 .description
= "FDC drive type, "
661 "144/288/120/none/auto",
662 .enum_table
= &FloppyDriveType_lookup
,
663 .get
= qdev_propinfo_get_enum
,
664 .set
= qdev_propinfo_set_enum
,
665 .set_default_value
= qdev_propinfo_set_default_value_enum
,
668 /* --- MultiFDCompression --- */
670 const PropertyInfo qdev_prop_multifd_compression
= {
671 .name
= "MultiFDCompression",
672 .description
= "multifd_compression values, "
674 .enum_table
= &MultiFDCompression_lookup
,
675 .get
= qdev_propinfo_get_enum
,
676 .set
= qdev_propinfo_set_enum
,
677 .set_default_value
= qdev_propinfo_set_default_value_enum
,
680 /* --- Reserved Region --- */
684 * <low address>:<high address>:<type>
685 * where low/high addresses are uint64_t in hexadecimal
686 * and type is a non-negative decimal integer
688 static void get_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
689 void *opaque
, Error
**errp
)
691 Property
*prop
= opaque
;
692 ReservedRegion
*rr
= object_field_prop_ptr(obj
, prop
);
697 rc
= snprintf(buffer
, sizeof(buffer
), "0x%"PRIx64
":0x%"PRIx64
":%u",
698 rr
->low
, rr
->high
, rr
->type
);
699 assert(rc
< sizeof(buffer
));
701 visit_type_str(v
, name
, &p
, errp
);
704 static void set_reserved_region(Object
*obj
, Visitor
*v
, const char *name
,
705 void *opaque
, Error
**errp
)
707 Property
*prop
= opaque
;
708 ReservedRegion
*rr
= object_field_prop_ptr(obj
, prop
);
713 if (!visit_type_str(v
, name
, &str
, errp
)) {
717 ret
= qemu_strtou64(str
, &endptr
, 16, &rr
->low
);
719 error_setg(errp
, "start address of '%s'"
720 " must be a hexadecimal integer", name
);
723 if (*endptr
!= ':') {
724 goto separator_error
;
727 ret
= qemu_strtou64(endptr
+ 1, &endptr
, 16, &rr
->high
);
729 error_setg(errp
, "end address of '%s'"
730 " must be a hexadecimal integer", name
);
733 if (*endptr
!= ':') {
734 goto separator_error
;
737 ret
= qemu_strtoui(endptr
+ 1, &endptr
, 10, &rr
->type
);
739 error_setg(errp
, "type of '%s'"
740 " must be a non-negative decimal integer", name
);
745 error_setg(errp
, "reserved region fields must be separated with ':'");
751 const PropertyInfo qdev_prop_reserved_region
= {
752 .name
= "reserved_region",
753 .description
= "Reserved Region, example: 0xFEE00000:0xFEEFFFFF:0",
754 .get
= get_reserved_region
,
755 .set
= set_reserved_region
,
758 /* --- pci address --- */
761 * bus-local address, i.e. "$slot" or "$slot.$fn"
763 static void set_pci_devfn(Object
*obj
, Visitor
*v
, const char *name
,
764 void *opaque
, Error
**errp
)
766 Property
*prop
= opaque
;
767 int32_t value
, *ptr
= object_field_prop_ptr(obj
, prop
);
768 unsigned int slot
, fn
, n
;
771 if (!visit_type_str(v
, name
, &str
, NULL
)) {
772 if (!visit_type_int32(v
, name
, &value
, errp
)) {
775 if (value
< -1 || value
> 255) {
776 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
777 name
? name
: "null", "a value between -1 and 255");
784 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
786 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
790 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
793 *ptr
= slot
<< 3 | fn
;
798 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
802 static int print_pci_devfn(Object
*obj
, Property
*prop
, char *dest
,
805 int32_t *ptr
= object_field_prop_ptr(obj
, prop
);
808 return snprintf(dest
, len
, "<unset>");
810 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
814 const PropertyInfo qdev_prop_pci_devfn
= {
816 .description
= "Slot and optional function number, example: 06.0 or 06",
817 .print
= print_pci_devfn
,
818 .get
= qdev_propinfo_get_int32
,
819 .set
= set_pci_devfn
,
820 .set_default_value
= qdev_propinfo_set_default_value_int
,
823 /* --- pci host address --- */
825 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
826 void *opaque
, Error
**errp
)
828 Property
*prop
= opaque
;
829 PCIHostDeviceAddress
*addr
= object_field_prop_ptr(obj
, prop
);
830 char buffer
[] = "ffff:ff:ff.f";
835 * Catch "invalid" device reference from vfio-pci and allow the
836 * default buffer representing the non-existent device to be used.
838 if (~addr
->domain
|| ~addr
->bus
|| ~addr
->slot
|| ~addr
->function
) {
839 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%0d",
840 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
841 assert(rc
== sizeof(buffer
) - 1);
844 visit_type_str(v
, name
, &p
, errp
);
848 * Parse [<domain>:]<bus>:<slot>.<func>
849 * if <domain> is not supplied, it's assumed to be 0.
851 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
852 void *opaque
, Error
**errp
)
854 Property
*prop
= opaque
;
855 PCIHostDeviceAddress
*addr
= object_field_prop_ptr(obj
, prop
);
859 unsigned long dom
= 0, bus
= 0;
860 unsigned int slot
= 0, func
= 0;
862 if (!visit_type_str(v
, name
, &str
, errp
)) {
867 val
= strtoul(p
, &e
, 16);
868 if (e
== p
|| *e
!= ':') {
874 val
= strtoul(p
, &e
, 16);
882 val
= strtoul(p
, &e
, 16);
893 val
= strtoul(p
, &e
, 10);
899 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
910 addr
->function
= func
;
916 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
920 const PropertyInfo qdev_prop_pci_host_devaddr
= {
922 .description
= "Address (bus/device/function) of "
923 "the host device, example: 04:10.0",
924 .get
= get_pci_host_devaddr
,
925 .set
= set_pci_host_devaddr
,
928 /* --- OffAutoPCIBAR off/auto/bar0/bar1/bar2/bar3/bar4/bar5 --- */
930 const PropertyInfo qdev_prop_off_auto_pcibar
= {
931 .name
= "OffAutoPCIBAR",
932 .description
= "off/auto/bar0/bar1/bar2/bar3/bar4/bar5",
933 .enum_table
= &OffAutoPCIBAR_lookup
,
934 .get
= qdev_propinfo_get_enum
,
935 .set
= qdev_propinfo_set_enum
,
936 .set_default_value
= qdev_propinfo_set_default_value_enum
,
939 /* --- PCIELinkSpeed 2_5/5/8/16 -- */
941 static void get_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
942 void *opaque
, Error
**errp
)
944 Property
*prop
= opaque
;
945 PCIExpLinkSpeed
*p
= object_field_prop_ptr(obj
, prop
);
949 case QEMU_PCI_EXP_LNK_2_5GT
:
950 speed
= PCIE_LINK_SPEED_2_5
;
952 case QEMU_PCI_EXP_LNK_5GT
:
953 speed
= PCIE_LINK_SPEED_5
;
955 case QEMU_PCI_EXP_LNK_8GT
:
956 speed
= PCIE_LINK_SPEED_8
;
958 case QEMU_PCI_EXP_LNK_16GT
:
959 speed
= PCIE_LINK_SPEED_16
;
966 visit_type_enum(v
, name
, &speed
, prop
->info
->enum_table
, errp
);
969 static void set_prop_pcielinkspeed(Object
*obj
, Visitor
*v
, const char *name
,
970 void *opaque
, Error
**errp
)
972 Property
*prop
= opaque
;
973 PCIExpLinkSpeed
*p
= object_field_prop_ptr(obj
, prop
);
976 if (!visit_type_enum(v
, name
, &speed
, prop
->info
->enum_table
,
982 case PCIE_LINK_SPEED_2_5
:
983 *p
= QEMU_PCI_EXP_LNK_2_5GT
;
985 case PCIE_LINK_SPEED_5
:
986 *p
= QEMU_PCI_EXP_LNK_5GT
;
988 case PCIE_LINK_SPEED_8
:
989 *p
= QEMU_PCI_EXP_LNK_8GT
;
991 case PCIE_LINK_SPEED_16
:
992 *p
= QEMU_PCI_EXP_LNK_16GT
;
1000 const PropertyInfo qdev_prop_pcie_link_speed
= {
1001 .name
= "PCIELinkSpeed",
1002 .description
= "2_5/5/8/16",
1003 .enum_table
= &PCIELinkSpeed_lookup
,
1004 .get
= get_prop_pcielinkspeed
,
1005 .set
= set_prop_pcielinkspeed
,
1006 .set_default_value
= qdev_propinfo_set_default_value_enum
,
1009 /* --- PCIELinkWidth 1/2/4/8/12/16/32 -- */
1011 static void get_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
1012 void *opaque
, Error
**errp
)
1014 Property
*prop
= opaque
;
1015 PCIExpLinkWidth
*p
= object_field_prop_ptr(obj
, prop
);
1019 case QEMU_PCI_EXP_LNK_X1
:
1020 width
= PCIE_LINK_WIDTH_1
;
1022 case QEMU_PCI_EXP_LNK_X2
:
1023 width
= PCIE_LINK_WIDTH_2
;
1025 case QEMU_PCI_EXP_LNK_X4
:
1026 width
= PCIE_LINK_WIDTH_4
;
1028 case QEMU_PCI_EXP_LNK_X8
:
1029 width
= PCIE_LINK_WIDTH_8
;
1031 case QEMU_PCI_EXP_LNK_X12
:
1032 width
= PCIE_LINK_WIDTH_12
;
1034 case QEMU_PCI_EXP_LNK_X16
:
1035 width
= PCIE_LINK_WIDTH_16
;
1037 case QEMU_PCI_EXP_LNK_X32
:
1038 width
= PCIE_LINK_WIDTH_32
;
1045 visit_type_enum(v
, name
, &width
, prop
->info
->enum_table
, errp
);
1048 static void set_prop_pcielinkwidth(Object
*obj
, Visitor
*v
, const char *name
,
1049 void *opaque
, Error
**errp
)
1051 Property
*prop
= opaque
;
1052 PCIExpLinkWidth
*p
= object_field_prop_ptr(obj
, prop
);
1055 if (!visit_type_enum(v
, name
, &width
, prop
->info
->enum_table
,
1061 case PCIE_LINK_WIDTH_1
:
1062 *p
= QEMU_PCI_EXP_LNK_X1
;
1064 case PCIE_LINK_WIDTH_2
:
1065 *p
= QEMU_PCI_EXP_LNK_X2
;
1067 case PCIE_LINK_WIDTH_4
:
1068 *p
= QEMU_PCI_EXP_LNK_X4
;
1070 case PCIE_LINK_WIDTH_8
:
1071 *p
= QEMU_PCI_EXP_LNK_X8
;
1073 case PCIE_LINK_WIDTH_12
:
1074 *p
= QEMU_PCI_EXP_LNK_X12
;
1076 case PCIE_LINK_WIDTH_16
:
1077 *p
= QEMU_PCI_EXP_LNK_X16
;
1079 case PCIE_LINK_WIDTH_32
:
1080 *p
= QEMU_PCI_EXP_LNK_X32
;
1088 const PropertyInfo qdev_prop_pcie_link_width
= {
1089 .name
= "PCIELinkWidth",
1090 .description
= "1/2/4/8/12/16/32",
1091 .enum_table
= &PCIELinkWidth_lookup
,
1092 .get
= get_prop_pcielinkwidth
,
1093 .set
= set_prop_pcielinkwidth
,
1094 .set_default_value
= qdev_propinfo_set_default_value_enum
,
1099 static void get_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1102 Property
*prop
= opaque
;
1103 QemuUUID
*uuid
= object_field_prop_ptr(obj
, prop
);
1104 char buffer
[UUID_FMT_LEN
+ 1];
1107 qemu_uuid_unparse(uuid
, buffer
);
1109 visit_type_str(v
, name
, &p
, errp
);
1112 #define UUID_VALUE_AUTO "auto"
1114 static void set_uuid(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1117 Property
*prop
= opaque
;
1118 QemuUUID
*uuid
= object_field_prop_ptr(obj
, prop
);
1121 if (!visit_type_str(v
, name
, &str
, errp
)) {
1125 if (!strcmp(str
, UUID_VALUE_AUTO
)) {
1126 qemu_uuid_generate(uuid
);
1127 } else if (qemu_uuid_parse(str
, uuid
) < 0) {
1128 error_set_from_qdev_prop_error(errp
, EINVAL
, obj
, name
, str
);
1133 static void set_default_uuid_auto(ObjectProperty
*op
, const Property
*prop
)
1135 object_property_set_default_str(op
, UUID_VALUE_AUTO
);
1138 const PropertyInfo qdev_prop_uuid
= {
1140 .description
= "UUID (aka GUID) or \"" UUID_VALUE_AUTO
1141 "\" for random value (default)",
1144 .set_default_value
= set_default_uuid_auto
,