gitignore: Add virtfs-proxy-helper
[qemu/ar7.git] / hw / qdev-core.h
blobd672ccafe619ef36ac43ee7d570f1583fa23ee79
1 #ifndef QDEV_CORE_H
2 #define QDEV_CORE_H
4 #include "qemu-queue.h"
5 #include "qemu-option.h"
6 #include "qemu-types.h"
7 #include "qemu/object.h"
8 #include "hw/irq.h"
9 #include "error.h"
11 enum DevState {
12 DEV_STATE_CREATED = 1,
13 DEV_STATE_INITIALIZED,
16 enum {
17 DEV_NVECTORS_UNSPECIFIED = -1,
20 #define TYPE_DEVICE "device"
21 #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
22 #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
23 #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
25 typedef int (*qdev_initfn)(DeviceState *dev);
26 typedef int (*qdev_event)(DeviceState *dev);
27 typedef void (*qdev_resetfn)(DeviceState *dev);
29 struct VMStateDescription;
31 typedef struct DeviceClass {
32 ObjectClass parent_class;
34 const char *fw_name;
35 const char *desc;
36 Property *props;
37 int no_user;
39 /* callbacks */
40 void (*reset)(DeviceState *dev);
42 /* device state */
43 const struct VMStateDescription *vmsd;
45 /* Private to qdev / bus. */
46 qdev_initfn init;
47 qdev_event unplug;
48 qdev_event exit;
49 const char *bus_type;
50 } DeviceClass;
52 /* This structure should not be accessed directly. We declare it here
53 so that it can be embedded in individual device state structures. */
54 struct DeviceState {
55 Object parent_obj;
57 const char *id;
58 enum DevState state;
59 QemuOpts *opts;
60 int hotplugged;
61 BusState *parent_bus;
62 int num_gpio_out;
63 qemu_irq *gpio_out;
64 int num_gpio_in;
65 qemu_irq *gpio_in;
66 QLIST_HEAD(, BusState) child_bus;
67 int num_child_bus;
68 int instance_id_alias;
69 int alias_required_for_version;
72 #define TYPE_BUS "bus"
73 #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
74 #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
75 #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
77 struct BusClass {
78 ObjectClass parent_class;
80 /* FIXME first arg should be BusState */
81 void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
82 char *(*get_dev_path)(DeviceState *dev);
84 * This callback is used to create Open Firmware device path in accordance
85 * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus
86 * bindings can be found at http://playground.sun.com/1275/bindings/.
88 char *(*get_fw_dev_path)(DeviceState *dev);
89 int (*reset)(BusState *bus);
92 typedef struct BusChild {
93 DeviceState *child;
94 int index;
95 QTAILQ_ENTRY(BusChild) sibling;
96 } BusChild;
98 /**
99 * BusState:
101 struct BusState {
102 Object obj;
103 DeviceState *parent;
104 const char *name;
105 int allow_hotplug;
106 int max_index;
107 QTAILQ_HEAD(ChildrenHead, BusChild) children;
108 QLIST_ENTRY(BusState) sibling;
111 struct Property {
112 const char *name;
113 PropertyInfo *info;
114 int offset;
115 uint8_t bitnr;
116 uint8_t qtype;
117 int64_t defval;
120 struct PropertyInfo {
121 const char *name;
122 const char *legacy_name;
123 const char **enum_table;
124 int (*parse)(DeviceState *dev, Property *prop, const char *str);
125 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
126 ObjectPropertyAccessor *get;
127 ObjectPropertyAccessor *set;
128 ObjectPropertyRelease *release;
131 typedef struct GlobalProperty {
132 const char *driver;
133 const char *property;
134 const char *value;
135 QTAILQ_ENTRY(GlobalProperty) next;
136 } GlobalProperty;
138 /*** Board API. This should go away once we have a machine config file. ***/
140 DeviceState *qdev_create(BusState *bus, const char *name);
141 DeviceState *qdev_try_create(BusState *bus, const char *name);
142 int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
143 void qdev_init_nofail(DeviceState *dev);
144 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
145 int required_for_version);
146 void qdev_unplug(DeviceState *dev, Error **errp);
147 void qdev_free(DeviceState *dev);
148 int qdev_simple_unplug_cb(DeviceState *dev);
149 void qdev_machine_creation_done(void);
150 bool qdev_machine_modified(void);
152 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
153 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
155 BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
157 /*** Device API. ***/
159 /* Register device properties. */
160 /* GPIO inputs also double as IRQ sinks. */
161 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
162 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
164 BusState *qdev_get_parent_bus(DeviceState *dev);
166 /*** BUS API. ***/
168 DeviceState *qdev_find_recursive(BusState *bus, const char *id);
170 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
171 typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
172 typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
174 void qbus_create_inplace(BusState *bus, const char *typename,
175 DeviceState *parent, const char *name);
176 BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
177 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
178 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
179 * 0 otherwise. */
180 int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
181 qbus_walkerfn *busfn, void *opaque);
182 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
183 qbus_walkerfn *busfn, void *opaque);
184 void qdev_reset_all(DeviceState *dev);
185 void qbus_reset_all_fn(void *opaque);
187 void qbus_free(BusState *bus);
189 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
191 /* This should go away once we get rid of the NULL bus hack */
192 BusState *sysbus_get_default(void);
194 char *qdev_get_fw_dev_path(DeviceState *dev);
197 * @qdev_machine_init
199 * Initialize platform devices before machine init. This is a hack until full
200 * support for composition is added.
202 void qdev_machine_init(void);
205 * @device_reset
207 * Reset a single device (by calling the reset method).
209 void device_reset(DeviceState *dev);
211 const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
213 const char *qdev_fw_name(DeviceState *dev);
215 Object *qdev_get_machine(void);
217 /* FIXME: make this a link<> */
218 void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
220 extern int qdev_hotplug;
222 char *qdev_get_dev_path(DeviceState *dev);
224 #endif