1 From b04ba21e22b2df805af8236bc462c5c403fc6ee4 Mon Sep 17 00:00:00 2001
2 From: Gerd Hoffmann <kraxel@redhat.com>
3 Date: Thu, 30 Aug 2012 12:06:59 +0200
4 Subject: [PATCH] xhci: add msix support
6 Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
8 hw/usb/hcd-xhci.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
10 2 files changed, 49 insertions(+), 1 deletion(-)
12 diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
13 index 1857f42..777f903 100644
14 --- a/hw/usb/hcd-xhci.c
15 +++ b/hw/usb/hcd-xhci.c
25 #define OFF_OPER LEN_CAP
26 #define OFF_RUNTIME 0x1000
27 #define OFF_DOORBELL 0x2000
28 +#define OFF_MSIX_TABLE 0x3000
29 +#define OFF_MSIX_PBA 0x3800
30 /* must be power of 2 */
31 #define LEN_REGS 0x4000
33 @@ -411,6 +414,7 @@ struct XHCIState {
39 int64_t mfindex_start;
40 QEMUTimer *mfwrap_timer;
41 @@ -437,6 +441,7 @@ typedef struct XHCIEvRingSeg {
44 XHCI_FLAG_USE_MSI = 1,
45 + XHCI_FLAG_USE_MSI_X,
48 static void xhci_kick_ep(XHCIState *xhci, unsigned int slotid,
49 @@ -616,7 +621,8 @@ static void xhci_intx_update(XHCIState *xhci)
53 - if (msi_enabled(&xhci->pci_dev)) {
54 + if (msix_enabled(&xhci->pci_dev) ||
55 + msi_enabled(&xhci->pci_dev)) {
59 @@ -630,6 +636,30 @@ static void xhci_intx_update(XHCIState *xhci)
60 qemu_set_irq(xhci->irq, level);
63 +static void xhci_msix_update(XHCIState *xhci)
67 + if (!msix_enabled(&xhci->pci_dev)) {
71 + enabled = xhci->iman & IMAN_IE;
72 + if (enabled == xhci->msix_used) {
77 + trace_usb_xhci_irq_msix_use(0);
78 + msix_vector_use(&xhci->pci_dev, 0);
79 + xhci->msix_used = true;
81 + trace_usb_xhci_irq_msix_unuse(0);
82 + msix_vector_unuse(&xhci->pci_dev, 0);
83 + xhci->msix_used = false;
87 static void xhci_intr_raise(XHCIState *xhci)
89 if (!(xhci->iman & IMAN_IP) ||
90 @@ -641,6 +671,12 @@ static void xhci_intr_raise(XHCIState *xhci)
94 + if (msix_enabled(&xhci->pci_dev)) {
95 + trace_usb_xhci_irq_msix(0);
96 + msix_notify(&xhci->pci_dev, 0);
100 if (msi_enabled(&xhci->pci_dev)) {
101 trace_usb_xhci_irq_msi(0);
102 msi_notify(&xhci->pci_dev, 0);
103 @@ -2282,6 +2318,7 @@ static void xhci_reset(DeviceState *dev)
104 xhci->erstba_high = 0;
107 + xhci->msix_used = 0;
111 @@ -2590,6 +2627,7 @@ static void xhci_runtime_write(XHCIState *xhci, uint32_t reg, uint32_t val)
112 xhci->iman &= ~IMAN_IE;
113 xhci->iman |= val & IMAN_IE;
114 xhci_intx_update(xhci);
115 + xhci_msix_update(xhci);
117 case 0x24: /* IMOD */
119 @@ -2885,6 +2923,12 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
120 if (xhci->flags & (1 << XHCI_FLAG_USE_MSI)) {
121 msi_init(&xhci->pci_dev, 0x70, MAXINTRS, true, false);
123 + if (xhci->flags & (1 << XHCI_FLAG_USE_MSI_X)) {
124 + msix_init(&xhci->pci_dev, MAXINTRS,
125 + &xhci->mem, 0, OFF_MSIX_TABLE,
126 + &xhci->mem, 0, OFF_MSIX_PBA,
132 @@ -2896,6 +2940,7 @@ static const VMStateDescription vmstate_xhci = {
134 static Property xhci_properties[] = {
135 DEFINE_PROP_BIT("msi", XHCIState, flags, XHCI_FLAG_USE_MSI, true),
136 + DEFINE_PROP_BIT("msix", XHCIState, flags, XHCI_FLAG_USE_MSI_X, true),
137 DEFINE_PROP_UINT32("p2", XHCIState, numports_2, 4),
138 DEFINE_PROP_UINT32("p3", XHCIState, numports_3, 4),
139 DEFINE_PROP_END_OF_LIST(),
140 diff --git a/trace-events b/trace-events
141 index d941e78..f86bbda 100644
144 @@ -316,6 +316,9 @@ usb_xhci_runtime_write(uint32_t off, uint32_t val) "off 0x%04x, val 0x%08x"
145 usb_xhci_doorbell_write(uint32_t off, uint32_t val) "off 0x%04x, val 0x%08x"
146 usb_xhci_irq_intx(uint32_t level) "level %d"
147 usb_xhci_irq_msi(uint32_t nr) "nr %d"
148 +usb_xhci_irq_msix(uint32_t nr) "nr %d"
149 +usb_xhci_irq_msix_use(uint32_t nr) "nr %d"
150 +usb_xhci_irq_msix_unuse(uint32_t nr) "nr %d"
151 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"
152 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"
153 usb_xhci_slot_enable(uint32_t slotid) "slotid %d"