blob: 0cc8628a63ad5116361bc6cbaba0f06887616c76 [file] [log] [blame]
Zelalem Aweke13dc8f12021-07-09 14:20:03 -05001/*
Juan Pablo Conde9b94a422024-07-10 14:33:42 -05002 * Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
Zelalem Aweke13dc8f12021-07-09 14:20:03 -05003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef RMMD_SVC_H
8#define RMMD_SVC_H
9
Raghu Krishnamurthy5821a542024-09-24 07:11:29 -070010#include <common/sha_common_macros.h>
Soby Mathew68ea9542022-03-22 13:58:52 +000011#include <lib/smccc.h>
12#include <lib/utils_def.h>
13
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010014/* STD calls FNUM Min/Max ranges */
Soby Mathew68ea9542022-03-22 13:58:52 +000015#define RMI_FNUM_MIN_VALUE U(0x150)
16#define RMI_FNUM_MAX_VALUE U(0x18F)
17
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010018/* Construct RMI fastcall std FID from offset */
19#define SMC64_RMI_FID(_offset) \
20 ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
21 (SMC_64 << FUNCID_CC_SHIFT) | \
22 (OEN_STD_START << FUNCID_OEN_SHIFT) | \
23 (((RMI_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \
24 << FUNCID_NUM_SHIFT))
25
Soby Mathew68ea9542022-03-22 13:58:52 +000026#define is_rmi_fid(fid) __extension__ ({ \
27 __typeof__(fid) _fid = (fid); \
28 ((GET_SMC_NUM(_fid) >= RMI_FNUM_MIN_VALUE) && \
29 (GET_SMC_NUM(_fid) <= RMI_FNUM_MAX_VALUE) && \
30 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
31 (GET_SMC_CC(_fid) == SMC_64) && \
32 (GET_SMC_OEN(_fid) == OEN_STD_START) && \
33 ((_fid & 0x00FE0000) == 0U)); })
34
35/*
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010036 * RMI_FNUM_REQ_COMPLETE is the only function in the RMI range that originates
Soby Mathew68ea9542022-03-22 13:58:52 +000037 * from the Realm world and is handled by the RMMD. The RMI functions are
38 * always invoked by the Normal world, forwarded by RMMD and handled by the
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010039 * RMM.
Soby Mathew68ea9542022-03-22 13:58:52 +000040 */
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010041 /* 0x18F */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +010042#define RMM_RMI_REQ_COMPLETE SMC64_RMI_FID(U(0x3F))
Soby Mathew68ea9542022-03-22 13:58:52 +000043
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +000044/* RMM_BOOT_COMPLETE arg0 error codes */
45#define E_RMM_BOOT_SUCCESS (0)
46#define E_RMM_BOOT_UNKNOWN (-1)
47#define E_RMM_BOOT_VERSION_MISMATCH (-2)
48#define E_RMM_BOOT_CPUS_OUT_OF_RANGE (-3)
49#define E_RMM_BOOT_CPU_ID_OUT_OF_RANGE (-4)
50#define E_RMM_BOOT_INVALID_SHARED_BUFFER (-5)
51#define E_RMM_BOOT_MANIFEST_VERSION_NOT_SUPPORTED (-6)
52#define E_RMM_BOOT_MANIFEST_DATA_ERROR (-7)
53
54/* The SMC in the range 0x8400 0191 - 0x8400 01AF are reserved for RSIs.*/
Soby Mathew68ea9542022-03-22 13:58:52 +000055
56/*
57 * EL3 - RMM SMCs used for requesting RMMD services. These SMCs originate in Realm
58 * world and return to Realm world.
59 *
60 * These are allocated from 0x8400 01B0 - 0x8400 01CF in the RMM Service range.
61 */
62#define RMMD_EL3_FNUM_MIN_VALUE U(0x1B0)
63#define RMMD_EL3_FNUM_MAX_VALUE U(0x1CF)
64
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010065/* Construct RMM_EL3 fastcall std FID from offset */
66#define SMC64_RMMD_EL3_FID(_offset) \
67 ((SMC_TYPE_FAST << FUNCID_TYPE_SHIFT) | \
68 (SMC_64 << FUNCID_CC_SHIFT) | \
69 (OEN_STD_START << FUNCID_OEN_SHIFT) | \
70 (((RMMD_EL3_FNUM_MIN_VALUE + (_offset)) & FUNCID_NUM_MASK) \
71 << FUNCID_NUM_SHIFT))
72
Soby Mathew68ea9542022-03-22 13:58:52 +000073/* The macros below are used to identify GTSI calls from the SMC function ID */
74#define is_rmmd_el3_fid(fid) __extension__ ({ \
75 __typeof__(fid) _fid = (fid); \
76 ((GET_SMC_NUM(_fid) >= RMMD_EL3_FNUM_MIN_VALUE) &&\
77 (GET_SMC_NUM(_fid) <= RMMD_EL3_FNUM_MAX_VALUE) &&\
78 (GET_SMC_TYPE(_fid) == SMC_TYPE_FAST) && \
79 (GET_SMC_CC(_fid) == SMC_64) && \
80 (GET_SMC_OEN(_fid) == OEN_STD_START) && \
81 ((_fid & 0x00FE0000) == 0U)); })
82
Subhasish Ghosh3ad16032022-05-12 12:22:17 +010083 /* 0x1B0 - 0x1B1 */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +010084#define RMM_GTSI_DELEGATE SMC64_RMMD_EL3_FID(U(0))
85#define RMM_GTSI_UNDELEGATE SMC64_RMMD_EL3_FID(U(1))
Soby Mathew68ea9542022-03-22 13:58:52 +000086
87/* Return error codes from RMM-EL3 SMCs */
Javier Almansa Sobrinodea652e2022-04-13 17:57:35 +010088#define E_RMM_OK 0
89#define E_RMM_UNK -1
90#define E_RMM_BAD_ADDR -2
91#define E_RMM_BAD_PAS -3
92#define E_RMM_NOMEM -4
93#define E_RMM_INVAL -5
Juan Pablo Conde9b94a422024-07-10 14:33:42 -050094#define E_RMM_AGAIN -6
Soby Mathew68ea9542022-03-22 13:58:52 +000095
Shruti Gupta23c87332023-10-26 12:01:28 +010096/* Return error codes from RMI SMCs */
97#define RMI_SUCCESS 0
98#define RMI_ERROR_INPUT 1
99
Soby Mathewf05d93a2022-03-22 16:21:19 +0000100/*
101 * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is
102 * supported. The arguments to this SMC are :
103 * arg0 - Function ID.
104 * arg1 - Realm attestation key buffer Physical address.
105 * arg2 - Realm attestation key buffer size (in bytes).
106 * arg3 - The type of the elliptic curve to which the requested
107 * attestation key belongs to. The value should be one of the
108 * defined curve types.
109 * The return arguments are :
110 * ret0 - Status / error.
111 * ret1 - Size of the realm attestation key if successful.
112 */
Subhasish Ghosh3ad16032022-05-12 12:22:17 +0100113 /* 0x1B2 */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +0100114#define RMM_ATTEST_GET_REALM_KEY SMC64_RMMD_EL3_FID(U(2))
Subhasish Ghosh3ad16032022-05-12 12:22:17 +0100115
116/*
117 * Retrieve Platform token from EL3.
118 * The arguments to this SMC are :
119 * arg0 - Function ID.
120 * arg1 - Platform attestation token buffer Physical address. (The challenge
121 * object is passed in this buffer.)
122 * arg2 - Platform attestation token buffer size (in bytes).
123 * arg3 - Challenge object size (in bytes). It has to be one of the defined
124 * SHA hash sizes.
125 * The return arguments are :
126 * ret0 - Status / error.
127 * ret1 - Size of the platform token if successful.
128 */
129 /* 0x1B3 */
Javier Almansa Sobrinof809b162022-07-04 17:06:36 +0100130#define RMM_ATTEST_GET_PLAT_TOKEN SMC64_RMMD_EL3_FID(U(3))
Soby Mathewf05d93a2022-03-22 16:21:19 +0000131
Raghu Krishnamurthyc11b60e2024-06-03 19:02:29 -0700132/* Starting RMM-EL3 interface version 0.4 */
133#define RMM_EL3_FEATURES SMC64_RMMD_EL3_FID(U(4))
134#define RMM_EL3_FEAT_REG_0_IDX U(0)
135/* Bit 0 of FEAT_REG_0 */
136/* 1 - the feature is present in EL3 , 0 - the feature is absent */
137#define RMM_EL3_FEAT_REG_0_EL3_TOKEN_SIGN_MASK U(0x1)
138
139/*
140 * Function codes to support attestation where EL3 is used to sign
141 * realm attestation tokens. In this model, the private key is not
142 * exposed to the RMM.
143 * The arguments to this SMC are:
144 * arg0 - Function ID.
145 * arg1 - Opcode, one of:
146 * RMM_EL3_TOKEN_SIGN_PUSH_REQ_OP,
147 * RMM_EL3_TOKEN_SIGN_PULL_RESP_OP,
148 * RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP
149 * arg2 - Pointer to buffer with request/response structures,
150 * which is in the RMM<->EL3 shared buffer.
151 * arg3 - Buffer size of memory pointed by arg2.
152 * arg4 - ECC Curve, when opcode is RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP
153 * The return arguments are:
154 * ret0 - Status/Error
155 * ret1 - Size of public key if opcode is RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP
156 */
157#define RMM_EL3_TOKEN_SIGN SMC64_RMMD_EL3_FID(U(5))
158
159/* Opcodes for RMM_EL3_TOKEN_SIGN */
160#define RMM_EL3_TOKEN_SIGN_PUSH_REQ_OP U(1)
161#define RMM_EL3_TOKEN_SIGN_PULL_RESP_OP U(2)
162#define RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP U(3)
163
Soby Mathewf05d93a2022-03-22 16:21:19 +0000164/* ECC Curve types for attest key generation */
Raghu Krishnamurthyc11b60e2024-06-03 19:02:29 -0700165#define ATTEST_KEY_CURVE_ECC_SECP384R1 U(0)
166
167/* Identifier for the hash algorithm used for attestation signing */
168#define EL3_TOKEN_SIGN_HASH_ALG_SHA384 U(1)
Soby Mathewf05d93a2022-03-22 16:21:19 +0000169
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +0000170/*
171 * RMM_BOOT_COMPLETE originates on RMM when the boot finishes (either cold
172 * or warm boot). This is handled by the RMM-EL3 interface SMC handler.
173 *
174 * RMM_BOOT_COMPLETE FID is located at the end of the available range.
175 */
176 /* 0x1CF */
177#define RMM_BOOT_COMPLETE SMC64_RMMD_EL3_FID(U(0x1F))
178
179/*
180 * The major version number of the RMM Boot Interface implementation.
181 * Increase this whenever the semantics of the boot arguments change making it
182 * backwards incompatible.
183 */
184#define RMM_EL3_IFC_VERSION_MAJOR (U(0))
185
186/*
187 * The minor version number of the RMM Boot Interface implementation.
188 * Increase this when a bug is fixed, or a feature is added without
189 * breaking compatibility.
190 */
Raghu Krishnamurthyc11b60e2024-06-03 19:02:29 -0700191#define RMM_EL3_IFC_VERSION_MINOR (U(4))
Javier Almansa Sobrino7176a772021-11-24 18:37:37 +0000192
193#define RMM_EL3_INTERFACE_VERSION \
194 (((RMM_EL3_IFC_VERSION_MAJOR << 16) & 0x7FFFF) | \
195 RMM_EL3_IFC_VERSION_MINOR)
196
197#define RMM_EL3_IFC_VERSION_GET_MAJOR(_version) (((_version) >> 16) \
198 & 0x7FFF)
199#define RMM_EL3_IFC_VERSION_GET_MAJOR_MINOR(_version) ((_version) & 0xFFFF)
Soby Mathewf05d93a2022-03-22 16:21:19 +0000200
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500201#ifndef __ASSEMBLER__
202#include <stdint.h>
203
204int rmmd_setup(void);
205uint64_t rmmd_rmi_handler(uint32_t smc_fid,
206 uint64_t x1,
207 uint64_t x2,
208 uint64_t x3,
209 uint64_t x4,
210 void *cookie,
211 void *handle,
212 uint64_t flags);
213
Soby Mathew68ea9542022-03-22 13:58:52 +0000214uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid,
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500215 uint64_t x1,
216 uint64_t x2,
217 uint64_t x3,
218 uint64_t x4,
219 void *cookie,
220 void *handle,
221 uint64_t flags);
222
223#endif /* __ASSEMBLER__ */
Zelalem Aweke13dc8f12021-07-09 14:20:03 -0500224#endif /* RMMD_SVC_H */