Brad Bishop | bec4ebc | 2022-08-03 09:55:16 -0400 | [diff] [blame^] | 1 | From 14b84786e85483bf3c737ef8b392204e307c0ff1 Mon Sep 17 00:00:00 2001 |
| 2 | From: Olivier Deprez <olivier.deprez@arm.com> |
| 3 | Date: Mon, 16 Nov 2020 10:14:02 +0100 |
| 4 | Subject: [PATCH] WIP: Enable managed exit |
| 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 +++++++++++ |
| 30 | .../arm/plat-totalcompute/fdts/optee_sp_manifest.dts | 2 +- |
| 31 | 4 files changed, 34 insertions(+), 2 deletions(-) |
| 32 | |
| 33 | diff --git a/core/arch/arm/kernel/boot.c b/core/arch/arm/kernel/boot.c |
| 34 | index 09c1b811..d130107f 100644 |
| 35 | --- a/core/arch/arm/kernel/boot.c |
| 36 | +++ b/core/arch/arm/kernel/boot.c |
| 37 | @@ -1279,6 +1279,18 @@ static void init_secondary_helper(unsigned long nsec_entry) |
| 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 |
| 57 | index 3e0f5115..63bf396a 100644 |
| 58 | --- a/core/arch/arm/kernel/thread_a64.S |
| 59 | +++ b/core/arch/arm/kernel/thread_a64.S |
| 60 | @@ -904,6 +904,14 @@ END_FUNC el0_sync_abort |
| 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 | */ |
| 75 | @@ -1021,8 +1029,9 @@ LOCAL_FUNC elx_irq , : |
| 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 |
| 87 | index bd7930e7..89ff82bc 100644 |
| 88 | --- a/core/arch/arm/kernel/thread_spmc.c |
| 89 | +++ b/core/arch/arm/kernel/thread_spmc.c |
| 90 | @@ -1394,6 +1394,17 @@ static TEE_Result spmc_init(void) |
| 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 | } |
| 107 | #endif /*CFG_CORE_SEL2_SPMC*/ |
| 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 |
| 109 | index 4b8b3681..04847c4d 100644 |
| 110 | --- a/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts |
| 111 | +++ b/core/arch/arm/plat-totalcompute/fdts/optee_sp_manifest.dts |
| 112 | @@ -23,7 +23,8 @@ |
| 113 | entrypoint-offset = <0x1000>; |
| 114 | xlat-granule = <0>; /* 4KiB */ |
| 115 | boot-order = <0>; |
| 116 | - messaging-method = <0>; /* Direct messaging only */ |
| 117 | + messaging-method = <3>; /* Direct request/response supported */ |
| 118 | + managed-exit; /* Managed exit supported */ |
| 119 | |
| 120 | device-regions { |
| 121 | compatible = "arm,ffa-manifest-device-regions"; |
| 122 | -- |
| 123 | 2.29.2 |
| 124 | |