qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: qemu-ppc@nongnu.org
Cc: qemu-devel@nongnu.org,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Greg Kurz" <groug@kaod.org>, "Cédric Le Goater" <clg@kaod.org>
Subject: [Qemu-devel] [PATCH v4 12/28] ppc/xive: notify the CPU when the interrupt priority is more privileged
Date: Thu,  7 Jun 2018 17:49:47 +0200	[thread overview]
Message-ID: <20180607155003.1580-13-clg@kaod.org> (raw)
In-Reply-To: <20180607155003.1580-1-clg@kaod.org>

After the event was pushed in the Xive EQ, the IVPE raises the bit
corresponding to the priority of the pending interrupt in the register
IBP (Interrupt Pending Buffer) to indicate there is an event pending
in one of the 8 priority queues. The Pending Interrupt Priority
Register (PIPR) is also updated using the IPB. This register represent
the priority of the most favored pending notification.

The PIPR is then compared to the the Current Processor Priority
Register (CPPR). If it is more favored (numerically less than), the
CPU interrupt line is raised and the EO bit of the Notification Source
Register (NSR) is updated to notify the presence of an exception for
the O/S. The check needs to be done whenever the PIPR or the CPPR are
changed.

The O/S acknowledges the interrupt with a special load in the Thread
Interrupt Management Area. If the EO bit of the NSR is set, the CPPR
takes the value of PIPR. The bit number in the IBP corresponding to
the priority of the pending interrupt is reseted and so is the EO bit
of the NSR.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 hw/intc/xive.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/hw/intc/xive.c b/hw/intc/xive.c
index 6ea9441852e3..f249ffc8943e 100644
--- a/hw/intc/xive.c
+++ b/hw/intc/xive.c
@@ -21,9 +21,73 @@
  * XIVE Thread Interrupt Management context
  */
 
+/* Convert a priority number to an Interrupt Pending Buffer (IPB)
+ * register, which indicates a pending interrupt at the priority
+ * corresponding to the bit number
+ */
+static uint8_t priority_to_ipb(uint8_t priority)
+{
+    return priority > XIVE_PRIORITY_MAX ?
+        0 : 1 << (XIVE_PRIORITY_MAX - priority);
+}
+
+/* Convert an Interrupt Pending Buffer (IPB) register to a Pending
+ * Interrupt Priority Register (PIPR), which contains the priority of
+ * the most favored pending notification.
+ */
+static uint8_t ipb_to_pipr(uint8_t ibp)
+{
+    return ibp ? clz32((uint32_t)ibp << 24) : 0xff;
+}
+
+static void ipb_update(uint8_t *regs, uint8_t priority)
+{
+    regs[TM_IPB] |= priority_to_ipb(priority);
+    regs[TM_PIPR] = ipb_to_pipr(regs[TM_IPB]);
+}
+
+static uint8_t exception_mask(uint8_t ring)
+{
+    switch (ring) {
+    case TM_QW1_OS:
+        return TM_QW1_NSR_EO;
+    default:
+        g_assert_not_reached();
+    }
+}
+
 static uint64_t xive_tctx_accept(XiveTCTX *tctx, uint8_t ring)
 {
-    return 0;
+    uint8_t *regs = &tctx->regs[ring];
+    uint8_t nsr = regs[TM_NSR];
+    uint8_t mask = exception_mask(ring);
+
+    qemu_irq_lower(tctx->output);
+
+    if (regs[TM_NSR] & mask) {
+        uint8_t cppr = regs[TM_PIPR];
+
+        regs[TM_CPPR] = cppr;
+
+        /* Reset the pending buffer bit */
+        regs[TM_IPB] &= ~priority_to_ipb(cppr);
+        regs[TM_PIPR] = ipb_to_pipr(regs[TM_IPB]);
+
+        /* Drop Exception bit */
+        regs[TM_NSR] &= ~mask;
+    }
+
+    return (nsr << 8) | regs[TM_CPPR];
+}
+
+static void xive_tctx_notify(XiveTCTX *tctx, uint8_t ring)
+{
+    uint8_t *regs = &tctx->regs[ring];
+
+    if (regs[TM_PIPR] < regs[TM_CPPR]) {
+        regs[TM_NSR] |= exception_mask(ring);
+        qemu_irq_raise(tctx->output);
+    }
 }
 
 static void xive_tctx_set_cppr(XiveTCTX *tctx, uint8_t ring, uint8_t cppr)
@@ -33,6 +97,9 @@ static void xive_tctx_set_cppr(XiveTCTX *tctx, uint8_t ring, uint8_t cppr)
     }
 
     tctx->regs[ring + TM_CPPR] = cppr;
+
+    /* CPPR has changed, check if we need to raise a pending exception */
+    xive_tctx_notify(tctx, ring);
 }
 
 /*
@@ -199,6 +266,17 @@ static void xive_tm_set_os_cppr(XiveTCTX *tctx, hwaddr offset,
 }
 
 /*
+ * Adjust the IPB to allow a CPU to process event queues of other
+ * priorities during one physical interrupt cycle.
+ */
+static void xive_tm_set_os_pending(XiveTCTX *tctx, hwaddr offset,
+                                   uint64_t value, unsigned size)
+{
+    ipb_update(&tctx->regs[TM_QW1_OS], value & 0xff);
+    xive_tctx_notify(tctx, TM_QW1_OS);
+}
+
+/*
  * Define a mapping of "special" operations depending on the TIMA page
  * offset and the size of the operation.
  */
