diff options
Diffstat (limited to 'hw/usb/host-libusb.c')
-rw-r--r-- | hw/usb/host-libusb.c | 94 |
1 files changed, 86 insertions, 8 deletions
diff --git a/hw/usb/host-libusb.c b/hw/usb/host-libusb.c index d1186b8a9f..f3de4591fd 100644 --- a/hw/usb/host-libusb.c +++ b/hw/usb/host-libusb.c @@ -94,7 +94,8 @@ struct USBHostDevice { } ifs[USB_MAX_INTERFACES]; /* callbacks & friends */ - QEMUBH *bh; + QEMUBH *bh_nodev; + QEMUBH *bh_postld; Notifier exit; /* request queues */ @@ -666,6 +667,42 @@ static void usb_host_iso_data_out(USBHostDevice *s, USBPacket *p) /* ------------------------------------------------------------------------ */ +static bool usb_host_full_speed_compat(USBHostDevice *s) +{ + struct libusb_config_descriptor *conf; + const struct libusb_interface_descriptor *intf; + const struct libusb_endpoint_descriptor *endp; + uint8_t type; + int rc, c, i, a, e; + + for (c = 0;; c++) { + rc = libusb_get_config_descriptor(s->dev, c, &conf); + if (rc != 0) { + break; + } + for (i = 0; i < conf->bNumInterfaces; i++) { + for (a = 0; a < conf->interface[i].num_altsetting; a++) { + intf = &conf->interface[i].altsetting[a]; + for (e = 0; e < intf->bNumEndpoints; e++) { + endp = &intf->endpoint[e]; + type = endp->bmAttributes & 0x3; + switch (type) { + case 0x01: /* ISO */ + return false; + case 0x03: /* INTERRUPT */ + if (endp->wMaxPacketSize > 64) { + return false; + } + break; + } + } + } + } + libusb_free_config_descriptor(conf); + } + return true; +} + static void usb_host_ep_update(USBHostDevice *s) { static const char *tname[] = { @@ -757,11 +794,9 @@ static int usb_host_open(USBHostDevice *s, libusb_device *dev) udev->speed = speed_map[libusb_get_device_speed(dev)]; udev->speedmask = (1 << udev->speed); -#if 0 - if (udev->speed == USB_SPEED_HIGH && usb_linux_full_speed_compat(dev)) { + if (udev->speed == USB_SPEED_HIGH && usb_host_full_speed_compat(s)) { udev->speedmask |= USB_SPEED_MASK_FULL; } -#endif if (s->ddesc.iProduct) { libusb_get_string_descriptor_ascii(s->dh, s->ddesc.iProduct, @@ -835,10 +870,10 @@ static void usb_host_nodev_bh(void *opaque) static void usb_host_nodev(USBHostDevice *s) { - if (!s->bh) { - s->bh = qemu_bh_new(usb_host_nodev_bh, s); + if (!s->bh_nodev) { + s->bh_nodev = qemu_bh_new(usb_host_nodev_bh, s); } - qemu_bh_schedule(s->bh); + qemu_bh_schedule(s->bh_nodev); } static void usb_host_exit_notifier(struct Notifier *n, void *data) @@ -1228,9 +1263,52 @@ static void usb_host_handle_reset(USBDevice *udev) usb_host_ep_update(s); } +/* + * This is *NOT* about restoring state. We have absolutely no idea + * what state the host device is in at the moment and whenever it is + * still present in the first place. Attemping to contine where we + * left off is impossible. + * + * What we are going to to to here is emulate a surprise removal of + * the usb device passed through, then kick host scan so the device + * will get re-attached (and re-initialized by the guest) in case it + * is still present. + * + * As the device removal will change the state of other devices (usb + * host controller, most likely interrupt controller too) we have to + * wait with it until *all* vmstate is loaded. Thus post_load just + * kicks a bottom half which then does the actual work. + */ +static void usb_host_post_load_bh(void *opaque) +{ + USBHostDevice *dev = opaque; + USBDevice *udev = USB_DEVICE(dev); + + if (dev->dh != NULL) { + usb_host_close(dev); + } + if (udev->attached) { + usb_device_detach(udev); + } + usb_host_auto_check(NULL); +} + +static int usb_host_post_load(void *opaque, int version_id) +{ + USBHostDevice *dev = opaque; + + if (!dev->bh_postld) { + dev->bh_postld = qemu_bh_new(usb_host_post_load_bh, dev); + } + qemu_bh_schedule(dev->bh_postld); + return 0; +} + static const VMStateDescription vmstate_usb_host = { .name = "usb-host", - .unmigratable = 1, + .version_id = 1, + .minimum_version_id = 1, + .post_load = usb_host_post_load, .fields = (VMStateField[]) { VMSTATE_USB_DEVICE(parent_obj, USBHostDevice), VMSTATE_END_OF_LIST() |