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