qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
	"Tyrone Ting" <kfting@nuvoton.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	"Joel Stanley" <joel@jms.id.au>,
	"Alistair Francis" <alistair@alistair23.me>,
	"Anton Johansson" <anjo@rev.ng>,
	"Andrey Smirnov" <andrew.smirnov@gmail.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Hao Wu" <wuhaotsh@google.com>, "Cédric Le Goater" <clg@kaod.org>,
	"Jean-Christophe Dubois" <jcd@tribudubois.net>,
	"Igor Mitsyanko" <i.mitsyanko@gmail.com>,
	"Edgar E. Iglesias" <edgar.iglesias@gmail.com>,
	"Andrew Jeffery" <andrew@codeconstruct.com.au>,
	"Rob Herring" <robh@kernel.org>,
	qemu-arm@nongnu.org,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 21/33] hw/cpu/arm: Create CPUs once in MPCore parent
Date: Tue, 12 Dec 2023 17:29:21 +0100	[thread overview]
Message-ID: <20231212162935.42910-22-philmd@linaro.org> (raw)
In-Reply-To: <20231212162935.42910-1-philmd@linaro.org>

Add support for creating the MPCore CPU cluster in the
abstract TYPE_CORTEX_MPCORE_PRIV parent realize() handler.

Only do so if the 'cpu-type' property is set, so current
behavior is not modified. Boards will be converted by
setting this property.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 include/hw/cpu/cortex_mpcore.h | 12 +++++
 hw/cpu/cortex_mpcore.c         | 88 ++++++++++++++++++++++++++++++++++
 2 files changed, 100 insertions(+)

diff --git a/include/hw/cpu/cortex_mpcore.h b/include/hw/cpu/cortex_mpcore.h
index 4e1aa9f7f7..9a4fc2404e 100644
--- a/include/hw/cpu/cortex_mpcore.h
+++ b/include/hw/cpu/cortex_mpcore.h
@@ -16,6 +16,7 @@
 #include "hw/misc/a9scu.h"
 #include "hw/timer/a9gtimer.h"
 #include "hw/timer/arm_mptimer.h"
+#include "target/arm/cpu-qom.h"
 
 /*
  * This is a model of the Arm Cortex-A MPCore family of hardware.
@@ -93,13 +94,24 @@ struct CortexMPPrivState {
     SysBusDevice parent_obj;
 
     MemoryRegion container;
+    ARMCPU *cpu[4];
     GICState gic;
 
     /* Properties */
+    uint8_t cluster_id;
     uint32_t num_cores;
 
+    char *cpu_type;
     bool cpu_has_el3;
     bool cpu_has_el2;
+    bool cpu_has_vfp_d32;
+    bool cpu_has_neon;
+    uint64_t cpu_freq_hz;
+    uint64_t cpu_midr;
+    uint32_t cpu_psci_conduit;
+    uint64_t cpu_reset_cbar;
+    bool cpu_reset_hivecs;
+    MemoryRegion *cpu_memory;
 
     uint32_t gic_spi_num;
 };
diff --git a/hw/cpu/cortex_mpcore.c b/hw/cpu/cortex_mpcore.c
index 75324268fa..65309636d7 100644
--- a/hw/cpu/cortex_mpcore.c
+++ b/hw/cpu/cortex_mpcore.c
@@ -12,6 +12,7 @@
 #include "hw/cpu/cortex_mpcore.h"
 #include "hw/irq.h"
 #include "sysemu/kvm.h"
+#include "target/arm/cpu.h"
 
 static void cortex_mpcore_priv_set_irq(void *opaque, int irq, int level)
 {
@@ -50,6 +51,12 @@ static void cortex_mpcore_priv_realize(DeviceState *dev, Error **errp)
         return;
     }
 
