diff mbox

[22/25] ne2000: port to vmstate

Message ID c819604108a02dbfbad361521192a07cae1afb26.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/ne2000-isa.c |    4 +-
 hw/ne2000.c     |  133 ++++++++++++++++++++-----------------------------------
 hw/ne2000.h     |    3 +-
 3 files changed, 51 insertions(+), 89 deletions(-)
diff mbox

Patch

diff --git a/hw/ne2000-isa.c b/hw/ne2000-isa.c
index e346731..0948b82 100644
--- a/hw/ne2000-isa.c
+++ b/hw/ne2000-isa.c
@@ -40,7 +40,7 @@  static void isa_ne2000_cleanup(VLANClientState *vc)
     NE2000State *s = vc->opaque;
     ISANE2000State *isa = container_of(s, ISANE2000State, ne2000);

-    unregister_savevm("ne2000", s);
+    vmstate_unregister(&vmstate_ne2000, s);

     isa_unassign_ioport(isa->iobase, 16);
     isa_unassign_ioport(isa->iobase + 0x10, 2);
@@ -73,7 +73,7 @@  static int isa_ne2000_initfn(ISADevice *dev)
                                  isa_ne2000_cleanup, s);
     qemu_format_nic_info_str(s->vc, s->macaddr);

-    register_savevm("ne2000", -1, 2, ne2000_save, ne2000_load, s);
+    vmstate_register(-1, &vmstate_ne2000, s);
     return 0;
 }

diff --git a/hw/ne2000.c b/hw/ne2000.c
index 87f1e59..88a81fb 100644
--- a/hw/ne2000.c
+++ b/hw/ne2000.c
@@ -622,94 +622,57 @@  uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr)
     return 0;
 }

-void ne2000_save(QEMUFile* f, void* opaque)
+static int ne2000_post_load(void* opaque, int version_id)
 {
-	NE2000State* s = opaque;
-        uint32_t tmp;
-
-        qemu_put_8s(f, &s->rxcr);
-
-	qemu_put_8s(f, &s->cmd);
-	qemu_put_be32s(f, &s->start);
-	qemu_put_be32s(f, &s->stop);
-	qemu_put_8s(f, &s->boundary);
-	qemu_put_8s(f, &s->tsr);
-	qemu_put_8s(f, &s->tpsr);
-	qemu_put_be16s(f, &s->tcnt);
-	qemu_put_be16s(f, &s->rcnt);
-	qemu_put_be32s(f, &s->rsar);
-	qemu_put_8s(f, &s->rsr);
-	qemu_put_8s(f, &s->isr);
-	qemu_put_8s(f, &s->dcfg);
-	qemu_put_8s(f, &s->imr);
-	qemu_put_buffer(f, s->phys, 6);
-	qemu_put_8s(f, &s->curpag);
-	qemu_put_buffer(f, s->mult, 8);
-        tmp = 0;
-	qemu_put_be32s(f, &tmp); /* ignored, was irq */
-	qemu_put_buffer(f, s->mem, NE2000_MEM_SIZE);
-}
-
-int ne2000_load(QEMUFile* f, void* opaque, int version_id)
-{
-	NE2000State* s = opaque;
-        uint32_t tmp;
-
-        if (version_id > 3)
-            return -EINVAL;
-
-        if (version_id >= 2) {
-            qemu_get_8s(f, &s->rxcr);
-        } else {
-            s->rxcr = 0x0c;
-        }
-
-	qemu_get_8s(f, &s->cmd);
-	qemu_get_be32s(f, &s->start);
-	qemu_get_be32s(f, &s->stop);
-	qemu_get_8s(f, &s->boundary);
-	qemu_get_8s(f, &s->tsr);
-	qemu_get_8s(f, &s->tpsr);
-	qemu_get_be16s(f, &s->tcnt);
-	qemu_get_be16s(f, &s->rcnt);
-	qemu_get_be32s(f, &s->rsar);
-	qemu_get_8s(f, &s->rsr);
-	qemu_get_8s(f, &s->isr);
-	qemu_get_8s(f, &s->dcfg);
-	qemu_get_8s(f, &s->imr);
-	qemu_get_buffer(f, s->phys, 6);
-	qemu_get_8s(f, &s->curpag);
-	qemu_get_buffer(f, s->mult, 8);
-	qemu_get_be32s(f, &tmp); /* ignored */
-	qemu_get_buffer(f, s->mem, NE2000_MEM_SIZE);
-
-	return 0;
-}
-
-static void pci_ne2000_save(QEMUFile* f, void* opaque)
-{
-	PCINE2000State* s = opaque;
+    NE2000State* s = opaque;

-        pci_device_save(&s->dev, f);
-        ne2000_save(f, &s->ne2000);
+    if (version_id < 2) {
+        s->rxcr = 0x0c;
+    }
+    return 0;
 }

