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