Message ID | 20250125181343.59151-3-philmd@linaro.org |
---|---|
State | New |
Headers | show |
Series | hw/sysbus/platform-bus: Introduce TYPE_DYNAMIC_SYS_BUS_DEVICE | expand |
On 1/25/25 10:13, Philippe Mathieu-Daudé wrote: > When multiple QOM types are registered in the same file, > it is simpler to use the the DEFINE_TYPES() macro. In > particular because type array declared with such macro > are easier to review. > > Signed-off-by: Philippe Mathieu-Daudé<philmd@linaro.org> > --- > hw/core/sysbus.c | 39 +++++++++++++++++---------------------- > 1 file changed, 17 insertions(+), 22 deletions(-) Reviewed-by: Richard Henderson <richard.henderson@linaro.org> r~
Reviewed-by: Clément Mathieu--Drif<clement.mathieu--drif@eviden.com> On 25/01/2025 19:13, Philippe Mathieu-Daudé wrote: > Caution: External email. Do not open attachments or click links, unless this email comes from a known sender and you know the content is safe. > > > When multiple QOM types are registered in the same file, > it is simpler to use the the DEFINE_TYPES() macro. In > particular because type array declared with such macro > are easier to review. > > Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> > --- > hw/core/sysbus.c | 39 +++++++++++++++++---------------------- > 1 file changed, 17 insertions(+), 22 deletions(-) > > diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c > index f713bbfe04f..306f98406c0 100644 > --- a/hw/core/sysbus.c > +++ b/hw/core/sysbus.c > @@ -80,13 +80,6 @@ static void system_bus_class_init(ObjectClass *klass, void *data) > k->get_fw_dev_path = sysbus_get_fw_dev_path; > } > > -static const TypeInfo system_bus_info = { > - .name = TYPE_SYSTEM_BUS, > - .parent = TYPE_BUS, > - .instance_size = sizeof(BusState), > - .class_init = system_bus_class_init, > -}; > - > /* Check whether an IRQ source exists */ > bool sysbus_has_irq(SysBusDevice *dev, int n) > { > @@ -306,15 +299,6 @@ static void sysbus_device_class_init(ObjectClass *klass, void *data) > k->user_creatable = false; > } > > -static const TypeInfo sysbus_device_type_info = { > - .name = TYPE_SYS_BUS_DEVICE, > - .parent = TYPE_DEVICE, > - .instance_size = sizeof(SysBusDevice), > - .abstract = true, > - .class_size = sizeof(SysBusDeviceClass), > - .class_init = sysbus_device_class_init, > -}; > - > static BusState *main_system_bus; > > static void main_system_bus_create(void) > @@ -337,10 +321,21 @@ BusState *sysbus_get_default(void) > return main_system_bus; > } > > -static void sysbus_register_types(void) > -{ > - type_register_static(&system_bus_info); > - type_register_static(&sysbus_device_type_info); > -} > +static const TypeInfo sysbus_types[] = { > + { > + .name = TYPE_SYSTEM_BUS, > + .parent = TYPE_BUS, > + .instance_size = sizeof(BusState), > + .class_init = system_bus_class_init, > + }, > + { > + .name = TYPE_SYS_BUS_DEVICE, > + .parent = TYPE_DEVICE, > + .instance_size = sizeof(SysBusDevice), > + .abstract = true, > + .class_size = sizeof(SysBusDeviceClass), > + .class_init = sysbus_device_class_init, > + }, > +}; > > -type_init(sysbus_register_types) > +DEFINE_TYPES(sysbus_types) > -- > 2.47.1 >
Am 25. Januar 2025 18:13:36 UTC schrieb "Philippe Mathieu-Daudé" <philmd@linaro.org>: >When multiple QOM types are registered in the same file, >it is simpler to use the the DEFINE_TYPES() macro. In >particular because type array declared with such macro >are easier to review. > >Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> >--- > hw/core/sysbus.c | 39 +++++++++++++++++---------------------- > 1 file changed, 17 insertions(+), 22 deletions(-) > >diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c >index f713bbfe04f..306f98406c0 100644 >--- a/hw/core/sysbus.c >+++ b/hw/core/sysbus.c >@@ -80,13 +80,6 @@ static void system_bus_class_init(ObjectClass *klass, void *data) > k->get_fw_dev_path = sysbus_get_fw_dev_path; > } > >-static const TypeInfo system_bus_info = { >- .name = TYPE_SYSTEM_BUS, >- .parent = TYPE_BUS, >- .instance_size = sizeof(BusState), >- .class_init = system_bus_class_init, >-}; >- > /* Check whether an IRQ source exists */ > bool sysbus_has_irq(SysBusDevice *dev, int n) > { >@@ -306,15 +299,6 @@ static void sysbus_device_class_init(ObjectClass *klass, void *data) > k->user_creatable = false; > } > >-static const TypeInfo sysbus_device_type_info = { >- .name = TYPE_SYS_BUS_DEVICE, >- .parent = TYPE_DEVICE, >- .instance_size = sizeof(SysBusDevice), >- .abstract = true, >- .class_size = sizeof(SysBusDeviceClass), >- .class_init = sysbus_device_class_init, >-}; >- > static BusState *main_system_bus; > > static void main_system_bus_create(void) >@@ -337,10 +321,21 @@ BusState *sysbus_get_default(void) > return main_system_bus; > } > >-static void sysbus_register_types(void) >-{ >- type_register_static(&system_bus_info); >- type_register_static(&sysbus_device_type_info); >-} >+static const TypeInfo sysbus_types[] = { >+ { >+ .name = TYPE_SYSTEM_BUS, >+ .parent = TYPE_BUS, >+ .instance_size = sizeof(BusState), >+ .class_init = system_bus_class_init, >+ }, >+ { >+ .name = TYPE_SYS_BUS_DEVICE, >+ .parent = TYPE_DEVICE, >+ .instance_size = sizeof(SysBusDevice), >+ .abstract = true, >+ .class_size = sizeof(SysBusDeviceClass), >+ .class_init = sysbus_device_class_init, >+ }, >+}; > >-type_init(sysbus_register_types) >+DEFINE_TYPES(sysbus_types) Can now omit the "qom/module.h" include. With that changed: Reviewed-by: Bernhard Beschow
diff --git a/hw/core/sysbus.c b/hw/core/sysbus.c index f713bbfe04f..306f98406c0 100644 --- a/hw/core/sysbus.c +++ b/hw/core/sysbus.c @@ -80,13 +80,6 @@ static void system_bus_class_init(ObjectClass *klass, void *data) k->get_fw_dev_path = sysbus_get_fw_dev_path; } -static const TypeInfo system_bus_info = { - .name = TYPE_SYSTEM_BUS, - .parent = TYPE_BUS, - .instance_size = sizeof(BusState), - .class_init = system_bus_class_init, -}; - /* Check whether an IRQ source exists */ bool sysbus_has_irq(SysBusDevice *dev, int n) { @@ -306,15 +299,6 @@ static void sysbus_device_class_init(ObjectClass *klass, void *data) k->user_creatable = false; } -static const TypeInfo sysbus_device_type_info = { - .name = TYPE_SYS_BUS_DEVICE, - .parent = TYPE_DEVICE, - .instance_size = sizeof(SysBusDevice), - .abstract = true, - .class_size = sizeof(SysBusDeviceClass), - .class_init = sysbus_device_class_init, -}; - static BusState *main_system_bus; static void main_system_bus_create(void) @@ -337,10 +321,21 @@ BusState *sysbus_get_default(void) return main_system_bus; } -static void sysbus_register_types(void) -{ - type_register_static(&system_bus_info); - type_register_static(&sysbus_device_type_info); -} +static const TypeInfo sysbus_types[] = { + { + .name = TYPE_SYSTEM_BUS, + .parent = TYPE_BUS, + .instance_size = sizeof(BusState), + .class_init = system_bus_class_init, + }, + { + .name = TYPE_SYS_BUS_DEVICE, + .parent = TYPE_DEVICE, + .instance_size = sizeof(SysBusDevice), + .abstract = true, + .class_size = sizeof(SysBusDeviceClass), + .class_init = sysbus_device_class_init, + }, +}; -type_init(sysbus_register_types) +DEFINE_TYPES(sysbus_types)
When multiple QOM types are registered in the same file, it is simpler to use the the DEFINE_TYPES() macro. In particular because type array declared with such macro are easier to review. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- hw/core/sysbus.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-)