blob: 9b90cd967e8fe1ed89e2555ed6fed76476bae9e0 [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
Yousuf A0ec040d2022-10-31 12:30:57 +000042/* Command completed successfully. index is zero. */
43#define RMI_SUCCESS U(0)
44
45/*
46 * The value of a command input value caused the command to fail.
47 * Index is zero.
48 */
49#define RMI_ERROR_INPUT U(1)
50
51/*
52 * An attribute of a Realm does not match the expected value.
53 * index varies between usages.
54 */
55#define RMI_ERROR_REALM U(2)
56
57/*
58 * An attribute of a REC does not match the expected value.
59 * Index is zero.
60 */
61#define RMI_ERROR_REC U(3)
62
63/*
64 * An RTT walk terminated before reaching the target RTT level, or reached
65 * an RTTE with an unexpected value. index: RTT level at which the walk
66 * terminated
67 */
68#define RMI_ERROR_RTT U(4)
69
70/*
71 * An operation cannot be completed because a resource is in use.
72 * Index is zero.
73 */
74#define RMI_ERROR_IN_USE U(5)
75
76/*
77 * Number of RMI Status Errors.
78 */
79#define RMI_ERROR_COUNT U(6)
80
Soby Mathewb4c6df42022-11-09 11:13:29 +000081/*
82 * The number of GPRs (starting from X0) that are
83 * configured by the host when a REC is created.
84 */
85#define REC_CREATE_NR_GPRS (8U)
86
87#define REC_PARAMS_FLAG_RUNNABLE (1UL << 0U)
88
89/*
90 * The number of GPRs (starting from X0) per voluntary exit context.
91 * Per SMCCC.
92 */
93#define REC_EXIT_NR_GPRS (31U)
94
95/* RmiHashAlgorithm type */
Soby Mathew3f56a4c2023-01-17 02:35:10 +000096#define RMI_HASH_ALGO_SHA256 0
97#define RMI_HASH_ALGO_SHA512 1
Soby Mathewb4c6df42022-11-09 11:13:29 +000098
99/* Maximum number of Interrupt Controller List Registers */
100#define REC_GIC_NUM_LRS (16U)
101
102/* Maximum number of auxiliary granules required for a REC */
103#define MAX_REC_AUX_GRANULES (16U)
104
105#define REC_ENTRY_FLAG_EMUL_MMIO (1UL << 0U)
106#define REC_ENTRY_FLAG_INJECT_SEA (1UL << 1U)
107
108/* Flags to specify if WFI/WFE should be trapped to host */
109#define REC_ENTRY_FLAG_TRAP_WFI (1UL << 2U)
110#define REC_ENTRY_FLAG_TRAP_WFE (1UL << 3U)
111
112/*
113 * RmiRecExitReason represents the reason for a REC exit.
114 * This is returned to NS hosts via RMI_REC_ENTER::run_ptr.
115 */
116#define RMI_EXIT_SYNC (0U)
117#define RMI_EXIT_IRQ (1U)
118#define RMI_EXIT_FIQ (2U)
119#define RMI_EXIT_PSCI (3U)
120#define RMI_EXIT_RIPAS_CHANGE (4U)
121#define RMI_EXIT_HOST_CALL (5U)
122#define RMI_EXIT_SERROR (6U)
123
124/* RmiRttEntryState represents the state of an RTTE */
125#define RMI_RTT_STATE_UNASSIGNED (0U)
126#define RMI_RTT_STATE_DESTROYED (1U)
127#define RMI_RTT_STATE_ASSIGNED (2U)
128#define RMI_RTT_STATE_TABLE (3U)
129#define RMI_RTT_STATE_VALID_NS (4U)
130
131/* no parameters */
132#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
133
134/*
135 * arg0 == target granule address
136 */
137#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
138
139/*
140 * arg0 == target granule address
141 */
142#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
143
144/* RmiDataMeasureContent type */
145#define RMI_NO_MEASURE_CONTENT 0
146#define RMI_MEASURE_CONTENT 1
147
148/*
149 * arg0 == data address
150 * arg1 == RD address
151 * arg2 == map address
152 * arg3 == SRC address
153 * arg4 == flags
154 */
155#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
156
157/*
158 * arg0 == data address
159 * arg1 == RD address
160 * arg2 == map address
161 */
162#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
163
164/*
165 * arg0 == RD address
166 * arg1 == map address
167 */
168#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
169
170/*
171 * arg0 == RD address
172 */
173#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
174
175/*
176 * arg0 == RD address
177 * arg1 == struct rmi_realm_params addr
178 */
179#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
180
181/*
182 * arg0 == RD address
183 */
184#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
185
186/*
187 * arg0 == REC address
188 * arg1 == RD address
189 * arg2 == struct rmm_rec address
190 */
191#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
192
193/*
194 * arg0 == REC address
195 */
196#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
197
198/*
199 * arg0 == rec address
200 * arg1 == rec_run address
201 */
202#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
203
204/*
205 * arg0 == RTT address
206 * arg1 == RD address
207 * arg2 == map address
208 * arg3 == level
209 */
210#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
211
212/*
213 * arg0 == RTT address
214 * arg1 == RD address
215 * arg2 == map address
216 * arg3 == level
217 */
218#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
219
220/*
221 * arg0 == RD address
222 * arg1 == map address
223 * arg2 == level
224 * arg3 == s2tte
225 */
226#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
227
228/*
229 * arg0 == RD address
230 * arg1 == map address
231 * arg2 == level
232 * ret1 == level
233 * ret2 == s2tte type
234 * ret3 == s2tte
235 * ret4 == ripas
236 */
237#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
238
239/*
240 * arg0 == RD address
241 * arg1 == map address
242 * arg2 == level
243 */
244#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
245
246/*
247 * arg0 == calling rec address
248 * arg1 == target rec address
249 */
250#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
251
252/*
253 * arg0 == Feature register index
254 */
255#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
256
257/*
258 * arg0 == RTT address
259 * arg1 == RD address
260 * arg2 == map address
261 * arg3 == level
262 */
263#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
264
265/*
266 * arg0 == RD address
267 */
268#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
269
270/*
271 * arg1 == RD address
272 * arg2 == map address
273 * arg3 == level
274 */
275#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
276
277/*
278 * arg0 == RD address
279 * arg1 == REC address
280 * arg2 == map address
281 * arg3 == level
282 * arg4 == ripas
283 */
284#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
285
286/* Size of Realm Personalization Value */
287#define RPV_SIZE 64
288
289/*
Soby Mathewc414f2a2023-01-17 02:50:17 +0000290 * Defines member of structure and reserves space
291 * for the next member with specified offset.
292 */
293#define SET_MEMBER_RMI SET_MEMBER
294
295/*
Soby Mathewb4c6df42022-11-09 11:13:29 +0000296 * The Realm attribute parameters are shared by the Host via
297 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
298 * either by the Host or by the Realm.
299 */
300struct rmi_realm_params {
301 /* Realm feature register 0 */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000302 SET_MEMBER_RMI(unsigned long features_0, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000303 /* Measurement algorithm */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000304 SET_MEMBER_RMI(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000305 /* Realm Personalization Value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000306 SET_MEMBER_RMI(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
307 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000308 /* Virtual Machine Identifier */
309 unsigned short vmid; /* 0x800 */
310 /* Realm Translation Table base */
311 unsigned long rtt_base; /* 0x808 */
312 /* RTT starting level */
313 long rtt_level_start; /* 0x810 */
314 /* Number of starting level RTTs */
315 unsigned int rtt_num_start; /* 0x818 */
316 }, 0x800, 0x1000);
317};
318
Soby Mathewb4c6df42022-11-09 11:13:29 +0000319/*
320 * The REC attribute parameters are shared by the Host via
321 * MI_REC_CREATE::params_ptr. The values can be observed or modified
322 * either by the Host or by the Realm which owns the REC.
323 */
324struct rmi_rec_params {
325 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000326 SET_MEMBER_RMI(unsigned long flags, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000327 /* MPIDR of the REC */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000328 SET_MEMBER_RMI(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000329 /* Program counter */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000330 SET_MEMBER_RMI(unsigned long pc, 0x200, 0x300); /* 0x200 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000331 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000332 SET_MEMBER_RMI(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
333 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000334 /* Number of auxiliary Granules */
335 unsigned long num_aux; /* 0x800 */
336 /* Addresses of auxiliary Granules */
337 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
338 }, 0x800, 0x1000);
339};
340
Soby Mathewb4c6df42022-11-09 11:13:29 +0000341/*
342 * Structure contains data passed from the Host to the RMM on REC entry
343 */
344struct rmi_rec_entry {
345 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000346 SET_MEMBER_RMI(unsigned long flags, 0, 0x200); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000347 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000348 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
349 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000350 /* GICv3 Hypervisor Control Register */
351 unsigned long gicv3_hcr; /* 0x300 */
352 /* GICv3 List Registers */
353 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
354 }, 0x300, 0x800);
355};
356
Soby Mathewb4c6df42022-11-09 11:13:29 +0000357/*
358 * Structure contains data passed from the RMM to the Host on REC exit
359 */
360struct rmi_rec_exit {
361 /* Exit reason */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000362 SET_MEMBER_RMI(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
363 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000364 /* Exception Syndrome Register */
365 unsigned long esr; /* 0x100 */
366 /* Fault Address Register */
367 unsigned long far; /* 0x108 */
368 /* Hypervisor IPA Fault Address register */
369 unsigned long hpfar; /* 0x110 */
370 }, 0x100, 0x200);
371 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000372 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
373 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000374 /* GICv3 Hypervisor Control Register */
375 unsigned long gicv3_hcr; /* 0x300 */
376 /* GICv3 List Registers */
377 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
378 /* GICv3 Maintenance Interrupt State Register */
379 unsigned long gicv3_misr; /* 0x388 */
380 /* GICv3 Virtual Machine Control Register */
381 unsigned long gicv3_vmcr; /* 0x390 */
382 }, 0x300, 0x400);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000383 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000384 /* Counter-timer Physical Timer Control Register */
385 unsigned long cntp_ctl; /* 0x400 */
386 /* Counter-timer Physical Timer CompareValue Register */
387 unsigned long cntp_cval; /* 0x408 */
388 /* Counter-timer Virtual Timer Control Register */
389 unsigned long cntv_ctl; /* 0x410 */
390 /* Counter-timer Virtual Timer CompareValue Register */
391 unsigned long cntv_cval; /* 0x418 */
392 }, 0x400, 0x500);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000393 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000394 /* Base address of pending RIPAS change */
395 unsigned long ripas_base; /* 0x500 */
396 /* Size of pending RIPAS change */
397 unsigned long ripas_size; /* 0x508 */
398 /* RIPAS value of pending RIPAS change */
399 unsigned char ripas_value; /* 0x510 */
400 }, 0x500, 0x600);
401 /* Host call immediate value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000402 SET_MEMBER_RMI(unsigned int imm, 0x600, 0x800); /* 0x600 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000403};
404
Soby Mathewb4c6df42022-11-09 11:13:29 +0000405/*
406 * Structure contains shared information between RMM and Host
407 * during REC entry and REC exit.
408 */
409struct rmi_rec_run {
410 /* Entry information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000411 SET_MEMBER_RMI(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000412 /* Exit information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000413 SET_MEMBER_RMI(struct rmi_rec_exit exit, 0x800, 0x1000); /* 0x800 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000414};
415
Soby Mathewb4c6df42022-11-09 11:13:29 +0000416#endif /* SMC_RMI_H */