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 | */ |
| 21 | #define RSI_ABI_VERSION_MAJOR 12U |
| 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 | |
| 29 | #define RSI_ABI_VERSION ((RSI_ABI_VERSION_MAJOR << 16U) | \ |
| 30 | RSI_ABI_VERSION_MINOR) |
| 31 | |
| 32 | #define RSI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> 16U) |
| 33 | #define RSI_ABI_VERSION_GET_MINOR(_version) ((_version) & 0xFFFFU) |
| 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 */ |
| 42 | typedef enum { |
| 43 | /* Command completed successfully */ |
| 44 | RSI_SUCCESS = 0U, |
| 45 | |
| 46 | /* |
| 47 | * The value of a command input value |
| 48 | * caused the command to fail |
| 49 | */ |
| 50 | RSI_ERROR_INPUT = 1U, |
| 51 | |
| 52 | /* |
| 53 | * The state of the current Realm or current REC |
| 54 | * does not match the state expected by the command |
| 55 | */ |
| 56 | RSI_ERROR_STATE = 2U, |
| 57 | |
| 58 | /* The operation requested by the command is not complete */ |
| 59 | RSI_INCOMPLETE = 3U, |
| 60 | |
| 61 | RSI_ERROR_COUNT |
| 62 | } rsi_status_t; |
| 63 | |
| 64 | /* |
| 65 | * Returns a measurement. |
| 66 | * arg1: Measurement index (0..4), measurement (RIM or REM) to read |
| 67 | * ret0: Status / error |
| 68 | * ret1: Measurement value, bytes: 0 - 7 |
| 69 | * ret2: Measurement value, bytes: 7 - 15 |
| 70 | * ret3: Measurement value, bytes: 16 - 23 |
| 71 | * ret4: Measurement value, bytes: 24 - 31 |
| 72 | * ret5: Measurement value, bytes: 32 - 39 |
| 73 | * ret6: Measurement value, bytes: 40 - 47 |
| 74 | * ret7: Measurement value, bytes: 48 - 55 |
| 75 | * ret8: Measurement value, bytes: 56 - 63 |
| 76 | */ |
| 77 | #define SMC_RSI_MEASUREMENT_READ SMC64_RSI_FID(U(0x2)) |
| 78 | |
| 79 | /* |
| 80 | * Extends a REM. |
| 81 | * arg0: Measurement index (1..4), measurement (REM) to extend |
| 82 | * arg1: Measurement size in bytes |
| 83 | * arg3: Challenge value, bytes: 0 - 7 |
| 84 | * arg4: Challenge value, bytes: 7 - 15 |
| 85 | * arg5: Challenge value, bytes: 16 - 23 |
| 86 | * arg6: Challenge value, bytes: 24 - 31 |
| 87 | * arg7: Challenge value, bytes: 32 - 39 |
| 88 | * arg8: Challenge value, bytes: 40 - 47 |
| 89 | * arg9: Challenge value, bytes: 48 - 55 |
| 90 | * arg10: Challenge value, bytes: 56 - 63 |
| 91 | * ret0: Status / error |
| 92 | */ |
| 93 | #define SMC_RSI_MEASUREMENT_EXTEND SMC64_RSI_FID(U(0x3)) |
| 94 | |
| 95 | /* |
| 96 | * Initialize the operation to retrieve an attestation token. |
| 97 | * arg1: The IPA of token buffer |
| 98 | * arg2: Challenge value, bytes: 0 - 7 |
| 99 | * arg3: Challenge value, bytes: 7 - 15 |
| 100 | * arg4: Challenge value, bytes: 16 - 23 |
| 101 | * arg5: Challenge value, bytes: 24 - 31 |
| 102 | * arg6: Challenge value, bytes: 32 - 39 |
| 103 | * arg7: Challenge value, bytes: 40 - 47 |
| 104 | * arg8: Challenge value, bytes: 48 - 55 |
| 105 | * arg9: Challenge value, bytes: 56 - 63 |
| 106 | * ret0: Status / error |
| 107 | * ret1: Size of completed token in bytes |
| 108 | */ |
| 109 | #define SMC_RSI_ATTEST_TOKEN_INIT SMC64_RSI_FID(U(0x4)) |
| 110 | |
| 111 | /* |
| 112 | * Continue the operation to retrieve an attestation token. |
| 113 | * arg1: The IPA of token buffer |
| 114 | * ret0: Status / error |
| 115 | * ret1: Size of completed token in bytes |
| 116 | */ |
| 117 | #define SMC_RSI_ATTEST_TOKEN_CONTINUE SMC64_RSI_FID(U(0x5)) |
| 118 | |
Soby Mathew | 5216d17 | 2023-01-17 04:09:33 +0000 | [diff] [blame^] | 119 | /* |
| 120 | * Defines member of structure and reserves space |
| 121 | * for the next member with specified offset. |
| 122 | */ |
| 123 | #define SET_MEMBER_RSI SET_MEMBER |
| 124 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 125 | struct rsi_realm_config { |
| 126 | /* IPA width in bits */ |
Soby Mathew | 5216d17 | 2023-01-17 04:09:33 +0000 | [diff] [blame^] | 127 | SET_MEMBER_RSI(unsigned long ipa_width, 0, 0x1000); /* Offset 0 */ |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 128 | }; |
| 129 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 130 | /* |
| 131 | * arg0 == struct rsi_realm_config address |
| 132 | */ |
| 133 | #define SMC_RSI_REALM_CONFIG SMC64_RSI_FID(U(0x6)) |
| 134 | |
| 135 | /* |
| 136 | * arg0 == IPA address of target region |
| 137 | * arg1 == Size of target region in bytes |
| 138 | * arg2 == RIPAS value |
| 139 | * ret0 == Status / error |
| 140 | * ret1 == Top of modified IPA range |
| 141 | */ |
| 142 | #define SMC_RSI_IPA_STATE_SET SMC64_RSI_FID(U(0x7)) |
| 143 | |
| 144 | /* |
| 145 | * arg0 == IPA |
| 146 | * ret0 == Status / error |
| 147 | * ret1 == RIPAS value |
| 148 | */ |
| 149 | #define SMC_RSI_IPA_STATE_GET SMC64_RSI_FID(U(0x8)) |
| 150 | |
| 151 | #define RSI_HOST_CALL_NR_GPRS 7U |
| 152 | |
| 153 | struct rsi_host_call { |
Soby Mathew | 5216d17 | 2023-01-17 04:09:33 +0000 | [diff] [blame^] | 154 | SET_MEMBER_RSI(struct { |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 155 | /* Immediate value */ |
| 156 | unsigned int imm; /* Offset 0 */ |
| 157 | /* Registers */ |
| 158 | unsigned long gprs[RSI_HOST_CALL_NR_GPRS]; |
| 159 | }, 0, 0x100); |
| 160 | }; |
| 161 | |
Soby Mathew | b4c6df4 | 2022-11-09 11:13:29 +0000 | [diff] [blame] | 162 | /* |
| 163 | * arg0 == struct rsi_host_call addr |
| 164 | */ |
| 165 | #define SMC_RSI_HOST_CALL SMC64_RSI_FID(U(0x9)) |
| 166 | |
| 167 | #endif /* SMC_RSI_H */ |