* [PATCH 0/1] hw/sd: Declare CPU QOM types using DEFINE_TYPES() macro
@ 2023-10-31 8:06 Philippe Mathieu-Daudé
2023-10-31 8:06 ` [PATCH 1/1] " Philippe Mathieu-Daudé
0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-31 8:06 UTC (permalink / raw)
To: qemu-devel
Cc: Igor Mammedov, qemu-arm, Peter Maydell, Eduardo Habkost,
Markus Armbruster, Philippe Mathieu-Daudé, Mark Cave-Ayland
Hi,
This is an intent to automatically convert to DEFINE_TYPES().
I used a Comby script, see https://comby.dev/.
Example in Comby playground:
https://comby.live/#%7B%22source%22%3A%22static%20const%20TypeInfo%20pl181_info%20%3D%20%7B%5Cn%20%20%20%20.name%20%20%20%20%20%20%20%20%20%20%3D%20TYPE_PL181%2C%5Cn%20%20%20%20.parent%20%20%20%20%20%20%20%20%3D%20TYPE_SYS_BUS_DEVICE%2C%5Cn%20%20%20%20.instance_size%20%3D%20sizeof(PL181State)%2C%5Cn%20%20%20%20.instance_init%20%3D%20pl181_init%2C%5Cn%20%20%20%20.class_init%20%20%20%20%3D%20pl181_class_init%2C%5Cn%7D%3B%5Cn%5Cnstatic%20void%20pl181_bus_class_init(ObjectClass%20*klass%2C%20void%20*data)%5Cn%7B%5Cn%20%20%20%20SDBusClass%20*sbc%20%3D%20SD_BUS_CLASS(klass)%3B%5Cn%5Cn%20%20%20%20sbc-%3Eset_inserted%20%3D%20pl181_set_inserted%3B%5Cn%20%20%20%20sbc-%3Eset_readonly%20%3D%20pl181_set_readonly%3B%5Cn%7D%5Cn%5Cnstatic%20const%20TypeInfo%20pl181_bus_info%20%3D%20%7B%5Cn%20%20%20%20.name%20%3D%20TYPE_PL181_BUS%2C%5Cn%20%20%20%20.parent%20%3D%20TYPE_SD_BUS%2C%5Cn%20%20%20%20.instance_size%20%3D%20sizeof(SDBus)%2C%5Cn%20%20%20%20.class_init%20%3D%20pl181_bus_class_init%2C%5Cn%7D%3B%5Cn%5Cnstatic%20void%20pl181_register_types(void)%5Cn%7B%5Cn%20%20%20%20type_register_static(%26pl181_info)%3B%5Cn%20%20%20%20type_register_static(%26pl181_bus_info)%3B%5Cn%7D%5Cn%5Cntype_init(pl181_register_types)%5Cn%22%2C%22match%22%3A%22static%20const%20TypeInfo%20%3A%5Bi1a~.*_info%5D%20%3D%20%7B%5Cn%20%20%20%20%3A%5Bbody1%5D%5Cn%7D%3B%5Cn...%5Cnstatic%20const%20TypeInfo%20%3A%5Bi2a~.*_info%5D%20%3D%20%7B%5Cn%20%20%20%20%3A%5Bbody2%5D%5Cn%7D%3B%5Cnstatic%20void%20%3A%5Brt1~.*_register_type.%5D(void)%5Cn%7B%5Cn%20%20%20%20type_register_static(%26%3A%5Bi1b~.*_info%5D)%3B%5Cn%20%20%20%20type_register_static(%26%3A%5Bi2b~.*_info%5D)%3B%5Cn%7D%5Cntype_init(%3A%5Brt2~.*_register_type.%5D)%22%2C%22rule%22%3A%22where%20true%22%2C%22rewrite%22%3A%22static%20const%20TypeInfo%20%3A%5Bi1a%5D%5B%5D%20%3D%20%7B%5Cn%20%20%20%20%7B%5Cn%20%20%20%20%3A%5Bbody1%5D%5Cn%20%20%20%20%7D%2C%5Cn%20%20%20%20%7B%5Cn%20%20%20%20%3A%5Bbody2%5D%5Cn%20%20%20%20%7D%2C%5Cn%7D%3B%5Cn%5CnDEFINE_TYPES(%3A%5Bi1a%5D)%5Cn%22%2C%22language%22%3A%22.generic%22%2C%22substitution_kind%22%3A%22in_place%22%2C%22id%22%3A0%7D
Regards,
Phil.
Philippe Mathieu-Daudé (1):
hw/sd: Declare CPU QOM types using DEFINE_TYPES() macro
hw/sd/aspeed_sdhci.c | 19 ++++++++-----------
hw/sd/bcm2835_sdhost.c | 33 ++++++++++++++-------------------
hw/sd/cadence_sdhci.c | 21 +++++++++------------
hw/sd/core.c | 19 ++++++++-----------
hw/sd/npcm7xx_sdhci.c | 21 +++++++++------------
hw/sd/pl181.c | 35 +++++++++++++++--------------------
hw/sd/pxa2xx_mmci.c | 35 +++++++++++++++--------------------
hw/sd/sd.c | 37 ++++++++++++++++---------------------
hw/sd/sdhci-pci.c | 25 +++++++++++--------------
hw/sd/ssi-sd.c | 19 ++++++++-----------
10 files changed, 113 insertions(+), 151 deletions(-)
--
2.41.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 1/1] hw/sd: Declare CPU QOM types using DEFINE_TYPES() macro
2023-10-31 8:06 [PATCH 0/1] hw/sd: Declare CPU QOM types using DEFINE_TYPES() macro Philippe Mathieu-Daudé
@ 2023-10-31 8:06 ` Philippe Mathieu-Daudé
2023-10-31 8:31 ` Cédric Le Goater
0 siblings, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-10-31 8:06 UTC (permalink / raw)
To: qemu-devel
Cc: Igor Mammedov, qemu-arm, Peter Maydell, Eduardo Habkost,
Markus Armbruster, Philippe Mathieu-Daudé, Mark Cave-Ayland,
Cédric Le Goater, Andrew Jeffery, Joel Stanley,
Edgar E. Iglesias, Alistair Francis, Bin Meng, Tyrone Ting,
Hao Wu, qemu-block
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.
Mechanical transformation using the following comby script:
[pattern-x1]
match='''
static const TypeInfo :[i1~.*_info] = {
:[body]
};
static void :[rt1~.*_register_type.](void)
{
type_register_static(&:[i2~.*_info]);
}
type_init(:[rt2~.*_register_type.])
'''
rewrite='''
static const TypeInfo :[i1][] = {
{
:[body]
},
};
DEFINE_TYPES(:[i1])
'''
rule='where :[i1] == :[i2], :[rt1] == :[rt2]'
[pattern-x2]
match='''
static const TypeInfo :[i1a~.*_info] = {
:[body1]
};
...
static const TypeInfo :[i2a~.*_info] = {
:[body2]
};
static void :[rt1~.*_register_type.](void)
{
type_register_static(&:[i1b~.*_info]);
type_register_static(&:[i2b~.*_info]);
}
type_init(:[rt2~.*_register_type.])
'''
rewrite='''
static const TypeInfo :[i1a][] = {
{
:[body1]
},
{
:[body2]
},
};
DEFINE_TYPES(:[i1a])
'''
rule='''
where
:[i1a] == :[i1b],
:[i2a] == :[i2b],
:[rt1] == :[rt2]
'''
and re-indented manually.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
hw/sd/aspeed_sdhci.c | 19 ++++++++-----------
hw/sd/bcm2835_sdhost.c | 33 ++++++++++++++-------------------
hw/sd/cadence_sdhci.c | 21 +++++++++------------
hw/sd/core.c | 19 ++++++++-----------
hw/sd/npcm7xx_sdhci.c | 21 +++++++++------------
hw/sd/pl181.c | 35 +++++++++++++++--------------------
hw/sd/pxa2xx_mmci.c | 35 +++++++++++++++--------------------
hw/sd/sd.c | 37 ++++++++++++++++---------------------
hw/sd/sdhci-pci.c | 25 +++++++++++--------------
hw/sd/ssi-sd.c | 19 ++++++++-----------
10 files changed, 113 insertions(+), 151 deletions(-)
diff --git a/hw/sd/aspeed_sdhci.c b/hw/sd/aspeed_sdhci.c
index be8cafd65f..e53206d959 100644
--- a/hw/sd/aspeed_sdhci.c
+++ b/hw/sd/aspeed_sdhci.c
@@ -198,16 +198,13 @@ static void aspeed_sdhci_class_init(ObjectClass *classp, void *data)
device_class_set_props(dc, aspeed_sdhci_properties);
}
-static const TypeInfo aspeed_sdhci_info = {
- .name = TYPE_ASPEED_SDHCI,
- .parent = TYPE_SYS_BUS_DEVICE,
- .instance_size = sizeof(AspeedSDHCIState),
- .class_init = aspeed_sdhci_class_init,
+static const TypeInfo aspeed_sdhci_types[] = {
+ {
+ .name = TYPE_ASPEED_SDHCI,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(AspeedSDHCIState),
+ .class_init = aspeed_sdhci_class_init,
+ },
};
-static void aspeed_sdhci_register_types(void)
-{
- type_register_static(&aspeed_sdhci_info);
-}
-
-type_init(aspeed_sdhci_register_types)
+DEFINE_TYPES(aspeed_sdhci_types)
diff --git a/hw/sd/bcm2835_sdhost.c b/hw/sd/bcm2835_sdhost.c
index 9431c35914..a600cf39e2 100644
--- a/hw/sd/bcm2835_sdhost.c
+++ b/hw/sd/bcm2835_sdhost.c
@@ -436,24 +436,19 @@ static void bcm2835_sdhost_class_init(ObjectClass *klass, void *data)
dc->vmsd = &vmstate_bcm2835_sdhost;
}
-static const TypeInfo bcm2835_sdhost_info = {
- .name = TYPE_BCM2835_SDHOST,
- .parent = TYPE_SYS_BUS_DEVICE,
- .instance_size = sizeof(BCM2835SDHostState),
- .class_init = bcm2835_sdhost_class_init,
- .instance_init = bcm2835_sdhost_init,
+static const TypeInfo bcm2835_sdhost_types[] = {
+ {
+ .name = TYPE_BCM2835_SDHOST,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(BCM2835SDHostState),
+ .class_init = bcm2835_sdhost_class_init,
+ .instance_init = bcm2835_sdhost_init,
+ },
+ {
+ .name = TYPE_BCM2835_SDHOST_BUS,
+ .parent = TYPE_SD_BUS,
+ .instance_size = sizeof(SDBus),
+ },
};
-static const TypeInfo bcm2835_sdhost_bus_info = {
- .name = TYPE_BCM2835_SDHOST_BUS,
- .parent = TYPE_SD_BUS,
- .instance_size = sizeof(SDBus),
-};
-
-static void bcm2835_sdhost_register_types(void)
-{
- type_register_static(&bcm2835_sdhost_info);
- type_register_static(&bcm2835_sdhost_bus_info);
-}
-
-type_init(bcm2835_sdhost_register_types)
+DEFINE_TYPES(bcm2835_sdhost_types)
diff --git a/hw/sd/cadence_sdhci.c b/hw/sd/cadence_sdhci.c
index 75db34befe..ef4e0d74e3 100644
--- a/hw/sd/cadence_sdhci.c
+++ b/hw/sd/cadence_sdhci.c
@@ -175,17 +175,14 @@ static void cadence_sdhci_class_init(ObjectClass *classp, void *data)
dc->vmsd = &vmstate_cadence_sdhci;
}
-static const TypeInfo cadence_sdhci_info = {
- .name = TYPE_CADENCE_SDHCI,
- .parent = TYPE_SYS_BUS_DEVICE,
- .instance_size = sizeof(CadenceSDHCIState),
- .instance_init = cadence_sdhci_instance_init,
- .class_init = cadence_sdhci_class_init,
+static const TypeInfo cadence_sdhci_types[] = {
+ {
+ .name = TYPE_CADENCE_SDHCI,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(CadenceSDHCIState),
+ .instance_init = cadence_sdhci_instance_init,
+ .class_init = cadence_sdhci_class_init,
+ },
};
-static void cadence_sdhci_register_types(void)
-{
- type_register_static(&cadence_sdhci_info);
-}
-
-type_init(cadence_sdhci_register_types)
+DEFINE_TYPES(cadence_sdhci_types)
diff --git a/hw/sd/core.c b/hw/sd/core.c
index 30ee62c510..52d5d90045 100644
--- a/hw/sd/core.c
+++ b/hw/sd/core.c
@@ -259,16 +259,13 @@ void sdbus_reparent_card(SDBus *from, SDBus *to)
sdbus_set_readonly(to, readonly);
}
-static const TypeInfo sd_bus_info = {
- .name = TYPE_SD_BUS,
- .parent = TYPE_BUS,
- .instance_size = sizeof(SDBus),
- .class_size = sizeof(SDBusClass),
+static const TypeInfo sd_bus_types[] = {
+ {
+ .name = TYPE_SD_BUS,
+ .parent = TYPE_BUS,
+ .instance_size = sizeof(SDBus),
+ .class_size = sizeof(SDBusClass),
+ },
};
-static void sd_bus_register_types(void)
-{
- type_register_static(&sd_bus_info);
-}
-
-type_init(sd_bus_register_types)
+DEFINE_TYPES(sd_bus_types)
diff --git a/hw/sd/npcm7xx_sdhci.c b/hw/sd/npcm7xx_sdhci.c
index b2f5b4a542..9958680090 100644
--- a/hw/sd/npcm7xx_sdhci.c
+++ b/hw/sd/npcm7xx_sdhci.c
@@ -166,17 +166,14 @@ static void npcm7xx_sdhci_instance_init(Object *obj)
TYPE_SYSBUS_SDHCI);
}
-static const TypeInfo npcm7xx_sdhci_info = {
- .name = TYPE_NPCM7XX_SDHCI,
- .parent = TYPE_SYS_BUS_DEVICE,
- .instance_size = sizeof(NPCM7xxSDHCIState),
- .instance_init = npcm7xx_sdhci_instance_init,
- .class_init = npcm7xx_sdhci_class_init,
+static const TypeInfo npcm7xx_sdhci_types[] = {
+ {
+ .name = TYPE_NPCM7XX_SDHCI,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(NPCM7xxSDHCIState),
+ .instance_init = npcm7xx_sdhci_instance_init,
+ .class_init = npcm7xx_sdhci_class_init,
+ },
};
-static void npcm7xx_sdhci_register_types(void)
-{
- type_register_static(&npcm7xx_sdhci_info);
-}
-
-type_init(npcm7xx_sdhci_register_types)
+DEFINE_TYPES(npcm7xx_sdhci_types)
diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c
index 5e554bd467..2b33814d83 100644
--- a/hw/sd/pl181.c
+++ b/hw/sd/pl181.c
@@ -519,14 +519,6 @@ static void pl181_class_init(ObjectClass *klass, void *data)
k->user_creatable = false;
}
-static const TypeInfo pl181_info = {
- .name = TYPE_PL181,
- .parent = TYPE_SYS_BUS_DEVICE,
- .instance_size = sizeof(PL181State),
- .instance_init = pl181_init,
- .class_init = pl181_class_init,
-};
-
static void pl181_bus_class_init(ObjectClass *klass, void *data)
{
SDBusClass *sbc = SD_BUS_CLASS(klass);
@@ -535,17 +527,20 @@ static void pl181_bus_class_init(ObjectClass *klass, void *data)
sbc->set_readonly = pl181_set_readonly;
}
-static const TypeInfo pl181_bus_info = {
- .name = TYPE_PL181_BUS,
- .parent = TYPE_SD_BUS,
- .instance_size = sizeof(SDBus),
- .class_init = pl181_bus_class_init,
+static const TypeInfo pl181_info[] = {
+ {
+ .name = TYPE_PL181,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(PL181State),
+ .instance_init = pl181_init,
+ .class_init = pl181_class_init,
+ },
+ {
+ .name = TYPE_PL181_BUS,
+ .parent = TYPE_SD_BUS,
+ .instance_size = sizeof(SDBus),
+ .class_init = pl181_bus_class_init,
+ },
};
-static void pl181_register_types(void)
-{
- type_register_static(&pl181_info);
- type_register_static(&pl181_bus_info);
-}
-
-type_init(pl181_register_types)
+DEFINE_TYPES(pl181_info)
diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
index 124fbf8bbd..d785a3d80f 100644
--- a/hw/sd/pxa2xx_mmci.c
+++ b/hw/sd/pxa2xx_mmci.c
@@ -580,25 +580,20 @@ static void pxa2xx_mmci_bus_class_init(ObjectClass *klass, void *data)
sbc->set_readonly = pxa2xx_mmci_set_readonly;
}
-static const TypeInfo pxa2xx_mmci_info = {
- .name = TYPE_PXA2XX_MMCI,
- .parent = TYPE_SYS_BUS_DEVICE,
- .instance_size = sizeof(PXA2xxMMCIState),
- .instance_init = pxa2xx_mmci_instance_init,
- .class_init = pxa2xx_mmci_class_init,
+static const TypeInfo pxa2xx_mmci_types[] = {
+ {
+ .name = TYPE_PXA2XX_MMCI,
+ .parent = TYPE_SYS_BUS_DEVICE,
+ .instance_size = sizeof(PXA2xxMMCIState),
+ .instance_init = pxa2xx_mmci_instance_init,
+ .class_init = pxa2xx_mmci_class_init,
+ },
+ {
+ .name = TYPE_PXA2XX_MMCI_BUS,
+ .parent = TYPE_SD_BUS,
+ .instance_size = sizeof(SDBus),
+ .class_init = pxa2xx_mmci_bus_class_init,
+ },
};
-static const TypeInfo pxa2xx_mmci_bus_info = {
- .name = TYPE_PXA2XX_MMCI_BUS,
- .parent = TYPE_SD_BUS,
- .instance_size = sizeof(SDBus),
- .class_init = pxa2xx_mmci_bus_class_init,
-};
-
-static void pxa2xx_mmci_register_types(void)
-{
- type_register_static(&pxa2xx_mmci_info);
- type_register_static(&pxa2xx_mmci_bus_info);
-}
-
-type_init(pxa2xx_mmci_register_types)
+DEFINE_TYPES(pxa2xx_mmci_types)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 4823befdef..1106ff7d78 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -2278,16 +2278,6 @@ static void sd_class_init(ObjectClass *klass, void *data)
sc->proto = &sd_proto_sd;
}
-static const TypeInfo sd_info = {
- .name = TYPE_SD_CARD,
- .parent = TYPE_DEVICE,
- .instance_size = sizeof(SDState),
- .class_size = sizeof(SDCardClass),
- .class_init = sd_class_init,
- .instance_init = sd_instance_init,
- .instance_finalize = sd_instance_finalize,
-};
-
/*
* We do not model the chip select pin, so allow the board to select
* whether card should be in SSI or MMC/SD mode. It is also up to the
@@ -2303,16 +2293,21 @@ static void sd_spi_class_init(ObjectClass *klass, void *data)
sc->proto = &sd_proto_spi;
}
-static const TypeInfo sd_spi_info = {
- .name = TYPE_SD_CARD_SPI,
- .parent = TYPE_SD_CARD,
- .class_init = sd_spi_class_init,
+static const TypeInfo sd_types[] = {
+ {
+ .name = TYPE_SD_CARD,
+ .parent = TYPE_DEVICE,
+ .instance_size = sizeof(SDState),
+ .class_size = sizeof(SDCardClass),
+ .class_init = sd_class_init,
+ .instance_init = sd_instance_init,
+ .instance_finalize = sd_instance_finalize,
+ },
+ {
+ .name = TYPE_SD_CARD_SPI,
+ .parent = TYPE_SD_CARD,
+ .class_init = sd_spi_class_init,
+ },
};
-static void sd_register_types(void)
-{
- type_register_static(&sd_info);
- type_register_static(&sd_spi_info);
-}
-
-type_init(sd_register_types)
+DEFINE_TYPES(sd_types)
diff --git a/hw/sd/sdhci-pci.c b/hw/sd/sdhci-pci.c
index c737c8b930..9b7bee8b3f 100644
--- a/hw/sd/sdhci-pci.c
+++ b/hw/sd/sdhci-pci.c
@@ -68,20 +68,17 @@ static void sdhci_pci_class_init(ObjectClass *klass, void *data)
sdhci_common_class_init(klass, data);
}
-static const TypeInfo sdhci_pci_info = {
- .name = TYPE_PCI_SDHCI,
- .parent = TYPE_PCI_DEVICE,
- .instance_size = sizeof(SDHCIState),
- .class_init = sdhci_pci_class_init,
- .interfaces = (InterfaceInfo[]) {
- { INTERFACE_CONVENTIONAL_PCI_DEVICE },
- { },
+static const TypeInfo sdhci_pci_types[] = {
+ {
+ .name = TYPE_PCI_SDHCI,
+ .parent = TYPE_PCI_DEVICE,
+ .instance_size = sizeof(SDHCIState),
+ .class_init = sdhci_pci_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { INTERFACE_CONVENTIONAL_PCI_DEVICE },
+ { },
+ },
},
};
-static void sdhci_pci_register_type(void)
-{
- type_register_static(&sdhci_pci_info);
-}
-
-type_init(sdhci_pci_register_type)
+DEFINE_TYPES(sdhci_pci_types)
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index 167c03b780..a6cc1ad6c8 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -403,16 +403,13 @@ static void ssi_sd_class_init(ObjectClass *klass, void *data)
dc->user_creatable = false;
}
-static const TypeInfo ssi_sd_info = {
- .name = TYPE_SSI_SD,
- .parent = TYPE_SSI_PERIPHERAL,
- .instance_size = sizeof(ssi_sd_state),
- .class_init = ssi_sd_class_init,
+static const TypeInfo ssi_sd_types[] = {
+ {
+ .name = TYPE_SSI_SD,
+ .parent = TYPE_SSI_PERIPHERAL,
+ .instance_size = sizeof(ssi_sd_state),
+ .class_init = ssi_sd_class_init,
+ },
};
-static void ssi_sd_register_types(void)
-{
- type_register_static(&ssi_sd_info);
-}
-
-type_init(ssi_sd_register_types)
+DEFINE_TYPES(ssi_sd_types)
--
2.41.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] hw/sd: Declare CPU QOM types using DEFINE_TYPES() macro
2023-10-31 8:06 ` [PATCH 1/1] " Philippe Mathieu-Daudé
@ 2023-10-31 8:31 ` Cédric Le Goater
2023-11-08 10:39 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 4+ messages in thread
From: Cédric Le Goater @ 2023-10-31 8:31 UTC (permalink / raw)
To: Philippe Mathieu-Daudé, qemu-devel
Cc: Igor Mammedov, qemu-arm, Peter Maydell, Eduardo Habkost,
Markus Armbruster, Mark Cave-Ayland, Andrew Jeffery, Joel Stanley,
Edgar E. Iglesias, Alistair Francis, Bin Meng, Tyrone Ting,
Hao Wu, qemu-block
On 10/31/23 09:06, 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.
>
> Mechanical transformation using the following comby script:
>
> [pattern-x1]
> match='''
> static const TypeInfo :[i1~.*_info] = {
> :[body]
> };
> static void :[rt1~.*_register_type.](void)
> {
> type_register_static(&:[i2~.*_info]);
> }
> type_init(:[rt2~.*_register_type.])
> '''
> rewrite='''
> static const TypeInfo :[i1][] = {
> {
> :[body]
> },
> };
>
> DEFINE_TYPES(:[i1])
> '''
> rule='where :[i1] == :[i2], :[rt1] == :[rt2]'
>
> [pattern-x2]
> match='''
> static const TypeInfo :[i1a~.*_info] = {
> :[body1]
> };
> ...
> static const TypeInfo :[i2a~.*_info] = {
> :[body2]
> };
> static void :[rt1~.*_register_type.](void)
> {
> type_register_static(&:[i1b~.*_info]);
> type_register_static(&:[i2b~.*_info]);
> }
> type_init(:[rt2~.*_register_type.])
> '''
> rewrite='''
> static const TypeInfo :[i1a][] = {
> {
> :[body1]
> },
> {
> :[body2]
> },
> };
>
> DEFINE_TYPES(:[i1a])
> '''
> rule='''
> where
> :[i1a] == :[i1b],
> :[i2a] == :[i2b],
> :[rt1] == :[rt2]
> '''
>
> and re-indented manually.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
I checked the aspeed part.
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Thanks,
C.
> ---
> hw/sd/aspeed_sdhci.c | 19 ++++++++-----------
> hw/sd/bcm2835_sdhost.c | 33 ++++++++++++++-------------------
> hw/sd/cadence_sdhci.c | 21 +++++++++------------
> hw/sd/core.c | 19 ++++++++-----------
> hw/sd/npcm7xx_sdhci.c | 21 +++++++++------------
> hw/sd/pl181.c | 35 +++++++++++++++--------------------
> hw/sd/pxa2xx_mmci.c | 35 +++++++++++++++--------------------
> hw/sd/sd.c | 37 ++++++++++++++++---------------------
> hw/sd/sdhci-pci.c | 25 +++++++++++--------------
> hw/sd/ssi-sd.c | 19 ++++++++-----------
> 10 files changed, 113 insertions(+), 151 deletions(-)
>
> diff --git a/hw/sd/aspeed_sdhci.c b/hw/sd/aspeed_sdhci.c
> index be8cafd65f..e53206d959 100644
> --- a/hw/sd/aspeed_sdhci.c
> +++ b/hw/sd/aspeed_sdhci.c
> @@ -198,16 +198,13 @@ static void aspeed_sdhci_class_init(ObjectClass *classp, void *data)
> device_class_set_props(dc, aspeed_sdhci_properties);
> }
>
> -static const TypeInfo aspeed_sdhci_info = {
> - .name = TYPE_ASPEED_SDHCI,
> - .parent = TYPE_SYS_BUS_DEVICE,
> - .instance_size = sizeof(AspeedSDHCIState),
> - .class_init = aspeed_sdhci_class_init,
> +static const TypeInfo aspeed_sdhci_types[] = {
> + {
> + .name = TYPE_ASPEED_SDHCI,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_size = sizeof(AspeedSDHCIState),
> + .class_init = aspeed_sdhci_class_init,
> + },
> };
>
> -static void aspeed_sdhci_register_types(void)
> -{
> - type_register_static(&aspeed_sdhci_info);
> -}
> -
> -type_init(aspeed_sdhci_register_types)
> +DEFINE_TYPES(aspeed_sdhci_types)
> diff --git a/hw/sd/bcm2835_sdhost.c b/hw/sd/bcm2835_sdhost.c
> index 9431c35914..a600cf39e2 100644
> --- a/hw/sd/bcm2835_sdhost.c
> +++ b/hw/sd/bcm2835_sdhost.c
> @@ -436,24 +436,19 @@ static void bcm2835_sdhost_class_init(ObjectClass *klass, void *data)
> dc->vmsd = &vmstate_bcm2835_sdhost;
> }
>
> -static const TypeInfo bcm2835_sdhost_info = {
> - .name = TYPE_BCM2835_SDHOST,
> - .parent = TYPE_SYS_BUS_DEVICE,
> - .instance_size = sizeof(BCM2835SDHostState),
> - .class_init = bcm2835_sdhost_class_init,
> - .instance_init = bcm2835_sdhost_init,
> +static const TypeInfo bcm2835_sdhost_types[] = {
> + {
> + .name = TYPE_BCM2835_SDHOST,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_size = sizeof(BCM2835SDHostState),
> + .class_init = bcm2835_sdhost_class_init,
> + .instance_init = bcm2835_sdhost_init,
> + },
> + {
> + .name = TYPE_BCM2835_SDHOST_BUS,
> + .parent = TYPE_SD_BUS,
> + .instance_size = sizeof(SDBus),
> + },
> };
>
> -static const TypeInfo bcm2835_sdhost_bus_info = {
> - .name = TYPE_BCM2835_SDHOST_BUS,
> - .parent = TYPE_SD_BUS,
> - .instance_size = sizeof(SDBus),
> -};
> -
> -static void bcm2835_sdhost_register_types(void)
> -{
> - type_register_static(&bcm2835_sdhost_info);
> - type_register_static(&bcm2835_sdhost_bus_info);
> -}
> -
> -type_init(bcm2835_sdhost_register_types)
> +DEFINE_TYPES(bcm2835_sdhost_types)
> diff --git a/hw/sd/cadence_sdhci.c b/hw/sd/cadence_sdhci.c
> index 75db34befe..ef4e0d74e3 100644
> --- a/hw/sd/cadence_sdhci.c
> +++ b/hw/sd/cadence_sdhci.c
> @@ -175,17 +175,14 @@ static void cadence_sdhci_class_init(ObjectClass *classp, void *data)
> dc->vmsd = &vmstate_cadence_sdhci;
> }
>
> -static const TypeInfo cadence_sdhci_info = {
> - .name = TYPE_CADENCE_SDHCI,
> - .parent = TYPE_SYS_BUS_DEVICE,
> - .instance_size = sizeof(CadenceSDHCIState),
> - .instance_init = cadence_sdhci_instance_init,
> - .class_init = cadence_sdhci_class_init,
> +static const TypeInfo cadence_sdhci_types[] = {
> + {
> + .name = TYPE_CADENCE_SDHCI,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_size = sizeof(CadenceSDHCIState),
> + .instance_init = cadence_sdhci_instance_init,
> + .class_init = cadence_sdhci_class_init,
> + },
> };
>
> -static void cadence_sdhci_register_types(void)
> -{
> - type_register_static(&cadence_sdhci_info);
> -}
> -
> -type_init(cadence_sdhci_register_types)
> +DEFINE_TYPES(cadence_sdhci_types)
> diff --git a/hw/sd/core.c b/hw/sd/core.c
> index 30ee62c510..52d5d90045 100644
> --- a/hw/sd/core.c
> +++ b/hw/sd/core.c
> @@ -259,16 +259,13 @@ void sdbus_reparent_card(SDBus *from, SDBus *to)
> sdbus_set_readonly(to, readonly);
> }
>
> -static const TypeInfo sd_bus_info = {
> - .name = TYPE_SD_BUS,
> - .parent = TYPE_BUS,
> - .instance_size = sizeof(SDBus),
> - .class_size = sizeof(SDBusClass),
> +static const TypeInfo sd_bus_types[] = {
> + {
> + .name = TYPE_SD_BUS,
> + .parent = TYPE_BUS,
> + .instance_size = sizeof(SDBus),
> + .class_size = sizeof(SDBusClass),
> + },
> };
>
> -static void sd_bus_register_types(void)
> -{
> - type_register_static(&sd_bus_info);
> -}
> -
> -type_init(sd_bus_register_types)
> +DEFINE_TYPES(sd_bus_types)
> diff --git a/hw/sd/npcm7xx_sdhci.c b/hw/sd/npcm7xx_sdhci.c
> index b2f5b4a542..9958680090 100644
> --- a/hw/sd/npcm7xx_sdhci.c
> +++ b/hw/sd/npcm7xx_sdhci.c
> @@ -166,17 +166,14 @@ static void npcm7xx_sdhci_instance_init(Object *obj)
> TYPE_SYSBUS_SDHCI);
> }
>
> -static const TypeInfo npcm7xx_sdhci_info = {
> - .name = TYPE_NPCM7XX_SDHCI,
> - .parent = TYPE_SYS_BUS_DEVICE,
> - .instance_size = sizeof(NPCM7xxSDHCIState),
> - .instance_init = npcm7xx_sdhci_instance_init,
> - .class_init = npcm7xx_sdhci_class_init,
> +static const TypeInfo npcm7xx_sdhci_types[] = {
> + {
> + .name = TYPE_NPCM7XX_SDHCI,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_size = sizeof(NPCM7xxSDHCIState),
> + .instance_init = npcm7xx_sdhci_instance_init,
> + .class_init = npcm7xx_sdhci_class_init,
> + },
> };
>
> -static void npcm7xx_sdhci_register_types(void)
> -{
> - type_register_static(&npcm7xx_sdhci_info);
> -}
> -
> -type_init(npcm7xx_sdhci_register_types)
> +DEFINE_TYPES(npcm7xx_sdhci_types)
> diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c
> index 5e554bd467..2b33814d83 100644
> --- a/hw/sd/pl181.c
> +++ b/hw/sd/pl181.c
> @@ -519,14 +519,6 @@ static void pl181_class_init(ObjectClass *klass, void *data)
> k->user_creatable = false;
> }
>
> -static const TypeInfo pl181_info = {
> - .name = TYPE_PL181,
> - .parent = TYPE_SYS_BUS_DEVICE,
> - .instance_size = sizeof(PL181State),
> - .instance_init = pl181_init,
> - .class_init = pl181_class_init,
> -};
> -
> static void pl181_bus_class_init(ObjectClass *klass, void *data)
> {
> SDBusClass *sbc = SD_BUS_CLASS(klass);
> @@ -535,17 +527,20 @@ static void pl181_bus_class_init(ObjectClass *klass, void *data)
> sbc->set_readonly = pl181_set_readonly;
> }
>
> -static const TypeInfo pl181_bus_info = {
> - .name = TYPE_PL181_BUS,
> - .parent = TYPE_SD_BUS,
> - .instance_size = sizeof(SDBus),
> - .class_init = pl181_bus_class_init,
> +static const TypeInfo pl181_info[] = {
> + {
> + .name = TYPE_PL181,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_size = sizeof(PL181State),
> + .instance_init = pl181_init,
> + .class_init = pl181_class_init,
> + },
> + {
> + .name = TYPE_PL181_BUS,
> + .parent = TYPE_SD_BUS,
> + .instance_size = sizeof(SDBus),
> + .class_init = pl181_bus_class_init,
> + },
> };
>
> -static void pl181_register_types(void)
> -{
> - type_register_static(&pl181_info);
> - type_register_static(&pl181_bus_info);
> -}
> -
> -type_init(pl181_register_types)
> +DEFINE_TYPES(pl181_info)
> diff --git a/hw/sd/pxa2xx_mmci.c b/hw/sd/pxa2xx_mmci.c
> index 124fbf8bbd..d785a3d80f 100644
> --- a/hw/sd/pxa2xx_mmci.c
> +++ b/hw/sd/pxa2xx_mmci.c
> @@ -580,25 +580,20 @@ static void pxa2xx_mmci_bus_class_init(ObjectClass *klass, void *data)
> sbc->set_readonly = pxa2xx_mmci_set_readonly;
> }
>
> -static const TypeInfo pxa2xx_mmci_info = {
> - .name = TYPE_PXA2XX_MMCI,
> - .parent = TYPE_SYS_BUS_DEVICE,
> - .instance_size = sizeof(PXA2xxMMCIState),
> - .instance_init = pxa2xx_mmci_instance_init,
> - .class_init = pxa2xx_mmci_class_init,
> +static const TypeInfo pxa2xx_mmci_types[] = {
> + {
> + .name = TYPE_PXA2XX_MMCI,
> + .parent = TYPE_SYS_BUS_DEVICE,
> + .instance_size = sizeof(PXA2xxMMCIState),
> + .instance_init = pxa2xx_mmci_instance_init,
> + .class_init = pxa2xx_mmci_class_init,
> + },
> + {
> + .name = TYPE_PXA2XX_MMCI_BUS,
> + .parent = TYPE_SD_BUS,
> + .instance_size = sizeof(SDBus),
> + .class_init = pxa2xx_mmci_bus_class_init,
> + },
> };
>
> -static const TypeInfo pxa2xx_mmci_bus_info = {
> - .name = TYPE_PXA2XX_MMCI_BUS,
> - .parent = TYPE_SD_BUS,
> - .instance_size = sizeof(SDBus),
> - .class_init = pxa2xx_mmci_bus_class_init,
> -};
> -
> -static void pxa2xx_mmci_register_types(void)
> -{
> - type_register_static(&pxa2xx_mmci_info);
> - type_register_static(&pxa2xx_mmci_bus_info);
> -}
> -
> -type_init(pxa2xx_mmci_register_types)
> +DEFINE_TYPES(pxa2xx_mmci_types)
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 4823befdef..1106ff7d78 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -2278,16 +2278,6 @@ static void sd_class_init(ObjectClass *klass, void *data)
> sc->proto = &sd_proto_sd;
> }
>
> -static const TypeInfo sd_info = {
> - .name = TYPE_SD_CARD,
> - .parent = TYPE_DEVICE,
> - .instance_size = sizeof(SDState),
> - .class_size = sizeof(SDCardClass),
> - .class_init = sd_class_init,
> - .instance_init = sd_instance_init,
> - .instance_finalize = sd_instance_finalize,
> -};
> -
> /*
> * We do not model the chip select pin, so allow the board to select
> * whether card should be in SSI or MMC/SD mode. It is also up to the
> @@ -2303,16 +2293,21 @@ static void sd_spi_class_init(ObjectClass *klass, void *data)
> sc->proto = &sd_proto_spi;
> }
>
> -static const TypeInfo sd_spi_info = {
> - .name = TYPE_SD_CARD_SPI,
> - .parent = TYPE_SD_CARD,
> - .class_init = sd_spi_class_init,
> +static const TypeInfo sd_types[] = {
> + {
> + .name = TYPE_SD_CARD,
> + .parent = TYPE_DEVICE,
> + .instance_size = sizeof(SDState),
> + .class_size = sizeof(SDCardClass),
> + .class_init = sd_class_init,
> + .instance_init = sd_instance_init,
> + .instance_finalize = sd_instance_finalize,
> + },
> + {
> + .name = TYPE_SD_CARD_SPI,
> + .parent = TYPE_SD_CARD,
> + .class_init = sd_spi_class_init,
> + },
> };
>
> -static void sd_register_types(void)
> -{
> - type_register_static(&sd_info);
> - type_register_static(&sd_spi_info);
> -}
> -
> -type_init(sd_register_types)
> +DEFINE_TYPES(sd_types)
> diff --git a/hw/sd/sdhci-pci.c b/hw/sd/sdhci-pci.c
> index c737c8b930..9b7bee8b3f 100644
> --- a/hw/sd/sdhci-pci.c
> +++ b/hw/sd/sdhci-pci.c
> @@ -68,20 +68,17 @@ static void sdhci_pci_class_init(ObjectClass *klass, void *data)
> sdhci_common_class_init(klass, data);
> }
>
> -static const TypeInfo sdhci_pci_info = {
> - .name = TYPE_PCI_SDHCI,
> - .parent = TYPE_PCI_DEVICE,
> - .instance_size = sizeof(SDHCIState),
> - .class_init = sdhci_pci_class_init,
> - .interfaces = (InterfaceInfo[]) {
> - { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> - { },
> +static const TypeInfo sdhci_pci_types[] = {
> + {
> + .name = TYPE_PCI_SDHCI,
> + .parent = TYPE_PCI_DEVICE,
> + .instance_size = sizeof(SDHCIState),
> + .class_init = sdhci_pci_class_init,
> + .interfaces = (InterfaceInfo[]) {
> + { INTERFACE_CONVENTIONAL_PCI_DEVICE },
> + { },
> + },
> },
> };
>
> -static void sdhci_pci_register_type(void)
> -{
> - type_register_static(&sdhci_pci_info);
> -}
> -
> -type_init(sdhci_pci_register_type)
> +DEFINE_TYPES(sdhci_pci_types)
> diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
> index 167c03b780..a6cc1ad6c8 100644
> --- a/hw/sd/ssi-sd.c
> +++ b/hw/sd/ssi-sd.c
> @@ -403,16 +403,13 @@ static void ssi_sd_class_init(ObjectClass *klass, void *data)
> dc->user_creatable = false;
> }
>
> -static const TypeInfo ssi_sd_info = {
> - .name = TYPE_SSI_SD,
> - .parent = TYPE_SSI_PERIPHERAL,
> - .instance_size = sizeof(ssi_sd_state),
> - .class_init = ssi_sd_class_init,
> +static const TypeInfo ssi_sd_types[] = {
> + {
> + .name = TYPE_SSI_SD,
> + .parent = TYPE_SSI_PERIPHERAL,
> + .instance_size = sizeof(ssi_sd_state),
> + .class_init = ssi_sd_class_init,
> + },
> };
>
> -static void ssi_sd_register_types(void)
> -{
> - type_register_static(&ssi_sd_info);
> -}
> -
> -type_init(ssi_sd_register_types)
> +DEFINE_TYPES(ssi_sd_types)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] hw/sd: Declare CPU QOM types using DEFINE_TYPES() macro
2023-10-31 8:31 ` Cédric Le Goater
@ 2023-11-08 10:39 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-11-08 10:39 UTC (permalink / raw)
To: Cédric Le Goater, qemu-devel
Cc: Igor Mammedov, qemu-arm, Peter Maydell, Eduardo Habkost,
Markus Armbruster, Mark Cave-Ayland, Andrew Jeffery, Joel Stanley,
Edgar E. Iglesias, Alistair Francis, Bin Meng, Tyrone Ting,
Hao Wu, qemu-block
On 31/10/23 09:31, Cédric Le Goater wrote:
> On 10/31/23 09:06, 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.
>>
>> Mechanical transformation using the following comby script:
>>
>> [pattern-x1]
>> match='''
>> static const TypeInfo :[i1~.*_info] = {
>> :[body]
>> };
>> static void :[rt1~.*_register_type.](void)
>> {
>> type_register_static(&:[i2~.*_info]);
>> }
>> type_init(:[rt2~.*_register_type.])
>> '''
>> rewrite='''
>> static const TypeInfo :[i1][] = {
>> {
>> :[body]
>> },
>> };
>>
>> DEFINE_TYPES(:[i1])
>> '''
>> rule='where :[i1] == :[i2], :[rt1] == :[rt2]'
>>
>> [pattern-x2]
>> match='''
>> static const TypeInfo :[i1a~.*_info] = {
>> :[body1]
>> };
>> ...
>> static const TypeInfo :[i2a~.*_info] = {
>> :[body2]
>> };
>> static void :[rt1~.*_register_type.](void)
>> {
>> type_register_static(&:[i1b~.*_info]);
>> type_register_static(&:[i2b~.*_info]);
>> }
>> type_init(:[rt2~.*_register_type.])
>> '''
>> rewrite='''
>> static const TypeInfo :[i1a][] = {
>> {
>> :[body1]
>> },
>> {
>> :[body2]
>> },
>> };
>>
>> DEFINE_TYPES(:[i1a])
>> '''
>> rule='''
>> where
>> :[i1a] == :[i1b],
>> :[i2a] == :[i2b],
>> :[rt1] == :[rt2]
>> '''
>>
>> and re-indented manually.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>
> I checked the aspeed part.
>
> Reviewed-by: Cédric Le Goater <clg@kaod.org>
In the absence of other reviews, I'm queueing this patch via my cpu/misc
tree, thanks!
>> ---
>> hw/sd/aspeed_sdhci.c | 19 ++++++++-----------
>> hw/sd/bcm2835_sdhost.c | 33 ++++++++++++++-------------------
>> hw/sd/cadence_sdhci.c | 21 +++++++++------------
>> hw/sd/core.c | 19 ++++++++-----------
>> hw/sd/npcm7xx_sdhci.c | 21 +++++++++------------
>> hw/sd/pl181.c | 35 +++++++++++++++--------------------
>> hw/sd/pxa2xx_mmci.c | 35 +++++++++++++++--------------------
>> hw/sd/sd.c | 37 ++++++++++++++++---------------------
>> hw/sd/sdhci-pci.c | 25 +++++++++++--------------
>> hw/sd/ssi-sd.c | 19 ++++++++-----------
>> 10 files changed, 113 insertions(+), 151 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-11-08 10:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-31 8:06 [PATCH 0/1] hw/sd: Declare CPU QOM types using DEFINE_TYPES() macro Philippe Mathieu-Daudé
2023-10-31 8:06 ` [PATCH 1/1] " Philippe Mathieu-Daudé
2023-10-31 8:31 ` Cédric Le Goater
2023-11-08 10:39 ` Philippe Mathieu-Daudé
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).