Patchwork [07/13] ide: port microdrive to vmstate

login
register
mail settings
Submitter Juan Quintela
Date Oct. 14, 2009, 11:37 a.m.
Message ID <fa6e9797c4de39dac5c0f5e203244a75fe91bbb0.1255520033.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/35950/
State New
Headers show

Comments

Juan Quintela - Oct. 14, 2009, 11:37 a.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/ide/microdrive.c |   61 +++++++++++++++------------------------------------
 1 files changed, 18 insertions(+), 43 deletions(-)

Patch

diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
index 49a9b93..9f7789d 100644
--- a/hw/ide/microdrive.c
+++ b/hw/ide/microdrive.c
@@ -300,48 +300,23 @@  static void md_common_write(void *opaque, uint32_t at, uint16_t value)
     }
 }

-static void md_save(QEMUFile *f, void *opaque)
-{
-    MicroDriveState *s = opaque;
-    int i;
-
-    qemu_put_8s(f, &s->opt);
-    qemu_put_8s(f, &s->stat);
-    qemu_put_8s(f, &s->pins);
-
-    qemu_put_8s(f, &s->ctrl);
-    qemu_put_be16s(f, &s->io);
-    qemu_put_byte(f, s->cycle);
-
-    idebus_save(f, &s->bus);
-
-    for (i = 0; i < 2; i ++)
-        ide_save(f, &s->bus.ifs[i]);
-}
-
-static int md_load(QEMUFile *f, void *opaque, int version_id)
-{
-    MicroDriveState *s = opaque;
-    int i;
-
-    if (version_id != 0 && version_id != 3)
-        return -EINVAL;
-
-    qemu_get_8s(f, &s->opt);
-    qemu_get_8s(f, &s->stat);
-    qemu_get_8s(f, &s->pins);
-
-    qemu_get_8s(f, &s->ctrl);
-    qemu_get_be16s(f, &s->io);
-    s->cycle = qemu_get_byte(f);
-
-    idebus_load(f, &s->bus, version_id);
-
-    for (i = 0; i < 2; i ++)
-        ide_load(f, &s->bus.ifs[i], version_id);
-
-    return 0;
-}
+const VMStateDescription vmstate_microdrive = {
+    .name = "microdrive",
+    .version_id = 3,
+    .minimum_version_id = 0,
+    .minimum_version_id_old = 0,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(opt, MicroDriveState),
+        VMSTATE_UINT8(stat, MicroDriveState),
+        VMSTATE_UINT8(pins, MicroDriveState),
+        VMSTATE_UINT8(ctrl, MicroDriveState),
+        VMSTATE_UINT16(io, MicroDriveState),
+        VMSTATE_UINT8(cycle, MicroDriveState),
+        VMSTATE_IDE_BUS(bus, MicroDriveState),
+        VMSTATE_IDE_DRIVES(bus.ifs, MicroDriveState),
+        VMSTATE_END_OF_LIST()
+    }
+};

 static const uint8_t dscm1xxxx_cis[0x14a] = {
     [0x000] = CISTPL_DEVICE,	/* 5V Device Information */
@@ -569,7 +544,7 @@  PCMCIACardState *dscm1xxxx_init(DriveInfo *bdrv)
     md->bus.ifs[0].mdata_size = METADATA_SIZE;
     md->bus.ifs[0].mdata_storage = (uint8_t *) qemu_mallocz(METADATA_SIZE);

-    register_savevm("microdrive", -1, 3, md_save, md_load, md);
+    vmstate_register(-1, &vmstate_microdrive, md);

     return &md->card;
 }