On Thu, Nov 21, 2019 at 6:04 PM Peter Maydell <peter.mayd...@linaro.org> wrote: > > On Wed, 20 Nov 2019 at 15:31, Marc-André Lureau > <marcandre.lur...@redhat.com> wrote: > > > > Embed the SerialMM sybus device, and re-export its "chardev" property. > > That way, we can get rid of PROP_PTR "chr-state" and better track > > devices relationship. > > > > Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com> > > --- > > hw/display/sm501.c | 33 ++++++++++++++++++++++++--------- > > hw/sh4/r2d.c | 2 +- > > 2 files changed, 25 insertions(+), 10 deletions(-) > > > > diff --git a/hw/display/sm501.c b/hw/display/sm501.c > > index 1f33c87e65..c4445b28f9 100644 > > --- a/hw/display/sm501.c > > +++ b/hw/display/sm501.c > > @@ -1930,13 +1930,14 @@ typedef struct { > > SM501State state; > > uint32_t vram_size; > > uint32_t base; > > - void *chr_state; > > + SerialMM serial; > > } SM501SysBusState; > > > > static void sm501_realize_sysbus(DeviceState *dev, Error **errp) > > { > > SM501SysBusState *s = SYSBUS_SM501(dev); > > SysBusDevice *sbd = SYS_BUS_DEVICE(dev); > > + SerialState *ss = &s->serial.serial; > > DeviceState *usb_dev; > > > > sm501_init(&s->state, dev, s->vram_size); > > @@ -1958,17 +1959,19 @@ static void sm501_realize_sysbus(DeviceState *dev, > > Error **errp) > > sysbus_pass_irq(sbd, SYS_BUS_DEVICE(usb_dev)); > > > > /* bridge to serial emulation module */ > > - if (s->chr_state) { > > - serial_mm_init(&s->state.mmio_region, SM501_UART0, 2, > > - NULL, /* TODO : chain irq to IRL */ > > - 115200, s->chr_state, DEVICE_LITTLE_ENDIAN); > > + /* FIXME: SM501_UART0 is always mapped, no need to check for the > > backend */ > > + if (qemu_chr_fe_backend_connected(&ss->chr)) { > > + MemoryRegion *mr; > > + qdev_init_nofail(DEVICE(&s->serial)); > > + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->serial), 0); > > + memory_region_add_subregion(&s->state.mmio_region, SM501_UART0, > > mr); > > + /* TODO : chain irq to IRL */ > > } > > I don't really understand what the FIXME is trying to > tell me here. If we don't need to check for the backend, > why is the code checking for it ? It means we have to fish > around inside the SerialMM's implementation, which seems odd. > Only mapping the UART registers if there happens to be a backend > connected also doesn't conceptually seem like the right behaviour, > because the registers should always exist. Since commit > 12051d82f004024d5d the chardev mid-layer has correctly handled > the backend not being connected (ie having a NULL chardev), > so there's no longer any need for board/device code to special > case the lack of a chardev.
As you noted, this is addressed by "[PATCH-for-5.0] hw/display/sm501: Always map the UART0". It's preferable to keep those 2 seperate. I can include Philippe change on top, or earlier in my series, is that ok? > > > } > > > > static Property sm501_sysbus_properties[] = { > > DEFINE_PROP_UINT32("vram-size", SM501SysBusState, vram_size, 0), > > DEFINE_PROP_UINT32("base", SM501SysBusState, base, 0), > > - DEFINE_PROP_PTR("chr-state", SM501SysBusState, chr_state), > > DEFINE_PROP_END_OF_LIST(), > > }; > > > > @@ -1999,9 +2002,20 @@ static void sm501_sysbus_class_init(ObjectClass > > *klass, void *data) > > dc->props = sm501_sysbus_properties; > > dc->reset = sm501_reset_sysbus; > > dc->vmsd = &vmstate_sm501_sysbus; > > - /* Note: pointer property "chr-state" may remain null, thus > > - * no need for dc->user_creatable = false; > > - */ > > +} > > + > > +static void sm501_sysbus_init(Object *o) > > +{ > > + SM501SysBusState *sm501 = SYSBUS_SM501(o); > > + SerialMM *smm = &sm501->serial; > > + > > + sysbus_init_child_obj(o, "serial", smm, sizeof(SerialMM), > > TYPE_SERIAL_MM); > > + qdev_set_legacy_instance_id(DEVICE(smm), SM501_UART0, 2); > > The only board we use the sm501 sysbus device is the sh4 r2d > board, and we don't care about migration compatibility there > (indeed I would be unsurprised to find that it doesn't even work ;-)) > So I think we can reasonably not set the legacy-instance-ID > and just declare in the commit message that this is a migration > compat break for that board. > I am simply adapting serial_mm_init() code from "serial: register vmsd with DeviceClass" here. Dropping qdev_set_legacy_instance_id() is proabably a seperate concern. > > + qdev_prop_set_uint8(DEVICE(smm), "regshift", 2); > > + qdev_prop_set_uint8(DEVICE(smm), "endianness", DEVICE_LITTLE_ENDIAN); > > + > > + object_property_add_alias(o, "chardev", > > + OBJECT(smm), "chardev", &error_abort); > > } > > > > static const TypeInfo sm501_sysbus_info = { > > @@ -2009,6 +2023,7 @@ static const TypeInfo sm501_sysbus_info = { > > .parent = TYPE_SYS_BUS_DEVICE, > > .instance_size = sizeof(SM501SysBusState), > > .class_init = sm501_sysbus_class_init, > > + .instance_init = sm501_sysbus_init, > > }; > > > > #define TYPE_PCI_SM501 "sm501" > > diff --git a/hw/sh4/r2d.c b/hw/sh4/r2d.c > > index ee0840f380..72bb5285cc 100644 > > --- a/hw/sh4/r2d.c > > +++ b/hw/sh4/r2d.c > > @@ -272,7 +272,7 @@ static void r2d_init(MachineState *machine) > > busdev = SYS_BUS_DEVICE(dev); > > qdev_prop_set_uint32(dev, "vram-size", SM501_VRAM_SIZE); > > qdev_prop_set_uint32(dev, "base", 0x10000000); > > - qdev_prop_set_ptr(dev, "chr-state", serial_hd(2)); > > + qdev_prop_set_chr(dev, "chardev", serial_hd(2)); > > qdev_init_nofail(dev); > > sysbus_mmio_map(busdev, 0, 0x10000000); > > sysbus_mmio_map(busdev, 1, 0x13e00000); > > -- > > 2.24.0 > > thanks > -- PMM > -- Marc-André Lureau