Statistics
| Branch: | Revision:

root / hw / qdev.h @ 6e4ec3f9

History | View | Annotate | Download (22.1 kB)

1
#ifndef QDEV_H
2
#define QDEV_H
3

    
4
#include "hw.h"
5
#include "qemu-queue.h"
6
#include "qemu-char.h"
7
#include "qemu-option.h"
8
#include "qapi/qapi-visit-core.h"
9
#include "qemu/object.h"
10

    
11
typedef struct Property Property;
12

    
13
typedef struct PropertyInfo PropertyInfo;
14

    
15
typedef struct CompatProperty CompatProperty;
16

    
17
typedef struct DeviceInfo DeviceInfo;
18

    
19
typedef struct BusState BusState;
20

    
21
typedef struct BusInfo BusInfo;
22

    
23
enum DevState {
24
    DEV_STATE_CREATED = 1,
25
    DEV_STATE_INITIALIZED,
26
};
27

    
28
enum {
29
    DEV_NVECTORS_UNSPECIFIED = -1,
30
};
31

    
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
 */
41
typedef 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
 */
54
typedef void (DevicePropertyRelease)(DeviceState *dev,
55
                                     const char *name,
56
                                     void *opaque);
57

    
58
typedef 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

    
70
#define TYPE_DEVICE "device"
71
#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
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)
74

    
75
typedef struct DeviceClass {
76
    ObjectClass parent_class;
77
    DeviceInfo *info;
78
    void (*reset)(DeviceState *dev);
79
} DeviceClass;
80

    
81
/* This structure should not be accessed directly.  We declare it here
82
   so that it can be embedded in individual device state structures.  */
83
struct DeviceState {
84
    Object parent_obj;
85

    
86
    const char *id;
87
    enum DevState state;
88
    QemuOpts *opts;
89
    int hotplugged;
90
    BusState *parent_bus;
91
    int num_gpio_out;
92
    qemu_irq *gpio_out;
93
    int num_gpio_in;
94
    qemu_irq *gpio_in;
95
    QLIST_HEAD(, BusState) child_bus;
96
    int num_child_bus;
97
    QTAILQ_ENTRY(DeviceState) sibling;
98
    int instance_id_alias;
99
    int alias_required_for_version;
100

    
101
    /**
102
     * This tracks the number of references between devices.  See @qdev_ref for
103
     * more information.
104
     */
105
    uint32_t ref;
106

    
107
    QTAILQ_HEAD(, DeviceProperty) properties;
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;
112
};
113

    
114
typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
115
typedef char *(*bus_get_dev_path)(DeviceState *dev);
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
 */
121
typedef char *(*bus_get_fw_dev_path)(DeviceState *dev);
122
typedef int (qbus_resetfn)(BusState *bus);
123

    
124
struct BusInfo {
125
    const char *name;
126
    size_t size;
127
    bus_dev_printfn print_dev;
128
    bus_get_dev_path get_dev_path;
129
    bus_get_fw_dev_path get_fw_dev_path;
130
    qbus_resetfn *reset;
131
    Property *props;
132
};
133

    
134
struct BusState {
135
    DeviceState *parent;
136
    BusInfo *info;
137
    const char *name;
138
    int allow_hotplug;
139
    int qdev_allocated;
140
    QTAILQ_HEAD(ChildrenHead, DeviceState) children;
141
    QLIST_ENTRY(BusState) sibling;
142
};
143

    
144
struct Property {
145
    const char   *name;
146
    PropertyInfo *info;
147
    int          offset;
148
    int          bitnr;
149
    void         *defval;
150
};
151

    
152
enum PropertyType {
153
    PROP_TYPE_UNSPEC = 0,
154
    PROP_TYPE_UINT8,
155
    PROP_TYPE_UINT16,
156
    PROP_TYPE_UINT32,
157
    PROP_TYPE_INT32,
158
    PROP_TYPE_UINT64,
159
    PROP_TYPE_TADDR,
160
    PROP_TYPE_MACADDR,
161
    PROP_TYPE_DRIVE,
162
    PROP_TYPE_CHR,
163
    PROP_TYPE_STRING,
164
    PROP_TYPE_NETDEV,
165
    PROP_TYPE_VLAN,
166
    PROP_TYPE_PTR,
167
    PROP_TYPE_BIT,
168
};
169

    
170
struct PropertyInfo {
171
    const char *name;
172
    const char *legacy_name;
173
    size_t size;
174
    enum PropertyType type;
175
    int64_t min;
176
    int64_t max;
177
    int (*parse)(DeviceState *dev, Property *prop, const char *str);
178
    int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
179
    void (*free)(DeviceState *dev, Property *prop);
180
    DevicePropertyAccessor *get;
181
    DevicePropertyAccessor *set;
182
};
183

    
184
typedef struct GlobalProperty {
185
    const char *driver;
186
    const char *property;
187
    const char *value;
188
    QTAILQ_ENTRY(GlobalProperty) next;
189
} GlobalProperty;
190

    
191
/*** Board API.  This should go away once we have a machine config file.  ***/
192

    
193
DeviceState *qdev_create(BusState *bus, const char *name);
194
DeviceState *qdev_try_create(BusState *bus, const char *name);
195
bool qdev_exists(const char *name);
196
int qdev_device_help(QemuOpts *opts);
197
DeviceState *qdev_device_add(QemuOpts *opts);
198
int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
199
void qdev_init_nofail(DeviceState *dev);
200
void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
201
                                 int required_for_version);
