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/pci-host/sh_pci.c | 40 +++++++++++++++++-----------------------
1 file changed, 17 insertions(+), 23 deletions(-)
diff --git a/hw/pci-host/sh_pci.c b/hw/pci-host/sh_pci.c
index 77e7bbc65f..41aed48c85 100644
--- a/hw/pci-host/sh_pci.c
+++ b/hw/pci-host/sh_pci.c
@@ -167,17 +167,6 @@ static void sh_pci_host_class_init(ObjectClass *klass, void *data)
dc->user_creatable = false;
}
-static const TypeInfo sh_pci_host_info = {
- .name = "sh_pci_host",
- .parent = TYPE_PCI_DEVICE,
- .instance_size = sizeof(PCIDevice),
- .class_init = sh_pci_host_class_init,
- .interfaces = (InterfaceInfo[]) {
- { INTERFACE_CONVENTIONAL_PCI_DEVICE },
- { },
- },
-};
-
static void sh_pci_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
@@ -185,17 +174,22 @@ static void sh_pci_device_class_init(ObjectClass *klass, void *data)
dc->realize = sh_pci_device_realize;
}
-static const TypeInfo sh_pci_device_info = {
- .name = TYPE_SH_PCI_HOST_BRIDGE,
- .parent = TYPE_PCI_HOST_BRIDGE,
- .instance_size = sizeof(SHPCIState),
- .class_init = sh_pci_device_class_init,
+static const TypeInfo sh_pcic_types[] = {
+ {
+ .name = TYPE_SH_PCI_HOST_BRIDGE,
+ .parent = TYPE_PCI_HOST_BRIDGE,
+ .instance_size = sizeof(SHPCIState),
+ .class_init = sh_pci_device_class_init,
+ }, {
+ .name = "sh_pci_host",
+ .parent = TYPE_PCI_DEVICE,
+ .instance_size = sizeof(PCIDevice),
+ .class_init = sh_pci_host_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+ { },
+ },
+ },
};
-static void sh_pci_register_types(void)
-{
- type_register_static(&sh_pci_device_info);
- type_register_static(&sh_pci_host_info);
-}
-
-type_init(sh_pci_register_types)
+DEFINE_TYPES(sh_pcic_types)
--
2.41.0
On Thu, 12 Oct 2023 13:12:35 +0900,
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>
Reviewed-by: Yoshinori Sato <ysato@users.sourceforge.jp>
> ---
> hw/pci-host/sh_pci.c | 40 +++++++++++++++++-----------------------
> 1 file changed, 17 insertions(+), 23 deletions(-)
>
> diff --git a/hw/pci-host/sh_pci.c b/hw/pci-host/sh_pci.c
> index 77e7bbc65f..41aed48c85 100644
> --- a/hw/pci-host/sh_pci.c
> +++ b/hw/pci-host/sh_pci.c
> @@ -167,17 +167,6 @@ static void sh_pci_host_class_init(ObjectClass *klass, void *data)
> dc->user_creatable = false;
> }
>
> -static const TypeInfo sh_pci_host_info = {
> - .name = "sh_pci_host",
> - .parent = TYPE_PCI_DEVICE,
> - .instance_size = sizeof(PCIDevice),
> - .class_init = sh_pci_host_class_init,
> - .interfaces = (InterfaceInfo[]) {
> - { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> - { },
> - },
> -};
> -
> static void sh_pci_device_class_init(ObjectClass *klass, void *data)
> {
> DeviceClass *dc = DEVICE_CLASS(klass);
> @@ -185,17 +174,22 @@ static void sh_pci_device_class_init(ObjectClass *klass, void *data)
> dc->realize = sh_pci_device_realize;
> }
>
> -static const TypeInfo sh_pci_device_info = {
> - .name = TYPE_SH_PCI_HOST_BRIDGE,
> - .parent = TYPE_PCI_HOST_BRIDGE,
> - .instance_size = sizeof(SHPCIState),
> - .class_init = sh_pci_device_class_init,
> +static const TypeInfo sh_pcic_types[] = {
> + {
> + .name = TYPE_SH_PCI_HOST_BRIDGE,
> + .parent = TYPE_PCI_HOST_BRIDGE,
> + .instance_size = sizeof(SHPCIState),
> + .class_init = sh_pci_device_class_init,
> + }, {
> + .name = "sh_pci_host",
> + .parent = TYPE_PCI_DEVICE,
> + .instance_size = sizeof(PCIDevice),
> + .class_init = sh_pci_host_class_init,
> + .interfaces = (InterfaceInfo[]) {
> + { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> + { },
> + },
> + },
> };
>
> -static void sh_pci_register_types(void)
> -{
> - type_register_static(&sh_pci_device_info);
> - type_register_static(&sh_pci_host_info);
> -}
> -
> -type_init(sh_pci_register_types)
> +DEFINE_TYPES(sh_pcic_types)
> --
> 2.41.0
>
© 2016 - 2026 Red Hat, Inc.