qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: qemu-ppc@nongnu.org, qemu-devel@nongnu.org,
	David Gibson <david@gibson.dropbear.id.au>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Greg Kurz <groug@kaod.org>
Cc: "Cédric Le Goater" <clg@kaod.org>
Subject: [Qemu-devel] [PATCH v2 17/19] spapr: toggle the ICP depending on the selected interrupt mode
Date: Sat,  9 Dec 2017 09:43:36 +0100	[thread overview]
Message-ID: <20171209084338.29395-18-clg@kaod.org> (raw)
In-Reply-To: <20171209084338.29395-1-clg@kaod.org>

Each interrupt mode has its own specific interrupt presenter object,
that we store under the CPU object, one for XICS and one for XIVE. The
active presenter, corresponding to the current interrupt mode, is
simply selected with a lookup on the children of the CPU.

Migration and CPU hotplug also need to reflect the current interrupt
mode in use.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---

 Changes since v1:
 
 - conditioned the creation of the sPAPRXiveNVT object to the
   xive_exploitation bool which false on older pseries machine.
 - moved the setting of the ICP under the machine reset handler.
 - introduced a spapr_xive_nvt_create() helper
 - handled errors in spapr_post_load() to return EINVAL

 hw/intc/spapr_xive.c            | 19 +++++++++++++++++++
 hw/ppc/spapr.c                  | 29 +++++++++++++++++++++++++++++
 hw/ppc/spapr_cpu_core.c         | 34 ++++++++++++++++++++++++++++++++++
 include/hw/ppc/spapr_cpu_core.h |  1 +
 include/hw/ppc/spapr_xive.h     |  1 +
 5 files changed, 84 insertions(+)

diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c
index e650ed69eb70..8e6997bb1deb 100644
--- a/hw/intc/spapr_xive.c
+++ b/hw/intc/spapr_xive.c
@@ -992,3 +992,22 @@ qemu_irq spapr_xive_qirq(sPAPRXive *xive, int lisn)
 
     return xive->qirqs[lisn];
 }
+
+Object *spapr_xive_nvt_create(Object *cpu, const char *type, Error **errp)
+{
+    Error *local_err = NULL;
+    Object *obj;
+
+    obj = object_new(type);
+    object_property_add_child(cpu, type, obj, &error_abort);
+    object_unref(obj);
+    object_property_add_const_link(obj, ICP_PROP_CPU, cpu, &error_abort);
+    object_property_set_bool(obj, true, "realized", &local_err);
+    if (local_err) {
+        object_unparent(obj);
+        error_propagate(errp, local_err);
+        obj = NULL;
+    }
+
+    return obj;
+}
diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c
index 65fca10e5b30..4d7a3d64e51e 100644
--- a/hw/ppc/spapr.c
+++ b/hw/ppc/spapr.c
@@ -1539,7 +1539,10 @@ static void ppc_spapr_reset(void)
 
     /* Setup XIVE resources if required by CAS */
     if (spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
+        spapr_cpu_core_set_icp(TYPE_SPAPR_XIVE_NVT, &error_fatal);
         spapr_xive_mmio_map(spapr->xive);
+    } else {
+        spapr_cpu_core_set_icp(spapr->icp_type, &error_fatal);
     }
 
     fdt = spapr_build_fdt(spapr, rtas_addr, spapr->rtas_size);
@@ -1651,7 +1654,13 @@ static int spapr_post_load(void *opaque, int version_id)
 
     /* Restore XIVE resources if required by CAS */
     if (spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
+        Error *local_err = NULL;
+
         spapr_xive_mmio_map(spapr->xive);
+        spapr_cpu_core_set_icp(TYPE_SPAPR_XIVE_NVT, &local_err);
+        if (local_err) {
+            return -EINVAL;
+        }
     }
 
     return err;
@@ -3832,6 +3841,26 @@ Object *spapr_icp_create(sPAPRMachineState *spapr, Object *cpu, Error **errp)
         return NULL;
     }
 
