blob: 0f0a76e4f1533a93eb13ea3c542c2b00c5974b43 [file] [log] [blame]
Patrick Williams8dd68482022-10-04 07:57:18 -05001From 34db1357ab3192f18629ceadf4ea33b948513fec 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
Patrick Williams8dd68482022-10-04 07:57:18 -05004Subject: [PATCH 1/2] 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>
26---
27 core/arch/arm/kernel/boot.c | 12 ++++++++++++
28 core/arch/arm/kernel/thread_a64.S | 11 ++++++++++-
29 core/arch/arm/kernel/thread_spmc.c | 11 +++++++++++
Patrick Williams8dd68482022-10-04 07:57:18 -050030 .../arm/plat-totalcompute/fdts/optee_sp_manifest.dts | 1 +
31 4 files changed, 34 insertions(+), 1 deletion(-)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040032
33diff --git a/core/arch/arm/kernel/boot.c b/core/arch/arm/kernel/boot.c
Patrick Williams8dd68482022-10-04 07:57:18 -050034index f173384d..466c042e 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040035--- a/core/arch/arm/kernel/boot.c
36+++ b/core/arch/arm/kernel/boot.c
Patrick Williams8dd68482022-10-04 07:57:18 -050037@@ -1350,6 +1350,18 @@ static void init_secondary_helper(unsigned long nsec_entry)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040038 init_vfp_sec();
39 init_vfp_nsec();
40
41+ /* Enable managed exit interrupt for secondary core. */
42+ __asm__ volatile (
43+ "mov x0, %0;"
44+ "mov x1, %1;"
45+ "mov x2, %2;"
46+ "mov x3, %3;"
47+ "hvc #0"
48+ : : "i" (0xff03), "i" (4), "i" (1), "i" (1));
49+
50+ IMSG("%s core %lu: enabled managed exit interrupt.",
51+ __func__, get_core_pos());
52+
53 IMSG("Secondary CPU %zu switching to normal world boot", get_core_pos());
54 }
55
56diff --git a/core/arch/arm/kernel/thread_a64.S b/core/arch/arm/kernel/thread_a64.S
Patrick Williams8dd68482022-10-04 07:57:18 -050057index d6baee4d..1b0c8f37 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040058--- a/core/arch/arm/kernel/thread_a64.S
59+++ b/core/arch/arm/kernel/thread_a64.S
Patrick Williams8dd68482022-10-04 07:57:18 -050060@@ -1087,6 +1087,14 @@ END_FUNC el0_sync_abort
Brad Bishopbec4ebc2022-08-03 09:55:16 -040061 bl dcache_op_louis
62 ic iallu
63 #endif
64+
65+ /* HF_INTERRUPT_GET */
66+ mov x0, #0xff04
67+ hvc #0
68+ /* Expect managed exit interrupt */
69+ cmp x0, #4
70+ bne .
71+
72 /*
73 * Mark current thread as suspended
74 */
Patrick Williams8dd68482022-10-04 07:57:18 -050075@@ -1204,8 +1212,9 @@ LOCAL_FUNC elx_irq , :
Brad Bishopbec4ebc2022-08-03 09:55:16 -040076 #endif
77 END_FUNC elx_irq
78
79+#define HF_MANAGED_EXIT 1
80 LOCAL_FUNC elx_fiq , :
81-#if defined(CFG_ARM_GICV3)
82+#if defined(CFG_ARM_GICV3) || defined (HF_MANAGED_EXIT)
83 foreign_intr_handler fiq
84 #else
85 native_intr_handler fiq
86diff --git a/core/arch/arm/kernel/thread_spmc.c b/core/arch/arm/kernel/thread_spmc.c
Patrick Williams8dd68482022-10-04 07:57:18 -050087index ea9e8f03..15577e7e 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -040088--- a/core/arch/arm/kernel/thread_spmc.c
89+++ b/core/arch/arm/kernel/thread_spmc.c
Patrick Williams8dd68482022-10-04 07:57:18 -050090@@ -1518,6 +1518,17 @@ static TEE_Result spmc_init(void)
Brad Bishopbec4ebc2022-08-03 09:55:16 -040091 my_endpoint_id = spmc_get_id();
92 DMSG("My endpoint ID %#x", my_endpoint_id);
93
94+ /* Enable managed exit interrupt for boot core. */
95+ __asm__ volatile (
96+ "mov x0, %0;"
97+ "mov x1, %1;"
98+ "mov x2, %2;"
99+ "mov x3, %3;"
100+ "hvc #0"
101+ : : "i" (0xff03), "i" (4), "i" (1), "i" (1));
102+
103+ IMSG("%s enabled managed exit interrupt.", __func__);
104+
105 return TEE_SUCCESS;
106 }
Patrick Williams8dd68482022-10-04 07:57:18 -0500107 #endif /* !defined(CFG_CORE_SEL1_SPMC) */
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400108diff --git a/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts b/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts
Patrick Williams8dd68482022-10-04 07:57:18 -0500109index 0bfe33f3..00cfa5b2 100644
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400110--- a/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts
111+++ b/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts
Patrick Williams8dd68482022-10-04 07:57:18 -0500112@@ -24,6 +24,7 @@
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400113 xlat-granule = <0>; /* 4KiB */
114 boot-order = <0>;
Patrick Williams8dd68482022-10-04 07:57:18 -0500115 messaging-method = <0x3>; /* Direct request/response supported */
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400116+ managed-exit; /* Managed exit supported */
Patrick Williams8dd68482022-10-04 07:57:18 -0500117
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400118 device-regions {
119 compatible = "arm,ffa-manifest-device-regions";
120--
Patrick Williams8dd68482022-10-04 07:57:18 -05001212.34.1
Brad Bishopbec4ebc2022-08-03 09:55:16 -0400122