qcow2: Bring synchronous read/write back to life
[qemu-kvm/fedora.git] / hw / qdev.h
blob59ac8dc512b9ec841b43f460b4832b259eaec623
1 #ifndef QDEV_H
2 #define QDEV_H
4 #include "hw.h"
5 #include "sys-queue.h"
7 typedef struct Property Property;
9 typedef struct PropertyInfo PropertyInfo;
11 typedef struct CompatProperty CompatProperty;
13 typedef struct DeviceInfo DeviceInfo;
15 typedef struct BusState BusState;
17 typedef struct BusInfo BusInfo;
19 /* This structure should not be accessed directly. We declare it here
20 so that it can be embedded in individual device state structures. */
21 struct DeviceState {
22 char *id;
23 DeviceInfo *info;
24 BusState *parent_bus;
25 int num_gpio_out;
26 qemu_irq *gpio_out;
27 int num_gpio_in;
28 qemu_irq *gpio_in;
29 LIST_HEAD(, BusState) child_bus;
30 NICInfo *nd;
31 LIST_ENTRY(DeviceState) sibling;
34 typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent);
35 struct BusInfo {
36 const char *name;
37 size_t size;
38 bus_dev_printfn print_dev;
39 Property *props;
42 struct BusState {
43 DeviceState *parent;
44 BusInfo *info;
45 const char *name;
46 LIST_HEAD(, DeviceState) children;
47 LIST_ENTRY(BusState) sibling;
50 struct Property {
51 const char *name;
52 PropertyInfo *info;
53 int offset;
54 void *defval;
57 enum PropertyType {
58 PROP_TYPE_UNSPEC = 0,
59 PROP_TYPE_UINT16,
60 PROP_TYPE_UINT32,
61 PROP_TYPE_TADDR,
62 PROP_TYPE_MACADDR,
63 PROP_TYPE_PTR,
66 struct PropertyInfo {
67 const char *name;
68 size_t size;
69 enum PropertyType type;
70 int (*parse)(DeviceState *dev, Property *prop, const char *str);
71 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
74 struct CompatProperty {
75 const char *driver;
76 const char *property;
77 const char *value;
80 /*** Board API. This should go away once we have a machine config file. ***/
82 DeviceState *qdev_create(BusState *bus, const char *name);
83 void qdev_init(DeviceState *dev);
84 void qdev_free(DeviceState *dev);
86 qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
87 void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
89 BusState *qdev_get_child_bus(DeviceState *dev, const char *name);
91 /*** Device API. ***/
93 typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
94 typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,
95 int unit);
97 struct DeviceInfo {
98 const char *name;
99 const char *alias;
100 const char *desc;
101 size_t size;
102 Property *props;
103 int no_user;
105 /* Private to qdev / bus. */
106 qdev_initfn init;
107 BusInfo *bus_info;
108 struct DeviceInfo *next;
111 void qdev_register(DeviceInfo *info);
113 /* Register device properties. */
114 /* GPIO inputs also double as IRQ sinks. */
115 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n);
116 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n);
118 void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
120 CharDriverState *qdev_init_chardev(DeviceState *dev);
122 BusState *qdev_get_parent_bus(DeviceState *dev);
124 /* Convery from a base type to a parent type, with compile time checking. */
125 #ifdef __GNUC__
126 #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
127 char __attribute__((unused)) offset_must_be_zero[ \
128 -offsetof(type, field)]; \
129 container_of(dev, type, field);}))
130 #else
131 #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
132 #endif
134 /*** BUS API. ***/
136 BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name);
138 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
140 /*** monitor commands ***/
142 void do_info_qtree(Monitor *mon);
144 /*** qdev-properties.c ***/
146 extern PropertyInfo qdev_prop_uint16;
147 extern PropertyInfo qdev_prop_uint32;
148 extern PropertyInfo qdev_prop_hex32;
149 extern PropertyInfo qdev_prop_ptr;
150 extern PropertyInfo qdev_prop_macaddr;
152 /* Set properties between creation and init. */
153 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
154 int qdev_prop_parse(DeviceState *dev, const char *name, const char *value);
155 void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type);
156 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
157 void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
158 /* FIXME: Remove opaque pointer properties. */
159 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
160 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
162 void qdev_prop_register_compat(CompatProperty *props);
163 void qdev_prop_set_compat(DeviceState *dev);
165 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
166 extern struct BusInfo system_bus_info;
168 #endif