5 #include "qemu-queue.h"
7 #include "qemu-option.h"
8 #include "qapi/qapi-visit-core.h"
9 #include "qemu/object.h"
11 typedef struct Property Property;
13 typedef struct PropertyInfo PropertyInfo;
15 typedef struct CompatProperty CompatProperty;
17 typedef struct BusState BusState;
19 typedef struct BusInfo BusInfo;
22 DEV_STATE_CREATED = 1,
23 DEV_STATE_INITIALIZED,
27 DEV_NVECTORS_UNSPECIFIED = -1,
30 #define TYPE_DEVICE "device"
31 #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
32 #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
33 #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
35 typedef int (*qdev_initfn)(DeviceState *dev);
36 typedef int (*qdev_event)(DeviceState *dev);
37 typedef void (*qdev_resetfn)(DeviceState *dev);
39 typedef struct DeviceClass {
40 ObjectClass parent_class;
48 void (*reset)(DeviceState *dev);
51 const VMStateDescription *vmsd;
53 /* Private to qdev / bus. */
60 /* This structure should not be accessed directly. We declare it here
61 so that it can be embedded in individual device state structures. */
74 QLIST_HEAD(, BusState) child_bus;
76 QTAILQ_ENTRY(DeviceState) sibling;
77 int instance_id_alias;
78 int alias_required_for_version;
81 typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
82 typedef char *(*bus_get_dev_path)(DeviceState *dev);
84 * This callback is used to create Open Firmware device path in accordance with
85 * OF spec http://forthworks.com/standards/of1275.pdf. Indicidual bus bindings
86 * can be found here http://playground.sun.com/1275/bindings/.
88 typedef char *(*bus_get_fw_dev_path)(DeviceState *dev);
89 typedef int (qbus_resetfn)(BusState *bus);
94 bus_dev_printfn print_dev;
95 bus_get_dev_path get_dev_path;
96 bus_get_fw_dev_path get_fw_dev_path;
107 QTAILQ_HEAD(ChildrenHead, DeviceState) children;
108 QLIST_ENTRY(BusState) sibling;
120 PROP_TYPE_UNSPEC = 0,
128 PROP_TYPE_LOSTTICKPOLICY,
138 struct PropertyInfo {
140 const char *legacy_name;
142 enum PropertyType type;
143 const char **enum_table;
146 int (*parse)(DeviceState *dev, Property *prop, const char *str);
147 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
148 ObjectPropertyAccessor *get;
149 ObjectPropertyAccessor *set;
150 ObjectPropertyRelease *release;
153 typedef struct GlobalProperty {
155 const char *property;
157 QTAILQ_ENTRY(GlobalProperty) next;
160 /*** Board API. This should go away once we have a machine config file. ***/
162 DeviceState *qdev_create(BusState *bus, const char *name);
163 DeviceState *qdev_try_create(BusState *bus, const char *name);
164 bool qdev_exists(const char *name);
165 int qdev_device_help(QemuOpts *opts);
166 DeviceState *qdev_device_add(QemuOpts *opts);
167 int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
168 void qdev_init_nofail(DeviceState *dev);
169 void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
170 int required_for_version);
171 int qdev_unplug(DeviceState *dev);
172 void qdev_free(DeviceState *dev);
173 int qdev_simple_unplug_cb(DeviceState *dev);
174 void qdev_machine_creation_done(void);
175 bool qdev_machine_modified(void);
177 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
178 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
180 BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
182 /*** Device API. ***/
184 /* Register device properties. */
185 /* GPIO inputs also double as IRQ sinks. */
186 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
187 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
189 BusState *qdev_get_parent_bus(DeviceState *dev);
193 DeviceState *qdev_find_recursive(BusState *bus, const char *id);
195 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
196 typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
197 typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
199 void qbus_create_inplace(BusState *bus, BusInfo *info,
200 DeviceState *parent, const char *name);
201 BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
202 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
203 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
205 int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
206 qbus_walkerfn *busfn, void *opaque);
207 int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
208 qbus_walkerfn *busfn, void *opaque);
209 void qdev_reset_all(DeviceState *dev);
210 void qbus_reset_all_fn(void *opaque);
212 void qbus_free(BusState *bus);
214 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
216 /* This should go away once we get rid of the NULL bus hack */
217 BusState *sysbus_get_default(void);
219 /*** monitor commands ***/
221 void do_info_qtree(Monitor *mon);
222 void do_info_qdm(Monitor *mon);
223 int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
224 int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
226 /*** qdev-properties.c ***/
228 extern PropertyInfo qdev_prop_bit;
229 extern PropertyInfo qdev_prop_uint8;
230 extern PropertyInfo qdev_prop_uint16;
231 extern PropertyInfo qdev_prop_uint32;
232 extern PropertyInfo qdev_prop_int32;
233 extern PropertyInfo qdev_prop_uint64;
234 extern PropertyInfo qdev_prop_hex8;
235 extern PropertyInfo qdev_prop_hex32;
236 extern PropertyInfo qdev_prop_hex64;
237 extern PropertyInfo qdev_prop_string;
238 extern PropertyInfo qdev_prop_chr;
239 extern PropertyInfo qdev_prop_ptr;
240 extern PropertyInfo qdev_prop_macaddr;
241 extern PropertyInfo qdev_prop_losttickpolicy;
242 extern PropertyInfo qdev_prop_drive;
243 extern PropertyInfo qdev_prop_netdev;
244 extern PropertyInfo qdev_prop_vlan;
245 extern PropertyInfo qdev_prop_pci_devfn;
247 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
250 .offset = offsetof(_state, _field) \
251 + type_check(_type,typeof_field(_state, _field)), \
253 #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
256 .offset = offsetof(_state, _field) \
257 + type_check(_type,typeof_field(_state, _field)), \
258 .defval = (_type[]) { _defval }, \
260 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
262 .info = &(qdev_prop_bit), \
264 .offset = offsetof(_state, _field) \
265 + type_check(uint32_t,typeof_field(_state, _field)), \
266 .defval = (bool[]) { (_defval) }, \
269 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
270 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
271 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
272 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
273 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
274 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
275 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
276 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
277 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
278 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
279 #define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
280 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
281 #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
282 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
283 #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
284 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
285 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
286 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
288 #define DEFINE_PROP_PTR(_n, _s, _f) \
289 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
290 #define DEFINE_PROP_CHR(_n, _s, _f) \
291 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
292 #define DEFINE_PROP_STRING(_n, _s, _f) \
293 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
294 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
295 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
296 #define DEFINE_PROP_VLAN(_n, _s, _f) \
297 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
298 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
299 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
300 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
301 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
302 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
303 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
306 #define DEFINE_PROP_END_OF_LIST() \
309 /* Set properties between creation and init. */
310 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
311 int qdev_prop_exists(DeviceState *dev, const char *name);
312 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
313 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
314 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
315 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
316 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
317 void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
318 void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
319 void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
320 void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
321 void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
322 void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
323 int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
324 void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
325 void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
326 void qdev_prop_set_enum(DeviceState *dev, const char *name, int value);
327 /* FIXME: Remove opaque pointer properties. */
328 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
329 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
331 void qdev_prop_register_global_list(GlobalProperty *props);
332 void qdev_prop_set_globals(DeviceState *dev);
333 void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
334 Property *prop, const char *value);
336 char *qdev_get_fw_dev_path(DeviceState *dev);
338 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
339 extern struct BusInfo system_bus_info;
342 * @qdev_property_add_static - add a @Property to a device referencing a
345 void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
350 * Initialize platform devices before machine init. This is a hack until full
351 * support for composition is added.
353 void qdev_machine_init(void);
358 * Reset a single device (by calling the reset method).
360 void device_reset(DeviceState *dev);
362 const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
364 const char *qdev_fw_name(DeviceState *dev);
366 BusInfo *qdev_get_bus_info(DeviceState *dev);
368 Property *qdev_get_props(DeviceState *dev);
370 /* FIXME: make this a link<> */
371 void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
373 extern int qdev_hotplug;