]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/qdev-core.h
spapr-vscsi: fix SOLNT bit in SRP_RSP
[mirror_qemu.git] / include / hw / qdev-core.h
CommitLineData
074a86fc
AL
1#ifndef QDEV_CORE_H
2#define QDEV_CORE_H
3
1de7afc9
PB
4#include "qemu/queue.h"
5#include "qemu/option.h"
6#include "qemu/typedefs.h"
14cccb61 7#include "qom/object.h"
074a86fc 8#include "hw/irq.h"
7b1b5d19 9#include "qapi/error.h"
074a86fc 10
074a86fc
AL
11enum {
12 DEV_NVECTORS_UNSPECIFIED = -1,
13};
14
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)
19
20typedef int (*qdev_initfn)(DeviceState *dev);
21typedef int (*qdev_event)(DeviceState *dev);
22typedef void (*qdev_resetfn)(DeviceState *dev);
249d4172
AF
23typedef void (*DeviceRealize)(DeviceState *dev, Error **errp);
24typedef void (*DeviceUnrealize)(DeviceState *dev, Error **errp);
074a86fc
AL
25
26struct VMStateDescription;
27
249d4172
AF
28/**
29 * DeviceClass:
30 * @props: Properties accessing state fields.
31 * @realize: Callback function invoked when the #DeviceState:realized
32 * property is changed to %true. The default invokes @init if not %NULL.
33 * @unrealize: Callback function invoked when the #DeviceState:realized
34 * property is changed to %false.
35 * @init: Callback function invoked when the #DeviceState::realized property
36 * is changed to %true. Deprecated, new types inheriting directly from
37 * TYPE_DEVICE should use @realize instead, new leaf types should consult
38 * their respective parent type.
39 *
40 * # Realization #
41 * Devices are constructed in two stages,
42 * 1) object instantiation via object_initialize() and
43 * 2) device realization via #DeviceState:realized property.
44 * The former may not fail (it might assert or exit), the latter may return
45 * error information to the caller and must be re-entrant.
46 * Trivial field initializations should go into #TypeInfo.instance_init.
47 * Operations depending on @props static properties should go into @realize.
48 * After successful realization, setting static properties will fail.
49 *
50 * As an interim step, the #DeviceState:realized property is set by deprecated
51 * functions qdev_init() and qdev_init_nofail().
52 * In the future, devices will propagate this state change to their children
53 * and along busses they expose.
54 * The point in time will be deferred to machine creation, so that values
55 * set in @realize will not be introspectable beforehand. Therefore devices
56 * must not create children during @realize; they should initialize them via
57 * object_initialize() in their own #TypeInfo.instance_init and forward the
58 * realization events appropriately.
59 *
60 * The @init callback is considered private to a particular bus implementation
61 * (immediate abstract child types of TYPE_DEVICE). Derived leaf types set an
62 * "init" callback on their parent class instead.
782beb52 63 *
249d4172 64 * Any type may override the @realize and/or @unrealize callbacks but needs
782beb52
AF
65 * to call the parent type's implementation if keeping their functionality
66 * is desired. Refer to QOM documentation for further discussion and examples.
67 *
68 * <note>
69 * <para>
249d4172
AF
70 * If a type derived directly from TYPE_DEVICE implements @realize, it does
71 * not need to implement @init and therefore does not need to store and call
72 * #DeviceClass' default @realize callback.
782beb52
AF
73 * For other types consult the documentation and implementation of the
74 * respective parent types.
75 * </para>
76 * </note>
249d4172 77 */
074a86fc 78typedef struct DeviceClass {
249d4172 79 /*< private >*/
074a86fc 80 ObjectClass parent_class;
249d4172 81 /*< public >*/
074a86fc
AL
82
83 const char *fw_name;
84 const char *desc;
85 Property *props;
86 int no_user;
87
88 /* callbacks */
89 void (*reset)(DeviceState *dev);
249d4172
AF
90 DeviceRealize realize;
91 DeviceUnrealize unrealize;
074a86fc
AL
92
93 /* device state */
94 const struct VMStateDescription *vmsd;
95
96 /* Private to qdev / bus. */
249d4172 97 qdev_initfn init; /* TODO remove, once users are converted to realize */
074a86fc 98 qdev_event unplug;
fe6c2117 99 qdev_event exit; /* TODO remove, once users are converted to unrealize */
074a86fc
AL
100 const char *bus_type;
101} DeviceClass;
102
7983c8a3
AF
103/**
104 * DeviceState:
105 * @realized: Indicates whether the device has been fully constructed.
106 *
107 * This structure should not be accessed directly. We declare it here
108 * so that it can be embedded in individual device state structures.
109 */
074a86fc 110struct DeviceState {
7983c8a3 111 /*< private >*/
074a86fc 112 Object parent_obj;
7983c8a3 113 /*< public >*/
074a86fc
AL
114
115 const char *id;
7983c8a3 116 bool realized;
074a86fc
AL
117 QemuOpts *opts;
118 int hotplugged;
119 BusState *parent_bus;
120 int num_gpio_out;
121 qemu_irq *gpio_out;
122 int num_gpio_in;
123 qemu_irq *gpio_in;
124 QLIST_HEAD(, BusState) child_bus;
125 int num_child_bus;
126 int instance_id_alias;
127 int alias_required_for_version;
128};
129
130#define TYPE_BUS "bus"
131#define BUS(obj) OBJECT_CHECK(BusState, (obj), TYPE_BUS)
132#define BUS_CLASS(klass) OBJECT_CLASS_CHECK(BusClass, (klass), TYPE_BUS)
133#define BUS_GET_CLASS(obj) OBJECT_GET_CLASS(BusClass, (obj), TYPE_BUS)
134
135struct BusClass {
136 ObjectClass parent_class;
137
138 /* FIXME first arg should be BusState */
139 void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
140 char *(*get_dev_path)(DeviceState *dev);
141 /*
142 * This callback is used to create Open Firmware device path in accordance
143 * with OF spec http://forthworks.com/standards/of1275.pdf. Individual bus
144 * bindings can be found at http://playground.sun.com/1275/bindings/.
145 */
146 char *(*get_fw_dev_path)(DeviceState *dev);
147 int (*reset)(BusState *bus);
1395af6f
FK
148 /* maximum devices allowed on the bus, 0: no limit. */
149 int max_dev;
074a86fc
AL
150};
151
152typedef struct BusChild {
153 DeviceState *child;
154 int index;
155 QTAILQ_ENTRY(BusChild) sibling;
156} BusChild;
157
158/**
159 * BusState:
074a86fc
AL
160 */
161struct BusState {
162 Object obj;
163 DeviceState *parent;
164 const char *name;
165 int allow_hotplug;
074a86fc
AL
166 int max_index;
167 QTAILQ_HEAD(ChildrenHead, BusChild) children;
168 QLIST_ENTRY(BusState) sibling;
169};
170
171struct Property {
172 const char *name;
173 PropertyInfo *info;
174 int offset;
175 uint8_t bitnr;
176 uint8_t qtype;
177 int64_t defval;
0be6bfac
PM
178 int arrayoffset;
179 PropertyInfo *arrayinfo;
180 int arrayfieldsize;
074a86fc
AL
181};
182
183struct PropertyInfo {
184 const char *name;
185 const char *legacy_name;
186 const char **enum_table;
187 int (*parse)(DeviceState *dev, Property *prop, const char *str);
188 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
189 ObjectPropertyAccessor *get;
190 ObjectPropertyAccessor *set;
191 ObjectPropertyRelease *release;
192};
193
194typedef struct GlobalProperty {
195 const char *driver;
196 const char *property;
197 const char *value;
198 QTAILQ_ENTRY(GlobalProperty) next;
199} GlobalProperty;
200
201/*** Board API. This should go away once we have a machine config file. ***/
202
203DeviceState *qdev_create(BusState *bus, const char *name);
204DeviceState *qdev_try_create(BusState *bus, const char *name);
205int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
206void qdev_init_nofail(DeviceState *dev);
207void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
208 int required_for_version);
209void qdev_unplug(DeviceState *dev, Error **errp);
210void qdev_free(DeviceState *dev);
211int qdev_simple_unplug_cb(DeviceState *dev);
212void qdev_machine_creation_done(void);
213bool qdev_machine_modified(void);
214
215qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
216void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
217
218BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
219
220/*** Device API. ***/
221
222/* Register device properties. */
223/* GPIO inputs also double as IRQ sinks. */
224void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
225void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
226
227BusState *qdev_get_parent_bus(DeviceState *dev);
228
229/*** BUS API. ***/
230
231DeviceState *qdev_find_recursive(BusState *bus, const char *id);
232
233/* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
234typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
235typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
236
39355c38 237void qbus_create_inplace(void *bus, const char *typename,
074a86fc
AL
238 DeviceState *parent, const char *name);
239BusState *qbus_create(const char *typename, DeviceState *parent, const char *name);
240/* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
241 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
242 * 0 otherwise. */
243int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
244 qbus_walkerfn *busfn, void *opaque);
245int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
246 qbus_walkerfn *busfn, void *opaque);
247void qdev_reset_all(DeviceState *dev);
d0508c36
PB
248
249/**
250 * @qbus_reset_all:
251 * @bus: Bus to be reset.
252 *
253 * Reset @bus and perform a bus-level ("hard") reset of all devices connected
254 * to it, including recursive processing of all buses below @bus itself. A
255 * hard reset means that qbus_reset_all will reset all state of the device.
256 * For PCI devices, for example, this will include the base address registers
257 * or configuration space.
258 */
259void qbus_reset_all(BusState *bus);
074a86fc
AL
260void qbus_reset_all_fn(void *opaque);
261
262void qbus_free(BusState *bus);
263
074a86fc
AL
264/* This should go away once we get rid of the NULL bus hack */
265BusState *sysbus_get_default(void);
266
267char *qdev_get_fw_dev_path(DeviceState *dev);
268
269/**
270 * @qdev_machine_init
271 *
272 * Initialize platform devices before machine init. This is a hack until full
273 * support for composition is added.
274 */
275void qdev_machine_init(void);
276
277/**
278 * @device_reset
279 *
280 * Reset a single device (by calling the reset method).
281 */
282void device_reset(DeviceState *dev);
283
284const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
285
286const char *qdev_fw_name(DeviceState *dev);
287
288Object *qdev_get_machine(void);
289
290/* FIXME: make this a link<> */
291void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
292
293extern int qdev_hotplug;
294
295char *qdev_get_dev_path(DeviceState *dev);
296
297#endif