From: Greg Kurz <groug@kaod.org>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, Greg Kurz <groug@kaod.org>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 1/6] spapr: Add an "spapr" property to sPAPR CPU core
Date: Wed, 9 Dec 2020 18:00:47 +0100 [thread overview]
Message-ID: <20201209170052.1431440-2-groug@kaod.org> (raw)
In-Reply-To: <20201209170052.1431440-1-groug@kaod.org>
The sPAPR CPU core device can only work with pseries machine types.
This is currently checked in the realize function with a dynamic
cast of qdev_get_machine(). Some other places also need to reach
out to the machine using qdev_get_machine().
Make this dependency explicit by introducing an "spapr" link
property which officialy points to the machine. This link is
set by pseries machine types only in the pre-plug handler. This
allows to drop some users of qdev_get_machine().
Signed-off-by: Greg Kurz <groug@kaod.org>
---
include/hw/ppc/spapr_cpu_core.h | 2 ++
hw/ppc/spapr.c | 4 ++++
hw/ppc/spapr_cpu_core.c | 17 +++++++----------
3 files changed, 13 insertions(+), 10 deletions(-)
diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
index dab3dfc76c0a..0969b29fd96c 100644
--- a/include/hw/ppc/spapr_cpu_core.h
+++ b/include/hw/ppc/spapr_cpu_core.h
@@ -10,6 +10,7 @@
#define HW_SPAPR_CPU_CORE_H
#include "hw/cpu/core.h"
+#include "hw/ppc/spapr.h"
#include "hw/qdev-core.h"
#include "target/ppc/cpu-qom.h"
#include "target/ppc/cpu.h"
@@ -24,6 +25,7 @@ OBJECT_DECLARE_TYPE(SpaprCpuCore, SpaprCpuCoreClass,
struct SpaprCpuCore {
/*< private >*/
CPUCore parent_obj;
+ SpaprMachineState *spapr;
/*< public >*/
PowerPCCPU **threads;
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index d1dcf3ab2c94..4cc51723c62e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -3816,6 +3816,10 @@ static void spapr_core_pre_plug(HotplugHandler *hotplug_dev, DeviceState *dev,
int index;
unsigned int smp_threads = machine->smp.threads;
+ /* Required by spapr_cpu_core_realize() */
+ object_property_set_link(OBJECT(dev), "spapr", OBJECT(hotplug_dev),
+ &error_abort);
+
if (dev->hotplugged && !mc->has_hotpluggable_cpus) {
error_setg(errp, "CPU hotplug not supported for this machine");
return;
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 2f7dc3c23ded..dec09367e4a0 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -25,14 +25,13 @@
#include "sysemu/hw_accel.h"
#include "qemu/error-report.h"
-static void spapr_reset_vcpu(PowerPCCPU *cpu)
+static void spapr_reset_vcpu(PowerPCCPU *cpu, SpaprMachineState *spapr)
{
CPUState *cs = CPU(cpu);
CPUPPCState *env = &cpu->env;
PowerPCCPUClass *pcc = POWERPC_CPU_GET_CLASS(cpu);
SpaprCpuState *spapr_cpu = spapr_cpu_state(cpu);
target_ulong lpcr;
- SpaprMachineState *spapr = SPAPR_MACHINE(qdev_get_machine());
cpu_reset(cs);
@@ -186,7 +185,7 @@ static void spapr_unrealize_vcpu(PowerPCCPU *cpu, SpaprCpuCore *sc)
if (!sc->pre_3_0_migration) {
vmstate_unregister(NULL, &vmstate_spapr_cpu_state, cpu->machine_data);
}
- spapr_irq_cpu_intc_destroy(SPAPR_MACHINE(qdev_get_machine()), cpu);
+ spapr_irq_cpu_intc_destroy(sc->spapr, cpu);
qdev_unrealize(DEVICE(cpu));
}
@@ -200,7 +199,7 @@ static void spapr_cpu_core_reset(DeviceState *dev)
int i;
for (i = 0; i < cc->nr_threads; i++) {
- spapr_reset_vcpu(sc->threads[i]);
+ spapr_reset_vcpu(sc->threads[i], sc->spapr);
}
}
@@ -314,16 +313,12 @@ err:
static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
{
- /* We don't use SPAPR_MACHINE() in order to exit gracefully if the user
- * tries to add a sPAPR CPU core to a non-pseries machine.
- */
- SpaprMachineState *spapr =
- (SpaprMachineState *) object_dynamic_cast(qdev_get_machine(),
- TYPE_SPAPR_MACHINE);
SpaprCpuCore *sc = SPAPR_CPU_CORE(OBJECT(dev));
+ SpaprMachineState *spapr = sc->spapr;
CPUCore *cc = CPU_CORE(OBJECT(dev));
int i;
+ /* Set in spapr_core_pre_plug() */
if (!spapr) {
error_setg(errp, TYPE_SPAPR_CPU_CORE " needs a pseries machine");
return;
@@ -345,6 +340,8 @@ static Property spapr_cpu_core_properties[] = {
DEFINE_PROP_INT32("node-id", SpaprCpuCore, node_id, CPU_UNSET_NUMA_NODE_ID),
DEFINE_PROP_BOOL("pre-3.0-migration", SpaprCpuCore, pre_3_0_migration,
false),
+ DEFINE_PROP_LINK("spapr", SpaprCpuCore, spapr, TYPE_SPAPR_MACHINE,
+ SpaprMachineState *),
DEFINE_PROP_END_OF_LIST()
};
--
2.26.2
next prev parent reply other threads:[~2020-12-09 17:21 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-09 17:00 [PATCH 0/6] spapr: Drop some users of qdev_get_machine() Greg Kurz
2020-12-09 17:00 ` Greg Kurz [this message]
2020-12-09 17:34 ` [PATCH 1/6] spapr: Add an "spapr" property to sPAPR CPU core Philippe Mathieu-Daudé
2020-12-09 17:42 ` Greg Kurz
2020-12-09 17:53 ` Philippe Mathieu-Daudé
2020-12-09 18:11 ` Philippe Mathieu-Daudé
2020-12-09 18:26 ` Eduardo Habkost
2020-12-09 20:24 ` Greg Kurz
2020-12-09 20:54 ` Eduardo Habkost
2020-12-10 8:23 ` Cédric Le Goater
2020-12-10 3:53 ` David Gibson
2020-12-10 8:54 ` Greg Kurz
2020-12-09 17:00 ` [PATCH 2/6] spapr: Add an "spapr" property to sPAPR PHB Greg Kurz
2020-12-09 17:00 ` [PATCH 3/6] spapr: Pass sPAPR machine state down to spapr_pci_switch_vga() Greg Kurz
2020-12-10 3:28 ` David Gibson
2020-12-09 17:00 ` [PATCH 4/6] spapr: Don't use qdev_get_machine() in spapr_msi_write() Greg Kurz
2020-12-10 3:30 ` David Gibson
2020-12-09 17:00 ` [PATCH 5/6] spapr: Pass sPAPR machine state to some RTAS events handling functions Greg Kurz
2020-12-10 3:31 ` David Gibson
2020-12-09 17:00 ` [PATCH 6/6] target/ppc: Add mce_req_event() handler to PPCVirtualHypervisorClass Greg Kurz
2020-12-10 3:54 ` David Gibson
2020-12-10 9:37 ` Greg Kurz
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=20201209170052.1431440-2-groug@kaod.org \
--to=groug@kaod.org \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@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).