Patchwork [RFC,05/10] serial: 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-6-git-send-email-andreas.faerber@web.de>
Download mbox | patch
Permalink /patch/98992/
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/isa.h    |    3 +++
 hw/serial.c |   23 ++++++++++++++++++++---
 2 files changed, 23 insertions(+), 3 deletions(-)
Richard Henderson - June 6, 2011, 8:08 p.m.
On 06/06/2011 11:20 AM, Andreas Färber wrote:
> +    if (iobase != isa->iobase) {
> +        isa->iobase = iobase;
> +        serial_isa_init_iobase(isa);

Forgot to unregister here?


r~
Andreas Färber - June 6, 2011, 8:25 p.m.
Am 06.06.2011 um 22:08 schrieb Richard Henderson:

> On 06/06/2011 11:20 AM, Andreas Färber wrote:
>> +    if (iobase != isa->iobase) {
>> +        isa->iobase = iobase;
>> +        serial_isa_init_iobase(isa);
>
> Forgot to unregister here?

Yeah, looks like it. Thanks.

Probably some stylistic issues, too. Just an RFC. :)

Andreas

Patch

diff --git a/hw/isa.h b/hw/isa.h
index 54698b5..8bd082a 100644
--- a/hw/isa.h
+++ b/hw/isa.h
@@ -45,6 +45,9 @@  void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size);
 void parallel_isa_reconfigure_iobase(ISADevice *dev, uint32_t base);
 void parallel_isa_reconfigure_irq(ISADevice *dev, uint32_t isairq);
 
+/* serial.c */
+void serial_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/serial.c b/hw/serial.c
index 0ee61dd..dd91272 100644
--- a/hw/serial.c
+++ b/hw/serial.c
@@ -752,6 +752,25 @@  void serial_set_frequency(SerialState *s, uint32_t frequency)
     serial_update_parameters(s);
 }
 
+static void serial_isa_init_iobase(ISASerialState *isa)
+{
+    SerialState *s = &isa->state;
+
+    register_ioport_write(isa->iobase, 8, 1, serial_ioport_write, s);
+    register_ioport_read(isa->iobase, 8, 1, serial_ioport_read, s);
+    isa_init_ioport_range(&isa->dev, isa->iobase, 8);
+}
+
+void serial_isa_reconfigure_iobase(ISADevice *dev, uint32_t iobase)
+{
+    ISASerialState *isa = DO_UPCAST(ISASerialState, dev, dev);
+
+    if (iobase != isa->iobase) {
+        isa->iobase = iobase;
+        serial_isa_init_iobase(isa);
+    }
+}
+
 static const int isa_serial_io[MAX_SERIAL_PORTS] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8 };
 static const int isa_serial_irq[MAX_SERIAL_PORTS] = { 4, 3, 4, 3 };
 
@@ -776,9 +795,7 @@  static int serial_isa_initfn(ISADevice *dev)
     serial_init_core(s);
     qdev_set_legacy_instance_id(&dev->qdev, isa->iobase, 3);
 
-    register_ioport_write(isa->iobase, 8, 1, serial_ioport_write, s);
-    register_ioport_read(isa->iobase, 8, 1, serial_ioport_read, s);
-    isa_init_ioport_range(dev, isa->iobase, 8);
+    serial_isa_init_iobase(isa);
     return 0;
 }