@@ -220,6 +298,7 @@ static const XiveTmOp xive_tm_operations[] = {
 
     /* MMIOs above 2K : special operations with side effects */
     { XIVE_TM_OS_PAGE, TM_SPC_ACK_OS_REG,     2, NULL, xive_tm_ack_os_reg },
+    { XIVE_TM_OS_PAGE, TM_SPC_SET_OS_PENDING, 1, xive_tm_set_os_pending, NULL },
 };
 
 static const XiveTmOp *xive_tm_find_op(hwaddr offset, unsigned size, bool write)
@@ -414,6 +493,13 @@ static void xive_tctx_reset(void *dev)
     tctx->regs[TM_QW1_OS + TM_LSMFB] = 0xFF;
     tctx->regs[TM_QW1_OS + TM_ACK_CNT] = 0xFF;
     tctx->regs[TM_QW1_OS + TM_AGE] = 0xFF;
+
+    /*
+     * Initialize PIPR to 0xFF to avoid phantom interrupts when the
+     * CPPR is first set.
+     */
+    tctx->regs[TM_QW1_OS + TM_PIPR] =
+        ipb_to_pipr(tctx->regs[TM_QW1_OS + TM_IPB]);
 }
 
 static void xive_tctx_realize(DeviceState *dev, Error **errp)
@@ -1185,9 +1271,15 @@ static void xive_presenter_notify(XiveRouter *xrtr, uint8_t format,
     found = xive_presenter_match(xrtr, format, vp_blk, vp_idx, cam_ignore,
                                  priority, logic_serv, &match);
     if (found) {
+        ipb_update(&match.tctx->regs[match.ring], priority);
+        xive_tctx_notify(match.tctx, match.ring);
         return;
     }
 
+    /* Record the IPB in the associated VP */
+    ipb_update((uint8_t *) &vp.w4, priority);
+    xive_router_set_vp(xrtr, vp_blk, vp_idx, &vp);
+
     /* If no VP dispatched on a HW thread :
      * - update the VP if backlog is activated
      * - escalate (ESe PQ bits and IVE in w4-5) if escalation is
-- 
2.13.6

  parent reply	other threads:[~2018-06-07 15:51 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-07 15:49 [Qemu-devel] [PATCH v4 00/28] ppc: support for the XIVE interrupt controller (POWER9) Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 01/28] sparp_pci: simplify how the PCI LSIs are allocated Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 02/28] spapr: introduce a generic IRQ frontend to the machine Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 03/28] spapr: introduce a new IRQ backend using fixed IRQ number ranges Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 04/28] ppc/xive: introduce a XIVE interrupt source model Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 05/28] ppc/xive: add support for the LSI interrupt sources Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 06/28] ppc/xive: introduce the XiveFabric interface Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 07/28] ppc/xive: introduce the XiveRouter model Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 08/28] ppc/xive: introduce the XIVE Event Queues Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 09/28] ppc/xive: add support for the EQ Event State buffers Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 10/28] ppc/xive: introduce the XIVE interrupt thread context Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 11/28] ppc/xive: introduce a simplified XIVE presenter Cédric Le Goater
2018-06-07 15:49 ` Cédric Le Goater [this message]
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 13/28] spapr/xive: introduce a XIVE interrupt controller Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 14/28] spapr/xive: use the VCPU id as a VP identifier in the OS CAM Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 15/28] spapr: initialize VSMT before initializing the IRQ backend Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 16/28] spapr: introdude a new machine IRQ backend for XIVE Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 17/28] spapr: add hcalls support for the XIVE exploitation interrupt mode Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 18/28] spapr: add device tree support for the XIVE exploitation mode Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 19/28] spapr: allocate the interrupt thread context under the CPU core Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 20/28] spapr: introduce a 'pseries-3.0-xive' QEMU machine Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 21/28] spapr: add classes for the XIVE models Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 22/28] target/ppc/kvm: add Linux KVM definitions for XIVE Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 23/28] spapr/xive: add common realize routine for KVM Cédric Le Goater
2018-06-07 15:49 ` [Qemu-devel] [PATCH v4 24/28] spapr/xive: add KVM support Cédric Le Goater
2018-06-07 15:50 ` [Qemu-devel] [PATCH v4 25/28] spapr: fix XICS migration Cédric Le Goater
2018-06-07 15:50 ` [Qemu-devel] [PATCH v4 26/28] pnv: add a physical mapping array describing MMIO ranges in each chip Cédric Le Goater
2018-06-07 15:50 ` [Qemu-devel] [PATCH v4 27/28] ppc: externalize ppc_get_vcpu_by_pir() Cédric Le Goater
2018-06-07 15:50 ` [Qemu-devel] [PATCH v4 28/28] ppc/pnv: add XIVE support 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=20180607155003.1580-13-clg@kaod.org \
    --to=clg@kaod.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).