Zelalem Aweke | 77c2775 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 1 | /* |
Tushar Khandelwal | f801fdc | 2024-04-22 15:35:40 +0100 | [diff] [blame] | 2 | * Copyright (c) 2021-2025, Arm Limited and Contributors. All rights reserved. |
Zelalem Aweke | 77c2775 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef RMMD_SVC_H |
| 8 | #define RMMD_SVC_H |
| 9 | |
Raghu Krishnamurthy | e9529e4 | 2024-09-24 07:11:29 -0700 | [diff] [blame] | 10 | #include <common/sha_common_macros.h> |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 11 | #include <lib/smccc.h> |
| 12 | #include <lib/utils_def.h> |
| 13 | |
Subhasish Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 14 | /* STD calls FNUM Min/Max ranges */ |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 15 | #define RMI_FNUM_MIN_VALUE U(0x150) |
| 16 | #define RMI_FNUM_MAX_VALUE U(0x18F) |
| 17 | |
Subhasish Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 18 | /* 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 Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 26 | #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 Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 36 | * RMI_FNUM_REQ_COMPLETE is the only function in the RMI range that originates |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 37 | * 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 Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 39 | * RMM. |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 40 | */ |
Subhasish Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 41 | /* 0x18F */ |
Javier Almansa Sobrino | e50fedb | 2022-07-04 17:06:36 +0100 | [diff] [blame] | 42 | #define RMM_RMI_REQ_COMPLETE SMC64_RMI_FID(U(0x3F)) |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 43 | |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 44 | /* 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 Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 55 | |
| 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 Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 65 | /* 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 Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 73 | /* 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 Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 83 | /* 0x1B0 - 0x1B1 */ |
Javier Almansa Sobrino | e50fedb | 2022-07-04 17:06:36 +0100 | [diff] [blame] | 84 | #define RMM_GTSI_DELEGATE SMC64_RMMD_EL3_FID(U(0)) |
| 85 | #define RMM_GTSI_UNDELEGATE SMC64_RMMD_EL3_FID(U(1)) |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 86 | |
| 87 | /* Return error codes from RMM-EL3 SMCs */ |
Javier Almansa Sobrino | dc65ae4 | 2022-04-13 17:57:35 +0100 | [diff] [blame] | 88 | #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 Conde | 42cf602 | 2024-07-10 14:33:42 -0500 | [diff] [blame] | 94 | #define E_RMM_AGAIN -6 |
Sona Mathew | 2132c70 | 2025-03-14 01:27:11 -0500 | [diff] [blame] | 95 | #define E_RMM_FAULT -7 |
| 96 | #define E_RMM_IN_PROGRESS -8 |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 97 | |
Shruti Gupta | ade6000 | 2023-10-26 12:01:28 +0100 | [diff] [blame] | 98 | /* Return error codes from RMI SMCs */ |
| 99 | #define RMI_SUCCESS 0 |
| 100 | #define RMI_ERROR_INPUT 1 |
| 101 | |
Soby Mathew | a043510 | 2022-03-22 16:21:19 +0000 | [diff] [blame] | 102 | /* |
| 103 | * Retrieve Realm attestation key from EL3. Only P-384 ECC curve key is |
| 104 | * supported. The arguments to this SMC are : |
| 105 | * arg0 - Function ID. |
| 106 | * arg1 - Realm attestation key buffer Physical address. |
| 107 | * arg2 - Realm attestation key buffer size (in bytes). |
| 108 | * arg3 - The type of the elliptic curve to which the requested |
| 109 | * attestation key belongs to. The value should be one of the |
| 110 | * defined curve types. |
| 111 | * The return arguments are : |
| 112 | * ret0 - Status / error. |
| 113 | * ret1 - Size of the realm attestation key if successful. |
| 114 | */ |
Subhasish Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 115 | /* 0x1B2 */ |
Javier Almansa Sobrino | e50fedb | 2022-07-04 17:06:36 +0100 | [diff] [blame] | 116 | #define RMM_ATTEST_GET_REALM_KEY SMC64_RMMD_EL3_FID(U(2)) |
Subhasish Ghosh | fb00dc4 | 2022-05-12 12:22:17 +0100 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * Retrieve Platform token from EL3. |
| 120 | * The arguments to this SMC are : |
| 121 | * arg0 - Function ID. |
| 122 | * arg1 - Platform attestation token buffer Physical address. (The challenge |
| 123 | * object is passed in this buffer.) |
| 124 | * arg2 - Platform attestation token buffer size (in bytes). |
| 125 | * arg3 - Challenge object size (in bytes). It has to be one of the defined |
| 126 | * SHA hash sizes. |
| 127 | * The return arguments are : |
| 128 | * ret0 - Status / error. |
| 129 | * ret1 - Size of the platform token if successful. |
| 130 | */ |
| 131 | /* 0x1B3 */ |
Javier Almansa Sobrino | e50fedb | 2022-07-04 17:06:36 +0100 | [diff] [blame] | 132 | #define RMM_ATTEST_GET_PLAT_TOKEN SMC64_RMMD_EL3_FID(U(3)) |
Soby Mathew | a043510 | 2022-03-22 16:21:19 +0000 | [diff] [blame] | 133 | |
Raghu Krishnamurthy | 6a88ec8 | 2024-06-03 19:02:29 -0700 | [diff] [blame] | 134 | /* Starting RMM-EL3 interface version 0.4 */ |
| 135 | #define RMM_EL3_FEATURES SMC64_RMMD_EL3_FID(U(4)) |
| 136 | #define RMM_EL3_FEAT_REG_0_IDX U(0) |
| 137 | /* Bit 0 of FEAT_REG_0 */ |
| 138 | /* 1 - the feature is present in EL3 , 0 - the feature is absent */ |
| 139 | #define RMM_EL3_FEAT_REG_0_EL3_TOKEN_SIGN_MASK U(0x1) |
| 140 | |
| 141 | /* |
| 142 | * Function codes to support attestation where EL3 is used to sign |
| 143 | * realm attestation tokens. In this model, the private key is not |
| 144 | * exposed to the RMM. |
| 145 | * The arguments to this SMC are: |
| 146 | * arg0 - Function ID. |
| 147 | * arg1 - Opcode, one of: |
| 148 | * RMM_EL3_TOKEN_SIGN_PUSH_REQ_OP, |
| 149 | * RMM_EL3_TOKEN_SIGN_PULL_RESP_OP, |
| 150 | * RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP |
| 151 | * arg2 - Pointer to buffer with request/response structures, |
| 152 | * which is in the RMM<->EL3 shared buffer. |
| 153 | * arg3 - Buffer size of memory pointed by arg2. |
| 154 | * arg4 - ECC Curve, when opcode is RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP |
| 155 | * The return arguments are: |
| 156 | * ret0 - Status/Error |
| 157 | * ret1 - Size of public key if opcode is RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP |
| 158 | */ |
| 159 | #define RMM_EL3_TOKEN_SIGN SMC64_RMMD_EL3_FID(U(5)) |
| 160 | |
| 161 | /* Opcodes for RMM_EL3_TOKEN_SIGN */ |
| 162 | #define RMM_EL3_TOKEN_SIGN_PUSH_REQ_OP U(1) |
| 163 | #define RMM_EL3_TOKEN_SIGN_PULL_RESP_OP U(2) |
| 164 | #define RMM_EL3_TOKEN_SIGN_GET_RAK_PUB_OP U(3) |
| 165 | |
Tushar Khandelwal | f801fdc | 2024-04-22 15:35:40 +0100 | [diff] [blame] | 166 | /* Starting RMM-EL3 interface version 0.5 */ |
| 167 | |
| 168 | /* |
| 169 | * Function code to support update of MEC keys. |
| 170 | * The arguments of this SMC are: |
| 171 | * arg0 - Function ID. |
| 172 | * arg1 - MECID |
| 173 | * The return arguments are: |
| 174 | * ret0 - Status/Error |
| 175 | */ |
| 176 | #define RMM_MECID_KEY_UPDATE SMC64_RMMD_EL3_FID(U(6)) |
| 177 | |
Soby Mathew | a043510 | 2022-03-22 16:21:19 +0000 | [diff] [blame] | 178 | /* ECC Curve types for attest key generation */ |
Raghu Krishnamurthy | 6a88ec8 | 2024-06-03 19:02:29 -0700 | [diff] [blame] | 179 | #define ATTEST_KEY_CURVE_ECC_SECP384R1 U(0) |
| 180 | |
| 181 | /* Identifier for the hash algorithm used for attestation signing */ |
| 182 | #define EL3_TOKEN_SIGN_HASH_ALG_SHA384 U(1) |
Soby Mathew | a043510 | 2022-03-22 16:21:19 +0000 | [diff] [blame] | 183 | |
Sona Mathew | 2132c70 | 2025-03-14 01:27:11 -0500 | [diff] [blame] | 184 | /* Starting RMM-EL3 interface version 0.6 */ |
| 185 | /* |
| 186 | * Function codes to support RMM IDE Key management Interface. |
| 187 | * The arguments to this SMC are: |
| 188 | * arg0 - Function ID. |
| 189 | * arg1 - Enhanced Configuration Access Mechanism address |
| 190 | * arg2 - Root Port ID |
| 191 | * arg3 - IDE selective stream info |
| 192 | * arg4 - Quad word of key[63:0] |
| 193 | * arg5 - Quad word of key[127:64] |
| 194 | * arg6 - Quad word of key[191:128] |
| 195 | * arg7 - Quad word of key[255:192] |
| 196 | * arg8 - Quad word of IV [63:0] |
| 197 | * arg9 - Quad word of IV [95:64] |
| 198 | * arg10 - request_id |
| 199 | * arg11 - cookie |
| 200 | * The return arguments are: |
| 201 | * ret0 - Status/Error |
| 202 | */ |
| 203 | #define RMM_IDE_KEY_PROG SMC64_RMMD_EL3_FID(U(7)) |
| 204 | |
| 205 | /******************************************************************************* |
| 206 | * Structure to hold el3_ide_key info |
| 207 | ******************************************************************************/ |
| 208 | #ifndef __ASSEMBLER__ |
| 209 | typedef struct rp_ide_key_info { |
| 210 | uint64_t keyqw0; |
| 211 | uint64_t keyqw1; |
| 212 | uint64_t keyqw2; |
| 213 | uint64_t keyqw3; |
| 214 | uint64_t ifvqw0; |
| 215 | uint64_t ifvqw1; |
| 216 | } rp_ide_key_info_t; |
| 217 | #endif /* __ASSEMBLER__ */ |
| 218 | |
| 219 | /* |
| 220 | * Function codes to support RMM IDE Key management Interface. |
| 221 | * The arguments to this SMC are: |
| 222 | * arg0 - Function ID. |
| 223 | * arg1 - Enhanced Configuration Access Mechanism address |
| 224 | * arg2 - Root Port ID |
| 225 | * arg3 - IDE selective stream info |
| 226 | * arg4 - request_id |
| 227 | * arg5 - cookie |
| 228 | * The return arguments are: |
| 229 | * ret0 - Status/Error |
| 230 | */ |
| 231 | #define RMM_IDE_KEY_SET_GO SMC64_RMMD_EL3_FID(U(8)) |
| 232 | |
| 233 | /* |
| 234 | * Function codes to support RMM IDE Key management Interface. |
| 235 | * The arguments to this SMC are: |
| 236 | * arg0 - Function ID. |
| 237 | * arg1 - Enhanced Configuration Access Mechanism address |
| 238 | * arg2 - Root Port ID |
| 239 | * arg3 - IDE selective stream info |
| 240 | * arg4 - request_id |
| 241 | * arg5 - cookie |
| 242 | * The return arguments are: |
| 243 | * ret0 - Status/Error |
| 244 | */ |
| 245 | #define RMM_IDE_KEY_SET_STOP SMC64_RMMD_EL3_FID(U(9)) |
| 246 | |
| 247 | /* |
| 248 | * Function codes to support RMM IDE Key management Interface. |
| 249 | * The arguments to this SMC are: |
| 250 | * arg0 - Function ID. |
| 251 | * arg1 - Enhanced Configuration Access Mechanism address |
| 252 | * arg2 - Root Port ID |
| 253 | * The return arguments are: |
| 254 | * ret0 - Status/Error |
| 255 | * ret1 - Retrieved response corresponding to the previous request. |
| 256 | * ret2 - request_id |
| 257 | * ret3 - cookie |
| 258 | */ |
| 259 | #define RMM_IDE_KM_PULL_RESPONSE SMC64_RMMD_EL3_FID(U(10)) |
| 260 | |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 261 | /* |
| 262 | * RMM_BOOT_COMPLETE originates on RMM when the boot finishes (either cold |
| 263 | * or warm boot). This is handled by the RMM-EL3 interface SMC handler. |
| 264 | * |
| 265 | * RMM_BOOT_COMPLETE FID is located at the end of the available range. |
| 266 | */ |
| 267 | /* 0x1CF */ |
| 268 | #define RMM_BOOT_COMPLETE SMC64_RMMD_EL3_FID(U(0x1F)) |
| 269 | |
| 270 | /* |
| 271 | * The major version number of the RMM Boot Interface implementation. |
| 272 | * Increase this whenever the semantics of the boot arguments change making it |
| 273 | * backwards incompatible. |
| 274 | */ |
| 275 | #define RMM_EL3_IFC_VERSION_MAJOR (U(0)) |
| 276 | |
| 277 | /* |
| 278 | * The minor version number of the RMM Boot Interface implementation. |
| 279 | * Increase this when a bug is fixed, or a feature is added without |
| 280 | * breaking compatibility. |
| 281 | */ |
Sona Mathew | 2132c70 | 2025-03-14 01:27:11 -0500 | [diff] [blame] | 282 | #define RMM_EL3_IFC_VERSION_MINOR (U(6)) |
Javier Almansa Sobrino | 8c980a4 | 2021-11-24 18:37:37 +0000 | [diff] [blame] | 283 | |
| 284 | #define RMM_EL3_INTERFACE_VERSION \ |
| 285 | (((RMM_EL3_IFC_VERSION_MAJOR << 16) & 0x7FFFF) | \ |
| 286 | RMM_EL3_IFC_VERSION_MINOR) |
| 287 | |
| 288 | #define RMM_EL3_IFC_VERSION_GET_MAJOR(_version) (((_version) >> 16) \ |
| 289 | & 0x7FFF) |
| 290 | #define RMM_EL3_IFC_VERSION_GET_MAJOR_MINOR(_version) ((_version) & 0xFFFF) |
Soby Mathew | a043510 | 2022-03-22 16:21:19 +0000 | [diff] [blame] | 291 | |
Zelalem Aweke | 77c2775 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 292 | #ifndef __ASSEMBLER__ |
| 293 | #include <stdint.h> |
| 294 | |
| 295 | int rmmd_setup(void); |
| 296 | uint64_t rmmd_rmi_handler(uint32_t smc_fid, |
| 297 | uint64_t x1, |
| 298 | uint64_t x2, |
| 299 | uint64_t x3, |
| 300 | uint64_t x4, |
| 301 | void *cookie, |
| 302 | void *handle, |
| 303 | uint64_t flags); |
| 304 | |
Soby Mathew | 319fb08 | 2022-03-22 13:58:52 +0000 | [diff] [blame] | 305 | uint64_t rmmd_rmm_el3_handler(uint32_t smc_fid, |
Zelalem Aweke | 77c2775 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 306 | uint64_t x1, |
| 307 | uint64_t x2, |
| 308 | uint64_t x3, |
| 309 | uint64_t x4, |
| 310 | void *cookie, |
| 311 | void *handle, |
| 312 | uint64_t flags); |
| 313 | |
| 314 | #endif /* __ASSEMBLER__ */ |
Zelalem Aweke | 77c2775 | 2021-07-09 14:20:03 -0500 | [diff] [blame] | 315 | #endif /* RMMD_SVC_H */ |