Skip to contentSkip to conversation

usb, xen: add pvUSB backend

RFC PATCH In review Juergen Gross 2 participants 15 messages Jul 16, 2015 – Jul 17, 2015

lore
Share & tools
lore
#0 lore raw

cover usb, xen: add pvUSB backend

This series adds a Xen pvUSB backend driver to qemu. USB devices connected to the host can be passed through to a Xen guest. The devices are specified via Xenstore. Access to the devices is done via host-libusb.c

I've tested the backend with various USB devices (memory sticks, keyboard, phono preamp, ...).

Juergen Gross (4):
usb: support device specification via <bus>-<port>
usb: add flag to USBPacket to request complete callback after isoc
transfer
xen: introduce dummy system device
xen: add pvUSB backend

 hw/usb/Makefile.objs         |    4 +
 hw/usb/core.c                |    2 +-
 hw/usb/host-legacy.c         |   56 ++-
 hw/usb/host-libusb.c         |   24 +-
 hw/usb/xen-usb.c             | 1130 ++++++++++++++++++++++++++++++++++++++++++
 hw/xenpv/xen_machine_pv.c    |   42 ++
 include/hw/usb.h             |    2 +
 include/hw/xen/xen_backend.h |    4 +
 8 files changed, 1238 insertions(+), 26 deletions(-)
 create mode 100644 hw/usb/xen-usb.c
Signature · 1 line
2.1.4
#1 lore raw

RFC PATCH 1/4 usb: support device specification via <bus>-<port>

Today a host usb device can be specified either via <vendor>:<product> or via <bus>.<device> syntax. Add the possibility to specify it via <bus>-<port> as this is needed for the support of xen pvusb backend.

---
 hw/usb/host-legacy.c | 56 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 33 insertions(+), 23 deletions(-)
hw/usb/host-legacy.c +33 -23
index 3cc9c42..526108c 100644
@@ -53,11 +53,6 @@ static int parse_filter(const char *spec, struct USBAutoFilter *f)
     const char *p = spec;
     int i;
 
