xref: /rk3399_ARM-atf/services/std_svc/std_svc_setup.c (revision cf0b1492ede6cbbf788144a56d276d8d7924500a)
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 
3197043ac9SDan Handley #include <debug.h>
3297043ac9SDan Handley #include <psci.h>
3364f6ea9bSJeenu Viswambharan #include <runtime_svc.h>
34*cf0b1492SSoby Mathew #include <smcc_helpers.h>
3564f6ea9bSJeenu Viswambharan #include <std_svc.h>
3697043ac9SDan Handley #include <stdint.h>
3797043ac9SDan Handley #include <uuid.h>
3864f6ea9bSJeenu Viswambharan 
3964f6ea9bSJeenu Viswambharan /* Standard Service UUID */
4064f6ea9bSJeenu Viswambharan DEFINE_SVC_UUID(arm_svc_uid,
4164f6ea9bSJeenu Viswambharan 		0x108d905b, 0xf863, 0x47e8, 0xae, 0x2d,
4264f6ea9bSJeenu Viswambharan 		0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2);
4364f6ea9bSJeenu Viswambharan 
4464f6ea9bSJeenu Viswambharan /*
4564f6ea9bSJeenu Viswambharan  * Top-level Standard Service SMC handler. This handler will in turn dispatch
4664f6ea9bSJeenu Viswambharan  * calls to PSCI SMC handler
4764f6ea9bSJeenu Viswambharan  */
484c0d0390SSoby Mathew uintptr_t std_svc_smc_handler(uint32_t smc_fid,
494c0d0390SSoby Mathew 			     u_register_t x1,
504c0d0390SSoby Mathew 			     u_register_t x2,
514c0d0390SSoby Mathew 			     u_register_t x3,
524c0d0390SSoby Mathew 			     u_register_t x4,
5364f6ea9bSJeenu Viswambharan 			     void *cookie,
5464f6ea9bSJeenu Viswambharan 			     void *handle,
554c0d0390SSoby Mathew 			     u_register_t flags)
5664f6ea9bSJeenu Viswambharan {
5764f6ea9bSJeenu Viswambharan 	/*
5864f6ea9bSJeenu Viswambharan 	 * Dispatch PSCI calls to PSCI SMC handler and return its return
5964f6ea9bSJeenu Viswambharan 	 * value
6064f6ea9bSJeenu Viswambharan 	 */
6164f6ea9bSJeenu Viswambharan 	if (is_psci_fid(smc_fid)) {
62*cf0b1492SSoby Mathew 		SMC_RET1(handle,
63*cf0b1492SSoby Mathew 			psci_smc_handler(smc_fid, x1, x2, x3, x4,
64*cf0b1492SSoby Mathew 					cookie, handle, flags));
6564f6ea9bSJeenu Viswambharan 	}
6664f6ea9bSJeenu Viswambharan 
6764f6ea9bSJeenu Viswambharan 	switch (smc_fid) {
6864f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_CALL_COUNT:
6964f6ea9bSJeenu Viswambharan 		/*
7064f6ea9bSJeenu Viswambharan 		 * Return the number of Standard Service Calls. PSCI is the only
7164f6ea9bSJeenu Viswambharan 		 * standard service implemented; so return number of PSCI calls
7264f6ea9bSJeenu Viswambharan 		 */
7364f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, PSCI_NUM_CALLS);
7464f6ea9bSJeenu Viswambharan 
7564f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_UID:
7664f6ea9bSJeenu Viswambharan 		/* Return UID to the caller */
7764f6ea9bSJeenu Viswambharan 		SMC_UUID_RET(handle, arm_svc_uid);
7864f6ea9bSJeenu Viswambharan 
7964f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_VERSION:
8064f6ea9bSJeenu Viswambharan 		/* Return the version of current implementation */
8164f6ea9bSJeenu Viswambharan 		SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR);
8264f6ea9bSJeenu Viswambharan 
8364f6ea9bSJeenu Viswambharan 	default:
8464f6ea9bSJeenu Viswambharan 		WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid);
8564f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, SMC_UNK);
8664f6ea9bSJeenu Viswambharan 	}
8764f6ea9bSJeenu Viswambharan }
8864f6ea9bSJeenu Viswambharan 
8964f6ea9bSJeenu Viswambharan /* Register Standard Service Calls as runtime service */
9064f6ea9bSJeenu Viswambharan DECLARE_RT_SVC(
9164f6ea9bSJeenu Viswambharan 		std_svc,
9264f6ea9bSJeenu Viswambharan 
9364f6ea9bSJeenu Viswambharan 		OEN_STD_START,
9464f6ea9bSJeenu Viswambharan 		OEN_STD_END,
9564f6ea9bSJeenu Viswambharan 		SMC_TYPE_FAST,
96*cf0b1492SSoby Mathew 		NULL,
9764f6ea9bSJeenu Viswambharan 		std_svc_smc_handler
9864f6ea9bSJeenu Viswambharan );
99