1#ifndef QEMU_QDEV_PROPERTIES_H
2#define QEMU_QDEV_PROPERTIES_H
3
4#include "hw/qdev-core.h"
5
6
7
8
9
10
11
12
13
14
15struct Property {
16 const char *name;
17 const PropertyInfo *info;
18 ptrdiff_t offset;
19 uint8_t bitnr;
20 uint64_t bitmask;
21 bool set_default;
22 union {
23 int64_t i;
24 uint64_t u;
25 } defval;
26 int arrayoffset;
27 const PropertyInfo *arrayinfo;
28 int arrayfieldsize;
29 const char *link_type;
30};
31
32struct PropertyInfo {
33 const char *name;
34 const char *description;
35 const QEnumLookup *enum_table;
36 bool realized_set_allowed;
37 int (*print)(Object *obj, Property *prop, char *dest, size_t len);
38 void (*set_default_value)(ObjectProperty *op, const Property *prop);
39 ObjectProperty *(*create)(ObjectClass *oc, const char *name,
40 Property *prop);
41 ObjectPropertyAccessor *get;
42 ObjectPropertyAccessor *set;
43 ObjectPropertyRelease *release;
44};
45
46
47
48
49extern const PropertyInfo qdev_prop_bit;
50extern const PropertyInfo qdev_prop_bit64;
51extern const PropertyInfo qdev_prop_bool;
52extern const PropertyInfo qdev_prop_enum;
53extern const PropertyInfo qdev_prop_uint8;
54extern const PropertyInfo qdev_prop_uint16;
55extern const PropertyInfo qdev_prop_uint32;
56extern const PropertyInfo qdev_prop_int32;
57extern const PropertyInfo qdev_prop_uint64;
58extern const PropertyInfo qdev_prop_uint64_checkmask;
59extern const PropertyInfo qdev_prop_int64;
60extern const PropertyInfo qdev_prop_size;
61extern const PropertyInfo qdev_prop_string;
62extern const PropertyInfo qdev_prop_on_off_auto;
63extern const PropertyInfo qdev_prop_size32;
64extern const PropertyInfo qdev_prop_arraylen;
65extern const PropertyInfo qdev_prop_link;
66
67#define DEFINE_PROP(_name, _state, _field, _prop, _type, ...) { \
68 .name = (_name), \
69 .info = &(_prop), \
70 .offset = offsetof(_state, _field) \
71 + type_check(_type, typeof_field(_state, _field)), \
72 __VA_ARGS__ \
73 }
74
75#define DEFINE_PROP_SIGNED(_name, _state, _field, _defval, _prop, _type) \
76 DEFINE_PROP(_name, _state, _field, _prop, _type, \
77 .set_default = true, \
78 .defval.i = (_type)_defval)
79
80#define DEFINE_PROP_SIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
81 DEFINE_PROP(_name, _state, _field, _prop, _type)
82
83#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) \
84 DEFINE_PROP(_name, _state, _field, qdev_prop_bit, uint32_t, \
85 .bitnr = (_bit), \
86 .set_default = true, \
87 .defval.u = (bool)_defval)
88
89#define DEFINE_PROP_UNSIGNED(_name, _state, _field, _defval, _prop, _type) \
90 DEFINE_PROP(_name, _state, _field, _prop, _type, \
91 .set_default = true, \
92 .defval.u = (_type)_defval)
93
94#define DEFINE_PROP_UNSIGNED_NODEFAULT(_name, _state, _field, _prop, _type) \
95 DEFINE_PROP(_name, _state, _field, _prop, _type)
96
97#define DEFINE_PROP_BIT64(_name, _state, _field, _bit, _defval) \
98 DEFINE_PROP(_name, _state, _field, qdev_prop_bit64, uint64_t, \
99 .bitnr = (_bit), \
100 .set_default = true, \
101 .defval.u = (bool)_defval)
102
103#define DEFINE_PROP_BOOL(_name, _state, _field, _defval) \
104 DEFINE_PROP(_name, _state, _field, qdev_prop_bool, bool, \
105 .set_default = true, \
106 .defval.u = (bool)_defval)
107
108
109
110
111
112
113#define DEFINE_PROP_UINT64_CHECKMASK(_name, _state, _field, _bitmask) \
114 DEFINE_PROP(_name, _state, _field, qdev_prop_uint64_checkmask, uint64_t, \
115 .bitmask = (_bitmask), \
116 .set_default = false)
117
118#define PROP_ARRAY_LEN_PREFIX "len-"
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144#define DEFINE_PROP_ARRAY(_name, _state, _field, \
145 _arrayfield, _arrayprop, _arraytype) \
146 DEFINE_PROP((PROP_ARRAY_LEN_PREFIX _name), \
147 _state, _field, qdev_prop_arraylen, uint32_t, \
148 .set_default = true, \
149 .defval.u = 0, \
150 .arrayinfo = &(_arrayprop), \
151 .arrayfieldsize = sizeof(_arraytype), \
152 .arrayoffset = offsetof(_state, _arrayfield))
153
154#define DEFINE_PROP_LINK(_name, _state, _field, _type, _ptr_type) \
155 DEFINE_PROP(_name, _state, _field, qdev_prop_link, _ptr_type, \
156 .link_type = _type)
157
158#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
159 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
160#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
161 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
162#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
163 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
164#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
165 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int32, int32_t)
166#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
167 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
168#define DEFINE_PROP_INT64(_n, _s, _f, _d) \
169 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_int64, int64_t)
170#define DEFINE_PROP_SIZE(_n, _s, _f, _d) \
171 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size, uint64_t)
172#define DEFINE_PROP_STRING(_n, _s, _f) \
173 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
174#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
175 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
176#define DEFINE_PROP_SIZE32(_n, _s, _f, _d) \
177 DEFINE_PROP_UNSIGNED(_n, _s, _f, _d, qdev_prop_size32, uint32_t)
178
179#define DEFINE_PROP_END_OF_LIST() \
180 {}
181
182
183
184
185
186
187bool qdev_prop_set_drive_err(DeviceState *dev, const char *name,
188 BlockBackend *value, Error **errp);
189
190
191
192
193
194void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
195void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
196void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
197void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
198void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
199void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
200void qdev_prop_set_string(DeviceState *dev, const char *name, const char *value);
201void qdev_prop_set_chr(DeviceState *dev, const char *name, Chardev *value);
202void qdev_prop_set_netdev(DeviceState *dev, const char *name, NetClientState *value);
203void qdev_prop_set_drive(DeviceState *dev, const char *name,
204 BlockBackend *value);
205void qdev_prop_set_macaddr(DeviceState *dev, const char *name,
206 const uint8_t *value);
207void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
208
209void *object_field_prop_ptr(Object *obj, Property *prop);
210
211void qdev_prop_register_global(GlobalProperty *prop);
212const GlobalProperty *qdev_find_global_prop(Object *obj,
213 const char *name);
214int qdev_prop_check_globals(void);
215void qdev_prop_set_globals(DeviceState *dev);
216void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
217 const char *name, const char *value);
218
219
220
221
222
223
224
225
226
227
228void qdev_property_add_static(DeviceState *dev, Property *prop);
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243void qdev_alias_all_properties(DeviceState *target, Object *source);
244
245
246
247
248
249
250
251
252
253
254
255void qdev_prop_set_after_realize(DeviceState *dev, const char *name,
256 Error **errp);
257
258
259
260
261
262
263
264
265void qdev_prop_allow_set_link_before_realize(const Object *obj,
266 const char *name,
267 Object *val, Error **errp);
268
269#endif
270