@@ -30,6 +30,8 @@
#include "hw/sd/sd.h"
#include "qom/object.h"
+typedef struct SDHCIClass SDHCIClass;
+
/*
* SD/MMC host controller state
*
@@ -41,13 +43,12 @@
* card to be protected).
*/
struct SDHCIState {
- /*< private >*/
union {
PCIDevice pcidev;
SysBusDevice busdev;
};
- /*< public >*/
+ SDHCIClass *sc;
SDBus sdbus;
MemoryRegion iomem;
AddressSpace sysbus_dma_as;
@@ -110,6 +111,13 @@ struct SDHCIState {
};
typedef struct SDHCIState SDHCIState;
+struct SDHCIClass {
+ union {
+ PCIDeviceClass pci_parent_class;
+ SysBusDeviceClass sbd_parent_class;
+ };
+};
+
/*
* NOTE: This definition is taken out of Linux kernel and so the
* original bit number is preserved
@@ -126,10 +134,11 @@ enum {
#define TYPE_PCI_SDHCI "sdhci-pci"
DECLARE_INSTANCE_CHECKER(SDHCIState, PCI_SDHCI,
TYPE_PCI_SDHCI)
+DECLARE_CLASS_CHECKERS(SDHCIClass, PCI_SDHCI,
+ TYPE_PCI_SDHCI)
#define TYPE_SYSBUS_SDHCI "generic-sdhci"
-DECLARE_INSTANCE_CHECKER(SDHCIState, SYSBUS_SDHCI,
- TYPE_SYSBUS_SDHCI)
+OBJECT_DECLARE_TYPE(SDHCIState, SDHCIClass, SYSBUS_SDHCI)
#define TYPE_IMX_USDHC "imx-usdhc"
@@ -73,6 +73,7 @@ static const TypeInfo sdhci_pci_types[] = {
.parent = TYPE_PCI_DEVICE,
.instance_size = sizeof(SDHCIState),
.class_init = sdhci_pci_class_init,
+ .class_size = sizeof(SDHCIClass),
.interfaces = (InterfaceInfo[]) {
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
{ },
@@ -1419,6 +1419,8 @@ static void sdhci_init_readonly_registers(SDHCIState *s, Error **errp)
void sdhci_initfn(SDHCIState *s)
{
+ s->sc = (SDHCIClass *)object_get_class(OBJECT(s)); /* Cache QOM parent */
+
qbus_init(&s->sdbus, sizeof(s->sdbus), TYPE_SDHCI_BUS, DEVICE(s), "sd-bus");
s->insert_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
@@ -1960,6 +1962,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,
},
{
TYPE_SYSBUS_SDHCI is a bit odd because it uses an union to work with both SysBus / PCI parent. For this reason, we can not use the OBJECT_DECLARE_TYPE() macro twice (on SYSBUS_SDHCI & PCI_SDHCI) and we must keep a pair of lower DECLARE_INSTANCE_CHECKER) and DECLARE_CLASS_CHECKERS() for PCI, in order to avoid: include/hw/sd/sdhci.h:165:1: error: redefinition of 'glib_autoptr_clear_SDHCIState' include/hw/sd/sdhci.h:165:1: error: redefinition of 'glib_autoptr_cleanup_SDHCIState' include/hw/sd/sdhci.h:165:1: error: redefinition of 'glib_autoptr_destroy_SDHCIState' include/hw/sd/sdhci.h:165:1: error: redefinition of 'glib_listautoptr_cleanup_SDHCIState' include/hw/sd/sdhci.h:165:1: error: redefinition of 'glib_slistautoptr_cleanup_SDHCIState' include/hw/sd/sdhci.h:165:1: error: redefinition of 'glib_queueautoptr_cleanup_SDHCIState' 165 | OBJECT_DECLARE_TYPE(SDHCIState, SDHCIClass, SYSBUS_SDHCI) | ^ include/hw/sd/sdhci.h:158:1: note: previous definition is here 158 | OBJECT_DECLARE_TYPE(SDHCIState, SDHCIClass, PCI_SDHCI) | ^ Since we can not use SYSBUS_SDHCI_GET_CLASS() on PCI instances, cache the class reference in the object state as 'sc'. As this is not a normal use, introduce SDHCIClass in its own commit. Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org> --- I plan to remove the union later. --- include/hw/sd/sdhci.h | 17 +++++++++++++---- hw/sd/sdhci-pci.c | 1 + hw/sd/sdhci.c | 3 +++ 3 files changed, 17 insertions(+), 4 deletions(-)