xref: /rk3399_ARM-atf/services/std_svc/std_svc_setup.c (revision 58e946aec50c022578fd47da93b0b4bd62e94d5b)
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 
31*58e946aeSSoby Mathew #include <assert.h>
3297043ac9SDan Handley #include <debug.h>
3397043ac9SDan Handley #include <psci.h>
3464f6ea9bSJeenu Viswambharan #include <runtime_svc.h>
35cf0b1492SSoby Mathew #include <smcc_helpers.h>
3664f6ea9bSJeenu Viswambharan #include <std_svc.h>
3797043ac9SDan Handley #include <stdint.h>
3897043ac9SDan Handley #include <uuid.h>
3964f6ea9bSJeenu Viswambharan 
4064f6ea9bSJeenu Viswambharan /* Standard Service UUID */
4164f6ea9bSJeenu Viswambharan DEFINE_SVC_UUID(arm_svc_uid,
4264f6ea9bSJeenu Viswambharan 		0x108d905b, 0xf863, 0x47e8, 0xae, 0x2d,
4364f6ea9bSJeenu Viswambharan 		0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2);
4464f6ea9bSJeenu Viswambharan 
45*58e946aeSSoby Mathew /* Setup Standard Services */
46*58e946aeSSoby Mathew static int32_t std_svc_setup(void)
47*58e946aeSSoby Mathew {
48*58e946aeSSoby Mathew 	uintptr_t svc_arg;
49*58e946aeSSoby Mathew 
50*58e946aeSSoby Mathew 	svc_arg = get_arm_std_svc_args(PSCI_FID_MASK);
51*58e946aeSSoby Mathew 	assert(svc_arg);
52*58e946aeSSoby Mathew 
53*58e946aeSSoby Mathew 	/*
54*58e946aeSSoby Mathew 	 * PSCI is the only specification implemented as a Standard Service.
55*58e946aeSSoby Mathew 	 * The `psci_setup()` also does EL3 architectural setup.
56*58e946aeSSoby Mathew 	 */
57*58e946aeSSoby Mathew 	return psci_setup((const psci_lib_args_t *)svc_arg);
58*58e946aeSSoby Mathew }
59*58e946aeSSoby Mathew 
6064f6ea9bSJeenu Viswambharan /*
6164f6ea9bSJeenu Viswambharan  * Top-level Standard Service SMC handler. This handler will in turn dispatch
6264f6ea9bSJeenu Viswambharan  * calls to PSCI SMC handler
6364f6ea9bSJeenu Viswambharan  */
644c0d0390SSoby Mathew uintptr_t std_svc_smc_handler(uint32_t smc_fid,
654c0d0390SSoby Mathew 			     u_register_t x1,
664c0d0390SSoby Mathew 			     u_register_t x2,
674c0d0390SSoby Mathew 			     u_register_t x3,
684c0d0390SSoby Mathew 			     u_register_t x4,
6964f6ea9bSJeenu Viswambharan 			     void *cookie,
7064f6ea9bSJeenu Viswambharan 			     void *handle,
714c0d0390SSoby Mathew 			     u_register_t flags)
7264f6ea9bSJeenu Viswambharan {
7364f6ea9bSJeenu Viswambharan 	/*
7464f6ea9bSJeenu Viswambharan 	 * Dispatch PSCI calls to PSCI SMC handler and return its return
7564f6ea9bSJeenu Viswambharan 	 * value
7664f6ea9bSJeenu Viswambharan 	 */
7764f6ea9bSJeenu Viswambharan 	if (is_psci_fid(smc_fid)) {
78cf0b1492SSoby Mathew 		SMC_RET1(handle,
79cf0b1492SSoby Mathew 			psci_smc_handler(smc_fid, x1, x2, x3, x4,
80cf0b1492SSoby Mathew 					cookie, handle, flags));
8164f6ea9bSJeenu Viswambharan 	}
8264f6ea9bSJeenu Viswambharan 
8364f6ea9bSJeenu Viswambharan 	switch (smc_fid) {
8464f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_CALL_COUNT:
8564f6ea9bSJeenu Viswambharan 		/*
8664f6ea9bSJeenu Viswambharan 		 * Return the number of Standard Service Calls. PSCI is the only
8764f6ea9bSJeenu Viswambharan 		 * standard service implemented; so return number of PSCI calls
8864f6ea9bSJeenu Viswambharan 		 */
8964f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, PSCI_NUM_CALLS);
9064f6ea9bSJeenu Viswambharan 
9164f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_UID:
9264f6ea9bSJeenu Viswambharan 		/* Return UID to the caller */
9364f6ea9bSJeenu Viswambharan 		SMC_UUID_RET(handle, arm_svc_uid);
9464f6ea9bSJeenu Viswambharan 
9564f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_VERSION:
9664f6ea9bSJeenu Viswambharan 		/* Return the version of current implementation */
9764f6ea9bSJeenu Viswambharan 		SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR);
9864f6ea9bSJeenu Viswambharan 
9964f6ea9bSJeenu Viswambharan 	default:
10064f6ea9bSJeenu Viswambharan 		WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid);
10164f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, SMC_UNK);
10264f6ea9bSJeenu Viswambharan 	}
10364f6ea9bSJeenu Viswambharan }
10464f6ea9bSJeenu Viswambharan 
10564f6ea9bSJeenu Viswambharan /* Register Standard Service Calls as runtime service */
10664f6ea9bSJeenu Viswambharan DECLARE_RT_SVC(
10764f6ea9bSJeenu Viswambharan 		std_svc,
10864f6ea9bSJeenu Viswambharan 
10964f6ea9bSJeenu Viswambharan 		OEN_STD_START,
11064f6ea9bSJeenu Viswambharan 		OEN_STD_END,
11164f6ea9bSJeenu Viswambharan 		SMC_TYPE_FAST,
112*58e946aeSSoby Mathew 		std_svc_setup,
11364f6ea9bSJeenu Viswambharan 		std_svc_smc_handler
11464f6ea9bSJeenu Viswambharan );
115