202
int qdev_unplug(DeviceState *dev);
203
void qdev_free(DeviceState *dev);
204
int qdev_simple_unplug_cb(DeviceState *dev);
205
void qdev_machine_creation_done(void);
206
bool qdev_machine_modified(void);
207

    
208
qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
209
void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
210

    
211
BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
212

    
213
/*** Device API.  ***/
214

    
215
typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
216
typedef int (*qdev_event)(DeviceState *dev);
217
typedef void (*qdev_resetfn)(DeviceState *dev);
218

    
219
struct DeviceInfo {
220
    const char *name;
221
    const char *fw_name;
222
    const char *alias;
223
    const char *desc;
224
    size_t size;
225
    Property *props;
226
    int no_user;
227

    
228
    /* callbacks */
229
    qdev_resetfn reset;
230

    
231
    /* device state */
232
    const VMStateDescription *vmsd;
233

    
234
    /**
235
     * See #TypeInfo::class_init()
236
     */
237
    void (*class_init)(ObjectClass *klass, void *data);
238

    
239
    /* Private to qdev / bus.  */
240
    qdev_initfn init;
241
    qdev_event unplug;
242
    qdev_event exit;
243
    BusInfo *bus_info;
244
    struct DeviceInfo *next;
245
};
246
extern DeviceInfo *device_info_list;
247

    
248
void qdev_register(DeviceInfo *info);
249
void qdev_register_subclass(DeviceInfo *info, const char *parent);
250

    
251
/* Register device properties.  */
252
/* GPIO inputs also double as IRQ sinks.  */
253
void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
254
void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
255

    
256
CharDriverState *qdev_init_chardev(DeviceState *dev);
257

    
258
BusState *qdev_get_parent_bus(DeviceState *dev);
259

    
260
/*** BUS API. ***/
261

    
262
DeviceState *qdev_find_recursive(BusState *bus, const char *id);
263

    
264
/* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
265
typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
266
typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
267

    
268
void qbus_create_inplace(BusState *bus, BusInfo *info,
269
                         DeviceState *parent, const char *name);
270
BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
271
/* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
272
 *         < 0 if either devfn or busfn terminate walk somewhere in cursion,
273
 *           0 otherwise. */
274
int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
275
                       qbus_walkerfn *busfn, void *opaque);
276
int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
277
                       qbus_walkerfn *busfn, void *opaque);
