xref: /openbmc/qemu/hw/usb/bus.c (revision 786a4ea8)
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 void usb_register_companion(const char *masterbus, USBPort *ports[],
364                             uint32_t portcount, uint32_t firstport,
365                             void *opaque, USBPortOps *ops, int speedmask,
366                             Error **errp)
367 {
368     USBBus *bus;
369     int i;
370 
371     QTAILQ_FOREACH(bus, &busses, next) {
372         if (strcmp(bus->qbus.name, masterbus) == 0) {
373             break;
374         }
375     }
376 
377     if (!bus) {
378         error_setg(errp, "USB bus '%s' not found", masterbus);
379         return;
380     }
381     if (!bus->ops->register_companion) {
382         error_setg(errp, "Can't use USB bus '%s' as masterbus,"
383                    " it doesn't support companion controllers",
384                    masterbus);
385         return;
386     }
387 
388     for (i = 0; i < portcount; i++) {
389         usb_fill_port(ports[i], opaque, i, ops, speedmask);
390     }
391 
392     bus->ops->register_companion(bus, ports, portcount, firstport, errp);
393 }
394 
395 void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
396 {
397     if (upstream) {
398         snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
399                  upstream->path, portnr);
400         downstream->hubcount = upstream->hubcount + 1;
401     } else {
402         snprintf(downstream->path, sizeof(downstream->path), "%d", portnr);
403         downstream->hubcount = 0;
404     }
405 }
406 
407 void usb_unregister_port(USBBus *bus, USBPort *port)
408 {
409     if (port->dev) {
410         object_unparent(OBJECT(port->dev));
411     }
412     QTAILQ_REMOVE(&bus->free, port, next);
413     bus->nfree--;
414 }
415 
416 void usb_claim_port(USBDevice *dev, Error **errp)
417 {
418     USBBus *bus = usb_bus_from_device(dev);
419     USBPort *port;
420 
421     assert(dev->port == NULL);
422 
423     if (dev->port_path) {
424         QTAILQ_FOREACH(port, &bus->free, next) {
425             if (strcmp(port->path, dev->port_path) == 0) {
426                 break;
427             }
428         }
429         if (port == NULL) {
430             error_setg(errp, "usb port %s (bus %s) not found (in use?)",
431                        dev->port_path, bus->qbus.name);
432             return;
433         }
434     } else {
435         if (bus->nfree == 1 && strcmp(object_get_typename(OBJECT(dev)), "usb-hub") != 0) {
436             /* Create a new hub and chain it on */
437             usb_try_create_simple(bus, "usb-hub", NULL);
438         }
439         if (bus->nfree == 0) {
440             error_setg(errp, "tried to attach usb device %s to a bus "
441                        "with no free ports", dev->product_desc);
442             return;
443         }
444         port = QTAILQ_FIRST(&bus->free);
445     }
446     trace_usb_port_claim(bus->busnr, port->path);
447 
448     QTAILQ_REMOVE(&bus->free, port, next);
449     bus->nfree--;
450 
451     dev->port = port;
452     port->dev = dev;
453 
454     QTAILQ_INSERT_TAIL(&bus->used, port, next);
455     bus->nused++;
456 }
457 
458 void usb_release_port(USBDevice *dev)
459 {
460     USBBus *bus = usb_bus_from_device(dev);
461     USBPort *port = dev->port;
462 
463     assert(port != NULL);
464     trace_usb_port_release(bus->busnr, port->path);
465 
466     QTAILQ_REMOVE(&bus->used, port, next);
467     bus->nused--;
468 
469     dev->port = NULL;
470     port->dev = NULL;
471 
472     QTAILQ_INSERT_TAIL(&bus->free, port, next);
473     bus->nfree++;
474 }
475 
476 static void usb_mask_to_str(char *dest, size_t size,
477                             unsigned int speedmask)
478 {
479     static const struct {
480         unsigned int mask;
481         const char *name;
482     } speeds[] = {
483         { .mask = USB_SPEED_MASK_FULL,  .name = "full"  },
484         { .mask = USB_SPEED_MASK_HIGH,  .name = "high"  },
485         { .mask = USB_SPEED_MASK_SUPER, .name = "super" },
486     };
487     int i, pos = 0;
488 
489     for (i = 0; i < ARRAY_SIZE(speeds); i++) {
490         if (speeds[i].mask & speedmask) {
491             pos += snprintf(dest + pos, size - pos, "%s%s",
492                             pos ? "+" : "",
493                             speeds[i].name);
494         }
495     }
496 }
497 
498 void usb_check_attach(USBDevice *dev, Error **errp)
499 {
500     USBBus *bus = usb_bus_from_device(dev);
501     USBPort *port = dev->port;
502     char devspeed[32], portspeed[32];
503 
504     assert(port != NULL);
505     assert(!dev->attached);
506     usb_mask_to_str(devspeed, sizeof(devspeed), dev->speedmask);
507     usb_mask_to_str(portspeed, sizeof(portspeed), port->speedmask);
508     trace_usb_port_attach(bus->busnr, port->path,
509                           devspeed, portspeed);
510 
511     if (!(port->speedmask & dev->speedmask)) {
512         error_setg(errp, "Warning: speed mismatch trying to attach"
513                    " usb device \"%s\" (%s speed)"
514                    " to bus \"%s\", port \"%s\" (%s speed)",
515                    dev->product_desc, devspeed,
516                    bus->qbus.name, port->path, portspeed);
517         return;
518     }
519 }
520 
521 void usb_device_attach(USBDevice *dev, Error **errp)
522 {
523     USBPort *port = dev->port;
524     Error *local_err = NULL;
525 
526     usb_check_attach(dev, &local_err);
527     if (local_err) {
528         error_propagate(errp, local_err);
529         return;
530     }
531 
532     dev->attached++;
533     usb_attach(port);
534 }
535 
536 int usb_device_detach(USBDevice *dev)
537 {
538     USBBus *bus = usb_bus_from_device(dev);
539     USBPort *port = dev->port;
540 
541     assert(port != NULL);
542     assert(dev->attached);
543     trace_usb_port_detach(bus->busnr, port->path);
544 
545     usb_detach(port);
546     dev->attached--;
547     return 0;
548 }
549 
550 int usb_device_delete_addr(int busnr, int addr)
551 {
552     USBBus *bus;
553     USBPort *port;
554     USBDevice *dev;
555 
556     bus = usb_bus_find(busnr);
557     if (!bus)
558         return -1;
559 
560     QTAILQ_FOREACH(port, &bus->used, next) {
561         if (port->dev->addr == addr)
562             break;
563     }
564     if (!port)
565         return -1;
566     dev = port->dev;
567 
568     object_unparent(OBJECT(dev));
569     return 0;
570 }
571 
572 static const char *usb_speed(unsigned int speed)
573 {
574     static const char *txt[] = {
575         [ USB_SPEED_LOW  ] = "1.5",
576         [ USB_SPEED_FULL ] = "12",
577         [ USB_SPEED_HIGH ] = "480",
578         [ USB_SPEED_SUPER ] = "5000",
579     };
580     if (speed >= ARRAY_SIZE(txt))
581         return "?";
582     return txt[speed];
583 }
584 
585 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
586 {
587     USBDevice *dev = USB_DEVICE(qdev);
588     USBBus *bus = usb_bus_from_device(dev);
589 
590     monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n",
591                    indent, "", bus->busnr, dev->addr,
592                    dev->port ? dev->port->path : "-",
593                    usb_speed(dev->speed), dev->product_desc,
594                    dev->attached ? ", attached" : "");
595 }
596 
597 static char *usb_get_dev_path(DeviceState *qdev)
598 {
599     USBDevice *dev = USB_DEVICE(qdev);
600     DeviceState *hcd = qdev->parent_bus->parent;
601     char *id = NULL;
602 
603     if (dev->flags & (1 << USB_DEV_FLAG_FULL_PATH)) {
604         id = qdev_get_dev_path(hcd);
605     }
606     if (id) {
607         char *ret = g_strdup_printf("%s/%s", id, dev->port->path);
608         g_free(id);
609         return ret;
610     } else {
611         return g_strdup(dev->port->path);
612     }
613 }
614 
615 static char *usb_get_fw_dev_path(DeviceState *qdev)
616 {
617     USBDevice *dev = USB_DEVICE(qdev);
618     char *fw_path, *in;
619     ssize_t pos = 0, fw_len;
620     long nr;
621 
622     fw_len = 32 + strlen(dev->port->path) * 6;
623     fw_path = g_malloc(fw_len);
624     in = dev->port->path;
625     while (fw_len - pos > 0) {
626         nr = strtol(in, &in, 10);
627         if (in[0] == '.') {
628             /* some hub between root port and device */
629             pos += snprintf(fw_path + pos, fw_len - pos, "hub@%lx/", nr);
630             in++;
631         } else {
632             /* the device itself */
633             pos += snprintf(fw_path + pos, fw_len - pos, "%s@%lx",
634                             qdev_fw_name(qdev), nr);
635             break;
636         }
637     }
638     return fw_path;
639 }
640 
641 void hmp_info_usb(Monitor *mon, const QDict *qdict)
642 {
643     USBBus *bus;
644     USBDevice *dev;
645     USBPort *port;
646 
647     if (QTAILQ_EMPTY(&busses)) {
648         monitor_printf(mon, "USB support not enabled\n");
649         return;
650     }
651 
652     QTAILQ_FOREACH(bus, &busses, next) {
653         QTAILQ_FOREACH(port, &bus->used, next) {
654             dev = port->dev;
655             if (!dev)
656                 continue;
657             monitor_printf(mon, "  Device %d.%d, Port %s, Speed %s Mb/s, Product %s\n",
658                            bus->busnr, dev->addr, port->path, usb_speed(dev->speed),
659                            dev->product_desc);
660         }
661     }
662 }
663 
664 /* handle legacy -usbdevice cmd line option */
665 USBDevice *usbdevice_create(const char *cmdline)
666 {
667     USBBus *bus = usb_bus_find(-1 /* any */);
668     LegacyUSBFactory *f = NULL;
669     Error *err = NULL;
670     GSList *i;
671     char driver[32];
672     const char *params;
673     int len;
674     USBDevice *dev;
675 
676     params = strchr(cmdline,':');
677     if (params) {
678         params++;
679         len = params - cmdline;
680         if (len > sizeof(driver))
681             len = sizeof(driver);
682         pstrcpy(driver, len, cmdline);
683     } else {
684         params = "";
685         pstrcpy(driver, sizeof(driver), cmdline);
686     }
687 
688     for (i = legacy_usb_factory; i; i = i->next) {
689         f = i->data;
690         if (strcmp(f->usbdevice_name, driver) == 0) {
691             break;
692         }
693     }
694     if (i == NULL) {
695 #if 0
696         /* no error because some drivers are not converted (yet) */
697         error_report("usbdevice %s not found", driver);
698 #endif
699         return NULL;
700     }
701 
702     if (!bus) {
703         error_report("Error: no usb bus to attach usbdevice %s, "
704                      "please try -machine usb=on and check that "
705                      "the machine model supports USB", driver);
706         return NULL;
707     }
708 
709     if (f->usbdevice_init) {
710         dev = f->usbdevice_init(bus, params);
711     } else {
712         if (*params) {
713             error_report("usbdevice %s accepts no params", driver);
714             return NULL;
715         }
716         dev = usb_create(bus, f->name);
717     }
718     if (!dev) {
719         error_report("Failed to create USB device '%s'", f->name);
720         return NULL;
721     }
722     object_property_set_bool(OBJECT(dev), true, "realized", &err);
723     if (err) {
724         error_report("Failed to initialize USB device '%s': %s",
725                      f->name, error_get_pretty(err));
726         error_free(err);
727         object_unparent(OBJECT(dev));
728         return NULL;
729     }
730     return dev;
731 }
732 
733 static void usb_device_class_init(ObjectClass *klass, void *data)
734 {
735     DeviceClass *k = DEVICE_CLASS(klass);
736     k->bus_type = TYPE_USB_BUS;
737     k->realize  = usb_qdev_realize;
738     k->unrealize = usb_qdev_unrealize;
739     k->props    = usb_props;
740 }
741 
742 static const TypeInfo usb_device_type_info = {
743     .name = TYPE_USB_DEVICE,
744     .parent = TYPE_DEVICE,
745     .instance_size = sizeof(USBDevice),
746     .abstract = true,
747     .class_size = sizeof(USBDeviceClass),
748     .class_init = usb_device_class_init,
749 };
750 
751 static void usb_register_types(void)
752 {
753     type_register_static(&usb_bus_info);
754     type_register_static(&usb_device_type_info);
755 }
756 
757 type_init(usb_register_types)
758