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
);
429 PropertyInfo qdev_prop_string
= {
431 .release
= release_string
,
436 /* --- pointer --- */
438 /* Not a proper property, just for dirty hacks. TODO Remove it! */
439 PropertyInfo qdev_prop_ptr
= {
443 /* --- mac address --- */
446 * accepted syntax versions:
450 static void get_mac(Object
*obj
, Visitor
*v
, void *opaque
,
451 const char *name
, Error
**errp
)
453 DeviceState
*dev
= DEVICE(obj
);
454 Property
*prop
= opaque
;
455 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
456 char buffer
[2 * 6 + 5 + 1];
459 snprintf(buffer
, sizeof(buffer
), "%02x:%02x:%02x:%02x:%02x:%02x",
460 mac
->a
[0], mac
->a
[1], mac
->a
[2],
461 mac
->a
[3], mac
->a
[4], mac
->a
[5]);
463 visit_type_str(v
, &p
, name
, errp
);
466 static void set_mac(Object
*obj
, Visitor
*v
, void *opaque
,
467 const char *name
, Error
**errp
)
469 DeviceState
*dev
= DEVICE(obj
);
470 Property
*prop
= opaque
;
471 MACAddr
*mac
= qdev_get_prop_ptr(dev
, prop
);
472 Error
*local_err
= NULL
;
477 qdev_prop_set_after_realize(dev
, name
, errp
);
481 visit_type_str(v
, &str
, name
, &local_err
);
483 error_propagate(errp
, local_err
);
487 for (i
= 0, pos
= 0; i
< 6; i
++, pos
+= 3) {
488 if (!qemu_isxdigit(str
[pos
])) {
491 if (!qemu_isxdigit(str
[pos
+1])) {
495 if (str
[pos
+2] != '\0') {
499 if (str
[pos
+2] != ':' && str
[pos
+2] != '-') {
503 mac
->a
[i
] = strtol(str
+pos
, &p
, 16);
509 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
513 PropertyInfo qdev_prop_macaddr
= {
515 .description
= "Ethernet 6-byte MAC Address, example: 52:54:00:12:34:56",
520 /* --- lost tick policy --- */
522 QEMU_BUILD_BUG_ON(sizeof(LostTickPolicy
) != sizeof(int));
524 PropertyInfo qdev_prop_losttickpolicy
= {
525 .name
= "LostTickPolicy",
526 .enum_table
= LostTickPolicy_lookup
,
531 /* --- BIOS CHS translation */
533 QEMU_BUILD_BUG_ON(sizeof(BiosAtaTranslation
) != sizeof(int));
535 PropertyInfo qdev_prop_bios_chs_trans
= {
536 .name
= "BiosAtaTranslation",
537 .description
= "Logical CHS translation algorithm, "
538 "auto/none/lba/large/rechs",
539 .enum_table
= BiosAtaTranslation_lookup
,
544 /* --- pci address --- */
547 * bus-local address, i.e. "$slot" or "$slot.$fn"
549 static void set_pci_devfn(Object
*obj
, Visitor
*v
, void *opaque
,
550 const char *name
, Error
**errp
)
552 DeviceState
*dev
= DEVICE(obj
);
553 Property
*prop
= opaque
;
554 int32_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
555 unsigned int slot
, fn
, n
;
556 Error
*local_err
= NULL
;
560 qdev_prop_set_after_realize(dev
, name
, errp
);
564 visit_type_str(v
, &str
, name
, &local_err
);
566 error_free(local_err
);
568 visit_type_int32(v
, &value
, name
, &local_err
);
570 error_propagate(errp
, local_err
);
571 } else if (value
< -1 || value
> 255) {
572 error_setg(errp
, QERR_INVALID_PARAMETER_VALUE
,
573 name
? name
: "null", "pci_devfn");
580 if (sscanf(str
, "%x.%x%n", &slot
, &fn
, &n
) != 2) {
582 if (sscanf(str
, "%x%n", &slot
, &n
) != 1) {
586 if (str
[n
] != '\0' || fn
> 7 || slot
> 31) {
589 *ptr
= slot
<< 3 | fn
;
594 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
598 static int print_pci_devfn(DeviceState
*dev
, Property
*prop
, char *dest
,
601 int32_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
604 return snprintf(dest
, len
, "<unset>");
606 return snprintf(dest
, len
, "%02x.%x", *ptr
>> 3, *ptr
& 7);
610 PropertyInfo qdev_prop_pci_devfn
= {
612 .description
= "Slot and optional function number, example: 06.0 or 06",
613 .print
= print_pci_devfn
,
615 .set
= set_pci_devfn
,
618 /* --- blocksize --- */
620 static void set_blocksize(Object
*obj
, Visitor
*v
, void *opaque
,
621 const char *name
, Error
**errp
)
623 DeviceState
*dev
= DEVICE(obj
);
624 Property
*prop
= opaque
;
625 uint16_t value
, *ptr
= qdev_get_prop_ptr(dev
, prop
);
626 Error
*local_err
= NULL
;
627 const int64_t min
= 512;
628 const int64_t max
= 32768;
631 qdev_prop_set_after_realize(dev
, name
, errp
);
635 visit_type_uint16(v
, &value
, name
, &local_err
);
637 error_propagate(errp
, local_err
);
640 /* value of 0 means "unset" */
641 if (value
&& (value
< min
|| value
> max
)) {
642 error_setg(errp
, QERR_PROPERTY_VALUE_OUT_OF_RANGE
,
643 dev
->id
? : "", name
, (int64_t)value
, min
, max
);
647 /* We rely on power-of-2 blocksizes for bitmasks */
648 if ((value
& (value
- 1)) != 0) {
650 "Property %s.%s doesn't take value '%" PRId64
"', it's not a power of 2",
651 dev
->id
?: "", name
, (int64_t)value
);
658 PropertyInfo qdev_prop_blocksize
= {
660 .description
= "A power of two between 512 and 32768",
662 .set
= set_blocksize
,
665 /* --- pci host address --- */
667 static void get_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
668 const char *name
, Error
**errp
)
670 DeviceState
*dev
= DEVICE(obj
);
671 Property
*prop
= opaque
;
672 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
673 char buffer
[] = "xxxx:xx:xx.x";
677 rc
= snprintf(buffer
, sizeof(buffer
), "%04x:%02x:%02x.%d",
678 addr
->domain
, addr
->bus
, addr
->slot
, addr
->function
);
679 assert(rc
== sizeof(buffer
) - 1);
681 visit_type_str(v
, &p
, name
, errp
);
685 * Parse [<domain>:]<bus>:<slot>.<func>
686 * if <domain> is not supplied, it's assumed to be 0.
688 static void set_pci_host_devaddr(Object
*obj
, Visitor
*v
, void *opaque
,
689 const char *name
, Error
**errp
)
691 DeviceState
*dev
= DEVICE(obj
);
692 Property
*prop
= opaque
;
693 PCIHostDeviceAddress
*addr
= qdev_get_prop_ptr(dev
, prop
);
694 Error
*local_err
= NULL
;
698 unsigned long dom
= 0, bus
= 0;
699 unsigned int slot
= 0, func
= 0;
702 qdev_prop_set_after_realize(dev
, name
, errp
);
706 visit_type_str(v
, &str
, name
, &local_err
);
708 error_propagate(errp
, local_err
);
713 val
= strtoul(p
, &e
, 16);
714 if (e
== p
|| *e
!= ':') {
720 val
= strtoul(p
, &e
, 16);
728 val
= strtoul(p
, &e
, 16);
739 val
= strtoul(p
, &e
, 10);
745 if (dom
> 0xffff || bus
> 0xff || slot
> 0x1f || func
> 7) {
756 addr
->function
= func
;
762 error_set_from_qdev_prop_error(errp
, EINVAL
, dev
, prop
, str
);
766 PropertyInfo qdev_prop_pci_host_devaddr
= {
768 .description
= "Address (bus/device/function) of "
769 "the host device, example: 04:10.0",
770 .get
= get_pci_host_devaddr
,
771 .set
= set_pci_host_devaddr
,
774 /* --- support for array properties --- */
776 /* Used as an opaque for the object properties we add for each
777 * array element. Note that the struct Property must be first
778 * in the struct so that a pointer to this works as the opaque
779 * for the underlying element's property hooks as well as for
780 * our own release callback.
783 struct Property prop
;
785 ObjectPropertyRelease
*release
;
786 } ArrayElementProperty
;
788 /* object property release callback for array element properties:
789 * we call the underlying element's property release hook, and
790 * then free the memory we allocated when we added the property.
792 static void array_element_release(Object
*obj
, const char *name
, void *opaque
)
794 ArrayElementProperty
*p
= opaque
;
796 p
->release(obj
, name
, opaque
);
802 static void set_prop_arraylen(Object
*obj
, Visitor
*v
, void *opaque
,
803 const char *name
, Error
**errp
)
805 /* Setter for the property which defines the length of a
806 * variable-sized property array. As well as actually setting the
807 * array-length field in the device struct, we have to create the
808 * array itself and dynamically add the corresponding properties.
810 DeviceState
*dev
= DEVICE(obj
);
811 Property
*prop
= opaque
;
812 uint32_t *alenptr
= qdev_get_prop_ptr(dev
, prop
);
813 void **arrayptr
= (void *)dev
+ prop
->arrayoffset
;
814 Error
*local_err
= NULL
;
816 const char *arrayname
;
820 qdev_prop_set_after_realize(dev
, name
, errp
);
824 error_setg(errp
, "array size property %s may not be set more than once",
828 visit_type_uint32(v
, alenptr
, name
, &local_err
);
830 error_propagate(errp
, local_err
);
837 /* DEFINE_PROP_ARRAY guarantees that name should start with this prefix;
838 * strip it off so we can get the name of the array itself.
840 assert(strncmp(name
, PROP_ARRAY_LEN_PREFIX
,
841 strlen(PROP_ARRAY_LEN_PREFIX
)) == 0);
842 arrayname
= name
+ strlen(PROP_ARRAY_LEN_PREFIX
);
844 /* Note that it is the responsibility of the individual device's deinit
845 * to free the array proper.
847 *arrayptr
= eltptr
= g_malloc0(*alenptr
* prop
->arrayfieldsize
);
848 for (i
= 0; i
< *alenptr
; i
++, eltptr
+= prop
->arrayfieldsize
) {
849 char *propname
= g_strdup_printf("%s[%d]", arrayname
, i
);
850 ArrayElementProperty
*arrayprop
= g_new0(ArrayElementProperty
, 1);
851 arrayprop
->release
= prop
->arrayinfo
->release
;
852 arrayprop
->propname
= propname
;
853 arrayprop
->prop
.info
= prop
->arrayinfo
;
854 arrayprop
->prop
.name
= propname
;
855 /* This ugly piece of pointer arithmetic sets up the offset so
856 * that when the underlying get/set hooks call qdev_get_prop_ptr
857 * they get the right answer despite the array element not actually
858 * being inside the device struct.
860 arrayprop
->prop
.offset
= eltptr
- (void *)dev
;
861 assert(qdev_get_prop_ptr(dev
, &arrayprop
->prop
) == eltptr
);
862 object_property_add(obj
, propname
,
863 arrayprop
->prop
.info
->name
,
864 arrayprop
->prop
.info
->get
,
865 arrayprop
->prop
.info
->set
,
866 array_element_release
,
867 arrayprop
, &local_err
);
869 error_propagate(errp
, local_err
);
875 PropertyInfo qdev_prop_arraylen
= {
878 .set
= set_prop_arraylen
,
881 /* --- public helpers --- */
883 static Property
*qdev_prop_walk(Property
*props
, const char *name
)
888 while (props
->name
) {
889 if (strcmp(props
->name
, name
) == 0) {
897 static Property
*qdev_prop_find(DeviceState
*dev
, const char *name
)
902 /* device properties */
903 class = object_get_class(OBJECT(dev
));
905 prop
= qdev_prop_walk(DEVICE_CLASS(class)->props
, name
);
909 class = object_class_get_parent(class);
910 } while (class != object_class_by_name(TYPE_DEVICE
));
915 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
916 Property
*prop
, const char *value
)
920 error_setg(errp
, "Property '%s.%s' can't take value '%s', it's in use",
921 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
925 error_setg(errp
, QERR_PROPERTY_VALUE_BAD
,
926 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
929 error_setg(errp
, "Property '%s.%s' can't find value '%s'",
930 object_get_typename(OBJECT(dev
)), prop
->name
, value
);
937 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
)
939 object_property_set_bool(OBJECT(dev
), value
, name
, &error_abort
);
942 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
)
944 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
947 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
)
949 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
952 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
)
954 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
957 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
)
959 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
962 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
)
964 object_property_set_int(OBJECT(dev
), value
, name
, &error_abort
);
967 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
)
969 object_property_set_str(OBJECT(dev
), value
, name
, &error_abort
);
972 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
)
974 char str
[2 * 6 + 5 + 1];
975 snprintf(str
, sizeof(str
), "%02x:%02x:%02x:%02x:%02x:%02x",
976 value
[0], value
[1], value
[2], value
[3], value
[4], value
[5]);
978 object_property_set_str(OBJECT(dev
), str
, name
, &error_abort
);
981 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
)
985 prop
= qdev_prop_find(dev
, name
);
986 object_property_set_str(OBJECT(dev
), prop
->info
->enum_table
[value
],
990 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
)
995 prop
= qdev_prop_find(dev
, name
);
996 assert(prop
&& prop
->info
== &qdev_prop_ptr
);
997 ptr
= qdev_get_prop_ptr(dev
, prop
);
1001 static QTAILQ_HEAD(, GlobalProperty
) global_props
=
1002 QTAILQ_HEAD_INITIALIZER(global_props
);
1004 void qdev_prop_register_global(GlobalProperty
*prop
)
1006 QTAILQ_INSERT_TAIL(&global_props
, prop
, next
);
1009 void qdev_prop_register_global_list(GlobalProperty
*props
)
1013 for (i
= 0; props
[i
].driver
!= NULL
; i
++) {
1014 qdev_prop_register_global(props
+i
);
1018 int qdev_prop_check_globals(void)
1020 GlobalProperty
*prop
;
1023 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1029 if (!prop
->user_provided
) {
1032 oc
= object_class_by_name(prop
->driver
);
1033 oc
= object_class_dynamic_cast(oc
, TYPE_DEVICE
);
1035 error_report("Warning: global %s.%s has invalid class name",
1036 prop
->driver
, prop
->property
);
1040 dc
= DEVICE_CLASS(oc
);
1041 if (!dc
->hotpluggable
&& !prop
->used
) {
1042 error_report("Warning: global %s.%s=%s not used",
1043 prop
->driver
, prop
->property
, prop
->value
);
1051 static void qdev_prop_set_globals_for_type(DeviceState
*dev
,
1052 const char *typename
)
1054 GlobalProperty
*prop
;
1056 QTAILQ_FOREACH(prop
, &global_props
, next
) {
1059 if (strcmp(typename
, prop
->driver
) != 0) {
1063 object_property_parse(OBJECT(dev
), prop
->value
, prop
->property
, &err
);
1065 assert(prop
->user_provided
);
1066 error_report("Warning: global %s.%s=%s ignored: %s",
1067 prop
->driver
, prop
->property
, prop
->value
,
1068 error_get_pretty(err
));
1075 void qdev_prop_set_globals(DeviceState
*dev
)
1077 ObjectClass
*class = object_get_class(OBJECT(dev
));
1080 qdev_prop_set_globals_for_type(dev
, object_class_get_name(class));
1081 class = object_class_get_parent(class);
1085 /* --- 64bit unsigned int 'size' type --- */
1087 static void get_size(Object
*obj
, Visitor
*v
, void *opaque
,
1088 const char *name
, Error
**errp
)
1090 DeviceState
*dev
= DEVICE(obj
);
1091 Property
*prop
= opaque
;
1092 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1094 visit_type_size(v
, ptr
, name
, errp
);
1097 static void set_size(Object
*obj
, Visitor
*v
, void *opaque
,
1098 const char *name
, Error
**errp
)
1100 DeviceState
*dev
= DEVICE(obj
);
1101 Property
*prop
= opaque
;
1102 uint64_t *ptr
= qdev_get_prop_ptr(dev
, prop
);
1104 visit_type_size(v
, ptr
, name
, errp
);
1107 PropertyInfo qdev_prop_size
= {