dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

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

5544c1
From 2255facbc338e73aa2442e2a1dc13b3474b35f98 Mon Sep 17 00:00:00 2001
Hans de Goede c8dfc6
From: Gerd Hoffmann <kraxel@redhat.com>
Hans de Goede c8dfc6
Date: Fri, 24 Aug 2012 14:21:39 +0200
5544c1
Subject: [PATCH] xhci: move device lookup into xhci_setup_packet
Hans de Goede c8dfc6
Hans de Goede c8dfc6
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Hans de Goede c8dfc6
---
Hans de Goede c8dfc6
 hw/usb/hcd-xhci.c | 74 ++++++++++++++++++++++++++++---------------------------
Hans de Goede c8dfc6
 1 file changed, 38 insertions(+), 36 deletions(-)
Hans de Goede c8dfc6
Hans de Goede c8dfc6
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
5544c1
index 333df59..316a303 100644
Hans de Goede c8dfc6
--- a/hw/usb/hcd-xhci.c
Hans de Goede c8dfc6
+++ b/hw/usb/hcd-xhci.c
Hans de Goede c8dfc6
@@ -1196,13 +1196,38 @@ static void xhci_stall_ep(XHCITransfer *xfer)
Hans de Goede c8dfc6
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer,
Hans de Goede c8dfc6
                        XHCIEPContext *epctx);
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
-static int xhci_setup_packet(XHCITransfer *xfer, USBDevice *dev)
Hans de Goede c8dfc6
+static USBDevice *xhci_find_device(XHCIPort *port, uint8_t addr)
Hans de Goede c8dfc6
 {
Hans de Goede c8dfc6
+    if (!(port->portsc & PORTSC_PED)) {
Hans de Goede c8dfc6
+        return NULL;
Hans de Goede c8dfc6
+    }
Hans de Goede c8dfc6
+    return usb_find_device(&port->port, addr);
Hans de Goede c8dfc6
+}
Hans de Goede c8dfc6
+
Hans de Goede c8dfc6
+static int xhci_setup_packet(XHCITransfer *xfer)
Hans de Goede c8dfc6
+{
Hans de Goede c8dfc6
+    XHCIState *xhci = xfer->xhci;
Hans de Goede c8dfc6
+    XHCIPort *port;
Hans de Goede c8dfc6
+    USBDevice *dev;
Hans de Goede c8dfc6
     USBEndpoint *ep;
Hans de Goede c8dfc6
     int dir;
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
     dir = xfer->in_xfer ? USB_TOKEN_IN : USB_TOKEN_OUT;
Hans de Goede c8dfc6
-    ep = usb_ep_get(dev, dir, xfer->epid >> 1);
Hans de Goede c8dfc6
+
Hans de Goede c8dfc6
+    if (xfer->packet.ep) {
Hans de Goede c8dfc6
+        ep = xfer->packet.ep;
Hans de Goede c8dfc6
+        dev = ep->dev;
Hans de Goede c8dfc6
+    } else {
Hans de Goede c8dfc6
+        port = &xhci->ports[xhci->slots[xfer->slotid-1].port-1];
Hans de Goede c8dfc6
+        dev = xhci_find_device(port, xhci->slots[xfer->slotid-1].devaddr);
Hans de Goede c8dfc6
+        if (!dev) {
Hans de Goede c8dfc6
+            fprintf(stderr, "xhci: slot %d port %d has no device\n",
Hans de Goede c8dfc6
+                    xfer->slotid, xhci->slots[xfer->slotid-1].port);
Hans de Goede c8dfc6
+            return -1;
Hans de Goede c8dfc6
+        }
Hans de Goede c8dfc6
+        ep = usb_ep_get(dev, dir, xfer->epid >> 1);
Hans de Goede c8dfc6
+    }
Hans de Goede c8dfc6
+
Hans de Goede c8dfc6
     usb_packet_setup(&xfer->packet, dir, ep, xfer->trbs[0].addr);
Hans de Goede c8dfc6
     xhci_xfer_map(xfer);
Hans de Goede c8dfc6
     DPRINTF("xhci: setup packet pid 0x%x addr %d ep %d\n",
Hans de Goede 93b7e3
@@ -1260,20 +1285,10 @@ static int xhci_complete_packet(XHCITransfer *xfer, int ret)
Hans de Goede c8dfc6
     return 0;
Hans de Goede c8dfc6
 }
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
-static USBDevice *xhci_find_device(XHCIPort *port, uint8_t addr)
Hans de Goede c8dfc6
-{
Hans de Goede c8dfc6
-    if (!(port->portsc & PORTSC_PED)) {
Hans de Goede c8dfc6
-        return NULL;
Hans de Goede c8dfc6
-    }
Hans de Goede c8dfc6
-    return usb_find_device(&port->port, addr);
Hans de Goede c8dfc6
-}
Hans de Goede c8dfc6
-
Hans de Goede c8dfc6
 static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
Hans de Goede c8dfc6
 {
Hans de Goede c8dfc6
     XHCITRB *trb_setup, *trb_status;
Hans de Goede c8dfc6
     uint8_t bmRequestType;
Hans de Goede c8dfc6
-    XHCIPort *port;
Hans de Goede c8dfc6
-    USBDevice *dev;
Hans de Goede c8dfc6
     int ret;
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
     trb_setup = &xfer->trbs[0];
Hans de Goede 93b7e3
@@ -1309,21 +1324,15 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
Hans de Goede 93b7e3
 
Hans de Goede c8dfc6
     bmRequestType = trb_setup->parameter;
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
-    port = &xhci->ports[xhci->slots[xfer->slotid-1].port-1];
Hans de Goede c8dfc6
-    dev = xhci_find_device(port, xhci->slots[xfer->slotid-1].devaddr);
Hans de Goede c8dfc6
-    if (!dev) {
Hans de Goede c8dfc6
-        fprintf(stderr, "xhci: slot %d port %d has no device\n", xfer->slotid,
Hans de Goede c8dfc6
-                xhci->slots[xfer->slotid-1].port);
Hans de Goede c8dfc6
-        return -1;
Hans de Goede c8dfc6
-    }
Hans de Goede c8dfc6
-
Hans de Goede c8dfc6
     xfer->in_xfer = bmRequestType & USB_DIR_IN;
Hans de Goede c8dfc6
     xfer->iso_xfer = false;
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
-    xhci_setup_packet(xfer, dev);
Hans de Goede c8dfc6
+    if (xhci_setup_packet(xfer) < 0) {
Hans de Goede c8dfc6
+        return -1;
Hans de Goede c8dfc6
+    }
Hans de Goede c8dfc6
     xfer->packet.parameter = trb_setup->parameter;
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
-    ret = usb_handle_packet(dev, &xfer->packet);
Hans de Goede c8dfc6
+    ret = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
     xhci_complete_packet(xfer, ret);
Hans de Goede c8dfc6
     if (!xfer->running_async && !xfer->running_retry) {
Hans de Goede 93b7e3
@@ -1334,8 +1343,6 @@ static int xhci_fire_ctl_transfer(XHCIState *xhci, XHCITransfer *xfer)
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
 static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx)
Hans de Goede c8dfc6
 {
Hans de Goede c8dfc6
-    XHCIPort *port;
Hans de Goede c8dfc6
-    USBDevice *dev;
Hans de Goede c8dfc6
     int ret;
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
     DPRINTF("xhci_submit(slotid=%d,epid=%d)\n", xfer->slotid, xfer->epid);
Hans de Goede 93b7e3
@@ -1348,16 +1355,6 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx
Hans de Goede c8dfc6
         xfer->pkts = 0;
Hans de Goede c8dfc6
     }
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
-    port = &xhci->ports[xhci->slots[xfer->slotid-1].port-1];
Hans de Goede c8dfc6
-    dev = xhci_find_device(port, xhci->slots[xfer->slotid-1].devaddr);
Hans de Goede c8dfc6
-    if (!dev) {
Hans de Goede c8dfc6
-        fprintf(stderr, "xhci: slot %d port %d has no device\n", xfer->slotid,
Hans de Goede c8dfc6
-                xhci->slots[xfer->slotid-1].port);
Hans de Goede c8dfc6
-        return -1;
Hans de Goede c8dfc6
-    }
Hans de Goede c8dfc6
-
Hans de Goede c8dfc6
-    xhci_setup_packet(xfer, dev);
Hans de Goede c8dfc6
-
Hans de Goede c8dfc6
     switch(epctx->type) {
Hans de Goede c8dfc6
     case ET_INTR_OUT:
Hans de Goede c8dfc6
     case ET_INTR_IN:
Hans de Goede 93b7e3
@@ -1375,7 +1372,10 @@ static int xhci_submit(XHCIState *xhci, XHCITransfer *xfer, XHCIEPContext *epctx
Hans de Goede c8dfc6
         return -1;
Hans de Goede c8dfc6
     }
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
-    ret = usb_handle_packet(dev, &xfer->packet);
Hans de Goede c8dfc6
+    if (xhci_setup_packet(xfer) < 0) {
Hans de Goede c8dfc6
+        return -1;
Hans de Goede c8dfc6
+    }
Hans de Goede c8dfc6
+    ret = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
     xhci_complete_packet(xfer, ret);
Hans de Goede c8dfc6
     if (!xfer->running_async && !xfer->running_retry) {
Hans de Goede 93b7e3
@@ -1418,7 +1418,9 @@ static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid, unsigned int epid
Hans de Goede c8dfc6
 
Hans de Goede c8dfc6
         trace_usb_xhci_xfer_retry(xfer);
Hans de Goede c8dfc6
         assert(xfer->running_retry);
Hans de Goede c8dfc6
-        xhci_setup_packet(xfer, xfer->packet.ep->dev);
Hans de Goede c8dfc6
+        if (xhci_setup_packet(xfer) < 0) {
Hans de Goede c8dfc6
+            return;
Hans de Goede c8dfc6
+        }
Hans de Goede c8dfc6
         result = usb_handle_packet(xfer->packet.ep->dev, &xfer->packet);
Hans de Goede c8dfc6
         if (result == USB_RET_NAK) {
Hans de Goede c8dfc6
             return;
Hans de Goede c8dfc6
-- 
5544c1
1.7.12.1
Hans de Goede c8dfc6