blob: efab18b0c48e5661305bfc960d5de5880bbb8fed [file] [log] [blame]
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +00001/*
2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef SMCCC_HELPERS_H
8#define SMCCC_HELPERS_H
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +00009
10#include <smccc.h>
11
12#ifndef __ASSEMBLY__
13#include <context.h>
Antonio Nino Diazf0b14cf2018-10-04 09:55:23 +010014#include <stdbool.h>
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000015
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
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000071/*
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); \
Antonio Nino Diazf0b14cf2018-10-04 09:55:23 +010081 } while (false)
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000082
83#endif /*__ASSEMBLY__*/
84
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +000085#endif /* SMCCC_HELPERS_H */