All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] USB support
@ 2005-11-05 14:45 Fabrice Bellard
  2005-11-05 16:31 ` Volker Ruppert
  2005-11-06  2:04 ` [Qemu-devel] " Mark Williamson
  0 siblings, 2 replies; 12+ messages in thread
From: Fabrice Bellard @ 2005-11-05 14:45 UTC (permalink / raw)
  To: qemu-devel

Hi,

I just commited an initial USB support for QEMU. This USB layer will 
ultimately enable QEMU to use some host USB devices and to simulate USB 
devices.

WARNING: the current USB support is for USB hackers only - it is not 
meant to be fully usable yet.

The following features are implemented:

- PCI UHCI USB controller (I finally decided to implement UHCI because I 
know it better than OHCI and because Bochs has a similar driver. Of 
course it would still be very interesting to have an equivalent OHCI 
controller for non PC targets and an EHCI controller for USB 2.0 devices).

- Virtual USB 1.1 hub.

- Linux host USB redirector to use the USB 1.1 host devices which are 
not requested by the host OS (i.e. no host driver is loaded for them). 
It is *very* limited and buggy at the moment, but I was able (once !) to 
mount a disk-on-key flash device.

I plan to implement a USB mouse device as in Bochs just to have at least 
one "useful" virtual USB device to play with. Anyone is free to 
implement other devices by looking at the USB hub implementation in usb.c.

Fabrice.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] USB support
  2005-11-05 14:45 [Qemu-devel] USB support Fabrice Bellard
@ 2005-11-05 16:31 ` Volker Ruppert
  2005-11-05 17:10   ` Fabrice Bellard
  2005-11-06  2:04 ` [Qemu-devel] " Mark Williamson
  1 sibling, 1 reply; 12+ messages in thread
From: Volker Ruppert @ 2005-11-05 16:31 UTC (permalink / raw)
  To: qemu-devel

Hi,

> The following features are implemented:
>
> - PCI UHCI USB controller (I finally decided to implement UHCI because I
> know it better than OHCI and because Bochs has a similar driver. Of
> course it would still be very interesting to have an equivalent OHCI
> controller for non PC targets and an EHCI controller for USB 2.0 devices).

I compared the Qemu USB controller with the Bochs one using Ralph Brown's 
pcifg utility and found two different things.
- Bochs USB appears at function 2 of the PIIX3
- Bochs USB uses PIRQ line INTD
You can find both things in the PIIX3 documentation.

I tried the Qemu USB implementation with Win98 here. The hubs are detected 
correctly, but it makes Win98 hang on shutdown.

> - Linux host USB redirector to use the USB 1.1 host devices which are
> not requested by the host OS (i.e. no host driver is loaded for them).
> It is *very* limited and buggy at the moment, but I was able (once !) to
> mount a disk-on-key flash device.

I guess the host OS doesn't like modifing data on a mounted devices. It might 
be okay for input-only devices. I cannot try it here, since it requires root 
permissions.

--
Bye

Volker

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] USB support
  2005-11-05 16:31 ` Volker Ruppert
@ 2005-11-05 17:10   ` Fabrice Bellard
  2005-11-05 17:24     ` Lonnie Mendez
  2005-11-05 23:39     ` [Qemu-devel] " Matthew Mastracci
  0 siblings, 2 replies; 12+ messages in thread
From: Fabrice Bellard @ 2005-11-05 17:10 UTC (permalink / raw)
  To: qemu-devel

Volker Ruppert wrote:
> Hi,
> 
> 
>>The following features are implemented:
>>
>>- PCI UHCI USB controller (I finally decided to implement UHCI because I
>>know it better than OHCI and because Bochs has a similar driver. Of
>>course it would still be very interesting to have an equivalent OHCI
>>controller for non PC targets and an EHCI controller for USB 2.0 devices).
> 
> 
> I compared the Qemu USB controller with the Bochs one using Ralph Brown's 
> pcifg utility and found two different things.
> - Bochs USB appears at function 2 of the PIIX3
> - Bochs USB uses PIRQ line INTD
> You can find both things in the PIIX3 documentation.

I'll try to update that.

> I tried the Qemu USB implementation with Win98 here. The hubs are detected 
> correctly, but it makes Win98 hang on shutdown.

I only tested with a Linux 2.4 guest OS. The USB mouse is working in X11 
and the USB hubs seem to work too.

>>- Linux host USB redirector to use the USB 1.1 host devices which are
>>not requested by the host OS (i.e. no host driver is loaded for them).
>>It is *very* limited and buggy at the moment, but I was able (once !) to
>>mount a disk-on-key flash device.
> 
> 
> I guess the host OS doesn't like modifing data on a mounted devices. It might 
> be okay for input-only devices. I cannot try it here, since it requires root 
> permissions.

I will add a documentation once it works better, but here are some 
information :

1) The host OS must not use the USB device. It means in particular that 
no host OS driver must be present for that device. The solution I am 
using is to rename the host kernel module "usb-storage.o" to 
"usb-storage.o.disabled" so that it is not loaded by Linux. Then QEMU 
can exclusively access to the corresponding host storage USB device. The 
same apply to every other type of USB devices.

2) In order not to launch QEMU as root, I changed the permissions in 
/proc/bus/usb : chown -R myuid /proc/bus/usb. I am sure it is possible 
to find a better solution !

3) Isosynchronous USB packets are not redirected yet, so host webcams 
have no chance to work.

Fabrice.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] USB support
  2005-11-05 17:10   ` Fabrice Bellard
