1#ifndef QEMU_QDEV_PROPERTIES_H
2#define QEMU_QDEV_PROPERTIES_H
3
4#include "hw/qdev-core.h"
5
6
7
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;
16extern const PropertyInfo qdev_prop_int64;
17extern const PropertyInfo qdev_prop_size;
18extern const PropertyInfo qdev_prop_string;
19extern const PropertyInfo qdev_prop_chr;
20extern const PropertyInfo qdev_prop_ptr;
21extern const PropertyInfo qdev_prop_macaddr;
22extern const PropertyInfo qdev_prop_on_off_auto;
23extern const PropertyInfo qdev_prop_losttickpolicy;
24extern const PropertyInfo qdev_prop_blockdev_on_error;
25extern const PropertyInfo qdev_prop_bios_chs_trans;
26extern const PropertyInfo qdev_prop_fdc_drive_type;
27extern const PropertyInfo qdev_prop_drive;
28extern const PropertyInfo qdev_prop_netdev;
29extern const PropertyInfo qdev_prop_vlan;
30extern const PropertyInfo qdev_prop_pci_devfn;
31extern const PropertyInfo qdev_prop_blocksize;
32extern const PropertyInfo qdev_prop_pci_host_devaddr;
33extern const PropertyInfo qdev_prop_arraylen;
34extern const PropertyInfo qdev_prop_link;
35
36#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
37 .name = (_name), \
38 .info = &(_prop), \
39 .offset = offsetof(_state, _field) \
40 + type_check(_type, typeof_field(_state, _field)), \
41 }
42
43#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) { \
44 .name = (_name), \
45 .info = &(_prop), \
46 .offset = offsetof(_state, _field) \
47 + type_check(_type,typeof_field(_state, _field)), \
48 .set_default = true, \
49 .defval.i = (_type)_defval, \
50 }
51
52#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
53 .name = (_name), \
54 .info = &(_prop), \
55 .offset = offsetof(_state, _field) \
56 + type_check(_type, typeof_field(_state, _field)), \
57 }
58
59#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
60 .name = (_name), \
61 .info = &(qdev_prop_bit), \
62 .bitnr = (_bit), \
63 .offset = offsetof(_state, _field) \
64 + type_check(uint32_t,typeof_field(_state, _field)), \
65 .set_default = true, \
66 .defval.u = (bool)_defval, \
67 }
68
69#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) { \
70 .name = (_name), \
71 .info = &(_prop), \
72 .offset = offsetof(_state, _field) \
73 + type_check(_type, typeof_field(_state, _field)), \
74 .set_default = true, \
75 .defval.u = (_type)_defval, \
76 }
77
78#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) { \
79 .name = (_name), \
80 .info = &(_prop), \
81 .offset = offsetof(_state, _field) \
82 + type_check(_type, typeof_field(_state, _field)), \
83 }
84
85#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) { \
86 .name = (_name), \
87 .info = &(qdev_prop_bit64), \
88 .bitnr = (_bit), \
89 .offset = offsetof(_state, _field) \
90 + type_check(uint64_t, typeof_field(_state, _field)), \
91 .set_default = true, \
92 .defval.u = (bool)_defval, \
93 }
94
95#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) { \
96 .name = (_name), \
97 .info = &(qdev_prop_bool), \
98 .offset = offsetof(_state, _field) \
99 + type_check(bool, typeof_field(_state, _field)), \
100 .set_default = true, \
101 .defval.u = (bool)_defval, \
102 }
103
104#define PROP_ARRAY_LEN_PREFIX "len-"
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130#define DEFINE_PROP_ARRAY(_name, _state, _field, \
131 _arrayfield, _arrayprop, _arraytype) { \
132 .name = (PROP_ARRAY_LEN_PREFIX _name), \
133 .info = &(qdev_prop_arraylen), \
134 .set_default = true, \
135 .defval.u = 0, \
136 .offset = offsetof(_state, _field) \
137 + type_check(uint32_t, typeof_field(_state, _field)), \
138 .arrayinfo = &(_arrayprop), \
139 .arrayfieldsize = sizeof(_arraytype), \
140 .arrayoffset = offsetof(_state, _arrayfield), \
141 }
142
143#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) { \
144 .name = (_name), \
145 .info = &(qdev_prop_link), \
146 .offset = offsetof(_state, _field) \
147 + type_check(_ptr_type, typeof_field(_state, _field)), \
148 .link_type = _type, \
149 }
150
151#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
152 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
153#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
154 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
155#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
156 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
157#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
158 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
159#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
160 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
161#define DEFINE_PROP_INT64(_n, _s, _f, _d) \
162 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
163#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
164 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
165#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
166 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184#define DEFINE_PROP_PTR(_n, _s, _f) \
185 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
186
187#define DEFINE_PROP_CHR(_n, _s, _f) \
188 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharBackend)
189#define DEFINE_PROP_STRING(_n, _s, _f) \
190 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
191#define DEFINE_PROP_NETDEV(_n, _s, _f) \
192 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NICPeers)
193#define DEFINE_PROP_VLAN(_n, _s, _f) \
194 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NICPeers)
195#define DEFINE_PROP_DRIVE(_n, _s, _f) \
196 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockBackend *)
197#define DEFINE_PROP_MACADDR(_n, _s, _f) \
198 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
199#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
200 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
201#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
202 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
203 LostTickPolicy)
204#define DEFINE_PROP_BLOCKDEV_ON_ERROR(_n, _s, _f, _d) \
205 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_blockdev_on_error, \
206 BlockdevOnError)
207#define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
208 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
209#define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
210 DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
211#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
212 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
213#define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \
214 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, MemoryRegion *)
215
216#define DEFINE_PROP_END_OF_LIST() \
217 {}
218
219
220void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
221void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
222void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
223void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
224void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
225void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
226void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
227void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
228void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value);
229void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
230void qdev_prop_set_drive(DeviceState *dev, const char *name,
231 BlockBackend *value, Error **errp);
232void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
233 const uint8_t *value);
234void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
235
236void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
237
238void qdev_prop_register_global(GlobalProperty *prop);
239void qdev_prop_register_global_list(GlobalProperty *props);
240int qdev_prop_check_globals(void);
241void qdev_prop_set_globals(DeviceState *dev);
242void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
243 Property *prop, const char *value);
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265void register_compat_prop(const char *driver, const char *property,
266 const char *value);
267
268
269
270
271
272void register_compat_props_array(GlobalProperty *prop);
273
274
275
276
277
278
279
280
281
282
283
284void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
285
286void qdev_alias_all_properties(DeviceState *target, Object *source);
287
288
289
290
291
292
293
294
295
296
297
298void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
299 Error **errp);
300
301
302
303
304
305
306
307
308void qdev_prop_allow_set_link_before_realize(const Object *obj,
309 const char *name,
310 Object *val, Error **errp);
311
312#endif
313