1#ifndef QDEV_CORE_H
2#define QDEV_CORE_H
3
4#include "qemu/queue.h"
5#include "qemu/bitmap.h"
6#include "qom/object.h"
7#include "hw/hotplug.h"
8
9enum {
10 DEV_NVECTORS_UNSPECIFIED = -1,
11};
12
13#define TYPE_DEVICE "device"
14#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
15#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
16#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
17
18typedef enum DeviceCategory {
19 DEVICE_CATEGORY_BRIDGE,
20 DEVICE_CATEGORY_USB,
21 DEVICE_CATEGORY_STORAGE,
22 DEVICE_CATEGORY_NETWORK,
23 DEVICE_CATEGORY_INPUT,
24 DEVICE_CATEGORY_DISPLAY,
25 DEVICE_CATEGORY_SOUND,
26 DEVICE_CATEGORY_MISC,
27 DEVICE_CATEGORY_CPU,
28 DEVICE_CATEGORY_MAX
29} DeviceCategory;
30
31typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
32typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
33typedef void (*DeviceReset)(DeviceState *dev);
34typedef void (*BusRealize)(BusState *bus, Error **errp);
35typedef void (*BusUnrealize)(BusState *bus, Error **errp);
36
37
38
39
40
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
94
95typedef struct DeviceClass {
96
97 ObjectClass parent_class;
98
99
100 DECLARE_BITMAP(categories, DEVICE_CATEGORY_MAX);
101 const char *fw_name;
102 const char *desc;
103 Property *props;
104
105
106
107
108
109
110
111
112
113
114
115
116 bool user_creatable;
117 bool hotpluggable;
118
119
120 DeviceReset reset;
121 DeviceRealize realize;
122 DeviceUnrealize unrealize;
123
124
125 const VMStateDescription *vmsd;
126
127
128 const char *bus_type;
129} DeviceClass;
130
131typedef struct NamedGPIOList NamedGPIOList;
132
133struct NamedGPIOList {
134 char *name;
135 qemu_irq *in;
136 int num_in;
137 int num_out;
138 QLIST_ENTRY(NamedGPIOList) node;
139};
140
141
142
143
144
145
146
147
148struct DeviceState {
149
150 Object parent_obj;
151
152
153 const char *id;
154 char *canonical_path;
155 bool realized;
156 bool pending_deleted_event;
157 QemuOpts *opts;
158 int hotplugged;
159 bool allow_unplug_during_migration;
160 BusState *parent_bus;
161 QLIST_HEAD(, NamedGPIOList) gpios;
162 QLIST_HEAD(, BusState) child_bus;
163 int num_child_bus;
164 int instance_id_alias;
165 int alias_required_for_version;
166};
167
168struct DeviceListener {
169 void (*realize)(DeviceListener *listener, DeviceState *dev);
170 void (*unrealize)(DeviceListener *listener, DeviceState *dev);
171
172
173
174
175
176 int (*should_be_hidden)(DeviceListener *listener, QemuOpts *device_opts);
177 QTAILQ_ENTRY(DeviceListener) link;
178};
179
180#define TYPE_BUS "bus"
181#define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
182#define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
183#define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
184
185struct BusClass {
186 ObjectClass parent_class;
187
188
189 void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
190 char *(*get_dev_path)(DeviceState *dev);
191
192
193
194
195
196 char *(*get_fw_dev_path)(DeviceState *dev);
197 void (*reset)(BusState *bus);
198 BusRealize realize;
199 BusUnrealize unrealize;
200
201
202 int max_dev;
203
204 int automatic_ids;
205};
206
207typedef struct BusChild {
208 DeviceState *child;
209 int index;
210 QTAILQ_ENTRY(BusChild) sibling;
211} BusChild;
212
213#define QDEV_HOTPLUG_HANDLER_PROPERTY "hotplug-handler"
214
215
216
217
218
219struct BusState {
220 Object obj;
221 DeviceState *parent;
222 char *name;
223 HotplugHandler *hotplug_handler;
224 int max_index;
225 bool realized;
226 int num_children;
227 QTAILQ_HEAD(, BusChild) children;
228 QLIST_ENTRY(BusState) sibling;
229};
230
231
232
233
234
235
236
237
238
239
240struct Property {
241 const char *name;
242 const PropertyInfo *info;
243 ptrdiff_t offset;
244 uint8_t bitnr;
245 bool set_default;
246 union {
247 int64_t i;
248 uint64_t u;
249 } defval;
250 int arrayoffset;
251 const PropertyInfo *arrayinfo;
252 int arrayfieldsize;
253 const char *link_type;
254};
255
256struct PropertyInfo {
257 const char *name;
258 const char *description;
259 const QEnumLookup *enum_table;
260 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
261 void (*set_default_value)(Object *obj, const Property *prop);
262 void (*create)(Object *obj, Property *prop, Error **errp);
263 ObjectPropertyAccessor *get;
264 ObjectPropertyAccessor *set;
265 ObjectPropertyRelease *release;
266};
267
268
269
270
271
272
273
274
275
276typedef struct GlobalProperty {
277 const char *driver;
278 const char *property;
279 const char *value;
280 bool used;
281 bool optional;
282} GlobalProperty;
283
284static inline void
285compat_props_add(GPtrArray *arr,
286 GlobalProperty props[], size_t nelem)
287{
288 int i;
289 for (i = 0; i < nelem; i++) {
290 g_ptr_array_add(arr, (void *)&props[i]);
291 }
292}
293
294
295
296DeviceState *qdev_create(BusState *bus, const char *name);
297DeviceState *qdev_try_create(BusState *bus, const char *name);
298void qdev_init_nofail(DeviceState *dev);
299void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
300 int required_for_version);
301HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev);
302HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev);
303bool qdev_hotplug_allowed(DeviceState *dev, Error **errp);
304
305
306
307
308
309
310
311
312
313
314
315HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev);
316void qdev_unplug(DeviceState *dev, Error **errp);
317void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
318 DeviceState *dev, Error **errp);
319void qdev_machine_creation_done(void);
320bool qdev_machine_modified(void);
321
322qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
323qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
324
325void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
326void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
327 qemu_irq pin);
328qemu_irq qdev_get_gpio_out_connector(DeviceState *dev, const char *name, int n);
329qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt,
330 const char *name, int n);
331
332BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
333
334
335
336
337
338void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
339void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
340void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins,
341 const char *name, int n);
342
343
344
345
346
347
348
349
350
351
352void qdev_init_gpio_in_named_with_opaque(DeviceState *dev,
353 qemu_irq_handler handler,
354 void *opaque,
355 const char *name, int n);
356
357
358
359
360
361
362
363
364static inline void qdev_init_gpio_in_named(DeviceState *dev,
365 qemu_irq_handler handler,
366 const char *name, int n)
367{
368 qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n);
369}
370
371void qdev_pass_gpios(DeviceState *dev, DeviceState *container,
372 const char *name);
373
374BusState *qdev_get_parent_bus(DeviceState *dev);
375
376
377
378DeviceState *qdev_find_recursive(BusState *bus, const char *id);
379
380
381typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
382typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
383
384void qbus_create_inplace(void *bus, size_t size, const char *typename,
385 DeviceState *parent, const char *name);
386BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
387
388
389
390int qbus_walk_children(BusState *bus,
391 qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
392 qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
393 void *opaque);
394int qdev_walk_children(DeviceState *dev,
395 qdev_walkerfn *pre_devfn, qbus_walkerfn *pre_busfn,
396 qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn,
397 void *opaque);
398
399void qdev_reset_all(DeviceState *dev);
400void qdev_reset_all_fn(void *opaque);
401
402
403
404
405
406
407
408
409
410
411
412void qbus_reset_all(BusState *bus);
413void qbus_reset_all_fn(void *opaque);
414
415
416BusState *sysbus_get_default(void);
417
418char *qdev_get_fw_dev_path(DeviceState *dev);
419char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev);
420
421
422
423
424
425
426
427void qdev_machine_init(void);
428
429
430
431
432
433
434void device_reset(DeviceState *dev);
435
436void device_class_set_parent_reset(DeviceClass *dc,
437 DeviceReset dev_reset,
438 DeviceReset *parent_reset);
439void device_class_set_parent_realize(DeviceClass *dc,
440 DeviceRealize dev_realize,
441 DeviceRealize *parent_realize);
442void device_class_set_parent_unrealize(DeviceClass *dc,
443 DeviceUnrealize dev_unrealize,
444 DeviceUnrealize *parent_unrealize);
445
446const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
447
448const char *qdev_fw_name(DeviceState *dev);
449
450Object *qdev_get_machine(void);
451
452
453void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
454
455extern bool qdev_hotplug;
456extern bool qdev_hot_removed;
457
458char *qdev_get_dev_path(DeviceState *dev);
459
460GSList *qdev_build_hotpluggable_device_list(Object *peripheral);
461
462void qbus_set_hotplug_handler(BusState *bus, Object *handler, Error **errp);
463
464void qbus_set_bus_hotplug_handler(BusState *bus, Error **errp);
465
466static inline bool qbus_is_hotpluggable(BusState *bus)
467{
468 return bus->hotplug_handler;
469}
470
471void device_listener_register(DeviceListener *listener);
472void device_listener_unregister(DeviceListener *listener);
473
474
475
476
477
478
479
480
481
482bool qdev_should_hide_device(QemuOpts *opts);
483
484#endif
485