blob: 916c9a2f12b1cf19d91248ec5a658e718c7d38d4 [file] [log] [blame]
Soby Mathewb4c6df42022-11-09 11:13:29 +00001/*
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * SPDX-FileCopyrightText: Copyright TF-RMM Contributors.
5 */
6
7#ifndef SMC_RMI_H
8#define SMC_RMI_H
9
Soby Mathewb4c6df42022-11-09 11:13:29 +000010#include <smc.h>
11
12/*
13 * This file describes the Realm Management Interface (RMI) Application Binary
14 * Interface (ABI) for SMC calls made from Non-secure state to the RMM and
15 * serviced by the RMM.
16 *
17 * See doc/rmm_interface.md for more details.
18 */
19
20/*
21 * The major version number of the RMI implementation. Increase this whenever
22 * the binary format or semantics of the SMC calls change.
23 */
24#define RMI_ABI_VERSION_MAJOR (56U)
25
26/*
27 * The minor version number of the RMI implementation. Increase this when
28 * a bug is fixed, or a feature is added without breaking binary compatibility.
29 */
30#define RMI_ABI_VERSION_MINOR (0U)
31
32#define RMI_ABI_VERSION ((RMI_ABI_VERSION_MAJOR << 16U) | \
33 RMI_ABI_VERSION_MINOR)
34
35#define RMI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> 16U)
36#define RMI_ABI_VERSION_GET_MINOR(_version) ((_version) & 0xFFFFU)
37
38#define SMC64_RMI_FID(_offset) SMC64_STD_FID(RMI, _offset)
39
40#define IS_SMC64_RMI_FID(_fid) IS_SMC64_STD_FAST_IN_RANGE(RMI, _fid)
41
42/*
43 * The number of GPRs (starting from X0) that are
44 * configured by the host when a REC is created.
45 */
46#define REC_CREATE_NR_GPRS (8U)
47
48#define REC_PARAMS_FLAG_RUNNABLE (1UL << 0U)
49
50/*
51 * The number of GPRs (starting from X0) per voluntary exit context.
52 * Per SMCCC.
53 */
54#define REC_EXIT_NR_GPRS (31U)
55
56/* RmiHashAlgorithm type */
Soby Mathew3f56a4c2023-01-17 02:35:10 +000057#define RMI_HASH_ALGO_SHA256 0
58#define RMI_HASH_ALGO_SHA512 1
Soby Mathewb4c6df42022-11-09 11:13:29 +000059
60/* Maximum number of Interrupt Controller List Registers */
61#define REC_GIC_NUM_LRS (16U)
62
63/* Maximum number of auxiliary granules required for a REC */
64#define MAX_REC_AUX_GRANULES (16U)
65
66#define REC_ENTRY_FLAG_EMUL_MMIO (1UL << 0U)
67#define REC_ENTRY_FLAG_INJECT_SEA (1UL << 1U)
68
69/* Flags to specify if WFI/WFE should be trapped to host */
70#define REC_ENTRY_FLAG_TRAP_WFI (1UL << 2U)
71#define REC_ENTRY_FLAG_TRAP_WFE (1UL << 3U)
72
73/*
74 * RmiRecExitReason represents the reason for a REC exit.
75 * This is returned to NS hosts via RMI_REC_ENTER::run_ptr.
76 */
77#define RMI_EXIT_SYNC (0U)
78#define RMI_EXIT_IRQ (1U)
79#define RMI_EXIT_FIQ (2U)
80#define RMI_EXIT_PSCI (3U)
81#define RMI_EXIT_RIPAS_CHANGE (4U)
82#define RMI_EXIT_HOST_CALL (5U)
83#define RMI_EXIT_SERROR (6U)
84
85/* RmiRttEntryState represents the state of an RTTE */
86#define RMI_RTT_STATE_UNASSIGNED (0U)
87#define RMI_RTT_STATE_DESTROYED (1U)
88#define RMI_RTT_STATE_ASSIGNED (2U)
89#define RMI_RTT_STATE_TABLE (3U)
90#define RMI_RTT_STATE_VALID_NS (4U)
91
92/* no parameters */
93#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
94
95/*
96 * arg0 == target granule address
97 */
98#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
99
100/*
101 * arg0 == target granule address
102 */
103#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
104
105/* RmiDataMeasureContent type */
106#define RMI_NO_MEASURE_CONTENT 0
107#define RMI_MEASURE_CONTENT 1
108
109/*
110 * arg0 == data address
111 * arg1 == RD address
112 * arg2 == map address
113 * arg3 == SRC address
114 * arg4 == flags
115 */
116#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
117
118/*
119 * arg0 == data address
120 * arg1 == RD address
121 * arg2 == map address
122 */
123#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
124
125/*
126 * arg0 == RD address
127 * arg1 == map address
128 */
129#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
130
131/*
132 * arg0 == RD address
133 */
134#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
135
136/*
137 * arg0 == RD address
138 * arg1 == struct rmi_realm_params addr
139 */
140#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
141
142/*
143 * arg0 == RD address
144 */
145#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
146
147/*
148 * arg0 == REC address
149 * arg1 == RD address
150 * arg2 == struct rmm_rec address
151 */
152#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
153
154/*
155 * arg0 == REC address
156 */
157#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
158
159/*
160 * arg0 == rec address
161 * arg1 == rec_run address
162 */
163#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
164
165/*
166 * arg0 == RTT address
167 * arg1 == RD address
168 * arg2 == map address
169 * arg3 == level
170 */
171#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
172
173/*
174 * arg0 == RTT address
175 * arg1 == RD address
176 * arg2 == map address
177 * arg3 == level
178 */
179#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
180
181/*
182 * arg0 == RD address
183 * arg1 == map address
184 * arg2 == level
185 * arg3 == s2tte
186 */
187#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
188
189/*
190 * arg0 == RD address
191 * arg1 == map address
192 * arg2 == level
193 * ret1 == level
194 * ret2 == s2tte type
195 * ret3 == s2tte
196 * ret4 == ripas
197 */
198#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
199
200/*
201 * arg0 == RD address
202 * arg1 == map address
203 * arg2 == level
204 */
205#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
206
207/*
208 * arg0 == calling rec address
209 * arg1 == target rec address
210 */
211#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
212
213/*
214 * arg0 == Feature register index
215 */
216#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
217
218/*
219 * arg0 == RTT address
220 * arg1 == RD address
221 * arg2 == map address
222 * arg3 == level
223 */
224#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
225
226/*
227 * arg0 == RD address
228 */
229#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
230
231/*
232 * arg1 == RD address
233 * arg2 == map address
234 * arg3 == level
235 */
236#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
237
238/*
239 * arg0 == RD address
240 * arg1 == REC address
241 * arg2 == map address
242 * arg3 == level
243 * arg4 == ripas
244 */
245#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
246
247/* Size of Realm Personalization Value */
248#define RPV_SIZE 64
249
250/*
Soby Mathewc414f2a2023-01-17 02:50:17 +0000251 * Defines member of structure and reserves space
252 * for the next member with specified offset.
253 */
254#define SET_MEMBER_RMI SET_MEMBER
255
256/*
Soby Mathewb4c6df42022-11-09 11:13:29 +0000257 * The Realm attribute parameters are shared by the Host via
258 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
259 * either by the Host or by the Realm.
260 */
261struct rmi_realm_params {
262 /* Realm feature register 0 */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000263 SET_MEMBER_RMI(unsigned long features_0, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000264 /* Measurement algorithm */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000265 SET_MEMBER_RMI(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000266 /* Realm Personalization Value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000267 SET_MEMBER_RMI(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
268 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000269 /* Virtual Machine Identifier */
270 unsigned short vmid; /* 0x800 */
271 /* Realm Translation Table base */
272 unsigned long rtt_base; /* 0x808 */
273 /* RTT starting level */
274 long rtt_level_start; /* 0x810 */
275 /* Number of starting level RTTs */
276 unsigned int rtt_num_start; /* 0x818 */
277 }, 0x800, 0x1000);
278};
279
Soby Mathewb4c6df42022-11-09 11:13:29 +0000280/*
281 * The REC attribute parameters are shared by the Host via
282 * MI_REC_CREATE::params_ptr. The values can be observed or modified
283 * either by the Host or by the Realm which owns the REC.
284 */
285struct rmi_rec_params {
286 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000287 SET_MEMBER_RMI(unsigned long flags, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000288 /* MPIDR of the REC */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000289 SET_MEMBER_RMI(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000290 /* Program counter */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000291 SET_MEMBER_RMI(unsigned long pc, 0x200, 0x300); /* 0x200 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000292 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000293 SET_MEMBER_RMI(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
294 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000295 /* Number of auxiliary Granules */
296 unsigned long num_aux; /* 0x800 */
297 /* Addresses of auxiliary Granules */
298 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
299 }, 0x800, 0x1000);
300};
301
Soby Mathewb4c6df42022-11-09 11:13:29 +0000302/*
303 * Structure contains data passed from the Host to the RMM on REC entry
304 */
305struct rmi_rec_entry {
306 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000307 SET_MEMBER_RMI(unsigned long flags, 0, 0x200); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000308 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000309 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
310 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000311 /* GICv3 Hypervisor Control Register */
312 unsigned long gicv3_hcr; /* 0x300 */
313 /* GICv3 List Registers */
314 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
315 }, 0x300, 0x800);
316};
317
Soby Mathewb4c6df42022-11-09 11:13:29 +0000318/*
319 * Structure contains data passed from the RMM to the Host on REC exit
320 */
321struct rmi_rec_exit {
322 /* Exit reason */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000323 SET_MEMBER_RMI(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
324 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000325 /* Exception Syndrome Register */
326 unsigned long esr; /* 0x100 */
327 /* Fault Address Register */
328 unsigned long far; /* 0x108 */
329 /* Hypervisor IPA Fault Address register */
330 unsigned long hpfar; /* 0x110 */
331 }, 0x100, 0x200);
332 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000333 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
334 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000335 /* GICv3 Hypervisor Control Register */
336 unsigned long gicv3_hcr; /* 0x300 */
337 /* GICv3 List Registers */
338 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
339 /* GICv3 Maintenance Interrupt State Register */
340 unsigned long gicv3_misr; /* 0x388 */
341 /* GICv3 Virtual Machine Control Register */
342 unsigned long gicv3_vmcr; /* 0x390 */
343 }, 0x300, 0x400);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000344 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000345 /* Counter-timer Physical Timer Control Register */
346 unsigned long cntp_ctl; /* 0x400 */
347 /* Counter-timer Physical Timer CompareValue Register */
348 unsigned long cntp_cval; /* 0x408 */
349 /* Counter-timer Virtual Timer Control Register */
350 unsigned long cntv_ctl; /* 0x410 */
351 /* Counter-timer Virtual Timer CompareValue Register */
352 unsigned long cntv_cval; /* 0x418 */
353 }, 0x400, 0x500);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000354 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000355 /* Base address of pending RIPAS change */
356 unsigned long ripas_base; /* 0x500 */
357 /* Size of pending RIPAS change */
358 unsigned long ripas_size; /* 0x508 */
359 /* RIPAS value of pending RIPAS change */
360 unsigned char ripas_value; /* 0x510 */
361 }, 0x500, 0x600);
362 /* Host call immediate value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000363 SET_MEMBER_RMI(unsigned int imm, 0x600, 0x800); /* 0x600 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000364};
365
Soby Mathewb4c6df42022-11-09 11:13:29 +0000366/*
367 * Structure contains shared information between RMM and Host
368 * during REC entry and REC exit.
369 */
370struct rmi_rec_run {
371 /* Entry information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000372 SET_MEMBER_RMI(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000373 /* Exit information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000374 SET_MEMBER_RMI(struct rmi_rec_exit exit, 0x800, 0x1000); /* 0x800 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000375};
376
Soby Mathewb4c6df42022-11-09 11:13:29 +0000377#endif /* SMC_RMI_H */