diff mbox

[RFC,v2,09/10] ide: Implement ISA set_state() callback

Message ID 1307458978-51287-10-git-send-email-andreas.faerber@web.de
State New
Headers show

Commit Message

Andreas Färber June 7, 2011, 3:02 p.m. UTC
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 hw/ide/isa.c |   27 +++++++++++++++++++++++----
 1 files changed, 23 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/hw/ide/isa.c b/hw/ide/isa.c
index 4ac7453..e6ee263 100644
--- a/hw/ide/isa.c
+++ b/hw/ide/isa.c
@@ -62,15 +62,33 @@  static const VMStateDescription vmstate_ide_isa = {
     }
 };
 
+static void 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);
+    }
+}
+
 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,6 +120,7 @@  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),