@ 2005-11-05 17:24     ` Lonnie Mendez
  2005-11-06 14:11       ` Fabrice Bellard
  2005-11-05 23:39     ` [Qemu-devel] " Matthew Mastracci
  1 sibling, 1 reply; 12+ messages in thread
From: Lonnie Mendez @ 2005-11-05 17:24 UTC (permalink / raw)
  To: qemu-devel

On Saturday 05 November 2005 11:10 am, Fabrice Bellard wrote: 
> 1) The host OS must not use the USB device. It means in particular that 
> no host OS driver must be present for that device. The solution I am 
> using is to rename the host kernel module "usb-storage.o" to 
> "usb-storage.o.disabled" so that it is not loaded by Linux. Then QEMU 
> can exclusively access to the corresponding host storage USB device. The 
> same apply to every other type of USB devices.

   usb devfs has a disconnect ioctl (USBDEVFS_DISCONNECT) which
allows you to disconnect a single device from a driver.

   A suggestion is to hook the interface up to qemu monitor.  Then you would 
be able to list usb devices and then claim only the ones you want to use.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] Re: USB support
  2005-11-05 17:10   ` Fabrice Bellard
  2005-11-05 17:24     ` Lonnie Mendez
@ 2005-11-05 23:39     ` Matthew Mastracci
  1 sibling, 0 replies; 12+ messages in thread
From: Matthew Mastracci @ 2005-11-05 23:39 UTC (permalink / raw)
  To: qemu-devel

> 1) The host OS must not use the USB device. It means in particular that 
> no host OS driver must be present for that device. The solution I am 
> using is to rename the host kernel module "usb-storage.o" to 
> "usb-storage.o.disabled" so that it is not loaded by Linux. Then QEMU 
> can exclusively access to the corresponding host storage USB device. The 
> same apply to every other type of USB devices.

For those using Fedora Core (and possibly a number of other Linux 
distributions), you can add your module to /etc/hotplug/blacklist to 
ensure it won't load.  I've been using this trick to get the USB support 
in VMWare to work for some time.

Matt.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] USB support
  2005-11-05 14:45 [Qemu-devel] USB support Fabrice Bellard
  2005-11-05 16:31 ` Volker Ruppert
@ 2005-11-06  2:04 ` Mark Williamson
  2005-11-06  2:10   ` Paul Brook
  1 sibling, 1 reply; 12+ messages in thread
From: Mark Williamson @ 2005-11-06  2:04 UTC (permalink / raw)
  To: qemu-devel

> I just commited an initial USB support for QEMU. This USB layer will
> ultimately enable QEMU to use some host USB devices and to simulate USB
> devices.

Coolness!

> - Linux host USB redirector to use the USB 1.1 host devices which are
> not requested by the host OS (i.e. no host driver is loaded for them).
> It is *very* limited and buggy at the moment, but I was able (once !) to
> mount a disk-on-key flash device.

Had you thought of adding a minimal kernel module to allow "stealing" of host 
drivers for use by QEmu?  When I looked into this, I had the impression that 
the 2.6 USB code ought to be able to support it, although I'm not sure how it 
would interact with the userspace driver layer in your case.

Cheers,
Mark

> I plan to implement a USB mouse device as in Bochs just to have at least
> one "useful" virtual USB device to play with. Anyone is free to
> implement other devices by looking at the USB hub implementation in usb.c.
>
> Fabrice.
>
>
> _______________________________________________
> Qemu-devel mailing list
> Qemu-devel@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/qemu-devel

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] USB support
  2005-11-06  2:04 ` [Qemu-devel] " Mark Williamson
