xref: /rk3399_ARM-atf/plat/arm/common/arm_sip_svc.c (revision 3d8256b2a1ef1195aed86bef7378e83d0a61a91b)
1 /*
2  * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  *
14  * Neither the name of ARM nor the names of its contributors may be used
15  * to endorse or promote products derived from this software without specific
16  * prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include <arm_sip_svc.h>
32 #include <debug.h>
33 #include <pmf.h>
34 #include <runtime_svc.h>
35 #include <stdint.h>
36 #include <uuid.h>
37 
38 
39 /* ARM SiP Service UUID */
40 DEFINE_SVC_UUID(arm_sip_svc_uid,
41 		0xe2756d55, 0x3360, 0x4bb5, 0xbf, 0xf3,
42 		0x62, 0x79, 0xfd, 0x11, 0x37, 0xff);
43 
44 static int arm_sip_setup(void)
45 {
46 	if (pmf_setup() != 0)
47 		return 1;
48 	return 0;
49 }
50 
51 /*
52  * This function handles ARM defined SiP Calls
53  */
54 static uintptr_t arm_sip_handler(unsigned int smc_fid,
55 			u_register_t x1,
56 			u_register_t x2,
57 			u_register_t x3,
58 			u_register_t x4,
59 			void *cookie,
60 			void *handle,
61 			u_register_t flags)
62 {
63 	/*
64 	 * Dispatch PMF calls to PMF SMC handler and return its return
65 	 * value
66 	 */
67 	if (is_pmf_fid(smc_fid)) {
68 		return pmf_smc_handler(smc_fid, x1, x2, x3, x4, cookie,
69 				handle, flags);
70 	}
71 
72 	switch (smc_fid) {
73 	case ARM_SIP_SVC_CALL_COUNT:
74 		/*
75 		 * Return the number of SiP Service Calls. PMF is the only
76 		 * SiP service implemented; so return number of PMF calls
77 		 */
78 		SMC_RET1(handle, PMF_NUM_SMC_CALLS);
79 
80 	case ARM_SIP_SVC_UID:
81 		/* Return UID to the caller */
82 		SMC_UUID_RET(handle, arm_sip_svc_uid);
83 
84 	case ARM_SIP_SVC_VERSION:
85 		/* Return the version of current implementation */
86 		SMC_RET2(handle, ARM_SIP_SVC_VERSION_MAJOR, ARM_SIP_SVC_VERSION_MINOR);
87 
88 	default:
89 		WARN("Unimplemented ARM SiP Service Call: 0x%x \n", smc_fid);
90 		SMC_RET1(handle, SMC_UNK);
91 	}
92 
93 }
94 
95 
96 /* Define a runtime service descriptor for fast SMC calls */
97 DECLARE_RT_SVC(
98 	arm_sip_svc,
99 	OEN_SIP_START,
100 	OEN_SIP_END,
101 	SMC_TYPE_FAST,
102 	arm_sip_setup,
103 	arm_sip_handler
104 );
105