1 /* 2 * QEMU USB HUB emulation 3 * 4 * Copyright (c) 2005 Fabrice Bellard 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 * THE SOFTWARE. 23 */ 24 25 #include "qemu/osdep.h" 26 #include "qapi/error.h" 27 #include "qemu/timer.h" 28 #include "trace.h" 29 #include "hw/usb.h" 30 #include "migration/vmstate.h" 31 #include "desc.h" 32 #include "qemu/error-report.h" 33 #include "qemu/module.h" 34 35 #define MAX_PORTS 8 36 37 typedef struct USBHubPort { 38 USBPort port; 39 uint16_t wPortStatus; 40 uint16_t wPortChange; 41 } USBHubPort; 42 43 typedef struct USBHubState { 44 USBDevice dev; 45 USBEndpoint *intr; 46 uint32_t num_ports; 47 bool port_power; 48 QEMUTimer *port_timer; 49 USBHubPort ports[MAX_PORTS]; 50 } USBHubState; 51 52 #define TYPE_USB_HUB "usb-hub" 53 #define USB_HUB(obj) OBJECT_CHECK(USBHubState, (obj), TYPE_USB_HUB) 54 55 #define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE) 56 #define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE) 57 #define GetHubDescriptor (0xa000 | USB_REQ_GET_DESCRIPTOR) 58 #define GetHubStatus (0xa000 | USB_REQ_GET_STATUS) 59 #define GetPortStatus (0xa300 | USB_REQ_GET_STATUS) 60 #define SetHubFeature (0x2000 | USB_REQ_SET_FEATURE) 61 #define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE) 62 63 #define PORT_STAT_CONNECTION 0x0001 64 #define PORT_STAT_ENABLE 0x0002 65 #define PORT_STAT_SUSPEND 0x0004 66 #define PORT_STAT_OVERCURRENT 0x0008 67 #define PORT_STAT_RESET 0x0010 68 #define PORT_STAT_POWER 0x0100 69 #define PORT_STAT_LOW_SPEED 0x0200 70 #define PORT_STAT_HIGH_SPEED 0x0400 71 #define PORT_STAT_TEST 0x0800 72 #define PORT_STAT_INDICATOR 0x1000 73 74 #define PORT_STAT_C_CONNECTION 0x0001 75 #define PORT_STAT_C_ENABLE 0x0002 76 #define PORT_STAT_C_SUSPEND 0x0004 77 #define PORT_STAT_C_OVERCURRENT 0x0008 78 #define PORT_STAT_C_RESET 0x0010 79 80 #define PORT_CONNECTION 0 81 #define PORT_ENABLE 1 82 #define PORT_SUSPEND 2 83 #define PORT_OVERCURRENT 3 84 #define PORT_RESET 4 85 #define PORT_POWER 8 86 #define PORT_LOWSPEED 9 87 #define PORT_HIGHSPEED 10 88 #define PORT_C_CONNECTION 16 89 #define PORT_C_ENABLE 17 90 #define PORT_C_SUSPEND 18 91 #define PORT_C_OVERCURRENT 19 92 #define PORT_C_RESET 20 93 #define PORT_TEST 21 94 #define PORT_INDICATOR 22 95 96 /* same as Linux kernel root hubs */ 97 98 enum { 99 STR_MANUFACTURER = 1, 100 STR_PRODUCT, 101 STR_SERIALNUMBER, 102 }; 103 104 static const USBDescStrings desc_strings = { 105 [STR_MANUFACTURER] = "QEMU", 106 [STR_PRODUCT] = "QEMU USB Hub", 107 [STR_SERIALNUMBER] = "314159", 108 }; 109 110 static const USBDescIface desc_iface_hub = { 111 .bInterfaceNumber = 0, 112 .bNumEndpoints = 1, 113 .bInterfaceClass = USB_CLASS_HUB, 114 .eps = (USBDescEndpoint[]) { 115 { 116 .bEndpointAddress = USB_DIR_IN | 0x01, 117 .bmAttributes = USB_ENDPOINT_XFER_INT, 118 .wMaxPacketSize = 1 + DIV_ROUND_UP(MAX_PORTS, 8), 119 .bInterval = 0xff, 120 }, 121 } 122 }; 123 124 static const USBDescDevice desc_device_hub = { 125 .bcdUSB = 0x0110, 126 .bDeviceClass = USB_CLASS_HUB, 127 .bMaxPacketSize0 = 8, 128 .bNumConfigurations = 1, 129 .confs = (USBDescConfig[]) { 130 { 131 .bNumInterfaces = 1, 132 .bConfigurationValue = 1, 133 .bmAttributes = USB_CFG_ATT_ONE | USB_CFG_ATT_SELFPOWER | 134 USB_CFG_ATT_WAKEUP, 135 .nif = 1, 136 .ifs = &desc_iface_hub, 137 }, 138 }, 139 }; 140 141 static const USBDesc desc_hub = { 142 .id = { 143 .idVendor = 0x0409, 144 .idProduct = 0x55aa, 145 .bcdDevice = 0x0101, 146 .iManufacturer = STR_MANUFACTURER, 147 .iProduct = STR_PRODUCT, 148 .iSerialNumber = STR_SERIALNUMBER, 149 }, 150 .full = &desc_device_hub, 151 .str = desc_strings, 152 }; 153 154 static const uint8_t qemu_hub_hub_descriptor[] = 155 { 156 0x00, /* u8 bLength; patched in later */ 157 0x29, /* u8 bDescriptorType; Hub-descriptor */ 158 0x00, /* u8 bNbrPorts; (patched later) */ 159 0x0a, /* u16 wHubCharacteristics; */ 160 0x00, /* (per-port OC, no power switching) */ 161 0x01, /* u8 bPwrOn2pwrGood; 2ms */ 162 0x00 /* u8 bHubContrCurrent; 0 mA */ 163 164 /* DeviceRemovable and PortPwrCtrlMask patched in later */ 165 }; 166 167 static bool usb_hub_port_change(USBHubPort *port, uint16_t status) 168 { 169 bool notify = false; 170 171 if (status & 0x1f) { 172 port->wPortChange |= status; 173 notify = true; 174 } 175 return notify; 176 } 177 178 static bool usb_hub_port_set(USBHubPort *port, uint16_t status) 179 { 180 if (port->wPortStatus & status) { 181 return false; 182 } 183 port->wPortStatus |= status; 184 return usb_hub_port_change(port, status); 185 } 186 187 static bool usb_hub_port_clear(USBHubPort *port, uint16_t status) 188 { 189 if (!(port->wPortStatus & status)) { 190 return false; 191 } 192 port->wPortStatus &= ~status; 193 return usb_hub_port_change(port, status); 194 } 195 196 static bool usb_hub_port_update(USBHubPort *port) 197 { 198 bool notify = false; 199 200 if (port->port.dev && port->port.dev->attached) { 201 notify = usb_hub_port_set(port, PORT_STAT_CONNECTION); 202 if (port->port.dev->speed == USB_SPEED_LOW) { 203 usb_hub_port_set(port, PORT_STAT_LOW_SPEED); 204 } else { 205 usb_hub_port_clear(port, PORT_STAT_LOW_SPEED); 206 } 207 } 208 return notify; 209 } 210 211 static void usb_hub_port_update_timer(void *opaque) 212 { 213 USBHubState *s = opaque; 214 bool notify = false; 215 int i; 216 217 for (i = 0; i < s->num_ports; i++) { 218 notify |= usb_hub_port_update(&s->ports[i]); 219 } 220 if (notify) { 221 usb_wakeup(s->intr, 0); 222 } 223 } 224 225 static void usb_hub_attach(USBPort *port1) 226 { 227 USBHubState *s = port1->opaque; 228 USBHubPort *port = &s->ports[port1->index]; 229 230 trace_usb_hub_attach(s->dev.addr, port1->index + 1); 231 usb_hub_port_update(port); 232 usb_wakeup(s->intr, 0); 233 } 234 235 static void usb_hub_detach(USBPort *port1) 236 { 237 USBHubState *s = port1->opaque; 238 USBHubPort *port = &s->ports[port1->index]; 239 240 trace_usb_hub_detach(s->dev.addr, port1->index + 1); 241 usb_wakeup(s->intr, 0); 242 243 /* Let upstream know the device on this port is gone */ 244 s->dev.port->ops->child_detach(s->dev.port, port1->dev); 245 246 usb_hub_port_clear(port, PORT_STAT_CONNECTION); 247 usb_hub_port_clear(port, PORT_STAT_ENABLE); 248 usb_hub_port_clear(port, PORT_STAT_SUSPEND); 249 usb_wakeup(s->intr, 0); 250 } 251 252 static void usb_hub_child_detach(USBPort *port1, USBDevice *child) 253 { 254 USBHubState *s = port1->opaque; 255 256 /* Pass along upstream */ 257 s->dev.port->ops->child_detach(s->dev.port, child); 258 } 259 260 static void usb_hub_wakeup(USBPort *port1) 261 { 262 USBHubState *s = port1->opaque; 263 USBHubPort *port = &s->ports[port1->index]; 264 265 if (usb_hub_port_clear(port, PORT_STAT_SUSPEND)) { 266 usb_wakeup(s->intr, 0); 267 } 268 } 269 270 static void usb_hub_complete(USBPort *port, USBPacket *packet) 271 { 272 USBHubState *s = port->opaque; 273 274 /* 275 * Just pass it along upstream for now. 276 * 277 * If we ever implement usb 2.0 split transactions this will 278 * become a little more complicated ... 279 * 280 * Can't use usb_packet_complete() here because packet->owner is 281 * cleared already, go call the ->complete() callback directly 282 * instead. 283 */ 284 s->dev.port->ops->complete(s->dev.port, packet); 285 } 286 287 static USBDevice *usb_hub_find_device(USBDevice *dev, uint8_t addr) 288 { 289 USBHubState *s = USB_HUB(dev); 290 USBHubPort *port; 291 USBDevice *downstream; 292 int i; 293 294 for (i = 0; i < s->num_ports; i++) { 295 port = &s->ports[i]; 296 if (!(port->wPortStatus & PORT_STAT_ENABLE)) { 297 continue; 298 } 299 downstream = usb_find_device(&port->port, addr); 300 if (downstream != NULL) { 301 return downstream; 302 } 303 } 304 return NULL; 305 } 306 307 static void usb_hub_handle_reset(USBDevice *dev) 308 { 309 USBHubState *s = USB_HUB(dev); 310 USBHubPort *port; 311 int i; 312 313 trace_usb_hub_reset(s->dev.addr); 314 for (i = 0; i < s->num_ports; i++) { 315 port = s->ports + i; 316 port->wPortStatus = 0; 317 port->wPortChange = 0; 318 usb_hub_port_set(port, PORT_STAT_POWER); 319 usb_hub_port_update(port); 320 } 321 } 322 323 static const char *feature_name(int feature) 324 { 325 static const char *name[] = { 326 [PORT_CONNECTION] = "connection", 327 [PORT_ENABLE] = "enable", 328 [PORT_SUSPEND] = "suspend", 329 [PORT_OVERCURRENT] = "overcurrent", 330 [PORT_RESET] = "reset", 331 [PORT_POWER] = "power", 332 [PORT_LOWSPEED] = "lowspeed", 333 [PORT_HIGHSPEED] = "highspeed", 334 [PORT_C_CONNECTION] = "change-connection", 335 [PORT_C_ENABLE] = "change-enable", 336 [PORT_C_SUSPEND] = "change-suspend", 337 [PORT_C_OVERCURRENT] = "change-overcurrent", 338 [PORT_C_RESET] = "change-reset", 339 [PORT_TEST] = "test", 340 [PORT_INDICATOR] = "indicator", 341 }; 342 if (feature < 0 || feature >= ARRAY_SIZE(name)) { 343 return "?"; 344 } 345 return name[feature] ?: "?"; 346 } 347 348 static void usb_hub_handle_control(USBDevice *dev, USBPacket *p, 349 int request, int value, int index, int length, uint8_t *data) 350 { 351 USBHubState *s = (USBHubState *)dev; 352 int ret; 353 354 trace_usb_hub_control(s->dev.addr, request, value, index, length); 355 356 ret = usb_desc_handle_control(dev, p, request, value, index, length, data); 357 if (ret >= 0) { 358 return; 359 } 360 361 switch(request) { 362 case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: 363 if (value == 0 && index != 0x81) { /* clear ep halt */ 364 goto fail; 365 } 366 break; 367 /* usb specific requests */ 368 case GetHubStatus: 369 data[0] = 0; 370 data[1] = 0; 371 data[2] = 0; 372 data[3] = 0; 373 p->actual_length = 4; 374 break; 375 case GetPortStatus: 376 { 377 unsigned int n = index - 1; 378 USBHubPort *port; 379 if (n >= s->num_ports) { 380 goto fail; 381 } 382 port = &s->ports[n]; 383 trace_usb_hub_get_port_status(s->dev.addr, index, 384 port->wPortStatus, 385 port->wPortChange); 386 data[0] = port->wPortStatus; 387 data[1] = port->wPortStatus >> 8; 388 data[2] = port->wPortChange; 389 data[3] = port->wPortChange >> 8; 390 p->actual_length = 4; 391 } 392 break; 393 case SetHubFeature: 394 case ClearHubFeature: 395 if (value != 0 && value != 1) { 396 goto fail; 397 } 398 break; 399 case SetPortFeature: 400 { 401 unsigned int n = index - 1; 402 USBHubPort *port; 403 USBDevice *dev; 404 405 trace_usb_hub_set_port_feature(s->dev.addr, index, 406 feature_name(value)); 407 408 if (n >= s->num_ports) { 409 goto fail; 410 } 411 port = &s->ports[n]; 412 dev = port->port.dev; 413 switch(value) { 414 case PORT_SUSPEND: 415 port->wPortStatus |= PORT_STAT_SUSPEND; 416 break; 417 case PORT_RESET: 418 usb_hub_port_set(port, PORT_STAT_RESET); 419 usb_hub_port_clear(port, PORT_STAT_RESET); 420 if (dev && dev->attached) { 421 usb_device_reset(dev); 422 usb_hub_port_set(port, PORT_STAT_ENABLE); 423 } 424 usb_wakeup(s->intr, 0); 425 break; 426 case PORT_POWER: 427 if (s->port_power) { 428 int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); 429 usb_hub_port_set(port, PORT_STAT_POWER); 430 timer_mod(s->port_timer, now + 5000000); /* 5 ms */ 431 } 432 break; 433 default: 434 goto fail; 435 } 436 } 437 break; 438 case ClearPortFeature: 439 { 440 unsigned int n = index - 1; 441 USBHubPort *port; 442 443 trace_usb_hub_clear_port_feature(s->dev.addr, index, 444 feature_name(value)); 445 446 if (n >= s->num_ports) { 447 goto fail; 448 } 449 port = &s->ports[n]; 450 switch(value) { 451 case PORT_ENABLE: 452 port->wPortStatus &= ~PORT_STAT_ENABLE; 453 break; 454 case PORT_C_ENABLE: 455 port->wPortChange &= ~PORT_STAT_C_ENABLE; 456 break; 457 case PORT_SUSPEND: 458 usb_hub_port_clear(port, PORT_STAT_SUSPEND); 459 break; 460 case PORT_C_SUSPEND: 461 port->wPortChange &= ~PORT_STAT_C_SUSPEND; 462 break; 463 case PORT_C_CONNECTION: 464 port->wPortChange &= ~PORT_STAT_C_CONNECTION; 465 break; 466 case PORT_C_OVERCURRENT: 467 port->wPortChange &= ~PORT_STAT_C_OVERCURRENT; 468 break; 469 case PORT_C_RESET: 470 port->wPortChange &= ~PORT_STAT_C_RESET; 471 break; 472 case PORT_POWER: 473 if (s->port_power) { 474 usb_hub_port_clear(port, PORT_STAT_POWER); 475 usb_hub_port_clear(port, PORT_STAT_CONNECTION); 476 usb_hub_port_clear(port, PORT_STAT_ENABLE); 477 usb_hub_port_clear(port, PORT_STAT_SUSPEND); 478 port->wPortChange = 0; 479 } 480 default: 481 goto fail; 482 } 483 } 484 break; 485 case GetHubDescriptor: 486 { 487 unsigned int n, limit, var_hub_size = 0; 488 memcpy(data, qemu_hub_hub_descriptor, 489 sizeof(qemu_hub_hub_descriptor)); 490 data[2] = s->num_ports; 491 492 if (s->port_power) { 493 data[3] &= ~0x03; 494 data[3] |= 0x01; 495 } 496 497 /* fill DeviceRemovable bits */ 498 limit = DIV_ROUND_UP(s->num_ports + 1, 8) + 7; 499 for (n = 7; n < limit; n++) { 500 data[n] = 0x00; 501 var_hub_size++; 502 } 503 504 /* fill PortPwrCtrlMask bits */ 505 limit = limit + DIV_ROUND_UP(s->num_ports, 8); 506 for (;n < limit; n++) { 507 data[n] = 0xff; 508 var_hub_size++; 509 } 510 511 p->actual_length = sizeof(qemu_hub_hub_descriptor) + var_hub_size; 512 data[0] = p->actual_length; 513 break; 514 } 515 default: 516 fail: 517 p->status = USB_RET_STALL; 518 break; 519 } 520 } 521 522 static void usb_hub_handle_data(USBDevice *dev, USBPacket *p) 523 { 524 USBHubState *s = (USBHubState *)dev; 525 526 switch(p->pid) { 527 case USB_TOKEN_IN: 528 if (p->ep->nr == 1) { 529 USBHubPort *port; 530 unsigned int status; 531 uint8_t buf[4]; 532 int i, n; 533 n = DIV_ROUND_UP(s->num_ports + 1, 8); 534 if (p->iov.size == 1) { /* FreeBSD workaround */ 535 n = 1; 536 } else if (n > p->iov.size) { 537 p->status = USB_RET_BABBLE; 538 return; 539 } 540 status = 0; 541 for (i = 0; i < s->num_ports; i++) { 542 port = &s->ports[i]; 543 if (port->wPortChange) 544 status |= (1 << (i + 1)); 545 } 546 if (status != 0) { 547 trace_usb_hub_status_report(s->dev.addr, status); 548 for(i = 0; i < n; i++) { 549 buf[i] = status >> (8 * i); 550 } 551 usb_packet_copy(p, buf, n); 552 } else { 553 p->status = USB_RET_NAK; /* usb11 11.13.1 */ 554 } 555 } else { 556 goto fail; 557 } 558 break; 559 case USB_TOKEN_OUT: 560 default: 561 fail: 562 p->status = USB_RET_STALL; 563 break; 564 } 565 } 566 567 static void usb_hub_unrealize(USBDevice *dev, Error **errp) 568 { 569 USBHubState *s = (USBHubState *)dev; 570 int i; 571 572 for (i = 0; i < s->num_ports; i++) { 573 usb_unregister_port(usb_bus_from_device(dev), 574 &s->ports[i].port); 575 } 576 577 timer_del(s->port_timer); 578 timer_free(s->port_timer); 579 } 580 581 static USBPortOps usb_hub_port_ops = { 582 .attach = usb_hub_attach, 583 .detach = usb_hub_detach, 584 .child_detach = usb_hub_child_detach, 585 .wakeup = usb_hub_wakeup, 586 .complete = usb_hub_complete, 587 }; 588 589 static void usb_hub_realize(USBDevice *dev, Error **errp) 590 { 591 USBHubState *s = USB_HUB(dev); 592 USBHubPort *port; 593 int i; 594 595 if (s->num_ports < 1 || s->num_ports > MAX_PORTS) { 596 error_setg(errp, "num_ports (%d) out of range (1..%d)", 597 s->num_ports, MAX_PORTS); 598 return; 599 } 600 601 if (dev->port->hubcount == 5) { 602 error_setg(errp, "usb hub chain too deep"); 603 return; 604 } 605 606 usb_desc_create_serial(dev); 607 usb_desc_init(dev); 608 s->port_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, 609 usb_hub_port_update_timer, s); 610 s->intr = usb_ep_get(dev, USB_TOKEN_IN, 1); 611 for (i = 0; i < s->num_ports; i++) { 612 port = &s->ports[i]; 613 usb_register_port(usb_bus_from_device(dev), 614 &port->port, s, i, &usb_hub_port_ops, 615 USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL); 616 usb_port_location(&port->port, dev->port, i+1); 617 } 618 usb_hub_handle_reset(dev); 619 } 620 621 static const VMStateDescription vmstate_usb_hub_port = { 622 .name = "usb-hub-port", 623 .version_id = 1, 624 .minimum_version_id = 1, 625 .fields = (VMStateField[]) { 626 VMSTATE_UINT16(wPortStatus, USBHubPort), 627 VMSTATE_UINT16(wPortChange, USBHubPort), 628 VMSTATE_END_OF_LIST() 629 } 630 }; 631 632 static bool usb_hub_port_timer_needed(void *opaque) 633 { 634 USBHubState *s = opaque; 635 636 return s->port_power; 637 } 638 639 static const VMStateDescription vmstate_usb_hub_port_timer = { 640 .name = "usb-hub/port-timer", 641 .version_id = 1, 642 .minimum_version_id = 1, 643 .needed = usb_hub_port_timer_needed, 644 .fields = (VMStateField[]) { 645 VMSTATE_TIMER_PTR(port_timer, USBHubState), 646 VMSTATE_END_OF_LIST() 647 }, 648 }; 649 650 static const VMStateDescription vmstate_usb_hub = { 651 .name = "usb-hub", 652 .version_id = 1, 653 .minimum_version_id = 1, 654 .fields = (VMStateField[]) { 655 VMSTATE_USB_DEVICE(dev, USBHubState), 656 VMSTATE_STRUCT_ARRAY(ports, USBHubState, MAX_PORTS, 0, 657 vmstate_usb_hub_port, USBHubPort), 658 VMSTATE_END_OF_LIST() 659 }, 660 .subsections = (const VMStateDescription * []) { 661 &vmstate_usb_hub_port_timer, 662 NULL 663 } 664 }; 665 666 static Property usb_hub_properties[] = { 667 DEFINE_PROP_UINT32("ports", USBHubState, num_ports, 8), 668 DEFINE_PROP_BOOL("port-power", USBHubState, port_power, false), 669 DEFINE_PROP_END_OF_LIST(), 670 }; 671 672 static void usb_hub_class_initfn(ObjectClass *klass, void *data) 673 { 674 DeviceClass *dc = DEVICE_CLASS(klass); 675 USBDeviceClass *uc = USB_DEVICE_CLASS(klass); 676 677 uc->realize = usb_hub_realize; 678 uc->product_desc = "QEMU USB Hub"; 679 uc->usb_desc = &desc_hub; 680 uc->find_device = usb_hub_find_device; 681 uc->handle_reset = usb_hub_handle_reset; 682 uc->handle_control = usb_hub_handle_control; 683 uc->handle_data = usb_hub_handle_data; 684 uc->unrealize = usb_hub_unrealize; 685 set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); 686 dc->fw_name = "hub"; 687 dc->vmsd = &vmstate_usb_hub; 688 dc->props = usb_hub_properties; 689 } 690 691 static const TypeInfo hub_info = { 692 .name = TYPE_USB_HUB, 693 .parent = TYPE_USB_DEVICE, 694 .instance_size = sizeof(USBHubState), 695 .class_init = usb_hub_class_initfn, 696 }; 697 698 static void usb_hub_register_types(void) 699 { 700 type_register_static(&hub_info); 701 } 702 703 type_init(usb_hub_register_types) 704