blob: 5442f68da318ba736ffa45bfa2a4303c26270ff4 [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.
Soby Mathewb4c6df42022-11-09 11:13:29 +000016 */
17
18/*
19 * The major version number of the RMI implementation. Increase this whenever
20 * the binary format or semantics of the SMC calls change.
21 */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000022#define RMI_ABI_VERSION_MAJOR U(56)
Soby Mathewb4c6df42022-11-09 11:13:29 +000023
24/*
25 * The minor version number of the RMI implementation. Increase this when
26 * a bug is fixed, or a feature is added without breaking binary compatibility.
27 */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000028#define RMI_ABI_VERSION_MINOR U(0)
Soby Mathewb4c6df42022-11-09 11:13:29 +000029
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000030#define RMI_ABI_VERSION ((RMI_ABI_VERSION_MAJOR << U(16)) | \
Soby Mathewb4c6df42022-11-09 11:13:29 +000031 RMI_ABI_VERSION_MINOR)
32
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000033#define RMI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> U(16))
34#define RMI_ABI_VERSION_GET_MINOR(_version) ((_version) & U(0xFFFF))
Soby Mathewb4c6df42022-11-09 11:13:29 +000035
36#define SMC64_RMI_FID(_offset) SMC64_STD_FID(RMI, _offset)
37
38#define IS_SMC64_RMI_FID(_fid) IS_SMC64_STD_FAST_IN_RANGE(RMI, _fid)
39
Yousuf A0ec040d2022-10-31 12:30:57 +000040/* Command completed successfully. index is zero. */
41#define RMI_SUCCESS U(0)
42
43/*
44 * The value of a command input value caused the command to fail.
45 * Index is zero.
46 */
47#define RMI_ERROR_INPUT U(1)
48
49/*
50 * An attribute of a Realm does not match the expected value.
51 * index varies between usages.
52 */
53#define RMI_ERROR_REALM U(2)
54
55/*
56 * An attribute of a REC does not match the expected value.
57 * Index is zero.
58 */
59#define RMI_ERROR_REC U(3)
60
61/*
62 * An RTT walk terminated before reaching the target RTT level, or reached
63 * an RTTE with an unexpected value. index: RTT level at which the walk
64 * terminated
65 */
66#define RMI_ERROR_RTT U(4)
67
68/*
69 * An operation cannot be completed because a resource is in use.
70 * Index is zero.
71 */
72#define RMI_ERROR_IN_USE U(5)
73
74/*
75 * Number of RMI Status Errors.
76 */
77#define RMI_ERROR_COUNT U(6)
78
Soby Mathewb4c6df42022-11-09 11:13:29 +000079/*
80 * The number of GPRs (starting from X0) that are
81 * configured by the host when a REC is created.
82 */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000083#define REC_CREATE_NR_GPRS U(8)
Soby Mathewb4c6df42022-11-09 11:13:29 +000084
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000085#define REC_PARAMS_FLAG_RUNNABLE (UL(1) << 0)
Soby Mathewb4c6df42022-11-09 11:13:29 +000086
87/*
88 * The number of GPRs (starting from X0) per voluntary exit context.
89 * Per SMCCC.
90 */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000091#define REC_EXIT_NR_GPRS U(31)
Soby Mathewb4c6df42022-11-09 11:13:29 +000092
93/* RmiHashAlgorithm type */
Soby Mathew3f56a4c2023-01-17 02:35:10 +000094#define RMI_HASH_ALGO_SHA256 0
95#define RMI_HASH_ALGO_SHA512 1
Soby Mathewb4c6df42022-11-09 11:13:29 +000096
97/* Maximum number of Interrupt Controller List Registers */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +000098#define REC_GIC_NUM_LRS U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +000099
100/* Maximum number of auxiliary granules required for a REC */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000101#define MAX_REC_AUX_GRANULES U(16)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000102
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000103#define REC_ENTRY_FLAG_EMUL_MMIO (UL(1) << 0)
104#define REC_ENTRY_FLAG_INJECT_SEA (UL(1) << 1)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000105
106/* Flags to specify if WFI/WFE should be trapped to host */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000107#define REC_ENTRY_FLAG_TRAP_WFI (UL(1) << 2)
108#define REC_ENTRY_FLAG_TRAP_WFE (UL(1) << 3)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000109
110/*
111 * RmiRecExitReason represents the reason for a REC exit.
112 * This is returned to NS hosts via RMI_REC_ENTER::run_ptr.
113 */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000114#define RMI_EXIT_SYNC U(0)
115#define RMI_EXIT_IRQ U(1)
116#define RMI_EXIT_FIQ U(2)
117#define RMI_EXIT_PSCI U(3)
118#define RMI_EXIT_RIPAS_CHANGE U(4)
119#define RMI_EXIT_HOST_CALL U(5)
120#define RMI_EXIT_SERROR U(6)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000121
122/* RmiRttEntryState represents the state of an RTTE */
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000123#define RMI_UNASSIGNED U(0)
124#define RMI_DESTROYED U(1)
125#define RMI_ASSIGNED U(2)
126#define RMI_TABLE U(3)
127#define RMI_VALID_NS U(4)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000128
Yousuf Aa297b9b2022-10-13 13:54:21 +0100129/* RmiFeatureRegister0 format */
130#define RMM_FEATURE_REGISTER_0_INDEX UL(0)
131
132#define RMM_FEATURE_REGISTER_0_S2SZ_SHIFT UL(0)
133#define RMM_FEATURE_REGISTER_0_S2SZ_WIDTH UL(8)
134
135#define RMM_FEATURE_REGISTER_0_LPA2_SHIFT UL(8)
136#define RMM_FEATURE_REGISTER_0_LPA2_WIDTH UL(1)
137#define RMI_NO_LPA2 UL(0)
138#define RMI_LPA2 UL(1)
139
140#define RMM_FEATURE_REGISTER_0_HASH_SHA_256_SHIFT UL(28)
141#define RMM_FEATURE_REGISTER_0_HASH_SHA_256_WIDTH UL(1)
142
143#define RMM_FEATURE_REGISTER_0_HASH_SHA_512_SHIFT UL(29)
144#define RMM_FEATURE_REGISTER_0_HASH_SHA_512_WIDTH UL(1)
145
Yousuf A62808152022-10-31 10:35:42 +0000146/* The RmmRipas enumeration representing realm IPA state */
147#define RMI_EMPTY (0)
148#define RMI_RAM (1)
149
Soby Mathewb4c6df42022-11-09 11:13:29 +0000150/* no parameters */
151#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
152
153/*
154 * arg0 == target granule address
155 */
156#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
157
158/*
159 * arg0 == target granule address
160 */
161#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
162
163/* RmiDataMeasureContent type */
164#define RMI_NO_MEASURE_CONTENT 0
165#define RMI_MEASURE_CONTENT 1
166
167/*
168 * arg0 == data address
169 * arg1 == RD address
170 * arg2 == map address
171 * arg3 == SRC address
172 * arg4 == flags
173 */
174#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
175
176/*
177 * arg0 == data address
178 * arg1 == RD address
179 * arg2 == map address
180 */
181#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
182
183/*
184 * arg0 == RD address
185 * arg1 == map address
186 */
187#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
188
189/*
190 * arg0 == RD address
191 */
192#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
193
194/*
195 * arg0 == RD address
196 * arg1 == struct rmi_realm_params addr
197 */
198#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
199
200/*
201 * arg0 == RD address
202 */
203#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
204
205/*
206 * arg0 == REC address
207 * arg1 == RD address
208 * arg2 == struct rmm_rec address
209 */
210#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
211
212/*
213 * arg0 == REC address
214 */
215#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
216
217/*
218 * arg0 == rec address
219 * arg1 == rec_run address
220 */
221#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
222
223/*
224 * arg0 == RTT address
225 * arg1 == RD address
226 * arg2 == map address
227 * arg3 == level
228 */
229#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
230
231/*
232 * arg0 == RTT address
233 * arg1 == RD address
234 * arg2 == map address
235 * arg3 == level
236 */
237#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
238
239/*
240 * arg0 == RD address
241 * arg1 == map address
242 * arg2 == level
243 * arg3 == s2tte
244 */
245#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
246
247/*
248 * arg0 == RD address
249 * arg1 == map address
250 * arg2 == level
251 * ret1 == level
252 * ret2 == s2tte type
253 * ret3 == s2tte
254 * ret4 == ripas
255 */
256#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
257
258/*
259 * arg0 == RD address
260 * arg1 == map address
261 * arg2 == level
262 */
263#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
264
265/*
266 * arg0 == calling rec address
267 * arg1 == target rec address
268 */
269#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
270
271/*
272 * arg0 == Feature register index
273 */
274#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
275
276/*
277 * arg0 == RTT address
278 * arg1 == RD address
279 * arg2 == map address
280 * arg3 == level
281 */
282#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
283
284/*
285 * arg0 == RD address
286 */
287#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
288
289/*
290 * arg1 == RD address
291 * arg2 == map address
292 * arg3 == level
293 */
294#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
295
296/*
297 * arg0 == RD address
298 * arg1 == REC address
299 * arg2 == map address
300 * arg3 == level
301 * arg4 == ripas
302 */
303#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
304
305/* Size of Realm Personalization Value */
306#define RPV_SIZE 64
307
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000308#ifndef __ASSEMBLER__
Soby Mathewb4c6df42022-11-09 11:13:29 +0000309/*
Soby Mathewc414f2a2023-01-17 02:50:17 +0000310 * Defines member of structure and reserves space
311 * for the next member with specified offset.
312 */
313#define SET_MEMBER_RMI SET_MEMBER
314
315/*
Soby Mathewb4c6df42022-11-09 11:13:29 +0000316 * The Realm attribute parameters are shared by the Host via
317 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
318 * either by the Host or by the Realm.
319 */
320struct rmi_realm_params {
321 /* Realm feature register 0 */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000322 SET_MEMBER_RMI(unsigned long features_0, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000323 /* Measurement algorithm */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000324 SET_MEMBER_RMI(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000325 /* Realm Personalization Value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000326 SET_MEMBER_RMI(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
327 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000328 /* Virtual Machine Identifier */
329 unsigned short vmid; /* 0x800 */
330 /* Realm Translation Table base */
331 unsigned long rtt_base; /* 0x808 */
332 /* RTT starting level */
333 long rtt_level_start; /* 0x810 */
334 /* Number of starting level RTTs */
335 unsigned int rtt_num_start; /* 0x818 */
336 }, 0x800, 0x1000);
337};
338
Soby Mathewb4c6df42022-11-09 11:13:29 +0000339/*
340 * The REC attribute parameters are shared by the Host via
341 * MI_REC_CREATE::params_ptr. The values can be observed or modified
342 * either by the Host or by the Realm which owns the REC.
343 */
344struct rmi_rec_params {
345 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000346 SET_MEMBER_RMI(unsigned long flags, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000347 /* MPIDR of the REC */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000348 SET_MEMBER_RMI(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000349 /* Program counter */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000350 SET_MEMBER_RMI(unsigned long pc, 0x200, 0x300); /* 0x200 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000351 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000352 SET_MEMBER_RMI(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
353 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000354 /* Number of auxiliary Granules */
355 unsigned long num_aux; /* 0x800 */
356 /* Addresses of auxiliary Granules */
357 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
358 }, 0x800, 0x1000);
359};
360
Soby Mathewb4c6df42022-11-09 11:13:29 +0000361/*
362 * Structure contains data passed from the Host to the RMM on REC entry
363 */
364struct rmi_rec_entry {
365 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000366 SET_MEMBER_RMI(unsigned long flags, 0, 0x200); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000367 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000368 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
369 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000370 /* GICv3 Hypervisor Control Register */
371 unsigned long gicv3_hcr; /* 0x300 */
372 /* GICv3 List Registers */
373 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
374 }, 0x300, 0x800);
375};
376
Soby Mathewb4c6df42022-11-09 11:13:29 +0000377/*
378 * Structure contains data passed from the RMM to the Host on REC exit
379 */
380struct rmi_rec_exit {
381 /* Exit reason */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000382 SET_MEMBER_RMI(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
383 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000384 /* Exception Syndrome Register */
385 unsigned long esr; /* 0x100 */
386 /* Fault Address Register */
387 unsigned long far; /* 0x108 */
388 /* Hypervisor IPA Fault Address register */
389 unsigned long hpfar; /* 0x110 */
390 }, 0x100, 0x200);
391 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000392 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
393 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000394 /* GICv3 Hypervisor Control Register */
395 unsigned long gicv3_hcr; /* 0x300 */
396 /* GICv3 List Registers */
397 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
398 /* GICv3 Maintenance Interrupt State Register */
399 unsigned long gicv3_misr; /* 0x388 */
400 /* GICv3 Virtual Machine Control Register */
401 unsigned long gicv3_vmcr; /* 0x390 */
402 }, 0x300, 0x400);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000403 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000404 /* Counter-timer Physical Timer Control Register */
405 unsigned long cntp_ctl; /* 0x400 */
406 /* Counter-timer Physical Timer CompareValue Register */
407 unsigned long cntp_cval; /* 0x408 */
408 /* Counter-timer Virtual Timer Control Register */
409 unsigned long cntv_ctl; /* 0x410 */
410 /* Counter-timer Virtual Timer CompareValue Register */
411 unsigned long cntv_cval; /* 0x418 */
412 }, 0x400, 0x500);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000413 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000414 /* Base address of pending RIPAS change */
415 unsigned long ripas_base; /* 0x500 */
416 /* Size of pending RIPAS change */
417 unsigned long ripas_size; /* 0x508 */
418 /* RIPAS value of pending RIPAS change */
419 unsigned char ripas_value; /* 0x510 */
420 }, 0x500, 0x600);
421 /* Host call immediate value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000422 SET_MEMBER_RMI(unsigned int imm, 0x600, 0x800); /* 0x600 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000423};
424
Soby Mathewb4c6df42022-11-09 11:13:29 +0000425/*
426 * Structure contains shared information between RMM and Host
427 * during REC entry and REC exit.
428 */
429struct rmi_rec_run {
430 /* Entry information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000431 SET_MEMBER_RMI(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000432 /* Exit information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000433 SET_MEMBER_RMI(struct rmi_rec_exit exit, 0x800, 0x1000); /* 0x800 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000434};
435
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000436#endif /* __ASSEMBLER__ */
437
Soby Mathewb4c6df42022-11-09 11:13:29 +0000438#endif /* SMC_RMI_H */