]> Git Repo - qemu.git/blame - hw/qdev.h
memory: change dirty getting API to take a size
[qemu.git] / hw / qdev.h
CommitLineData
aae9460e
PB
1#ifndef QDEV_H
2#define QDEV_H
3
4#include "hw.h"
72cf2d4f 5#include "qemu-queue.h"
313feaab 6#include "qemu-char.h"
f31d07d1 7#include "qemu-option.h"
44677ded 8#include "qapi/qapi-visit-core.h"
32fea402 9#include "qemu/object.h"
aae9460e 10
ee6847d1
GH
11typedef struct Property Property;
12
13typedef struct PropertyInfo PropertyInfo;
aae9460e 14
b6b61144
GH
15typedef struct CompatProperty CompatProperty;
16
02e2da45 17typedef struct BusState BusState;
4d6ae674 18
10c4c98a
GH
19typedef struct BusInfo BusInfo;
20
131ec1bd
GH
21enum DevState {
22 DEV_STATE_CREATED = 1,
23 DEV_STATE_INITIALIZED,
24};
25
75422b0d
AS
26enum {
27 DEV_NVECTORS_UNSPECIFIED = -1,
28};
29
32fea402
AL
30#define TYPE_DEVICE "device"
31#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE)
30fbb9fc
AL
32#define DEVICE_CLASS(klass) OBJECT_CLASS_CHECK(DeviceClass, (klass), TYPE_DEVICE)
33#define DEVICE_GET_CLASS(obj) OBJECT_GET_CLASS(DeviceClass, (obj), TYPE_DEVICE)
32fea402 34
d307af79 35typedef int (*qdev_initfn)(DeviceState *dev);
6e008585
AL
36typedef int (*qdev_event)(DeviceState *dev);
37typedef void (*qdev_resetfn)(DeviceState *dev);
38
32fea402
AL
39typedef struct DeviceClass {
40 ObjectClass parent_class;
6e008585
AL
41
42 const char *fw_name;
6e008585
AL
43 const char *desc;
44 Property *props;
45 int no_user;
46
47 /* callbacks */
94afdadc 48 void (*reset)(DeviceState *dev);
6e008585
AL
49
50 /* device state */
51 const VMStateDescription *vmsd;
52
53 /* Private to qdev / bus. */
54 qdev_initfn init;
55 qdev_event unplug;
56 qdev_event exit;
57 BusInfo *bus_info;
32fea402
AL
58} DeviceClass;
59
aae9460e
PB
60/* This structure should not be accessed directly. We declare it here
61 so that it can be embedded in individual device state structures. */
02e2da45 62struct DeviceState {
32fea402
AL
63 Object parent_obj;
64
f31d07d1 65 const char *id;
131ec1bd 66 enum DevState state;
ef80b466 67 QemuOpts *opts;
3418bd25 68 int hotplugged;
02e2da45 69 BusState *parent_bus;
aae9460e
PB
70 int num_gpio_out;
71 qemu_irq *gpio_out;
72 int num_gpio_in;
73 qemu_irq *gpio_in;
72cf2d4f 74 QLIST_HEAD(, BusState) child_bus;
d271de9f 75 int num_child_bus;
d8bb00d6 76 QTAILQ_ENTRY(DeviceState) sibling;
4d2ffa08
JK
77 int instance_id_alias;
78 int alias_required_for_version;
02e2da45
PB
79};
80
10c4c98a 81typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
6772b936 82typedef char *(*bus_get_dev_path)(DeviceState *dev);
21150814
GN
83/*
84 * This callback is used to create Open Firmware device path in accordance with
85 * OF spec http://forthworks.com/standards/of1275.pdf. Indicidual bus bindings
86 * can be found here http://playground.sun.com/1275/bindings/.
87 */
88typedef char *(*bus_get_fw_dev_path)(DeviceState *dev);
b4694b7c 89typedef int (qbus_resetfn)(BusState *bus);
6772b936 90
10c4c98a
GH
91struct BusInfo {
92 const char *name;
93 size_t size;
94 bus_dev_printfn print_dev;
6772b936 95 bus_get_dev_path get_dev_path;
21150814 96 bus_get_fw_dev_path get_fw_dev_path;
b4694b7c 97 qbus_resetfn *reset;
ee6847d1 98 Property *props;
10c4c98a 99};
02e2da45
PB
100
101struct BusState {
102 DeviceState *parent;
10c4c98a 103 BusInfo *info;
02e2da45 104 const char *name;
3418bd25 105 int allow_hotplug;
cd739fb6 106 int qdev_allocated;
f48a7a6e 107 QTAILQ_HEAD(ChildrenHead, DeviceState) children;
72cf2d4f 108 QLIST_ENTRY(BusState) sibling;
aae9460e
PB
109};
110
ee6847d1
GH
111struct Property {
112 const char *name;
113 PropertyInfo *info;
114 int offset;
d2364ee4 115 int bitnr;
ee6847d1
GH
116 void *defval;
117};
118
119enum PropertyType {
120 PROP_TYPE_UNSPEC = 0,
c7cc172d 121 PROP_TYPE_UINT8,
ee6847d1
GH
122 PROP_TYPE_UINT16,
123 PROP_TYPE_UINT32,
316940b0 124 PROP_TYPE_INT32,
5a053d1f 125 PROP_TYPE_UINT64,
ee6847d1
GH
126 PROP_TYPE_TADDR,
127 PROP_TYPE_MACADDR,
4e4fa398 128 PROP_TYPE_LOSTTICKPOLICY,
14b41872 129 PROP_TYPE_DRIVE,
313feaab 130 PROP_TYPE_CHR,
59419663 131 PROP_TYPE_STRING,
2ef924b4 132 PROP_TYPE_NETDEV,
851bec09 133 PROP_TYPE_VLAN,
ee6847d1 134 PROP_TYPE_PTR,
d2364ee4 135 PROP_TYPE_BIT,
ee6847d1
GH
136};
137
138struct PropertyInfo {
139 const char *name;
cafe5bdb 140 const char *legacy_name;
ee6847d1
GH
141 size_t size;
142 enum PropertyType type;
80e555c2
PB
143 int64_t min;
144 int64_t max;
ee6847d1
GH
145 int (*parse)(DeviceState *dev, Property *prop, const char *str);
146 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
d21357df 147 void (*free)(DeviceState *dev, Property *prop);
57c9fafe
AL
148 ObjectPropertyAccessor *get;
149 ObjectPropertyAccessor *set;
ee6847d1
GH
150};
151
458fb679 152typedef struct GlobalProperty {
b6b61144
GH
153 const char *driver;
154 const char *property;
155 const char *value;
458fb679
GH
156 QTAILQ_ENTRY(GlobalProperty) next;
157} GlobalProperty;
b6b61144 158
aae9460e
PB
159/*** Board API. This should go away once we have a machine config file. ***/
160
02e2da45 161DeviceState *qdev_create(BusState *bus, const char *name);
0bcdeda7 162DeviceState *qdev_try_create(BusState *bus, const char *name);
a369da5f 163bool qdev_exists(const char *name);
ff952ba2 164int qdev_device_help(QemuOpts *opts);
f31d07d1 165DeviceState *qdev_device_add(QemuOpts *opts);
747bbdf7 166int qdev_init(DeviceState *dev) QEMU_WARN_UNUSED_RESULT;
e23a1b33 167void qdev_init_nofail(DeviceState *dev);
4d2ffa08
JK
168void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,
169 int required_for_version);
3418bd25 170int qdev_unplug(DeviceState *dev);
02e2da45 171void qdev_free(DeviceState *dev);
3418bd25
GH
172int qdev_simple_unplug_cb(DeviceState *dev);
173void qdev_machine_creation_done(void);
0ac8ef71 174bool qdev_machine_modified(void);
aae9460e 175
aae9460e
PB
176qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
177void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
178
02e2da45 179BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
4d6ae674 180
aae9460e
PB
181/*** Device API. ***/
182
aae9460e 183/* Register device properties. */
067a3ddc 184/* GPIO inputs also double as IRQ sinks. */
aae9460e
PB
185void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
186void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
187
02e2da45 188BusState *qdev_get_parent_bus(DeviceState *dev);
aae9460e 189
02e2da45
PB
190/*** BUS API. ***/
191
a2ee6b4f
IY
192DeviceState *qdev_find_recursive(BusState *bus, const char *id);
193
81699d8a
AL
194/* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
195typedef int (qbus_walkerfn)(BusState *bus, void *opaque);
196typedef int (qdev_walkerfn)(DeviceState *dev, void *opaque);
197
cd739fb6
GH
198void qbus_create_inplace(BusState *bus, BusInfo *info,
199 DeviceState *parent, const char *name);
10c4c98a 200BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
81699d8a
AL
201/* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
202 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
203 * 0 otherwise. */
204int qbus_walk_children(BusState *bus, qdev_walkerfn *devfn,
205 qbus_walkerfn *busfn, void *opaque);
206int qdev_walk_children(DeviceState *dev, qdev_walkerfn *devfn,
207 qbus_walkerfn *busfn, void *opaque);
5af0a04b 208void qdev_reset_all(DeviceState *dev);
80376c3f
IY
209void qbus_reset_all_fn(void *opaque);
210
131ec1bd 211void qbus_free(BusState *bus);
02e2da45
PB
212
213#define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
214
ec990eb6
AL
215/* This should go away once we get rid of the NULL bus hack */
216BusState *sysbus_get_default(void);
217
cae4956e
GH
218/*** monitor commands ***/
219
220void do_info_qtree(Monitor *mon);
f6c64e0e 221void do_info_qdm(Monitor *mon);
8bc27249 222int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
17a38eaa 223int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
cae4956e 224
ee6847d1
GH
225/*** qdev-properties.c ***/
226
d2364ee4 227extern PropertyInfo qdev_prop_bit;
c7cc172d 228extern PropertyInfo qdev_prop_uint8;
ee6847d1
GH
229extern PropertyInfo qdev_prop_uint16;
230extern PropertyInfo qdev_prop_uint32;
316940b0 231extern PropertyInfo qdev_prop_int32;
5a053d1f 232extern PropertyInfo qdev_prop_uint64;
6835678c 233extern PropertyInfo qdev_prop_hex8;
ee6847d1 234extern PropertyInfo qdev_prop_hex32;
5a053d1f 235extern PropertyInfo qdev_prop_hex64;
59419663 236extern PropertyInfo qdev_prop_string;
313feaab 237extern PropertyInfo qdev_prop_chr;
ee6847d1
GH
238extern PropertyInfo qdev_prop_ptr;
239extern PropertyInfo qdev_prop_macaddr;
4e4fa398 240extern PropertyInfo qdev_prop_losttickpolicy;
14b41872 241extern PropertyInfo qdev_prop_drive;
851bec09
GH
242extern PropertyInfo qdev_prop_netdev;
243extern PropertyInfo qdev_prop_vlan;
05cb5fe4 244extern PropertyInfo qdev_prop_pci_devfn;
ee6847d1 245
cf12b95b
GH
246#define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
247 .name = (_name), \
248 .info = &(_prop), \
249 .offset = offsetof(_state, _field) \
250 + type_check(_type,typeof_field(_state, _field)), \
251 }
252#define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
253 .name = (_name), \
254 .info = &(_prop), \
255 .offset = offsetof(_state, _field) \
256 + type_check(_type,typeof_field(_state, _field)), \
257 .defval = (_type[]) { _defval }, \
258 }
d2364ee4
MT
259#define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
260 .name = (_name), \
261 .info = &(qdev_prop_bit), \
262 .bitnr = (_bit), \
263 .offset = offsetof(_state, _field) \
264 + type_check(uint32_t,typeof_field(_state, _field)), \
265 .defval = (bool[]) { (_defval) }, \
266 }
cf12b95b 267
c7cc172d
JQ
268#define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
269 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
cf12b95b
GH
270#define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
271 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
272#define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
273 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
316940b0
GH
274#define DEFINE_PROP_INT32(_n, _s, _f, _d) \
275 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
cf12b95b
GH
276#define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
277 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
6835678c
JK
278#define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
279 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
cf12b95b
GH
280#define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
281 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
282#define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
283 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
284#define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
285 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
286
287#define DEFINE_PROP_PTR(_n, _s, _f) \
288 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
313feaab
GH
289#define DEFINE_PROP_CHR(_n, _s, _f) \
290 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
59419663
GH
291#define DEFINE_PROP_STRING(_n, _s, _f) \
292 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
2ef924b4
GH
293#define DEFINE_PROP_NETDEV(_n, _s, _f) \
294 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
851bec09
GH
295#define DEFINE_PROP_VLAN(_n, _s, _f) \
296 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
f8b6cc00
MA
297#define DEFINE_PROP_DRIVE(_n, _s, _f) \
298 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
cf12b95b 299#define DEFINE_PROP_MACADDR(_n, _s, _f) \
1503fff3 300 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
4e4fa398
JK
301#define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
302 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
303 LostTickPolicy)
cf12b95b
GH
304
305#define DEFINE_PROP_END_OF_LIST() \
306 {}
307
ee6847d1
GH
308/* Set properties between creation and init. */
309void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
d8ed79ae 310int qdev_prop_exists(DeviceState *dev, const char *name);
ee6847d1
GH
311int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
312void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
f4594a3b 313void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
c7cc172d 314void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
ee6847d1
GH
315void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
316void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
316940b0 317void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
5a053d1f 318void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
cc984673 319void qdev_prop_set_string(DeviceState *dev, const char *name, char *value);
313feaab 320void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
2ef924b4 321void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
851bec09 322void qdev_prop_set_vlan(DeviceState *dev, const char *name, VLANState *value);
18846dee
MA
323int qdev_prop_set_drive(DeviceState *dev, const char *name, BlockDriverState *value) QEMU_WARN_UNUSED_RESULT;
324void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name, BlockDriverState *value);
1503fff3 325void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
4e4fa398
JK
326void qdev_prop_set_losttickpolicy(DeviceState *dev, const char *name,
327 LostTickPolicy *value);
ee6847d1
GH
328/* FIXME: Remove opaque pointer properties. */
329void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
330void qdev_prop_set_defaults(DeviceState *dev, Property *props);
331
458fb679
GH
332void qdev_prop_register_global_list(GlobalProperty *props);
333void qdev_prop_set_globals(DeviceState *dev);
7db4c4e8
PB
334void error_set_from_qdev_prop_error(Error **errp, int ret, DeviceState *dev,
335 Property *prop, const char *value);
b6b61144 336
1ca4d09a 337char *qdev_get_fw_dev_path(DeviceState *dev);
4be9f0d1 338
a9ff9df1
BS
339/* This is a nasty hack to allow passing a NULL bus to qdev_create. */
340extern struct BusInfo system_bus_info;
341
a5296ca9 342/**
ca2cc788
PB
343 * @qdev_property_add_static - add a @Property to a device referencing a
344 * field in a struct.
a5296ca9 345 */
ca2cc788 346void qdev_property_add_static(DeviceState *dev, Property *prop, Error **errp);
a5296ca9 347
1de81d28
AL
348/**
349 * @qdev_machine_init
350 *
351 * Initialize platform devices before machine init. This is a hack until full
352 * support for composition is added.
353 */
354void qdev_machine_init(void);
355
94afdadc
AL
356/**
357 * @device_reset
358 *
359 * Reset a single device (by calling the reset method).
360 */
361void device_reset(DeviceState *dev);
362
4be9f0d1
AL
363const VMStateDescription *qdev_get_vmsd(DeviceState *dev);
364
365const char *qdev_fw_name(DeviceState *dev);
366
367BusInfo *qdev_get_bus_info(DeviceState *dev);
368
369Property *qdev_get_props(DeviceState *dev);
370
9fbe6127
AL
371/* FIXME: make this a link<> */
372void qdev_set_parent_bus(DeviceState *dev, BusState *bus);
373
ee46d8a5
AL
374extern int qdev_hotplug;
375
aae9460e 376#endif
This page took 0.515451 seconds and 4 git commands to generate.