blob: 7fae7d8dc1f70db583ac06ae97a08a36dea53884 [file] [log] [blame]
Soby Mathewd0194872016-04-29 19:01:30 +01001/*
2 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __SMCC_HELPERS_H__
32#define __SMCC_HELPERS_H__
33
34#include <smcc.h>
35
36#ifndef __ASSEMBLY__
37#include <context.h>
38
39/* Convenience macros to return from SMC handler */
40#define SMC_RET0(_h) { \
41 return (uint64_t) (_h); \
42}
43#define SMC_RET1(_h, _x0) { \
44 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X0, (_x0)); \
45 SMC_RET0(_h); \
46}
47#define SMC_RET2(_h, _x0, _x1) { \
48 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X1, (_x1)); \
49 SMC_RET1(_h, (_x0)); \
50}
51#define SMC_RET3(_h, _x0, _x1, _x2) { \
52 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X2, (_x2)); \
53 SMC_RET2(_h, (_x0), (_x1)); \
54}
55#define SMC_RET4(_h, _x0, _x1, _x2, _x3) { \
56 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X3, (_x3)); \
57 SMC_RET3(_h, (_x0), (_x1), (_x2)); \
58}
Anthony Zhou700ebe52015-10-31 06:03:41 +080059#define SMC_RET5(_h, _x0, _x1, _x2, _x3, _x4) { \
60 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X4, (_x4)); \
61 SMC_RET4(_h, (_x0), (_x1), (_x2), (_x3)); \
62}
63#define SMC_RET6(_h, _x0, _x1, _x2, _x3, _x4, _x5) { \
64 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X5, (_x5)); \
65 SMC_RET5(_h, (_x0), (_x1), (_x2), (_x3), (_x4)); \
66}
67#define SMC_RET7(_h, _x0, _x1, _x2, _x3, _x4, _x5, _x6) { \
68 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X6, (_x6)); \
69 SMC_RET6(_h, (_x0), (_x1), (_x2), (_x3), (_x4), (_x5)); \
70}
71#define SMC_RET8(_h, _x0, _x1, _x2, _x3, _x4, _x5, _x6, _x7) { \
72 write_ctx_reg(get_gpregs_ctx(_h), CTX_GPREG_X7, (_x7)); \
73 SMC_RET7(_h, (_x0), (_x1), (_x2), (_x3), (_x4), (_x5), (_x6)); \
74}
Soby Mathewd0194872016-04-29 19:01:30 +010075
76/*
77 * Convenience macros to access general purpose registers using handle provided
78 * to SMC handler. These take the offset values defined in context.h
79 */
80#define SMC_GET_GP(_h, _g) \
81 read_ctx_reg(get_gpregs_ctx(_h), (_g))
82#define SMC_SET_GP(_h, _g, _v) \
83 write_ctx_reg(get_gpregs_ctx(_h), (_g), (_v))
84
85/*
86 * Convenience macros to access EL3 context registers using handle provided to
87 * SMC handler. These take the offset values defined in context.h
88 */
89#define SMC_GET_EL3(_h, _e) \
90 read_ctx_reg(get_el3state_ctx(_h), (_e))
91#define SMC_SET_EL3(_h, _e, _v) \
92 write_ctx_reg(get_el3state_ctx(_h), (_e), (_v))
93
94/* Return a UUID in the SMC return registers */
95#define SMC_UUID_RET(_h, _uuid) \
96 SMC_RET4(handle, ((const uint32_t *) &(_uuid))[0], \
97 ((const uint32_t *) &(_uuid))[1], \
98 ((const uint32_t *) &(_uuid))[2], \
99 ((const uint32_t *) &(_uuid))[3])
100
Soby Mathewa9482df2016-05-05 12:49:09 +0100101/*
102 * Helper macro to retrieve the SMC parameters from cpu_context_t.
103 */
104#define get_smc_params_from_ctx(_hdl, _x1, _x2, _x3, _x4) \
105 do { \
106 const gp_regs_t *regs = get_gpregs_ctx(_hdl); \
107 _x1 = read_ctx_reg(regs, CTX_GPREG_X1); \
108 _x2 = read_ctx_reg(regs, CTX_GPREG_X2); \
109 _x3 = read_ctx_reg(regs, CTX_GPREG_X3); \
110 _x4 = read_ctx_reg(regs, CTX_GPREG_X4); \
111 } while (0)
112
Soby Mathewd0194872016-04-29 19:01:30 +0100113#endif /*__ASSEMBLY__*/
114#endif /* __SMCC_HELPERS_H__ */