From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Paul Burton" <paulburton@kernel.org>,
"Aurelien Jarno" <aurelien@aurel32.net>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
"Aleksandar Rikalo" <arikalo@gmail.com>,
"Huacai Chen" <chenhuacai@kernel.org>
Subject: [PATCH v2 01/19] hw/mips/cps: Keep reference of vCPUs in MIPSCPSState
Date: Mon, 13 Jan 2025 20:55:07 +0100 [thread overview]
Message-ID: <20250113195525.57150-2-philmd@linaro.org> (raw)
In-Reply-To: <20250113195525.57150-1-philmd@linaro.org>
When a QOM object create children with object_new(),
it is better to keep reference to them for further
use. In particular, this allow to remove one global
&first_cpu use.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/mips/cps.h | 1 +
hw/mips/cps.c | 4 +++-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/include/hw/mips/cps.h b/include/hw/mips/cps.h
index 05ef9f76b74..0968b57c5a0 100644
--- a/include/hw/mips/cps.h
+++ b/include/hw/mips/cps.h
@@ -40,6 +40,7 @@ struct MIPSCPSState {
char *cpu_type;
bool cpu_is_bigendian;
+ MIPSCPU **cpus;
MemoryRegion container;
MIPSGCRState gcr;
MIPSGICState gic;
diff --git a/hw/mips/cps.c b/hw/mips/cps.c
index 293b405b965..494213b2ab6 100644
--- a/hw/mips/cps.c
+++ b/hw/mips/cps.c
@@ -73,6 +73,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
return;
}
+ s->cpus = g_new(MIPSCPU *, s->num_vp);
for (int i = 0; i < s->num_vp; i++) {
MIPSCPU *cpu = MIPS_CPU(object_new(s->cpu_type));
CPUMIPSState *env = &cpu->env;
@@ -91,6 +92,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
if (!qdev_realize_and_unref(DEVICE(cpu), NULL, errp)) {
return;
}
+ s->cpus[i] = cpu;
/* Init internal devices */
cpu_mips_irq_init_cpu(cpu);
@@ -146,7 +148,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
/* Global Configuration Registers */
- gcr_base = MIPS_CPU(first_cpu)->env.CP0_CMGCRBase << 4;
+ gcr_base = s->cpus[0]->env.CP0_CMGCRBase << 4;
object_initialize_child(OBJECT(dev), "gcr", &s->gcr, TYPE_MIPS_GCR);
object_property_set_uint(OBJECT(&s->gcr), "num-vp", s->num_vp,
--
2.47.1
next prev parent reply other threads:[~2025-01-13 19:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 19:55 [PATCH v2 00/19] hw/mips: Remove all uses of &first_cpu Philippe Mathieu-Daudé
2025-01-13 19:55 ` Philippe Mathieu-Daudé [this message]
2025-01-13 19:55 ` [PATCH v2 02/19] hw/mips/malta: Check CPU index instead of using &first_cpu Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 03/19] hw/mips/malta: Keep reference of vCPUs in MaltaState Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 04/19] hw/mips/malta: Propagate MaltaState to write_bootloader() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 05/19] hw/mips/malta: Propagate MaltaState to bl_setup_gt64120_jump_kernel() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 06/19] hw/mips/boston: Replace bl_gen_write_ulong() -> bl_gen_write_u64() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 07/19] hw/mips/boston: Propagate CPU to gen_firmware() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 08/19] hw/mips/fuloong: Propagate CPU to write_bootloader() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 09/19] hw/mips/bootloader: Document public API Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 10/19] hw/mips/bootloader: Propagate CPU to bl_gen_write_u[32, 64, long]() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 11/19] hw/mips/bootloader: Propagate CPU to bl_gen_jump_[to, kernel]() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 12/19] hw/mips/bootloader: Propagate CPU env to bl_gen_load_ulong() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 13/19] hw/mips/bootloader: Propagate CPU env to bl_gen_[d]li() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 14/19] hw/mips/bootloader: Propagate CPU env to bl_gen_s[w, d]() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 15/19] hw/mips/bootloader: Propagate CPU env to bl_gen_jalr() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 16/19] hw/mips/bootloader: Propagate CPU env to bl_gen_dsll() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 17/19] hw/mips/bootloader: Propagate CPU env to bl_gen_nop() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 18/19] hw/mips/bootloader: Propagate CPU env to bootcpu_supports_isa() Philippe Mathieu-Daudé
2025-01-13 19:55 ` [PATCH v2 19/19] hw/mips/bootloader: Remove use of &first_cpu in bootcpu_supports_isa() Philippe Mathieu-Daudé
2025-01-13 23:40 ` [PATCH v2 00/19] hw/mips: Remove all uses of &first_cpu Jiaxun Yang
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=20250113195525.57150-2-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=arikalo@gmail.com \
--cc=aurelien@aurel32.net \
--cc=chenhuacai@kernel.org \
--cc=jiaxun.yang@flygoat.com \
--cc=paulburton@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.