Andreas Färber <andreas.faer...@web.de> writes:

> Incorporate ISA VMState. Add "enabled" property.

Could you explain why you need to stick VMSTATE_ISA_DEVICE_V() into
vmstate_isa_serial, but not for the other devices?

>
> Signed-off-by: Andreas Färber <andreas.faer...@web.de>
> ---
>  hw/serial.c |   30 +++++++++++++++++++++++++-----
>  1 files changed, 25 insertions(+), 5 deletions(-)
>
> diff --git a/hw/serial.c b/hw/serial.c
> index 0ee61dd..a058cb6 100644
> --- a/hw/serial.c
> +++ b/hw/serial.c
> @@ -752,6 +752,26 @@ void serial_set_frequency(SerialState *s, uint32_t 
> frequency)
>      serial_update_parameters(s);
>  }
>  
> +static int 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);
> +    }
> +    return 0;
> +}
> +
>  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,21 +792,19 @@ 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;
>  }
>  
>  static const VMStateDescription vmstate_isa_serial = {
>      .name = "serial",
> -    .version_id = 3,
> +    .version_id = 4,
>      .minimum_version_id = 2,
>      .fields      = (VMStateField []) {
> +        VMSTATE_ISA_DEVICE_V(dev, ISASerialState, 4),
>          VMSTATE_STRUCT(state, ISASerialState, 0, vmstate_serial, 
> SerialState),
>          VMSTATE_END_OF_LIST()
>      }

If I understand vmstate correctly, this breaks migration new -> old.  Do
we care?

> @@ -962,11 +980,13 @@ 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),
>          DEFINE_PROP_UINT32("irq",   ISASerialState, isairq,  -1),
>          DEFINE_PROP_CHR("chardev",  ISASerialState, state.chr),
> +        DEFINE_PROP_BOOL("enabled", ISASerialState, dev.enabled, true),
>          DEFINE_PROP_END_OF_LIST(),
>      },
>  };

Reply via email to