]>
Commit | Line | Data |
---|---|---|
aae9460e PB |
1 | #ifndef QDEV_H |
2 | #define QDEV_H | |
3 | ||
4 | #include "hw.h" | |
72cf2d4f | 5 | #include "qemu-queue.h" |
313feaab | 6 | #include "qemu-char.h" |
f31d07d1 | 7 | #include "qemu-option.h" |
44677ded | 8 | #include "qapi/qapi-visit-core.h" |
aae9460e | 9 | |
ee6847d1 GH |
10 | typedef struct Property Property; |
11 | ||
12 | typedef struct PropertyInfo PropertyInfo; | |
aae9460e | 13 | |
b6b61144 GH |
14 | typedef struct CompatProperty CompatProperty; |
15 | ||
ee6847d1 | 16 | typedef struct DeviceInfo DeviceInfo; |
aae9460e | 17 | |
02e2da45 | 18 | typedef struct BusState BusState; |
4d6ae674 | 19 | |
10c4c98a GH |
20 | typedef struct BusInfo BusInfo; |
21 | ||
131ec1bd GH |
22 | enum DevState { |
23 | DEV_STATE_CREATED = 1, | |
24 | DEV_STATE_INITIALIZED, | |
25 | }; | |
26 | ||
75422b0d AS |
27 | enum { |
28 | DEV_NVECTORS_UNSPECIFIED = -1, | |
29 | }; | |
30 | ||
44677ded AL |
31 | /** |
32 | * @DevicePropertyAccessor - called when trying to get/set a property | |
33 | * | |
34 | * @dev the device that owns the property | |
35 | * @v the visitor that contains the property data | |
36 | * @opaque the device property opaque | |
37 | * @name the name of the property | |
38 | * @errp a pointer to an Error that is filled if getting/setting fails. | |
39 | */ | |
40 | typedef void (DevicePropertyAccessor)(DeviceState *dev, | |
41 | Visitor *v, | |
42 | void *opaque, | |
43 | const char *name, | |
44 | Error **errp); | |
45 | ||
46 | /** | |
47 | * @DevicePropertyRelease - called when a property is removed from a device | |
48 | * | |
49 | * @dev the device that owns the property | |
50 | * @name the name of the property | |
51 | * @opaque the opaque registered with the property | |
52 | */ | |
53 | typedef void (DevicePropertyRelease)(DeviceState *dev, | |
54 | const char *name, | |
55 | void *opaque); | |
56 | ||
57 | typedef struct DeviceProperty | |
58 | { | |
59 | gchar *name; | |
60 | gchar *type; | |
61 | DevicePropertyAccessor *get; | |
62 | DevicePropertyAccessor *set; | |
63 | DevicePropertyRelease *release; | |
64 | void *opaque; | |
65 | ||
66 | QTAILQ_ENTRY(DeviceProperty) node; | |
67 | } DeviceProperty; | |
68 | ||
aae9460e PB |
69 | /* This structure should not be accessed directly. We declare it here |
70 | so that it can be embedded in individual device state structures. */ | |
02e2da45 | 71 | struct DeviceState { |
f31d07d1 | 72 | const char *id; |
131ec1bd | 73 | enum DevState state; |
ef80b466 | 74 | QemuOpts *opts; |
3418bd25 | 75 | int hotplugged; |
042f84d0 | 76 | DeviceInfo *info; |
02e2da45 | 77 | BusState *parent_bus; |
aae9460e PB |
78 | int num_gpio_out; |
79 | qemu_irq *gpio_out; | |
80 | int num_gpio_in; | |
81 | qemu_irq *gpio_in; | |
72cf2d4f | 82 | QLIST_HEAD(, BusState) child_bus; |
d271de9f | 83 | int num_child_bus; |
d8bb00d6 | 84 | QTAILQ_ENTRY(DeviceState) sibling; |
4d2ffa08 JK |
85 | int instance_id_alias; |
86 | int alias_required_for_version; | |
85ed303b AL |
87 | |
88 | /** | |
89 | * This tracks the number of references between devices. See @qdev_ref for | |
90 | * more information. | |
91 | */ | |
92 | uint32_t ref; | |
44677ded AL |
93 | |
94 | QTAILQ_HEAD(, DeviceProperty) properties; | |
b2b6c39a AL |
95 | |
96 | /* Do not, under any circumstance, use this parent link below anywhere | |
97 | * outside of qdev.c. You have been warned. */ | |
98 | DeviceState *parent; | |
02e2da45 PB |
99 | }; |
100 | ||
10c4c98a | 101 | typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); |
6772b936 | 102 | typedef char *(*bus_get_dev_path)(DeviceState *dev); |
21150814 GN |
103 | /* |
104 | * This callback is used to create Open Firmware device path in accordance with | |
105 | * OF spec http://forthworks.com/standards/of1275.pdf. Indicidual bus bindings | |
106 | * can be found here http://playground.sun.com/1275/bindings/. | |
107 | */ | |
108 | typedef char *(*bus_get_fw_dev_path)(DeviceState *dev); | |
b4694b7c | 109 | typedef int (qbus_resetfn)(BusState *bus); |
6772b936 | 110 | |
10c4c98a GH |
111 | struct BusInfo { |
112 | const char *name; | |
113 | size_t size; | |
114 | bus_dev_printfn print_dev; | |
6772b936 | 115 | bus_get_dev_path get_dev_path; |
21150814 | 116 | bus_get_fw_dev_path get_fw_dev_path; |
b4694b7c | 117 | qbus_resetfn *reset; |
ee6847d1 | 118 | Property *props; |
10c4c98a | 119 | }; |
02e2da45 PB |
120 | |
121 | struct BusState { | |
122 | DeviceState *parent; | |
10c4c98a | 123 | BusInfo *info; |
02e2da45 | 124 | const char *name; |
3418bd25 | 125 | int allow_hotplug; |
cd739fb6 | 126 | int qdev_allocated; |
f48a7a6e | 127 | QTAILQ_HEAD(ChildrenHead, DeviceState) children; |
72cf2d4f | 128 | QLIST_ENTRY(BusState) sibling; |
aae9460e PB |
129 | }; |
130 | ||
ee6847d1 GH |
131 | struct Property { |
132 | const char *name; | |
133 | PropertyInfo *info; | |
134 | int offset; | |
d2364ee4 | 135 | int bitnr; |
ee6847d1 GH |
136 | void *defval; |
137 | }; | |
138 | ||
139 | enum PropertyType { | |
140 | PROP_TYPE_UNSPEC = 0, | |
c7cc172d | 141 | PROP_TYPE_UINT8, |
ee6847d1 GH |
142 | PROP_TYPE_UINT16, |
143 | PROP_TYPE_UINT32, | |
316940b0 | 144 | PROP_TYPE_INT32, |
5a053d1f | 145 | PROP_TYPE_UINT64, |
ee6847d1 GH |
146 | PROP_TYPE_TADDR, |
147 | PROP_TYPE_MACADDR, | |
14b41872 | 148 | PROP_TYPE_DRIVE, |
313feaab | 149 | PROP_TYPE_CHR, |
59419663 | 150 | PROP_TYPE_STRING, |
2ef924b4 | 151 | PROP_TYPE_NETDEV, |
851bec09 | 152 | PROP_TYPE_VLAN, |
ee6847d1 | 153 | PROP_TYPE_PTR, |
d2364ee4 | 154 | PROP_TYPE_BIT, |
ee6847d1 GH |
155 | }; |
156 | ||
157 | struct PropertyInfo { | |
158 | const char *name; | |
159 | size_t size; | |
160 | enum PropertyType type; | |
161 | int (*parse)(DeviceState *dev, Property *prop, const char *str); | |
162 | int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); | |
d21357df | 163 | void (*free)(DeviceState *dev, Property *prop); |
ee6847d1 GH |
164 | }; |
165 | ||
458fb679 | 166 | typedef struct GlobalProperty { |
b6b61144 GH |
167 | const char *driver; |
168 | const char *property; | |
169 | const char *value; | |
458fb679 GH |
170 | QTAILQ_ENTRY(GlobalProperty) next; |
171 | } GlobalProperty; | |
b6b61144 | 172 | |
aae9460e PB |
173 | /*** Board API. This should go away once we have a machine config file. ***/ |
174 | ||
02e2da45 | 175 | DeviceState *qdev_create(BusState *bus, const char *name); |
0bcdeda7 | 176 | DeviceState *qdev_try_create(BusState *bus, const char *name); |
ff952ba2 | 177 | int qdev_device_help(QemuOpts *opts); |
f31d07d1 | 178 | DeviceState *qdev_device_add(QemuOpts *opts); |
747bbdf7 | 179 | int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT; |
e23a1b33 | 180 | void qdev_init_nofail(DeviceState *dev); |
4d2ffa08 JK |
181 | void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, |
182 | int required_for_version); | |
3418bd25 | 183 | int qdev_unplug(DeviceState *dev); |
02e2da45 | 184 | void qdev_free(DeviceState *dev); |
3418bd25 GH |
185 | int qdev_simple_unplug_cb(DeviceState *dev); |
186 | void qdev_machine_creation_done(void); | |
0ac8ef71 | 187 | bool qdev_machine_modified(void); |
aae9460e | 188 | |
aae9460e PB |
189 | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); |
190 | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); | |
191 | ||
02e2da45 | 192 | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); |
4d6ae674 | 193 | |
aae9460e PB |
194 | /*** Device API. ***/ |
195 | ||
81a322d4 | 196 | typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); |
3418bd25 | 197 | typedef int (*qdev_event)(DeviceState *dev); |
7f23f812 | 198 | typedef void (*qdev_resetfn)(DeviceState *dev); |
aae9460e | 199 | |
02e2da45 | 200 | struct DeviceInfo { |
074f2fff | 201 | const char *name; |
779206de | 202 | const char *fw_name; |
3320e56e GH |
203 | const char *alias; |
204 | const char *desc; | |
074f2fff | 205 | size_t size; |
ee6847d1 | 206 | Property *props; |
3320e56e | 207 | int no_user; |
074f2fff | 208 | |
959f733a | 209 | /* callbacks */ |
7f23f812 | 210 | qdev_resetfn reset; |
959f733a | 211 | |
391a079e GH |
212 | /* device state */ |
213 | const VMStateDescription *vmsd; | |
214 | ||
074f2fff | 215 | /* Private to qdev / bus. */ |
02e2da45 | 216 | qdev_initfn init; |
3418bd25 GH |
217 | qdev_event unplug; |
218 | qdev_event exit; | |
10c4c98a | 219 | BusInfo *bus_info; |
042f84d0 | 220 | struct DeviceInfo *next; |
02e2da45 | 221 | }; |
0958b4cc | 222 | extern DeviceInfo *device_info_list; |
02e2da45 | 223 | |
074f2fff | 224 | void qdev_register(DeviceInfo *info); |
aae9460e PB |
225 | |
226 | /* Register device properties. */ | |
067a3ddc | 227 | /* GPIO inputs also double as IRQ sinks. */ |
aae9460e PB |
228 | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); |
229 | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); | |
230 | ||
231 | CharDriverState *qdev_init_chardev(DeviceState *dev); | |
232 | ||
02e2da45 | 233 | BusState *qdev_get_parent_bus(DeviceState *dev); |
aae9460e | 234 | |
02e2da45 PB |
235 | /*** BUS API. ***/ |
236 | ||
a2ee6b4f IY |
237 | DeviceState *qdev_find_recursive(BusState *bus, const char *id); |
238 | ||
81699d8a AL |
239 | /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ |
240 | typedef int (qbus_walkerfn)(BusState *bus, void *opaque); | |
241 | typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); | |
242 | ||
cd739fb6 GH |
243 | void qbus_create_inplace(BusState *bus, BusInfo *info, |
244 | DeviceState *parent, const char *name); | |
10c4c98a | 245 | BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name); |
81699d8a AL |
246 | /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, |
247 | * < 0 if either devfn or busfn terminate walk somewhere in cursion, | |
248 | * 0 otherwise. */ | |
249 | int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, | |
250 | qbus_walkerfn *busfn, void *opaque); | |
251 | int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn, | |
252 | qbus_walkerfn *busfn, void *opaque); | |
5af0a04b | 253 | void qdev_reset_all(DeviceState *dev); |
80376c3f IY |
254 | void qbus_reset_all_fn(void *opaque); |
255 | ||
131ec1bd | 256 | void qbus_free(BusState *bus); |
02e2da45 PB |
257 | |
258 | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) | |
259 | ||
ec990eb6 AL |
260 | /* This should go away once we get rid of the NULL bus hack */ |
261 | BusState *sysbus_get_default(void); | |
262 | ||
cae4956e GH |
263 | /*** monitor commands ***/ |
264 | ||
265 | void do_info_qtree(Monitor *mon); | |
f6c64e0e | 266 | void do_info_qdm(Monitor *mon); |
8bc27249 | 267 | int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data); |
17a38eaa | 268 | int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data); |
cae4956e | 269 | |
ee6847d1 GH |
270 | /*** qdev-properties.c ***/ |
271 | ||
d2364ee4 | 272 | extern PropertyInfo qdev_prop_bit; |
c7cc172d | 273 | extern PropertyInfo qdev_prop_uint8; |
ee6847d1 GH |
274 | extern PropertyInfo qdev_prop_uint16; |
275 | extern PropertyInfo qdev_prop_uint32; | |
316940b0 | 276 | extern PropertyInfo qdev_prop_int32; |
5a053d1f | 277 | extern PropertyInfo qdev_prop_uint64; |
6835678c | 278 | extern PropertyInfo qdev_prop_hex8; |
ee6847d1 | 279 | extern PropertyInfo qdev_prop_hex32; |
5a053d1f | 280 | extern PropertyInfo qdev_prop_hex64; |
59419663 | 281 | extern PropertyInfo qdev_prop_string; |
313feaab | 282 | extern PropertyInfo qdev_prop_chr; |
ee6847d1 GH |
283 | extern PropertyInfo qdev_prop_ptr; |
284 | extern PropertyInfo qdev_prop_macaddr; | |
14b41872 | 285 | extern PropertyInfo qdev_prop_drive; |
851bec09 GH |
286 | extern PropertyInfo qdev_prop_netdev; |
287 | extern PropertyInfo qdev_prop_vlan; | |
05cb5fe4 | 288 | extern PropertyInfo qdev_prop_pci_devfn; |
ee6847d1 | 289 | |
cf12b95b GH |
290 | #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ |
291 | .name = (_name), \ | |
292 | .info = &(_prop), \ | |
293 | .offset = offsetof(_state, _field) \ | |
294 | + type_check(_type,typeof_field(_state, _field)), \ | |
295 | } | |
296 | #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \ | |
297 | .name = (_name), \ | |
298 | .info = &(_prop), \ | |
299 | .offset = offsetof(_state, _field) \ | |
300 | + type_check(_type,typeof_field(_state, _field)), \ | |
301 | .defval = (_type[]) { _defval }, \ | |
302 | } | |
d2364ee4 MT |
303 | #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ |
304 | .name = (_name), \ | |
305 | .info = &(qdev_prop_bit), \ | |
306 | .bitnr = (_bit), \ | |
307 | .offset = offsetof(_state, _field) \ | |
308 | + type_check(uint32_t,typeof_field(_state, _field)), \ | |
309 | .defval = (bool[]) { (_defval) }, \ | |
310 | } | |
cf12b95b | 311 | |
c7cc172d JQ |
312 | #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ |
313 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) | |
cf12b95b GH |
314 | #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ |
315 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) | |
316 | #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ | |
317 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) | |
316940b0 GH |
318 | #define DEFINE_PROP_INT32(_n, _s, _f, _d) \ |
319 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t) | |
cf12b95b GH |
320 | #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \ |
321 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) | |
6835678c JK |
322 | #define DEFINE_PROP_HEX8(_n, _s, _f, _d) \ |
323 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t) | |
cf12b95b GH |
324 | #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \ |
325 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t) | |
326 | #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \ | |
327 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t) | |
328 | #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ | |
329 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t) | |
330 | ||
331 | #define DEFINE_PROP_PTR(_n, _s, _f) \ | |
332 | DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) | |
313feaab GH |
333 | #define DEFINE_PROP_CHR(_n, _s, _f) \ |
334 | DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) | |
59419663 GH |
335 | #define DEFINE_PROP_STRING(_n, _s, _f) \ |
336 | DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) | |
2ef924b4 GH |
337 | #define DEFINE_PROP_NETDEV(_n, _s, _f) \ |
338 | DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*) | |
851bec09 GH |
339 | #define DEFINE_PROP_VLAN(_n, _s, _f) \ |
340 | DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*) | |
f8b6cc00 MA |
341 | #define DEFINE_PROP_DRIVE(_n, _s, _f) \ |
342 | DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *) | |
cf12b95b | 343 | #define DEFINE_PROP_MACADDR(_n, _s, _f) \ |
1503fff3 | 344 | DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) |
cf12b95b GH |
345 | |
346 | #define DEFINE_PROP_END_OF_LIST() \ | |
347 | {} | |
348 | ||
ee6847d1 GH |
349 | /* Set properties between creation and init. */ |
350 | void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); | |
d8ed79ae | 351 | int qdev_prop_exists(DeviceState *dev, const char *name); |
ee6847d1 GH |
352 | int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); |
353 | void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); | |
f4594a3b | 354 | void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value); |
c7cc172d | 355 | void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value); |
ee6847d1 GH |
356 | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); |
357 | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); | |
316940b0 | 358 | void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); |
5a053d1f | 359 | void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); |
cc984673 | 360 | void qdev_prop_set_string(DeviceState *dev, const char *name, char *value); |
313feaab | 361 | void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); |
2ef924b4 | 362 | void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value); |
851bec09 | 363 | void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value); |
18846dee MA |
364 | int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT; |
365 | void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value); | |
1503fff3 | 366 | void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); |
ee6847d1 GH |
367 | /* FIXME: Remove opaque pointer properties. */ |
368 | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); | |
369 | void qdev_prop_set_defaults(DeviceState *dev, Property *props); | |
370 | ||
458fb679 GH |
371 | void qdev_prop_register_global_list(GlobalProperty *props); |
372 | void qdev_prop_set_globals(DeviceState *dev); | |
7db4c4e8 PB |
373 | void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev, |
374 | Property *prop, const char *value); | |
b6b61144 | 375 | |
779206de GN |
376 | static inline const char *qdev_fw_name(DeviceState *dev) |
377 | { | |
378 | return dev->info->fw_name ? : dev->info->alias ? : dev->info->name; | |
379 | } | |
380 | ||
1ca4d09a | 381 | char *qdev_get_fw_dev_path(DeviceState *dev); |
a9ff9df1 BS |
382 | /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ |
383 | extern struct BusInfo system_bus_info; | |
384 | ||
85ed303b AL |
385 | /** |
386 | * @qdev_ref | |
387 | * | |
388 | * Increase the reference count of a device. A device cannot be freed as long | |
389 | * as its reference count is greater than zero. | |
390 | * | |
391 | * @dev - the device | |
392 | */ | |
393 | void qdev_ref(DeviceState *dev); | |
394 | ||
395 | /** | |
396 | * @qdef_unref | |
397 | * | |
398 | * Decrease the reference count of a device. A device cannot be freed as long | |
399 | * as its reference count is greater than zero. | |
400 | * | |
401 | * @dev - the device | |
402 | */ | |
403 | void qdev_unref(DeviceState *dev); | |
404 | ||
44677ded AL |
405 | /** |
406 | * @qdev_property_add - add a new property to a device | |
407 | * | |
408 | * @dev - the device to add a property to | |
409 | * | |
410 | * @name - the name of the property. This can contain any character except for | |
411 | * a forward slash. In general, you should use hyphens '-' instead of | |
412 | * underscores '_' when naming properties. | |
413 | * | |
414 | * @type - the type name of the property. This namespace is pretty loosely | |
415 | * defined. Sub namespaces are constructed by using a prefix and then | |
416 | * to angle brackets. For instance, the type 'virtio-net-pci' in the | |
417 | * 'link' namespace would be 'link<virtio-net-pci>'. | |
418 | * | |
419 | * @get - the getter to be called to read a property. If this is NULL, then | |
420 | * the property cannot be read. | |
421 | * | |
422 | * @set - the setter to be called to write a property. If this is NULL, | |
423 | * then the property cannot be written. | |
424 | * | |
425 | * @release - called when the property is removed from the device. This is | |
426 | * meant to allow a property to free its opaque upon device | |
427 | * destruction. This may be NULL. | |
428 | * | |
429 | * @opaque - an opaque pointer to pass to the callbacks for the property | |
430 | * | |
431 | * @errp - returns an error if this function fails | |
432 | */ | |
433 | void qdev_property_add(DeviceState *dev, const char *name, const char *type, | |
434 | DevicePropertyAccessor *get, DevicePropertyAccessor *set, | |
435 | DevicePropertyRelease *release, | |
436 | void *opaque, Error **errp); | |
437 | ||
438 | /** | |
439 | * @qdev_property_get - reads a property from a device | |
440 | * | |
441 | * @dev - the device | |
442 | * | |
443 | * @v - the visitor that will receive the property value. This should be an | |
444 | * Output visitor and the data will be written with @name as the name. | |
445 | * | |
446 | * @name - the name of the property | |
447 | * | |
448 | * @errp - returns an error if this function fails | |
449 | */ | |
450 | void qdev_property_get(DeviceState *dev, Visitor *v, const char *name, | |
451 | Error **errp); | |
452 | ||
453 | /** | |
454 | * @qdev_property_set - writes a property to a device | |
455 | * | |
456 | * @dev - the device | |
457 | * | |
458 | * @v - the visitor that will be used to write the property value. This should | |
459 | * be an Input visitor and the data will be first read with @name as the | |
460 | * name and then written as the property value. | |
461 | * | |
462 | * @name - the name of the property | |
463 | * | |
464 | * @errp - returns an error if this function fails | |
465 | */ | |
466 | void qdev_property_set(DeviceState *dev, Visitor *v, const char *name, | |
467 | Error **errp); | |
468 | ||
469 | /** | |
470 | * @qdev_property_get_type - returns the type of a property | |
471 | * | |
472 | * @dev - the device | |
473 | * | |
474 | * @name - the name of the property | |
475 | * | |
476 | * @errp - returns an error if this function fails | |
477 | * | |
478 | * Returns: | |
479 | * The type name of the property. | |
480 | */ | |
481 | const char *qdev_property_get_type(DeviceState *dev, const char *name, | |
482 | Error **errp); | |
483 | ||
a5296ca9 AL |
484 | /** |
485 | * @qdev_property_add_legacy - add a legacy @Property to a device | |
486 | * | |
487 | * DO NOT USE THIS IN NEW CODE! | |
488 | */ | |
489 | void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp); | |
490 | ||
a10f07a7 AL |
491 | /** |
492 | * @qdev_get_root - returns the root device of the composition tree | |
493 | * | |
494 | * Returns: | |
495 | * The root of the composition tree. | |
496 | */ | |
497 | DeviceState *qdev_get_root(void); | |
498 | ||
f9fbd2fd AL |
499 | /** |
500 | * @qdev_get_canonical_path - returns the canonical path for a device. This | |
501 | * is the path within the composition tree starting from the root. | |
502 | * | |
503 | * Returns: | |
504 | * The canonical path in the composition tree. | |
505 | */ | |
506 | gchar *qdev_get_canonical_path(DeviceState *dev); | |
507 | ||
dc45c21f AL |
508 | /** |
509 | * @qdev_resolve_path - resolves a path returning a device | |
510 | * | |
511 | * There are two types of supported paths--absolute paths and partial paths. | |
512 | * | |
513 | * Absolute paths are derived from the root device and can follow child<> or | |
514 | * link<> properties. Since they can follow link<> properties, they can be | |
515 | * arbitrarily long. Absolute paths look like absolute filenames and are | |
516 | * prefixed with a leading slash. | |
517 | * | |
518 | * Partial paths look like relative filenames. They do not begin with a | |
519 | * prefix. The matching rules for partial paths are subtle but designed to make | |
520 | * specifying devices easy. At each level of the composition tree, the partial | |
521 | * path is matched as an absolute path. The first match is not returned. At | |
522 | * least two matches are searched for. A successful result is only returned if | |
523 | * only one match is founded. If more than one match is found, a flag is | |
524 | * return to indicate that the match was ambiguous. | |
525 | * | |
526 | * @path - the path to resolve | |
527 | * | |
528 | * @ambiguous - returns true if the path resolution failed because of an | |
529 | * ambiguous match | |
530 | * | |
531 | * Returns: | |
532 | * The matched device or NULL on path lookup failure. | |
533 | */ | |
534 | DeviceState *qdev_resolve_path(const char *path, bool *ambiguous); | |
535 | ||
3de1c3e8 AL |
536 | /** |
537 | * @qdev_property_add_child - Add a child property to a device | |
538 | * | |
539 | * Child properties form the composition tree. All devices need to be a child | |
540 | * of another device. Devices can only be a child of one device. | |
541 | * | |
542 | * There is no way for a child to determine what its parent is. It is not | |
543 | * a bidirectional relationship. This is by design. | |
544 | * | |
545 | * @dev - the device to add a property to | |
546 | * | |
547 | * @name - the name of the property | |
548 | * | |
549 | * @child - the child device | |
550 | * | |
551 | * @errp - if an error occurs, a pointer to an area to store the area | |
552 | */ | |
553 | void qdev_property_add_child(DeviceState *dev, const char *name, | |
554 | DeviceState *child, Error **errp); | |
555 | ||
83e94fb8 AL |
556 | /** |
557 | * @qdev_property_add_link - Add a link property to a device | |
558 | * | |
559 | * Links establish relationships between devices. Links are unidirectional | |
560 | * although two links can be combined to form a bidirectional relationship | |
561 | * between devices. | |
562 | * | |
563 | * Links form the graph in the device model. | |
564 | * | |
565 | * @dev - the device to add a property to | |
566 | * | |
567 | * @name - the name of the property | |
568 | * | |
569 | * @type - the qdev type of the link | |
570 | * | |
571 | * @child - a pointer to where the link device reference is stored | |
572 | * | |
573 | * @errp - if an error occurs, a pointer to an area to store the area | |
574 | */ | |
575 | void qdev_property_add_link(DeviceState *dev, const char *name, | |
576 | const char *type, DeviceState **child, | |
577 | Error **errp); | |
578 | ||
6a146eba AL |
579 | /** |
580 | * @qdev_property_add_str | |
581 | * | |
582 | * Add a string property using getters/setters. This function will add a | |
583 | * property of type 'string'. | |
584 | * | |
585 | * @dev - the device to add a property to | |
586 | * | |
587 | * @name - the name of the property | |
588 | * | |
589 | * @get - the getter or NULL if the property is write-only. This function must | |
590 | * return a string to be freed by @g_free(). | |
591 | * | |
592 | * @set - the setter or NULL if the property is read-only | |
593 | * | |
594 | * @errp - if an error occurs, a pointer to an area to store the error | |
595 | */ | |
596 | void qdev_property_add_str(DeviceState *dev, const char *name, | |
597 | char *(*get)(DeviceState *, Error **), | |
598 | void (*set)(DeviceState *, const char *, Error **), | |
599 | Error **errp); | |
600 | ||
cd34d667 AL |
601 | /** |
602 | * @qdev_get_type | |
603 | * | |
604 | * Returns the string representation of the type of this object. | |
605 | * | |
606 | * @dev - the device | |
607 | * | |
608 | * @errp - if an error occurs, a pointer to an area to store the error | |
609 | * | |
610 | * Returns: a string representing the type. This must be freed by the caller | |
611 | * with g_free(). | |
612 | */ | |
613 | char *qdev_get_type(DeviceState *dev, Error **errp); | |
614 | ||
aae9460e | 615 | #endif |