mvadkert / rpms / qemu

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