blob: 1e7af6ab8e10aa5db6c2693663eb560205a89cba [file] [log] [blame]
Antonio Nino Diaz085e80e2018-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 Diaz2f370462018-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) \
17 ( (((uint32_t)(_major) & SMCCC_VERSION_MAJOR_MASK) << SMCCC_VERSION_MAJOR_SHIFT) \
18 | (((uint32_t)(_minor) & SMCCC_VERSION_MINOR_MASK) << SMCCC_VERSION_MINOR_SHIFT))
Antonio Nino Diaz085e80e2018-03-21 10:49:27 +000019
Antonio Nino Diaz2f370462018-04-23 15:43:29 +010020#if SMCCC_MAJOR_VERSION == 1
21# define SMCCC_MINOR_VERSION U(1)
22# include <smccc_v1.h>
23#elif SMCCC_MAJOR_VERSION == 2
24# define SMCCC_MINOR_VERSION U(0)
25# include <smccc_v2.h>
26#else
27# error "Unsupported version of SMCCC."
Antonio Nino Diaz085e80e2018-03-21 10:49:27 +000028#endif
Antonio Nino Diaz2f370462018-04-23 15:43:29 +010029
30/* Various flags passed to SMC handlers */
31#define SMC_FROM_SECURE (U(0) << 0)
32#define SMC_FROM_NON_SECURE (U(1) << 0)
Antonio Nino Diaz085e80e2018-03-21 10:49:27 +000033
34#ifndef __ASSEMBLY__
35
36#include <cassert.h>
37#include <stdint.h>
38
Antonio Nino Diazb3323cd2018-04-17 15:10:18 +010039#define is_caller_non_secure(_f) (((_f) & SMC_FROM_NON_SECURE) != U(0))
40#define is_caller_secure(_f) (!is_caller_non_secure(_f))
Antonio Nino Diaz085e80e2018-03-21 10:49:27 +000041
42/* The macro below is used to identify a Standard Service SMC call */
Antonio Nino Diaz2f370462018-04-23 15:43:29 +010043#define is_std_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_STD_START)
Antonio Nino Diaz085e80e2018-03-21 10:49:27 +000044
45/* The macro below is used to identify a Arm Architectural Service SMC call */
Antonio Nino Diaz2f370462018-04-23 15:43:29 +010046#define is_arm_arch_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_ARM_START)
Antonio Nino Diaz085e80e2018-03-21 10:49:27 +000047
48/* The macro below is used to identify a valid Fast SMC call */
49#define is_valid_fast_smc(_fid) ((!(((_fid) >> 16) & U(0xff))) && \
50 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST))
51
52/*
53 * Macro to define UUID for services. Apart from defining and initializing a
54 * uuid_t structure, this macro verifies that the first word of the defined UUID
55 * does not equal SMC_UNK. This is to ensure that the caller won't mistake the
56 * returned UUID in x0 for an invalid SMC error return
57 */
58#define DEFINE_SVC_UUID(_name, _tl, _tm, _th, _cl, _ch, \
59 _n0, _n1, _n2, _n3, _n4, _n5) \
60 CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\
61 static const uuid_t _name = { \
62 _tl, _tm, _th, _cl, _ch, \
63 { _n0, _n1, _n2, _n3, _n4, _n5 } \
64 }
65
66#endif /*__ASSEMBLY__*/
67#endif /* __SMCCC_H__ */