Patchwork [RFC,08/10] fdc: Allow to reconfigure ISA I/O base

login
register
mail settings
Submitter Andreas Färber
Date June 6, 2011, 4:20 p.m.
Message ID <1307377259-41434-9-git-send-email-andreas.faerber@web.de>
Download mbox | patch
Permalink /patch/98987/
State New
Headers show

Comments

Andreas Färber - June 6, 2011, 4:20 p.m.
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 hw/fdc.c |   29 ++++++++++++++++++++++++++---
 hw/fdc.h |    3 +++
 2 files changed, 29 insertions(+), 3 deletions(-)

Patch

diff --git a/hw/fdc.c b/hw/fdc.c
index f4e3e0d..abdd806 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -1894,11 +1894,10 @@  static int fdctrl_init_common(FDCtrl *fdctrl)
     return fdctrl_connect_drives(fdctrl);
 }
 
-static int isabus_fdc_init1(ISADevice *dev)
+static void isabus_fdc_init_iobase(FDCtrlISABus *isa)
 {
-    FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
+    ISADevice *dev = &isa->busdev;
     FDCtrl *fdctrl = &isa->state;
-    int ret;
 
     register_ioport_read(isa->iobase + 0x01, 5, 1,
                          &fdctrl_read_port, fdctrl);
@@ -1910,6 +1909,30 @@  static int isabus_fdc_init1(ISADevice *dev)
                           &fdctrl_write_port, fdctrl);
     isa_init_ioport_range(dev, isa->iobase, 6);
     isa_init_ioport(dev, isa->iobase + 7);
+}
+
+void fdctrl_isa_reconfigure_iobase(ISADevice *dev, uint32_t base)
+{
+    FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
+
+    if (base != isa->iobase) {
+        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->iobase = base;
+        isabus_fdc_init_iobase(isa);
+    }
+}
+
+static int isabus_fdc_init1(ISADevice *dev)
+{
+    FDCtrlISABus *isa = DO_UPCAST(FDCtrlISABus, busdev, dev);
+    FDCtrl *fdctrl = &isa->state;
+    int ret;
+
+    isabus_fdc_init_iobase(isa);
 
     isa_init_irq(&isa->busdev, &fdctrl->irq, isa->irq);
     fdctrl->dma_chann = isa->dma;
diff --git a/hw/fdc.h b/hw/fdc.h
index 09f73c6..3e410e9 100644
--- a/hw/fdc.h
+++ b/hw/fdc.h
@@ -28,4 +28,7 @@  void fdctrl_init_sysbus(qemu_irq irq, int dma_chann,
                         target_phys_addr_t mmio_base, DriveInfo **fds);
 void sun4m_fdctrl_init(qemu_irq irq, target_phys_addr_t io_base,
                        DriveInfo **fds, qemu_irq *fdc_tc);
+
+void fdctrl_isa_reconfigure_iobase(ISADevice *dev, uint32_t base);
+
 #endif