Signed-off-by: Andreas Färber <andreas.faer...@web.de>
---
 hw/serial.c |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/hw/serial.c b/hw/serial.c
index 0ee61dd..ec1e0a0 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_statefn(ISADevice *dev, bool enabled)
+{
+    ISASerialState *isa = DO_UPCAST(ISASerialState, dev, dev);
+    SerialState *s = &isa->state;
+
+    if (enabled) {
+        isa_init_irq(dev, &s->irq, isa->isairq);
+
+        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);
+    } else {
+        isa_discard_irq(dev, isa->isairq);
+
+        isa_discard_ioport_range(dev, isa->iobase, 8);
+        isa_unassign_ioport(isa->iobase, 8);
+    }
+}
+
 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 };
 
@@ -772,13 +791,10 @@ static int serial_isa_initfn(ISADevice *dev)
     index++;
 
     s->baudbase = 115200;
-    isa_init_irq(dev, &s->irq, isa->isairq);
     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_statefn(dev, true);
     return 0;
 }
 
@@ -962,6 +978,7 @@ static ISADeviceInfo serial_isa_info = {
     .qdev.size  = sizeof(ISASerialState),
     .qdev.vmsd  = &vmstate_isa_serial,
     .init       = serial_isa_initfn,
+    .set_state  = serial_isa_statefn,
     .qdev.props = (Property[]) {
         DEFINE_PROP_UINT32("index", ISASerialState, index,   -1),
         DEFINE_PROP_HEX32("iobase", ISASerialState, iobase,  -1),
-- 
1.7.5.3


Reply via email to