diff options
author | Juan Quintela <quintela@redhat.com> | 2009-10-07 17:59:47 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-10-27 12:28:45 -0500 |
commit | 37159f1305ef9751c8939443eae218cce24b9beb (patch) | |
tree | 5c6887fb8375abf16363ceece25ec84d4ab42405 | |
parent | 25dc563b09476c503634892c7a55d887ae7dc4ff (diff) | |
download | qemu-37159f1305ef9751c8939443eae218cce24b9beb.zip qemu-37159f1305ef9751c8939443eae218cce24b9beb.tar.gz qemu-37159f1305ef9751c8939443eae218cce24b9beb.tar.bz2 |
ide: port ide_drive to vmstate
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r-- | hw/ide/core.c | 113 |
1 files changed, 56 insertions, 57 deletions
diff --git a/hw/ide/core.c b/hw/ide/core.c index aeff034..c08d5aa 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -2591,70 +2591,69 @@ void ide_init_ioport(IDEBus *bus, int iobase, int iobase2) register_ioport_read(iobase, 4, 4, ide_data_readl, bus); } -/* save per IDE drive data */ -void ide_save(QEMUFile* f, IDEState *s) +static bool is_identify_set(void *opaque, int version_id) { - qemu_put_be32(f, s->mult_sectors); - qemu_put_be32(f, s->identify_set); - if (s->identify_set) { - qemu_put_buffer(f, (const uint8_t *)s->identify_data, 512); - } - qemu_put_8s(f, &s->feature); - qemu_put_8s(f, &s->error); - qemu_put_be32s(f, &s->nsector); - qemu_put_8s(f, &s->sector); - qemu_put_8s(f, &s->lcyl); - qemu_put_8s(f, &s->hcyl); - qemu_put_8s(f, &s->hob_feature); - qemu_put_8s(f, &s->hob_nsector); - qemu_put_8s(f, &s->hob_sector); - qemu_put_8s(f, &s->hob_lcyl); - qemu_put_8s(f, &s->hob_hcyl); - qemu_put_8s(f, &s->select); - qemu_put_8s(f, &s->status); - qemu_put_8s(f, &s->lba48); - - qemu_put_8s(f, &s->sense_key); - qemu_put_8s(f, &s->asc); - qemu_put_8s(f, &s->cdrom_changed); - /* XXX: if a transfer is pending, we do not save it yet */ -} - -/* load per IDE drive data */ -void ide_load(QEMUFile* f, IDEState *s, int version_id) + IDEState *s = opaque; + + return s->identify_set != 0; +} + +static int ide_drive_post_load(void *opaque, int version_id) { - s->mult_sectors=qemu_get_be32(f); - s->identify_set=qemu_get_be32(f); - if (s->identify_set) { - qemu_get_buffer(f, (uint8_t *)s->identify_data, 512); - } - qemu_get_8s(f, &s->feature); - qemu_get_8s(f, &s->error); - qemu_get_be32s(f, &s->nsector); - qemu_get_8s(f, &s->sector); - qemu_get_8s(f, &s->lcyl); - qemu_get_8s(f, &s->hcyl); - qemu_get_8s(f, &s->hob_feature); - qemu_get_8s(f, &s->hob_nsector); - qemu_get_8s(f, &s->hob_sector); - qemu_get_8s(f, &s->hob_lcyl); - qemu_get_8s(f, &s->hob_hcyl); - qemu_get_8s(f, &s->select); - qemu_get_8s(f, &s->status); - qemu_get_8s(f, &s->lba48); - - qemu_get_8s(f, &s->sense_key); - qemu_get_8s(f, &s->asc); - if (version_id == 3) { - qemu_get_8s(f, &s->cdrom_changed); - } else { + IDEState *s = opaque; + + if (version_id < 3) { if (s->sense_key == SENSE_UNIT_ATTENTION && - s->asc == ASC_MEDIUM_MAY_HAVE_CHANGED) + s->asc == ASC_MEDIUM_MAY_HAVE_CHANGED) { s->cdrom_changed = 1; + } } - /* XXX: if a transfer is pending, we do not save it yet */ + return 0; } +const VMStateDescription vmstate_ide_drive = { + .name = "ide_drive", + .version_id = 3, + .minimum_version_id = 0, + .minimum_version_id_old = 0, + .post_load = ide_drive_post_load, + .fields = (VMStateField []) { + VMSTATE_INT32(mult_sectors, IDEState), + VMSTATE_INT32(identify_set, IDEState), + VMSTATE_BUFFER_TEST(identify_data, IDEState, is_identify_set), + VMSTATE_UINT8(feature, IDEState), + VMSTATE_UINT8(error, IDEState), + VMSTATE_UINT32(nsector, IDEState), + VMSTATE_UINT8(sector, IDEState), + VMSTATE_UINT8(lcyl, IDEState), + VMSTATE_UINT8(hcyl, IDEState), + VMSTATE_UINT8(hob_feature, IDEState), + VMSTATE_UINT8(hob_sector, IDEState), + VMSTATE_UINT8(hob_nsector, IDEState), + VMSTATE_UINT8(hob_lcyl, IDEState), + VMSTATE_UINT8(hob_hcyl, IDEState), + VMSTATE_UINT8(select, IDEState), + VMSTATE_UINT8(status, IDEState), + VMSTATE_UINT8(lba48, IDEState), + VMSTATE_UINT8(sense_key, IDEState), + VMSTATE_UINT8(asc, IDEState), + VMSTATE_UINT8_V(cdrom_changed, IDEState, 3), + /* XXX: if a transfer is pending, we do not save it yet */ + VMSTATE_END_OF_LIST() + } +}; + +void ide_save(QEMUFile* f, IDEState *s) +{ + vmstate_save_state(f, &vmstate_ide_drive, s); +} + +void ide_load(QEMUFile* f, IDEState *s, int version_id) +{ + vmstate_load_state(f, &vmstate_ide_drive, s, vmstate_ide_drive.version_id); +} + + const VMStateDescription vmstate_ide_bus = { .name = "ide_bus", .version_id = 1, |