root / hw / qdev.h @ 636aa70a
History | View | Annotate | Download (4.5 kB)
1 | aae9460e | Paul Brook | #ifndef QDEV_H
|
---|---|---|---|
2 | aae9460e | Paul Brook | #define QDEV_H
|
3 | aae9460e | Paul Brook | |
4 | aae9460e | Paul Brook | #include "hw.h" |
5 | 02e2da45 | Paul Brook | #include "sys-queue.h" |
6 | aae9460e | Paul Brook | |
7 | ee6847d1 | Gerd Hoffmann | typedef struct Property Property; |
8 | ee6847d1 | Gerd Hoffmann | |
9 | ee6847d1 | Gerd Hoffmann | typedef struct PropertyInfo PropertyInfo; |
10 | aae9460e | Paul Brook | |
11 | b6b61144 | Gerd Hoffmann | typedef struct CompatProperty CompatProperty; |
12 | b6b61144 | Gerd Hoffmann | |
13 | ee6847d1 | Gerd Hoffmann | typedef struct DeviceInfo DeviceInfo; |
14 | aae9460e | Paul Brook | |
15 | 02e2da45 | Paul Brook | typedef struct BusState BusState; |
16 | 4d6ae674 | Paul Brook | |
17 | 10c4c98a | Gerd Hoffmann | typedef struct BusInfo BusInfo; |
18 | 10c4c98a | Gerd Hoffmann | |
19 | aae9460e | Paul Brook | /* This structure should not be accessed directly. We declare it here
|
20 | aae9460e | Paul Brook | so that it can be embedded in individual device state structures. */
|
21 | 02e2da45 | Paul Brook | struct DeviceState {
|
22 | ccb63de3 | Gerd Hoffmann | char *id;
|
23 | 042f84d0 | Gerd Hoffmann | DeviceInfo *info; |
24 | 02e2da45 | Paul Brook | BusState *parent_bus; |
25 | aae9460e | Paul Brook | int num_gpio_out;
|
26 | aae9460e | Paul Brook | qemu_irq *gpio_out; |
27 | aae9460e | Paul Brook | int num_gpio_in;
|
28 | aae9460e | Paul Brook | qemu_irq *gpio_in; |
29 | 02e2da45 | Paul Brook | LIST_HEAD(, BusState) child_bus; |
30 | 9d07d757 | Paul Brook | NICInfo *nd; |
31 | 02e2da45 | Paul Brook | LIST_ENTRY(DeviceState) sibling; |
32 | 02e2da45 | Paul Brook | }; |
33 | 02e2da45 | Paul Brook | |
34 | 10c4c98a | Gerd Hoffmann | typedef void (*bus_dev_printfn)(Monitor *mon, DeviceState *dev, int indent); |
35 | 10c4c98a | Gerd Hoffmann | struct BusInfo {
|
36 | 10c4c98a | Gerd Hoffmann | const char *name; |
37 | 10c4c98a | Gerd Hoffmann | size_t size; |
38 | 10c4c98a | Gerd Hoffmann | bus_dev_printfn print_dev; |
39 | ee6847d1 | Gerd Hoffmann | Property *props; |
40 | 10c4c98a | Gerd Hoffmann | }; |
41 | 02e2da45 | Paul Brook | |
42 | 02e2da45 | Paul Brook | struct BusState {
|
43 | 02e2da45 | Paul Brook | DeviceState *parent; |
44 | 10c4c98a | Gerd Hoffmann | BusInfo *info; |
45 | 02e2da45 | Paul Brook | const char *name; |
46 | 02e2da45 | Paul Brook | LIST_HEAD(, DeviceState) children; |
47 | 02e2da45 | Paul Brook | LIST_ENTRY(BusState) sibling; |
48 | aae9460e | Paul Brook | }; |
49 | aae9460e | Paul Brook | |
50 | ee6847d1 | Gerd Hoffmann | struct Property {
|
51 | ee6847d1 | Gerd Hoffmann | const char *name; |
52 | ee6847d1 | Gerd Hoffmann | PropertyInfo *info; |
53 | ee6847d1 | Gerd Hoffmann | int offset;
|
54 | ee6847d1 | Gerd Hoffmann | void *defval;
|
55 | ee6847d1 | Gerd Hoffmann | }; |
56 | ee6847d1 | Gerd Hoffmann | |
57 | ee6847d1 | Gerd Hoffmann | enum PropertyType {
|
58 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_UNSPEC = 0,
|
59 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_UINT16, |
60 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_UINT32, |
61 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_TADDR, |
62 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_MACADDR, |
63 | ee6847d1 | Gerd Hoffmann | PROP_TYPE_PTR, |
64 | ee6847d1 | Gerd Hoffmann | }; |
65 | ee6847d1 | Gerd Hoffmann | |
66 | ee6847d1 | Gerd Hoffmann | struct PropertyInfo {
|
67 | ee6847d1 | Gerd Hoffmann | const char *name; |
68 | ee6847d1 | Gerd Hoffmann | size_t size; |
69 | ee6847d1 | Gerd Hoffmann | enum PropertyType type;
|
70 | ee6847d1 | Gerd Hoffmann | int (*parse)(DeviceState *dev, Property *prop, const char *str); |
71 | ee6847d1 | Gerd Hoffmann | int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); |
72 | ee6847d1 | Gerd Hoffmann | }; |
73 | ee6847d1 | Gerd Hoffmann | |
74 | b6b61144 | Gerd Hoffmann | struct CompatProperty {
|
75 | b6b61144 | Gerd Hoffmann | const char *driver; |
76 | b6b61144 | Gerd Hoffmann | const char *property; |
77 | b6b61144 | Gerd Hoffmann | const char *value; |
78 | b6b61144 | Gerd Hoffmann | }; |
79 | b6b61144 | Gerd Hoffmann | |
80 | aae9460e | Paul Brook | /*** Board API. This should go away once we have a machine config file. ***/
|
81 | aae9460e | Paul Brook | |
82 | 02e2da45 | Paul Brook | DeviceState *qdev_create(BusState *bus, const char *name); |
83 | aae9460e | Paul Brook | void qdev_init(DeviceState *dev);
|
84 | 02e2da45 | Paul Brook | void qdev_free(DeviceState *dev);
|
85 | aae9460e | Paul Brook | |
86 | aae9460e | Paul Brook | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n);
|
87 | aae9460e | Paul Brook | void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin); |
88 | aae9460e | Paul Brook | |
89 | 02e2da45 | Paul Brook | BusState *qdev_get_child_bus(DeviceState *dev, const char *name); |
90 | 4d6ae674 | Paul Brook | |
91 | aae9460e | Paul Brook | /*** Device API. ***/
|
92 | aae9460e | Paul Brook | |
93 | 02e2da45 | Paul Brook | typedef void (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); |
94 | 6f68ecb2 | Paul Brook | typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, |
95 | 6f68ecb2 | Paul Brook | int unit);
|
96 | aae9460e | Paul Brook | |
97 | 02e2da45 | Paul Brook | struct DeviceInfo {
|
98 | 074f2fff | Gerd Hoffmann | const char *name; |
99 | 3320e56e | Gerd Hoffmann | const char *alias; |
100 | 3320e56e | Gerd Hoffmann | const char *desc; |
101 | 074f2fff | Gerd Hoffmann | size_t size; |
102 | ee6847d1 | Gerd Hoffmann | Property *props; |
103 | 3320e56e | Gerd Hoffmann | int no_user;
|
104 | 074f2fff | Gerd Hoffmann | |
105 | 074f2fff | Gerd Hoffmann | /* Private to qdev / bus. */
|
106 | 02e2da45 | Paul Brook | qdev_initfn init; |
107 | 10c4c98a | Gerd Hoffmann | BusInfo *bus_info; |
108 | 042f84d0 | Gerd Hoffmann | struct DeviceInfo *next;
|
109 | 02e2da45 | Paul Brook | }; |
110 | 02e2da45 | Paul Brook | |
111 | 074f2fff | Gerd Hoffmann | void qdev_register(DeviceInfo *info);
|
112 | aae9460e | Paul Brook | |
113 | aae9460e | Paul Brook | /* Register device properties. */
|
114 | 067a3ddc | Paul Brook | /* GPIO inputs also double as IRQ sinks. */
|
115 | aae9460e | Paul Brook | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); |
116 | aae9460e | Paul Brook | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); |
117 | aae9460e | Paul Brook | |
118 | 6f68ecb2 | Paul Brook | void scsi_bus_new(DeviceState *host, SCSIAttachFn attach);
|
119 | 6f68ecb2 | Paul Brook | |
120 | aae9460e | Paul Brook | CharDriverState *qdev_init_chardev(DeviceState *dev); |
121 | aae9460e | Paul Brook | |
122 | 02e2da45 | Paul Brook | BusState *qdev_get_parent_bus(DeviceState *dev); |
123 | aae9460e | Paul Brook | |
124 | aae9460e | Paul Brook | /* Convery from a base type to a parent type, with compile time checking. */
|
125 | aae9460e | Paul Brook | #ifdef __GNUC__
|
126 | aae9460e | Paul Brook | #define DO_UPCAST(type, field, dev) ( __extension__ ( { \
|
127 | aae9460e | Paul Brook | char __attribute__((unused)) offset_must_be_zero[ \
|
128 | aae9460e | Paul Brook | -offsetof(type, field)]; \ |
129 | aae9460e | Paul Brook | container_of(dev, type, field);})) |
130 | aae9460e | Paul Brook | #else
|
131 | aae9460e | Paul Brook | #define DO_UPCAST(type, field, dev) container_of(dev, type, field)
|
132 | aae9460e | Paul Brook | #endif
|
133 | aae9460e | Paul Brook | |
134 | 02e2da45 | Paul Brook | /*** BUS API. ***/
|
135 | 02e2da45 | Paul Brook | |
136 | 10c4c98a | Gerd Hoffmann | BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name); |
137 | 02e2da45 | Paul Brook | |
138 | 02e2da45 | Paul Brook | #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
|
139 | 02e2da45 | Paul Brook | |
140 | cae4956e | Gerd Hoffmann | /*** monitor commands ***/
|
141 | cae4956e | Gerd Hoffmann | |
142 | cae4956e | Gerd Hoffmann | void do_info_qtree(Monitor *mon);
|
143 | cae4956e | Gerd Hoffmann | |
144 | ee6847d1 | Gerd Hoffmann | /*** qdev-properties.c ***/
|
145 | ee6847d1 | Gerd Hoffmann | |
146 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_uint16;
|
147 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_uint32;
|
148 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_hex32;
|
149 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_ptr;
|
150 | ee6847d1 | Gerd Hoffmann | extern PropertyInfo qdev_prop_macaddr;
|
151 | ee6847d1 | Gerd Hoffmann | |
152 | ee6847d1 | Gerd Hoffmann | /* Set properties between creation and init. */
|
153 | ee6847d1 | Gerd Hoffmann | void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
|
154 | ee6847d1 | Gerd Hoffmann | int qdev_prop_parse(DeviceState *dev, const char *name, const char *value); |
155 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set(DeviceState *dev, const char *name, void *src, enum PropertyType type); |
156 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value); |
157 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); |
158 | ee6847d1 | Gerd Hoffmann | /* FIXME: Remove opaque pointer properties. */
|
159 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); |
160 | ee6847d1 | Gerd Hoffmann | void qdev_prop_set_defaults(DeviceState *dev, Property *props);
|
161 | ee6847d1 | Gerd Hoffmann | |
162 | b6b61144 | Gerd Hoffmann | void qdev_prop_register_compat(CompatProperty *props);
|
163 | b6b61144 | Gerd Hoffmann | void qdev_prop_set_compat(DeviceState *dev);
|
164 | b6b61144 | Gerd Hoffmann | |
165 | a9ff9df1 | Blue Swirl | /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
|
166 | a9ff9df1 | Blue Swirl | extern struct BusInfo system_bus_info; |
167 | a9ff9df1 | Blue Swirl | |
168 | aae9460e | Paul Brook | #endif |