blob: 0cd327eab1a55ba5e580ac08e098ed922953e20f [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 */
Yousuf A3daed822022-10-13 16:06:00 +0100125#define RMI_UNASSIGNED (0U)
126#define RMI_DESTROYED (1U)
127#define RMI_ASSIGNED (2U)
128#define RMI_TABLE (3U)
129#define RMI_VALID_NS (4U)
Soby Mathewb4c6df42022-11-09 11:13:29 +0000130
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
Yousuf A62808152022-10-31 10:35:42 +0000148/* The RmmRipas enumeration representing realm IPA state */
149#define RMI_EMPTY (0)
150#define RMI_RAM (1)
151
Soby Mathewb4c6df42022-11-09 11:13:29 +0000152/* no parameters */
153#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
154
155/*
156 * arg0 == target granule address
157 */
158#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
159
160/*
161 * arg0 == target granule address
162 */
163#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
164
165/* RmiDataMeasureContent type */
166#define RMI_NO_MEASURE_CONTENT 0
167#define RMI_MEASURE_CONTENT 1
168
169/*
170 * arg0 == data address
171 * arg1 == RD address
172 * arg2 == map address
173 * arg3 == SRC address
174 * arg4 == flags
175 */
176#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
177
178/*
179 * arg0 == data address
180 * arg1 == RD address
181 * arg2 == map address
182 */
183#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
184
185/*
186 * arg0 == RD address
187 * arg1 == map address
188 */
189#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
190
191/*
192 * arg0 == RD address
193 */
194#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
195
196/*
197 * arg0 == RD address
198 * arg1 == struct rmi_realm_params addr
199 */
200#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
201
202/*
203 * arg0 == RD address
204 */
205#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
206
207/*
208 * arg0 == REC address
209 * arg1 == RD address
210 * arg2 == struct rmm_rec address
211 */
212#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
213
214/*
215 * arg0 == REC address
216 */
217#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
218
219/*
220 * arg0 == rec address
221 * arg1 == rec_run address
222 */
223#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
224
225/*
226 * arg0 == RTT address
227 * arg1 == RD address
228 * arg2 == map address
229 * arg3 == level
230 */
231#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
232
233/*
234 * arg0 == RTT address
235 * arg1 == RD address
236 * arg2 == map address
237 * arg3 == level
238 */
239#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
240
241/*
242 * arg0 == RD address
243 * arg1 == map address
244 * arg2 == level
245 * arg3 == s2tte
246 */
247#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
248
249/*
250 * arg0 == RD address
251 * arg1 == map address
252 * arg2 == level
253 * ret1 == level
254 * ret2 == s2tte type
255 * ret3 == s2tte
256 * ret4 == ripas
257 */
258#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
259
260/*
261 * arg0 == RD address
262 * arg1 == map address
263 * arg2 == level
264 */
265#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
266
267/*
268 * arg0 == calling rec address
269 * arg1 == target rec address
270 */
271#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
272
273/*
274 * arg0 == Feature register index
275 */
276#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
277
278/*
279 * arg0 == RTT address
280 * arg1 == RD address
281 * arg2 == map address
282 * arg3 == level
283 */
284#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
285
286/*
287 * arg0 == RD address
288 */
289#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
290
291/*
292 * arg1 == RD address
293 * arg2 == map address
294 * arg3 == level
295 */
296#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
297
298/*
299 * arg0 == RD address
300 * arg1 == REC address
301 * arg2 == map address
302 * arg3 == level
303 * arg4 == ripas
304 */
305#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
306
307/* Size of Realm Personalization Value */
308#define RPV_SIZE 64
309
310/*
Soby Mathewc414f2a2023-01-17 02:50:17 +0000311 * Defines member of structure and reserves space
312 * for the next member with specified offset.
313 */
314#define SET_MEMBER_RMI SET_MEMBER
315
316/*
Soby Mathewb4c6df42022-11-09 11:13:29 +0000317 * The Realm attribute parameters are shared by the Host via
318 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
319 * either by the Host or by the Realm.
320 */
321struct rmi_realm_params {
322 /* Realm feature register 0 */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000323 SET_MEMBER_RMI(unsigned long features_0, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000324 /* Measurement algorithm */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000325 SET_MEMBER_RMI(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000326 /* Realm Personalization Value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000327 SET_MEMBER_RMI(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
328 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000329 /* Virtual Machine Identifier */
330 unsigned short vmid; /* 0x800 */
331 /* Realm Translation Table base */
332 unsigned long rtt_base; /* 0x808 */
333 /* RTT starting level */
334 long rtt_level_start; /* 0x810 */
335 /* Number of starting level RTTs */
336 unsigned int rtt_num_start; /* 0x818 */
337 }, 0x800, 0x1000);
338};
339
Soby Mathewb4c6df42022-11-09 11:13:29 +0000340/*
341 * The REC attribute parameters are shared by the Host via
342 * MI_REC_CREATE::params_ptr. The values can be observed or modified
343 * either by the Host or by the Realm which owns the REC.
344 */
345struct rmi_rec_params {
346 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000347 SET_MEMBER_RMI(unsigned long flags, 0, 0x100); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000348 /* MPIDR of the REC */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000349 SET_MEMBER_RMI(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000350 /* Program counter */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000351 SET_MEMBER_RMI(unsigned long pc, 0x200, 0x300); /* 0x200 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000352 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000353 SET_MEMBER_RMI(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
354 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000355 /* Number of auxiliary Granules */
356 unsigned long num_aux; /* 0x800 */
357 /* Addresses of auxiliary Granules */
358 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
359 }, 0x800, 0x1000);
360};
361
Soby Mathewb4c6df42022-11-09 11:13:29 +0000362/*
363 * Structure contains data passed from the Host to the RMM on REC entry
364 */
365struct rmi_rec_entry {
366 /* Flags */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000367 SET_MEMBER_RMI(unsigned long flags, 0, 0x200); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000368 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000369 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
370 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000371 /* GICv3 Hypervisor Control Register */
372 unsigned long gicv3_hcr; /* 0x300 */
373 /* GICv3 List Registers */
374 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
375 }, 0x300, 0x800);
376};
377
Soby Mathewb4c6df42022-11-09 11:13:29 +0000378/*
379 * Structure contains data passed from the RMM to the Host on REC exit
380 */
381struct rmi_rec_exit {
382 /* Exit reason */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000383 SET_MEMBER_RMI(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
384 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000385 /* Exception Syndrome Register */
386 unsigned long esr; /* 0x100 */
387 /* Fault Address Register */
388 unsigned long far; /* 0x108 */
389 /* Hypervisor IPA Fault Address register */
390 unsigned long hpfar; /* 0x110 */
391 }, 0x100, 0x200);
392 /* General-purpose registers */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000393 SET_MEMBER_RMI(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
394 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000395 /* GICv3 Hypervisor Control Register */
396 unsigned long gicv3_hcr; /* 0x300 */
397 /* GICv3 List Registers */
398 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
399 /* GICv3 Maintenance Interrupt State Register */
400 unsigned long gicv3_misr; /* 0x388 */
401 /* GICv3 Virtual Machine Control Register */
402 unsigned long gicv3_vmcr; /* 0x390 */
403 }, 0x300, 0x400);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000404 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000405 /* Counter-timer Physical Timer Control Register */
406 unsigned long cntp_ctl; /* 0x400 */
407 /* Counter-timer Physical Timer CompareValue Register */
408 unsigned long cntp_cval; /* 0x408 */
409 /* Counter-timer Virtual Timer Control Register */
410 unsigned long cntv_ctl; /* 0x410 */
411 /* Counter-timer Virtual Timer CompareValue Register */
412 unsigned long cntv_cval; /* 0x418 */
413 }, 0x400, 0x500);
Soby Mathewc414f2a2023-01-17 02:50:17 +0000414 SET_MEMBER_RMI(struct {
Soby Mathewb4c6df42022-11-09 11:13:29 +0000415 /* Base address of pending RIPAS change */
416 unsigned long ripas_base; /* 0x500 */
417 /* Size of pending RIPAS change */
418 unsigned long ripas_size; /* 0x508 */
419 /* RIPAS value of pending RIPAS change */
420 unsigned char ripas_value; /* 0x510 */
421 }, 0x500, 0x600);
422 /* Host call immediate value */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000423 SET_MEMBER_RMI(unsigned int imm, 0x600, 0x800); /* 0x600 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000424};
425
Soby Mathewb4c6df42022-11-09 11:13:29 +0000426/*
427 * Structure contains shared information between RMM and Host
428 * during REC entry and REC exit.
429 */
430struct rmi_rec_run {
431 /* Entry information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000432 SET_MEMBER_RMI(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000433 /* Exit information */
Soby Mathewc414f2a2023-01-17 02:50:17 +0000434 SET_MEMBER_RMI(struct rmi_rec_exit exit, 0x800, 0x1000); /* 0x800 */
Soby Mathewb4c6df42022-11-09 11:13:29 +0000435};
436
Soby Mathewb4c6df42022-11-09 11:13:29 +0000437#endif /* SMC_RMI_H */