]>
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 { |
12 | DEV_NVECTORS_UNSPECIFIED = -1, | |
13 | }; | |
14 | ||
15 | #define TYPE_DEVICE "device" | |
16 | #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE) | |
17 | #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE) | |
18 | #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE) | |
19 | ||
20 | typedef int (*qdev_initfn)(DeviceState *dev); | |
21 | typedef int (*qdev_event)(DeviceState *dev); | |
22 | typedef void (*qdev_resetfn)(DeviceState *dev); | |
23 | ||
24 | struct VMStateDescription; | |
25 | ||
26 | typedef struct DeviceClass { | |
27 | ObjectClass parent_class; | |
28 | ||
29 | const char *fw_name; | |
30 | const char *desc; | |
31 | Property *props; | |
32 | int no_user; | |
33 | ||
34 | /* callbacks */ | |
35 | void (*reset)(DeviceState *dev); | |
36 | ||
37 | /* device state */ | |
38 | const struct VMStateDescription *vmsd; | |
39 | ||
40 | /* Private to qdev / bus. */ | |
41 | qdev_initfn init; | |
42 | qdev_event unplug; | |
43 | qdev_event exit; | |
44 | const char *bus_type; | |
45 | } DeviceClass; | |
46 | ||
7983c8a3 AF |
47 | /** |
48 | * DeviceState: | |
49 | * @realized: Indicates whether the device has been fully constructed. | |
50 | * | |
51 | * This structure should not be accessed directly. We declare it here | |
52 | * so that it can be embedded in individual device state structures. | |
53 | */ | |
074a86fc | 54 | struct DeviceState { |
7983c8a3 | 55 | /*< private >*/ |
074a86fc | 56 | Object parent_obj; |
7983c8a3 | 57 | /*< public >*/ |
074a86fc AL |
58 | |
59 | const char *id; | |
7983c8a3 | 60 | bool realized; |
074a86fc AL |
61 | QemuOpts *opts; |
62 | int hotplugged; | |
63 | BusState *parent_bus; | |
64 | int num_gpio_out; | |
65 | qemu_irq *gpio_out; | |
66 | int num_gpio_in; | |
67 | qemu_irq *gpio_in; | |
68 | QLIST_HEAD(, BusState) child_bus; | |
69 | int num_child_bus; | |
70 | int instance_id_alias; | |
71 | int alias_required_for_version; | |
72 | }; | |
73 | ||
74 | #define TYPE_BUS "bus" | |
75 | #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS) | |
76 | #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS) | |
77 | #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS) | |
78 | ||
79 | struct BusClass { | |
80 | ObjectClass parent_class; | |
81 | ||
82 | /* FIXME first arg should be BusState */ | |
83 | void (*print_dev)(Monitor *mon, DeviceState *dev, int indent); | |
84 | char *(*get_dev_path)(DeviceState *dev); | |
85 | /* | |
86 | * This callback is used to create Open Firmware device path in accordance | |
87 | * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus | |
88 | * bindings can be found at http://playground.sun.com/1275/bindings/. | |
89 | */ | |
90 | char *(*get_fw_dev_path)(DeviceState *dev); | |
91 | int (*reset)(BusState *bus); | |
92 | }; | |
93 | ||
94 | typedef struct BusChild { | |
95 | DeviceState *child; | |
96 | int index; | |
97 | QTAILQ_ENTRY(BusChild) sibling; | |
98 | } BusChild; | |
99 | ||
100 | /** | |
101 | * BusState: | |
074a86fc AL |
102 | */ |
103 | struct BusState { | |
104 | Object obj; | |
105 | DeviceState *parent; | |
106 | const char *name; | |
107 | int allow_hotplug; | |
074a86fc AL |
108 | int max_index; |
109 | QTAILQ_HEAD(ChildrenHead, BusChild) children; | |
110 | QLIST_ENTRY(BusState) sibling; | |
111 | }; | |
112 | ||
113 | struct Property { | |
114 | const char *name; | |
115 | PropertyInfo *info; | |
116 | int offset; | |
117 | uint8_t bitnr; | |
118 | uint8_t qtype; | |
119 | int64_t defval; | |
120 | }; | |
121 | ||
122 | struct PropertyInfo { | |
123 | const char *name; | |
124 | const char *legacy_name; | |
125 | const char **enum_table; | |
126 | int (*parse)(DeviceState *dev, Property *prop, const char *str); | |
127 | int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); | |
128 | ObjectPropertyAccessor *get; | |
129 | ObjectPropertyAccessor *set; | |
130 | ObjectPropertyRelease *release; | |
131 | }; | |
132 | ||
133 | typedef struct GlobalProperty { | |
134 | const char *driver; | |
135 | const char *property; | |
136 | const char *value; | |
137 | QTAILQ_ENTRY(GlobalProperty) next; | |
138 | } GlobalProperty; | |
139 | ||
140 | /*** Board API. This should go away once we have a machine config file. ***/ | |
141 | ||
142 | DeviceState *qdev_create(BusState *bus, const char *name); | |
143 | DeviceState *qdev_try_create(BusState *bus, const char *name); | |
144 | int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT; | |
145 | void qdev_init_nofail(DeviceState *dev); | |
146 | void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, | |
147 | int required_for_version); | |
148 | void qdev_unplug(DeviceState *dev, Error **errp); | |
149 | void qdev_free(DeviceState *dev); | |
150 | int qdev_simple_unplug_cb(DeviceState *dev); | |
151 | void qdev_machine_creation_done(void); | |
152 | bool qdev_machine_modified(void); | |
153 | ||
154 | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); | |
155 | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); | |
156 | ||
157 | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); | |
158 | ||
159 | /*** Device API. ***/ | |
160 | ||
161 | /* Register device properties. */ | |
162 | /* GPIO inputs also double as IRQ sinks. */ | |
163 | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); | |
164 | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); | |
165 | ||
166 | BusState *qdev_get_parent_bus(DeviceState *dev); | |
167 | ||
168 | /*** BUS API. ***/ | |
169 | ||
170 | DeviceState *qdev_find_recursive(BusState *bus, const char *id); | |
171 | ||
172 | /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */ | |
173 | typedef int (qbus_walkerfn)(BusState *bus, void *opaque); | |
174 | typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque); | |
175 | ||
176 | void qbus_create_inplace(BusState *bus, const char *typename, | |
177 | DeviceState *parent, const char *name); | |
178 | BusState *qbus_create(const char *typename, DeviceState *parent, const char *name); | |
179 | /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion, | |
180 | * < 0 if either devfn or busfn terminate walk somewhere in cursion, | |
181 | * 0 otherwise. */ | |
182 | int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn, | |
183 | qbus_walkerfn *busfn, void *opaque); | |
184 | int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn, | |
185 | qbus_walkerfn *busfn, void *opaque); | |
186 | void qdev_reset_all(DeviceState *dev); | |
d0508c36 PB |
187 | |
188 | /** | |
189 | * @qbus_reset_all: | |
190 | * @bus: Bus to be reset. | |
191 | * | |
192 | * Reset @bus and perform a bus-level ("hard") reset of all devices connected | |
193 | * to it, including recursive processing of all buses below @bus itself. A | |
194 | * hard reset means that qbus_reset_all will reset all state of the device. | |
195 | * For PCI devices, for example, this will include the base address registers | |
196 | * or configuration space. | |
197 | */ | |
198 | void qbus_reset_all(BusState *bus); | |
074a86fc AL |
199 | void qbus_reset_all_fn(void *opaque); |
200 | ||
201 | void qbus_free(BusState *bus); | |
202 | ||
203 | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) | |
204 | ||
205 | /* This should go away once we get rid of the NULL bus hack */ | |
206 | BusState *sysbus_get_default(void); | |
207 | ||
208 | char *qdev_get_fw_dev_path(DeviceState *dev); | |
209 | ||
210 | /** | |
211 | * @qdev_machine_init | |
212 | * | |
213 | * Initialize platform devices before machine init. This is a hack until full | |
214 | * support for composition is added. | |
215 | */ | |
216 | void qdev_machine_init(void); | |
217 | ||
218 | /** | |
219 | * @device_reset | |
220 | * | |
221 | * Reset a single device (by calling the reset method). | |
222 | */ | |
223 | void device_reset(DeviceState *dev); | |
224 | ||
225 | const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev); | |
226 | ||
227 | const char *qdev_fw_name(DeviceState *dev); | |
228 | ||
229 | Object *qdev_get_machine(void); | |
230 | ||
231 | /* FIXME: make this a link<> */ | |
232 | void qdev_set_parent_bus(DeviceState *dev, BusState *bus); | |
233 | ||
234 | extern int qdev_hotplug; | |
235 | ||
236 | char *qdev_get_dev_path(DeviceState *dev); | |
237 | ||
238 | #endif |