summaryrefslogtreecommitdiff
path: root/spm/cactus
diff options
context:
space:
mode:
authorOlivier Deprez <olivier.deprez@arm.com>2021-04-21 07:20:06 +0200
committerTrustedFirmware Code Review <review@review.trustedfirmware.org>2021-04-21 07:20:06 +0200
commit476ffb30f7e99b030bc4d257a41cb54cb6713087 (patch)
tree73c27f50d2137dd826461428df98e4da5682c6ff /spm/cactus
parent8b96e4cc79dd90712da07fe68c8821dd16acdf06 (diff)
parent25df7f7f7f4e04ea974010a6d0cff56c630edb4d (diff)
Merge changes from topic "od/ns-interrupts"
* changes: Cactus: enable managed exit for primary cactus SPM: test handling of non-secure interrupt while running SP Cactus: helper commands needed for interrupt testing Cactus: add handler from managed exit FIQ interrupt Cactus: make ffa_id global Cactus: implement hvc call to enable an interrupt Cactus: decouple exception handling from tftf framework spmc: hypervisor calls moved to a separate module
Diffstat (limited to 'spm/cactus')
-rw-r--r--spm/cactus/aarch64/cactus_entrypoint.S4
-rw-r--r--spm/cactus/aarch64/cactus_exceptions.S131
-rw-r--r--spm/cactus/cactus.mk5
-rw-r--r--spm/cactus/cactus_debug.c2
-rw-r--r--spm/cactus/cactus_interrupt.c51
-rw-r--r--spm/cactus/cactus_main.c17
-rw-r--r--spm/cactus/cactus_tests/cactus_test_ffa.c1
-rw-r--r--spm/cactus/cactus_tests/cactus_test_interrupts.c51
-rw-r--r--spm/cactus/plat/arm/fvp/fdts/cactus.dts4
9 files changed, 258 insertions, 8 deletions
diff --git a/spm/cactus/aarch64/cactus_entrypoint.S b/spm/cactus/aarch64/cactus_entrypoint.S
index 7775b46..1541063 100644
--- a/spm/cactus/aarch64/cactus_entrypoint.S
+++ b/spm/cactus/aarch64/cactus_entrypoint.S
@@ -59,8 +59,8 @@ secondary_cold_entry:
isb
/* Set up exceptions vector table */
- adrp x1, tftf_vector
- add x1, x1, :lo12:tftf_vector
+ adrp x1, cactus_vector
+ add x1, x1, :lo12:cactus_vector
msr vbar_el1, x1
isb
diff --git a/spm/cactus/aarch64/cactus_exceptions.S b/spm/cactus/aarch64/cactus_exceptions.S
new file mode 100644
index 0000000..31cdbf9
--- /dev/null
+++ b/spm/cactus/aarch64/cactus_exceptions.S
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <asm_macros.S>
+
+ .globl cactus_vector
+
+/*
+ * Exception vector code for unhandled exceptions.
+ * Print a crash dump on the UART and loops forever.
+ */
+.macro unhandled_exception name
+ vector_entry \name
+ b crash_dump
+ end_vector_entry \name
+.endm
+
+vector_base cactus_vector
+
+ /*
+ * Current EL with SP0 : 0x0 - 0x200.
+ */
+unhandled_exception sync_sp0
+unhandled_exception irq_sp0
+unhandled_exception fiq_sp0
+unhandled_exception serr_sp0
+
+ /*
+ * Current EL with SPx : 0x200 - 0x400.
+ */
+unhandled_exception sync_spx
+
+vector_entry irq_spx
+ b irq_vector_entry
+end_vector_entry irq_spx
+
+vector_entry fiq_spx
+ b fiq_vector_entry
+end_vector_entry fiq_spx
+
+unhandled_exception serr_spx
+
+ /*
+ * Lower EL using AArch64 : 0x400 - 0x600.
+ */
+unhandled_exception sync_a64
+unhandled_exception irq_a64
+unhandled_exception fiq_a64
+unhandled_exception serr_a64
+
+ /*
+ * Lower EL using AArch32 : 0x600 - 0x800.
+ */
+unhandled_exception sync_a32
+unhandled_exception irq_a32
+unhandled_exception fiq_a32
+unhandled_exception serr_a32
+
+.macro save_gp_regs
+ stp x0, x1, [sp, #0x0]
+ stp x2, x3, [sp, #0x10]
+ stp x4, x5, [sp, #0x20]
+ stp x6, x7, [sp, #0x30]
+ stp x8, x9, [sp, #0x40]
+ stp x10, x11, [sp, #0x50]
+ stp x12, x13, [sp, #0x60]
+ stp x14, x15, [sp, #0x70]
+ stp x16, x17, [sp, #0x80]
+ stp x18, x19, [sp, #0x90]
+ stp x20, x21, [sp, #0xa0]
+ stp x22, x23, [sp, #0xb0]
+ stp x24, x25, [sp, #0xc0]
+ stp x26, x27, [sp, #0xd0]
+ stp x28, x29, [sp, #0xe0]
+ /* We push xzr simply to keep the stack 16-byte aligned. */
+ stp x30, xzr, [sp, #0xf0]
+.endm
+
+.macro restore_gp_regs
+ ldp x30, xzr, [sp, #0xf0]
+ ldp x28, x29, [sp, #0xe0]
+ ldp x26, x27, [sp, #0xd0]
+ ldp x24, x25, [sp, #0xc0]
+ ldp x22, x23, [sp, #0xb0]
+ ldp x20, x21, [sp, #0xa0]
+ ldp x18, x19, [sp, #0x90]
+ ldp x16, x17, [sp, #0x80]
+ ldp x14, x15, [sp, #0x70]
+ ldp x12, x13, [sp, #0x60]
+ ldp x10, x11, [sp, #0x50]
+ ldp x8, x9, [sp, #0x40]
+ ldp x6, x7, [sp, #0x30]
+ ldp x4, x5, [sp, #0x20]
+ ldp x2, x3, [sp, #0x10]
+ ldp x0, x1, [sp, #0x0]
+.endm
+
+func irq_vector_entry
+ sub sp, sp, #0x100
+ save_gp_regs
+ bl cactus_irq_handler
+ restore_gp_regs
+ add sp, sp, #0x100
+ eret
+endfunc irq_vector_entry
+
+func fiq_vector_entry
+ sub sp, sp, #0x100
+ save_gp_regs
+ bl cactus_fiq_handler
+ restore_gp_regs
+ add sp, sp, #0x100
+ eret
+endfunc fiq_vector_entry
+
+func crash_dump
+ /* Save general-purpose registers on the stack. */
+ sub sp, sp, #0x100
+ save_gp_regs
+
+ /* Save original stack pointer value on the stack. */
+ add x1, sp, #0x100
+ str x1, [sp, #0xf8]
+
+ /* Print the saved CPU context on the UART. */
+ mov x0, sp
+ b print_exception
+endfunc crash_dump
diff --git a/spm/cactus/cactus.mk b/spm/cactus/cactus.mk
index 08b824c..a52120f 100644
--- a/spm/cactus/cactus.mk
+++ b/spm/cactus/cactus.mk
@@ -32,18 +32,22 @@ CACTUS_INCLUDES := \
CACTUS_SOURCES := \
$(addprefix spm/cactus/, \
aarch64/cactus_entrypoint.S \
+ aarch64/cactus_exceptions.S \
cactus_debug.c \
+ cactus_interrupt.c \
cactus_main.c \
) \
$(addprefix spm/common/, \
aarch64/sp_arch_helpers.S \
sp_helpers.c \
+ spm_helpers.c \
) \
$(addprefix spm/cactus/cactus_tests/, \
cactus_message_loop.c \
cactus_test_cpu_features.c \
cactus_test_direct_messaging.c \
cactus_test_ffa.c \
+ cactus_test_interrupts.c \
cactus_test_memory_sharing.c \
)
@@ -53,7 +57,6 @@ CACTUS_SOURCES += \
tftf/framework/${ARCH}/asm_debug.S \
tftf/tests/runtime_services/secure_service/ffa_helpers.c \
tftf/tests/runtime_services/secure_service/spm_common.c \
- tftf/framework/${ARCH}/exceptions.S \
tftf/framework/${ARCH}/exception_report.c
CACTUS_SOURCES += drivers/arm/pl011/${ARCH}/pl011_console.S \
diff --git a/spm/cactus/cactus_debug.c b/spm/cactus/cactus_debug.c
index 43093a6..30a2527 100644
--- a/spm/cactus/cactus_debug.c
+++ b/spm/cactus/cactus_debug.c
@@ -6,7 +6,7 @@
#include <drivers/arm/pl011.h>
#include <drivers/console.h>
-#include <sp_helpers.h>
+#include <spm_helpers.h>
#include "cactus.h"
diff --git a/spm/cactus/cactus_interrupt.c b/spm/cactus/cactus_interrupt.c
new file mode 100644
index 0000000..7de36cf
--- /dev/null
+++ b/spm/cactus/cactus_interrupt.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <debug.h>
+
+#include <ffa_helpers.h>
+#include <sp_helpers.h>
+#include <spm_helpers.h>
+
+#include "cactus_test_cmds.h"
+#include "spm_common.h"
+
+extern ffa_vm_id_t g_ffa_id;
+
+static void managed_exit_handler(void)
+{
+ /*
+ * Real SP will save its context here.
+ * Send interrupt ID for acknowledgement
+ */
+ cactus_response(g_ffa_id, HYP_ID, MANAGED_EXIT_INTERRUPT_ID);
+}
+
+int cactus_irq_handler(void)
+{
+ uint32_t irq_num;
+
+ irq_num = spm_interrupt_get();
+
+ ERROR("%s: Interrupt ID %u not handled!\n", __func__, irq_num);
+
+ return 0;
+}
+
+int cactus_fiq_handler(void)
+{
+ uint32_t fiq_num;
+
+ fiq_num = spm_interrupt_get();
+
+ if (fiq_num == MANAGED_EXIT_INTERRUPT_ID) {
+ managed_exit_handler();
+ } else {
+ ERROR("%s: Interrupt ID %u not handled!\n", __func__, fiq_num);
+ }
+
+ return 0;
+}
diff --git a/spm/cactus/cactus_main.c b/spm/cactus/cactus_main.c
index e54f3b0..45d2db0 100644
--- a/spm/cactus/cactus_main.c
+++ b/spm/cactus/cactus_main.c
@@ -20,6 +20,7 @@
#include <plat/common/platform.h>
#include <platform_def.h>
#include <sp_helpers.h>
+#include <spm_helpers.h>
#include <std_svc.h>
#include "cactus_def.h"
@@ -32,6 +33,9 @@ extern const char version_string[];
extern void secondary_cold_entry(void);
+/* Global ffa_id */
+ffa_vm_id_t g_ffa_id;
+
/*
*
* Message loop function
@@ -175,18 +179,17 @@ void __dead2 cactus_main(bool primary_cold_boot)
/* Get current FFA id */
smc_ret_values ffa_id_ret = ffa_id_get();
+ ffa_vm_id_t ffa_id = (ffa_vm_id_t)(ffa_id_ret.ret2 & 0xffff);
if (ffa_func_id(ffa_id_ret) != FFA_SUCCESS_SMC32) {
ERROR("FFA_ID_GET failed.\n");
panic();
}
- ffa_vm_id_t ffa_id = ffa_id_ret.ret2 & 0xffff;
if (primary_cold_boot == true) {
/* Clear BSS */
memset((void *)CACTUS_BSS_START,
0, CACTUS_BSS_END - CACTUS_BSS_START);
-
mb.send = (void *) get_sp_tx_start(ffa_id);
mb.recv = (void *) get_sp_rx_start(ffa_id);
@@ -194,8 +197,18 @@ void __dead2 cactus_main(bool primary_cold_boot)
cactus_plat_configure_mmu(ffa_id);
}
+ /*
+ * The local ffa_id value is held on the stack. The global g_ffa_id
+ * value is set after BSS is cleared.
+ */
+ g_ffa_id = ffa_id;
+
enable_mmu_el1(0);
+ /* Enable IRQ/FIQ */
+ enable_irq();
+ enable_fiq();
+
if (primary_cold_boot == false) {
goto msg_loop;
}
diff --git a/spm/cactus/cactus_tests/cactus_test_ffa.c b/spm/cactus/cactus_tests/cactus_test_ffa.c
index c1ba783..2ade7bd 100644
--- a/spm/cactus/cactus_tests/cactus_test_ffa.c
+++ b/spm/cactus/cactus_tests/cactus_test_ffa.c
@@ -11,6 +11,7 @@
#include <cactus_platform_def.h>
#include <ffa_endpoints.h>
#include <sp_helpers.h>
+#include <spm_helpers.h>
#include <spm_common.h>
#include <lib/libc/string.h>
diff --git a/spm/cactus/cactus_tests/cactus_test_interrupts.c b/spm/cactus/cactus_tests/cactus_test_interrupts.c
new file mode 100644
index 0000000..b675dfc
--- /dev/null
+++ b/spm/cactus/cactus_tests/cactus_test_interrupts.c
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2021, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <common/debug.h>
+#include <sp_helpers.h>
+#include <spm_helpers.h>
+
+#include "cactus_message_loop.h"
+#include "cactus_test_cmds.h"
+
+CACTUS_CMD_HANDLER(sleep_cmd, CACTUS_SLEEP_CMD)
+{
+ uint64_t timer_freq = read_cntfrq_el0();
+ uint64_t time1, time2, time_lapsed;
+ uint32_t sleep_time = cactus_get_sleep_time(*args);
+
+ VERBOSE("Request to sleep %x for %ums.\n", ffa_dir_msg_dest(*args), sleep_time);
+
+ time1 = read_cntvct_el0();
+ sp_sleep(sleep_time);
+ time2 = read_cntvct_el0();
+
+ /* Lapsed time should be at least equal to sleep time */
+ time_lapsed = ((time2 - time1) * 1000) / timer_freq;
+
+ return cactus_response(ffa_dir_msg_dest(*args),
+ ffa_dir_msg_source(*args),
+ time_lapsed);
+}
+
+CACTUS_CMD_HANDLER(interrupt_cmd, CACTUS_INTERRUPT_CMD)
+{
+ uint32_t int_id = cactus_get_interrupt_id(*args);
+ bool enable = cactus_get_interrupt_enable(*args);
+ enum interrupt_pin pin = cactus_get_interrupt_pin(*args);
+ int64_t ret;
+
+ ret = spm_interrupt_enable(int_id, enable, pin);
+ if (ret != 0) {
+ return cactus_error_resp(ffa_dir_msg_dest(*args),
+ ffa_dir_msg_source(*args),
+ CACTUS_ERROR_TEST);
+ }
+
+ return cactus_response(ffa_dir_msg_dest(*args),
+ ffa_dir_msg_source(*args),
+ CACTUS_SUCCESS);
+}
diff --git a/spm/cactus/plat/arm/fvp/fdts/cactus.dts b/spm/cactus/plat/arm/fvp/fdts/cactus.dts
index 4529273..eb569f7 100644
--- a/spm/cactus/plat/arm/fvp/fdts/cactus.dts
+++ b/spm/cactus/plat/arm/fvp/fdts/cactus.dts
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -27,7 +27,7 @@
entrypoint-offset = <0x00001000>;
xlat-granule = <0>; /* 4KiB */
boot-order = <0>;
- messaging-method = <0>; /* Direct messaging only */
+ messaging-method = <3>; /* Direct messaging with managed exit */
run-time-model = <0>; /* Run to completion */
/* Boot protocol */