]> git.proxmox.com Git - mirror_qemu.git/blame - hw/qdev-core.h
qom: move include files to include/qom/
[mirror_qemu.git] / hw / qdev-core.h
CommitLineData
074a86fc
AL
1#ifndef QDEV_CORE_H
2#define QDEV_CORE_H
3
4#include "qemu-queue.h"
5#include "qemu-option.h"
394e1bb7 6#include "qemu-types.h"
14cccb61 7#include "qom/object.h"
074a86fc 8#include "hw/irq.h"
7b1b5d19 9#include "qapi/error.h"
074a86fc 10
074a86fc
AL
11enum DevState {
12 DEV_STATE_CREATED = 1,
13 DEV_STATE_INITIALIZED,
14};
15
16enum {
17 DEV_NVECTORS_UNSPECIFIED = -1,
18};
19
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)
24
25typedef int (*qdev_initfn)(DeviceState *dev);
26typedef int (*qdev_event)(DeviceState *dev);
27typedef void (*qdev_resetfn)(DeviceState *dev);
28
29struct VMStateDescription;
30
31typedef struct DeviceClass {
32 ObjectClass parent_class;
33
34 const char *fw_name;
35 const char *desc;
36 Property *props;
37 int no_user;
38
39 /* callbacks */
40 void (*reset)(DeviceState *dev);
41
42 /* device state */
43 const struct VMStateDescription *vmsd;
44
45 /* Private to qdev / bus. */
46 qdev_initfn init;
47 qdev_event unplug;
48 qdev_event exit;
49 const char *bus_type;
50} DeviceClass;
51
52/* This structure should not be accessed directly. We declare it here
53 so that it can be embedded in individual device state structures. */
54struct DeviceState {
55 Object parent_obj;
56
57 const char *id;
58 enum DevState state;
59 QemuOpts *opts;
60 int hotplugged;
61 BusState *parent_bus;
62 int num_gpio_out;
63 qemu_irq *gpio_out;
64 int num_gpio_in;
65 qemu_irq *gpio_in;
66 QLIST_HEAD(, BusState) child_bus;
67 int num_child_bus;
68 int instance_id_alias;
69 int alias_required_for_version;
70};
71
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)
76
77struct BusClass {
78 ObjectClass parent_class;
79
80 /* FIXME first arg should be BusState */
81 void (*print_dev)(Monitor *mon, DeviceState *dev, int indent);
82 char *(*get_dev_path)(DeviceState *dev);
83 /*
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/.
87 */
88 char *(*get_fw_dev_path)(DeviceState *dev);
89 int (*reset)(BusState *bus);
90};
91
92typedef struct BusChild {
93 DeviceState *child;
94 int index;
95 QTAILQ_ENTRY(BusChild) sibling;
96} BusChild;
97
98/**
99 * BusState:
074a86fc
AL
100 */
101struct BusState {
102 Object obj;
103 DeviceState *parent;
104 const char *name;
105 int allow_hotplug;
074a86fc
AL
106 int max_index;
107 QTAILQ_HEAD(ChildrenHead, BusChild) children;
108 QLIST_ENTRY(BusState) sibling;
109};
110
111struct Property {
112 const char *name;
113 PropertyInfo *info;
114 int offset;
115 uint8_t bitnr;
116 uint8_t qtype;
117 int64_t defval;
118};
119
120struct PropertyInfo {
121 const char *name;
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;
129};
130
131typedef struct GlobalProperty {
132 const char *driver;
133 const char *property;
134 const char *value;
135 QTAILQ_ENTRY(GlobalProperty) next;
136} GlobalProperty;
137
138/*** Board API. This should go away once we have a machine config file. ***/
139
140DeviceState *qdev_create(BusState *bus, const char *name);
141DeviceState *qdev_try_create(BusState *bus, const char *name);
142int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
143void qdev_init_nofail(DeviceState *dev);
144void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
145 int required_for_version);
146void qdev_unplug(DeviceState *dev, Error **errp);
147void qdev_free(DeviceState *dev);
148int qdev_simple_unplug_cb(DeviceState *dev);
149void qdev_machine_creation_done(void);
150bool qdev_machine_modified(void);
151
152qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
153void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
154
155BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
156
157/*** Device API. ***/
158
159/* Register device properties. */
160/* GPIO inputs also double as IRQ sinks. */
161void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
162void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
163
164BusState *qdev_get_parent_bus(DeviceState *dev);
165
166/*** BUS API. ***/
167
168DeviceState *qdev_find_recursive(BusState *bus, const char *id);
169
170/* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
171typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
172typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
173
174void qbus_create_inplace(BusState *bus, const char *typename,
175 DeviceState *parent, const char *name);
176BusState *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,
179 * 0 otherwise. */
180int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
181 qbus_walkerfn *busfn, void *opaque);
182int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
183 qbus_walkerfn *busfn, void *opaque);
184void qdev_reset_all(DeviceState *dev);
185void qbus_reset_all_fn(void *opaque);
186
187void qbus_free(BusState *bus);
188
189#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
190
191/* This should go away once we get rid of the NULL bus hack */
192BusState *sysbus_get_default(void);
193
194char *qdev_get_fw_dev_path(DeviceState *dev);
195
196/**
197 * @qdev_machine_init
198 *
199 * Initialize platform devices before machine init. This is a hack until full
200 * support for composition is added.
201 */
202void qdev_machine_init(void);
203
204/**
205 * @device_reset
206 *
207 * Reset a single device (by calling the reset method).
208 */
209void device_reset(DeviceState *dev);
210
211const struct VMStateDescription *qdev_get_vmsd(DeviceState *dev);
212
213const char *qdev_fw_name(DeviceState *dev);
214
215Object *qdev_get_machine(void);
216
217/* FIXME: make this a link<> */
218void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
219
220extern int qdev_hotplug;
221
222char *qdev_get_dev_path(DeviceState *dev);
223
224#endif