blob: f2155785506827628c3d5a6cb287a37e9df5e668 [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
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000129/* RmiFeature enumerations */
130#define RMI_NOT_SUPPORTED UL(0)
131#define RMI_SUPPORTED UL(1)
132
Yousuf Aa297b9b2022-10-13 13:54:21 +0100133/* RmiFeatureRegister0 format */
134#define RMM_FEATURE_REGISTER_0_INDEX UL(0)
135
136#define RMM_FEATURE_REGISTER_0_S2SZ_SHIFT UL(0)
137#define RMM_FEATURE_REGISTER_0_S2SZ_WIDTH UL(8)
138
139#define RMM_FEATURE_REGISTER_0_LPA2_SHIFT UL(8)
140#define RMM_FEATURE_REGISTER_0_LPA2_WIDTH UL(1)
141#define RMI_NO_LPA2 UL(0)
142#define RMI_LPA2 UL(1)
143
144#define RMM_FEATURE_REGISTER_0_HASH_SHA_256_SHIFT UL(28)
145#define RMM_FEATURE_REGISTER_0_HASH_SHA_256_WIDTH UL(1)
146
147#define RMM_FEATURE_REGISTER_0_HASH_SHA_512_SHIFT UL(29)
148#define RMM_FEATURE_REGISTER_0_HASH_SHA_512_WIDTH UL(1)
149
AlexeiFedorov7bb7a702023-01-17 17:04:14 +0000150#define RMM_FEATURE_REGISTER_0_PMU_EN_SHIFT UL(22)
151#define RMM_FEATURE_REGISTER_0_PMU_EN_WIDTH UL(1)
152
153#define RMM_FEATURE_REGISTER_0_PMU_NUM_CTRS_SHIFT UL(23)
154#define RMM_FEATURE_REGISTER_0_PMU_NUM_CTRS_WIDTH UL(5)
155
Arunachalam Ganapathyf6491212023-02-23 16:04:34 +0000156#define RMM_FEATURE_REGISTER_0_SVE_EN_SHIFT UL(9)
157#define RMM_FEATURE_REGISTER_0_SVE_EN_WIDTH UL(1)
158#define RMM_FEATURE_REGISTER_0_SVE_VL_SHIFT UL(10)
159#define RMM_FEATURE_REGISTER_0_SVE_VL_WIDTH UL(4)
160
Yousuf A62808152022-10-31 10:35:42 +0000161/* The RmmRipas enumeration representing realm IPA state */
162#define RMI_EMPTY (0)
163#define RMI_RAM (1)
164
Soby Mathewb4c6df42022-11-09 11:13:29 +0000165/* no parameters */
166#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
167
168/*
169 * arg0 == target granule address
170 */
171#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
172
173/*
174 * arg0 == target granule address
175 */
176#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
177
178/* RmiDataMeasureContent type */
179#define RMI_NO_MEASURE_CONTENT 0
180#define RMI_MEASURE_CONTENT 1
181
182/*
183 * arg0 == data address
184 * arg1 == RD address
185 * arg2 == map address
186 * arg3 == SRC address
187 * arg4 == flags
188 */
189#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
190
191/*
192 * arg0 == data address
193 * arg1 == RD address
194 * arg2 == map address
195 */
196#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
197
198/*
199 * arg0 == RD address
200 * arg1 == map address
201 */
202#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
203
204/*
205 * arg0 == RD address
206 */
207#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
208
209/*
210 * arg0 == RD address
211 * arg1 == struct rmi_realm_params addr
212 */
213#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
214
215/*
216 * arg0 == RD address
217 */
218#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
219
220/*
221 * arg0 == REC address
222 * arg1 == RD address
223 * arg2 == struct rmm_rec address
224 */
225#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
226
227/*
228 * arg0 == REC address
229 */
230#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
231
232/*
233 * arg0 == rec address
234 * arg1 == rec_run address
235 */
236#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
237
238/*
239 * arg0 == RTT address
240 * arg1 == RD address
241 * arg2 == map address
242 * arg3 == level
243 */
244#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
245
246/*
247 * arg0 == RTT address
248 * arg1 == RD address
249 * arg2 == map address
250 * arg3 == level
251 */
252#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
253
254/*
255 * arg0 == RD address
256 * arg1 == map address
257 * arg2 == level
258 * arg3 == s2tte
259 */
260#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
261
262/*
263 * arg0 == RD address
264 * arg1 == map address
265 * arg2 == level
266 * ret1 == level
267 * ret2 == s2tte type
268 * ret3 == s2tte
269 * ret4 == ripas
270 */
271#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
272
273/*
274 * arg0 == RD address
275 * arg1 == map address
276 * arg2 == level
277 */
278#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
279
280/*
281 * arg0 == calling rec address
282 * arg1 == target rec address
283 */
284#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
285
286/*
287 * arg0 == Feature register index
288 */
289#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
290
291/*
292 * arg0 == RTT address
293 * arg1 == RD address
294 * arg2 == map address
295 * arg3 == level
296 */
297#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
298
299/*
300 * arg0 == RD address
301 */
302#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
303
304/*
305 * arg1 == RD address
306 * arg2 == map address
307 * arg3 == level
308 */
309#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
310
311/*
312 * arg0 == RD address
313 * arg1 == REC address
314 * arg2 == map address
315 * arg3 == level
316 * arg4 == ripas
317 */
318#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
319
320/* Size of Realm Personalization Value */
321#define RPV_SIZE 64
322
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000323#ifndef __ASSEMBLER__
Soby Mathewb4c6df42022-11-09 11:13:29 +0000324/*
Soby Mathewc414f2a2023-01-17 02:50:17 +0000325 * Defines member of structure and reserves space
326 * for the next member with specified offset.
327 */
328#define SET_MEMBER_RMI SET_MEMBER
329
330/*
Soby Mathewb4c6df42022-11-09 11:13:29 +0000331 * The Realm attribute parameters are shared by the Host via
332 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
333 * either by the Host or by the Realm.
334 */
335struct rmi_realm_params {
336 /* Realm feature register 0 */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000337 SET_MEMBER_RMI(unsigned long features_0, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000338 /* Measurement algorithm */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000339 SET_MEMBER_RMI(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000340 /* Realm Personalization Value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000341 SET_MEMBER_RMI(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
342 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000343 /* Virtual Machine Identifier */
344 unsigned short vmid; /* 0x800 */
345 /* Realm Translation Table base */
346 unsigned long rtt_base; /* 0x808 */
347 /* RTT starting level */
348 long rtt_level_start; /* 0x810 */
349 /* Number of starting level RTTs */
350 unsigned int rtt_num_start; /* 0x818 */
351 }, 0x800, 0x1000);
352};
353
Soby Mathewb4c6df42022-11-09 11:13:29 +0000354/*
355 * The REC attribute parameters are shared by the Host via
356 * MI_REC_CREATE::params_ptr. The values can be observed or modified
357 * either by the Host or by the Realm which owns the REC.
358 */
359struct rmi_rec_params {
360 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000361 SET_MEMBER_RMI(unsigned long flags, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000362 /* MPIDR of the REC */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000363 SET_MEMBER_RMI(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000364 /* Program counter */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000365 SET_MEMBER_RMI(unsigned long pc, 0x200, 0x300); /* 0x200 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000366 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000367 SET_MEMBER_RMI(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
368 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000369 /* Number of auxiliary Granules */
370 unsigned long num_aux; /* 0x800 */
371 /* Addresses of auxiliary Granules */
372 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
373 }, 0x800, 0x1000);
374};
375
Soby Mathewb4c6df42022-11-09 11:13:29 +0000376/*
377 * Structure contains data passed from the Host to the RMM on REC entry
378 */
379struct rmi_rec_entry {
380 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000381 SET_MEMBER_RMI(unsigned long flags, 0, 0x200); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000382 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000383 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
384 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000385 /* GICv3 Hypervisor Control Register */
386 unsigned long gicv3_hcr; /* 0x300 */
387 /* GICv3 List Registers */
388 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
389 }, 0x300, 0x800);
390};
391
Soby Mathewb4c6df42022-11-09 11:13:29 +0000392/*
393 * Structure contains data passed from the RMM to the Host on REC exit
394 */
395struct rmi_rec_exit {
396 /* Exit reason */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000397 SET_MEMBER_RMI(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
398 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000399 /* Exception Syndrome Register */
400 unsigned long esr; /* 0x100 */
401 /* Fault Address Register */
402 unsigned long far; /* 0x108 */
403 /* Hypervisor IPA Fault Address register */
404 unsigned long hpfar; /* 0x110 */
405 }, 0x100, 0x200);
406 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000407 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
408 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000409 /* GICv3 Hypervisor Control Register */
410 unsigned long gicv3_hcr; /* 0x300 */
411 /* GICv3 List Registers */
412 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
413 /* GICv3 Maintenance Interrupt State Register */
414 unsigned long gicv3_misr; /* 0x388 */
415 /* GICv3 Virtual Machine Control Register */
416 unsigned long gicv3_vmcr; /* 0x390 */
417 }, 0x300, 0x400);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000418 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000419 /* Counter-timer Physical Timer Control Register */
420 unsigned long cntp_ctl; /* 0x400 */
421 /* Counter-timer Physical Timer CompareValue Register */
422 unsigned long cntp_cval; /* 0x408 */
423 /* Counter-timer Virtual Timer Control Register */
424 unsigned long cntv_ctl; /* 0x410 */
425 /* Counter-timer Virtual Timer CompareValue Register */
426 unsigned long cntv_cval; /* 0x418 */
427 }, 0x400, 0x500);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000428 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000429 /* Base address of pending RIPAS change */
430 unsigned long ripas_base; /* 0x500 */
431 /* Size of pending RIPAS change */
432 unsigned long ripas_size; /* 0x508 */
433 /* RIPAS value of pending RIPAS change */
434 unsigned char ripas_value; /* 0x510 */
435 }, 0x500, 0x600);
436 /* Host call immediate value */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000437 SET_MEMBER_RMI(unsigned int imm, 0x600, 0x700); /* 0x600 */
438
439 /* PMU overflow */
440 SET_MEMBER_RMI(unsigned long pmu_ovf, 0x700, 0x708); /* 0x700 */
441
442 /* PMU interrupt enable */
443 SET_MEMBER_RMI(unsigned long pmu_intr_en, 0x708, 0x710); /* 0x708 */
444
445 /* PMU counter enable */
446 SET_MEMBER_RMI(unsigned long pmu_cntr_en, 0x710, 0x800); /* 0x710 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000447};
448
Soby Mathewb4c6df42022-11-09 11:13:29 +0000449/*
450 * Structure contains shared information between RMM and Host
451 * during REC entry and REC exit.
452 */
453struct rmi_rec_run {
454 /* Entry information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000455 SET_MEMBER_RMI(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000456 /* Exit information */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000457 SET_MEMBER_RMI(struct rmi_rec_exit exit, 0x800, 0x1000);/* 0x800 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000458};
459
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000460#endif /* __ASSEMBLER__ */
461
Soby Mathewb4c6df42022-11-09 11:13:29 +0000462#endif /* SMC_RMI_H */