root / hw / qdev.h @ f8274971
History | View | Annotate | Download (7.2 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 | 02e2da45 | Paul Brook | #include "sys-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 | aae9460e | Paul Brook | /* This structure should not be accessed directly. We declare it here
|
23 | aae9460e | Paul Brook | so that it can be embedded in individual device state structures. */
|
24 | 02e2da45 | Paul Brook | struct DeviceState {
|
25 | f31d07d1 | Gerd Hoffmann | const char *id; |
26 | 042f84d0 | Gerd Hoffmann | DeviceInfo *info; |
27 | 02e2da45 | Paul Brook | BusState *parent_bus; |
28 | aae9460e | Paul Brook | int num_gpio_out;
|
29 | aae9460e | Paul Brook | qemu_irq *gpio_out; |
30 | aae9460e | Paul Brook | int num_gpio_in;
|
31 | aae9460e | Paul Brook | qemu_irq *gpio_in; |
32 | 02e2da45 | Paul Brook | LIST_HEAD(, BusState) child_bus; |
33 | d271de9f | Gerd Hoffmann | int num_child_bus;
|
34 | 9d07d757 | Paul Brook | NICInfo *nd; |
35 | 02e2da45 | Paul Brook | LIST_ENTRY(DeviceState) sibling; |
36 | 02e2da45 | Paul Brook | }; |
37 | 02e2da45 | Paul Brook | |
38 | 10c4c98a | Gerd Hoffmann | typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); |
39 | 10c4c98a | Gerd Hoffmann | struct BusInfo {
|
40 | 10c4c98a | Gerd Hoffmann | const char *name; |
41 | 10c4c98a | Gerd Hoffmann | size_t size; |
42 | 10c4c98a | Gerd Hoffmann | bus_dev_printfn print_dev; |
43 | ee6847d1 | Gerd Hoffmann | Property *props; |
44 | 10c4c98a | Gerd Hoffmann | }; |
45 | 02e2da45 | Paul Brook | |
46 | 02e2da45 | Paul Brook | struct BusState {
|
47 | 02e2da45 | Paul Brook | DeviceState *parent; |
48 | 10c4c98a | Gerd Hoffmann | BusInfo *info; |
49 | 02e2da45 | Paul Brook | const char *name; |
50 | 02e2da45 | Paul Brook | LIST_HEAD(, DeviceState) children; |
51 | 02e2da45 | Paul Brook | LIST_ENTRY(BusState) sibling; |
52 | aae9460e | Paul Brook | }; |
53 | aae9460e | Paul Brook | |
54 | ee6847d1 | Gerd Hoffmann | struct Property {
|
55 | ee6847d1 | Gerd Hoffmann | const char *name; |
56 | ee6847d1 | Gerd Hoffmann | PropertyInfo *info; |
57 | ee6847d1 | Gerd Hoffmann | int offset;
|
58 | ee6847d1 | Gerd Hoffmann | void *defval;
|
59 | ee6847d1 | Gerd Hoffmann | }; |
60 | ee6847d1 | Gerd Hoffmann | |
61 | ee6847d1 | Gerd Hoffmann | enum PropertyType {
|
62 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_UNSPEC = 0,
|
63 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_UINT16, |
64 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_UINT32, |
65 | 5a053d1f | Blue Swirl | PROP_TYPE_UINT64, |
66 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_TADDR, |
67 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_MACADDR, |
68 | 14b41872 | Gerd Hoffmann | PROP_TYPE_DRIVE, |
69 | 313feaab | Gerd Hoffmann | PROP_TYPE_CHR, |
70 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_PTR, |
71 | ee6847d1 | Gerd Hoffmann | }; |
72 | ee6847d1 | Gerd Hoffmann | |
73 | ee6847d1 | Gerd Hoffmann | struct PropertyInfo {
|
74 | ee6847d1 | Gerd Hoffmann | const char *name; |
75 | ee6847d1 | Gerd Hoffmann | size_t size; |
76 | ee6847d1 | Gerd Hoffmann | enum PropertyType type;
|
77 | ee6847d1 | Gerd Hoffmann | int (*parse)(DeviceState *dev, Property *prop, const char *str); |
78 | ee6847d1 | Gerd Hoffmann | int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); |
79 | ee6847d1 | Gerd Hoffmann | }; |
80 | ee6847d1 | Gerd Hoffmann | |
81 | b6b61144 | Gerd Hoffmann | struct CompatProperty {
|
82 | b6b61144 | Gerd Hoffmann | const char *driver; |
83 | b6b61144 | Gerd Hoffmann | const char *property; |
84 | b6b61144 | Gerd Hoffmann | const char *value; |
85 | b6b61144 | Gerd Hoffmann | }; |
86 | b6b61144 | Gerd Hoffmann | |
87 | aae9460e | Paul Brook | /*** Board API. This should go away once we have a machine config file. ***/
|
88 | aae9460e | Paul Brook | |
89 | 02e2da45 | Paul Brook | DeviceState *qdev_create(BusState *bus, const char *name); |
90 | f31d07d1 | Gerd Hoffmann | DeviceState *qdev_device_add(QemuOpts *opts); |
91 | 81a322d4 | Gerd Hoffmann | int qdev_init(DeviceState *dev);
|
92 | 02e2da45 | Paul Brook | void qdev_free(DeviceState *dev);
|
93 | aae9460e | Paul Brook | |
94 | aae9460e | Paul Brook | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
|
95 | aae9460e | Paul Brook | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); |
96 | aae9460e | Paul Brook | |
97 | 02e2da45 | Paul Brook | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); |
98 | 4d6ae674 | Paul Brook | |
99 | aae9460e | Paul Brook | /*** Device API. ***/
|
100 | aae9460e | Paul Brook | |
101 | 81a322d4 | Gerd Hoffmann | typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); |
102 | 6f68ecb2 | Paul Brook | typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, |
103 | 6f68ecb2 | Paul Brook | int unit);
|
104 | aae9460e | Paul Brook | |
105 | 02e2da45 | Paul Brook | struct DeviceInfo {
|
106 | 074f2fff | Gerd Hoffmann | const char *name; |
107 | 3320e56e | Gerd Hoffmann | const char *alias; |
108 | 3320e56e | Gerd Hoffmann | const char *desc; |
109 | 074f2fff | Gerd Hoffmann | size_t size; |
110 | ee6847d1 | Gerd Hoffmann | Property *props; |
111 | 3320e56e | Gerd Hoffmann | int no_user;
|
112 | 074f2fff | Gerd Hoffmann | |
113 | 074f2fff | Gerd Hoffmann | /* Private to qdev / bus. */
|
114 | 02e2da45 | Paul Brook | qdev_initfn init; |
115 | 10c4c98a | Gerd Hoffmann | BusInfo *bus_info; |
116 | 042f84d0 | Gerd Hoffmann | struct DeviceInfo *next;
|
117 | 02e2da45 | Paul Brook | }; |
118 | 02e2da45 | Paul Brook | |
119 | 074f2fff | Gerd Hoffmann | void qdev_register(DeviceInfo *info);
|
120 | aae9460e | Paul Brook | |
121 | aae9460e | Paul Brook | /* Register device properties. */
|
122 | 067a3ddc | Paul Brook | /* GPIO inputs also double as IRQ sinks. */
|
123 | aae9460e | Paul Brook | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); |
124 | aae9460e | Paul Brook | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); |
125 | aae9460e | Paul Brook | |
126 | 6f68ecb2 | Paul Brook | void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
|
127 | 6f68ecb2 | Paul Brook | |
128 | aae9460e | Paul Brook | CharDriverState *qdev_init_chardev(DeviceState *dev); |
129 | aae9460e | Paul Brook | |
130 | 02e2da45 | Paul Brook | BusState *qdev_get_parent_bus(DeviceState *dev); |
131 | aae9460e | Paul Brook | |
132 | aae9460e | Paul Brook | /* Convery from a base type to a parent type, with compile time checking. */
|
133 | aae9460e | Paul Brook | #ifdef __GNUC__
|
134 | aae9460e | Paul Brook | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
|
135 | aae9460e | Paul Brook | char __attribute__((unused)) offset_must_be_zero[ \
|
136 | aae9460e | Paul Brook | -offsetof(type, field)]; \ |
137 | aae9460e | Paul Brook | container_of(dev, type, field);})) |
138 | aae9460e | Paul Brook | #else
|
139 | aae9460e | Paul Brook | #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
|
140 | aae9460e | Paul Brook | #endif
|
141 | aae9460e | Paul Brook | |
142 | 02e2da45 | Paul Brook | /*** BUS API. ***/
|
143 | 02e2da45 | Paul Brook | |
144 | 10c4c98a | Gerd Hoffmann | BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name); |
145 | 02e2da45 | Paul Brook | |
146 | 02e2da45 | Paul Brook | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
|
147 | 02e2da45 | Paul Brook | |
148 | cae4956e | Gerd Hoffmann | /*** monitor commands ***/
|
149 | cae4956e | Gerd Hoffmann | |
150 | cae4956e | Gerd Hoffmann | void do_info_qtree(Monitor *mon);
|
151 | f6c64e0e | Gerd Hoffmann | void do_info_qdm(Monitor *mon);
|
152 | cae4956e | Gerd Hoffmann | |
153 | ee6847d1 | Gerd Hoffmann | /*** qdev-properties.c ***/
|
154 | ee6847d1 | Gerd Hoffmann | |
155 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_uint16;
|
156 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_uint32;
|
157 | 5a053d1f | Blue Swirl | extern PropertyInfo qdev_prop_uint64;
|
158 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_hex32;
|
159 | 5a053d1f | Blue Swirl | extern PropertyInfo qdev_prop_hex64;
|
160 | 313feaab | Gerd Hoffmann | extern PropertyInfo qdev_prop_chr;
|
161 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_ptr;
|
162 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_macaddr;
|
163 | 14b41872 | Gerd Hoffmann | extern PropertyInfo qdev_prop_drive;
|
164 | 05cb5fe4 | Gerd Hoffmann | extern PropertyInfo qdev_prop_pci_devfn;
|
165 | ee6847d1 | Gerd Hoffmann | |
166 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
|
167 | cf12b95b | Gerd Hoffmann | .name = (_name), \ |
168 | cf12b95b | Gerd Hoffmann | .info = &(_prop), \ |
169 | cf12b95b | Gerd Hoffmann | .offset = offsetof(_state, _field) \ |
170 | cf12b95b | Gerd Hoffmann | + type_check(_type,typeof_field(_state, _field)), \ |
171 | cf12b95b | Gerd Hoffmann | } |
172 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
|
173 | cf12b95b | Gerd Hoffmann | .name = (_name), \ |
174 | cf12b95b | Gerd Hoffmann | .info = &(_prop), \ |
175 | cf12b95b | Gerd Hoffmann | .offset = offsetof(_state, _field) \ |
176 | cf12b95b | Gerd Hoffmann | + type_check(_type,typeof_field(_state, _field)), \ |
177 | cf12b95b | Gerd Hoffmann | .defval = (_type[]) { _defval }, \ |
178 | cf12b95b | Gerd Hoffmann | } |
179 | cf12b95b | Gerd Hoffmann | |
180 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
|
181 | cf12b95b | Gerd Hoffmann | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t) |
182 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
|
183 | cf12b95b | Gerd Hoffmann | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t) |
184 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
|
185 | cf12b95b | Gerd Hoffmann | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t) |
186 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
|
187 | cf12b95b | Gerd Hoffmann | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t) |
188 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
|
189 | cf12b95b | Gerd Hoffmann | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t) |
190 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
|
191 | cf12b95b | Gerd Hoffmann | DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t) |
192 | cf12b95b | Gerd Hoffmann | |
193 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_PTR(_n, _s, _f) \
|
194 | cf12b95b | Gerd Hoffmann | DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
|
195 | 313feaab | Gerd Hoffmann | #define DEFINE_PROP_CHR(_n, _s, _f) \
|
196 | 313feaab | Gerd Hoffmann | DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*) |
197 | f6c64e0e | Gerd Hoffmann | #define DEFINE_PROP_DRIVE(_n, _s, _f) \
|
198 | c981d39c | Anthony Liguori | DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*) |
199 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_MACADDR(_n, _s, _f) \
|
200 | cf12b95b | Gerd Hoffmann | DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, uint8_t[6])
|
201 | cf12b95b | Gerd Hoffmann | |
202 | cf12b95b | Gerd Hoffmann | #define DEFINE_PROP_END_OF_LIST() \
|
203 | cf12b95b | Gerd Hoffmann | {} |
204 | cf12b95b | Gerd Hoffmann | |
205 | ee6847d1 | Gerd Hoffmann | /* Set properties between creation and init. */
|
206 | ee6847d1 | Gerd Hoffmann | void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
|
207 | ee6847d1 | Gerd Hoffmann | int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); |
208 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); |
209 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); |
210 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); |
211 | 5a053d1f | Blue Swirl | void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value); |
212 | 313feaab | Gerd Hoffmann | void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value); |
213 | 14b41872 | Gerd Hoffmann | void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value); |
214 | ee6847d1 | Gerd Hoffmann | /* FIXME: Remove opaque pointer properties. */
|
215 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); |
216 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_defaults(DeviceState *dev, Property *props);
|
217 | ee6847d1 | Gerd Hoffmann | |
218 | b6b61144 | Gerd Hoffmann | void qdev_prop_register_compat(CompatProperty *props);
|
219 | b6b61144 | Gerd Hoffmann | void qdev_prop_set_compat(DeviceState *dev);
|
220 | b6b61144 | Gerd Hoffmann | |
221 | a9ff9df1 | Blue Swirl | /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
|
222 | a9ff9df1 | Blue Swirl | extern struct BusInfo system_bus_info; |
223 | a9ff9df1 | Blue Swirl | |
224 | aae9460e | Paul Brook | #endif |