xref: /rk3399_ARM-atf/services/std_svc/std_svc_setup.c (revision 97043ac98e13a726dbf8b3b41654dca759e3da2c)
164f6ea9bSJeenu Viswambharan /*
264f6ea9bSJeenu Viswambharan  * Copyright (c) 2014, 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*97043ac9SDan Handley #include <debug.h>
32*97043ac9SDan Handley #include <psci.h>
3364f6ea9bSJeenu Viswambharan #include <runtime_svc.h>
3464f6ea9bSJeenu Viswambharan #include <std_svc.h>
35*97043ac9SDan Handley #include <stdint.h>
36*97043ac9SDan Handley #include <uuid.h>
3764f6ea9bSJeenu Viswambharan 
3864f6ea9bSJeenu Viswambharan /* Standard Service UUID */
3964f6ea9bSJeenu Viswambharan DEFINE_SVC_UUID(arm_svc_uid,
4064f6ea9bSJeenu Viswambharan 		0x108d905b, 0xf863, 0x47e8, 0xae, 0x2d,
4164f6ea9bSJeenu Viswambharan 		0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2);
4264f6ea9bSJeenu Viswambharan 
4364f6ea9bSJeenu Viswambharan /* Setup Standard Services */
4464f6ea9bSJeenu Viswambharan static int32_t std_svc_setup(void)
4564f6ea9bSJeenu Viswambharan {
4664f6ea9bSJeenu Viswambharan 	/*
4764f6ea9bSJeenu Viswambharan 	 * PSCI is the only specification implemented as a Standard Service.
4864f6ea9bSJeenu Viswambharan 	 * Invoke PSCI setup from here
4964f6ea9bSJeenu Viswambharan 	 */
5064f6ea9bSJeenu Viswambharan 	return psci_setup();
5164f6ea9bSJeenu Viswambharan }
5264f6ea9bSJeenu Viswambharan 
5364f6ea9bSJeenu Viswambharan /*
5464f6ea9bSJeenu Viswambharan  * Top-level Standard Service SMC handler. This handler will in turn dispatch
5564f6ea9bSJeenu Viswambharan  * calls to PSCI SMC handler
5664f6ea9bSJeenu Viswambharan  */
5764f6ea9bSJeenu Viswambharan uint64_t std_svc_smc_handler(uint32_t smc_fid,
5864f6ea9bSJeenu Viswambharan 			     uint64_t x1,
5964f6ea9bSJeenu Viswambharan 			     uint64_t x2,
6064f6ea9bSJeenu Viswambharan 			     uint64_t x3,
6164f6ea9bSJeenu Viswambharan 			     uint64_t x4,
6264f6ea9bSJeenu Viswambharan 			     void *cookie,
6364f6ea9bSJeenu Viswambharan 			     void *handle,
6464f6ea9bSJeenu Viswambharan 			     uint64_t flags)
6564f6ea9bSJeenu Viswambharan {
6664f6ea9bSJeenu Viswambharan 	/*
6764f6ea9bSJeenu Viswambharan 	 * Dispatch PSCI calls to PSCI SMC handler and return its return
6864f6ea9bSJeenu Viswambharan 	 * value
6964f6ea9bSJeenu Viswambharan 	 */
7064f6ea9bSJeenu Viswambharan 	if (is_psci_fid(smc_fid)) {
7164f6ea9bSJeenu Viswambharan 		return psci_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
7264f6ea9bSJeenu Viswambharan 				handle, flags);
7364f6ea9bSJeenu Viswambharan 	}
7464f6ea9bSJeenu Viswambharan 
7564f6ea9bSJeenu Viswambharan 	switch (smc_fid) {
7664f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_CALL_COUNT:
7764f6ea9bSJeenu Viswambharan 		/*
7864f6ea9bSJeenu Viswambharan 		 * Return the number of Standard Service Calls. PSCI is the only
7964f6ea9bSJeenu Viswambharan 		 * standard service implemented; so return number of PSCI calls
8064f6ea9bSJeenu Viswambharan 		 */
8164f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, PSCI_NUM_CALLS);
8264f6ea9bSJeenu Viswambharan 
8364f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_UID:
8464f6ea9bSJeenu Viswambharan 		/* Return UID to the caller */
8564f6ea9bSJeenu Viswambharan 		SMC_UUID_RET(handle, arm_svc_uid);
8664f6ea9bSJeenu Viswambharan 
8764f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_VERSION:
8864f6ea9bSJeenu Viswambharan 		/* Return the version of current implementation */
8964f6ea9bSJeenu Viswambharan 		SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR);
9064f6ea9bSJeenu Viswambharan 
9164f6ea9bSJeenu Viswambharan 	default:
9264f6ea9bSJeenu Viswambharan 		WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid);
9364f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, SMC_UNK);
9464f6ea9bSJeenu Viswambharan 	}
9564f6ea9bSJeenu Viswambharan }
9664f6ea9bSJeenu Viswambharan 
9764f6ea9bSJeenu Viswambharan /* Register Standard Service Calls as runtime service */
9864f6ea9bSJeenu Viswambharan DECLARE_RT_SVC(
9964f6ea9bSJeenu Viswambharan 		std_svc,
10064f6ea9bSJeenu Viswambharan 
10164f6ea9bSJeenu Viswambharan 		OEN_STD_START,
10264f6ea9bSJeenu Viswambharan 		OEN_STD_END,
10364f6ea9bSJeenu Viswambharan 		SMC_TYPE_FAST,
10464f6ea9bSJeenu Viswambharan 		std_svc_setup,
10564f6ea9bSJeenu Viswambharan 		std_svc_smc_handler
10664f6ea9bSJeenu Viswambharan );
107