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