Patchwork [04/20] vmstate: port i2c_slave device

login
register
mail settings
Submitter Juan Quintela
Date Sept. 11, 2009, 10:10 a.m.
Message ID <191b407d783f4b02582579da89aa91b638f37575.1252662256.git.quintela@redhat.com>
Download mbox | patch
Permalink /patch/33429/
State Superseded
Headers show

Comments

Juan Quintela - Sept. 11, 2009, 10:10 a.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/i2c.c |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

Patch

diff --git a/hw/i2c.c b/hw/i2c.c
index 8d9e950..bdfe009 100644
--- a/hw/i2c.c
+++ b/hw/i2c.c
@@ -142,19 +142,38 @@  void i2c_nack(i2c_bus *bus)
     dev->info->event(dev, I2C_NACK);
 }

-void i2c_slave_save(QEMUFile *f, i2c_slave *dev)
-{
-    qemu_put_8s(f, &dev->address);
-}
-
-void i2c_slave_load(QEMUFile *f, i2c_slave *dev)
+static int i2c_slave_post_load(void *opaque)
 {
+    i2c_slave *dev = opaque;
     i2c_bus *bus;
     bus = FROM_QBUS(i2c_bus, qdev_get_parent_bus(&dev->qdev));
-    qemu_get_8s(f, &dev->address);
     if (bus->saved_address == dev->address) {
         bus->current_dev = dev;
     }
+    return 0;
+}
+
+static const VMStateDescription vmstate_i2c_slave = {
+    .name = "i2c_slave",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .post_load = i2c_slave_post_load,
+    .fields      = (VMStateField []) {
+        VMSTATE_UINT8(address, i2c_slave),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+void i2c_slave_save(QEMUFile *f, i2c_slave *dev)
+{
+    vmstate_save_state(f, &vmstate_i2c_slave, dev);
+}
+
+void i2c_slave_load(QEMUFile *f, i2c_slave *dev)
+{
+    vmstate_load_state(f, &vmstate_i2c_slave, dev,
+                       vmstate_i2c_slave.version_id);
 }

 static int i2c_slave_qdev_init(DeviceState *dev, DeviceInfo *base)