@ 2005-11-06  2:10   ` Paul Brook
  0 siblings, 0 replies; 12+ messages in thread
From: Paul Brook @ 2005-11-06  2:10 UTC (permalink / raw)
  To: qemu-devel

> > - Linux host USB redirector to use the USB 1.1 host devices which are
> > not requested by the host OS (i.e. no host driver is loaded for them).
> > It is *very* limited and buggy at the moment, but I was able (once !) to
> > mount a disk-on-key flash device.
>
> Had you thought of adding a minimal kernel module to allow "stealing" of
> host drivers for use by QEmu?  When I looked into this, I had the
> impression that the 2.6 USB code ought to be able to support it, although
> I'm not sure how it would interact with the userspace driver layer in your
> case.

Someone else already pointed out there's a usbdevfs ioctl for this.

Paul

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] USB support
  2005-11-05 17:24     ` Lonnie Mendez
@ 2005-11-06 14:11       ` Fabrice Bellard
  2005-11-13  1:00         ` [Qemu-devel] [patch] " Oliver Gerlich
  0 siblings, 1 reply; 12+ messages in thread
From: Fabrice Bellard @ 2005-11-06 14:11 UTC (permalink / raw)
  To: qemu-devel

Lonnie Mendez wrote:
> On Saturday 05 November 2005 11:10 am, Fabrice Bellard wrote: 
> 
>>1) The host OS must not use the USB device. It means in particular that 
>>no host OS driver must be present for that device. The solution I am 
>>using is to rename the host kernel module "usb-storage.o" to 
>>"usb-storage.o.disabled" so that it is not loaded by Linux. Then QEMU 
>>can exclusively access to the corresponding host storage USB device. The 
>>same apply to every other type of USB devices.
> 
> 
>    usb devfs has a disconnect ioctl (USBDEVFS_DISCONNECT) which
> allows you to disconnect a single device from a driver.
> 
>    A suggestion is to hook the interface up to qemu monitor.  Then you would 
> be able to list usb devices and then claim only the ones you want to use.

Good idea. I am adding something like that:

In the monitor:

'info usbhost' lists the available host USB devices

'usbhost_add 3.4' or 'usbhost_add 1234:5678' adds the USB host device on 
bus 3 at address 4 or the first one matching the vendor ID 0x1234 and 
product ID 0x5678.

The QEMU option '-usbhost x' can be used to do the same as usbhost_add.

