Patchwork [12/13] ide: port pci ide to vmstate

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

Comments

Juan Quintela - Oct. 14, 2009, 11:37 a.m.
Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 hw/ide/cmd646.c   |    2 +-
 hw/ide/internal.h |    3 ++
 hw/ide/pci.c      |   95 ++++++++++++++++++++---------------------------------
 hw/ide/pci.h      |    4 +-
 hw/ide/piix.c     |    2 +-
 5 files changed, 43 insertions(+), 63 deletions(-)

Patch

diff --git a/hw/ide/cmd646.c b/hw/ide/cmd646.c
index 5c8f615..ea116fc 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 a67e39f..158146e 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 dea126a..780fc5f 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 9377503..d46a95e 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 ddce684..a17bf59 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);