xref: /rk3399_ARM-atf/plat/rockchip/common/rockchip_sip_svc.c (revision a1c3faa6c7f877bd81efce5b5c426393f7107104)
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  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  *
10  * 2. 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  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24  * POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #include <assert.h>
28 #include <debug.h>
29 #include <mmio.h>
30 #include <plat_sip_calls.h>
31 #include <rockchip_sip_svc.h>
32 #include <runtime_svc.h>
33 #include <uuid.h>
34 
35 /* Rockchip SiP Service UUID */
36 DEFINE_SVC_UUID(rk_sip_svc_uid,
37 		0xe86fc7e2, 0x313e, 0x11e6, 0xb7, 0x0d,
38 		0x8f, 0x88, 0xee, 0x74, 0x7b, 0x72);
39 
40 #pragma weak rockchip_plat_sip_handler
41 uint64_t rockchip_plat_sip_handler(uint32_t smc_fid,
42 				   uint64_t x1,
43 				   uint64_t x2,
44 				   uint64_t x3,
45 				   uint64_t x4,
46 				   void *cookie,
47 				   void *handle,
48 				   uint64_t flags)
49 {
50 	ERROR("%s: unhandled SMC (0x%x)\n", __func__, smc_fid);
51 	SMC_RET1(handle, SMC_UNK);
52 }
53 
54 /*
55  * This function is responsible for handling all SiP calls from the NS world
56  */
57 uint64_t sip_smc_handler(uint32_t smc_fid,
58 			 uint64_t x1,
59 			 uint64_t x2,
60 			 uint64_t x3,
61 			 uint64_t x4,
62 			 void *cookie,
63 			 void *handle,
64 			 uint64_t flags)
65 {
66 	uint32_t ns;
67 
68 	/* Determine which security state this SMC originated from */
69 	ns = is_caller_non_secure(flags);
70 	if (!ns)
71 		SMC_RET1(handle, SMC_UNK);
72 
73 	switch (smc_fid) {
74 	case SIP_SVC_CALL_COUNT:
75 		/* Return the number of Rockchip SiP Service Calls. */
76 		SMC_RET1(handle,
77 			 RK_COMMON_SIP_NUM_CALLS + RK_PLAT_SIP_NUM_CALLS);
78 
79 	case SIP_SVC_UID:
80 		/* Return UID to the caller */
81 		SMC_UUID_RET(handle, rk_sip_svc_uid);
82 		break;
83 
84 	case SIP_SVC_VERSION:
85 		/* Return the version of current implementation */
86 		SMC_RET2(handle, RK_SIP_SVC_VERSION_MAJOR,
87 			RK_SIP_SVC_VERSION_MINOR);
88 		break;
89 
90 	default:
91 		return rockchip_plat_sip_handler(smc_fid, x1, x2, x3, x4,
92 			cookie, handle, flags);
93 	}
94 }
95 
96 /* Define a runtime service descriptor for fast SMC calls */
97 DECLARE_RT_SVC(
98 	rockchip_sip_svc,
99 	OEN_SIP_START,
100 	OEN_SIP_END,
101 	SMC_TYPE_FAST,
102 	NULL,
103 	sip_smc_handler
104 );
105