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