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