+    if (spapr->xive_exploitation) {
+        Object *obj_xive;
+
+        /* Add a XIVE interrupt presenter. The machine will switch
+         * the CPU ICP depending on the interrupt model negotiated
+         * at CAS time.
+         */
+        obj_xive = spapr_xive_nvt_create(cpu, TYPE_SPAPR_XIVE_NVT, &local_err);
+        if (local_err) {
+            object_unparent(obj);
+            error_propagate(errp, local_err);
+            return NULL;
+        }
+
+        /* when hotplugged, the CPU should have the correct ICP */
+        if (spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)) {
+            return obj_xive;
+        }
+    }
+
     return obj;
 }
 
diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 1bfe3ff55058..e5c39cdec998 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -253,3 +253,37 @@ static const TypeInfo spapr_cpu_core_type_infos[] = {
 };
 
 DEFINE_TYPES(spapr_cpu_core_type_infos)
+
+typedef struct ForeachFindICPArgs {
+    const char *icp_type;
+    Object *icp;
+} ForeachFindICPArgs;
+
+static int spapr_cpu_core_find_icp(Object *child, void *opaque)
+{
+    ForeachFindICPArgs *args = opaque;
+
+    if (object_dynamic_cast(child, args->icp_type)) {
+        args->icp = child;
+    }
+
+    return args->icp != NULL;
+}
+
+void spapr_cpu_core_set_icp(const char *icp_type, Error **errp)
+{
+    CPUState *cs;
+
+    CPU_FOREACH(cs) {
+        ForeachFindICPArgs args = { icp_type, NULL };
+        PowerPCCPU *cpu = POWERPC_CPU(cs);
+
+        object_child_foreach(OBJECT(cs), spapr_cpu_core_find_icp, &args);
+        if (!args.icp) {
+            error_setg(errp, "Couldn't find a '%s' icp", icp_type);
+            return;
+        }
+
+        cpu->intc = args.icp;
+    }
+}
diff --git a/include/hw/ppc/spapr_cpu_core.h b/include/hw/ppc/spapr_cpu_core.h
index 1129f344aa0c..916aea6137a6 100644
--- a/include/hw/ppc/spapr_cpu_core.h
+++ b/include/hw/ppc/spapr_cpu_core.h
@@ -38,4 +38,5 @@ typedef struct sPAPRCPUCoreClass {
 } sPAPRCPUCoreClass;
 
 const char *spapr_get_cpu_core_type(const char *cpu_type);
+void spapr_cpu_core_set_icp(const char *icp_type, Error **errp);
 #endif
diff --git a/include/hw/ppc/spapr_xive.h b/include/hw/ppc/spapr_xive.h
index 8eefb09999de..22eb6e8a4d01 100644
--- a/include/hw/ppc/spapr_xive.h
+++ b/include/hw/ppc/spapr_xive.h
@@ -59,6 +59,7 @@ bool spapr_xive_irq_enable(sPAPRXive *xive, uint32_t lisn, bool lsi);
 bool spapr_xive_irq_disable(sPAPRXive *xive, uint32_t lisn);
 void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon);
 void spapr_xive_nvt_pic_print_info(sPAPRXiveNVT *nvt, Monitor *mon);
+Object *spapr_xive_nvt_create(Object *cpu, const char *type, Error **errp);
 void spapr_xive_mmio_map(sPAPRXive *xive);
 qemu_irq spapr_xive_qirq(sPAPRXive *xive, int lisn);
 
-- 
2.13.6

  parent reply	other threads:[~2017-12-09  8:45 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-09  8:43 [Qemu-devel] [PATCH v2 00/19] spapr: Guest exploitation of the XIVE interrupt controller (POWER9) Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 01/19] dma-helpers: add a return value to store helpers Cédric Le Goater
