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