qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Joaquin de Andres" <me@xcancerberox.com.ar>,
	"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
	"Andrew Baumann" <Andrew.Baumann@microsoft.com>,
	"Esteban Bosse" <estebanbosse@gmail.com>,
	qemu-arm@nongnu.org, "Igor Mammedov" <imammedo@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH v2 15/30] hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type
Date: Thu,  6 Feb 2020 02:17:41 +0100	[thread overview]
Message-ID: <20200206011756.2413-16-f4bug@amsat.org> (raw)
In-Reply-To: <20200206011756.2413-1-f4bug@amsat.org>

Remove usage of TypeInfo::class_data. Instead fill the fields in
the corresponding class_init().

Cc: Igor Mammedov <imammedo@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 hw/arm/bcm2836.c | 109 ++++++++++++++++++++++-------------------------
 1 file changed, 51 insertions(+), 58 deletions(-)

diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c
index 24109fef1d..683d04d6ea 100644
--- a/hw/arm/bcm2836.c
+++ b/hw/arm/bcm2836.c
@@ -16,57 +16,30 @@
 #include "hw/arm/raspi_platform.h"
 #include "hw/sysbus.h"
 
-typedef struct BCM283XInfo BCM283XInfo;
-
 typedef struct BCM283XClass {
     /*< private >*/
     DeviceClass parent_class;
     /*< public >*/
-    const BCM283XInfo *info;
-} BCM283XClass;
-
-struct BCM283XInfo {
-    const char *name;
     const char *cpu_type;
     hwaddr peri_base; /* Peripheral base address seen by the CPU */
     hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */
     int clusterid;
-};
+} BCM283XClass;
 
 #define BCM283X_CLASS(klass) \
     OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X)
 #define BCM283X_GET_CLASS(obj) \
     OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X)
 
-static const BCM283XInfo bcm283x_socs[] = {
-    {
-        .name = TYPE_BCM2836,
-        .cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"),
-        .peri_base = 0x3f000000,
-        .ctrl_base = 0x40000000,
-        .clusterid = 0xf,
-    },
-#ifdef TARGET_AARCH64
-    {
-        .name = TYPE_BCM2837,
-        .cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"),
-        .peri_base = 0x3f000000,
-        .ctrl_base = 0x40000000,
-        .clusterid = 0x0,
-    },
-#endif
-};
-
 static void bcm2836_init(Object *obj)
 {
     BCM283XState *s = BCM283X(obj);
     BCM283XClass *bc = BCM283X_GET_CLASS(obj);
-    const BCM283XInfo *info = bc->info;
     int n;
 
     for (n = 0; n < BCM283X_NCPUS; n++) {
         object_initialize_child(obj, "cpu[*]", &s->cpu[n].core,
-                                sizeof(s->cpu[n].core), info->cpu_type,
+                                sizeof(s->cpu[n].core), bc->cpu_type,
                                 &error_abort, NULL);
     }
 
@@ -85,7 +58,6 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
 {
     BCM283XState *s = BCM283X(dev);
     BCM283XClass *bc = BCM283X_GET_CLASS(dev);
-    const BCM283XInfo *info = bc->info;
     Object *obj;
     Error *err = NULL;
     int n;
@@ -119,7 +91,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
     }
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0,
-                            info->peri_base, 1);
+                            bc->peri_base, 1);
 
     /* bcm2836 interrupt controller (and mailboxes, etc.) */
     object_property_set_bool(OBJECT(&s->control), true, "realized", &err);
@@ -128,7 +100,7 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base);
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base);
 
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0,
         qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0));
