diff mbox

[21/25] pcnet: port to vmstate

Message ID f516ba567e1ffb5c31e171e6461284b02dc82dd2.1255976538.git.quintela@redhat.com
State New
Headers show

Commit Message

Juan Quintela Oct. 19, 2009, 6:43 p.m. UTC
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/pcnet.c |  110 +++++++++++++++++++++--------------------------------------
 1 files changed, 39 insertions(+), 71 deletions(-)
diff mbox

Patch

diff --git a/hw/pcnet.c b/hw/pcnet.c
index fecbff7..bd69735 100644
--- a/hw/pcnet.c
+++ b/hw/pcnet.c
@@ -1878,83 +1878,49 @@  static uint32_t pcnet_mmio_readl(void *opaque, target_phys_addr_t addr)
     return val;
 }

-
-static void pcnet_save(QEMUFile *f, void *opaque)
+static bool is_version_2(void *opaque, int version_id)
 {
-    PCNetState *s = opaque;
-    unsigned int i;
-
-    qemu_put_sbe32(f, s->rap);
-    qemu_put_sbe32(f, s->isr);
-    qemu_put_sbe32(f, s->lnkst);
-    qemu_put_be32s(f, &s->rdra);
-    qemu_put_be32s(f, &s->tdra);
-    qemu_put_buffer(f, s->prom, 16);
-    for (i = 0; i < 128; i++)
-        qemu_put_be16s(f, &s->csr[i]);
-    for (i = 0; i < 32; i++)
-        qemu_put_be16s(f, &s->bcr[i]);
-    qemu_put_be64s(f, &s->timer);
-    qemu_put_sbe32(f, s->xmit_pos);
-    qemu_put_buffer(f, s->buffer, 4096);
-    qemu_put_sbe32(f, s->tx_busy);
-    qemu_put_timer(f, s->poll_timer);
+    return version_id == 2;
 }

-static int pcnet_load(QEMUFile *f, void *opaque, int version_id)
-{
-    PCNetState *s = opaque;
-    int i, dummy;
-
-    if (version_id < 2 || version_id > 3)
-        return -EINVAL;
-
-    qemu_get_sbe32s(f, &s->rap);
-    qemu_get_sbe32s(f, &s->isr);
-    qemu_get_sbe32s(f, &s->lnkst);
-    qemu_get_be32s(f, &s->rdra);
-    qemu_get_be32s(f, &s->tdra);
-    qemu_get_buffer(f, s->prom, 16);
-    for (i = 0; i < 128; i++)
-        qemu_get_be16s(f, &s->csr[i]);
-    for (i = 0; i < 32; i++)
-        qemu_get_be16s(f, &s->bcr[i]);
-    qemu_get_be64s(f, &s->timer);
-    qemu_get_sbe32s(f, &s->xmit_pos);
-    if (version_id == 2) {
-        qemu_get_sbe32s(f, &dummy);
+static const VMStateDescription vmstate_pcnet = {
+    .name = "pcnet",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
+    .fields      = (VMStateField []) {
+        VMSTATE_INT32(rap, PCNetState),
+        VMSTATE_INT32(isr, PCNetState),
+        VMSTATE_INT32(lnkst, PCNetState),
+        VMSTATE_UINT32(rdra, PCNetState),
+        VMSTATE_UINT32(tdra, PCNetState),
+        VMSTATE_BUFFER(prom, PCNetState),
+        VMSTATE_UINT16_ARRAY(csr, PCNetState, 128),
+        VMSTATE_UINT16_ARRAY(bcr, PCNetState, 32),
+        VMSTATE_UINT64(timer, PCNetState),
+        VMSTATE_INT32(xmit_pos, PCNetState),
+        VMSTATE_BUFFER(buffer, PCNetState),
+        VMSTATE_UNUSED_TEST(is_version_2, 4),
+        VMSTATE_INT32(tx_busy, PCNetState),
+        VMSTATE_TIMER(poll_timer, PCNetState),
+        VMSTATE_END_OF_LIST()
     }
-    qemu_get_buffer(f, s->buffer, 4096);
-    qemu_get_sbe32s(f, &s->tx_busy);
-    qemu_get_timer(f, s->poll_timer);
-
-    return 0;
-}
-
-static void pci_pcnet_save(QEMUFile *f, void *opaque)
-{
-    PCIPCNetState *s = opaque;
-
-    pci_device_save(&s->pci_dev, f);
-    pcnet_save(f, &s->state);
-}
-
-static int pci_pcnet_load(QEMUFile *f, void *opaque, int version_id)
-{
-    PCIPCNetState *s = opaque;
-    int ret;
-
-    ret = pci_device_load(&s->pci_dev, f);
-    if (ret < 0)
-        return ret;
+};

-    return pcnet_load(f, &s->state, version_id);
-}
+static const VMStateDescription vmstate_pci_pcnet = {
+    .name = "pcnet",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
+    .fields      = (VMStateField []) {
+        VMSTATE_PCI_DEVICE(pci_dev, PCIPCNetState),
+        VMSTATE_STRUCT(state, PCIPCNetState, 0, vmstate_pcnet, PCNetState),
+        VMSTATE_END_OF_LIST()
+    }
+};

 static void pcnet_common_cleanup(PCNetState *d)
 {
-    unregister_savevm("pcnet", d);
-
     qemu_del_timer(d->poll_timer);
     qemu_free_timer(d->poll_timer);
 }
@@ -2015,6 +1981,7 @@  static void pci_pcnet_cleanup(VLANClientState *vc)
 {
     PCNetState *d = vc->opaque;

+    vmstate_unregister(&vmstate_pci_pcnet, d);
     pcnet_common_cleanup(d);
 }

@@ -2070,7 +2037,7 @@  static int pci_pcnet_init(PCIDevice *pci_dev)
     s->phys_mem_read = pci_physical_memory_read;
     s->phys_mem_write = pci_physical_memory_write;

-    register_savevm("pcnet", -1, 3, pci_pcnet_save, pci_pcnet_load, d);
+    vmstate_register(-1, &vmstate_pci_pcnet, d);
     return pcnet_common_init(&pci_dev->qdev, s, pci_pcnet_cleanup);
 }

@@ -2127,6 +2094,7 @@  static void lance_cleanup(VLANClientState *vc)
 {
     PCNetState *d = vc->opaque;

+    vmstate_unregister(&vmstate_pcnet, d);
     pcnet_common_cleanup(d);
 }

@@ -2147,7 +2115,7 @@  static int lance_init(SysBusDevice *dev)
     s->phys_mem_read = ledma_memory_read;
     s->phys_mem_write = ledma_memory_write;

-    register_savevm("pcnet", -1, 3, pcnet_save, pcnet_load, s);
+    vmstate_register(-1, &vmstate_pcnet, d);
     return pcnet_common_init(&dev->qdev, s, lance_cleanup);
 }