Message ID | 20250124175053.74461-3-philmd@linaro.org (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | hw/char/sh_serial: QOM housekeeping | expand |
On 24/1/25 18:50, Philippe Mathieu-Daudé wrote: > QOM types are now registered using as TypeInfo via DEFINE_TYPES() > or type_init(). Update TYPE_SH_SERIAL, removing the empty QOM > instance_init/finalize handlers. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/char/sh_serial.c | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c > index 29ac9f9e5e7..b1db91656fe 100644 > --- a/hw/char/sh_serial.c > +++ b/hw/char/sh_serial.c > @@ -78,10 +78,6 @@ struct SHSerialState { > qemu_irq bri; > }; > > -typedef struct {} SHSerialStateClass; Note this structure was buggy, as it should have embedded its parent... struct SHSerialStateClass { SysBusDeviceClass parent_class; ... }; > - > -OBJECT_DEFINE_TYPE(SHSerialState, sh_serial, SH_SERIAL, SYS_BUS_DEVICE) > - > static void sh_serial_clear_fifo(SHSerialState *s) > { > memset(s->rx_fifo, 0, SH_RX_FIFO_LENGTH); > @@ -443,14 +439,6 @@ static void sh_serial_unrealize(DeviceState *dev) > timer_del(&s->fifo_timeout_timer); > } > > -static void sh_serial_init(Object *obj) > -{ > -} > - > -static void sh_serial_finalize(Object *obj) > -{ > -} > - > static const Property sh_serial_properties[] = { > DEFINE_PROP_CHR("chardev", SHSerialState, chr), > DEFINE_PROP_UINT8("features", SHSerialState, feat, 0), > @@ -467,3 +455,14 @@ static void sh_serial_class_init(ObjectClass *oc, void *data) > /* Reason: part of SuperH CPU/SoC, needs to be wired up */ > dc->user_creatable = false; > } > + > +static const TypeInfo sh_serial_types[] = { > + { > + .name = TYPE_SH_SERIAL, > + .parent = TYPE_SYS_BUS_DEVICE, > + .instance_size = sizeof(SHSerialState), > + .class_init = sh_serial_class_init, > + }, > +}; > + > +DEFINE_TYPES(sh_serial_types)
On Fri, 24 Jan 2025 at 17:51, Philippe Mathieu-Daudé <philmd@linaro.org> wrote: > > QOM types are now registered using as TypeInfo via DEFINE_TYPES() > or type_init(). Update TYPE_SH_SERIAL, removing the empty QOM > instance_init/finalize handlers. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/char/sh_serial.c | 23 +++++++++++------------ > 1 file changed, 11 insertions(+), 12 deletions(-) > > diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c > index 29ac9f9e5e7..b1db91656fe 100644 > --- a/hw/char/sh_serial.c > +++ b/hw/char/sh_serial.c > @@ -78,10 +78,6 @@ struct SHSerialState { > qemu_irq bri; > }; > > -typedef struct {} SHSerialStateClass; > - > -OBJECT_DEFINE_TYPE(SHSerialState, sh_serial, SH_SERIAL, SYS_BUS_DEVICE) > - This was definitely wrong, because OBJECT_DEFINE_TYPE() is only for cases where the class needs its own virtual methods or some other per-class state in its own class struct. > static void sh_serial_clear_fifo(SHSerialState *s) > { > memset(s->rx_fifo, 0, SH_RX_FIFO_LENGTH); > @@ -443,14 +439,6 @@ static void sh_serial_unrealize(DeviceState *dev) > timer_del(&s->fifo_timeout_timer); > } > > -static void sh_serial_init(Object *obj) > -{ > -} > - > -static void sh_serial_finalize(Object *obj) > -{ > -} > - > static const Property sh_serial_properties[] = { > DEFINE_PROP_CHR("chardev", SHSerialState, chr), > DEFINE_PROP_UINT8("features", SHSerialState, feat, 0), > @@ -467,3 +455,14 @@ static void sh_serial_class_init(ObjectClass *oc, void *data) > /* Reason: part of SuperH CPU/SoC, needs to be wired up */ > dc->user_creatable = false; > } > + > +static const TypeInfo sh_serial_types[] = { > + { > + .name = TYPE_SH_SERIAL, > + .parent = TYPE_SYS_BUS_DEVICE, > + .instance_size = sizeof(SHSerialState), > + .class_init = sh_serial_class_init, > + }, > +}; > + > +DEFINE_TYPES(sh_serial_types) Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Do you have a view on when we should: * use DEFINE_TYPES like this * longhand write out a type_init() and a function (maybe only if you need to programmatically construct the type structs, e.g. in a loop ?) * use OBJECT_DEFINE_TYPE() ? Currently docs/devel/qom.rst leads off with the "write it out longhand" approach, then mentions DEFINE_TYPES for if you want to register "several static types", and finally documents the OBJECT_DECLARE and OBJECT_DEFINE families of macros. thanks -- PMM
diff --git a/hw/char/sh_serial.c b/hw/char/sh_serial.c index 29ac9f9e5e7..b1db91656fe 100644 --- a/hw/char/sh_serial.c +++ b/hw/char/sh_serial.c @@ -78,10 +78,6 @@ struct SHSerialState { qemu_irq bri; }; -typedef struct {} SHSerialStateClass; - -OBJECT_DEFINE_TYPE(SHSerialState, sh_serial, SH_SERIAL, SYS_BUS_DEVICE) - static void sh_serial_clear_fifo(SHSerialState *s) { memset(s->rx_fifo, 0, SH_RX_FIFO_LENGTH); @@ -443,14 +439,6 @@ static void sh_serial_unrealize(DeviceState *dev) timer_del(&s->fifo_timeout_timer); } -static void sh_serial_init(Object *obj) -{ -} - -static void sh_serial_finalize(Object *obj) -{ -} - static const Property sh_serial_properties[] = { DEFINE_PROP_CHR("chardev", SHSerialState, chr), DEFINE_PROP_UINT8("features", SHSerialState, feat, 0), @@ -467,3 +455,14 @@ static void sh_serial_class_init(ObjectClass *oc, void *data) /* Reason: part of SuperH CPU/SoC, needs to be wired up */ dc->user_creatable = false; } + +static const TypeInfo sh_serial_types[] = { + { + .name = TYPE_SH_SERIAL, + .parent = TYPE_SYS_BUS_DEVICE, + .instance_size = sizeof(SHSerialState), + .class_init = sh_serial_class_init, + }, +}; + +DEFINE_TYPES(sh_serial_types)
QOM types are now registered using as TypeInfo via DEFINE_TYPES() or type_init(). Update TYPE_SH_SERIAL, removing the empty QOM instance_init/finalize handlers. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/char/sh_serial.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)