-static int pci_ne2000_load(QEMUFile* f, void* opaque, int version_id)
-{
-	PCINE2000State* s = opaque;
-        int ret;
-
-        if (version_id > 3)
-            return -EINVAL;
-
-        if (version_id >= 3) {
-            ret = pci_device_load(&s->dev, f);
-            if (ret < 0)
-                return ret;
-        }
+const VMStateDescription vmstate_ne2000 = {
+    .name = "ne2000",
+    .version_id = 2,
+    .minimum_version_id = 0,
+    .minimum_version_id_old = 0,
+    .post_load = ne2000_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8_V(rxcr, NE2000State, 2),
+        VMSTATE_UINT8(cmd, NE2000State),
+        VMSTATE_UINT32(start, NE2000State),
+        VMSTATE_UINT32(stop, NE2000State),
+        VMSTATE_UINT8(boundary, NE2000State),
+        VMSTATE_UINT8(tsr, NE2000State),
+        VMSTATE_UINT8(tpsr, NE2000State),
+        VMSTATE_UINT16(tcnt, NE2000State),
+        VMSTATE_UINT16(rcnt, NE2000State),
+        VMSTATE_UINT32(rsar, NE2000State),
+        VMSTATE_UINT8(rsr, NE2000State),
+        VMSTATE_UINT8(isr, NE2000State),
+        VMSTATE_UINT8(dcfg, NE2000State),
+        VMSTATE_UINT8(imr, NE2000State),
+        VMSTATE_BUFFER(phys, NE2000State),
+        VMSTATE_UINT8(curpag, NE2000State),
+        VMSTATE_BUFFER(mult, NE2000State),
+        VMSTATE_UNUSED(4), /* was irq */
+        VMSTATE_BUFFER(mem, NE2000State),
+        VMSTATE_END_OF_LIST()
+    }
+};

-        return ne2000_load(f, &s->ne2000, version_id);
-}
+const VMStateDescription vmstate_pci_ne2000 = {
+    .name = "ne2000",
+    .version_id = 3,
+    .minimum_version_id = 3,
+    .minimum_version_id_old = 3,
+    .fields      = (VMStateField []) {
+        VMSTATE_PCI_DEVICE(dev, PCINE2000State),
+        VMSTATE_STRUCT(ne2000, PCINE2000State, 0, vmstate_ne2000, NE2000State),
+        VMSTATE_END_OF_LIST()
+    }
+};

 /***********************************************************/
 /* PCI NE2000 definitions */
@@ -738,7 +701,7 @@  static void ne2000_cleanup(VLANClientState *vc)
 {
     NE2000State *s = vc->opaque;

-    unregister_savevm("ne2000", s);
+    vmstate_unregister(&vmstate_pci_ne2000, s);
 }

 static int pci_ne2000_init(PCIDevice *pci_dev)
@@ -766,7 +729,7 @@  static int pci_ne2000_init(PCIDevice *pci_dev)

     qemu_format_nic_info_str(s->vc, s->macaddr);

-    register_savevm("ne2000", -1, 3, pci_ne2000_save, pci_ne2000_load, d);
+    vmstate_register(-1, &vmstate_pci_ne2000, d);
     return 0;
 }

diff --git a/hw/ne2000.h b/hw/ne2000.h
index 92a2ddb..9bd5cab 100644
--- a/hw/ne2000.h
+++ b/hw/ne2000.h
@@ -33,8 +33,7 @@  void ne2000_asic_ioport_write(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ne2000_asic_ioport_read(void *opaque, uint32_t addr);
 void ne2000_reset_ioport_write(void *opaque, uint32_t addr, uint32_t val);
 uint32_t ne2000_reset_ioport_read(void *opaque, uint32_t addr);
-void ne2000_save(QEMUFile* f, void* opaque);
-int ne2000_load(QEMUFile* f, void* opaque, int version_id);
+extern const VMStateDescription vmstate_ne2000;
 void ne2000_reset(NE2000State *s);
 int ne2000_can_receive(VLANClientState *vc);
 ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_);