cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
958e1b
From 36b1f983a244521a4dd7293b36b152222aa953ed Mon Sep 17 00:00:00 2001
958e1b
From: Gerd Hoffmann <kraxel@redhat.com>
958e1b
Date: Fri, 11 Jul 2014 14:20:44 +0200
958e1b
Subject: [PATCH 10/43] xhci: Add xhci_epid_to_usbep helper function
958e1b
958e1b
Message-id: <1405088470-24115-12-git-send-email-kraxel@redhat.com>
958e1b
Patchwork-id: 59837
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH 11/37] xhci: Add xhci_epid_to_usbep helper function
958e1b
Bugzilla: 980833
958e1b
RH-Acked-by: Dr. David Alan Gilbert (git) <dgilbert@redhat.com>
958e1b
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
958e1b
958e1b
From: Hans de Goede <hdegoede@redhat.com>
958e1b
958e1b
And use it instead of prying the USBEndpoint out of the packet struct
958e1b
in various places.
958e1b
958e1b
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
958e1b
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
958e1b
(cherry picked from commit 518ad5f2a0754f0a5ce4e478b79f4926ce46111b)
958e1b
---
958e1b
 hw/usb/hcd-xhci.c | 32 ++++++++++++++++++++++----------
958e1b
 1 file changed, 22 insertions(+), 10 deletions(-)
958e1b
958e1b
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
958e1b
---
958e1b
 hw/usb/hcd-xhci.c | 32 ++++++++++++++++++++++----------
958e1b
 1 file changed, 22 insertions(+), 10 deletions(-)
958e1b
958e1b
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
958e1b
index 2daf334..56145a5 100644
958e1b
--- a/hw/usb/hcd-xhci.c
958e1b
+++ b/hw/usb/hcd-xhci.c
958e1b
@@ -511,6 +511,8 @@ static TRBCCode xhci_disable_ep(XHCIState *xhci, unsigned int slotid,
958e1b
                                 unsigned int epid);
958e1b
 static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v);
958e1b
 static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v);
958e1b
+static USBEndpoint *xhci_epid_to_usbep(XHCIState *xhci,
958e1b
+                                       unsigned int slotid, unsigned int epid);
958e1b
 
958e1b
 static const char *TRBType_names[] = {
958e1b
     [TRB_RESERVED]                     = "TRB_RESERVED",
958e1b
@@ -1363,13 +1365,12 @@ static int xhci_ep_nuke_xfers(XHCIState *xhci, unsigned int slotid,
958e1b
 
958e1b
     xferi = epctx->next_xfer;
958e1b
     for (i = 0; i < TD_QUEUE; i++) {
958e1b
-        if (epctx->transfers[xferi].packet.ep) {
958e1b
-            ep = epctx->transfers[xferi].packet.ep;
958e1b
-        }
958e1b
         killed += xhci_ep_nuke_one_xfer(&epctx->transfers[xferi]);
958e1b
         epctx->transfers[xferi].packet.ep = NULL;
958e1b
         xferi = (xferi + 1) % TD_QUEUE;
958e1b
     }
958e1b
+
958e1b
+    ep = xhci_epid_to_usbep(xhci, slotid, epid);
958e1b
     if (ep) {
958e1b
         usb_device_ep_stopped(ep->dev, ep);
958e1b
     }
958e1b
@@ -1701,7 +1702,6 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer,
958e1b
 static int xhci_setup_packet(XHCITransfer *xfer)
958e1b
 {
958e1b
     XHCIState *xhci = xfer->xhci;
958e1b
-    USBDevice *dev;
958e1b
     USBEndpoint *ep;
958e1b
     int dir;
958e1b
 
958e1b
@@ -1709,15 +1709,13 @@ static int xhci_setup_packet(XHCITransfer *xfer)
958e1b
 
958e1b
     if (xfer->packet.ep) {
958e1b
         ep = xfer->packet.ep;
958e1b
-        dev = ep->dev;
958e1b
     } else {
958e1b
-        if (!xhci->slots[xfer->slotid-1].uport) {
958e1b
+        ep = xhci_epid_to_usbep(xhci, xfer->slotid, xfer->epid);
958e1b
+        if (!ep) {
958e1b
             fprintf(stderr, "xhci: slot %d has no device\n",
958e1b
                     xfer->slotid);
958e1b
             return -1;
958e1b
         }
958e1b
-        dev = xhci->slots[xfer->slotid-1].uport->dev;
958e1b
-        ep = usb_ep_get(dev, dir, xfer->epid >> 1);
958e1b
     }
958e1b
 
958e1b
     xhci_xfer_create_sgl(xfer, dir == USB_TOKEN_IN); /* Also sets int_req */
958e1b
@@ -1725,7 +1723,7 @@ static int xhci_setup_packet(XHCITransfer *xfer)
958e1b
                      xfer->trbs[0].addr, false, xfer->int_req);
958e1b
     usb_packet_map(&xfer->packet, &xfer->sgl);
958e1b
     DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n",
958e1b
-            xfer->packet.pid, dev->addr, ep->nr);
958e1b
+            xfer->packet.pid, ep->dev->addr, ep->nr);
958e1b
     return 0;
958e1b
 }
958e1b
 
958e1b
@@ -2077,7 +2075,6 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
958e1b
         } else {
958e1b
             if (xhci_fire_transfer(xhci, xfer, epctx) >= 0) {
958e1b
                 epctx->next_xfer = (epctx->next_xfer + 1) % TD_QUEUE;
958e1b
-                ep = xfer->packet.ep;
958e1b
             } else {
958e1b
                 if (!xfer->timed_xfer) {
958e1b
                     fprintf(stderr, "xhci: error firing data transfer\n");
958e1b
@@ -2094,6 +2091,8 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
958e1b
             break;
958e1b
         }
958e1b
     }
958e1b
+
958e1b
+    ep = xhci_epid_to_usbep(xhci, slotid, epid);
958e1b
     if (ep) {
958e1b
         usb_device_flush_ep_queue(ep->dev, ep);
958e1b
     }
958e1b
@@ -3331,6 +3330,19 @@ static int xhci_find_epid(USBEndpoint *ep)
958e1b
     }
958e1b
 }
958e1b
 
958e1b
+static USBEndpoint *xhci_epid_to_usbep(XHCIState *xhci,
958e1b
+                                       unsigned int slotid, unsigned int epid)
958e1b
+{
958e1b
+    assert(slotid >= 1 && slotid <= xhci->numslots);
958e1b
+
958e1b
+    if (!xhci->slots[slotid - 1].uport) {
958e1b
+        return NULL;
958e1b
+    }
958e1b
+
958e1b
+    return usb_ep_get(xhci->slots[slotid - 1].uport->dev,
958e1b
+                      (epid & 1) ? USB_TOKEN_IN : USB_TOKEN_OUT, epid >> 1);
958e1b
+}
958e1b
+
958e1b
 static void xhci_wakeup_endpoint(USBBus *bus, USBEndpoint *ep,
958e1b
                                  unsigned int stream)
958e1b
 {
958e1b
-- 
958e1b
1.8.3.1
958e1b