mvadkert / rpms / qemu

Forked from rpms/qemu 6 years ago
Clone
9290838
From 0d297b79dc199a7670c867e035d20a1f1b4a02e0 Mon Sep 17 00:00:00 2001
c8dfc65
From: Gerd Hoffmann <kraxel@redhat.com>
c8dfc65
Date: Thu, 30 Aug 2012 15:49:03 +0200
5544c1b
Subject: [PATCH] xhci: add XHCIInterrupter
c8dfc65
c8dfc65
Move all state belonging to the (single) interrupter into a separate
c8dfc65
struct.  First step in adding support for multiple interrupters.
c8dfc65
c8dfc65
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
c8dfc65
---
c8dfc65
 hw/usb/hcd-xhci.c | 307 ++++++++++++++++++++++++++++--------------------------
c8dfc65
 trace-events      |   2 +-
c8dfc65
 2 files changed, 161 insertions(+), 148 deletions(-)
c8dfc65
c8dfc65
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
f375e62
index ae5620f..76da7a9 100644
c8dfc65
--- a/hw/usb/hcd-xhci.c
c8dfc65
+++ b/hw/usb/hcd-xhci.c
c8dfc65
@@ -378,6 +378,27 @@ typedef struct XHCIEvent {
c8dfc65
     uint8_t epid;
c8dfc65
 } XHCIEvent;
c8dfc65
 
c8dfc65
+typedef struct XHCIInterrupter {
c8dfc65
+    uint32_t iman;
c8dfc65
+    uint32_t imod;
c8dfc65
+    uint32_t erstsz;
c8dfc65
+    uint32_t erstba_low;
c8dfc65
+    uint32_t erstba_high;
c8dfc65
+    uint32_t erdp_low;
c8dfc65
+    uint32_t erdp_high;
c8dfc65
+
c8dfc65
+    bool msix_used, er_pcs, er_full;
c8dfc65
+
c8dfc65
+    dma_addr_t er_start;
c8dfc65
+    uint32_t er_size;
c8dfc65
+    unsigned int er_ep_idx;
c8dfc65
+
c8dfc65
+    XHCIEvent ev_buffer[EV_QUEUE];
c8dfc65
+    unsigned int ev_buffer_put;
c8dfc65
+    unsigned int ev_buffer_get;
c8dfc65
+
c8dfc65
+} XHCIInterrupter;
c8dfc65
+
c8dfc65
 struct XHCIState {
c8dfc65
     PCIDevice pci_dev;
c8dfc65
     USBBus bus;
c8dfc65
@@ -407,27 +428,9 @@ struct XHCIState {
c8dfc65
     uint32_t numports;
c8dfc65
 
c8dfc65
     /* Runtime Registers */
c8dfc65
-    uint32_t iman;
c8dfc65
-    uint32_t imod;
c8dfc65
-    uint32_t erstsz;
c8dfc65
-    uint32_t erstba_low;
c8dfc65
-    uint32_t erstba_high;
c8dfc65
-    uint32_t erdp_low;
c8dfc65
-    uint32_t erdp_high;
c8dfc65
-    bool     msix_used;
c8dfc65
-
c8dfc65
     int64_t mfindex_start;
c8dfc65
     QEMUTimer *mfwrap_timer;
c8dfc65
-
c8dfc65
-    dma_addr_t er_start;
c8dfc65
-    uint32_t er_size;
c8dfc65
-    bool er_pcs;
c8dfc65
-    unsigned int er_ep_idx;
c8dfc65
-    bool er_full;
c8dfc65
-
c8dfc65
-    XHCIEvent ev_buffer[EV_QUEUE];
c8dfc65
-    unsigned int ev_buffer_put;
c8dfc65
-    unsigned int ev_buffer_get;
c8dfc65
+    XHCIInterrupter intr[MAXINTRS];
c8dfc65
 
c8dfc65
     XHCIRing cmd_ring;
c8dfc65
 };
c8dfc65
@@ -446,8 +449,8 @@ enum xhci_flags {
c8dfc65
 
c8dfc65
 static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
c8dfc65
                          unsigned int epid);
c8dfc65
-static void xhci_event(XHCIState *xhci, XHCIEvent *event);
c8dfc65
-static void xhci_write_event(XHCIState *xhci, XHCIEvent *event);
c8dfc65
+static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v);
c8dfc65
+static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v);
c8dfc65
 
c8dfc65
 static const char *TRBType_names[] = {
c8dfc65
     [TRB_RESERVED]                     = "TRB_RESERVED",
c8dfc65
@@ -573,7 +576,7 @@ static void xhci_mfwrap_timer(void *opaque)
c8dfc65
     XHCIState *xhci = opaque;
c8dfc65
     XHCIEvent wrap = { ER_MFINDEX_WRAP, CC_SUCCESS };
c8dfc65
 
c8dfc65
-    xhci_event(xhci, &wrap);
c8dfc65
+    xhci_event(xhci, &wrap, 0);
c8dfc65
     xhci_mfwrap_update(xhci);
c8dfc65
 }
