6 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
)
13 static uint32_t qdev_get_prop_mask(Property
*prop
)
15 assert(prop
->info
== &qdev_prop_bit
);
16 return 0x1 << prop
->bitnr
;
19 static void bit_prop_set(DeviceState
*dev
, Property
*props
, bool val
)
21 uint32_t *p
= qdev_get_prop_ptr(dev
, props
);
22 uint32_t mask
= qdev_get_prop_mask(props
);
31 static int print_bit(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
33 uint32_t *p
= qdev_get_prop_ptr(dev
, prop
);
34 return snprintf(dest
, len
, (*p
& qdev_get_prop_mask(prop
)) ? "on" : "off");
37 static void get_bit(Object
*obj
, Visitor
*v
, void *opaque
,
38 const char *name
, Error
**errp
)
40 DeviceState
*dev
= DEVICE(obj
);
41 Property
*prop
= opaque
;
42 uint32_t *p
= qdev_get_prop_ptr(dev
, prop
);
43 bool value
= (*p
& qdev_get_prop_mask(prop
)) != 0;
45 visit_type_bool(v
, &value
, name
, errp
);
48 static void set_bit(Object
*obj
, Visitor
*v
, void *opaque
,
49 const char *name
, Error
**errp
)
51 DeviceState
*dev
= DEVICE(obj
);
52 Property
*prop
= opaque
;
53 Error
*local_err
= NULL
;
56 if (dev
->state
!= DEV_STATE_CREATED
) {
57 error_set(errp
, QERR_PERMISSION_DENIED
);
61 visit_type_bool(v
, &value
, name
, &local_err
);
63 error_propagate(errp
, local_err
);
66 bit_prop_set(dev
, prop
, value
);
69 PropertyInfo qdev_prop_bit
= {
71 .legacy_name
= "on/off",
77 /* --- 8bit integer --- */
79 static void get_int8(Object
*obj
, Visitor
*v
, void *opaque
,
80 const char *name
, Error
**errp
)
82 DeviceState
*dev
= DEVICE(obj
);
83 Property
*prop
= opaque
;
84 int8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
88 visit_type_int(v
, &value
, name
, errp
);
91 static void set_int8(Object
*obj
, Visitor
*v
, void *opaque
,
92 const char *name
, Error
**errp
)
94 DeviceState
*dev
= DEVICE(obj
);
95 Property
*prop
= opaque
;
96 int8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
97 Error
*local_err
= NULL
;
100 if (dev
->state
!= DEV_STATE_CREATED
) {
101 error_set(errp
, QERR_PERMISSION_DENIED
);
105 visit_type_int(v
, &value
, name
, &local_err
);
107 error_propagate(errp
, local_err
);
110 if (value
>= prop
->info
->min
&& value
<= prop
->info
->max
) {
113 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
114 dev
->id
?:"", name
, value
, prop
->info
->min
,
119 PropertyInfo qdev_prop_uint8
= {
127 /* --- 8bit hex value --- */
129 static int parse_hex8(DeviceState
*dev
, Property
*prop
, const char *str
)
131 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
134 if (str
[0] != '0' || str
[1] != 'x') {
138 *ptr
= strtoul(str
, &end
, 16);
139 if ((*end
!= '\0') || (end
== str
)) {
146 static int print_hex8(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
148 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
149 return snprintf(dest
, len
, "0x%" PRIx8
, *ptr
);
152 PropertyInfo qdev_prop_hex8
= {
154 .legacy_name
= "hex8",
163 /* --- 16bit integer --- */
165 static void get_int16(Object
*obj
, Visitor
*v
, void *opaque
,
166 const char *name
, Error
**errp
)
168 DeviceState
*dev
= DEVICE(obj
);
169 Property
*prop
= opaque
;
170 int16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
174 visit_type_int(v
, &value
, name
, errp
);
177 static void set_int16(Object
*obj
, Visitor
*v
, void *opaque
,
178 const char *name
, Error
**errp
)
180 DeviceState
*dev
= DEVICE(obj
);
181 Property
*prop
= opaque
;
182 int16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
183 Error
*local_err
= NULL
;
186 if (dev
->state
!= DEV_STATE_CREATED
) {
187 error_set(errp
, QERR_PERMISSION_DENIED
);
191 visit_type_int(v
, &value
, name
, &local_err
);
193 error_propagate(errp
, local_err
);
196 if (value
>= prop
->info
->min
&& value
<= prop
->info
->max
) {
199 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
200 dev
->id
?:"", name
, value
, prop
->info
->min
,
205 PropertyInfo qdev_prop_uint16
= {
213 /* --- 32bit integer --- */
215 static void get_int32(Object
*obj
, Visitor
*v
, void *opaque
,
216 const char *name
, Error
**errp
)
218 DeviceState
*dev
= DEVICE(obj
);
219 Property
*prop
= opaque
;
220 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
224 visit_type_int(v
, &value
, name
, errp
);
227 static void set_int32(Object
*obj
, Visitor
*v
, void *opaque
,
228 const char *name
, Error
**errp
)
230 DeviceState
*dev
= DEVICE(obj
);
231 Property
*prop
= opaque
;
232 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
233 Error
*local_err
= NULL
;
236 if (dev
->state
!= DEV_STATE_CREATED
) {
237 error_set(errp
, QERR_PERMISSION_DENIED
);
241 visit_type_int(v
, &value
, name
, &local_err
);
243 error_propagate(errp
, local_err
);
246 if (value
>= prop
->info
->min
&& value
<= prop
->info
->max
) {
249 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
250 dev
->id
?:"", name
, value
, prop
->info
->min
,
255 PropertyInfo qdev_prop_uint32
= {
260 .max
= 0xFFFFFFFFULL
,
263 PropertyInfo qdev_prop_int32
= {
267 .min
= -0x80000000LL
,
271 /* --- 32bit hex value --- */
273 static int parse_hex32(DeviceState
*dev
, Property
*prop
, const char *str
)
275 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
278 if (str
[0] != '0' || str
[1] != 'x') {
282 *ptr
= strtoul(str
, &end
, 16);
283 if ((*end
!= '\0') || (end
== str
)) {
290 static int print_hex32(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
292 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
293 return snprintf(dest
, len
, "0x%" PRIx32
, *ptr
);
296 PropertyInfo qdev_prop_hex32
= {
298 .legacy_name
= "hex32",
299 .parse
= parse_hex32
,
300 .print
= print_hex32
,
304 .max
= 0xFFFFFFFFULL
,
307 /* --- 64bit integer --- */
309 static void get_int64(Object
*obj
, Visitor
*v
, void *opaque
,
310 const char *name
, Error
**errp
)
312 DeviceState
*dev
= DEVICE(obj
);
313 Property
*prop
= opaque
;
314 int64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
316 visit_type_int(v
, ptr
, name
, errp
);
319 static void set_int64(Object
*obj
, Visitor
*v
, void *opaque
,
320 const char *name
, Error
**errp
)
322 DeviceState
*dev
= DEVICE(obj
);
323 Property
*prop
= opaque
;
324 int64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
326 if (dev
->state
!= DEV_STATE_CREATED
) {
327 error_set(errp
, QERR_PERMISSION_DENIED
);
331 visit_type_int(v
, ptr
, name
, errp
);
334 PropertyInfo qdev_prop_uint64
= {
340 /* --- 64bit hex value --- */
342 static int parse_hex64(DeviceState
*dev
, Property
*prop
, const char *str
)
344 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
347 if (str
[0] != '0' || str
[1] != 'x') {
351 *ptr
= strtoull(str
, &end
, 16);
352 if ((*end
!= '\0') || (end
== str
)) {
359 static int print_hex64(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
361 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
362 return snprintf(dest
, len
, "0x%" PRIx64
, *ptr
);
365 PropertyInfo qdev_prop_hex64
= {
367 .legacy_name
= "hex64",
368 .parse
= parse_hex64
,
369 .print
= print_hex64
,
376 static void release_string(Object
*obj
, const char *name
, void *opaque
)
378 Property
*prop
= opaque
;
379 g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj
), prop
));
382 static int print_string(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
384 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
386 return snprintf(dest
, len
, "<null>");
387 return snprintf(dest
, len
, "\"%s\"", *ptr
);
390 static void get_string(Object
*obj
, Visitor
*v
, void *opaque
,
391 const char *name
, Error
**errp
)
393 DeviceState
*dev
= DEVICE(obj
);
394 Property
*prop
= opaque
;
395 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
398 char *str
= (char *)"";
399 visit_type_str(v
, &str
, name
, errp
);
401 visit_type_str(v
, ptr
, name
, errp
);
405 static void set_string(Object
*obj
, Visitor
*v
, void *opaque
,
406 const char *name
, Error
**errp
)
408 DeviceState
*dev
= DEVICE(obj
);
409 Property
*prop
= opaque
;
410 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
411 Error
*local_err
= NULL
;
414 if (dev
->state
!= DEV_STATE_CREATED
) {
415 error_set(errp
, QERR_PERMISSION_DENIED
);
419 visit_type_str(v
, &str
, name
, &local_err
);
421 error_propagate(errp
, local_err
);
434 PropertyInfo qdev_prop_string
= {
436 .print
= print_string
,
437 .release
= release_string
,
444 static int parse_drive(DeviceState
*dev
, const char *str
, void **ptr
)
446 BlockDriverState
*bs
;
451 if (bdrv_attach_dev(bs
, dev
) < 0)
457 static void release_drive(Object
*obj
, const char *name
, void *opaque
)
459 DeviceState
*dev
= DEVICE(obj
);
460 Property
*prop
= opaque
;
461 BlockDriverState
**ptr
= qdev_get_prop_ptr(dev
, prop
);
464 bdrv_detach_dev(*ptr
, dev
);
465 blockdev_auto_del(*ptr
);
469 static const char *print_drive(void *ptr
)
471 return bdrv_get_device_name(ptr
);
474 static void get_pointer(Object
*obj
, Visitor
*v
, Property
*prop
,
475 const char *(*print
)(void *ptr
),
476 const char *name
, Error
**errp
)
478 DeviceState
*dev
= DEVICE(obj
);
479 void **ptr
= qdev_get_prop_ptr(dev
, prop
);
482 p
= (char *) (*ptr
? print(*ptr
) : "");
483 visit_type_str(v
, &p
, name
, errp
);
486 static void set_pointer(Object
*obj
, Visitor
*v
, Property
*prop
,
487 int (*parse
)(DeviceState
*dev
, const char *str
, void **ptr
),
488 const char *name
, Error
**errp
)
490 DeviceState
*dev
= DEVICE(obj
);
491 Error
*local_err
= NULL
;
492 void **ptr
= qdev_get_prop_ptr(dev
, prop
);
496 if (dev
->state
!= DEV_STATE_CREATED
) {
497 error_set(errp
, QERR_PERMISSION_DENIED
);
501 visit_type_str(v
, &str
, name
, &local_err
);
503 error_propagate(errp
, local_err
);
511 ret
= parse(dev
, str
, ptr
);
512 error_set_from_qdev_prop_error(errp
, ret
, dev
, prop
, str
);
516 static void get_drive(Object
*obj
, Visitor
*v
, void *opaque
,
517 const char *name
, Error
**errp
)
519 get_pointer(obj
, v
, opaque
, print_drive
, name
, errp
);
522 static void set_drive(Object
*obj
, Visitor
*v
, void *opaque
,
523 const char *name
, Error
**errp
)
525 set_pointer(obj
, v
, opaque
, parse_drive
, name
, errp
);
528 PropertyInfo qdev_prop_drive
= {
532 .release
= release_drive
,
535 /* --- character device --- */
537 static int parse_chr(DeviceState
*dev
, const char *str
, void **ptr
)
539 CharDriverState
*chr
= qemu_chr_find(str
);
543 if (chr
->avail_connections
< 1) {
547 --chr
->avail_connections
;
551 static void release_chr(Object
*obj
, const char *name
, void *opaque
)
553 DeviceState
*dev
= DEVICE(obj
);
554 Property
*prop
= opaque
;
555 CharDriverState
**ptr
= qdev_get_prop_ptr(dev
, prop
);
558 qemu_chr_add_handlers(*ptr
, NULL
, NULL
, NULL
, NULL
);
563 static const char *print_chr(void *ptr
)
565 CharDriverState
*chr
= ptr
;
567 return chr
->label
? chr
->label
: "";
570 static void get_chr(Object
*obj
, Visitor
*v
, void *opaque
,
571 const char *name
, Error
**errp
)
573 get_pointer(obj
, v
, opaque
, print_chr
, name
, errp
);
576 static void set_chr(Object
*obj
, Visitor
*v
, void *opaque
,
577 const char *name
, Error
**errp
)
579 set_pointer(obj
, v
, opaque
, parse_chr
, name
, errp
);
582 PropertyInfo qdev_prop_chr
= {
586 .release
= release_chr
,
589 /* --- netdev device --- */
591 static int parse_netdev(DeviceState
*dev
, const char *str
, void **ptr
)
593 VLANClientState
*netdev
= qemu_find_netdev(str
);
595 if (netdev
== NULL
) {
605 static const char *print_netdev(void *ptr
)
607 VLANClientState
*netdev
= ptr
;
609 return netdev
->name
? netdev
->name
: "";
612 static void get_netdev(Object
*obj
, Visitor
*v
, void *opaque
,
613 const char *name
, Error
**errp
)
615 get_pointer(obj
, v
, opaque
, print_netdev
, name
, errp
);
618 static void set_netdev(Object
*obj
, Visitor
*v
, void *opaque
,
619 const char *name
, Error
**errp
)
621 set_pointer(obj
, v
, opaque
, parse_netdev
, name
, errp
);
624 PropertyInfo qdev_prop_netdev
= {
632 static int print_vlan(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
634 VLANState
**ptr
= qdev_get_prop_ptr(dev
, prop
);
637 return snprintf(dest
, len
, "%d", (*ptr
)->id
);
639 return snprintf(dest
, len
, "<null>");
643 static void get_vlan(Object
*obj
, Visitor
*v
, void *opaque
,
644 const char *name
, Error
**errp
)
646 DeviceState
*dev
= DEVICE(obj
);
647 Property
*prop
= opaque
;
648 VLANState
**ptr
= qdev_get_prop_ptr(dev
, prop
);
651 id
= *ptr
? (*ptr
)->id
: -1;
652 visit_type_int(v
, &id
, name
, errp
);
655 static void set_vlan(Object
*obj
, Visitor
*v
, void *opaque
,
656 const char *name
, Error
**errp
)
658 DeviceState
*dev
= DEVICE(obj
);
659 Property
*prop
= opaque
;
660 VLANState
**ptr
= qdev_get_prop_ptr(dev
, prop
);
661 Error
*local_err
= NULL
;
665 if (dev
->state
!= DEV_STATE_CREATED
) {
666 error_set(errp
, QERR_PERMISSION_DENIED
);
670 visit_type_int(v
, &id
, name
, &local_err
);
672 error_propagate(errp
, local_err
);
679 vlan
= qemu_find_vlan(id
, 1);
681 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
,
682 name
, prop
->info
->name
);
688 PropertyInfo qdev_prop_vlan
= {
695 /* --- pointer --- */
697 /* Not a proper property, just for dirty hacks. TODO Remove it! */
698 PropertyInfo qdev_prop_ptr
= {
702 /* --- mac address --- */
705 * accepted syntax versions:
709 static void get_mac(Object
*obj
, Visitor
*v
, void *opaque
,
710 const char *name
, Error
**errp
)
712 DeviceState
*dev
= DEVICE(obj
);
713 Property
*prop
= opaque
;
714 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
715 char buffer
[2 * 6 + 5 + 1];
718 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
719 mac
->a
[0], mac
->a
[1], mac
->a
[2],
720 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
722 visit_type_str(v
, &p
, name
, errp
);
725 static void set_mac(Object
*obj
, Visitor
*v
, void *opaque
,
726 const char *name
, Error
**errp
)
728 DeviceState
*dev
= DEVICE(obj
);
729 Property
*prop
= opaque
;
730 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
731 Error
*local_err
= NULL
;
735 if (dev
->state
!= DEV_STATE_CREATED
) {
736 error_set(errp
, QERR_PERMISSION_DENIED
);
740 visit_type_str(v
, &str
, name
, &local_err
);
742 error_propagate(errp
, local_err
);
746 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
747 if (!qemu_isxdigit(str
[pos
]))
749 if (!qemu_isxdigit(str
[pos
+1]))
752 if (str
[pos
+2] != '\0')
755 if (str
[pos
+2] != ':' && str
[pos
+2] != '-')
758 mac
->a
[i
] = strtol(str
+pos
, &p
, 16);
763 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
766 PropertyInfo qdev_prop_macaddr
= {
773 /* --- lost tick policy --- */
775 static const char *lost_tick_policy_table
[LOST_TICK_MAX
+1] = {
776 [LOST_TICK_DISCARD
] = "discard",
777 [LOST_TICK_DELAY
] = "delay",
778 [LOST_TICK_MERGE
] = "merge",
779 [LOST_TICK_SLEW
] = "slew",
780 [LOST_TICK_MAX
] = NULL
,
783 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
785 static void get_enum(Object
*obj
, Visitor
*v
, void *opaque
,
786 const char *name
, Error
**errp
)
788 DeviceState
*dev
= DEVICE(obj
);
789 Property
*prop
= opaque
;
790 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
792 visit_type_enum(v
, ptr
, prop
->info
->enum_table
,
793 prop
->info
->name
, prop
->name
, errp
);
796 static void set_enum(Object
*obj
, Visitor
*v
, void *opaque
,
797 const char *name
, Error
**errp
)
799 DeviceState
*dev
= DEVICE(obj
);
800 Property
*prop
= opaque
;
801 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
803 if (dev
->state
!= DEV_STATE_CREATED
) {
804 error_set(errp
, QERR_PERMISSION_DENIED
);
808 visit_type_enum(v
, ptr
, prop
->info
->enum_table
,
809 prop
->info
->name
, prop
->name
, errp
);
812 PropertyInfo qdev_prop_losttickpolicy
= {
813 .name
= "LostTickPolicy",
814 .enum_table
= lost_tick_policy_table
,
819 /* --- pci address --- */
822 * bus-local address, i.e. "$slot" or "$slot.$fn"
824 static void set_pci_devfn(Object
*obj
, Visitor
*v
, void *opaque
,
825 const char *name
, Error
**errp
)
827 DeviceState
*dev
= DEVICE(obj
);
828 Property
*prop
= opaque
;
829 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
830 unsigned int slot
, fn
, n
;
831 Error
*local_err
= NULL
;
832 char *str
= (char *)"";
834 if (dev
->state
!= DEV_STATE_CREATED
) {
835 error_set(errp
, QERR_PERMISSION_DENIED
);
839 visit_type_str(v
, &str
, name
, &local_err
);
841 return set_int32(obj
, v
, opaque
, name
, errp
);
844 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
846 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
850 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
853 *ptr
= slot
<< 3 | fn
;
857 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
860 static int print_pci_devfn(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
862 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
865 return snprintf(dest
, len
, "<unset>");
867 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
871 PropertyInfo qdev_prop_pci_devfn
= {
873 .legacy_name
= "pci-devfn",
874 .print
= print_pci_devfn
,
876 .set
= set_pci_devfn
,
877 /* FIXME: this should be -1...255, but the address is stored
878 * into an uint32_t rather than int32_t.
881 .max
= 0xFFFFFFFFULL
,
884 /* --- public helpers --- */
886 static Property
*qdev_prop_walk(Property
*props
, const char *name
)
890 while (props
->name
) {
891 if (strcmp(props
->name
, name
) == 0)
898 static Property
*qdev_prop_find(DeviceState
*dev
, const char *name
)
902 /* device properties */
903 prop
= qdev_prop_walk(qdev_get_props(dev
), name
);
908 prop
= qdev_prop_walk(dev
->parent_bus
->info
->props
, name
);
915 int qdev_prop_exists(DeviceState
*dev
, const char *name
)
917 return qdev_prop_find(dev
, name
) ? true : false;
920 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
921 Property
*prop
, const char *value
)
925 error_set(errp
, QERR_PROPERTY_VALUE_IN_USE
,
926 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
930 error_set(errp
, QERR_PROPERTY_VALUE_BAD
,
931 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
934 error_set(errp
, QERR_PROPERTY_VALUE_NOT_FOUND
,
935 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
942 int qdev_prop_parse(DeviceState
*dev
, const char *name
, const char *value
)
947 legacy_name
= g_strdup_printf("legacy-%s", name
);
948 if (object_property_get_type(OBJECT(dev
), legacy_name
, NULL
)) {
949 object_property_parse(OBJECT(dev
), value
, legacy_name
, &err
);
951 object_property_parse(OBJECT(dev
), value
, name
, &err
);
956 qerror_report_err(err
);
963 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
)
966 object_property_set_bool(OBJECT(dev
), value
, name
, &errp
);
967 assert_no_error(errp
);
970 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
)
973 object_property_set_int(OBJECT(dev
), value
, name
, &errp
);
974 assert_no_error(errp
);
977 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
)
980 object_property_set_int(OBJECT(dev
), value
, name
, &errp
);
981 assert_no_error(errp
);
984 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
)
987 object_property_set_int(OBJECT(dev
), value
, name
, &errp
);
988 assert_no_error(errp
);
991 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
)
994 object_property_set_int(OBJECT(dev
), value
, name
, &errp
);
995 assert_no_error(errp
);
998 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
)
1001 object_property_set_int(OBJECT(dev
), value
, name
, &errp
);
1002 assert_no_error(errp
);
1005 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, char *value
)
1008 object_property_set_str(OBJECT(dev
), value
, name
, &errp
);
1009 assert_no_error(errp
);
1012 int qdev_prop_set_drive(DeviceState
*dev
, const char *name
, BlockDriverState
*value
)
1015 const char *bdrv_name
= value
? bdrv_get_device_name(value
) : "";
1016 object_property_set_str(OBJECT(dev
), bdrv_name
,
1019 qerror_report_err(errp
);
1026 void qdev_prop_set_drive_nofail(DeviceState
*dev
, const char *name
, BlockDriverState
*value
)
1028 if (qdev_prop_set_drive(dev
, name
, value
) < 0) {
1032 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
, CharDriverState
*value
)
1035 assert(!value
|| value
->label
);
1036 object_property_set_str(OBJECT(dev
),
1037 value
? value
->label
: "", name
, &errp
);
1038 assert_no_error(errp
);
1041 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
, VLANClientState
*value
)
1044 assert(!value
|| value
->name
);
1045 object_property_set_str(OBJECT(dev
),
1046 value
? value
->name
: "", name
, &errp
);
1047 assert_no_error(errp
);
1050 void qdev_prop_set_vlan(DeviceState
*dev
, const char *name
, VLANState
*value
)
1053 object_property_set_int(OBJECT(dev
), value
? value
->id
: -1, name
, &errp
);
1054 assert_no_error(errp
);
1057 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
)
1060 char str
[2 * 6 + 5 + 1];
1061 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
1062 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
1064 object_property_set_str(OBJECT(dev
), str
, name
, &errp
);
1065 assert_no_error(errp
);
1068 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
)
1073 prop
= qdev_prop_find(dev
, name
);
1074 object_property_set_str(OBJECT(dev
), prop
->info
->enum_table
[value
],
1076 assert_no_error(errp
);
1079 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
)
1084 prop
= qdev_prop_find(dev
, name
);
1085 assert(prop
&& prop
->info
== &qdev_prop_ptr
);
1086 ptr
= qdev_get_prop_ptr(dev
, prop
);
1090 void qdev_prop_set_defaults(DeviceState
*dev
, Property
*props
)
1092 Object
*obj
= OBJECT(dev
);
1095 for (; props
->name
; props
++) {
1097 if (props
->qtype
== QTYPE_NONE
) {
1100 if (props
->qtype
== QTYPE_QBOOL
) {
1101 object_property_set_bool(obj
, props
->defval
, props
->name
, &errp
);
1102 } else if (props
->info
->enum_table
) {
1103 object_property_set_str(obj
, props
->info
->enum_table
[props
->defval
],
1104 props
->name
, &errp
);
1105 } else if (props
->qtype
== QTYPE_QINT
) {
1106 object_property_set_int(obj
, props
->defval
, props
->name
, &errp
);
1108 assert_no_error(errp
);
1112 static QTAILQ_HEAD(, GlobalProperty
) global_props
= QTAILQ_HEAD_INITIALIZER(global_props
);
1114 static void qdev_prop_register_global(GlobalProperty
*prop
)
1116 QTAILQ_INSERT_TAIL(&global_props
, prop
, next
);
1119 void qdev_prop_register_global_list(GlobalProperty
*props
)
1123 for (i
= 0; props
[i
].driver
!= NULL
; i
++) {
1124 qdev_prop_register_global(props
+i
);
1128 void qdev_prop_set_globals(DeviceState
*dev
)
1130 GlobalProperty
*prop
;
1132 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1133 if (strcmp(object_get_typename(OBJECT(dev
)), prop
->driver
) != 0 &&
1134 strcmp(qdev_get_bus_info(dev
)->name
, prop
->driver
) != 0) {
1137 if (qdev_prop_parse(dev
, prop
->property
, prop
->value
) != 0) {
1143 static int qdev_add_one_global(QemuOpts
*opts
, void *opaque
)
1147 g
= g_malloc0(sizeof(*g
));
1148 g
->driver
= qemu_opt_get(opts
, "driver");
1149 g
->property
= qemu_opt_get(opts
, "property");
1150 g
->value
= qemu_opt_get(opts
, "value");
1151 qdev_prop_register_global(g
);
1155 void qemu_add_globals(void)
1157 qemu_opts_foreach(qemu_find_opts("global"), qdev_add_one_global
, NULL
, 0);