All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: patches@linaro.org
Subject: [Qemu-devel] [PATCH 19/19] nvic: Support banked exceptions in acknowledge and complete
Date: Tue, 12 Sep 2017 19:14:06 +0100	[thread overview]
Message-ID: <1505240046-11454-20-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1505240046-11454-1-git-send-email-peter.maydell@linaro.org>

Update armv7m_nvic_acknowledge_irq() and armv7m_nvic_complete_irq()
to handle banked exceptions:
 * acknowledge needs to use the correct vector, which may be
   in sec_vectors[]
 * acknowledge needs to return to its caller whether the
   exception should be taken to secure or non-secure state
 * complete needs its caller to tell it whether the exception
   being completed is a secure one or not

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/arm/cpu.h      | 15 +++++++++++++--
 hw/intc/armv7m_nvic.c | 26 ++++++++++++++++++++------
 target/arm/helper.c   |  8 +++++---
 hw/intc/trace-events  |  4 ++--
 4 files changed, 40 insertions(+), 13 deletions(-)

diff --git a/target/arm/cpu.h b/target/arm/cpu.h
index 02be3ca..9c336bc 100644
--- a/target/arm/cpu.h
+++ b/target/arm/cpu.h
@@ -1476,18 +1476,29 @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque)
  * of architecturally banked exceptions.
  */
 void armv7m_nvic_set_pending(void *opaque, int irq, bool secure);
-void armv7m_nvic_acknowledge_irq(void *opaque);
+/**
+ * armv7m_nvic_acknowledge_irq: make highest priority pending exception active
+ * @opaque: the NVIC
+ *
+ * Move the current highest priority pending exception from the pending
+ * state to the active state, and update v7m.exception to indicate that
+ * it is the exception currently being handled.
+ *
+ * Returns: true if exception should be taken to Secure state, false for NS
+ */
+bool armv7m_nvic_acknowledge_irq(void *opaque);
 /**
  * armv7m_nvic_complete_irq: complete specified interrupt or exception
  * @opaque: the NVIC
  * @irq: the exception number to complete
+ * @secure: true if this exception was secure
  *
  * Returns: -1 if the irq was not active
  *           1 if completing this irq brought us back to base (no active irqs)
  *           0 if there is still an irq active after this one was completed
  * (Ignoring -1, this is the same as the RETTOBASE value before completion.)
  */
-int armv7m_nvic_complete_irq(void *opaque, int irq);
+int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure);
 /**
  * armv7m_nvic_raw_execution_priority: return the raw execution priority
  * @opaque: the NVIC
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index 9613990..078532a 100644
--- a/hw/intc/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -586,24 +586,32 @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure)
 }
 
 /* Make pending IRQ active.  */
-void armv7m_nvic_acknowledge_irq(void *opaque)
+bool armv7m_nvic_acknowledge_irq(void *opaque)
 {
     NVICState *s = (NVICState *)opaque;
     CPUARMState *env = &s->cpu->env;
     const int pending = s->vectpending;
     const int running = nvic_exec_prio(s);
     VecInfo *vec;
+    bool targets_secure;
 
     assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq);
 
-    vec = &s->vectors[pending];
+    if (s->vectpending_is_s_banked) {
+        vec = &s->sec_vectors[pending];
+        targets_secure = true;
+    } else {
+        vec = &s->vectors[pending];
+        targets_secure = !exc_is_banked(s->vectpending) &&
+            exc_targets_secure(s, s->vectpending);
+    }
 
     assert(vec->enabled);
     assert(vec->pending);
 
     assert(s->vectpending_prio < running);
 
-    trace_nvic_acknowledge_irq(pending, s->vectpending_prio);
+    trace_nvic_acknowledge_irq(pending, s->vectpending_prio, targets_secure);
 
     vec->active = 1;
     vec->pending = 0;
@@ -611,9 +619,11 @@ void armv7m_nvic_acknowledge_irq(void *opaque)
     env->v7m.exception = s->vectpending;
 
     nvic_irq_update(s);
+
+    return targets_secure;
 }
 
