xref: /rk3399_rockchip-uboot/include/linux/arm-smccc.h (revision c2da86f39ed6cbccccc2736bdc421fd606734232)
1*c2da86f3SMasahiro Yamada /*
2*c2da86f3SMasahiro Yamada  * Copyright (c) 2015, Linaro Limited
3*c2da86f3SMasahiro Yamada  *
4*c2da86f3SMasahiro Yamada  * This software is licensed under the terms of the GNU General Public
5*c2da86f3SMasahiro Yamada  * License version 2, as published by the Free Software Foundation, and
6*c2da86f3SMasahiro Yamada  * may be copied, distributed, and modified under those terms.
7*c2da86f3SMasahiro Yamada  *
8*c2da86f3SMasahiro Yamada  * This program is distributed in the hope that it will be useful,
9*c2da86f3SMasahiro Yamada  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10*c2da86f3SMasahiro Yamada  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11*c2da86f3SMasahiro Yamada  * GNU General Public License for more details.
12*c2da86f3SMasahiro Yamada  *
13*c2da86f3SMasahiro Yamada  */
14*c2da86f3SMasahiro Yamada #ifndef __LINUX_ARM_SMCCC_H
15*c2da86f3SMasahiro Yamada #define __LINUX_ARM_SMCCC_H
16*c2da86f3SMasahiro Yamada 
17*c2da86f3SMasahiro Yamada /*
18*c2da86f3SMasahiro Yamada  * This file provides common defines for ARM SMC Calling Convention as
19*c2da86f3SMasahiro Yamada  * specified in
20*c2da86f3SMasahiro Yamada  * http://infocenter.arm.com/help/topic/com.arm.doc.den0028a/index.html
21*c2da86f3SMasahiro Yamada  */
22*c2da86f3SMasahiro Yamada 
23*c2da86f3SMasahiro Yamada #define ARM_SMCCC_STD_CALL		0
24*c2da86f3SMasahiro Yamada #define ARM_SMCCC_FAST_CALL		1
25*c2da86f3SMasahiro Yamada #define ARM_SMCCC_TYPE_SHIFT		31
26*c2da86f3SMasahiro Yamada 
27*c2da86f3SMasahiro Yamada #define ARM_SMCCC_SMC_32		0
28*c2da86f3SMasahiro Yamada #define ARM_SMCCC_SMC_64		1
29*c2da86f3SMasahiro Yamada #define ARM_SMCCC_CALL_CONV_SHIFT	30
30*c2da86f3SMasahiro Yamada 
31*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_MASK		0x3F
32*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_SHIFT		24
33*c2da86f3SMasahiro Yamada 
34*c2da86f3SMasahiro Yamada #define ARM_SMCCC_FUNC_MASK		0xFFFF
35*c2da86f3SMasahiro Yamada 
36*c2da86f3SMasahiro Yamada #define ARM_SMCCC_IS_FAST_CALL(smc_val)	\
37*c2da86f3SMasahiro Yamada 	((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT))
38*c2da86f3SMasahiro Yamada #define ARM_SMCCC_IS_64(smc_val) \
39*c2da86f3SMasahiro Yamada 	((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT))
40*c2da86f3SMasahiro Yamada #define ARM_SMCCC_FUNC_NUM(smc_val)	((smc_val) & ARM_SMCCC_FUNC_MASK)
41*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_NUM(smc_val) \
42*c2da86f3SMasahiro Yamada 	(((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK)
43*c2da86f3SMasahiro Yamada 
44*c2da86f3SMasahiro Yamada #define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \
45*c2da86f3SMasahiro Yamada 	(((type) << ARM_SMCCC_TYPE_SHIFT) | \
46*c2da86f3SMasahiro Yamada 	((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \
47*c2da86f3SMasahiro Yamada 	(((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \
48*c2da86f3SMasahiro Yamada 	((func_num) & ARM_SMCCC_FUNC_MASK))
49*c2da86f3SMasahiro Yamada 
50*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_ARCH		0
51*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_CPU		1
52*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_SIP		2
53*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_OEM		3
54*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_STANDARD	4
55*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_TRUSTED_APP	48
56*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_TRUSTED_APP_END	49
57*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_TRUSTED_OS	50
58*c2da86f3SMasahiro Yamada #define ARM_SMCCC_OWNER_TRUSTED_OS_END	63
59*c2da86f3SMasahiro Yamada 
60*c2da86f3SMasahiro Yamada #define ARM_SMCCC_QUIRK_NONE		0
61*c2da86f3SMasahiro Yamada #define ARM_SMCCC_QUIRK_QCOM_A6		1 /* Save/restore register a6 */
62*c2da86f3SMasahiro Yamada 
63*c2da86f3SMasahiro Yamada #ifndef __ASSEMBLY__
64*c2da86f3SMasahiro Yamada 
65*c2da86f3SMasahiro Yamada #include <linux/linkage.h>
66*c2da86f3SMasahiro Yamada #include <linux/types.h>
67*c2da86f3SMasahiro Yamada /**
68*c2da86f3SMasahiro Yamada  * struct arm_smccc_res - Result from SMC/HVC call
69*c2da86f3SMasahiro Yamada  * @a0-a3 result values from registers 0 to 3
70*c2da86f3SMasahiro Yamada  */
71*c2da86f3SMasahiro Yamada struct arm_smccc_res {
72*c2da86f3SMasahiro Yamada 	unsigned long a0;
73*c2da86f3SMasahiro Yamada 	unsigned long a1;
74*c2da86f3SMasahiro Yamada 	unsigned long a2;
75*c2da86f3SMasahiro Yamada 	unsigned long a3;
76*c2da86f3SMasahiro Yamada };
77*c2da86f3SMasahiro Yamada 
78*c2da86f3SMasahiro Yamada /**
79*c2da86f3SMasahiro Yamada  * struct arm_smccc_quirk - Contains quirk information
80*c2da86f3SMasahiro Yamada  * @id: quirk identification
81*c2da86f3SMasahiro Yamada  * @state: quirk specific information
82*c2da86f3SMasahiro Yamada  * @a6: Qualcomm quirk entry for returning post-smc call contents of a6
83*c2da86f3SMasahiro Yamada  */
84*c2da86f3SMasahiro Yamada struct arm_smccc_quirk {
85*c2da86f3SMasahiro Yamada 	int	id;
86*c2da86f3SMasahiro Yamada 	union {
87*c2da86f3SMasahiro Yamada 		unsigned long a6;
88*c2da86f3SMasahiro Yamada 	} state;
89*c2da86f3SMasahiro Yamada };
90*c2da86f3SMasahiro Yamada 
91*c2da86f3SMasahiro Yamada /**
92*c2da86f3SMasahiro Yamada  * __arm_smccc_smc() - make SMC calls
93*c2da86f3SMasahiro Yamada  * @a0-a7: arguments passed in registers 0 to 7
94*c2da86f3SMasahiro Yamada  * @res: result values from registers 0 to 3
95*c2da86f3SMasahiro Yamada  * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
96*c2da86f3SMasahiro Yamada  *
97*c2da86f3SMasahiro Yamada  * This function is used to make SMC calls following SMC Calling Convention.
98*c2da86f3SMasahiro Yamada  * The content of the supplied param are copied to registers 0 to 7 prior
99*c2da86f3SMasahiro Yamada  * to the SMC instruction. The return values are updated with the content
100*c2da86f3SMasahiro Yamada  * from register 0 to 3 on return from the SMC instruction.  An optional
101*c2da86f3SMasahiro Yamada  * quirk structure provides vendor specific behavior.
102*c2da86f3SMasahiro Yamada  */
103*c2da86f3SMasahiro Yamada asmlinkage void __arm_smccc_smc(unsigned long a0, unsigned long a1,
104*c2da86f3SMasahiro Yamada 			unsigned long a2, unsigned long a3, unsigned long a4,
105*c2da86f3SMasahiro Yamada 			unsigned long a5, unsigned long a6, unsigned long a7,
106*c2da86f3SMasahiro Yamada 			struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
107*c2da86f3SMasahiro Yamada 
108*c2da86f3SMasahiro Yamada /**
109*c2da86f3SMasahiro Yamada  * __arm_smccc_hvc() - make HVC calls
110*c2da86f3SMasahiro Yamada  * @a0-a7: arguments passed in registers 0 to 7
111*c2da86f3SMasahiro Yamada  * @res: result values from registers 0 to 3
112*c2da86f3SMasahiro Yamada  * @quirk: points to an arm_smccc_quirk, or NULL when no quirks are required.
113*c2da86f3SMasahiro Yamada  *
114*c2da86f3SMasahiro Yamada  * This function is used to make HVC calls following SMC Calling
115*c2da86f3SMasahiro Yamada  * Convention.  The content of the supplied param are copied to registers 0
116*c2da86f3SMasahiro Yamada  * to 7 prior to the HVC instruction. The return values are updated with
117*c2da86f3SMasahiro Yamada  * the content from register 0 to 3 on return from the HVC instruction.  An
118*c2da86f3SMasahiro Yamada  * optional quirk structure provides vendor specific behavior.
119*c2da86f3SMasahiro Yamada  */
120*c2da86f3SMasahiro Yamada asmlinkage void __arm_smccc_hvc(unsigned long a0, unsigned long a1,
121*c2da86f3SMasahiro Yamada 			unsigned long a2, unsigned long a3, unsigned long a4,
122*c2da86f3SMasahiro Yamada 			unsigned long a5, unsigned long a6, unsigned long a7,
123*c2da86f3SMasahiro Yamada 			struct arm_smccc_res *res, struct arm_smccc_quirk *quirk);
124*c2da86f3SMasahiro Yamada 
125*c2da86f3SMasahiro Yamada #define arm_smccc_smc(...) __arm_smccc_smc(__VA_ARGS__, NULL)
126*c2da86f3SMasahiro Yamada 
127*c2da86f3SMasahiro Yamada #define arm_smccc_smc_quirk(...) __arm_smccc_smc(__VA_ARGS__)
128*c2da86f3SMasahiro Yamada 
129*c2da86f3SMasahiro Yamada #define arm_smccc_hvc(...) __arm_smccc_hvc(__VA_ARGS__, NULL)
130*c2da86f3SMasahiro Yamada 
131*c2da86f3SMasahiro Yamada #define arm_smccc_hvc_quirk(...) __arm_smccc_hvc(__VA_ARGS__)
132*c2da86f3SMasahiro Yamada 
133*c2da86f3SMasahiro Yamada #endif /*__ASSEMBLY__*/
134*c2da86f3SMasahiro Yamada #endif /*__LINUX_ARM_SMCCC_H*/
135