1#ifndef QDEV_CORE_H
2#define QDEV_CORE_H
3
4#include "qemu/queue.h"
5#include "qemu/option.h"
6#include "qemu/bitmap.h"
7#include "qom/object.h"
8#include "hw/irq.h"
9#include "hw/hotplug.h"
10
11enum {
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
20typedef enum DeviceCategory {
21 DEVICE_CATEGORY_BRIDGE,
22 DEVICE_CATEGORY_USB,
23 DEVICE_CATEGORY_STORAGE,
24 DEVICE_CATEGORY_NETWORK,
25 DEVICE_CATEGORY_INPUT,
26 DEVICE_CATEGORY_DISPLAY,
27 DEVICE_CATEGORY_SOUND,
28 DEVICE_CATEGORY_MISC,
29 DEVICE_CATEGORY_MAX
30} DeviceCategory;
31
32typedef int (*qdev_initfn)(DeviceState *dev);
33typedef int (*qdev_event)(DeviceState *dev);
34typedef void (*qdev_resetfn)(DeviceState *dev);
35typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
36typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
37typedef void (*BusRealize)(BusState *bus, Error **errp);
38typedef void (*BusUnrealize)(BusState *bus, Error **errp);
39
40struct VMStateDescription;
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94typedef struct DeviceClass {
95
96 ObjectClass parent_class;
97
98
99 DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX);
100 const char *fw_name;
101 const char *desc;
102 Property *props;
103
104
105
106
107
108
109
110
111
112
113
114 bool cannot_instantiate_with_device_add_yet;
115
116
117
118
119
120
121
122
123
124
125
126 bool cannot_destroy_with_object_finalize_yet;
127
128 bool hotpluggable;
129
130
131 void (*reset)(DeviceState *dev);
132 DeviceRealize realize;
133 DeviceUnrealize unrealize;
134
135
136 const struct VMStateDescription *vmsd;
137
138
139 qdev_initfn init;
140 qdev_event exit;
141 const char *bus_type;
142} DeviceClass;
143
144typedef struct NamedGPIOList NamedGPIOList;
145
146struct NamedGPIOList {
147 char *name;
148 qemu_irq *in;
149 int num_in;
150 int num_out;
151 QLIST_ENTRY(NamedGPIOList) node;
152};
153
154
155
156
157
158
159
160
161struct DeviceState {
162
163 Object parent_obj;
164
165
166 const char *id;
167 bool realized;
168 bool pending_deleted_event;
169 QemuOpts *opts;
170 int hotplugged;
171 BusState *parent_bus;
172 QLIST_HEAD(, NamedGPIOList) gpios;
173 QLIST_HEAD(, BusState) child_bus;
174 int num_child_bus;
175 int instance_id_alias;
176 int alias_required_for_version;
177};
178
179struct DeviceListener {
180 void (*realize)(DeviceListener *listener, DeviceState *dev);
181 void (*unrealize)(DeviceListener *listener, DeviceState *dev);
182 QTAILQ_ENTRY(DeviceListener) link;
183};
184
185#define TYPE_BUS "bus"
186#define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
187#define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
188#define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
189
190struct BusClass {
191 ObjectClass parent_class;
192
193
194 void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
195 char *(*get_dev_path)(DeviceState *dev);
196
197
198
199
200
201 char *(*get_fw_dev_path)(DeviceState *dev);
202 void (*reset)(BusState *bus);
203 BusRealize realize;
204 BusUnrealize unrealize;
205
206
207 int max_dev;
208
209 int automatic_ids;
210};
211
212typedef struct BusChild {
213 DeviceState *child;
214 int index;
215 QTAILQ_ENTRY(BusChild) sibling;
216} BusChild;
217
218#define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler"
219
220
221
222
223
224struct BusState {
225 Object obj;
226 DeviceState *parent;
227 const char *name;
228 HotplugHandler *hotplug_handler;
229 int max_index;
230 bool realized;
231 QTAILQ_HEAD(ChildrenHead, BusChild) children;
232 QLIST_ENTRY(BusState) sibling;
233};
234
235struct Property {
236 const char *name;
237 PropertyInfo *info;
238 ptrdiff_t offset;
239 uint8_t bitnr;
240 QType qtype;
241 int64_t defval;
242 int arrayoffset;
243 PropertyInfo *arrayinfo;
244 int arrayfieldsize;
245};
246
247struct PropertyInfo {
248 const char *name;
249 const char *description;
250 const char * const *enum_table;
251 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
252 ObjectPropertyAccessor *get;
253 ObjectPropertyAccessor *set;
254 ObjectPropertyRelease *release;
255};
256
257
258
259
260
261
262
263typedef struct GlobalProperty {
264 const char *driver;
265 const char *property;
266 const char *value;
267 bool user_provided;
268 bool used;
269 QTAILQ_ENTRY(GlobalProperty) next;
270} GlobalProperty;
271
272
273
274DeviceState *qdev_create(BusState *bus, const char *name);
275DeviceState *qdev_try_create(BusState *bus, const char *name);
276void qdev_init_nofail(DeviceState *dev);
277void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
278 int required_for_version);
279HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev);
280void qdev_unplug(DeviceState *dev, Error **errp);
281void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
282 DeviceState *dev, Error **errp);
283void qdev_machine_creation_done(void);
284bool qdev_machine_modified(void);
285
286qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
287qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
288
289void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
290void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
291 qemu_irq pin);
292qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
293qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt,
294 const char *name, int n);
295
296BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
297
298
299
300
301
302void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
303void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
304void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler,
305 const char *name, int n);
306void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
307 const char *name, int n);
308
309void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
310 const char *name);
311
312BusState *qdev_get_parent_bus(DeviceState *dev);
313
314
315
316DeviceState *qdev_find_recursive(BusState *bus, const char *id);
317
318
319typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
320typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
321
322void qbus_create_inplace(void *bus, size_t size, const char *typename,
323 DeviceState *parent, const char *name);
324BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
325
326
327
328int qbus_walk_children(BusState *bus,
329 qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
330 qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
331 void *opaque);
332int qdev_walk_children(DeviceState *dev,
333 qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
334 qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
335 void *opaque);
336
337void qdev_reset_all(DeviceState *dev);
338void qdev_reset_all_fn(void *opaque);
339
340
341
342
343
344
345
346
347
348
349
350void qbus_reset_all(BusState *bus);
351void qbus_reset_all_fn(void *opaque);
352
353
354BusState *sysbus_get_default(void);
355
356char *qdev_get_fw_dev_path(DeviceState *dev);
357char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev);
358
359
360
361
362
363
364
365void qdev_machine_init(void);
366
367
368
369
370
371
372void device_reset(DeviceState *dev);
373
374const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
375
376const char *qdev_fw_name(DeviceState *dev);
377
378Object *qdev_get_machine(void);
379
380
381void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
382
383extern int qdev_hotplug;
384
385char *qdev_get_dev_path(DeviceState *dev);
386
387GSList *qdev_build_hotpluggable_device_list(Object *peripheral);
388
389void qbus_set_hotplug_handler(BusState *bus, DeviceState *handler,
390 Error **errp);
391
392void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp);
393
394static inline bool qbus_is_hotpluggable(BusState *bus)
395{
396 return bus->hotplug_handler;
397}
398
399void device_listener_register(DeviceListener *listener);
400void device_listener_unregister(DeviceListener *listener);
401
402#endif
403