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