1 #include "qemu/osdep.h"
4 #include "qapi/qmp/qerror.h"
5 #include "qemu/error-report.h"
6 #include "sysemu/block-backend.h"
7 #include "hw/block/block.h"
9 #include "qapi/visitor.h"
10 #include "sysemu/char.h"
12 void qdev_prop_set_after_realize(DeviceState
*dev
, const char *name
,
16 error_setg(errp
, "Attempt to set property '%s' on device '%s' "
17 "(type '%s') after it was realized", name
, dev
->id
,
18 object_get_typename(OBJECT(dev
)));
20 error_setg(errp
, "Attempt to set property '%s' on anonymous device "
21 "(type '%s') after it was realized", name
,
22 object_get_typename(OBJECT(dev
)));
26 void qdev_prop_allow_set_link_before_realize(Object
*obj
, const char *name
,
27 Object
*val
, Error
**errp
)
29 DeviceState
*dev
= DEVICE(obj
);
32 error_setg(errp
, "Attempt to set link property '%s' on device '%s' "
33 "(type '%s') after it was realized",
34 name
, dev
->id
, object_get_typename(obj
));
38 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
)
45 static void get_enum(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
48 DeviceState
*dev
= DEVICE(obj
);
49 Property
*prop
= opaque
;
50 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
52 visit_type_enum(v
, prop
->name
, ptr
, prop
->info
->enum_table
, errp
);
55 static void set_enum(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
58 DeviceState
*dev
= DEVICE(obj
);
59 Property
*prop
= opaque
;
60 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
63 qdev_prop_set_after_realize(dev
, name
, errp
);
67 visit_type_enum(v
, prop
->name
, ptr
, prop
->info
->enum_table
, errp
);
72 static uint32_t qdev_get_prop_mask(Property
*prop
)
74 assert(prop
->info
== &qdev_prop_bit
);
75 return 0x1 << prop
->bitnr
;
78 static void bit_prop_set(DeviceState
*dev
, Property
*props
, bool val
)
80 uint32_t *p
= qdev_get_prop_ptr(dev
, props
);
81 uint32_t mask
= qdev_get_prop_mask(props
);
89 static void prop_get_bit(Object
*obj
, Visitor
*v
, const char *name
,
90 void *opaque
, Error
**errp
)
92 DeviceState
*dev
= DEVICE(obj
);
93 Property
*prop
= opaque
;
94 uint32_t *p
= qdev_get_prop_ptr(dev
, prop
);
95 bool value
= (*p
& qdev_get_prop_mask(prop
)) != 0;
97 visit_type_bool(v
, name
, &value
, errp
);
100 static void prop_set_bit(Object
*obj
, Visitor
*v
, const char *name
,
101 void *opaque
, Error
**errp
)
103 DeviceState
*dev
= DEVICE(obj
);
104 Property
*prop
= opaque
;
105 Error
*local_err
= NULL
;
109 qdev_prop_set_after_realize(dev
, name
, errp
);
113 visit_type_bool(v
, name
, &value
, &local_err
);
115 error_propagate(errp
, local_err
);
118 bit_prop_set(dev
, prop
, value
);
121 PropertyInfo qdev_prop_bit
= {
123 .description
= "on/off",
130 static uint64_t qdev_get_prop_mask64(Property
*prop
)
132 assert(prop
->info
== &qdev_prop_bit64
);
133 return 0x1ull
<< prop
->bitnr
;
136 static void bit64_prop_set(DeviceState
*dev
, Property
*props
, bool val
)
138 uint64_t *p
= qdev_get_prop_ptr(dev
, props
);
139 uint64_t mask
= qdev_get_prop_mask64(props
);
147 static void prop_get_bit64(Object
*obj
, Visitor
*v
, const char *name
,
148 void *opaque
, Error
**errp
)
150 DeviceState
*dev
= DEVICE(obj
);
151 Property
*prop
= opaque
;
152 uint64_t *p
= qdev_get_prop_ptr(dev
, prop
);
153 bool value
= (*p
& qdev_get_prop_mask64(prop
)) != 0;
155 visit_type_bool(v
, name
, &value
, errp
);
158 static void prop_set_bit64(Object
*obj
, Visitor
*v
, const char *name
,
159 void *opaque
, Error
**errp
)
161 DeviceState
*dev
= DEVICE(obj
);
162 Property
*prop
= opaque
;
163 Error
*local_err
= NULL
;
167 qdev_prop_set_after_realize(dev
, name
, errp
);
171 visit_type_bool(v
, name
, &value
, &local_err
);
173 error_propagate(errp
, local_err
);
176 bit64_prop_set(dev
, prop
, value
);
179 PropertyInfo qdev_prop_bit64
= {
181 .description
= "on/off",
182 .get
= prop_get_bit64
,
183 .set
= prop_set_bit64
,
188 static void get_bool(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
191 DeviceState
*dev
= DEVICE(obj
);
192 Property
*prop
= opaque
;
193 bool *ptr
= qdev_get_prop_ptr(dev
, prop
);
195 visit_type_bool(v
, name
, ptr
, errp
);
198 static void set_bool(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
201 DeviceState
*dev
= DEVICE(obj
);
202 Property
*prop
= opaque
;
203 bool *ptr
= qdev_get_prop_ptr(dev
, prop
);
206 qdev_prop_set_after_realize(dev
, name
, errp
);
210 visit_type_bool(v
, name
, ptr
, errp
);
213 PropertyInfo qdev_prop_bool
= {
219 /* --- 8bit integer --- */
221 static void get_uint8(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
224 DeviceState
*dev
= DEVICE(obj
);
225 Property
*prop
= opaque
;
226 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
228 visit_type_uint8(v
, name
, ptr
, errp
);
231 static void set_uint8(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
234 DeviceState
*dev
= DEVICE(obj
);
235 Property
*prop
= opaque
;
236 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
239 qdev_prop_set_after_realize(dev
, name
, errp
);
243 visit_type_uint8(v
, name
, ptr
, errp
);
246 PropertyInfo qdev_prop_uint8
= {
252 /* --- 16bit integer --- */
254 static void get_uint16(Object
*obj
, Visitor
*v
, const char *name
,
255 void *opaque
, Error
**errp
)
257 DeviceState
*dev
= DEVICE(obj
);
258 Property
*prop
= opaque
;
259 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
261 visit_type_uint16(v
, name
, ptr
, errp
);
264 static void set_uint16(Object
*obj
, Visitor
*v
, const char *name
,
265 void *opaque
, Error
**errp
)
267 DeviceState
*dev
= DEVICE(obj
);
268 Property
*prop
= opaque
;
269 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
272 qdev_prop_set_after_realize(dev
, name
, errp
);
276 visit_type_uint16(v
, name
, ptr
, errp
);
279 PropertyInfo qdev_prop_uint16
= {
285 /* --- 32bit integer --- */
287 static void get_uint32(Object
*obj
, Visitor
*v
, const char *name
,
288 void *opaque
, Error
**errp
)
290 DeviceState
*dev
= DEVICE(obj
);
291 Property
*prop
= opaque
;
292 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
294 visit_type_uint32(v
, name
, ptr
, errp
);
297 static void set_uint32(Object
*obj
, Visitor
*v
, const char *name
,
298 void *opaque
, Error
**errp
)
300 DeviceState
*dev
= DEVICE(obj
);
301 Property
*prop
= opaque
;
302 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
305 qdev_prop_set_after_realize(dev
, name
, errp
);
309 visit_type_uint32(v
, name
, ptr
, errp
);
312 static void get_int32(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
315 DeviceState
*dev
= DEVICE(obj
);
316 Property
*prop
= opaque
;
317 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
319 visit_type_int32(v
, name
, ptr
, errp
);
322 static void set_int32(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
325 DeviceState
*dev
= DEVICE(obj
);
326 Property
*prop
= opaque
;
327 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
330 qdev_prop_set_after_realize(dev
, name
, errp
);
334 visit_type_int32(v
, name
, ptr
, errp
);
337 PropertyInfo qdev_prop_uint32
= {
343 PropertyInfo qdev_prop_int32
= {
349 /* --- 64bit integer --- */
351 static void get_uint64(Object
*obj
, Visitor
*v
, const char *name
,
352 void *opaque
, Error
**errp
)
354 DeviceState
*dev
= DEVICE(obj
);
355 Property
*prop
= opaque
;
356 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
358 visit_type_uint64(v
, name
, ptr
, errp
);
361 static void set_uint64(Object
*obj
, Visitor
*v
, const char *name
,
362 void *opaque
, Error
**errp
)
364 DeviceState
*dev
= DEVICE(obj
);
365 Property
*prop
= opaque
;
366 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
369 qdev_prop_set_after_realize(dev
, name
, errp
);
373 visit_type_uint64(v
, name
, ptr
, errp
);
376 PropertyInfo qdev_prop_uint64
= {
384 static void release_string(Object
*obj
, const char *name
, void *opaque
)
386 Property
*prop
= opaque
;
387 g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj
), prop
));
390 static void get_string(Object
*obj
, Visitor
*v
, const char *name
,
391 void *opaque
, 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
, name
, &str
, errp
);
401 visit_type_str(v
, name
, ptr
, errp
);
405 static void set_string(Object
*obj
, Visitor
*v
, const char *name
,
406 void *opaque
, 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
;
415 qdev_prop_set_after_realize(dev
, name
, errp
);
419 visit_type_str(v
, name
, &str
, &local_err
);
421 error_propagate(errp
, local_err
);
428 PropertyInfo qdev_prop_string
= {
430 .release
= release_string
,
435 /* --- pointer --- */
437 /* Not a proper property, just for dirty hacks. TODO Remove it! */
438 PropertyInfo qdev_prop_ptr
= {
442 /* --- mac address --- */
445 * accepted syntax versions:
449 static void get_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
452 DeviceState
*dev
= DEVICE(obj
);
453 Property
*prop
= opaque
;
454 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
455 char buffer
[2 * 6 + 5 + 1];
458 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
459 mac
->a
[0], mac
->a
[1], mac
->a
[2],
460 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
462 visit_type_str(v
, name
, &p
, errp
);
465 static void set_mac(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
468 DeviceState
*dev
= DEVICE(obj
);
469 Property
*prop
= opaque
;
470 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
471 Error
*local_err
= NULL
;
476 qdev_prop_set_after_realize(dev
, name
, errp
);
480 visit_type_str(v
, name
, &str
, &local_err
);
482 error_propagate(errp
, local_err
);
486 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
487 if (!qemu_isxdigit(str
[pos
])) {
490 if (!qemu_isxdigit(str
[pos
+1])) {
494 if (str
[pos
+2] != '\0') {
498 if (str
[pos
+2] != ':' && str
[pos
+2] != '-') {
502 mac
->a
[i
] = strtol(str
+pos
, &p
, 16);
508 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
512 PropertyInfo qdev_prop_macaddr
= {
514 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
519 /* --- on/off/auto --- */
521 PropertyInfo qdev_prop_on_off_auto
= {
523 .description
= "on/off/auto",
524 .enum_table
= OnOffAuto_lookup
,
529 /* --- lost tick policy --- */
531 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
533 PropertyInfo qdev_prop_losttickpolicy
= {
534 .name
= "LostTickPolicy",
535 .enum_table
= LostTickPolicy_lookup
,
540 /* --- BIOS CHS translation */
542 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
544 PropertyInfo qdev_prop_bios_chs_trans
= {
545 .name
= "BiosAtaTranslation",
546 .description
= "Logical CHS translation algorithm, "
547 "auto/none/lba/large/rechs",
548 .enum_table
= BiosAtaTranslation_lookup
,
553 /* --- FDC default drive types */
555 PropertyInfo qdev_prop_fdc_drive_type
= {
556 .name
= "FdcDriveType",
557 .description
= "FDC drive type, "
558 "144/288/120/none/auto",
559 .enum_table
= FloppyDriveType_lookup
,
564 /* --- pci address --- */
567 * bus-local address, i.e. "$slot" or "$slot.$fn"
569 static void set_pci_devfn(Object
*obj
, Visitor
*v
, const char *name
,
570 void *opaque
, Error
**errp
)
572 DeviceState
*dev
= DEVICE(obj
);
573 Property
*prop
= opaque
;
574 int32_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
575 unsigned int slot
, fn
, n
;
576 Error
*local_err
= NULL
;
580 qdev_prop_set_after_realize(dev
, name
, errp
);
584 visit_type_str(v
, name
, &str
, &local_err
);
586 error_free(local_err
);
588 visit_type_int32(v
, name
, &value
, &local_err
);
590 error_propagate(errp
, local_err
);
591 } else if (value
< -1 || value
> 255) {
592 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
593 name
? name
: "null", "pci_devfn");
600 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
602 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
606 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
609 *ptr
= slot
<< 3 | fn
;
614 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
618 static int print_pci_devfn(DeviceState
*dev
, Property
*prop
, char *dest
,
621 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
624 return snprintf(dest
, len
, "<unset>");
626 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
630 PropertyInfo qdev_prop_pci_devfn
= {
632 .description
= "Slot and optional function number, example: 06.0 or 06",
633 .print
= print_pci_devfn
,
635 .set
= set_pci_devfn
,
638 /* --- blocksize --- */
640 static void set_blocksize(Object
*obj
, Visitor
*v
, const char *name
,
641 void *opaque
, Error
**errp
)
643 DeviceState
*dev
= DEVICE(obj
);
644 Property
*prop
= opaque
;
645 uint16_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
646 Error
*local_err
= NULL
;
647 const int64_t min
= 512;
648 const int64_t max
= 32768;
651 qdev_prop_set_after_realize(dev
, name
, errp
);
655 visit_type_uint16(v
, name
, &value
, &local_err
);
657 error_propagate(errp
, local_err
);
660 /* value of 0 means "unset" */
661 if (value
&& (value
< min
|| value
> max
)) {
662 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
663 dev
->id
? : "", name
, (int64_t)value
, min
, max
);
667 /* We rely on power-of-2 blocksizes for bitmasks */
668 if ((value
& (value
- 1)) != 0) {
670 "Property %s.%s doesn't take value '%" PRId64
"', it's not a power of 2",
671 dev
->id
?: "", name
, (int64_t)value
);
678 PropertyInfo qdev_prop_blocksize
= {
680 .description
= "A power of two between 512 and 32768",
682 .set
= set_blocksize
,
685 /* --- pci host address --- */
687 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
688 void *opaque
, Error
**errp
)
690 DeviceState
*dev
= DEVICE(obj
);
691 Property
*prop
= opaque
;
692 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
693 char buffer
[] = "xxxx:xx:xx.x";
697 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%d",
698 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
699 assert(rc
== sizeof(buffer
) - 1);
701 visit_type_str(v
, name
, &p
, errp
);
705 * Parse [<domain>:]<bus>:<slot>.<func>
706 * if <domain> is not supplied, it's assumed to be 0.
708 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, const char *name
,
709 void *opaque
, Error
**errp
)
711 DeviceState
*dev
= DEVICE(obj
);
712 Property
*prop
= opaque
;
713 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
714 Error
*local_err
= NULL
;
718 unsigned long dom
= 0, bus
= 0;
719 unsigned int slot
= 0, func
= 0;
722 qdev_prop_set_after_realize(dev
, name
, errp
);
726 visit_type_str(v
, name
, &str
, &local_err
);
728 error_propagate(errp
, local_err
);
733 val
= strtoul(p
, &e
, 16);
734 if (e
== p
|| *e
!= ':') {
740 val
= strtoul(p
, &e
, 16);
748 val
= strtoul(p
, &e
, 16);
759 val
= strtoul(p
, &e
, 10);
765 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
776 addr
->function
= func
;
782 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
786 PropertyInfo qdev_prop_pci_host_devaddr
= {
788 .description
= "Address (bus/device/function) of "
789 "the host device, example: 04:10.0",
790 .get
= get_pci_host_devaddr
,
791 .set
= set_pci_host_devaddr
,
794 /* --- support for array properties --- */
796 /* Used as an opaque for the object properties we add for each
797 * array element. Note that the struct Property must be first
798 * in the struct so that a pointer to this works as the opaque
799 * for the underlying element's property hooks as well as for
800 * our own release callback.
803 struct Property prop
;
805 ObjectPropertyRelease
*release
;
806 } ArrayElementProperty
;
808 /* object property release callback for array element properties:
809 * we call the underlying element's property release hook, and
810 * then free the memory we allocated when we added the property.
812 static void array_element_release(Object
*obj
, const char *name
, void *opaque
)
814 ArrayElementProperty
*p
= opaque
;
816 p
->release(obj
, name
, opaque
);
822 static void set_prop_arraylen(Object
*obj
, Visitor
*v
, const char *name
,
823 void *opaque
, Error
**errp
)
825 /* Setter for the property which defines the length of a
826 * variable-sized property array. As well as actually setting the
827 * array-length field in the device struct, we have to create the
828 * array itself and dynamically add the corresponding properties.
830 DeviceState
*dev
= DEVICE(obj
);
831 Property
*prop
= opaque
;
832 uint32_t *alenptr
= qdev_get_prop_ptr(dev
, prop
);
833 void **arrayptr
= (void *)dev
+ prop
->arrayoffset
;
834 Error
*local_err
= NULL
;
836 const char *arrayname
;
840 qdev_prop_set_after_realize(dev
, name
, errp
);
844 error_setg(errp
, "array size property %s may not be set more than once",
848 visit_type_uint32(v
, name
, alenptr
, &local_err
);
850 error_propagate(errp
, local_err
);
857 /* DEFINE_PROP_ARRAY guarantees that name should start with this prefix;
858 * strip it off so we can get the name of the array itself.
860 assert(strncmp(name
, PROP_ARRAY_LEN_PREFIX
,
861 strlen(PROP_ARRAY_LEN_PREFIX
)) == 0);
862 arrayname
= name
+ strlen(PROP_ARRAY_LEN_PREFIX
);
864 /* Note that it is the responsibility of the individual device's deinit
865 * to free the array proper.
867 *arrayptr
= eltptr
= g_malloc0(*alenptr
* prop
->arrayfieldsize
);
868 for (i
= 0; i
< *alenptr
; i
++, eltptr
+= prop
->arrayfieldsize
) {
869 char *propname
= g_strdup_printf("%s[%d]", arrayname
, i
);
870 ArrayElementProperty
*arrayprop
= g_new0(ArrayElementProperty
, 1);
871 arrayprop
->release
= prop
->arrayinfo
->release
;
872 arrayprop
->propname
= propname
;
873 arrayprop
->prop
.info
= prop
->arrayinfo
;
874 arrayprop
->prop
.name
= propname
;
875 /* This ugly piece of pointer arithmetic sets up the offset so
876 * that when the underlying get/set hooks call qdev_get_prop_ptr
877 * they get the right answer despite the array element not actually
878 * being inside the device struct.
880 arrayprop
->prop
.offset
= eltptr
- (void *)dev
;
881 assert(qdev_get_prop_ptr(dev
, &arrayprop
->prop
) == eltptr
);
882 object_property_add(obj
, propname
,
883 arrayprop
->prop
.info
->name
,
884 arrayprop
->prop
.info
->get
,
885 arrayprop
->prop
.info
->set
,
886 array_element_release
,
887 arrayprop
, &local_err
);
889 error_propagate(errp
, local_err
);
895 PropertyInfo qdev_prop_arraylen
= {
898 .set
= set_prop_arraylen
,
901 /* --- public helpers --- */
903 static Property
*qdev_prop_walk(Property
*props
, const char *name
)
908 while (props
->name
) {
909 if (strcmp(props
->name
, name
) == 0) {
917 static Property
*qdev_prop_find(DeviceState
*dev
, const char *name
)
922 /* device properties */
923 class = object_get_class(OBJECT(dev
));
925 prop
= qdev_prop_walk(DEVICE_CLASS(class)->props
, name
);
929 class = object_class_get_parent(class);
930 } while (class != object_class_by_name(TYPE_DEVICE
));
935 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
936 Property
*prop
, const char *value
)
940 error_setg(errp
, "Property '%s.%s' can't take value '%s', it's in use",
941 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
945 error_setg(errp
, QERR_PROPERTY_VALUE_BAD
,
946 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
949 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
950 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
957 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
)
959 object_property_set_bool(OBJECT(dev
), value
, name
, &error_abort
);
962 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
)
964 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
967 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
)
969 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
972 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
)
974 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
977 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
)
979 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
982 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
)
984 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
987 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
)
989 object_property_set_str(OBJECT(dev
), value
, name
, &error_abort
);
992 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
)
994 char str
[2 * 6 + 5 + 1];
995 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
996 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
998 object_property_set_str(OBJECT(dev
), str
, name
, &error_abort
);
1001 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
)
1005 prop
= qdev_prop_find(dev
, name
);
1006 object_property_set_str(OBJECT(dev
), prop
->info
->enum_table
[value
],
1007 name
, &error_abort
);
1010 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
)
1015 prop
= qdev_prop_find(dev
, name
);
1016 assert(prop
&& prop
->info
== &qdev_prop_ptr
);
1017 ptr
= qdev_get_prop_ptr(dev
, prop
);
1021 static QTAILQ_HEAD(, GlobalProperty
) global_props
=
1022 QTAILQ_HEAD_INITIALIZER(global_props
);
1024 void qdev_prop_register_global(GlobalProperty
*prop
)
1026 QTAILQ_INSERT_TAIL(&global_props
, prop
, next
);
1029 void qdev_prop_register_global_list(GlobalProperty
*props
)
1033 for (i
= 0; props
[i
].driver
!= NULL
; i
++) {
1034 qdev_prop_register_global(props
+i
);
1038 int qdev_prop_check_globals(void)
1040 GlobalProperty
*prop
;
1043 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1049 if (!prop
->user_provided
) {
1052 oc
= object_class_by_name(prop
->driver
);
1053 oc
= object_class_dynamic_cast(oc
, TYPE_DEVICE
);
1055 error_report("Warning: global %s.%s has invalid class name",
1056 prop
->driver
, prop
->property
);
1060 dc
= DEVICE_CLASS(oc
);
1061 if (!dc
->hotpluggable
&& !prop
->used
) {
1062 error_report("Warning: global %s.%s=%s not used",
1063 prop
->driver
, prop
->property
, prop
->value
);
1071 static void qdev_prop_set_globals_for_type(DeviceState
*dev
,
1072 const char *typename
)
1074 GlobalProperty
*prop
;
1076 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1079 if (strcmp(typename
, prop
->driver
) != 0) {
1083 object_property_parse(OBJECT(dev
), prop
->value
, prop
->property
, &err
);
1085 assert(prop
->user_provided
);
1086 error_reportf_err(err
, "Warning: global %s.%s=%s ignored: ",
1087 prop
->driver
, prop
->property
, prop
->value
);
1093 void qdev_prop_set_globals(DeviceState
*dev
)
1095 ObjectClass
*class = object_get_class(OBJECT(dev
));
1098 qdev_prop_set_globals_for_type(dev
, object_class_get_name(class));
1099 class = object_class_get_parent(class);
1103 /* --- 64bit unsigned int 'size' type --- */
1105 static void get_size(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1108 DeviceState
*dev
= DEVICE(obj
);
1109 Property
*prop
= opaque
;
1110 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1112 visit_type_size(v
, name
, ptr
, errp
);
1115 static void set_size(Object
*obj
, Visitor
*v
, const char *name
, void *opaque
,
1118 DeviceState
*dev
= DEVICE(obj
);
1119 Property
*prop
= opaque
;
1120 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1122 visit_type_size(v
, name
, ptr
, errp
);
1125 PropertyInfo qdev_prop_size
= {