]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/qdev-properties.h
qapi: Empty out qapi-schema.json
[mirror_qemu.git] / include / hw / qdev-properties.h
CommitLineData
074a86fc
AL
1#ifndef QEMU_QDEV_PROPERTIES_H
2#define QEMU_QDEV_PROPERTIES_H
3
112ed241
MA
4#include "qapi/qapi-types-block.h"
5#include "qapi/qapi-types-misc.h"
83c9f4ca 6#include "hw/qdev-core.h"
074a86fc
AL
7
8/*** qdev-properties.c ***/
9
1b6b7d10
FZ
10extern const PropertyInfo qdev_prop_bit;
11extern const PropertyInfo qdev_prop_bit64;
12extern const PropertyInfo qdev_prop_bool;
13extern const PropertyInfo qdev_prop_uint8;
14extern const PropertyInfo qdev_prop_uint16;
15extern const PropertyInfo qdev_prop_uint32;
16extern const PropertyInfo qdev_prop_int32;
17extern const PropertyInfo qdev_prop_uint64;
07d1d063 18extern const PropertyInfo qdev_prop_int64;
1b6b7d10
FZ
19extern const PropertyInfo qdev_prop_size;
20extern const PropertyInfo qdev_prop_string;
21extern const PropertyInfo qdev_prop_chr;
493b7830 22extern const PropertyInfo qdev_prop_tpm;
1b6b7d10
FZ
23extern const PropertyInfo qdev_prop_ptr;
24extern const PropertyInfo qdev_prop_macaddr;
25extern const PropertyInfo qdev_prop_on_off_auto;
26extern const PropertyInfo qdev_prop_losttickpolicy;
27extern const PropertyInfo qdev_prop_blockdev_on_error;
28extern const PropertyInfo qdev_prop_bios_chs_trans;
29extern const PropertyInfo qdev_prop_fdc_drive_type;
30extern const PropertyInfo qdev_prop_drive;
31extern const PropertyInfo qdev_prop_netdev;
32extern const PropertyInfo qdev_prop_vlan;
33extern const PropertyInfo qdev_prop_pci_devfn;
34extern const PropertyInfo qdev_prop_blocksize;
35extern const PropertyInfo qdev_prop_pci_host_devaddr;
87e6ed56 36extern const PropertyInfo qdev_prop_uuid;
1b6b7d10
FZ
37extern const PropertyInfo qdev_prop_arraylen;
38extern const PropertyInfo qdev_prop_link;
c3bbbdbf 39extern const PropertyInfo qdev_prop_off_auto_pcibar;
074a86fc
AL
40
41#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
42 .name = (_name), \
43 .info = &(_prop), \
44 .offset = offsetof(_state, _field) \
1ceef9f2 45 + type_check(_type, typeof_field(_state, _field)), \
074a86fc 46 }
3fb2111f 47
85bbd1e7 48#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
074a86fc
AL
49 .name = (_name), \
50 .info = &(_prop), \
51 .offset = offsetof(_state, _field) \
52 + type_check(_type,typeof_field(_state, _field)), \
5cc56cc6 53 .set_default = true, \
76318657 54 .defval.i = (_type)_defval, \
074a86fc 55 }
3fb2111f 56
5cc56cc6
PM
57#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
58 .name = (_name), \
59 .info = &(_prop), \
60 .offset = offsetof(_state, _field) \
61 + type_check(_type, typeof_field(_state, _field)), \
62 }
63
074a86fc
AL
64#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
65 .name = (_name), \
66 .info = &(qdev_prop_bit), \
67 .bitnr = (_bit), \
68 .offset = offsetof(_state, _field) \
69 + type_check(uint32_t,typeof_field(_state, _field)), \
5cc56cc6 70 .set_default = true, \
3fb2111f
MAL
71 .defval.u = (bool)_defval, \
72 }
73
74#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \
75 .name = (_name), \
76 .info = &(_prop), \
77 .offset = offsetof(_state, _field) \
78 + type_check(_type, typeof_field(_state, _field)), \
5cc56cc6 79 .set_default = true, \
3fb2111f 80 .defval.u = (_type)_defval, \
074a86fc 81 }
3fb2111f 82
5cc56cc6
PM
83#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
84 .name = (_name), \
85 .info = &(_prop), \
86 .offset = offsetof(_state, _field) \
87 + type_check(_type, typeof_field(_state, _field)), \
88 }
89
fdba6d96
GH
90#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
91 .name = (_name), \
8aedc369 92 .info = &(qdev_prop_bit64), \
fdba6d96
GH
93 .bitnr = (_bit), \
94 .offset = offsetof(_state, _field) \
95 + type_check(uint64_t, typeof_field(_state, _field)), \
5cc56cc6 96 .set_default = true, \
3fb2111f 97 .defval.u = (bool)_defval, \
fdba6d96 98 }
074a86fc 99
72cc5137
IM
100#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
101 .name = (_name), \
102 .info = &(qdev_prop_bool), \
103 .offset = offsetof(_state, _field) \
104 + type_check(bool, typeof_field(_state, _field)), \
5cc56cc6 105 .set_default = true, \
3fb2111f 106 .defval.u = (bool)_defval, \
72cc5137
IM
107 }
108
0be6bfac
PM
109#define PROP_ARRAY_LEN_PREFIX "len-"
110
111/**
112 * DEFINE_PROP_ARRAY:
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
120 *
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.
127 *
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.
134 */
135#define DEFINE_PROP_ARRAY(_name, _state, _field, \
136 _arrayfield, _arrayprop, _arraytype) { \
137 .name = (PROP_ARRAY_LEN_PREFIX _name), \
138 .info = &(qdev_prop_arraylen), \
5cc56cc6 139 .set_default = true, \
d9a7b125 140 .defval.u = 0, \
0be6bfac
PM
141 .offset = offsetof(_state, _field) \
142 + type_check(uint32_t, typeof_field(_state, _field)), \
0be6bfac
PM
143 .arrayinfo = &(_arrayprop), \
144 .arrayfieldsize = sizeof(_arraytype), \
145 .arrayoffset = offsetof(_state, _arrayfield), \
146 }
147
5b4ff3c6
FZ
148#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
149 .name = (_name), \
150 .info = &(qdev_prop_link), \
151 .offset = offsetof(_state, _field) \
152 + type_check(_ptr_type, typeof_field(_state, _field)), \
153 .link_type = _type, \
154 }
155
074a86fc 156#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
3fb2111f 157 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
074a86fc 158#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
3fb2111f 159 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
074a86fc 160#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
3fb2111f 161 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
074a86fc 162#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
85bbd1e7 163 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
074a86fc 164#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
3fb2111f 165 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
07d1d063
PX
166#define DEFINE_PROP_INT64(_n, _s, _f, _d) \
167 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
e8cd45c7 168#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
3fb2111f 169 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
074a86fc 170#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
85bbd1e7 171 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
074a86fc 172
c272758f
MA
173/*
174 * Please avoid pointer properties. If you must use them, you must
175 * cover them in their device's class init function as follows:
176 *
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);
e90f2a8c 181 * dc->user_creatable = false;
c272758f
MA
182 *
183 * - If the property may safely remain null, document it like this:
184 * |*
185 * * Note: pointer property "interrupt_vector" may remain null, thus
e90f2a8c 186 * * no need for dc->user_creatable = false;
c272758f
MA
187 * *|
188 */
074a86fc
AL
189#define DEFINE_PROP_PTR(_n, _s, _f) \
190 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
c272758f 191
074a86fc 192#define DEFINE_PROP_CHR(_n, _s, _f) \
becdfa00 193 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend)
074a86fc
AL
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) \
1ceef9f2 197 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
074a86fc 198#define DEFINE_PROP_VLAN(_n, _s, _f) \
1ceef9f2 199 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
074a86fc 200#define DEFINE_PROP_DRIVE(_n, _s, _f) \
4be74634 201 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *)
074a86fc
AL
202#define DEFINE_PROP_MACADDR(_n, _s, _f) \
203 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
55e8a154 204#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
85bbd1e7 205 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
074a86fc 206#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
85bbd1e7 207 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
074a86fc 208 LostTickPolicy)
8c398252 209#define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \
85bbd1e7 210 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \
8c398252 211 BlockdevOnError)
074a86fc 212#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
85bbd1e7 213 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
0eb28a42 214#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
3fb2111f 215 DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
074a86fc
AL
216#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
217 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
ed03d749
FK
218#define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \
219 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
c3bbbdbf
AW
220#define DEFINE_PROP_OFF_AUTO_PCIBAR(_n, _s, _f, _d) \
221 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_off_auto_pcibar, \
222 OffAutoPCIBAR)
074a86fc 223
87e6ed56
RK
224#define DEFINE_PROP_UUID(_name, _state, _field) { \
225 .name = (_name), \
226 .info = &qdev_prop_uuid, \
227 .offset = offsetof(_state, _field) \
228 + type_check(QemuUUID, typeof_field(_state, _field)), \
229 .set_default = true, \
230 }
231
074a86fc
AL
232#define DEFINE_PROP_END_OF_LIST() \
233 {}
234
235/* Set properties between creation and init. */
236void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
074a86fc
AL
237void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
238void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
239void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
240void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
241void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
242void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
243void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
0ec7b3e7 244void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value);
074a86fc 245void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
9b3d111a
MA
246void qdev_prop_set_drive(DeviceState *dev, const char *name,
247 BlockBackend *value, Error **errp);
606fd0e2
KK
248void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
249 const uint8_t *value);
074a86fc
AL
250void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
251/* FIXME: Remove opaque pointer properties. */
252void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
253
a404b612 254void qdev_prop_register_global(GlobalProperty *prop);
074a86fc 255void qdev_prop_register_global_list(GlobalProperty *props);
d828c430 256int qdev_prop_check_globals(void);
25f8dd96 257void qdev_prop_set_globals(DeviceState *dev);
074a86fc
AL
258void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
259 Property *prop, const char *value);
260
60d7caca
PX
261/**
262 * register_compat_prop:
263 *
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.
268 *
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.
272 *
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.
276 *
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
280 */
281void register_compat_prop(const char *driver, const char *property,
282 const char *value);
9ffea096
PX
283/*
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)
287 */
288void register_compat_props_array(GlobalProperty *prop);
60d7caca 289
074a86fc 290/**
d9d8d452
C
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.
295 *
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.
074a86fc
AL
299 */
300void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
301
67cc7e0a
SH
302void qdev_alias_all_properties(DeviceState *target, Object *source);
303
b000dfbd
PM
304/**
305 * @qdev_prop_set_after_realize:
306 * @dev: device
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.
313 */
314void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
315 Error **errp);
39f72ef9
SH
316
317/**
318 * qdev_prop_allow_set_link_before_realize:
319 *
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().
323 */
8f5d58ef
IM
324void qdev_prop_allow_set_link_before_realize(const Object *obj,
325 const char *name,
39f72ef9
SH
326 Object *val, Error **errp);
327
074a86fc 328#endif