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