Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 1 | #include "hw.h" |
| 2 | #include "usb.h" |
| 3 | #include "qdev.h" |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 4 | #include "sysemu.h" |
| 5 | #include "monitor.h" |
| 6 | |
| 7 | static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); |
Gerd Hoffmann | c7a2196 | 2010-12-10 11:37:45 +0100 | [diff] [blame] | 8 | |
| 9 | static char *usb_get_dev_path(DeviceState *dev); |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 10 | static char *usb_get_fw_dev_path(DeviceState *qdev); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 11 | |
| 12 | static struct BusInfo usb_bus_info = { |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 13 | .name = "USB", |
| 14 | .size = sizeof(USBBus), |
| 15 | .print_dev = usb_bus_dev_print, |
Gerd Hoffmann | c7a2196 | 2010-12-10 11:37:45 +0100 | [diff] [blame] | 16 | .get_dev_path = usb_get_dev_path, |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 17 | .get_fw_dev_path = usb_get_fw_dev_path, |
Gerd Hoffmann | 5f69076 | 2010-12-10 11:43:35 +0100 | [diff] [blame] | 18 | .props = (Property[]) { |
| 19 | DEFINE_PROP_STRING("port", USBDevice, port_path), |
| 20 | DEFINE_PROP_END_OF_LIST() |
| 21 | }, |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 22 | }; |
| 23 | static int next_usb_bus = 0; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 24 | static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 25 | |
Gerd Hoffmann | c1ecb40 | 2010-12-10 14:20:46 +0100 | [diff] [blame] | 26 | const VMStateDescription vmstate_usb_device = { |
| 27 | .name = "USBDevice", |
| 28 | .version_id = 1, |
| 29 | .minimum_version_id = 1, |
| 30 | .fields = (VMStateField []) { |
| 31 | VMSTATE_UINT8(addr, USBDevice), |
| 32 | VMSTATE_INT32(state, USBDevice), |
| 33 | VMSTATE_INT32(remote_wakeup, USBDevice), |
| 34 | VMSTATE_INT32(setup_state, USBDevice), |
| 35 | VMSTATE_INT32(setup_len, USBDevice), |
| 36 | VMSTATE_INT32(setup_index, USBDevice), |
| 37 | VMSTATE_UINT8_ARRAY(setup_buf, USBDevice, 8), |
| 38 | VMSTATE_END_OF_LIST(), |
| 39 | } |
| 40 | }; |
| 41 | |
Gerd Hoffmann | b231783 | 2009-09-16 22:25:29 +0200 | [diff] [blame] | 42 | void usb_bus_new(USBBus *bus, DeviceState *host) |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 43 | { |
Gerd Hoffmann | b231783 | 2009-09-16 22:25:29 +0200 | [diff] [blame] | 44 | qbus_create_inplace(&bus->qbus, &usb_bus_info, host, NULL); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 45 | bus->busnr = next_usb_bus++; |
Gerd Hoffmann | ef816d8 | 2009-09-25 21:42:42 +0200 | [diff] [blame] | 46 | bus->qbus.allow_hotplug = 1; /* Yes, we can */ |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 47 | QTAILQ_INIT(&bus->free); |
| 48 | QTAILQ_INIT(&bus->used); |
| 49 | QTAILQ_INSERT_TAIL(&busses, bus, next); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | USBBus *usb_bus_find(int busnr) |
| 53 | { |
| 54 | USBBus *bus; |
| 55 | |
| 56 | if (-1 == busnr) |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 57 | return QTAILQ_FIRST(&busses); |
| 58 | QTAILQ_FOREACH(bus, &busses, next) { |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 59 | if (bus->busnr == busnr) |
| 60 | return bus; |
| 61 | } |
| 62 | return NULL; |
| 63 | } |
| 64 | |
| 65 | static int usb_qdev_init(DeviceState *qdev, DeviceInfo *base) |
| 66 | { |
| 67 | USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev); |
| 68 | USBDeviceInfo *info = DO_UPCAST(USBDeviceInfo, qdev, base); |
| 69 | int rc; |
| 70 | |
Markus Armbruster | 0638469 | 2009-12-09 17:07:52 +0100 | [diff] [blame] | 71 | pstrcpy(dev->product_desc, sizeof(dev->product_desc), info->product_desc); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 72 | dev->info = info; |
Gerd Hoffmann | 61e094c | 2009-10-26 15:56:48 +0100 | [diff] [blame] | 73 | dev->auto_attach = 1; |
Gerd Hoffmann | 132a3f5 | 2010-11-26 12:25:32 +0100 | [diff] [blame] | 74 | QLIST_INIT(&dev->strings); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 75 | rc = dev->info->init(dev); |
Gerd Hoffmann | 61e094c | 2009-10-26 15:56:48 +0100 | [diff] [blame] | 76 | if (rc == 0 && dev->auto_attach) |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 77 | usb_device_attach(dev); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 78 | return rc; |
| 79 | } |
| 80 | |
Gerd Hoffmann | a8e662b | 2009-09-25 21:42:39 +0200 | [diff] [blame] | 81 | static int usb_qdev_exit(DeviceState *qdev) |
| 82 | { |
| 83 | USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev); |
| 84 | |
| 85 | usb_device_detach(dev); |
| 86 | if (dev->info->handle_destroy) { |
| 87 | dev->info->handle_destroy(dev); |
| 88 | } |
| 89 | return 0; |
| 90 | } |
| 91 | |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 92 | void usb_qdev_register(USBDeviceInfo *info) |
| 93 | { |
| 94 | info->qdev.bus_info = &usb_bus_info; |
| 95 | info->qdev.init = usb_qdev_init; |
Gerd Hoffmann | ef816d8 | 2009-09-25 21:42:42 +0200 | [diff] [blame] | 96 | info->qdev.unplug = qdev_simple_unplug_cb; |
Gerd Hoffmann | a8e662b | 2009-09-25 21:42:39 +0200 | [diff] [blame] | 97 | info->qdev.exit = usb_qdev_exit; |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 98 | qdev_register(&info->qdev); |
| 99 | } |
| 100 | |
| 101 | void usb_qdev_register_many(USBDeviceInfo *info) |
| 102 | { |
| 103 | while (info->qdev.name) { |
| 104 | usb_qdev_register(info); |
| 105 | info++; |
| 106 | } |
| 107 | } |
| 108 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 109 | USBDevice *usb_create(USBBus *bus, const char *name) |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 110 | { |
| 111 | DeviceState *dev; |
| 112 | |
| 113 | #if 1 |
| 114 | /* temporary stopgap until all usb is properly qdev-ified */ |
| 115 | if (!bus) { |
| 116 | bus = usb_bus_find(-1); |
| 117 | if (!bus) |
| 118 | return NULL; |
| 119 | fprintf(stderr, "%s: no bus specified, using \"%s\" for \"%s\"\n", |
| 120 | __FUNCTION__, bus->qbus.name, name); |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | dev = qdev_create(&bus->qbus, name); |
Gerd Hoffmann | 806b602 | 2009-08-31 14:23:59 +0200 | [diff] [blame] | 125 | return DO_UPCAST(USBDevice, qdev, dev); |
| 126 | } |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 127 | |
| 128 | USBDevice *usb_create_simple(USBBus *bus, const char *name) |
| 129 | { |
| 130 | USBDevice *dev = usb_create(bus, name); |
Paul Brook | d44168f | 2010-02-25 13:29:06 +0000 | [diff] [blame] | 131 | if (!dev) { |
| 132 | hw_error("Failed to create USB device '%s'\n", name); |
| 133 | } |
Markus Armbruster | e23a1b3 | 2009-10-07 01:15:58 +0200 | [diff] [blame] | 134 | qdev_init_nofail(&dev->qdev); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 135 | return dev; |
| 136 | } |
| 137 | |
| 138 | void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, |
Gerd Hoffmann | ace1318 | 2011-01-12 11:34:50 +0100 | [diff] [blame] | 139 | USBPortOps *ops, int speedmask) |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 140 | { |
| 141 | port->opaque = opaque; |
| 142 | port->index = index; |
Gerd Hoffmann | 0d86d2b | 2010-12-01 11:08:44 +0100 | [diff] [blame] | 143 | port->opaque = opaque; |
| 144 | port->index = index; |
| 145 | port->ops = ops; |
Gerd Hoffmann | 843d4e0 | 2010-12-03 17:30:13 +0100 | [diff] [blame] | 146 | port->speedmask = speedmask; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 147 | QTAILQ_INSERT_TAIL(&bus->free, port, next); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 148 | bus->nfree++; |
| 149 | } |
| 150 | |
Gerd Hoffmann | c7a2196 | 2010-12-10 11:37:45 +0100 | [diff] [blame] | 151 | void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr) |
| 152 | { |
| 153 | if (upstream) { |
| 154 | snprintf(downstream->path, sizeof(downstream->path), "%s.%d", |
| 155 | upstream->path, portnr); |
| 156 | } else { |
| 157 | snprintf(downstream->path, sizeof(downstream->path), "%d", portnr); |
| 158 | } |
| 159 | } |
| 160 | |
Gerd Hoffmann | a8e662b | 2009-09-25 21:42:39 +0200 | [diff] [blame] | 161 | void usb_unregister_port(USBBus *bus, USBPort *port) |
| 162 | { |
| 163 | if (port->dev) |
| 164 | qdev_free(&port->dev->qdev); |
| 165 | QTAILQ_REMOVE(&bus->free, port, next); |
| 166 | bus->nfree--; |
| 167 | } |
| 168 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 169 | static void do_attach(USBDevice *dev) |
| 170 | { |
| 171 | USBBus *bus = usb_bus_from_device(dev); |
| 172 | USBPort *port; |
| 173 | |
| 174 | if (dev->attached) { |
| 175 | fprintf(stderr, "Warning: tried to attach usb device %s twice\n", |
Markus Armbruster | 0fe6d12 | 2009-12-09 17:07:51 +0100 | [diff] [blame] | 176 | dev->product_desc); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 177 | return; |
| 178 | } |
Gerd Hoffmann | 5f69076 | 2010-12-10 11:43:35 +0100 | [diff] [blame] | 179 | if (dev->port_path) { |
| 180 | QTAILQ_FOREACH(port, &bus->free, next) { |
| 181 | if (strcmp(port->path, dev->port_path) == 0) { |
| 182 | break; |
| 183 | } |
| 184 | } |
| 185 | if (port == NULL) { |
| 186 | fprintf(stderr, "Warning: usb port %s (bus %s) not found\n", |
| 187 | dev->port_path, bus->qbus.name); |
| 188 | return; |
| 189 | } |
| 190 | } else { |
| 191 | port = QTAILQ_FIRST(&bus->free); |
| 192 | } |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 193 | |
Gerd Hoffmann | 5f69076 | 2010-12-10 11:43:35 +0100 | [diff] [blame] | 194 | dev->attached++; |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 195 | QTAILQ_REMOVE(&bus->free, port, next); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 196 | bus->nfree--; |
| 197 | |
| 198 | usb_attach(port, dev); |
| 199 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 200 | QTAILQ_INSERT_TAIL(&bus->used, port, next); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 201 | bus->nused++; |
| 202 | } |
| 203 | |
| 204 | int usb_device_attach(USBDevice *dev) |
| 205 | { |
| 206 | USBBus *bus = usb_bus_from_device(dev); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 207 | |
Gerd Hoffmann | 5f69076 | 2010-12-10 11:43:35 +0100 | [diff] [blame] | 208 | if (bus->nfree == 1 && dev->port_path == NULL) { |
| 209 | /* Create a new hub and chain it on |
| 210 | (unless a physical port location is specified). */ |
Blue Swirl | d4c4e6f | 2010-04-25 18:23:04 +0000 | [diff] [blame] | 211 | usb_create_simple(bus, "usb-hub"); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 212 | } |
| 213 | do_attach(dev); |
| 214 | return 0; |
| 215 | } |
| 216 | |
Gerd Hoffmann | a8e662b | 2009-09-25 21:42:39 +0200 | [diff] [blame] | 217 | int usb_device_detach(USBDevice *dev) |
| 218 | { |
| 219 | USBBus *bus = usb_bus_from_device(dev); |
| 220 | USBPort *port; |
| 221 | |
| 222 | if (!dev->attached) { |
| 223 | fprintf(stderr, "Warning: tried to detach unattached usb device %s\n", |
Markus Armbruster | 0fe6d12 | 2009-12-09 17:07:51 +0100 | [diff] [blame] | 224 | dev->product_desc); |
Gerd Hoffmann | a8e662b | 2009-09-25 21:42:39 +0200 | [diff] [blame] | 225 | return -1; |
| 226 | } |
| 227 | dev->attached--; |
| 228 | |
| 229 | QTAILQ_FOREACH(port, &bus->used, next) { |
| 230 | if (port->dev == dev) |
| 231 | break; |
| 232 | } |
| 233 | assert(port != NULL); |
| 234 | |
| 235 | QTAILQ_REMOVE(&bus->used, port, next); |
| 236 | bus->nused--; |
| 237 | |
| 238 | usb_attach(port, NULL); |
| 239 | |
| 240 | QTAILQ_INSERT_TAIL(&bus->free, port, next); |
| 241 | bus->nfree++; |
| 242 | return 0; |
| 243 | } |
| 244 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 245 | int usb_device_delete_addr(int busnr, int addr) |
| 246 | { |
| 247 | USBBus *bus; |
| 248 | USBPort *port; |
| 249 | USBDevice *dev; |
| 250 | |
| 251 | bus = usb_bus_find(busnr); |
| 252 | if (!bus) |
| 253 | return -1; |
| 254 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 255 | QTAILQ_FOREACH(port, &bus->used, next) { |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 256 | if (port->dev->addr == addr) |
| 257 | break; |
| 258 | } |
| 259 | if (!port) |
| 260 | return -1; |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 261 | dev = port->dev; |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 262 | |
Gerd Hoffmann | a8e662b | 2009-09-25 21:42:39 +0200 | [diff] [blame] | 263 | qdev_free(&dev->qdev); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static const char *usb_speed(unsigned int speed) |
| 268 | { |
| 269 | static const char *txt[] = { |
| 270 | [ USB_SPEED_LOW ] = "1.5", |
| 271 | [ USB_SPEED_FULL ] = "12", |
| 272 | [ USB_SPEED_HIGH ] = "480", |
| 273 | }; |
| 274 | if (speed >= ARRAY_SIZE(txt)) |
| 275 | return "?"; |
| 276 | return txt[speed]; |
| 277 | } |
| 278 | |
| 279 | static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) |
| 280 | { |
| 281 | USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev); |
| 282 | USBBus *bus = usb_bus_from_device(dev); |
| 283 | |
Gerd Hoffmann | c7a2196 | 2010-12-10 11:37:45 +0100 | [diff] [blame] | 284 | monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n", |
Gerd Hoffmann | 66a6593 | 2009-10-26 15:56:51 +0100 | [diff] [blame] | 285 | indent, "", bus->busnr, dev->addr, |
Gerd Hoffmann | c7a2196 | 2010-12-10 11:37:45 +0100 | [diff] [blame] | 286 | dev->port ? dev->port->path : "-", |
Markus Armbruster | 0fe6d12 | 2009-12-09 17:07:51 +0100 | [diff] [blame] | 287 | usb_speed(dev->speed), dev->product_desc, |
Gerd Hoffmann | 66a6593 | 2009-10-26 15:56:51 +0100 | [diff] [blame] | 288 | dev->attached ? ", attached" : ""); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 289 | } |
| 290 | |
Gerd Hoffmann | c7a2196 | 2010-12-10 11:37:45 +0100 | [diff] [blame] | 291 | static char *usb_get_dev_path(DeviceState *qdev) |
| 292 | { |
| 293 | USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev); |
| 294 | return qemu_strdup(dev->port->path); |
| 295 | } |
| 296 | |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 297 | static char *usb_get_fw_dev_path(DeviceState *qdev) |
| 298 | { |
| 299 | USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev); |
| 300 | char *fw_path, *in; |
Blue Swirl | ea87e95 | 2011-01-23 08:48:41 +0000 | [diff] [blame] | 301 | ssize_t pos = 0, fw_len; |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 302 | long nr; |
| 303 | |
Blue Swirl | ea87e95 | 2011-01-23 08:48:41 +0000 | [diff] [blame] | 304 | fw_len = 32 + strlen(dev->port->path) * 6; |
| 305 | fw_path = qemu_malloc(fw_len); |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 306 | in = dev->port->path; |
Blue Swirl | ea87e95 | 2011-01-23 08:48:41 +0000 | [diff] [blame] | 307 | while (fw_len - pos > 0) { |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 308 | nr = strtol(in, &in, 10); |
| 309 | if (in[0] == '.') { |
| 310 | /* some hub between root port and device */ |
Blue Swirl | ea87e95 | 2011-01-23 08:48:41 +0000 | [diff] [blame] | 311 | pos += snprintf(fw_path + pos, fw_len - pos, "hub@%ld/", nr); |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 312 | in++; |
| 313 | } else { |
| 314 | /* the device itself */ |
Blue Swirl | ea87e95 | 2011-01-23 08:48:41 +0000 | [diff] [blame] | 315 | pos += snprintf(fw_path + pos, fw_len - pos, "%s@%ld", |
| 316 | qdev_fw_name(qdev), nr); |
Gerd Hoffmann | 70d31cb | 2011-01-12 10:58:27 +0100 | [diff] [blame] | 317 | break; |
| 318 | } |
| 319 | } |
| 320 | return fw_path; |
| 321 | } |
| 322 | |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 323 | void usb_info(Monitor *mon) |
| 324 | { |
| 325 | USBBus *bus; |
| 326 | USBDevice *dev; |
| 327 | USBPort *port; |
| 328 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 329 | if (QTAILQ_EMPTY(&busses)) { |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 330 | monitor_printf(mon, "USB support not enabled\n"); |
| 331 | return; |
| 332 | } |
| 333 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 334 | QTAILQ_FOREACH(bus, &busses, next) { |
| 335 | QTAILQ_FOREACH(port, &bus->used, next) { |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 336 | dev = port->dev; |
| 337 | if (!dev) |
| 338 | continue; |
Gerd Hoffmann | c7a2196 | 2010-12-10 11:37:45 +0100 | [diff] [blame] | 339 | monitor_printf(mon, " Device %d.%d, Port %s, Speed %s Mb/s, Product %s\n", |
| 340 | bus->busnr, dev->addr, port->path, usb_speed(dev->speed), |
Markus Armbruster | 0fe6d12 | 2009-12-09 17:07:51 +0100 | [diff] [blame] | 341 | dev->product_desc); |
Gerd Hoffmann | a5d2f72 | 2009-08-31 14:24:00 +0200 | [diff] [blame] | 342 | } |
| 343 | } |
| 344 | } |
| 345 | |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 346 | /* handle legacy -usbdevice cmd line option */ |
| 347 | USBDevice *usbdevice_create(const char *cmdline) |
| 348 | { |
| 349 | USBBus *bus = usb_bus_find(-1 /* any */); |
| 350 | DeviceInfo *info; |
| 351 | USBDeviceInfo *usb; |
Jan Kiszka | 702f3e0 | 2010-03-07 12:17:08 +0100 | [diff] [blame] | 352 | char driver[32]; |
| 353 | const char *params; |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 354 | int len; |
| 355 | |
| 356 | params = strchr(cmdline,':'); |
| 357 | if (params) { |
| 358 | params++; |
| 359 | len = params - cmdline; |
| 360 | if (len > sizeof(driver)) |
| 361 | len = sizeof(driver); |
| 362 | pstrcpy(driver, len, cmdline); |
| 363 | } else { |
Jan Kiszka | 702f3e0 | 2010-03-07 12:17:08 +0100 | [diff] [blame] | 364 | params = ""; |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 365 | pstrcpy(driver, sizeof(driver), cmdline); |
| 366 | } |
| 367 | |
| 368 | for (info = device_info_list; info != NULL; info = info->next) { |
| 369 | if (info->bus_info != &usb_bus_info) |
| 370 | continue; |
| 371 | usb = DO_UPCAST(USBDeviceInfo, qdev, info); |
| 372 | if (usb->usbdevice_name == NULL) |
| 373 | continue; |
| 374 | if (strcmp(usb->usbdevice_name, driver) != 0) |
| 375 | continue; |
| 376 | break; |
| 377 | } |
| 378 | if (info == NULL) { |
| 379 | #if 0 |
| 380 | /* no error because some drivers are not converted (yet) */ |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 381 | error_report("usbdevice %s not found", driver); |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 382 | #endif |
| 383 | return NULL; |
| 384 | } |
| 385 | |
| 386 | if (!usb->usbdevice_init) { |
TeLeMan | 98f22dc | 2010-03-30 09:33:24 +0800 | [diff] [blame] | 387 | if (*params) { |
Markus Armbruster | 1ecda02 | 2010-02-18 17:25:24 +0100 | [diff] [blame] | 388 | error_report("usbdevice %s accepts no params", driver); |
Gerd Hoffmann | 0958b4c | 2009-10-26 15:56:45 +0100 | [diff] [blame] | 389 | return NULL; |
| 390 | } |
| 391 | return usb_create_simple(bus, usb->qdev.name); |
| 392 | } |
| 393 | return usb->usbdevice_init(params); |
| 394 | } |