diff mbox

[RFC,03/10] parallel: Allow to reconfigure ISA I/O base

Message ID 1307377259-41434-4-git-send-email-andreas.faerber@web.de
State New
Headers show

Commit Message

Andreas Färber June 6, 2011, 4:20 p.m. UTC
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 hw/isa.h      |    3 ++
 hw/parallel.c |   70 +++++++++++++++++++++++++++++++++++++++------------------
 2 files changed, 51 insertions(+), 22 deletions(-)
diff mbox

Patch

diff --git a/hw/isa.h b/hw/isa.h
index 789d91c..2bd8c82 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -41,6 +41,9 @@  extern target_phys_addr_t isa_mem_base;
 
 void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size);
 
+/* parallel.c */
+void parallel_isa_reconfigure_iobase(ISADevice *dev, uint32_t base);
+
 /* dma.c */
 int DMA_get_channel_mode (int nchan);
 int DMA_read_memory (int nchan, void *buf, int pos, int size);
diff --git a/hw/parallel.c b/hw/parallel.c
index cc853a5..5cb3856 100644
--- a/hw/parallel.c
+++ b/hw/parallel.c
@@ -446,6 +446,53 @@  static void parallel_reset(void *opaque)
     s->last_read_offset = ~0U;
 }
 
+static void parallel_isa_init_iobase(ISAParallelState *isa)
+{
+    ISADevice *dev = &isa->dev;
+    ParallelState *s = &isa->state;
+    int base;
+
+    base = isa->iobase;
+    if (s->hw_driver) {
+        register_ioport_write(base, 8, 1, parallel_ioport_write_hw, s);
+        register_ioport_read(base, 8, 1, parallel_ioport_read_hw, s);
+        isa_init_ioport_range(dev, base, 8);
+
+        register_ioport_write(base + 4, 1, 2, parallel_ioport_eppdata_write_hw2, s);
+        register_ioport_read(base + 4, 1, 2, parallel_ioport_eppdata_read_hw2, s);
+        register_ioport_write(base + 4, 1, 4, parallel_ioport_eppdata_write_hw4, s);
+        register_ioport_read(base + 4, 1, 4, parallel_ioport_eppdata_read_hw4, s);
+        isa_init_ioport(dev, base + 4);
+        register_ioport_write(base + 0x400, 8, 1, parallel_ioport_ecp_write, s);
+        register_ioport_read(base + 0x400, 8, 1, parallel_ioport_ecp_read, s);
+        isa_init_ioport_range(dev, base + 0x400, 8);
+    } else {
+        register_ioport_write(base, 8, 1, parallel_ioport_write_sw, s);
+        register_ioport_read(base, 8, 1, parallel_ioport_read_sw, s);
+        isa_init_ioport_range(dev, base, 8);
+    }
+}
+
+void parallel_isa_reconfigure_iobase(ISADevice *dev, uint32_t base)
+{
+    ISAParallelState *isa = DO_UPCAST(ISAParallelState, dev, dev);
+    ParallelState *s = &isa->state;
+
+    if (base != isa->iobase) {
+        isa_discard_ioport_range(dev, base, 8);
+        isa_unassign_ioport(base, 8);
+        if (s->hw_driver) {
+            isa_discard_ioport_range(dev, base + 4, 1);
+            isa_unassign_ioport(base + 4, 1);
+            isa_discard_ioport_range(dev, base + 0x400, 8);
+            isa_unassign_ioport(base + 0x400, 8);
+        }
+
+        isa->iobase = base;
+        parallel_isa_init_iobase(isa);
+    }
+}
+
 static const int isa_parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
 
 static int parallel_isa_initfn(ISADevice *dev)
@@ -453,7 +500,6 @@  static int parallel_isa_initfn(ISADevice *dev)
     static int index;
     ISAParallelState *isa = DO_UPCAST(ISAParallelState, dev, dev);
     ParallelState *s = &isa->state;
-    int base;
     uint8_t dummy;
 
     if (!s->chr) {
@@ -469,7 +515,6 @@  static int parallel_isa_initfn(ISADevice *dev)
         isa->iobase = isa_parallel_io[isa->index];
     index++;
 
-    base = isa->iobase;
     isa_init_irq(dev, &s->irq, isa->isairq);
     qemu_register_reset(parallel_reset, s);
 
@@ -477,26 +522,7 @@  static int parallel_isa_initfn(ISADevice *dev)
         s->hw_driver = 1;
         s->status = dummy;
     }
-
-    if (s->hw_driver) {
-        register_ioport_write(base, 8, 1, parallel_ioport_write_hw, s);
-        register_ioport_read(base, 8, 1, parallel_ioport_read_hw, s);
-        isa_init_ioport_range(dev, base, 8);
-
-        register_ioport_write(base+4, 1, 2, parallel_ioport_eppdata_write_hw2, s);
-        register_ioport_read(base+4, 1, 2, parallel_ioport_eppdata_read_hw2, s);
-        register_ioport_write(base+4, 1, 4, parallel_ioport_eppdata_write_hw4, s);
-        register_ioport_read(base+4, 1, 4, parallel_ioport_eppdata_read_hw4, s);
-        isa_init_ioport(dev, base+4);
-        register_ioport_write(base+0x400, 8, 1, parallel_ioport_ecp_write, s);
-        register_ioport_read(base+0x400, 8, 1, parallel_ioport_ecp_read, s);
-        isa_init_ioport_range(dev, base+0x400, 8);
-    }
-    else {
-        register_ioport_write(base, 8, 1, parallel_ioport_write_sw, s);
-        register_ioport_read(base, 8, 1, parallel_ioport_read_sw, s);
-        isa_init_ioport_range(dev, base, 8);
-    }
+    parallel_isa_init_iobase(isa);
     return 0;
 }