4 #include "qemu/queue.h"
5 #include "qemu/option.h"
6 #include "qemu/typedefs.h"
7 #include "qom/object.h"
9 #include "qapi/error.h"
12 DEV_STATE_CREATED
= 1,
13 DEV_STATE_INITIALIZED
,
17 DEV_NVECTORS_UNSPECIFIED
= -1,
20 #define TYPE_DEVICE "device"
21 #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
22 #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
23 #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
25 typedef int (*qdev_initfn
)(DeviceState
*dev
);
26 typedef int (*qdev_event
)(DeviceState
*dev
);
27 typedef void (*qdev_resetfn
)(DeviceState
*dev
);
29 struct VMStateDescription
;
31 typedef struct DeviceClass
{
32 ObjectClass parent_class
;
40 void (*reset
)(DeviceState
*dev
);
43 const struct VMStateDescription
*vmsd
;
45 /* Private to qdev / bus. */
52 /* This structure should not be accessed directly. We declare it here
53 so that it can be embedded in individual device state structures. */
66 QLIST_HEAD(, BusState
) child_bus
;
68 int instance_id_alias
;
69 int alias_required_for_version
;
72 #define TYPE_BUS "bus"
73 #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
74 #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
75 #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
78 ObjectClass parent_class
;
80 /* FIXME first arg should be BusState */
81 void (*print_dev
)(Monitor
*mon
, DeviceState
*dev
, int indent
);
82 char *(*get_dev_path
)(DeviceState
*dev
);
84 * This callback is used to create Open Firmware device path in accordance
85 * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus
86 * bindings can be found at http://playground.sun.com/1275/bindings/.
88 char *(*get_fw_dev_path
)(DeviceState
*dev
);
89 int (*reset
)(BusState
*bus
);
92 typedef struct BusChild
{
95 QTAILQ_ENTRY(BusChild
) sibling
;
107 QTAILQ_HEAD(ChildrenHead
, BusChild
) children
;
108 QLIST_ENTRY(BusState
) sibling
;
120 struct PropertyInfo
{
122 const char *legacy_name
;
123 const char **enum_table
;
124 int (*parse
)(DeviceState
*dev
, Property
*prop
, const char *str
);
125 int (*print
)(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
);
126 ObjectPropertyAccessor
*get
;
127 ObjectPropertyAccessor
*set
;
128 ObjectPropertyRelease
*release
;
131 typedef struct GlobalProperty
{
133 const char *property
;
135 QTAILQ_ENTRY(GlobalProperty
) next
;
138 /*** Board API. This should go away once we have a machine config file. ***/
140 DeviceState
*qdev_create(BusState
*bus
, const char *name
);
141 DeviceState
*qdev_try_create(BusState
*bus
, const char *name
);
142 int qdev_init(DeviceState
*dev
) QEMU_WARN_UNUSED_RESULT
;
143 void qdev_init_nofail(DeviceState
*dev
);
144 void qdev_set_legacy_instance_id(DeviceState
*dev
, int alias_id
,
145 int required_for_version
);
146 void qdev_unplug(DeviceState
*dev
, Error
**errp
);
147 void qdev_free(DeviceState
*dev
);
148 int qdev_simple_unplug_cb(DeviceState
*dev
);
149 void qdev_machine_creation_done(void);
150 bool qdev_machine_modified(void);
152 qemu_irq
qdev_get_gpio_in(DeviceState
*dev
, int n
);
153 void qdev_connect_gpio_out(DeviceState
*dev
, int n
, qemu_irq pin
);
155 BusState
*qdev_get_child_bus(DeviceState
*dev
, const char *name
);
157 /*** Device API. ***/
159 /* Register device properties. */
160 /* GPIO inputs also double as IRQ sinks. */
161 void qdev_init_gpio_in(DeviceState
*dev
, qemu_irq_handler handler
, int n
);
162 void qdev_init_gpio_out(DeviceState
*dev
, qemu_irq
*pins
, int n
);
164 BusState
*qdev_get_parent_bus(DeviceState
*dev
);
168 DeviceState
*qdev_find_recursive(BusState
*bus
, const char *id
);
170 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
171 typedef int (qbus_walkerfn
)(BusState
*bus
, void *opaque
);
172 typedef int (qdev_walkerfn
)(DeviceState
*dev
, void *opaque
);
174 void qbus_create_inplace(BusState
*bus
, const char *typename
,
175 DeviceState
*parent
, const char *name
);
176 BusState
*qbus_create(const char *typename
, DeviceState
*parent
, const char *name
);
177 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
178 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
180 int qbus_walk_children(BusState
*bus
, qdev_walkerfn
*devfn
,
181 qbus_walkerfn
*busfn
, void *opaque
);
182 int qdev_walk_children(DeviceState
*dev
, qdev_walkerfn
*devfn
,
183 qbus_walkerfn
*busfn
, void *opaque
);
184 void qdev_reset_all(DeviceState
*dev
);
188 * @bus: Bus to be reset.
190 * Reset @bus and perform a bus-level ("hard") reset of all devices connected
191 * to it, including recursive processing of all buses below @bus itself. A
192 * hard reset means that qbus_reset_all will reset all state of the device.
193 * For PCI devices, for example, this will include the base address registers
194 * or configuration space.
196 void qbus_reset_all(BusState
*bus
);
197 void qbus_reset_all_fn(void *opaque
);
199 void qbus_free(BusState
*bus
);
201 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
203 /* This should go away once we get rid of the NULL bus hack */
204 BusState
*sysbus_get_default(void);
206 char *qdev_get_fw_dev_path(DeviceState
*dev
);
211 * Initialize platform devices before machine init. This is a hack until full
212 * support for composition is added.
214 void qdev_machine_init(void);
219 * Reset a single device (by calling the reset method).
221 void device_reset(DeviceState
*dev
);
223 const struct VMStateDescription
*qdev_get_vmsd(DeviceState
*dev
);
225 const char *qdev_fw_name(DeviceState
*dev
);
227 Object
*qdev_get_machine(void);
229 /* FIXME: make this a link<> */
230 void qdev_set_parent_bus(DeviceState
*dev
, BusState
*bus
);
232 extern int qdev_hotplug
;
234 char *qdev_get_dev_path(DeviceState
*dev
);