c8dfc65
 
c8dfc65
@@ -626,8 +629,8 @@ static void xhci_intx_update(XHCIState *xhci)
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
-    if (xhci->iman & IMAN_IP &&
c8dfc65
-        xhci->iman & IMAN_IE &&
c8dfc65
+    if (xhci->intr[0].iman & IMAN_IP &&
c8dfc65
+        xhci->intr[0].iman & IMAN_IE &&
c8dfc65
         xhci->usbcmd & USBCMD_INTE) {
c8dfc65
         level = 1;
c8dfc65
     }
c8dfc65
@@ -636,7 +639,7 @@ static void xhci_intx_update(XHCIState *xhci)
c8dfc65
     qemu_set_irq(xhci->irq, level);
c8dfc65
 }
c8dfc65
 
c8dfc65
-static void xhci_msix_update(XHCIState *xhci)
c8dfc65
+static void xhci_msix_update(XHCIState *xhci, int v)
c8dfc65
 {
c8dfc65
     bool enabled;
c8dfc65
 
c8dfc65
@@ -644,29 +647,29 @@ static void xhci_msix_update(XHCIState *xhci)
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
-    enabled = xhci->iman & IMAN_IE;
c8dfc65
-    if (enabled == xhci->msix_used) {
c8dfc65
+    enabled = xhci->intr[v].iman & IMAN_IE;
c8dfc65
+    if (enabled == xhci->intr[v].msix_used) {
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
     if (enabled) {
c8dfc65
-        trace_usb_xhci_irq_msix_use(0);
c8dfc65
-        msix_vector_use(&xhci->pci_dev, 0);
c8dfc65
-        xhci->msix_used = true;
c8dfc65
+        trace_usb_xhci_irq_msix_use(v);
c8dfc65
+        msix_vector_use(&xhci->pci_dev, v);
c8dfc65
+        xhci->intr[v].msix_used = true;
c8dfc65
     } else {
c8dfc65
-        trace_usb_xhci_irq_msix_unuse(0);
c8dfc65
-        msix_vector_unuse(&xhci->pci_dev, 0);
c8dfc65
-        xhci->msix_used = false;
c8dfc65
+        trace_usb_xhci_irq_msix_unuse(v);
c8dfc65
+        msix_vector_unuse(&xhci->pci_dev, v);
c8dfc65
+        xhci->intr[v].msix_used = false;
c8dfc65
     }
c8dfc65
 }
c8dfc65
 
c8dfc65
-static void xhci_intr_raise(XHCIState *xhci)
c8dfc65
+static void xhci_intr_raise(XHCIState *xhci, int v)
c8dfc65
 {
c8dfc65
-    xhci->erdp_low |= ERDP_EHB;
c8dfc65
-    xhci->iman |= IMAN_IP;
c8dfc65
+    xhci->intr[v].erdp_low |= ERDP_EHB;
c8dfc65
+    xhci->intr[v].iman |= IMAN_IP;
c8dfc65
     xhci->usbsts |= USBSTS_EINT;
c8dfc65
 
c8dfc65
-    if (!(xhci->iman & IMAN_IE)) {
c8dfc65
+    if (!(xhci->intr[v].iman & IMAN_IE)) {
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
@@ -675,24 +678,26 @@ static void xhci_intr_raise(XHCIState *xhci)
c8dfc65
     }
c8dfc65
 
c8dfc65
     if (msix_enabled(&xhci->pci_dev)) {
c8dfc65
-        trace_usb_xhci_irq_msix(0);
c8dfc65
-        msix_notify(&xhci->pci_dev, 0);
c8dfc65
+        trace_usb_xhci_irq_msix(v);
c8dfc65
+        msix_notify(&xhci->pci_dev, v);
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
     if (msi_enabled(&xhci->pci_dev)) {
c8dfc65
-        trace_usb_xhci_irq_msi(0);
c8dfc65
-        msi_notify(&xhci->pci_dev, 0);
c8dfc65
+        trace_usb_xhci_irq_msi(v);
c8dfc65
+        msi_notify(&xhci->pci_dev, v);
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
-    trace_usb_xhci_irq_intx(1);
c8dfc65
-    qemu_set_irq(xhci->irq, 1);
c8dfc65
+    if (v == 0) {
c8dfc65
+        trace_usb_xhci_irq_intx(1);
c8dfc65
+        qemu_set_irq(xhci->irq, 1);
c8dfc65
+    }
c8dfc65
 }
c8dfc65
 
c8dfc65
 static inline int xhci_running(XHCIState *xhci)
c8dfc65
 {
c8dfc65
-    return !(xhci->usbsts & USBSTS_HCH) && !xhci->er_full;
c8dfc65
+    return !(xhci->usbsts & USBSTS_HCH) && !xhci->intr[0].er_full;
c8dfc65
 }
c8dfc65
 
c8dfc65
 static void xhci_die(XHCIState *xhci)
c8dfc65
@@ -701,8 +706,9 @@ static void xhci_die(XHCIState *xhci)
c8dfc65
     fprintf(stderr, "xhci: asserted controller error\n");
c8dfc65
 }
c8dfc65
 
c8dfc65
-static void xhci_write_event(XHCIState *xhci, XHCIEvent *event)
c8dfc65
+static void xhci_write_event(XHCIState *xhci, XHCIEvent *event, int v)
c8dfc65
 {
c8dfc65
+    XHCIInterrupter *intr = &xhci->intr[v];
c8dfc65
     XHCITRB ev_trb;
c8dfc65
     dma_addr_t addr;
c8dfc65
 
c8dfc65
@@ -710,27 +716,28 @@ static void xhci_write_event(XHCIState *xhci, XHCIEvent *event)
c8dfc65
     ev_trb.status = cpu_to_le32(event->length | (event->ccode << 24));
c8dfc65
     ev_trb.control = (event->slotid << 24) | (event->epid << 16) |
c8dfc65
                      event->flags | (event->type << TRB_TYPE_SHIFT);
c8dfc65
-    if (xhci->er_pcs) {
c8dfc65
+    if (intr->er_pcs) {
c8dfc65
         ev_trb.control |= TRB_C;
c8dfc65
     }
c8dfc65
     ev_trb.control = cpu_to_le32(ev_trb.control);
c8dfc65
 
c8dfc65
-    trace_usb_xhci_queue_event(xhci->er_ep_idx, trb_name(&ev_trb),
c8dfc65
+    trace_usb_xhci_queue_event(v, intr->er_ep_idx, trb_name(&ev_trb),
c8dfc65
                                event_name(event), ev_trb.parameter,
c8dfc65
                                ev_trb.status, ev_trb.control);
c8dfc65
 
c8dfc65
-    addr = xhci->er_start + TRB_SIZE*xhci->er_ep_idx;
c8dfc65
+    addr = intr->er_start + TRB_SIZE*intr->er_ep_idx;
c8dfc65
     pci_dma_write(&xhci->pci_dev, addr, &ev_trb, TRB_SIZE);
c8dfc65
 
c8dfc65
-    xhci->er_ep_idx++;
c8dfc65
-    if (xhci->er_ep_idx >= xhci->er_size) {
c8dfc65
-        xhci->er_ep_idx = 0;
c8dfc65
-        xhci->er_pcs = !xhci->er_pcs;
c8dfc65
+    intr->er_ep_idx++;
c8dfc65
+    if (intr->er_ep_idx >= intr->er_size) {
c8dfc65
+        intr->er_ep_idx = 0;
c8dfc65
+        intr->er_pcs = !intr->er_pcs;
c8dfc65
     }
c8dfc65
 }
c8dfc65
 
c8dfc65
-static void xhci_events_update(XHCIState *xhci)
c8dfc65
+static void xhci_events_update(XHCIState *xhci, int v)
c8dfc65
 {
c8dfc65
+    XHCIInterrupter *intr = &xhci->intr[v];
c8dfc65
     dma_addr_t erdp;
c8dfc65
     unsigned int dp_idx;
c8dfc65
     bool do_irq = 0;
c8dfc65
@@ -739,115 +746,116 @@ static void xhci_events_update(XHCIState *xhci)
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
-    erdp = xhci_addr64(xhci->erdp_low, xhci->erdp_high);
c8dfc65
-    if (erdp < xhci->er_start ||
c8dfc65
-        erdp >= (xhci->er_start + TRB_SIZE*xhci->er_size)) {
c8dfc65
+    erdp = xhci_addr64(intr->erdp_low, intr->erdp_high);
c8dfc65
+    if (erdp < intr->er_start ||
c8dfc65
+        erdp >= (intr->er_start + TRB_SIZE*intr->er_size)) {
c8dfc65
         fprintf(stderr, "xhci: ERDP out of bounds: "DMA_ADDR_FMT"\n", erdp);
c8dfc65
-        fprintf(stderr, "xhci: ER at "DMA_ADDR_FMT" len %d\n",
c8dfc65
-                xhci->er_start, xhci->er_size);
c8dfc65
+        fprintf(stderr, "xhci: ER[%d] at "DMA_ADDR_FMT" len %d\n",
c8dfc65
+                v, intr->er_start, intr->er_size);
c8dfc65
         xhci_die(xhci);
c8dfc65
         return;
c8dfc65
     }
c8dfc65
-    dp_idx = (erdp - xhci->er_start) / TRB_SIZE;
c8dfc65
-    assert(dp_idx < xhci->er_size);
c8dfc65
+    dp_idx = (erdp - intr->er_start) / TRB_SIZE;
c8dfc65
+    assert(dp_idx < intr->er_size);
c8dfc65
 
c8dfc65
     /* NEC didn't read section 4.9.4 of the spec (v1.0 p139 top Note) and thus
c8dfc65
      * deadlocks when the ER is full. Hack it by holding off events until
c8dfc65
      * the driver decides to free at least half of the ring */
c8dfc65
-    if (xhci->er_full) {
c8dfc65
-        int er_free = dp_idx - xhci->er_ep_idx;
c8dfc65
+    if (intr->er_full) {
c8dfc65
+        int er_free = dp_idx - intr->er_ep_idx;
c8dfc65
         if (er_free <= 0) {
c8dfc65
-            er_free += xhci->er_size;
c8dfc65
+            er_free += intr->er_size;
c8dfc65
         }
c8dfc65
-        if (er_free < (xhci->er_size/2)) {
c8dfc65
+        if (er_free < (intr->er_size/2)) {
c8dfc65
             DPRINTF("xhci_events_update(): event ring still "
c8dfc65
                     "more than half full (hack)\n");
c8dfc65
             return;
c8dfc65
         }
c8dfc65
     }
c8dfc65
 
c8dfc65
-    while (xhci->ev_buffer_put != xhci->ev_buffer_get) {
c8dfc65
-        assert(xhci->er_full);
c8dfc65
-        if (((xhci->er_ep_idx+1) % xhci->er_size) == dp_idx) {
c8dfc65
+    while (intr->ev_buffer_put != intr->ev_buffer_get) {
c8dfc65
+        assert(intr->er_full);
c8dfc65
+        if (((intr->er_ep_idx+1) % intr->er_size) == dp_idx) {
c8dfc65
             DPRINTF("xhci_events_update(): event ring full again\n");
c8dfc65
 #ifndef ER_FULL_HACK
c8dfc65
             XHCIEvent full = {ER_HOST_CONTROLLER, CC_EVENT_RING_FULL_ERROR};
c8dfc65
-            xhci_write_event(xhci, &full);
c8dfc65
+            xhci_write_event(xhci, &full, v);
c8dfc65
 #endif
c8dfc65
             do_irq = 1;
c8dfc65
             break;
c8dfc65
         }
c8dfc65
-        XHCIEvent *event = &xhci->ev_buffer[xhci->ev_buffer_get];
c8dfc65
-        xhci_write_event(xhci, event);
c8dfc65
-        xhci->ev_buffer_get++;
c8dfc65
+        XHCIEvent *event = &intr->ev_buffer[intr->ev_buffer_get];
c8dfc65
+        xhci_write_event(xhci, event, v);
c8dfc65
+        intr->ev_buffer_get++;
c8dfc65
         do_irq = 1;
c8dfc65
-        if (xhci->ev_buffer_get == EV_QUEUE) {
c8dfc65
-            xhci->ev_buffer_get = 0;
c8dfc65
+        if (intr->ev_buffer_get == EV_QUEUE) {
c8dfc65
+            intr->ev_buffer_get = 0;
c8dfc65
         }
c8dfc65
     }
c8dfc65
 
c8dfc65
     if (do_irq) {
c8dfc65
-        xhci_intr_raise(xhci);
c8dfc65
+        xhci_intr_raise(xhci, v);
c8dfc65
     }
c8dfc65
 
c8dfc65
-    if (xhci->er_full && xhci->ev_buffer_put == xhci->ev_buffer_get) {
c8dfc65
+    if (intr->er_full && intr->ev_buffer_put == intr->ev_buffer_get) {
c8dfc65
         DPRINTF("xhci_events_update(): event ring no longer full\n");
c8dfc65
-        xhci->er_full = 0;
c8dfc65
+        intr->er_full = 0;
c8dfc65
     }
c8dfc65
     return;
c8dfc65
 }
c8dfc65
 
c8dfc65
-static void xhci_event(XHCIState *xhci, XHCIEvent *event)
c8dfc65
+static void xhci_event(XHCIState *xhci, XHCIEvent *event, int v)
c8dfc65
 {
c8dfc65
+    XHCIInterrupter *intr = &xhci->intr[v];
c8dfc65
     dma_addr_t erdp;
c8dfc65
     unsigned int dp_idx;
c8dfc65
 
c8dfc65
-    if (xhci->er_full) {
c8dfc65
+    if (intr->er_full) {
c8dfc65
         DPRINTF("xhci_event(): ER full, queueing\n");
c8dfc65
-        if (((xhci->ev_buffer_put+1) % EV_QUEUE) == xhci->ev_buffer_get) {
c8dfc65
+        if (((intr->ev_buffer_put+1) % EV_QUEUE) == intr->ev_buffer_get) {
c8dfc65
             fprintf(stderr, "xhci: event queue full, dropping event!\n");
c8dfc65
             return;
c8dfc65
         }
c8dfc65
-        xhci->ev_buffer[xhci->ev_buffer_put++] = *event;
c8dfc65
-        if (xhci->ev_buffer_put == EV_QUEUE) {
c8dfc65
-            xhci->ev_buffer_put = 0;
c8dfc65
+        intr->ev_buffer[intr->ev_buffer_put++] = *event;
c8dfc65
+        if (intr->ev_buffer_put == EV_QUEUE) {
c8dfc65
+            intr->ev_buffer_put = 0;
c8dfc65
         }
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
-    erdp = xhci_addr64(xhci->erdp_low, xhci->erdp_high);
c8dfc65
-    if (erdp < xhci->er_start ||
c8dfc65
-        erdp >= (xhci->er_start + TRB_SIZE*xhci->er_size)) {
c8dfc65
+    erdp = xhci_addr64(intr->erdp_low, intr->erdp_high);
c8dfc65
+    if (erdp < intr->er_start ||
c8dfc65
+        erdp >= (intr->er_start + TRB_SIZE*intr->er_size)) {
c8dfc65
         fprintf(stderr, "xhci: ERDP out of bounds: "DMA_ADDR_FMT"\n", erdp);
c8dfc65
-        fprintf(stderr, "xhci: ER at "DMA_ADDR_FMT" len %d\n",
c8dfc65
-                xhci->er_start, xhci->er_size);
c8dfc65
+        fprintf(stderr, "xhci: ER[%d] at "DMA_ADDR_FMT" len %d\n",
c8dfc65
+                v, intr->er_start, intr->er_size);
c8dfc65
         xhci_die(xhci);
c8dfc65
         return;
c8dfc65
     }
c8dfc65
 
c8dfc65
-    dp_idx = (erdp - xhci->er_start) / TRB_SIZE;
c8dfc65
-    assert(dp_idx < xhci->er_size);
c8dfc65
+    dp_idx = (erdp - intr->er_start) / TRB_SIZE;
c8dfc65
+    assert(dp_idx < intr->er_size);
c8dfc65
 
c8dfc65
-    if ((xhci->er_ep_idx+1) % xhci->er_size == dp_idx) {
c8dfc65
+    if ((intr->er_ep_idx+1) % intr->er_size == dp_idx) {
c8dfc65
         DPRINTF("xhci_event(): ER full, queueing\n");
c8dfc65
 #ifndef ER_FULL_HACK
c8dfc65
         XHCIEvent full = {ER_HOST_CONTROLLER, CC_EVENT_RING_FULL_ERROR};
c8dfc65
         xhci_write_event(xhci, &full);
c8dfc65
 #endif
c8dfc65
-        xhci->er_full = 1;
c8dfc65
-        if (((xhci->ev_buffer_put+1) % EV_QUEUE) == xhci->ev_buffer_get) {
c8dfc65
+        intr->er_full = 1;
c8dfc65
+        if (((intr->ev_buffer_put+1) % EV_QUEUE) == intr->ev_buffer_get) {
c8dfc65
             fprintf(stderr, "xhci: event queue full, dropping event!\n");
c8dfc65
             return;
c8dfc65
         }
c8dfc65
-        xhci->ev_buffer[xhci->ev_buffer_put++] = *event;
c8dfc65
-        if (xhci->ev_buffer_put == EV_QUEUE) {
c8dfc65
-            xhci->ev_buffer_put = 0;
c8dfc65
+        intr->ev_buffer[intr->ev_buffer_put++] = *event;
c8dfc65
+        if (intr->ev_buffer_put == EV_QUEUE) {
c8dfc65
+            intr->ev_buffer_put = 0;
c8dfc65
         }
c8dfc65
     } else {
c8dfc65
-        xhci_write_event(xhci, event);
c8dfc65
+        xhci_write_event(xhci, event, v);
c8dfc65
     }
c8dfc65
 
c8dfc65
-    xhci_intr_raise(xhci);
c8dfc65
+    xhci_intr_raise(xhci, v);
c8dfc65
 }
c8dfc65
 
c8dfc65
 static void xhci_ring_init(XHCIState *xhci, XHCIRing *ring,
c8dfc65
@@ -939,17 +947,18 @@ static int xhci_ring_chain_length(XHCIState *xhci, const XHCIRing *ring)
c8dfc65
     }
c8dfc65
 }
c8dfc65
 
c8dfc65
-static void xhci_er_reset(XHCIState *xhci)
c8dfc65
+static void xhci_er_reset(XHCIState *xhci, int v)
c8dfc65
 {
c8dfc65
+    XHCIInterrupter *intr = &xhci->intr[v];
c8dfc65
     XHCIEvRingSeg seg;
c8dfc65
 
c8dfc65
     /* cache the (sole) event ring segment location */
c8dfc65
-    if (xhci->erstsz != 1) {
c8dfc65
-        fprintf(stderr, "xhci: invalid value for ERSTSZ: %d\n", xhci->erstsz);
c8dfc65
+    if (intr->erstsz != 1) {
c8dfc65
+        fprintf(stderr, "xhci: invalid value for ERSTSZ: %d\n", intr->erstsz);
c8dfc65
         xhci_die(xhci);
c8dfc65
         return;
c8dfc65
     }
c8dfc65
-    dma_addr_t erstba = xhci_addr64(xhci->erstba_low, xhci->erstba_high);
c8dfc65
+    dma_addr_t erstba = xhci_addr64(intr->erstba_low, intr->erstba_high);
c8dfc65
     pci_dma_read(&xhci->pci_dev, erstba, &seg, sizeof(seg));
c8dfc65
     le32_to_cpus(&seg.addr_low);
c8dfc65
     le32_to_cpus(&seg.addr_high);
c8dfc65
@@ -959,15 +968,15 @@ static void xhci_er_reset(XHCIState *xhci)
c8dfc65
         xhci_die(xhci);
c8dfc65
         return;
c8dfc65
     }
c8dfc65
-    xhci->er_start = xhci_addr64(seg.addr_low, seg.addr_high);
c8dfc65
-    xhci->er_size = seg.size;
c8dfc65
+    intr->er_start = xhci_addr64(seg.addr_low, seg.addr_high);
c8dfc65
+    intr->er_size = seg.size;
c8dfc65
 
c8dfc65
-    xhci->er_ep_idx = 0;
c8dfc65
-    xhci->er_pcs = 1;
c8dfc65
-    xhci->er_full = 0;
c8dfc65
+    intr->er_ep_idx = 0;
c8dfc65
+    intr->er_pcs = 1;
c8dfc65
+    intr->er_full = 0;
c8dfc65
 
c8dfc65
-    DPRINTF("xhci: event ring:" DMA_ADDR_FMT " [%d]\n",
c8dfc65
-            xhci->er_start, xhci->er_size);
c8dfc65
+    DPRINTF("xhci: event ring[%d]:" DMA_ADDR_FMT " [%d]\n",
c8dfc65
+            v, intr->er_start, intr->er_size);
c8dfc65
 }
c8dfc65
 
c8dfc65
 static void xhci_run(XHCIState *xhci)
c8dfc65
@@ -1368,7 +1377,7 @@ static void xhci_xfer_report(XHCITransfer *xfer)
c8dfc65
                 DPRINTF("xhci_xfer_data: EDTLA=%d\n", event.length);
c8dfc65
                 edtla = 0;
c8dfc65
             }
c8dfc65
-            xhci_event(xhci, &event);
c8dfc65
+            xhci_event(xhci, &event, 0 /* FIXME */);
c8dfc65
             reported = 1;
c8dfc65
             if (xfer->status != CC_SUCCESS) {
c8dfc65
                 return;
5544c1b
@@ -2244,7 +2253,7 @@ static void xhci_process_commands(XHCIState *xhci)
c8dfc65
             break;
c8dfc65
         }
c8dfc65
         event.slotid = slotid;
c8dfc65
-        xhci_event(xhci, &event);
c8dfc65
+        xhci_event(xhci, &event, 0 /* FIXME */);
c8dfc65
     }
c8dfc65
 }
c8dfc65
 
5544c1b
@@ -2274,7 +2283,7 @@ static void xhci_update_port(XHCIState *xhci, XHCIPort *port, int is_detach)
c8dfc65
         port->portsc |= PORTSC_CSC;
c8dfc65
         XHCIEvent ev = { ER_PORT_STATUS_CHANGE, CC_SUCCESS,
c8dfc65
                          port->portnr << 24};
c8dfc65
-        xhci_event(xhci, &ev;;
c8dfc65
+        xhci_event(xhci, &ev, 0 /* FIXME */);
c8dfc65
         DPRINTF("xhci: port change event for port %d\n", port->portnr);
c8dfc65
     }
c8dfc65
 }
5544c1b
@@ -2307,20 +2316,22 @@ static void xhci_reset(DeviceState *dev)
c8dfc65
         xhci_update_port(xhci, xhci->ports + i, 0);
c8dfc65
     }
c8dfc65
 
c8dfc65
-    xhci->iman = 0;
c8dfc65
-    xhci->imod = 0;
c8dfc65
-    xhci->erstsz = 0;
c8dfc65
-    xhci->erstba_low = 0;
c8dfc65
-    xhci->erstba_high = 0;
c8dfc65
-    xhci->erdp_low = 0;
c8dfc65
-    xhci->erdp_high = 0;
c8dfc65
-    xhci->msix_used = 0;
c8dfc65
+    for (i = 0; i < MAXINTRS; i++) {
c8dfc65
+        xhci->intr[i].iman = 0;
c8dfc65
+        xhci->intr[i].imod = 0;
c8dfc65
+        xhci->intr[i].erstsz = 0;
c8dfc65
+        xhci->intr[i].erstba_low = 0;
c8dfc65
+        xhci->intr[i].erstba_high = 0;
c8dfc65
+        xhci->intr[i].erdp_low = 0;
c8dfc65
+        xhci->intr[i].erdp_high = 0;
c8dfc65
+        xhci->intr[i].msix_used = 0;
c8dfc65
 
c8dfc65
-    xhci->er_ep_idx = 0;
c8dfc65
-    xhci->er_pcs = 1;
c8dfc65
-    xhci->er_full = 0;
c8dfc65
-    xhci->ev_buffer_put = 0;
c8dfc65
-    xhci->ev_buffer_get = 0;
c8dfc65
+        xhci->intr[i].er_ep_idx = 0;
c8dfc65
+        xhci->intr[i].er_pcs = 1;
c8dfc65
+        xhci->intr[i].er_full = 0;
c8dfc65
+        xhci->intr[i].ev_buffer_put = 0;
c8dfc65
+        xhci->intr[i].ev_buffer_get = 0;
c8dfc65
+    }
c8dfc65
 
c8dfc65
     xhci->mfindex_start = qemu_get_clock_ns(vm_clock);
c8dfc65
     xhci_mfwrap_update(xhci);
5544c1b
@@ -2551,7 +2562,7 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t reg, uint32_t val)
c8dfc65
         if (xhci->crcr_low & (CRCR_CA|CRCR_CS) && (xhci->crcr_low & CRCR_CRR)) {
c8dfc65
             XHCIEvent event = {ER_COMMAND_COMPLETE, CC_COMMAND_RING_STOPPED};
c8dfc65
             xhci->crcr_low &= ~CRCR_CRR;
c8dfc65
-            xhci_event(xhci, &event);
c8dfc65
+            xhci_event(xhci, &event, 0 /* FIXME */);
c8dfc65
             DPRINTF("xhci: command ring stopped (CRCR=%08x)\n", xhci->crcr_low);
c8dfc65
         } else {
c8dfc65
             dma_addr_t base = xhci_addr64(xhci->crcr_low & ~0x3f, val);
5544c1b
@@ -2575,6 +2586,7 @@ 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
 
c8dfc65
     switch (reg) {
5544c1b
@@ -2582,25 +2594,25 @@ static uint32_t xhci_runtime_read(XHCIState *xhci, uint32_t reg)
c8dfc65
         ret = xhci_mfindex_get(xhci) & 0x3fff;
c8dfc65
         break;
c8dfc65
     case 0x20: /* IMAN */
c8dfc65
-        ret = xhci->iman;
c8dfc65
+        ret = intr->iman;
c8dfc65
         break;
c8dfc65
     case 0x24: /* IMOD */
c8dfc65
-        ret = xhci->imod;
c8dfc65
+        ret = intr->imod;
c8dfc65
         break;
c8dfc65
     case 0x28: /* ERSTSZ */
c8dfc65
-        ret = xhci->erstsz;
c8dfc65
+        ret = intr->erstsz;
c8dfc65
         break;
c8dfc65
     case 0x30: /* ERSTBA low */
c8dfc65
-        ret = xhci->erstba_low;
c8dfc65
+        ret = intr->erstba_low;
c8dfc65
         break;
c8dfc65
     case 0x34: /* ERSTBA high */
c8dfc65
-        ret = xhci->erstba_high;
c8dfc65
+        ret = intr->erstba_high;
c8dfc65
         break;
c8dfc65
     case 0x38: /* ERDP low */
c8dfc65
-        ret = xhci->erdp_low;
c8dfc65
+        ret = intr->erdp_low;
c8dfc65
         break;
c8dfc65
     case 0x3c: /* ERDP high */
c8dfc65
-        ret = xhci->erdp_high;
c8dfc65
+        ret = intr->erdp_high;
c8dfc65
         break;
c8dfc65
     default:
c8dfc65
         fprintf(stderr, "xhci_runtime_read: reg 0x%x unimplemented\n", reg);
5544c1b
@@ -2613,42 +2625,43 @@ 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
     trace_usb_xhci_runtime_write(reg, val);
c8dfc65
 
c8dfc65
     switch (reg) {
c8dfc65
     case 0x20: /* IMAN */
c8dfc65
         if (val & IMAN_IP) {
c8dfc65
-            xhci->iman &= ~IMAN_IP;
c8dfc65
+            intr->iman &= ~IMAN_IP;
c8dfc65
         }
c8dfc65
-        xhci->iman &= ~IMAN_IE;
c8dfc65
-        xhci->iman |= val & IMAN_IE;
c8dfc65
+        intr->iman &= ~IMAN_IE;
c8dfc65
+        intr->iman |= val & IMAN_IE;
c8dfc65
         xhci_intx_update(xhci);
c8dfc65
-        xhci_msix_update(xhci);
c8dfc65
+        xhci_msix_update(xhci, 0);
c8dfc65
         break;
c8dfc65
     case 0x24: /* IMOD */
c8dfc65
-        xhci->imod = val;
c8dfc65
+        intr->imod = val;
c8dfc65
         break;
c8dfc65
     case 0x28: /* ERSTSZ */
c8dfc65
-        xhci->erstsz = val & 0xffff;
c8dfc65
+        intr->erstsz = val & 0xffff;
c8dfc65
         break;
c8dfc65
     case 0x30: /* ERSTBA low */
c8dfc65
         /* XXX NEC driver bug: it doesn't align this to 64 bytes
c8dfc65
-        xhci->erstba_low = val & 0xffffffc0; */
c8dfc65
-        xhci->erstba_low = val & 0xfffffff0;
c8dfc65
+        intr->erstba_low = val & 0xffffffc0; */
c8dfc65
+        intr->erstba_low = val & 0xfffffff0;
c8dfc65
         break;
c8dfc65
     case 0x34: /* ERSTBA high */
c8dfc65
-        xhci->erstba_high = val;
c8dfc65
-        xhci_er_reset(xhci);
c8dfc65
+        intr->erstba_high = val;
c8dfc65
+        xhci_er_reset(xhci, 0);
c8dfc65
         break;
c8dfc65
     case 0x38: /* ERDP low */
c8dfc65
         if (val & ERDP_EHB) {
c8dfc65
-            xhci->erdp_low &= ~ERDP_EHB;
c8dfc65
+            intr->erdp_low &= ~ERDP_EHB;
c8dfc65
         }
c8dfc65
-        xhci->erdp_low = (val & ~ERDP_EHB) | (xhci->erdp_low & ERDP_EHB);
c8dfc65
+        intr->erdp_low = (val & ~ERDP_EHB) | (intr->erdp_low & ERDP_EHB);
c8dfc65
         break;
c8dfc65
     case 0x3c: /* ERDP high */
c8dfc65
-        xhci->erdp_high = val;
c8dfc65
-        xhci_events_update(xhci);
c8dfc65
+        intr->erdp_high = val;
c8dfc65
+        xhci_events_update(xhci, 0);
c8dfc65
         break;
c8dfc65
     default:
c8dfc65
         fprintf(stderr, "xhci_oper_write: reg 0x%x unimplemented\n", reg);
c8dfc65
@@ -2780,7 +2793,7 @@ static void xhci_wakeup(USBPort *usbport)
c8dfc65
         return;
c8dfc65
     }
c8dfc65
     port->portsc |= PORTSC_PLC;
c8dfc65
-    xhci_event(xhci, &ev;;
c8dfc65
+    xhci_event(xhci, &ev, 0 /* FIXME */);
c8dfc65
 }
c8dfc65
 
c8dfc65
 static void xhci_complete(USBPort *port, USBPacket *packet)
c8dfc65
diff --git a/trace-events b/trace-events
9290838
index 93b05ab..9d39d8d 100644
c8dfc65
--- a/trace-events
c8dfc65
+++ b/trace-events
5544c1b
@@ -319,7 +319,7 @@ usb_xhci_irq_msi(uint32_t nr) "nr %d"
c8dfc65
 usb_xhci_irq_msix(uint32_t nr) "nr %d"
c8dfc65
 usb_xhci_irq_msix_use(uint32_t nr) "nr %d"
c8dfc65
 usb_xhci_irq_msix_unuse(uint32_t nr) "nr %d"
c8dfc65
-usb_xhci_queue_event(uint32_t idx, const char *trb, const char *evt, uint64_t param, uint32_t status, uint32_t control) "idx %d, %s, %s, p %016" PRIx64 ", s %08x, c 0x%08x"
c8dfc65
+usb_xhci_queue_event(uint32_t vector, uint32_t idx, const char *trb, const char *evt, uint64_t param, uint32_t status, uint32_t control) "v %d, idx %d, %s, %s, p %016" PRIx64 ", s %08x, c 0x%08x"
c8dfc65
 usb_xhci_fetch_trb(uint64_t addr, const char *name, uint64_t param, uint32_t status, uint32_t control) "addr %016" PRIx64 ", %s, p %016" PRIx64 ", s %08x, c 0x%08x"
c8dfc65
 usb_xhci_slot_enable(uint32_t slotid) "slotid %d"
c8dfc65
 usb_xhci_slot_disable(uint32_t slotid) "slotid %d"