]>
Commit | Line | Data |
---|---|---|
aae9460e PB |
1 | #ifndef QDEV_H |
2 | #define QDEV_H | |
3 | ||
4 | #include "hw.h" | |
72cf2d4f | 5 | #include "qemu-queue.h" |
313feaab | 6 | #include "qemu-char.h" |
f31d07d1 | 7 | #include "qemu-option.h" |
aae9460e | 8 | |
ee6847d1 GH |
9 | typedef struct Property Property; |
10 | ||
11 | typedef struct PropertyInfo PropertyInfo; | |
aae9460e | 12 | |
b6b61144 GH |
13 | typedef struct CompatProperty CompatProperty; |
14 | ||
ee6847d1 | 15 | typedef struct DeviceInfo DeviceInfo; |
aae9460e | 16 | |
02e2da45 | 17 | typedef struct BusState BusState; |
4d6ae674 | 18 | |
10c4c98a GH |
19 | typedef struct BusInfo BusInfo; |
20 | ||
131ec1bd GH |
21 | enum DevState { |
22 | DEV_STATE_CREATED = 1, | |
23 | DEV_STATE_INITIALIZED, | |
24 | }; | |
25 | ||
75422b0d AS |
26 | enum { |
27 | DEV_NVECTORS_UNSPECIFIED = -1, | |
28 | }; | |
29 | ||
aae9460e PB |
30 | /* This structure should not be accessed directly. We declare it here |
31 | so that it can be embedded in individual device state structures. */ | |
02e2da45 | 32 | struct DeviceState { |
f31d07d1 | 33 | const char *id; |
131ec1bd | 34 | enum DevState state; |
ef80b466 | 35 | QemuOpts *opts; |
3418bd25 | 36 | int hotplugged; |
042f84d0 | 37 | DeviceInfo *info; |
02e2da45 | 38 | BusState *parent_bus; |
aae9460e PB |
39 | int num_gpio_out; |
40 | qemu_irq *gpio_out; | |
41 | int num_gpio_in; | |
42 | qemu_irq *gpio_in; | |
72cf2d4f | 43 | QLIST_HEAD(, BusState) child_bus; |
d271de9f | 44 | int num_child_bus; |
72cf2d4f | 45 | QLIST_ENTRY(DeviceState) sibling; |
4d2ffa08 JK |
46 | int instance_id_alias; |
47 | int alias_required_for_version; | |
02e2da45 PB |
48 | }; |
49 | ||
10c4c98a | 50 | typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); |
6772b936 AW |
51 | typedef char *(*bus_get_dev_path)(DeviceState *dev); |
52 | ||
10c4c98a GH |
53 | struct BusInfo { |
54 | const char *name; | |
55 | size_t size; | |
56 | bus_dev_printfn print_dev; | |
6772b936 | 57 | bus_get_dev_path get_dev_path; |
ee6847d1 | 58 | Property *props; |
10c4c98a | 59 | }; |
02e2da45 PB |
60 | |
61 | struct BusState { | |
62 | DeviceState *parent; | |
10c4c98a | 63 | BusInfo *info; |
02e2da45 | 64 | const char *name; |
3418bd25 | 65 | int allow_hotplug; |
cd739fb6 | 66 | int qdev_allocated; |
72cf2d4f BS |
67 | QLIST_HEAD(, DeviceState) children; |
68 | QLIST_ENTRY(BusState) sibling; | |
aae9460e PB |
69 | }; |
70 | ||
ee6847d1 GH |
71 | struct Property { |
72 | const char *name; | |
73 | PropertyInfo *info; | |
74 | int offset; | |
d2364ee4 | 75 | int bitnr; |
ee6847d1 GH |
76 | void *defval; |
77 | }; | |
78 | ||
79 | enum PropertyType { | |
80 | PROP_TYPE_UNSPEC = 0, | |
c7cc172d | 81 | PROP_TYPE_UINT8, |
ee6847d1 GH |
82 | PROP_TYPE_UINT16, |
83 | PROP_TYPE_UINT32, | |
316940b0 | 84 | PROP_TYPE_INT32, |
5a053d1f | 85 | PROP_TYPE_UINT64, |
ee6847d1 GH |
86 | PROP_TYPE_TADDR, |
87 | PROP_TYPE_MACADDR, | |
14b41872 | 88 | PROP_TYPE_DRIVE, |
313feaab | 89 | PROP_TYPE_CHR, |
59419663 | 90 | PROP_TYPE_STRING, |
2ef924b4 | 91 | PROP_TYPE_NETDEV, |
851bec09 | 92 | PROP_TYPE_VLAN, |
ee6847d1 | 93 | PROP_TYPE_PTR, |
d2364ee4 | 94 | PROP_TYPE_BIT, |
ee6847d1 GH |
95 | }; |
96 | ||
97 | struct PropertyInfo { | |
98 | const char *name; | |
99 | size_t size; | |
100 | enum PropertyType type; | |
101 | int (*parse)(DeviceState *dev, Property *prop, const char *str); | |
102 | int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); | |
d21357df | 103 | void (*free)(DeviceState *dev, Property *prop); |
ee6847d1 GH |
104 | }; |
105 | ||
458fb679 | 106 | typedef struct GlobalProperty { |
b6b61144 GH |
107 | const char *driver; |
108 | const char *property; | |
109 | const char *value; | |
458fb679 GH |
110 | QTAILQ_ENTRY(GlobalProperty) next; |
111 | } GlobalProperty; | |
b6b61144 | 112 | |
aae9460e PB |
113 | /*** Board API. This should go away once we have a machine config file. ***/ |
114 | ||
02e2da45 | 115 | DeviceState *qdev_create(BusState *bus, const char *name); |
ff952ba2 | 116 | int qdev_device_help(QemuOpts *opts); |
f31d07d1 | 117 | DeviceState *qdev_device_add(QemuOpts *opts); |
747bbdf7 | 118 | int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT; |
e23a1b33 | 119 | void qdev_init_nofail(DeviceState *dev); |
4d2ffa08 JK |
120 | void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, |
121 | int required_for_version); | |
3418bd25 | 122 | int qdev_unplug(DeviceState *dev); |
02e2da45 | 123 | void qdev_free(DeviceState *dev); |
3418bd25 GH |
124 | int qdev_simple_unplug_cb(DeviceState *dev); |
125 | void qdev_machine_creation_done(void); | |
aae9460e | 126 | |
aae9460e PB |
127 | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n); |
128 | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); | |
129 | ||
7b370f51 MA |
130 | BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type); |
131 | ||
02e2da45 | 132 | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); |
4d6ae674 | 133 | |
aae9460e PB |
134 | /*** Device API. ***/ |
135 | ||
81a322d4 | 136 | typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); |
3418bd25 | 137 | typedef int (*qdev_event)(DeviceState *dev); |
7f23f812 | 138 | typedef void (*qdev_resetfn)(DeviceState *dev); |
aae9460e | 139 | |
02e2da45 | 140 | struct DeviceInfo { |
074f2fff | 141 | const char *name; |
3320e56e GH |
142 | const char *alias; |
143 | const char *desc; | |
074f2fff | 144 | size_t size; |
ee6847d1 | 145 | Property *props; |
3320e56e | 146 | int no_user; |
074f2fff | 147 | |
959f733a | 148 | /* callbacks */ |
7f23f812 | 149 | qdev_resetfn reset; |
959f733a | 150 | |
391a079e GH |
151 | /* device state */ |
152 | const VMStateDescription *vmsd; | |
153 | ||
074f2fff | 154 | /* Private to qdev / bus. */ |
02e2da45 | 155 | qdev_initfn init; |
3418bd25 GH |
156 | qdev_event unplug; |
157 | qdev_event exit; | |
10c4c98a | 158 | BusInfo *bus_info; |
042f84d0 | 159 | struct DeviceInfo *next; |
02e2da45 | 160 | }; |
0958b4cc | 161 | extern DeviceInfo *device_info_list; |
02e2da45 | 162 | |
074f2fff | 163 | void qdev_register(DeviceInfo *info); |
aae9460e PB |
164 | |
165 | /* Register device properties. */ | |
067a3ddc | 166 | /* GPIO inputs also double as IRQ sinks. */ |
aae9460e PB |
167 | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); |
168 | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); | |
169 | ||
170 | CharDriverState *qdev_init_chardev(DeviceState *dev); | |
171 | ||
02e2da45 | 172 | BusState *qdev_get_parent_bus(DeviceState *dev); |
aae9460e | 173 | |
02e2da45 PB |
174 | /*** BUS API. ***/ |
175 | ||
cd739fb6 GH |
176 | void qbus_create_inplace(BusState *bus, BusInfo *info, |
177 | DeviceState *parent, const char *name); | |
10c4c98a | 178 | BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name); |
131ec1bd | 179 | void qbus_free(BusState *bus); |
02e2da45 PB |
180 | |
181 | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev) | |
182 | ||
cae4956e GH |
183 | /*** monitor commands ***/ |
184 | ||
185 | void do_info_qtree(Monitor *mon); | |
f6c64e0e | 186 | void do_info_qdm(Monitor *mon); |
8bc27249 | 187 | int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data); |
17a38eaa | 188 | int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data); |
cae4956e | 189 | |
ee6847d1 GH |
190 | /*** qdev-properties.c ***/ |
191 | ||
d2364ee4 | 192 | extern PropertyInfo qdev_prop_bit; |
c7cc172d | 193 | extern PropertyInfo qdev_prop_uint8; |
ee6847d1 GH |
194 | extern PropertyInfo qdev_prop_uint16; |
195 | extern PropertyInfo qdev_prop_uint32; | |
316940b0 | 196 | extern PropertyInfo qdev_prop_int32; |
5a053d1f | 197 | extern PropertyInfo qdev_prop_uint64; |
ee6847d1 | 198 | extern PropertyInfo qdev_prop_hex32; |
5a053d1f | 199 | extern PropertyInfo qdev_prop_hex64; |
59419663 | 200 | extern PropertyInfo qdev_prop_string; |
313feaab | 201 | extern PropertyInfo qdev_prop_chr; |
ee6847d1 GH |
202 | extern PropertyInfo qdev_prop_ptr; |
203 | extern PropertyInfo qdev_prop_macaddr; | |
14b41872 | 204 | extern PropertyInfo qdev_prop_drive; |
851bec09 GH |
205 | extern PropertyInfo qdev_prop_netdev; |
206 | extern PropertyInfo qdev_prop_vlan; | |
05cb5fe4 | 207 | extern PropertyInfo qdev_prop_pci_devfn; |
ee6847d1 | 208 | |
cf12b95b GH |
209 | #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ |
210 | .name = (_name), \ | |
211 | .info = &(_prop), \ | |
212 | .offset = offsetof(_state, _field) \ | |
213 | + type_check(_type,typeof_field(_state, _field)), \ | |
214 | } | |
215 | #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \ | |
216 | .name = (_name), \ | |
217 | .info = &(_prop), \ | |
218 | .offset = offsetof(_state, _field) \ | |
219 | + type_check(_type,typeof_field(_state, _field)), \ | |
220 | .defval = (_type[]) { _defval }, \ | |
221 | } | |
d2364ee4 MT |
222 | #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \ |
223 | .name = (_name), \ | |
224 | .info = &(qdev_prop_bit), \ | |
225 | .bitnr = (_bit), \ | |
226 | .offset = offsetof(_state, _field) \ | |
227 | + type_check(uint32_t,typeof_field(_state, _field)), \ | |
228 | .defval = (bool[]) { (_defval) }, \ | |
229 | } | |
cf12b95b | 230 | |
c7cc172d JQ |
231 | #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \ |
232 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t) | |
cf12b95b GH |
233 | #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \ |
234 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) | |
235 | #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \ | |
236 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) | |
316940b0 GH |
237 | #define DEFINE_PROP_INT32(_n, _s, _f, _d) \ |
238 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t) | |
cf12b95b GH |
239 | #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \ |
240 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) | |
241 | #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \ | |
242 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t) | |
243 | #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \ | |
244 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t) | |
245 | #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \ | |
246 | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t) | |
247 | ||
248 | #define DEFINE_PROP_PTR(_n, _s, _f) \ | |
249 | DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*) | |
313feaab GH |
250 | #define DEFINE_PROP_CHR(_n, _s, _f) \ |
251 | DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) | |
59419663 GH |
252 | #define DEFINE_PROP_STRING(_n, _s, _f) \ |
253 | DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*) | |
2ef924b4 GH |
254 | #define DEFINE_PROP_NETDEV(_n, _s, _f) \ |
255 | DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*) | |
851bec09 GH |
256 | #define DEFINE_PROP_VLAN(_n, _s, _f) \ |
257 | DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*) | |
f8b6cc00 MA |
258 | #define DEFINE_PROP_DRIVE(_n, _s, _f) \ |
259 | DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *) | |
cf12b95b | 260 | #define DEFINE_PROP_MACADDR(_n, _s, _f) \ |
1503fff3 | 261 | DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr) |
cf12b95b GH |
262 | |
263 | #define DEFINE_PROP_END_OF_LIST() \ | |
264 | {} | |
265 | ||
ee6847d1 GH |
266 | /* Set properties between creation and init. */ |
267 | void *qdev_get_prop_ptr(DeviceState *dev, Property *prop); | |
d8ed79ae | 268 | int qdev_prop_exists(DeviceState *dev, const char *name); |
ee6847d1 GH |
269 | int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); |
270 | void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); | |
f4594a3b | 271 | void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value); |
c7cc172d | 272 | void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value); |
ee6847d1 GH |
273 | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); |
274 | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); | |
316940b0 | 275 | void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value); |
5a053d1f | 276 | void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); |
cc984673 | 277 | void qdev_prop_set_string(DeviceState *dev, const char *name, char *value); |
313feaab | 278 | void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); |
2ef924b4 | 279 | void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value); |
851bec09 | 280 | void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value); |
18846dee MA |
281 | int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT; |
282 | void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value); | |
1503fff3 | 283 | void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value); |
ee6847d1 GH |
284 | /* FIXME: Remove opaque pointer properties. */ |
285 | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); | |
286 | void qdev_prop_set_defaults(DeviceState *dev, Property *props); | |
287 | ||
458fb679 GH |
288 | void qdev_prop_register_global_list(GlobalProperty *props); |
289 | void qdev_prop_set_globals(DeviceState *dev); | |
b6b61144 | 290 | |
a9ff9df1 BS |
291 | /* This is a nasty hack to allow passing a NULL bus to qdev_create. */ |
292 | extern struct BusInfo system_bus_info; | |
293 | ||
aae9460e | 294 | #endif |