diff options
author | Juan Quintela <quintela@redhat.com> | 2009-10-07 20:55:32 +0200 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-10-27 12:28:46 -0500 |
commit | 407a4f3073803a948843617239f1729faaeda23f (patch) | |
tree | 68103f93ef727b7c1cee29cc01de24e6fe7a4f66 /hw | |
parent | 44bfa332813a9dde9349fa52b1807706143d5d66 (diff) |
ide: port pci ide to vmstate
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/ide/cmd646.c | 2 | ||||
-rw-r--r-- | hw/ide/internal.h | 3 | ||||
-rw-r--r-- | hw/ide/pci.c | 95 | ||||
-rw-r--r-- | hw/ide/pci.h | 4 | ||||
-rw-r--r-- | hw/ide/piix.c | 2 |
5 files changed, 43 insertions, 63 deletions
diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c index 5c8f615258..ea116fce71 100644 --- a/hw/ide/cmd646.c +++ b/hw/ide/cmd646.c @@ -233,7 +233,7 @@ static int pci_cmd646_ide_initfn(PCIDevice *dev) ide_init2(&d->bus[0], NULL, NULL, irq[0]); ide_init2(&d->bus[1], NULL, NULL, irq[1]); - register_savevm("ide", 0, 3, pci_ide_save, pci_ide_load, d); + vmstate_register(0, &vmstate_ide_pci, d); qemu_register_reset(cmd646_reset, d); cmd646_reset(d); return 0; diff --git a/hw/ide/internal.h b/hw/ide/internal.h index a67e39f461..158146e39d 100644 --- a/hw/ide/internal.h +++ b/hw/ide/internal.h @@ -517,6 +517,9 @@ extern const VMStateDescription vmstate_ide_bus; #define VMSTATE_IDE_BUS(_field, _state) \ VMSTATE_STRUCT(_field, _state, 1, vmstate_ide_bus, IDEBus) +#define VMSTATE_IDE_BUS_ARRAY(_field, _state, _num) \ + VMSTATE_STRUCT_ARRAY(_field, _state, _num, 1, vmstate_ide_bus, IDEBus) + extern const VMStateDescription vmstate_ide_drive; #define VMSTATE_IDE_DRIVES(_field, _state) \ diff --git a/hw/ide/pci.c b/hw/ide/pci.c index dea126a3cd..780fc5f115 100644 --- a/hw/ide/pci.c +++ b/hw/ide/pci.c @@ -121,75 +121,52 @@ void bmdma_addr_writel(void *opaque, uint32_t addr, uint32_t val) bm->cur_addr = bm->addr; } -void pci_ide_save(QEMUFile* f, void *opaque) -{ - PCIIDEState *d = opaque; - int i; - - pci_device_save(&d->dev, f); - - for(i = 0; i < 2; i++) { - BMDMAState *bm = &d->bmdma[i]; - uint8_t ifidx; - qemu_put_8s(f, &bm->cmd); - qemu_put_8s(f, &bm->status); - qemu_put_be32s(f, &bm->addr); - qemu_put_sbe64s(f, &bm->sector_num); - qemu_put_be32s(f, &bm->nsector); - ifidx = bm->unit + 2*i; - qemu_put_8s(f, &ifidx); - /* XXX: if a transfer is pending, we do not save it yet */ +static const VMStateDescription vmstate_bmdma = { + .name = "ide bmdma", + .version_id = 3, + .minimum_version_id = 0, + .minimum_version_id_old = 0, + .fields = (VMStateField []) { + VMSTATE_UINT8(cmd, BMDMAState), + VMSTATE_UINT8(status, BMDMAState), + VMSTATE_UINT32(addr, BMDMAState), + VMSTATE_INT64(sector_num, BMDMAState), + VMSTATE_UINT32(nsector, BMDMAState), + VMSTATE_UINT8(unit, BMDMAState), + VMSTATE_END_OF_LIST() } +}; - /* per IDE interface data */ - for(i = 0; i < 2; i++) { - idebus_save(f, d->bus+i); - } - - /* per IDE drive data */ - for(i = 0; i < 2; i++) { - ide_save(f, &d->bus[i].ifs[0]); - ide_save(f, &d->bus[i].ifs[1]); - } -} - -int pci_ide_load(QEMUFile* f, void *opaque, int version_id) +static int ide_pci_post_load(void *opaque, int version_id) { PCIIDEState *d = opaque; - int ret, i; - - if (version_id != 2 && version_id != 3) - return -EINVAL; - ret = pci_device_load(&d->dev, f); - if (ret < 0) - return ret; - - for(i = 0; i < 2; i++) { - BMDMAState *bm = &d->bmdma[i]; - uint8_t ifidx; - qemu_get_8s(f, &bm->cmd); - qemu_get_8s(f, &bm->status); - qemu_get_be32s(f, &bm->addr); - qemu_get_sbe64s(f, &bm->sector_num); - qemu_get_be32s(f, &bm->nsector); - qemu_get_8s(f, &ifidx); - bm->unit = ifidx & 1; - /* XXX: if a transfer is pending, we do not save it yet */ - } - - /* per IDE interface data */ - for(i = 0; i < 2; i++) { - idebus_load(f, d->bus+i, version_id); - } + int i; - /* per IDE drive data */ for(i = 0; i < 2; i++) { - ide_load(f, &d->bus[i].ifs[0], version_id); - ide_load(f, &d->bus[i].ifs[1], version_id); + /* current versions always store 0/1, but older version + stored bigger values. We only need last bit */ + d->bmdma[i].unit &= 1; } return 0; } +const VMStateDescription vmstate_ide_pci = { + .name = "ide", + .version_id = 3, + .minimum_version_id = 0, + .minimum_version_id_old = 0, + .post_load = ide_pci_post_load, + .fields = (VMStateField []) { + VMSTATE_PCI_DEVICE(dev, PCIIDEState), + VMSTATE_STRUCT_ARRAY(bmdma, PCIIDEState, 2, 0, + vmstate_bmdma, BMDMAState), + VMSTATE_IDE_BUS_ARRAY(bus, PCIIDEState, 2), + VMSTATE_IDE_DRIVES(bus[0].ifs, PCIIDEState), + VMSTATE_IDE_DRIVES(bus[1].ifs, PCIIDEState), + VMSTATE_END_OF_LIST() + } +}; + void pci_ide_create_devs(PCIDevice *dev, DriveInfo **hd_table) { PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, dev); diff --git a/hw/ide/pci.h b/hw/ide/pci.h index 93775030b1..d46a95eb90 100644 --- a/hw/ide/pci.h +++ b/hw/ide/pci.h @@ -17,7 +17,7 @@ uint32_t bmdma_addr_readw(void *opaque, uint32_t addr); void bmdma_addr_writew(void *opaque, uint32_t addr, uint32_t val); uint32_t bmdma_addr_readl(void *opaque, uint32_t addr); void bmdma_addr_writel(void *opaque, uint32_t addr, uint32_t val); -void pci_ide_save(QEMUFile* f, void *opaque); -int pci_ide_load(QEMUFile* f, void *opaque, int version_id); void pci_ide_create_devs(PCIDevice *dev, DriveInfo **hd_table); + +extern const VMStateDescription vmstate_ide_pci; #endif diff --git a/hw/ide/piix.c b/hw/ide/piix.c index ddce6847df..a17bf5951c 100644 --- a/hw/ide/piix.c +++ b/hw/ide/piix.c @@ -124,7 +124,7 @@ static int pci_piix_ide_initfn(PCIIDEState *d) pci_register_bar(&d->dev, 4, 0x10, PCI_ADDRESS_SPACE_IO, bmdma_map); - register_savevm("ide", 0, 3, pci_ide_save, pci_ide_load, d); + vmstate_register(0, &vmstate_ide_pci, d); ide_bus_new(&d->bus[0], &d->dev.qdev); ide_bus_new(&d->bus[1], &d->dev.qdev); |