Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 1 | From 34db1357ab3192f18629ceadf4ea33b948513fec Mon Sep 17 00:00:00 2001 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 2 | From: Olivier Deprez <olivier.deprez@arm.com> |
| 3 | Date: Mon, 16 Nov 2020 10:14:02 +0100 |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 4 | Subject: [PATCH 1/2] WIP: Enable managed exit |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 5 | |
| 6 | This change declares OP-TEE SP as supporting managed exit in response to |
| 7 | a NS interrupt triggering while the SWd runs. |
| 8 | |
| 9 | At init OP-TEE enables (HF_INTERRUPT_ENABLE) the managed exit virtual |
| 10 | interrupt through the Hafnium para-virtualized interface. |
| 11 | |
| 12 | Physical interrupts are trapped to the SPMC which injects a managed exit |
| 13 | interrupt to OP-TEE. The managed exit interrupt is acknowledged by |
| 14 | OP-TEE by HF_INTERUPT_GET hvc call. |
| 15 | |
| 16 | Note: this code change is meant with in mind the SPMC runs at SEL2. It |
| 17 | needs slight refactoring such that it does not break the SEL1 SPMC |
| 18 | configuration. |
| 19 | |
| 20 | Change-Id: I9a95f36cf517c11048ff04680007f40259c4f636 |
| 21 | Signed-off-by: Olivier Deprez <olivier.deprez@arm.com> |
| 22 | Signed-off-by: Arunachalam Ganapathy <arunachalam.ganapathy@arm.com> |
| 23 | |
| 24 | Upstream-Status: Pending [Not submitted to upstream yet] |
| 25 | Signed-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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 30 | .../arm/plat-totalcompute/fdts/optee_sp_manifest.dts | 1 + |
| 31 | 4 files changed, 34 insertions(+), 1 deletion(-) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 32 | |
| 33 | diff --git a/core/arch/arm/kernel/boot.c b/core/arch/arm/kernel/boot.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 34 | index f173384d..466c042e 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 35 | --- a/core/arch/arm/kernel/boot.c |
| 36 | +++ b/core/arch/arm/kernel/boot.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 37 | @@ -1350,6 +1350,18 @@ static void init_secondary_helper(unsigned long nsec_entry) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 38 | 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 | |
| 56 | diff --git a/core/arch/arm/kernel/thread_a64.S b/core/arch/arm/kernel/thread_a64.S |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 57 | index d6baee4d..1b0c8f37 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 58 | --- a/core/arch/arm/kernel/thread_a64.S |
| 59 | +++ b/core/arch/arm/kernel/thread_a64.S |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 60 | @@ -1087,6 +1087,14 @@ END_FUNC el0_sync_abort |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 61 | 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 75 | @@ -1204,8 +1212,9 @@ LOCAL_FUNC elx_irq , : |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 76 | #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 |
| 86 | diff --git a/core/arch/arm/kernel/thread_spmc.c b/core/arch/arm/kernel/thread_spmc.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 87 | index ea9e8f03..15577e7e 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 88 | --- a/core/arch/arm/kernel/thread_spmc.c |
| 89 | +++ b/core/arch/arm/kernel/thread_spmc.c |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 90 | @@ -1518,6 +1518,17 @@ static TEE_Result spmc_init(void) |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 91 | 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 Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 107 | #endif /* !defined(CFG_CORE_SEL1_SPMC) */ |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 108 | diff --git a/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts b/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 109 | index 0bfe33f3..00cfa5b2 100644 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 110 | --- a/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts |
| 111 | +++ b/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 112 | @@ -24,6 +24,7 @@ |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 113 | xlat-granule = <0>; /* 4KiB */ |
| 114 | boot-order = <0>; |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 115 | messaging-method = <0x3>; /* Direct request/response supported */ |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 116 | + managed-exit; /* Managed exit supported */ |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 117 | |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 118 | device-regions { |
| 119 | compatible = "arm,ffa-manifest-device-regions"; |
| 120 | -- |
Patrick Williams | 8dd6848 | 2022-10-04 07:57:18 -0500 | [diff] [blame] | 121 | 2.34.1 |
Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame] | 122 | |