blob: 5e13e6f0a5e64d7ac932ffdf12907384a8ee71dc [file] [log] [blame]
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +00001/*
Olivier Deprez304b7f92019-12-23 12:04:45 +01002 * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef SMCCC_H
8#define SMCCC_H
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +00009
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010#include <lib/utils_def.h>
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000011
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 Diaz0e402d32019-01-30 16:01:49 +000022#define SMCCC_MAJOR_VERSION U(1)
Madhukar Pappireddy20be0772019-11-09 23:28:08 -060023#define SMCCC_MINOR_VERSION U(2)
Antonio Nino Diaz0e402d32019-01-30 16:01:49 +000024
25/*******************************************************************************
26 * Bit definitions inside the function id as per the SMC calling convention
27 ******************************************************************************/
28#define FUNCID_TYPE_SHIFT U(31)
29#define FUNCID_TYPE_MASK U(0x1)
30#define FUNCID_TYPE_WIDTH U(1)
31
32#define FUNCID_CC_SHIFT U(30)
33#define FUNCID_CC_MASK U(0x1)
34#define FUNCID_CC_WIDTH U(1)
35
36#define FUNCID_OEN_SHIFT U(24)
37#define FUNCID_OEN_MASK U(0x3f)
38#define FUNCID_OEN_WIDTH U(6)
39
40#define FUNCID_NUM_SHIFT U(0)
41#define FUNCID_NUM_MASK U(0xffff)
42#define FUNCID_NUM_WIDTH U(16)
43
Olivier Deprez304b7f92019-12-23 12:04:45 +010044#define GET_SMC_NUM(id) (((id) >> FUNCID_NUM_SHIFT) & \
45 FUNCID_NUM_MASK)
Antonio Nino Diaz0e402d32019-01-30 16:01:49 +000046#define GET_SMC_TYPE(id) (((id) >> FUNCID_TYPE_SHIFT) & \
47 FUNCID_TYPE_MASK)
48#define GET_SMC_CC(id) (((id) >> FUNCID_CC_SHIFT) & \
49 FUNCID_CC_MASK)
50#define GET_SMC_OEN(id) (((id) >> FUNCID_OEN_SHIFT) & \
51 FUNCID_OEN_MASK)
52
53/*******************************************************************************
54 * Owning entity number definitions inside the function id as per the SMC
55 * calling convention
56 ******************************************************************************/
57#define OEN_ARM_START U(0)
58#define OEN_ARM_END U(0)
59#define OEN_CPU_START U(1)
60#define OEN_CPU_END U(1)
61#define OEN_SIP_START U(2)
62#define OEN_SIP_END U(2)
63#define OEN_OEM_START U(3)
64#define OEN_OEM_END U(3)
65#define OEN_STD_START U(4) /* Standard Service Calls */
66#define OEN_STD_END U(4)
67#define OEN_STD_HYP_START U(5) /* Standard Hypervisor Service calls */
68#define OEN_STD_HYP_END U(5)
69#define OEN_VEN_HYP_START U(6) /* Vendor Hypervisor Service calls */
70#define OEN_VEN_HYP_END U(6)
71#define OEN_TAP_START U(48) /* Trusted Applications */
72#define OEN_TAP_END U(49)
73#define OEN_TOS_START U(50) /* Trusted OS */
74#define OEN_TOS_END U(63)
75#define OEN_LIMIT U(64)
76
77/* Flags and error codes */
78#define SMC_64 U(1)
79#define SMC_32 U(0)
80
81#define SMC_TYPE_FAST ULL(1)
82#define SMC_TYPE_YIELD ULL(0)
83
84#define SMC_OK ULL(0)
85#define SMC_UNK -1
86#define SMC_PREEMPTED -2 /* Not defined by the SMCCC */
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +010087
Madhukar Pappireddy20be0772019-11-09 23:28:08 -060088/* Return codes for Arm Architecture Service SMC calls */
89#define SMC_ARCH_CALL_SUCCESS 0
90#define SMC_ARCH_CALL_NOT_SUPPORTED -1
91#define SMC_ARCH_CALL_NOT_REQUIRED -2
92#define SMC_ARCH_CALL_INVAL_PARAM -3
93
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +010094/* Various flags passed to SMC handlers */
95#define SMC_FROM_SECURE (U(0) << 0)
96#define SMC_FROM_NON_SECURE (U(1) << 0)
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000097
Julius Werner53456fc2019-07-09 13:49:11 -070098#ifndef __ASSEMBLER__
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +000099
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +0000100#include <stdint.h>
101
Antonio Nino Diaze0f90632018-12-14 00:18:21 +0000102#include <lib/cassert.h>
103
Antonio Nino Diaze8811472018-04-17 15:10:18 +0100104#define is_caller_non_secure(_f) (((_f) & SMC_FROM_NON_SECURE) != U(0))
105#define is_caller_secure(_f) (!is_caller_non_secure(_f))
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +0000106
107/* The macro below is used to identify a Standard Service SMC call */
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +0100108#define is_std_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_STD_START)
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +0000109
110/* The macro below is used to identify a Arm Architectural Service SMC call */
Antonio Nino Diaz35c8cfc2018-04-23 15:43:29 +0100111#define is_arm_arch_svc_call(_fid) (GET_SMC_OEN(_fid) == OEN_ARM_START)
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +0000112
113/* The macro below is used to identify a valid Fast SMC call */
114#define is_valid_fast_smc(_fid) ((!(((_fid) >> 16) & U(0xff))) && \
115 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST))
116
117/*
118 * Macro to define UUID for services. Apart from defining and initializing a
119 * uuid_t structure, this macro verifies that the first word of the defined UUID
120 * does not equal SMC_UNK. This is to ensure that the caller won't mistake the
121 * returned UUID in x0 for an invalid SMC error return
122 */
Roberto Vargaseace8f12018-04-26 13:36:53 +0100123#define DEFINE_SVC_UUID2(_name, _tl, _tm, _th, _cl, _ch, \
124 _n0, _n1, _n2, _n3, _n4, _n5) \
125 CASSERT((uint32_t)(_tl) != (uint32_t) SMC_UNK, invalid_svc_uuid);\
126 static const uuid_t _name = { \
127 {(_tl >> 24) & 0xFF, \
128 (_tl >> 16) & 0xFF, \
129 (_tl >> 8) & 0xFF, \
130 (_tl & 0xFF)}, \
131 {(_tm >> 8) & 0xFF, \
132 (_tm & 0xFF)}, \
133 {(_th >> 8) & 0xFF, \
134 (_th & 0xFF)}, \
135 _cl, _ch, \
136 { _n0, _n1, _n2, _n3, _n4, _n5 } \
137 }
Antonio Nino Diaz3c817f42018-03-21 10:49:27 +0000138
Sandrine Bailleuxc5e89782018-07-02 13:01:16 +0200139/*
140 * Return a UUID in the SMC return registers.
141 *
142 * Acccording to section 5.3 of the SMCCC, UUIDs are returned as a single
143 * 128-bit value using the SMC32 calling convention. This value is mapped to
144 * argument registers x0-x3 on AArch64 (resp. r0-r3 on AArch32). x0 for example
145 * shall hold bytes 0 to 3, with byte 0 in the low-order bits.
146 */
147static inline uint32_t smc_uuid_word(uint8_t b0, uint8_t b1, uint8_t b2, uint8_t b3)
148{
149 return ((uint32_t) b0) | (((uint32_t) b1) << 8) |
150 (((uint32_t) b2) << 16) | (((uint32_t) b3) << 24);
151}
152
153#define SMC_UUID_RET(_h, _uuid) \
154 SMC_RET4(handle, \
155 smc_uuid_word((_uuid).time_low[0], (_uuid).time_low[1], \
156 (_uuid).time_low[2], (_uuid).time_low[3]), \
157 smc_uuid_word((_uuid).time_mid[0], (_uuid).time_mid[1], \
158 (_uuid).time_hi_and_version[0], \
159 (_uuid).time_hi_and_version[1]), \
160 smc_uuid_word((_uuid).clock_seq_hi_and_reserved, \
161 (_uuid).clock_seq_low, (_uuid).node[0], \
162 (_uuid).node[1]), \
163 smc_uuid_word((_uuid).node[2], (_uuid).node[3], \
164 (_uuid).node[4], (_uuid).node[5]))
165
Julius Werner53456fc2019-07-09 13:49:11 -0700166#endif /*__ASSEMBLER__*/
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000167#endif /* SMCCC_H */