vmstate: port i2c_bus device
Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
This commit is contained in:
parent
5b7f53270a
commit
8d0eb050d6
31
hw/i2c.c
31
hw/i2c.c
@ -26,36 +26,43 @@ static struct BusInfo i2c_bus_info = {
|
||||
}
|
||||
};
|
||||
|
||||
static void i2c_bus_save(QEMUFile *f, void *opaque)
|
||||
static void i2c_bus_pre_save(void *opaque)
|
||||
{
|
||||
i2c_bus *bus = (i2c_bus *)opaque;
|
||||
bus->saved_address = bus->current_dev ? bus->current_dev->address : -1;
|
||||
i2c_bus *bus = opaque;
|
||||
|
||||
qemu_put_8s(f, &bus->saved_address);
|
||||
bus->saved_address = bus->current_dev ? bus->current_dev->address : -1;
|
||||
}
|
||||
|
||||
static int i2c_bus_load(QEMUFile *f, void *opaque, int version_id)
|
||||
static int i2c_bus_post_load(void *opaque, int version_id)
|
||||
{
|
||||
i2c_bus *bus = (i2c_bus *)opaque;
|
||||
|
||||
if (version_id != 1)
|
||||
return -EINVAL;
|
||||
i2c_bus *bus = opaque;
|
||||
|
||||
/* The bus is loaded before attached devices, so load and save the
|
||||
current device id. Devices will check themselves as loaded. */
|
||||
qemu_get_8s(f, &bus->saved_address);
|
||||
bus->current_dev = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const VMStateDescription vmstate_i2c_bus = {
|
||||
.name = "i2c_bus",
|
||||
.version_id = 1,
|
||||
.minimum_version_id = 1,
|
||||
.minimum_version_id_old = 1,
|
||||
.pre_save = i2c_bus_pre_save,
|
||||
.post_load = i2c_bus_post_load,
|
||||
.fields = (VMStateField []) {
|
||||
VMSTATE_UINT8(saved_address, i2c_bus),
|
||||
VMSTATE_END_OF_LIST()
|
||||
}
|
||||
};
|
||||
|
||||
/* Create a new I2C bus. */
|
||||
i2c_bus *i2c_init_bus(DeviceState *parent, const char *name)
|
||||
{
|
||||
i2c_bus *bus;
|
||||
|
||||
bus = FROM_QBUS(i2c_bus, qbus_create(&i2c_bus_info, parent, name));
|
||||
register_savevm("i2c_bus", -1, 1, i2c_bus_save, i2c_bus_load, bus);
|
||||
vmstate_register(-1, &vmstate_i2c_bus, bus);
|
||||
return bus;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user