xref: /rk3399_ARM-atf/include/lib/smccc.h (revision 43b8fa8e981226418b8d0722ba260a7df63638ab)
1085e80ecSAntonio Nino Diaz /*
2085e80ecSAntonio Nino Diaz  * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
3085e80ecSAntonio Nino Diaz  *
4085e80ecSAntonio Nino Diaz  * SPDX-License-Identifier: BSD-3-Clause
5085e80ecSAntonio Nino Diaz  */
6085e80ecSAntonio Nino Diaz 
7085e80ecSAntonio Nino Diaz #ifndef __SMCCC_H__
8085e80ecSAntonio Nino Diaz #define __SMCCC_H__
9085e80ecSAntonio Nino Diaz 
10085e80ecSAntonio Nino Diaz #include <utils_def.h>
11085e80ecSAntonio Nino Diaz 
122f370465SAntonio Nino Diaz #define SMCCC_VERSION_MAJOR_SHIFT	U(16)
132f370465SAntonio Nino Diaz #define SMCCC_VERSION_MAJOR_MASK	U(0x7FFF)
142f370465SAntonio Nino Diaz #define SMCCC_VERSION_MINOR_SHIFT	U(0)
152f370465SAntonio Nino Diaz #define SMCCC_VERSION_MINOR_MASK	U(0xFFFF)
162f370465SAntonio Nino Diaz #define MAKE_SMCCC_VERSION(_major, _minor) \
170c487ea4SAntonio Nino Diaz 	((((uint32_t)(_major) & SMCCC_VERSION_MAJOR_MASK) << \
180c487ea4SAntonio Nino Diaz 						SMCCC_VERSION_MAJOR_SHIFT) \
190c487ea4SAntonio Nino Diaz 	| (((uint32_t)(_minor) & SMCCC_VERSION_MINOR_MASK) << \
200c487ea4SAntonio Nino Diaz 						SMCCC_VERSION_MINOR_SHIFT))
21085e80ecSAntonio Nino Diaz 
222f370465SAntonio Nino Diaz #if SMCCC_MAJOR_VERSION == 1
232f370465SAntonio Nino Diaz # define SMCCC_MINOR_VERSION U(1)
242f370465SAntonio Nino Diaz # include <smccc_v1.h>
252f370465SAntonio Nino Diaz #elif SMCCC_MAJOR_VERSION == 2
262f370465SAntonio Nino Diaz # define SMCCC_MINOR_VERSION U(0)
272f370465SAntonio Nino Diaz # include <smccc_v2.h>
282f370465SAntonio Nino Diaz #else
292f370465SAntonio Nino Diaz # error "Unsupported version of SMCCC."
30085e80ecSAntonio Nino Diaz #endif
312f370465SAntonio Nino Diaz 
322f370465SAntonio Nino Diaz /* Various flags passed to SMC handlers */
332f370465SAntonio Nino Diaz #define SMC_FROM_SECURE		(U(0) << 0)
342f370465SAntonio Nino Diaz #define SMC_FROM_NON_SECURE	(U(1) << 0)
35085e80ecSAntonio Nino Diaz 
36085e80ecSAntonio Nino Diaz #ifndef __ASSEMBLY__
37085e80ecSAntonio Nino Diaz 
38085e80ecSAntonio Nino Diaz #include <cassert.h>
39085e80ecSAntonio Nino Diaz #include <stdint.h>
40085e80ecSAntonio Nino Diaz 
41b3323cd6SAntonio Nino Diaz #define is_caller_non_secure(_f)	(((_f) & SMC_FROM_NON_SECURE) != U(0))
42b3323cd6SAntonio Nino Diaz #define is_caller_secure(_f)		(!is_caller_non_secure(_f))
43085e80ecSAntonio Nino Diaz 
44085e80ecSAntonio Nino Diaz /* The macro below is used to identify a Standard Service SMC call */
452f370465SAntonio Nino Diaz #define is_std_svc_call(_fid)		(GET_SMC_OEN(_fid) == OEN_STD_START)
46085e80ecSAntonio Nino Diaz 
47085e80ecSAntonio Nino Diaz /* The macro below is used to identify a Arm Architectural Service SMC call */
482f370465SAntonio Nino Diaz #define is_arm_arch_svc_call(_fid)	(GET_SMC_OEN(_fid) == OEN_ARM_START)
49085e80ecSAntonio Nino Diaz 
50085e80ecSAntonio Nino Diaz /* The macro below is used to identify a valid Fast SMC call */
51085e80ecSAntonio Nino Diaz #define is_valid_fast_smc(_fid)		((!(((_fid) >> 16) & U(0xff))) && \
52085e80ecSAntonio Nino Diaz 					   (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST))
53085e80ecSAntonio Nino Diaz 
54085e80ecSAntonio Nino Diaz /*
55085e80ecSAntonio Nino Diaz  * Macro to define UUID for services. Apart from defining and initializing a
56085e80ecSAntonio Nino Diaz  * uuid_t structure, this macro verifies that the first word of the defined UUID
57085e80ecSAntonio Nino Diaz  * does not equal SMC_UNK. This is to ensure that the caller won't mistake the
58085e80ecSAntonio Nino Diaz  * returned UUID in x0 for an invalid SMC error return
59085e80ecSAntonio Nino Diaz  */
6003364865SRoberto Vargas #if !ERROR_DEPRECATED
61085e80ecSAntonio Nino Diaz #define DEFINE_SVC_UUID(_name, _tl, _tm, _th, _cl, _ch, \
62085e80ecSAntonio Nino Diaz 		_n0, _n1, _n2, _n3, _n4, _n5) \
63085e80ecSAntonio Nino Diaz 	CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\
64085e80ecSAntonio Nino Diaz 	static const uuid_t _name = { \
65085e80ecSAntonio Nino Diaz 		_tl, _tm, _th, _cl, _ch, \
66085e80ecSAntonio Nino Diaz 		{ _n0, _n1, _n2, _n3, _n4, _n5 } \
67085e80ecSAntonio Nino Diaz 	}
6803364865SRoberto Vargas #endif
6903364865SRoberto Vargas 
7003364865SRoberto Vargas 
7103364865SRoberto Vargas #define DEFINE_SVC_UUID2(_name, _tl, _tm, _th, _cl, _ch,		\
7203364865SRoberto Vargas 		_n0, _n1, _n2, _n3, _n4, _n5)				\
7303364865SRoberto Vargas 	CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\
7403364865SRoberto Vargas 	static const uuid_t _name = {					\
7503364865SRoberto Vargas 		{(_tl >> 24) & 0xFF,					\
7603364865SRoberto Vargas 		 (_tl >> 16) & 0xFF,					\
7703364865SRoberto Vargas 		 (_tl >> 8)  & 0xFF,					\
7803364865SRoberto Vargas 		 (_tl & 0xFF)},						\
7903364865SRoberto Vargas 		{(_tm >> 8) & 0xFF,					\
8003364865SRoberto Vargas 		 (_tm  & 0xFF)},					\
8103364865SRoberto Vargas 		{(_th >> 8) & 0xFF,					\
8203364865SRoberto Vargas 		 (_th & 0xFF)},						\
8303364865SRoberto Vargas 		_cl, _ch,						\
8403364865SRoberto Vargas 		{ _n0, _n1, _n2, _n3, _n4, _n5 }			\
8503364865SRoberto Vargas 	}
86085e80ecSAntonio Nino Diaz 
87*43b8fa8eSSandrine Bailleux /*
88*43b8fa8eSSandrine Bailleux  * Return a UUID in the SMC return registers.
89*43b8fa8eSSandrine Bailleux  *
90*43b8fa8eSSandrine Bailleux  * Acccording to section 5.3 of the SMCCC, UUIDs are returned as a single
91*43b8fa8eSSandrine Bailleux  * 128-bit value using the SMC32 calling convention. This value is mapped to
92*43b8fa8eSSandrine Bailleux  * argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example
93*43b8fa8eSSandrine Bailleux  * shall hold bytes 0 to 3, with byte 0 in the low-order bits.
94*43b8fa8eSSandrine Bailleux  */
95*43b8fa8eSSandrine Bailleux static inline uint32_t smc_uuid_word(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3)
96*43b8fa8eSSandrine Bailleux {
97*43b8fa8eSSandrine Bailleux 	return ((uint32_t) b0) | (((uint32_t) b1) << 8) |
98*43b8fa8eSSandrine Bailleux 		(((uint32_t) b2) << 16) | (((uint32_t) b3) << 24);
99*43b8fa8eSSandrine Bailleux }
100*43b8fa8eSSandrine Bailleux 
101*43b8fa8eSSandrine Bailleux #define SMC_UUID_RET(_h, _uuid)							\
102*43b8fa8eSSandrine Bailleux 	SMC_RET4(handle,							\
103*43b8fa8eSSandrine Bailleux 		smc_uuid_word((_uuid).time_low[0], (_uuid).time_low[1],		\
104*43b8fa8eSSandrine Bailleux 			      (_uuid).time_low[2], (_uuid).time_low[3]),	\
105*43b8fa8eSSandrine Bailleux 		smc_uuid_word((_uuid).time_mid[0], (_uuid).time_mid[1],		\
106*43b8fa8eSSandrine Bailleux 			      (_uuid).time_hi_and_version[0],			\
107*43b8fa8eSSandrine Bailleux 			      (_uuid).time_hi_and_version[1]),			\
108*43b8fa8eSSandrine Bailleux 		smc_uuid_word((_uuid).clock_seq_hi_and_reserved,		\
109*43b8fa8eSSandrine Bailleux 			      (_uuid).clock_seq_low, (_uuid).node[0],		\
110*43b8fa8eSSandrine Bailleux 			      (_uuid).node[1]),					\
111*43b8fa8eSSandrine Bailleux 		smc_uuid_word((_uuid).node[2], (_uuid).node[3],			\
112*43b8fa8eSSandrine Bailleux 			      (_uuid).node[4], (_uuid).node[5]))
113*43b8fa8eSSandrine Bailleux 
114085e80ecSAntonio Nino Diaz #endif /*__ASSEMBLY__*/
115085e80ecSAntonio Nino Diaz #endif /* __SMCCC_H__ */
116