1 #ifndef QEMU_QDEV_PROPERTIES_H
2 #define QEMU_QDEV_PROPERTIES_H
4 #include "hw/qdev-core.h"
6 /*** qdev-properties.c ***/
8 extern const PropertyInfo qdev_prop_bit
;
9 extern const PropertyInfo qdev_prop_bit64
;
10 extern const PropertyInfo qdev_prop_bool
;
11 extern const PropertyInfo qdev_prop_uint8
;
12 extern const PropertyInfo qdev_prop_uint16
;
13 extern const PropertyInfo qdev_prop_uint32
;
14 extern const PropertyInfo qdev_prop_int32
;
15 extern const PropertyInfo qdev_prop_uint64
;
16 extern const PropertyInfo qdev_prop_int64
;
17 extern const PropertyInfo qdev_prop_size
;
18 extern const PropertyInfo qdev_prop_string
;
19 extern const PropertyInfo qdev_prop_chr
;
20 extern const PropertyInfo qdev_prop_tpm
;
21 extern const PropertyInfo qdev_prop_macaddr
;
22 extern const PropertyInfo qdev_prop_on_off_auto
;
23 extern const PropertyInfo qdev_prop_multifd_compression
;
24 extern const PropertyInfo qdev_prop_losttickpolicy
;
25 extern const PropertyInfo qdev_prop_blockdev_on_error
;
26 extern const PropertyInfo qdev_prop_bios_chs_trans
;
27 extern const PropertyInfo qdev_prop_fdc_drive_type
;
28 extern const PropertyInfo qdev_prop_drive
;
29 extern const PropertyInfo qdev_prop_drive_iothread
;
30 extern const PropertyInfo qdev_prop_netdev
;
31 extern const PropertyInfo qdev_prop_pci_devfn
;
32 extern const PropertyInfo qdev_prop_blocksize
;
33 extern const PropertyInfo qdev_prop_pci_host_devaddr
;
34 extern const PropertyInfo qdev_prop_uuid
;
35 extern const PropertyInfo qdev_prop_arraylen
;
36 extern const PropertyInfo qdev_prop_audiodev
;
37 extern const PropertyInfo qdev_prop_link
;
38 extern const PropertyInfo qdev_prop_off_auto_pcibar
;
39 extern const PropertyInfo qdev_prop_pcie_link_speed
;
40 extern const PropertyInfo qdev_prop_pcie_link_width
;
42 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
45 .offset = offsetof(_state, _field) \
46 + type_check(_type, typeof_field(_state, _field)), \
49 #define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
52 .offset = offsetof(_state, _field) \
53 + type_check(_type,typeof_field(_state, _field)), \
54 .set_default = true, \
55 .defval.i = (_type)_defval, \
58 #define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
61 .offset = offsetof(_state, _field) \
62 + type_check(_type, typeof_field(_state, _field)), \
65 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
67 .info = &(qdev_prop_bit), \
69 .offset = offsetof(_state, _field) \
70 + type_check(uint32_t,typeof_field(_state, _field)), \
71 .set_default = true, \
72 .defval.u = (bool)_defval, \
75 #define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \
78 .offset = offsetof(_state, _field) \
79 + type_check(_type, typeof_field(_state, _field)), \
80 .set_default = true, \
81 .defval.u = (_type)_defval, \
84 #define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
87 .offset = offsetof(_state, _field) \
88 + type_check(_type, typeof_field(_state, _field)), \
91 #define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
93 .info = &(qdev_prop_bit64), \
95 .offset = offsetof(_state, _field) \
96 + type_check(uint64_t, typeof_field(_state, _field)), \
97 .set_default = true, \
98 .defval.u = (bool)_defval, \
101 #define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
103 .info = &(qdev_prop_bool), \
104 .offset = offsetof(_state, _field) \
105 + type_check(bool, typeof_field(_state, _field)), \
106 .set_default = true, \
107 .defval.u = (bool)_defval, \
110 #define PROP_ARRAY_LEN_PREFIX "len-"
114 * @_name: name of the array
115 * @_state: name of the device state structure type
116 * @_field: uint32_t field in @_state to hold the array length
117 * @_arrayfield: field in @_state (of type '@_arraytype *') which
118 * will point to the array
119 * @_arrayprop: PropertyInfo defining what property the array elements have
120 * @_arraytype: C type of the array elements
122 * Define device properties for a variable-length array _name. A
123 * static property "len-arrayname" is defined. When the device creator
124 * sets this property to the desired length of array, further dynamic
125 * properties "arrayname[0]", "arrayname[1]", ... are defined so the
126 * device creator can set the array element values. Setting the
127 * "len-arrayname" property more than once is an error.
129 * When the array length is set, the @_field member of the device
130 * struct is set to the array length, and @_arrayfield is set to point
131 * to (zero-initialised) memory allocated for the array. For a zero
132 * length array, @_field will be set to 0 and @_arrayfield to NULL.
133 * It is the responsibility of the device deinit code to free the
134 * @_arrayfield memory.
136 #define DEFINE_PROP_ARRAY(_name, _state, _field, \
137 _arrayfield, _arrayprop, _arraytype) { \
138 .name = (PROP_ARRAY_LEN_PREFIX _name), \
139 .info = &(qdev_prop_arraylen), \
140 .set_default = true, \
142 .offset = offsetof(_state, _field) \
143 + type_check(uint32_t, typeof_field(_state, _field)), \
144 .arrayinfo = &(_arrayprop), \
145 .arrayfieldsize = sizeof(_arraytype), \
146 .arrayoffset = offsetof(_state, _arrayfield), \
149 #define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
151 .info = &(qdev_prop_link), \
152 .offset = offsetof(_state, _field) \
153 + type_check(_ptr_type, typeof_field(_state, _field)), \
154 .link_type = _type, \
157 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
158 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
159 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
160 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
161 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
162 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
163 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
164 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
165 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
166 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
167 #define DEFINE_PROP_INT64(_n, _s, _f, _d) \
168 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
169 #define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
170 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
171 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
172 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
174 #define DEFINE_PROP_CHR(_n, _s, _f) \
175 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend)
176 #define DEFINE_PROP_STRING(_n, _s, _f) \
177 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
178 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
179 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
180 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
181 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *)
182 #define DEFINE_PROP_DRIVE_IOTHREAD(_n, _s, _f) \
183 DEFINE_PROP(_n, _s, _f, qdev_prop_drive_iothread, BlockBackend *)
184 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
185 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
186 #define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
187 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
188 #define DEFINE_PROP_MULTIFD_COMPRESSION(_n, _s, _f, _d) \
189 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_multifd_compression, \
191 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
192 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
194 #define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \
195 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \
197 #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
198 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
199 #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
200 DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
201 #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
202 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
203 #define DEFINE_PROP_OFF_AUTO_PCIBAR(_n, _s, _f, _d) \
204 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_off_auto_pcibar, \
206 #define DEFINE_PROP_PCIE_LINK_SPEED(_n, _s, _f, _d) \
207 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_speed, \
209 #define DEFINE_PROP_PCIE_LINK_WIDTH(_n, _s, _f, _d) \
210 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \
213 #define DEFINE_PROP_UUID(_name, _state, _field) { \
215 .info = &qdev_prop_uuid, \
216 .offset = offsetof(_state, _field) \
217 + type_check(QemuUUID, typeof_field(_state, _field)), \
218 .set_default = true, \
220 #define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
221 DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
223 #define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) { \
225 .info = &qdev_prop_uuid, \
226 .offset = offsetof(_state, _field) \
227 + type_check(QemuUUID, typeof_field(_state, _field)), \
230 #define DEFINE_PROP_END_OF_LIST() \
233 /* Set properties between creation and init. */
234 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
);
235 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
);
236 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
);
237 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
);
238 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
);
239 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
);
240 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
);
241 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
);
242 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
, Chardev
*value
);
243 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
, NetClientState
*value
);
244 void qdev_prop_set_drive(DeviceState
*dev
, const char *name
,
245 BlockBackend
*value
, Error
**errp
);
246 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
,
247 const uint8_t *value
);
248 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
);
250 void qdev_prop_register_global(GlobalProperty
*prop
);
251 int qdev_prop_check_globals(void);
252 void qdev_prop_set_globals(DeviceState
*dev
);
253 void error_set_from_qdev_prop_error(Error
**errp
, int ret
, DeviceState
*dev
,
254 Property
*prop
, const char *value
);
257 * qdev_property_add_static:
258 * @dev: Device to add the property to.
259 * @prop: The qdev property definition.
261 * Add a static QOM property to @dev for qdev property @prop.
262 * On error, store error in @errp. Static properties access data in a struct.
263 * The type of the QOM property is derived from prop->info.
265 void qdev_property_add_static(DeviceState
*dev
, Property
*prop
);
267 void qdev_alias_all_properties(DeviceState
*target
, Object
*source
);
270 * @qdev_prop_set_after_realize:
272 * @name: name of property
273 * @errp: indirect pointer to Error to be set
274 * Set the Error object to report that an attempt was made to set a property
275 * on a device after it has already been realized. This is a utility function
276 * which allows property-setter functions to easily report the error in
277 * a friendly format identifying both the device and the property.
279 void qdev_prop_set_after_realize(DeviceState
*dev
, const char *name
,
283 * qdev_prop_allow_set_link_before_realize:
285 * Set the #Error object if an attempt is made to set the link after realize.
286 * This function should be used as the check() argument to
287 * object_property_add_link().
289 void qdev_prop_allow_set_link_before_realize(const Object
*obj
,
291 Object
*val
, Error
**errp
);