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