3 #include "qapi/qmp/qerror.h"
4 #include "qemu/error-report.h"
5 #include "sysemu/block-backend.h"
6 #include "hw/block/block.h"
8 #include "qapi/visitor.h"
9 #include "sysemu/char.h"
11 void qdev_prop_set_after_realize(DeviceState
*dev
, const char *name
,
15 error_setg(errp
, "Attempt to set property '%s' on device '%s' "
16 "(type '%s') after it was realized", name
, dev
->id
,
17 object_get_typename(OBJECT(dev
)));
19 error_setg(errp
, "Attempt to set property '%s' on anonymous device "
20 "(type '%s') after it was realized", name
,
21 object_get_typename(OBJECT(dev
)));
25 void qdev_prop_allow_set_link_before_realize(Object
*obj
, const char *name
,
26 Object
*val
, Error
**errp
)
28 DeviceState
*dev
= DEVICE(obj
);
31 error_setg(errp
, "Attempt to set link property '%s' on device '%s' "
32 "(type '%s') after it was realized",
33 name
, dev
->id
, object_get_typename(obj
));
37 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
)
44 static void get_enum(Object
*obj
, Visitor
*v
, void *opaque
,
45 const char *name
, Error
**errp
)
47 DeviceState
*dev
= DEVICE(obj
);
48 Property
*prop
= opaque
;
49 int *ptr
= qdev_get_prop_ptr(dev
, prop
);
51 visit_type_enum(v
, ptr
, prop
->info
->enum_table
,
52 prop
->info
->name
, prop
->name
, errp
);
55 static void set_enum(Object
*obj
, Visitor
*v
, void *opaque
,
56 const char *name
, Error
**errp
)
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
, ptr
, prop
->info
->enum_table
,
68 prop
->info
->name
, prop
->name
, errp
);
73 static uint32_t qdev_get_prop_mask(Property
*prop
)
75 assert(prop
->info
== &qdev_prop_bit
);
76 return 0x1 << prop
->bitnr
;
79 static void bit_prop_set(DeviceState
*dev
, Property
*props
, bool val
)
81 uint32_t *p
= qdev_get_prop_ptr(dev
, props
);
82 uint32_t mask
= qdev_get_prop_mask(props
);
90 static void prop_get_bit(Object
*obj
, Visitor
*v
, void *opaque
,
91 const char *name
, Error
**errp
)
93 DeviceState
*dev
= DEVICE(obj
);
94 Property
*prop
= opaque
;
95 uint32_t *p
= qdev_get_prop_ptr(dev
, prop
);
96 bool value
= (*p
& qdev_get_prop_mask(prop
)) != 0;
98 visit_type_bool(v
, &value
, name
, errp
);
101 static void prop_set_bit(Object
*obj
, Visitor
*v
, void *opaque
,
102 const char *name
, Error
**errp
)
104 DeviceState
*dev
= DEVICE(obj
);
105 Property
*prop
= opaque
;
106 Error
*local_err
= NULL
;
110 qdev_prop_set_after_realize(dev
, name
, errp
);
114 visit_type_bool(v
, &value
, name
, &local_err
);
116 error_propagate(errp
, local_err
);
119 bit_prop_set(dev
, prop
, value
);
122 PropertyInfo qdev_prop_bit
= {
124 .description
= "on/off",
131 static uint64_t qdev_get_prop_mask64(Property
*prop
)
133 assert(prop
->info
== &qdev_prop_bit64
);
134 return 0x1ull
<< prop
->bitnr
;
137 static void bit64_prop_set(DeviceState
*dev
, Property
*props
, bool val
)
139 uint64_t *p
= qdev_get_prop_ptr(dev
, props
);
140 uint64_t mask
= qdev_get_prop_mask64(props
);
148 static void prop_get_bit64(Object
*obj
, Visitor
*v
, void *opaque
,
149 const char *name
, Error
**errp
)
151 DeviceState
*dev
= DEVICE(obj
);
152 Property
*prop
= opaque
;
153 uint64_t *p
= qdev_get_prop_ptr(dev
, prop
);
154 bool value
= (*p
& qdev_get_prop_mask64(prop
)) != 0;
156 visit_type_bool(v
, &value
, name
, errp
);
159 static void prop_set_bit64(Object
*obj
, Visitor
*v
, void *opaque
,
160 const char *name
, Error
**errp
)
162 DeviceState
*dev
= DEVICE(obj
);
163 Property
*prop
= opaque
;
164 Error
*local_err
= NULL
;
168 qdev_prop_set_after_realize(dev
, name
, errp
);
172 visit_type_bool(v
, &value
, name
, &local_err
);
174 error_propagate(errp
, local_err
);
177 bit64_prop_set(dev
, prop
, value
);
180 PropertyInfo qdev_prop_bit64
= {
182 .description
= "on/off",
183 .get
= prop_get_bit64
,
184 .set
= prop_set_bit64
,
189 static void get_bool(Object
*obj
, Visitor
*v
, void *opaque
,
190 const char *name
, Error
**errp
)
192 DeviceState
*dev
= DEVICE(obj
);
193 Property
*prop
= opaque
;
194 bool *ptr
= qdev_get_prop_ptr(dev
, prop
);
196 visit_type_bool(v
, ptr
, name
, errp
);
199 static void set_bool(Object
*obj
, Visitor
*v
, void *opaque
,
200 const char *name
, Error
**errp
)
202 DeviceState
*dev
= DEVICE(obj
);
203 Property
*prop
= opaque
;
204 bool *ptr
= qdev_get_prop_ptr(dev
, prop
);
207 qdev_prop_set_after_realize(dev
, name
, errp
);
211 visit_type_bool(v
, ptr
, name
, errp
);
214 PropertyInfo qdev_prop_bool
= {
220 /* --- 8bit integer --- */
222 static void get_uint8(Object
*obj
, Visitor
*v
, void *opaque
,
223 const char *name
, Error
**errp
)
225 DeviceState
*dev
= DEVICE(obj
);
226 Property
*prop
= opaque
;
227 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
229 visit_type_uint8(v
, ptr
, name
, errp
);
232 static void set_uint8(Object
*obj
, Visitor
*v
, void *opaque
,
233 const char *name
, Error
**errp
)
235 DeviceState
*dev
= DEVICE(obj
);
236 Property
*prop
= opaque
;
237 uint8_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
240 qdev_prop_set_after_realize(dev
, name
, errp
);
244 visit_type_uint8(v
, ptr
, name
, errp
);
247 PropertyInfo qdev_prop_uint8
= {
253 /* --- 16bit integer --- */
255 static void get_uint16(Object
*obj
, Visitor
*v
, void *opaque
,
256 const char *name
, Error
**errp
)
258 DeviceState
*dev
= DEVICE(obj
);
259 Property
*prop
= opaque
;
260 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
262 visit_type_uint16(v
, ptr
, name
, errp
);
265 static void set_uint16(Object
*obj
, Visitor
*v
, void *opaque
,
266 const char *name
, Error
**errp
)
268 DeviceState
*dev
= DEVICE(obj
);
269 Property
*prop
= opaque
;
270 uint16_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
273 qdev_prop_set_after_realize(dev
, name
, errp
);
277 visit_type_uint16(v
, ptr
, name
, errp
);
280 PropertyInfo qdev_prop_uint16
= {
286 /* --- 32bit integer --- */
288 static void get_uint32(Object
*obj
, Visitor
*v
, void *opaque
,
289 const char *name
, Error
**errp
)
291 DeviceState
*dev
= DEVICE(obj
);
292 Property
*prop
= opaque
;
293 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
295 visit_type_uint32(v
, ptr
, name
, errp
);
298 static void set_uint32(Object
*obj
, Visitor
*v
, void *opaque
,
299 const char *name
, Error
**errp
)
301 DeviceState
*dev
= DEVICE(obj
);
302 Property
*prop
= opaque
;
303 uint32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
306 qdev_prop_set_after_realize(dev
, name
, errp
);
310 visit_type_uint32(v
, ptr
, name
, errp
);
313 static void get_int32(Object
*obj
, Visitor
*v
, void *opaque
,
314 const char *name
, Error
**errp
)
316 DeviceState
*dev
= DEVICE(obj
);
317 Property
*prop
= opaque
;
318 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
320 visit_type_int32(v
, ptr
, name
, errp
);
323 static void set_int32(Object
*obj
, Visitor
*v
, void *opaque
,
324 const char *name
, Error
**errp
)
326 DeviceState
*dev
= DEVICE(obj
);
327 Property
*prop
= opaque
;
328 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
331 qdev_prop_set_after_realize(dev
, name
, errp
);
335 visit_type_int32(v
, ptr
, name
, errp
);
338 PropertyInfo qdev_prop_uint32
= {
344 PropertyInfo qdev_prop_int32
= {
350 /* --- 64bit integer --- */
352 static void get_uint64(Object
*obj
, Visitor
*v
, void *opaque
,
353 const char *name
, Error
**errp
)
355 DeviceState
*dev
= DEVICE(obj
);
356 Property
*prop
= opaque
;
357 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
359 visit_type_uint64(v
, ptr
, name
, errp
);
362 static void set_uint64(Object
*obj
, Visitor
*v
, void *opaque
,
363 const char *name
, Error
**errp
)
365 DeviceState
*dev
= DEVICE(obj
);
366 Property
*prop
= opaque
;
367 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
370 qdev_prop_set_after_realize(dev
, name
, errp
);
374 visit_type_uint64(v
, ptr
, name
, errp
);
377 PropertyInfo qdev_prop_uint64
= {
385 static void release_string(Object
*obj
, const char *name
, void *opaque
)
387 Property
*prop
= opaque
;
388 g_free(*(char **)qdev_get_prop_ptr(DEVICE(obj
), prop
));
391 static void get_string(Object
*obj
, Visitor
*v
, void *opaque
,
392 const char *name
, Error
**errp
)
394 DeviceState
*dev
= DEVICE(obj
);
395 Property
*prop
= opaque
;
396 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
399 char *str
= (char *)"";
400 visit_type_str(v
, &str
, name
, errp
);
402 visit_type_str(v
, ptr
, name
, errp
);
406 static void set_string(Object
*obj
, Visitor
*v
, void *opaque
,
407 const char *name
, Error
**errp
)
409 DeviceState
*dev
= DEVICE(obj
);
410 Property
*prop
= opaque
;
411 char **ptr
= qdev_get_prop_ptr(dev
, prop
);
412 Error
*local_err
= NULL
;
416 qdev_prop_set_after_realize(dev
, name
, errp
);
420 visit_type_str(v
, &str
, name
, &local_err
);
422 error_propagate(errp
, local_err
);
431 PropertyInfo qdev_prop_string
= {
433 .release
= release_string
,
438 /* --- pointer --- */
440 /* Not a proper property, just for dirty hacks. TODO Remove it! */
441 PropertyInfo qdev_prop_ptr
= {
445 /* --- mac address --- */
448 * accepted syntax versions:
452 static void get_mac(Object
*obj
, Visitor
*v
, void *opaque
,
453 const char *name
, Error
**errp
)
455 DeviceState
*dev
= DEVICE(obj
);
456 Property
*prop
= opaque
;
457 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
458 char buffer
[2 * 6 + 5 + 1];
461 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
462 mac
->a
[0], mac
->a
[1], mac
->a
[2],
463 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
465 visit_type_str(v
, &p
, name
, errp
);
468 static void set_mac(Object
*obj
, Visitor
*v
, void *opaque
,
469 const char *name
, Error
**errp
)
471 DeviceState
*dev
= DEVICE(obj
);
472 Property
*prop
= opaque
;
473 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
474 Error
*local_err
= NULL
;
479 qdev_prop_set_after_realize(dev
, name
, errp
);
483 visit_type_str(v
, &str
, name
, &local_err
);
485 error_propagate(errp
, local_err
);
489 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
490 if (!qemu_isxdigit(str
[pos
])) {
493 if (!qemu_isxdigit(str
[pos
+1])) {
497 if (str
[pos
+2] != '\0') {
501 if (str
[pos
+2] != ':' && str
[pos
+2] != '-') {
505 mac
->a
[i
] = strtol(str
+pos
, &p
, 16);
511 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
515 PropertyInfo qdev_prop_macaddr
= {
517 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
522 /* --- lost tick policy --- */
524 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
526 PropertyInfo qdev_prop_losttickpolicy
= {
527 .name
= "LostTickPolicy",
528 .enum_table
= LostTickPolicy_lookup
,
533 /* --- BIOS CHS translation */
535 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
537 PropertyInfo qdev_prop_bios_chs_trans
= {
538 .name
= "BiosAtaTranslation",
539 .description
= "Logical CHS translation algorithm, "
540 "auto/none/lba/large/rechs",
541 .enum_table
= BiosAtaTranslation_lookup
,
546 /* --- pci address --- */
549 * bus-local address, i.e. "$slot" or "$slot.$fn"
551 static void set_pci_devfn(Object
*obj
, Visitor
*v
, void *opaque
,
552 const char *name
, Error
**errp
)
554 DeviceState
*dev
= DEVICE(obj
);
555 Property
*prop
= opaque
;
556 int32_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
557 unsigned int slot
, fn
, n
;
558 Error
*local_err
= NULL
;
562 qdev_prop_set_after_realize(dev
, name
, errp
);
566 visit_type_str(v
, &str
, name
, &local_err
);
568 error_free(local_err
);
570 visit_type_int32(v
, &value
, name
, &local_err
);
572 error_propagate(errp
, local_err
);
573 } else if (value
< -1 || value
> 255) {
574 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
575 name
? name
: "null", "pci_devfn");
582 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
584 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
588 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
591 *ptr
= slot
<< 3 | fn
;
596 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
600 static int print_pci_devfn(DeviceState
*dev
, Property
*prop
, char *dest
,
603 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
606 return snprintf(dest
, len
, "<unset>");
608 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
612 PropertyInfo qdev_prop_pci_devfn
= {
614 .description
= "Slot and optional function number, example: 06.0 or 06",
615 .print
= print_pci_devfn
,
617 .set
= set_pci_devfn
,
620 /* --- blocksize --- */
622 static void set_blocksize(Object
*obj
, Visitor
*v
, void *opaque
,
623 const char *name
, Error
**errp
)
625 DeviceState
*dev
= DEVICE(obj
);
626 Property
*prop
= opaque
;
627 uint16_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
628 Error
*local_err
= NULL
;
629 const int64_t min
= 512;
630 const int64_t max
= 32768;
633 qdev_prop_set_after_realize(dev
, name
, errp
);
637 visit_type_uint16(v
, &value
, name
, &local_err
);
639 error_propagate(errp
, local_err
);
642 /* value of 0 means "unset" */
643 if (value
&& (value
< min
|| value
> max
)) {
644 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
645 dev
->id
? : "", name
, (int64_t)value
, min
, max
);
649 /* We rely on power-of-2 blocksizes for bitmasks */
650 if ((value
& (value
- 1)) != 0) {
652 "Property %s.%s doesn't take value '%" PRId64
"', it's not a power of 2",
653 dev
->id
?: "", name
, (int64_t)value
);
660 PropertyInfo qdev_prop_blocksize
= {
662 .description
= "A power of two between 512 and 32768",
664 .set
= set_blocksize
,
667 /* --- pci host address --- */
669 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
670 const char *name
, Error
**errp
)
672 DeviceState
*dev
= DEVICE(obj
);
673 Property
*prop
= opaque
;
674 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
675 char buffer
[] = "xxxx:xx:xx.x";
679 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%d",
680 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
681 assert(rc
== sizeof(buffer
) - 1);
683 visit_type_str(v
, &p
, name
, errp
);
687 * Parse [<domain>:]<bus>:<slot>.<func>
688 * if <domain> is not supplied, it's assumed to be 0.
690 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
691 const char *name
, Error
**errp
)
693 DeviceState
*dev
= DEVICE(obj
);
694 Property
*prop
= opaque
;
695 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
696 Error
*local_err
= NULL
;
700 unsigned long dom
= 0, bus
= 0;
701 unsigned int slot
= 0, func
= 0;
704 qdev_prop_set_after_realize(dev
, name
, errp
);
708 visit_type_str(v
, &str
, name
, &local_err
);
710 error_propagate(errp
, local_err
);
715 val
= strtoul(p
, &e
, 16);
716 if (e
== p
|| *e
!= ':') {
722 val
= strtoul(p
, &e
, 16);
730 val
= strtoul(p
, &e
, 16);
741 val
= strtoul(p
, &e
, 10);
747 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
758 addr
->function
= func
;
764 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
768 PropertyInfo qdev_prop_pci_host_devaddr
= {
770 .description
= "Address (bus/device/function) of "
771 "the host device, example: 04:10.0",
772 .get
= get_pci_host_devaddr
,
773 .set
= set_pci_host_devaddr
,
776 /* --- support for array properties --- */
778 /* Used as an opaque for the object properties we add for each
779 * array element. Note that the struct Property must be first
780 * in the struct so that a pointer to this works as the opaque
781 * for the underlying element's property hooks as well as for
782 * our own release callback.
785 struct Property prop
;
787 ObjectPropertyRelease
*release
;
788 } ArrayElementProperty
;
790 /* object property release callback for array element properties:
791 * we call the underlying element's property release hook, and
792 * then free the memory we allocated when we added the property.
794 static void array_element_release(Object
*obj
, const char *name
, void *opaque
)
796 ArrayElementProperty
*p
= opaque
;
798 p
->release(obj
, name
, opaque
);
804 static void set_prop_arraylen(Object
*obj
, Visitor
*v
, void *opaque
,
805 const char *name
, Error
**errp
)
807 /* Setter for the property which defines the length of a
808 * variable-sized property array. As well as actually setting the
809 * array-length field in the device struct, we have to create the
810 * array itself and dynamically add the corresponding properties.
812 DeviceState
*dev
= DEVICE(obj
);
813 Property
*prop
= opaque
;
814 uint32_t *alenptr
= qdev_get_prop_ptr(dev
, prop
);
815 void **arrayptr
= (void *)dev
+ prop
->arrayoffset
;
816 Error
*local_err
= NULL
;
818 const char *arrayname
;
822 qdev_prop_set_after_realize(dev
, name
, errp
);
826 error_setg(errp
, "array size property %s may not be set more than once",
830 visit_type_uint32(v
, alenptr
, name
, &local_err
);
832 error_propagate(errp
, local_err
);
839 /* DEFINE_PROP_ARRAY guarantees that name should start with this prefix;
840 * strip it off so we can get the name of the array itself.
842 assert(strncmp(name
, PROP_ARRAY_LEN_PREFIX
,
843 strlen(PROP_ARRAY_LEN_PREFIX
)) == 0);
844 arrayname
= name
+ strlen(PROP_ARRAY_LEN_PREFIX
);
846 /* Note that it is the responsibility of the individual device's deinit
847 * to free the array proper.
849 *arrayptr
= eltptr
= g_malloc0(*alenptr
* prop
->arrayfieldsize
);
850 for (i
= 0; i
< *alenptr
; i
++, eltptr
+= prop
->arrayfieldsize
) {
851 char *propname
= g_strdup_printf("%s[%d]", arrayname
, i
);
852 ArrayElementProperty
*arrayprop
= g_new0(ArrayElementProperty
, 1);
853 arrayprop
->release
= prop
->arrayinfo
->release
;
854 arrayprop
->propname
= propname
;
855 arrayprop
->prop
.info
= prop
->arrayinfo
;
856 arrayprop
->prop
.name
= propname
;
857 /* This ugly piece of pointer arithmetic sets up the offset so
858 * that when the underlying get/set hooks call qdev_get_prop_ptr
859 * they get the right answer despite the array element not actually
860 * being inside the device struct.
862 arrayprop
->prop
.offset
= eltptr
- (void *)dev
;
863 assert(qdev_get_prop_ptr(dev
, &arrayprop
->prop
) == eltptr
);
864 object_property_add(obj
, propname
,
865 arrayprop
->prop
.info
->name
,
866 arrayprop
->prop
.info
->get
,
867 arrayprop
->prop
.info
->set
,
868 array_element_release
,
869 arrayprop
, &local_err
);
871 error_propagate(errp
, local_err
);
877 PropertyInfo qdev_prop_arraylen
= {
880 .set
= set_prop_arraylen
,
883 /* --- public helpers --- */
885 static Property
*qdev_prop_walk(Property
*props
, const char *name
)
890 while (props
->name
) {
891 if (strcmp(props
->name
, name
) == 0) {
899 static Property
*qdev_prop_find(DeviceState
*dev
, const char *name
)
904 /* device properties */
905 class = object_get_class(OBJECT(dev
));
907 prop
= qdev_prop_walk(DEVICE_CLASS(class)->props
, name
);
911 class = object_class_get_parent(class);
912 } while (class != object_class_by_name(TYPE_DEVICE
));
917 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
918 Property
*prop
, const char *value
)
922 error_setg(errp
, "Property '%s.%s' can't take value '%s', it's in use",
923 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
927 error_setg(errp
, QERR_PROPERTY_VALUE_BAD
,
928 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
931 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
932 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
939 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
)
941 object_property_set_bool(OBJECT(dev
), value
, name
, &error_abort
);
944 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
)
946 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
949 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
)
951 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
954 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
)
956 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
959 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
)
961 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
964 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
)
966 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
969 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
)
971 object_property_set_str(OBJECT(dev
), value
, name
, &error_abort
);
974 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
)
976 char str
[2 * 6 + 5 + 1];
977 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
978 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
980 object_property_set_str(OBJECT(dev
), str
, name
, &error_abort
);
983 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
)
987 prop
= qdev_prop_find(dev
, name
);
988 object_property_set_str(OBJECT(dev
), prop
->info
->enum_table
[value
],
992 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
)
997 prop
= qdev_prop_find(dev
, name
);
998 assert(prop
&& prop
->info
== &qdev_prop_ptr
);
999 ptr
= qdev_get_prop_ptr(dev
, prop
);
1003 static QTAILQ_HEAD(, GlobalProperty
) global_props
=
1004 QTAILQ_HEAD_INITIALIZER(global_props
);
1006 void qdev_prop_register_global(GlobalProperty
*prop
)
1008 QTAILQ_INSERT_TAIL(&global_props
, prop
, next
);
1011 void qdev_prop_register_global_list(GlobalProperty
*props
)
1015 for (i
= 0; props
[i
].driver
!= NULL
; i
++) {
1016 qdev_prop_register_global(props
+i
);
1020 int qdev_prop_check_globals(void)
1022 GlobalProperty
*prop
;
1025 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1031 if (!prop
->user_provided
) {
1034 oc
= object_class_by_name(prop
->driver
);
1035 oc
= object_class_dynamic_cast(oc
, TYPE_DEVICE
);
1037 error_report("Warning: global %s.%s has invalid class name",
1038 prop
->driver
, prop
->property
);
1042 dc
= DEVICE_CLASS(oc
);
1043 if (!dc
->hotpluggable
&& !prop
->used
) {
1044 error_report("Warning: global %s.%s=%s not used",
1045 prop
->driver
, prop
->property
, prop
->value
);
1053 static void qdev_prop_set_globals_for_type(DeviceState
*dev
,
1054 const char *typename
)
1056 GlobalProperty
*prop
;
1058 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1061 if (strcmp(typename
, prop
->driver
) != 0) {
1065 object_property_parse(OBJECT(dev
), prop
->value
, prop
->property
, &err
);
1067 assert(prop
->user_provided
);
1068 error_report("Warning: global %s.%s=%s ignored (%s)",
1069 prop
->driver
, prop
->property
, prop
->value
,
1070 error_get_pretty(err
));
1077 void qdev_prop_set_globals(DeviceState
*dev
)
1079 ObjectClass
*class = object_get_class(OBJECT(dev
));
1082 qdev_prop_set_globals_for_type(dev
, object_class_get_name(class));
1083 class = object_class_get_parent(class);
1087 /* --- 64bit unsigned int 'size' type --- */
1089 static void get_size(Object
*obj
, Visitor
*v
, void *opaque
,
1090 const char *name
, Error
**errp
)
1092 DeviceState
*dev
= DEVICE(obj
);
1093 Property
*prop
= opaque
;
1094 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1096 visit_type_size(v
, ptr
, name
, errp
);
1099 static void set_size(Object
*obj
, Visitor
*v
, void *opaque
,
1100 const char *name
, Error
**errp
)
1102 DeviceState
*dev
= DEVICE(obj
);
1103 Property
*prop
= opaque
;
1104 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1106 visit_type_size(v
, ptr
, name
, errp
);
1109 PropertyInfo qdev_prop_size
= {