Fabrice.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [patch] USB support
  2005-11-06 14:11       ` Fabrice Bellard
@ 2005-11-13  1:00         ` Oliver Gerlich
  2005-11-13 21:47           ` Fabrice Bellard
  0 siblings, 1 reply; 12+ messages in thread
From: Oliver Gerlich @ 2005-11-13  1:00 UTC (permalink / raw)
  To: qemu-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Fabrice Bellard schrieb:
> Lonnie Mendez wrote:
> 
>> On Saturday 05 November 2005 11:10 am, Fabrice Bellard wrote:
>>
>>> 1) The host OS must not use the USB device. It means in particular
>>> that no host OS driver must be present for that device. The solution
>>> I am using is to rename the host kernel module "usb-storage.o" to
>>> "usb-storage.o.disabled" so that it is not loaded by Linux. Then QEMU
>>> can exclusively access to the corresponding host storage USB device.
>>> The same apply to every other type of USB devices.
>>
>>
>>
>>    usb devfs has a disconnect ioctl (USBDEVFS_DISCONNECT) which
>> allows you to disconnect a single device from a driver.
>>
>>    A suggestion is to hook the interface up to qemu monitor.  Then you
>> would be able to list usb devices and then claim only the ones you
>> want to use.
> 
> 
> Good idea. I am adding something like that:
> 
> In the monitor:
> 
> 'info usbhost' lists the available host USB devices
> 
> 'usbhost_add 3.4' or 'usbhost_add 1234:5678' adds the USB host device on
> bus 3 at address 4 or the first one matching the vendor ID 0x1234 and
> product ID 0x5678.
> 
> The QEMU option '-usbhost x' can be used to do the same as usbhost_add.
> 
> Fabrice.
> 
> 
> _______________________________________________
> Qemu-devel mailing list
> Qemu-devel@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/qemu-devel
> 
> 

When I use usb_add, I get:
USBDEVFS_DISCONNECT: Inappropriate ioctl for device

This is with snapshot from 2005-11-11, on Debian testing, kernel 2.6.13
(with 1000Hz timer).
The patch below fixes this (plainly taken from
http://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg35550.html
; is ifno = 0 correct?)


diff -Naur qemu-snapshot-2005-11-11_23/usb-linux.c
qemu-snapshot-2005-11-11_23-usb/usb-linux.c
- --- qemu-snapshot-2005-11-11_23/usb-linux.c     2005-11-06
17:13:29.000000000 +0
100
+++ qemu-snapshot-2005-11-11_23-usb/usb-linux.c 2005-11-13
01:10:19.000000000 +0
100
@@ -181,7 +181,10 @@

 #ifdef USBDEVFS_DISCONNECT
     /* earlier Linux 2.4 do not support that */
- -    ret = ioctl(fd, USBDEVFS_DISCONNECT);
+    struct usbdevfs_ioctl ctrl;
+    ctrl.ioctl_code = USBDEVFS_DISCONNECT;
+    ctrl.ifno = 0;
+    ret = ioctl(fd, USBDEVFS_IOCTL, &ctrl);
     if (ret < 0 && errno != ENODATA) {
         perror("USBDEVFS_DISCONNECT");
         goto fail;


With this patch, qemu recognized all USB devices I had available - which
is actually only one device, a joystick :)
Win2k showed it in the control panel with all available buttons and axes
and reacted to events correctly.

Though, a strange thing is that as long as the device is attached to the
guest, Windows gets very slow. The Windows task manager shows that the
guest CPU load is at 100%; but "top" on the guest shows that qemu uses
only 20% host CPU. This starts as soon as usb_add is executed, and stops
as soon as usb_del is executed.
Does qemu use sleep in the usb code, or does maybe Windows sent the CPU
a HLT ? I don't really understand that behaviour :)


Regards,
Oliver
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFDdpAWTFOM6DcNJ6cRAjzgAJ4rJlhVBe8thmg3VCBRRs+iw7dCsgCeI8s/
vDSywn5WpfH4vkCNSfEpDvI=
=Djpx
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [Qemu-devel] [patch] USB support
  2005-11-13  1:00         ` [Qemu-devel] [patch] " Oliver Gerlich
@ 2005-11-13 21:47           ` Fabrice Bellard
  0 siblings, 0 replies; 12+ messages in thread
From: Fabrice Bellard @ 2005-11-13 21:47 UTC (permalink / raw)
  To: qemu-devel


> When I use usb_add, I get:
> USBDEVFS_DISCONNECT: Inappropriate ioctl for device
> 
> This is with snapshot from 2005-11-11, on Debian testing, kernel 2.6.13
> (with 1000Hz timer).
> The patch below fixes this (plainly taken from
> http://www.mail-archive.com/linux-usb-devel@lists.sourceforge.net/msg35550.html
> ; is ifno = 0 correct?)

Thank you. I was not able to test this ioctl on my PC, hence the problem...

> With this patch, qemu recognized all USB devices I had available - which
> is actually only one device, a joystick :)
> Win2k showed it in the control panel with all available buttons and axes
> and reacted to events correctly.
> 
> Though, a strange thing is that as long as the device is attached to the
> guest, Windows gets very slow. The Windows task manager shows that the
> guest CPU load is at 100%; but "top" on the guest shows that qemu uses
> only 20% host CPU. This starts as soon as usb_add is executed, and stops
> as soon as usb_del is executed.
> Does qemu use sleep in the usb code, or does maybe Windows sent the CPU
> a HLT ? I don't really understand that behaviour :)

As mentionned in the documentation, the USB host emulation is very slow 
in QEMU. The problem is that USB requests block the whole VM. I plan to 
implement non blocking USB I/Os soon.

Fabrice.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* RE: [Qemu-devel] USB support
  2008-02-09 15:34 Marek Zelem
@ 2008-02-10 13:06 ` Arnon Gilboa
  0 siblings, 0 replies; 12+ messages in thread
From: Arnon Gilboa @ 2008-02-10 13:06 UTC (permalink / raw)
  To: qemu-devel

The multi-config patch is already merged in Qemu 9.1 

