3 #include "qapi/qmp/qerror.h"
4 #include "sysemu/block-backend.h"
5 #include "hw/block/block.h"
7 #include "qapi/visitor.h"
8 #include "sysemu/char.h"
10 void qdev_prop_set_after_realize(DeviceState
*dev
, const char *name
,
14 error_setg(errp
, "Attempt to set property '%s' on device '%s' "
15 "(type '%s') after it was realized", name
, dev
->id
,
16 object_get_typename(OBJECT(dev
)));
18 error_setg(errp
, "Attempt to set property '%s' on anonymous device "
19 "(type '%s') after it was realized", name
,
20 object_get_typename(OBJECT(dev
)));
24 void qdev_prop_allow_set_link_before_realize(Object
*obj
, const char *name
,
25 Object
*val
, Error
**errp
)
27 DeviceState
*dev
= DEVICE(obj
);
30 error_setg(errp
, "Attempt to set link property '%s' on device '%s' "
31 "(type '%s') after it was realized",
32 name
, dev
->id
, object_get_typename(obj
));
36 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
)
43 static void get_enum(Object
*obj
, Visitor
*v
, void *opaque
,
44 const char *name
, Error
**errp
)
46 DeviceState
*dev
= DEVICE(obj
);
47 Property
*prop
= opaque
;
48 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
50 visit_type_enum(v
, ptr
, prop
->info
->enum_table
,
51 prop
->info
->name
, prop
->name
, errp
);
54 static void set_enum(Object
*obj
, Visitor
*v
, void *opaque
,
55 const char *name
, Error
**errp
)
57 DeviceState
*dev
= DEVICE(obj
);
58 Property
*prop
= opaque
;
59 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
62 qdev_prop_set_after_realize(dev
, name
, errp
);
66 visit_type_enum(v
, ptr
, prop
->info
->enum_table
,
67 prop
->info
->name
, prop
->name
, 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
, void *opaque
,
90 const char *name
, 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
, &value
, name
, errp
);
100 static void prop_set_bit(Object
*obj
, Visitor
*v
, void *opaque
,
101 const char *name
, 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
, &value
, name
, &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 void get_bool(Object
*obj
, Visitor
*v
, void *opaque
,
131 const char *name
, Error
**errp
)
133 DeviceState
*dev
= DEVICE(obj
);
134 Property
*prop
= opaque
;
135 bool *ptr
= qdev_get_prop_ptr(dev
, prop
);
137 visit_type_bool(v
, ptr
, name
, errp
);
140 static void set_bool(Object
*obj
, Visitor
*v
, void *opaque
,
141 const char *name
, Error
**errp
)
143 DeviceState
*dev
= DEVICE(obj
);
144 Property
*prop
= opaque
;
145 bool *ptr
= qdev_get_prop_ptr(dev
, prop
);
148 qdev_prop_set_after_realize(dev
, name
, errp
);
152 visit_type_bool(v
, ptr
, name
, errp
);
155 PropertyInfo qdev_prop_bool
= {
161 /* --- 8bit integer --- */
163 static void get_uint8(Object
*obj
, Visitor
*v
, void *opaque
,
164 const char *name
, Error
**errp
)
166 DeviceState
*dev
= DEVICE(obj
);
167 Property
*prop
= opaque
;
168 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
170 visit_type_uint8(v
, ptr
, name
, errp
);
173 static void set_uint8(Object
*obj
, Visitor
*v
, void *opaque
,
174 const char *name
, Error
**errp
)
176 DeviceState
*dev
= DEVICE(obj
);
177 Property
*prop
= opaque
;
178 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
181 qdev_prop_set_after_realize(dev
, name
, errp
);
185 visit_type_uint8(v
, ptr
, name
, errp
);
188 PropertyInfo qdev_prop_uint8
= {
194 /* --- 16bit integer --- */
196 static void get_uint16(Object
*obj
, Visitor
*v
, void *opaque
,
197 const char *name
, Error
**errp
)
199 DeviceState
*dev
= DEVICE(obj
);
200 Property
*prop
= opaque
;
201 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
203 visit_type_uint16(v
, ptr
, name
, errp
);
206 static void set_uint16(Object
*obj
, Visitor
*v
, void *opaque
,
207 const char *name
, Error
**errp
)
209 DeviceState
*dev
= DEVICE(obj
);
210 Property
*prop
= opaque
;
211 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
214 qdev_prop_set_after_realize(dev
, name
, errp
);
218 visit_type_uint16(v
, ptr
, name
, errp
);
221 PropertyInfo qdev_prop_uint16
= {
227 /* --- 32bit integer --- */
229 static void get_uint32(Object
*obj
, Visitor
*v
, void *opaque
,
230 const char *name
, Error
**errp
)
232 DeviceState
*dev
= DEVICE(obj
);
233 Property
*prop
= opaque
;
234 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
236 visit_type_uint32(v
, ptr
, name
, errp
);
239 static void set_uint32(Object
*obj
, Visitor
*v
, void *opaque
,
240 const char *name
, Error
**errp
)
242 DeviceState
*dev
= DEVICE(obj
);
243 Property
*prop
= opaque
;
244 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
247 qdev_prop_set_after_realize(dev
, name
, errp
);
251 visit_type_uint32(v
, ptr
, name
, errp
);
254 static void get_int32(Object
*obj
, Visitor
*v
, void *opaque
,
255 const char *name
, Error
**errp
)
257 DeviceState
*dev
= DEVICE(obj
);
258 Property
*prop
= opaque
;
259 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
261 visit_type_int32(v
, ptr
, name
, errp
);
264 static void set_int32(Object
*obj
, Visitor
*v
, void *opaque
,
265 const char *name
, Error
**errp
)
267 DeviceState
*dev
= DEVICE(obj
);
268 Property
*prop
= opaque
;
269 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
272 qdev_prop_set_after_realize(dev
, name
, errp
);
276 visit_type_int32(v
, ptr
, name
, errp
);
279 PropertyInfo qdev_prop_uint32
= {
285 PropertyInfo qdev_prop_int32
= {
291 /* --- 64bit integer --- */
293 static void get_uint64(Object
*obj
, Visitor
*v
, void *opaque
,
294 const char *name
, Error
**errp
)
296 DeviceState
*dev
= DEVICE(obj
);
297 Property
*prop
= opaque
;
298 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
300 visit_type_uint64(v
, ptr
, name
, errp
);
303 static void set_uint64(Object
*obj
, Visitor
*v
, void *opaque
,
304 const char *name
, Error
**errp
)
306 DeviceState
*dev
= DEVICE(obj
);
307 Property
*prop
= opaque
;
308 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
311 qdev_prop_set_after_realize(dev
, name
, errp
);
315 visit_type_uint64(v
, ptr
, name
, errp
);
318 PropertyInfo qdev_prop_uint64
= {
326 static void release_string(Object
*obj
, const char *name
, void *opaque
)
328 Property
*prop
= opaque
;
329 g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj
), prop
));
332 static void get_string(Object
*obj
, Visitor
*v
, void *opaque
,
333 const char *name
, Error
**errp
)
335 DeviceState
*dev
= DEVICE(obj
);
336 Property
*prop
= opaque
;
337 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
340 char *str
= (char *)"";
341 visit_type_str(v
, &str
, name
, errp
);
343 visit_type_str(v
, ptr
, name
, errp
);
347 static void set_string(Object
*obj
, Visitor
*v
, void *opaque
,
348 const char *name
, Error
**errp
)
350 DeviceState
*dev
= DEVICE(obj
);
351 Property
*prop
= opaque
;
352 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
353 Error
*local_err
= NULL
;
357 qdev_prop_set_after_realize(dev
, name
, errp
);
361 visit_type_str(v
, &str
, name
, &local_err
);
363 error_propagate(errp
, local_err
);
372 PropertyInfo qdev_prop_string
= {
374 .release
= release_string
,
379 /* --- pointer --- */
381 /* Not a proper property, just for dirty hacks. TODO Remove it! */
382 PropertyInfo qdev_prop_ptr
= {
386 /* --- mac address --- */
389 * accepted syntax versions:
393 static void get_mac(Object
*obj
, Visitor
*v
, void *opaque
,
394 const char *name
, Error
**errp
)
396 DeviceState
*dev
= DEVICE(obj
);
397 Property
*prop
= opaque
;
398 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
399 char buffer
[2 * 6 + 5 + 1];
402 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
403 mac
->a
[0], mac
->a
[1], mac
->a
[2],
404 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
406 visit_type_str(v
, &p
, name
, errp
);
409 static void set_mac(Object
*obj
, Visitor
*v
, void *opaque
,
410 const char *name
, Error
**errp
)
412 DeviceState
*dev
= DEVICE(obj
);
413 Property
*prop
= opaque
;
414 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
415 Error
*local_err
= NULL
;
420 qdev_prop_set_after_realize(dev
, name
, errp
);
424 visit_type_str(v
, &str
, name
, &local_err
);
426 error_propagate(errp
, local_err
);
430 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
431 if (!qemu_isxdigit(str
[pos
])) {
434 if (!qemu_isxdigit(str
[pos
+1])) {
438 if (str
[pos
+2] != '\0') {
442 if (str
[pos
+2] != ':' && str
[pos
+2] != '-') {
446 mac
->a
[i
] = strtol(str
+pos
, &p
, 16);
452 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
456 PropertyInfo qdev_prop_macaddr
= {
458 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
463 /* --- lost tick policy --- */
465 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
467 PropertyInfo qdev_prop_losttickpolicy
= {
468 .name
= "LostTickPolicy",
469 .enum_table
= LostTickPolicy_lookup
,
474 /* --- BIOS CHS translation */
476 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
478 PropertyInfo qdev_prop_bios_chs_trans
= {
479 .name
= "BiosAtaTranslation",
480 .description
= "Logical CHS translation algorithm, "
481 "auto/none/lba/large/rechs",
482 .enum_table
= BiosAtaTranslation_lookup
,
487 /* --- pci address --- */
490 * bus-local address, i.e. "$slot" or "$slot.$fn"
492 static void set_pci_devfn(Object
*obj
, Visitor
*v
, void *opaque
,
493 const char *name
, Error
**errp
)
495 DeviceState
*dev
= DEVICE(obj
);
496 Property
*prop
= opaque
;
497 int32_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
498 unsigned int slot
, fn
, n
;
499 Error
*local_err
= NULL
;
503 qdev_prop_set_after_realize(dev
, name
, errp
);
507 visit_type_str(v
, &str
, name
, &local_err
);
509 error_free(local_err
);
511 visit_type_int32(v
, &value
, name
, &local_err
);
513 error_propagate(errp
, local_err
);
514 } else if (value
< -1 || value
> 255) {
515 error_set(errp
, QERR_INVALID_PARAMETER_VALUE
, name
? name
: "null",
523 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
525 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
529 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
532 *ptr
= slot
<< 3 | fn
;
537 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
541 static int print_pci_devfn(DeviceState
*dev
, Property
*prop
, char *dest
,
544 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
547 return snprintf(dest
, len
, "<unset>");
549 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
553 PropertyInfo qdev_prop_pci_devfn
= {
555 .description
= "Slot and optional function number, example: 06.0 or 06",
556 .print
= print_pci_devfn
,
558 .set
= set_pci_devfn
,
561 /* --- blocksize --- */
563 static void set_blocksize(Object
*obj
, Visitor
*v
, void *opaque
,
564 const char *name
, Error
**errp
)
566 DeviceState
*dev
= DEVICE(obj
);
567 Property
*prop
= opaque
;
568 uint16_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
569 Error
*local_err
= NULL
;
570 const int64_t min
= 512;
571 const int64_t max
= 32768;
574 qdev_prop_set_after_realize(dev
, name
, errp
);
578 visit_type_uint16(v
, &value
, name
, &local_err
);
580 error_propagate(errp
, local_err
);
583 /* value of 0 means "unset" */
584 if (value
&& (value
< min
|| value
> max
)) {
585 error_set(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
586 dev
->id
?:"", name
, (int64_t)value
, min
, max
);
590 /* We rely on power-of-2 blocksizes for bitmasks */
591 if ((value
& (value
- 1)) != 0) {
593 "Property %s.%s doesn't take value '%" PRId64
"', it's not a power of 2",
594 dev
->id
?: "", name
, (int64_t)value
);
601 PropertyInfo qdev_prop_blocksize
= {
603 .description
= "A power of two between 512 and 32768",
605 .set
= set_blocksize
,
608 /* --- pci host address --- */
610 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
611 const char *name
, Error
**errp
)
613 DeviceState
*dev
= DEVICE(obj
);
614 Property
*prop
= opaque
;
615 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
616 char buffer
[] = "xxxx:xx:xx.x";
620 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%d",
621 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
622 assert(rc
== sizeof(buffer
) - 1);
624 visit_type_str(v
, &p
, name
, errp
);
628 * Parse [<domain>:]<bus>:<slot>.<func>
629 * if <domain> is not supplied, it's assumed to be 0.
631 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
632 const char *name
, Error
**errp
)
634 DeviceState
*dev
= DEVICE(obj
);
635 Property
*prop
= opaque
;
636 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
637 Error
*local_err
= NULL
;
641 unsigned long dom
= 0, bus
= 0;
642 unsigned int slot
= 0, func
= 0;
645 qdev_prop_set_after_realize(dev
, name
, errp
);
649 visit_type_str(v
, &str
, name
, &local_err
);
651 error_propagate(errp
, local_err
);
656 val
= strtoul(p
, &e
, 16);
657 if (e
== p
|| *e
!= ':') {
663 val
= strtoul(p
, &e
, 16);
671 val
= strtoul(p
, &e
, 16);
682 val
= strtoul(p
, &e
, 10);
688 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
699 addr
->function
= func
;
705 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
709 PropertyInfo qdev_prop_pci_host_devaddr
= {
711 .description
= "Address (bus/device/function) of "
712 "the host device, example: 04:10.0",
713 .get
= get_pci_host_devaddr
,
714 .set
= set_pci_host_devaddr
,
717 /* --- support for array properties --- */
719 /* Used as an opaque for the object properties we add for each
720 * array element. Note that the struct Property must be first
721 * in the struct so that a pointer to this works as the opaque
722 * for the underlying element's property hooks as well as for
723 * our own release callback.
726 struct Property prop
;
728 ObjectPropertyRelease
*release
;
729 } ArrayElementProperty
;
731 /* object property release callback for array element properties:
732 * we call the underlying element's property release hook, and
733 * then free the memory we allocated when we added the property.
735 static void array_element_release(Object
*obj
, const char *name
, void *opaque
)
737 ArrayElementProperty
*p
= opaque
;
739 p
->release(obj
, name
, opaque
);
745 static void set_prop_arraylen(Object
*obj
, Visitor
*v
, void *opaque
,
746 const char *name
, Error
**errp
)
748 /* Setter for the property which defines the length of a
749 * variable-sized property array. As well as actually setting the
750 * array-length field in the device struct, we have to create the
751 * array itself and dynamically add the corresponding properties.
753 DeviceState
*dev
= DEVICE(obj
);
754 Property
*prop
= opaque
;
755 uint32_t *alenptr
= qdev_get_prop_ptr(dev
, prop
);
756 void **arrayptr
= (void *)dev
+ prop
->arrayoffset
;
757 Error
*local_err
= NULL
;
759 const char *arrayname
;
763 qdev_prop_set_after_realize(dev
, name
, errp
);
767 error_setg(errp
, "array size property %s may not be set more than once",
771 visit_type_uint32(v
, alenptr
, name
, &local_err
);
773 error_propagate(errp
, local_err
);
780 /* DEFINE_PROP_ARRAY guarantees that name should start with this prefix;
781 * strip it off so we can get the name of the array itself.
783 assert(strncmp(name
, PROP_ARRAY_LEN_PREFIX
,
784 strlen(PROP_ARRAY_LEN_PREFIX
)) == 0);
785 arrayname
= name
+ strlen(PROP_ARRAY_LEN_PREFIX
);
787 /* Note that it is the responsibility of the individual device's deinit
788 * to free the array proper.
790 *arrayptr
= eltptr
= g_malloc0(*alenptr
* prop
->arrayfieldsize
);
791 for (i
= 0; i
< *alenptr
; i
++, eltptr
+= prop
->arrayfieldsize
) {
792 char *propname
= g_strdup_printf("%s[%d]", arrayname
, i
);
793 ArrayElementProperty
*arrayprop
= g_new0(ArrayElementProperty
, 1);
794 arrayprop
->release
= prop
->arrayinfo
->release
;
795 arrayprop
->propname
= propname
;
796 arrayprop
->prop
.info
= prop
->arrayinfo
;
797 arrayprop
->prop
.name
= propname
;
798 /* This ugly piece of pointer arithmetic sets up the offset so
799 * that when the underlying get/set hooks call qdev_get_prop_ptr
800 * they get the right answer despite the array element not actually
801 * being inside the device struct.
803 arrayprop
->prop
.offset
= eltptr
- (void *)dev
;
804 assert(qdev_get_prop_ptr(dev
, &arrayprop
->prop
) == eltptr
);
805 object_property_add(obj
, propname
,
806 arrayprop
->prop
.info
->name
,
807 arrayprop
->prop
.info
->get
,
808 arrayprop
->prop
.info
->set
,
809 array_element_release
,
810 arrayprop
, &local_err
);
812 error_propagate(errp
, local_err
);
818 PropertyInfo qdev_prop_arraylen
= {
821 .set
= set_prop_arraylen
,
824 /* --- public helpers --- */
826 static Property
*qdev_prop_walk(Property
*props
, const char *name
)
831 while (props
->name
) {
832 if (strcmp(props
->name
, name
) == 0) {
840 static Property
*qdev_prop_find(DeviceState
*dev
, const char *name
)
845 /* device properties */
846 class = object_get_class(OBJECT(dev
));
848 prop
= qdev_prop_walk(DEVICE_CLASS(class)->props
, name
);
852 class = object_class_get_parent(class);
853 } while (class != object_class_by_name(TYPE_DEVICE
));
858 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
859 Property
*prop
, const char *value
)
863 error_setg(errp
, "Property '%s.%s' can't take value '%s', it's in use",
864 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
868 error_set(errp
, QERR_PROPERTY_VALUE_BAD
,
869 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
872 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
873 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
880 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
)
882 object_property_set_bool(OBJECT(dev
), value
, name
, &error_abort
);
885 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
)
887 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
890 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
)
892 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
895 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
)
897 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
900 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
)
902 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
905 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
)
907 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
910 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
)
912 object_property_set_str(OBJECT(dev
), value
, name
, &error_abort
);
915 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
)
917 char str
[2 * 6 + 5 + 1];
918 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
919 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
921 object_property_set_str(OBJECT(dev
), str
, name
, &error_abort
);
924 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
)
928 prop
= qdev_prop_find(dev
, name
);
929 object_property_set_str(OBJECT(dev
), prop
->info
->enum_table
[value
],
933 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
)
938 prop
= qdev_prop_find(dev
, name
);
939 assert(prop
&& prop
->info
== &qdev_prop_ptr
);
940 ptr
= qdev_get_prop_ptr(dev
, prop
);
944 static QTAILQ_HEAD(, GlobalProperty
) global_props
=
945 QTAILQ_HEAD_INITIALIZER(global_props
);
947 void qdev_prop_register_global(GlobalProperty
*prop
)
949 QTAILQ_INSERT_TAIL(&global_props
, prop
, next
);
952 void qdev_prop_register_global_list(GlobalProperty
*props
)
956 for (i
= 0; props
[i
].driver
!= NULL
; i
++) {
957 qdev_prop_register_global(props
+i
);
961 int qdev_prop_check_globals(void)
963 GlobalProperty
*prop
;
966 QTAILQ_FOREACH(prop
, &global_props
, next
) {
972 if (!prop
->user_provided
) {
975 oc
= object_class_by_name(prop
->driver
);
976 oc
= object_class_dynamic_cast(oc
, TYPE_DEVICE
);
978 error_report("Warning: global %s.%s has invalid class name",
979 prop
->driver
, prop
->property
);
983 dc
= DEVICE_CLASS(oc
);
984 if (!dc
->hotpluggable
&& !prop
->used
) {
985 error_report("Warning: global %s.%s=%s not used",
986 prop
->driver
, prop
->property
, prop
->value
);
994 static void qdev_prop_set_globals_for_type(DeviceState
*dev
,
995 const char *typename
)
997 GlobalProperty
*prop
;
999 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1002 if (strcmp(typename
, prop
->driver
) != 0) {
1006 object_property_parse(OBJECT(dev
), prop
->value
, prop
->property
, &err
);
1008 assert(prop
->user_provided
);
1009 error_report("Warning: global %s.%s=%s ignored (%s)",
1010 prop
->driver
, prop
->property
, prop
->value
,
1011 error_get_pretty(err
));
1018 void qdev_prop_set_globals(DeviceState
*dev
)
1020 ObjectClass
*class = object_get_class(OBJECT(dev
));
1023 qdev_prop_set_globals_for_type(dev
, object_class_get_name(class));
1024 class = object_class_get_parent(class);
1028 /* --- 64bit unsigned int 'size' type --- */
1030 static void get_size(Object
*obj
, Visitor
*v
, void *opaque
,
1031 const char *name
, Error
**errp
)
1033 DeviceState
*dev
= DEVICE(obj
);
1034 Property
*prop
= opaque
;
1035 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1037 visit_type_size(v
, ptr
, name
, errp
);
1040 static void set_size(Object
*obj
, Visitor
*v
, void *opaque
,
1041 const char *name
, Error
**errp
)
1043 DeviceState
*dev
= DEVICE(obj
);
1044 Property
*prop
= opaque
;
1045 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1047 visit_type_size(v
, ptr
, name
, errp
);
1050 PropertyInfo qdev_prop_size
= {