164f6ea9bSJeenu Viswambharan /* 24c0d0390SSoby Mathew * Copyright (c) 2014-2016, ARM Limited and Contributors. All rights reserved. 364f6ea9bSJeenu Viswambharan * 464f6ea9bSJeenu Viswambharan * Redistribution and use in source and binary forms, with or without 564f6ea9bSJeenu Viswambharan * modification, are permitted provided that the following conditions are met: 664f6ea9bSJeenu Viswambharan * 764f6ea9bSJeenu Viswambharan * Redistributions of source code must retain the above copyright notice, this 864f6ea9bSJeenu Viswambharan * list of conditions and the following disclaimer. 964f6ea9bSJeenu Viswambharan * 1064f6ea9bSJeenu Viswambharan * Redistributions in binary form must reproduce the above copyright notice, 1164f6ea9bSJeenu Viswambharan * this list of conditions and the following disclaimer in the documentation 1264f6ea9bSJeenu Viswambharan * and/or other materials provided with the distribution. 1364f6ea9bSJeenu Viswambharan * 1464f6ea9bSJeenu Viswambharan * Neither the name of ARM nor the names of its contributors may be used 1564f6ea9bSJeenu Viswambharan * to endorse or promote products derived from this software without specific 1664f6ea9bSJeenu Viswambharan * prior written permission. 1764f6ea9bSJeenu Viswambharan * 1864f6ea9bSJeenu Viswambharan * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 1964f6ea9bSJeenu Viswambharan * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2064f6ea9bSJeenu Viswambharan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2164f6ea9bSJeenu Viswambharan * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 2264f6ea9bSJeenu Viswambharan * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2364f6ea9bSJeenu Viswambharan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2464f6ea9bSJeenu Viswambharan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2564f6ea9bSJeenu Viswambharan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2664f6ea9bSJeenu Viswambharan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 2764f6ea9bSJeenu Viswambharan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 2864f6ea9bSJeenu Viswambharan * POSSIBILITY OF SUCH DAMAGE. 2964f6ea9bSJeenu Viswambharan */ 3064f6ea9bSJeenu Viswambharan 3158e946aeSSoby Mathew #include <assert.h> 32*872be88aSdp-arm #include <cpu_data.h> 3397043ac9SDan Handley #include <debug.h> 34*872be88aSdp-arm #include <pmf.h> 3597043ac9SDan Handley #include <psci.h> 36*872be88aSdp-arm #include <runtime_instr.h> 3764f6ea9bSJeenu Viswambharan #include <runtime_svc.h> 38cf0b1492SSoby Mathew #include <smcc_helpers.h> 3964f6ea9bSJeenu Viswambharan #include <std_svc.h> 4097043ac9SDan Handley #include <stdint.h> 4197043ac9SDan Handley #include <uuid.h> 4264f6ea9bSJeenu Viswambharan 4364f6ea9bSJeenu Viswambharan /* Standard Service UUID */ 4464f6ea9bSJeenu Viswambharan DEFINE_SVC_UUID(arm_svc_uid, 4564f6ea9bSJeenu Viswambharan 0x108d905b, 0xf863, 0x47e8, 0xae, 0x2d, 4664f6ea9bSJeenu Viswambharan 0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2); 4764f6ea9bSJeenu Viswambharan 4858e946aeSSoby Mathew /* Setup Standard Services */ 4958e946aeSSoby Mathew static int32_t std_svc_setup(void) 5058e946aeSSoby Mathew { 5158e946aeSSoby Mathew uintptr_t svc_arg; 5258e946aeSSoby Mathew 5358e946aeSSoby Mathew svc_arg = get_arm_std_svc_args(PSCI_FID_MASK); 5458e946aeSSoby Mathew assert(svc_arg); 5558e946aeSSoby Mathew 5658e946aeSSoby Mathew /* 5758e946aeSSoby Mathew * PSCI is the only specification implemented as a Standard Service. 5858e946aeSSoby Mathew * The `psci_setup()` also does EL3 architectural setup. 5958e946aeSSoby Mathew */ 6058e946aeSSoby Mathew return psci_setup((const psci_lib_args_t *)svc_arg); 6158e946aeSSoby Mathew } 6258e946aeSSoby Mathew 6364f6ea9bSJeenu Viswambharan /* 6464f6ea9bSJeenu Viswambharan * Top-level Standard Service SMC handler. This handler will in turn dispatch 6564f6ea9bSJeenu Viswambharan * calls to PSCI SMC handler 6664f6ea9bSJeenu Viswambharan */ 674c0d0390SSoby Mathew uintptr_t std_svc_smc_handler(uint32_t smc_fid, 684c0d0390SSoby Mathew u_register_t x1, 694c0d0390SSoby Mathew u_register_t x2, 704c0d0390SSoby Mathew u_register_t x3, 714c0d0390SSoby Mathew u_register_t x4, 7264f6ea9bSJeenu Viswambharan void *cookie, 7364f6ea9bSJeenu Viswambharan void *handle, 744c0d0390SSoby Mathew u_register_t flags) 7564f6ea9bSJeenu Viswambharan { 7664f6ea9bSJeenu Viswambharan /* 7764f6ea9bSJeenu Viswambharan * Dispatch PSCI calls to PSCI SMC handler and return its return 7864f6ea9bSJeenu Viswambharan * value 7964f6ea9bSJeenu Viswambharan */ 8064f6ea9bSJeenu Viswambharan if (is_psci_fid(smc_fid)) { 81*872be88aSdp-arm uint64_t ret; 82*872be88aSdp-arm 83*872be88aSdp-arm #if ENABLE_RUNTIME_INSTRUMENTATION 84*872be88aSdp-arm PMF_WRITE_TIMESTAMP(rt_instr_svc, 85*872be88aSdp-arm RT_INSTR_ENTER_PSCI, 86*872be88aSdp-arm PMF_NO_CACHE_MAINT, 87*872be88aSdp-arm get_cpu_data(cpu_data_pmf_ts[CPU_DATA_PMF_TS0_IDX])); 88*872be88aSdp-arm #endif 89*872be88aSdp-arm 90*872be88aSdp-arm ret = psci_smc_handler(smc_fid, x1, x2, x3, x4, 91*872be88aSdp-arm cookie, handle, flags); 92*872be88aSdp-arm 93*872be88aSdp-arm #if ENABLE_RUNTIME_INSTRUMENTATION 94*872be88aSdp-arm PMF_CAPTURE_TIMESTAMP(rt_instr_svc, 95*872be88aSdp-arm RT_INSTR_EXIT_PSCI, 96*872be88aSdp-arm PMF_NO_CACHE_MAINT); 97*872be88aSdp-arm #endif 98*872be88aSdp-arm 99*872be88aSdp-arm SMC_RET1(handle, ret); 10064f6ea9bSJeenu Viswambharan } 10164f6ea9bSJeenu Viswambharan 10264f6ea9bSJeenu Viswambharan switch (smc_fid) { 10364f6ea9bSJeenu Viswambharan case ARM_STD_SVC_CALL_COUNT: 10464f6ea9bSJeenu Viswambharan /* 10564f6ea9bSJeenu Viswambharan * Return the number of Standard Service Calls. PSCI is the only 10664f6ea9bSJeenu Viswambharan * standard service implemented; so return number of PSCI calls 10764f6ea9bSJeenu Viswambharan */ 10864f6ea9bSJeenu Viswambharan SMC_RET1(handle, PSCI_NUM_CALLS); 10964f6ea9bSJeenu Viswambharan 11064f6ea9bSJeenu Viswambharan case ARM_STD_SVC_UID: 11164f6ea9bSJeenu Viswambharan /* Return UID to the caller */ 11264f6ea9bSJeenu Viswambharan SMC_UUID_RET(handle, arm_svc_uid); 11364f6ea9bSJeenu Viswambharan 11464f6ea9bSJeenu Viswambharan case ARM_STD_SVC_VERSION: 11564f6ea9bSJeenu Viswambharan /* Return the version of current implementation */ 11664f6ea9bSJeenu Viswambharan SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR); 11764f6ea9bSJeenu Viswambharan 11864f6ea9bSJeenu Viswambharan default: 11964f6ea9bSJeenu Viswambharan WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid); 12064f6ea9bSJeenu Viswambharan SMC_RET1(handle, SMC_UNK); 12164f6ea9bSJeenu Viswambharan } 12264f6ea9bSJeenu Viswambharan } 12364f6ea9bSJeenu Viswambharan 12464f6ea9bSJeenu Viswambharan /* Register Standard Service Calls as runtime service */ 12564f6ea9bSJeenu Viswambharan DECLARE_RT_SVC( 12664f6ea9bSJeenu Viswambharan std_svc, 12764f6ea9bSJeenu Viswambharan 12864f6ea9bSJeenu Viswambharan OEN_STD_START, 12964f6ea9bSJeenu Viswambharan OEN_STD_END, 13064f6ea9bSJeenu Viswambharan SMC_TYPE_FAST, 13158e946aeSSoby Mathew std_svc_setup, 13264f6ea9bSJeenu Viswambharan std_svc_smc_handler 13364f6ea9bSJeenu Viswambharan ); 134