+    if (s->num_cores > ARRAY_SIZE(s->cpu)) {
+        error_setg(errp,
+                   "At most %zu CPU cores are supported", ARRAY_SIZE(s->cpu));
+        return;
+    }
+
     qdev_prop_set_uint32(gicdev, "num-cpu", s->num_cores);
     qdev_prop_set_uint32(gicdev, "num-irq", s->gic_spi_num);
     if (k->gic_priority_bits) {
@@ -75,14 +82,95 @@ static void cortex_mpcore_priv_realize(DeviceState *dev, Error **errp)
 
     /* Pass through inbound GPIO lines to the GIC */
     qdev_init_gpio_in(dev, cortex_mpcore_priv_set_irq, s->gic_spi_num - 32);
+
+
+    /* CPU */
+    if (!s->cpu_type) {
+        return;
+    }
+    for (int i = 0; i < s->num_cores; i++) {
+        Object *cpuobj;
+
+        cpuobj = object_new(s->cpu_type);
+        object_property_add_child(OBJECT(dev), "cpu[*]", OBJECT(cpuobj));
+        object_unref(cpuobj);
+        s->cpu[i] = ARM_CPU(cpuobj);
+
+        object_property_set_bool(cpuobj, "neon", s->cpu_has_neon,
+                                &error_abort);
+        object_property_set_bool(cpuobj, "vfp-d32", s->cpu_has_vfp_d32,
+                                &error_abort);
+        if (object_property_find(cpuobj, "has_el3")) {
+            object_property_set_bool(cpuobj, "has_el3", s->cpu_has_el3,
+                                     &error_abort);
+        }
+        if (object_property_find(cpuobj, "has_el2")) {
+            object_property_set_bool(cpuobj, "has_el2", s->cpu_has_el2,
+                                     &error_abort);
+        }
+        if (s->cpu_freq_hz) {
+            object_property_set_int(cpuobj, "cntfrq", s->cpu_freq_hz,
+                                    &error_abort);
+        }
+        object_property_set_int(cpuobj, "midr", s->cpu_midr, &error_abort);
+        object_property_set_bool(cpuobj, "reset-hivecs", s->cpu_reset_hivecs,
+                                 &error_abort);
+        if (s->num_cores == 1) {
+            /* On uniprocessor, the CBAR is set to 0 */
+        } else if (object_property_find(cpuobj, "reset-cbar")) {
+            object_property_set_int(cpuobj, "reset-cbar",
+                                    s->cpu_reset_cbar, &error_abort);
+        }
+        if (i > 0) {
+            /*
+             * Secondary CPUs start in powered-down state (and can be
+             * powered up via the SRC system reset controller)
+             */
+            object_property_set_bool(cpuobj, "start-powered-off", true,
+                                     &error_abort);
+        }
+        if (s->cluster_id) {
+            object_property_set_int(cpuobj, "mp-affinity",
+                                    (s->cluster_id << ARM_AFF1_SHIFT) | i,
+                                    &error_abort);
+        } else {
+            object_property_set_int(cpuobj, "mp-affinity",
+                                    arm_cpu_mp_affinity(i, s->num_cores),
+                                    &error_abort);
+        }
+        object_property_set_int(cpuobj, "psci-conduit",
+                                s->cpu_psci_conduit, &error_abort);
+        if (s->cpu_memory) {
+            object_property_set_link(cpuobj, "memory",
+                                     OBJECT(s->cpu_memory), &error_abort);
+        }
+
+        if (!qdev_realize(DEVICE(s->cpu[i]), NULL, errp)) {
+            return;
+        }
+    }
 }
 
 static Property cortex_mpcore_priv_properties[] = {
+    DEFINE_PROP_UINT8("cluster-id", CortexMPPrivState, cluster_id, 0),
     DEFINE_PROP_UINT32("num-cores", CortexMPPrivState, num_cores, 1),
     DEFINE_PROP_UINT32("num-cpu", CortexMPPrivState, num_cores, 1), /* alias */
 
+    DEFINE_PROP_STRING("cpu-type", CortexMPPrivState, cpu_type),
     DEFINE_PROP_BOOL("cpu-has-el3", CortexMPPrivState, cpu_has_el3, true),
     DEFINE_PROP_BOOL("cpu-has-el2", CortexMPPrivState, cpu_has_el2, false),
+    DEFINE_PROP_BOOL("cpu-has-vfp-d32", CortexMPPrivState, cpu_has_vfp_d32,
+                     true),
+    DEFINE_PROP_BOOL("cpu-has-neon", CortexMPPrivState, cpu_has_neon, true),
+    DEFINE_PROP_UINT64("cpu-freq-hz", CortexMPPrivState, cpu_freq_hz, 0),
+    DEFINE_PROP_UINT64("cpu-midr", CortexMPPrivState, cpu_midr, 0),
+    DEFINE_PROP_UINT32("cpu-psci-conduit", CortexMPPrivState, cpu_psci_conduit,
+                       QEMU_PSCI_CONDUIT_DISABLED),
+    DEFINE_PROP_UINT64("cpu-reset-cbar", CortexMPPrivState, cpu_reset_cbar, 0),
+    DEFINE_PROP_BOOL("cpu-reset-hivecs", CortexMPPrivState, cpu_reset_hivecs,
+                     false),
+    DEFINE_PROP_LINK("cpu-memory", CortexMPPrivState, cpu_memory,
+                     TYPE_MEMORY_REGION, MemoryRegion *),
 
     DEFINE_PROP_UINT32("gic-spi-num", CortexMPPrivState, gic_spi_num, 0),
     DEFINE_PROP_UINT32("num-irq", CortexMPPrivState, gic_spi_num, 0), /* alias */
-- 
2.41.0



  parent reply	other threads:[~2023-12-12 16:34 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-12 16:29 [PATCH 00/33] hw/cpu/arm: Remove one use of qemu_get_cpu() in A7/A15 MPCore priv Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 01/33] hw/arm/boot: Propagate vCPU to arm_load_dtb() Philippe Mathieu-Daudé
2024-01-02 13:51   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 02/33] hw/arm/fsl-imx6: Add a local 'gic' variable Philippe Mathieu-Daudé
2024-01-02 13:52   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 03/33] hw/arm/fsl-imx6ul: " Philippe Mathieu-Daudé
2024-01-02 13:52   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 04/33] hw/arm/fsl-imx7: " Philippe Mathieu-Daudé
2024-01-02 13:53   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 05/33] hw/cpu: Remove dead Kconfig Philippe Mathieu-Daudé
2024-01-02 13:53   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 06/33] hw/cpu/arm: Rename 'busdev' -> 'gicsbd' in a15mp_priv_realize() Philippe Mathieu-Daudé
2024-01-02 13:54   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 07/33] hw/cpu/arm: Alias 'num-cpu' property on TYPE_REALVIEW_MPCORE Philippe Mathieu-Daudé
2024-01-02 13:57   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 08/33] hw/cpu/arm: Declare CPU QOM types using DEFINE_TYPES() macro Philippe Mathieu-Daudé
2024-01-02 13:57   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 09/33] hw/cpu/arm: Merge {a9mpcore.h, a15mpcore.h} as cortex_mpcore.h Philippe Mathieu-Daudé
2024-01-02 14:00   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 10/33] hw/cpu/arm: Introduce abstract CORTEX_MPCORE_PRIV QOM type Philippe Mathieu-Daudé
2024-01-02 14:23   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 11/33] hw/cpu/arm: Have A9MPCORE/A15MPCORE inheritate common CORTEX_MPCORE_PRIV Philippe Mathieu-Daudé
2024-01-02 14:23   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 12/33] hw/cpu/arm: Create MPCore container in QOM parent Philippe Mathieu-Daudé
2024-01-02 14:23   ` Cédric Le Goater
2023-12-12 16:29 ` [PATCH 13/33] hw/cpu/arm: Handle 'num_cores' property once in MPCore parent Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 14/33] hw/cpu/arm: Handle 'has_el2/3' properties " Philippe Mathieu-Daudé
2024-01-12 21:33   ` Fabiano Rosas
2024-01-16 16:25     ` Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 15/33] hw/cpu/arm: Handle 'gic-irq' property " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 16/33] hw/cpu/arm: Handle GIC " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 17/33] hw/cpu/arm: Document more properties of CORTEX_MPCORE_PRIV QOM type Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 18/33] hw/cpu/arm: Replace A15MPPrivState by CortexMPPrivState Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 19/33] hw/cpu/arm: Introduce TYPE_A7MPCORE_PRIV for Cortex-A7 MPCore Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 20/33] hw/cpu/arm: Consolidate check on max GIC spi supported Philippe Mathieu-Daudé
2023-12-12 16:29 ` Philippe Mathieu-Daudé [this message]
2023-12-12 16:29 ` [PATCH 22/33] hw/arm/aspeed_ast2600: Let the A7MPcore create/wire the CPU cores Philippe Mathieu-Daudé
2024-01-02  0:11   ` Andrew Jeffery
2023-12-12 16:29 ` [PATCH 23/33] hw/arm/exynos4210: Let the A9MPcore " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 24/33] hw/arm/fsl-imx6: " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 25/33] hw/arm/fsl-imx6ul: Let the A7MPcore " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 26/33] hw/arm/fsl-imx7: " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 27/33] hw/arm/highbank: Let the A9/A15MPcore " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 28/33] hw/arm/vexpress: " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 29/33] hw/arm/xilinx_zynq: Let the A9MPcore " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 30/33] hw/arm/npcm7xx: " Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 31/33] hw/cpu/a9mpcore: Remove legacy code Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 32/33] hw/cpu/arm: Remove 'num-cpu' property alias Philippe Mathieu-Daudé
2023-12-12 16:29 ` [PATCH 33/33] hw/cpu/arm: Remove use of qemu_get_cpu() in A7/A15 realize() Philippe Mathieu-Daudé
2023-12-26 11:17 ` [PATCH 00/33] hw/cpu/arm: Remove one use of qemu_get_cpu() in A7/A15 MPCore priv Philippe Mathieu-Daudé
2024-01-02 14:55 ` Cédric Le Goater
2024-01-02 16:15   ` Philippe Mathieu-Daudé
2024-01-02 16:41     ` Cédric Le Goater
2024-01-03  9:19       ` Philippe Mathieu-Daudé
2024-01-03 19:53         ` Fabiano Rosas
2024-01-09 15:02           ` Cédric Le Goater
2024-01-09 17:40             ` Fabiano Rosas
2024-01-09 18:06               ` Cédric Le Goater
2024-01-09 20:21                 ` Fabiano Rosas
2024-01-09 21:22                   ` Philippe Mathieu-Daudé
2024-01-10  3:36                     ` Peter Xu
2024-01-10  6:03                       ` Markus Armbruster
2024-01-10  6:26                         ` Peter Xu
2024-01-10  8:09                           ` Markus Armbruster
2024-01-10  8:44                             ` Peter Xu
2024-01-12  9:03                           ` Cédric Le Goater
2024-01-10 13:19                         ` Fabiano Rosas
2024-01-10 13:54                           ` Markus Armbruster
2024-01-12 10:26                           ` Cédric Le Goater
2024-01-12 19:54                             ` Fabiano Rosas
2024-01-15  9:04                               ` Cédric Le Goater
2024-01-12  8:41                         ` Cédric Le Goater
2024-01-09 21:07                 ` Philippe Mathieu-Daudé
2024-01-09 21:09                   ` Philippe Mathieu-Daudé
2024-01-12  8:00                     ` Cédric Le Goater
2024-01-12  7:29                   ` Cédric Le Goater

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=20231212162935.42910-22-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=alistair@alistair23.me \
    --cc=andrew.smirnov@gmail.com \
    --cc=andrew@codeconstruct.com.au \
    --cc=anjo@rev.ng \
    --cc=clg@kaod.org \
    --cc=edgar.iglesias@gmail.com \
    --cc=eduardo@habkost.net \
    --cc=i.mitsyanko@gmail.com \
    --cc=jcd@tribudubois.net \
    --cc=joel@jms.id.au \
    --cc=kfting@nuvoton.com \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=robh@kernel.org \
    --cc=wuhaotsh@google.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).