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