]> git.proxmox.com Git - mirror_qemu.git/blob - hw/qdev.h
qdev: kill off DeviceInfo list
[mirror_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 };
262
263 void qdev_register(DeviceInfo *info);
264 void qdev_register_subclass(DeviceInfo *info, const char *parent);
265
266 /* Register device properties. */
267 /* GPIO inputs also double as IRQ sinks. */
268 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
269 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
270
271 CharDriverState *qdev_init_chardev(DeviceState *dev);
272
273 BusState *qdev_get_parent_bus(DeviceState *dev);
274
275 /*** BUS API. ***/
276
277 DeviceState *qdev_find_recursive(BusState *bus, const char *id);
278
279 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
280 typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
281 typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
282
283 void qbus_create_inplace(BusState *bus, BusInfo *info,
284 DeviceState *parent, const char *name);
285 BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
286 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
287 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
288 * 0 otherwise. */
289 int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
290 qbus_walkerfn *busfn, void *opaque);
291 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
292 qbus_walkerfn *busfn, void *opaque);
293 void qdev_reset_all(DeviceState *dev);
294 void qbus_reset_all_fn(void *opaque);
295
296 void qbus_free(BusState *bus);
297
298 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
299
300 /* This should go away once we get rid of the NULL bus hack */
301 BusState *sysbus_get_default(void);
302
303 /*** monitor commands ***/
304
305 void do_info_qtree(Monitor *mon);
306 void do_info_qdm(Monitor *mon);
307 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
308 int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
309
310 /*** qdev-properties.c ***/
311
312 extern PropertyInfo qdev_prop_bit;
313 extern PropertyInfo qdev_prop_uint8;
314 extern PropertyInfo qdev_prop_uint16;
315 extern PropertyInfo qdev_prop_uint32;
316 extern PropertyInfo qdev_prop_int32;
317 extern PropertyInfo qdev_prop_uint64;
318 extern PropertyInfo qdev_prop_hex8;
319 extern PropertyInfo qdev_prop_hex32;
320 extern PropertyInfo qdev_prop_hex64;
321 extern PropertyInfo qdev_prop_string;
322 extern PropertyInfo qdev_prop_chr;
323 extern PropertyInfo qdev_prop_ptr;
324 extern PropertyInfo qdev_prop_macaddr;
325 extern PropertyInfo qdev_prop_losttickpolicy;
326 extern PropertyInfo qdev_prop_drive;
327 extern PropertyInfo qdev_prop_netdev;
328 extern PropertyInfo qdev_prop_vlan;
329 extern PropertyInfo qdev_prop_pci_devfn;
330
331 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
332 .name = (_name), \
333 .info = &(_prop), \
334 .offset = offsetof(_state, _field) \
335 + type_check(_type,typeof_field(_state, _field)), \
336 }
337 #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
338 .name = (_name), \
339 .info = &(_prop), \
340 .offset = offsetof(_state, _field) \
341 + type_check(_type,typeof_field(_state, _field)), \
342 .defval = (_type[]) { _defval }, \
343 }
344 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
345 .name = (_name), \
346 .info = &(qdev_prop_bit), \
347 .bitnr = (_bit), \
348 .offset = offsetof(_state, _field) \
349 + type_check(uint32_t,typeof_field(_state, _field)), \
350 .defval = (bool[]) { (_defval) }, \
351 }
352
353 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
354 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
355 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
356 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
357 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
358 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
359 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
360 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
361 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
362 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
363 #define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
364 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
365 #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
366 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
367 #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
368 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
369 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
370 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
371
372 #define DEFINE_PROP_PTR(_n, _s, _f) \
373 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
374 #define DEFINE_PROP_CHR(_n, _s, _f) \
375 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
376 #define DEFINE_PROP_STRING(_n, _s, _f) \
377 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
378 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
379 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
380 #define DEFINE_PROP_VLAN(_n, _s, _f) \
381 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
382 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
383 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
384 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
385 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
386 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
387 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
388 LostTickPolicy)
389
390 #define DEFINE_PROP_END_OF_LIST() \
391 {}
392
393 /* Set properties between creation and init. */
394 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
395 int qdev_prop_exists(DeviceState *dev, const char *name);
396 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
397 void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
398 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
399 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
400 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
401 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
402 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
403 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
404 void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
405 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
406 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
407 void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
408 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
409 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
410 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
411 void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
412 LostTickPolicy *value);
413 /* FIXME: Remove opaque pointer properties. */
414 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
415 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
416
417 void qdev_prop_register_global_list(GlobalProperty *props);
418 void qdev_prop_set_globals(DeviceState *dev);
419 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
420 Property *prop, const char *value);
421
422 char *qdev_get_fw_dev_path(DeviceState *dev);
423
424 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
425 extern struct BusInfo system_bus_info;
426
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 */
435 void 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 */
445 void qdev_unref(DeviceState *dev);
446
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 */
475 void 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 */
492 void 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 */
508 void 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 */
523 const char *qdev_property_get_type(DeviceState *dev, const char *name,
524 Error **errp);
525
526 /**
527 * @qdev_property_add_static - add a @Property to a device referencing a
528 * field in a struct.
529 */
530 void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
531
532 /**
533 * @qdev_get_root - returns the root device of the composition tree
534 *
535 * Returns:
536 * The root of the composition tree.
537 */
538 DeviceState *qdev_get_root(void);
539
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 */
547 gchar *qdev_get_canonical_path(DeviceState *dev);
548
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 */
575 DeviceState *qdev_resolve_path(const char *path, bool *ambiguous);
576
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 */
594 void qdev_property_add_child(DeviceState *dev, const char *name,
595 DeviceState *child, Error **errp);
596
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 */
616 void qdev_property_add_link(DeviceState *dev, const char *name,
617 const char *type, DeviceState **child,
618 Error **errp);
619
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 */
637 void 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
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 */
654 char *qdev_get_type(DeviceState *dev, Error **errp);
655
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 */
662 void qdev_machine_init(void);
663
664 /**
665 * @device_reset
666 *
667 * Reset a single device (by calling the reset method).
668 */
669 void device_reset(DeviceState *dev);
670
671 const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
672
673 const char *qdev_fw_name(DeviceState *dev);
674
675 BusInfo *qdev_get_bus_info(DeviceState *dev);
676
677 Property *qdev_get_props(DeviceState *dev);
678
679 #endif