-----Original Message-----
From: qemu-devel-bounces+arnong=qumranet.com@nongnu.org
[mailto:qemu-devel-bounces+arnong=qumranet.com@nongnu.org] On Behalf Of
Marek Zelem
Sent: Saturday, February 09, 2008 5:34 PM
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] USB support


    Hi

I want to inform you that I successfully attached my Canon MP830
(printer, scanner, fax) to Qemu via USB.
It was not easy, I had to pass though two stoppages.

1. There is no support for multi port/config (do not know proper term
for that) USB devices in Qemu. Meaning that if single USB device
provides multiple functionalities (like printer, scanner, fax) it will
be rejected by Qemu.
Fortunately there is patch for that available on internet page
http://www.wina.at/uni/html/linux-qemu.html
(qemu-0.9.0-usb-multi-configs.patch).

2. When I applied the patch I hit another issue. When the USB device is
not ready it is automatically switched to HALT state (if I understood it
correctly) and additional ioctl USBDEVFS_CLEAR_HALT is required to give
device another chance. Thus, I have written patch for that issue. The
patch I am sending as attachment.

When I applied both patches, everything worked fine. I suggest to
include those two patches in Qemu.

Best regards

Marek Zelem

--
  e-mail: marek@terminus.sk
  web: http://marek.terminus.sk/
  pgp key: http://marek.terminus.sk/gpg.txt

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Qemu-devel] USB support
@ 2008-02-09 15:34 Marek Zelem
  2008-02-10 13:06 ` Arnon Gilboa
  0 siblings, 1 reply; 12+ messages in thread
From: Marek Zelem @ 2008-02-09 15:34 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1102 bytes --]


    Hi

I want to inform you that I successfully attached my Canon MP830
(printer, scanner, fax) to Qemu via USB.
It was not easy, I had to pass though two stoppages.

1. There is no support for multi port/config (do not know proper term
for that) USB devices in Qemu. Meaning that if single USB device
provides multiple functionalities (like printer, scanner, fax) it will
be rejected by Qemu.
Fortunately there is patch for that available on internet page
http://www.wina.at/uni/html/linux-qemu.html
(qemu-0.9.0-usb-multi-configs.patch).

2. When I applied the patch I hit another issue. When the USB device is
not ready it is automatically switched to HALT state (if I understood it
correctly) and additional ioctl USBDEVFS_CLEAR_HALT is required to give
device another chance. Thus, I have written patch for that issue. The
patch I am sending as attachment.

When I applied both patches, everything worked fine. I suggest to
include those two patches in Qemu.

Best regards

Marek Zelem

--
  e-mail: marek@terminus.sk
  web: http://marek.terminus.sk/
  pgp key: http://marek.terminus.sk/gpg.txt


[-- Attachment #2: qemu-0.9.0-usb-clrhalt.patch --]
[-- Type: text/x-patch, Size: 524 bytes --]

--- usb-linux.c.orig	2008-01-12 12:56:09.000000000 +0100
+++ usb-linux.c	2008-01-12 14:02:47.000000000 +0100
@@ -229,12 +229,14 @@
     if (ret < 0) {
         switch(errno) {
         case ETIMEDOUT:
+	    ret = ioctl(s->fd, USBDEVFS_CLEAR_HALT, &(bt.ep));
             return USB_RET_NAK;
         case EPIPE:
         default:
 #ifdef DEBUG
             printf("handle_data: errno=%d\n", errno);
 #endif
+	    ret = ioctl(s->fd, USBDEVFS_CLEAR_HALT, &(bt.ep));
             return USB_RET_STALL;
         }
     } else {

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2008-02-10 13:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-05 14:45 [Qemu-devel] USB support Fabrice Bellard
2005-11-05 16:31 ` Volker Ruppert
2005-11-05 17:10   ` Fabrice Bellard
2005-11-05 17:24     ` Lonnie Mendez
2005-11-06 14:11       ` Fabrice Bellard
2005-11-13  1:00         ` [Qemu-devel] [patch] " Oliver Gerlich
2005-11-13 21:47           ` Fabrice Bellard
2005-11-05 23:39     ` [Qemu-devel] " Matthew Mastracci
2005-11-06  2:04 ` [Qemu-devel] " Mark Williamson
2005-11-06  2:10   ` Paul Brook
2008-02-09 15:34 Marek Zelem
2008-02-10 13:06 ` Arnon Gilboa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.