-int armv7m_nvic_complete_irq(void *opaque, int irq)
+int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure)
 {
     NVICState *s = (NVICState *)opaque;
     VecInfo *vec;
@@ -621,9 +631,13 @@ int armv7m_nvic_complete_irq(void *opaque, int irq)
 
     assert(irq > ARMV7M_EXCP_RESET && irq < s->num_irq);
 
-    vec = &s->vectors[irq];
+    if (secure && exc_is_banked(irq)) {
+        vec = &s->sec_vectors[irq];
+    } else {
+        vec = &s->vectors[irq];
+    }
 
-    trace_nvic_complete_irq(irq);
+    trace_nvic_complete_irq(irq, secure);
 
     if (!vec->active) {
         /* Tell the caller this was an illegal exception return */
diff --git a/target/arm/helper.c b/target/arm/helper.c
index b64acd8..8be78ea 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -6218,6 +6218,7 @@ static void do_v7m_exception_exit(ARMCPU *cpu)
     bool return_to_sp_process = false;
     bool return_to_handler = false;
     bool rettobase = false;
+    bool exc_secure = false;
 
     /* We can only get here from an EXCP_EXCEPTION_EXIT, and
      * gen_bx_excret() enforces the architectural rule
@@ -6256,16 +6257,17 @@ static void do_v7m_exception_exit(ARMCPU *cpu)
          * which security state's faultmask to clear. (v8M ARM ARM R_KBNF.)
          */
         if (arm_feature(env, ARM_FEATURE_M_SECURITY)) {
-            int es = excret & R_V7M_EXCRET_ES_MASK;
+            exc_secure = excret & R_V7M_EXCRET_ES_MASK;
             if (armv7m_nvic_raw_execution_priority(env->nvic) >= 0) {
-                env->v7m.faultmask[es] = 0;
+                env->v7m.faultmask[exc_secure] = 0;
             }
         } else {
             env->v7m.faultmask[M_REG_NS] = 0;
         }
     }
 
-    switch (armv7m_nvic_complete_irq(env->nvic, env->v7m.exception)) {
+    switch (armv7m_nvic_complete_irq(env->nvic, env->v7m.exception,
+                                     exc_secure)) {
     case -1:
         /* attempt to exit an exception that isn't active */
         ufault = true;
diff --git a/hw/intc/trace-events b/hw/intc/trace-events
index 29bd308..b86f242 100644
--- a/hw/intc/trace-events
+++ b/hw/intc/trace-events
@@ -176,8 +176,8 @@ nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled"
 nvic_set_pending(int irq, bool secure, int en, int prio) "NVIC set pending irq %d secure-bank %d (enabled: %d priority %d)"
 nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)"
 nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1"
-nvic_acknowledge_irq(int irq, int prio) "NVIC acknowledge IRQ: %d now active (prio %d)"
-nvic_complete_irq(int irq) "NVIC complete IRQ %d"
+nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)"
+nvic_complete_irq(int irq, bool secure) "NVIC complete IRQ %d (secure %d)"
 nvic_set_irq_level(int irq, int level) "NVIC external irq %d level set to %d"
 nvic_sysreg_read(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
 nvic_sysreg_write(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg write addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u"
-- 
2.7.4

  parent reply	other threads:[~2017-09-12 18:14 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-12 18:13 [Qemu-devel] [PATCH 00/19] ARMv8M: support security extn in the NVIC Peter Maydell
2017-09-12 18:13 ` [Qemu-devel] [PATCH 01/19] target/arm: Implement MSR/MRS access to NS banked registers Peter Maydell
2017-09-13 22:58   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 02/19] nvic: Add banked exception states Peter Maydell
2017-09-13 23:08   ` Richard Henderson
2017-09-19 18:31   ` [Qemu-devel] [Qemu-arm] " Peter Maydell
2017-09-12 18:13 ` [Qemu-devel] [PATCH 03/19] nvic: Add cached vectpending_is_s_banked state Peter Maydell
2017-09-12 18:13 ` [Qemu-devel] [PATCH 04/19] nvic: Add cached vectpending_prio state Peter Maydell
2017-09-13 23:25   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 05/19] nvic: Implement AIRCR changes for v8M Peter Maydell
2017-09-13 23:35   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 06/19] nvic: Make ICSR.RETTOBASE handle banked exceptions Peter Maydell
2017-09-19 18:04   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 07/19] nvic: Implement NVIC_ITNS<n> registers Peter Maydell
2017-09-19 18:19   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 08/19] nvic: Handle banked exceptions in nvic_recompute_state() Peter Maydell
2017-09-19 18:32   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 09/19] nvic: Make set_pending and clear_pending take a secure parameter Peter Maydell
2017-09-19 18:41   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 10/19] nvic: Make SHPR registers banked Peter Maydell
2017-09-19 18:47   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 11/19] nvic: Compare group priority for escalation to HF Peter Maydell
2017-09-19 18:48   ` Richard Henderson
2017-09-12 18:13 ` [Qemu-devel] [PATCH 12/19] nvic: In escalation to HardFault, support HF not being priority -1 Peter Maydell
2017-09-19 18:50   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 13/19] nvic: Implement v8M changes to fixed priority exceptions Peter Maydell
2017-09-19 18:54   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 14/19] nvic: Disable the non-secure HardFault if AIRCR.BFHFNMINS is clear Peter Maydell
2017-09-19 18:59   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 15/19] nvic: Handle v8M changes in nvic_exec_prio() Peter Maydell
2017-09-20 17:21   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 16/19] target/arm: Handle banking in negative-execution-priority check in cpu_mmu_index() Peter Maydell
2017-09-20 17:35   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 17/19] nvic: Make ICSR banked for v8M Peter Maydell
2017-09-20 17:43   ` Richard Henderson
2017-09-12 18:14 ` [Qemu-devel] [PATCH 18/19] nvic: Make SHCSR " Peter Maydell
2017-09-20 18:37   ` Richard Henderson
2017-09-12 18:14 ` Peter Maydell [this message]
2017-09-20 18:39   ` [Qemu-devel] [PATCH 19/19] nvic: Support banked exceptions in acknowledge and complete Richard Henderson
2017-09-19 18:12 ` [Qemu-devel] [PATCH 00/19] ARMv8M: support security extn in the NVIC no-reply
2017-09-19 18:29   ` Peter Maydell
2017-09-19 18:22 ` no-reply

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=1505240046-11454-20-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=patches@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 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.