278
void qdev_reset_all(DeviceState *dev);
279
void qbus_reset_all_fn(void *opaque);
280

    
281
void qbus_free(BusState *bus);
282

    
283
#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
284

    
285
/* This should go away once we get rid of the NULL bus hack */
286
BusState *sysbus_get_default(void);
287

    
288
/*** monitor commands ***/
289

    
290
void do_info_qtree(Monitor *mon);
291
void do_info_qdm(Monitor *mon);
292
int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
293
int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
294

    
295
/*** qdev-properties.c ***/
296

    
297
extern PropertyInfo qdev_prop_bit;
298
extern PropertyInfo qdev_prop_uint8;
299
extern PropertyInfo qdev_prop_uint16;
300
extern PropertyInfo qdev_prop_uint32;
301
extern PropertyInfo qdev_prop_int32;
302
extern PropertyInfo qdev_prop_uint64;
303
extern PropertyInfo qdev_prop_hex8;
304
extern PropertyInfo qdev_prop_hex32;
305
extern PropertyInfo qdev_prop_hex64;
306
extern PropertyInfo qdev_prop_string;
307
extern PropertyInfo qdev_prop_chr;
308
extern PropertyInfo qdev_prop_ptr;
309
extern PropertyInfo qdev_prop_macaddr;
310
extern PropertyInfo qdev_prop_drive;
311
extern PropertyInfo qdev_prop_netdev;
312
extern PropertyInfo qdev_prop_vlan;
313
extern PropertyInfo qdev_prop_pci_devfn;
314

    
315
#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
316
        .name      = (_name),                                    \
317
        .info      = &(_prop),                                   \
318
        .offset    = offsetof(_state, _field)                    \
319
            + type_check(_type,typeof_field(_state, _field)),    \
320
        }
321
#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
322
        .name      = (_name),                                           \
323
        .info      = &(_prop),                                          \
324
        .offset    = offsetof(_state, _field)                           \
325
            + type_check(_type,typeof_field(_state, _field)),           \
326
        .defval    = (_type[]) { _defval },                             \
327
        }
328
#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) {  \
329
        .name      = (_name),                                    \
330
        .info      = &(qdev_prop_bit),                           \
331
        .bitnr    = (_bit),                                      \
332
        .offset    = offsetof(_state, _field)                    \
333
            + type_check(uint32_t,typeof_field(_state, _field)), \
334
        .defval    = (bool[]) { (_defval) },                     \
335
        }
336

    
337
#define DEFINE_PROP_UINT8(_n, _s, _f, _d)                       \
338
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
339
#define DEFINE_PROP_UINT16(_n, _s, _f, _d)                      \
340
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
341
#define DEFINE_PROP_UINT32(_n, _s, _f, _d)                      \
342
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
343
#define DEFINE_PROP_INT32(_n, _s, _f, _d)                      \
344
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
345
#define DEFINE_PROP_UINT64(_n, _s, _f, _d)                      \
346
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
347
#define DEFINE_PROP_HEX8(_n, _s, _f, _d)                       \
348
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
349
#define DEFINE_PROP_HEX32(_n, _s, _f, _d)                       \
350
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
351
#define DEFINE_PROP_HEX64(_n, _s, _f, _d)                       \
352
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
353
#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d)                   \
354
    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
355

    
356
#define DEFINE_PROP_PTR(_n, _s, _f)             \
357
    DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
358
#define DEFINE_PROP_CHR(_n, _s, _f)             \
359
    DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
360
#define DEFINE_PROP_STRING(_n, _s, _f)             \
361
    DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
362
#define DEFINE_PROP_NETDEV(_n, _s, _f)             \
363
    DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
364
#define DEFINE_PROP_VLAN(_n, _s, _f)             \
365
    DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
366
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
367
    DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
368
#define DEFINE_PROP_MACADDR(_n, _s, _f)         \
369
    DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
370

    
371
#define DEFINE_PROP_END_OF_LIST()               \
372
    {}
373

    
374
/* Set properties between creation and init.  */
375
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
376
int qdev_prop_exists(DeviceState *dev, const char *name);
377
int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
378
void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
379
void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
380
void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
381
void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
382
void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
383
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
384
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
385
void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
386
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
387
void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
388
void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
389
int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
390
void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
391
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
392
/* FIXME: Remove opaque pointer properties.  */
393
void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
394
void qdev_prop_set_defaults(DeviceState *dev, Property *props);
395

    
396
void qdev_prop_register_global_list(GlobalProperty *props);
397
void qdev_prop_set_globals(DeviceState *dev);
398
void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
399
                                    Property *prop, const char *value);
