blob: 4571409bc64e9cdc1a25c978f71e8fc61cf5aa79 [file] [log] [blame]
Andrew Geisslerfc7e7972023-09-11 08:24:07 -04001From f449f6fdcbd987e18a26f0daeccfa447fe76821a Mon Sep 17 00:00:00 2001
Brad Bishopbec4ebc2022-08-03 09:55:16 -04002From: Olivier Deprez <olivier.deprez@arm.com>
3Date: Mon, 16 Nov 2020 10:14:02 +0100
Andrew Geisslerfc7e7972023-09-11 08:24:07 -04004Subject: [PATCH] WIP: Enable managed exit
Brad Bishopbec4ebc2022-08-03 09:55:16 -04005
6This change declares OP-TEE SP as supporting managed exit in response to
7a NS interrupt triggering while the SWd runs.
8
9At init OP-TEE enables (HF_INTERRUPT_ENABLE) the managed exit virtual
10interrupt through the Hafnium para-virtualized interface.
11
12Physical interrupts are trapped to the SPMC which injects a managed exit
13interrupt to OP-TEE. The managed exit interrupt is acknowledged by
14OP-TEE by HF_INTERUPT_GET hvc call.
15
16Note: this code change is meant with in mind the SPMC runs at SEL2. It
17needs slight refactoring such that it does not break the SEL1 SPMC
18configuration.
19
20Change-Id: I9a95f36cf517c11048ff04680007f40259c4f636
21Signed-off-by: Olivier Deprez <olivier.deprez@arm.com>
22Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
23
24Upstream-Status: Pending [Not submitted to upstream yet]
25Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com>
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040026
Brad Bishopbec4ebc2022-08-03 09:55:16 -040027---
28 core/arch/arm/kernel/boot.c | 12 ++++++++++++
29 core/arch/arm/kernel/thread_a64.S | 11 ++++++++++-
30 core/arch/arm/kernel/thread_spmc.c | 11 +++++++++++
Patrick Williams8dd68482022-10-04 07:57:18 -050031 .../arm/plat-totalcompute/fdts/optee_sp_manifest.dts | 1 +
32 4 files changed, 34 insertions(+), 1 deletion(-)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040033
34diff --git a/core/arch/arm/kernel/boot.c b/core/arch/arm/kernel/boot.c
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040035index dd34173e8..7d2ac74e8 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040036--- a/core/arch/arm/kernel/boot.c
37+++ b/core/arch/arm/kernel/boot.c
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040038@@ -1424,6 +1424,18 @@ static void init_secondary_helper(unsigned long nsec_entry)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040039 init_vfp_sec();
40 init_vfp_nsec();
41
42+ /* Enable managed exit interrupt for secondary core. */
43+ __asm__ volatile (
44+ "mov x0, %0;"
45+ "mov x1, %1;"
46+ "mov x2, %2;"
47+ "mov x3, %3;"
48+ "hvc #0"
49+ : : "i" (0xff03), "i" (4), "i" (1), "i" (1));
50+
51+ IMSG("%s core %lu: enabled managed exit interrupt.",
52+ __func__, get_core_pos());
53+
54 IMSG("Secondary CPU %zu switching to normal world boot", get_core_pos());
55 }
56
57diff --git a/core/arch/arm/kernel/thread_a64.S b/core/arch/arm/kernel/thread_a64.S
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040058index 4fa97de24..4facc7631 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040059--- a/core/arch/arm/kernel/thread_a64.S
60+++ b/core/arch/arm/kernel/thread_a64.S
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040061@@ -1162,6 +1162,14 @@ END_FUNC el0_sync_abort
Brad Bishopbec4ebc2022-08-03 09:55:16 -040062 bl dcache_op_louis
63 ic iallu
64 #endif
65+
66+ /* HF_INTERRUPT_GET */
67+ mov x0, #0xff04
68+ hvc #0
69+ /* Expect managed exit interrupt */
70+ cmp x0, #4
71+ bne .
72+
73 /*
74 * Mark current thread as suspended
75 */
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040076@@ -1318,8 +1326,9 @@ LOCAL_FUNC elx_irq , :
Brad Bishopbec4ebc2022-08-03 09:55:16 -040077 #endif
78 END_FUNC elx_irq
79
80+#define HF_MANAGED_EXIT 1
81 LOCAL_FUNC elx_fiq , :
82-#if defined(CFG_ARM_GICV3)
83+#if defined(CFG_ARM_GICV3) || defined (HF_MANAGED_EXIT)
84 foreign_intr_handler fiq
85 #else
86 native_intr_handler fiq
87diff --git a/core/arch/arm/kernel/thread_spmc.c b/core/arch/arm/kernel/thread_spmc.c
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040088index 3b4ac0b4e..8f7c18dfa 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040089--- a/core/arch/arm/kernel/thread_spmc.c
90+++ b/core/arch/arm/kernel/thread_spmc.c
Andrew Geisslerfc7e7972023-09-11 08:24:07 -040091@@ -1517,6 +1517,17 @@ static TEE_Result spmc_init(void)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040092 my_endpoint_id = spmc_get_id();
93 DMSG("My endpoint ID %#x", my_endpoint_id);
94
95+ /* Enable managed exit interrupt for boot core. */
96+ __asm__ volatile (
97+ "mov x0, %0;"
98+ "mov x1, %1;"
99+ "mov x2, %2;"
100+ "mov x3, %3;"
101+ "hvc #0"
102+ : : "i" (0xff03), "i" (4), "i" (1), "i" (1));
103+
104+ IMSG("%s enabled managed exit interrupt.", __func__);
105+
106 return TEE_SUCCESS;
107 }
Patrick Williams8dd68482022-10-04 07:57:18 -0500108 #endif /* !defined(CFG_CORE_SEL1_SPMC) */
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400109diff --git a/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts b/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts
Andrew Geisslerfc7e7972023-09-11 08:24:07 -0400110index 3ebbaddc8..56e69f372 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400111--- a/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts
112+++ b/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts
Patrick Williams8dd68482022-10-04 07:57:18 -0500113@@ -24,6 +24,7 @@
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400114 xlat-granule = <0>; /* 4KiB */
115 boot-order = <0>;
Patrick Williams8dd68482022-10-04 07:57:18 -0500116 messaging-method = <0x3>; /* Direct request/response supported */
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400117+ managed-exit; /* Managed exit supported */
Patrick Williams8dd68482022-10-04 07:57:18 -0500118
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400119 device-regions {
120 compatible = "arm,ffa-manifest-device-regions";