blob: cb722b0e2e238fc57f7c827e409635ddbaa4a046 [file] [log] [blame]
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +00001/*
2 * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef __SMCCC_H__
8#define __SMCCC_H__
9
10#include <utils_def.h>
11
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +010012#define SMCCC_VERSION_MAJOR_SHIFT U(16)
13#define SMCCC_VERSION_MAJOR_MASK U(0x7FFF)
14#define SMCCC_VERSION_MINOR_SHIFT U(0)
15#define SMCCC_VERSION_MINOR_MASK U(0xFFFF)
16#define MAKE_SMCCC_VERSION(_major, _minor) \
Antonio Nino Diaz39ed74d2018-05-02 09:52:35 +010017 ((((uint32_t)(_major) & SMCCC_VERSION_MAJOR_MASK) << \
18 SMCCC_VERSION_MAJOR_SHIFT) \
19 | (((uint32_t)(_minor) & SMCCC_VERSION_MINOR_MASK) << \
20 SMCCC_VERSION_MINOR_SHIFT))
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000021
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +010022#if SMCCC_MAJOR_VERSION == 1
23# define SMCCC_MINOR_VERSION U(1)
24# include <smccc_v1.h>
25#elif SMCCC_MAJOR_VERSION == 2
26# define SMCCC_MINOR_VERSION U(0)
27# include <smccc_v2.h>
28#else
29# error "Unsupported version of SMCCC."
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000030#endif
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +010031
32/* Various flags passed to SMC handlers */
33#define SMC_FROM_SECURE (U(0) << 0)
34#define SMC_FROM_NON_SECURE (U(1) << 0)
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000035
36#ifndef __ASSEMBLY__
37
38#include <cassert.h>
39#include <stdint.h>
40
Antonio Nino Diaze8811472018-04-17 15:10:18 +010041#define is_caller_non_secure(_f) (((_f) & SMC_FROM_NON_SECURE) != U(0))
42#define is_caller_secure(_f) (!is_caller_non_secure(_f))
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000043
44/* The macro below is used to identify a Standard Service SMC call */
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +010045#define is_std_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_STD_START)
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000046
47/* The macro below is used to identify a Arm Architectural Service SMC call */
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +010048#define is_arm_arch_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_ARM_START)
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000049
50/* The macro below is used to identify a valid Fast SMC call */
51#define is_valid_fast_smc(_fid) ((!(((_fid) >> 16) & U(0xff))) && \
52 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST))
53
54/*
55 * Macro to define UUID for services. Apart from defining and initializing a
56 * uuid_t structure, this macro verifies that the first word of the defined UUID
57 * does not equal SMC_UNK. This is to ensure that the caller won't mistake the
58 * returned UUID in x0 for an invalid SMC error return
59 */
Roberto Vargaseace8f12018-04-26 13:36:53 +010060#if !ERROR_DEPRECATED
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000061#define DEFINE_SVC_UUID(_name, _tl, _tm, _th, _cl, _ch, \
62 _n0, _n1, _n2, _n3, _n4, _n5) \
63 CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\
64 static const uuid_t _name = { \
65 _tl, _tm, _th, _cl, _ch, \
66 { _n0, _n1, _n2, _n3, _n4, _n5 } \
67 }
Roberto Vargaseace8f12018-04-26 13:36:53 +010068#endif
69
70
71#define DEFINE_SVC_UUID2(_name, _tl, _tm, _th, _cl, _ch, \
72 _n0, _n1, _n2, _n3, _n4, _n5) \
73 CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\
74 static const uuid_t _name = { \
75 {(_tl >> 24) & 0xFF, \
76 (_tl >> 16) & 0xFF, \
77 (_tl >> 8) & 0xFF, \
78 (_tl & 0xFF)}, \
79 {(_tm >> 8) & 0xFF, \
80 (_tm & 0xFF)}, \
81 {(_th >> 8) & 0xFF, \
82 (_th & 0xFF)}, \
83 _cl, _ch, \
84 { _n0, _n1, _n2, _n3, _n4, _n5 } \
85 }
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000086
87#endif /*__ASSEMBLY__*/
88#endif /* __SMCCC_H__ */