1 #ifndef QEMU_QDEV_PROPERTIES_H
2 #define QEMU_QDEV_PROPERTIES_H
4 #include "qapi/qapi-types-block.h"
5 #include "qapi/qapi-types-misc.h"
6 #include "hw/qdev-core.h"
8 /*** qdev-properties.c ***/
10 extern const PropertyInfo qdev_prop_bit
;
11 extern const PropertyInfo qdev_prop_bit64
;
12 extern const PropertyInfo qdev_prop_bool
;
13 extern const PropertyInfo qdev_prop_uint8
;
14 extern const PropertyInfo qdev_prop_uint16
;
15 extern const PropertyInfo qdev_prop_uint32
;
16 extern const PropertyInfo qdev_prop_int32
;
17 extern const PropertyInfo qdev_prop_uint64
;
18 extern const PropertyInfo qdev_prop_int64
;
19 extern const PropertyInfo qdev_prop_size
;
20 extern const PropertyInfo qdev_prop_string
;
21 extern const PropertyInfo qdev_prop_chr
;
22 extern const PropertyInfo qdev_prop_tpm
;
23 extern const PropertyInfo qdev_prop_ptr
;
24 extern const PropertyInfo qdev_prop_macaddr
;
25 extern const PropertyInfo qdev_prop_on_off_auto
;
26 extern const PropertyInfo qdev_prop_losttickpolicy
;
27 extern const PropertyInfo qdev_prop_blockdev_on_error
;
28 extern const PropertyInfo qdev_prop_bios_chs_trans
;
29 extern const PropertyInfo qdev_prop_fdc_drive_type
;
30 extern const PropertyInfo qdev_prop_drive
;
31 extern const PropertyInfo qdev_prop_netdev
;
32 extern const PropertyInfo qdev_prop_vlan
;
33 extern const PropertyInfo qdev_prop_pci_devfn
;
34 extern const PropertyInfo qdev_prop_blocksize
;
35 extern const PropertyInfo qdev_prop_pci_host_devaddr
;
36 extern const PropertyInfo qdev_prop_uuid
;
37 extern const PropertyInfo qdev_prop_arraylen
;
38 extern const PropertyInfo qdev_prop_link
;
39 extern const PropertyInfo qdev_prop_off_auto_pcibar
;
41 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
44 .offset = offsetof(_state, _field) \
45 + type_check(_type, typeof_field(_state, _field)), \
48 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
51 .offset = offsetof(_state, _field) \
52 + type_check(_type,typeof_field(_state, _field)), \
53 .set_default = true, \
54 .defval.i = (_type)_defval, \
57 #define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
60 .offset = offsetof(_state, _field) \
61 + type_check(_type, typeof_field(_state, _field)), \
64 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
66 .info = &(qdev_prop_bit), \
68 .offset = offsetof(_state, _field) \
69 + type_check(uint32_t,typeof_field(_state, _field)), \
70 .set_default = true, \
71 .defval.u = (bool)_defval, \
74 #define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \
77 .offset = offsetof(_state, _field) \
78 + type_check(_type, typeof_field(_state, _field)), \
79 .set_default = true, \
80 .defval.u = (_type)_defval, \
83 #define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
86 .offset = offsetof(_state, _field) \
87 + type_check(_type, typeof_field(_state, _field)), \
90 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
92 .info = &(qdev_prop_bit64), \
94 .offset = offsetof(_state, _field) \
95 + type_check(uint64_t, typeof_field(_state, _field)), \
96 .set_default = true, \
97 .defval.u = (bool)_defval, \
100 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
102 .info = &(qdev_prop_bool), \
103 .offset = offsetof(_state, _field) \
104 + type_check(bool, typeof_field(_state, _field)), \
105 .set_default = true, \
106 .defval.u = (bool)_defval, \
109 #define PROP_ARRAY_LEN_PREFIX "len-"
113 * @_name: name of the array
114 * @_state: name of the device state structure type
115 * @_field: uint32_t field in @_state to hold the array length
116 * @_arrayfield: field in @_state (of type '@_arraytype *') which
117 * will point to the array
118 * @_arrayprop: PropertyInfo defining what property the array elements have
119 * @_arraytype: C type of the array elements
121 * Define device properties for a variable-length array _name. A
122 * static property "len-arrayname" is defined. When the device creator
123 * sets this property to the desired length of array, further dynamic
124 * properties "arrayname[0]", "arrayname[1]", ... are defined so the
125 * device creator can set the array element values. Setting the
126 * "len-arrayname" property more than once is an error.
128 * When the array length is set, the @_field member of the device
129 * struct is set to the array length, and @_arrayfield is set to point
130 * to (zero-initialised) memory allocated for the array. For a zero
131 * length array, @_field will be set to 0 and @_arrayfield to NULL.
132 * It is the responsibility of the device deinit code to free the
133 * @_arrayfield memory.
135 #define DEFINE_PROP_ARRAY(_name, _state, _field, \
136 _arrayfield, _arrayprop, _arraytype) { \
137 .name = (PROP_ARRAY_LEN_PREFIX _name), \
138 .info = &(qdev_prop_arraylen), \
139 .set_default = true, \
141 .offset = offsetof(_state, _field) \
142 + type_check(uint32_t, typeof_field(_state, _field)), \
143 .arrayinfo = &(_arrayprop), \
144 .arrayfieldsize = sizeof(_arraytype), \
145 .arrayoffset = offsetof(_state, _arrayfield), \
148 #define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
150 .info = &(qdev_prop_link), \
151 .offset = offsetof(_state, _field) \
152 + type_check(_ptr_type, typeof_field(_state, _field)), \
153 .link_type = _type, \
156 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
157 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
158 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
159 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
160 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
161 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
162 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
163 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
164 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
165 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
166 #define DEFINE_PROP_INT64(_n, _s, _f, _d) \
167 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
168 #define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
169 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
170 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
171 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
174 * Please avoid pointer properties. If you must use them, you must
175 * cover them in their device's class init function as follows:
177 * - If the property must be set, the device cannot be used with
178 * device_add, so add code like this:
179 * |* Reason: pointer property "NAME-OF-YOUR-PROP" *|
180 * DeviceClass *dc = DEVICE_CLASS(class);
181 * dc->user_creatable = false;
183 * - If the property may safely remain null, document it like this:
185 * * Note: pointer property "interrupt_vector" may remain null, thus
186 * * no need for dc->user_creatable = false;
189 #define DEFINE_PROP_PTR(_n, _s, _f) \
190 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
192 #define DEFINE_PROP_CHR(_n, _s, _f) \
193 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend)
194 #define DEFINE_PROP_STRING(_n, _s, _f) \
195 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
196 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
197 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
198 #define DEFINE_PROP_VLAN(_n, _s, _f) \
199 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
200 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
201 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *)
202 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
203 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
204 #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
205 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
206 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
207 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
209 #define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \
210 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \
212 #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
213 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
214 #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
215 DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
216 #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
217 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
218 #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \
219 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
220 #define DEFINE_PROP_OFF_AUTO_PCIBAR(_n, _s, _f, _d) \
221 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_off_auto_pcibar, \
224 #define DEFINE_PROP_UUID(_name, _state, _field) { \
226 .info = &qdev_prop_uuid, \
227 .offset = offsetof(_state, _field) \
228 + type_check(QemuUUID, typeof_field(_state, _field)), \
229 .set_default = true, \
232 #define DEFINE_PROP_END_OF_LIST() \
235 /* Set properties between creation and init. */
236 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
);
237 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
);
238 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
);
239 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
);
240 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
);
241 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
);
242 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
);
243 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
);
244 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
, Chardev
*value
);
245 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
, NetClientState
*value
);
246 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
247 BlockBackend
*value
, Error
**errp
);
248 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
,
249 const uint8_t *value
);
250 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
);
251 /* FIXME: Remove opaque pointer properties. */
252 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
);
254 void qdev_prop_register_global(GlobalProperty
*prop
);
255 void qdev_prop_register_global_list(GlobalProperty
*props
);
256 int qdev_prop_check_globals(void);
257 void qdev_prop_set_globals(DeviceState
*dev
);
258 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
259 Property
*prop
, const char *value
);
262 * register_compat_prop:
264 * Register internal (not user-provided) global property, changing the
265 * default value of a given property in a device type. This can be used
266 * for enabling machine-type compatibility or for enabling
267 * accelerator-specific defaults in devices.
269 * The property values set using this function must be always valid and
270 * never report setter errors, as the property will have
271 * GlobalProperty::errp set to &error_abort.
273 * User-provided global properties should override internal global
274 * properties, so callers of this function should ensure that it is
275 * called before user-provided global properties are registered.
277 * @driver: Device type to be affected
278 * @property: Property whose default value is going to be changed
279 * @value: New default value for the property
281 void register_compat_prop(const char *driver
, const char *property
,
284 * register_compat_props_array(): using register_compat_prop(), which
285 * only registers internal global properties (which has lower priority
286 * than user-provided global properties)
288 void register_compat_props_array(GlobalProperty
*prop
);
291 * qdev_property_add_static:
292 * @dev: Device to add the property to.
293 * @prop: The qdev property definition.
294 * @errp: location to store error information.
296 * Add a static QOM property to @dev for qdev property @prop.
297 * On error, store error in @errp. Static properties access data in a struct.
298 * The type of the QOM property is derived from prop->info.
300 void qdev_property_add_static(DeviceState
*dev
, Property
*prop
, Error
**errp
);
302 void qdev_alias_all_properties(DeviceState
*target
, Object
*source
);
305 * @qdev_prop_set_after_realize:
307 * @name: name of property
308 * @errp: indirect pointer to Error to be set
309 * Set the Error object to report that an attempt was made to set a property
310 * on a device after it has already been realized. This is a utility function
311 * which allows property-setter functions to easily report the error in
312 * a friendly format identifying both the device and the property.
314 void qdev_prop_set_after_realize(DeviceState
*dev
, const char *name
,
318 * qdev_prop_allow_set_link_before_realize:
320 * Set the #Error object if an attempt is made to set the link after realize.
321 * This function should be used as the check() argument to
322 * object_property_add_link().
324 void qdev_prop_allow_set_link_before_realize(const Object
*obj
,
326 Object
*val
, Error
**errp
);