5 #include "qemu-queue.h"
7 #include "qemu-option.h"
9 typedef struct Property Property
;
11 typedef struct PropertyInfo PropertyInfo
;
13 typedef struct CompatProperty CompatProperty
;
15 typedef struct DeviceInfo DeviceInfo
;
17 typedef struct BusState BusState
;
19 typedef struct BusInfo BusInfo
;
22 DEV_STATE_CREATED
= 1,
23 DEV_STATE_INITIALIZED
,
27 DEV_NVECTORS_UNSPECIFIED
= -1,
30 /* This structure should not be accessed directly. We declare it here
31 so that it can be embedded in individual device state structures. */
43 QLIST_HEAD(, BusState
) child_bus
;
45 QTAILQ_ENTRY(DeviceState
) sibling
;
46 int instance_id_alias
;
47 int alias_required_for_version
;
50 typedef void (*bus_dev_printfn
)(Monitor
*mon
, DeviceState
*dev
, int indent
);
51 typedef char *(*bus_get_dev_path
)(DeviceState
*dev
);
53 * This callback is used to create Open Firmware device path in accordance with
54 * OF spec http://forthworks.com/standards/of1275.pdf. Indicidual bus bindings
55 * can be found here http://playground.sun.com/1275/bindings/.
57 typedef char *(*bus_get_fw_dev_path
)(DeviceState
*dev
);
58 typedef int (qbus_resetfn
)(BusState
*bus
);
63 bus_dev_printfn print_dev
;
64 bus_get_dev_path get_dev_path
;
65 bus_get_fw_dev_path get_fw_dev_path
;
76 QTAILQ_HEAD(ChildrenHead
, DeviceState
) children
;
77 QLIST_ENTRY(BusState
) sibling
;
106 struct PropertyInfo
{
109 enum PropertyType type
;
110 int (*parse
)(DeviceState
*dev
, Property
*prop
, const char *str
);
111 int (*print
)(DeviceState
*dev
, Property
*prop
, char *dest
, size_t len
);
112 void (*free
)(DeviceState
*dev
, Property
*prop
);
115 typedef struct GlobalProperty
{
117 const char *property
;
119 QTAILQ_ENTRY(GlobalProperty
) next
;
122 /*** Board API. This should go away once we have a machine config file. ***/
124 DeviceState
*qdev_create(BusState
*bus
, const char *name
);
125 DeviceState
*qdev_try_create(BusState
*bus
, const char *name
);
126 int qdev_device_help(QemuOpts
*opts
);
127 DeviceState
*qdev_device_add(QemuOpts
*opts
);
128 int qdev_init(DeviceState
*dev
) QEMU_WARN_UNUSED_RESULT
;
129 void qdev_init_nofail(DeviceState
*dev
);
130 void qdev_set_legacy_instance_id(DeviceState
*dev
, int alias_id
,
131 int required_for_version
);
132 int qdev_unplug(DeviceState
*dev
);
133 void qdev_free(DeviceState
*dev
);
134 int qdev_simple_unplug_cb(DeviceState
*dev
);
135 void qdev_machine_creation_done(void);
136 bool qdev_machine_modified(void);
138 qemu_irq
qdev_get_gpio_in(DeviceState
*dev
, int n
);
139 void qdev_connect_gpio_out(DeviceState
*dev
, int n
, qemu_irq pin
);
141 BusState
*qdev_get_child_bus(DeviceState
*dev
, const char *name
);
143 /*** Device API. ***/
145 typedef int (*qdev_initfn
)(DeviceState
*dev
, DeviceInfo
*info
);
146 typedef int (*qdev_event
)(DeviceState
*dev
);
147 typedef void (*qdev_resetfn
)(DeviceState
*dev
);
162 const VMStateDescription
*vmsd
;
164 /* Private to qdev / bus. */
169 struct DeviceInfo
*next
;
171 extern DeviceInfo
*device_info_list
;
173 void qdev_register(DeviceInfo
*info
);
175 /* Register device properties. */
176 /* GPIO inputs also double as IRQ sinks. */
177 void qdev_init_gpio_in(DeviceState
*dev
, qemu_irq_handler handler
, int n
);
178 void qdev_init_gpio_out(DeviceState
*dev
, qemu_irq
*pins
, int n
);
180 CharDriverState
*qdev_init_chardev(DeviceState
*dev
);
182 BusState
*qdev_get_parent_bus(DeviceState
*dev
);
186 DeviceState
*qdev_find_recursive(BusState
*bus
, const char *id
);
188 /* Returns 0 to walk children, > 0 to skip walk, < 0 to terminate walk. */
189 typedef int (qbus_walkerfn
)(BusState
*bus
, void *opaque
);
190 typedef int (qdev_walkerfn
)(DeviceState
*dev
, void *opaque
);
192 void qbus_create_inplace(BusState
*bus
, BusInfo
*info
,
193 DeviceState
*parent
, const char *name
);
194 BusState
*qbus_create(BusInfo
*info
, DeviceState
*parent
, const char *name
);
195 /* Returns > 0 if either devfn or busfn skip walk somewhere in cursion,
196 * < 0 if either devfn or busfn terminate walk somewhere in cursion,
198 int qbus_walk_children(BusState
*bus
, qdev_walkerfn
*devfn
,
199 qbus_walkerfn
*busfn
, void *opaque
);
200 int qdev_walk_children(DeviceState
*dev
, qdev_walkerfn
*devfn
,
201 qbus_walkerfn
*busfn
, void *opaque
);
202 void qdev_reset_all(DeviceState
*dev
);
203 void qbus_reset_all_fn(void *opaque
);
205 void qbus_free(BusState
*bus
);
207 #define FROM_QBUS(type, dev) DO_UPCAST(type, qbus, dev)
209 /* This should go away once we get rid of the NULL bus hack */
210 BusState
*sysbus_get_default(void);
212 /*** monitor commands ***/
214 void do_info_qtree(Monitor
*mon
);
215 void do_info_qdm(Monitor
*mon
);
216 int do_device_add(Monitor
*mon
, const QDict
*qdict
, QObject
**ret_data
);
217 int do_device_del(Monitor
*mon
, const QDict
*qdict
, QObject
**ret_data
);
219 /*** qdev-properties.c ***/
221 extern PropertyInfo qdev_prop_bit
;
222 extern PropertyInfo qdev_prop_uint8
;
223 extern PropertyInfo qdev_prop_uint16
;
224 extern PropertyInfo qdev_prop_uint32
;
225 extern PropertyInfo qdev_prop_int32
;
226 extern PropertyInfo qdev_prop_uint64
;
227 extern PropertyInfo qdev_prop_hex8
;
228 extern PropertyInfo qdev_prop_hex32
;
229 extern PropertyInfo qdev_prop_hex64
;
230 extern PropertyInfo qdev_prop_string
;
231 extern PropertyInfo qdev_prop_chr
;
232 extern PropertyInfo qdev_prop_ptr
;
233 extern PropertyInfo qdev_prop_macaddr
;
234 extern PropertyInfo qdev_prop_drive
;
235 extern PropertyInfo qdev_prop_netdev
;
236 extern PropertyInfo qdev_prop_vlan
;
237 extern PropertyInfo qdev_prop_pci_devfn
;
239 #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
242 .offset = offsetof(_state, _field) \
243 + type_check(_type,typeof_field(_state, _field)), \
245 #define DEFINE_PROP_DEFAULT(_name, _state, _field, _defval, _prop, _type) { \
248 .offset = offsetof(_state, _field) \
249 + type_check(_type,typeof_field(_state, _field)), \
250 .defval = (_type[]) { _defval }, \
252 #define DEFINE_PROP_BIT(_name, _state, _field, _bit, _defval) { \
254 .info = &(qdev_prop_bit), \
256 .offset = offsetof(_state, _field) \
257 + type_check(uint32_t,typeof_field(_state, _field)), \
258 .defval = (bool[]) { (_defval) }, \
261 #define DEFINE_PROP_UINT8(_n, _s, _f, _d) \
262 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint8, uint8_t)
263 #define DEFINE_PROP_UINT16(_n, _s, _f, _d) \
264 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint16, uint16_t)
265 #define DEFINE_PROP_UINT32(_n, _s, _f, _d) \
266 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint32, uint32_t)
267 #define DEFINE_PROP_INT32(_n, _s, _f, _d) \
268 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_int32, int32_t)
269 #define DEFINE_PROP_UINT64(_n, _s, _f, _d) \
270 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_uint64, uint64_t)
271 #define DEFINE_PROP_HEX8(_n, _s, _f, _d) \
272 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex8, uint8_t)
273 #define DEFINE_PROP_HEX32(_n, _s, _f, _d) \
274 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex32, uint32_t)
275 #define DEFINE_PROP_HEX64(_n, _s, _f, _d) \
276 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_hex64, uint64_t)
277 #define DEFINE_PROP_PCI_DEVFN(_n, _s, _f, _d) \
278 DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_pci_devfn, uint32_t)
280 #define DEFINE_PROP_PTR(_n, _s, _f) \
281 DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
282 #define DEFINE_PROP_CHR(_n, _s, _f) \
283 DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
284 #define DEFINE_PROP_STRING(_n, _s, _f) \
285 DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
286 #define DEFINE_PROP_NETDEV(_n, _s, _f) \
287 DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
288 #define DEFINE_PROP_VLAN(_n, _s, _f) \
289 DEFINE_PROP(_n, _s, _f, qdev_prop_vlan, VLANState*)
290 #define DEFINE_PROP_DRIVE(_n, _s, _f) \
291 DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
292 #define DEFINE_PROP_MACADDR(_n, _s, _f) \
293 DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
295 #define DEFINE_PROP_END_OF_LIST() \
298 /* Set properties between creation and init. */
299 void *qdev_get_prop_ptr(DeviceState
*dev
, Property
*prop
);
300 int qdev_prop_exists(DeviceState
*dev
, const char *name
);
301 int qdev_prop_parse(DeviceState
*dev
, const char *name
, const char *value
);
302 void qdev_prop_set(DeviceState
*dev
, const char *name
, void *src
, enum PropertyType type
);
303 void qdev_prop_set_bit(DeviceState
*dev
, const char *name
, bool value
);
304 void qdev_prop_set_uint8(DeviceState
*dev
, const char *name
, uint8_t value
);
305 void qdev_prop_set_uint16(DeviceState
*dev
, const char *name
, uint16_t value
);
306 void qdev_prop_set_uint32(DeviceState
*dev
, const char *name
, uint32_t value
);
307 void qdev_prop_set_int32(DeviceState
*dev
, const char *name
, int32_t value
);
308 void qdev_prop_set_uint64(DeviceState
*dev
, const char *name
, uint64_t value
);
309 void qdev_prop_set_string(DeviceState
*dev
, const char *name
, char *value
);
310 void qdev_prop_set_chr(DeviceState
*dev
, const char *name
, CharDriverState
*value
);
311 void qdev_prop_set_netdev(DeviceState
*dev
, const char *name
, VLANClientState
*value
);
312 void qdev_prop_set_vlan(DeviceState
*dev
, const char *name
, VLANState
*value
);
313 int qdev_prop_set_drive(DeviceState
*dev
, const char *name
, BlockDriverState
*value
) QEMU_WARN_UNUSED_RESULT
;
314 void qdev_prop_set_drive_nofail(DeviceState
*dev
, const char *name
, BlockDriverState
*value
);
315 void qdev_prop_set_macaddr(DeviceState
*dev
, const char *name
, uint8_t *value
);
316 /* FIXME: Remove opaque pointer properties. */
317 void qdev_prop_set_ptr(DeviceState
*dev
, const char *name
, void *value
);
318 void qdev_prop_set_defaults(DeviceState
*dev
, Property
*props
);
320 void qdev_prop_register_global_list(GlobalProperty
*props
);
321 void qdev_prop_set_globals(DeviceState
*dev
);
323 static inline const char *qdev_fw_name(DeviceState
*dev
)
325 return dev
->info
->fw_name
? : dev
->info
->alias
? : dev
->info
->name
;
328 char *qdev_get_fw_dev_path(DeviceState
*dev
);
329 /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
330 extern struct BusInfo system_bus_info
;