|
|
9ae3a8 |
From e07526dd14669081a569bb6b1e3d72e1ee59ebad Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
Date: Wed, 7 Aug 2013 09:22:48 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 17/28] xhci: add live migration support
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1375867368-18979-6-git-send-email-kraxel@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 53041
|
|
|
9ae3a8 |
O-Subject: [RHEL-7 qemu-kvm PATCH 5/5] xhci: add live migration support
|
|
|
9ae3a8 |
Bugzilla: 838170
|
|
|
9ae3a8 |
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Orit Wasserman <owasserm@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
With all preparing pieces in place we can finally drop in
|
|
|
9ae3a8 |
the vmstate structs and the postload function.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 37352df30fbc38d1de464db8927536d5e36cf52a)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/usb/hcd-xhci.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
9ae3a8 |
1 file changed, 163 insertions(+), 1 deletion(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/usb/hcd-xhci.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
|
|
|
9ae3a8 |
1 files changed, 163 insertions(+), 1 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c
|
|
|
9ae3a8 |
index 8224465..3d3d6c3 100644
|
|
|
9ae3a8 |
--- a/hw/usb/hcd-xhci.c
|
|
|
9ae3a8 |
+++ b/hw/usb/hcd-xhci.c
|
|
|
9ae3a8 |
@@ -3386,9 +3386,171 @@ static int usb_xhci_initfn(struct PCIDevice *dev)
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static int usb_xhci_post_load(void *opaque, int version_id)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ XHCIState *xhci = opaque;
|
|
|
9ae3a8 |
+ XHCISlot *slot;
|
|
|
9ae3a8 |
+ XHCIEPContext *epctx;
|
|
|
9ae3a8 |
+ dma_addr_t dcbaap, pctx;
|
|
|
9ae3a8 |
+ uint32_t slot_ctx[4];
|
|
|
9ae3a8 |
+ uint32_t ep_ctx[5];
|
|
|
9ae3a8 |
+ int slotid, epid, state, intr;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ dcbaap = xhci_addr64(xhci->dcbaap_low, xhci->dcbaap_high);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (slotid = 1; slotid <= xhci->numslots; slotid++) {
|
|
|
9ae3a8 |
+ slot = &xhci->slots[slotid-1];
|
|
|
9ae3a8 |
+ if (!slot->addressed) {
|
|
|
9ae3a8 |
+ continue;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ slot->ctx =
|
|
|
9ae3a8 |
+ xhci_mask64(ldq_le_pci_dma(&xhci->pci_dev, dcbaap + 8*slotid));
|
|
|
9ae3a8 |
+ xhci_dma_read_u32s(xhci, slot->ctx, slot_ctx, sizeof(slot_ctx));
|
|
|
9ae3a8 |
+ slot->uport = xhci_lookup_uport(xhci, slot_ctx);
|
|
|
9ae3a8 |
+ assert(slot->uport && slot->uport->dev);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (epid = 1; epid <= 32; epid++) {
|
|
|
9ae3a8 |
+ pctx = slot->ctx + 32 * epid;
|
|
|
9ae3a8 |
+ xhci_dma_read_u32s(xhci, pctx, ep_ctx, sizeof(ep_ctx));
|
|
|
9ae3a8 |
+ state = ep_ctx[0] & EP_STATE_MASK;
|
|
|
9ae3a8 |
+ if (state == EP_DISABLED) {
|
|
|
9ae3a8 |
+ continue;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ epctx = xhci_alloc_epctx(xhci, slotid, epid);
|
|
|
9ae3a8 |
+ slot->eps[epid-1] = epctx;
|
|
|
9ae3a8 |
+ xhci_init_epctx(epctx, pctx, ep_ctx);
|
|
|
9ae3a8 |
+ epctx->state = state;
|
|
|
9ae3a8 |
+ if (state == EP_RUNNING) {
|
|
|
9ae3a8 |
+ /* kick endpoint after vmload is finished */
|
|
|
9ae3a8 |
+ qemu_mod_timer(epctx->kick_timer, qemu_get_clock_ns(vm_clock));
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ for (intr = 0; intr < xhci->numintrs; intr++) {
|
|
|
9ae3a8 |
+ if (xhci->intr[intr].msix_used) {
|
|
|
9ae3a8 |
+ msix_vector_use(&xhci->pci_dev, intr);
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ msix_vector_unuse(&xhci->pci_dev, intr);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return 0;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static const VMStateDescription vmstate_xhci_ring = {
|
|
|
9ae3a8 |
+ .name = "xhci-ring",
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]) {
|
|
|
9ae3a8 |
+ VMSTATE_UINT64(dequeue, XHCIRing),
|
|
|
9ae3a8 |
+ VMSTATE_BOOL(ccs, XHCIRing),
|
|
|
9ae3a8 |
+ VMSTATE_END_OF_LIST()
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static const VMStateDescription vmstate_xhci_port = {
|
|
|
9ae3a8 |
+ .name = "xhci-port",
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]) {
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(portsc, XHCIPort),
|
|
|
9ae3a8 |
+ VMSTATE_END_OF_LIST()
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static const VMStateDescription vmstate_xhci_slot = {
|
|
|
9ae3a8 |
+ .name = "xhci-slot",
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]) {
|
|
|
9ae3a8 |
+ VMSTATE_BOOL(enabled, XHCISlot),
|
|
|
9ae3a8 |
+ VMSTATE_BOOL(addressed, XHCISlot),
|
|
|
9ae3a8 |
+ VMSTATE_END_OF_LIST()
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static const VMStateDescription vmstate_xhci_event = {
|
|
|
9ae3a8 |
+ .name = "xhci-event",
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]) {
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(type, XHCIEvent),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(ccode, XHCIEvent),
|
|
|
9ae3a8 |
+ VMSTATE_UINT64(ptr, XHCIEvent),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(length, XHCIEvent),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(flags, XHCIEvent),
|
|
|
9ae3a8 |
+ VMSTATE_UINT8(slotid, XHCIEvent),
|
|
|
9ae3a8 |
+ VMSTATE_UINT8(epid, XHCIEvent),
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static bool xhci_er_full(void *opaque, int version_id)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ struct XHCIInterrupter *intr = opaque;
|
|
|
9ae3a8 |
+ return intr->er_full;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+static const VMStateDescription vmstate_xhci_intr = {
|
|
|
9ae3a8 |
+ .name = "xhci-intr",
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]) {
|
|
|
9ae3a8 |
+ /* registers */
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(iman, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(imod, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(erstsz, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(erstba_low, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(erstba_high, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(erdp_low, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(erdp_high, XHCIInterrupter),
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* state */
|
|
|
9ae3a8 |
+ VMSTATE_BOOL(msix_used, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_BOOL(er_pcs, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT64(er_start, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(er_size, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(er_ep_idx, XHCIInterrupter),
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* event queue (used if ring is full) */
|
|
|
9ae3a8 |
+ VMSTATE_BOOL(er_full, XHCIInterrupter),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32_TEST(ev_buffer_put, XHCIInterrupter, xhci_er_full),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32_TEST(ev_buffer_get, XHCIInterrupter, xhci_er_full),
|
|
|
9ae3a8 |
+ VMSTATE_STRUCT_ARRAY_TEST(ev_buffer, XHCIInterrupter, EV_QUEUE,
|
|
|
9ae3a8 |
+ xhci_er_full, 1,
|
|
|
9ae3a8 |
+ vmstate_xhci_event, XHCIEvent),
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ VMSTATE_END_OF_LIST()
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+};
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static const VMStateDescription vmstate_xhci = {
|
|
|
9ae3a8 |
.name = "xhci",
|
|
|
9ae3a8 |
- .unmigratable = 1,
|
|
|
9ae3a8 |
+ .version_id = 1,
|
|
|
9ae3a8 |
+ .post_load = usb_xhci_post_load,
|
|
|
9ae3a8 |
+ .fields = (VMStateField[]) {
|
|
|
9ae3a8 |
+ VMSTATE_PCIE_DEVICE(pci_dev, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_MSIX(pci_dev, XHCIState),
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ VMSTATE_STRUCT_VARRAY_UINT32(ports, XHCIState, numports, 1,
|
|
|
9ae3a8 |
+ vmstate_xhci_port, XHCIPort),
|
|
|
9ae3a8 |
+ VMSTATE_STRUCT_VARRAY_UINT32(slots, XHCIState, numslots, 1,
|
|
|
9ae3a8 |
+ vmstate_xhci_slot, XHCISlot),
|
|
|
9ae3a8 |
+ VMSTATE_STRUCT_VARRAY_UINT32(intr, XHCIState, numintrs, 1,
|
|
|
9ae3a8 |
+ vmstate_xhci_intr, XHCIInterrupter),
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Operational Registers */
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(usbcmd, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(usbsts, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(dnctrl, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(crcr_low, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(crcr_high, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(dcbaap_low, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(dcbaap_high, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_UINT32(config, XHCIState),
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ /* Runtime Registers & state */
|
|
|
9ae3a8 |
+ VMSTATE_INT64(mfindex_start, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_TIMER(mfwrap_timer, XHCIState),
|
|
|
9ae3a8 |
+ VMSTATE_STRUCT(cmd_ring, XHCIState, 1, vmstate_xhci_ring, XHCIRing),
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ VMSTATE_END_OF_LIST()
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static Property xhci_properties[] = {
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|