-    f->bus_num    = 0;
-    f->addr       = 0;
-    f->vendor_id  = 0;
-    f->product_id = 0;
-
     for (i = BUS; i < DONE; i++) {
         p = strpbrk(p, ":.");
         if (!p) {
@@ -100,32 +95,47 @@ USBDevice *usb_host_device_open(USBBus *bus, const char *devname)
 
     dev = usb_create(bus, "usb-host");
 
+    memset(&filter, 0, sizeof(filter));
+
     if (strstr(devname, "auto:")) {
         if (parse_filter(devname, &filter) < 0) {
             goto fail;
         }
-    } else {
-        p = strchr(devname, '.');
-        if (p) {
-            filter.bus_num    = strtoul(devname, NULL, 0);
-            filter.addr       = strtoul(p + 1, NULL, 0);
-            filter.vendor_id  = 0;
-            filter.product_id = 0;
-        } else {
-            p = strchr(devname, ':');
-            if (p) {
-                filter.bus_num    = 0;
-                filter.addr       = 0;
-                filter.vendor_id  = strtoul(devname, NULL, 16);
-                filter.product_id = strtoul(p + 1, NULL, 16);
-            } else {
-                goto fail;
-            }
-        }
+        goto out;
     }
 
+    /* Check for <bus>-<port> specification. */
+    p = strchr(devname, '-');
+    if (p && p != devname) {
+        filter.bus_num    = strtoul(devname, NULL, 0);
+        filter.port       = p + 1;
+        goto out;
+    }
+
+    /* Check for <bus>.<addr> specification. */
+    p = strchr(devname, '.');
+    if (p) {
+        filter.bus_num    = strtoul(devname, NULL, 0);
+        filter.addr       = strtoul(p + 1, NULL, 0);
+        goto out;
+    }
+
+    /* Check for <vendorid>:<productid> specification. */
+    p = strchr(devname, ':');
+    if (p) {
+        filter.vendor_id  = strtoul(devname, NULL, 16);
+        filter.product_id = strtoul(p + 1, NULL, 16);
+        goto out;
+    }
+
+    goto fail;
+
+out:
     qdev_prop_set_uint32(&dev->qdev, "hostbus",   filter.bus_num);
     qdev_prop_set_uint32(&dev->qdev, "hostaddr",  filter.addr);
+    if (filter.port) {
+        qdev_prop_set_string(&dev->qdev, "port",  filter.port);
+    }
     qdev_prop_set_uint32(&dev->qdev, "vendorid",  filter.vendor_id);
     qdev_prop_set_uint32(&dev->qdev, "productid", filter.product_id);
     qdev_init_nofail(&dev->qdev);
Signature · 1 line
2.1.4
#2 lore raw

Re: [Patch RFC 1/4] usb: support device specification via <bus>-<port>

Quoted 3 lines · Juergen Gross

Today a host usb device can be specified either via <vendor>:<product> or via <bus>.<device> syntax. Add the possibility to specify it via <bus>-<port> as this is needed for the support of xen pvusb backend.

-device usb-host,hostbus=<bus>,hostport=<port> should already do what you want.

hw/usb/host-legacy.c

Quoted 4 lines
hw/usb/host-legacy.c +0 -0
index 3cc9c42..526108c 100644

I don't think we should extend this. This exists purely for backward compatibility reasons.

hw/usb/host-legacy.c USBDevice *usb_host_device_open(USBBus *bus, const char *devname) · line 137

Quoted 5 lines
hw/usb/host-legacy.c +3 -0
+out:
     qdev_prop_set_uint32(&dev->qdev, "hostbus",   filter.bus_num);
     qdev_prop_set_uint32(&dev->qdev, "hostaddr",  filter.addr);
+    if (filter.port) {
+        qdev_prop_set_string(&dev->qdev, "port",  filter.port);

Hmm? This should have been "hostport", right?

cheers,
Gerd

#3 lore raw

Re: [Patch RFC 1/4] usb: support device specification via <bus>-<port>

Quoted 7 lines · Gerd Hoffmann
Quoted 3 lines · Juergen Gross

Today a host usb device can be specified either via <vendor>:<product> or via <bus>.<device> syntax. Add the possibility to specify it via <bus>-<port> as this is needed for the support of xen pvusb backend.

-device usb-host,hostbus=<bus>,hostport=<port> should already do what you want.

The problem is I have to add the device while qemu is already running, so I'm using usb_host_device_open(). To be able to specify the device via <bus>-<port> I have to add the capability to find the device by those parameters.

I haven't found another way to achieve this.

Quoted 8 lines

hw/usb/host-legacy.c

Quoted 4 lines
hw/usb/host-legacy.c +0 -0
index 3cc9c42..526108c 100644

I don't think we should extend this. This exists purely for backward compatibility reasons.

Quoted 7 lines

hw/usb/host-legacy.c USBDevice *usb_host_device_open(USBBus *bus, const char *devname) · line 137

Quoted 5 lines
hw/usb/host-legacy.c +3 -0
+out:
      qdev_prop_set_uint32(&dev->qdev, "hostbus",   filter.bus_num);
      qdev_prop_set_uint32(&dev->qdev, "hostaddr",  filter.addr);
+    if (filter.port) {
+        qdev_prop_set_string(&dev->qdev, "port",  filter.port);

Hmm? This should have been "hostport", right?

Hmm, yes.

Juergen

#4 lore raw

Re: [Patch RFC 1/4] usb: support device specification via <bus>-<port>

Quoted 9 lines · Juergen Gross
Quoted 7 lines · Gerd Hoffmann
Quoted 3 lines · Juergen Gross

Today a host usb device can be specified either via <vendor>:<product> or via <bus>.<device> syntax. Add the possibility to specify it via <bus>-<port> as this is needed for the support of xen pvusb backend.

-device usb-host,hostbus=<bus>,hostport=<port> should already do what you want.

Quoted 6 lines

The problem is I have to add the device while qemu is already running, so I'm using usb_host_device_open(). To be able to specify the device via <bus>-<port> I have to add the capability to find the device by those parameters.

I haven't found another way to achieve this.

device_add monitor command.

cheers,
Gerd

#5 lore raw

Re: [Patch RFC 1/4] usb: support device specification via <bus>-<port>

Quoted 10 lines · Gerd Hoffmann
Quoted 9 lines · Juergen Gross
Quoted 7 lines · Gerd Hoffmann
Quoted 3 lines · Juergen Gross

Today a host usb device can be specified either via <vendor>:<product> or via <bus>.<device> syntax. Add the possibility to specify it via <bus>-<port> as this is needed for the support of xen pvusb backend.

-device usb-host,hostbus=<bus>,hostport=<port> should already do what you want.

Quoted 8 lines
Quoted 6 lines

The problem is I have to add the device while qemu is already running, so I'm using usb_host_device_open(). To be able to specify the device via <bus>-<port> I have to add the capability to find the device by those parameters.

I haven't found another way to achieve this.

device_add monitor command.

Okay. I guess the USBDevice for the added device can be obtained in USBPortOps->attach via USBPort->dev ?

Doing a quick search through the sources I couldn't find a way to issue a monitor command from inside qemu. I assume I'd have to use do_device_add() directly?

Juergen

#6 lore raw

Re: [Patch RFC 1/4] usb: support device specification via <bus>-<port>

Hi,

Quoted 4 lines
Quoted 1 line

device_add monitor command.

Okay. I guess the USBDevice for the added device can be obtained in USBPortOps->attach via USBPort->dev ?

Yes.

Quoted 3 lines

Doing a quick search through the sources I couldn't find a way to issue a monitor command from inside qemu. I assume I'd have to use do_device_add() directly?

qdev_device_add() should do it, yes.
Why do you need to call this from inside qemu? Watching on xenbus and responding to new devices created there?

cheers,
Gerd

#7 lore raw

Re: [Patch RFC 1/4] usb: support device specification via <bus>-<port>

Quoted 9 lines · Gerd Hoffmann
   Hi,
Quoted 4 lines
Quoted 1 line

device_add monitor command.

Okay. I guess the USBDevice for the added device can be obtained in USBPortOps->attach via USBPort->dev ?

Yes.

Quoted 7 lines
Quoted 3 lines

Doing a quick search through the sources I couldn't find a way to issue a monitor command from inside qemu. I assume I'd have to use do_device_add() directly?

qdev_device_add() should do it, yes.
Why do you need to call this from inside qemu? Watching on xenbus and responding to new devices created there?

Exactly.

Juergen

#8 lore raw

RFC PATCH 2/4 usb: add flag to USBPacket to request complete callback after isoc transfer

In reply to Juergen Gross

In order to avoid having to poll for the result of an iso transfer add the possibility to request the "complete" callback which is being used for bulk transfers as well.

---
 hw/usb/core.c        |  2 +-
 hw/usb/host-libusb.c | 24 ++++++++++++++++++++++--
 include/hw/usb.h     |  2 ++
 3 files changed, 25 insertions(+), 3 deletions(-)
hw/usb/core.c +1 -1
index cf34755..bc01713 100644
@@ -428,7 +428,7 @@ void usb_handle_packet(USBDevice *dev, USBPacket *p)
         usb_process_one(p);
         if (p->status == USB_RET_ASYNC) {
             /* hcd drivers cannot handle async for isoc */
-            assert(p->ep->type != USB_ENDPOINT_XFER_ISOC);
+            assert(p->ep->type != USB_ENDPOINT_XFER_ISOC || p->isoc_complete);
             /* using async for interrupt packets breaks migration */
             assert(p->ep->type != USB_ENDPOINT_XFER_INT ||
                    (dev->flags & (1 << USB_DEV_FLAG_IS_HOST)));
hw/usb/host-libusb.c +22 -2
index a5f9dab..9e39b29 100644
@@ -120,6 +120,7 @@ struct USBHostIsoXfer {
     struct libusb_transfer           *xfer;
     bool                             copy_complete;
     unsigned int                     packet;
+    QTAILQ_HEAD(, USBPacket)         callback;
     QTAILQ_ENTRY(USBHostIsoXfer)     next;
 };
 
@@ -432,6 +433,17 @@ static void usb_host_req_abort(USBHostRequest *r)
 
 /* ------------------------------------------------------------------------ */
 
+static void usb_host_iso_xfer_complete(USBHostIsoXfer *xfer)
+{
+    USBHostDevice *s = xfer->ring->host;
+    USBPacket *packet;
+
+    while ((packet = QTAILQ_FIRST(&xfer->callback)) != NULL) {
+        QTAILQ_REMOVE(&xfer->callback, packet, isoc_queue);
+        usb_packet_complete(USB_DEVICE(s), packet);
+    }
+}
+
 static void usb_host_req_complete_iso(struct libusb_transfer *transfer)
 {
     USBHostIsoXfer *xfer = transfer->user_data;
@@ -451,6 +463,7 @@ static void usb_host_req_complete_iso(struct libusb_transfer *transfer)
     if (xfer->ring->ep->pid == USB_TOKEN_IN) {
         QTAILQ_INSERT_TAIL(&xfer->ring->copy, xfer, next);
     } else {
+        usb_host_iso_xfer_complete(xfer);
         QTAILQ_INSERT_TAIL(&xfer->ring->unused, xfer, next);
     }
 }
@@ -654,6 +667,10 @@ static void usb_host_iso_data_out(USBHostDevice *s, USBPacket *p)
         usb_host_iso_reset_xfer(xfer);
         QTAILQ_INSERT_TAIL(&ring->copy, xfer, next);
     }
+    if (p->isoc_complete) {
+        p->status = USB_RET_ASYNC;
+        QTAILQ_INSERT_TAIL(&xfer->callback, p, isoc_queue);
+    }
     usb_host_iso_data_copy(xfer, p);
 
     if (QTAILQ_EMPTY(&ring->inflight)) {
@@ -671,6 +688,7 @@ static void usb_host_iso_data_out(USBHostDevice *s, USBPacket *p)
         rc = libusb_submit_transfer(xfer->xfer);
         if (rc != 0) {
             usb_host_libusb_error("libusb_submit_transfer [iso]", rc);
+            usb_host_iso_xfer_complete(xfer);
             QTAILQ_INSERT_TAIL(&ring->unused, xfer, next);
             if (rc == LIBUSB_ERROR_NO_DEVICE) {
                 disconnect = true;
@@ -1329,8 +1347,10 @@ static void usb_host_handle_data(USBDevice *udev, USBPacket *p)
         } else {
             usb_host_iso_data_out(s, p);
         }
-        trace_usb_host_req_complete(s->bus_num, s->addr, p,
-                                    p->status, p->actual_length);
+        if (p->status != USB_RET_ASYNC) {
+            trace_usb_host_req_complete(s->bus_num, s->addr, p,
+                                        p->status, p->actual_length);
+        }
         return;
     default:
         p->status = USB_RET_STALL;
include/hw/usb.h +2 -0
index b20b959..e8f5a63 100644
@@ -398,6 +398,7 @@ struct USBPacket {
     uint64_t parameter; /* control transfers */
     bool short_not_ok;
     bool int_req;
+    bool isoc_complete;
     int status; /* USB_RET_* status code */
     int actual_length; /* Number of bytes actually transferred */
     /* Internal use by the USB layer.  */
@@ -405,6 +406,7 @@ struct USBPacket {
     USBCombinedPacket *combined;
     QTAILQ_ENTRY(USBPacket) queue;
     QTAILQ_ENTRY(USBPacket) combined_entry;
+    QTAILQ_ENTRY(USBPacket) isoc_queue;
 };
 
 struct USBCombinedPacket {
Signature · 1 line
2.1.4
#9 lore raw

Re: [Patch RFC 2/4] usb: add flag to USBPacket to request complete callback after isoc transfer

Quoted 3 lines · Juergen Gross

In order to avoid having to poll for the result of an iso transfer add the possibility to request the "complete" callback which is being used for bulk transfers as well.

Sorry for the late notice (didn't do much usb coding recently and forgot about it): We actually _have_ a notification mechanism already:
usb_wakeup(USBEndpoint *ep, int streamid). That will trigger a USBPortOps->wakeup callback in the host adapter emulation.

So, the usb-host change should be as simple as this:

hw/usb/host-libusb.c +0 -0
@@ -451,6 +451,7 @@ static void usb_host_req_complete_iso(struct

libusb_transfer *transfer)

     }
     if (xfer->ring->ep->pid == USB_TOKEN_IN) {
         QTAILQ_INSERT_TAIL(&xfer->ring->copy, xfer, next);
+        usb_wakeup(xfer->ring->ep, 0);
     } else {
         QTAILQ_INSERT_TAIL(&xfer->ring->unused, xfer, next);
     }

cheers,
Gerd

#10 lore raw

Re: [Patch RFC 2/4] usb: add flag to USBPacket to request complete callback after isoc transfer

Quoted 22 lines · Gerd Hoffmann
Quoted 3 lines · Juergen Gross

In order to avoid having to poll for the result of an iso transfer add the possibility to request the "complete" callback which is being used for bulk transfers as well.

Sorry for the late notice (didn't do much usb coding recently and forgot about it): We actually _have_ a notification mechanism already:
usb_wakeup(USBEndpoint *ep, int streamid). That will trigger a USBPortOps->wakeup callback in the host adapter emulation.

So, the usb-host change should be as simple as this:

hw/usb/host-libusb.c +1 -0
@@ -451,6 +451,7 @@ static void usb_host_req_complete_iso(struct
 libusb_transfer *transfer)
      }
      if (xfer->ring->ep->pid == USB_TOKEN_IN) {
          QTAILQ_INSERT_TAIL(&xfer->ring->copy, xfer, next);
+        usb_wakeup(xfer->ring->ep, 0);
      } else {
          QTAILQ_INSERT_TAIL(&xfer->ring->unused, xfer, next);
Quoted 1 line
      }

Hmm, I can see the benefit of this call to avoid polling.

OTOH I don't see how to find the packages already processed via this mechanism. To help in my case I'd need:

- the call being made in the else clause
- some way to have a package reference in the endpoint (assuming to use the bus .endpoint_wakeup callback which is called by usb_wakeup(), too).
The problem here is that host-libusb.c would call usb_wakeup() not for each packet, but for each libusb I/O, which is combining multiple packets given to usb_handle_packet().

Juergen

#11 lore raw

Re: [Patch RFC 2/4] usb: add flag to USBPacket to request complete callback after isoc transfer

Quoted 14 lines
Quoted 11 lines
hw/usb/host-libusb.c +1 -0
@@ -451,6 +451,7 @@ static void usb_host_req_complete_iso(struct
 libusb_transfer *transfer)
      }
      if (xfer->ring->ep->pid == USB_TOKEN_IN) {
          QTAILQ_INSERT_TAIL(&xfer->ring->copy, xfer, next);
+        usb_wakeup(xfer->ring->ep, 0);
      } else {
          QTAILQ_INSERT_TAIL(&xfer->ring->unused, xfer, next);
      }

Hmm, I can see the benefit of this call to avoid polling.

Quoted 4 lines

OTOH I don't see how to find the packages already processed via this mechanism. To help in my case I'd need:

- the call being made in the else clause

Hmm. This is for IN transfers, notifying the host adapter "I have data for you, please hand me one (or more) USBPacket which I can fill".

Why do you need it for OUT transfers too? usb-host has copyed and queued up the data already, there is nothing to pass back ...

Quoted 3 lines

- some way to have a package reference in the endpoint (assuming to use the bus .endpoint_wakeup callback which is called by usb_wakeup(), too).

Yes, endpoint callback would be more useful for this. PortOps needs this for remote wakeup implementation.

Quoted 3 lines

The problem here is that host-libusb.c would call usb_wakeup() not for each packet, but for each libusb I/O, which is combining multiple packets given to usb_handle_packet().

You can call just call usb_handle_packet() multiple times, either calculate how often based on time and bandwidth, or continue calling until you get no more data back.

cheers,
Gerd

#12 lore raw

Re: [Patch RFC 2/4] usb: add flag to USBPacket to request complete callback after isoc transfer

Quoted 17 lines · Gerd Hoffmann
Quoted 17 lines
Quoted 11 lines
hw/usb/host-libusb.c +1 -0
@@ -451,6 +451,7 @@ static void usb_host_req_complete_iso(struct
 libusb_transfer *transfer)
       }
       if (xfer->ring->ep->pid == USB_TOKEN_IN) {
           QTAILQ_INSERT_TAIL(&xfer->ring->copy, xfer, next);
+        usb_wakeup(xfer->ring->ep, 0);
       } else {
           QTAILQ_INSERT_TAIL(&xfer->ring->unused, xfer, next);
       }

Hmm, I can see the benefit of this call to avoid polling.

OTOH I don't see how to find the packages already processed via this mechanism. To help in my case I'd need:

Quoted 7 lines
Quoted 1 line

- the call being made in the else clause

Hmm. This is for IN transfers, notifying the host adapter "I have data for you, please hand me one (or more) USBPacket which I can fill".

Why do you need it for OUT transfers too? usb-host has copyed and queued up the data already, there is nothing to pass back ...

Aah, right. The packet->actual_length is filled during the copy. Is this correct? What does libusb return for the single frames? I assume this will be the amount which was sent out to the device, not the size of the frame given to it.

Quoted 7 lines
Quoted 3 lines

- some way to have a package reference in the endpoint (assuming to use the bus .endpoint_wakeup callback which is called by usb_wakeup(), too).

Yes, endpoint callback would be more useful for this. PortOps needs this for remote wakeup implementation.

Quoted 7 lines
Quoted 3 lines

The problem here is that host-libusb.c would call usb_wakeup() not for each packet, but for each libusb I/O, which is combining multiple packets given to usb_handle_packet().

You can call just call usb_handle_packet() multiple times, either calculate how often based on time and bandwidth, or continue calling until you get no more data back.

Understood. That's the polling case I mentioned above.

Juergen

#13 lore raw

RFC PATCH 3/4 xen: introduce dummy system device

In reply to Juergen Gross

Introduce a new dummy system device serving as parent for virtual buses. This will enable new pv backends to introduce virtual buses which are removable again opposed to system buses which are meant to stay once added.

---
 hw/xenpv/xen_machine_pv.c    | 39 +++++++++++++++++++++++++++++++++++++++
 include/hw/xen/xen_backend.h |  1 +
 2 files changed, 40 insertions(+)
hw/xenpv/xen_machine_pv.c +39 -0
index 2e545d2..57bc071 100644
@@ -24,10 +24,15 @@
 
 #include "hw/hw.h"
 #include "hw/boards.h"
+#include "hw/sysbus.h"
 #include "hw/xen/xen_backend.h"
 #include "xen_domainbuild.h"
 #include "sysemu/block-backend.h"
 
+#define TYPE_XENSYSDEV "xensysdev"
+
+DeviceState *xen_sysdev;
+
 static void xen_init_pv(MachineState *machine)
 {
     const char *kernel_filename = machine->kernel_filename;
@@ -59,6 +64,9 @@ static void xen_init_pv(MachineState *machine)
         break;
     }
 
+    xen_sysdev = qdev_create(NULL, TYPE_XENSYSDEV);
+    qdev_init_nofail(xen_sysdev);
+
     xen_be_register("console", &xen_console_ops);
     xen_be_register("vkbd", &xen_kbdmouse_ops);
     xen_be_register("vfb", &xen_framebuffer_ops);
@@ -93,6 +101,31 @@ static void xen_init_pv(MachineState *machine)
     xen_init_display(xen_domid);
 }
 
+static int xen_sysdev_init(SysBusDevice *dev)
+{
+    return 0;
+}
+
+static Property xen_sysdev_properties[] = {
+    {/* end of property list */},
+};
+
+static void xen_sysdev_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+
+    k->init = xen_sysdev_init;
+    dc->props = xen_sysdev_properties;
+}
+
+static const TypeInfo xensysdev_info = {
+    .name          = TYPE_XENSYSDEV,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(SysBusDevice),
+    .class_init    = xen_sysdev_class_init,
+};
+
 static QEMUMachine xenpv_machine = {
     .name = "xenpv",
     .desc = "Xen Para-virtualized PC",
@@ -101,9 +134,15 @@ static QEMUMachine xenpv_machine = {
     .default_machine_opts = "accel=xen",
 };
 
+static void xenpv_register_types(void)
+{
+    type_register_static(&xensysdev_info);
+}
+
 static void xenpv_machine_init(void)
 {
     qemu_register_machine(&xenpv_machine);
 }
 
+type_init(xenpv_register_types)
 machine_init(xenpv_machine_init);
include/hw/xen/xen_backend.h +1 -0
index 3b4125e..911ba6d 100644
@@ -59,6 +59,7 @@ struct XenDevice {
 extern XenXC xen_xc;
 extern struct xs_handle *xenstore;
 extern const char *xen_protocol;
+extern DeviceState *xen_sysdev;
 
 /* xenstore helper functions */
 int xenstore_write_str(const char *base, const char *node, const char *val);
Signature · 1 line
2.1.4
#14 lore raw

RFC PATCH 4/4 xen: add pvUSB backend

In reply to Juergen Gross

Add a backend for para-virtualized USB devices for xen domains.

The backend is using host-libusb to forward USB requests from a domain via libusb to the real device(s) passed through.

---
 hw/usb/Makefile.objs         |    4 +
 hw/usb/xen-usb.c             | 1130 ++++++++++++++++++++++++++++++++++++++++++
 hw/xenpv/xen_machine_pv.c    |    3 +
 include/hw/xen/xen_backend.h |    3 +
 4 files changed, 1140 insertions(+)
 create mode 100644 hw/usb/xen-usb.c
hw/usb/Makefile.objs +4 -0
index 3fe4dff..0253184 100644
@@ -36,3 +36,7 @@ common-obj-$(CONFIG_USB_REDIR) += redirect.o quirks.o
 
 # usb pass-through
 common-obj-y += $(patsubst %,host-%.o,$(HOST_USB))
+
+ifeq ($(CONFIG_USB_LIBUSB),y)
+common-obj-$(CONFIG_XEN_BACKEND) += xen-usb.o
+endif
hw/usb/xen-usb.c new file +1130 -0

1,130 lines not on this page · raw message

hw/xenpv/xen_machine_pv.c +3 -0
index 57bc071..03eb6fe 100644
@@ -72,6 +72,9 @@ static void xen_init_pv(MachineState *machine)
     xen_be_register("vfb", &xen_framebuffer_ops);
     xen_be_register("qdisk", &xen_blkdev_ops);
     xen_be_register("qnic", &xen_netdev_ops);
+#ifdef CONFIG_USB_LIBUSB
+    xen_be_register("vusb", &xen_usb_ops);
+#endif
 
     /* configure framebuffer */
     if (xenfb_enabled) {
include/hw/xen/xen_backend.h +3 -0
index 911ba6d..23527cb 100644
@@ -98,6 +98,9 @@ extern struct XenDevOps xen_kbdmouse_ops;     /* xen_framebuffer.c */
 extern struct XenDevOps xen_framebuffer_ops;  /* xen_framebuffer.c */
 extern struct XenDevOps xen_blkdev_ops;       /* xen_disk.c        */
 extern struct XenDevOps xen_netdev_ops;       /* xen_nic.c         */
+#ifdef CONFIG_USB_LIBUSB
+extern struct XenDevOps xen_usb_ops;          /* xen-usb.c         */
+#endif
 
 void xen_init_display(int domid);
 
Signature · 1 line
2.1.4