1#ifndef QDEV_CORE_H
2#define QDEV_CORE_H
3
4#include "qemu-queue.h"
5#include "qemu-option.h"
6#include "qemu/object.h"
7#include "hw/irq.h"
8#include "error.h"
9
10typedef struct Property Property;
11
12typedef struct PropertyInfo PropertyInfo;
13
14typedef struct CompatProperty CompatProperty;
15
16typedef struct BusState BusState;
17
18typedef struct BusClass BusClass;
19
20enum DevState {
21 DEV_STATE_CREATED = 1,
22 DEV_STATE_INITIALIZED,
23};
24
25enum {
26 DEV_NVECTORS_UNSPECIFIED = -1,
27};
28
29#define TYPE_DEVICE "device"
30#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
31#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
32#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
33
34typedef int (*qdev_initfn)(DeviceState *dev);
35typedef int (*qdev_event)(DeviceState *dev);
36typedef void (*qdev_resetfn)(DeviceState *dev);
37
38struct VMStateDescription;
39
40typedef struct DeviceClass {
41 ObjectClass parent_class;
42
43 const char *fw_name;
44 const char *desc;
45 Property *props;
46 int no_user;
47
48
49 void (*reset)(DeviceState *dev);
50
51
52 const struct VMStateDescription *vmsd;
53
54
55 qdev_initfn init;
56 qdev_event unplug;
57 qdev_event exit;
58 const char *bus_type;
59} DeviceClass;
60
61
62
63struct DeviceState {
64 Object parent_obj;
65
66 const char *id;
67 enum DevState state;
68 QemuOpts *opts;
69 int hotplugged;
70 BusState *parent_bus;
71 int num_gpio_out;
72 qemu_irq *gpio_out;
73 int num_gpio_in;
74 qemu_irq *gpio_in;
75 QLIST_HEAD(, BusState) child_bus;
76 int num_child_bus;
77 int instance_id_alias;
78 int alias_required_for_version;
79};
80
81#define TYPE_BUS "bus"
82#define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
83#define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
84#define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
85
86struct BusClass {
87 ObjectClass parent_class;
88
89
90 void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
91 char *(*get_dev_path)(DeviceState *dev);
92
93
94
95
96
97 char *(*get_fw_dev_path)(DeviceState *dev);
98 int (*reset)(BusState *bus);
99};
100
101typedef struct BusChild {
102 DeviceState *child;
103 int index;
104 QTAILQ_ENTRY(BusChild) sibling;
105} BusChild;
106
107
108
109
110struct BusState {
111 Object obj;
112 DeviceState *parent;
113 const char *name;
114 int allow_hotplug;
115 int max_index;
116 QTAILQ_HEAD(ChildrenHead, BusChild) children;
117 QLIST_ENTRY(BusState) sibling;
118};
119
120struct Property {
121 const char *name;
122 PropertyInfo *info;
123 int offset;
124 uint8_t bitnr;
125 uint8_t qtype;
126 int64_t defval;
127};
128
129struct PropertyInfo {
130 const char *name;
131 const char *legacy_name;
132 const char **enum_table;
133 int (*parse)(DeviceState *dev, Property *prop, const char *str);
134 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
135 ObjectPropertyAccessor *get;
136 ObjectPropertyAccessor *set;
137 ObjectPropertyRelease *release;
138};
139
140typedef struct GlobalProperty {
141 const char *driver;
142 const char *property;
143 const char *value;
144 QTAILQ_ENTRY(GlobalProperty) next;
145} GlobalProperty;
146
147
148
149DeviceState *qdev_create(BusState *bus, const char *name);
150DeviceState *qdev_try_create(BusState *bus, const char *name);
151int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
152void qdev_init_nofail(DeviceState *dev);
153void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
154 int required_for_version);
155void qdev_unplug(DeviceState *dev, Error **errp);
156void qdev_free(DeviceState *dev);
157int qdev_simple_unplug_cb(DeviceState *dev);
158void qdev_machine_creation_done(void);
159bool qdev_machine_modified(void);
160
161qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
162void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
163
164BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
165
166
167
168
169
170void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
171void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
172
173BusState *qdev_get_parent_bus(DeviceState *dev);
174
175
176
177DeviceState *qdev_find_recursive(BusState *bus, const char *id);
178
179
180typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
181typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
182
183void qbus_create_inplace(BusState *bus, const char *typename,
184 DeviceState *parent, const char *name);
185BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
186
187
188
189int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
190 qbus_walkerfn *busfn, void *opaque);
191int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
192 qbus_walkerfn *busfn, void *opaque);
193void qdev_reset_all(DeviceState *dev);
194void qbus_reset_all_fn(void *opaque);
195
196void qbus_free(BusState *bus);
197
198#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
199
200
201BusState *sysbus_get_default(void);
202
203char *qdev_get_fw_dev_path(DeviceState *dev);
204
205
206
207
208
209
210
211void qdev_machine_init(void);
212
213
214
215
216
217
218void device_reset(DeviceState *dev);
219
220const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
221
222const char *qdev_fw_name(DeviceState *dev);
223
224Object *qdev_get_machine(void);
225
226
227void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
228
229extern int qdev_hotplug;
230
231char *qdev_get_dev_path(DeviceState *dev);
232
233#endif
234