400

    
401
DeviceInfo *qdev_get_info(DeviceState *dev);
402

    
403
static inline const char *qdev_fw_name(DeviceState *dev)
404
{
405
    DeviceInfo *info = qdev_get_info(dev);
406

    
407
    if (info->fw_name) {
408
        return info->fw_name;
409
    } else if (info->alias) {
410
        return info->alias;
411
    }
412

    
413
    return object_get_typename(OBJECT(dev));
414
}
415

    
416
char *qdev_get_fw_dev_path(DeviceState *dev);
417
/* This is a nasty hack to allow passing a NULL bus to qdev_create.  */
418
extern struct BusInfo system_bus_info;
419

    
420
/**
421
 * @qdev_ref
422
 *
423
 * Increase the reference count of a device.  A device cannot be freed as long
424
 * as its reference count is greater than zero.
425
 *
426
 * @dev - the device
427
 */
428
void qdev_ref(DeviceState *dev);
429

    
430
/**
431
 * @qdef_unref
432
 *
433
 * Decrease the reference count of a device.  A device cannot be freed as long
434
 * as its reference count is greater than zero.
435
 *
436
 * @dev - the device
437
 */
438
void qdev_unref(DeviceState *dev);
439

    
440
/**
441
 * @qdev_property_add - add a new property to a device
442
 *
443
 * @dev - the device to add a property to
444
 *
445
 * @name - the name of the property.  This can contain any character except for
446
 *         a forward slash.  In general, you should use hyphens '-' instead of
447
 *         underscores '_' when naming properties.
448
 *
449
 * @type - the type name of the property.  This namespace is pretty loosely
450
 *         defined.  Sub namespaces are constructed by using a prefix and then
451
 *         to angle brackets.  For instance, the type 'virtio-net-pci' in the
452
 *         'link' namespace would be 'link<virtio-net-pci>'.
453
 *
454
 * @get - the getter to be called to read a property.  If this is NULL, then
455
 *        the property cannot be read.
456
 *
457
 * @set - the setter to be called to write a property.  If this is NULL,
458
 *        then the property cannot be written.
459
 *
460
 * @release - called when the property is removed from the device.  This is
461
 *            meant to allow a property to free its opaque upon device
462
 *            destruction.  This may be NULL.
463
 *
464
 * @opaque - an opaque pointer to pass to the callbacks for the property
465
 *
466
 * @errp - returns an error if this function fails
467
 */
468
void qdev_property_add(DeviceState *dev, const char *name, const char *type,
469
                       DevicePropertyAccessor *get, DevicePropertyAccessor *set,
470
                       DevicePropertyRelease *release,
471
                       void *opaque, Error **errp);
472

    
473
/**
474
 * @qdev_property_get - reads a property from a device
475
 *
476
 * @dev - the device
477
 *
478
 * @v - the visitor that will receive the property value.  This should be an
479
 *      Output visitor and the data will be written with @name as the name.
480
 *
481
 * @name - the name of the property
482
 *
483
 * @errp - returns an error if this function fails
484
 */
485
void qdev_property_get(DeviceState *dev, Visitor *v, const char *name,
486
                       Error **errp);
487

    
488
/**
489
 * @qdev_property_set - writes a property to a device
490
 *
491
 * @dev - the device
492
 *
493
 * @v - the visitor that will be used to write the property value.  This should
494
 *      be an Input visitor and the data will be first read with @name as the
495
 *      name and then written as the property value.
496
 *
497
 * @name - the name of the property
498
 *
499
 * @errp - returns an error if this function fails
500
 */
501
void qdev_property_set(DeviceState *dev, Visitor *v, const char *name,
502
                       Error **errp);
503

    
504
/**
505
 * @qdev_property_get_type - returns the type of a property
506
 *
507
 * @dev - the device
508
 *
509
 * @name - the name of the property
510
 *
511
 * @errp - returns an error if this function fails
512
 *
513
 * Returns:
514
 *   The type name of the property.
515
 */
516
const char *qdev_property_get_type(DeviceState *dev, const char *name,
517
                                   Error **errp);
518

    
519
/**
520
 * @qdev_property_add_static - add a @Property to a device referencing a
521
 * field in a struct.
522
 */
523
void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
524

    
525
/**
526
 * @qdev_get_root - returns the root device of the composition tree
527
 *
528
 * Returns:
529
 *   The root of the composition tree.
530
 */
531
DeviceState *qdev_get_root(void);
532

    
533
/**
534
 * @qdev_get_canonical_path - returns the canonical path for a device.  This
535
 * is the path within the composition tree starting from the root.
536
 *
537
 * Returns:
538
 *   The canonical path in the composition tree.
539
 */
