Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * SPDX-License-Identifier: BSD-3-Clause |
| 3 | * SPDX-FileCopyrightText: Copyright TF-RMM Contributors. |
| 4 | */ |
| 5 | |
| 6 | #ifndef SMC_RSI_H |
| 7 | #define SMC_RSI_H |
| 8 | |
| 9 | #include <smc.h> |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 10 | |
| 11 | /* |
| 12 | * This file describes the Realm Services Interface (RSI) Application Binary |
| 13 | * Interface (ABI) for SMC calls made from within the Realm to the RMM and |
| 14 | * serviced by the RMM. |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * The major version number of the RSI implementation. Increase this whenever |
| 19 | * the binary format or semantics of the SMC calls change. |
| 20 | */ |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 21 | #define RSI_ABI_VERSION_MAJOR U(12) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 22 | |
| 23 | /* |
| 24 | * The minor version number of the RSI implementation. Increase this when |
| 25 | * a bug is fixed, or a feature is added without breaking binary compatibility. |
| 26 | */ |
| 27 | #define RSI_ABI_VERSION_MINOR 0 |
| 28 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 29 | #define RSI_ABI_VERSION ((RSI_ABI_VERSION_MAJOR << U(16)) | \ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 30 | RSI_ABI_VERSION_MINOR) |
| 31 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 32 | #define RSI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> U(16)) |
| 33 | #define RSI_ABI_VERSION_GET_MINOR(_version) ((_version) & U(0xFFFF)) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 34 | |
| 35 | #define IS_SMC64_RSI_FID(_fid) IS_SMC64_STD_FAST_IN_RANGE(RSI, _fid) |
| 36 | |
| 37 | #define SMC64_RSI_FID(_offset) SMC64_STD_FID(RSI, _offset) |
| 38 | |
| 39 | #define SMC_RSI_ABI_VERSION SMC64_RSI_FID(U(0x0)) |
| 40 | |
| 41 | /* RSI Status code enumeration as per Section D4.3.6 of the RMM Spec */ |
Soby Mathew | 40852d2 | 2023-01-17 04:16:07 +0000 | [diff] [blame] | 42 | /* Command completed successfully */ |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 43 | #define RSI_SUCCESS U(0) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 44 | |
Soby Mathew | 40852d2 | 2023-01-17 04:16:07 +0000 | [diff] [blame] | 45 | /* The value of a command input value caused the command to fail */ |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 46 | #define RSI_ERROR_INPUT U(1) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 47 | |
Soby Mathew | 40852d2 | 2023-01-17 04:16:07 +0000 | [diff] [blame] | 48 | /* |
| 49 | * The state of the current Realm or current REC |
| 50 | * does not match the state expected by the command |
| 51 | */ |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 52 | #define RSI_ERROR_STATE U(2) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 53 | |
Soby Mathew | 40852d2 | 2023-01-17 04:16:07 +0000 | [diff] [blame] | 54 | /* The operation requested by the command is not complete */ |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 55 | #define RSI_INCOMPLETE U(3) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 56 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 57 | #define RSI_ERROR_COUNT U(4) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * Returns a measurement. |
| 61 | * arg1: Measurement index (0..4), measurement (RIM or REM) to read |
| 62 | * ret0: Status / error |
| 63 | * ret1: Measurement value, bytes: 0 - 7 |
| 64 | * ret2: Measurement value, bytes: 7 - 15 |
| 65 | * ret3: Measurement value, bytes: 16 - 23 |
| 66 | * ret4: Measurement value, bytes: 24 - 31 |
| 67 | * ret5: Measurement value, bytes: 32 - 39 |
| 68 | * ret6: Measurement value, bytes: 40 - 47 |
| 69 | * ret7: Measurement value, bytes: 48 - 55 |
| 70 | * ret8: Measurement value, bytes: 56 - 63 |
| 71 | */ |
| 72 | #define SMC_RSI_MEASUREMENT_READ SMC64_RSI_FID(U(0x2)) |
| 73 | |
| 74 | /* |
| 75 | * Extends a REM. |
| 76 | * arg0: Measurement index (1..4), measurement (REM) to extend |
| 77 | * arg1: Measurement size in bytes |
| 78 | * arg3: Challenge value, bytes: 0 - 7 |
| 79 | * arg4: Challenge value, bytes: 7 - 15 |
| 80 | * arg5: Challenge value, bytes: 16 - 23 |
| 81 | * arg6: Challenge value, bytes: 24 - 31 |
| 82 | * arg7: Challenge value, bytes: 32 - 39 |
| 83 | * arg8: Challenge value, bytes: 40 - 47 |
| 84 | * arg9: Challenge value, bytes: 48 - 55 |
| 85 | * arg10: Challenge value, bytes: 56 - 63 |
| 86 | * ret0: Status / error |
| 87 | */ |
| 88 | #define SMC_RSI_MEASUREMENT_EXTEND SMC64_RSI_FID(U(0x3)) |
| 89 | |
| 90 | /* |
| 91 | * Initialize the operation to retrieve an attestation token. |
| 92 | * arg1: The IPA of token buffer |
| 93 | * arg2: Challenge value, bytes: 0 - 7 |
| 94 | * arg3: Challenge value, bytes: 7 - 15 |
| 95 | * arg4: Challenge value, bytes: 16 - 23 |
| 96 | * arg5: Challenge value, bytes: 24 - 31 |
| 97 | * arg6: Challenge value, bytes: 32 - 39 |
| 98 | * arg7: Challenge value, bytes: 40 - 47 |
| 99 | * arg8: Challenge value, bytes: 48 - 55 |
| 100 | * arg9: Challenge value, bytes: 56 - 63 |
| 101 | * ret0: Status / error |
| 102 | * ret1: Size of completed token in bytes |
| 103 | */ |
| 104 | #define SMC_RSI_ATTEST_TOKEN_INIT SMC64_RSI_FID(U(0x4)) |
| 105 | |
| 106 | /* |
| 107 | * Continue the operation to retrieve an attestation token. |
| 108 | * arg1: The IPA of token buffer |
| 109 | * ret0: Status / error |
| 110 | * ret1: Size of completed token in bytes |
| 111 | */ |
| 112 | #define SMC_RSI_ATTEST_TOKEN_CONTINUE SMC64_RSI_FID(U(0x5)) |
| 113 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 114 | #ifndef __ASSEMBLER__ |
Soby Mathew | 5216d17 | 2023-01-17 04:09:33 +0000 | [diff] [blame] | 115 | /* |
| 116 | * Defines member of structure and reserves space |
| 117 | * for the next member with specified offset. |
| 118 | */ |
| 119 | #define SET_MEMBER_RSI SET_MEMBER |
| 120 | |
AlexeiFedorov | 531b527 | 2023-06-13 15:36:32 +0100 | [diff] [blame] | 121 | /* RsiHashAlgorithm type */ |
| 122 | #define RSI_HASH_SHA_256 U(0) |
| 123 | #define RSI_HASH_SHA_512 U(1) |
| 124 | |
| 125 | /* RsiRealmConfig structure containing realm configuration */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 126 | struct rsi_realm_config { |
| 127 | /* IPA width in bits */ |
AlexeiFedorov | 531b527 | 2023-06-13 15:36:32 +0100 | [diff] [blame] | 128 | SET_MEMBER_RSI(unsigned long ipa_width, 0, 8); /* Offset 0 */ |
| 129 | /* Hash algorithm */ |
| 130 | SET_MEMBER_RSI(unsigned long hash_algo, 8, 0x1000); /* Offset 8 */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 131 | }; |
| 132 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 133 | #endif /* __ASSEMBLER__ */ |
| 134 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 135 | /* |
| 136 | * arg0 == struct rsi_realm_config address |
| 137 | */ |
| 138 | #define SMC_RSI_REALM_CONFIG SMC64_RSI_FID(U(0x6)) |
| 139 | |
| 140 | /* |
AlexeiFedorov | 233bcb2 | 2023-04-28 18:43:44 +0100 | [diff] [blame] | 141 | * arg0 == Base IPA address of target region |
| 142 | * arg1 == Top address of target region |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 143 | * arg2 == RIPAS value |
| 144 | * ret0 == Status / error |
| 145 | * ret1 == Top of modified IPA range |
| 146 | */ |
| 147 | #define SMC_RSI_IPA_STATE_SET SMC64_RSI_FID(U(0x7)) |
| 148 | |
| 149 | /* |
| 150 | * arg0 == IPA |
| 151 | * ret0 == Status / error |
| 152 | * ret1 == RIPAS value |
| 153 | */ |
| 154 | #define SMC_RSI_IPA_STATE_GET SMC64_RSI_FID(U(0x8)) |
| 155 | |
AlexeiFedorov | c7d62c2 | 2023-04-06 15:32:36 +0100 | [diff] [blame] | 156 | #define RSI_HOST_CALL_NR_GPRS U(31) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 157 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 158 | #ifndef __ASSEMBLER__ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 159 | struct rsi_host_call { |
Soby Mathew | 5216d17 | 2023-01-17 04:09:33 +0000 | [diff] [blame] | 160 | SET_MEMBER_RSI(struct { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 161 | /* Immediate value */ |
| 162 | unsigned int imm; /* Offset 0 */ |
| 163 | /* Registers */ |
| 164 | unsigned long gprs[RSI_HOST_CALL_NR_GPRS]; |
| 165 | }, 0, 0x100); |
| 166 | }; |
| 167 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 168 | #endif /* __ASSEMBLER__ */ |
| 169 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 170 | /* |
AlexeiFedorov | c7d62c2 | 2023-04-06 15:32:36 +0100 | [diff] [blame] | 171 | * arg0 == struct rsi_host_call address |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 172 | */ |
| 173 | #define SMC_RSI_HOST_CALL SMC64_RSI_FID(U(0x9)) |
| 174 | |
| 175 | #endif /* SMC_RSI_H */ |