2017-12-19  4:46   ` David Gibson
2017-12-19  6:43     ` Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller Cédric Le Goater
2017-12-09 14:06   ` Cédric Le Goater
2017-12-20  5:09   ` David Gibson
2017-12-20  7:38     ` Cédric Le Goater
2018-04-12  5:07       ` David Gibson
2018-04-12  8:18         ` Cédric Le Goater
2018-04-16  4:26           ` David Gibson
2018-04-19 17:40             ` Cédric Le Goater
2018-04-26  5:36               ` David Gibson
2018-04-26  8:17                 ` Cédric Le Goater
2018-05-03  2:29                   ` David Gibson
2018-05-03  8:43                     ` Cédric Le Goater
2018-05-04  6:35                       ` David Gibson
2018-05-04 15:35                         ` Cédric Le Goater
2017-12-21  0:12     ` Benjamin Herrenschmidt
2017-12-21  9:16       ` Cédric Le Goater
2017-12-21 10:09         ` Cédric Le Goater
2017-12-21 22:53         ` Benjamin Herrenschmidt
2018-01-17  9:18           ` Cédric Le Goater
2018-01-17 11:10             ` Benjamin Herrenschmidt
2018-01-17 14:39               ` Cédric Le Goater
2018-01-17 17:57                 ` Cédric Le Goater
2018-01-17 21:27                 ` Benjamin Herrenschmidt
2018-01-18 13:27                   ` Cédric Le Goater
2018-01-18 21:08                     ` Benjamin Herrenschmidt
2018-02-11  8:08                   ` David Gibson
2018-02-11 22:55                     ` Benjamin Herrenschmidt
2018-02-12  2:02                       ` Alexey Kardashevskiy
2018-02-12 12:20                         ` [Qemu-devel] [Qemu-ppc] " Andrea Bolognani
2018-02-12 14:40                           ` Benjamin Herrenschmidt
2018-02-13  1:11                             ` Alexey Kardashevskiy
2018-02-13  7:40                             ` Cédric Le Goater
2018-02-12  7:10                       ` [Qemu-devel] " Cédric Le Goater
2018-04-12  5:16                       ` David Gibson
2018-04-12  8:36                         ` Cédric Le Goater
2018-04-16  4:29                           ` David Gibson
2018-04-19 13:01                             ` Cédric Le Goater
2018-04-12  5:15                 ` David Gibson
2018-04-12  8:51                   ` Cédric Le Goater
2018-04-12  5:10             ` David Gibson
2018-04-12  8:41               ` Cédric Le Goater
2018-04-12  5:08       ` David Gibson
2018-04-12  8:28         ` Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources Cédric Le Goater
2017-12-14 15:24   ` Cédric Le Goater
2017-12-18  0:59     ` Benjamin Herrenschmidt
2017-12-19  6:37       ` Cédric Le Goater
2017-12-20  5:13         ` David Gibson
2017-12-20  5:22   ` David Gibson
2017-12-20  7:54     ` Cédric Le Goater
2017-12-20 18:08       ` Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 04/19] spapr: add support for the LSI " Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 05/19] spapr: introduce a XIVE interrupt presenter model Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 06/19] spapr: introduce the XIVE Event Queues Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 07/19] spapr: push the XIVE EQ data in OS event queue Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 08/19] spapr: notify the CPU when the XIVE interrupt priority is more privileged Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 09/19] spapr: add support for the SET_OS_PENDING command (XIVE) Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 10/19] spapr: introduce a 'xive_exploitation' boolean to enable XIVE Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 11/19] spapr: add a sPAPRXive object to the machine Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 12/19] spapr: add hcalls support for the XIVE exploitation interrupt mode Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 13/19] spapr: add device tree support for the XIVE " Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 14/19] spapr: introduce a helper to map the XIVE memory regions Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 15/19] spapr: add XIVE support to spapr_qirq() Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 16/19] spapr: introduce a spapr_icp_create() helper Cédric Le Goater
2017-12-09  8:43 ` Cédric Le Goater [this message]
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 18/19] spapr: add support to dump XIVE information Cédric Le Goater
2017-12-09  8:43 ` [Qemu-devel] [PATCH v2 19/19] spapr: advertise XIVE exploitation mode in CAS 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=20171209084338.29395-18-clg@kaod.org \
    --to=clg@kaod.org \
    --cc=benh@kernel.crashing.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=groug@kaod.org \
    --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).