Blame 0333-xhci-move-device-lookup-into-xhci_setup_packet.patch

c8dfc6
From 76d49f5c5abc30f33f5b9288df68d53dba9e10f0 Mon Sep 17 00:00:00 2001
c8dfc6
From: Gerd Hoffmann <kraxel@redhat.com>
c8dfc6
Date: Fri, 24 Aug 2012 14:21:39 +0200
c8dfc6
Subject: [PATCH 333/366] xhci: move device lookup into xhci_setup_packet
c8dfc6
c8dfc6
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
c8dfc6
---
c8dfc6
 hw/usb/hcd-xhci.c | 74 ++++++++++++++++++++++++++++---------------------------
c8dfc6
 1 file changed, 38 insertions(+), 36 deletions(-)
c8dfc6
c8dfc6
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
c8dfc6
index c858b6d..303e1ac 100644
c8dfc6
--- a/hw/usb/hcd-xhci.c
c8dfc6
+++ b/hw/usb/hcd-xhci.c
c8dfc6
@@ -1196,13 +1196,38 @@ static void xhci_stall_ep(XHCITransfer *xfer)
c8dfc6
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer,
c8dfc6
                        XHCIEPContext *epctx);
c8dfc6
 
c8dfc6
-static int xhci_setup_packet(XHCITransfer *xfer, USBDevice *dev)
c8dfc6
+static USBDevice *xhci_find_device(XHCIPort *port, uint8_t addr)
c8dfc6
 {
c8dfc6
+    if (!(port->portsc & PORTSC_PED)) {
c8dfc6
+        return NULL;
c8dfc6
+    }
c8dfc6
+    return usb_find_device(&port->port, addr);
c8dfc6
+}
c8dfc6
+
c8dfc6
+static int xhci_setup_packet(XHCITransfer *xfer)
c8dfc6
+{
c8dfc6
+    XHCIState *xhci = xfer->xhci;
c8dfc6
+    XHCIPort *port;
c8dfc6
+    USBDevice *dev;
c8dfc6
     USBEndpoint *ep;
c8dfc6
     int dir;
c8dfc6
 
c8dfc6
     dir = xfer->in_xfer ? USB_TOKEN_IN : USB_TOKEN_OUT;
c8dfc6
-    ep = usb_ep_get(dev, dir, xfer->epid >> 1);
c8dfc6
+
c8dfc6
+    if (xfer->packet.ep) {
c8dfc6
+        ep = xfer->packet.ep;
c8dfc6
+        dev = ep->dev;
c8dfc6
+    } else {
c8dfc6
+        port = &xhci->ports[xhci->slots[xfer->slotid-1].port-1];
c8dfc6
+        dev = xhci_find_device(port, xhci->slots[xfer->slotid-1].devaddr);
c8dfc6
+        if (!dev) {
c8dfc6
+            fprintf(stderr, "xhci: slot %d port %d has no device\n",
c8dfc6
+                    xfer->slotid, xhci->slots[xfer->slotid-1].port);
c8dfc6
+            return -1;
c8dfc6
+        }
c8dfc6
+        ep = usb_ep_get(dev, dir, xfer->epid >> 1);
c8dfc6
+    }
c8dfc6
+
c8dfc6
     usb_packet_setup(&xfer->packet, dir, ep, xfer->trbs[0].addr);
c8dfc6
     xhci_xfer_map(xfer);
c8dfc6
     DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n",
c8dfc6
@@ -1260,21 +1285,11 @@ static int xhci_complete_packet(XHCITransfer *xfer, int ret)
c8dfc6
     return 0;
c8dfc6
 }
c8dfc6
 
c8dfc6
-static USBDevice *xhci_find_device(XHCIPort *port, uint8_t addr)
c8dfc6
-{
c8dfc6
-    if (!(port->portsc & PORTSC_PED)) {
c8dfc6
-        return NULL;
c8dfc6
-    }
c8dfc6
-    return usb_find_device(&port->port, addr);
c8dfc6
-}
c8dfc6
-
c8dfc6
 static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
