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