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_NVECTORS_UNSPECIFIED
= -1,
15 #define TYPE_DEVICE "device"
16 #define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
17 #define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
18 #define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
20 typedef int (*qdev_initfn
)(DeviceState
*dev
);
21 typedef int (*qdev_event
)(DeviceState
*dev
);
22 typedef void (*qdev_resetfn
)(DeviceState
*dev
);
24 struct VMStateDescription
;
26 typedef struct DeviceClass
{
27 ObjectClass parent_class
;
35 void (*reset
)(DeviceState
*dev
);
38 const struct VMStateDescription
*vmsd
;
40 /* Private to qdev / bus. */
49 * @realized: Indicates whether the device has been fully constructed.
51 * This structure should not be accessed directly. We declare it here
52 * so that it can be embedded in individual device state structures.
68 QLIST_HEAD(, BusState
) child_bus
;
70 int instance_id_alias
;
71 int alias_required_for_version
;
74 #define TYPE_BUS "bus"
75 #define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
76 #define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
77 #define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
80 ObjectClass parent_class
;
82 /* FIXME first arg should be BusState */
83 void (*print_dev
)(Monitor
*mon
, DeviceState
*dev
, int indent
);
84 char *(*get_dev_path
)(DeviceState
*dev
);
86 * This callback is used to create Open Firmware device path in accordance
87 * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus
88 * bindings can be found at http://playground.sun.com/1275/bindings/.
90 char *(*get_fw_dev_path
)(DeviceState
*dev
);
91 int (*reset
)(BusState
*bus
);
94 typedef struct BusChild
{
97 QTAILQ_ENTRY(BusChild
) sibling
;
109 QTAILQ_HEAD(ChildrenHead
, BusChild
) children
;
110 QLIST_ENTRY(BusState
) sibling
;
122 struct PropertyInfo
{
124 const char *legacy_name
;
125 const char **enum_table
;
126 int (*parse
)(DeviceState
*dev
, Property
*prop
, const char *str
);
127 int (*print
)(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
);
128 ObjectPropertyAccessor
*get
;
129 ObjectPropertyAccessor
*set
;
130 ObjectPropertyRelease
*release
;
133 typedef struct GlobalProperty
{
135 const char *property
;
137 QTAILQ_ENTRY(GlobalProperty
) next
;
140 /*** Board API. This should go away once we have a machine config file. ***/
142 DeviceState
*qdev_create(BusState
*bus
, const char *name
);
143 DeviceState
*qdev_try_create(BusState
*bus
, const char *name
);
144 int qdev_init(DeviceState
*dev
) QEMU_WARN_UNUSED_RESULT
;
145 void qdev_init_nofail(DeviceState
*dev
);
146 void qdev_set_legacy_instance_id(DeviceState
*dev
, int alias_id
,
147 int required_for_version
);
148 void qdev_unplug(DeviceState
*dev
, Error
**errp
);
149 void qdev_free(DeviceState
*dev
);
150 int qdev_simple_unplug_cb(DeviceState
*dev
);
151 void qdev_machine_creation_done(void);
152 bool qdev_machine_modified(void);
154 qemu_irq
qdev_get_gpio_in(DeviceState
*dev
, int n
);
155 void qdev_connect_gpio_out(DeviceState
*dev
, int n
, qemu_irq pin
);
157 BusState
*qdev_get_child_bus(DeviceState
*dev
, const char *name
);
159 /*** Device API. ***/
161 /* Register device properties. */
162 /* GPIO inputs also double as IRQ sinks. */
163 void qdev_init_gpio_in(DeviceState
*dev
, qemu_irq_handler handler
, int n
);
164 void qdev_init_gpio_out(DeviceState
*dev
, qemu_irq
*pins
, int n
);
166 BusState
*qdev_get_parent_bus(DeviceState
*dev
);
170 DeviceState
*qdev_find_recursive(BusState
*bus
, const char *id
);
172 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
173 typedef int (qbus_walkerfn
)(BusState
*bus
, void *opaque
);
174 typedef int (qdev_walkerfn
)(DeviceState
*dev
, void *opaque
);
176 void qbus_create_inplace(BusState
*bus
, const char *typename
,
177 DeviceState
*parent
, const char *name
);
178 BusState
*qbus_create(const char *typename
, DeviceState
*parent
, const char *name
);
179 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
180 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
182 int qbus_walk_children(BusState
*bus
, qdev_walkerfn
*devfn
,
183 qbus_walkerfn
*busfn
, void *opaque
);
184 int qdev_walk_children(DeviceState
*dev
, qdev_walkerfn
*devfn
,
185 qbus_walkerfn
*busfn
, void *opaque
);
186 void qdev_reset_all(DeviceState
*dev
);
190 * @bus: Bus to be reset.
192 * Reset @bus and perform a bus-level ("hard") reset of all devices connected
193 * to it, including recursive processing of all buses below @bus itself. A
194 * hard reset means that qbus_reset_all will reset all state of the device.
195 * For PCI devices, for example, this will include the base address registers
196 * or configuration space.
198 void qbus_reset_all(BusState
*bus
);
199 void qbus_reset_all_fn(void *opaque
);
201 void qbus_free(BusState
*bus
);
203 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
205 /* This should go away once we get rid of the NULL bus hack */
206 BusState
*sysbus_get_default(void);
208 char *qdev_get_fw_dev_path(DeviceState
*dev
);
213 * Initialize platform devices before machine init. This is a hack until full
214 * support for composition is added.
216 void qdev_machine_init(void);
221 * Reset a single device (by calling the reset method).
223 void device_reset(DeviceState
*dev
);
225 const struct VMStateDescription
*qdev_get_vmsd(DeviceState
*dev
);
227 const char *qdev_fw_name(DeviceState
*dev
);
229 Object
*qdev_get_machine(void);
231 /* FIXME: make this a link<> */
232 void qdev_set_parent_bus(DeviceState
*dev
, BusState
*bus
);
234 extern int qdev_hotplug
;
236 char *qdev_get_dev_path(DeviceState
*dev
);