diff mbox

[09/41] msix: port to vmstate

Message ID 9f139edc9978d7a3ab9b2639cf688430ec3101f4.1259754427.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Dec. 2, 2009, 12:04 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/msix.c |   39 ++++++++++++++++++++++++++++++++-------
 hw/msix.h |    1 +
 2 files changed, 33 insertions(+), 7 deletions(-)
diff mbox

Patch

diff --git a/hw/msix.c b/hw/msix.c
index 62865d0..f00256a 100644
--- a/hw/msix.c
+++ b/hw/msix.c
@@ -291,29 +291,54 @@  int msix_uninit(PCIDevice *dev)
     return 0;
 }

-void msix_save(PCIDevice *dev, QEMUFile *f)
+static void msix_pre_save(void *opaque)
 {
+    PCIDevice *dev = opaque;
     unsigned n = dev->msix_entries_nr;
+
     dev->msix_entries_size = n * MSIX_ENTRY_SIZE;
     dev->msix_pending_size = (n + 7) / 8;
-
-    qemu_put_buffer(f, dev->msix_table_page, dev->msix_entries_size);
-    qemu_put_buffer(f, dev->msix_table_page + MSIX_PAGE_PENDING, dev->msix_pending_size);
 }

 /* Should be called after restoring the config space. */
-void msix_load(PCIDevice *dev, QEMUFile *f)
+static int msix_pre_load(void *opaque)
 {
+    PCIDevice *dev = opaque;
     unsigned n = dev->msix_entries_nr;

     dev->msix_entries_size = n * MSIX_ENTRY_SIZE;
     dev->msix_pending_size = (n + 7) / 8;

     msix_free_irq_entries(dev);
-    qemu_get_buffer(f, dev->msix_table_page, dev->msix_entries_size);
-    qemu_get_buffer(f, dev->msix_table_page + MSIX_PAGE_PENDING, dev->msix_pending_size);
+    return 0;
 }

+const VMStateDescription vmstate_msix = {
+    .name = "msix",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .pre_load = msix_pre_load,
+    .pre_save = msix_pre_save,
+    .fields      = (VMStateField []) {
+        VMSTATE_PARTIAL_VBUFFER(msix_table_page, PCIDevice, msix_entries_size),
+        VMSTATE_SUB_VBUFFER(msix_table_page, PCIDevice, MSIX_PAGE_PENDING,
+                            msix_pending_size),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+void msix_save(PCIDevice *dev, QEMUFile *f)
+{
+    vmstate_save_state(f, &vmstate_msix, dev);
+}
+
+void msix_load(PCIDevice *dev, QEMUFile *f)
+{
+    vmstate_load_state(f, &vmstate_msix, dev, vmstate_msix.version_id);
+}
+
+
 /* Does device support MSI-X? */
 int msix_present(PCIDevice *dev)
 {
diff --git a/hw/msix.h b/hw/msix.h
index a9f7993..a921a98 100644
--- a/hw/msix.h
+++ b/hw/msix.h
@@ -15,6 +15,7 @@  void msix_mmio_map(PCIDevice *pci_dev, int region_num,

 int msix_uninit(PCIDevice *d);

+extern const VMStateDescription vmstate_msix;
 void msix_save(PCIDevice *dev, QEMUFile *f);
 void msix_load(PCIDevice *dev, QEMUFile *f);