root / hw / qdev.c @ cda9046b
History | View | Annotate | Download (10.8 kB)
1 | aae9460e | Paul Brook | /*
|
---|---|---|---|
2 | aae9460e | Paul Brook | * Dynamic device configuration and creation.
|
3 | aae9460e | Paul Brook | *
|
4 | aae9460e | Paul Brook | * Copyright (c) 2009 CodeSourcery
|
5 | aae9460e | Paul Brook | *
|
6 | aae9460e | Paul Brook | * This library is free software; you can redistribute it and/or
|
7 | aae9460e | Paul Brook | * modify it under the terms of the GNU Lesser General Public
|
8 | aae9460e | Paul Brook | * License as published by the Free Software Foundation; either
|
9 | aae9460e | Paul Brook | * version 2 of the License, or (at your option) any later version.
|
10 | aae9460e | Paul Brook | *
|
11 | aae9460e | Paul Brook | * This library is distributed in the hope that it will be useful,
|
12 | aae9460e | Paul Brook | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | aae9460e | Paul Brook | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | aae9460e | Paul Brook | * Lesser General Public License for more details.
|
15 | aae9460e | Paul Brook | *
|
16 | aae9460e | Paul Brook | * You should have received a copy of the GNU Lesser General Public
|
17 | aae9460e | Paul Brook | * License along with this library; if not, write to the Free Software
|
18 | aae9460e | Paul Brook | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
|
19 | aae9460e | Paul Brook | */
|
20 | aae9460e | Paul Brook | |
21 | aae9460e | Paul Brook | /* The theory here is that it should be possible to create a machine without
|
22 | aae9460e | Paul Brook | knowledge of specific devices. Historically board init routines have
|
23 | aae9460e | Paul Brook | passed a bunch of arguments to each device, requiring the board know
|
24 | aae9460e | Paul Brook | exactly which device it is dealing with. This file provides an abstract
|
25 | aae9460e | Paul Brook | API for device configuration and initialization. Devices will generally
|
26 | aae9460e | Paul Brook | inherit from a particular bus (e.g. PCI or I2C) rather than
|
27 | aae9460e | Paul Brook | this API directly. */
|
28 | aae9460e | Paul Brook | |
29 | 9d07d757 | Paul Brook | #include "net.h" |
30 | aae9460e | Paul Brook | #include "qdev.h" |
31 | aae9460e | Paul Brook | #include "sysemu.h" |
32 | cae4956e | Gerd Hoffmann | #include "monitor.h" |
33 | aae9460e | Paul Brook | |
34 | aae9460e | Paul Brook | struct DeviceProperty {
|
35 | aae9460e | Paul Brook | const char *name; |
36 | 1431b6a1 | Paul Brook | DevicePropType type; |
37 | aae9460e | Paul Brook | union {
|
38 | 89a740e1 | Paul Brook | uint64_t i; |
39 | aae9460e | Paul Brook | void *ptr;
|
40 | aae9460e | Paul Brook | } value; |
41 | aae9460e | Paul Brook | DeviceProperty *next; |
42 | aae9460e | Paul Brook | }; |
43 | aae9460e | Paul Brook | |
44 | aae9460e | Paul Brook | struct DeviceType {
|
45 | aae9460e | Paul Brook | const char *name; |
46 | 02e2da45 | Paul Brook | DeviceInfo *info; |
47 | aae9460e | Paul Brook | int size;
|
48 | aae9460e | Paul Brook | DeviceType *next; |
49 | aae9460e | Paul Brook | }; |
50 | aae9460e | Paul Brook | |
51 | 02e2da45 | Paul Brook | /* This is a nasty hack to allow passing a NULL bus to qdev_create. */
|
52 | 02e2da45 | Paul Brook | BusState *main_system_bus; |
53 | 4d6ae674 | Paul Brook | |
54 | aae9460e | Paul Brook | static DeviceType *device_type_list;
|
55 | aae9460e | Paul Brook | |
56 | aae9460e | Paul Brook | /* Register a new device type. */
|
57 | 02e2da45 | Paul Brook | void qdev_register(const char *name, int size, DeviceInfo *info) |
58 | aae9460e | Paul Brook | { |
59 | aae9460e | Paul Brook | DeviceType *t; |
60 | aae9460e | Paul Brook | |
61 | aae9460e | Paul Brook | assert(size >= sizeof(DeviceState));
|
62 | aae9460e | Paul Brook | |
63 | aae9460e | Paul Brook | t = qemu_mallocz(sizeof(DeviceType));
|
64 | aae9460e | Paul Brook | t->next = device_type_list; |
65 | aae9460e | Paul Brook | device_type_list = t; |
66 | aae9460e | Paul Brook | t->name = qemu_strdup(name); |
67 | aae9460e | Paul Brook | t->size = size; |
68 | 02e2da45 | Paul Brook | t->info = info; |
69 | aae9460e | Paul Brook | } |
70 | aae9460e | Paul Brook | |
71 | aae9460e | Paul Brook | /* Create a new device. This only initializes the device state structure
|
72 | aae9460e | Paul Brook | and allows properties to be set. qdev_init should be called to
|
73 | aae9460e | Paul Brook | initialize the actual device emulation. */
|
74 | 02e2da45 | Paul Brook | DeviceState *qdev_create(BusState *bus, const char *name) |
75 | aae9460e | Paul Brook | { |
76 | aae9460e | Paul Brook | DeviceType *t; |
77 | aae9460e | Paul Brook | DeviceState *dev; |
78 | aae9460e | Paul Brook | |
79 | aae9460e | Paul Brook | for (t = device_type_list; t; t = t->next) {
|
80 | aae9460e | Paul Brook | if (strcmp(t->name, name) == 0) { |
81 | aae9460e | Paul Brook | break;
|
82 | aae9460e | Paul Brook | } |
83 | aae9460e | Paul Brook | } |
84 | aae9460e | Paul Brook | if (!t) {
|
85 | 02e2da45 | Paul Brook | hw_error("Unknown device '%s'\n", name);
|
86 | aae9460e | Paul Brook | } |
87 | aae9460e | Paul Brook | |
88 | aae9460e | Paul Brook | dev = qemu_mallocz(t->size); |
89 | aae9460e | Paul Brook | dev->type = t; |
90 | 02e2da45 | Paul Brook | |
91 | 02e2da45 | Paul Brook | if (!bus) {
|
92 | 02e2da45 | Paul Brook | /* ???: This assumes system busses have no additional state. */
|
93 | 02e2da45 | Paul Brook | if (!main_system_bus) {
|
94 | 02e2da45 | Paul Brook | main_system_bus = qbus_create(BUS_TYPE_SYSTEM, sizeof(BusState),
|
95 | 02e2da45 | Paul Brook | NULL, "main-system-bus"); |
96 | 02e2da45 | Paul Brook | } |
97 | 02e2da45 | Paul Brook | bus = main_system_bus; |
98 | 02e2da45 | Paul Brook | } |
99 | 02e2da45 | Paul Brook | if (t->info->bus_type != bus->type) {
|
100 | 02e2da45 | Paul Brook | /* TODO: Print bus type names. */
|
101 | 02e2da45 | Paul Brook | hw_error("Device '%s' on wrong bus type (%d/%d)", name,
|
102 | 02e2da45 | Paul Brook | t->info->bus_type, bus->type); |
103 | 02e2da45 | Paul Brook | } |
104 | 02e2da45 | Paul Brook | dev->parent_bus = bus; |
105 | 02e2da45 | Paul Brook | LIST_INSERT_HEAD(&bus->children, dev, sibling); |
106 | aae9460e | Paul Brook | return dev;
|
107 | aae9460e | Paul Brook | } |
108 | aae9460e | Paul Brook | |
109 | aae9460e | Paul Brook | /* Initialize a device. Device properties should be set before calling
|
110 | aae9460e | Paul Brook | this function. IRQs and MMIO regions should be connected/mapped after
|
111 | aae9460e | Paul Brook | calling this function. */
|
112 | aae9460e | Paul Brook | void qdev_init(DeviceState *dev)
|
113 | aae9460e | Paul Brook | { |
114 | 02e2da45 | Paul Brook | dev->type->info->init(dev, dev->type->info); |
115 | 02e2da45 | Paul Brook | } |
116 | 02e2da45 | Paul Brook | |
117 | 02e2da45 | Paul Brook | /* Unlink device from bus and free the structure. */
|
118 | 02e2da45 | Paul Brook | void qdev_free(DeviceState *dev)
|
119 | 02e2da45 | Paul Brook | { |
120 | 02e2da45 | Paul Brook | LIST_REMOVE(dev, sibling); |
121 | 02e2da45 | Paul Brook | free(dev); |
122 | aae9460e | Paul Brook | } |
123 | aae9460e | Paul Brook | |
124 | 1431b6a1 | Paul Brook | static DeviceProperty *create_prop(DeviceState *dev, const char *name, |
125 | 1431b6a1 | Paul Brook | DevicePropType type) |
126 | aae9460e | Paul Brook | { |
127 | aae9460e | Paul Brook | DeviceProperty *prop; |
128 | aae9460e | Paul Brook | |
129 | aae9460e | Paul Brook | /* TODO: Check for duplicate properties. */
|
130 | aae9460e | Paul Brook | prop = qemu_mallocz(sizeof(*prop));
|
131 | aae9460e | Paul Brook | prop->name = qemu_strdup(name); |
132 | 1431b6a1 | Paul Brook | prop->type = type; |
133 | aae9460e | Paul Brook | prop->next = dev->props; |
134 | aae9460e | Paul Brook | dev->props = prop; |
135 | aae9460e | Paul Brook | |
136 | aae9460e | Paul Brook | return prop;
|
137 | aae9460e | Paul Brook | } |
138 | aae9460e | Paul Brook | |
139 | 89a740e1 | Paul Brook | void qdev_set_prop_int(DeviceState *dev, const char *name, uint64_t value) |
140 | aae9460e | Paul Brook | { |
141 | aae9460e | Paul Brook | DeviceProperty *prop; |
142 | aae9460e | Paul Brook | |
143 | 1431b6a1 | Paul Brook | prop = create_prop(dev, name, PROP_TYPE_INT); |
144 | aae9460e | Paul Brook | prop->value.i = value; |
145 | aae9460e | Paul Brook | } |
146 | aae9460e | Paul Brook | |
147 | 1431b6a1 | Paul Brook | void qdev_set_prop_dev(DeviceState *dev, const char *name, DeviceState *value) |
148 | 1431b6a1 | Paul Brook | { |
149 | 1431b6a1 | Paul Brook | DeviceProperty *prop; |
150 | 1431b6a1 | Paul Brook | |
151 | 1431b6a1 | Paul Brook | prop = create_prop(dev, name, PROP_TYPE_DEV); |
152 | 1431b6a1 | Paul Brook | prop->value.ptr = value; |
153 | 1431b6a1 | Paul Brook | } |
154 | 1431b6a1 | Paul Brook | |
155 | aae9460e | Paul Brook | void qdev_set_prop_ptr(DeviceState *dev, const char *name, void *value) |
156 | aae9460e | Paul Brook | { |
157 | aae9460e | Paul Brook | DeviceProperty *prop; |
158 | aae9460e | Paul Brook | |
159 | db241f40 | Paul Brook | prop = create_prop(dev, name, PROP_TYPE_PTR); |
160 | aae9460e | Paul Brook | prop->value.ptr = value; |
161 | aae9460e | Paul Brook | } |
162 | aae9460e | Paul Brook | |
163 | 9d07d757 | Paul Brook | void qdev_set_netdev(DeviceState *dev, NICInfo *nd)
|
164 | 9d07d757 | Paul Brook | { |
165 | 9d07d757 | Paul Brook | assert(!dev->nd); |
166 | 9d07d757 | Paul Brook | dev->nd = nd; |
167 | 9d07d757 | Paul Brook | } |
168 | 9d07d757 | Paul Brook | |
169 | aae9460e | Paul Brook | |
170 | aae9460e | Paul Brook | /* Get a character (serial) device interface. */
|
171 | aae9460e | Paul Brook | CharDriverState *qdev_init_chardev(DeviceState *dev) |
172 | aae9460e | Paul Brook | { |
173 | aae9460e | Paul Brook | static int next_serial; |
174 | aae9460e | Paul Brook | static int next_virtconsole; |
175 | aae9460e | Paul Brook | /* FIXME: This is a nasty hack that needs to go away. */
|
176 | aca312af | Gerd Hoffmann | if (strncmp(dev->type->name, "virtio", 6) == 0) { |
177 | aae9460e | Paul Brook | return virtcon_hds[next_virtconsole++];
|
178 | aae9460e | Paul Brook | } else {
|
179 | aae9460e | Paul Brook | return serial_hds[next_serial++];
|
180 | aae9460e | Paul Brook | } |
181 | aae9460e | Paul Brook | } |
182 | aae9460e | Paul Brook | |
183 | 02e2da45 | Paul Brook | BusState *qdev_get_parent_bus(DeviceState *dev) |
184 | aae9460e | Paul Brook | { |
185 | 02e2da45 | Paul Brook | return dev->parent_bus;
|
186 | aae9460e | Paul Brook | } |
187 | aae9460e | Paul Brook | |
188 | 1431b6a1 | Paul Brook | static DeviceProperty *find_prop(DeviceState *dev, const char *name, |
189 | 1431b6a1 | Paul Brook | DevicePropType type) |
190 | aae9460e | Paul Brook | { |
191 | aae9460e | Paul Brook | DeviceProperty *prop; |
192 | aae9460e | Paul Brook | |
193 | aae9460e | Paul Brook | for (prop = dev->props; prop; prop = prop->next) {
|
194 | aae9460e | Paul Brook | if (strcmp(prop->name, name) == 0) { |
195 | 1431b6a1 | Paul Brook | assert (prop->type == type); |
196 | aae9460e | Paul Brook | return prop;
|
197 | aae9460e | Paul Brook | } |
198 | aae9460e | Paul Brook | } |
199 | aae9460e | Paul Brook | return NULL; |
200 | aae9460e | Paul Brook | } |
201 | aae9460e | Paul Brook | |
202 | aae9460e | Paul Brook | uint64_t qdev_get_prop_int(DeviceState *dev, const char *name, uint64_t def) |
203 | aae9460e | Paul Brook | { |
204 | aae9460e | Paul Brook | DeviceProperty *prop; |
205 | aae9460e | Paul Brook | |
206 | 1431b6a1 | Paul Brook | prop = find_prop(dev, name, PROP_TYPE_INT); |
207 | 1431b6a1 | Paul Brook | if (!prop) {
|
208 | aae9460e | Paul Brook | return def;
|
209 | 1431b6a1 | Paul Brook | } |
210 | aae9460e | Paul Brook | |
211 | aae9460e | Paul Brook | return prop->value.i;
|
212 | aae9460e | Paul Brook | } |
213 | aae9460e | Paul Brook | |
214 | aae9460e | Paul Brook | void *qdev_get_prop_ptr(DeviceState *dev, const char *name) |
215 | aae9460e | Paul Brook | { |
216 | aae9460e | Paul Brook | DeviceProperty *prop; |
217 | aae9460e | Paul Brook | |
218 | 1431b6a1 | Paul Brook | prop = find_prop(dev, name, PROP_TYPE_PTR); |
219 | aae9460e | Paul Brook | assert(prop); |
220 | aae9460e | Paul Brook | return prop->value.ptr;
|
221 | aae9460e | Paul Brook | } |
222 | aae9460e | Paul Brook | |
223 | 1431b6a1 | Paul Brook | DeviceState *qdev_get_prop_dev(DeviceState *dev, const char *name) |
224 | 1431b6a1 | Paul Brook | { |
225 | 1431b6a1 | Paul Brook | DeviceProperty *prop; |
226 | 1431b6a1 | Paul Brook | |
227 | 1431b6a1 | Paul Brook | prop = find_prop(dev, name, PROP_TYPE_DEV); |
228 | 1431b6a1 | Paul Brook | if (!prop) {
|
229 | 1431b6a1 | Paul Brook | return NULL; |
230 | 1431b6a1 | Paul Brook | } |
231 | 1431b6a1 | Paul Brook | return prop->value.ptr;
|
232 | 1431b6a1 | Paul Brook | } |
233 | 1431b6a1 | Paul Brook | |
234 | aae9460e | Paul Brook | void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n) |
235 | aae9460e | Paul Brook | { |
236 | aae9460e | Paul Brook | assert(dev->num_gpio_in == 0);
|
237 | aae9460e | Paul Brook | dev->num_gpio_in = n; |
238 | aae9460e | Paul Brook | dev->gpio_in = qemu_allocate_irqs(handler, dev, n); |
239 | aae9460e | Paul Brook | } |
240 | aae9460e | Paul Brook | |
241 | aae9460e | Paul Brook | void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n) |
242 | aae9460e | Paul Brook | { |
243 | aae9460e | Paul Brook | assert(dev->num_gpio_out == 0);
|
244 | aae9460e | Paul Brook | dev->num_gpio_out = n; |
245 | aae9460e | Paul Brook | dev->gpio_out = pins; |
246 | aae9460e | Paul Brook | } |
247 | aae9460e | Paul Brook | |
248 | aae9460e | Paul Brook | qemu_irq qdev_get_gpio_in(DeviceState *dev, int n)
|
249 | aae9460e | Paul Brook | { |
250 | aae9460e | Paul Brook | assert(n >= 0 && n < dev->num_gpio_in);
|
251 | aae9460e | Paul Brook | return dev->gpio_in[n];
|
252 | aae9460e | Paul Brook | } |
253 | aae9460e | Paul Brook | |
254 | aae9460e | Paul Brook | void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin) |
255 | aae9460e | Paul Brook | { |
256 | aae9460e | Paul Brook | assert(n >= 0 && n < dev->num_gpio_out);
|
257 | aae9460e | Paul Brook | dev->gpio_out[n] = pin; |
258 | aae9460e | Paul Brook | } |
259 | aae9460e | Paul Brook | |
260 | 9d07d757 | Paul Brook | VLANClientState *qdev_get_vlan_client(DeviceState *dev, |
261 | cda9046b | Mark McLoughlin | NetCanReceive *can_receive, |
262 | cda9046b | Mark McLoughlin | NetReceive *receive, |
263 | cda9046b | Mark McLoughlin | NetReceiveIOV *receive_iov, |
264 | 9d07d757 | Paul Brook | NetCleanup *cleanup, |
265 | 9d07d757 | Paul Brook | void *opaque)
|
266 | 9d07d757 | Paul Brook | { |
267 | 9d07d757 | Paul Brook | NICInfo *nd = dev->nd; |
268 | 9d07d757 | Paul Brook | assert(nd); |
269 | cda9046b | Mark McLoughlin | return qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive,
|
270 | cda9046b | Mark McLoughlin | receive, receive_iov, cleanup, opaque); |
271 | 9d07d757 | Paul Brook | } |
272 | 9d07d757 | Paul Brook | |
273 | 9d07d757 | Paul Brook | |
274 | 9d07d757 | Paul Brook | void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr)
|
275 | 9d07d757 | Paul Brook | { |
276 | 9d07d757 | Paul Brook | memcpy(macaddr, dev->nd->macaddr, 6);
|
277 | 9d07d757 | Paul Brook | } |
278 | 9d07d757 | Paul Brook | |
279 | aae9460e | Paul Brook | static int next_block_unit[IF_COUNT]; |
280 | aae9460e | Paul Brook | |
281 | aae9460e | Paul Brook | /* Get a block device. This should only be used for single-drive devices
|
282 | aae9460e | Paul Brook | (e.g. SD/Floppy/MTD). Multi-disk devices (scsi/ide) should use the
|
283 | aae9460e | Paul Brook | appropriate bus. */
|
284 | aae9460e | Paul Brook | BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type) |
285 | aae9460e | Paul Brook | { |
286 | aae9460e | Paul Brook | int unit = next_block_unit[type]++;
|
287 | aae9460e | Paul Brook | int index;
|
288 | aae9460e | Paul Brook | |
289 | aae9460e | Paul Brook | index = drive_get_index(type, 0, unit);
|
290 | aae9460e | Paul Brook | if (index == -1) { |
291 | aae9460e | Paul Brook | return NULL; |
292 | aae9460e | Paul Brook | } |
293 | aae9460e | Paul Brook | return drives_table[index].bdrv;
|
294 | aae9460e | Paul Brook | } |
295 | 4d6ae674 | Paul Brook | |
296 | 02e2da45 | Paul Brook | BusState *qdev_get_child_bus(DeviceState *dev, const char *name) |
297 | 4d6ae674 | Paul Brook | { |
298 | 02e2da45 | Paul Brook | BusState *bus; |
299 | 4d6ae674 | Paul Brook | |
300 | 02e2da45 | Paul Brook | LIST_FOREACH(bus, &dev->child_bus, sibling) { |
301 | 4d6ae674 | Paul Brook | if (strcmp(name, bus->name) == 0) { |
302 | 02e2da45 | Paul Brook | return bus;
|
303 | 4d6ae674 | Paul Brook | } |
304 | 4d6ae674 | Paul Brook | } |
305 | 4d6ae674 | Paul Brook | return NULL; |
306 | 4d6ae674 | Paul Brook | } |
307 | 4d6ae674 | Paul Brook | |
308 | 6f68ecb2 | Paul Brook | static int next_scsi_bus; |
309 | 6f68ecb2 | Paul Brook | |
310 | 6f68ecb2 | Paul Brook | /* Create a scsi bus, and attach devices to it. */
|
311 | 6f68ecb2 | Paul Brook | /* TODO: Actually create a scsi bus for hotplug to use. */
|
312 | 6f68ecb2 | Paul Brook | void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)
|
313 | 6f68ecb2 | Paul Brook | { |
314 | 6f68ecb2 | Paul Brook | int bus = next_scsi_bus++;
|
315 | 6f68ecb2 | Paul Brook | int unit;
|
316 | 6f68ecb2 | Paul Brook | int index;
|
317 | 6f68ecb2 | Paul Brook | |
318 | 6f68ecb2 | Paul Brook | for (unit = 0; unit < MAX_SCSI_DEVS; unit++) { |
319 | 6f68ecb2 | Paul Brook | index = drive_get_index(IF_SCSI, bus, unit); |
320 | 6f68ecb2 | Paul Brook | if (index == -1) { |
321 | 6f68ecb2 | Paul Brook | continue;
|
322 | 6f68ecb2 | Paul Brook | } |
323 | 6f68ecb2 | Paul Brook | attach(host, drives_table[index].bdrv, unit); |
324 | 6f68ecb2 | Paul Brook | } |
325 | 6f68ecb2 | Paul Brook | } |
326 | 02e2da45 | Paul Brook | |
327 | 02e2da45 | Paul Brook | BusState *qbus_create(BusType type, size_t size, |
328 | 02e2da45 | Paul Brook | DeviceState *parent, const char *name) |
329 | 02e2da45 | Paul Brook | { |
330 | 02e2da45 | Paul Brook | BusState *bus; |
331 | 02e2da45 | Paul Brook | |
332 | 02e2da45 | Paul Brook | bus = qemu_mallocz(size); |
333 | 02e2da45 | Paul Brook | bus->type = type; |
334 | 02e2da45 | Paul Brook | bus->parent = parent; |
335 | 02e2da45 | Paul Brook | bus->name = qemu_strdup(name); |
336 | 02e2da45 | Paul Brook | LIST_INIT(&bus->children); |
337 | 02e2da45 | Paul Brook | if (parent) {
|
338 | 02e2da45 | Paul Brook | LIST_INSERT_HEAD(&parent->child_bus, bus, sibling); |
339 | 02e2da45 | Paul Brook | } |
340 | 02e2da45 | Paul Brook | return bus;
|
341 | 02e2da45 | Paul Brook | } |
342 | cae4956e | Gerd Hoffmann | |
343 | cae4956e | Gerd Hoffmann | static const char *bus_type_names[] = { |
344 | 98ba2632 | Gerd Hoffmann | [ BUS_TYPE_SYSTEM ] = "System",
|
345 | 98ba2632 | Gerd Hoffmann | [ BUS_TYPE_PCI ] = "PCI",
|
346 | 98ba2632 | Gerd Hoffmann | [ BUS_TYPE_SCSI ] = "SCSI",
|
347 | 98ba2632 | Gerd Hoffmann | [ BUS_TYPE_I2C ] = "I2C",
|
348 | 98ba2632 | Gerd Hoffmann | [ BUS_TYPE_SSI ] = "SSI",
|
349 | cae4956e | Gerd Hoffmann | }; |
350 | cae4956e | Gerd Hoffmann | |
351 | cae4956e | Gerd Hoffmann | #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__) |
352 | cae4956e | Gerd Hoffmann | static void qbus_print(Monitor *mon, BusState *bus, int indent); |
353 | cae4956e | Gerd Hoffmann | |
354 | cae4956e | Gerd Hoffmann | static void qdev_print(Monitor *mon, DeviceState *dev, int indent) |
355 | cae4956e | Gerd Hoffmann | { |
356 | cae4956e | Gerd Hoffmann | DeviceProperty *prop; |
357 | cae4956e | Gerd Hoffmann | BusState *child; |
358 | cae4956e | Gerd Hoffmann | qdev_printf("dev: %s\n", dev->type->name);
|
359 | cae4956e | Gerd Hoffmann | indent += 2;
|
360 | cae4956e | Gerd Hoffmann | if (dev->num_gpio_in) {
|
361 | cae4956e | Gerd Hoffmann | qdev_printf("gpio-in %d\n", dev->num_gpio_in);
|
362 | cae4956e | Gerd Hoffmann | } |
363 | cae4956e | Gerd Hoffmann | if (dev->num_gpio_out) {
|
364 | cae4956e | Gerd Hoffmann | qdev_printf("gpio-out %d\n", dev->num_gpio_out);
|
365 | cae4956e | Gerd Hoffmann | } |
366 | cae4956e | Gerd Hoffmann | for (prop = dev->props; prop; prop = prop->next) {
|
367 | cae4956e | Gerd Hoffmann | switch (prop->type) {
|
368 | cae4956e | Gerd Hoffmann | case PROP_TYPE_INT:
|
369 | cae4956e | Gerd Hoffmann | qdev_printf("prop-int %s 0x%" PRIx64 "\n", prop->name, |
370 | cae4956e | Gerd Hoffmann | prop->value.i); |
371 | cae4956e | Gerd Hoffmann | break;
|
372 | cae4956e | Gerd Hoffmann | case PROP_TYPE_PTR:
|
373 | cae4956e | Gerd Hoffmann | qdev_printf("prop-ptr %s\n", prop->name);
|
374 | cae4956e | Gerd Hoffmann | break;
|
375 | cae4956e | Gerd Hoffmann | case PROP_TYPE_DEV:
|
376 | cae4956e | Gerd Hoffmann | qdev_printf("prop-dev %s %s\n", prop->name,
|
377 | cae4956e | Gerd Hoffmann | ((DeviceState *)prop->value.ptr)->type->name); |
378 | cae4956e | Gerd Hoffmann | break;
|
379 | cae4956e | Gerd Hoffmann | default:
|
380 | cae4956e | Gerd Hoffmann | qdev_printf("prop-unknown%d %s\n", prop->type, prop->name);
|
381 | cae4956e | Gerd Hoffmann | break;
|
382 | cae4956e | Gerd Hoffmann | } |
383 | cae4956e | Gerd Hoffmann | } |
384 | cae4956e | Gerd Hoffmann | switch (dev->parent_bus->type) {
|
385 | cae4956e | Gerd Hoffmann | case BUS_TYPE_SYSTEM:
|
386 | cae4956e | Gerd Hoffmann | sysbus_dev_print(mon, dev, indent); |
387 | cae4956e | Gerd Hoffmann | break;
|
388 | cae4956e | Gerd Hoffmann | default:
|
389 | cae4956e | Gerd Hoffmann | break;
|
390 | cae4956e | Gerd Hoffmann | } |
391 | cae4956e | Gerd Hoffmann | LIST_FOREACH(child, &dev->child_bus, sibling) { |
392 | cae4956e | Gerd Hoffmann | qbus_print(mon, child, indent); |
393 | cae4956e | Gerd Hoffmann | } |
394 | cae4956e | Gerd Hoffmann | } |
395 | cae4956e | Gerd Hoffmann | |
396 | cae4956e | Gerd Hoffmann | static void qbus_print(Monitor *mon, BusState *bus, int indent) |
397 | cae4956e | Gerd Hoffmann | { |
398 | cae4956e | Gerd Hoffmann | struct DeviceState *dev;
|
399 | cae4956e | Gerd Hoffmann | |
400 | cae4956e | Gerd Hoffmann | qdev_printf("bus: %s\n", bus->name);
|
401 | cae4956e | Gerd Hoffmann | indent += 2;
|
402 | cae4956e | Gerd Hoffmann | qdev_printf("type %s\n", bus_type_names[bus->type]);
|
403 | cae4956e | Gerd Hoffmann | LIST_FOREACH(dev, &bus->children, sibling) { |
404 | cae4956e | Gerd Hoffmann | qdev_print(mon, dev, indent); |
405 | cae4956e | Gerd Hoffmann | } |
406 | cae4956e | Gerd Hoffmann | } |
407 | cae4956e | Gerd Hoffmann | #undef qdev_printf
|
408 | cae4956e | Gerd Hoffmann | |
409 | cae4956e | Gerd Hoffmann | void do_info_qtree(Monitor *mon)
|
410 | cae4956e | Gerd Hoffmann | { |
411 | cae4956e | Gerd Hoffmann | if (main_system_bus)
|
412 | cae4956e | Gerd Hoffmann | qbus_print(mon, main_system_bus, 0);
|
413 | cae4956e | Gerd Hoffmann | } |