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