1 #ifndef QEMU_QDEV_PROPERTIES_H
2 #define QEMU_QDEV_PROPERTIES_H
4 #include "hw/qdev-core.h"
8 * @set_default: true if the default value should be set from @defval,
9 * in which case @info->set_default_value must not be NULL
10 * (if false then no default value is set by the property system
11 * and the field retains whatever value it was given by instance_init).
12 * @defval: default value for the property. This is used only if @set_default
17 const PropertyInfo
*info
;
26 const PropertyInfo
*arrayinfo
;
28 const char *link_type
;
33 const char *description
;
34 const QEnumLookup
*enum_table
;
35 bool realized_set_allowed
; /* allow setting property on realized device */
36 int (*print
)(Object
*obj
, Property
*prop
, char *dest
, size_t len
);
37 void (*set_default_value
)(ObjectProperty
*op
, const Property
*prop
);
38 ObjectProperty
*(*create
)(ObjectClass
*oc
, const char *name
,
40 ObjectPropertyAccessor
*get
;
41 ObjectPropertyAccessor
*set
;
42 ObjectPropertyRelease
*release
;
46 /*** qdev-properties.c ***/
48 extern const PropertyInfo qdev_prop_bit
;
49 extern const PropertyInfo qdev_prop_bit64
;
50 extern const PropertyInfo qdev_prop_bool
;
51 extern const PropertyInfo qdev_prop_enum
;
52 extern const PropertyInfo qdev_prop_uint8
;
53 extern const PropertyInfo qdev_prop_uint16
;
54 extern const PropertyInfo qdev_prop_uint32
;
55 extern const PropertyInfo qdev_prop_int32
;
56 extern const PropertyInfo qdev_prop_uint64
;
57 extern const PropertyInfo qdev_prop_int64
;
58 extern const PropertyInfo qdev_prop_size
;
59 extern const PropertyInfo qdev_prop_string
;
60 extern const PropertyInfo qdev_prop_on_off_auto
;
61 extern const PropertyInfo qdev_prop_size32
;
62 extern const PropertyInfo qdev_prop_arraylen
;
63 extern const PropertyInfo qdev_prop_link
;
65 #define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \
68 .offset = offsetof(_state, _field) \
69 + type_check(_type, typeof_field(_state, _field)), \
73 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
74 DEFINE_PROP(_name, _state, _field, _prop, _type, \
75 .set_default = true, \
76 .defval.i = (_type)_defval)
78 #define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
79 DEFINE_PROP(_name, _state, _field, _prop, _type)
81 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \
82 DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \
84 .set_default = true, \
85 .defval.u = (bool)_defval)
87 #define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
88 DEFINE_PROP(_name, _state, _field, _prop, _type, \
89 .set_default = true, \
90 .defval.u = (_type)_defval)
92 #define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
93 DEFINE_PROP(_name, _state, _field, _prop, _type)
95 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \
96 DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \
98 .set_default = true, \
99 .defval.u = (bool)_defval)
101 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \
102 DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \
103 .set_default = true, \
104 .defval.u = (bool)_defval)
106 #define PROP_ARRAY_LEN_PREFIX "len-"
110 * @_name: name of the array
111 * @_state: name of the device state structure type
112 * @_field: uint32_t field in @_state to hold the array length
113 * @_arrayfield: field in @_state (of type '@_arraytype *') which
114 * will point to the array
115 * @_arrayprop: PropertyInfo defining what property the array elements have
116 * @_arraytype: C type of the array elements
118 * Define device properties for a variable-length array _name. A
119 * static property "len-arrayname" is defined. When the device creator
120 * sets this property to the desired length of array, further dynamic
121 * properties "arrayname[0]", "arrayname[1]", ... are defined so the
122 * device creator can set the array element values. Setting the
123 * "len-arrayname" property more than once is an error.
125 * When the array length is set, the @_field member of the device
126 * struct is set to the array length, and @_arrayfield is set to point
127 * to (zero-initialised) memory allocated for the array. For a zero
128 * length array, @_field will be set to 0 and @_arrayfield to NULL.
129 * It is the responsibility of the device deinit code to free the
130 * @_arrayfield memory.
132 #define DEFINE_PROP_ARRAY(_name, _state, _field, \
133 _arrayfield, _arrayprop, _arraytype) \
134 DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \
135 _state, _field, qdev_prop_arraylen, uint32_t, \
136 .set_default = true, \
138 .arrayinfo = &(_arrayprop), \
139 .arrayfieldsize = sizeof(_arraytype), \
140 .arrayoffset = offsetof(_state, _arrayfield))
142 #define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \
143 DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type, \
146 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
147 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
148 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
149 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
150 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
151 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
152 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
153 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
154 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
155 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
156 #define DEFINE_PROP_INT64(_n, _s, _f, _d) \
157 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
158 #define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
159 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
160 #define DEFINE_PROP_STRING(_n, _s, _f) \
161 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
162 #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
163 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
164 #define DEFINE_PROP_SIZE32(_n, _s, _f, _d) \
165 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size32, uint32_t)
167 #define DEFINE_PROP_END_OF_LIST() \
171 * Set properties between creation and realization.
173 * Returns: %true on success, %false on error.
175 bool qdev_prop_set_drive_err(DeviceState
*dev
, const char *name
,
176 BlockBackend
*value
, Error
**errp
);
179 * Set properties between creation and realization.
180 * @value must be valid. Each property may be set at most once.
182 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
);
183 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
);
184 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
);
185 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
);
186 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
);
187 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
);
188 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
);
189 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
, Chardev
*value
);
190 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
, NetClientState
*value
);
191 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
192 BlockBackend
*value
);
193 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
,
194 const uint8_t *value
);
195 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
);
197 void *object_field_prop_ptr(Object
*obj
, Property
*prop
);
199 void qdev_prop_register_global(GlobalProperty
*prop
);
200 const GlobalProperty
*qdev_find_global_prop(Object
*obj
,
202 int qdev_prop_check_globals(void);
203 void qdev_prop_set_globals(DeviceState
*dev
);
204 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, Object
*obj
,
205 const char *name
, const char *value
);
208 * qdev_property_add_static:
209 * @dev: Device to add the property to.
210 * @prop: The qdev property definition.
212 * Add a static QOM property to @dev for qdev property @prop.
213 * On error, store error in @errp. Static properties access data in a struct.
214 * The type of the QOM property is derived from prop->info.
216 void qdev_property_add_static(DeviceState
*dev
, Property
*prop
);
219 * qdev_alias_all_properties: Create aliases on source for all target properties
220 * @target: Device which has properties to be aliased
221 * @source: Object to add alias properties to
223 * Add alias properties to the @source object for all qdev properties on
224 * the @target DeviceState.
226 * This is useful when @target is an internal implementation object
227 * owned by @source, and you want to expose all the properties of that
228 * implementation object as properties on the @source object so that users
229 * of @source can set them.
231 void qdev_alias_all_properties(DeviceState
*target
, Object
*source
);
234 * @qdev_prop_set_after_realize:
236 * @name: name of property
237 * @errp: indirect pointer to Error to be set
238 * Set the Error object to report that an attempt was made to set a property
239 * on a device after it has already been realized. This is a utility function
240 * which allows property-setter functions to easily report the error in
241 * a friendly format identifying both the device and the property.
243 void qdev_prop_set_after_realize(DeviceState
*dev
, const char *name
,
247 * qdev_prop_allow_set_link_before_realize:
249 * Set the #Error object if an attempt is made to set the link after realize.
250 * This function should be used as the check() argument to
251 * object_property_add_link().
253 void qdev_prop_allow_set_link_before_realize(const Object
*obj
,
255 Object
*val
, Error
**errp
);