Skip to contentSkip to conversation

[5048] husb: support for USB host device auto connect (Max Krasnyansky)

Qemu-devel Anthony Liguori 2 participants 3 messages Aug 21, 2008 – Sep 2, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5048

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5048
Author:   aliguori
Date:     2008-08-21 19:28:55 +0000 (Thu, 21 Aug 2008)

Log Message:
-----------
husb: support for USB host device auto connect (Max Krasnyansky)

QEMU can now automatically grab host USB devices that match the filter. For now I just extended 'host:X.Y' and 'host:VID:PID' syntax to handle wildcards. So for example if you do something like
usb_add host:5.*
QEMU will automatically grab any non-hub device with host address 5.*.

Same with the 'host:PID:*', we grab any device that matches PID.

Filtering itself is very generic so we can probably add more elaborate syntax like 'host:BUS.ADDR:VID:PID'. So that we can do 'host:5.*:6000:*'.

Anyway, it's implemented using a periodic timer that scans host devices and grabs those that match the filter. Timer is started when the first filter is added.

We now keep the list of all host devices that we grabbed to make sure that we do not grab the same device twice.

btw It's currently possible to grab the same host device more than once. ie You can just do "usb_add host:1.1" more than once, which of course does not work. So this patch fixes that issue too.

Along with auto disconnect patch that I send a minute ago the setup is very seamless now. You can just allocate some usb ports to the VMs and plug/unplug devices at any time.

Modified Paths:
--------------
trunk/hw/usb.h
trunk/usb-linux.c
trunk/vl.c

Modified: trunk/hw/usb.h
===================================================================

hw/usb.h +1 -0
@@ -197,6 +197,7 @@
     p->cancel_cb(p, p->cancel_opaque);
 }
 
+int usb_device_add_dev(USBDevice *dev);
 int usb_device_del_addr(int bus_num, int addr);
 void usb_attach(USBPort *port, USBDevice *dev);
 int usb_generic_handle_packet(USBDevice *s, USBPacket *p);

Modified: trunk/usb-linux.c
===================================================================

usb-linux.c +195 -14

304 lines not on this page · raw message

Modified: trunk/vl.c
===================================================================

vl.c +29 -28

79 lines not on this page · raw message

#1 lore raw
Quoted 38 lines · Anthony Liguori

Revision: 5048

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5048
Author:   aliguori
Date:     2008-08-21 19:28:55 +0000 (Thu, 21 Aug 2008)

Log Message:
-----------
husb: support for USB host device auto connect (Max Krasnyansky)

QEMU can now automatically grab host USB devices that match the filter. For now I just extended 'host:X.Y' and 'host:VID:PID' syntax to handle wildcards. So for example if you do something like
usb_add host:5.*
QEMU will automatically grab any non-hub device with host address 5.*.

Same with the 'host:PID:*', we grab any device that matches PID.

Filtering itself is very generic so we can probably add more elaborate syntax like 'host:BUS.ADDR:VID:PID'. So that we can do 'host:5.*:6000:*'.

Anyway, it's implemented using a periodic timer that scans host devices and grabs those that match the filter. Timer is started when the first filter is added.

We now keep the list of all host devices that we grabbed to make sure that we do not grab the same device twice.

btw It's currently possible to grab the same host device more than once. ie You can just do "usb_add host:1.1" more than once, which of course does not work. So this patch fixes that issue too.

Along with auto disconnect patch that I send a minute ago the setup is very seamless now. You can just allocate some usb ports to the VMs and plug/unplug devices at any time.

...

Quoted 56 lines

Modified: trunk/vl.c
===================================================================

vl.c +26 -14
@@ -5747,6 +5747,32 @@
     free_usb_ports = port;
 }
 
+int usb_device_add_dev(USBDevice *dev)
+{
+    USBPort *port;
+
+    /* Find a USB port to add the device to.  */
+    port = free_usb_ports;
+    if (!port->next) {
+        USBDevice *hub;
+
+        /* Create a new hub and chain it on.  */
+        free_usb_ports = NULL;
+        port->next = used_usb_ports;
+        used_usb_ports = port;
+
+        hub = usb_hub_init(VM_USB_HUB_SIZE);
+        usb_attach(port, hub);
+        port = free_usb_ports;
+    }
+
+    free_usb_ports = port->next;
+    port->next = used_usb_ports;
+    used_usb_ports = port;
+    usb_attach(port, dev);
+    return 0;
+}
+
 static int usb_device_add(const char *devname)
 {
     const char *p;
@@ -5787,26 +5813,7 @@
     if (!dev)
         return -1;
 
-    /* Find a USB port to add the device to.  */
-    port = free_usb_ports;
-    if (!port->next) {
-        USBDevice *hub;
-
-        /* Create a new hub and chain it on.  */
-        free_usb_ports = NULL;
-        port->next = used_usb_ports;
-        used_usb_ports = port;
-
-        hub = usb_hub_init(VM_USB_HUB_SIZE);
-        usb_attach(port, hub);
-        port = free_usb_ports;
-    }

vl.c line 5819

Quoted 10 lines
vl.c +1 -6
-
-    free_usb_ports = port->next;
-    port->next = used_usb_ports;
-    used_usb_ports = port;
-    usb_attach(port, dev);
-    return 0;
+    return usb_device_add_dev(dev);
 }
 
 int usb_device_del_addr(int bus_num, int addr)

