blob: 6c6268b94567187a5263bc1d27ce3b82ca4c2167 [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
Yousuf A62808152022-10-31 10:35:42 +0000156/* The RmmRipas enumeration representing realm IPA state */
157#define RMI_EMPTY (0)
158#define RMI_RAM (1)
159
Soby Mathewb4c6df42022-11-09 11:13:29 +0000160/* no parameters */
161#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
162
163/*
164 * arg0 == target granule address
165 */
166#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
167
168/*
169 * arg0 == target granule address
170 */
171#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
172
173/* RmiDataMeasureContent type */
174#define RMI_NO_MEASURE_CONTENT 0
175#define RMI_MEASURE_CONTENT 1
176
177/*
178 * arg0 == data address
179 * arg1 == RD address
180 * arg2 == map address
181 * arg3 == SRC address
182 * arg4 == flags
183 */
184#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
185
186/*
187 * arg0 == data address
188 * arg1 == RD address
189 * arg2 == map address
190 */
191#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
192
193/*
194 * arg0 == RD address
195 * arg1 == map address
196 */
197#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
198
199/*
200 * arg0 == RD address
201 */
202#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
203
204/*
205 * arg0 == RD address
206 * arg1 == struct rmi_realm_params addr
207 */
208#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
209
210/*
211 * arg0 == RD address
212 */
213#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
214
215/*
216 * arg0 == REC address
217 * arg1 == RD address
218 * arg2 == struct rmm_rec address
219 */
220#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
221
222/*
223 * arg0 == REC address
224 */
225#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
226
227/*
228 * arg0 == rec address
229 * arg1 == rec_run address
230 */
231#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
232
233/*
234 * arg0 == RTT address
235 * arg1 == RD address
236 * arg2 == map address
237 * arg3 == level
238 */
239#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
240
241/*
242 * arg0 == RTT address
243 * arg1 == RD address
244 * arg2 == map address
245 * arg3 == level
246 */
247#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
248
249/*
250 * arg0 == RD address
251 * arg1 == map address
252 * arg2 == level
253 * arg3 == s2tte
254 */
255#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
256
257/*
258 * arg0 == RD address
259 * arg1 == map address
260 * arg2 == level
261 * ret1 == level
262 * ret2 == s2tte type
263 * ret3 == s2tte
264 * ret4 == ripas
265 */
266#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
267
268/*
269 * arg0 == RD address
270 * arg1 == map address
271 * arg2 == level
272 */
273#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
274
275/*
276 * arg0 == calling rec address
277 * arg1 == target rec address
278 */
279#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
280
281/*
282 * arg0 == Feature register index
283 */
284#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
285
286/*
287 * arg0 == RTT address
288 * arg1 == RD address
289 * arg2 == map address
290 * arg3 == level
291 */
292#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
293
294/*
295 * arg0 == RD address
296 */
297#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
298
299/*
300 * arg1 == RD address
301 * arg2 == map address
302 * arg3 == level
303 */
304#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
305
306/*
307 * arg0 == RD address
308 * arg1 == REC address
309 * arg2 == map address
310 * arg3 == level
311 * arg4 == ripas
312 */
313#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
314
315/* Size of Realm Personalization Value */
316#define RPV_SIZE 64
317
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000318#ifndef __ASSEMBLER__
Soby Mathewb4c6df42022-11-09 11:13:29 +0000319/*
Soby Mathewc414f2a2023-01-17 02:50:17 +0000320 * Defines member of structure and reserves space
321 * for the next member with specified offset.
322 */
323#define SET_MEMBER_RMI SET_MEMBER
324
325/*
Soby Mathewb4c6df42022-11-09 11:13:29 +0000326 * The Realm attribute parameters are shared by the Host via
327 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
328 * either by the Host or by the Realm.
329 */
330struct rmi_realm_params {
331 /* Realm feature register 0 */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000332 SET_MEMBER_RMI(unsigned long features_0, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000333 /* Measurement algorithm */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000334 SET_MEMBER_RMI(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000335 /* Realm Personalization Value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000336 SET_MEMBER_RMI(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
337 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000338 /* Virtual Machine Identifier */
339 unsigned short vmid; /* 0x800 */
340 /* Realm Translation Table base */
341 unsigned long rtt_base; /* 0x808 */
342 /* RTT starting level */
343 long rtt_level_start; /* 0x810 */
344 /* Number of starting level RTTs */
345 unsigned int rtt_num_start; /* 0x818 */
346 }, 0x800, 0x1000);
347};
348
Soby Mathewb4c6df42022-11-09 11:13:29 +0000349/*
350 * The REC attribute parameters are shared by the Host via
351 * MI_REC_CREATE::params_ptr. The values can be observed or modified
352 * either by the Host or by the Realm which owns the REC.
353 */
354struct rmi_rec_params {
355 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000356 SET_MEMBER_RMI(unsigned long flags, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000357 /* MPIDR of the REC */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000358 SET_MEMBER_RMI(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000359 /* Program counter */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000360 SET_MEMBER_RMI(unsigned long pc, 0x200, 0x300); /* 0x200 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000361 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000362 SET_MEMBER_RMI(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
363 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000364 /* Number of auxiliary Granules */
365 unsigned long num_aux; /* 0x800 */
366 /* Addresses of auxiliary Granules */
367 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
368 }, 0x800, 0x1000);
369};
370
Soby Mathewb4c6df42022-11-09 11:13:29 +0000371/*
372 * Structure contains data passed from the Host to the RMM on REC entry
373 */
374struct rmi_rec_entry {
375 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000376 SET_MEMBER_RMI(unsigned long flags, 0, 0x200); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000377 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000378 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
379 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000380 /* GICv3 Hypervisor Control Register */
381 unsigned long gicv3_hcr; /* 0x300 */
382 /* GICv3 List Registers */
383 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
384 }, 0x300, 0x800);
385};
386
Soby Mathewb4c6df42022-11-09 11:13:29 +0000387/*
388 * Structure contains data passed from the RMM to the Host on REC exit
389 */
390struct rmi_rec_exit {
391 /* Exit reason */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000392 SET_MEMBER_RMI(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
393 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000394 /* Exception Syndrome Register */
395 unsigned long esr; /* 0x100 */
396 /* Fault Address Register */
397 unsigned long far; /* 0x108 */
398 /* Hypervisor IPA Fault Address register */
399 unsigned long hpfar; /* 0x110 */
400 }, 0x100, 0x200);
401 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000402 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
403 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000404 /* GICv3 Hypervisor Control Register */
405 unsigned long gicv3_hcr; /* 0x300 */
406 /* GICv3 List Registers */
407 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
408 /* GICv3 Maintenance Interrupt State Register */
409 unsigned long gicv3_misr; /* 0x388 */
410 /* GICv3 Virtual Machine Control Register */
411 unsigned long gicv3_vmcr; /* 0x390 */
412 }, 0x300, 0x400);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000413 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000414 /* Counter-timer Physical Timer Control Register */
415 unsigned long cntp_ctl; /* 0x400 */
416 /* Counter-timer Physical Timer CompareValue Register */
417 unsigned long cntp_cval; /* 0x408 */
418 /* Counter-timer Virtual Timer Control Register */
419 unsigned long cntv_ctl; /* 0x410 */
420 /* Counter-timer Virtual Timer CompareValue Register */
421 unsigned long cntv_cval; /* 0x418 */
422 }, 0x400, 0x500);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000423 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000424 /* Base address of pending RIPAS change */
425 unsigned long ripas_base; /* 0x500 */
426 /* Size of pending RIPAS change */
427 unsigned long ripas_size; /* 0x508 */
428 /* RIPAS value of pending RIPAS change */
429 unsigned char ripas_value; /* 0x510 */
430 }, 0x500, 0x600);
431 /* Host call immediate value */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000432 SET_MEMBER_RMI(unsigned int imm, 0x600, 0x700); /* 0x600 */
433
434 /* PMU overflow */
435 SET_MEMBER_RMI(unsigned long pmu_ovf, 0x700, 0x708); /* 0x700 */
436
437 /* PMU interrupt enable */
438 SET_MEMBER_RMI(unsigned long pmu_intr_en, 0x708, 0x710); /* 0x708 */
439
440 /* PMU counter enable */
441 SET_MEMBER_RMI(unsigned long pmu_cntr_en, 0x710, 0x800); /* 0x710 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000442};
443
Soby Mathewb4c6df42022-11-09 11:13:29 +0000444/*
445 * Structure contains shared information between RMM and Host
446 * during REC entry and REC exit.
447 */
448struct rmi_rec_run {
449 /* Entry information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000450 SET_MEMBER_RMI(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000451 /* Exit information */
AlexeiFedoroveaec0c42023-02-01 18:13:32 +0000452 SET_MEMBER_RMI(struct rmi_rec_exit exit, 0x800, 0x1000);/* 0x800 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000453};
454
Soby Mathewc9b6ecd2023-01-17 03:40:44 +0000455#endif /* __ASSEMBLER__ */
456
Soby Mathewb4c6df42022-11-09 11:13:29 +0000457#endif /* SMC_RMI_H */