blob: 649fe9f7a8f85022a117bd1e6e570632c5e46893 [file] [log] [blame]
Achin Gupta86f23532019-10-11 15:41:16 +01001/*
Daniel Boulby9460a232021-12-09 11:20:13 +00002 * Copyright (c) 2020-2022, ARM Limited and Contributors. All rights reserved.
Achin Gupta86f23532019-10-11 15:41:16 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
8#include <errno.h>
Scott Brandene5dcf982020-08-25 13:49:32 -07009#include <inttypes.h>
10#include <stdint.h>
Achin Gupta86f23532019-10-11 15:41:16 +010011#include <string.h>
12
13#include <arch_helpers.h>
Olivier Deprez2bae35f2020-04-16 13:39:06 +020014#include <arch/aarch64/arch_features.h>
Achin Gupta86f23532019-10-11 15:41:16 +010015#include <bl31/bl31.h>
Olivier Depreza664c492020-08-05 11:27:42 +020016#include <bl31/interrupt_mgmt.h>
Achin Gupta86f23532019-10-11 15:41:16 +010017#include <common/debug.h>
18#include <common/runtime_svc.h>
19#include <lib/el3_runtime/context_mgmt.h>
20#include <lib/smccc.h>
21#include <lib/spinlock.h>
22#include <lib/utils.h>
Achin Gupta86f23532019-10-11 15:41:16 +010023#include <plat/common/common_def.h>
24#include <plat/common/platform.h>
25#include <platform_def.h>
J-Alves2672cde2020-05-07 18:42:25 +010026#include <services/ffa_svc.h>
Achin Gupta86f23532019-10-11 15:41:16 +010027#include <services/spmd_svc.h>
28#include <smccc_helpers.h>
29#include "spmd_private.h"
30
31/*******************************************************************************
32 * SPM Core context information.
33 ******************************************************************************/
Olivier Deprez2bae35f2020-04-16 13:39:06 +020034static spmd_spm_core_context_t spm_core_context[PLATFORM_CORE_COUNT];
Achin Gupta86f23532019-10-11 15:41:16 +010035
36/*******************************************************************************
37 * SPM Core attribute information read from its manifest.
38 ******************************************************************************/
Olivier Deprez2bae35f2020-04-16 13:39:06 +020039static spmc_manifest_attribute_t spmc_attrs;
Achin Gupta86f23532019-10-11 15:41:16 +010040
41/*******************************************************************************
Max Shvetsov745889c2020-02-27 14:54:21 +000042 * SPM Core entry point information. Discovered on the primary core and reused
43 * on secondary cores.
44 ******************************************************************************/
45static entry_point_info_t *spmc_ep_info;
46
47/*******************************************************************************
Olivier Deprez73ef0dc2020-06-19 15:33:41 +020048 * SPM Core context on CPU based on mpidr.
49 ******************************************************************************/
50spmd_spm_core_context_t *spmd_get_context_by_mpidr(uint64_t mpidr)
51{
Max Shvetsovf80c64d2020-08-25 11:50:18 +010052 int core_idx = plat_core_pos_by_mpidr(mpidr);
53
54 if (core_idx < 0) {
Scott Brandene5dcf982020-08-25 13:49:32 -070055 ERROR("Invalid mpidr: %" PRIx64 ", returned ID: %d\n", mpidr, core_idx);
Max Shvetsovf80c64d2020-08-25 11:50:18 +010056 panic();
57 }
58
59 return &spm_core_context[core_idx];
Olivier Deprez73ef0dc2020-06-19 15:33:41 +020060}
61
62/*******************************************************************************
Olivier Deprez2bae35f2020-04-16 13:39:06 +020063 * SPM Core context on current CPU get helper.
64 ******************************************************************************/
65spmd_spm_core_context_t *spmd_get_context(void)
66{
Olivier Deprez73ef0dc2020-06-19 15:33:41 +020067 return spmd_get_context_by_mpidr(read_mpidr());
Olivier Deprez2bae35f2020-04-16 13:39:06 +020068}
69
70/*******************************************************************************
Olivier Deprezc7631a52020-03-23 09:53:06 +010071 * SPM Core ID getter.
72 ******************************************************************************/
73uint16_t spmd_spmc_id_get(void)
74{
75 return spmc_attrs.spmc_id;
76}
77
78/*******************************************************************************
Max Shvetsov745889c2020-02-27 14:54:21 +000079 * Static function declaration.
80 ******************************************************************************/
Olivier Deprez2bae35f2020-04-16 13:39:06 +020081static int32_t spmd_init(void);
Olivier Deprez69ca84a2020-02-07 15:44:43 +010082static int spmd_spmc_init(void *pm_addr);
J-Alves2672cde2020-05-07 18:42:25 +010083static uint64_t spmd_ffa_error_return(void *handle,
Olivier Deprez2bae35f2020-04-16 13:39:06 +020084 int error_code);
85static uint64_t spmd_smc_forward(uint32_t smc_fid,
86 bool secure_origin,
87 uint64_t x1,
88 uint64_t x2,
89 uint64_t x3,
90 uint64_t x4,
91 void *handle);
Max Shvetsov745889c2020-02-27 14:54:21 +000092
Daniel Boulby9460a232021-12-09 11:20:13 +000093/******************************************************************************
94 * Builds an SPMD to SPMC direct message request.
95 *****************************************************************************/
96void spmd_build_spmc_message(gp_regs_t *gpregs, uint8_t target_func,
97 unsigned long long message)
98{
99 write_ctx_reg(gpregs, CTX_GPREG_X0, FFA_MSG_SEND_DIRECT_REQ_SMC32);
100 write_ctx_reg(gpregs, CTX_GPREG_X1,
101 (SPMD_DIRECT_MSG_ENDPOINT_ID << FFA_DIRECT_MSG_SOURCE_SHIFT) |
102 spmd_spmc_id_get());
103 write_ctx_reg(gpregs, CTX_GPREG_X2, BIT(31) | target_func);
104 write_ctx_reg(gpregs, CTX_GPREG_X3, message);
105}
106
107
Max Shvetsov745889c2020-02-27 14:54:21 +0000108/*******************************************************************************
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200109 * This function takes an SPMC context pointer and performs a synchronous
110 * SPMC entry.
Achin Gupta86f23532019-10-11 15:41:16 +0100111 ******************************************************************************/
112uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *spmc_ctx)
113{
114 uint64_t rc;
115
116 assert(spmc_ctx != NULL);
117
118 cm_set_context(&(spmc_ctx->cpu_ctx), SECURE);
119
120 /* Restore the context assigned above */
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000121#if SPMD_SPM_AT_SEL2
Max Shvetsovbdf502d2020-02-25 13:56:19 +0000122 cm_el2_sysregs_context_restore(SECURE);
Olivier Deprez9a2e5be2021-05-21 18:00:04 +0200123#else
124 cm_el1_sysregs_context_restore(SECURE);
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000125#endif
Achin Gupta86f23532019-10-11 15:41:16 +0100126 cm_set_next_eret_context(SECURE);
127
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000128 /* Enter SPMC */
Achin Gupta86f23532019-10-11 15:41:16 +0100129 rc = spmd_spm_core_enter(&spmc_ctx->c_rt_ctx);
130
131 /* Save secure state */
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000132#if SPMD_SPM_AT_SEL2
Max Shvetsovbdf502d2020-02-25 13:56:19 +0000133 cm_el2_sysregs_context_save(SECURE);
Olivier Deprez9a2e5be2021-05-21 18:00:04 +0200134#else
135 cm_el1_sysregs_context_save(SECURE);
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000136#endif
Achin Gupta86f23532019-10-11 15:41:16 +0100137
138 return rc;
139}
140
141/*******************************************************************************
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200142 * This function returns to the place where spmd_spm_core_sync_entry() was
Achin Gupta86f23532019-10-11 15:41:16 +0100143 * called originally.
144 ******************************************************************************/
145__dead2 void spmd_spm_core_sync_exit(uint64_t rc)
146{
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200147 spmd_spm_core_context_t *ctx = spmd_get_context();
Achin Gupta86f23532019-10-11 15:41:16 +0100148
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200149 /* Get current CPU context from SPMC context */
Achin Gupta86f23532019-10-11 15:41:16 +0100150 assert(cm_get_context(SECURE) == &(ctx->cpu_ctx));
151
152 /*
153 * The SPMD must have initiated the original request through a
154 * synchronous entry into SPMC. Jump back to the original C runtime
155 * context with the value of rc in x0;
156 */
157 spmd_spm_core_exit(ctx->c_rt_ctx, rc);
158
159 panic();
160}
161
162/*******************************************************************************
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200163 * Jump to the SPM Core for the first time.
Achin Gupta86f23532019-10-11 15:41:16 +0100164 ******************************************************************************/
165static int32_t spmd_init(void)
166{
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200167 spmd_spm_core_context_t *ctx = spmd_get_context();
168 uint64_t rc;
Achin Gupta86f23532019-10-11 15:41:16 +0100169
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200170 VERBOSE("SPM Core init start.\n");
Olivier Deprez7c016332019-10-28 09:03:13 +0000171
Olivier Deprez4ab7a4a2021-06-21 09:47:13 +0200172 /* Primary boot core enters the SPMC for initialization. */
173 ctx->state = SPMC_STATE_ON_PENDING;
Achin Gupta86f23532019-10-11 15:41:16 +0100174
175 rc = spmd_spm_core_sync_entry(ctx);
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200176 if (rc != 0ULL) {
Scott Brandene5dcf982020-08-25 13:49:32 -0700177 ERROR("SPMC initialisation failed 0x%" PRIx64 "\n", rc);
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200178 return 0;
Achin Gupta86f23532019-10-11 15:41:16 +0100179 }
180
Olivier Deprez7c016332019-10-28 09:03:13 +0000181 ctx->state = SPMC_STATE_ON;
182
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200183 VERBOSE("SPM Core init end.\n");
Achin Gupta86f23532019-10-11 15:41:16 +0100184
185 return 1;
186}
187
188/*******************************************************************************
Olivier Depreza664c492020-08-05 11:27:42 +0200189 * spmd_secure_interrupt_handler
190 * Enter the SPMC for further handling of the secure interrupt by the SPMC
191 * itself or a Secure Partition.
192 ******************************************************************************/
193static uint64_t spmd_secure_interrupt_handler(uint32_t id,
194 uint32_t flags,
195 void *handle,
196 void *cookie)
197{
198 spmd_spm_core_context_t *ctx = spmd_get_context();
199 gp_regs_t *gpregs = get_gpregs_ctx(&ctx->cpu_ctx);
200 unsigned int linear_id = plat_my_core_pos();
201 int64_t rc;
202
203 /* Sanity check the security state when the exception was generated */
204 assert(get_interrupt_src_ss(flags) == NON_SECURE);
205
206 /* Sanity check the pointer to this cpu's context */
207 assert(handle == cm_get_context(NON_SECURE));
208
209 /* Save the non-secure context before entering SPMC */
210 cm_el1_sysregs_context_save(NON_SECURE);
211#if SPMD_SPM_AT_SEL2
212 cm_el2_sysregs_context_save(NON_SECURE);
213#endif
214
215 /* Convey the event to the SPMC through the FFA_INTERRUPT interface. */
216 write_ctx_reg(gpregs, CTX_GPREG_X0, FFA_INTERRUPT);
217 write_ctx_reg(gpregs, CTX_GPREG_X1, 0);
218 write_ctx_reg(gpregs, CTX_GPREG_X2, 0);
219 write_ctx_reg(gpregs, CTX_GPREG_X3, 0);
220 write_ctx_reg(gpregs, CTX_GPREG_X4, 0);
221 write_ctx_reg(gpregs, CTX_GPREG_X5, 0);
222 write_ctx_reg(gpregs, CTX_GPREG_X6, 0);
223 write_ctx_reg(gpregs, CTX_GPREG_X7, 0);
224
225 /* Mark current core as handling a secure interrupt. */
226 ctx->secure_interrupt_ongoing = true;
227
228 rc = spmd_spm_core_sync_entry(ctx);
229 if (rc != 0ULL) {
Olivier Deprezba100f22021-11-09 12:37:20 +0100230 ERROR("%s failed (%" PRId64 ") on CPU%u\n", __func__, rc, linear_id);
Olivier Depreza664c492020-08-05 11:27:42 +0200231 }
232
233 ctx->secure_interrupt_ongoing = false;
234
235 cm_el1_sysregs_context_restore(NON_SECURE);
236#if SPMD_SPM_AT_SEL2
237 cm_el2_sysregs_context_restore(NON_SECURE);
238#endif
239 cm_set_next_eret_context(NON_SECURE);
240
241 SMC_RET0(&ctx->cpu_ctx);
242}
243
244/*******************************************************************************
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200245 * Loads SPMC manifest and inits SPMC.
Achin Gupta86f23532019-10-11 15:41:16 +0100246 ******************************************************************************/
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100247static int spmd_spmc_init(void *pm_addr)
Achin Gupta86f23532019-10-11 15:41:16 +0100248{
Olivier Deprez4ab7a4a2021-06-21 09:47:13 +0200249 cpu_context_t *cpu_ctx;
250 unsigned int core_id;
Olivier Depreza664c492020-08-05 11:27:42 +0200251 uint32_t ep_attr, flags;
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200252 int rc;
Achin Gupta86f23532019-10-11 15:41:16 +0100253
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200254 /* Load the SPM Core manifest */
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100255 rc = plat_spm_core_manifest_load(&spmc_attrs, pm_addr);
Max Shvetsov745889c2020-02-27 14:54:21 +0000256 if (rc != 0) {
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200257 WARN("No or invalid SPM Core manifest image provided by BL2\n");
258 return rc;
Achin Gupta86f23532019-10-11 15:41:16 +0100259 }
260
261 /*
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200262 * Ensure that the SPM Core version is compatible with the SPM
263 * Dispatcher version.
Achin Gupta86f23532019-10-11 15:41:16 +0100264 */
J-Alves2672cde2020-05-07 18:42:25 +0100265 if ((spmc_attrs.major_version != FFA_VERSION_MAJOR) ||
266 (spmc_attrs.minor_version > FFA_VERSION_MINOR)) {
267 WARN("Unsupported FFA version (%u.%u)\n",
Achin Gupta86f23532019-10-11 15:41:16 +0100268 spmc_attrs.major_version, spmc_attrs.minor_version);
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200269 return -EINVAL;
Achin Gupta86f23532019-10-11 15:41:16 +0100270 }
271
J-Alves2672cde2020-05-07 18:42:25 +0100272 VERBOSE("FFA version (%u.%u)\n", spmc_attrs.major_version,
Achin Gupta86f23532019-10-11 15:41:16 +0100273 spmc_attrs.minor_version);
274
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200275 VERBOSE("SPM Core run time EL%x.\n",
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000276 SPMD_SPM_AT_SEL2 ? MODE_EL2 : MODE_EL1);
Achin Gupta86f23532019-10-11 15:41:16 +0100277
Max Shvetsove79062e2020-03-12 15:16:40 +0000278 /* Validate the SPMC ID, Ensure high bit is set */
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200279 if (((spmc_attrs.spmc_id >> SPMC_SECURE_ID_SHIFT) &
280 SPMC_SECURE_ID_MASK) == 0U) {
281 WARN("Invalid ID (0x%x) for SPMC.\n", spmc_attrs.spmc_id);
282 return -EINVAL;
Max Shvetsove79062e2020-03-12 15:16:40 +0000283 }
284
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200285 /* Validate the SPM Core execution state */
Achin Gupta86f23532019-10-11 15:41:16 +0100286 if ((spmc_attrs.exec_state != MODE_RW_64) &&
287 (spmc_attrs.exec_state != MODE_RW_32)) {
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100288 WARN("Unsupported %s%x.\n", "SPM Core execution state 0x",
Achin Gupta86f23532019-10-11 15:41:16 +0100289 spmc_attrs.exec_state);
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200290 return -EINVAL;
Achin Gupta86f23532019-10-11 15:41:16 +0100291 }
292
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100293 VERBOSE("%s%x.\n", "SPM Core execution state 0x",
294 spmc_attrs.exec_state);
Achin Gupta86f23532019-10-11 15:41:16 +0100295
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000296#if SPMD_SPM_AT_SEL2
297 /* Ensure manifest has not requested AArch32 state in S-EL2 */
298 if (spmc_attrs.exec_state == MODE_RW_32) {
299 WARN("AArch32 state at S-EL2 is not supported.\n");
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200300 return -EINVAL;
Achin Gupta86f23532019-10-11 15:41:16 +0100301 }
302
303 /*
304 * Check if S-EL2 is supported on this system if S-EL2
305 * is required for SPM
306 */
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200307 if (!is_armv8_4_sel2_present()) {
308 WARN("SPM Core run time S-EL2 is not supported.\n");
309 return -EINVAL;
Achin Gupta86f23532019-10-11 15:41:16 +0100310 }
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000311#endif /* SPMD_SPM_AT_SEL2 */
Achin Gupta86f23532019-10-11 15:41:16 +0100312
313 /* Initialise an entrypoint to set up the CPU context */
314 ep_attr = SECURE | EP_ST_ENABLE;
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200315 if ((read_sctlr_el3() & SCTLR_EE_BIT) != 0ULL) {
Achin Gupta86f23532019-10-11 15:41:16 +0100316 ep_attr |= EP_EE_BIG;
Max Shvetsov745889c2020-02-27 14:54:21 +0000317 }
318
Achin Gupta86f23532019-10-11 15:41:16 +0100319 SET_PARAM_HEAD(spmc_ep_info, PARAM_EP, VERSION_1, ep_attr);
Achin Gupta86f23532019-10-11 15:41:16 +0100320
321 /*
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200322 * Populate SPSR for SPM Core based upon validated parameters from the
323 * manifest.
Achin Gupta86f23532019-10-11 15:41:16 +0100324 */
325 if (spmc_attrs.exec_state == MODE_RW_32) {
326 spmc_ep_info->spsr = SPSR_MODE32(MODE32_svc, SPSR_T_ARM,
327 SPSR_E_LITTLE,
328 DAIF_FIQ_BIT |
329 DAIF_IRQ_BIT |
330 DAIF_ABT_BIT);
331 } else {
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000332
333#if SPMD_SPM_AT_SEL2
334 static const uint32_t runtime_el = MODE_EL2;
335#else
336 static const uint32_t runtime_el = MODE_EL1;
337#endif
338 spmc_ep_info->spsr = SPSR_64(runtime_el,
Achin Gupta86f23532019-10-11 15:41:16 +0100339 MODE_SP_ELX,
340 DISABLE_ALL_EXCEPTIONS);
341 }
342
Olivier Deprez4ab7a4a2021-06-21 09:47:13 +0200343 /* Set an initial SPMC context state for all cores. */
344 for (core_id = 0U; core_id < PLATFORM_CORE_COUNT; core_id++) {
345 spm_core_context[core_id].state = SPMC_STATE_OFF;
Max Shvetsov745889c2020-02-27 14:54:21 +0000346
Olivier Deprez4ab7a4a2021-06-21 09:47:13 +0200347 /* Setup an initial cpu context for the SPMC. */
348 cpu_ctx = &spm_core_context[core_id].cpu_ctx;
349 cm_setup_context(cpu_ctx, spmc_ep_info);
Achin Gupta86f23532019-10-11 15:41:16 +0100350
Olivier Deprez4ab7a4a2021-06-21 09:47:13 +0200351 /*
352 * Pass the core linear ID to the SPMC through x4.
353 * (TF-A implementation defined behavior helping
354 * a legacy TOS migration to adopt FF-A).
355 */
356 write_ctx_reg(get_gpregs_ctx(cpu_ctx), CTX_GPREG_X4, core_id);
357 }
Achin Gupta86f23532019-10-11 15:41:16 +0100358
Olivier Deprez9afca122019-10-28 09:15:52 +0000359 /* Register power management hooks with PSCI */
360 psci_register_spd_pm_hook(&spmd_pm);
361
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200362 /* Register init function for deferred init. */
Achin Gupta86f23532019-10-11 15:41:16 +0100363 bl31_register_bl32_init(&spmd_init);
364
Olivier Deprez4ab7a4a2021-06-21 09:47:13 +0200365 INFO("SPM Core setup done.\n");
366
Olivier Depreza664c492020-08-05 11:27:42 +0200367 /*
368 * Register an interrupt handler routing secure interrupts to SPMD
369 * while the NWd is running.
370 */
371 flags = 0;
372 set_interrupt_rm_flag(flags, NON_SECURE);
373 rc = register_interrupt_type_handler(INTR_TYPE_S_EL1,
374 spmd_secure_interrupt_handler,
375 flags);
376 if (rc != 0) {
377 panic();
378 }
379
Achin Gupta86f23532019-10-11 15:41:16 +0100380 return 0;
Max Shvetsov745889c2020-02-27 14:54:21 +0000381}
Achin Gupta86f23532019-10-11 15:41:16 +0100382
Max Shvetsov745889c2020-02-27 14:54:21 +0000383/*******************************************************************************
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200384 * Initialize context of SPM Core.
Max Shvetsov745889c2020-02-27 14:54:21 +0000385 ******************************************************************************/
386int spmd_setup(void)
387{
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100388 void *spmc_manifest;
Max Shvetsov745889c2020-02-27 14:54:21 +0000389 int rc;
Achin Gupta86f23532019-10-11 15:41:16 +0100390
Max Shvetsov745889c2020-02-27 14:54:21 +0000391 spmc_ep_info = bl31_plat_get_next_image_ep_info(SECURE);
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200392 if (spmc_ep_info == NULL) {
393 WARN("No SPM Core image provided by BL2 boot loader.\n");
394 return -EINVAL;
Max Shvetsov745889c2020-02-27 14:54:21 +0000395 }
396
397 /* Under no circumstances will this parameter be 0 */
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200398 assert(spmc_ep_info->pc != 0ULL);
Max Shvetsov745889c2020-02-27 14:54:21 +0000399
400 /*
401 * Check if BL32 ep_info has a reference to 'tos_fw_config'. This will
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200402 * be used as a manifest for the SPM Core at the next lower EL/mode.
Max Shvetsov745889c2020-02-27 14:54:21 +0000403 */
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100404 spmc_manifest = (void *)spmc_ep_info->args.arg0;
405 if (spmc_manifest == NULL) {
406 ERROR("Invalid or absent SPM Core manifest.\n");
407 return -EINVAL;
Max Shvetsov745889c2020-02-27 14:54:21 +0000408 }
409
410 /* Load manifest, init SPMC */
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100411 rc = spmd_spmc_init(spmc_manifest);
Max Shvetsov745889c2020-02-27 14:54:21 +0000412 if (rc != 0) {
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200413 WARN("Booting device without SPM initialization.\n");
Max Shvetsov745889c2020-02-27 14:54:21 +0000414 }
415
Olivier Deprez69ca84a2020-02-07 15:44:43 +0100416 return rc;
Max Shvetsov745889c2020-02-27 14:54:21 +0000417}
418
419/*******************************************************************************
420 * Forward SMC to the other security state
421 ******************************************************************************/
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200422static uint64_t spmd_smc_forward(uint32_t smc_fid,
423 bool secure_origin,
424 uint64_t x1,
425 uint64_t x2,
426 uint64_t x3,
427 uint64_t x4,
428 void *handle)
Max Shvetsov745889c2020-02-27 14:54:21 +0000429{
Olivier Deprezebc34772020-04-16 16:59:21 +0200430 unsigned int secure_state_in = (secure_origin) ? SECURE : NON_SECURE;
431 unsigned int secure_state_out = (!secure_origin) ? SECURE : NON_SECURE;
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100432
Max Shvetsov745889c2020-02-27 14:54:21 +0000433 /* Save incoming security state */
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000434#if SPMD_SPM_AT_SEL2
Olivier Deprez9a2e5be2021-05-21 18:00:04 +0200435 if (secure_state_in == NON_SECURE) {
436 cm_el1_sysregs_context_save(secure_state_in);
437 }
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100438 cm_el2_sysregs_context_save(secure_state_in);
Olivier Deprez9a2e5be2021-05-21 18:00:04 +0200439#else
440 cm_el1_sysregs_context_save(secure_state_in);
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000441#endif
Max Shvetsov745889c2020-02-27 14:54:21 +0000442
443 /* Restore outgoing security state */
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000444#if SPMD_SPM_AT_SEL2
Olivier Deprez9a2e5be2021-05-21 18:00:04 +0200445 if (secure_state_out == NON_SECURE) {
446 cm_el1_sysregs_context_restore(secure_state_out);
447 }
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100448 cm_el2_sysregs_context_restore(secure_state_out);
Olivier Deprez9a2e5be2021-05-21 18:00:04 +0200449#else
450 cm_el1_sysregs_context_restore(secure_state_out);
Max Shvetsove7fd80e2020-02-25 13:55:00 +0000451#endif
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100452 cm_set_next_eret_context(secure_state_out);
Max Shvetsov745889c2020-02-27 14:54:21 +0000453
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100454 SMC_RET8(cm_get_context(secure_state_out), smc_fid, x1, x2, x3, x4,
Max Shvetsov745889c2020-02-27 14:54:21 +0000455 SMC_GET_GP(handle, CTX_GPREG_X5),
456 SMC_GET_GP(handle, CTX_GPREG_X6),
457 SMC_GET_GP(handle, CTX_GPREG_X7));
458}
459
460/*******************************************************************************
J-Alves2672cde2020-05-07 18:42:25 +0100461 * Return FFA_ERROR with specified error code
Max Shvetsov745889c2020-02-27 14:54:21 +0000462 ******************************************************************************/
J-Alves2672cde2020-05-07 18:42:25 +0100463static uint64_t spmd_ffa_error_return(void *handle, int error_code)
Max Shvetsov745889c2020-02-27 14:54:21 +0000464{
J-Alves64ff9932021-03-01 10:26:59 +0000465 SMC_RET8(handle, (uint32_t) FFA_ERROR,
466 FFA_TARGET_INFO_MBZ, (uint32_t)error_code,
J-Alves2672cde2020-05-07 18:42:25 +0100467 FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
468 FFA_PARAM_MBZ, FFA_PARAM_MBZ);
Achin Gupta86f23532019-10-11 15:41:16 +0100469}
470
Olivier Deprez33e44122020-04-16 17:54:27 +0200471/*******************************************************************************
472 * spmd_check_address_in_binary_image
473 ******************************************************************************/
474bool spmd_check_address_in_binary_image(uint64_t address)
475{
476 assert(!check_uptr_overflow(spmc_attrs.load_address, spmc_attrs.binary_size));
477
478 return ((address >= spmc_attrs.load_address) &&
479 (address < (spmc_attrs.load_address + spmc_attrs.binary_size)));
480}
481
Olivier Deprezebc34772020-04-16 16:59:21 +0200482/******************************************************************************
483 * spmd_is_spmc_message
484 *****************************************************************************/
485static bool spmd_is_spmc_message(unsigned int ep)
486{
487 return ((ffa_endpoint_destination(ep) == SPMD_DIRECT_MSG_ENDPOINT_ID)
488 && (ffa_endpoint_source(ep) == spmc_attrs.spmc_id));
489}
490
Olivier Deprez33e44122020-04-16 17:54:27 +0200491/******************************************************************************
492 * spmd_handle_spmc_message
493 *****************************************************************************/
Olivier Deprezc7631a52020-03-23 09:53:06 +0100494static int spmd_handle_spmc_message(unsigned long long msg,
495 unsigned long long parm1, unsigned long long parm2,
496 unsigned long long parm3, unsigned long long parm4)
Olivier Deprez33e44122020-04-16 17:54:27 +0200497{
498 VERBOSE("%s %llx %llx %llx %llx %llx\n", __func__,
499 msg, parm1, parm2, parm3, parm4);
500
Olivier Deprez33e44122020-04-16 17:54:27 +0200501 return -EINVAL;
502}
503
Achin Gupta86f23532019-10-11 15:41:16 +0100504/*******************************************************************************
J-Alves2672cde2020-05-07 18:42:25 +0100505 * This function handles all SMCs in the range reserved for FFA. Each call is
Achin Gupta86f23532019-10-11 15:41:16 +0100506 * either forwarded to the other security state or handled by the SPM dispatcher
507 ******************************************************************************/
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200508uint64_t spmd_smc_handler(uint32_t smc_fid,
509 uint64_t x1,
510 uint64_t x2,
511 uint64_t x3,
512 uint64_t x4,
513 void *cookie,
514 void *handle,
Achin Gupta86f23532019-10-11 15:41:16 +0100515 uint64_t flags)
516{
Olivier Deprezeae45962021-01-19 15:06:47 +0100517 unsigned int linear_id = plat_my_core_pos();
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200518 spmd_spm_core_context_t *ctx = spmd_get_context();
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100519 bool secure_origin;
520 int32_t ret;
J-Alves4c95c702020-05-26 14:03:05 +0100521 uint32_t input_version;
Achin Gupta86f23532019-10-11 15:41:16 +0100522
523 /* Determine which security state this SMC originated from */
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100524 secure_origin = is_caller_secure(flags);
Achin Gupta86f23532019-10-11 15:41:16 +0100525
Scott Brandene5dcf982020-08-25 13:49:32 -0700526 VERBOSE("SPM(%u): 0x%x 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64
527 " 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 "\n",
528 linear_id, smc_fid, x1, x2, x3, x4,
529 SMC_GET_GP(handle, CTX_GPREG_X5),
530 SMC_GET_GP(handle, CTX_GPREG_X6),
531 SMC_GET_GP(handle, CTX_GPREG_X7));
Achin Gupta86f23532019-10-11 15:41:16 +0100532
533 switch (smc_fid) {
J-Alves2672cde2020-05-07 18:42:25 +0100534 case FFA_ERROR:
Achin Gupta86f23532019-10-11 15:41:16 +0100535 /*
536 * Check if this is the first invocation of this interface on
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200537 * this CPU. If so, then indicate that the SPM Core initialised
Achin Gupta86f23532019-10-11 15:41:16 +0100538 * unsuccessfully.
539 */
Olivier Deprez7c016332019-10-28 09:03:13 +0000540 if (secure_origin && (ctx->state == SPMC_STATE_ON_PENDING)) {
Achin Gupta86f23532019-10-11 15:41:16 +0100541 spmd_spm_core_sync_exit(x2);
Max Shvetsov745889c2020-02-27 14:54:21 +0000542 }
Achin Gupta86f23532019-10-11 15:41:16 +0100543
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100544 return spmd_smc_forward(smc_fid, secure_origin,
Max Shvetsov745889c2020-02-27 14:54:21 +0000545 x1, x2, x3, x4, handle);
Achin Gupta86f23532019-10-11 15:41:16 +0100546 break; /* not reached */
547
J-Alves2672cde2020-05-07 18:42:25 +0100548 case FFA_VERSION:
J-Alves4c95c702020-05-26 14:03:05 +0100549 input_version = (uint32_t)(0xFFFFFFFF & x1);
Achin Gupta86f23532019-10-11 15:41:16 +0100550 /*
J-Alves4c95c702020-05-26 14:03:05 +0100551 * If caller is secure and SPMC was initialized,
552 * return FFA_VERSION of SPMD.
553 * If caller is non secure and SPMC was initialized,
554 * return SPMC's version.
555 * Sanity check to "input_version".
Achin Gupta86f23532019-10-11 15:41:16 +0100556 */
J-Alves4c95c702020-05-26 14:03:05 +0100557 if ((input_version & FFA_VERSION_BIT31_MASK) ||
558 (ctx->state == SPMC_STATE_RESET)) {
559 ret = FFA_ERROR_NOT_SUPPORTED;
560 } else if (!secure_origin) {
Daniel Boulby9460a232021-12-09 11:20:13 +0000561 gp_regs_t *gpregs = get_gpregs_ctx(&ctx->cpu_ctx);
562 uint64_t rc;
563
564 if (spmc_attrs.major_version == 1 &&
565 spmc_attrs.minor_version == 0) {
566 ret = MAKE_FFA_VERSION(spmc_attrs.major_version,
567 spmc_attrs.minor_version);
568 SMC_RET8(handle, (uint32_t)ret,
569 FFA_TARGET_INFO_MBZ,
570 FFA_TARGET_INFO_MBZ,
571 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
572 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
573 FFA_PARAM_MBZ);
574 break;
575 }
576 /* Save non-secure system registers context */
577 cm_el1_sysregs_context_save(NON_SECURE);
578#if SPMD_SPM_AT_SEL2
579 cm_el2_sysregs_context_save(NON_SECURE);
580#endif
581
582 /*
583 * The incoming request has FFA_VERSION as X0 smc_fid
584 * and requested version in x1. Prepare a direct request
585 * from SPMD to SPMC with FFA_VERSION framework function
586 * identifier in X2 and requested version in X3.
587 */
588 spmd_build_spmc_message(gpregs,
589 SPMD_FWK_MSG_FFA_VERSION_REQ,
590 input_version);
591
592 rc = spmd_spm_core_sync_entry(ctx);
593
594 if ((rc != 0ULL) ||
595 (SMC_GET_GP(gpregs, CTX_GPREG_X0) !=
596 FFA_MSG_SEND_DIRECT_RESP_SMC32) ||
597 (SMC_GET_GP(gpregs, CTX_GPREG_X2) !=
598 (SPMD_FWK_MSG_BIT |
599 SPMD_FWK_MSG_FFA_VERSION_RESP))) {
600 ERROR("Failed to forward FFA_VERSION\n");
601 ret = FFA_ERROR_NOT_SUPPORTED;
602 } else {
603 ret = SMC_GET_GP(gpregs, CTX_GPREG_X3);
604 }
605
606 /*
607 * Return here after SPMC has handled FFA_VERSION.
608 * The returned SPMC version is held in X3.
609 * Forward this version in X0 to the non-secure caller.
610 */
611 return spmd_smc_forward(ret, true, FFA_PARAM_MBZ,
612 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
613 FFA_PARAM_MBZ, gpregs);
J-Alves4c95c702020-05-26 14:03:05 +0100614 } else {
J-Alves64ff9932021-03-01 10:26:59 +0000615 ret = MAKE_FFA_VERSION(FFA_VERSION_MAJOR,
616 FFA_VERSION_MINOR);
J-Alves4c95c702020-05-26 14:03:05 +0100617 }
618
J-Alves64ff9932021-03-01 10:26:59 +0000619 SMC_RET8(handle, (uint32_t)ret, FFA_TARGET_INFO_MBZ,
620 FFA_TARGET_INFO_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ,
621 FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ);
Achin Gupta86f23532019-10-11 15:41:16 +0100622 break; /* not reached */
623
J-Alves2672cde2020-05-07 18:42:25 +0100624 case FFA_FEATURES:
Achin Gupta86f23532019-10-11 15:41:16 +0100625 /*
626 * This is an optional interface. Do the minimal checks and
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200627 * forward to SPM Core which will handle it if implemented.
Achin Gupta86f23532019-10-11 15:41:16 +0100628 */
629
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200630 /* Forward SMC from Normal world to the SPM Core */
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100631 if (!secure_origin) {
632 return spmd_smc_forward(smc_fid, secure_origin,
Max Shvetsov745889c2020-02-27 14:54:21 +0000633 x1, x2, x3, x4, handle);
Achin Gupta86f23532019-10-11 15:41:16 +0100634 }
Max Shvetsov745889c2020-02-27 14:54:21 +0000635
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200636 /*
637 * Return success if call was from secure world i.e. all
J-Alves2672cde2020-05-07 18:42:25 +0100638 * FFA functions are supported. This is essentially a
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200639 * nop.
640 */
J-Alves2672cde2020-05-07 18:42:25 +0100641 SMC_RET8(handle, FFA_SUCCESS_SMC32, x1, x2, x3, x4,
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200642 SMC_GET_GP(handle, CTX_GPREG_X5),
643 SMC_GET_GP(handle, CTX_GPREG_X6),
644 SMC_GET_GP(handle, CTX_GPREG_X7));
645
Achin Gupta86f23532019-10-11 15:41:16 +0100646 break; /* not reached */
647
J-Alves2672cde2020-05-07 18:42:25 +0100648 case FFA_ID_GET:
Max Shvetsove79062e2020-03-12 15:16:40 +0000649 /*
J-Alves2672cde2020-05-07 18:42:25 +0100650 * Returns the ID of the calling FFA component.
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200651 */
Max Shvetsove79062e2020-03-12 15:16:40 +0000652 if (!secure_origin) {
J-Alves2672cde2020-05-07 18:42:25 +0100653 SMC_RET8(handle, FFA_SUCCESS_SMC32,
654 FFA_TARGET_INFO_MBZ, FFA_NS_ENDPOINT_ID,
655 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
656 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
657 FFA_PARAM_MBZ);
Max Shvetsove79062e2020-03-12 15:16:40 +0000658 }
659
J-Alves2672cde2020-05-07 18:42:25 +0100660 SMC_RET8(handle, FFA_SUCCESS_SMC32,
661 FFA_TARGET_INFO_MBZ, spmc_attrs.spmc_id,
662 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
663 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
664 FFA_PARAM_MBZ);
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200665
Max Shvetsove79062e2020-03-12 15:16:40 +0000666 break; /* not reached */
667
Olivier Deprezeae45962021-01-19 15:06:47 +0100668 case FFA_SECONDARY_EP_REGISTER_SMC64:
669 if (secure_origin) {
670 ret = spmd_pm_secondary_ep_register(x1);
671
672 if (ret < 0) {
673 SMC_RET8(handle, FFA_ERROR_SMC64,
674 FFA_TARGET_INFO_MBZ, ret,
675 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
676 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
677 FFA_PARAM_MBZ);
678 } else {
679 SMC_RET8(handle, FFA_SUCCESS_SMC64,
680 FFA_TARGET_INFO_MBZ, FFA_PARAM_MBZ,
681 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
682 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
683 FFA_PARAM_MBZ);
684 }
685 }
686
687 return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED);
688 break; /* Not reached */
689
Daniel Boulby27f35df2021-02-03 12:13:19 +0000690 case FFA_SPM_ID_GET:
691 if (MAKE_FFA_VERSION(1, 1) > FFA_VERSION_COMPILED) {
692 return spmd_ffa_error_return(handle,
693 FFA_ERROR_NOT_SUPPORTED);
694 }
695 /*
696 * Returns the ID of the SPMC or SPMD depending on the FF-A
697 * instance where this function is invoked
698 */
699 if (!secure_origin) {
700 SMC_RET8(handle, FFA_SUCCESS_SMC32,
701 FFA_TARGET_INFO_MBZ, spmc_attrs.spmc_id,
702 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
703 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
704 FFA_PARAM_MBZ);
705 }
706 SMC_RET8(handle, FFA_SUCCESS_SMC32,
707 FFA_TARGET_INFO_MBZ, SPMD_DIRECT_MSG_ENDPOINT_ID,
708 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
709 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
710 FFA_PARAM_MBZ);
711
712 break; /* not reached */
713
Olivier Deprez33e44122020-04-16 17:54:27 +0200714 case FFA_MSG_SEND_DIRECT_REQ_SMC32:
715 if (secure_origin && spmd_is_spmc_message(x1)) {
716 ret = spmd_handle_spmc_message(x3, x4,
717 SMC_GET_GP(handle, CTX_GPREG_X5),
718 SMC_GET_GP(handle, CTX_GPREG_X6),
719 SMC_GET_GP(handle, CTX_GPREG_X7));
720
721 SMC_RET8(handle, FFA_SUCCESS_SMC32,
722 FFA_TARGET_INFO_MBZ, ret,
723 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
724 FFA_PARAM_MBZ, FFA_PARAM_MBZ,
725 FFA_PARAM_MBZ);
726 } else {
727 /* Forward direct message to the other world */
728 return spmd_smc_forward(smc_fid, secure_origin,
729 x1, x2, x3, x4, handle);
730 }
731 break; /* Not reached */
732
733 case FFA_MSG_SEND_DIRECT_RESP_SMC32:
734 if (secure_origin && spmd_is_spmc_message(x1)) {
Olivier Depreza664c492020-08-05 11:27:42 +0200735 spmd_spm_core_sync_exit(0ULL);
Olivier Deprez33e44122020-04-16 17:54:27 +0200736 } else {
737 /* Forward direct message to the other world */
738 return spmd_smc_forward(smc_fid, secure_origin,
739 x1, x2, x3, x4, handle);
740 }
741 break; /* Not reached */
742
J-Alves2672cde2020-05-07 18:42:25 +0100743 case FFA_RX_RELEASE:
744 case FFA_RXTX_MAP_SMC32:
745 case FFA_RXTX_MAP_SMC64:
746 case FFA_RXTX_UNMAP:
Ruari Phipps93dff702020-07-28 10:33:35 +0100747 case FFA_PARTITION_INFO_GET:
J-Alves2621cfd2021-03-11 17:46:47 +0000748#if MAKE_FFA_VERSION(1, 1) <= FFA_VERSION_COMPILED
749 case FFA_NOTIFICATION_BITMAP_CREATE:
750 case FFA_NOTIFICATION_BITMAP_DESTROY:
751 case FFA_NOTIFICATION_BIND:
752 case FFA_NOTIFICATION_UNBIND:
753 case FFA_NOTIFICATION_SET:
754 case FFA_NOTIFICATION_GET:
755 case FFA_NOTIFICATION_INFO_GET:
756 case FFA_NOTIFICATION_INFO_GET_SMC64:
Federico Recanatieecb4b02022-02-03 17:22:37 +0100757 case FFA_MSG_SEND2:
Federico Recanati5c7c5c42022-03-18 10:30:00 +0100758 case FFA_RX_ACQUIRE:
J-Alves2621cfd2021-03-11 17:46:47 +0000759#endif
Federico Recanatieecb4b02022-02-03 17:22:37 +0100760 case FFA_MSG_RUN:
Ruari Phipps93dff702020-07-28 10:33:35 +0100761 /*
Federico Recanatieecb4b02022-02-03 17:22:37 +0100762 * Above calls should be invoked only by the Normal world and
763 * must not be forwarded from Secure world to Normal world.
Ruari Phipps93dff702020-07-28 10:33:35 +0100764 */
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100765 if (secure_origin) {
J-Alves2672cde2020-05-07 18:42:25 +0100766 return spmd_ffa_error_return(handle,
Ruari Phipps93dff702020-07-28 10:33:35 +0100767 FFA_ERROR_NOT_SUPPORTED);
Achin Gupta86f23532019-10-11 15:41:16 +0100768 }
769
770 /* Fall through to forward the call to the other world */
J-Alves2672cde2020-05-07 18:42:25 +0100771 case FFA_MSG_SEND:
J-Alves2672cde2020-05-07 18:42:25 +0100772 case FFA_MSG_SEND_DIRECT_REQ_SMC64:
J-Alves2672cde2020-05-07 18:42:25 +0100773 case FFA_MSG_SEND_DIRECT_RESP_SMC64:
774 case FFA_MEM_DONATE_SMC32:
775 case FFA_MEM_DONATE_SMC64:
776 case FFA_MEM_LEND_SMC32:
777 case FFA_MEM_LEND_SMC64:
778 case FFA_MEM_SHARE_SMC32:
779 case FFA_MEM_SHARE_SMC64:
780 case FFA_MEM_RETRIEVE_REQ_SMC32:
781 case FFA_MEM_RETRIEVE_REQ_SMC64:
782 case FFA_MEM_RETRIEVE_RESP:
783 case FFA_MEM_RELINQUISH:
784 case FFA_MEM_RECLAIM:
785 case FFA_SUCCESS_SMC32:
786 case FFA_SUCCESS_SMC64:
Achin Gupta86f23532019-10-11 15:41:16 +0100787 /*
788 * TODO: Assume that no requests originate from EL3 at the
789 * moment. This will change if a SP service is required in
790 * response to secure interrupts targeted to EL3. Until then
791 * simply forward the call to the Normal world.
792 */
793
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100794 return spmd_smc_forward(smc_fid, secure_origin,
Max Shvetsov745889c2020-02-27 14:54:21 +0000795 x1, x2, x3, x4, handle);
Achin Gupta86f23532019-10-11 15:41:16 +0100796 break; /* not reached */
797
J-Alves2672cde2020-05-07 18:42:25 +0100798 case FFA_MSG_WAIT:
Achin Gupta86f23532019-10-11 15:41:16 +0100799 /*
800 * Check if this is the first invocation of this interface on
801 * this CPU from the Secure world. If so, then indicate that the
Olivier Deprez2bae35f2020-04-16 13:39:06 +0200802 * SPM Core initialised successfully.
Achin Gupta86f23532019-10-11 15:41:16 +0100803 */
Olivier Deprez7c016332019-10-28 09:03:13 +0000804 if (secure_origin && (ctx->state == SPMC_STATE_ON_PENDING)) {
Olivier Depreza664c492020-08-05 11:27:42 +0200805 spmd_spm_core_sync_exit(0ULL);
Achin Gupta86f23532019-10-11 15:41:16 +0100806 }
807
Max Shvetsov745889c2020-02-27 14:54:21 +0000808 /* Fall through to forward the call to the other world */
Olivier Deprezae18caf2021-04-02 11:09:10 +0200809 case FFA_INTERRUPT:
J-Alves2672cde2020-05-07 18:42:25 +0100810 case FFA_MSG_YIELD:
Achin Gupta86f23532019-10-11 15:41:16 +0100811 /* This interface must be invoked only by the Secure world */
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100812 if (!secure_origin) {
J-Alves2672cde2020-05-07 18:42:25 +0100813 return spmd_ffa_error_return(handle,
814 FFA_ERROR_NOT_SUPPORTED);
Achin Gupta86f23532019-10-11 15:41:16 +0100815 }
816
Olivier Deprez41ff36a2019-12-23 16:21:12 +0100817 return spmd_smc_forward(smc_fid, secure_origin,
Max Shvetsov745889c2020-02-27 14:54:21 +0000818 x1, x2, x3, x4, handle);
Achin Gupta86f23532019-10-11 15:41:16 +0100819 break; /* not reached */
820
Olivier Depreza664c492020-08-05 11:27:42 +0200821 case FFA_NORMAL_WORLD_RESUME:
822 if (secure_origin && ctx->secure_interrupt_ongoing) {
823 spmd_spm_core_sync_exit(0ULL);
824 } else {
825 return spmd_ffa_error_return(handle, FFA_ERROR_DENIED);
826 }
827 break; /* Not reached */
828
Achin Gupta86f23532019-10-11 15:41:16 +0100829 default:
830 WARN("SPM: Unsupported call 0x%08x\n", smc_fid);
J-Alves2672cde2020-05-07 18:42:25 +0100831 return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED);
Achin Gupta86f23532019-10-11 15:41:16 +0100832 }
833}