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