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