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 | |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame^] | 41 | /* |
| 42 | * RsiCommandReturnCode enumeration |
| 43 | * representing a return code from an RSI command. |
| 44 | */ |
Soby Mathew | 40852d2 | 2023-01-17 04:16:07 +0000 | [diff] [blame] | 45 | /* Command completed successfully */ |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame^] | 46 | #define RSI_SUCCESS UL(0) |
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 | /* The value of a command input value caused the command to fail */ |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame^] | 49 | #define RSI_ERROR_INPUT UL(1) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 50 | |
Soby Mathew | 40852d2 | 2023-01-17 04:16:07 +0000 | [diff] [blame] | 51 | /* |
| 52 | * The state of the current Realm or current REC |
| 53 | * does not match the state expected by the command |
| 54 | */ |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame^] | 55 | #define RSI_ERROR_STATE UL(2) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 56 | |
Soby Mathew | 40852d2 | 2023-01-17 04:16:07 +0000 | [diff] [blame] | 57 | /* The operation requested by the command is not complete */ |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame^] | 58 | #define RSI_INCOMPLETE UL(3) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 59 | |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame^] | 60 | #define RSI_ERROR_COUNT UL(4) |
| 61 | |
| 62 | /* RsiHashAlgorithm */ |
| 63 | #define RSI_HASH_SHA_256 U(0) |
| 64 | #define RSI_HASH_SHA_512 U(1) |
| 65 | |
| 66 | /* |
| 67 | * RsiRipasChangeDestroyed: |
| 68 | * RIPAS change from DESTROYED should not be permitted |
| 69 | */ |
| 70 | #define RSI_NO_CHANGE_DESTROYED U(0) |
| 71 | |
| 72 | /* A RIPAS change from DESTROYED should be permitted */ |
| 73 | #define RSI_CHANGE_DESTROYED U(1) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Returns a measurement. |
| 77 | * arg1: Measurement index (0..4), measurement (RIM or REM) to read |
| 78 | * ret0: Status / error |
| 79 | * ret1: Measurement value, bytes: 0 - 7 |
| 80 | * ret2: Measurement value, bytes: 7 - 15 |
| 81 | * ret3: Measurement value, bytes: 16 - 23 |
| 82 | * ret4: Measurement value, bytes: 24 - 31 |
| 83 | * ret5: Measurement value, bytes: 32 - 39 |
| 84 | * ret6: Measurement value, bytes: 40 - 47 |
| 85 | * ret7: Measurement value, bytes: 48 - 55 |
| 86 | * ret8: Measurement value, bytes: 56 - 63 |
| 87 | */ |
| 88 | #define SMC_RSI_MEASUREMENT_READ SMC64_RSI_FID(U(0x2)) |
| 89 | |
| 90 | /* |
| 91 | * Extends a REM. |
| 92 | * arg0: Measurement index (1..4), measurement (REM) to extend |
| 93 | * arg1: Measurement size in bytes |
| 94 | * arg3: Challenge value, bytes: 0 - 7 |
| 95 | * arg4: Challenge value, bytes: 7 - 15 |
| 96 | * arg5: Challenge value, bytes: 16 - 23 |
| 97 | * arg6: Challenge value, bytes: 24 - 31 |
| 98 | * arg7: Challenge value, bytes: 32 - 39 |
| 99 | * arg8: Challenge value, bytes: 40 - 47 |
| 100 | * arg9: Challenge value, bytes: 48 - 55 |
| 101 | * arg10: Challenge value, bytes: 56 - 63 |
| 102 | * ret0: Status / error |
| 103 | */ |
| 104 | #define SMC_RSI_MEASUREMENT_EXTEND SMC64_RSI_FID(U(0x3)) |
| 105 | |
| 106 | /* |
| 107 | * Initialize the operation to retrieve an attestation token. |
| 108 | * arg1: The IPA of token buffer |
| 109 | * arg2: Challenge value, bytes: 0 - 7 |
| 110 | * arg3: Challenge value, bytes: 7 - 15 |
| 111 | * arg4: Challenge value, bytes: 16 - 23 |
| 112 | * arg5: Challenge value, bytes: 24 - 31 |
| 113 | * arg6: Challenge value, bytes: 32 - 39 |
| 114 | * arg7: Challenge value, bytes: 40 - 47 |
| 115 | * arg8: Challenge value, bytes: 48 - 55 |
| 116 | * arg9: Challenge value, bytes: 56 - 63 |
| 117 | * ret0: Status / error |
| 118 | * ret1: Size of completed token in bytes |
| 119 | */ |
| 120 | #define SMC_RSI_ATTEST_TOKEN_INIT SMC64_RSI_FID(U(0x4)) |
| 121 | |
| 122 | /* |
| 123 | * Continue the operation to retrieve an attestation token. |
| 124 | * arg1: The IPA of token buffer |
| 125 | * ret0: Status / error |
| 126 | * ret1: Size of completed token in bytes |
| 127 | */ |
| 128 | #define SMC_RSI_ATTEST_TOKEN_CONTINUE SMC64_RSI_FID(U(0x5)) |
| 129 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 130 | #ifndef __ASSEMBLER__ |
Soby Mathew | 5216d17 | 2023-01-17 04:09:33 +0000 | [diff] [blame] | 131 | /* |
| 132 | * Defines member of structure and reserves space |
| 133 | * for the next member with specified offset. |
| 134 | */ |
| 135 | #define SET_MEMBER_RSI SET_MEMBER |
| 136 | |
AlexeiFedorov | 531b527 | 2023-06-13 15:36:32 +0100 | [diff] [blame] | 137 | /* RsiRealmConfig structure containing realm configuration */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 138 | struct rsi_realm_config { |
| 139 | /* IPA width in bits */ |
AlexeiFedorov | 531b527 | 2023-06-13 15:36:32 +0100 | [diff] [blame] | 140 | SET_MEMBER_RSI(unsigned long ipa_width, 0, 8); /* Offset 0 */ |
| 141 | /* Hash algorithm */ |
| 142 | SET_MEMBER_RSI(unsigned long hash_algo, 8, 0x1000); /* Offset 8 */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 145 | #endif /* __ASSEMBLER__ */ |
| 146 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 147 | /* |
| 148 | * arg0 == struct rsi_realm_config address |
| 149 | */ |
| 150 | #define SMC_RSI_REALM_CONFIG SMC64_RSI_FID(U(0x6)) |
| 151 | |
| 152 | /* |
AlexeiFedorov | 233bcb2 | 2023-04-28 18:43:44 +0100 | [diff] [blame] | 153 | * arg0 == Base IPA address of target region |
| 154 | * arg1 == Top address of target region |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 155 | * arg2 == RIPAS value |
AlexeiFedorov | 63614ea | 2023-07-14 17:07:20 +0100 | [diff] [blame^] | 156 | * arg3 == flags |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 157 | * ret0 == Status / error |
| 158 | * ret1 == Top of modified IPA range |
| 159 | */ |
| 160 | #define SMC_RSI_IPA_STATE_SET SMC64_RSI_FID(U(0x7)) |
| 161 | |
| 162 | /* |
| 163 | * arg0 == IPA |
| 164 | * ret0 == Status / error |
| 165 | * ret1 == RIPAS value |
| 166 | */ |
| 167 | #define SMC_RSI_IPA_STATE_GET SMC64_RSI_FID(U(0x8)) |
| 168 | |
AlexeiFedorov | c7d62c2 | 2023-04-06 15:32:36 +0100 | [diff] [blame] | 169 | #define RSI_HOST_CALL_NR_GPRS U(31) |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 170 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 171 | #ifndef __ASSEMBLER__ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 172 | struct rsi_host_call { |
Soby Mathew | 5216d17 | 2023-01-17 04:09:33 +0000 | [diff] [blame] | 173 | SET_MEMBER_RSI(struct { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 174 | /* Immediate value */ |
| 175 | unsigned int imm; /* Offset 0 */ |
| 176 | /* Registers */ |
| 177 | unsigned long gprs[RSI_HOST_CALL_NR_GPRS]; |
| 178 | }, 0, 0x100); |
| 179 | }; |
| 180 | |
Yousuf A | fa6c521 | 2022-10-14 11:40:43 +0100 | [diff] [blame] | 181 | #endif /* __ASSEMBLER__ */ |
| 182 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 183 | /* |
AlexeiFedorov | c7d62c2 | 2023-04-06 15:32:36 +0100 | [diff] [blame] | 184 | * arg0 == struct rsi_host_call address |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 185 | */ |
| 186 | #define SMC_RSI_HOST_CALL SMC64_RSI_FID(U(0x9)) |
| 187 | |
| 188 | #endif /* SMC_RSI_H */ |