Patchwork [RFC,v4,09/12] fdc: Implement ISA set_state() callback

login
register
mail settings
Submitter Andreas Färber
Date June 8, 2011, 6:55 p.m.
Message ID <1307559319-16183-10-git-send-email-andreas.faerber@web.de>
Download mbox | patch
Permalink /patch/99540/
State New
Headers show

Comments

Andreas Färber - June 8, 2011, 6:55 p.m.
Incorporate ISA VMState. Add "enabled" property.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 hw/fdc.c |   47 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 34 insertions(+), 13 deletions(-)
Gerd Hoffmann - June 9, 2011, 7:56 a.m.
Hi,

> +        VMSTATE_ISA_DEVICE_V(busdev, FDCtrlISABus, 3),

Where is the patch adding this?

cheers,
   Gerd
Andreas Färber - June 9, 2011, 9:23 a.m.
Am 09.06.2011 um 09:56 schrieb Gerd Hoffmann:

>> +        VMSTATE_ISA_DEVICE_V(busdev, FDCtrlISABus, 3),
>
> Where is the patch adding this?

v4 03/12: http://patchwork.ozlabs.org/patch/99537/

Note that there's no VMSTATE_PCI_DEVICE_V(), but I found the _V very  
convenient here.

Andreas

Patch

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(),
     },
 };