540
gchar *qdev_get_canonical_path(DeviceState *dev);
541

    
542
/**
543
 * @qdev_resolve_path - resolves a path returning a device
544
 *
545
 * There are two types of supported paths--absolute paths and partial paths.
546
 * 
547
 * Absolute paths are derived from the root device and can follow child<> or
548
 * link<> properties.  Since they can follow link<> properties, they can be
549
 * arbitrarily long.  Absolute paths look like absolute filenames and are
550
 * prefixed with a leading slash.
551
 * 
552
 * Partial paths look like relative filenames.  They do not begin with a
553
 * prefix.  The matching rules for partial paths are subtle but designed to make
554
 * specifying devices easy.  At each level of the composition tree, the partial
555
 * path is matched as an absolute path.  The first match is not returned.  At
556
 * least two matches are searched for.  A successful result is only returned if
557
 * only one match is founded.  If more than one match is found, a flag is
558
 * return to indicate that the match was ambiguous.
559
 *
560
 * @path - the path to resolve
561
 *
562
 * @ambiguous - returns true if the path resolution failed because of an
563
 *              ambiguous match
564
 *
565
 * Returns:
566
 *   The matched device or NULL on path lookup failure.
567
 */
568
DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
569

    
570
/**
571
 * @qdev_property_add_child - Add a child property to a device
572
 *
573
 * Child properties form the composition tree.  All devices need to be a child
574
 * of another device.  Devices can only be a child of one device.
575
 *
576
 * There is no way for a child to determine what its parent is.  It is not
577
 * a bidirectional relationship.  This is by design.
578
 *
579
 * @dev - the device to add a property to
580
 *
581
 * @name - the name of the property
582
 *
583
 * @child - the child device
584
 *
585
 * @errp - if an error occurs, a pointer to an area to store the area
586
 */
587
void qdev_property_add_child(DeviceState *dev, const char *name,
588
                             DeviceState *child, Error **errp);
589

    
590
/**
591
 * @qdev_property_add_link - Add a link property to a device
592
 *
593
 * Links establish relationships between devices.  Links are unidirectional
594
 * although two links can be combined to form a bidirectional relationship
595
 * between devices.
596
 *
597
 * Links form the graph in the device model.
598
 *
599
 * @dev - the device to add a property to
600
 *
601
 * @name - the name of the property
602
 *
603
 * @type - the qdev type of the link
604
 *
605
 * @child - a pointer to where the link device reference is stored
606
 *
607
 * @errp - if an error occurs, a pointer to an area to store the area
608
 */
609
void qdev_property_add_link(DeviceState *dev, const char *name,
610
                            const char *type, DeviceState **child,
611
                            Error **errp);
612

    
613
/**
614
 * @qdev_property_add_str
615
 *
616
 * Add a string property using getters/setters.  This function will add a
617
 * property of type 'string'.
618
 *
619
 * @dev - the device to add a property to
620
 *
621
 * @name - the name of the property
622
 *
623
 * @get - the getter or NULL if the property is write-only.  This function must
624
 *        return a string to be freed by @g_free().
625
 *
626
 * @set - the setter or NULL if the property is read-only
627
 *
628
 * @errp - if an error occurs, a pointer to an area to store the error
629
 */
630
void qdev_property_add_str(DeviceState *dev, const char *name,
631
                           char *(*get)(DeviceState *, Error **),
632
                           void (*set)(DeviceState *, const char *, Error **),
633
                           Error **errp);
634

    
635
/**
636
 * @qdev_get_type
637
 *
638
 * Returns the string representation of the type of this object.
639
 *
640
 * @dev - the device
641
 *
642
 * @errp - if an error occurs, a pointer to an area to store the error
643
 *
644
 * Returns: a string representing the type.  This must be freed by the caller
645
 *          with g_free().
646
 */
647
char *qdev_get_type(DeviceState *dev, Error **errp);
648

    
649
/**
650
 * @qdev_machine_init
651
 *
652
 * Initialize platform devices before machine init.  This is a hack until full
653
 * support for composition is added.
654
 */
655
void qdev_machine_init(void);
656

    
657
/**
658
 * @device_reset
659
 *
660
 * Reset a single device (by calling the reset method).
661
 */
662
void device_reset(DeviceState *dev);
663

    
664
#endif