|
|
5544c1 |
From 1f98b775c9f02caece1df5813edbb9c0a509bd58 Mon Sep 17 00:00:00 2001
|
|
Hans de Goede |
c8dfc6 |
From: Gerd Hoffmann <kraxel@redhat.com>
|
|
Hans de Goede |
c8dfc6 |
Date: Tue, 21 Aug 2012 12:32:58 +0200
|
|
|
5544c1 |
Subject: [PATCH] xhci: implement mfindex
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
Implement mfindex register and mfindex wrap event.
|
|
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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++-------
|
|
Hans de Goede |
c8dfc6 |
1 file changed, 46 insertions(+), 7 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 316a303..f5ba6a4 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 |
@@ -380,8 +380,6 @@ struct XHCIState {
|
|
Hans de Goede |
c8dfc6 |
XHCISlot slots[MAXSLOTS];
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
/* Runtime Registers */
|
|
Hans de Goede |
c8dfc6 |
- uint32_t mfindex;
|
|
Hans de Goede |
c8dfc6 |
- /* note: we only support one interrupter */
|
|
Hans de Goede |
c8dfc6 |
uint32_t iman;
|
|
Hans de Goede |
c8dfc6 |
uint32_t imod;
|
|
Hans de Goede |
c8dfc6 |
uint32_t erstsz;
|
|
Hans de Goede |
c8dfc6 |
@@ -390,6 +388,9 @@ struct XHCIState {
|
|
Hans de Goede |
c8dfc6 |
uint32_t erdp_low;
|
|
Hans de Goede |
c8dfc6 |
uint32_t erdp_high;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
+ int64_t mfindex_start;
|
|
Hans de Goede |
c8dfc6 |
+ QEMUTimer *mfwrap_timer;
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
dma_addr_t er_start;
|
|
Hans de Goede |
c8dfc6 |
uint32_t er_size;
|
|
Hans de Goede |
c8dfc6 |
bool er_pcs;
|
|
Hans de Goede |
c8dfc6 |
@@ -410,6 +411,11 @@ typedef struct XHCIEvRingSeg {
|
|
Hans de Goede |
c8dfc6 |
uint32_t rsvd;
|
|
Hans de Goede |
c8dfc6 |
} XHCIEvRingSeg;
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
|
|
Hans de Goede |
c8dfc6 |
+ unsigned int epid);
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_event(XHCIState *xhci, XHCIEvent *event);
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_write_event(XHCIState *xhci, XHCIEvent *event);
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
static const char *TRBType_names[] = {
|
|
Hans de Goede |
c8dfc6 |
[TRB_RESERVED] = "TRB_RESERVED",
|
|
Hans de Goede |
c8dfc6 |
[TR_NORMAL] = "TR_NORMAL",
|
|
Hans de Goede |
c8dfc6 |
@@ -462,8 +468,36 @@ static const char *trb_name(XHCITRB *trb)
|
|
Hans de Goede |
c8dfc6 |
ARRAY_SIZE(TRBType_names));
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
-static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
|
|
Hans de Goede |
c8dfc6 |
- unsigned int epid);
|
|
Hans de Goede |
c8dfc6 |
+static uint64_t xhci_mfindex_get(XHCIState *xhci)
|
|
Hans de Goede |
c8dfc6 |
+{
|
|
Hans de Goede |
c8dfc6 |
+ int64_t now = qemu_get_clock_ns(vm_clock);
|
|
Hans de Goede |
c8dfc6 |
+ return (now - xhci->mfindex_start) / 125000;
|
|
Hans de Goede |
c8dfc6 |
+}
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_mfwrap_update(XHCIState *xhci)
|
|
Hans de Goede |
c8dfc6 |
+{
|
|
Hans de Goede |
c8dfc6 |
+ const uint32_t bits = USBCMD_RS | USBCMD_EWE;
|
|
Hans de Goede |
c8dfc6 |
+ uint32_t mfindex, left;
|
|
Hans de Goede |
c8dfc6 |
+ int64_t now;
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+ if ((xhci->usbcmd & bits) == bits) {
|
|
Hans de Goede |
c8dfc6 |
+ now = qemu_get_clock_ns(vm_clock);
|
|
Hans de Goede |
c8dfc6 |
+ mfindex = ((now - xhci->mfindex_start) / 125000) & 0x3fff;
|
|
Hans de Goede |
c8dfc6 |
+ left = 0x4000 - mfindex;
|
|
Hans de Goede |
c8dfc6 |
+ qemu_mod_timer(xhci->mfwrap_timer, now + left * 125000);
|
|
Hans de Goede |
c8dfc6 |
+ } else {
|
|
Hans de Goede |
c8dfc6 |
+ qemu_del_timer(xhci->mfwrap_timer);
|
|
Hans de Goede |
c8dfc6 |
+ }
|
|
Hans de Goede |
c8dfc6 |
+}
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+static void xhci_mfwrap_timer(void *opaque)
|
|
Hans de Goede |
c8dfc6 |
+{
|
|
Hans de Goede |
c8dfc6 |
+ XHCIState *xhci = opaque;
|
|
Hans de Goede |
c8dfc6 |
+ XHCIEvent wrap = { ER_MFINDEX_WRAP, CC_SUCCESS };
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+ xhci_event(xhci, &wrap);
|
|
Hans de Goede |
c8dfc6 |
+ xhci_mfwrap_update(xhci);
|
|
Hans de Goede |
c8dfc6 |
+}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static inline dma_addr_t xhci_addr64(uint32_t low, uint32_t high)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
@@ -793,6 +827,7 @@ static void xhci_run(XHCIState *xhci)
|
|
Hans de Goede |
c8dfc6 |
{
|
|
Hans de Goede |
c8dfc6 |
trace_usb_xhci_run();
|
|
Hans de Goede |
c8dfc6 |
xhci->usbsts &= ~USBSTS_HCH;
|
|
Hans de Goede |
c8dfc6 |
+ xhci->mfindex_start = qemu_get_clock_ns(vm_clock);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static void xhci_stop(XHCIState *xhci)
|
|
|
5544c1 |
@@ -2048,7 +2083,6 @@ static void xhci_reset(DeviceState *dev)
|
|
Hans de Goede |
c8dfc6 |
xhci_update_port(xhci, xhci->ports + i, 0);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
- xhci->mfindex = 0;
|
|
Hans de Goede |
c8dfc6 |
xhci->iman = 0;
|
|
Hans de Goede |
c8dfc6 |
xhci->imod = 0;
|
|
Hans de Goede |
c8dfc6 |
xhci->erstsz = 0;
|
|
|
5544c1 |
@@ -2062,6 +2096,9 @@ static void xhci_reset(DeviceState *dev)
|
|
Hans de Goede |
c8dfc6 |
xhci->er_full = 0;
|
|
Hans de Goede |
c8dfc6 |
xhci->ev_buffer_put = 0;
|
|
Hans de Goede |
c8dfc6 |
xhci->ev_buffer_get = 0;
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
+ xhci->mfindex_start = qemu_get_clock_ns(vm_clock);
|
|
Hans de Goede |
c8dfc6 |
+ xhci_mfwrap_update(xhci);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
static uint32_t xhci_cap_read(XHCIState *xhci, uint32_t reg)
|
|
|
5544c1 |
@@ -2264,6 +2301,7 @@ static void xhci_oper_write(XHCIState *xhci, uint32_t reg, uint32_t val)
|
|
Hans de Goede |
c8dfc6 |
xhci_stop(xhci);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
Hans de Goede |
c8dfc6 |
xhci->usbcmd = val & 0xc0f;
|
|
Hans de Goede |
c8dfc6 |
+ xhci_mfwrap_update(xhci);
|
|
Hans de Goede |
c8dfc6 |
if (val & USBCMD_HCRST) {
|
|
Hans de Goede |
c8dfc6 |
xhci_reset(&xhci->pci_dev.qdev);
|
|
Hans de Goede |
c8dfc6 |
}
|
|
|
5544c1 |
@@ -2315,8 +2353,7 @@ static uint32_t xhci_runtime_read(XHCIState *xhci, uint32_t reg)
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
switch (reg) {
|
|
Hans de Goede |
c8dfc6 |
case 0x00: /* MFINDEX */
|
|
Hans de Goede |
c8dfc6 |
- fprintf(stderr, "xhci_runtime_read: MFINDEX not yet implemented\n");
|
|
Hans de Goede |
c8dfc6 |
- ret = xhci->mfindex;
|
|
Hans de Goede |
c8dfc6 |
+ ret = xhci_mfindex_get(xhci) & 0x3fff;
|
|
Hans de Goede |
c8dfc6 |
break;
|
|
Hans de Goede |
c8dfc6 |
case 0x20: /* IMAN */
|
|
Hans de Goede |
c8dfc6 |
ret = xhci->iman;
|
|
Hans de Goede |
c8dfc6 |
@@ -2618,6 +2655,8 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
usb_xhci_init(xhci, &dev->qdev);
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
+ xhci->mfwrap_timer = qemu_new_timer_ns(vm_clock, xhci_mfwrap_timer, xhci);
|
|
Hans de Goede |
c8dfc6 |
+
|
|
Hans de Goede |
c8dfc6 |
xhci->irq = xhci->pci_dev.irq[0];
|
|
Hans de Goede |
c8dfc6 |
|
|
Hans de Goede |
c8dfc6 |
memory_region_init_io(&xhci->mem, &xhci_mem_ops, xhci,
|
|
Hans de Goede |
c8dfc6 |
--
|
|
|
5544c1 |
1.7.12.1
|
|
Hans de Goede |
c8dfc6 |
|