smcc_helpers.h 2.9 KB
Newer Older
Soby Mathew's avatar
Soby Mathew committed
1
/*
2
 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
Soby Mathew's avatar
Soby Mathew committed
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
Soby Mathew's avatar
Soby Mathew committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 */

#ifndef __SMCC_HELPERS_H__
#define __SMCC_HELPERS_H__

#include <smcc.h>

#ifndef __ASSEMBLY__
#include <context.h>

/* Convenience macros to return from SMC handler */
#define SMC_RET0(_h)	{					\
	return (uint64_t) (_h);					\
}
#define SMC_RET1(_h, _x0)	{				\
20
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X0), (_x0));	\
Soby Mathew's avatar
Soby Mathew committed
21
22
23
	SMC_RET0(_h);						\
}
#define SMC_RET2(_h, _x0, _x1)	{				\
24
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X1), (_x1));	\
Soby Mathew's avatar
Soby Mathew committed
25
26
27
	SMC_RET1(_h, (_x0));					\
}
#define SMC_RET3(_h, _x0, _x1, _x2)	{			\
28
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X2), (_x2));	\
Soby Mathew's avatar
Soby Mathew committed
29
30
31
	SMC_RET2(_h, (_x0), (_x1));				\
}
#define SMC_RET4(_h, _x0, _x1, _x2, _x3)	{		\
32
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X3), (_x3));	\
Soby Mathew's avatar
Soby Mathew committed
33
34
	SMC_RET3(_h, (_x0), (_x1), (_x2));			\
}
Anthony Zhou's avatar
Anthony Zhou committed
35
#define SMC_RET5(_h, _x0, _x1, _x2, _x3, _x4)	{		\
36
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X4), (_x4));	\
Anthony Zhou's avatar
Anthony Zhou committed
37
38
39
	SMC_RET4(_h, (_x0), (_x1), (_x2), (_x3));		\
}
#define SMC_RET6(_h, _x0, _x1, _x2, _x3, _x4, _x5)	{	\
40
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X5), (_x5));	\
Anthony Zhou's avatar
Anthony Zhou committed
41
42
43
	SMC_RET5(_h, (_x0), (_x1), (_x2), (_x3), (_x4));	\
}
#define SMC_RET7(_h, _x0, _x1, _x2, _x3, _x4, _x5, _x6)	{	\
44
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X6), (_x6));	\
Anthony Zhou's avatar
Anthony Zhou committed
45
46
47
	SMC_RET6(_h, (_x0), (_x1), (_x2), (_x3), (_x4), (_x5));	\
}
#define SMC_RET8(_h, _x0, _x1, _x2, _x3, _x4, _x5, _x6, _x7) {	\
48
	write_ctx_reg((get_gpregs_ctx(_h)), (CTX_GPREG_X7), (_x7));	\
Anthony Zhou's avatar
Anthony Zhou committed
49
50
	SMC_RET7(_h, (_x0), (_x1), (_x2), (_x3), (_x4), (_x5), (_x6));	\
}
Soby Mathew's avatar
Soby Mathew committed
51
52
53
54
55
56

/*
 * Convenience macros to access general purpose registers using handle provided
 * to SMC handler. These take the offset values defined in context.h
 */
#define SMC_GET_GP(_h, _g)					\
57
	read_ctx_reg((get_gpregs_ctx(_h)), (_g))
Soby Mathew's avatar
Soby Mathew committed
58
#define SMC_SET_GP(_h, _g, _v)					\
59
	write_ctx_reg((get_gpregs_ctx(_h)), (_g), (_v))
Soby Mathew's avatar
Soby Mathew committed
60
61
62
63
64
65

/*
 * Convenience macros to access EL3 context registers using handle provided to
 * SMC handler. These take the offset values defined in context.h
 */
#define SMC_GET_EL3(_h, _e)					\
66
	read_ctx_reg((get_el3state_ctx(_h)), (_e))
Soby Mathew's avatar
Soby Mathew committed
67
#define SMC_SET_EL3(_h, _e, _v)					\
68
	write_ctx_reg((get_el3state_ctx(_h)), (_e), (_v))
Soby Mathew's avatar
Soby Mathew committed
69
70
71
72
73
74
75
76

/* Return a UUID in the SMC return registers */
#define SMC_UUID_RET(_h, _uuid)					\
	SMC_RET4(handle, ((const uint32_t *) &(_uuid))[0],	\
			 ((const uint32_t *) &(_uuid))[1],	\
			 ((const uint32_t *) &(_uuid))[2],	\
			 ((const uint32_t *) &(_uuid))[3])

77
78
79
80
81
82
83
84
85
86
87
88
/*
 * Helper macro to retrieve the SMC parameters from cpu_context_t.
 */
#define get_smc_params_from_ctx(_hdl, _x1, _x2, _x3, _x4)	\
	do {							\
		const gp_regs_t *regs = get_gpregs_ctx(_hdl);	\
		_x1 = read_ctx_reg(regs, CTX_GPREG_X1);		\
		_x2 = read_ctx_reg(regs, CTX_GPREG_X2);		\
		_x3 = read_ctx_reg(regs, CTX_GPREG_X3);		\
		_x4 = read_ctx_reg(regs, CTX_GPREG_X4);		\
	} while (0)

Soby Mathew's avatar
Soby Mathew committed
89
90
#endif /*__ASSEMBLY__*/
#endif /* __SMCC_HELPERS_H__ */