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:
		
							parent
							
								
									a67188743b
								
							
						
					
					
						commit
						2b2325ff64
					
				| 
						 | 
				
			
			@ -226,6 +226,7 @@ trace_file="trace"
 | 
			
		|||
spice=""
 | 
			
		||||
rbd=""
 | 
			
		||||
smartcard_nss=""
 | 
			
		||||
libusb=""
 | 
			
		||||
usb_redir=""
 | 
			
		||||
glx=""
 | 
			
		||||
zlib="yes"
 | 
			
		||||
| 
						 | 
				
			
			@ -890,6 +891,10 @@ for opt do
 | 
			
		|||
  ;;
 | 
			
		||||
  --enable-smartcard-nss) smartcard_nss="yes"
 | 
			
		||||
  ;;
 | 
			
		||||
  --disable-libusb) libusb="no"
 | 
			
		||||
  ;;
 | 
			
		||||
  --enable-libusb) libusb="yes"
 | 
			
		||||
  ;;
 | 
			
		||||
  --disable-usb-redir) usb_redir="no"
 | 
			
		||||
  ;;
 | 
			
		||||
  --enable-usb-redir) usb_redir="yes"
 | 
			
		||||
| 
						 | 
				
			
			@ -1175,6 +1180,8 @@ echo "  --disable-libiscsi       disable iscsi support"
 | 
			
		|||
echo "  --enable-libiscsi        enable iscsi support"
 | 
			
		||||
echo "  --disable-smartcard-nss  disable smartcard nss support"
 | 
			
		||||
echo "  --enable-smartcard-nss   enable smartcard nss support"
 | 
			
		||||
echo "  --disable-libusb         disable libusb (for usb passthrough)"
 | 
			
		||||
echo "  --enable-libusb          enable libusb (for usb passthrough)"
 | 
			
		||||
echo "  --disable-usb-redir      disable usb network redirection support"
 | 
			
		||||
echo "  --enable-usb-redir       enable usb network redirection support"
 | 
			
		||||
echo "  --disable-guest-agent    disable building of the QEMU Guest Agent"
 | 
			
		||||
| 
						 | 
				
			
			@ -3005,6 +3012,23 @@ EOF
 | 
			
		|||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# check for libusb
 | 
			
		||||
if test "$libusb" != "no" ; then
 | 
			
		||||
    if $pkg_config libusb-1.0 >/dev/null 2>&1 ; then
 | 
			
		||||
        libusb="yes"
 | 
			
		||||
	usb="libusb"
 | 
			
		||||
        libusb_cflags=$($pkg_config --cflags libusb-1.0 2>/dev/null)
 | 
			
		||||
        libusb_libs=$($pkg_config --libs libusb-1.0 2>/dev/null)
 | 
			
		||||
        QEMU_CFLAGS="$QEMU_CFLAGS $libusb_cflags"
 | 
			
		||||
        libs_softmmu="$libs_softmmu $libusb_libs"
 | 
			
		||||
    else
 | 
			
		||||
        if test "$libusb" = "yes"; then
 | 
			
		||||
            feature_not_found "libusb"
 | 
			
		||||
        fi
 | 
			
		||||
        libusb="no"
 | 
			
		||||
    fi
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# check for usbredirparser for usb network redirection support
 | 
			
		||||
if test "$usb_redir" != "no" ; then
 | 
			
		||||
    if $pkg_config --atleast-version=0.6 libusbredirparser-0.5 >/dev/null 2>&1 ; then
 | 
			
		||||
| 
						 | 
				
			
			@ -3516,6 +3540,7 @@ echo "spice support     $spice ($spice_protocol_version/$spice_server_version)"
 | 
			
		|||
echo "rbd support       $rbd"
 | 
			
		||||
echo "xfsctl support    $xfs"
 | 
			
		||||
echo "nss used          $smartcard_nss"
 | 
			
		||||
echo "libusb            $libusb"
 | 
			
		||||
echo "usb net redir     $usb_redir"
 | 
			
		||||
echo "GLX support       $glx"
 | 
			
		||||
echo "libiscsi support  $libiscsi"
 | 
			
		||||
| 
						 | 
				
			
			@ -3823,6 +3848,10 @@ if test "$smartcard_nss" = "yes" ; then
 | 
			
		|||
  echo "libcacard_cflags=$libcacard_cflags" >> $config_host_mak
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if test "$libusb" = "yes" ; then
 | 
			
		||||
  echo "CONFIG_USB_LIBUSB=y" >> $config_host_mak
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if test "$usb_redir" = "yes" ; then
 | 
			
		||||
  echo "CONFIG_USB_REDIR=y" >> $config_host_mak
 | 
			
		||||
fi
 | 
			
		||||
| 
						 | 
				
			
			@ -3907,6 +3936,13 @@ linux)
 | 
			
		|||
bsd)
 | 
			
		||||
  echo "HOST_USB=bsd" >> $config_host_mak
 | 
			
		||||
;;
 | 
			
		||||
libusb)
 | 
			
		||||
  if test "$linux" = "yes"; then
 | 
			
		||||
    echo "HOST_USB=libusb linux legacy" >> $config_host_mak
 | 
			
		||||
  else
 | 
			
		||||
    echo "HOST_USB=libusb legacy" >> $config_host_mak
 | 
			
		||||
  fi
 | 
			
		||||
;;
 | 
			
		||||
*)
 | 
			
		||||
  echo "HOST_USB=stub" >> $config_host_mak
 | 
			
		||||
;;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -425,11 +425,15 @@ usb_host_open_success(int bus, int addr) "dev %d:%d"
 | 
			
		|||
usb_host_open_failure(int bus, int addr) "dev %d:%d"
 | 
			
		||||
usb_host_disconnect(int bus, int addr) "dev %d:%d"
 | 
			
		||||
usb_host_close(int bus, int addr) "dev %d:%d"
 | 
			
		||||
usb_host_attach_kernel(int bus, int addr, int interface) "dev %d:%d, if %d"
 | 
			
		||||
usb_host_detach_kernel(int bus, int addr, int interface) "dev %d:%d, if %d"
 | 
			
		||||
usb_host_set_address(int bus, int addr, int config) "dev %d:%d, address %d"
 | 
			
		||||
usb_host_set_config(int bus, int addr, int config) "dev %d:%d, config %d"
 | 
			
		||||
usb_host_set_interface(int bus, int addr, int interface, int alt) "dev %d:%d, interface %d, alt %d"
 | 
			
		||||
usb_host_claim_interfaces(int bus, int addr, int config, int nif) "dev %d:%d, config %d, nif %d"
 | 
			
		||||
usb_host_claim_interface(int bus, int addr, int config, int interface) "dev %d:%d, config %d, if %d"
 | 
			
		||||
usb_host_release_interfaces(int bus, int addr) "dev %d:%d"
 | 
			
		||||
usb_host_release_interface(int bus, int addr, int interface) "dev %d:%d, if %d"
 | 
			
		||||
usb_host_req_control(int bus, int addr, void *p, int req, int value, int index) "dev %d:%d, packet %p, req 0x%x, value %d, index %d"
 | 
			
		||||
usb_host_req_data(int bus, int addr, void *p, int in, int ep, int size) "dev %d:%d, packet %p, in %d, ep %d, size %d"
 | 
			
		||||
usb_host_req_complete(int bus, int addr, void *p, int status, int length) "dev %d:%d, packet %p, status %d, length %d"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue