And move the "it_shift" field there, since it's specific. Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> --- hw/char/serial.c | 10 ++++++---- include/hw/char/serial.h | 9 +++++++-- 2 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/hw/char/serial.c b/hw/char/serial.c index b623c4e79f..4fc2bcedf1 100644 --- a/hw/char/serial.c +++ b/hw/char/serial.c @@ -1025,14 +1025,14 @@ static const TypeInfo serial_info = { static uint64_t serial_mm_read(void *opaque, hwaddr addr, unsigned size) { - SerialState *s = opaque; + SerialMMState *s = SERIAL_MM(opaque); return serial_ioport_read(s, addr >> s->it_shift, 1); } static void serial_mm_write(void *opaque, hwaddr addr, uint64_t value, unsigned size) { - SerialState *s = opaque; + SerialMMState *s = SERIAL_MM(opaque); value &= 255; serial_ioport_write(s, addr >> s->it_shift, value, 1); } @@ -1066,10 +1066,11 @@ SerialState *serial_mm_init(MemoryRegion *address_space, qemu_irq irq, int baudbase, Chardev *chr, enum device_endian end) { - DeviceState *dev = DEVICE(object_new(TYPE_SERIAL)); + DeviceState *dev = DEVICE(object_new(TYPE_SERIAL_MM)); + SerialMMState *m = SERIAL_MM(dev); SerialState *s = SERIAL(dev); - s->it_shift = it_shift; + m->it_shift = it_shift; s->irq = irq; s->baudbase = baudbase; qdev_prop_set_chr(dev, "chardev", chr); @@ -1088,6 +1089,7 @@ SerialState *serial_mm_init(MemoryRegion *address_space, static const TypeInfo serial_mm_info = { .name = TYPE_SERIAL_MM, .parent = TYPE_SERIAL, + .instance_size = sizeof(SerialMMState), }; static void serial_register_types(void) diff --git a/include/hw/char/serial.h b/include/hw/char/serial.h index 2b8dbd88f1..62962e3c5a 100644 --- a/include/hw/char/serial.h +++ b/include/hw/char/serial.h @@ -57,7 +57,6 @@ typedef struct SerialState { qemu_irq irq; CharBackend chr; int last_break_enable; - int it_shift; int baudbase; uint32_t tsr_retry; guint watch_tag; @@ -80,6 +79,12 @@ typedef struct SerialState { MemoryRegion io; } SerialState; +typedef struct SerialMMState { + SerialState parent; + + int it_shift; +} SerialMMState; + extern const VMStateDescription vmstate_serial; extern const MemoryRegionOps serial_io_ops; @@ -91,7 +96,7 @@ void serial_set_frequency(SerialState *s, uint32_t frequency); #define SERIAL(s) OBJECT_CHECK(SerialState, (s), TYPE_SERIAL) #define TYPE_SERIAL_MM "serial-mm" -#define SERIAL_MM(s) OBJECT_CHECK(SerialState, (s), TYPE_SERIAL_MM) +#define SERIAL_MM(s) OBJECT_CHECK(SerialMMState, (s), TYPE_SERIAL_MM) SerialState *serial_init(int base, qemu_irq irq, int baudbase, Chardev *chr, MemoryRegion *system_io); -- 2.23.0.606.g08da6496b6