qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>
Subject: [PATCH 9/9] hw/arm/armv7m: Pass CPU/NVIC using object_property_add_const_link()
Date: Mon,  6 Feb 2023 13:17:14 +0100	[thread overview]
Message-ID: <20230206121714.85084-10-philmd@linaro.org> (raw)
In-Reply-To: <20230206121714.85084-1-philmd@linaro.org>

Avoid having QOM objects poke at each other internals.
Instead, pass references using QOM link properties.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
Cc: Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
---
 hw/arm/armv7m.c       | 4 ++--
 hw/intc/armv7m_nvic.c | 3 ++-
 target/arm/cpu.c      | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c
index 50a9507c0b..edde774da2 100644
--- a/hw/arm/armv7m.c
+++ b/hw/arm/armv7m.c
@@ -338,8 +338,8 @@ static void armv7m_realize(DeviceState *dev, Error **errp)
      * Tell the CPU where the NVIC is; it will fail realize if it doesn't
      * have one. Similarly, tell the NVIC where its CPU is.
      */
-    s->cpu->env.nvic = &s->nvic;
-    s->nvic.cpu = s->cpu;
+    object_property_add_const_link(OBJECT(s->cpu), "nvic", OBJECT(&s->nvic));
+    object_property_add_const_link(OBJECT(&s->nvic), "cpu", OBJECT(s->cpu));
 
     if (!qdev_realize(DEVICE(s->cpu), NULL, errp)) {
         return;
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index d9c7e414bc..e43898a9e0 100644
--- a/hw/intc/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -2668,7 +2668,8 @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp)
     NVICState *s = NVIC(dev);
 
     /* The armv7m container object will have set our CPU pointer */
-    if (!s->cpu || !arm_feature(&s->cpu->env, ARM_FEATURE_M)) {
+    s->cpu = ARM_CPU(object_property_get_link(OBJECT(dev), "cpu", &error_abort));
+    if (!arm_feature(&s->cpu->env, ARM_FEATURE_M)) {
         error_setg(errp, "The NVIC can only be used with a Cortex-M CPU");
         return;
     }
diff --git a/target/arm/cpu.c b/target/arm/cpu.c
index 876ab8f3bf..f081861947 100644
--- a/target/arm/cpu.c
+++ b/target/arm/cpu.c
@@ -1573,12 +1573,13 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
      * error and will result in segfaults if not caught here.
      */
     if (arm_feature(env, ARM_FEATURE_M)) {
+        env->nvic = NVIC(object_property_get_link(OBJECT(dev), "nvic", NULL));
         if (!env->nvic) {
             error_setg(errp, "This board cannot be used with Cortex-M CPUs");
             return;
         }
     } else {
-        if (env->nvic) {
+        if (object_property_find(OBJECT(dev), "nvic")) {
             error_setg(errp, "This board can only be used with Cortex-M CPUs");
             return;
         }
-- 
2.38.1



  parent reply	other threads:[~2023-02-06 12:18 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-06 12:17 [PATCH 0/9] target/arm: Housekeeping around NVIC Philippe Mathieu-Daudé
2023-02-06 12:17 ` [PATCH 1/9] target/arm: Restrict v7-M MMU helpers to sysemu TCG Philippe Mathieu-Daudé
2023-02-06 18:48   ` Richard Henderson
2023-02-06 12:17 ` [PATCH 2/9] target/arm: Constify ID_PFR1 on user emulation Philippe Mathieu-Daudé
2023-02-06 18:38   ` Richard Henderson
2023-02-06 12:17 ` [PATCH 3/9] target/arm: Avoid resetting CPUARMState::eabi field Philippe Mathieu-Daudé
2023-02-06 18:37   ` Richard Henderson
2023-02-06 12:17 ` [PATCH 4/9] target/arm: Restrict CPUARMState::arm_boot_info to sysemu Philippe Mathieu-Daudé
2023-02-06 18:52   ` Richard Henderson
2023-02-06 12:17 ` [PATCH 5/9] target/arm: Restrict CPUARMState::gicv3state " Philippe Mathieu-Daudé
2023-02-06 18:53   ` Richard Henderson
2023-02-06 12:17 ` [PATCH 6/9] target/arm: Restrict CPUARMState::nvic to sysemu and store as NVICState* Philippe Mathieu-Daudé
2023-02-06 18:57   ` Richard Henderson
2023-02-06 19:00     ` Philippe Mathieu-Daudé
2023-02-06 19:17       ` Richard Henderson
2023-02-06 12:17 ` [PATCH 7/9] target/arm: Declare CPU <-> NVIC helpers in 'hw/intc/armv7m_nvic.h' Philippe Mathieu-Daudé
2023-02-06 18:59   ` Richard Henderson
2023-02-06 12:17 ` [PATCH 8/9] hw/intc/armv7m_nvic: Allow calling neg_prio_requested on unrealized NVIC Philippe Mathieu-Daudé
2023-02-06 12:17 ` Philippe Mathieu-Daudé [this message]
2023-02-06 14:35   ` [PATCH 9/9] hw/arm/armv7m: Pass CPU/NVIC using object_property_add_const_link() 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=20230206121714.85084-10-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=peter.maydell@linaro.org \
    --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).