qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 02/31] nvic: Add banked exception states
Date: Thu, 21 Sep 2017 17:41:10 +0100	[thread overview]
Message-ID: <1506012099-13605-3-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1506012099-13605-1-git-send-email-peter.maydell@linaro.org>

For the v8M security extension, some exceptions must be banked
between security states. Add the new vecinfo array which holds
the state for the banked exceptions and migrate it if the
CPU the NVIC is attached to implements the security extension.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 include/hw/intc/armv7m_nvic.h | 14 ++++++++++++
 hw/intc/armv7m_nvic.c         | 53 ++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h
index 1a4cce7..317601e 100644
--- a/include/hw/intc/armv7m_nvic.h
+++ b/include/hw/intc/armv7m_nvic.h
@@ -21,6 +21,8 @@
 
 /* Highest permitted number of exceptions (architectural limit) */
 #define NVIC_MAX_VECTORS 512
+/* Number of internal exceptions */
+#define NVIC_INTERNAL_VECTORS 16
 
 typedef struct VecInfo {
     /* Exception priorities can range from -3 to 255; only the unmodifiable
@@ -41,6 +43,18 @@ typedef struct NVICState {
     ARMCPU *cpu;
 
     VecInfo vectors[NVIC_MAX_VECTORS];
+    /* If the v8M security extension is implemented, some of the internal
+     * exceptions are banked between security states (ie there exists both
+     * a Secure and a NonSecure version of the exception and its state):
+     *  HardFault, MemManage, UsageFault, SVCall, PendSV, SysTick (R_PJHV)
+     * The rest (including all the external exceptions) are not banked, though
+     * they may be configurable to target either Secure or NonSecure state.
+     * We store the secure exception state in sec_vectors[] for the banked
+     * exceptions, and otherwise use only vectors[] (including for exceptions
+     * like SecureFault that unconditionally target Secure state).
+     * Entries in sec_vectors[] for non-banked exception numbers are unused.
+     */
+    VecInfo sec_vectors[NVIC_INTERNAL_VECTORS];
     uint32_t prigroup;
 
     /* vectpending and exception_prio are both cached state that can
diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c
index d3e2056..8793f75 100644
--- a/hw/intc/armv7m_nvic.c
+++ b/hw/intc/armv7m_nvic.c
@@ -47,7 +47,7 @@
  * For historical reasons QEMU tends to use "interrupt" and
  * "exception" more or less interchangeably.
  */
-#define NVIC_FIRST_IRQ 16
+#define NVIC_FIRST_IRQ NVIC_INTERNAL_VECTORS
 #define NVIC_MAX_IRQ (NVIC_MAX_VECTORS - NVIC_FIRST_IRQ)
 
 /* Effective running priority of the CPU when no exception is active
@@ -1158,6 +1158,43 @@ static const VMStateDescription vmstate_VecInfo = {
     }
 };
 
+static bool nvic_security_needed(void *opaque)
+{
+    NVICState *s = opaque;
+
+    return arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY);
+}
+
+static int nvic_security_post_load(void *opaque, int version_id)
+{
+    NVICState *s = opaque;
+    int i;
+
+    /* Check for out of range priority settings */
+    if (s->sec_vectors[ARMV7M_EXCP_HARD].prio != -1) {
+        return 1;
+    }
+    for (i = ARMV7M_EXCP_MEM; i < ARRAY_SIZE(s->sec_vectors); i++) {
+        if (s->sec_vectors[i].prio & ~0xff) {
+            return 1;
+        }
+    }
+    return 0;
+}
+
+static const VMStateDescription vmstate_nvic_security = {
+    .name = "nvic/m-security",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .needed = nvic_security_needed,
+    .post_load = &nvic_security_post_load,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT_ARRAY(sec_vectors, NVICState, NVIC_INTERNAL_VECTORS, 1,
+                             vmstate_VecInfo, VecInfo),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static const VMStateDescription vmstate_nvic = {
     .name = "armv7m_nvic",
     .version_id = 4,
@@ -1168,6 +1205,10 @@ static const VMStateDescription vmstate_nvic = {
                              vmstate_VecInfo, VecInfo),
         VMSTATE_UINT32(prigroup, NVICState),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (const VMStateDescription*[]) {
+        &vmstate_nvic_security,
+        NULL
     }
 };
 
@@ -1195,6 +1236,16 @@ static void armv7m_nvic_reset(DeviceState *dev)
     s->vectors[ARMV7M_EXCP_NMI].prio = -2;
     s->vectors[ARMV7M_EXCP_HARD].prio = -1;
 
+    if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) {
+        s->sec_vectors[ARMV7M_EXCP_HARD].enabled = 1;
+        s->sec_vectors[ARMV7M_EXCP_SVC].enabled = 1;
+        s->sec_vectors[ARMV7M_EXCP_PENDSV].enabled = 1;
+        s->sec_vectors[ARMV7M_EXCP_SYSTICK].enabled = 1;
+
+        /* AIRCR.BFHFNMINS resets to 0 so Secure HF is priority -1 (R_CMTC) */
+        s->sec_vectors[ARMV7M_EXCP_HARD].prio = -1;
+    }
+
     /* Strictly speaking the reset handler should be enabled.
      * However, we don't simulate soft resets through the NVIC,
      * and the reset vector should never be pended.
-- 
2.7.4

  parent reply	other threads:[~2017-09-21 16:41 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-21 16:41 [Qemu-devel] [PULL 00/31] target-arm queue Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 01/31] target/arm: Implement MSR/MRS access to NS banked registers Peter Maydell
2017-09-21 16:41 ` Peter Maydell [this message]
2017-09-21 16:41 ` [Qemu-devel] [PULL 03/31] nvic: Add cached vectpending_is_s_banked state Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 04/31] nvic: Add cached vectpending_prio state Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 05/31] nvic: Implement AIRCR changes for v8M Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 06/31] nvic: Make ICSR.RETTOBASE handle banked exceptions Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 07/31] nvic: Implement NVIC_ITNS<n> registers Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 08/31] nvic: Handle banked exceptions in nvic_recompute_state() Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 09/31] nvic: Make set_pending and clear_pending take a secure parameter Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 10/31] nvic: Make SHPR registers banked Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 11/31] nvic: Compare group priority for escalation to HF Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 12/31] nvic: In escalation to HardFault, support HF not being priority -1 Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 13/31] nvic: Implement v8M changes to fixed priority exceptions Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 14/31] nvic: Disable the non-secure HardFault if AIRCR.BFHFNMINS is clear Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 15/31] nvic: Handle v8M changes in nvic_exec_prio() Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 16/31] target/arm: Handle banking in negative-execution-priority check in cpu_mmu_index() Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 17/31] nvic: Make ICSR banked for v8M Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 18/31] nvic: Make SHCSR " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 19/31] nvic: Support banked exceptions in acknowledge and complete Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 20/31] target/arm: Remove out of date ARM ARM section references in A64 decoder Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 21/31] hw/arm/palm.c: Don't use old_mmio for static_ops Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 22/31] hw/gpio/omap_gpio.c: Don't use old_mmio Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 23/31] hw/timer/omap_synctimer.c: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 24/31] hw/timer/omap_gptimer: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 25/31] hw/i2c/omap_i2c.c: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 26/31] hw/arm/omap2.c: " Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 27/31] msf2: Add Smartfusion2 System timer Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 28/31] msf2: Microsemi Smartfusion2 System Register block Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 29/31] msf2: Add Smartfusion2 SPI controller Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 30/31] msf2: Add Smartfusion2 SoC Peter Maydell
2017-09-21 16:41 ` [Qemu-devel] [PULL 31/31] msf2: Add Emcraft's Smartfusion2 SOM kit Peter Maydell
2017-09-21 17:28 ` [Qemu-devel] [PULL 00/31] target-arm queue Peter Maydell

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=1506012099-13605-3-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.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 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).