blob: fd87000e9b84ff9d3e5bd46f5c668402dd254a6a [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
Yousuf Aa297b9b2022-10-13 13:54:21 +0100131/* RmiFeatureRegister0 format */
132#define RMM_FEATURE_REGISTER_0_INDEX UL(0)
133
134#define RMM_FEATURE_REGISTER_0_S2SZ_SHIFT UL(0)
135#define RMM_FEATURE_REGISTER_0_S2SZ_WIDTH UL(8)
136
137#define RMM_FEATURE_REGISTER_0_LPA2_SHIFT UL(8)
138#define RMM_FEATURE_REGISTER_0_LPA2_WIDTH UL(1)
139#define RMI_NO_LPA2 UL(0)
140#define RMI_LPA2 UL(1)
141
142#define RMM_FEATURE_REGISTER_0_HASH_SHA_256_SHIFT UL(28)
143#define RMM_FEATURE_REGISTER_0_HASH_SHA_256_WIDTH UL(1)
144
145#define RMM_FEATURE_REGISTER_0_HASH_SHA_512_SHIFT UL(29)
146#define RMM_FEATURE_REGISTER_0_HASH_SHA_512_WIDTH UL(1)
147
Soby Mathewb4c6df42022-11-09 11:13:29 +0000148/* no parameters */
149#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
150
151/*
152 * arg0 == target granule address
153 */
154#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
155
156/*
157 * arg0 == target granule address
158 */
159#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
160
161/* RmiDataMeasureContent type */
162#define RMI_NO_MEASURE_CONTENT 0
163#define RMI_MEASURE_CONTENT 1
164
165/*
166 * arg0 == data address
167 * arg1 == RD address
168 * arg2 == map address
169 * arg3 == SRC address
170 * arg4 == flags
171 */
172#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
173
174/*
175 * arg0 == data address
176 * arg1 == RD address
177 * arg2 == map address
178 */
179#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
180
181/*
182 * arg0 == RD address
183 * arg1 == map address
184 */
185#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
186
187/*
188 * arg0 == RD address
189 */
190#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
191
192/*
193 * arg0 == RD address
194 * arg1 == struct rmi_realm_params addr
195 */
196#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
197
198/*
199 * arg0 == RD address
200 */
201#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
202
203/*
204 * arg0 == REC address
205 * arg1 == RD address
206 * arg2 == struct rmm_rec address
207 */
208#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
209
210/*
211 * arg0 == REC address
212 */
213#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
214
215/*
216 * arg0 == rec address
217 * arg1 == rec_run address
218 */
219#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
220
221/*
222 * arg0 == RTT address
223 * arg1 == RD address
224 * arg2 == map address
225 * arg3 == level
226 */
227#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
228
229/*
230 * arg0 == RTT address
231 * arg1 == RD address
232 * arg2 == map address
233 * arg3 == level
234 */
235#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
236
237/*
238 * arg0 == RD address
239 * arg1 == map address
240 * arg2 == level
241 * arg3 == s2tte
242 */
243#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
244
245/*
246 * arg0 == RD address
247 * arg1 == map address
248 * arg2 == level
249 * ret1 == level
250 * ret2 == s2tte type
251 * ret3 == s2tte
252 * ret4 == ripas
253 */
254#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
255
256/*
257 * arg0 == RD address
258 * arg1 == map address
259 * arg2 == level
260 */
261#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
262
263/*
264 * arg0 == calling rec address
265 * arg1 == target rec address
266 */
267#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
268
269/*
270 * arg0 == Feature register index
271 */
272#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
273
274/*
275 * arg0 == RTT address
276 * arg1 == RD address
277 * arg2 == map address
278 * arg3 == level
279 */
280#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
281
282/*
283 * arg0 == RD address
284 */
285#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
286
287/*
288 * arg1 == RD address
289 * arg2 == map address
290 * arg3 == level
291 */
292#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
293
294/*
295 * arg0 == RD address
296 * arg1 == REC address
297 * arg2 == map address
298 * arg3 == level
299 * arg4 == ripas
300 */
301#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
302
303/* Size of Realm Personalization Value */
304#define RPV_SIZE 64
305
306/*
Soby Mathewc414f2a2023-01-17 02:50:17 +0000307 * Defines member of structure and reserves space
308 * for the next member with specified offset.
309 */
310#define SET_MEMBER_RMI SET_MEMBER
311
312/*
Soby Mathewb4c6df42022-11-09 11:13:29 +0000313 * The Realm attribute parameters are shared by the Host via
314 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
315 * either by the Host or by the Realm.
316 */
317struct rmi_realm_params {
318 /* Realm feature register 0 */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000319 SET_MEMBER_RMI(unsigned long features_0, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000320 /* Measurement algorithm */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000321 SET_MEMBER_RMI(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000322 /* Realm Personalization Value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000323 SET_MEMBER_RMI(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
324 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000325 /* Virtual Machine Identifier */
326 unsigned short vmid; /* 0x800 */
327 /* Realm Translation Table base */
328 unsigned long rtt_base; /* 0x808 */
329 /* RTT starting level */
330 long rtt_level_start; /* 0x810 */
331 /* Number of starting level RTTs */
332 unsigned int rtt_num_start; /* 0x818 */
333 }, 0x800, 0x1000);
334};
335
Soby Mathewb4c6df42022-11-09 11:13:29 +0000336/*
337 * The REC attribute parameters are shared by the Host via
338 * MI_REC_CREATE::params_ptr. The values can be observed or modified
339 * either by the Host or by the Realm which owns the REC.
340 */
341struct rmi_rec_params {
342 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000343 SET_MEMBER_RMI(unsigned long flags, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000344 /* MPIDR of the REC */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000345 SET_MEMBER_RMI(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000346 /* Program counter */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000347 SET_MEMBER_RMI(unsigned long pc, 0x200, 0x300); /* 0x200 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000348 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000349 SET_MEMBER_RMI(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
350 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000351 /* Number of auxiliary Granules */
352 unsigned long num_aux; /* 0x800 */
353 /* Addresses of auxiliary Granules */
354 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
355 }, 0x800, 0x1000);
356};
357
Soby Mathewb4c6df42022-11-09 11:13:29 +0000358/*
359 * Structure contains data passed from the Host to the RMM on REC entry
360 */
361struct rmi_rec_entry {
362 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000363 SET_MEMBER_RMI(unsigned long flags, 0, 0x200); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000364 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000365 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
366 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000367 /* GICv3 Hypervisor Control Register */
368 unsigned long gicv3_hcr; /* 0x300 */
369 /* GICv3 List Registers */
370 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
371 }, 0x300, 0x800);
372};
373
Soby Mathewb4c6df42022-11-09 11:13:29 +0000374/*
375 * Structure contains data passed from the RMM to the Host on REC exit
376 */
377struct rmi_rec_exit {
378 /* Exit reason */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000379 SET_MEMBER_RMI(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
380 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000381 /* Exception Syndrome Register */
382 unsigned long esr; /* 0x100 */
383 /* Fault Address Register */
384 unsigned long far; /* 0x108 */
385 /* Hypervisor IPA Fault Address register */
386 unsigned long hpfar; /* 0x110 */
387 }, 0x100, 0x200);
388 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000389 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
390 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000391 /* GICv3 Hypervisor Control Register */
392 unsigned long gicv3_hcr; /* 0x300 */
393 /* GICv3 List Registers */
394 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
395 /* GICv3 Maintenance Interrupt State Register */
396 unsigned long gicv3_misr; /* 0x388 */
397 /* GICv3 Virtual Machine Control Register */
398 unsigned long gicv3_vmcr; /* 0x390 */
399 }, 0x300, 0x400);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000400 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000401 /* Counter-timer Physical Timer Control Register */
402 unsigned long cntp_ctl; /* 0x400 */
403 /* Counter-timer Physical Timer CompareValue Register */
404 unsigned long cntp_cval; /* 0x408 */
405 /* Counter-timer Virtual Timer Control Register */
406 unsigned long cntv_ctl; /* 0x410 */
407 /* Counter-timer Virtual Timer CompareValue Register */
408 unsigned long cntv_cval; /* 0x418 */
409 }, 0x400, 0x500);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000410 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000411 /* Base address of pending RIPAS change */
412 unsigned long ripas_base; /* 0x500 */
413 /* Size of pending RIPAS change */
414 unsigned long ripas_size; /* 0x508 */
415 /* RIPAS value of pending RIPAS change */
416 unsigned char ripas_value; /* 0x510 */
417 }, 0x500, 0x600);
418 /* Host call immediate value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000419 SET_MEMBER_RMI(unsigned int imm, 0x600, 0x800); /* 0x600 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000420};
421
Soby Mathewb4c6df42022-11-09 11:13:29 +0000422/*
423 * Structure contains shared information between RMM and Host
424 * during REC entry and REC exit.
425 */
426struct rmi_rec_run {
427 /* Entry information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000428 SET_MEMBER_RMI(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000429 /* Exit information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000430 SET_MEMBER_RMI(struct rmi_rec_exit exit, 0x800, 0x1000); /* 0x800 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000431};
432
Soby Mathewb4c6df42022-11-09 11:13:29 +0000433#endif /* SMC_RMI_H */