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