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