Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1 | /* |
Kathleen Capella | 9d826a1 | 2023-07-31 14:45:58 -0400 | [diff] [blame] | 2 | * Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <errno.h> |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 9 | #include <inttypes.h> |
| 10 | #include <stdint.h> |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 11 | #include <string.h> |
| 12 | |
| 13 | #include <arch_helpers.h> |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 14 | #include <arch/aarch64/arch_features.h> |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 15 | #include <bl31/bl31.h> |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 16 | #include <bl31/interrupt_mgmt.h> |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 17 | #include <common/debug.h> |
| 18 | #include <common/runtime_svc.h> |
Manish V Badarkhe | 2f4279a | 2023-02-07 11:26:38 +0000 | [diff] [blame] | 19 | #include <common/tbbr/tbbr_img_def.h> |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 20 | #include <lib/el3_runtime/context_mgmt.h> |
Manish V Badarkhe | 2f4279a | 2023-02-07 11:26:38 +0000 | [diff] [blame] | 21 | #include <lib/fconf/fconf.h> |
| 22 | #include <lib/fconf/fconf_dyn_cfg_getter.h> |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 23 | #include <lib/smccc.h> |
| 24 | #include <lib/spinlock.h> |
| 25 | #include <lib/utils.h> |
Manish V Badarkhe | 2f4279a | 2023-02-07 11:26:38 +0000 | [diff] [blame] | 26 | #include <lib/xlat_tables/xlat_tables_v2.h> |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 27 | #include <plat/common/common_def.h> |
| 28 | #include <plat/common/platform.h> |
| 29 | #include <platform_def.h> |
Raghu Krishnamurthy | 7f046c1 | 2023-02-25 13:26:10 -0800 | [diff] [blame] | 30 | #include <services/el3_spmd_logical_sp.h> |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 31 | #include <services/ffa_svc.h> |
Marc Bonnici | 1c33cc3 | 2021-11-29 17:57:03 +0000 | [diff] [blame] | 32 | #include <services/spmc_svc.h> |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 33 | #include <services/spmd_svc.h> |
| 34 | #include <smccc_helpers.h> |
| 35 | #include "spmd_private.h" |
| 36 | |
| 37 | /******************************************************************************* |
| 38 | * SPM Core context information. |
| 39 | ******************************************************************************/ |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 40 | static spmd_spm_core_context_t spm_core_context[PLATFORM_CORE_COUNT]; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 41 | |
| 42 | /******************************************************************************* |
Marc Bonnici | 1c33cc3 | 2021-11-29 17:57:03 +0000 | [diff] [blame] | 43 | * SPM Core attribute information is read from its manifest if the SPMC is not |
| 44 | * at EL3. Else, it is populated from the SPMC directly. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 45 | ******************************************************************************/ |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 46 | static spmc_manifest_attribute_t spmc_attrs; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 47 | |
| 48 | /******************************************************************************* |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 49 | * SPM Core entry point information. Discovered on the primary core and reused |
| 50 | * on secondary cores. |
| 51 | ******************************************************************************/ |
| 52 | static entry_point_info_t *spmc_ep_info; |
| 53 | |
| 54 | /******************************************************************************* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 55 | * SPM Core context on current CPU get helper. |
| 56 | ******************************************************************************/ |
| 57 | spmd_spm_core_context_t *spmd_get_context(void) |
| 58 | { |
Olivier Deprez | 13a4a07 | 2024-06-07 08:51:20 +0200 | [diff] [blame] | 59 | return &spm_core_context[plat_my_core_pos()]; |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | /******************************************************************************* |
Olivier Deprez | c7631a5 | 2020-03-23 09:53:06 +0100 | [diff] [blame] | 63 | * SPM Core ID getter. |
| 64 | ******************************************************************************/ |
| 65 | uint16_t spmd_spmc_id_get(void) |
| 66 | { |
| 67 | return spmc_attrs.spmc_id; |
| 68 | } |
| 69 | |
| 70 | /******************************************************************************* |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 71 | * Static function declaration. |
| 72 | ******************************************************************************/ |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 73 | static int32_t spmd_init(void); |
Olivier Deprez | 69ca84a | 2020-02-07 15:44:43 +0100 | [diff] [blame] | 74 | static int spmd_spmc_init(void *pm_addr); |
Raghu Krishnamurthy | 9d9584f | 2023-04-22 18:00:02 -0700 | [diff] [blame] | 75 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 76 | static uint64_t spmd_smc_forward(uint32_t smc_fid, |
| 77 | bool secure_origin, |
| 78 | uint64_t x1, |
| 79 | uint64_t x2, |
| 80 | uint64_t x3, |
| 81 | uint64_t x4, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 82 | void *cookie, |
| 83 | void *handle, |
| 84 | uint64_t flags); |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 85 | |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 86 | /****************************************************************************** |
| 87 | * Builds an SPMD to SPMC direct message request. |
| 88 | *****************************************************************************/ |
| 89 | void spmd_build_spmc_message(gp_regs_t *gpregs, uint8_t target_func, |
| 90 | unsigned long long message) |
| 91 | { |
| 92 | write_ctx_reg(gpregs, CTX_GPREG_X0, FFA_MSG_SEND_DIRECT_REQ_SMC32); |
| 93 | write_ctx_reg(gpregs, CTX_GPREG_X1, |
| 94 | (SPMD_DIRECT_MSG_ENDPOINT_ID << FFA_DIRECT_MSG_SOURCE_SHIFT) | |
| 95 | spmd_spmc_id_get()); |
| 96 | write_ctx_reg(gpregs, CTX_GPREG_X2, BIT(31) | target_func); |
| 97 | write_ctx_reg(gpregs, CTX_GPREG_X3, message); |
Olivier Deprez | 4911eb8 | 2023-07-10 11:04:30 +0200 | [diff] [blame] | 98 | |
| 99 | /* Zero out x4-x7 for the direct request emitted towards the SPMC. */ |
| 100 | write_ctx_reg(gpregs, CTX_GPREG_X4, 0); |
| 101 | write_ctx_reg(gpregs, CTX_GPREG_X5, 0); |
| 102 | write_ctx_reg(gpregs, CTX_GPREG_X6, 0); |
| 103 | write_ctx_reg(gpregs, CTX_GPREG_X7, 0); |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 107 | /******************************************************************************* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 108 | * This function takes an SPMC context pointer and performs a synchronous |
| 109 | * SPMC entry. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 110 | ******************************************************************************/ |
| 111 | uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *spmc_ctx) |
| 112 | { |
| 113 | uint64_t rc; |
| 114 | |
| 115 | assert(spmc_ctx != NULL); |
| 116 | |
| 117 | cm_set_context(&(spmc_ctx->cpu_ctx), SECURE); |
| 118 | |
| 119 | /* Restore the context assigned above */ |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 120 | #if SPMD_SPM_AT_SEL2 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 121 | cm_el2_sysregs_context_restore(SECURE); |
Olivier Deprez | 9a2e5be | 2021-05-21 18:00:04 +0200 | [diff] [blame] | 122 | #else |
| 123 | cm_el1_sysregs_context_restore(SECURE); |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 124 | #endif |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 125 | cm_set_next_eret_context(SECURE); |
| 126 | |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 127 | /* Enter SPMC */ |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 128 | rc = spmd_spm_core_enter(&spmc_ctx->c_rt_ctx); |
| 129 | |
| 130 | /* Save secure state */ |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 131 | #if SPMD_SPM_AT_SEL2 |
Max Shvetsov | bdf502d | 2020-02-25 13:56:19 +0000 | [diff] [blame] | 132 | cm_el2_sysregs_context_save(SECURE); |
Olivier Deprez | 9a2e5be | 2021-05-21 18:00:04 +0200 | [diff] [blame] | 133 | #else |
| 134 | cm_el1_sysregs_context_save(SECURE); |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 135 | #endif |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 136 | |
| 137 | return rc; |
| 138 | } |
| 139 | |
| 140 | /******************************************************************************* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 141 | * This function returns to the place where spmd_spm_core_sync_entry() was |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 142 | * called originally. |
| 143 | ******************************************************************************/ |
| 144 | __dead2 void spmd_spm_core_sync_exit(uint64_t rc) |
| 145 | { |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 146 | spmd_spm_core_context_t *ctx = spmd_get_context(); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 147 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 148 | /* Get current CPU context from SPMC context */ |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 149 | assert(cm_get_context(SECURE) == &(ctx->cpu_ctx)); |
| 150 | |
| 151 | /* |
| 152 | * The SPMD must have initiated the original request through a |
| 153 | * synchronous entry into SPMC. Jump back to the original C runtime |
| 154 | * context with the value of rc in x0; |
| 155 | */ |
| 156 | spmd_spm_core_exit(ctx->c_rt_ctx, rc); |
| 157 | |
| 158 | panic(); |
| 159 | } |
| 160 | |
| 161 | /******************************************************************************* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 162 | * Jump to the SPM Core for the first time. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 163 | ******************************************************************************/ |
| 164 | static int32_t spmd_init(void) |
| 165 | { |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 166 | spmd_spm_core_context_t *ctx = spmd_get_context(); |
| 167 | uint64_t rc; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 168 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 169 | VERBOSE("SPM Core init start.\n"); |
Olivier Deprez | 7c01633 | 2019-10-28 09:03:13 +0000 | [diff] [blame] | 170 | |
Olivier Deprez | 4ab7a4a | 2021-06-21 09:47:13 +0200 | [diff] [blame] | 171 | /* Primary boot core enters the SPMC for initialization. */ |
| 172 | ctx->state = SPMC_STATE_ON_PENDING; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 173 | |
| 174 | rc = spmd_spm_core_sync_entry(ctx); |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 175 | if (rc != 0ULL) { |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 176 | ERROR("SPMC initialisation failed 0x%" PRIx64 "\n", rc); |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 177 | return 0; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 178 | } |
| 179 | |
Olivier Deprez | 7c01633 | 2019-10-28 09:03:13 +0000 | [diff] [blame] | 180 | ctx->state = SPMC_STATE_ON; |
| 181 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 182 | VERBOSE("SPM Core init end.\n"); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 183 | |
Raghu Krishnamurthy | 7f046c1 | 2023-02-25 13:26:10 -0800 | [diff] [blame] | 184 | spmd_logical_sp_set_spmc_initialized(); |
| 185 | rc = spmd_logical_sp_init(); |
| 186 | if (rc != 0) { |
| 187 | WARN("SPMD Logical partitions failed init.\n"); |
| 188 | } |
| 189 | |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 190 | return 1; |
| 191 | } |
| 192 | |
| 193 | /******************************************************************************* |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 194 | * spmd_secure_interrupt_handler |
| 195 | * Enter the SPMC for further handling of the secure interrupt by the SPMC |
| 196 | * itself or a Secure Partition. |
| 197 | ******************************************************************************/ |
| 198 | static uint64_t spmd_secure_interrupt_handler(uint32_t id, |
| 199 | uint32_t flags, |
| 200 | void *handle, |
| 201 | void *cookie) |
| 202 | { |
| 203 | spmd_spm_core_context_t *ctx = spmd_get_context(); |
| 204 | gp_regs_t *gpregs = get_gpregs_ctx(&ctx->cpu_ctx); |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 205 | int64_t rc; |
| 206 | |
| 207 | /* Sanity check the security state when the exception was generated */ |
| 208 | assert(get_interrupt_src_ss(flags) == NON_SECURE); |
| 209 | |
| 210 | /* Sanity check the pointer to this cpu's context */ |
| 211 | assert(handle == cm_get_context(NON_SECURE)); |
| 212 | |
| 213 | /* Save the non-secure context before entering SPMC */ |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 214 | #if SPMD_SPM_AT_SEL2 |
| 215 | cm_el2_sysregs_context_save(NON_SECURE); |
Madhukar Pappireddy | d3f3207 | 2024-01-29 16:43:56 -0600 | [diff] [blame] | 216 | #else |
| 217 | cm_el1_sysregs_context_save(NON_SECURE); |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 218 | #endif |
| 219 | |
| 220 | /* Convey the event to the SPMC through the FFA_INTERRUPT interface. */ |
| 221 | write_ctx_reg(gpregs, CTX_GPREG_X0, FFA_INTERRUPT); |
| 222 | write_ctx_reg(gpregs, CTX_GPREG_X1, 0); |
| 223 | write_ctx_reg(gpregs, CTX_GPREG_X2, 0); |
| 224 | write_ctx_reg(gpregs, CTX_GPREG_X3, 0); |
| 225 | write_ctx_reg(gpregs, CTX_GPREG_X4, 0); |
| 226 | write_ctx_reg(gpregs, CTX_GPREG_X5, 0); |
| 227 | write_ctx_reg(gpregs, CTX_GPREG_X6, 0); |
| 228 | write_ctx_reg(gpregs, CTX_GPREG_X7, 0); |
| 229 | |
| 230 | /* Mark current core as handling a secure interrupt. */ |
| 231 | ctx->secure_interrupt_ongoing = true; |
| 232 | |
| 233 | rc = spmd_spm_core_sync_entry(ctx); |
| 234 | if (rc != 0ULL) { |
Olivier Deprez | 5f875b8 | 2024-06-07 10:22:50 +0200 | [diff] [blame] | 235 | ERROR("%s failed (%" PRId64 ") on CPU%u\n", __func__, rc, plat_my_core_pos()); |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | ctx->secure_interrupt_ongoing = false; |
| 239 | |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 240 | #if SPMD_SPM_AT_SEL2 |
| 241 | cm_el2_sysregs_context_restore(NON_SECURE); |
Madhukar Pappireddy | d3f3207 | 2024-01-29 16:43:56 -0600 | [diff] [blame] | 242 | #else |
| 243 | cm_el1_sysregs_context_restore(NON_SECURE); |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 244 | #endif |
| 245 | cm_set_next_eret_context(NON_SECURE); |
| 246 | |
| 247 | SMC_RET0(&ctx->cpu_ctx); |
| 248 | } |
| 249 | |
Olivier Deprez | 35bbcf2 | 2023-06-08 18:23:26 +0200 | [diff] [blame] | 250 | #if (EL3_EXCEPTION_HANDLING == 0) |
Madhukar Pappireddy | b494acf | 2023-03-02 15:34:05 -0600 | [diff] [blame] | 251 | /******************************************************************************* |
| 252 | * spmd_group0_interrupt_handler_nwd |
| 253 | * Group0 secure interrupt in the normal world are trapped to EL3. Delegate the |
| 254 | * handling of the interrupt to the platform handler, and return only upon |
| 255 | * successfully handling the Group0 interrupt. |
| 256 | ******************************************************************************/ |
| 257 | static uint64_t spmd_group0_interrupt_handler_nwd(uint32_t id, |
| 258 | uint32_t flags, |
| 259 | void *handle, |
| 260 | void *cookie) |
| 261 | { |
| 262 | uint32_t intid; |
| 263 | |
| 264 | /* Sanity check the security state when the exception was generated. */ |
| 265 | assert(get_interrupt_src_ss(flags) == NON_SECURE); |
| 266 | |
| 267 | /* Sanity check the pointer to this cpu's context. */ |
| 268 | assert(handle == cm_get_context(NON_SECURE)); |
| 269 | |
| 270 | assert(id == INTR_ID_UNAVAILABLE); |
| 271 | |
| 272 | assert(plat_ic_get_pending_interrupt_type() == INTR_TYPE_EL3); |
| 273 | |
Madhukar Pappireddy | 2ca7570 | 2023-07-12 16:28:05 -0500 | [diff] [blame] | 274 | intid = plat_ic_acknowledge_interrupt(); |
Madhukar Pappireddy | b494acf | 2023-03-02 15:34:05 -0600 | [diff] [blame] | 275 | |
| 276 | if (plat_spmd_handle_group0_interrupt(intid) < 0) { |
| 277 | ERROR("Group0 interrupt %u not handled\n", intid); |
| 278 | panic(); |
| 279 | } |
| 280 | |
Madhukar Pappireddy | 2ca7570 | 2023-07-12 16:28:05 -0500 | [diff] [blame] | 281 | /* Deactivate the corresponding Group0 interrupt. */ |
| 282 | plat_ic_end_of_interrupt(intid); |
| 283 | |
Madhukar Pappireddy | b494acf | 2023-03-02 15:34:05 -0600 | [diff] [blame] | 284 | return 0U; |
| 285 | } |
Olivier Deprez | 35bbcf2 | 2023-06-08 18:23:26 +0200 | [diff] [blame] | 286 | #endif |
Madhukar Pappireddy | b494acf | 2023-03-02 15:34:05 -0600 | [diff] [blame] | 287 | |
Madhukar Pappireddy | 41416cc | 2023-03-02 16:04:38 -0600 | [diff] [blame] | 288 | /******************************************************************************* |
| 289 | * spmd_handle_group0_intr_swd |
| 290 | * SPMC delegates handling of Group0 secure interrupt to EL3 firmware using |
| 291 | * FFA_EL3_INTR_HANDLE SMC call. Further, SPMD delegates the handling of the |
| 292 | * interrupt to the platform handler, and returns only upon successfully |
| 293 | * handling the Group0 interrupt. |
| 294 | ******************************************************************************/ |
| 295 | static uint64_t spmd_handle_group0_intr_swd(void *handle) |
| 296 | { |
| 297 | uint32_t intid; |
| 298 | |
| 299 | /* Sanity check the pointer to this cpu's context */ |
| 300 | assert(handle == cm_get_context(SECURE)); |
| 301 | |
| 302 | assert(plat_ic_get_pending_interrupt_type() == INTR_TYPE_EL3); |
| 303 | |
Madhukar Pappireddy | 2ca7570 | 2023-07-12 16:28:05 -0500 | [diff] [blame] | 304 | intid = plat_ic_acknowledge_interrupt(); |
Madhukar Pappireddy | 41416cc | 2023-03-02 16:04:38 -0600 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * TODO: Currently due to a limitation in SPMD implementation, the |
| 308 | * platform handler is expected to not delegate handling to NWd while |
| 309 | * processing Group0 secure interrupt. |
| 310 | */ |
| 311 | if (plat_spmd_handle_group0_interrupt(intid) < 0) { |
| 312 | /* Group0 interrupt was not handled by the platform. */ |
| 313 | ERROR("Group0 interrupt %u not handled\n", intid); |
| 314 | panic(); |
| 315 | } |
| 316 | |
Madhukar Pappireddy | 2ca7570 | 2023-07-12 16:28:05 -0500 | [diff] [blame] | 317 | /* Deactivate the corresponding Group0 interrupt. */ |
| 318 | plat_ic_end_of_interrupt(intid); |
| 319 | |
Madhukar Pappireddy | 41416cc | 2023-03-02 16:04:38 -0600 | [diff] [blame] | 320 | /* Return success. */ |
| 321 | SMC_RET8(handle, FFA_SUCCESS_SMC32, FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 322 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 323 | FFA_PARAM_MBZ); |
| 324 | } |
| 325 | |
Manish V Badarkhe | 2f4279a | 2023-02-07 11:26:38 +0000 | [diff] [blame] | 326 | #if ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 |
| 327 | static int spmd_dynamic_map_mem(uintptr_t base_addr, size_t size, |
| 328 | unsigned int attr, uintptr_t *align_addr, |
| 329 | size_t *align_size) |
| 330 | { |
| 331 | uintptr_t base_addr_align; |
| 332 | size_t mapped_size_align; |
| 333 | int rc; |
| 334 | |
| 335 | /* Page aligned address and size if necessary */ |
| 336 | base_addr_align = page_align(base_addr, DOWN); |
| 337 | mapped_size_align = page_align(size, UP); |
| 338 | |
| 339 | if ((base_addr != base_addr_align) && |
| 340 | (size == mapped_size_align)) { |
| 341 | mapped_size_align += PAGE_SIZE; |
| 342 | } |
| 343 | |
| 344 | /* |
| 345 | * Map dynamically given region with its aligned base address and |
| 346 | * size |
| 347 | */ |
| 348 | rc = mmap_add_dynamic_region((unsigned long long)base_addr_align, |
| 349 | base_addr_align, |
| 350 | mapped_size_align, |
| 351 | attr); |
| 352 | if (rc == 0) { |
| 353 | *align_addr = base_addr_align; |
| 354 | *align_size = mapped_size_align; |
| 355 | } |
| 356 | |
| 357 | return rc; |
| 358 | } |
| 359 | |
| 360 | static void spmd_do_sec_cpy(uintptr_t root_base_addr, uintptr_t sec_base_addr, |
| 361 | size_t size) |
| 362 | { |
| 363 | uintptr_t root_base_addr_align, sec_base_addr_align; |
| 364 | size_t root_mapped_size_align, sec_mapped_size_align; |
| 365 | int rc; |
| 366 | |
| 367 | assert(root_base_addr != 0UL); |
| 368 | assert(sec_base_addr != 0UL); |
| 369 | assert(size != 0UL); |
| 370 | |
| 371 | /* Map the memory with required attributes */ |
| 372 | rc = spmd_dynamic_map_mem(root_base_addr, size, MT_RO_DATA | MT_ROOT, |
| 373 | &root_base_addr_align, |
| 374 | &root_mapped_size_align); |
| 375 | if (rc != 0) { |
| 376 | ERROR("%s %s %lu (%d)\n", "Error while mapping", "root region", |
| 377 | root_base_addr, rc); |
| 378 | panic(); |
| 379 | } |
| 380 | |
| 381 | rc = spmd_dynamic_map_mem(sec_base_addr, size, MT_RW_DATA | MT_SECURE, |
| 382 | &sec_base_addr_align, &sec_mapped_size_align); |
| 383 | if (rc != 0) { |
| 384 | ERROR("%s %s %lu (%d)\n", "Error while mapping", |
| 385 | "secure region", sec_base_addr, rc); |
| 386 | panic(); |
| 387 | } |
| 388 | |
| 389 | /* Do copy operation */ |
| 390 | (void)memcpy((void *)sec_base_addr, (void *)root_base_addr, size); |
| 391 | |
| 392 | /* Unmap root memory region */ |
| 393 | rc = mmap_remove_dynamic_region(root_base_addr_align, |
| 394 | root_mapped_size_align); |
| 395 | if (rc != 0) { |
| 396 | ERROR("%s %s %lu (%d)\n", "Error while unmapping", |
| 397 | "root region", root_base_addr_align, rc); |
| 398 | panic(); |
| 399 | } |
| 400 | |
| 401 | /* Unmap secure memory region */ |
| 402 | rc = mmap_remove_dynamic_region(sec_base_addr_align, |
| 403 | sec_mapped_size_align); |
| 404 | if (rc != 0) { |
| 405 | ERROR("%s %s %lu (%d)\n", "Error while unmapping", |
| 406 | "secure region", sec_base_addr_align, rc); |
| 407 | panic(); |
| 408 | } |
| 409 | } |
| 410 | #endif /* ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 */ |
| 411 | |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 412 | /******************************************************************************* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 413 | * Loads SPMC manifest and inits SPMC. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 414 | ******************************************************************************/ |
Olivier Deprez | 69ca84a | 2020-02-07 15:44:43 +0100 | [diff] [blame] | 415 | static int spmd_spmc_init(void *pm_addr) |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 416 | { |
Olivier Deprez | 4ab7a4a | 2021-06-21 09:47:13 +0200 | [diff] [blame] | 417 | cpu_context_t *cpu_ctx; |
| 418 | unsigned int core_id; |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 419 | uint32_t ep_attr, flags; |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 420 | int rc; |
Manish V Badarkhe | 2f4279a | 2023-02-07 11:26:38 +0000 | [diff] [blame] | 421 | const struct dyn_cfg_dtb_info_t *image_info __unused; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 422 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 423 | /* Load the SPM Core manifest */ |
Olivier Deprez | 69ca84a | 2020-02-07 15:44:43 +0100 | [diff] [blame] | 424 | rc = plat_spm_core_manifest_load(&spmc_attrs, pm_addr); |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 425 | if (rc != 0) { |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 426 | WARN("No or invalid SPM Core manifest image provided by BL2\n"); |
| 427 | return rc; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 431 | * Ensure that the SPM Core version is compatible with the SPM |
| 432 | * Dispatcher version. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 433 | */ |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 434 | if ((spmc_attrs.major_version != FFA_VERSION_MAJOR) || |
| 435 | (spmc_attrs.minor_version > FFA_VERSION_MINOR)) { |
| 436 | WARN("Unsupported FFA version (%u.%u)\n", |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 437 | spmc_attrs.major_version, spmc_attrs.minor_version); |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 438 | return -EINVAL; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 439 | } |
| 440 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 441 | VERBOSE("FFA version (%u.%u)\n", spmc_attrs.major_version, |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 442 | spmc_attrs.minor_version); |
| 443 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 444 | VERBOSE("SPM Core run time EL%x.\n", |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 445 | SPMD_SPM_AT_SEL2 ? MODE_EL2 : MODE_EL1); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 446 | |
Max Shvetsov | e79062e | 2020-03-12 15:16:40 +0000 | [diff] [blame] | 447 | /* Validate the SPMC ID, Ensure high bit is set */ |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 448 | if (((spmc_attrs.spmc_id >> SPMC_SECURE_ID_SHIFT) & |
| 449 | SPMC_SECURE_ID_MASK) == 0U) { |
| 450 | WARN("Invalid ID (0x%x) for SPMC.\n", spmc_attrs.spmc_id); |
| 451 | return -EINVAL; |
Max Shvetsov | e79062e | 2020-03-12 15:16:40 +0000 | [diff] [blame] | 452 | } |
| 453 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 454 | /* Validate the SPM Core execution state */ |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 455 | if ((spmc_attrs.exec_state != MODE_RW_64) && |
| 456 | (spmc_attrs.exec_state != MODE_RW_32)) { |
Olivier Deprez | 69ca84a | 2020-02-07 15:44:43 +0100 | [diff] [blame] | 457 | WARN("Unsupported %s%x.\n", "SPM Core execution state 0x", |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 458 | spmc_attrs.exec_state); |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 459 | return -EINVAL; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 460 | } |
| 461 | |
Olivier Deprez | 69ca84a | 2020-02-07 15:44:43 +0100 | [diff] [blame] | 462 | VERBOSE("%s%x.\n", "SPM Core execution state 0x", |
| 463 | spmc_attrs.exec_state); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 464 | |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 465 | #if SPMD_SPM_AT_SEL2 |
| 466 | /* Ensure manifest has not requested AArch32 state in S-EL2 */ |
| 467 | if (spmc_attrs.exec_state == MODE_RW_32) { |
| 468 | WARN("AArch32 state at S-EL2 is not supported.\n"); |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 469 | return -EINVAL; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | /* |
| 473 | * Check if S-EL2 is supported on this system if S-EL2 |
| 474 | * is required for SPM |
| 475 | */ |
Andre Przywara | 6dd2d06 | 2023-02-22 16:53:50 +0000 | [diff] [blame] | 476 | if (!is_feat_sel2_supported()) { |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 477 | WARN("SPM Core run time S-EL2 is not supported.\n"); |
| 478 | return -EINVAL; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 479 | } |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 480 | #endif /* SPMD_SPM_AT_SEL2 */ |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 481 | |
| 482 | /* Initialise an entrypoint to set up the CPU context */ |
| 483 | ep_attr = SECURE | EP_ST_ENABLE; |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 484 | if ((read_sctlr_el3() & SCTLR_EE_BIT) != 0ULL) { |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 485 | ep_attr |= EP_EE_BIG; |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 486 | } |
| 487 | |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 488 | SET_PARAM_HEAD(spmc_ep_info, PARAM_EP, VERSION_1, ep_attr); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 489 | |
| 490 | /* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 491 | * Populate SPSR for SPM Core based upon validated parameters from the |
| 492 | * manifest. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 493 | */ |
| 494 | if (spmc_attrs.exec_state == MODE_RW_32) { |
| 495 | spmc_ep_info->spsr = SPSR_MODE32(MODE32_svc, SPSR_T_ARM, |
| 496 | SPSR_E_LITTLE, |
| 497 | DAIF_FIQ_BIT | |
| 498 | DAIF_IRQ_BIT | |
| 499 | DAIF_ABT_BIT); |
| 500 | } else { |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 501 | |
| 502 | #if SPMD_SPM_AT_SEL2 |
| 503 | static const uint32_t runtime_el = MODE_EL2; |
| 504 | #else |
| 505 | static const uint32_t runtime_el = MODE_EL1; |
| 506 | #endif |
| 507 | spmc_ep_info->spsr = SPSR_64(runtime_el, |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 508 | MODE_SP_ELX, |
| 509 | DISABLE_ALL_EXCEPTIONS); |
| 510 | } |
| 511 | |
Manish V Badarkhe | 2f4279a | 2023-02-07 11:26:38 +0000 | [diff] [blame] | 512 | #if ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 |
| 513 | image_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, TOS_FW_CONFIG_ID); |
| 514 | assert(image_info != NULL); |
| 515 | |
| 516 | if ((image_info->config_addr == 0UL) || |
| 517 | (image_info->secondary_config_addr == 0UL) || |
| 518 | (image_info->config_max_size == 0UL)) { |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | |
| 522 | /* Copy manifest from root->secure region */ |
| 523 | spmd_do_sec_cpy(image_info->config_addr, |
| 524 | image_info->secondary_config_addr, |
| 525 | image_info->config_max_size); |
| 526 | |
| 527 | /* Update ep info of BL32 */ |
| 528 | assert(spmc_ep_info != NULL); |
| 529 | spmc_ep_info->args.arg0 = image_info->secondary_config_addr; |
| 530 | #endif /* ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 */ |
| 531 | |
Olivier Deprez | 4ab7a4a | 2021-06-21 09:47:13 +0200 | [diff] [blame] | 532 | /* Set an initial SPMC context state for all cores. */ |
| 533 | for (core_id = 0U; core_id < PLATFORM_CORE_COUNT; core_id++) { |
| 534 | spm_core_context[core_id].state = SPMC_STATE_OFF; |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 535 | |
Olivier Deprez | 4ab7a4a | 2021-06-21 09:47:13 +0200 | [diff] [blame] | 536 | /* Setup an initial cpu context for the SPMC. */ |
| 537 | cpu_ctx = &spm_core_context[core_id].cpu_ctx; |
| 538 | cm_setup_context(cpu_ctx, spmc_ep_info); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 539 | |
Olivier Deprez | 4ab7a4a | 2021-06-21 09:47:13 +0200 | [diff] [blame] | 540 | /* |
| 541 | * Pass the core linear ID to the SPMC through x4. |
| 542 | * (TF-A implementation defined behavior helping |
| 543 | * a legacy TOS migration to adopt FF-A). |
| 544 | */ |
| 545 | write_ctx_reg(get_gpregs_ctx(cpu_ctx), CTX_GPREG_X4, core_id); |
| 546 | } |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 547 | |
Olivier Deprez | 9afca12 | 2019-10-28 09:15:52 +0000 | [diff] [blame] | 548 | /* Register power management hooks with PSCI */ |
| 549 | psci_register_spd_pm_hook(&spmd_pm); |
| 550 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 551 | /* Register init function for deferred init. */ |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 552 | bl31_register_bl32_init(&spmd_init); |
| 553 | |
Olivier Deprez | 4ab7a4a | 2021-06-21 09:47:13 +0200 | [diff] [blame] | 554 | INFO("SPM Core setup done.\n"); |
| 555 | |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 556 | /* |
| 557 | * Register an interrupt handler routing secure interrupts to SPMD |
| 558 | * while the NWd is running. |
| 559 | */ |
| 560 | flags = 0; |
| 561 | set_interrupt_rm_flag(flags, NON_SECURE); |
| 562 | rc = register_interrupt_type_handler(INTR_TYPE_S_EL1, |
| 563 | spmd_secure_interrupt_handler, |
| 564 | flags); |
| 565 | if (rc != 0) { |
| 566 | panic(); |
| 567 | } |
| 568 | |
Madhukar Pappireddy | b494acf | 2023-03-02 15:34:05 -0600 | [diff] [blame] | 569 | /* |
Olivier Deprez | 35bbcf2 | 2023-06-08 18:23:26 +0200 | [diff] [blame] | 570 | * Permit configurations where the SPM resides at S-EL1/2 and upon a |
| 571 | * Group0 interrupt triggering while the normal world runs, the |
| 572 | * interrupt is routed either through the EHF or directly to the SPMD: |
| 573 | * |
| 574 | * EL3_EXCEPTION_HANDLING=0: the Group0 interrupt is routed to the SPMD |
| 575 | * for handling by spmd_group0_interrupt_handler_nwd. |
| 576 | * |
| 577 | * EL3_EXCEPTION_HANDLING=1: the Group0 interrupt is routed to the EHF. |
| 578 | * |
| 579 | */ |
| 580 | #if (EL3_EXCEPTION_HANDLING == 0) |
| 581 | /* |
Madhukar Pappireddy | 89e8456 | 2024-03-26 09:21:25 -0500 | [diff] [blame] | 582 | * If EL3 interrupts are supported by the platform, register an |
| 583 | * interrupt handler routing Group0 interrupts to SPMD while the NWd is |
| 584 | * running. |
Madhukar Pappireddy | b494acf | 2023-03-02 15:34:05 -0600 | [diff] [blame] | 585 | */ |
Madhukar Pappireddy | 89e8456 | 2024-03-26 09:21:25 -0500 | [diff] [blame] | 586 | if (plat_ic_has_interrupt_type(INTR_TYPE_EL3)) { |
| 587 | rc = register_interrupt_type_handler(INTR_TYPE_EL3, |
| 588 | spmd_group0_interrupt_handler_nwd, |
| 589 | flags); |
| 590 | if (rc != 0) { |
| 591 | panic(); |
| 592 | } |
Madhukar Pappireddy | b494acf | 2023-03-02 15:34:05 -0600 | [diff] [blame] | 593 | } |
Olivier Deprez | 35bbcf2 | 2023-06-08 18:23:26 +0200 | [diff] [blame] | 594 | #endif |
| 595 | |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 596 | return 0; |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 597 | } |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 598 | |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 599 | /******************************************************************************* |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 600 | * Initialize context of SPM Core. |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 601 | ******************************************************************************/ |
| 602 | int spmd_setup(void) |
| 603 | { |
| 604 | int rc; |
Marc Bonnici | 1c33cc3 | 2021-11-29 17:57:03 +0000 | [diff] [blame] | 605 | void *spmc_manifest; |
| 606 | |
| 607 | /* |
| 608 | * If the SPMC is at EL3, then just initialise it directly. The |
| 609 | * shenanigans of when it is at a lower EL are not needed. |
| 610 | */ |
| 611 | if (is_spmc_at_el3()) { |
| 612 | /* Allow the SPMC to populate its attributes directly. */ |
| 613 | spmc_populate_attrs(&spmc_attrs); |
| 614 | |
| 615 | rc = spmc_setup(); |
| 616 | if (rc != 0) { |
Olivier Deprez | 3d203f4 | 2022-11-16 16:46:23 +0100 | [diff] [blame] | 617 | WARN("SPMC initialisation failed 0x%x.\n", rc); |
Marc Bonnici | 1c33cc3 | 2021-11-29 17:57:03 +0000 | [diff] [blame] | 618 | } |
Olivier Deprez | 3d203f4 | 2022-11-16 16:46:23 +0100 | [diff] [blame] | 619 | return 0; |
Marc Bonnici | 1c33cc3 | 2021-11-29 17:57:03 +0000 | [diff] [blame] | 620 | } |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 621 | |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 622 | spmc_ep_info = bl31_plat_get_next_image_ep_info(SECURE); |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 623 | if (spmc_ep_info == NULL) { |
| 624 | WARN("No SPM Core image provided by BL2 boot loader.\n"); |
Olivier Deprez | 3d203f4 | 2022-11-16 16:46:23 +0100 | [diff] [blame] | 625 | return 0; |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | /* Under no circumstances will this parameter be 0 */ |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 629 | assert(spmc_ep_info->pc != 0ULL); |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 630 | |
| 631 | /* |
| 632 | * Check if BL32 ep_info has a reference to 'tos_fw_config'. This will |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 633 | * be used as a manifest for the SPM Core at the next lower EL/mode. |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 634 | */ |
Olivier Deprez | 69ca84a | 2020-02-07 15:44:43 +0100 | [diff] [blame] | 635 | spmc_manifest = (void *)spmc_ep_info->args.arg0; |
| 636 | if (spmc_manifest == NULL) { |
Olivier Deprez | 3d203f4 | 2022-11-16 16:46:23 +0100 | [diff] [blame] | 637 | WARN("Invalid or absent SPM Core manifest.\n"); |
| 638 | return 0; |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | /* Load manifest, init SPMC */ |
Olivier Deprez | 69ca84a | 2020-02-07 15:44:43 +0100 | [diff] [blame] | 642 | rc = spmd_spmc_init(spmc_manifest); |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 643 | if (rc != 0) { |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 644 | WARN("Booting device without SPM initialization.\n"); |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Olivier Deprez | 3d203f4 | 2022-11-16 16:46:23 +0100 | [diff] [blame] | 647 | return 0; |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /******************************************************************************* |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 651 | * Forward FF-A SMCs to the other security state. |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 652 | ******************************************************************************/ |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 653 | uint64_t spmd_smc_switch_state(uint32_t smc_fid, |
| 654 | bool secure_origin, |
| 655 | uint64_t x1, |
| 656 | uint64_t x2, |
| 657 | uint64_t x3, |
| 658 | uint64_t x4, |
Olivier Deprez | dce23c0 | 2022-10-31 12:38:17 +0100 | [diff] [blame] | 659 | void *handle, |
| 660 | uint64_t flags) |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 661 | { |
Olivier Deprez | ebc3477 | 2020-04-16 16:59:21 +0200 | [diff] [blame] | 662 | unsigned int secure_state_in = (secure_origin) ? SECURE : NON_SECURE; |
| 663 | unsigned int secure_state_out = (!secure_origin) ? SECURE : NON_SECURE; |
Olivier Deprez | aed3031 | 2024-06-07 09:24:43 +0200 | [diff] [blame] | 664 | void *ctx_out; |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 665 | |
Olivier Deprez | dce23c0 | 2022-10-31 12:38:17 +0100 | [diff] [blame] | 666 | #if SPMD_SPM_AT_SEL2 |
| 667 | if ((secure_state_out == SECURE) && (is_sve_hint_set(flags) == true)) { |
| 668 | /* |
| 669 | * Set the SVE hint bit in x0 and pass to the lower secure EL, |
| 670 | * if it was set by the caller. |
| 671 | */ |
| 672 | smc_fid |= (FUNCID_SVE_HINT_MASK << FUNCID_SVE_HINT_SHIFT); |
| 673 | } |
| 674 | #endif |
| 675 | |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 676 | /* Save incoming security state */ |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 677 | #if SPMD_SPM_AT_SEL2 |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 678 | cm_el2_sysregs_context_save(secure_state_in); |
Olivier Deprez | 9a2e5be | 2021-05-21 18:00:04 +0200 | [diff] [blame] | 679 | #else |
| 680 | cm_el1_sysregs_context_save(secure_state_in); |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 681 | #endif |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 682 | |
| 683 | /* Restore outgoing security state */ |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 684 | #if SPMD_SPM_AT_SEL2 |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 685 | cm_el2_sysregs_context_restore(secure_state_out); |
Olivier Deprez | 9a2e5be | 2021-05-21 18:00:04 +0200 | [diff] [blame] | 686 | #else |
| 687 | cm_el1_sysregs_context_restore(secure_state_out); |
Max Shvetsov | e7fd80e | 2020-02-25 13:55:00 +0000 | [diff] [blame] | 688 | #endif |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 689 | cm_set_next_eret_context(secure_state_out); |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 690 | |
Olivier Deprez | aed3031 | 2024-06-07 09:24:43 +0200 | [diff] [blame] | 691 | ctx_out = cm_get_context(secure_state_out); |
Raghu Krishnamurthy | 435f11c | 2022-12-25 13:02:00 -0800 | [diff] [blame] | 692 | #if SPMD_SPM_AT_SEL2 |
| 693 | /* |
| 694 | * If SPMC is at SEL2, save additional registers x8-x17, which may |
| 695 | * be used in FF-A calls such as FFA_PARTITION_INFO_GET_REGS. |
| 696 | * Note that technically, all SPMCs can support this, but this code is |
| 697 | * under ifdef to minimize breakage in case other SPMCs do not save |
| 698 | * and restore x8-x17. |
| 699 | * We also need to pass through these registers since not all FF-A ABIs |
| 700 | * modify x8-x17, in which case, SMCCC requires that these registers be |
| 701 | * preserved, so the SPMD passes through these registers and expects the |
| 702 | * SPMC to save and restore (potentially also modify) them. |
| 703 | */ |
Olivier Deprez | aed3031 | 2024-06-07 09:24:43 +0200 | [diff] [blame] | 704 | SMC_RET18(ctx_out, smc_fid, x1, x2, x3, x4, |
Raghu Krishnamurthy | 435f11c | 2022-12-25 13:02:00 -0800 | [diff] [blame] | 705 | SMC_GET_GP(handle, CTX_GPREG_X5), |
| 706 | SMC_GET_GP(handle, CTX_GPREG_X6), |
| 707 | SMC_GET_GP(handle, CTX_GPREG_X7), |
| 708 | SMC_GET_GP(handle, CTX_GPREG_X8), |
| 709 | SMC_GET_GP(handle, CTX_GPREG_X9), |
| 710 | SMC_GET_GP(handle, CTX_GPREG_X10), |
| 711 | SMC_GET_GP(handle, CTX_GPREG_X11), |
| 712 | SMC_GET_GP(handle, CTX_GPREG_X12), |
| 713 | SMC_GET_GP(handle, CTX_GPREG_X13), |
| 714 | SMC_GET_GP(handle, CTX_GPREG_X14), |
| 715 | SMC_GET_GP(handle, CTX_GPREG_X15), |
| 716 | SMC_GET_GP(handle, CTX_GPREG_X16), |
| 717 | SMC_GET_GP(handle, CTX_GPREG_X17) |
| 718 | ); |
| 719 | |
| 720 | #else |
Olivier Deprez | aed3031 | 2024-06-07 09:24:43 +0200 | [diff] [blame] | 721 | SMC_RET8(ctx_out, smc_fid, x1, x2, x3, x4, |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 722 | SMC_GET_GP(handle, CTX_GPREG_X5), |
| 723 | SMC_GET_GP(handle, CTX_GPREG_X6), |
| 724 | SMC_GET_GP(handle, CTX_GPREG_X7)); |
Raghu Krishnamurthy | 435f11c | 2022-12-25 13:02:00 -0800 | [diff] [blame] | 725 | #endif |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /******************************************************************************* |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 729 | * Forward SMCs to the other security state. |
| 730 | ******************************************************************************/ |
| 731 | static uint64_t spmd_smc_forward(uint32_t smc_fid, |
| 732 | bool secure_origin, |
| 733 | uint64_t x1, |
| 734 | uint64_t x2, |
| 735 | uint64_t x3, |
| 736 | uint64_t x4, |
| 737 | void *cookie, |
| 738 | void *handle, |
| 739 | uint64_t flags) |
| 740 | { |
| 741 | if (is_spmc_at_el3() && !secure_origin) { |
| 742 | return spmc_smc_handler(smc_fid, secure_origin, x1, x2, x3, x4, |
| 743 | cookie, handle, flags); |
| 744 | } |
Olivier Deprez | dce23c0 | 2022-10-31 12:38:17 +0100 | [diff] [blame] | 745 | |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 746 | return spmd_smc_switch_state(smc_fid, secure_origin, x1, x2, x3, x4, |
Olivier Deprez | dce23c0 | 2022-10-31 12:38:17 +0100 | [diff] [blame] | 747 | handle, flags); |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 748 | |
| 749 | } |
| 750 | |
| 751 | /******************************************************************************* |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 752 | * Return FFA_ERROR with specified error code |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 753 | ******************************************************************************/ |
Raghu Krishnamurthy | 9d9584f | 2023-04-22 18:00:02 -0700 | [diff] [blame] | 754 | uint64_t spmd_ffa_error_return(void *handle, int error_code) |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 755 | { |
J-Alves | 64ff993 | 2021-03-01 10:26:59 +0000 | [diff] [blame] | 756 | SMC_RET8(handle, (uint32_t) FFA_ERROR, |
| 757 | FFA_TARGET_INFO_MBZ, (uint32_t)error_code, |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 758 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 759 | FFA_PARAM_MBZ, FFA_PARAM_MBZ); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 760 | } |
| 761 | |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 762 | /******************************************************************************* |
| 763 | * spmd_check_address_in_binary_image |
| 764 | ******************************************************************************/ |
| 765 | bool spmd_check_address_in_binary_image(uint64_t address) |
| 766 | { |
| 767 | assert(!check_uptr_overflow(spmc_attrs.load_address, spmc_attrs.binary_size)); |
| 768 | |
| 769 | return ((address >= spmc_attrs.load_address) && |
| 770 | (address < (spmc_attrs.load_address + spmc_attrs.binary_size))); |
| 771 | } |
| 772 | |
Olivier Deprez | ebc3477 | 2020-04-16 16:59:21 +0200 | [diff] [blame] | 773 | /****************************************************************************** |
| 774 | * spmd_is_spmc_message |
| 775 | *****************************************************************************/ |
| 776 | static bool spmd_is_spmc_message(unsigned int ep) |
| 777 | { |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 778 | if (is_spmc_at_el3()) { |
| 779 | return false; |
| 780 | } |
| 781 | |
Olivier Deprez | ebc3477 | 2020-04-16 16:59:21 +0200 | [diff] [blame] | 782 | return ((ffa_endpoint_destination(ep) == SPMD_DIRECT_MSG_ENDPOINT_ID) |
| 783 | && (ffa_endpoint_source(ep) == spmc_attrs.spmc_id)); |
| 784 | } |
| 785 | |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 786 | /****************************************************************************** |
| 787 | * spmd_handle_spmc_message |
| 788 | *****************************************************************************/ |
Olivier Deprez | c7631a5 | 2020-03-23 09:53:06 +0100 | [diff] [blame] | 789 | static int spmd_handle_spmc_message(unsigned long long msg, |
| 790 | unsigned long long parm1, unsigned long long parm2, |
| 791 | unsigned long long parm3, unsigned long long parm4) |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 792 | { |
| 793 | VERBOSE("%s %llx %llx %llx %llx %llx\n", __func__, |
| 794 | msg, parm1, parm2, parm3, parm4); |
| 795 | |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 796 | return -EINVAL; |
| 797 | } |
| 798 | |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 799 | /******************************************************************************* |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 800 | * This function forwards FF-A SMCs to either the main SPMD handler or the |
| 801 | * SPMC at EL3, depending on the origin security state, if enabled. |
| 802 | ******************************************************************************/ |
| 803 | uint64_t spmd_ffa_smc_handler(uint32_t smc_fid, |
| 804 | uint64_t x1, |
| 805 | uint64_t x2, |
| 806 | uint64_t x3, |
| 807 | uint64_t x4, |
| 808 | void *cookie, |
| 809 | void *handle, |
| 810 | uint64_t flags) |
| 811 | { |
| 812 | if (is_spmc_at_el3()) { |
| 813 | /* |
| 814 | * If we have an SPMC at EL3 allow handling of the SMC first. |
| 815 | * The SPMC will call back through to SPMD handler if required. |
| 816 | */ |
| 817 | if (is_caller_secure(flags)) { |
| 818 | return spmc_smc_handler(smc_fid, |
| 819 | is_caller_secure(flags), |
| 820 | x1, x2, x3, x4, cookie, |
| 821 | handle, flags); |
| 822 | } |
| 823 | } |
| 824 | return spmd_smc_handler(smc_fid, x1, x2, x3, x4, cookie, |
| 825 | handle, flags); |
| 826 | } |
| 827 | |
| 828 | /******************************************************************************* |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 829 | * This function handles all SMCs in the range reserved for FFA. Each call is |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 830 | * either forwarded to the other security state or handled by the SPM dispatcher |
| 831 | ******************************************************************************/ |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 832 | uint64_t spmd_smc_handler(uint32_t smc_fid, |
| 833 | uint64_t x1, |
| 834 | uint64_t x2, |
| 835 | uint64_t x3, |
| 836 | uint64_t x4, |
| 837 | void *cookie, |
| 838 | void *handle, |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 839 | uint64_t flags) |
| 840 | { |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 841 | spmd_spm_core_context_t *ctx = spmd_get_context(); |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 842 | bool secure_origin; |
J-Alves | 8676f24 | 2023-10-04 17:16:45 +0100 | [diff] [blame] | 843 | int ret; |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 844 | uint32_t input_version; |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 845 | |
| 846 | /* Determine which security state this SMC originated from */ |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 847 | secure_origin = is_caller_secure(flags); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 848 | |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 849 | VERBOSE("SPM(%u): 0x%x 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 |
| 850 | " 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 "\n", |
Olivier Deprez | 5f875b8 | 2024-06-07 10:22:50 +0200 | [diff] [blame] | 851 | plat_my_core_pos(), smc_fid, x1, x2, x3, x4, |
Scott Branden | e5dcf98 | 2020-08-25 13:49:32 -0700 | [diff] [blame] | 852 | SMC_GET_GP(handle, CTX_GPREG_X5), |
| 853 | SMC_GET_GP(handle, CTX_GPREG_X6), |
| 854 | SMC_GET_GP(handle, CTX_GPREG_X7)); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 855 | |
Raghu Krishnamurthy | 43fda97 | 2023-04-22 11:28:38 -0700 | [diff] [blame] | 856 | /* |
| 857 | * If there is an on-going info regs from EL3 SPMD LP, unconditionally |
| 858 | * return, we don't expect any other FF-A ABIs to be called between |
| 859 | * calls to FFA_PARTITION_INFO_GET_REGS. |
| 860 | */ |
| 861 | if (is_spmd_logical_sp_info_regs_req_in_progress(ctx)) { |
| 862 | assert(secure_origin); |
| 863 | spmd_spm_core_sync_exit(0ULL); |
| 864 | } |
| 865 | |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 866 | switch (smc_fid) { |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 867 | case FFA_ERROR: |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 868 | /* |
| 869 | * Check if this is the first invocation of this interface on |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 870 | * this CPU. If so, then indicate that the SPM Core initialised |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 871 | * unsuccessfully. |
| 872 | */ |
Olivier Deprez | 7c01633 | 2019-10-28 09:03:13 +0000 | [diff] [blame] | 873 | if (secure_origin && (ctx->state == SPMC_STATE_ON_PENDING)) { |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 874 | spmd_spm_core_sync_exit(x2); |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 875 | } |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 876 | |
Raghu Krishnamurthy | 6a30514 | 2023-03-03 06:41:29 -0800 | [diff] [blame] | 877 | /* |
| 878 | * If there was an SPMD logical partition direct request on-going, |
| 879 | * return back to the SPMD logical partition so the error can be |
| 880 | * consumed. |
| 881 | */ |
| 882 | if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { |
| 883 | assert(secure_origin); |
| 884 | spmd_spm_core_sync_exit(0ULL); |
| 885 | } |
| 886 | |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 887 | return spmd_smc_forward(smc_fid, secure_origin, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 888 | x1, x2, x3, x4, cookie, |
| 889 | handle, flags); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 890 | break; /* not reached */ |
| 891 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 892 | case FFA_VERSION: |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 893 | input_version = (uint32_t)(0xFFFFFFFF & x1); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 894 | /* |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 895 | * If caller is secure and SPMC was initialized, |
| 896 | * return FFA_VERSION of SPMD. |
| 897 | * If caller is non secure and SPMC was initialized, |
Marc Bonnici | 815d101 | 2021-12-08 14:27:40 +0000 | [diff] [blame] | 898 | * forward to the EL3 SPMC if enabled, otherwise return |
| 899 | * the SPMC version if implemented at a lower EL. |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 900 | * Sanity check to "input_version". |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 901 | * If the EL3 SPMC is enabled, ignore the SPMC state as |
| 902 | * this is not used. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 903 | */ |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 904 | if ((input_version & FFA_VERSION_BIT31_MASK) || |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 905 | (!is_spmc_at_el3() && (ctx->state == SPMC_STATE_RESET))) { |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 906 | ret = FFA_ERROR_NOT_SUPPORTED; |
| 907 | } else if (!secure_origin) { |
Marc Bonnici | 815d101 | 2021-12-08 14:27:40 +0000 | [diff] [blame] | 908 | if (is_spmc_at_el3()) { |
| 909 | /* |
| 910 | * Forward the call directly to the EL3 SPMC, if |
| 911 | * enabled, as we don't need to wrap the call in |
| 912 | * a direct request. |
| 913 | */ |
| 914 | return spmd_smc_forward(smc_fid, secure_origin, |
| 915 | x1, x2, x3, x4, cookie, |
| 916 | handle, flags); |
| 917 | } |
| 918 | |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 919 | gp_regs_t *gpregs = get_gpregs_ctx(&ctx->cpu_ctx); |
| 920 | uint64_t rc; |
| 921 | |
| 922 | if (spmc_attrs.major_version == 1 && |
| 923 | spmc_attrs.minor_version == 0) { |
| 924 | ret = MAKE_FFA_VERSION(spmc_attrs.major_version, |
| 925 | spmc_attrs.minor_version); |
| 926 | SMC_RET8(handle, (uint32_t)ret, |
| 927 | FFA_TARGET_INFO_MBZ, |
| 928 | FFA_TARGET_INFO_MBZ, |
| 929 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 930 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 931 | FFA_PARAM_MBZ); |
| 932 | break; |
| 933 | } |
| 934 | /* Save non-secure system registers context */ |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 935 | #if SPMD_SPM_AT_SEL2 |
| 936 | cm_el2_sysregs_context_save(NON_SECURE); |
Madhukar Pappireddy | d3f3207 | 2024-01-29 16:43:56 -0600 | [diff] [blame] | 937 | #else |
| 938 | cm_el1_sysregs_context_save(NON_SECURE); |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 939 | #endif |
| 940 | |
| 941 | /* |
| 942 | * The incoming request has FFA_VERSION as X0 smc_fid |
| 943 | * and requested version in x1. Prepare a direct request |
| 944 | * from SPMD to SPMC with FFA_VERSION framework function |
| 945 | * identifier in X2 and requested version in X3. |
| 946 | */ |
| 947 | spmd_build_spmc_message(gpregs, |
| 948 | SPMD_FWK_MSG_FFA_VERSION_REQ, |
| 949 | input_version); |
| 950 | |
Olivier Deprez | 4911eb8 | 2023-07-10 11:04:30 +0200 | [diff] [blame] | 951 | /* |
| 952 | * Ensure x8-x17 NS GP register values are untouched when returning |
| 953 | * from the SPMC. |
| 954 | */ |
| 955 | write_ctx_reg(gpregs, CTX_GPREG_X8, SMC_GET_GP(handle, CTX_GPREG_X8)); |
| 956 | write_ctx_reg(gpregs, CTX_GPREG_X9, SMC_GET_GP(handle, CTX_GPREG_X9)); |
| 957 | write_ctx_reg(gpregs, CTX_GPREG_X10, SMC_GET_GP(handle, CTX_GPREG_X10)); |
| 958 | write_ctx_reg(gpregs, CTX_GPREG_X11, SMC_GET_GP(handle, CTX_GPREG_X11)); |
| 959 | write_ctx_reg(gpregs, CTX_GPREG_X12, SMC_GET_GP(handle, CTX_GPREG_X12)); |
| 960 | write_ctx_reg(gpregs, CTX_GPREG_X13, SMC_GET_GP(handle, CTX_GPREG_X13)); |
| 961 | write_ctx_reg(gpregs, CTX_GPREG_X14, SMC_GET_GP(handle, CTX_GPREG_X14)); |
| 962 | write_ctx_reg(gpregs, CTX_GPREG_X15, SMC_GET_GP(handle, CTX_GPREG_X15)); |
| 963 | write_ctx_reg(gpregs, CTX_GPREG_X16, SMC_GET_GP(handle, CTX_GPREG_X16)); |
| 964 | write_ctx_reg(gpregs, CTX_GPREG_X17, SMC_GET_GP(handle, CTX_GPREG_X17)); |
| 965 | |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 966 | rc = spmd_spm_core_sync_entry(ctx); |
| 967 | |
| 968 | if ((rc != 0ULL) || |
| 969 | (SMC_GET_GP(gpregs, CTX_GPREG_X0) != |
| 970 | FFA_MSG_SEND_DIRECT_RESP_SMC32) || |
| 971 | (SMC_GET_GP(gpregs, CTX_GPREG_X2) != |
Marc Bonnici | 25f4b54 | 2022-04-12 17:18:13 +0100 | [diff] [blame] | 972 | (FFA_FWK_MSG_BIT | |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 973 | SPMD_FWK_MSG_FFA_VERSION_RESP))) { |
| 974 | ERROR("Failed to forward FFA_VERSION\n"); |
| 975 | ret = FFA_ERROR_NOT_SUPPORTED; |
| 976 | } else { |
| 977 | ret = SMC_GET_GP(gpregs, CTX_GPREG_X3); |
| 978 | } |
| 979 | |
| 980 | /* |
Olivier Deprez | 4911eb8 | 2023-07-10 11:04:30 +0200 | [diff] [blame] | 981 | * x0-x4 are updated by spmd_smc_forward below. |
| 982 | * Zero out x5-x7 in the FFA_VERSION response. |
| 983 | */ |
| 984 | write_ctx_reg(gpregs, CTX_GPREG_X5, 0); |
| 985 | write_ctx_reg(gpregs, CTX_GPREG_X6, 0); |
| 986 | write_ctx_reg(gpregs, CTX_GPREG_X7, 0); |
| 987 | |
| 988 | /* |
Daniel Boulby | 9460a23 | 2021-12-09 11:20:13 +0000 | [diff] [blame] | 989 | * Return here after SPMC has handled FFA_VERSION. |
| 990 | * The returned SPMC version is held in X3. |
| 991 | * Forward this version in X0 to the non-secure caller. |
| 992 | */ |
| 993 | return spmd_smc_forward(ret, true, FFA_PARAM_MBZ, |
| 994 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 995 | FFA_PARAM_MBZ, cookie, gpregs, |
| 996 | flags); |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 997 | } else { |
J-Alves | 64ff993 | 2021-03-01 10:26:59 +0000 | [diff] [blame] | 998 | ret = MAKE_FFA_VERSION(FFA_VERSION_MAJOR, |
| 999 | FFA_VERSION_MINOR); |
J-Alves | 4c95c70 | 2020-05-26 14:03:05 +0100 | [diff] [blame] | 1000 | } |
| 1001 | |
J-Alves | 64ff993 | 2021-03-01 10:26:59 +0000 | [diff] [blame] | 1002 | SMC_RET8(handle, (uint32_t)ret, FFA_TARGET_INFO_MBZ, |
| 1003 | FFA_TARGET_INFO_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1004 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1005 | break; /* not reached */ |
| 1006 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1007 | case FFA_FEATURES: |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1008 | /* |
| 1009 | * This is an optional interface. Do the minimal checks and |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1010 | * forward to SPM Core which will handle it if implemented. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1011 | */ |
| 1012 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1013 | /* Forward SMC from Normal world to the SPM Core */ |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 1014 | if (!secure_origin) { |
| 1015 | return spmd_smc_forward(smc_fid, secure_origin, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 1016 | x1, x2, x3, x4, cookie, |
| 1017 | handle, flags); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1018 | } |
Max Shvetsov | 745889c | 2020-02-27 14:54:21 +0000 | [diff] [blame] | 1019 | |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1020 | /* |
| 1021 | * Return success if call was from secure world i.e. all |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1022 | * FFA functions are supported. This is essentially a |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1023 | * nop. |
| 1024 | */ |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1025 | SMC_RET8(handle, FFA_SUCCESS_SMC32, x1, x2, x3, x4, |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1026 | SMC_GET_GP(handle, CTX_GPREG_X5), |
| 1027 | SMC_GET_GP(handle, CTX_GPREG_X6), |
| 1028 | SMC_GET_GP(handle, CTX_GPREG_X7)); |
| 1029 | |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1030 | break; /* not reached */ |
| 1031 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1032 | case FFA_ID_GET: |
Max Shvetsov | e79062e | 2020-03-12 15:16:40 +0000 | [diff] [blame] | 1033 | /* |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1034 | * Returns the ID of the calling FFA component. |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1035 | */ |
Max Shvetsov | e79062e | 2020-03-12 15:16:40 +0000 | [diff] [blame] | 1036 | if (!secure_origin) { |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1037 | SMC_RET8(handle, FFA_SUCCESS_SMC32, |
| 1038 | FFA_TARGET_INFO_MBZ, FFA_NS_ENDPOINT_ID, |
| 1039 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1040 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1041 | FFA_PARAM_MBZ); |
Max Shvetsov | e79062e | 2020-03-12 15:16:40 +0000 | [diff] [blame] | 1042 | } |
| 1043 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1044 | SMC_RET8(handle, FFA_SUCCESS_SMC32, |
| 1045 | FFA_TARGET_INFO_MBZ, spmc_attrs.spmc_id, |
| 1046 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1047 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1048 | FFA_PARAM_MBZ); |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1049 | |
Max Shvetsov | e79062e | 2020-03-12 15:16:40 +0000 | [diff] [blame] | 1050 | break; /* not reached */ |
| 1051 | |
Olivier Deprez | eae4596 | 2021-01-19 15:06:47 +0100 | [diff] [blame] | 1052 | case FFA_SECONDARY_EP_REGISTER_SMC64: |
| 1053 | if (secure_origin) { |
| 1054 | ret = spmd_pm_secondary_ep_register(x1); |
| 1055 | |
| 1056 | if (ret < 0) { |
| 1057 | SMC_RET8(handle, FFA_ERROR_SMC64, |
| 1058 | FFA_TARGET_INFO_MBZ, ret, |
| 1059 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1060 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1061 | FFA_PARAM_MBZ); |
| 1062 | } else { |
| 1063 | SMC_RET8(handle, FFA_SUCCESS_SMC64, |
| 1064 | FFA_TARGET_INFO_MBZ, FFA_PARAM_MBZ, |
| 1065 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1066 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1067 | FFA_PARAM_MBZ); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); |
| 1072 | break; /* Not reached */ |
| 1073 | |
Daniel Boulby | 27f35df | 2021-02-03 12:13:19 +0000 | [diff] [blame] | 1074 | case FFA_SPM_ID_GET: |
| 1075 | if (MAKE_FFA_VERSION(1, 1) > FFA_VERSION_COMPILED) { |
| 1076 | return spmd_ffa_error_return(handle, |
| 1077 | FFA_ERROR_NOT_SUPPORTED); |
| 1078 | } |
| 1079 | /* |
| 1080 | * Returns the ID of the SPMC or SPMD depending on the FF-A |
| 1081 | * instance where this function is invoked |
| 1082 | */ |
| 1083 | if (!secure_origin) { |
| 1084 | SMC_RET8(handle, FFA_SUCCESS_SMC32, |
| 1085 | FFA_TARGET_INFO_MBZ, spmc_attrs.spmc_id, |
| 1086 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1087 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1088 | FFA_PARAM_MBZ); |
| 1089 | } |
| 1090 | SMC_RET8(handle, FFA_SUCCESS_SMC32, |
| 1091 | FFA_TARGET_INFO_MBZ, SPMD_DIRECT_MSG_ENDPOINT_ID, |
| 1092 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1093 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1094 | FFA_PARAM_MBZ); |
| 1095 | |
| 1096 | break; /* not reached */ |
| 1097 | |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 1098 | case FFA_MSG_SEND_DIRECT_REQ_SMC32: |
Shruti | 3d85967 | 2022-06-09 11:03:11 +0100 | [diff] [blame] | 1099 | case FFA_MSG_SEND_DIRECT_REQ_SMC64: |
Raghu Krishnamurthy | 6a30514 | 2023-03-03 06:41:29 -0800 | [diff] [blame] | 1100 | /* |
| 1101 | * Regardless of secure_origin, SPMD logical partitions cannot |
| 1102 | * handle direct messages. They can only initiate direct |
| 1103 | * messages and consume direct responses or errors. |
| 1104 | */ |
| 1105 | if (is_spmd_lp_id(ffa_endpoint_source(x1)) || |
| 1106 | is_spmd_lp_id(ffa_endpoint_destination(x1))) { |
| 1107 | return spmd_ffa_error_return(handle, |
| 1108 | FFA_ERROR_INVALID_PARAMETER |
| 1109 | ); |
| 1110 | } |
| 1111 | |
| 1112 | /* |
| 1113 | * When there is an ongoing SPMD logical partition direct |
| 1114 | * request, there cannot be another direct request. Return |
| 1115 | * error in this case. Panic'ing is an option but that does |
| 1116 | * not provide the opportunity for caller to abort based on |
| 1117 | * error codes. |
| 1118 | */ |
| 1119 | if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { |
| 1120 | assert(secure_origin); |
| 1121 | return spmd_ffa_error_return(handle, |
| 1122 | FFA_ERROR_DENIED); |
| 1123 | } |
| 1124 | |
Shruti | 3d85967 | 2022-06-09 11:03:11 +0100 | [diff] [blame] | 1125 | if (!secure_origin) { |
| 1126 | /* Validate source endpoint is non-secure for non-secure caller. */ |
| 1127 | if (ffa_is_secure_world_id(ffa_endpoint_source(x1))) { |
| 1128 | return spmd_ffa_error_return(handle, |
| 1129 | FFA_ERROR_INVALID_PARAMETER); |
| 1130 | } |
| 1131 | } |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 1132 | if (secure_origin && spmd_is_spmc_message(x1)) { |
| 1133 | ret = spmd_handle_spmc_message(x3, x4, |
| 1134 | SMC_GET_GP(handle, CTX_GPREG_X5), |
| 1135 | SMC_GET_GP(handle, CTX_GPREG_X6), |
| 1136 | SMC_GET_GP(handle, CTX_GPREG_X7)); |
| 1137 | |
| 1138 | SMC_RET8(handle, FFA_SUCCESS_SMC32, |
| 1139 | FFA_TARGET_INFO_MBZ, ret, |
| 1140 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1141 | FFA_PARAM_MBZ, FFA_PARAM_MBZ, |
| 1142 | FFA_PARAM_MBZ); |
| 1143 | } else { |
| 1144 | /* Forward direct message to the other world */ |
| 1145 | return spmd_smc_forward(smc_fid, secure_origin, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 1146 | x1, x2, x3, x4, cookie, |
| 1147 | handle, flags); |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 1148 | } |
| 1149 | break; /* Not reached */ |
| 1150 | |
Kathleen Capella | 9d826a1 | 2023-07-31 14:45:58 -0400 | [diff] [blame] | 1151 | case FFA_MSG_SEND_DIRECT_REQ2_SMC64: |
| 1152 | if (!secure_origin) { |
| 1153 | /* Validate source endpoint is non-secure for non-secure caller. */ |
| 1154 | if (ffa_is_secure_world_id(ffa_endpoint_source(x1))) { |
| 1155 | return spmd_ffa_error_return(handle, |
| 1156 | FFA_ERROR_INVALID_PARAMETER); |
| 1157 | } |
| 1158 | } |
| 1159 | /* FFA_MSG_SEND_DIRECT_REQ2 not used for framework messages. */ |
| 1160 | if (secure_origin && spmd_is_spmc_message(x1)) { |
| 1161 | return spmd_ffa_error_return(handle, FFA_ERROR_INVALID_PARAMETER); |
| 1162 | } else { |
| 1163 | /* Forward direct message to the other world */ |
| 1164 | return spmd_smc_forward(smc_fid, secure_origin, |
| 1165 | x1, x2, x3, x4, cookie, |
| 1166 | handle, flags); |
| 1167 | } |
| 1168 | break; /* Not reached */ |
| 1169 | |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 1170 | case FFA_MSG_SEND_DIRECT_RESP_SMC32: |
Raghu Krishnamurthy | 6a30514 | 2023-03-03 06:41:29 -0800 | [diff] [blame] | 1171 | case FFA_MSG_SEND_DIRECT_RESP_SMC64: |
| 1172 | if (secure_origin && (spmd_is_spmc_message(x1) || |
| 1173 | is_spmd_logical_sp_dir_req_in_progress(ctx))) { |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 1174 | spmd_spm_core_sync_exit(0ULL); |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 1175 | } else { |
| 1176 | /* Forward direct message to the other world */ |
| 1177 | return spmd_smc_forward(smc_fid, secure_origin, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 1178 | x1, x2, x3, x4, cookie, |
| 1179 | handle, flags); |
Olivier Deprez | 33e4412 | 2020-04-16 17:54:27 +0200 | [diff] [blame] | 1180 | } |
| 1181 | break; /* Not reached */ |
Kathleen Capella | a85a9d1 | 2023-09-08 17:45:45 -0400 | [diff] [blame] | 1182 | case FFA_MSG_SEND_DIRECT_RESP2_SMC64: |
| 1183 | /* Forward direct message to the other world */ |
| 1184 | return spmd_smc_forward(smc_fid, secure_origin, |
| 1185 | x1, x2, x3, x4, cookie, |
| 1186 | handle, flags); |
| 1187 | break; /* Not reached */ |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1188 | case FFA_RX_RELEASE: |
| 1189 | case FFA_RXTX_MAP_SMC32: |
| 1190 | case FFA_RXTX_MAP_SMC64: |
| 1191 | case FFA_RXTX_UNMAP: |
Ruari Phipps | 93dff70 | 2020-07-28 10:33:35 +0100 | [diff] [blame] | 1192 | case FFA_PARTITION_INFO_GET: |
J-Alves | 2621cfd | 2021-03-11 17:46:47 +0000 | [diff] [blame] | 1193 | #if MAKE_FFA_VERSION(1, 1) <= FFA_VERSION_COMPILED |
| 1194 | case FFA_NOTIFICATION_BITMAP_CREATE: |
| 1195 | case FFA_NOTIFICATION_BITMAP_DESTROY: |
| 1196 | case FFA_NOTIFICATION_BIND: |
| 1197 | case FFA_NOTIFICATION_UNBIND: |
| 1198 | case FFA_NOTIFICATION_SET: |
| 1199 | case FFA_NOTIFICATION_GET: |
| 1200 | case FFA_NOTIFICATION_INFO_GET: |
| 1201 | case FFA_NOTIFICATION_INFO_GET_SMC64: |
Federico Recanati | eecb4b0 | 2022-02-03 17:22:37 +0100 | [diff] [blame] | 1202 | case FFA_MSG_SEND2: |
Federico Recanati | 5c7c5c4 | 2022-03-18 10:30:00 +0100 | [diff] [blame] | 1203 | case FFA_RX_ACQUIRE: |
J-Alves | 2621cfd | 2021-03-11 17:46:47 +0000 | [diff] [blame] | 1204 | #endif |
Federico Recanati | eecb4b0 | 2022-02-03 17:22:37 +0100 | [diff] [blame] | 1205 | case FFA_MSG_RUN: |
Ruari Phipps | 93dff70 | 2020-07-28 10:33:35 +0100 | [diff] [blame] | 1206 | /* |
Federico Recanati | eecb4b0 | 2022-02-03 17:22:37 +0100 | [diff] [blame] | 1207 | * Above calls should be invoked only by the Normal world and |
| 1208 | * must not be forwarded from Secure world to Normal world. |
Ruari Phipps | 93dff70 | 2020-07-28 10:33:35 +0100 | [diff] [blame] | 1209 | */ |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 1210 | if (secure_origin) { |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1211 | return spmd_ffa_error_return(handle, |
Ruari Phipps | 93dff70 | 2020-07-28 10:33:35 +0100 | [diff] [blame] | 1212 | FFA_ERROR_NOT_SUPPORTED); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1213 | } |
| 1214 | |
Boyan Karatotev | 8726600 | 2022-11-18 14:17:17 +0000 | [diff] [blame] | 1215 | /* Forward the call to the other world */ |
| 1216 | /* fallthrough */ |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1217 | case FFA_MSG_SEND: |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1218 | case FFA_MEM_DONATE_SMC32: |
| 1219 | case FFA_MEM_DONATE_SMC64: |
| 1220 | case FFA_MEM_LEND_SMC32: |
| 1221 | case FFA_MEM_LEND_SMC64: |
| 1222 | case FFA_MEM_SHARE_SMC32: |
| 1223 | case FFA_MEM_SHARE_SMC64: |
| 1224 | case FFA_MEM_RETRIEVE_REQ_SMC32: |
| 1225 | case FFA_MEM_RETRIEVE_REQ_SMC64: |
| 1226 | case FFA_MEM_RETRIEVE_RESP: |
| 1227 | case FFA_MEM_RELINQUISH: |
| 1228 | case FFA_MEM_RECLAIM: |
Marc Bonnici | 9fa01e9 | 2021-09-23 09:44:14 +0100 | [diff] [blame] | 1229 | case FFA_MEM_FRAG_TX: |
| 1230 | case FFA_MEM_FRAG_RX: |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1231 | case FFA_SUCCESS_SMC32: |
| 1232 | case FFA_SUCCESS_SMC64: |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1233 | /* |
Raghu Krishnamurthy | 6a30514 | 2023-03-03 06:41:29 -0800 | [diff] [blame] | 1234 | * If there is an ongoing direct request from an SPMD logical |
| 1235 | * partition, return an error. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1236 | */ |
Raghu Krishnamurthy | 6a30514 | 2023-03-03 06:41:29 -0800 | [diff] [blame] | 1237 | if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { |
| 1238 | assert(secure_origin); |
| 1239 | return spmd_ffa_error_return(handle, |
| 1240 | FFA_ERROR_DENIED); |
| 1241 | } |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1242 | |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 1243 | return spmd_smc_forward(smc_fid, secure_origin, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 1244 | x1, x2, x3, x4, cookie, |
| 1245 | handle, flags); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1246 | break; /* not reached */ |
| 1247 | |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1248 | case FFA_MSG_WAIT: |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1249 | /* |
| 1250 | * Check if this is the first invocation of this interface on |
| 1251 | * this CPU from the Secure world. If so, then indicate that the |
Olivier Deprez | 2bae35f | 2020-04-16 13:39:06 +0200 | [diff] [blame] | 1252 | * SPM Core initialised successfully. |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1253 | */ |
Olivier Deprez | 7c01633 | 2019-10-28 09:03:13 +0000 | [diff] [blame] | 1254 | if (secure_origin && (ctx->state == SPMC_STATE_ON_PENDING)) { |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 1255 | spmd_spm_core_sync_exit(0ULL); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1256 | } |
| 1257 | |
Boyan Karatotev | 8726600 | 2022-11-18 14:17:17 +0000 | [diff] [blame] | 1258 | /* Forward the call to the other world */ |
| 1259 | /* fallthrough */ |
Olivier Deprez | ae18caf | 2021-04-02 11:09:10 +0200 | [diff] [blame] | 1260 | case FFA_INTERRUPT: |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1261 | case FFA_MSG_YIELD: |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1262 | /* This interface must be invoked only by the Secure world */ |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 1263 | if (!secure_origin) { |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1264 | return spmd_ffa_error_return(handle, |
| 1265 | FFA_ERROR_NOT_SUPPORTED); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1266 | } |
| 1267 | |
Raghu Krishnamurthy | 6a30514 | 2023-03-03 06:41:29 -0800 | [diff] [blame] | 1268 | if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { |
| 1269 | assert(secure_origin); |
| 1270 | return spmd_ffa_error_return(handle, |
| 1271 | FFA_ERROR_DENIED); |
| 1272 | } |
| 1273 | |
Olivier Deprez | 41ff36a | 2019-12-23 16:21:12 +0100 | [diff] [blame] | 1274 | return spmd_smc_forward(smc_fid, secure_origin, |
Marc Bonnici | da2c9e1 | 2021-11-29 18:02:45 +0000 | [diff] [blame] | 1275 | x1, x2, x3, x4, cookie, |
| 1276 | handle, flags); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1277 | break; /* not reached */ |
| 1278 | |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 1279 | case FFA_NORMAL_WORLD_RESUME: |
| 1280 | if (secure_origin && ctx->secure_interrupt_ongoing) { |
| 1281 | spmd_spm_core_sync_exit(0ULL); |
| 1282 | } else { |
| 1283 | return spmd_ffa_error_return(handle, FFA_ERROR_DENIED); |
| 1284 | } |
| 1285 | break; /* Not reached */ |
Raghu Krishnamurthy | 435f11c | 2022-12-25 13:02:00 -0800 | [diff] [blame] | 1286 | #if MAKE_FFA_VERSION(1, 1) <= FFA_VERSION_COMPILED |
| 1287 | case FFA_PARTITION_INFO_GET_REGS_SMC64: |
| 1288 | if (secure_origin) { |
Raghu Krishnamurthy | 9d9584f | 2023-04-22 18:00:02 -0700 | [diff] [blame] | 1289 | return spmd_el3_populate_logical_partition_info(handle, x1, |
| 1290 | x2, x3); |
Raghu Krishnamurthy | 435f11c | 2022-12-25 13:02:00 -0800 | [diff] [blame] | 1291 | } |
Olivier Deprez | a664c49 | 2020-08-05 11:27:42 +0200 | [diff] [blame] | 1292 | |
Raghu Krishnamurthy | 435f11c | 2022-12-25 13:02:00 -0800 | [diff] [blame] | 1293 | /* Call only supported with SMCCC 1.2+ */ |
| 1294 | if (MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION) < 0x10002) { |
| 1295 | return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); |
| 1296 | } |
| 1297 | |
| 1298 | return spmd_smc_forward(smc_fid, secure_origin, |
| 1299 | x1, x2, x3, x4, cookie, |
| 1300 | handle, flags); |
| 1301 | break; /* Not reached */ |
| 1302 | #endif |
Shruti Gupta | a5a1cbd | 2023-01-19 21:50:55 +0000 | [diff] [blame] | 1303 | case FFA_CONSOLE_LOG_SMC32: |
| 1304 | case FFA_CONSOLE_LOG_SMC64: |
| 1305 | /* This interface must not be forwarded to other worlds. */ |
| 1306 | return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); |
| 1307 | break; /* not reached */ |
| 1308 | |
Madhukar Pappireddy | 41416cc | 2023-03-02 16:04:38 -0600 | [diff] [blame] | 1309 | case FFA_EL3_INTR_HANDLE: |
| 1310 | if (secure_origin) { |
| 1311 | return spmd_handle_group0_intr_swd(handle); |
| 1312 | } else { |
Madhukar Pappireddy | 2ca7570 | 2023-07-12 16:28:05 -0500 | [diff] [blame] | 1313 | return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); |
Madhukar Pappireddy | 41416cc | 2023-03-02 16:04:38 -0600 | [diff] [blame] | 1314 | } |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1315 | default: |
| 1316 | WARN("SPM: Unsupported call 0x%08x\n", smc_fid); |
J-Alves | 2672cde | 2020-05-07 18:42:25 +0100 | [diff] [blame] | 1317 | return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); |
Achin Gupta | 86f2353 | 2019-10-11 15:41:16 +0100 | [diff] [blame] | 1318 | } |
| 1319 | } |