use libusb for usb-host

Reimplement usb-host on top of libusb.
Reasons to do this:

 (1) Largely rewritten from scratch, nice opportunity to kill historical
     cruft.
 (2) Offload usbfs handling to libusb.
 (3) Have a single portable code base instead of bsd + linux variants.
 (4) Bring usb-host support to any platform supported by libusbx.

For now this goes side-by-side to the existing code.  That is only to
simplify regression testing though, at the end of the day I want remove
the old code and support libusb exclusively.  Merge early in 1.5 cycle,
remove the old code after 1.5 release or something like this.

Thanks to qdev the old and new code can coexist nicely on linux.  Just
use "-device usb-host-linux" to use the old linux driver instead of the
libusb one (which takes over the "usb-host" name).

The bsd driver isn't qdev'ified so it isn't that easy for bsd.
I didn't bother making it runtime switchable, so you have to rebuild
qemu with --disable-libusb to get back the old code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Gerd Hoffmann 2012-11-30 16:02:11 +01:00
parent a67188743b
commit 2b2325ff64
4 changed files with 1501 additions and 2 deletions

1449
hw/usb/host-libusb.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -45,6 +45,12 @@
#include "hw/usb/desc.h"
#include "hw/usb/host.h"
#ifdef CONFIG_USB_LIBUSB
# define DEVNAME "usb-host-linux"
#else
# define DEVNAME "usb-host"
#endif
/* We redefine it to avoid version problems */
struct usb_ctrltransfer {
uint8_t bRequestType;
@ -1487,7 +1493,7 @@ static int usb_host_initfn(USBDevice *dev)
}
static const VMStateDescription vmstate_usb_host = {
.name = "usb-host",
.name = DEVNAME,
.version_id = 1,
.minimum_version_id = 1,
.post_load = usb_host_post_load,
@ -1527,7 +1533,7 @@ static void usb_host_class_initfn(ObjectClass *klass, void *data)
}
static const TypeInfo usb_host_dev_info = {
.name = "usb-host",
.name = DEVNAME,
.parent = TYPE_USB_DEVICE,
.instance_size = sizeof(USBHostDevice),
.class_init = usb_host_class_initfn,
@ -1767,6 +1773,8 @@ static void usb_host_auto_check(void *unused)
qemu_mod_timer(usb_auto_timer, qemu_get_clock_ms(rt_clock) + 2000);
}
#ifndef CONFIG_USB_LIBUSB
/**********************/
/* USB host device info */
@ -1898,3 +1906,5 @@ void usb_host_info(Monitor *mon, const QDict *qdict)
bus, addr, f->port ? f->port : "*", vid, pid);
}
}
#endif