3 #include "qapi/qmp/qerror.h"
4 #include "sysemu/blockdev.h"
5 #include "hw/block-common.h"
7 #include "qapi/visitor.h"
10 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
)
17 static void get_enum(Object
*obj
, Visitor
*v
, void *opaque
,
18 const char *name
, Error
**errp
)
20 DeviceState
*dev
= DEVICE(obj
);
21 Property
*prop
= opaque
;
22 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
24 visit_type_enum(v
, ptr
, prop
->info
->enum_table
,
25 prop
->info
->name
, prop
->name
, errp
);
28 static void set_enum(Object
*obj
, Visitor
*v
, void *opaque
,
29 const char *name
, Error
**errp
)
31 DeviceState
*dev
= DEVICE(obj
);
32 Property
*prop
= opaque
;
33 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
36 error_set(errp
, QERR_PERMISSION_DENIED
);
40 visit_type_enum(v
, ptr
, prop
->info
->enum_table
,
41 prop
->info
->name
, prop
->name
, errp
);
46 static uint32_t qdev_get_prop_mask(Property
*prop
)
48 assert(prop
->info
== &qdev_prop_bit
);
49 return 0x1 << prop
->bitnr
;
52 static void bit_prop_set(DeviceState
*dev
, Property
*props
, bool val
)
54 uint32_t *p
= qdev_get_prop_ptr(dev
, props
);
55 uint32_t mask
= qdev_get_prop_mask(props
);
63 static int print_bit(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
65 uint32_t *p
= qdev_get_prop_ptr(dev
, prop
);
66 return snprintf(dest
, len
, (*p
& qdev_get_prop_mask(prop
)) ? "on" : "off");
69 static void get_bit(Object
*obj
, Visitor
*v
, void *opaque
,
70 const char *name
, Error
**errp
)
72 DeviceState
*dev
= DEVICE(obj
);
73 Property
*prop
= opaque
;
74 uint32_t *p
= qdev_get_prop_ptr(dev
, prop
);
75 bool value
= (*p
& qdev_get_prop_mask(prop
)) != 0;
77 visit_type_bool(v
, &value
, name
, errp
);
80 static void set_bit(Object
*obj
, Visitor
*v
, void *opaque
,
81 const char *name
, Error
**errp
)
83 DeviceState
*dev
= DEVICE(obj
);
84 Property
*prop
= opaque
;
85 Error
*local_err
= NULL
;
89 error_set(errp
, QERR_PERMISSION_DENIED
);
93 visit_type_bool(v
, &value
, name
, &local_err
);
95 error_propagate(errp
, local_err
);
98 bit_prop_set(dev
, prop
, value
);
101 PropertyInfo qdev_prop_bit
= {
103 .legacy_name
= "on/off",
109 /* --- 8bit integer --- */
111 static void get_uint8(Object
*obj
, Visitor
*v
, void *opaque
,
112 const char *name
, Error
**errp
)
114 DeviceState
*dev
= DEVICE(obj
);
115 Property
*prop
= opaque
;
116 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
118 visit_type_uint8(v
, ptr
, name
, errp
);
121 static void set_uint8(Object
*obj
, Visitor
*v
, void *opaque
,
122 const char *name
, Error
**errp
)
124 DeviceState
*dev
= DEVICE(obj
);
125 Property
*prop
= opaque
;
126 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
129 error_set(errp
, QERR_PERMISSION_DENIED
);
133 visit_type_uint8(v
, ptr
, name
, errp
);
136 PropertyInfo qdev_prop_uint8
= {
142 /* --- 8bit hex value --- */
144 static int parse_hex8(DeviceState
*dev
, Property
*prop
, const char *str
)
146 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
149 if (str
[0] != '0' || str
[1] != 'x') {
153 *ptr
= strtoul(str
, &end
, 16);
154 if ((*end
!= '\0') || (end
== str
)) {
161 static int print_hex8(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
163 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
164 return snprintf(dest
, len
, "0x%" PRIx8
, *ptr
);
167 PropertyInfo qdev_prop_hex8
= {
169 .legacy_name
= "hex8",
176 /* --- 16bit integer --- */
178 static void get_uint16(Object
*obj
, Visitor
*v
, void *opaque
,
179 const char *name
, Error
**errp
)
181 DeviceState
*dev
= DEVICE(obj
);
182 Property
*prop
= opaque
;
183 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
185 visit_type_uint16(v
, ptr
, name
, errp
);
188 static void set_uint16(Object
*obj
, Visitor
*v
, void *opaque
,
189 const char *name
, Error
**errp
)
191 DeviceState
*dev
= DEVICE(obj
);
192 Property
*prop
= opaque
;
193 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
196 error_set(errp
, QERR_PERMISSION_DENIED
);
200 visit_type_uint16(v
, ptr
, name
, errp
);
203 PropertyInfo qdev_prop_uint16
= {
209 /* --- 32bit integer --- */
211 static void get_uint32(Object
*obj
, Visitor
*v
, void *opaque
,
212 const char *name
, Error
**errp
)
214 DeviceState
*dev
= DEVICE(obj
);
215 Property
*prop
= opaque
;
216 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
218 visit_type_uint32(v
, ptr
, name
, errp
);
221 static void set_uint32(Object
*obj
, Visitor
*v
, void *opaque
,
222 const char *name
, Error
**errp
)
224 DeviceState
*dev
= DEVICE(obj
);
225 Property
*prop
= opaque
;
226 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
229 error_set(errp
, QERR_PERMISSION_DENIED
);
233 visit_type_uint32(v
, ptr
, name
, errp
);
236 static void get_int32(Object
*obj
, Visitor
*v
, void *opaque
,
237 const char *name
, Error
**errp
)
239 DeviceState
*dev
= DEVICE(obj
);
240 Property
*prop
= opaque
;
241 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
243 visit_type_int32(v
, ptr
, name
, errp
);
246 static void set_int32(Object
*obj
, Visitor
*v
, void *opaque
,
247 const char *name
, Error
**errp
)
249 DeviceState
*dev
= DEVICE(obj
);
250 Property
*prop
= opaque
;
251 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
254 error_set(errp
, QERR_PERMISSION_DENIED
);
258 visit_type_int32(v
, ptr
, name
, errp
);
261 PropertyInfo qdev_prop_uint32
= {
267 PropertyInfo qdev_prop_int32
= {
273 /* --- 32bit hex value --- */
275 static int parse_hex32(DeviceState
*dev
, Property
*prop
, const char *str
)
277 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
280 if (str
[0] != '0' || str
[1] != 'x') {
284 *ptr
= strtoul(str
, &end
, 16);
285 if ((*end
!= '\0') || (end
== str
)) {
292 static int print_hex32(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
)
294 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
295 return snprintf(dest
, len
, "0x%" PRIx32
, *ptr
);
298 PropertyInfo qdev_prop_hex32
= {
300 .legacy_name
= "hex32",
301 .parse
= parse_hex32
,
302 .print
= print_hex32
,
307 /* --- 64bit integer --- */
309 static void get_uint64(Object
*obj
, Visitor
*v
, void *opaque
,
310 const char *name
, Error
**errp
)
312 DeviceState
*dev
= DEVICE(obj
);
313 Property
*prop
= opaque
;
314 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
316 visit_type_uint64(v
, ptr
, name
, errp
);
319 static void set_uint64(Object
*obj
, Visitor
*v
, void *opaque
,
320 const char *name
, Error
**errp
)
322 DeviceState
*dev
= DEVICE(obj
);
323 Property
*prop
= opaque
;
324 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
327 error_set(errp
, QERR_PERMISSION_DENIED
);
331 visit_type_uint64(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
,
385 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
387 return snprintf(dest
, len
, "<null>");
389 return snprintf(dest
, len
, "\"%s\"", *ptr
);
392 static void get_string(Object
*obj
, Visitor
*v
, void *opaque
,
393 const char *name
, Error
**errp
)
395 DeviceState
*dev
= DEVICE(obj
);
396 Property
*prop
= opaque
;
397 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
400 char *str
= (char *)"";
401 visit_type_str(v
, &str
, name
, errp
);
403 visit_type_str(v
, ptr
, name
, errp
);
407 static void set_string(Object
*obj
, Visitor
*v
, void *opaque
,
408 const char *name
, Error
**errp
)
410 DeviceState
*dev
= DEVICE(obj
);
411 Property
*prop
= opaque
;
412 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
413 Error
*local_err
= NULL
;
417 error_set(errp
, QERR_PERMISSION_DENIED
);
421 visit_type_str(v
, &str
, name
, &local_err
);
423 error_propagate(errp
, local_err
);
432 PropertyInfo qdev_prop_string
= {
434 .print
= print_string
,
435 .release
= release_string
,
440 /* --- pointer --- */
442 /* Not a proper property, just for dirty hacks. TODO Remove it! */
443 PropertyInfo qdev_prop_ptr
= {
447 /* --- mac address --- */
450 * accepted syntax versions:
454 static void get_mac(Object
*obj
, Visitor
*v
, void *opaque
,
455 const char *name
, Error
**errp
)
457 DeviceState
*dev
= DEVICE(obj
);
458 Property
*prop
= opaque
;
459 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
460 char buffer
[2 * 6 + 5 + 1];
463 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
464 mac
->a
[0], mac
->a
[1], mac
->a
[2],
465 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
467 visit_type_str(v
, &p
, name
, errp
);
470 static void set_mac(Object
*obj
, Visitor
*v
, void *opaque
,
471 const char *name
, Error
**errp
)
473 DeviceState
*dev
= DEVICE(obj
);
474 Property
*prop
= opaque
;
475 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
476 Error
*local_err
= NULL
;
481 error_set(errp
, QERR_PERMISSION_DENIED
);
485 visit_type_str(v
, &str
, name
, &local_err
);
487 error_propagate(errp
, local_err
);
491 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
492 if (!qemu_isxdigit(str
[pos
])) {
495 if (!qemu_isxdigit(str
[pos
+1])) {
499 if (str
[pos
+2] != '\0') {
503 if (str
[pos
+2] != ':' && str
[pos
+2] != '-') {
507 mac
->a
[i
] = strtol(str
+pos
, &p
, 16);
513 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
517 PropertyInfo qdev_prop_macaddr
= {
523 /* --- lost tick policy --- */
525 static const char *lost_tick_policy_table
[LOST_TICK_MAX
+1] = {
526 [LOST_TICK_DISCARD
] = "discard",
527 [LOST_TICK_DELAY
] = "delay",
528 [LOST_TICK_MERGE
] = "merge",
529 [LOST_TICK_SLEW
] = "slew",
530 [LOST_TICK_MAX
] = NULL
,
533 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
535 PropertyInfo qdev_prop_losttickpolicy
= {
536 .name
= "LostTickPolicy",
537 .enum_table
= lost_tick_policy_table
,
542 /* --- BIOS CHS translation */
544 static const char *bios_chs_trans_table
[] = {
545 [BIOS_ATA_TRANSLATION_AUTO
] = "auto",
546 [BIOS_ATA_TRANSLATION_NONE
] = "none",
547 [BIOS_ATA_TRANSLATION_LBA
] = "lba",
550 PropertyInfo qdev_prop_bios_chs_trans
= {
551 .name
= "bios-chs-trans",
552 .enum_table
= bios_chs_trans_table
,
557 /* --- pci address --- */
560 * bus-local address, i.e. "$slot" or "$slot.$fn"
562 static void set_pci_devfn(Object
*obj
, Visitor
*v
, void *opaque
,
563 const char *name
, Error
**errp
)
565 DeviceState
*dev
= DEVICE(obj
);
566 Property
*prop
= opaque
;
567 int32_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
568 unsigned int slot
, fn
, n
;
569 Error
*local_err
= NULL
;
573 error_set(errp
, QERR_PERMISSION_DENIED
);
577 visit_type_str(v
, &str
, name
, &local_err
);
579 error_free(local_err
);
581 visit_type_int32(v
, &value
, name
, &local_err
);
583 error_propagate(errp
, local_err
);
584 } else if (value
< -1 || value
> 255) {
585 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
593 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
595 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
599 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
602 *ptr
= slot
<< 3 | fn
;
607 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
611 static int print_pci_devfn(DeviceState
*dev
, Property
*prop
, char *dest
,
614 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
617 return snprintf(dest
, len
, "<unset>");
619 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
623 PropertyInfo qdev_prop_pci_devfn
= {
625 .legacy_name
= "pci-devfn",
626 .print
= print_pci_devfn
,
628 .set
= set_pci_devfn
,
631 /* --- blocksize --- */
633 static void set_blocksize(Object
*obj
, Visitor
*v
, void *opaque
,
634 const char *name
, Error
**errp
)
636 DeviceState
*dev
= DEVICE(obj
);
637 Property
*prop
= opaque
;
638 uint16_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
639 Error
*local_err
= NULL
;
640 const int64_t min
= 512;
641 const int64_t max
= 32768;
644 error_set(errp
, QERR_PERMISSION_DENIED
);
648 visit_type_uint16(v
, &value
, name
, &local_err
);
650 error_propagate(errp
, local_err
);
653 if (value
< min
|| value
> max
) {
654 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
655 dev
->id
?:"", name
, (int64_t)value
, min
, max
);
659 /* We rely on power-of-2 blocksizes for bitmasks */
660 if ((value
& (value
- 1)) != 0) {
661 error_set(errp
, QERR_PROPERTY_VALUE_NOT_POWER_OF_2
,
662 dev
->id
?:"", name
, (int64_t)value
);
669 PropertyInfo qdev_prop_blocksize
= {
672 .set
= set_blocksize
,
675 /* --- pci host address --- */
677 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
678 const char *name
, Error
**errp
)
680 DeviceState
*dev
= DEVICE(obj
);
681 Property
*prop
= opaque
;
682 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
683 char buffer
[] = "xxxx:xx:xx.x";
687 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%d",
688 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
689 assert(rc
== sizeof(buffer
) - 1);
691 visit_type_str(v
, &p
, name
, errp
);
695 * Parse [<domain>:]<bus>:<slot>.<func>
696 * if <domain> is not supplied, it's assumed to be 0.
698 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
699 const char *name
, Error
**errp
)
701 DeviceState
*dev
= DEVICE(obj
);
702 Property
*prop
= opaque
;
703 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
704 Error
*local_err
= NULL
;
708 unsigned long dom
= 0, bus
= 0;
709 unsigned int slot
= 0, func
= 0;
712 error_set(errp
, QERR_PERMISSION_DENIED
);
716 visit_type_str(v
, &str
, name
, &local_err
);
718 error_propagate(errp
, local_err
);
723 val
= strtoul(p
, &e
, 16);
724 if (e
== p
|| *e
!= ':') {
730 val
= strtoul(p
, &e
, 16);
738 val
= strtoul(p
, &e
, 16);
749 val
= strtoul(p
, &e
, 10);
755 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
766 addr
->function
= func
;
772 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
776 PropertyInfo qdev_prop_pci_host_devaddr
= {
777 .name
= "pci-host-devaddr",
778 .get
= get_pci_host_devaddr
,
779 .set
= set_pci_host_devaddr
,
782 /* --- support for array properties --- */
784 /* Used as an opaque for the object properties we add for each
785 * array element. Note that the struct Property must be first
786 * in the struct so that a pointer to this works as the opaque
787 * for the underlying element's property hooks as well as for
788 * our own release callback.
791 struct Property prop
;
793 ObjectPropertyRelease
*release
;
794 } ArrayElementProperty
;
796 /* object property release callback for array element properties:
797 * we call the underlying element's property release hook, and
798 * then free the memory we allocated when we added the property.
800 static void array_element_release(Object
*obj
, const char *name
, void *opaque
)
802 ArrayElementProperty
*p
= opaque
;
804 p
->release(obj
, name
, opaque
);
810 static void set_prop_arraylen(Object
*obj
, Visitor
*v
, void *opaque
,
811 const char *name
, Error
**errp
)
813 /* Setter for the property which defines the length of a
814 * variable-sized property array. As well as actually setting the
815 * array-length field in the device struct, we have to create the
816 * array itself and dynamically add the corresponding properties.
818 DeviceState
*dev
= DEVICE(obj
);
819 Property
*prop
= opaque
;
820 uint32_t *alenptr
= qdev_get_prop_ptr(dev
, prop
);
821 void **arrayptr
= (void *)dev
+ prop
->arrayoffset
;
823 const char *arrayname
;
827 error_set(errp
, QERR_PERMISSION_DENIED
);
831 error_setg(errp
, "array size property %s may not be set more than once",
835 visit_type_uint32(v
, alenptr
, name
, errp
);
836 if (error_is_set(errp
)) {
843 /* DEFINE_PROP_ARRAY guarantees that name should start with this prefix;
844 * strip it off so we can get the name of the array itself.
846 assert(strncmp(name
, PROP_ARRAY_LEN_PREFIX
,
847 strlen(PROP_ARRAY_LEN_PREFIX
)) == 0);
848 arrayname
= name
+ strlen(PROP_ARRAY_LEN_PREFIX
);
850 /* Note that it is the responsibility of the individual device's deinit
851 * to free the array proper.
853 *arrayptr
= eltptr
= g_malloc0(*alenptr
* prop
->arrayfieldsize
);
854 for (i
= 0; i
< *alenptr
; i
++, eltptr
+= prop
->arrayfieldsize
) {
855 char *propname
= g_strdup_printf("%s[%d]", arrayname
, i
);
856 ArrayElementProperty
*arrayprop
= g_new0(ArrayElementProperty
, 1);
857 arrayprop
->release
= prop
->arrayinfo
->release
;
858 arrayprop
->propname
= propname
;
859 arrayprop
->prop
.info
= prop
->arrayinfo
;
860 arrayprop
->prop
.name
= propname
;
861 /* This ugly piece of pointer arithmetic sets up the offset so
862 * that when the underlying get/set hooks call qdev_get_prop_ptr
863 * they get the right answer despite the array element not actually
864 * being inside the device struct.
866 arrayprop
->prop
.offset
= eltptr
- (void *)dev
;
867 assert(qdev_get_prop_ptr(dev
, &arrayprop
->prop
) == eltptr
);
868 object_property_add(obj
, propname
,
869 arrayprop
->prop
.info
->name
,
870 arrayprop
->prop
.info
->get
,
871 arrayprop
->prop
.info
->set
,
872 array_element_release
,
874 if (error_is_set(errp
)) {
880 PropertyInfo qdev_prop_arraylen
= {
883 .set
= set_prop_arraylen
,
886 /* --- public helpers --- */
888 static Property
*qdev_prop_walk(Property
*props
, const char *name
)
893 while (props
->name
) {
894 if (strcmp(props
->name
, name
) == 0) {
902 static Property
*qdev_prop_find(DeviceState
*dev
, const char *name
)
907 /* device properties */
908 class = object_get_class(OBJECT(dev
));
910 prop
= qdev_prop_walk(DEVICE_CLASS(class)->props
, name
);
914 class = object_class_get_parent(class);
915 } while (class != object_class_by_name(TYPE_DEVICE
));
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
, const char *value
)
1008 object_property_set_str(OBJECT(dev
), value
, name
, &errp
);
1009 assert_no_error(errp
);
1012 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
)
1015 char str
[2 * 6 + 5 + 1];
1016 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
1017 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
1019 object_property_set_str(OBJECT(dev
), str
, name
, &errp
);
1020 assert_no_error(errp
);
1023 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
)
1028 prop
= qdev_prop_find(dev
, name
);
1029 object_property_set_str(OBJECT(dev
), prop
->info
->enum_table
[value
],
1031 assert_no_error(errp
);
1034 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
)
1039 prop
= qdev_prop_find(dev
, name
);
1040 assert(prop
&& prop
->info
== &qdev_prop_ptr
);
1041 ptr
= qdev_get_prop_ptr(dev
, prop
);
1045 static QTAILQ_HEAD(, GlobalProperty
) global_props
=
1046 QTAILQ_HEAD_INITIALIZER(global_props
);
1048 void qdev_prop_register_global(GlobalProperty
*prop
)
1050 QTAILQ_INSERT_TAIL(&global_props
, prop
, next
);
1053 void qdev_prop_register_global_list(GlobalProperty
*props
)
1057 for (i
= 0; props
[i
].driver
!= NULL
; i
++) {
1058 qdev_prop_register_global(props
+i
);
1062 void qdev_prop_set_globals(DeviceState
*dev
)
1064 ObjectClass
*class = object_get_class(OBJECT(dev
));
1067 GlobalProperty
*prop
;
1068 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1069 if (strcmp(object_class_get_name(class), prop
->driver
) != 0) {
1072 if (qdev_prop_parse(dev
, prop
->property
, prop
->value
) != 0) {
1076 class = object_class_get_parent(class);