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