1 /* 2 * Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <stdint.h> 8 9 #include <common/debug.h> 10 #include <common/runtime_svc.h> 11 #include <lib/pmf/pmf.h> 12 #include <plat/arm/common/arm_sip_svc.h> 13 #include <plat/arm/common/plat_arm.h> 14 #include <tools_share/uuid.h> 15 16 /* ARM SiP Service UUID */ 17 DEFINE_SVC_UUID2(arm_sip_svc_uid, 18 0x556d75e2, 0x6033, 0xb54b, 0xb5, 0x75, 19 0x62, 0x79, 0xfd, 0x11, 0x37, 0xff); 20 21 static int arm_sip_setup(void) 22 { 23 if (pmf_setup() != 0) 24 return 1; 25 return 0; 26 } 27 28 /* 29 * This function handles ARM defined SiP Calls 30 */ 31 static uintptr_t arm_sip_handler(unsigned int smc_fid, 32 u_register_t x1, 33 u_register_t x2, 34 u_register_t x3, 35 u_register_t x4, 36 void *cookie, 37 void *handle, 38 u_register_t flags) 39 { 40 int call_count = 0; 41 42 /* 43 * Dispatch PMF calls to PMF SMC handler and return its return 44 * value 45 */ 46 if (is_pmf_fid(smc_fid)) { 47 return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie, 48 handle, flags); 49 } 50 51 switch (smc_fid) { 52 case ARM_SIP_SVC_EXE_STATE_SWITCH: { 53 /* Execution state can be switched only if EL3 is AArch64 */ 54 #ifdef __aarch64__ 55 /* Allow calls from non-secure only */ 56 if (!is_caller_non_secure(flags)) 57 SMC_RET1(handle, STATE_SW_E_DENIED); 58 59 /* 60 * Pointers used in execution state switch are all 32 bits wide 61 */ 62 return (uintptr_t) arm_execution_state_switch(smc_fid, 63 (uint32_t) x1, (uint32_t) x2, (uint32_t) x3, 64 (uint32_t) x4, handle); 65 #else 66 /* State switch denied */ 67 SMC_RET1(handle, STATE_SW_E_DENIED); 68 #endif /* __aarch64__ */ 69 } 70 71 case ARM_SIP_SVC_CALL_COUNT: 72 /* PMF calls */ 73 call_count += PMF_NUM_SMC_CALLS; 74 75 /* State switch call */ 76 call_count += 1; 77 78 SMC_RET1(handle, call_count); 79 80 case ARM_SIP_SVC_UID: 81 /* Return UID to the caller */ 82 SMC_UUID_RET(handle, arm_sip_svc_uid); 83 84 case ARM_SIP_SVC_VERSION: 85 /* Return the version of current implementation */ 86 SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR); 87 88 default: 89 WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid); 90 SMC_RET1(handle, SMC_UNK); 91 } 92 93 } 94 95 96 /* Define a runtime service descriptor for fast SMC calls */ 97 DECLARE_RT_SVC( 98 arm_sip_svc, 99 OEN_SIP_START, 100 OEN_SIP_END, 101 SMC_TYPE_FAST, 102 arm_sip_setup, 103 arm_sip_handler 104 ); 105