Same complaint here: Please avoid adding new warnings, it makes tracking my own regressions only harder. ;)

Jan

-------

---
 vl.c |    1 -
 1 file changed, 1 deletion(-)
vl.c +0 -1
Index: b/vl.c
===================================================================
@@ -5779,7 +5779,6 @@ static int usb_device_add(const char *de
 {
     const char *p;
     USBDevice *dev;
-    USBPort *port;
 
     if (!free_usb_ports)
         return -1;
#2 lore raw
Quoted 125 lines · Jan Kiszka
Quoted 38 lines · Anthony Liguori

Revision: 5048

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5048
Author:   aliguori
Date:     2008-08-21 19:28:55 +0000 (Thu, 21 Aug 2008)

Log Message:
-----------
husb: support for USB host device auto connect (Max Krasnyansky)

QEMU can now automatically grab host USB devices that match the filter. For now I just extended 'host:X.Y' and 'host:VID:PID' syntax to handle wildcards. So for example if you do something like
usb_add host:5.*
QEMU will automatically grab any non-hub device with host address 5.*.

Same with the 'host:PID:*', we grab any device that matches PID.

Filtering itself is very generic so we can probably add more elaborate syntax like 'host:BUS.ADDR:VID:PID'. So that we can do 'host:5.*:6000:*'.

Anyway, it's implemented using a periodic timer that scans host devices and grabs those that match the filter. Timer is started when the first filter is added.

We now keep the list of all host devices that we grabbed to make sure that we do not grab the same device twice.

btw It's currently possible to grab the same host device more than once. ie You can just do "usb_add host:1.1" more than once, which of course does not work. So this patch fixes that issue too.

Along with auto disconnect patch that I send a minute ago the setup is very seamless now. You can just allocate some usb ports to the VMs and plug/unplug devices at any time.

...

Quoted 55 lines

Modified: trunk/vl.c
===================================================================

vl.c +26 -14
@@ -5747,6 +5747,32 @@
     free_usb_ports = port;
 }
 
+int usb_device_add_dev(USBDevice *dev)
+{
+    USBPort *port;
+
+    /* Find a USB port to add the device to.  */
+    port = free_usb_ports;
+    if (!port->next) {
+        USBDevice *hub;
+
+        /* Create a new hub and chain it on.  */
+        free_usb_ports = NULL;
+        port->next = used_usb_ports;
+        used_usb_ports = port;
+
+        hub = usb_hub_init(VM_USB_HUB_SIZE);
+        usb_attach(port, hub);
+        port = free_usb_ports;
+    }
+
+    free_usb_ports = port->next;
+    port->next = used_usb_ports;
+    used_usb_ports = port;
+    usb_attach(port, dev);
+    return 0;
+}
+
 static int usb_device_add(const char *devname)
 {
     const char *p;
@@ -5787,26 +5813,7 @@
     if (!dev)
         return -1;
 
-    /* Find a USB port to add the device to.  */
-    port = free_usb_ports;
-    if (!port->next) {
-        USBDevice *hub;
-
-        /* Create a new hub and chain it on.  */
-        free_usb_ports = NULL;
-        port->next = used_usb_ports;
-        used_usb_ports = port;
-
-        hub = usb_hub_init(VM_USB_HUB_SIZE);
-        usb_attach(port, hub);
-        port = free_usb_ports;
-    }

vl.c line 5819

Quoted 10 lines
vl.c +1 -6
-
-    free_usb_ports = port->next;
-    port->next = used_usb_ports;
-    used_usb_ports = port;
-    usb_attach(port, dev);
-    return 0;
+    return usb_device_add_dev(dev);
 }
 
 int usb_device_del_addr(int bus_num, int addr)

Same complaint here: Please avoid adding new warnings, it makes tracking my own regressions only harder. ;)

Jan

-------

---
 vl.c |    1 -
 1 file changed, 1 deletion(-)

Index: b/vl.c
===================================================================

vl.c static int usb_device_add(const char *de · line 5784

Quoted 7 lines
vl.c +0 -1
@@ -5779,7 +5779,6 @@ static int usb_device_add(const char *de
 {
     const char *p;
     USBDevice *dev;
-    USBPort *port;
 
     if (!free_usb_ports)
         return -1;

It's still throwing a warning at me...

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux