qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: BALATON Zoltan <balaton@eik.bme.hu>, qemu-devel@nongnu.org
Cc: "Steven Lee" <steven_lee@aspeedtech.com>,
	"Joel Stanley" <joel@jms.id.au>,
	"Bernhard Beschow" <shentey@gmail.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	qemu-arm@nongnu.org, "Andrey Smirnov" <andrew.smirnov@gmail.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Bin Meng" <bmeng.cn@gmail.com>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	qemu-ppc@nongnu.org, "Daniel P. Berrangé" <berrange@redhat.com>,
	"Guenter Roeck" <linux@roeck-us.net>,
	"Andrew Jeffery" <andrew@codeconstruct.com.au>,
	"Troy Lee" <leetroy@gmail.com>,
	"Jean-Christophe Dubois" <jcd@tribudubois.net>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	qemu-block@nongnu.org, "Jamin Lin" <jamin_lin@aspeedtech.com>
Subject: [PATCH v5 06/14] hw/sd/sdhci: Introduce SDHCIClass stub
Date: Mon, 10 Mar 2025 01:06:12 +0100	[thread overview]
Message-ID: <20250310000620.70120-7-philmd@linaro.org> (raw)
In-Reply-To: <20250310000620.70120-1-philmd@linaro.org>

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(-)

diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h
index 2e6e719df7b..c42aeab6848 100644
--- a/include/hw/sd/sdhci.h
+++ b/include/hw/sd/sdhci.h
@@ -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"
 
diff --git a/hw/sd/sdhci-pci.c b/hw/sd/sdhci-pci.c
index 5268c0dee50..fe62582de90 100644
--- a/hw/sd/sdhci-pci.c
+++ b/hw/sd/sdhci-pci.c
@@ -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 },
             { },
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index d1b1b187874..176bee6b8f5 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -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,
     },
     {
-- 
2.47.1



  parent reply	other threads:[~2025-03-10  0:07 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-10  0:06 [PATCH v5 00/14] hw/sd/sdhci: Set reset value of interrupt registers Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 01/14] hw/qdev-properties-system: Include missing 'qapi/qapi-types-common.h' Philippe Mathieu-Daudé
2025-03-11 10:56   ` Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 02/14] hw/sd/sdhci: Remove need for SDHCIState::vendor field Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 03/14] hw/sd/sdhci: Redefine SDHCI_QUIRK_NO_BUSY_IRQ bitmask as bit Philippe Mathieu-Daudé
2025-03-10 13:31   ` BALATON Zoltan
2025-03-10  0:06 ` [PATCH v5 04/14] hw/sd/sdhci: Include 'wp-inverted' property in quirk bitmask Philippe Mathieu-Daudé
2025-03-10 13:36   ` BALATON Zoltan
2025-03-10  0:06 ` [PATCH v5 05/14] hw/sd/sdhci: Include 'pending-insert-quirk' " Philippe Mathieu-Daudé
2025-03-10 13:39   ` BALATON Zoltan
2025-03-10  0:06 ` Philippe Mathieu-Daudé [this message]
2025-03-10  0:06 ` [PATCH v5 07/14] hw/sd/sdhci: Make quirks a class property Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 08/14] hw/sd/sdhci: Make I/O region size " Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 09/14] hw/sd/sdhci: Allow SDHCI classes to register their own MemoryRegionOps Philippe Mathieu-Daudé
2025-03-10 13:50   ` BALATON Zoltan
2025-03-10  0:06 ` [PATCH v5 10/14] hw/sd/sdhci: Allow SDHCI classes to register their own read-only regs Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 11/14] hw/sd/sdhci: Allow SDHCI classes to have different register reset values Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 12/14] hw/sd/sdhci: Implement Freescale eSDHC as TYPE_FSL_ESDHC Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 13/14] hw/ppc/e500: Replace generic SDHCI by Freescale eSDHC Philippe Mathieu-Daudé
2025-03-10  0:06 ` [PATCH v5 14/14] hw/sd/sdhci: Remove unnecessary 'endianness' property Philippe Mathieu-Daudé
2025-03-10 14:09   ` BALATON Zoltan
2025-03-10 15:27     ` Philippe Mathieu-Daudé
2025-03-10 15:56       ` Guenter Roeck
2025-03-10 17:31         ` Philippe Mathieu-Daudé
2025-03-10 17:38           ` Bernhard Beschow
2025-03-10 18:24             ` Cédric Le Goater
2025-03-10 18:34               ` Philippe Mathieu-Daudé
2025-03-10 22:30           ` Guenter Roeck
2025-03-11  7:31   ` Bernhard Beschow
2025-03-11  7:59     ` Philippe Mathieu-Daudé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250310000620.70120-7-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=andrew.smirnov@gmail.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=balaton@eik.bme.hu \
    --cc=berrange@redhat.com \
    --cc=bmeng.cn@gmail.com \
    --cc=clg@kaod.org \
    --cc=eduardo@habkost.net \
    --cc=jamin_lin@aspeedtech.com \
    --cc=jcd@tribudubois.net \
    --cc=joel@jms.id.au \
    --cc=leetroy@gmail.com \
    --cc=linux@roeck-us.net \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=shentey@gmail.com \
    --cc=steven_lee@aspeedtech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).