qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 12/13] ide: port pci ide to vmstate
Date: Wed, 14 Oct 2009 13:37:52 +0200	[thread overview]
Message-ID: <0f462e6bd5d0b59cb7de872d7c9c06b4bbdc99a7.1255520033.git.quintela@redhat.com> (raw)
In-Reply-To: <cover.1255520033.git.quintela@redhat.com>
In-Reply-To: <cover.1255520033.git.quintela@redhat.com>


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(-)

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);
-- 
1.6.2.5

  parent reply	other threads:[~2009-10-14 11:38 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-14 11:37 [Qemu-devel] [PATCH 00/13] Port ide to vmstate Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 01/13] ide: port idebus " Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 02/13] ide: change identify_data type to uint8_t Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 03/13] vmstate: add VMSTATE_BUFFER_TEST Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 04/13] ide: port ide_drive to vmstate Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 05/13] ide: microdrive cycle field is set as uint8_t Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 06/13] ide: add VMSTATE_IDE_BUS and VMSTATE_IDE_DRIVES Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 07/13] ide: port microdrive to vmstate Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 08/13] ide: include bus in MMIOState Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 09/13] ide: port ide mmio to vmstate Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 10/13] ide: port isa ide " Juan Quintela
2009-10-14 11:37 ` [Qemu-devel] [PATCH 11/13] ide: port pmac " Juan Quintela
2009-10-14 11:37 ` Juan Quintela [this message]
2009-10-14 11:37 ` [Qemu-devel] [PATCH 13/13] ide: pre VMState functions are not needed anymore Juan Quintela

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0f462e6bd5d0b59cb7de872d7c9c06b4bbdc99a7.1255520033.git.quintela@redhat.com \
    --to=quintela@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).