Patchwork [27/29] ide: add qom property for piix3/piix4-ide state

login
register
mail settings
Submitter Michael Roth
Date Nov. 1, 2012, 1:04 p.m.
Message ID <1351775071-7644-28-git-send-email-mdroth@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/196197/
State New
Headers show

Comments

Michael Roth - Nov. 1, 2012, 1:04 p.m.
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 hw/ide/pci.c  |    9 +++++++--
 hw/ide/pci.h  |    3 +++
 hw/ide/piix.c |   39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 2 deletions(-)

Patch

diff --git a/hw/ide/pci.c b/hw/ide/pci.c
index bcdd70e..6629b3a 100644
--- a/hw/ide/pci.c
+++ b/hw/ide/pci.c
@@ -28,9 +28,14 @@ 
 #include <hw/isa.h>
 #include "block.h"
 #include "dma.h"
+#include "qidl.h"
 
 #include <hw/ide/pci.h>
 
+QIDL_ENABLE()
+QIDL_IMPLEMENT_PUBLIC(BMDMAState)
+QIDL_IMPLEMENT_PUBLIC(PCIIDEState)
+
 #define BMDMA_PAGE_SIZE 4096
 
 static void bmdma_start_dma(IDEDMA *dma, IDEState *s,
@@ -380,7 +385,7 @@  static bool ide_bmdma_status_needed(void *opaque)
     return ((bm->status & abused_bits) != 0);
 }
 
-static void ide_bmdma_pre_save(void *opaque)
+void ide_bmdma_pre_save(void *opaque)
 {
     BMDMAState *bm = opaque;
     uint8_t abused_bits = BM_MIGRATION_COMPAT_STATUS_BITS;
@@ -458,7 +463,7 @@  static const VMStateDescription vmstate_bmdma = {
     }
 };
 
-static int ide_pci_post_load(void *opaque, int version_id)
+int ide_pci_post_load(void *opaque, int version_id)
 {
     PCIIDEState *d = opaque;
     int i;
diff --git a/hw/ide/pci.h b/hw/ide/pci.h
index b54ea26..de9545f 100644
--- a/hw/ide/pci.h
+++ b/hw/ide/pci.h
@@ -4,6 +4,9 @@ 
 #include <hw/ide/internal.h>
 #include "qidl.h"
 
+void ide_bmdma_pre_save(void *opaque);
+int ide_pci_post_load(void *opaque, int version_id);
+
 typedef struct BMDMAState BMDMAState;
 
 QIDL_DECLARE_PUBLIC(BMDMAState) {
diff --git a/hw/ide/piix.c b/hw/ide/piix.c
index 9431bad..e65b689 100644
--- a/hw/ide/piix.c
+++ b/hw/ide/piix.c
@@ -30,9 +30,12 @@ 
 #include "blockdev.h"
 #include "sysemu.h"
 #include "dma.h"
+#include "qidl.h"
 
 #include <hw/ide/pci.h>
 
+QIDL_ENABLE()
+
 static uint64_t bmdma_read(void *opaque, hwaddr addr, unsigned size)
 {
     BMDMAState *bm = opaque;
@@ -147,6 +150,38 @@  static void pci_piix_init_ports(PCIIDEState *d) {
     }
 }
 
+static void pci_piix_ide_get_state(Object *obj, Visitor *v, void *opaque,
+                                   const char *name, Error **errp)
+{
+    PCIDevice *pci = PCI_DEVICE(obj);
+    PCIIDEState *s = DO_UPCAST(PCIIDEState, dev, pci);
+    int i, j;
+
+    for (i = 0; i < 2; i++) {
+        for (j = 0; j < 2; j++) {
+            ide_drive_pio_pre_save(&s->bus[i].ifs[j]);
+        }
+        ide_bmdma_pre_save(&s->bmdma[i]);
+    }
+    QIDL_VISIT_TYPE(PCIIDEState, v, &s, name, errp);
+}
+
+static void pci_piix_ide_set_state(Object *obj, Visitor *v, void *opaque,
+                                   const char *name, Error **errp)
+{
+    PCIDevice *pci = PCI_DEVICE(obj);
+    PCIIDEState *s = DO_UPCAST(PCIIDEState, dev, pci);
+    int i, j;
+
+    QIDL_VISIT_TYPE(PCIIDEState, v, &s, name, errp);
+    for (i = 0; i < 2; i++) {
+        for (j = 0; j < 2; j++) {
+            ide_drive_pio_post_load(&s->bus[i].ifs[j], -1);
+        }
+    }
+    ide_pci_post_load(s, -1);
+}
+
 static int pci_piix_ide_initfn(PCIDevice *dev)
 {
     PCIIDEState *d = DO_UPCAST(PCIIDEState, dev, dev);
@@ -162,6 +197,10 @@  static int pci_piix_ide_initfn(PCIDevice *dev)
     vmstate_register(&d->dev.qdev, 0, &vmstate_ide_pci, d);
 
     pci_piix_init_ports(d);
+    object_property_add(OBJECT(d), "state", "PCIIDEState",
+                        pci_piix_ide_get_state, pci_piix_ide_set_state,
+                        NULL, NULL, NULL);
+    QIDL_SCHEMA_ADD_LINK(PCIIDEState, OBJECT(d), "state_schema", NULL);
 
     return 0;
 }