On Sat, 8 Mar 2025, Philippe Mathieu-Daudé wrote:
TYPE_SYSBUS_SDHCI is a bit odd because it uses an union
to work with both SysBus / PCI parent. As this is not a
normal use, introduce SDHCIClass in its own commit.

Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org>
---
include/hw/sd/sdhci.h | 9 +++++++++
hw/sd/sdhci.c         | 1 +
2 files changed, 10 insertions(+)

diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h
index 48247e9a20f..c4b20db3877 100644
--- a/include/hw/sd/sdhci.h
+++ b/include/hw/sd/sdhci.h
@@ -107,6 +107,13 @@ struct SDHCIState {
};
typedef struct SDHCIState SDHCIState;

+typedef struct SDHCIClass {
+    union {
+        PCIDeviceClass pci_parent_class;
+        SysBusDeviceClass sbd_parent_class;
+    };
+} SDHCIClass;
+
/*
 * Controller does not provide transfer-complete interrupt when not
 * busy.
@@ -123,6 +130,8 @@ DECLARE_INSTANCE_CHECKER(SDHCIState, PCI_SDHCI,
#define TYPE_SYSBUS_SDHCI "generic-sdhci"
DECLARE_INSTANCE_CHECKER(SDHCIState, SYSBUS_SDHCI,
                         TYPE_SYSBUS_SDHCI)
+DECLARE_CLASS_CHECKERS(SDHCIClass, SYSBUS_SDHCI,
+                       TYPE_SYSBUS_SDHCI)

Are these two together just OBJECT_DECLARE_TYPE? Then the above typedefs are also not needed just the struct definitions.

Regards,
BALATON Zoltan

#define TYPE_IMX_USDHC "imx-usdhc"

diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index 149b748cbee..4917a9b3632 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -1960,6 +1960,7 @@ static const TypeInfo sdhci_types[] = {
        .instance_size = sizeof(SDHCIState),
        .instance_init = sdhci_sysbus_init,
        .instance_finalize = sdhci_sysbus_finalize,
+        .class_size = sizeof(SDHCIClass),
        .class_init = sdhci_sysbus_class_init,
    },
    {

Reply via email to