1bdd2596dSAchin Gupta /* 2cc6047b3SKathleen Capella * Copyright (c) 2020-2024, Arm Limited and Contributors. All rights reserved. 3bdd2596dSAchin Gupta * 4bdd2596dSAchin Gupta * SPDX-License-Identifier: BSD-3-Clause 5bdd2596dSAchin Gupta */ 6bdd2596dSAchin Gupta 7bdd2596dSAchin Gupta #include <assert.h> 8bdd2596dSAchin Gupta #include <errno.h> 94ce3e99aSScott Branden #include <inttypes.h> 104ce3e99aSScott Branden #include <stdint.h> 11bdd2596dSAchin Gupta #include <string.h> 12bdd2596dSAchin Gupta 13bdd2596dSAchin Gupta #include <arch_helpers.h> 1452696946SOlivier Deprez #include <arch/aarch64/arch_features.h> 15bdd2596dSAchin Gupta #include <bl31/bl31.h> 168cb99c3fSOlivier Deprez #include <bl31/interrupt_mgmt.h> 17bdd2596dSAchin Gupta #include <common/debug.h> 18bdd2596dSAchin Gupta #include <common/runtime_svc.h> 190cea2ae0SManish V Badarkhe #include <common/tbbr/tbbr_img_def.h> 20bdd2596dSAchin Gupta #include <lib/el3_runtime/context_mgmt.h> 210cea2ae0SManish V Badarkhe #include <lib/fconf/fconf.h> 220cea2ae0SManish V Badarkhe #include <lib/fconf/fconf_dyn_cfg_getter.h> 23bdd2596dSAchin Gupta #include <lib/smccc.h> 24bdd2596dSAchin Gupta #include <lib/spinlock.h> 25bdd2596dSAchin Gupta #include <lib/utils.h> 260cea2ae0SManish V Badarkhe #include <lib/xlat_tables/xlat_tables_v2.h> 27bdd2596dSAchin Gupta #include <plat/common/common_def.h> 28bdd2596dSAchin Gupta #include <plat/common/platform.h> 29bdd2596dSAchin Gupta #include <platform_def.h> 30890b5088SRaghu Krishnamurthy #include <services/el3_spmd_logical_sp.h> 31662af36dSJ-Alves #include <services/ffa_svc.h> 326da76075SMarc Bonnici #include <services/spmc_svc.h> 33bdd2596dSAchin Gupta #include <services/spmd_svc.h> 34bdd2596dSAchin Gupta #include <smccc_helpers.h> 35bdd2596dSAchin Gupta #include "spmd_private.h" 36bdd2596dSAchin Gupta 37bdd2596dSAchin Gupta /******************************************************************************* 38bdd2596dSAchin Gupta * SPM Core context information. 39bdd2596dSAchin Gupta ******************************************************************************/ 4052696946SOlivier Deprez static spmd_spm_core_context_t spm_core_context[PLATFORM_CORE_COUNT]; 41bdd2596dSAchin Gupta 42bdd2596dSAchin Gupta /******************************************************************************* 436da76075SMarc Bonnici * SPM Core attribute information is read from its manifest if the SPMC is not 446da76075SMarc Bonnici * at EL3. Else, it is populated from the SPMC directly. 45bdd2596dSAchin Gupta ******************************************************************************/ 4652696946SOlivier Deprez static spmc_manifest_attribute_t spmc_attrs; 470f14d02fSMax Shvetsov 480f14d02fSMax Shvetsov /******************************************************************************* 490f14d02fSMax Shvetsov * SPM Core entry point information. Discovered on the primary core and reused 500f14d02fSMax Shvetsov * on secondary cores. 510f14d02fSMax Shvetsov ******************************************************************************/ 520f14d02fSMax Shvetsov static entry_point_info_t *spmc_ep_info; 530f14d02fSMax Shvetsov 540f14d02fSMax Shvetsov /******************************************************************************* 5502d50bb0SOlivier Deprez * SPM Core context on CPU based on mpidr. 5602d50bb0SOlivier Deprez ******************************************************************************/ 5702d50bb0SOlivier Deprez spmd_spm_core_context_t *spmd_get_context_by_mpidr(uint64_t mpidr) 5802d50bb0SOlivier Deprez { 59f7fb0bf7SMax Shvetsov int core_idx = plat_core_pos_by_mpidr(mpidr); 60f7fb0bf7SMax Shvetsov 61f7fb0bf7SMax Shvetsov if (core_idx < 0) { 624ce3e99aSScott Branden ERROR("Invalid mpidr: %" PRIx64 ", returned ID: %d\n", mpidr, core_idx); 63f7fb0bf7SMax Shvetsov panic(); 64f7fb0bf7SMax Shvetsov } 65f7fb0bf7SMax Shvetsov 66f7fb0bf7SMax Shvetsov return &spm_core_context[core_idx]; 6702d50bb0SOlivier Deprez } 6802d50bb0SOlivier Deprez 6902d50bb0SOlivier Deprez /******************************************************************************* 7052696946SOlivier Deprez * SPM Core context on current CPU get helper. 7152696946SOlivier Deprez ******************************************************************************/ 7252696946SOlivier Deprez spmd_spm_core_context_t *spmd_get_context(void) 7352696946SOlivier Deprez { 7402d50bb0SOlivier Deprez return spmd_get_context_by_mpidr(read_mpidr()); 7552696946SOlivier Deprez } 7652696946SOlivier Deprez 7752696946SOlivier Deprez /******************************************************************************* 78a92bc73bSOlivier Deprez * SPM Core ID getter. 79a92bc73bSOlivier Deprez ******************************************************************************/ 80a92bc73bSOlivier Deprez uint16_t spmd_spmc_id_get(void) 81a92bc73bSOlivier Deprez { 82a92bc73bSOlivier Deprez return spmc_attrs.spmc_id; 83a92bc73bSOlivier Deprez } 84a92bc73bSOlivier Deprez 85a92bc73bSOlivier Deprez /******************************************************************************* 860f14d02fSMax Shvetsov * Static function declaration. 870f14d02fSMax Shvetsov ******************************************************************************/ 880f14d02fSMax Shvetsov static int32_t spmd_init(void); 8923d5ba86SOlivier Deprez static int spmd_spmc_init(void *pm_addr); 9095f7f6d8SRaghu Krishnamurthy 9152696946SOlivier Deprez static uint64_t spmd_smc_forward(uint32_t smc_fid, 9252696946SOlivier Deprez bool secure_origin, 9352696946SOlivier Deprez uint64_t x1, 9452696946SOlivier Deprez uint64_t x2, 9552696946SOlivier Deprez uint64_t x3, 9652696946SOlivier Deprez uint64_t x4, 97bb01a673SMarc Bonnici void *cookie, 98bb01a673SMarc Bonnici void *handle, 99bb01a673SMarc Bonnici uint64_t flags); 100bdd2596dSAchin Gupta 1019944f557SDaniel Boulby /****************************************************************************** 1029944f557SDaniel Boulby * Builds an SPMD to SPMC direct message request. 1039944f557SDaniel Boulby *****************************************************************************/ 1049944f557SDaniel Boulby void spmd_build_spmc_message(gp_regs_t *gpregs, uint8_t target_func, 1059944f557SDaniel Boulby unsigned long long message) 1069944f557SDaniel Boulby { 1079944f557SDaniel Boulby write_ctx_reg(gpregs, CTX_GPREG_X0, FFA_MSG_SEND_DIRECT_REQ_SMC32); 1089944f557SDaniel Boulby write_ctx_reg(gpregs, CTX_GPREG_X1, 1099944f557SDaniel Boulby (SPMD_DIRECT_MSG_ENDPOINT_ID << FFA_DIRECT_MSG_SOURCE_SHIFT) | 1109944f557SDaniel Boulby spmd_spmc_id_get()); 1119944f557SDaniel Boulby write_ctx_reg(gpregs, CTX_GPREG_X2, BIT(31) | target_func); 1129944f557SDaniel Boulby write_ctx_reg(gpregs, CTX_GPREG_X3, message); 11376d53ee1SOlivier Deprez 11476d53ee1SOlivier Deprez /* Zero out x4-x7 for the direct request emitted towards the SPMC. */ 11576d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X4, 0); 11676d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X5, 0); 11776d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X6, 0); 11876d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X7, 0); 1199944f557SDaniel Boulby } 1209944f557SDaniel Boulby 1219944f557SDaniel Boulby 122bdd2596dSAchin Gupta /******************************************************************************* 12352696946SOlivier Deprez * This function takes an SPMC context pointer and performs a synchronous 12452696946SOlivier Deprez * SPMC entry. 125bdd2596dSAchin Gupta ******************************************************************************/ 126bdd2596dSAchin Gupta uint64_t spmd_spm_core_sync_entry(spmd_spm_core_context_t *spmc_ctx) 127bdd2596dSAchin Gupta { 128bdd2596dSAchin Gupta uint64_t rc; 129bdd2596dSAchin Gupta 130bdd2596dSAchin Gupta assert(spmc_ctx != NULL); 131bdd2596dSAchin Gupta 132bdd2596dSAchin Gupta cm_set_context(&(spmc_ctx->cpu_ctx), SECURE); 133bdd2596dSAchin Gupta 134bdd2596dSAchin Gupta /* Restore the context assigned above */ 135033039f8SMax Shvetsov #if SPMD_SPM_AT_SEL2 13628f39f02SMax Shvetsov cm_el2_sysregs_context_restore(SECURE); 137678ce223SOlivier Deprez #else 138678ce223SOlivier Deprez cm_el1_sysregs_context_restore(SECURE); 139033039f8SMax Shvetsov #endif 140bdd2596dSAchin Gupta cm_set_next_eret_context(SECURE); 141bdd2596dSAchin Gupta 142033039f8SMax Shvetsov /* Enter SPMC */ 143bdd2596dSAchin Gupta rc = spmd_spm_core_enter(&spmc_ctx->c_rt_ctx); 144bdd2596dSAchin Gupta 145bdd2596dSAchin Gupta /* Save secure state */ 146033039f8SMax Shvetsov #if SPMD_SPM_AT_SEL2 14728f39f02SMax Shvetsov cm_el2_sysregs_context_save(SECURE); 148678ce223SOlivier Deprez #else 149678ce223SOlivier Deprez cm_el1_sysregs_context_save(SECURE); 150033039f8SMax Shvetsov #endif 151bdd2596dSAchin Gupta 152bdd2596dSAchin Gupta return rc; 153bdd2596dSAchin Gupta } 154bdd2596dSAchin Gupta 155bdd2596dSAchin Gupta /******************************************************************************* 15652696946SOlivier Deprez * This function returns to the place where spmd_spm_core_sync_entry() was 157bdd2596dSAchin Gupta * called originally. 158bdd2596dSAchin Gupta ******************************************************************************/ 159bdd2596dSAchin Gupta __dead2 void spmd_spm_core_sync_exit(uint64_t rc) 160bdd2596dSAchin Gupta { 16152696946SOlivier Deprez spmd_spm_core_context_t *ctx = spmd_get_context(); 162bdd2596dSAchin Gupta 16352696946SOlivier Deprez /* Get current CPU context from SPMC context */ 164bdd2596dSAchin Gupta assert(cm_get_context(SECURE) == &(ctx->cpu_ctx)); 165bdd2596dSAchin Gupta 166bdd2596dSAchin Gupta /* 167bdd2596dSAchin Gupta * The SPMD must have initiated the original request through a 168bdd2596dSAchin Gupta * synchronous entry into SPMC. Jump back to the original C runtime 169bdd2596dSAchin Gupta * context with the value of rc in x0; 170bdd2596dSAchin Gupta */ 171bdd2596dSAchin Gupta spmd_spm_core_exit(ctx->c_rt_ctx, rc); 172bdd2596dSAchin Gupta 173bdd2596dSAchin Gupta panic(); 174bdd2596dSAchin Gupta } 175bdd2596dSAchin Gupta 176bdd2596dSAchin Gupta /******************************************************************************* 17752696946SOlivier Deprez * Jump to the SPM Core for the first time. 178bdd2596dSAchin Gupta ******************************************************************************/ 179bdd2596dSAchin Gupta static int32_t spmd_init(void) 180bdd2596dSAchin Gupta { 18152696946SOlivier Deprez spmd_spm_core_context_t *ctx = spmd_get_context(); 18252696946SOlivier Deprez uint64_t rc; 183bdd2596dSAchin Gupta 18452696946SOlivier Deprez VERBOSE("SPM Core init start.\n"); 1859dcf63ddSOlivier Deprez 186f2dcf418SOlivier Deprez /* Primary boot core enters the SPMC for initialization. */ 187f2dcf418SOlivier Deprez ctx->state = SPMC_STATE_ON_PENDING; 188bdd2596dSAchin Gupta 189bdd2596dSAchin Gupta rc = spmd_spm_core_sync_entry(ctx); 19052696946SOlivier Deprez if (rc != 0ULL) { 1914ce3e99aSScott Branden ERROR("SPMC initialisation failed 0x%" PRIx64 "\n", rc); 19252696946SOlivier Deprez return 0; 193bdd2596dSAchin Gupta } 194bdd2596dSAchin Gupta 1959dcf63ddSOlivier Deprez ctx->state = SPMC_STATE_ON; 1969dcf63ddSOlivier Deprez 19752696946SOlivier Deprez VERBOSE("SPM Core init end.\n"); 198bdd2596dSAchin Gupta 199890b5088SRaghu Krishnamurthy spmd_logical_sp_set_spmc_initialized(); 200890b5088SRaghu Krishnamurthy rc = spmd_logical_sp_init(); 201890b5088SRaghu Krishnamurthy if (rc != 0) { 202890b5088SRaghu Krishnamurthy WARN("SPMD Logical partitions failed init.\n"); 203890b5088SRaghu Krishnamurthy } 204890b5088SRaghu Krishnamurthy 205bdd2596dSAchin Gupta return 1; 206bdd2596dSAchin Gupta } 207bdd2596dSAchin Gupta 208bdd2596dSAchin Gupta /******************************************************************************* 2098cb99c3fSOlivier Deprez * spmd_secure_interrupt_handler 2108cb99c3fSOlivier Deprez * Enter the SPMC for further handling of the secure interrupt by the SPMC 2118cb99c3fSOlivier Deprez * itself or a Secure Partition. 2128cb99c3fSOlivier Deprez ******************************************************************************/ 2138cb99c3fSOlivier Deprez static uint64_t spmd_secure_interrupt_handler(uint32_t id, 2148cb99c3fSOlivier Deprez uint32_t flags, 2158cb99c3fSOlivier Deprez void *handle, 2168cb99c3fSOlivier Deprez void *cookie) 2178cb99c3fSOlivier Deprez { 2188cb99c3fSOlivier Deprez spmd_spm_core_context_t *ctx = spmd_get_context(); 2198cb99c3fSOlivier Deprez gp_regs_t *gpregs = get_gpregs_ctx(&ctx->cpu_ctx); 2208cb99c3fSOlivier Deprez unsigned int linear_id = plat_my_core_pos(); 2218cb99c3fSOlivier Deprez int64_t rc; 2228cb99c3fSOlivier Deprez 2238cb99c3fSOlivier Deprez /* Sanity check the security state when the exception was generated */ 2248cb99c3fSOlivier Deprez assert(get_interrupt_src_ss(flags) == NON_SECURE); 2258cb99c3fSOlivier Deprez 2268cb99c3fSOlivier Deprez /* Sanity check the pointer to this cpu's context */ 2278cb99c3fSOlivier Deprez assert(handle == cm_get_context(NON_SECURE)); 2288cb99c3fSOlivier Deprez 2298cb99c3fSOlivier Deprez /* Save the non-secure context before entering SPMC */ 2308cb99c3fSOlivier Deprez cm_el1_sysregs_context_save(NON_SECURE); 2318cb99c3fSOlivier Deprez #if SPMD_SPM_AT_SEL2 2328cb99c3fSOlivier Deprez cm_el2_sysregs_context_save(NON_SECURE); 2338cb99c3fSOlivier Deprez #endif 2348cb99c3fSOlivier Deprez 2358cb99c3fSOlivier Deprez /* Convey the event to the SPMC through the FFA_INTERRUPT interface. */ 2368cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X0, FFA_INTERRUPT); 2378cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X1, 0); 2388cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X2, 0); 2398cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X3, 0); 2408cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X4, 0); 2418cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X5, 0); 2428cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X6, 0); 2438cb99c3fSOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X7, 0); 2448cb99c3fSOlivier Deprez 2458cb99c3fSOlivier Deprez /* Mark current core as handling a secure interrupt. */ 2468cb99c3fSOlivier Deprez ctx->secure_interrupt_ongoing = true; 2478cb99c3fSOlivier Deprez 2488cb99c3fSOlivier Deprez rc = spmd_spm_core_sync_entry(ctx); 2498cb99c3fSOlivier Deprez if (rc != 0ULL) { 2500c23e6f4SOlivier Deprez ERROR("%s failed (%" PRId64 ") on CPU%u\n", __func__, rc, linear_id); 2518cb99c3fSOlivier Deprez } 2528cb99c3fSOlivier Deprez 2538cb99c3fSOlivier Deprez ctx->secure_interrupt_ongoing = false; 2548cb99c3fSOlivier Deprez 2558cb99c3fSOlivier Deprez cm_el1_sysregs_context_restore(NON_SECURE); 2568cb99c3fSOlivier Deprez #if SPMD_SPM_AT_SEL2 2578cb99c3fSOlivier Deprez cm_el2_sysregs_context_restore(NON_SECURE); 2588cb99c3fSOlivier Deprez #endif 2598cb99c3fSOlivier Deprez cm_set_next_eret_context(NON_SECURE); 2608cb99c3fSOlivier Deprez 2618cb99c3fSOlivier Deprez SMC_RET0(&ctx->cpu_ctx); 2628cb99c3fSOlivier Deprez } 2638cb99c3fSOlivier Deprez 264bb6d0a17SOlivier Deprez #if (EL3_EXCEPTION_HANDLING == 0) 265a1e0e871SMadhukar Pappireddy /******************************************************************************* 266a1e0e871SMadhukar Pappireddy * spmd_group0_interrupt_handler_nwd 267a1e0e871SMadhukar Pappireddy * Group0 secure interrupt in the normal world are trapped to EL3. Delegate the 268a1e0e871SMadhukar Pappireddy * handling of the interrupt to the platform handler, and return only upon 269a1e0e871SMadhukar Pappireddy * successfully handling the Group0 interrupt. 270a1e0e871SMadhukar Pappireddy ******************************************************************************/ 271a1e0e871SMadhukar Pappireddy static uint64_t spmd_group0_interrupt_handler_nwd(uint32_t id, 272a1e0e871SMadhukar Pappireddy uint32_t flags, 273a1e0e871SMadhukar Pappireddy void *handle, 274a1e0e871SMadhukar Pappireddy void *cookie) 275a1e0e871SMadhukar Pappireddy { 276a1e0e871SMadhukar Pappireddy uint32_t intid; 277a1e0e871SMadhukar Pappireddy 278a1e0e871SMadhukar Pappireddy /* Sanity check the security state when the exception was generated. */ 279a1e0e871SMadhukar Pappireddy assert(get_interrupt_src_ss(flags) == NON_SECURE); 280a1e0e871SMadhukar Pappireddy 281a1e0e871SMadhukar Pappireddy /* Sanity check the pointer to this cpu's context. */ 282a1e0e871SMadhukar Pappireddy assert(handle == cm_get_context(NON_SECURE)); 283a1e0e871SMadhukar Pappireddy 284a1e0e871SMadhukar Pappireddy assert(id == INTR_ID_UNAVAILABLE); 285a1e0e871SMadhukar Pappireddy 286a1e0e871SMadhukar Pappireddy assert(plat_ic_get_pending_interrupt_type() == INTR_TYPE_EL3); 287a1e0e871SMadhukar Pappireddy 2886c91fc44SMadhukar Pappireddy intid = plat_ic_acknowledge_interrupt(); 289a1e0e871SMadhukar Pappireddy 290a1e0e871SMadhukar Pappireddy if (plat_spmd_handle_group0_interrupt(intid) < 0) { 291a1e0e871SMadhukar Pappireddy ERROR("Group0 interrupt %u not handled\n", intid); 292a1e0e871SMadhukar Pappireddy panic(); 293a1e0e871SMadhukar Pappireddy } 294a1e0e871SMadhukar Pappireddy 2956c91fc44SMadhukar Pappireddy /* Deactivate the corresponding Group0 interrupt. */ 2966c91fc44SMadhukar Pappireddy plat_ic_end_of_interrupt(intid); 2976c91fc44SMadhukar Pappireddy 298a1e0e871SMadhukar Pappireddy return 0U; 299a1e0e871SMadhukar Pappireddy } 300bb6d0a17SOlivier Deprez #endif 301a1e0e871SMadhukar Pappireddy 3026671b3d8SMadhukar Pappireddy /******************************************************************************* 3036671b3d8SMadhukar Pappireddy * spmd_handle_group0_intr_swd 3046671b3d8SMadhukar Pappireddy * SPMC delegates handling of Group0 secure interrupt to EL3 firmware using 3056671b3d8SMadhukar Pappireddy * FFA_EL3_INTR_HANDLE SMC call. Further, SPMD delegates the handling of the 3066671b3d8SMadhukar Pappireddy * interrupt to the platform handler, and returns only upon successfully 3076671b3d8SMadhukar Pappireddy * handling the Group0 interrupt. 3086671b3d8SMadhukar Pappireddy ******************************************************************************/ 3096671b3d8SMadhukar Pappireddy static uint64_t spmd_handle_group0_intr_swd(void *handle) 3106671b3d8SMadhukar Pappireddy { 3116671b3d8SMadhukar Pappireddy uint32_t intid; 3126671b3d8SMadhukar Pappireddy 3136671b3d8SMadhukar Pappireddy /* Sanity check the pointer to this cpu's context */ 3146671b3d8SMadhukar Pappireddy assert(handle == cm_get_context(SECURE)); 3156671b3d8SMadhukar Pappireddy 3166671b3d8SMadhukar Pappireddy assert(plat_ic_get_pending_interrupt_type() == INTR_TYPE_EL3); 3176671b3d8SMadhukar Pappireddy 3186c91fc44SMadhukar Pappireddy intid = plat_ic_acknowledge_interrupt(); 3196671b3d8SMadhukar Pappireddy 3206671b3d8SMadhukar Pappireddy /* 3216671b3d8SMadhukar Pappireddy * TODO: Currently due to a limitation in SPMD implementation, the 3226671b3d8SMadhukar Pappireddy * platform handler is expected to not delegate handling to NWd while 3236671b3d8SMadhukar Pappireddy * processing Group0 secure interrupt. 3246671b3d8SMadhukar Pappireddy */ 3256671b3d8SMadhukar Pappireddy if (plat_spmd_handle_group0_interrupt(intid) < 0) { 3266671b3d8SMadhukar Pappireddy /* Group0 interrupt was not handled by the platform. */ 3276671b3d8SMadhukar Pappireddy ERROR("Group0 interrupt %u not handled\n", intid); 3286671b3d8SMadhukar Pappireddy panic(); 3296671b3d8SMadhukar Pappireddy } 3306671b3d8SMadhukar Pappireddy 3316c91fc44SMadhukar Pappireddy /* Deactivate the corresponding Group0 interrupt. */ 3326c91fc44SMadhukar Pappireddy plat_ic_end_of_interrupt(intid); 3336c91fc44SMadhukar Pappireddy 3346671b3d8SMadhukar Pappireddy /* Return success. */ 3356671b3d8SMadhukar Pappireddy SMC_RET8(handle, FFA_SUCCESS_SMC32, FFA_PARAM_MBZ, FFA_PARAM_MBZ, 3366671b3d8SMadhukar Pappireddy FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, 3376671b3d8SMadhukar Pappireddy FFA_PARAM_MBZ); 3386671b3d8SMadhukar Pappireddy } 3396671b3d8SMadhukar Pappireddy 3400cea2ae0SManish V Badarkhe #if ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 3410cea2ae0SManish V Badarkhe static int spmd_dynamic_map_mem(uintptr_t base_addr, size_t size, 3420cea2ae0SManish V Badarkhe unsigned int attr, uintptr_t *align_addr, 3430cea2ae0SManish V Badarkhe size_t *align_size) 3440cea2ae0SManish V Badarkhe { 3450cea2ae0SManish V Badarkhe uintptr_t base_addr_align; 3460cea2ae0SManish V Badarkhe size_t mapped_size_align; 3470cea2ae0SManish V Badarkhe int rc; 3480cea2ae0SManish V Badarkhe 3490cea2ae0SManish V Badarkhe /* Page aligned address and size if necessary */ 3500cea2ae0SManish V Badarkhe base_addr_align = page_align(base_addr, DOWN); 3510cea2ae0SManish V Badarkhe mapped_size_align = page_align(size, UP); 3520cea2ae0SManish V Badarkhe 3530cea2ae0SManish V Badarkhe if ((base_addr != base_addr_align) && 3540cea2ae0SManish V Badarkhe (size == mapped_size_align)) { 3550cea2ae0SManish V Badarkhe mapped_size_align += PAGE_SIZE; 3560cea2ae0SManish V Badarkhe } 3570cea2ae0SManish V Badarkhe 3580cea2ae0SManish V Badarkhe /* 3590cea2ae0SManish V Badarkhe * Map dynamically given region with its aligned base address and 3600cea2ae0SManish V Badarkhe * size 3610cea2ae0SManish V Badarkhe */ 3620cea2ae0SManish V Badarkhe rc = mmap_add_dynamic_region((unsigned long long)base_addr_align, 3630cea2ae0SManish V Badarkhe base_addr_align, 3640cea2ae0SManish V Badarkhe mapped_size_align, 3650cea2ae0SManish V Badarkhe attr); 3660cea2ae0SManish V Badarkhe if (rc == 0) { 3670cea2ae0SManish V Badarkhe *align_addr = base_addr_align; 3680cea2ae0SManish V Badarkhe *align_size = mapped_size_align; 3690cea2ae0SManish V Badarkhe } 3700cea2ae0SManish V Badarkhe 3710cea2ae0SManish V Badarkhe return rc; 3720cea2ae0SManish V Badarkhe } 3730cea2ae0SManish V Badarkhe 3740cea2ae0SManish V Badarkhe static void spmd_do_sec_cpy(uintptr_t root_base_addr, uintptr_t sec_base_addr, 3750cea2ae0SManish V Badarkhe size_t size) 3760cea2ae0SManish V Badarkhe { 3770cea2ae0SManish V Badarkhe uintptr_t root_base_addr_align, sec_base_addr_align; 3780cea2ae0SManish V Badarkhe size_t root_mapped_size_align, sec_mapped_size_align; 3790cea2ae0SManish V Badarkhe int rc; 3800cea2ae0SManish V Badarkhe 3810cea2ae0SManish V Badarkhe assert(root_base_addr != 0UL); 3820cea2ae0SManish V Badarkhe assert(sec_base_addr != 0UL); 3830cea2ae0SManish V Badarkhe assert(size != 0UL); 3840cea2ae0SManish V Badarkhe 3850cea2ae0SManish V Badarkhe /* Map the memory with required attributes */ 3860cea2ae0SManish V Badarkhe rc = spmd_dynamic_map_mem(root_base_addr, size, MT_RO_DATA | MT_ROOT, 3870cea2ae0SManish V Badarkhe &root_base_addr_align, 3880cea2ae0SManish V Badarkhe &root_mapped_size_align); 3890cea2ae0SManish V Badarkhe if (rc != 0) { 3900cea2ae0SManish V Badarkhe ERROR("%s %s %lu (%d)\n", "Error while mapping", "root region", 3910cea2ae0SManish V Badarkhe root_base_addr, rc); 3920cea2ae0SManish V Badarkhe panic(); 3930cea2ae0SManish V Badarkhe } 3940cea2ae0SManish V Badarkhe 3950cea2ae0SManish V Badarkhe rc = spmd_dynamic_map_mem(sec_base_addr, size, MT_RW_DATA | MT_SECURE, 3960cea2ae0SManish V Badarkhe &sec_base_addr_align, &sec_mapped_size_align); 3970cea2ae0SManish V Badarkhe if (rc != 0) { 3980cea2ae0SManish V Badarkhe ERROR("%s %s %lu (%d)\n", "Error while mapping", 3990cea2ae0SManish V Badarkhe "secure region", sec_base_addr, rc); 4000cea2ae0SManish V Badarkhe panic(); 4010cea2ae0SManish V Badarkhe } 4020cea2ae0SManish V Badarkhe 4030cea2ae0SManish V Badarkhe /* Do copy operation */ 4040cea2ae0SManish V Badarkhe (void)memcpy((void *)sec_base_addr, (void *)root_base_addr, size); 4050cea2ae0SManish V Badarkhe 4060cea2ae0SManish V Badarkhe /* Unmap root memory region */ 4070cea2ae0SManish V Badarkhe rc = mmap_remove_dynamic_region(root_base_addr_align, 4080cea2ae0SManish V Badarkhe root_mapped_size_align); 4090cea2ae0SManish V Badarkhe if (rc != 0) { 4100cea2ae0SManish V Badarkhe ERROR("%s %s %lu (%d)\n", "Error while unmapping", 4110cea2ae0SManish V Badarkhe "root region", root_base_addr_align, rc); 4120cea2ae0SManish V Badarkhe panic(); 4130cea2ae0SManish V Badarkhe } 4140cea2ae0SManish V Badarkhe 4150cea2ae0SManish V Badarkhe /* Unmap secure memory region */ 4160cea2ae0SManish V Badarkhe rc = mmap_remove_dynamic_region(sec_base_addr_align, 4170cea2ae0SManish V Badarkhe sec_mapped_size_align); 4180cea2ae0SManish V Badarkhe if (rc != 0) { 4190cea2ae0SManish V Badarkhe ERROR("%s %s %lu (%d)\n", "Error while unmapping", 4200cea2ae0SManish V Badarkhe "secure region", sec_base_addr_align, rc); 4210cea2ae0SManish V Badarkhe panic(); 4220cea2ae0SManish V Badarkhe } 4230cea2ae0SManish V Badarkhe } 4240cea2ae0SManish V Badarkhe #endif /* ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 */ 4250cea2ae0SManish V Badarkhe 4268cb99c3fSOlivier Deprez /******************************************************************************* 42752696946SOlivier Deprez * Loads SPMC manifest and inits SPMC. 4280f14d02fSMax Shvetsov ******************************************************************************/ 42923d5ba86SOlivier Deprez static int spmd_spmc_init(void *pm_addr) 4300f14d02fSMax Shvetsov { 431f2dcf418SOlivier Deprez cpu_context_t *cpu_ctx; 432f2dcf418SOlivier Deprez unsigned int core_id; 4338cb99c3fSOlivier Deprez uint32_t ep_attr, flags; 43452696946SOlivier Deprez int rc; 4350cea2ae0SManish V Badarkhe const struct dyn_cfg_dtb_info_t *image_info __unused; 4360f14d02fSMax Shvetsov 43752696946SOlivier Deprez /* Load the SPM Core manifest */ 43823d5ba86SOlivier Deprez rc = plat_spm_core_manifest_load(&spmc_attrs, pm_addr); 4390f14d02fSMax Shvetsov if (rc != 0) { 44052696946SOlivier Deprez WARN("No or invalid SPM Core manifest image provided by BL2\n"); 44152696946SOlivier Deprez return rc; 4420f14d02fSMax Shvetsov } 4430f14d02fSMax Shvetsov 4440f14d02fSMax Shvetsov /* 44552696946SOlivier Deprez * Ensure that the SPM Core version is compatible with the SPM 44652696946SOlivier Deprez * Dispatcher version. 4470f14d02fSMax Shvetsov */ 448662af36dSJ-Alves if ((spmc_attrs.major_version != FFA_VERSION_MAJOR) || 449662af36dSJ-Alves (spmc_attrs.minor_version > FFA_VERSION_MINOR)) { 450662af36dSJ-Alves WARN("Unsupported FFA version (%u.%u)\n", 4510f14d02fSMax Shvetsov spmc_attrs.major_version, spmc_attrs.minor_version); 45252696946SOlivier Deprez return -EINVAL; 4530f14d02fSMax Shvetsov } 4540f14d02fSMax Shvetsov 455662af36dSJ-Alves VERBOSE("FFA version (%u.%u)\n", spmc_attrs.major_version, 4560f14d02fSMax Shvetsov spmc_attrs.minor_version); 4570f14d02fSMax Shvetsov 45852696946SOlivier Deprez VERBOSE("SPM Core run time EL%x.\n", 459033039f8SMax Shvetsov SPMD_SPM_AT_SEL2 ? MODE_EL2 : MODE_EL1); 4600f14d02fSMax Shvetsov 461ac03ac5eSMax Shvetsov /* Validate the SPMC ID, Ensure high bit is set */ 46252696946SOlivier Deprez if (((spmc_attrs.spmc_id >> SPMC_SECURE_ID_SHIFT) & 46352696946SOlivier Deprez SPMC_SECURE_ID_MASK) == 0U) { 46452696946SOlivier Deprez WARN("Invalid ID (0x%x) for SPMC.\n", spmc_attrs.spmc_id); 46552696946SOlivier Deprez return -EINVAL; 466ac03ac5eSMax Shvetsov } 467ac03ac5eSMax Shvetsov 46852696946SOlivier Deprez /* Validate the SPM Core execution state */ 4690f14d02fSMax Shvetsov if ((spmc_attrs.exec_state != MODE_RW_64) && 4700f14d02fSMax Shvetsov (spmc_attrs.exec_state != MODE_RW_32)) { 47123d5ba86SOlivier Deprez WARN("Unsupported %s%x.\n", "SPM Core execution state 0x", 4720f14d02fSMax Shvetsov spmc_attrs.exec_state); 47352696946SOlivier Deprez return -EINVAL; 4740f14d02fSMax Shvetsov } 4750f14d02fSMax Shvetsov 47623d5ba86SOlivier Deprez VERBOSE("%s%x.\n", "SPM Core execution state 0x", 47723d5ba86SOlivier Deprez spmc_attrs.exec_state); 4780f14d02fSMax Shvetsov 479033039f8SMax Shvetsov #if SPMD_SPM_AT_SEL2 480033039f8SMax Shvetsov /* Ensure manifest has not requested AArch32 state in S-EL2 */ 481033039f8SMax Shvetsov if (spmc_attrs.exec_state == MODE_RW_32) { 482033039f8SMax Shvetsov WARN("AArch32 state at S-EL2 is not supported.\n"); 48352696946SOlivier Deprez return -EINVAL; 4840f14d02fSMax Shvetsov } 4850f14d02fSMax Shvetsov 4860f14d02fSMax Shvetsov /* 4870f14d02fSMax Shvetsov * Check if S-EL2 is supported on this system if S-EL2 4880f14d02fSMax Shvetsov * is required for SPM 4890f14d02fSMax Shvetsov */ 490623f6140SAndre Przywara if (!is_feat_sel2_supported()) { 49152696946SOlivier Deprez WARN("SPM Core run time S-EL2 is not supported.\n"); 49252696946SOlivier Deprez return -EINVAL; 4930f14d02fSMax Shvetsov } 494033039f8SMax Shvetsov #endif /* SPMD_SPM_AT_SEL2 */ 4950f14d02fSMax Shvetsov 4960f14d02fSMax Shvetsov /* Initialise an entrypoint to set up the CPU context */ 4970f14d02fSMax Shvetsov ep_attr = SECURE | EP_ST_ENABLE; 49852696946SOlivier Deprez if ((read_sctlr_el3() & SCTLR_EE_BIT) != 0ULL) { 4990f14d02fSMax Shvetsov ep_attr |= EP_EE_BIG; 5000f14d02fSMax Shvetsov } 5010f14d02fSMax Shvetsov 5020f14d02fSMax Shvetsov SET_PARAM_HEAD(spmc_ep_info, PARAM_EP, VERSION_1, ep_attr); 5030f14d02fSMax Shvetsov 5040f14d02fSMax Shvetsov /* 50552696946SOlivier Deprez * Populate SPSR for SPM Core based upon validated parameters from the 50652696946SOlivier Deprez * manifest. 5070f14d02fSMax Shvetsov */ 5080f14d02fSMax Shvetsov if (spmc_attrs.exec_state == MODE_RW_32) { 5090f14d02fSMax Shvetsov spmc_ep_info->spsr = SPSR_MODE32(MODE32_svc, SPSR_T_ARM, 5100f14d02fSMax Shvetsov SPSR_E_LITTLE, 5110f14d02fSMax Shvetsov DAIF_FIQ_BIT | 5120f14d02fSMax Shvetsov DAIF_IRQ_BIT | 5130f14d02fSMax Shvetsov DAIF_ABT_BIT); 5140f14d02fSMax Shvetsov } else { 515033039f8SMax Shvetsov 516033039f8SMax Shvetsov #if SPMD_SPM_AT_SEL2 517033039f8SMax Shvetsov static const uint32_t runtime_el = MODE_EL2; 518033039f8SMax Shvetsov #else 519033039f8SMax Shvetsov static const uint32_t runtime_el = MODE_EL1; 520033039f8SMax Shvetsov #endif 521033039f8SMax Shvetsov spmc_ep_info->spsr = SPSR_64(runtime_el, 5220f14d02fSMax Shvetsov MODE_SP_ELX, 5230f14d02fSMax Shvetsov DISABLE_ALL_EXCEPTIONS); 5240f14d02fSMax Shvetsov } 5250f14d02fSMax Shvetsov 5260cea2ae0SManish V Badarkhe #if ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 5270cea2ae0SManish V Badarkhe image_info = FCONF_GET_PROPERTY(dyn_cfg, dtb, TOS_FW_CONFIG_ID); 5280cea2ae0SManish V Badarkhe assert(image_info != NULL); 5290cea2ae0SManish V Badarkhe 5300cea2ae0SManish V Badarkhe if ((image_info->config_addr == 0UL) || 5310cea2ae0SManish V Badarkhe (image_info->secondary_config_addr == 0UL) || 5320cea2ae0SManish V Badarkhe (image_info->config_max_size == 0UL)) { 5330cea2ae0SManish V Badarkhe return -EINVAL; 5340cea2ae0SManish V Badarkhe } 5350cea2ae0SManish V Badarkhe 5360cea2ae0SManish V Badarkhe /* Copy manifest from root->secure region */ 5370cea2ae0SManish V Badarkhe spmd_do_sec_cpy(image_info->config_addr, 5380cea2ae0SManish V Badarkhe image_info->secondary_config_addr, 5390cea2ae0SManish V Badarkhe image_info->config_max_size); 5400cea2ae0SManish V Badarkhe 5410cea2ae0SManish V Badarkhe /* Update ep info of BL32 */ 5420cea2ae0SManish V Badarkhe assert(spmc_ep_info != NULL); 5430cea2ae0SManish V Badarkhe spmc_ep_info->args.arg0 = image_info->secondary_config_addr; 5440cea2ae0SManish V Badarkhe #endif /* ENABLE_RME && SPMD_SPM_AT_SEL2 && !RESET_TO_BL31 */ 5450cea2ae0SManish V Badarkhe 546f2dcf418SOlivier Deprez /* Set an initial SPMC context state for all cores. */ 547f2dcf418SOlivier Deprez for (core_id = 0U; core_id < PLATFORM_CORE_COUNT; core_id++) { 548f2dcf418SOlivier Deprez spm_core_context[core_id].state = SPMC_STATE_OFF; 5490f14d02fSMax Shvetsov 550f2dcf418SOlivier Deprez /* Setup an initial cpu context for the SPMC. */ 551f2dcf418SOlivier Deprez cpu_ctx = &spm_core_context[core_id].cpu_ctx; 552f2dcf418SOlivier Deprez cm_setup_context(cpu_ctx, spmc_ep_info); 5530f14d02fSMax Shvetsov 554f2dcf418SOlivier Deprez /* 555f2dcf418SOlivier Deprez * Pass the core linear ID to the SPMC through x4. 556f2dcf418SOlivier Deprez * (TF-A implementation defined behavior helping 557f2dcf418SOlivier Deprez * a legacy TOS migration to adopt FF-A). 558f2dcf418SOlivier Deprez */ 559f2dcf418SOlivier Deprez write_ctx_reg(get_gpregs_ctx(cpu_ctx), CTX_GPREG_X4, core_id); 560f2dcf418SOlivier Deprez } 5610f14d02fSMax Shvetsov 562a334c4e6SOlivier Deprez /* Register power management hooks with PSCI */ 563a334c4e6SOlivier Deprez psci_register_spd_pm_hook(&spmd_pm); 564a334c4e6SOlivier Deprez 5650f14d02fSMax Shvetsov /* Register init function for deferred init. */ 5660f14d02fSMax Shvetsov bl31_register_bl32_init(&spmd_init); 5670f14d02fSMax Shvetsov 568f2dcf418SOlivier Deprez INFO("SPM Core setup done.\n"); 569f2dcf418SOlivier Deprez 5708cb99c3fSOlivier Deprez /* 5718cb99c3fSOlivier Deprez * Register an interrupt handler routing secure interrupts to SPMD 5728cb99c3fSOlivier Deprez * while the NWd is running. 5738cb99c3fSOlivier Deprez */ 5748cb99c3fSOlivier Deprez flags = 0; 5758cb99c3fSOlivier Deprez set_interrupt_rm_flag(flags, NON_SECURE); 5768cb99c3fSOlivier Deprez rc = register_interrupt_type_handler(INTR_TYPE_S_EL1, 5778cb99c3fSOlivier Deprez spmd_secure_interrupt_handler, 5788cb99c3fSOlivier Deprez flags); 5798cb99c3fSOlivier Deprez if (rc != 0) { 5808cb99c3fSOlivier Deprez panic(); 5818cb99c3fSOlivier Deprez } 5828cb99c3fSOlivier Deprez 583a1e0e871SMadhukar Pappireddy /* 584bb6d0a17SOlivier Deprez * Permit configurations where the SPM resides at S-EL1/2 and upon a 585bb6d0a17SOlivier Deprez * Group0 interrupt triggering while the normal world runs, the 586bb6d0a17SOlivier Deprez * interrupt is routed either through the EHF or directly to the SPMD: 587bb6d0a17SOlivier Deprez * 588bb6d0a17SOlivier Deprez * EL3_EXCEPTION_HANDLING=0: the Group0 interrupt is routed to the SPMD 589bb6d0a17SOlivier Deprez * for handling by spmd_group0_interrupt_handler_nwd. 590bb6d0a17SOlivier Deprez * 591bb6d0a17SOlivier Deprez * EL3_EXCEPTION_HANDLING=1: the Group0 interrupt is routed to the EHF. 592bb6d0a17SOlivier Deprez * 593bb6d0a17SOlivier Deprez */ 594bb6d0a17SOlivier Deprez #if (EL3_EXCEPTION_HANDLING == 0) 595bb6d0a17SOlivier Deprez /* 596*fca5f0ebSMadhukar Pappireddy * If EL3 interrupts are supported by the platform, register an 597*fca5f0ebSMadhukar Pappireddy * interrupt handler routing Group0 interrupts to SPMD while the NWd is 598*fca5f0ebSMadhukar Pappireddy * running. 599a1e0e871SMadhukar Pappireddy */ 600*fca5f0ebSMadhukar Pappireddy if (plat_ic_has_interrupt_type(INTR_TYPE_EL3)) { 601a1e0e871SMadhukar Pappireddy rc = register_interrupt_type_handler(INTR_TYPE_EL3, 602a1e0e871SMadhukar Pappireddy spmd_group0_interrupt_handler_nwd, 603a1e0e871SMadhukar Pappireddy flags); 604a1e0e871SMadhukar Pappireddy if (rc != 0) { 605a1e0e871SMadhukar Pappireddy panic(); 606a1e0e871SMadhukar Pappireddy } 607*fca5f0ebSMadhukar Pappireddy } 608bb6d0a17SOlivier Deprez #endif 609bb6d0a17SOlivier Deprez 6100f14d02fSMax Shvetsov return 0; 6110f14d02fSMax Shvetsov } 6120f14d02fSMax Shvetsov 6130f14d02fSMax Shvetsov /******************************************************************************* 61452696946SOlivier Deprez * Initialize context of SPM Core. 615bdd2596dSAchin Gupta ******************************************************************************/ 6160f14d02fSMax Shvetsov int spmd_setup(void) 617bdd2596dSAchin Gupta { 618bdd2596dSAchin Gupta int rc; 6196da76075SMarc Bonnici void *spmc_manifest; 6206da76075SMarc Bonnici 6216da76075SMarc Bonnici /* 6226da76075SMarc Bonnici * If the SPMC is at EL3, then just initialise it directly. The 6236da76075SMarc Bonnici * shenanigans of when it is at a lower EL are not needed. 6246da76075SMarc Bonnici */ 6256da76075SMarc Bonnici if (is_spmc_at_el3()) { 6266da76075SMarc Bonnici /* Allow the SPMC to populate its attributes directly. */ 6276da76075SMarc Bonnici spmc_populate_attrs(&spmc_attrs); 6286da76075SMarc Bonnici 6296da76075SMarc Bonnici rc = spmc_setup(); 6306da76075SMarc Bonnici if (rc != 0) { 6310d33649eSOlivier Deprez WARN("SPMC initialisation failed 0x%x.\n", rc); 6326da76075SMarc Bonnici } 6330d33649eSOlivier Deprez return 0; 6346da76075SMarc Bonnici } 635bdd2596dSAchin Gupta 636bdd2596dSAchin Gupta spmc_ep_info = bl31_plat_get_next_image_ep_info(SECURE); 63752696946SOlivier Deprez if (spmc_ep_info == NULL) { 63852696946SOlivier Deprez WARN("No SPM Core image provided by BL2 boot loader.\n"); 6390d33649eSOlivier Deprez return 0; 640bdd2596dSAchin Gupta } 641bdd2596dSAchin Gupta 642bdd2596dSAchin Gupta /* Under no circumstances will this parameter be 0 */ 64352696946SOlivier Deprez assert(spmc_ep_info->pc != 0ULL); 644bdd2596dSAchin Gupta 645bdd2596dSAchin Gupta /* 646bdd2596dSAchin Gupta * Check if BL32 ep_info has a reference to 'tos_fw_config'. This will 64752696946SOlivier Deprez * be used as a manifest for the SPM Core at the next lower EL/mode. 648bdd2596dSAchin Gupta */ 64923d5ba86SOlivier Deprez spmc_manifest = (void *)spmc_ep_info->args.arg0; 65023d5ba86SOlivier Deprez if (spmc_manifest == NULL) { 6510d33649eSOlivier Deprez WARN("Invalid or absent SPM Core manifest.\n"); 6520d33649eSOlivier Deprez return 0; 653bdd2596dSAchin Gupta } 654bdd2596dSAchin Gupta 6550f14d02fSMax Shvetsov /* Load manifest, init SPMC */ 65623d5ba86SOlivier Deprez rc = spmd_spmc_init(spmc_manifest); 6570f14d02fSMax Shvetsov if (rc != 0) { 65852696946SOlivier Deprez WARN("Booting device without SPM initialization.\n"); 659bdd2596dSAchin Gupta } 660bdd2596dSAchin Gupta 6610d33649eSOlivier Deprez return 0; 6620f14d02fSMax Shvetsov } 6630f14d02fSMax Shvetsov 6640f14d02fSMax Shvetsov /******************************************************************************* 665bb01a673SMarc Bonnici * Forward FF-A SMCs to the other security state. 6660f14d02fSMax Shvetsov ******************************************************************************/ 667bb01a673SMarc Bonnici uint64_t spmd_smc_switch_state(uint32_t smc_fid, 66852696946SOlivier Deprez bool secure_origin, 66952696946SOlivier Deprez uint64_t x1, 67052696946SOlivier Deprez uint64_t x2, 67152696946SOlivier Deprez uint64_t x3, 67252696946SOlivier Deprez uint64_t x4, 673c925867eSOlivier Deprez void *handle, 674c925867eSOlivier Deprez uint64_t flags) 6750f14d02fSMax Shvetsov { 676c2901419SOlivier Deprez unsigned int secure_state_in = (secure_origin) ? SECURE : NON_SECURE; 677c2901419SOlivier Deprez unsigned int secure_state_out = (!secure_origin) ? SECURE : NON_SECURE; 67893ff138bSOlivier Deprez 679c925867eSOlivier Deprez #if SPMD_SPM_AT_SEL2 680c925867eSOlivier Deprez if ((secure_state_out == SECURE) && (is_sve_hint_set(flags) == true)) { 681c925867eSOlivier Deprez /* 682c925867eSOlivier Deprez * Set the SVE hint bit in x0 and pass to the lower secure EL, 683c925867eSOlivier Deprez * if it was set by the caller. 684c925867eSOlivier Deprez */ 685c925867eSOlivier Deprez smc_fid |= (FUNCID_SVE_HINT_MASK << FUNCID_SVE_HINT_SHIFT); 686c925867eSOlivier Deprez } 687c925867eSOlivier Deprez #endif 688c925867eSOlivier Deprez 6890f14d02fSMax Shvetsov /* Save incoming security state */ 690033039f8SMax Shvetsov #if SPMD_SPM_AT_SEL2 691678ce223SOlivier Deprez if (secure_state_in == NON_SECURE) { 692678ce223SOlivier Deprez cm_el1_sysregs_context_save(secure_state_in); 693678ce223SOlivier Deprez } 69493ff138bSOlivier Deprez cm_el2_sysregs_context_save(secure_state_in); 695678ce223SOlivier Deprez #else 696678ce223SOlivier Deprez cm_el1_sysregs_context_save(secure_state_in); 697033039f8SMax Shvetsov #endif 6980f14d02fSMax Shvetsov 6990f14d02fSMax Shvetsov /* Restore outgoing security state */ 700033039f8SMax Shvetsov #if SPMD_SPM_AT_SEL2 701678ce223SOlivier Deprez if (secure_state_out == NON_SECURE) { 702678ce223SOlivier Deprez cm_el1_sysregs_context_restore(secure_state_out); 703678ce223SOlivier Deprez } 70493ff138bSOlivier Deprez cm_el2_sysregs_context_restore(secure_state_out); 705678ce223SOlivier Deprez #else 706678ce223SOlivier Deprez cm_el1_sysregs_context_restore(secure_state_out); 707033039f8SMax Shvetsov #endif 70893ff138bSOlivier Deprez cm_set_next_eret_context(secure_state_out); 7090f14d02fSMax Shvetsov 710eaaf517cSRaghu Krishnamurthy #if SPMD_SPM_AT_SEL2 711eaaf517cSRaghu Krishnamurthy /* 712eaaf517cSRaghu Krishnamurthy * If SPMC is at SEL2, save additional registers x8-x17, which may 713eaaf517cSRaghu Krishnamurthy * be used in FF-A calls such as FFA_PARTITION_INFO_GET_REGS. 714eaaf517cSRaghu Krishnamurthy * Note that technically, all SPMCs can support this, but this code is 715eaaf517cSRaghu Krishnamurthy * under ifdef to minimize breakage in case other SPMCs do not save 716eaaf517cSRaghu Krishnamurthy * and restore x8-x17. 717eaaf517cSRaghu Krishnamurthy * We also need to pass through these registers since not all FF-A ABIs 718eaaf517cSRaghu Krishnamurthy * modify x8-x17, in which case, SMCCC requires that these registers be 719eaaf517cSRaghu Krishnamurthy * preserved, so the SPMD passes through these registers and expects the 720eaaf517cSRaghu Krishnamurthy * SPMC to save and restore (potentially also modify) them. 721eaaf517cSRaghu Krishnamurthy */ 722eaaf517cSRaghu Krishnamurthy SMC_RET18(cm_get_context(secure_state_out), smc_fid, x1, x2, x3, x4, 723eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X5), 724eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X6), 725eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X7), 726eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X8), 727eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X9), 728eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X10), 729eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X11), 730eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X12), 731eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X13), 732eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X14), 733eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X15), 734eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X16), 735eaaf517cSRaghu Krishnamurthy SMC_GET_GP(handle, CTX_GPREG_X17) 736eaaf517cSRaghu Krishnamurthy ); 737eaaf517cSRaghu Krishnamurthy 738eaaf517cSRaghu Krishnamurthy #else 73993ff138bSOlivier Deprez SMC_RET8(cm_get_context(secure_state_out), smc_fid, x1, x2, x3, x4, 7400f14d02fSMax Shvetsov SMC_GET_GP(handle, CTX_GPREG_X5), 7410f14d02fSMax Shvetsov SMC_GET_GP(handle, CTX_GPREG_X6), 7420f14d02fSMax Shvetsov SMC_GET_GP(handle, CTX_GPREG_X7)); 743eaaf517cSRaghu Krishnamurthy #endif 7440f14d02fSMax Shvetsov } 7450f14d02fSMax Shvetsov 7460f14d02fSMax Shvetsov /******************************************************************************* 747bb01a673SMarc Bonnici * Forward SMCs to the other security state. 748bb01a673SMarc Bonnici ******************************************************************************/ 749bb01a673SMarc Bonnici static uint64_t spmd_smc_forward(uint32_t smc_fid, 750bb01a673SMarc Bonnici bool secure_origin, 751bb01a673SMarc Bonnici uint64_t x1, 752bb01a673SMarc Bonnici uint64_t x2, 753bb01a673SMarc Bonnici uint64_t x3, 754bb01a673SMarc Bonnici uint64_t x4, 755bb01a673SMarc Bonnici void *cookie, 756bb01a673SMarc Bonnici void *handle, 757bb01a673SMarc Bonnici uint64_t flags) 758bb01a673SMarc Bonnici { 759bb01a673SMarc Bonnici if (is_spmc_at_el3() && !secure_origin) { 760bb01a673SMarc Bonnici return spmc_smc_handler(smc_fid, secure_origin, x1, x2, x3, x4, 761bb01a673SMarc Bonnici cookie, handle, flags); 762bb01a673SMarc Bonnici } 763c925867eSOlivier Deprez 764bb01a673SMarc Bonnici return spmd_smc_switch_state(smc_fid, secure_origin, x1, x2, x3, x4, 765c925867eSOlivier Deprez handle, flags); 766bb01a673SMarc Bonnici 767bb01a673SMarc Bonnici } 768bb01a673SMarc Bonnici 769bb01a673SMarc Bonnici /******************************************************************************* 770662af36dSJ-Alves * Return FFA_ERROR with specified error code 7710f14d02fSMax Shvetsov ******************************************************************************/ 77295f7f6d8SRaghu Krishnamurthy uint64_t spmd_ffa_error_return(void *handle, int error_code) 7730f14d02fSMax Shvetsov { 774e46b2fd2SJ-Alves SMC_RET8(handle, (uint32_t) FFA_ERROR, 775e46b2fd2SJ-Alves FFA_TARGET_INFO_MBZ, (uint32_t)error_code, 776662af36dSJ-Alves FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, 777662af36dSJ-Alves FFA_PARAM_MBZ, FFA_PARAM_MBZ); 778bdd2596dSAchin Gupta } 779bdd2596dSAchin Gupta 780f0d743dbSOlivier Deprez /******************************************************************************* 781f0d743dbSOlivier Deprez * spmd_check_address_in_binary_image 782f0d743dbSOlivier Deprez ******************************************************************************/ 783f0d743dbSOlivier Deprez bool spmd_check_address_in_binary_image(uint64_t address) 784f0d743dbSOlivier Deprez { 785f0d743dbSOlivier Deprez assert(!check_uptr_overflow(spmc_attrs.load_address, spmc_attrs.binary_size)); 786f0d743dbSOlivier Deprez 787f0d743dbSOlivier Deprez return ((address >= spmc_attrs.load_address) && 788f0d743dbSOlivier Deprez (address < (spmc_attrs.load_address + spmc_attrs.binary_size))); 789f0d743dbSOlivier Deprez } 790f0d743dbSOlivier Deprez 791c2901419SOlivier Deprez /****************************************************************************** 792c2901419SOlivier Deprez * spmd_is_spmc_message 793c2901419SOlivier Deprez *****************************************************************************/ 794c2901419SOlivier Deprez static bool spmd_is_spmc_message(unsigned int ep) 795c2901419SOlivier Deprez { 796bb01a673SMarc Bonnici if (is_spmc_at_el3()) { 797bb01a673SMarc Bonnici return false; 798bb01a673SMarc Bonnici } 799bb01a673SMarc Bonnici 800c2901419SOlivier Deprez return ((ffa_endpoint_destination(ep) == SPMD_DIRECT_MSG_ENDPOINT_ID) 801c2901419SOlivier Deprez && (ffa_endpoint_source(ep) == spmc_attrs.spmc_id)); 802c2901419SOlivier Deprez } 803c2901419SOlivier Deprez 804f0d743dbSOlivier Deprez /****************************************************************************** 805f0d743dbSOlivier Deprez * spmd_handle_spmc_message 806f0d743dbSOlivier Deprez *****************************************************************************/ 807a92bc73bSOlivier Deprez static int spmd_handle_spmc_message(unsigned long long msg, 808a92bc73bSOlivier Deprez unsigned long long parm1, unsigned long long parm2, 809a92bc73bSOlivier Deprez unsigned long long parm3, unsigned long long parm4) 810f0d743dbSOlivier Deprez { 811f0d743dbSOlivier Deprez VERBOSE("%s %llx %llx %llx %llx %llx\n", __func__, 812f0d743dbSOlivier Deprez msg, parm1, parm2, parm3, parm4); 813f0d743dbSOlivier Deprez 814f0d743dbSOlivier Deprez return -EINVAL; 815f0d743dbSOlivier Deprez } 816f0d743dbSOlivier Deprez 817bdd2596dSAchin Gupta /******************************************************************************* 818bb01a673SMarc Bonnici * This function forwards FF-A SMCs to either the main SPMD handler or the 819bb01a673SMarc Bonnici * SPMC at EL3, depending on the origin security state, if enabled. 820bb01a673SMarc Bonnici ******************************************************************************/ 821bb01a673SMarc Bonnici uint64_t spmd_ffa_smc_handler(uint32_t smc_fid, 822bb01a673SMarc Bonnici uint64_t x1, 823bb01a673SMarc Bonnici uint64_t x2, 824bb01a673SMarc Bonnici uint64_t x3, 825bb01a673SMarc Bonnici uint64_t x4, 826bb01a673SMarc Bonnici void *cookie, 827bb01a673SMarc Bonnici void *handle, 828bb01a673SMarc Bonnici uint64_t flags) 829bb01a673SMarc Bonnici { 830bb01a673SMarc Bonnici if (is_spmc_at_el3()) { 831bb01a673SMarc Bonnici /* 832bb01a673SMarc Bonnici * If we have an SPMC at EL3 allow handling of the SMC first. 833bb01a673SMarc Bonnici * The SPMC will call back through to SPMD handler if required. 834bb01a673SMarc Bonnici */ 835bb01a673SMarc Bonnici if (is_caller_secure(flags)) { 836bb01a673SMarc Bonnici return spmc_smc_handler(smc_fid, 837bb01a673SMarc Bonnici is_caller_secure(flags), 838bb01a673SMarc Bonnici x1, x2, x3, x4, cookie, 839bb01a673SMarc Bonnici handle, flags); 840bb01a673SMarc Bonnici } 841bb01a673SMarc Bonnici } 842bb01a673SMarc Bonnici return spmd_smc_handler(smc_fid, x1, x2, x3, x4, cookie, 843bb01a673SMarc Bonnici handle, flags); 844bb01a673SMarc Bonnici } 845bb01a673SMarc Bonnici 846bb01a673SMarc Bonnici /******************************************************************************* 847662af36dSJ-Alves * This function handles all SMCs in the range reserved for FFA. Each call is 848bdd2596dSAchin Gupta * either forwarded to the other security state or handled by the SPM dispatcher 849bdd2596dSAchin Gupta ******************************************************************************/ 85052696946SOlivier Deprez uint64_t spmd_smc_handler(uint32_t smc_fid, 85152696946SOlivier Deprez uint64_t x1, 85252696946SOlivier Deprez uint64_t x2, 85352696946SOlivier Deprez uint64_t x3, 85452696946SOlivier Deprez uint64_t x4, 85552696946SOlivier Deprez void *cookie, 85652696946SOlivier Deprez void *handle, 857bdd2596dSAchin Gupta uint64_t flags) 858bdd2596dSAchin Gupta { 859cdb49d47SOlivier Deprez unsigned int linear_id = plat_my_core_pos(); 86052696946SOlivier Deprez spmd_spm_core_context_t *ctx = spmd_get_context(); 86193ff138bSOlivier Deprez bool secure_origin; 8626873088cSJ-Alves int ret; 8634388f28fSJ-Alves uint32_t input_version; 864bdd2596dSAchin Gupta 865bdd2596dSAchin Gupta /* Determine which security state this SMC originated from */ 86693ff138bSOlivier Deprez secure_origin = is_caller_secure(flags); 867bdd2596dSAchin Gupta 8684ce3e99aSScott Branden VERBOSE("SPM(%u): 0x%x 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 8694ce3e99aSScott Branden " 0x%" PRIx64 " 0x%" PRIx64 " 0x%" PRIx64 "\n", 870cdb49d47SOlivier Deprez linear_id, smc_fid, x1, x2, x3, x4, 871cdb49d47SOlivier Deprez SMC_GET_GP(handle, CTX_GPREG_X5), 872bdd2596dSAchin Gupta SMC_GET_GP(handle, CTX_GPREG_X6), 873bdd2596dSAchin Gupta SMC_GET_GP(handle, CTX_GPREG_X7)); 874bdd2596dSAchin Gupta 8750b850e9eSRaghu Krishnamurthy /* 8760b850e9eSRaghu Krishnamurthy * If there is an on-going info regs from EL3 SPMD LP, unconditionally 8770b850e9eSRaghu Krishnamurthy * return, we don't expect any other FF-A ABIs to be called between 8780b850e9eSRaghu Krishnamurthy * calls to FFA_PARTITION_INFO_GET_REGS. 8790b850e9eSRaghu Krishnamurthy */ 8800b850e9eSRaghu Krishnamurthy if (is_spmd_logical_sp_info_regs_req_in_progress(ctx)) { 8810b850e9eSRaghu Krishnamurthy assert(secure_origin); 8820b850e9eSRaghu Krishnamurthy spmd_spm_core_sync_exit(0ULL); 8830b850e9eSRaghu Krishnamurthy } 8840b850e9eSRaghu Krishnamurthy 885bdd2596dSAchin Gupta switch (smc_fid) { 886662af36dSJ-Alves case FFA_ERROR: 887bdd2596dSAchin Gupta /* 888bdd2596dSAchin Gupta * Check if this is the first invocation of this interface on 88952696946SOlivier Deprez * this CPU. If so, then indicate that the SPM Core initialised 890bdd2596dSAchin Gupta * unsuccessfully. 891bdd2596dSAchin Gupta */ 8929dcf63ddSOlivier Deprez if (secure_origin && (ctx->state == SPMC_STATE_ON_PENDING)) { 893bdd2596dSAchin Gupta spmd_spm_core_sync_exit(x2); 8940f14d02fSMax Shvetsov } 895bdd2596dSAchin Gupta 89666bdfd6eSRaghu Krishnamurthy /* 89766bdfd6eSRaghu Krishnamurthy * If there was an SPMD logical partition direct request on-going, 89866bdfd6eSRaghu Krishnamurthy * return back to the SPMD logical partition so the error can be 89966bdfd6eSRaghu Krishnamurthy * consumed. 90066bdfd6eSRaghu Krishnamurthy */ 90166bdfd6eSRaghu Krishnamurthy if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { 90266bdfd6eSRaghu Krishnamurthy assert(secure_origin); 90366bdfd6eSRaghu Krishnamurthy spmd_spm_core_sync_exit(0ULL); 90466bdfd6eSRaghu Krishnamurthy } 90566bdfd6eSRaghu Krishnamurthy 90693ff138bSOlivier Deprez return spmd_smc_forward(smc_fid, secure_origin, 907bb01a673SMarc Bonnici x1, x2, x3, x4, cookie, 908bb01a673SMarc Bonnici handle, flags); 909bdd2596dSAchin Gupta break; /* not reached */ 910bdd2596dSAchin Gupta 911662af36dSJ-Alves case FFA_VERSION: 9124388f28fSJ-Alves input_version = (uint32_t)(0xFFFFFFFF & x1); 913bdd2596dSAchin Gupta /* 9144388f28fSJ-Alves * If caller is secure and SPMC was initialized, 9154388f28fSJ-Alves * return FFA_VERSION of SPMD. 9164388f28fSJ-Alves * If caller is non secure and SPMC was initialized, 9179576fa93SMarc Bonnici * forward to the EL3 SPMC if enabled, otherwise return 9189576fa93SMarc Bonnici * the SPMC version if implemented at a lower EL. 9194388f28fSJ-Alves * Sanity check to "input_version". 920bb01a673SMarc Bonnici * If the EL3 SPMC is enabled, ignore the SPMC state as 921bb01a673SMarc Bonnici * this is not used. 922bdd2596dSAchin Gupta */ 9234388f28fSJ-Alves if ((input_version & FFA_VERSION_BIT31_MASK) || 924bb01a673SMarc Bonnici (!is_spmc_at_el3() && (ctx->state == SPMC_STATE_RESET))) { 9254388f28fSJ-Alves ret = FFA_ERROR_NOT_SUPPORTED; 9264388f28fSJ-Alves } else if (!secure_origin) { 9279576fa93SMarc Bonnici if (is_spmc_at_el3()) { 9289576fa93SMarc Bonnici /* 9299576fa93SMarc Bonnici * Forward the call directly to the EL3 SPMC, if 9309576fa93SMarc Bonnici * enabled, as we don't need to wrap the call in 9319576fa93SMarc Bonnici * a direct request. 9329576fa93SMarc Bonnici */ 9339576fa93SMarc Bonnici return spmd_smc_forward(smc_fid, secure_origin, 9349576fa93SMarc Bonnici x1, x2, x3, x4, cookie, 9359576fa93SMarc Bonnici handle, flags); 9369576fa93SMarc Bonnici } 9379576fa93SMarc Bonnici 9389944f557SDaniel Boulby gp_regs_t *gpregs = get_gpregs_ctx(&ctx->cpu_ctx); 9399944f557SDaniel Boulby uint64_t rc; 9409944f557SDaniel Boulby 9419944f557SDaniel Boulby if (spmc_attrs.major_version == 1 && 9429944f557SDaniel Boulby spmc_attrs.minor_version == 0) { 943e46b2fd2SJ-Alves ret = MAKE_FFA_VERSION(spmc_attrs.major_version, 944e46b2fd2SJ-Alves spmc_attrs.minor_version); 9459944f557SDaniel Boulby SMC_RET8(handle, (uint32_t)ret, 9469944f557SDaniel Boulby FFA_TARGET_INFO_MBZ, 9479944f557SDaniel Boulby FFA_TARGET_INFO_MBZ, 9489944f557SDaniel Boulby FFA_PARAM_MBZ, FFA_PARAM_MBZ, 9499944f557SDaniel Boulby FFA_PARAM_MBZ, FFA_PARAM_MBZ, 9509944f557SDaniel Boulby FFA_PARAM_MBZ); 9519944f557SDaniel Boulby break; 9529944f557SDaniel Boulby } 9539944f557SDaniel Boulby /* Save non-secure system registers context */ 9549944f557SDaniel Boulby cm_el1_sysregs_context_save(NON_SECURE); 9559944f557SDaniel Boulby #if SPMD_SPM_AT_SEL2 9569944f557SDaniel Boulby cm_el2_sysregs_context_save(NON_SECURE); 9579944f557SDaniel Boulby #endif 9589944f557SDaniel Boulby 9599944f557SDaniel Boulby /* 9609944f557SDaniel Boulby * The incoming request has FFA_VERSION as X0 smc_fid 9619944f557SDaniel Boulby * and requested version in x1. Prepare a direct request 9629944f557SDaniel Boulby * from SPMD to SPMC with FFA_VERSION framework function 9639944f557SDaniel Boulby * identifier in X2 and requested version in X3. 9649944f557SDaniel Boulby */ 9659944f557SDaniel Boulby spmd_build_spmc_message(gpregs, 9669944f557SDaniel Boulby SPMD_FWK_MSG_FFA_VERSION_REQ, 9679944f557SDaniel Boulby input_version); 9689944f557SDaniel Boulby 96976d53ee1SOlivier Deprez /* 97076d53ee1SOlivier Deprez * Ensure x8-x17 NS GP register values are untouched when returning 97176d53ee1SOlivier Deprez * from the SPMC. 97276d53ee1SOlivier Deprez */ 97376d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X8, SMC_GET_GP(handle, CTX_GPREG_X8)); 97476d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X9, SMC_GET_GP(handle, CTX_GPREG_X9)); 97576d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X10, SMC_GET_GP(handle, CTX_GPREG_X10)); 97676d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X11, SMC_GET_GP(handle, CTX_GPREG_X11)); 97776d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X12, SMC_GET_GP(handle, CTX_GPREG_X12)); 97876d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X13, SMC_GET_GP(handle, CTX_GPREG_X13)); 97976d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X14, SMC_GET_GP(handle, CTX_GPREG_X14)); 98076d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X15, SMC_GET_GP(handle, CTX_GPREG_X15)); 98176d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X16, SMC_GET_GP(handle, CTX_GPREG_X16)); 98276d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X17, SMC_GET_GP(handle, CTX_GPREG_X17)); 98376d53ee1SOlivier Deprez 9849944f557SDaniel Boulby rc = spmd_spm_core_sync_entry(ctx); 9859944f557SDaniel Boulby 9869944f557SDaniel Boulby if ((rc != 0ULL) || 9879944f557SDaniel Boulby (SMC_GET_GP(gpregs, CTX_GPREG_X0) != 9889944f557SDaniel Boulby FFA_MSG_SEND_DIRECT_RESP_SMC32) || 9899944f557SDaniel Boulby (SMC_GET_GP(gpregs, CTX_GPREG_X2) != 99059bd2ad8SMarc Bonnici (FFA_FWK_MSG_BIT | 9919944f557SDaniel Boulby SPMD_FWK_MSG_FFA_VERSION_RESP))) { 9929944f557SDaniel Boulby ERROR("Failed to forward FFA_VERSION\n"); 9939944f557SDaniel Boulby ret = FFA_ERROR_NOT_SUPPORTED; 9949944f557SDaniel Boulby } else { 9959944f557SDaniel Boulby ret = SMC_GET_GP(gpregs, CTX_GPREG_X3); 9969944f557SDaniel Boulby } 9979944f557SDaniel Boulby 9989944f557SDaniel Boulby /* 99976d53ee1SOlivier Deprez * x0-x4 are updated by spmd_smc_forward below. 100076d53ee1SOlivier Deprez * Zero out x5-x7 in the FFA_VERSION response. 100176d53ee1SOlivier Deprez */ 100276d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X5, 0); 100376d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X6, 0); 100476d53ee1SOlivier Deprez write_ctx_reg(gpregs, CTX_GPREG_X7, 0); 100576d53ee1SOlivier Deprez 100676d53ee1SOlivier Deprez /* 10079944f557SDaniel Boulby * Return here after SPMC has handled FFA_VERSION. 10089944f557SDaniel Boulby * The returned SPMC version is held in X3. 10099944f557SDaniel Boulby * Forward this version in X0 to the non-secure caller. 10109944f557SDaniel Boulby */ 10119944f557SDaniel Boulby return spmd_smc_forward(ret, true, FFA_PARAM_MBZ, 10129944f557SDaniel Boulby FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1013bb01a673SMarc Bonnici FFA_PARAM_MBZ, cookie, gpregs, 1014bb01a673SMarc Bonnici flags); 10154388f28fSJ-Alves } else { 1016e46b2fd2SJ-Alves ret = MAKE_FFA_VERSION(FFA_VERSION_MAJOR, 1017e46b2fd2SJ-Alves FFA_VERSION_MINOR); 10184388f28fSJ-Alves } 10194388f28fSJ-Alves 1020e46b2fd2SJ-Alves SMC_RET8(handle, (uint32_t)ret, FFA_TARGET_INFO_MBZ, 1021e46b2fd2SJ-Alves FFA_TARGET_INFO_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1022e46b2fd2SJ-Alves FFA_PARAM_MBZ, FFA_PARAM_MBZ, FFA_PARAM_MBZ); 1023bdd2596dSAchin Gupta break; /* not reached */ 1024bdd2596dSAchin Gupta 1025662af36dSJ-Alves case FFA_FEATURES: 1026bdd2596dSAchin Gupta /* 1027bdd2596dSAchin Gupta * This is an optional interface. Do the minimal checks and 102852696946SOlivier Deprez * forward to SPM Core which will handle it if implemented. 1029bdd2596dSAchin Gupta */ 1030bdd2596dSAchin Gupta 103152696946SOlivier Deprez /* Forward SMC from Normal world to the SPM Core */ 103293ff138bSOlivier Deprez if (!secure_origin) { 103393ff138bSOlivier Deprez return spmd_smc_forward(smc_fid, secure_origin, 1034bb01a673SMarc Bonnici x1, x2, x3, x4, cookie, 1035bb01a673SMarc Bonnici handle, flags); 103652696946SOlivier Deprez } 103752696946SOlivier Deprez 1038bdd2596dSAchin Gupta /* 1039bdd2596dSAchin Gupta * Return success if call was from secure world i.e. all 1040662af36dSJ-Alves * FFA functions are supported. This is essentially a 1041bdd2596dSAchin Gupta * nop. 1042bdd2596dSAchin Gupta */ 1043662af36dSJ-Alves SMC_RET8(handle, FFA_SUCCESS_SMC32, x1, x2, x3, x4, 1044bdd2596dSAchin Gupta SMC_GET_GP(handle, CTX_GPREG_X5), 1045bdd2596dSAchin Gupta SMC_GET_GP(handle, CTX_GPREG_X6), 1046bdd2596dSAchin Gupta SMC_GET_GP(handle, CTX_GPREG_X7)); 10470f14d02fSMax Shvetsov 1048bdd2596dSAchin Gupta break; /* not reached */ 1049bdd2596dSAchin Gupta 1050662af36dSJ-Alves case FFA_ID_GET: 1051ac03ac5eSMax Shvetsov /* 1052662af36dSJ-Alves * Returns the ID of the calling FFA component. 1053ac03ac5eSMax Shvetsov */ 1054ac03ac5eSMax Shvetsov if (!secure_origin) { 1055662af36dSJ-Alves SMC_RET8(handle, FFA_SUCCESS_SMC32, 1056662af36dSJ-Alves FFA_TARGET_INFO_MBZ, FFA_NS_ENDPOINT_ID, 1057662af36dSJ-Alves FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1058662af36dSJ-Alves FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1059662af36dSJ-Alves FFA_PARAM_MBZ); 106052696946SOlivier Deprez } 106152696946SOlivier Deprez 1062662af36dSJ-Alves SMC_RET8(handle, FFA_SUCCESS_SMC32, 1063662af36dSJ-Alves FFA_TARGET_INFO_MBZ, spmc_attrs.spmc_id, 1064662af36dSJ-Alves FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1065662af36dSJ-Alves FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1066662af36dSJ-Alves FFA_PARAM_MBZ); 1067ac03ac5eSMax Shvetsov 1068ac03ac5eSMax Shvetsov break; /* not reached */ 1069ac03ac5eSMax Shvetsov 1070cdb49d47SOlivier Deprez case FFA_SECONDARY_EP_REGISTER_SMC64: 1071cdb49d47SOlivier Deprez if (secure_origin) { 1072cdb49d47SOlivier Deprez ret = spmd_pm_secondary_ep_register(x1); 1073cdb49d47SOlivier Deprez 1074cdb49d47SOlivier Deprez if (ret < 0) { 1075cdb49d47SOlivier Deprez SMC_RET8(handle, FFA_ERROR_SMC64, 1076cdb49d47SOlivier Deprez FFA_TARGET_INFO_MBZ, ret, 1077cdb49d47SOlivier Deprez FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1078cdb49d47SOlivier Deprez FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1079cdb49d47SOlivier Deprez FFA_PARAM_MBZ); 1080cdb49d47SOlivier Deprez } else { 1081cdb49d47SOlivier Deprez SMC_RET8(handle, FFA_SUCCESS_SMC64, 1082cdb49d47SOlivier Deprez FFA_TARGET_INFO_MBZ, FFA_PARAM_MBZ, 1083cdb49d47SOlivier Deprez FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1084cdb49d47SOlivier Deprez FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1085cdb49d47SOlivier Deprez FFA_PARAM_MBZ); 1086cdb49d47SOlivier Deprez } 1087cdb49d47SOlivier Deprez } 1088cdb49d47SOlivier Deprez 1089cdb49d47SOlivier Deprez return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); 1090cdb49d47SOlivier Deprez break; /* Not reached */ 1091cdb49d47SOlivier Deprez 109270c121a2SDaniel Boulby case FFA_SPM_ID_GET: 109370c121a2SDaniel Boulby if (MAKE_FFA_VERSION(1, 1) > FFA_VERSION_COMPILED) { 109470c121a2SDaniel Boulby return spmd_ffa_error_return(handle, 109570c121a2SDaniel Boulby FFA_ERROR_NOT_SUPPORTED); 109670c121a2SDaniel Boulby } 109770c121a2SDaniel Boulby /* 109870c121a2SDaniel Boulby * Returns the ID of the SPMC or SPMD depending on the FF-A 109970c121a2SDaniel Boulby * instance where this function is invoked 110070c121a2SDaniel Boulby */ 110170c121a2SDaniel Boulby if (!secure_origin) { 110270c121a2SDaniel Boulby SMC_RET8(handle, FFA_SUCCESS_SMC32, 110370c121a2SDaniel Boulby FFA_TARGET_INFO_MBZ, spmc_attrs.spmc_id, 110470c121a2SDaniel Boulby FFA_PARAM_MBZ, FFA_PARAM_MBZ, 110570c121a2SDaniel Boulby FFA_PARAM_MBZ, FFA_PARAM_MBZ, 110670c121a2SDaniel Boulby FFA_PARAM_MBZ); 110770c121a2SDaniel Boulby } 110870c121a2SDaniel Boulby SMC_RET8(handle, FFA_SUCCESS_SMC32, 110970c121a2SDaniel Boulby FFA_TARGET_INFO_MBZ, SPMD_DIRECT_MSG_ENDPOINT_ID, 111070c121a2SDaniel Boulby FFA_PARAM_MBZ, FFA_PARAM_MBZ, 111170c121a2SDaniel Boulby FFA_PARAM_MBZ, FFA_PARAM_MBZ, 111270c121a2SDaniel Boulby FFA_PARAM_MBZ); 111370c121a2SDaniel Boulby 111470c121a2SDaniel Boulby break; /* not reached */ 111570c121a2SDaniel Boulby 1116f0d743dbSOlivier Deprez case FFA_MSG_SEND_DIRECT_REQ_SMC32: 11175519f07cSShruti case FFA_MSG_SEND_DIRECT_REQ_SMC64: 111866bdfd6eSRaghu Krishnamurthy /* 111966bdfd6eSRaghu Krishnamurthy * Regardless of secure_origin, SPMD logical partitions cannot 112066bdfd6eSRaghu Krishnamurthy * handle direct messages. They can only initiate direct 112166bdfd6eSRaghu Krishnamurthy * messages and consume direct responses or errors. 112266bdfd6eSRaghu Krishnamurthy */ 112366bdfd6eSRaghu Krishnamurthy if (is_spmd_lp_id(ffa_endpoint_source(x1)) || 112466bdfd6eSRaghu Krishnamurthy is_spmd_lp_id(ffa_endpoint_destination(x1))) { 112566bdfd6eSRaghu Krishnamurthy return spmd_ffa_error_return(handle, 112666bdfd6eSRaghu Krishnamurthy FFA_ERROR_INVALID_PARAMETER 112766bdfd6eSRaghu Krishnamurthy ); 112866bdfd6eSRaghu Krishnamurthy } 112966bdfd6eSRaghu Krishnamurthy 113066bdfd6eSRaghu Krishnamurthy /* 113166bdfd6eSRaghu Krishnamurthy * When there is an ongoing SPMD logical partition direct 113266bdfd6eSRaghu Krishnamurthy * request, there cannot be another direct request. Return 113366bdfd6eSRaghu Krishnamurthy * error in this case. Panic'ing is an option but that does 113466bdfd6eSRaghu Krishnamurthy * not provide the opportunity for caller to abort based on 113566bdfd6eSRaghu Krishnamurthy * error codes. 113666bdfd6eSRaghu Krishnamurthy */ 113766bdfd6eSRaghu Krishnamurthy if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { 113866bdfd6eSRaghu Krishnamurthy assert(secure_origin); 113966bdfd6eSRaghu Krishnamurthy return spmd_ffa_error_return(handle, 114066bdfd6eSRaghu Krishnamurthy FFA_ERROR_DENIED); 114166bdfd6eSRaghu Krishnamurthy } 114266bdfd6eSRaghu Krishnamurthy 11435519f07cSShruti if (!secure_origin) { 11445519f07cSShruti /* Validate source endpoint is non-secure for non-secure caller. */ 11455519f07cSShruti if (ffa_is_secure_world_id(ffa_endpoint_source(x1))) { 11465519f07cSShruti return spmd_ffa_error_return(handle, 11475519f07cSShruti FFA_ERROR_INVALID_PARAMETER); 11485519f07cSShruti } 11495519f07cSShruti } 1150f0d743dbSOlivier Deprez if (secure_origin && spmd_is_spmc_message(x1)) { 1151f0d743dbSOlivier Deprez ret = spmd_handle_spmc_message(x3, x4, 1152f0d743dbSOlivier Deprez SMC_GET_GP(handle, CTX_GPREG_X5), 1153f0d743dbSOlivier Deprez SMC_GET_GP(handle, CTX_GPREG_X6), 1154f0d743dbSOlivier Deprez SMC_GET_GP(handle, CTX_GPREG_X7)); 1155f0d743dbSOlivier Deprez 1156f0d743dbSOlivier Deprez SMC_RET8(handle, FFA_SUCCESS_SMC32, 1157f0d743dbSOlivier Deprez FFA_TARGET_INFO_MBZ, ret, 1158f0d743dbSOlivier Deprez FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1159f0d743dbSOlivier Deprez FFA_PARAM_MBZ, FFA_PARAM_MBZ, 1160f0d743dbSOlivier Deprez FFA_PARAM_MBZ); 1161f0d743dbSOlivier Deprez } else { 1162f0d743dbSOlivier Deprez /* Forward direct message to the other world */ 1163f0d743dbSOlivier Deprez return spmd_smc_forward(smc_fid, secure_origin, 1164bb01a673SMarc Bonnici x1, x2, x3, x4, cookie, 1165bb01a673SMarc Bonnici handle, flags); 1166f0d743dbSOlivier Deprez } 1167f0d743dbSOlivier Deprez break; /* Not reached */ 1168f0d743dbSOlivier Deprez 1169cc6047b3SKathleen Capella case FFA_MSG_SEND_DIRECT_REQ2_SMC64: 1170cc6047b3SKathleen Capella if (!secure_origin) { 1171cc6047b3SKathleen Capella /* Validate source endpoint is non-secure for non-secure caller. */ 1172cc6047b3SKathleen Capella if (ffa_is_secure_world_id(ffa_endpoint_source(x1))) { 1173cc6047b3SKathleen Capella return spmd_ffa_error_return(handle, 1174cc6047b3SKathleen Capella FFA_ERROR_INVALID_PARAMETER); 1175cc6047b3SKathleen Capella } 1176cc6047b3SKathleen Capella } 1177cc6047b3SKathleen Capella /* FFA_MSG_SEND_DIRECT_REQ2 not used for framework messages. */ 1178cc6047b3SKathleen Capella if (secure_origin && spmd_is_spmc_message(x1)) { 1179cc6047b3SKathleen Capella return spmd_ffa_error_return(handle, FFA_ERROR_INVALID_PARAMETER); 1180cc6047b3SKathleen Capella } else { 1181cc6047b3SKathleen Capella /* Forward direct message to the other world */ 1182cc6047b3SKathleen Capella return spmd_smc_forward(smc_fid, secure_origin, 1183cc6047b3SKathleen Capella x1, x2, x3, x4, cookie, 1184cc6047b3SKathleen Capella handle, flags); 1185cc6047b3SKathleen Capella } 1186cc6047b3SKathleen Capella break; /* Not reached */ 1187cc6047b3SKathleen Capella 1188f0d743dbSOlivier Deprez case FFA_MSG_SEND_DIRECT_RESP_SMC32: 118966bdfd6eSRaghu Krishnamurthy case FFA_MSG_SEND_DIRECT_RESP_SMC64: 119066bdfd6eSRaghu Krishnamurthy if (secure_origin && (spmd_is_spmc_message(x1) || 119166bdfd6eSRaghu Krishnamurthy is_spmd_logical_sp_dir_req_in_progress(ctx))) { 11928cb99c3fSOlivier Deprez spmd_spm_core_sync_exit(0ULL); 1193f0d743dbSOlivier Deprez } else { 1194f0d743dbSOlivier Deprez /* Forward direct message to the other world */ 1195f0d743dbSOlivier Deprez return spmd_smc_forward(smc_fid, secure_origin, 1196bb01a673SMarc Bonnici x1, x2, x3, x4, cookie, 1197bb01a673SMarc Bonnici handle, flags); 1198f0d743dbSOlivier Deprez } 1199f0d743dbSOlivier Deprez break; /* Not reached */ 12000651b7beSKathleen Capella case FFA_MSG_SEND_DIRECT_RESP2_SMC64: 12010651b7beSKathleen Capella /* Forward direct message to the other world */ 12020651b7beSKathleen Capella return spmd_smc_forward(smc_fid, secure_origin, 12030651b7beSKathleen Capella x1, x2, x3, x4, cookie, 12040651b7beSKathleen Capella handle, flags); 12050651b7beSKathleen Capella break; /* Not reached */ 1206662af36dSJ-Alves case FFA_RX_RELEASE: 1207662af36dSJ-Alves case FFA_RXTX_MAP_SMC32: 1208662af36dSJ-Alves case FFA_RXTX_MAP_SMC64: 1209662af36dSJ-Alves case FFA_RXTX_UNMAP: 1210545b8eb3SRuari Phipps case FFA_PARTITION_INFO_GET: 1211fc3f4800SJ-Alves #if MAKE_FFA_VERSION(1, 1) <= FFA_VERSION_COMPILED 1212fc3f4800SJ-Alves case FFA_NOTIFICATION_BITMAP_CREATE: 1213fc3f4800SJ-Alves case FFA_NOTIFICATION_BITMAP_DESTROY: 1214fc3f4800SJ-Alves case FFA_NOTIFICATION_BIND: 1215fc3f4800SJ-Alves case FFA_NOTIFICATION_UNBIND: 1216fc3f4800SJ-Alves case FFA_NOTIFICATION_SET: 1217fc3f4800SJ-Alves case FFA_NOTIFICATION_GET: 1218fc3f4800SJ-Alves case FFA_NOTIFICATION_INFO_GET: 1219fc3f4800SJ-Alves case FFA_NOTIFICATION_INFO_GET_SMC64: 1220c2eba07cSFederico Recanati case FFA_MSG_SEND2: 1221d555233fSFederico Recanati case FFA_RX_ACQUIRE: 1222fc3f4800SJ-Alves #endif 1223662af36dSJ-Alves case FFA_MSG_RUN: 1224c2eba07cSFederico Recanati /* 1225c2eba07cSFederico Recanati * Above calls should be invoked only by the Normal world and 1226c2eba07cSFederico Recanati * must not be forwarded from Secure world to Normal world. 1227c2eba07cSFederico Recanati */ 122893ff138bSOlivier Deprez if (secure_origin) { 1229662af36dSJ-Alves return spmd_ffa_error_return(handle, 1230662af36dSJ-Alves FFA_ERROR_NOT_SUPPORTED); 1231bdd2596dSAchin Gupta } 1232bdd2596dSAchin Gupta 1233e138400dSBoyan Karatotev /* Forward the call to the other world */ 1234e138400dSBoyan Karatotev /* fallthrough */ 1235662af36dSJ-Alves case FFA_MSG_SEND: 1236662af36dSJ-Alves case FFA_MEM_DONATE_SMC32: 1237662af36dSJ-Alves case FFA_MEM_DONATE_SMC64: 1238662af36dSJ-Alves case FFA_MEM_LEND_SMC32: 1239662af36dSJ-Alves case FFA_MEM_LEND_SMC64: 1240662af36dSJ-Alves case FFA_MEM_SHARE_SMC32: 1241662af36dSJ-Alves case FFA_MEM_SHARE_SMC64: 1242662af36dSJ-Alves case FFA_MEM_RETRIEVE_REQ_SMC32: 1243662af36dSJ-Alves case FFA_MEM_RETRIEVE_REQ_SMC64: 1244662af36dSJ-Alves case FFA_MEM_RETRIEVE_RESP: 1245662af36dSJ-Alves case FFA_MEM_RELINQUISH: 1246662af36dSJ-Alves case FFA_MEM_RECLAIM: 1247642db984SMarc Bonnici case FFA_MEM_FRAG_TX: 1248642db984SMarc Bonnici case FFA_MEM_FRAG_RX: 1249662af36dSJ-Alves case FFA_SUCCESS_SMC32: 1250662af36dSJ-Alves case FFA_SUCCESS_SMC64: 1251bdd2596dSAchin Gupta /* 125266bdfd6eSRaghu Krishnamurthy * If there is an ongoing direct request from an SPMD logical 125366bdfd6eSRaghu Krishnamurthy * partition, return an error. 1254bdd2596dSAchin Gupta */ 125566bdfd6eSRaghu Krishnamurthy if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { 125666bdfd6eSRaghu Krishnamurthy assert(secure_origin); 125766bdfd6eSRaghu Krishnamurthy return spmd_ffa_error_return(handle, 125866bdfd6eSRaghu Krishnamurthy FFA_ERROR_DENIED); 125966bdfd6eSRaghu Krishnamurthy } 1260bdd2596dSAchin Gupta 126193ff138bSOlivier Deprez return spmd_smc_forward(smc_fid, secure_origin, 1262bb01a673SMarc Bonnici x1, x2, x3, x4, cookie, 1263bb01a673SMarc Bonnici handle, flags); 1264bdd2596dSAchin Gupta break; /* not reached */ 1265bdd2596dSAchin Gupta 1266662af36dSJ-Alves case FFA_MSG_WAIT: 1267bdd2596dSAchin Gupta /* 1268bdd2596dSAchin Gupta * Check if this is the first invocation of this interface on 1269bdd2596dSAchin Gupta * this CPU from the Secure world. If so, then indicate that the 127052696946SOlivier Deprez * SPM Core initialised successfully. 1271bdd2596dSAchin Gupta */ 12729dcf63ddSOlivier Deprez if (secure_origin && (ctx->state == SPMC_STATE_ON_PENDING)) { 12738cb99c3fSOlivier Deprez spmd_spm_core_sync_exit(0ULL); 1274bdd2596dSAchin Gupta } 1275bdd2596dSAchin Gupta 1276e138400dSBoyan Karatotev /* Forward the call to the other world */ 1277e138400dSBoyan Karatotev /* fallthrough */ 1278386dc365SOlivier Deprez case FFA_INTERRUPT: 1279662af36dSJ-Alves case FFA_MSG_YIELD: 1280bdd2596dSAchin Gupta /* This interface must be invoked only by the Secure world */ 128193ff138bSOlivier Deprez if (!secure_origin) { 1282662af36dSJ-Alves return spmd_ffa_error_return(handle, 1283662af36dSJ-Alves FFA_ERROR_NOT_SUPPORTED); 1284bdd2596dSAchin Gupta } 1285bdd2596dSAchin Gupta 128666bdfd6eSRaghu Krishnamurthy if (is_spmd_logical_sp_dir_req_in_progress(ctx)) { 128766bdfd6eSRaghu Krishnamurthy assert(secure_origin); 128866bdfd6eSRaghu Krishnamurthy return spmd_ffa_error_return(handle, 128966bdfd6eSRaghu Krishnamurthy FFA_ERROR_DENIED); 129066bdfd6eSRaghu Krishnamurthy } 129166bdfd6eSRaghu Krishnamurthy 129293ff138bSOlivier Deprez return spmd_smc_forward(smc_fid, secure_origin, 1293bb01a673SMarc Bonnici x1, x2, x3, x4, cookie, 1294bb01a673SMarc Bonnici handle, flags); 1295bdd2596dSAchin Gupta break; /* not reached */ 1296bdd2596dSAchin Gupta 12978cb99c3fSOlivier Deprez case FFA_NORMAL_WORLD_RESUME: 12988cb99c3fSOlivier Deprez if (secure_origin && ctx->secure_interrupt_ongoing) { 12998cb99c3fSOlivier Deprez spmd_spm_core_sync_exit(0ULL); 13008cb99c3fSOlivier Deprez } else { 13018cb99c3fSOlivier Deprez return spmd_ffa_error_return(handle, FFA_ERROR_DENIED); 13028cb99c3fSOlivier Deprez } 13038cb99c3fSOlivier Deprez break; /* Not reached */ 1304eaaf517cSRaghu Krishnamurthy #if MAKE_FFA_VERSION(1, 1) <= FFA_VERSION_COMPILED 1305eaaf517cSRaghu Krishnamurthy case FFA_PARTITION_INFO_GET_REGS_SMC64: 1306eaaf517cSRaghu Krishnamurthy if (secure_origin) { 130795f7f6d8SRaghu Krishnamurthy return spmd_el3_populate_logical_partition_info(handle, x1, 130895f7f6d8SRaghu Krishnamurthy x2, x3); 1309eaaf517cSRaghu Krishnamurthy } 13108cb99c3fSOlivier Deprez 1311eaaf517cSRaghu Krishnamurthy /* Call only supported with SMCCC 1.2+ */ 1312eaaf517cSRaghu Krishnamurthy if (MAKE_SMCCC_VERSION(SMCCC_MAJOR_VERSION, SMCCC_MINOR_VERSION) < 0x10002) { 1313eaaf517cSRaghu Krishnamurthy return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); 1314eaaf517cSRaghu Krishnamurthy } 1315eaaf517cSRaghu Krishnamurthy 1316eaaf517cSRaghu Krishnamurthy return spmd_smc_forward(smc_fid, secure_origin, 1317eaaf517cSRaghu Krishnamurthy x1, x2, x3, x4, cookie, 1318eaaf517cSRaghu Krishnamurthy handle, flags); 1319eaaf517cSRaghu Krishnamurthy break; /* Not reached */ 1320eaaf517cSRaghu Krishnamurthy #endif 1321638a6f8eSShruti Gupta case FFA_CONSOLE_LOG_SMC32: 1322638a6f8eSShruti Gupta case FFA_CONSOLE_LOG_SMC64: 1323638a6f8eSShruti Gupta /* This interface must not be forwarded to other worlds. */ 1324638a6f8eSShruti Gupta return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); 1325638a6f8eSShruti Gupta break; /* not reached */ 1326638a6f8eSShruti Gupta 13276671b3d8SMadhukar Pappireddy case FFA_EL3_INTR_HANDLE: 13286671b3d8SMadhukar Pappireddy if (secure_origin) { 13296671b3d8SMadhukar Pappireddy return spmd_handle_group0_intr_swd(handle); 13306671b3d8SMadhukar Pappireddy } else { 13316c91fc44SMadhukar Pappireddy return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); 13326671b3d8SMadhukar Pappireddy } 1333bdd2596dSAchin Gupta default: 1334bdd2596dSAchin Gupta WARN("SPM: Unsupported call 0x%08x\n", smc_fid); 1335662af36dSJ-Alves return spmd_ffa_error_return(handle, FFA_ERROR_NOT_SUPPORTED); 1336bdd2596dSAchin Gupta } 1337bdd2596dSAchin Gupta } 1338