Incorporate ISA VMState. Add "enabled" property.

Signed-off-by: Andreas Färber <andreas.faer...@web.de>
---
 hw/fdc.c |   47 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index f4e3e0d..e2dcff0 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1894,25 +1894,43 @@ static int fdctrl_init_common(FDCtrl *fdctrl)
     return fdctrl_connect_drives(fdctrl);
 }
 
+static int isabus_fdc_set_state(ISADevice *dev, bool enabled)
+{
+    FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
+    FDCtrl *fdctrl = &isa->state;
+
+    if (enabled) {
+        register_ioport_read(isa->iobase + 0x01, 5, 1,
+                             &fdctrl_read_port, fdctrl);
+        register_ioport_read(isa->iobase + 0x07, 1, 1,
+                             &fdctrl_read_port, fdctrl);
+        register_ioport_write(isa->iobase + 0x01, 5, 1,
+                              &fdctrl_write_port, fdctrl);
+        register_ioport_write(isa->iobase + 0x07, 1, 1,
+                              &fdctrl_write_port, fdctrl);
+        isa_init_ioport_range(dev, isa->iobase, 6);
+        isa_init_ioport(dev, isa->iobase + 7);
+
+        isa_init_irq(&isa->busdev, &fdctrl->irq, isa->irq);
+    } else {
+        isa_discard_ioport_range(dev, isa->iobase + 0x07, 1);
+        isa_discard_ioport_range(dev, isa->iobase + 0x01, 5);
+        isa_unassign_ioport(isa->iobase + 7, 1);
+        isa_unassign_ioport(isa->iobase, 6);
+        
+        isa_discard_irq(&isa->busdev, isa->irq);
+    }
+    return 0;
+}
+
 static int isabus_fdc_init1(ISADevice *dev)
 {
     FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
     FDCtrl *fdctrl = &isa->state;
     int ret;
 
-    register_ioport_read(isa->iobase + 0x01, 5, 1,
-                         &fdctrl_read_port, fdctrl);
-    register_ioport_read(isa->iobase + 0x07, 1, 1,
-                         &fdctrl_read_port, fdctrl);
-    register_ioport_write(isa->iobase + 0x01, 5, 1,
-                          &fdctrl_write_port, fdctrl);
-    register_ioport_write(isa->iobase + 0x07, 1, 1,
-                          &fdctrl_write_port, fdctrl);
-    isa_init_ioport_range(dev, isa->iobase, 6);
-    isa_init_ioport(dev, isa->iobase + 7);
-
-    isa_init_irq(&isa->busdev, &fdctrl->irq, isa->irq);
     fdctrl->dma_chann = isa->dma;
+    isabus_fdc_set_state(dev, true);
 
     qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 2);
     ret = fdctrl_init_common(fdctrl);
@@ -1962,9 +1980,10 @@ static int sun4m_fdc_init1(SysBusDevice *dev)
 
 static const VMStateDescription vmstate_isa_fdc ={
     .name = "fdc",
-    .version_id = 2,
+    .version_id = 3,
     .minimum_version_id = 2,
     .fields = (VMStateField []) {
+        VMSTATE_ISA_DEVICE_V(busdev, FDCtrlISABus, 3),
         VMSTATE_STRUCT(state, FDCtrlISABus, 0, vmstate_fdc, FDCtrl),
         VMSTATE_END_OF_LIST()
     }
@@ -1972,6 +1991,7 @@ static const VMStateDescription vmstate_isa_fdc ={
 
 static ISADeviceInfo isa_fdc_info = {
     .init = isabus_fdc_init1,
+    .set_state = isabus_fdc_set_state,
     .qdev.name  = "isa-fdc",
     .qdev.fw_name  = "fdc",
     .qdev.size  = sizeof(FDCtrlISABus),
@@ -1986,6 +2006,7 @@ static ISADeviceInfo isa_fdc_info = {
         DEFINE_PROP_DRIVE("driveB", FDCtrlISABus, state.drives[1].bs),
         DEFINE_PROP_INT32("bootindexA", FDCtrlISABus, bootindexA, -1),
         DEFINE_PROP_INT32("bootindexB", FDCtrlISABus, bootindexB, -1),
+        DEFINE_PROP_BOOL("enabled", FDCtrlISABus, busdev.enabled, true),
         DEFINE_PROP_END_OF_LIST(),
     },
 };
-- 
1.7.5.3


Reply via email to