]> Git Repo - qemu.git/blame - include/hw/qdev-properties.h
Merge remote-tracking branch 'remotes/dgibson/tags/ppc-for-4.2-20191126' into staging
[qemu.git] / include / hw / qdev-properties.h
CommitLineData
074a86fc
AL
1#ifndef QEMU_QDEV_PROPERTIES_H
2#define QEMU_QDEV_PROPERTIES_H
3
83c9f4ca 4#include "hw/qdev-core.h"
074a86fc
AL
5
6/*** qdev-properties.c ***/
7
1b6b7d10
FZ
8extern const PropertyInfo qdev_prop_bit;
9extern const PropertyInfo qdev_prop_bit64;
10extern const PropertyInfo qdev_prop_bool;
11extern const PropertyInfo qdev_prop_uint8;
12extern const PropertyInfo qdev_prop_uint16;
13extern const PropertyInfo qdev_prop_uint32;
14extern const PropertyInfo qdev_prop_int32;
15extern const PropertyInfo qdev_prop_uint64;
07d1d063 16extern const PropertyInfo qdev_prop_int64;
1b6b7d10
FZ
17extern const PropertyInfo qdev_prop_size;
18extern const PropertyInfo qdev_prop_string;
19extern const PropertyInfo qdev_prop_chr;
493b7830 20extern const PropertyInfo qdev_prop_tpm;
1b6b7d10
FZ
21extern const PropertyInfo qdev_prop_ptr;
22extern const PropertyInfo qdev_prop_macaddr;
23extern const PropertyInfo qdev_prop_on_off_auto;
24extern const PropertyInfo qdev_prop_losttickpolicy;
25extern const PropertyInfo qdev_prop_blockdev_on_error;
26extern const PropertyInfo qdev_prop_bios_chs_trans;
27extern const PropertyInfo qdev_prop_fdc_drive_type;
28extern const PropertyInfo qdev_prop_drive;
307a5f60 29extern const PropertyInfo qdev_prop_drive_iothread;
1b6b7d10 30extern const PropertyInfo qdev_prop_netdev;
1b6b7d10
FZ
31extern const PropertyInfo qdev_prop_pci_devfn;
32extern const PropertyInfo qdev_prop_blocksize;
33extern const PropertyInfo qdev_prop_pci_host_devaddr;
87e6ed56 34extern const PropertyInfo qdev_prop_uuid;
1b6b7d10 35extern const PropertyInfo qdev_prop_arraylen;
88e47b9a 36extern const PropertyInfo qdev_prop_audiodev;
1b6b7d10 37extern const PropertyInfo qdev_prop_link;
c3bbbdbf 38extern const PropertyInfo qdev_prop_off_auto_pcibar;
4695a2c5
AW
39extern const PropertyInfo qdev_prop_pcie_link_speed;
40extern const PropertyInfo qdev_prop_pcie_link_width;
074a86fc
AL
41
42#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
43 .name = (_name), \
44 .info = &(_prop), \
45 .offset = offsetof(_state, _field) \
1ceef9f2 46 + type_check(_type, typeof_field(_state, _field)), \
074a86fc 47 }
3fb2111f 48
85bbd1e7 49#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
074a86fc
AL
50 .name = (_name), \
51 .info = &(_prop), \
52 .offset = offsetof(_state, _field) \
53 + type_check(_type,typeof_field(_state, _field)), \
5cc56cc6 54 .set_default = true, \
76318657 55 .defval.i = (_type)_defval, \
074a86fc 56 }
3fb2111f 57
5cc56cc6
PM
58#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
59 .name = (_name), \
60 .info = &(_prop), \
61 .offset = offsetof(_state, _field) \
62 + type_check(_type, typeof_field(_state, _field)), \
63 }
64
074a86fc
AL
65#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
66 .name = (_name), \
67 .info = &(qdev_prop_bit), \
68 .bitnr = (_bit), \
69 .offset = offsetof(_state, _field) \
70 + type_check(uint32_t,typeof_field(_state, _field)), \
5cc56cc6 71 .set_default = true, \
3fb2111f
MAL
72 .defval.u = (bool)_defval, \
73 }
74
75#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \
76 .name = (_name), \
77 .info = &(_prop), \
78 .offset = offsetof(_state, _field) \
79 + type_check(_type, typeof_field(_state, _field)), \
5cc56cc6 80 .set_default = true, \
3fb2111f 81 .defval.u = (_type)_defval, \
074a86fc 82 }
3fb2111f 83
5cc56cc6
PM
84#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
85 .name = (_name), \
86 .info = &(_prop), \
87 .offset = offsetof(_state, _field) \
88 + type_check(_type, typeof_field(_state, _field)), \
89 }
90
fdba6d96
GH
91#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
92 .name = (_name), \
8aedc369 93 .info = &(qdev_prop_bit64), \
fdba6d96
GH
94 .bitnr = (_bit), \
95 .offset = offsetof(_state, _field) \
96 + type_check(uint64_t, typeof_field(_state, _field)), \
5cc56cc6 97 .set_default = true, \
3fb2111f 98 .defval.u = (bool)_defval, \
fdba6d96 99 }
074a86fc 100
72cc5137
IM
101#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
102 .name = (_name), \
103 .info = &(qdev_prop_bool), \
104 .offset = offsetof(_state, _field) \
105 + type_check(bool, typeof_field(_state, _field)), \
5cc56cc6 106 .set_default = true, \
3fb2111f 107 .defval.u = (bool)_defval, \
72cc5137
IM
108 }
109
0be6bfac
PM
110#define PROP_ARRAY_LEN_PREFIX "len-"
111
112/**
113 * DEFINE_PROP_ARRAY:
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
121 *
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.
128 *
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.
135 */
136#define DEFINE_PROP_ARRAY(_name, _state, _field, \
137 _arrayfield, _arrayprop, _arraytype) { \
138 .name = (PROP_ARRAY_LEN_PREFIX _name), \
139 .info = &(qdev_prop_arraylen), \
5cc56cc6 140 .set_default = true, \
d9a7b125 141 .defval.u = 0, \
0be6bfac
PM
142 .offset = offsetof(_state, _field) \
143 + type_check(uint32_t, typeof_field(_state, _field)), \
0be6bfac
PM
144 .arrayinfo = &(_arrayprop), \
145 .arrayfieldsize = sizeof(_arraytype), \
146 .arrayoffset = offsetof(_state, _arrayfield), \
147 }
148
5b4ff3c6
FZ
149#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
150 .name = (_name), \
151 .info = &(qdev_prop_link), \
152 .offset = offsetof(_state, _field) \
153 + type_check(_ptr_type, typeof_field(_state, _field)), \
154 .link_type = _type, \
155 }
156
074a86fc 157#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
3fb2111f 158 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
074a86fc 159#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
3fb2111f 160 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
074a86fc 161#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
3fb2111f 162 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
074a86fc 163#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
85bbd1e7 164 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
074a86fc 165#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
3fb2111f 166 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
07d1d063
PX
167#define DEFINE_PROP_INT64(_n, _s, _f, _d) \
168 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
e8cd45c7 169#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
3fb2111f 170 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
074a86fc 171#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
85bbd1e7 172 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
074a86fc 173
c272758f
MA
174/*
175 * Please avoid pointer properties. If you must use them, you must
176 * cover them in their device's class init function as follows:
177 *
178 * - If the property must be set, the device cannot be used with
179 * device_add, so add code like this:
180 * |* Reason: pointer property "NAME-OF-YOUR-PROP" *|
181 * DeviceClass *dc = DEVICE_CLASS(class);
e90f2a8c 182 * dc->user_creatable = false;
c272758f
MA
183 *
184 * - If the property may safely remain null, document it like this:
185 * |*
186 * * Note: pointer property "interrupt_vector" may remain null, thus
e90f2a8c 187 * * no need for dc->user_creatable = false;
c272758f
MA
188 * *|
189 */
074a86fc
AL
190#define DEFINE_PROP_PTR(_n, _s, _f) \
191 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
c272758f 192
074a86fc 193#define DEFINE_PROP_CHR(_n, _s, _f) \
becdfa00 194 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend)
074a86fc
AL
195#define DEFINE_PROP_STRING(_n, _s, _f) \
196 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
197#define DEFINE_PROP_NETDEV(_n, _s, _f) \
1ceef9f2 198 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
074a86fc 199#define DEFINE_PROP_DRIVE(_n, _s, _f) \
4be74634 200 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *)
307a5f60
KW
201#define DEFINE_PROP_DRIVE_IOTHREAD(_n, _s, _f) \
202 DEFINE_PROP(_n, _s, _f, qdev_prop_drive_iothread, BlockBackend *)
074a86fc
AL
203#define DEFINE_PROP_MACADDR(_n, _s, _f) \
204 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
55e8a154 205#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
85bbd1e7 206 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
074a86fc 207#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
85bbd1e7 208 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
074a86fc 209 LostTickPolicy)
8c398252 210#define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \
85bbd1e7 211 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \
8c398252 212 BlockdevOnError)
074a86fc 213#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
85bbd1e7 214 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
0eb28a42 215#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
3fb2111f 216 DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
074a86fc
AL
217#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
218 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
ed03d749
FK
219#define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \
220 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
c3bbbdbf
AW
221#define DEFINE_PROP_OFF_AUTO_PCIBAR(_n, _s, _f, _d) \
222 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_off_auto_pcibar, \
223 OffAutoPCIBAR)
4695a2c5
AW
224#define DEFINE_PROP_PCIE_LINK_SPEED(_n, _s, _f, _d) \
225 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_speed, \
226 PCIExpLinkSpeed)
227#define DEFINE_PROP_PCIE_LINK_WIDTH(_n, _s, _f, _d) \
228 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pcie_link_width, \
229 PCIExpLinkWidth)
074a86fc 230
87e6ed56
RK
231#define DEFINE_PROP_UUID(_name, _state, _field) { \
232 .name = (_name), \
233 .info = &qdev_prop_uuid, \
234 .offset = offsetof(_state, _field) \
235 + type_check(QemuUUID, typeof_field(_state, _field)), \
236 .set_default = true, \
237 }
88e47b9a
KZ
238#define DEFINE_PROP_AUDIODEV(_n, _s, _f) \
239 DEFINE_PROP(_n, _s, _f, qdev_prop_audiodev, QEMUSoundCard)
87e6ed56 240
a65f4d40
CM
241#define DEFINE_PROP_UUID_NODEFAULT(_name, _state, _field) { \
242 .name = (_name), \
243 .info = &qdev_prop_uuid, \
244 .offset = offsetof(_state, _field) \
245 + type_check(QemuUUID, typeof_field(_state, _field)), \
246 }
247
074a86fc
AL
248#define DEFINE_PROP_END_OF_LIST() \
249 {}
250
251/* Set properties between creation and init. */
252void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
074a86fc
AL
253void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
254void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
255void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
256void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
257void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
258void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
259void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
0ec7b3e7 260void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value);
074a86fc 261void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
9b3d111a
MA
262void qdev_prop_set_drive(DeviceState *dev, const char *name,
263 BlockBackend *value, Error **errp);
606fd0e2
KK
264void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
265 const uint8_t *value);
074a86fc
AL
266void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
267/* FIXME: Remove opaque pointer properties. */
268void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
269
a404b612 270void qdev_prop_register_global(GlobalProperty *prop);
d828c430 271int qdev_prop_check_globals(void);
25f8dd96 272void qdev_prop_set_globals(DeviceState *dev);
074a86fc
AL
273void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
274 Property *prop, const char *value);
275
276/**
d9d8d452
C
277 * qdev_property_add_static:
278 * @dev: Device to add the property to.
279 * @prop: The qdev property definition.
280 * @errp: location to store error information.
281 *
282 * Add a static QOM property to @dev for qdev property @prop.
283 * On error, store error in @errp. Static properties access data in a struct.
284 * The type of the QOM property is derived from prop->info.
074a86fc
AL
285 */
286void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
287
67cc7e0a
SH
288void qdev_alias_all_properties(DeviceState *target, Object *source);
289
b000dfbd
PM
290/**
291 * @qdev_prop_set_after_realize:
292 * @dev: device
293 * @name: name of property
294 * @errp: indirect pointer to Error to be set
295 * Set the Error object to report that an attempt was made to set a property
296 * on a device after it has already been realized. This is a utility function
297 * which allows property-setter functions to easily report the error in
298 * a friendly format identifying both the device and the property.
299 */
300void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
301 Error **errp);
39f72ef9
SH
302
303/**
304 * qdev_prop_allow_set_link_before_realize:
305 *
306 * Set the #Error object if an attempt is made to set the link after realize.
307 * This function should be used as the check() argument to
308 * object_property_add_link().
309 */
8f5d58ef
IM
310void qdev_prop_allow_set_link_before_realize(const Object *obj,
311 const char *name,
39f72ef9
SH
312 Object *val, Error **errp);
313
074a86fc 314#endif
This page took 0.427242 seconds and 4 git commands to generate.