]>
Commit | Line | Data |
---|---|---|
074a86fc AL |
1 | #ifndef QDEV_CORE_H |
2 | #define QDEV_CORE_H | |
3 | ||
1de7afc9 PB |
4 | #include "qemu/queue.h" |
5 | #include "qemu/option.h" | |
6 | #include "qemu/typedefs.h" | |
14cccb61 | 7 | #include "qom/object.h" |
074a86fc | 8 | #include "hw/irq.h" |
7b1b5d19 | 9 | #include "qapi/error.h" |
074a86fc | 10 | |
074a86fc AL |
11 | enum DevState { |
12 | DEV_STATE_CREATED = 1, | |
13 | DEV_STATE_INITIALIZED, | |
14 | }; | |
15 | ||
16 | enum { | |
17 | DEV_NVECTORS_UNSPECIFIED = -1, | |
18 | }; | |
19 | ||
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) | |
24 | ||
25 | typedef int (*qdev_initfn)(DeviceState *dev); | |
26 | typedef int (*qdev_event)(DeviceState *dev); | |
27 | typedef void (*qdev_resetfn)(DeviceState *dev); | |
28 | ||
29 | struct VMStateDescription; | |
30 | ||
31 | typedef struct DeviceClass { | |
32 | ObjectClass parent_class; | |
33 | ||
34 | const char *fw_name; | |
35 | const char *desc; | |
36 | Property *props; | |
37 | int no_user; | |
38 | ||
39 | /* callbacks */ | |
40 | void (*reset)(DeviceState *dev); | |
41 | ||
42 | /* device state */ | |
43 | const struct VMStateDescription *vmsd; | |
44 | ||
45 | /* Private to qdev / bus. */ | |
46 | qdev_initfn init; | |
47 | qdev_event unplug; | |
48 | qdev_event exit; | |
49 | const char *bus_type; | |
50 | } DeviceClass; | |
51 | ||
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; | |
56 | ||
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; | |
70 | }; | |
71 | ||
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) | |
76 | ||
77 | struct BusClass { | |
78 | ObjectClass parent_class; | |
79 | ||
80 | /* FIXME first arg should be BusState */ | |
81 | void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); | |
82 | char *(*get_dev_path)(DeviceState *dev); | |
83 | /* | |
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/. | |
87 | */ | |
88 | char *(*get_fw_dev_path)(DeviceState *dev); | |
89 | int (*reset)(BusState *bus); | |
90 | }; | |
91 | ||
92 | typedef struct BusChild { | |
93 | DeviceState *child; | |
94 | int index; | |
95 | QTAILQ_ENTRY(BusChild) sibling; | |
96 | } BusChild; | |
97 | ||
98 | /** | |
99 | * BusState: | |
074a86fc AL |
100 | */ |
101 | struct BusState { | |
102 | Object obj; | |
103 | DeviceState *parent; | |
104 | const char *name; | |
105 | int allow_hotplug; | |
074a86fc AL |
106 | int max_index; |
107 | QTAILQ_HEAD(ChildrenHead, BusChild) children; | |
108 | QLIST_ENTRY(BusState) sibling; | |
109 | }; | |
110 | ||
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; | |
118 | }; | |
119 | ||
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; | |
129 | }; | |
130 | ||
131 | typedef struct GlobalProperty { | |
132 | const char *driver; | |
133 | const char *property; | |
134 | const char *value; | |
135 | QTAILQ_ENTRY(GlobalProperty) next; | |
136 | } GlobalProperty; | |
137 | ||
138 | /*** Board API. This should go away once we have a machine config file. ***/ | |
139 | ||
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); | |
151 | ||
152 | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); | |
153 | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); | |
154 | ||
155 | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); | |
156 | ||
157 | /*** Device API. ***/ | |
158 | ||
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); | |
163 | ||
164 | BusState *qdev_get_parent_bus(DeviceState *dev); | |
165 | ||
166 | /*** BUS API. ***/ | |
167 | ||
168 | DeviceState *qdev_find_recursive(BusState *bus, const char *id); | |
169 | ||
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); | |
173 | ||
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); | |
d0508c36 PB |
185 | |
186 | /** | |
187 | * @qbus_reset_all: | |
188 | * @bus: Bus to be reset. | |
189 | * | |
190 | * Reset @bus and perform a bus-level ("hard") reset of all devices connected | |
191 | * to it, including recursive processing of all buses below @bus itself. A | |
192 | * hard reset means that qbus_reset_all will reset all state of the device. | |
193 | * For PCI devices, for example, this will include the base address registers | |
194 | * or configuration space. | |
195 | */ | |
196 | void qbus_reset_all(BusState *bus); | |
074a86fc AL |
197 | void qbus_reset_all_fn(void *opaque); |
198 | ||
199 | void qbus_free(BusState *bus); | |
200 | ||
201 | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) | |
202 | ||
203 | /* This should go away once we get rid of the NULL bus hack */ | |
204 | BusState *sysbus_get_default(void); | |
205 | ||
206 | char *qdev_get_fw_dev_path(DeviceState *dev); | |
207 | ||
208 | /** | |
209 | * @qdev_machine_init | |
210 | * | |
211 | * Initialize platform devices before machine init. This is a hack until full | |
212 | * support for composition is added. | |
213 | */ | |
214 | void qdev_machine_init(void); | |
215 | ||
216 | /** | |
217 | * @device_reset | |
218 | * | |
219 | * Reset a single device (by calling the reset method). | |
220 | */ | |
221 | void device_reset(DeviceState *dev); | |
222 | ||
223 | const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); | |
224 | ||
225 | const char *qdev_fw_name(DeviceState *dev); | |
226 | ||
227 | Object *qdev_get_machine(void); | |
228 | ||
229 | /* FIXME: make this a link<> */ | |
230 | void qdev_set_parent_bus(DeviceState *dev, BusState *bus); | |
231 | ||
232 | extern int qdev_hotplug; | |
233 | ||
234 | char *qdev_get_dev_path(DeviceState *dev); | |
235 | ||
236 | #endif |