1 #include "hw/hw.h" 2 #include "hw/usb.h" 3 #include "hw/qdev.h" 4 #include "sysemu/sysemu.h" 5 #include "monitor/monitor.h" 6 #include "trace.h" 7 8 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent); 9 10 static char *usb_get_dev_path(DeviceState *dev); 11 static char *usb_get_fw_dev_path(DeviceState *qdev); 12 static void usb_qdev_unrealize(DeviceState *qdev, Error **errp); 13 14 static Property usb_props[] = { 15 DEFINE_PROP_STRING("port", USBDevice, port_path), 16 DEFINE_PROP_STRING("serial", USBDevice, serial), 17 DEFINE_PROP_BIT("full-path", USBDevice, flags, 18 USB_DEV_FLAG_FULL_PATH, true), 19 DEFINE_PROP_BIT("msos-desc", USBDevice, flags, 20 USB_DEV_FLAG_MSOS_DESC_ENABLE, true), 21 DEFINE_PROP_END_OF_LIST() 22 }; 23 24 static void usb_bus_class_init(ObjectClass *klass, void *data) 25 { 26 BusClass *k = BUS_CLASS(klass); 27 HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass); 28 29 k->print_dev = usb_bus_dev_print; 30 k->get_dev_path = usb_get_dev_path; 31 k->get_fw_dev_path = usb_get_fw_dev_path; 32 hc->unplug = qdev_simple_device_unplug_cb; 33 } 34 35 static const TypeInfo usb_bus_info = { 36 .name = TYPE_USB_BUS, 37 .parent = TYPE_BUS, 38 .instance_size = sizeof(USBBus), 39 .class_init = usb_bus_class_init, 40 .interfaces = (InterfaceInfo[]) { 41 { TYPE_HOTPLUG_HANDLER }, 42 { } 43 } 44 }; 45 46 static int next_usb_bus = 0; 47 static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses); 48 49 static int usb_device_post_load(void *opaque, int version_id) 50 { 51 USBDevice *dev = opaque; 52 53 if (dev->state == USB_STATE_NOTATTACHED) { 54 dev->attached = 0; 55 } else { 56 dev->attached = 1; 57 } 58 if (dev->setup_index < 0 || 59 dev->setup_len < 0 || 60 dev->setup_index > dev->setup_len || 61 dev->setup_len > sizeof(dev->data_buf)) { 62 return -EINVAL; 63 } 64 return 0; 65 } 66 67 const VMStateDescription vmstate_usb_device = { 68 .name = "USBDevice", 69 .version_id = 1, 70 .minimum_version_id = 1, 71 .post_load = usb_device_post_load, 72 .fields = (VMStateField[]) { 73 VMSTATE_UINT8(addr, USBDevice), 74 VMSTATE_INT32(state, USBDevice), 75 VMSTATE_INT32(remote_wakeup, USBDevice), 76 VMSTATE_INT32(setup_state, USBDevice), 77 VMSTATE_INT32(setup_len, USBDevice), 78 VMSTATE_INT32(setup_index, USBDevice), 79 VMSTATE_UINT8_ARRAY(setup_buf, USBDevice, 8), 80 VMSTATE_END_OF_LIST(), 81 } 82 }; 83 84 void usb_bus_new(USBBus *bus, size_t bus_size, 85 USBBusOps *ops, DeviceState *host) 86 { 87 qbus_create_inplace(bus, bus_size, TYPE_USB_BUS, host, NULL); 88 qbus_set_bus_hotplug_handler(BUS(bus), &error_abort); 89 bus->ops = ops; 90 bus->busnr = next_usb_bus++; 91 QTAILQ_INIT(&bus->free); 92 QTAILQ_INIT(&bus->used); 93 QTAILQ_INSERT_TAIL(&busses, bus, next); 94 } 95 96 void usb_bus_release(USBBus *bus) 97 { 98 assert(next_usb_bus > 0); 99 100 QTAILQ_REMOVE(&busses, bus, next); 101 } 102 103 USBBus *usb_bus_find(int busnr) 104 { 105 USBBus *bus; 106 107 if (-1 == busnr) 108 return QTAILQ_FIRST(&busses); 109 QTAILQ_FOREACH(bus, &busses, next) { 110 if (bus->busnr == busnr) 111 return bus; 112 } 113 return NULL; 114 } 115 116 static void usb_device_realize(USBDevice *dev, Error **errp) 117 { 118 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 119 120 if (klass->realize) { 121 klass->realize(dev, errp); 122 } 123 } 124 125 USBDevice *usb_device_find_device(USBDevice *dev, uint8_t addr) 126 { 127 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 128 if (klass->find_device) { 129 return klass->find_device(dev, addr); 130 } 131 return NULL; 132 } 133 134 static void usb_device_handle_destroy(USBDevice *dev) 135 { 136 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 137 if (klass->handle_destroy) { 138 klass->handle_destroy(dev); 139 } 140 } 141 142 void usb_device_cancel_packet(USBDevice *dev, USBPacket *p) 143 { 144 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 145 if (klass->cancel_packet) { 146 klass->cancel_packet(dev, p); 147 } 148 } 149 150 void usb_device_handle_attach(USBDevice *dev) 151 { 152 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 153 if (klass->handle_attach) { 154 klass->handle_attach(dev); 155 } 156 } 157 158 void usb_device_handle_reset(USBDevice *dev) 159 { 160 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 161 if (klass->handle_reset) { 162 klass->handle_reset(dev); 163 } 164 } 165 166 void usb_device_handle_control(USBDevice *dev, USBPacket *p, int request, 167 int value, int index, int length, uint8_t *data) 168 { 169 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 170 if (klass->handle_control) { 171 klass->handle_control(dev, p, request, value, index, length, data); 172 } 173 } 174 175 void usb_device_handle_data(USBDevice *dev, USBPacket *p) 176 { 177 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 178 if (klass->handle_data) { 179 klass->handle_data(dev, p); 180 } 181 } 182 183 const char *usb_device_get_product_desc(USBDevice *dev) 184 { 185 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 186 return klass->product_desc; 187 } 188 189 const USBDesc *usb_device_get_usb_desc(USBDevice *dev) 190 { 191 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 192 if (dev->usb_desc) { 193 return dev->usb_desc; 194 } 195 return klass->usb_desc; 196 } 197 198 void usb_device_set_interface(USBDevice *dev, int interface, 199 int alt_old, int alt_new) 200 { 201 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 202 if (klass->set_interface) { 203 klass->set_interface(dev, interface, alt_old, alt_new); 204 } 205 } 206 207 void usb_device_flush_ep_queue(USBDevice *dev, USBEndpoint *ep) 208 { 209 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 210 if (klass->flush_ep_queue) { 211 klass->flush_ep_queue(dev, ep); 212 } 213 } 214 215 void usb_device_ep_stopped(USBDevice *dev, USBEndpoint *ep) 216 { 217 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 218 if (klass->ep_stopped) { 219 klass->ep_stopped(dev, ep); 220 } 221 } 222 223 int usb_device_alloc_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps, 224 int streams) 225 { 226 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 227 if (klass->alloc_streams) { 228 return klass->alloc_streams(dev, eps, nr_eps, streams); 229 } 230 return 0; 231 } 232 233 void usb_device_free_streams(USBDevice *dev, USBEndpoint **eps, int nr_eps) 234 { 235 USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev); 236 if (klass->free_streams) { 237 klass->free_streams(dev, eps, nr_eps); 238 } 239 } 240 241 static void usb_qdev_realize(DeviceState *qdev, Error **errp) 242 { 243 USBDevice *dev = USB_DEVICE(qdev); 244 Error *local_err = NULL; 245 246 pstrcpy(dev->product_desc, sizeof(dev->product_desc), 247 usb_device_get_product_desc(dev)); 248 dev->auto_attach = 1; 249 QLIST_INIT(&dev->strings); 250 usb_ep_init(dev); 251 252 usb_claim_port(dev, &local_err); 253 if (local_err) { 254 error_propagate(errp, local_err); 255 return; 256 } 257 258 usb_device_realize(dev, &local_err); 259 if (local_err) { 260 usb_release_port(dev); 261 error_propagate(errp, local_err); 262 return; 263 } 264 265 if (dev->auto_attach) { 266 usb_device_attach(dev, &local_err); 267 if (local_err) { 268 usb_qdev_unrealize(qdev, NULL); 269 error_propagate(errp, local_err); 270 return; 271 } 272 } 273 } 274 275 static void usb_qdev_unrealize(DeviceState *qdev, Error **errp) 276 { 277 USBDevice *dev = USB_DEVICE(qdev); 278 279 if (dev->attached) { 280 usb_device_detach(dev); 281 } 282 usb_device_handle_destroy(dev); 283 if (dev->port) { 284 usb_release_port(dev); 285 } 286 } 287 288 typedef struct LegacyUSBFactory 289 { 290 const char *name; 291 const char *usbdevice_name; 292 USBDevice *(*usbdevice_init)(USBBus *bus, const char *params); 293 } LegacyUSBFactory; 294 295 static GSList *legacy_usb_factory; 296 297 void usb_legacy_register(const char *typename, const char *usbdevice_name, 298 USBDevice *(*usbdevice_init)(USBBus *bus, 299 const char *params)) 300 { 301 if (usbdevice_name) { 302 LegacyUSBFactory *f = g_malloc0(sizeof(*f)); 303 f->name = typename; 304 f->usbdevice_name = usbdevice_name; 305 f->usbdevice_init = usbdevice_init; 306 legacy_usb_factory = g_slist_append(legacy_usb_factory, f); 307 } 308 } 309 310 USBDevice *usb_create(USBBus *bus, const char *name) 311 { 312 DeviceState *dev; 313 314 dev = qdev_create(&bus->qbus, name); 315 return USB_DEVICE(dev); 316 } 317 318 static USBDevice *usb_try_create_simple(USBBus *bus, const char *name, 319 Error **errp) 320 { 321 Error *err = NULL; 322 USBDevice *dev; 323 324 dev = USB_DEVICE(qdev_try_create(&bus->qbus, name)); 325 if (!dev) { 326 error_setg(errp, "Failed to create USB device '%s'", name); 327 return NULL; 328 } 329 object_property_set_bool(OBJECT(dev), true, "realized", &err); 330 if (err) { 331 error_setg(errp, "Failed to initialize USB device '%s': %s", 332 name, error_get_pretty(err)); 333 error_free(err); 334 object_unparent(OBJECT(dev)); 335 return NULL; 336 } 337 return dev; 338 } 339 340 USBDevice *usb_create_simple(USBBus *bus, const char *name) 341 { 342 return usb_try_create_simple(bus, name, &error_abort); 343 } 344 345 static void usb_fill_port(USBPort *port, void *opaque, int index, 346 USBPortOps *ops, int speedmask) 347 { 348 port->opaque = opaque; 349 port->index = index; 350 port->ops = ops; 351 port->speedmask = speedmask; 352 usb_port_location(port, NULL, index + 1); 353 } 354 355 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, 356 USBPortOps *ops, int speedmask) 357 { 358 usb_fill_port(port, opaque, index, ops, speedmask); 359 QTAILQ_INSERT_TAIL(&bus->free, port, next); 360 bus->nfree++; 361 } 362 363 int usb_register_companion(const char *masterbus, USBPort *ports[], 364 uint32_t portcount, uint32_t firstport, 365 void *opaque, USBPortOps *ops, int speedmask) 366 { 367 USBBus *bus; 368 int i; 369 370 QTAILQ_FOREACH(bus, &busses, next) { 371 if (strcmp(bus->qbus.name, masterbus) == 0) { 372 break; 373 } 374 } 375 376 if (!bus || !bus->ops->register_companion) { 377 qerror_report(QERR_INVALID_PARAMETER_VALUE, "masterbus", 378 "an USB masterbus"); 379 if (bus) { 380 error_printf_unless_qmp( 381 "USB bus '%s' does not allow companion controllers\n", 382 masterbus); 383 } 384 return -1; 385 } 386 387 for (i = 0; i < portcount; i++) { 388 usb_fill_port(ports[i], opaque, i, ops, speedmask); 389 } 390 391 return bus->ops->register_companion(bus, ports, portcount, firstport); 392 } 393 394 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr) 395 { 396 if (upstream) { 397 snprintf(downstream->path, sizeof(downstream->path), "%s.%d", 398 upstream->path, portnr); 399 downstream->hubcount = upstream->hubcount + 1; 400 } else { 401 snprintf(downstream->path, sizeof(downstream->path), "%d", portnr); 402 downstream->hubcount = 0; 403 } 404 } 405 406 void usb_unregister_port(USBBus *bus, USBPort *port) 407 { 408 if (port->dev) { 409 object_unparent(OBJECT(port->dev)); 410 } 411 QTAILQ_REMOVE(&bus->free, port, next); 412 bus->nfree--; 413 } 414 415 void usb_claim_port(USBDevice *dev, Error **errp) 416 { 417 USBBus *bus = usb_bus_from_device(dev); 418 USBPort *port; 419 420 assert(dev->port == NULL); 421 422 if (dev->port_path) { 423 QTAILQ_FOREACH(port, &bus->free, next) { 424 if (strcmp(port->path, dev->port_path) == 0) { 425 break; 426 } 427 } 428 if (port == NULL) { 429 error_setg(errp, "usb port %s (bus %s) not found (in use?)", 430 dev->port_path, bus->qbus.name); 431 return; 432 } 433 } else { 434 if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) { 435 /* Create a new hub and chain it on */ 436 usb_try_create_simple(bus, "usb-hub", NULL); 437 } 438 if (bus->nfree == 0) { 439 error_setg(errp, "tried to attach usb device %s to a bus " 440 "with no free ports", dev->product_desc); 441 return; 442 } 443 port = QTAILQ_FIRST(&bus->free); 444 } 445 trace_usb_port_claim(bus->busnr, port->path); 446 447 QTAILQ_REMOVE(&bus->free, port, next); 448 bus->nfree--; 449 450 dev->port = port; 451 port->dev = dev; 452 453 QTAILQ_INSERT_TAIL(&bus->used, port, next); 454 bus->nused++; 455 } 456 457 void usb_release_port(USBDevice *dev) 458 { 459 USBBus *bus = usb_bus_from_device(dev); 460 USBPort *port = dev->port; 461 462 assert(port != NULL); 463 trace_usb_port_release(bus->busnr, port->path); 464 465 QTAILQ_REMOVE(&bus->used, port, next); 466 bus->nused--; 467 468 dev->port = NULL; 469 port->dev = NULL; 470 471 QTAILQ_INSERT_TAIL(&bus->free, port, next); 472 bus->nfree++; 473 } 474 475 static void usb_mask_to_str(char *dest, size_t size, 476 unsigned int speedmask) 477 { 478 static const struct { 479 unsigned int mask; 480 const char *name; 481 } speeds[] = { 482 { .mask = USB_SPEED_MASK_FULL, .name = "full" }, 483 { .mask = USB_SPEED_MASK_HIGH, .name = "high" }, 484 { .mask = USB_SPEED_MASK_SUPER, .name = "super" }, 485 }; 486 int i, pos = 0; 487 488 for (i = 0; i < ARRAY_SIZE(speeds); i++) { 489 if (speeds[i].mask & speedmask) { 490 pos += snprintf(dest + pos, size - pos, "%s%s", 491 pos ? "+" : "", 492 speeds[i].name); 493 } 494 } 495 } 496 497 void usb_check_attach(USBDevice *dev, Error **errp) 498 { 499 USBBus *bus = usb_bus_from_device(dev); 500 USBPort *port = dev->port; 501 char devspeed[32], portspeed[32]; 502 503 assert(port != NULL); 504 assert(!dev->attached); 505 usb_mask_to_str(devspeed, sizeof(devspeed), dev->speedmask); 506 usb_mask_to_str(portspeed, sizeof(portspeed), port->speedmask); 507 trace_usb_port_attach(bus->busnr, port->path, 508 devspeed, portspeed); 509 510 if (!(port->speedmask & dev->speedmask)) { 511 error_setg(errp, "Warning: speed mismatch trying to attach" 512 " usb device \"%s\" (%s speed)" 513 " to bus \"%s\", port \"%s\" (%s speed)", 514 dev->product_desc, devspeed, 515 bus->qbus.name, port->path, portspeed); 516 return; 517 } 518 } 519 520 void usb_device_attach(USBDevice *dev, Error **errp) 521 { 522 USBPort *port = dev->port; 523 Error *local_err = NULL; 524 525 usb_check_attach(dev, &local_err); 526 if (local_err) { 527 error_propagate(errp, local_err); 528 return; 529 } 530 531 dev->attached++; 532 usb_attach(port); 533 } 534 535 int usb_device_detach(USBDevice *dev) 536 { 537 USBBus *bus = usb_bus_from_device(dev); 538 USBPort *port = dev->port; 539 540 assert(port != NULL); 541 assert(dev->attached); 542 trace_usb_port_detach(bus->busnr, port->path); 543 544 usb_detach(port); 545 dev->attached--; 546 return 0; 547 } 548 549 int usb_device_delete_addr(int busnr, int addr) 550 { 551 USBBus *bus; 552 USBPort *port; 553 USBDevice *dev; 554 555 bus = usb_bus_find(busnr); 556 if (!bus) 557 return -1; 558 559 QTAILQ_FOREACH(port, &bus->used, next) { 560 if (port->dev->addr == addr) 561 break; 562 } 563 if (!port) 564 return -1; 565 dev = port->dev; 566 567 object_unparent(OBJECT(dev)); 568 return 0; 569 } 570 571 static const char *usb_speed(unsigned int speed) 572 { 573 static const char *txt[] = { 574 [ USB_SPEED_LOW ] = "1.5", 575 [ USB_SPEED_FULL ] = "12", 576 [ USB_SPEED_HIGH ] = "480", 577 [ USB_SPEED_SUPER ] = "5000", 578 }; 579 if (speed >= ARRAY_SIZE(txt)) 580 return "?"; 581 return txt[speed]; 582 } 583 584 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent) 585 { 586 USBDevice *dev = USB_DEVICE(qdev); 587 USBBus *bus = usb_bus_from_device(dev); 588 589 monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n", 590 indent, "", bus->busnr, dev->addr, 591 dev->port ? dev->port->path : "-", 592 usb_speed(dev->speed), dev->product_desc, 593 dev->attached ? ", attached" : ""); 594 } 595 596 static char *usb_get_dev_path(DeviceState *qdev) 597 { 598 USBDevice *dev = USB_DEVICE(qdev); 599 DeviceState *hcd = qdev->parent_bus->parent; 600 char *id = NULL; 601 602 if (dev->flags & (1 << USB_DEV_FLAG_FULL_PATH)) { 603 id = qdev_get_dev_path(hcd); 604 } 605 if (id) { 606 char *ret = g_strdup_printf("%s/%s", id, dev->port->path); 607 g_free(id); 608 return ret; 609 } else { 610 return g_strdup(dev->port->path); 611 } 612 } 613 614 static char *usb_get_fw_dev_path(DeviceState *qdev) 615 { 616 USBDevice *dev = USB_DEVICE(qdev); 617 char *fw_path, *in; 618 ssize_t pos = 0, fw_len; 619 long nr; 620 621 fw_len = 32 + strlen(dev->port->path) * 6; 622 fw_path = g_malloc(fw_len); 623 in = dev->port->path; 624 while (fw_len - pos > 0) { 625 nr = strtol(in, &in, 10); 626 if (in[0] == '.') { 627 /* some hub between root port and device */ 628 pos += snprintf(fw_path + pos, fw_len - pos, "hub@%lx/", nr); 629 in++; 630 } else { 631 /* the device itself */ 632 pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx", 633 qdev_fw_name(qdev), nr); 634 break; 635 } 636 } 637 return fw_path; 638 } 639 640 void hmp_info_usb(Monitor *mon, const QDict *qdict) 641 { 642 USBBus *bus; 643 USBDevice *dev; 644 USBPort *port; 645 646 if (QTAILQ_EMPTY(&busses)) { 647 monitor_printf(mon, "USB support not enabled\n"); 648 return; 649 } 650 651 QTAILQ_FOREACH(bus, &busses, next) { 652 QTAILQ_FOREACH(port, &bus->used, next) { 653 dev = port->dev; 654 if (!dev) 655 continue; 656 monitor_printf(mon, " Device %d.%d, Port %s, Speed %s Mb/s, Product %s\n", 657 bus->busnr, dev->addr, port->path, usb_speed(dev->speed), 658 dev->product_desc); 659 } 660 } 661 } 662 663 /* handle legacy -usbdevice cmd line option */ 664 USBDevice *usbdevice_create(const char *cmdline) 665 { 666 USBBus *bus = usb_bus_find(-1 /* any */); 667 LegacyUSBFactory *f = NULL; 668 Error *err = NULL; 669 GSList *i; 670 char driver[32]; 671 const char *params; 672 int len; 673 USBDevice *dev; 674 675 params = strchr(cmdline,':'); 676 if (params) { 677 params++; 678 len = params - cmdline; 679 if (len > sizeof(driver)) 680 len = sizeof(driver); 681 pstrcpy(driver, len, cmdline); 682 } else { 683 params = ""; 684 pstrcpy(driver, sizeof(driver), cmdline); 685 } 686 687 for (i = legacy_usb_factory; i; i = i->next) { 688 f = i->data; 689 if (strcmp(f->usbdevice_name, driver) == 0) { 690 break; 691 } 692 } 693 if (i == NULL) { 694 #if 0 695 /* no error because some drivers are not converted (yet) */ 696 error_report("usbdevice %s not found", driver); 697 #endif 698 return NULL; 699 } 700 701 if (!bus) { 702 error_report("Error: no usb bus to attach usbdevice %s, " 703 "please try -machine usb=on and check that " 704 "the machine model supports USB", driver); 705 return NULL; 706 } 707 708 if (f->usbdevice_init) { 709 dev = f->usbdevice_init(bus, params); 710 } else { 711 if (*params) { 712 error_report("usbdevice %s accepts no params", driver); 713 return NULL; 714 } 715 dev = usb_create(bus, f->name); 716 } 717 if (!dev) { 718 error_report("Failed to create USB device '%s'", f->name); 719 return NULL; 720 } 721 object_property_set_bool(OBJECT(dev), true, "realized", &err); 722 if (err) { 723 error_report("Failed to initialize USB device '%s': %s", 724 f->name, error_get_pretty(err)); 725 error_free(err); 726 object_unparent(OBJECT(dev)); 727 return NULL; 728 } 729 return dev; 730 } 731 732 static void usb_device_class_init(ObjectClass *klass, void *data) 733 { 734 DeviceClass *k = DEVICE_CLASS(klass); 735 k->bus_type = TYPE_USB_BUS; 736 k->realize = usb_qdev_realize; 737 k->unrealize = usb_qdev_unrealize; 738 k->props = usb_props; 739 } 740 741 static const TypeInfo usb_device_type_info = { 742 .name = TYPE_USB_DEVICE, 743 .parent = TYPE_DEVICE, 744 .instance_size = sizeof(USBDevice), 745 .abstract = true, 746 .class_size = sizeof(USBDeviceClass), 747 .class_init = usb_device_class_init, 748 }; 749 750 static void usb_register_types(void) 751 { 752 type_register_static(&usb_bus_info); 753 type_register_static(&usb_device_type_info); 754 } 755 756 type_init(usb_register_types) 757