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