blob: 00ac669192f8993157821fa133f4a12b54d6ed23 [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
42/*
43 * The number of GPRs (starting from X0) that are
44 * configured by the host when a REC is created.
45 */
46#define REC_CREATE_NR_GPRS (8U)
47
48#define REC_PARAMS_FLAG_RUNNABLE (1UL << 0U)
49
50/*
51 * The number of GPRs (starting from X0) per voluntary exit context.
52 * Per SMCCC.
53 */
54#define REC_EXIT_NR_GPRS (31U)
55
56/* RmiHashAlgorithm type */
Soby Mathew3f56a4c2023-01-17 02:35:10 +000057#define RMI_HASH_ALGO_SHA256 0
58#define RMI_HASH_ALGO_SHA512 1
Soby Mathewb4c6df42022-11-09 11:13:29 +000059
60/* Maximum number of Interrupt Controller List Registers */
61#define REC_GIC_NUM_LRS (16U)
62
63/* Maximum number of auxiliary granules required for a REC */
64#define MAX_REC_AUX_GRANULES (16U)
65
66#define REC_ENTRY_FLAG_EMUL_MMIO (1UL << 0U)
67#define REC_ENTRY_FLAG_INJECT_SEA (1UL << 1U)
68
69/* Flags to specify if WFI/WFE should be trapped to host */
70#define REC_ENTRY_FLAG_TRAP_WFI (1UL << 2U)
71#define REC_ENTRY_FLAG_TRAP_WFE (1UL << 3U)
72
73/*
74 * RmiRecExitReason represents the reason for a REC exit.
75 * This is returned to NS hosts via RMI_REC_ENTER::run_ptr.
76 */
77#define RMI_EXIT_SYNC (0U)
78#define RMI_EXIT_IRQ (1U)
79#define RMI_EXIT_FIQ (2U)
80#define RMI_EXIT_PSCI (3U)
81#define RMI_EXIT_RIPAS_CHANGE (4U)
82#define RMI_EXIT_HOST_CALL (5U)
83#define RMI_EXIT_SERROR (6U)
84
85/* RmiRttEntryState represents the state of an RTTE */
86#define RMI_RTT_STATE_UNASSIGNED (0U)
87#define RMI_RTT_STATE_DESTROYED (1U)
88#define RMI_RTT_STATE_ASSIGNED (2U)
89#define RMI_RTT_STATE_TABLE (3U)
90#define RMI_RTT_STATE_VALID_NS (4U)
91
92/* no parameters */
93#define SMC_RMM_VERSION SMC64_RMI_FID(U(0x0))
94
95/*
96 * arg0 == target granule address
97 */
98#define SMC_RMM_GRANULE_DELEGATE SMC64_RMI_FID(U(0x1))
99
100/*
101 * arg0 == target granule address
102 */
103#define SMC_RMM_GRANULE_UNDELEGATE SMC64_RMI_FID(U(0x2))
104
105/* RmiDataMeasureContent type */
106#define RMI_NO_MEASURE_CONTENT 0
107#define RMI_MEASURE_CONTENT 1
108
109/*
110 * arg0 == data address
111 * arg1 == RD address
112 * arg2 == map address
113 * arg3 == SRC address
114 * arg4 == flags
115 */
116#define SMC_RMM_DATA_CREATE SMC64_RMI_FID(U(0x3))
117
118/*
119 * arg0 == data address
120 * arg1 == RD address
121 * arg2 == map address
122 */
123#define SMC_RMM_DATA_CREATE_UNKNOWN SMC64_RMI_FID(U(0x4))
124
125/*
126 * arg0 == RD address
127 * arg1 == map address
128 */
129#define SMC_RMM_DATA_DESTROY SMC64_RMI_FID(U(0x5))
130
131/*
132 * arg0 == RD address
133 */
134#define SMC_RMM_REALM_ACTIVATE SMC64_RMI_FID(U(0x7))
135
136/*
137 * arg0 == RD address
138 * arg1 == struct rmi_realm_params addr
139 */
140#define SMC_RMM_REALM_CREATE SMC64_RMI_FID(U(0x8))
141
142/*
143 * arg0 == RD address
144 */
145#define SMC_RMM_REALM_DESTROY SMC64_RMI_FID(U(0x9))
146
147/*
148 * arg0 == REC address
149 * arg1 == RD address
150 * arg2 == struct rmm_rec address
151 */
152#define SMC_RMM_REC_CREATE SMC64_RMI_FID(U(0xA))
153
154/*
155 * arg0 == REC address
156 */
157#define SMC_RMM_REC_DESTROY SMC64_RMI_FID(U(0xB))
158
159/*
160 * arg0 == rec address
161 * arg1 == rec_run address
162 */
163#define SMC_RMM_REC_ENTER SMC64_RMI_FID(U(0xC))
164
165/*
166 * arg0 == RTT address
167 * arg1 == RD address
168 * arg2 == map address
169 * arg3 == level
170 */
171#define SMC_RMM_RTT_CREATE SMC64_RMI_FID(U(0xD))
172
173/*
174 * arg0 == RTT address
175 * arg1 == RD address
176 * arg2 == map address
177 * arg3 == level
178 */
179#define SMC_RMM_RTT_DESTROY SMC64_RMI_FID(U(0xE))
180
181/*
182 * arg0 == RD address
183 * arg1 == map address
184 * arg2 == level
185 * arg3 == s2tte
186 */
187#define SMC_RMM_RTT_MAP_UNPROTECTED SMC64_RMI_FID(U(0xF))
188
189/*
190 * arg0 == RD address
191 * arg1 == map address
192 * arg2 == level
193 * ret1 == level
194 * ret2 == s2tte type
195 * ret3 == s2tte
196 * ret4 == ripas
197 */
198#define SMC_RMM_RTT_READ_ENTRY SMC64_RMI_FID(U(0x11))
199
200/*
201 * arg0 == RD address
202 * arg1 == map address
203 * arg2 == level
204 */
205#define SMC_RMM_RTT_UNMAP_UNPROTECTED SMC64_RMI_FID(U(0x12))
206
207/*
208 * arg0 == calling rec address
209 * arg1 == target rec address
210 */
211#define SMC_RMM_PSCI_COMPLETE SMC64_RMI_FID(U(0x14))
212
213/*
214 * arg0 == Feature register index
215 */
216#define SMC_RMM_FEATURES SMC64_RMI_FID(U(0x15))
217
218/*
219 * arg0 == RTT address
220 * arg1 == RD address
221 * arg2 == map address
222 * arg3 == level
223 */
224#define SMC_RMM_RTT_FOLD SMC64_RMI_FID(U(0x16))
225
226/*
227 * arg0 == RD address
228 */
229#define SMC_RMM_REC_AUX_COUNT SMC64_RMI_FID(U(0x17))
230
231/*
232 * arg1 == RD address
233 * arg2 == map address
234 * arg3 == level
235 */
236#define SMC_RMM_RTT_INIT_RIPAS SMC64_RMI_FID(U(0x18))
237
238/*
239 * arg0 == RD address
240 * arg1 == REC address
241 * arg2 == map address
242 * arg3 == level
243 * arg4 == ripas
244 */
245#define SMC_RMM_RTT_SET_RIPAS SMC64_RMI_FID(U(0x19))
246
247/* Size of Realm Personalization Value */
248#define RPV_SIZE 64
249
250/*
251 * The Realm attribute parameters are shared by the Host via
252 * RMI_REALM_CREATE::params_ptr. The values can be observed or modified
253 * either by the Host or by the Realm.
254 */
255struct rmi_realm_params {
256 /* Realm feature register 0 */
257 SET_MEMBER(unsigned long features_0, 0, 0x100); /* Offset 0 */
258 /* Measurement algorithm */
259 SET_MEMBER(unsigned char hash_algo, 0x100, 0x400); /* 0x100 */
260 /* Realm Personalization Value */
261 SET_MEMBER(unsigned char rpv[RPV_SIZE], 0x400, 0x800); /* 0x400 */
262 SET_MEMBER(struct {
263 /* Virtual Machine Identifier */
264 unsigned short vmid; /* 0x800 */
265 /* Realm Translation Table base */
266 unsigned long rtt_base; /* 0x808 */
267 /* RTT starting level */
268 long rtt_level_start; /* 0x810 */
269 /* Number of starting level RTTs */
270 unsigned int rtt_num_start; /* 0x818 */
271 }, 0x800, 0x1000);
272};
273
Soby Mathewb4c6df42022-11-09 11:13:29 +0000274/*
275 * The REC attribute parameters are shared by the Host via
276 * MI_REC_CREATE::params_ptr. The values can be observed or modified
277 * either by the Host or by the Realm which owns the REC.
278 */
279struct rmi_rec_params {
280 /* Flags */
281 SET_MEMBER(unsigned long flags, 0, 0x100); /* Offset 0 */
282 /* MPIDR of the REC */
283 SET_MEMBER(unsigned long mpidr, 0x100, 0x200); /* 0x100 */
284 /* Program counter */
285 SET_MEMBER(unsigned long pc, 0x200, 0x300); /* 0x200 */
286 /* General-purpose registers */
287 SET_MEMBER(unsigned long gprs[REC_CREATE_NR_GPRS], 0x300, 0x800); /* 0x300 */
288 SET_MEMBER(struct {
289 /* Number of auxiliary Granules */
290 unsigned long num_aux; /* 0x800 */
291 /* Addresses of auxiliary Granules */
292 unsigned long aux[MAX_REC_AUX_GRANULES];/* 0x808 */
293 }, 0x800, 0x1000);
294};
295
Soby Mathewb4c6df42022-11-09 11:13:29 +0000296/*
297 * Structure contains data passed from the Host to the RMM on REC entry
298 */
299struct rmi_rec_entry {
300 /* Flags */
301 SET_MEMBER(unsigned long flags, 0, 0x200); /* Offset 0 */
302 /* General-purpose registers */
303 SET_MEMBER(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
304 SET_MEMBER(struct {
305 /* GICv3 Hypervisor Control Register */
306 unsigned long gicv3_hcr; /* 0x300 */
307 /* GICv3 List Registers */
308 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
309 }, 0x300, 0x800);
310};
311
Soby Mathewb4c6df42022-11-09 11:13:29 +0000312/*
313 * Structure contains data passed from the RMM to the Host on REC exit
314 */
315struct rmi_rec_exit {
316 /* Exit reason */
317 SET_MEMBER(unsigned long exit_reason, 0, 0x100);/* Offset 0 */
318 SET_MEMBER(struct {
319 /* Exception Syndrome Register */
320 unsigned long esr; /* 0x100 */
321 /* Fault Address Register */
322 unsigned long far; /* 0x108 */
323 /* Hypervisor IPA Fault Address register */
324 unsigned long hpfar; /* 0x110 */
325 }, 0x100, 0x200);
326 /* General-purpose registers */
327 SET_MEMBER(unsigned long gprs[REC_EXIT_NR_GPRS], 0x200, 0x300); /* 0x200 */
328 SET_MEMBER(struct {
329 /* GICv3 Hypervisor Control Register */
330 unsigned long gicv3_hcr; /* 0x300 */
331 /* GICv3 List Registers */
332 unsigned long gicv3_lrs[REC_GIC_NUM_LRS]; /* 0x308 */
333 /* GICv3 Maintenance Interrupt State Register */
334 unsigned long gicv3_misr; /* 0x388 */
335 /* GICv3 Virtual Machine Control Register */
336 unsigned long gicv3_vmcr; /* 0x390 */
337 }, 0x300, 0x400);
338 SET_MEMBER(struct {
339 /* Counter-timer Physical Timer Control Register */
340 unsigned long cntp_ctl; /* 0x400 */
341 /* Counter-timer Physical Timer CompareValue Register */
342 unsigned long cntp_cval; /* 0x408 */
343 /* Counter-timer Virtual Timer Control Register */
344 unsigned long cntv_ctl; /* 0x410 */
345 /* Counter-timer Virtual Timer CompareValue Register */
346 unsigned long cntv_cval; /* 0x418 */
347 }, 0x400, 0x500);
348 SET_MEMBER(struct {
349 /* Base address of pending RIPAS change */
350 unsigned long ripas_base; /* 0x500 */
351 /* Size of pending RIPAS change */
352 unsigned long ripas_size; /* 0x508 */
353 /* RIPAS value of pending RIPAS change */
354 unsigned char ripas_value; /* 0x510 */
355 }, 0x500, 0x600);
356 /* Host call immediate value */
357 SET_MEMBER(unsigned int imm, 0x600, 0x800); /* 0x600 */
358};
359
Soby Mathewb4c6df42022-11-09 11:13:29 +0000360/*
361 * Structure contains shared information between RMM and Host
362 * during REC entry and REC exit.
363 */
364struct rmi_rec_run {
365 /* Entry information */
366 SET_MEMBER(struct rmi_rec_entry entry, 0, 0x800); /* Offset 0 */
367 /* Exit information */
368 SET_MEMBER(struct rmi_rec_exit exit, 0x800, 0x1000); /* 0x800 */
369};
370
Soby Mathewb4c6df42022-11-09 11:13:29 +0000371#endif /* SMC_RMI_H */