On Sun, 9 Mar 2025, Philippe Mathieu-Daudé wrote:
On 8/3/25 23:34, BALATON Zoltan wrote:
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.
I'd like to but it isn't possible because the same object state/class is
used by distinct types (PCI & SysBus).
The following (expected to be correct) change ...:
-- >8 --
diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h
index 966a1751f50..341b130995b 100644
--- a/include/hw/sd/sdhci.h
+++ b/include/hw/sd/sdhci.h
@@ -155,10 +155,6 @@ typedef struct SDHCIClass {
#define TYPE_PCI_SDHCI "sdhci-pci"
-DECLARE_INSTANCE_CHECKER(SDHCIState, PCI_SDHCI,
- TYPE_PCI_SDHCI)
+OBJECT_DECLARE_TYPE(SDHCIState, SDHCIClass, PCI_SDHCI)
It would be same as the original patch if you omit this one and only use
OBJECT_DECLARE_TYPE below. You didn't add CLASS_CHECKER to the PCI version
in the original patch either. But I see now it's more complex and so maybe
it's not so easy.
#define TYPE_SYSBUS_SDHCI "generic-sdhci"
-DECLARE_INSTANCE_CHECKER(SDHCIState, SYSBUS_SDHCI,
- TYPE_SYSBUS_SDHCI)
-DECLARE_CLASS_CHECKERS(SDHCIClass, SYSBUS_SDHCI,
- TYPE_SYSBUS_SDHCI)
+OBJECT_DECLARE_TYPE(SDHCIState, SDHCIClass, SYSBUS_SDHCI)
---
[...]
Meanwhile the current legacy macros seems good enough for soft freeze ;)
Good enough for me. I was also happy with my way simpler solution. This is
much more clean up already.
Regards,
BALATON Zoltan