Blame 0621-xhci-prepare-xhci_runtime_-read-write-for-multiple-i.patch

5544c1
From 670eba790c368e9c37b0c964d94e0ff7f0d0c443 Mon Sep 17 00:00:00 2001
c8dfc6
From: Gerd Hoffmann <kraxel@redhat.com>
c8dfc6
Date: Thu, 30 Aug 2012 17:15:12 +0200
5544c1
Subject: [PATCH] xhci: prepare xhci_runtime_{read,write} for multiple
c8dfc6
 interrupters
c8dfc6
c8dfc6
Prepare xhci runtime register access function for multiple interrupters.
c8dfc6
c8dfc6
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
c8dfc6
---
c8dfc6
 hw/usb/hcd-xhci.c | 100 +++++++++++++++++++++++++++++++-----------------------
c8dfc6
 1 file changed, 57 insertions(+), 43 deletions(-)
c8dfc6
c8dfc6
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
5544c1
index 8a14ee8..6b3ff16 100644
c8dfc6
--- a/hw/usb/hcd-xhci.c
c8dfc6
+++ b/hw/usb/hcd-xhci.c
5544c1
@@ -2586,37 +2586,43 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t reg, uint32_t val)
c8dfc6
 
c8dfc6
 static uint32_t xhci_runtime_read(XHCIState *xhci, uint32_t reg)
