From patchwork Wed Dec 2 12:04:07 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [09/41] msix: port to vmstate From: Juan Quintela X-Patchwork-Id: 40014 Message-Id: <9f139edc9978d7a3ab9b2639cf688430ec3101f4.1259754427.git.quintela@redhat.com> To: qemu-devel@nongnu.org Cc: mst@redhat.com Date: Wed, 2 Dec 2009 13:04:07 +0100 Signed-off-by: Juan Quintela --- hw/msix.c | 39 ++++++++++++++++++++++++++++++++------- hw/msix.h | 1 + 2 files changed, 33 insertions(+), 7 deletions(-) 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);