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