@@ -137,11 +109,11 @@ static void bcm2836_realize(DeviceState *dev, Error **errp)
 
     for (n = 0; n < BCM283X_NCPUS; n++) {
         /* TODO: this should be converted to a property of ARM_CPU */
-        s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n;
+        s->cpu[n].core.mp_affinity = (bc->clusterid << 8) | n;
 
         /* set periphbase/CBAR value for CPU-local registers */
         object_property_set_int(OBJECT(&s->cpu[n].core),
-                                info->peri_base,
+                                bc->peri_base,
                                 "reset-cbar", &err);
         if (err) {
             error_propagate(errp, err);
@@ -190,38 +162,59 @@ static Property bcm2836_props[] = {
 static void bcm283x_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
-    BCM283XClass *bc = BCM283X_CLASS(oc);
 
-    bc->info = data;
-    dc->realize = bcm2836_realize;
-    device_class_set_props(dc, bcm2836_props);
     /* Reason: Must be wired up in code (see raspi_init() function) */
     dc->user_creatable = false;
 }
 
-static const TypeInfo bcm283x_type_info = {
-    .name = TYPE_BCM283X,
-    .parent = TYPE_DEVICE,
-    .instance_size = sizeof(BCM283XState),
-    .instance_init = bcm2836_init,
-    .class_size = sizeof(BCM283XClass),
-    .abstract = true,
+static void bcm2836_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    BCM283XClass *bc = BCM283X_CLASS(oc);
+
+    bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7");
+    bc->peri_base = 0x3f000000;
+    bc->ctrl_base = 0x40000000;
+    bc->clusterid = 0xf;
+    dc->realize = bcm2836_realize;
+    device_class_set_props(dc, bcm2836_props);
 };
 
-static void bcm2836_register_types(void)
+#ifdef TARGET_AARCH64
+static void bcm2837_class_init(ObjectClass *oc, void *data)
 {
-    int i;
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    BCM283XClass *bc = BCM283X_CLASS(oc);
 
-    type_register_static(&bcm283x_type_info);
-    for (i = 0; i < ARRAY_SIZE(bcm283x_socs); i++) {
-        TypeInfo ti = {
-            .name = bcm283x_socs[i].name,
-            .parent = TYPE_BCM283X,
-            .class_init = bcm283x_class_init,
-            .class_data = (void *) &bcm283x_socs[i],
-        };
-        type_register(&ti);
+    bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53");
+    bc->peri_base = 0x3f000000;
+    bc->ctrl_base = 0x40000000;
+    bc->clusterid = 0x0;
+    dc->realize = bcm2836_realize;
+    device_class_set_props(dc, bcm2836_props);
+};
+#endif
+
+static const TypeInfo bcm283x_types[] = {
+    {
+        .name           = TYPE_BCM2836,
+        .parent         = TYPE_BCM283X,
+        .class_init     = bcm2836_class_init,
+#ifdef TARGET_AARCH64
+    }, {
+        .name           = TYPE_BCM2837,
+        .parent         = TYPE_BCM283X,
+        .class_init     = bcm2837_class_init,
+#endif
+    }, {
+        .name           = TYPE_BCM283X,
+        .parent         = TYPE_DEVICE,
+        .instance_size  = sizeof(BCM283XState),
+        .instance_init  = bcm2836_init,
+        .class_size     = sizeof(BCM283XClass),
+        .class_init     = bcm283x_class_init,
+        .abstract       = true,
     }
-}
+};
 
-type_init(bcm2836_register_types)
+DEFINE_TYPES(bcm283x_types)
-- 
2.21.1



  parent reply	other threads:[~2020-02-06  1:26 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06  1:17 [PATCH v2 00/30] hw/arm/raspi: Dynamically create machines based on the board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 01/30] hw/arm/raspi: Use BCM2708 machine type with pre Device Tree kernels Philippe Mathieu-Daudé
2020-02-06 12:21   ` BALATON Zoltan
2020-02-07 14:50     ` Philippe Mathieu-Daudé
2020-02-07 22:19       ` BALATON Zoltan
2020-02-06  1:17 ` [PATCH v2 02/30] hw/arm/raspi: Correct the board descriptions Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 03/30] hw/arm/raspi: Extract the version from the board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 04/30] hw/arm/raspi: Extract the RAM size " Philippe Mathieu-Daudé
2020-02-06 12:24   ` BALATON Zoltan
2020-02-06  1:17 ` [PATCH v2 05/30] hw/arm/raspi: Extract the processor type " Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 06/30] hw/arm/raspi: Trivial code movement Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 07/30] hw/arm/raspi: Make machines children of abstract RaspiMachineClass Philippe Mathieu-Daudé
2020-02-06 12:24   ` BALATON Zoltan
2020-02-06  1:17 ` [PATCH v2 08/30] hw/arm/raspi: Make board_rev a field of RaspiMachineClass Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 09/30] hw/arm/raspi: Let class_init() directly call raspi_machine_init() Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 10/30] hw/arm/raspi: Set default RAM size to size encoded in board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 11/30] hw/arm/raspi: Extract the board model from the " Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 12/30] hw/arm/raspi: Use a unique raspi_machine_class_init() method Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 13/30] hw/arm/raspi: Extract the cores count from the board revision Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 14/30] hw/arm/bcm2836: Restrict BCM283XClass declaration to C source Philippe Mathieu-Daudé
2020-02-06  1:17 ` Philippe Mathieu-Daudé [this message]
2020-02-06  1:17 ` [PATCH v2 16/30] hw/arm/bcm2836: Introduce BCM283XClass::core_count Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 17/30] hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 18/30] hw/arm/bcm2836: Split out common realize() code Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 19/30] hw/arm/bcm2836: Introduce the BCM2835 SoC Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 20/30] hw/arm/raspi: Add the Raspberry Pi Zero machine Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 21/30] hw/arm/raspi: Add the Raspberry Pi B+ machine Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 22/30] tests/acceptance/boot_linux_console: Use raspi console model as key Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 23/30] tests/acceptance/boot_linux_console: Add raspi version=2 parameter Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 24/30] tests/acceptance/boot_linux_console: Test the raspi1 console Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 25/30] tests/acceptance/boot_linux_console: Test the raspi0 console Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 26/30] python/qemu/machine: Allow to use other serial consoles than default Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 27/30] tests/acceptance/boot_linux_console: Test the raspi1 AUX console Philippe Mathieu-Daudé
2020-02-06  1:17 ` [PATCH v2 28/30] tests/acceptance: Count Raspberry Pi logos displayed on framebuffer Philippe Mathieu-Daudé
2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 29/30] hw/arm/bcm2836: Add the BCM2838 (ARMv8) Philippe Mathieu-Daudé
2020-02-06  1:17 ` [NOTFORMERGE PATCH v2 30/30] hw/arm/raspi: Add the Raspberry Pi 4 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=20200206011756.2413-16-f4bug@amsat.org \
    --to=f4bug@amsat.org \
    --cc=Andrew.Baumann@microsoft.com \
    --cc=estebanbosse@gmail.com \
    --cc=imammedo@redhat.com \
    --cc=me@xcancerberox.com.ar \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).