Introduce fw_name field to DeviceInfo structure.
[qemu/opensuse.git] / hw / qdev.h
blobbc7111089ef297aa708cfd1a2ae26a05d46641bf
1 #ifndef QDEV_H
2 #define QDEV_H
4 #include "hw.h"
5 #include "qemu-queue.h"
6 #include "qemu-char.h"
7 #include "qemu-option.h"
9 typedef struct Property Property;
11 typedef struct PropertyInfo PropertyInfo;
13 typedef struct CompatProperty CompatProperty;
15 typedef struct DeviceInfo DeviceInfo;
17 typedef struct BusState BusState;
19 typedef struct BusInfo BusInfo;
21 enum DevState {
22 DEV_STATE_CREATED = 1,
23 DEV_STATE_INITIALIZED,
26 enum {
27 DEV_NVECTORS_UNSPECIFIED = -1,
30 /* This structure should not be accessed directly. We declare it here
31 so that it can be embedded in individual device state structures. */
32 struct DeviceState {
33 const char *id;
34 enum DevState state;
35 QemuOpts *opts;
36 int hotplugged;
37 DeviceInfo *info;
38 BusState *parent_bus;
39 int num_gpio_out;
40 qemu_irq *gpio_out;
41 int num_gpio_in;
42 qemu_irq *gpio_in;
43 QLIST_HEAD(, BusState) child_bus;
44 int num_child_bus;
45 QLIST_ENTRY(DeviceState) sibling;
46 int instance_id_alias;
47 int alias_required_for_version;
50 typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
51 typedef char *(*bus_get_dev_path)(DeviceState *dev);
52 typedef int (qbus_resetfn)(BusState *bus);
54 struct BusInfo {
55 const char *name;
56 size_t size;
57 bus_dev_printfn print_dev;
58 bus_get_dev_path get_dev_path;
59 qbus_resetfn *reset;
60 Property *props;
63 struct BusState {
64 DeviceState *parent;
65 BusInfo *info;
66 const char *name;
67 int allow_hotplug;
68 int qdev_allocated;
69 QLIST_HEAD(, DeviceState) children;
70 QLIST_ENTRY(BusState) sibling;
73 struct Property {
74 const char *name;
75 PropertyInfo *info;
76 int offset;
77 int bitnr;
78 void *defval;
81 enum PropertyType {
82 PROP_TYPE_UNSPEC = 0,
83 PROP_TYPE_UINT8,
84 PROP_TYPE_UINT16,
85 PROP_TYPE_UINT32,
86 PROP_TYPE_INT32,
87 PROP_TYPE_UINT64,
88 PROP_TYPE_TADDR,
89 PROP_TYPE_MACADDR,
90 PROP_TYPE_DRIVE,
91 PROP_TYPE_CHR,
92 PROP_TYPE_STRING,
93 PROP_TYPE_NETDEV,
94 PROP_TYPE_VLAN,
95 PROP_TYPE_PTR,
96 PROP_TYPE_BIT,
99 struct PropertyInfo {
100 const char *name;
101 size_t size;
102 enum PropertyType type;
103 int (*parse)(DeviceState *dev, Property *prop, const char *str);
104 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
105 void (*free)(DeviceState *dev, Property *prop);
108 typedef struct GlobalProperty {
109 const char *driver;
110 const char *property;
111 const char *value;
112 QTAILQ_ENTRY(GlobalProperty) next;
113 } GlobalProperty;
115 /*** Board API. This should go away once we have a machine config file. ***/
117 DeviceState *qdev_create(BusState *bus, const char *name);
118 int qdev_device_help(QemuOpts *opts);
119 DeviceState *qdev_device_add(QemuOpts *opts);
120 int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
121 void qdev_init_nofail(DeviceState *dev);
122 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
123 int required_for_version);
124 int qdev_unplug(DeviceState *dev);
125 void qdev_free(DeviceState *dev);
126 int qdev_simple_unplug_cb(DeviceState *dev);
127 void qdev_machine_creation_done(void);
129 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
130 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
132 BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type);
134 BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
136 /*** Device API. ***/
138 typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
139 typedef int (*qdev_event)(DeviceState *dev);
140 typedef void (*qdev_resetfn)(DeviceState *dev);
142 struct DeviceInfo {
143 const char *name;
144 const char *fw_name;
145 const char *alias;
146 const char *desc;
147 size_t size;
148 Property *props;
149 int no_user;
151 /* callbacks */
152 qdev_resetfn reset;
154 /* device state */
155 const VMStateDescription *vmsd;
157 /* Private to qdev / bus. */
158 qdev_initfn init;
159 qdev_event unplug;
160 qdev_event exit;
161 BusInfo *bus_info;
162 struct DeviceInfo *next;
164 extern DeviceInfo *device_info_list;
166 void qdev_register(DeviceInfo *info);
168 /* Register device properties. */
169 /* GPIO inputs also double as IRQ sinks. */
170 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
171 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
173 CharDriverState *qdev_init_chardev(DeviceState *dev);
175 BusState *qdev_get_parent_bus(DeviceState *dev);
177 /*** BUS API. ***/
179 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
180 typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
181 typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
183 void qbus_create_inplace(BusState *bus, BusInfo *info,
184 DeviceState *parent, const char *name);
185 BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
186 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
187 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
188 * 0 otherwise. */
189 int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
190 qbus_walkerfn *busfn, void *opaque);
191 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
192 qbus_walkerfn *busfn, void *opaque);
193 void qdev_reset_all(DeviceState *dev);
194 void qbus_reset_all(BusState *bus);
195 void qbus_free(BusState *bus);
197 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
199 /* This should go away once we get rid of the NULL bus hack */
200 BusState *sysbus_get_default(void);
202 /*** monitor commands ***/
204 void do_info_qtree(Monitor *mon);
205 void do_info_qdm(Monitor *mon);
206 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
207 int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
209 /*** qdev-properties.c ***/
211 extern PropertyInfo qdev_prop_bit;
212 extern PropertyInfo qdev_prop_uint8;
213 extern PropertyInfo qdev_prop_uint16;
214 extern PropertyInfo qdev_prop_uint32;
215 extern PropertyInfo qdev_prop_int32;
216 extern PropertyInfo qdev_prop_uint64;
217 extern PropertyInfo qdev_prop_hex32;
218 extern PropertyInfo qdev_prop_hex64;
219 extern PropertyInfo qdev_prop_string;
220 extern PropertyInfo qdev_prop_chr;
221 extern PropertyInfo qdev_prop_ptr;
222 extern PropertyInfo qdev_prop_macaddr;
223 extern PropertyInfo qdev_prop_drive;
224 extern PropertyInfo qdev_prop_netdev;
225 extern PropertyInfo qdev_prop_vlan;
226 extern PropertyInfo qdev_prop_pci_devfn;
228 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
229 .name = (_name), \
230 .info = &(_prop), \
231 .offset = offsetof(_state, _field) \
232 + type_check(_type,typeof_field(_state, _field)), \
234 #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
235 .name = (_name), \
236 .info = &(_prop), \
237 .offset = offsetof(_state, _field) \
238 + type_check(_type,typeof_field(_state, _field)), \
239 .defval = (_type[]) { _defval }, \
241 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
242 .name = (_name), \
243 .info = &(qdev_prop_bit), \
244 .bitnr = (_bit), \
245 .offset = offsetof(_state, _field) \
246 + type_check(uint32_t,typeof_field(_state, _field)), \
247 .defval = (bool[]) { (_defval) }, \
250 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
251 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
252 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
253 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
254 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
255 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
256 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
257 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
258 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
259 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
260 #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
261 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
262 #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
263 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
264 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
265 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
267 #define DEFINE_PROP_PTR(_n, _s, _f) \
268 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
269 #define DEFINE_PROP_CHR(_n, _s, _f) \
270 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
271 #define DEFINE_PROP_STRING(_n, _s, _f) \
272 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
273 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
274 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
275 #define DEFINE_PROP_VLAN(_n, _s, _f) \
276 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
277 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
278 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
279 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
280 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
282 #define DEFINE_PROP_END_OF_LIST() \
285 /* Set properties between creation and init. */
286 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
287 int qdev_prop_exists(DeviceState *dev, const char *name);
288 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
289 void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
290 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
291 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
292 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
293 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
294 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
295 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
296 void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
297 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
298 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
299 void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
300 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
301 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
302 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
303 /* FIXME: Remove opaque pointer properties. */
304 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
305 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
307 void qdev_prop_register_global_list(GlobalProperty *props);
308 void qdev_prop_set_globals(DeviceState *dev);
310 static inline const char *qdev_fw_name(DeviceState *dev)
312 return dev->info->fw_name ? : dev->info->alias ? : dev->info->name;
315 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
316 extern struct BusInfo system_bus_info;
318 #endif