Incorporate ISA VMState. Add "enabled" property.

Signed-off-by: Andreas Färber <andreas.faer...@web.de>
---
 hw/ide/isa.c |   32 +++++++++++++++++++++++++++-----
 1 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 4ac7453..fd5c55e 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -52,25 +52,45 @@ static void isa_ide_reset(DeviceState *d)
 
 static const VMStateDescription vmstate_ide_isa = {
     .name = "isa-ide",
-    .version_id = 3,
+    .version_id = 4,
     .minimum_version_id = 0,
     .minimum_version_id_old = 0,
     .fields      = (VMStateField []) {
+        VMSTATE_ISA_DEVICE_V(dev, ISAIDEState, 4),
         VMSTATE_IDE_BUS(bus, ISAIDEState),
         VMSTATE_IDE_DRIVES(bus.ifs, ISAIDEState),
         VMSTATE_END_OF_LIST()
     }
 };
 
+static int isa_ide_statefn(ISADevice *dev, bool enabled)
+{
+    ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
+
+    if (enabled) {
+        ide_init_ioport(&s->bus, s->iobase, s->iobase2);
+
+        isa_init_ioport_range(dev, s->iobase, 8);
+        isa_init_ioport(dev, s->iobase2);
+
+        isa_init_irq(dev, &s->irq, s->isairq);
+    } else {
+        ide_discard_ioport(s->iobase, s->iobase2);
+
+        isa_discard_ioport_range(dev, s->iobase2, 1);
+        isa_discard_ioport_range(dev, s->iobase, 8);
+
+        isa_discard_irq(dev, s->isairq);
+    }
+    return 0;
+}
+
 static int isa_ide_initfn(ISADevice *dev)
 {
     ISAIDEState *s = DO_UPCAST(ISAIDEState, dev, dev);
 
     ide_bus_new(&s->bus, &s->dev.qdev, 0);
-    ide_init_ioport(&s->bus, s->iobase, s->iobase2);
-    isa_init_irq(dev, &s->irq, s->isairq);
-    isa_init_ioport_range(dev, s->iobase, 8);
-    isa_init_ioport(dev, s->iobase2);
+    isa_ide_statefn(dev, true);
     ide_init2(&s->bus, s->irq);
     vmstate_register(&dev->qdev, 0, &vmstate_ide_isa, s);
     return 0;
@@ -102,11 +122,13 @@ static ISADeviceInfo isa_ide_info = {
     .qdev.fw_name  = "ide",
     .qdev.size  = sizeof(ISAIDEState),
     .init       = isa_ide_initfn,
+    .set_state  = isa_ide_statefn,
     .qdev.reset = isa_ide_reset,
     .qdev.props = (Property[]) {
         DEFINE_PROP_HEX32("iobase",  ISAIDEState, iobase,  0x1f0),
         DEFINE_PROP_HEX32("iobase2", ISAIDEState, iobase2, 0x3f6),
         DEFINE_PROP_UINT32("irq",    ISAIDEState, isairq,  14),
+        DEFINE_PROP_BOOL("enabled",  ISAIDEState, dev.enabled, true),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
-- 
1.7.5.3


Reply via email to