c8dfc6
 {
c8dfc6
-    XHCIInterrupter *intr = &xhci->intr[0];
c8dfc6
-    uint32_t ret;
c8dfc6
+    uint32_t ret = 0;
c8dfc6
 
c8dfc6
-    switch (reg) {
c8dfc6
-    case 0x00: /* MFINDEX */
c8dfc6
-        ret = xhci_mfindex_get(xhci) & 0x3fff;
c8dfc6
-        break;
c8dfc6
-    case 0x20: /* IMAN */
c8dfc6
-        ret = intr->iman;
c8dfc6
-        break;
c8dfc6
-    case 0x24: /* IMOD */
c8dfc6
-        ret = intr->imod;
c8dfc6
-        break;
c8dfc6
-    case 0x28: /* ERSTSZ */
c8dfc6
-        ret = intr->erstsz;
c8dfc6
-        break;
c8dfc6
-    case 0x30: /* ERSTBA low */
c8dfc6
-        ret = intr->erstba_low;
c8dfc6
-        break;
c8dfc6
-    case 0x34: /* ERSTBA high */
c8dfc6
-        ret = intr->erstba_high;
c8dfc6
-        break;
c8dfc6
-    case 0x38: /* ERDP low */
c8dfc6
-        ret = intr->erdp_low;
c8dfc6
-        break;
c8dfc6
-    case 0x3c: /* ERDP high */
c8dfc6
-        ret = intr->erdp_high;
c8dfc6
-        break;
c8dfc6
-    default:
c8dfc6
-        fprintf(stderr, "xhci_runtime_read: reg 0x%x unimplemented\n", reg);
c8dfc6
-        ret = 0;
c8dfc6
+    if (reg < 0x20) {
c8dfc6
+        switch (reg) {
c8dfc6
+        case 0x00: /* MFINDEX */
c8dfc6
+            ret = xhci_mfindex_get(xhci) & 0x3fff;
c8dfc6
+            break;
c8dfc6
+        default:
c8dfc6
+            fprintf(stderr, "xhci_runtime_read: reg 0x%x unimplemented\n", reg);
c8dfc6
+            break;
c8dfc6
+        }
c8dfc6
+    } else {
c8dfc6
+        int v = (reg - 0x20) / 0x20;
c8dfc6
+        XHCIInterrupter *intr = &xhci->intr[v];
c8dfc6
+        switch (reg & 0x1f) {
c8dfc6
+        case 0x00: /* IMAN */
c8dfc6
+            ret = intr->iman;
c8dfc6
+            break;
c8dfc6
+        case 0x04: /* IMOD */
c8dfc6
+            ret = intr->imod;
c8dfc6
+            break;
c8dfc6
+        case 0x08: /* ERSTSZ */
c8dfc6
+            ret = intr->erstsz;
c8dfc6
+            break;
c8dfc6
+        case 0x10: /* ERSTBA low */
c8dfc6
+            ret = intr->erstba_low;
c8dfc6
+            break;
c8dfc6
+        case 0x14: /* ERSTBA high */
c8dfc6
+            ret = intr->erstba_high;
c8dfc6
+            break;
c8dfc6
+        case 0x18: /* ERDP low */
c8dfc6
+            ret = intr->erdp_low;
c8dfc6
+            break;
c8dfc6
+        case 0x1c: /* ERDP high */
c8dfc6
+            ret = intr->erdp_high;
c8dfc6
+            break;
c8dfc6
+        }
c8dfc6
     }
c8dfc6
 
c8dfc6
     trace_usb_xhci_runtime_read(reg, ret);
5544c1
@@ -2625,43 +2631,51 @@ static uint32_t xhci_runtime_read(XHCIState *xhci, uint32_t reg)
c8dfc6
 
c8dfc6
 static void xhci_runtime_write(XHCIState *xhci, uint32_t reg, uint32_t val)
c8dfc6
 {
c8dfc6
-    XHCIInterrupter *intr = &xhci->intr[0];
c8dfc6
+    int v = (reg - 0x20) / 0x20;
c8dfc6
+    XHCIInterrupter *intr = &xhci->intr[v];
c8dfc6
     trace_usb_xhci_runtime_write(reg, val);
c8dfc6
 
c8dfc6
-    switch (reg) {
c8dfc6
-    case 0x20: /* IMAN */
c8dfc6
+    if (reg < 0x20) {
c8dfc6
+        fprintf(stderr, "xhci_oper_write: reg 0x%x unimplemented\n", reg);
c8dfc6
+        return;
c8dfc6
+    }
c8dfc6
+
c8dfc6
+    switch (reg & 0x1f) {
c8dfc6
+    case 0x00: /* IMAN */
c8dfc6
         if (val & IMAN_IP) {
c8dfc6
             intr->iman &= ~IMAN_IP;
c8dfc6
         }
c8dfc6
         intr->iman &= ~IMAN_IE;
c8dfc6
         intr->iman |= val & IMAN_IE;
c8dfc6
-        xhci_intx_update(xhci);
c8dfc6
-        xhci_msix_update(xhci, 0);
c8dfc6
+        if (v == 0) {
c8dfc6
+            xhci_intx_update(xhci);
c8dfc6
+        }
c8dfc6
+        xhci_msix_update(xhci, v);
c8dfc6
         break;
c8dfc6
-    case 0x24: /* IMOD */
c8dfc6
+    case 0x04: /* IMOD */
c8dfc6
         intr->imod = val;
c8dfc6
         break;
c8dfc6
-    case 0x28: /* ERSTSZ */
c8dfc6
+    case 0x08: /* ERSTSZ */
c8dfc6
         intr->erstsz = val & 0xffff;
c8dfc6
         break;
c8dfc6
-    case 0x30: /* ERSTBA low */
c8dfc6
+    case 0x10: /* ERSTBA low */
c8dfc6
         /* XXX NEC driver bug: it doesn't align this to 64 bytes
c8dfc6
         intr->erstba_low = val & 0xffffffc0; */
c8dfc6
         intr->erstba_low = val & 0xfffffff0;
c8dfc6
         break;
c8dfc6
-    case 0x34: /* ERSTBA high */
c8dfc6
+    case 0x14: /* ERSTBA high */
c8dfc6
         intr->erstba_high = val;
c8dfc6
-        xhci_er_reset(xhci, 0);
c8dfc6
+        xhci_er_reset(xhci, v);
c8dfc6
         break;
c8dfc6
-    case 0x38: /* ERDP low */
c8dfc6
+    case 0x18: /* ERDP low */
c8dfc6
         if (val & ERDP_EHB) {
c8dfc6
             intr->erdp_low &= ~ERDP_EHB;
c8dfc6
         }
c8dfc6
         intr->erdp_low = (val & ~ERDP_EHB) | (intr->erdp_low & ERDP_EHB);
c8dfc6
         break;
c8dfc6
-    case 0x3c: /* ERDP high */
c8dfc6
+    case 0x1c: /* ERDP high */
c8dfc6
         intr->erdp_high = val;
c8dfc6
-        xhci_events_update(xhci, 0);
c8dfc6
+        xhci_events_update(xhci, v);
c8dfc6
         break;
c8dfc6
     default:
c8dfc6
         fprintf(stderr, "xhci_oper_write: reg 0x%x unimplemented\n", reg);
c8dfc6
-- 
5544c1
1.7.12.1
c8dfc6