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