xref: /rk3399_ARM-atf/include/arch/aarch64/smccc_helpers.h (revision f5478dedf9e096d9539362b38ceb096b940ba3e2)
1 /*
2  * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef SMCCC_HELPERS_H
8 #define SMCCC_HELPERS_H
9 
10 #include <smccc.h>
11 
12 #ifndef __ASSEMBLY__
13 #include <context.h>
14 #include <stdbool.h>
15 
16 /* Convenience macros to return from SMC handler */
17 #define SMC_RET0(_h)	{					\
18 	return (uint64_t) (_h);					\
19 }
20 #define SMC_RET1(_h, _x0)	{				\
21 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X0), (_x0));	\
22 	SMC_RET0(_h);						\
23 }
24 #define SMC_RET2(_h, _x0, _x1)	{				\
25 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X1), (_x1));	\
26 	SMC_RET1(_h, (_x0));					\
27 }
28 #define SMC_RET3(_h, _x0, _x1, _x2)	{			\
29 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X2), (_x2));	\
30 	SMC_RET2(_h, (_x0), (_x1));				\
31 }
32 #define SMC_RET4(_h, _x0, _x1, _x2, _x3)	{		\
33 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X3), (_x3));	\
34 	SMC_RET3(_h, (_x0), (_x1), (_x2));			\
35 }
36 #define SMC_RET5(_h, _x0, _x1, _x2, _x3, _x4)	{		\
37 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X4), (_x4));	\
38 	SMC_RET4(_h, (_x0), (_x1), (_x2), (_x3));		\
39 }
40 #define SMC_RET6(_h, _x0, _x1, _x2, _x3, _x4, _x5)	{	\
41 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X5), (_x5));	\
42 	SMC_RET5(_h, (_x0), (_x1), (_x2), (_x3), (_x4));	\
43 }
44 #define SMC_RET7(_h, _x0, _x1, _x2, _x3, _x4, _x5, _x6)	{	\
45 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X6), (_x6));	\
46 	SMC_RET6(_h, (_x0), (_x1), (_x2), (_x3), (_x4), (_x5));	\
47 }
48 #define SMC_RET8(_h, _x0, _x1, _x2, _x3, _x4, _x5, _x6, _x7) {	\
49 	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X7), (_x7));	\
50 	SMC_RET7(_h, (_x0), (_x1), (_x2), (_x3), (_x4), (_x5), (_x6));	\
51 }
52 
53 /*
54  * Convenience macros to access general purpose registers using handle provided
55  * to SMC handler. These take the offset values defined in context.h
56  */
57 #define SMC_GET_GP(_h, _g)					\
58 	read_ctx_reg((get_gpregs_ctx(_h)), (_g))
59 #define SMC_SET_GP(_h, _g, _v)					\
60 	write_ctx_reg((get_gpregs_ctx(_h)), (_g), (_v))
61 
62 /*
63  * Convenience macros to access EL3 context registers using handle provided to
64  * SMC handler. These take the offset values defined in context.h
65  */
66 #define SMC_GET_EL3(_h, _e)					\
67 	read_ctx_reg((get_el3state_ctx(_h)), (_e))
68 #define SMC_SET_EL3(_h, _e, _v)					\
69 	write_ctx_reg((get_el3state_ctx(_h)), (_e), (_v))
70 
71 /*
72  * Helper macro to retrieve the SMC parameters from cpu_context_t.
73  */
74 #define get_smc_params_from_ctx(_hdl, _x1, _x2, _x3, _x4)	\
75 	do {							\
76 		const gp_regs_t *regs = get_gpregs_ctx(_hdl);	\
77 		_x1 = read_ctx_reg(regs, CTX_GPREG_X1);		\
78 		_x2 = read_ctx_reg(regs, CTX_GPREG_X2);		\
79 		_x3 = read_ctx_reg(regs, CTX_GPREG_X3);		\
80 		_x4 = read_ctx_reg(regs, CTX_GPREG_X4);		\
81 	} while (false)
82 
83 #endif /*__ASSEMBLY__*/
84 
85 #endif /* SMCCC_HELPERS_H */
86