xref: /rk3399_ARM-atf/services/std_svc/std_svc_setup.c (revision 64f6ea9be7d00f1d7a09c4d928124d93354d9e2f)
1*64f6ea9bSJeenu Viswambharan /*
2*64f6ea9bSJeenu Viswambharan  * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3*64f6ea9bSJeenu Viswambharan  *
4*64f6ea9bSJeenu Viswambharan  * Redistribution and use in source and binary forms, with or without
5*64f6ea9bSJeenu Viswambharan  * modification, are permitted provided that the following conditions are met:
6*64f6ea9bSJeenu Viswambharan  *
7*64f6ea9bSJeenu Viswambharan  * Redistributions of source code must retain the above copyright notice, this
8*64f6ea9bSJeenu Viswambharan  * list of conditions and the following disclaimer.
9*64f6ea9bSJeenu Viswambharan  *
10*64f6ea9bSJeenu Viswambharan  * Redistributions in binary form must reproduce the above copyright notice,
11*64f6ea9bSJeenu Viswambharan  * this list of conditions and the following disclaimer in the documentation
12*64f6ea9bSJeenu Viswambharan  * and/or other materials provided with the distribution.
13*64f6ea9bSJeenu Viswambharan  *
14*64f6ea9bSJeenu Viswambharan  * Neither the name of ARM nor the names of its contributors may be used
15*64f6ea9bSJeenu Viswambharan  * to endorse or promote products derived from this software without specific
16*64f6ea9bSJeenu Viswambharan  * prior written permission.
17*64f6ea9bSJeenu Viswambharan  *
18*64f6ea9bSJeenu Viswambharan  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19*64f6ea9bSJeenu Viswambharan  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*64f6ea9bSJeenu Viswambharan  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*64f6ea9bSJeenu Viswambharan  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22*64f6ea9bSJeenu Viswambharan  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*64f6ea9bSJeenu Viswambharan  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*64f6ea9bSJeenu Viswambharan  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*64f6ea9bSJeenu Viswambharan  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*64f6ea9bSJeenu Viswambharan  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*64f6ea9bSJeenu Viswambharan  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*64f6ea9bSJeenu Viswambharan  * POSSIBILITY OF SUCH DAMAGE.
29*64f6ea9bSJeenu Viswambharan  */
30*64f6ea9bSJeenu Viswambharan 
31*64f6ea9bSJeenu Viswambharan #include <stdint.h>
32*64f6ea9bSJeenu Viswambharan #include <uuid.h>
33*64f6ea9bSJeenu Viswambharan #include <context_mgmt.h>
34*64f6ea9bSJeenu Viswambharan #include <runtime_svc.h>
35*64f6ea9bSJeenu Viswambharan #include <std_svc.h>
36*64f6ea9bSJeenu Viswambharan #include <psci.h>
37*64f6ea9bSJeenu Viswambharan #include <psci_private.h>
38*64f6ea9bSJeenu Viswambharan #include <debug.h>
39*64f6ea9bSJeenu Viswambharan 
40*64f6ea9bSJeenu Viswambharan /* Standard Service UUID */
41*64f6ea9bSJeenu Viswambharan DEFINE_SVC_UUID(arm_svc_uid,
42*64f6ea9bSJeenu Viswambharan 		0x108d905b, 0xf863, 0x47e8, 0xae, 0x2d,
43*64f6ea9bSJeenu Viswambharan 		0xc0, 0xfb, 0x56, 0x41, 0xf6, 0xe2);
44*64f6ea9bSJeenu Viswambharan 
45*64f6ea9bSJeenu Viswambharan /* Setup Standard Services */
46*64f6ea9bSJeenu Viswambharan static int32_t std_svc_setup(void)
47*64f6ea9bSJeenu Viswambharan {
48*64f6ea9bSJeenu Viswambharan 	/*
49*64f6ea9bSJeenu Viswambharan 	 * PSCI is the only specification implemented as a Standard Service.
50*64f6ea9bSJeenu Viswambharan 	 * Invoke PSCI setup from here
51*64f6ea9bSJeenu Viswambharan 	 */
52*64f6ea9bSJeenu Viswambharan 	return psci_setup();
53*64f6ea9bSJeenu Viswambharan }
54*64f6ea9bSJeenu Viswambharan 
55*64f6ea9bSJeenu Viswambharan /*
56*64f6ea9bSJeenu Viswambharan  * Top-level Standard Service SMC handler. This handler will in turn dispatch
57*64f6ea9bSJeenu Viswambharan  * calls to PSCI SMC handler
58*64f6ea9bSJeenu Viswambharan  */
59*64f6ea9bSJeenu Viswambharan uint64_t std_svc_smc_handler(uint32_t smc_fid,
60*64f6ea9bSJeenu Viswambharan 			     uint64_t x1,
61*64f6ea9bSJeenu Viswambharan 			     uint64_t x2,
62*64f6ea9bSJeenu Viswambharan 			     uint64_t x3,
63*64f6ea9bSJeenu Viswambharan 			     uint64_t x4,
64*64f6ea9bSJeenu Viswambharan 			     void *cookie,
65*64f6ea9bSJeenu Viswambharan 			     void *handle,
66*64f6ea9bSJeenu Viswambharan 			     uint64_t flags)
67*64f6ea9bSJeenu Viswambharan {
68*64f6ea9bSJeenu Viswambharan 	/*
69*64f6ea9bSJeenu Viswambharan 	 * Dispatch PSCI calls to PSCI SMC handler and return its return
70*64f6ea9bSJeenu Viswambharan 	 * value
71*64f6ea9bSJeenu Viswambharan 	 */
72*64f6ea9bSJeenu Viswambharan 	if (is_psci_fid(smc_fid)) {
73*64f6ea9bSJeenu Viswambharan 		return psci_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
74*64f6ea9bSJeenu Viswambharan 				handle, flags);
75*64f6ea9bSJeenu Viswambharan 	}
76*64f6ea9bSJeenu Viswambharan 
77*64f6ea9bSJeenu Viswambharan 	switch (smc_fid) {
78*64f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_CALL_COUNT:
79*64f6ea9bSJeenu Viswambharan 		/*
80*64f6ea9bSJeenu Viswambharan 		 * Return the number of Standard Service Calls. PSCI is the only
81*64f6ea9bSJeenu Viswambharan 		 * standard service implemented; so return number of PSCI calls
82*64f6ea9bSJeenu Viswambharan 		 */
83*64f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, PSCI_NUM_CALLS);
84*64f6ea9bSJeenu Viswambharan 
85*64f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_UID:
86*64f6ea9bSJeenu Viswambharan 		/* Return UID to the caller */
87*64f6ea9bSJeenu Viswambharan 		SMC_UUID_RET(handle, arm_svc_uid);
88*64f6ea9bSJeenu Viswambharan 
89*64f6ea9bSJeenu Viswambharan 	case ARM_STD_SVC_VERSION:
90*64f6ea9bSJeenu Viswambharan 		/* Return the version of current implementation */
91*64f6ea9bSJeenu Viswambharan 		SMC_RET2(handle, STD_SVC_VERSION_MAJOR, STD_SVC_VERSION_MINOR);
92*64f6ea9bSJeenu Viswambharan 
93*64f6ea9bSJeenu Viswambharan 	default:
94*64f6ea9bSJeenu Viswambharan 		WARN("Unimplemented Standard Service Call: 0x%x \n", smc_fid);
95*64f6ea9bSJeenu Viswambharan 		SMC_RET1(handle, SMC_UNK);
96*64f6ea9bSJeenu Viswambharan 	}
97*64f6ea9bSJeenu Viswambharan }
98*64f6ea9bSJeenu Viswambharan 
99*64f6ea9bSJeenu Viswambharan /* Register Standard Service Calls as runtime service */
100*64f6ea9bSJeenu Viswambharan DECLARE_RT_SVC(
101*64f6ea9bSJeenu Viswambharan 		std_svc,
102*64f6ea9bSJeenu Viswambharan 
103*64f6ea9bSJeenu Viswambharan 		OEN_STD_START,
104*64f6ea9bSJeenu Viswambharan 		OEN_STD_END,
105*64f6ea9bSJeenu Viswambharan 		SMC_TYPE_FAST,
106*64f6ea9bSJeenu Viswambharan 		std_svc_setup,
107*64f6ea9bSJeenu Viswambharan 		std_svc_smc_handler
108*64f6ea9bSJeenu Viswambharan );
109