c8dfc6
 {
c8dfc6
     XHCITRB *trb_setup, *trb_status;
c8dfc6
     uint8_t bmRequestType;
c8dfc6
     uint16_t wLength;
c8dfc6
-    XHCIPort *port;
c8dfc6
-    USBDevice *dev;
c8dfc6
     int ret;
c8dfc6
 
c8dfc6
     trb_setup = &xfer->trbs[0];
c8dfc6
@@ -1311,21 +1326,15 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
c8dfc6
     bmRequestType = trb_setup->parameter;
c8dfc6
     wLength = trb_setup->parameter >> 48;
c8dfc6
 
c8dfc6
-    port = &xhci->ports[xhci->slots[xfer->slotid-1].port-1];
c8dfc6
-    dev = xhci_find_device(port, xhci->slots[xfer->slotid-1].devaddr);
c8dfc6
-    if (!dev) {
c8dfc6
-        fprintf(stderr, "xhci: slot %d port %d has no device\n", xfer->slotid,
c8dfc6
-                xhci->slots[xfer->slotid-1].port);
c8dfc6
-        return -1;
c8dfc6
-    }
c8dfc6
-
c8dfc6
     xfer->in_xfer = bmRequestType & USB_DIR_IN;
c8dfc6
     xfer->iso_xfer = false;
c8dfc6
 
c8dfc6
-    xhci_setup_packet(xfer, dev);
c8dfc6
+    if (xhci_setup_packet(xfer) < 0) {
c8dfc6
+        return -1;
c8dfc6
+    }
c8dfc6
     xfer->packet.parameter = trb_setup->parameter;
c8dfc6
 
c8dfc6
-    ret = usb_handle_packet(dev, &xfer->packet);
c8dfc6
+    ret = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
c8dfc6
 
c8dfc6
     xhci_complete_packet(xfer, ret);
c8dfc6
     if (!xfer->running_async && !xfer->running_retry) {
c8dfc6
@@ -1336,8 +1345,6 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
c8dfc6
 
c8dfc6
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx)
c8dfc6
 {
c8dfc6
-    XHCIPort *port;
c8dfc6
-    USBDevice *dev;
c8dfc6
     int ret;
c8dfc6
 
c8dfc6
     DPRINTF("xhci_submit(slotid=%d,epid=%d)\n", xfer->slotid, xfer->epid);
c8dfc6
@@ -1350,16 +1357,6 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx
c8dfc6
         xfer->pkts = 0;
c8dfc6
     }
c8dfc6
 
c8dfc6
-    port = &xhci->ports[xhci->slots[xfer->slotid-1].port-1];
c8dfc6
-    dev = xhci_find_device(port, xhci->slots[xfer->slotid-1].devaddr);
c8dfc6
-    if (!dev) {
c8dfc6
-        fprintf(stderr, "xhci: slot %d port %d has no device\n", xfer->slotid,
c8dfc6
-                xhci->slots[xfer->slotid-1].port);
c8dfc6
-        return -1;
c8dfc6
-    }
c8dfc6
-
c8dfc6
-    xhci_setup_packet(xfer, dev);
c8dfc6
-
c8dfc6
     switch(epctx->type) {
c8dfc6
     case ET_INTR_OUT:
c8dfc6
     case ET_INTR_IN:
c8dfc6
@@ -1377,7 +1374,10 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx
c8dfc6
         return -1;
c8dfc6
     }
c8dfc6
 
c8dfc6
-    ret = usb_handle_packet(dev, &xfer->packet);
c8dfc6
+    if (xhci_setup_packet(xfer) < 0) {
c8dfc6
+        return -1;
c8dfc6
+    }
c8dfc6
+    ret = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
c8dfc6
 
c8dfc6
     xhci_complete_packet(xfer, ret);
c8dfc6
     if (!xfer->running_async && !xfer->running_retry) {
c8dfc6
@@ -1420,7 +1420,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid
c8dfc6
 
c8dfc6
         trace_usb_xhci_xfer_retry(xfer);
c8dfc6
         assert(xfer->running_retry);
c8dfc6
-        xhci_setup_packet(xfer, xfer->packet.ep->dev);
c8dfc6
+        if (xhci_setup_packet(xfer) < 0) {
c8dfc6
+            return;
c8dfc6
+        }
c8dfc6
         result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
c8dfc6
         if (result == USB_RET_NAK) {
c8dfc6
             return;
c8dfc6
-- 
c8dfc6
1.7.12
c8dfc6