5 #include "qemu-queue.h"
7 #include "qemu-option.h"
8 #include "qapi/qapi-visit-core.h"
9 #include "qemu/object.h"
12 typedef struct Property Property
;
14 typedef struct PropertyInfo PropertyInfo
;
16 typedef struct CompatProperty CompatProperty
;
18 typedef struct BusState BusState
;
20 typedef struct BusClass BusClass
;
23 DEV_STATE_CREATED
= 1,
24 DEV_STATE_INITIALIZED
,
28 DEV_NVECTORS_UNSPECIFIED
= -1,
31 #define TYPE_DEVICE "device"
32 #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
33 #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
34 #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
36 typedef int (*qdev_initfn
)(DeviceState
*dev
);
37 typedef int (*qdev_event
)(DeviceState
*dev
);
38 typedef void (*qdev_resetfn
)(DeviceState
*dev
);
40 typedef struct DeviceClass
{
41 ObjectClass parent_class
;
49 void (*reset
)(DeviceState
*dev
);
52 const VMStateDescription
*vmsd
;
54 /* Private to qdev / bus. */
61 /* This structure should not be accessed directly. We declare it here
62 so that it can be embedded in individual device state structures. */
75 QLIST_HEAD(, BusState
) child_bus
;
77 int instance_id_alias
;
78 int alias_required_for_version
;
81 #define TYPE_BUS "bus"
82 #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
83 #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
84 #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
87 ObjectClass parent_class
;
89 /* FIXME first arg should be BusState */
90 void (*print_dev
)(Monitor
*mon
, DeviceState
*dev
, int indent
);
91 char *(*get_dev_path
)(DeviceState
*dev
);
93 * This callback is used to create Open Firmware device path in accordance
94 * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus
95 * bindings can be found at http://playground.sun.com/1275/bindings/.
97 char *(*get_fw_dev_path
)(DeviceState
*dev
);
98 int (*reset
)(BusState
*bus
);
101 typedef struct BusChild
{
104 QTAILQ_ENTRY(BusChild
) sibling
;
109 * @qom_allocated: Indicates whether the object was allocated by QOM.
110 * @glib_allocated: Indicates whether the object was initialized in-place
111 * yet is expected to be freed with g_free().
121 QTAILQ_HEAD(ChildrenHead
, BusChild
) children
;
122 QLIST_ENTRY(BusState
) sibling
;
134 struct PropertyInfo
{
136 const char *legacy_name
;
137 const char **enum_table
;
138 int (*parse
)(DeviceState
*dev
, Property
*prop
, const char *str
);
139 int (*print
)(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
);
140 ObjectPropertyAccessor
*get
;
141 ObjectPropertyAccessor
*set
;
142 ObjectPropertyRelease
*release
;
145 typedef struct GlobalProperty
{
147 const char *property
;
149 QTAILQ_ENTRY(GlobalProperty
) next
;
152 /*** Board API. This should go away once we have a machine config file. ***/
154 DeviceState
*qdev_create(BusState
*bus
, const char *name
);
155 DeviceState
*qdev_try_create(BusState
*bus
, const char *name
);
156 bool qdev_exists(const char *name
);
157 int qdev_device_help(QemuOpts
*opts
);
158 DeviceState
*qdev_device_add(QemuOpts
*opts
);
159 int qdev_init(DeviceState
*dev
) QEMU_WARN_UNUSED_RESULT
;
160 void qdev_init_nofail(DeviceState
*dev
);
161 void qdev_set_legacy_instance_id(DeviceState
*dev
, int alias_id
,
162 int required_for_version
);
163 void qdev_unplug(DeviceState
*dev
, Error
**errp
);
164 void qdev_free(DeviceState
*dev
);
165 int qdev_simple_unplug_cb(DeviceState
*dev
);
166 void qdev_machine_creation_done(void);
167 bool qdev_machine_modified(void);
169 qemu_irq
qdev_get_gpio_in(DeviceState
*dev
, int n
);
170 void qdev_connect_gpio_out(DeviceState
*dev
, int n
, qemu_irq pin
);
172 BusState
*qdev_get_child_bus(DeviceState
*dev
, const char *name
);
174 /*** Device API. ***/
176 /* Register device properties. */
177 /* GPIO inputs also double as IRQ sinks. */
178 void qdev_init_gpio_in(DeviceState
*dev
, qemu_irq_handler handler
, int n
);
179 void qdev_init_gpio_out(DeviceState
*dev
, qemu_irq
*pins
, int n
);
181 BusState
*qdev_get_parent_bus(DeviceState
*dev
);
185 DeviceState
*qdev_find_recursive(BusState
*bus
, const char *id
);
187 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
188 typedef int (qbus_walkerfn
)(BusState
*bus
, void *opaque
);
189 typedef int (qdev_walkerfn
)(DeviceState
*dev
, void *opaque
);
191 void qbus_create_inplace(BusState
*bus
, const char *typename
,
192 DeviceState
*parent
, const char *name
);
193 BusState
*qbus_create(const char *typename
, DeviceState
*parent
, const char *name
);
194 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
195 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
197 int qbus_walk_children(BusState
*bus
, qdev_walkerfn
*devfn
,
198 qbus_walkerfn
*busfn
, void *opaque
);
199 int qdev_walk_children(DeviceState
*dev
, qdev_walkerfn
*devfn
,
200 qbus_walkerfn
*busfn
, void *opaque
);
201 void qdev_reset_all(DeviceState
*dev
);
202 void qbus_reset_all_fn(void *opaque
);
204 void qbus_free(BusState
*bus
);
206 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
208 /* This should go away once we get rid of the NULL bus hack */
209 BusState
*sysbus_get_default(void);
211 /*** monitor commands ***/
213 void do_info_qtree(Monitor
*mon
);
214 void do_info_qdm(Monitor
*mon
);
215 int do_device_add(Monitor
*mon
, const QDict
*qdict
, QObject
**ret_data
);
216 int do_device_del(Monitor
*mon
, const QDict
*qdict
, QObject
**ret_data
);
218 /*** qdev-properties.c ***/
220 extern PropertyInfo qdev_prop_bit
;
221 extern PropertyInfo qdev_prop_uint8
;
222 extern PropertyInfo qdev_prop_uint16
;
223 extern PropertyInfo qdev_prop_uint32
;
224 extern PropertyInfo qdev_prop_int32
;
225 extern PropertyInfo qdev_prop_uint64
;
226 extern PropertyInfo qdev_prop_hex8
;
227 extern PropertyInfo qdev_prop_hex32
;
228 extern PropertyInfo qdev_prop_hex64
;
229 extern PropertyInfo qdev_prop_string
;
230 extern PropertyInfo qdev_prop_chr
;
231 extern PropertyInfo qdev_prop_ptr
;
232 extern PropertyInfo qdev_prop_macaddr
;
233 extern PropertyInfo qdev_prop_losttickpolicy
;
234 extern PropertyInfo qdev_prop_bios_chs_trans
;
235 extern PropertyInfo qdev_prop_drive
;
236 extern PropertyInfo qdev_prop_netdev
;
237 extern PropertyInfo qdev_prop_vlan
;
238 extern PropertyInfo qdev_prop_pci_devfn
;
239 extern PropertyInfo qdev_prop_blocksize
;
240 extern PropertyInfo qdev_prop_pci_host_devaddr
;
242 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
245 .offset = offsetof(_state, _field) \
246 + type_check(_type,typeof_field(_state, _field)), \
248 #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
251 .offset = offsetof(_state, _field) \
252 + type_check(_type,typeof_field(_state, _field)), \
253 .qtype = QTYPE_QINT, \
254 .defval = (_type)_defval, \
256 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
258 .info = &(qdev_prop_bit), \
260 .offset = offsetof(_state, _field) \
261 + type_check(uint32_t,typeof_field(_state, _field)), \
262 .qtype = QTYPE_QBOOL, \
263 .defval = (bool)_defval, \
266 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
267 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
268 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
269 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
270 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
271 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
272 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
273 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
274 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
275 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
276 #define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
277 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
278 #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
279 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
280 #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
281 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
282 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
283 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, int32_t)
285 #define DEFINE_PROP_PTR(_n, _s, _f) \
286 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
287 #define DEFINE_PROP_CHR(_n, _s, _f) \
288 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
289 #define DEFINE_PROP_STRING(_n, _s, _f) \
290 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
291 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
292 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, NetClientState*)
293 #define DEFINE_PROP_VLAN(_n, _s, _f) \
294 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, NetClientState*)
295 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
296 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
297 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
298 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
299 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
300 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
302 #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
303 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
304 #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \
305 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t)
306 #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
307 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
309 #define DEFINE_PROP_END_OF_LIST() \
312 /* Set properties between creation and init. */
313 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
);
314 int qdev_prop_parse(DeviceState
*dev
, const char *name
, const char *value
);
315 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
);
316 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
);
317 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
);
318 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
);
319 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
);
320 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
);
321 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, const char *value
);
322 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
, CharDriverState
*value
);
323 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
, NetClientState
*value
);
324 int qdev_prop_set_drive(DeviceState
*dev
, const char *name
, BlockDriverState
*value
) QEMU_WARN_UNUSED_RESULT
;
325 void qdev_prop_set_drive_nofail(DeviceState
*dev
, const char *name
, BlockDriverState
*value
);
326 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
);
327 void qdev_prop_set_enum(DeviceState
*dev
, const char *name
, int value
);
328 /* FIXME: Remove opaque pointer properties. */
329 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
);
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
);
339 * @qdev_property_add_static - add a @Property to a device referencing a
342 void qdev_property_add_static(DeviceState
*dev
, Property
*prop
, Error
**errp
);
347 * Initialize platform devices before machine init. This is a hack until full
348 * support for composition is added.
350 void qdev_machine_init(void);
355 * Reset a single device (by calling the reset method).
357 void device_reset(DeviceState
*dev
);
359 const VMStateDescription
*qdev_get_vmsd(DeviceState
*dev
);
361 const char *qdev_fw_name(DeviceState
*dev
);
363 Object
*qdev_get_machine(void);
365 /* FIXME: make this a link<> */
366 void qdev_set_parent_bus(DeviceState
*dev
, BusState
*bus
);
368 extern int qdev_hotplug
;
370 char *qdev_get_dev_path(DeviceState
*dev
);