blob: e72a769c5c7e488fac909db663bdd7f30e394629 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +01002 * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
nabkah01002e5692022-10-10 12:36:46 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef REALM_RSI_H
9#define REALM_RSI_H
10
Shruti Gupta5abab762024-11-27 04:57:53 +000011#include <arch.h>
nabkah01002e5692022-10-10 12:36:46 +010012#include <stdint.h>
AlexeiFedorov2f30f102023-03-13 19:37:46 +000013#include <host_shared_data.h>
nabkah01002e5692022-10-10 12:36:46 +010014#include <tftf_lib.h>
15
16#define SMC_RSI_CALL_BASE 0xC4000190
17#define SMC_RSI_FID(_x) (SMC_RSI_CALL_BASE + (_x))
18/*
19 * This file describes the Realm Services Interface (RSI) Application Binary
20 * Interface (ABI) for SMC calls made from within the Realm to the RMM and
21 * serviced by the RMM.
22 *
23 * See doc/rmm_interface.md for more details.
24 */
25
26/*
27 * The major version number of the RSI implementation. Increase this whenever
28 * the binary format or semantics of the SMC calls change.
29 */
Shruti Gupta40de8ec2023-10-12 21:45:12 +010030#define RSI_ABI_VERSION_MAJOR 1U
nabkah01002e5692022-10-10 12:36:46 +010031
32/*
33 * The minor version number of the RSI implementation. Increase this when
34 * a bug is fixed, or a feature is added without breaking binary compatibility.
35 */
36#define RSI_ABI_VERSION_MINOR 0U
37
38#define RSI_ABI_VERSION_VAL ((RSI_ABI_VERSION_MAJOR << 16U) | \
39 RSI_ABI_VERSION_MINOR)
40
41#define RSI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> 16U)
42#define RSI_ABI_VERSION_GET_MINOR(_version) ((_version) & 0xFFFFU)
43
44
45/* RSI Status code enumeration as per Section D4.3.6 of the RMM Spec */
46typedef enum {
47 /* Command completed successfully */
48 RSI_SUCCESS = 0U,
49
50 /*
51 * The value of a command input value
52 * caused the command to fail
53 */
54 RSI_ERROR_INPUT = 1U,
55
56 /*
57 * The state of the current Realm or current REC
58 * does not match the state expected by the command
59 */
60 RSI_ERROR_STATE = 2U,
61
62 /* The operation requested by the command is not complete */
63 RSI_INCOMPLETE = 3U,
64
65 RSI_ERROR_COUNT
66} rsi_status_t;
67
AlexeiFedorovdff904b2024-08-05 17:11:18 +010068/* Size of Realm Personalization Value */
69#define RSI_RPV_SIZE 64U
70
nabkah01002e5692022-10-10 12:36:46 +010071struct rsi_realm_config {
72 /* IPA width in bits */
AlexeiFedorovdff904b2024-08-05 17:11:18 +010073 SET_MEMBER(unsigned long ipa_width, 0, 8); /* Offset 0 */
74 /* Hash algorithm */
Shruti Gupta5abab762024-11-27 04:57:53 +000075 SET_MEMBER(unsigned long algorithm, 8, 0x10); /* Offset 8 */
76 /* Number of auxiliary Planes */
77 SET_MEMBER(unsigned long num_aux_planes, 0x10, 0x200); /* Offset 0x10 */
AlexeiFedorovdff904b2024-08-05 17:11:18 +010078 /* Realm Personalization Value */
79 SET_MEMBER(unsigned char rpv[RSI_RPV_SIZE], 0x200, 0x1000); /* Offset 0x200 */
nabkah01002e5692022-10-10 12:36:46 +010080};
81
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010082#define RSI_HOST_CALL_NR_GPRS 31U
nabkah01002e5692022-10-10 12:36:46 +010083
84struct rsi_host_call {
85 SET_MEMBER(struct {
86 /* Immediate value */
87 unsigned int imm; /* Offset 0 */
88 /* Registers */
89 unsigned long gprs[RSI_HOST_CALL_NR_GPRS];
90 }, 0, 0x100);
91};
92
93/*
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010094 * arg0 == struct rsi_host_call address
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010095 * ret0 == Status / error
nabkah01002e5692022-10-10 12:36:46 +010096 */
97#define RSI_HOST_CALL SMC_RSI_FID(9U)
98
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010099/*
100 * arg0: Requested interface version
101 * ret0: Status / error
102 * ret1: Lower implemented interface revision
103 * ret2: Higher implemented interface revision
104 */
Shruti Gupta40de8ec2023-10-12 21:45:12 +0100105#define RSI_VERSION SMC_RSI_FID(0U)
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000106
nabkah01002e5692022-10-10 12:36:46 +0100107/*
108 * arg0 == struct rsi_realm_config address
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100109 * ret0 == Status / error
nabkah01002e5692022-10-10 12:36:46 +0100110 */
111#define RSI_REALM_CONFIG SMC_RSI_FID(6U)
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100112
113/*
114 * arg0 == Base IPA address of target region
115 * arg1 == Top address of target region
116 * arg2 == RIPAS value
117 * arg3 == flags
118 * ret0 == Status / error
119 * ret1 == Base of IPA region which was not modified by the command
120 * ret2 == RSI response
121 */
Shruti Guptabb772192023-10-09 16:08:28 +0100122#define RSI_IPA_STATE_SET SMC_RSI_FID(7U)
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100123
124/*
125 * arg0 == Base of target IPA region
126 * arg1 == End of target IPA region
127 * ret0 == Status / error
128 * ret1 == Top of IPA region which has the reported RIPAS value
129 * ret2 == RIPAS value
130 */
Shruti Guptabb772192023-10-09 16:08:28 +0100131#define RSI_IPA_STATE_GET SMC_RSI_FID(8U)
132
Juan Pablo Conde88ffad22024-10-11 21:22:29 -0500133/*
134 * ret0 == Status / error
135 * ret1 == Token maximum length
136 */
137#define RSI_ATTEST_TOKEN_INIT SMC_RSI_FID(4U)
138
139/*
140 * arg0 == Base of buffer to write the token to
141 * arg1 == Offset within the buffer
142 * arg2 == Size of the buffer
143 * ret0 == Status / error
144 * ret1 == Size of received token hunk
145 */
146#define RSI_ATTEST_TOKEN_CONTINUE SMC_RSI_FID(5U)
147
Shruti Guptabb772192023-10-09 16:08:28 +0100148typedef enum {
149 RSI_EMPTY = 0U,
150 RSI_RAM,
AlexeiFedorovdff904b2024-08-05 17:11:18 +0100151 RSI_DESTROYED,
152 RSI_DEV
Shruti Guptabb772192023-10-09 16:08:28 +0100153} rsi_ripas_type;
154
155typedef enum {
156 RSI_ACCEPT = 0U,
157 RSI_REJECT
158} rsi_ripas_respose_type;
159
160#define RSI_NO_CHANGE_DESTROYED 0UL
161#define RSI_CHANGE_DESTROYED 1UL
162
Shruti Gupta5abab762024-11-27 04:57:53 +0000163/*
164 * arg1 == plane index
165 * arg2 == perm index
166 *
167 * ret0 == status
168 * ret1 == perm value
169 */
170#define RSI_MEM_GET_PERM_VALUE SMC_RSI_FID(0x10U)
171
172/*
173 * arg1 == base adr
174 * arg2 == top adr
175 * arg3 == perm index
176 * arg4 == cookie
177 *
178 * ret0 == status
179 * ret1 == new_base
180 * ret2 == response
181 * ret3 == new_cookie
182 */
183#define RSI_MEM_SET_PERM_INDEX SMC_RSI_FID(0x11U)
184
185/*
186 * arg1 == plane index
187 * arg2 == perm index
188 *
189 * ret0 == status
190 */
191#define RSI_MEM_SET_PERM_VALUE SMC_RSI_FID(0x12U)
192
193#define RSI_PLANE_NR_GPRS 31U
194#define RSI_PLANE_GIC_NUM_LRS 16U
195
196/*
197 * Flags provided by the Primary Plane to the secondary ones upon
198 * plane entry.
199 */
200#define RSI_PLANE_ENTRY_FLAG_TRAP_WFI U(1UL << 0)
201#define RSI_PLANE_ENTRY_FLAG_TRAP_WFE U(1UL << 1)
202#define RSI_PLANE_ENTRY_FLAG_TRAP_HC U(1UL << 2)
203
204/* Data structure used to pass values from P0 to the RMM on Plane entry */
205struct rsi_plane_entry {
206 /* Flags */
207 SET_MEMBER(u_register_t flags, 0, 0x8); /* Offset 0 */
208 /* PC */
209 SET_MEMBER(u_register_t pc, 0x8, 0x100); /* Offset 0x8 */
210 /* General-purpose registers */
211 SET_MEMBER(u_register_t gprs[RSI_PLANE_NR_GPRS], 0x100, 0x200); /* 0x100 */
212 /* EL1 system registers */
213 SET_MEMBER(struct {
214 /* GICv3 Hypervisor Control Register */
215 u_register_t gicv3_hcr; /* 0x200 */
216 /* GICv3 List Registers */
217 u_register_t gicv3_lrs[RSI_PLANE_GIC_NUM_LRS]; /* 0x208 */
218 }, 0x200, 0x800);
219};
220
221/* Data structure used to pass values from the RMM to P0 on Plane exit */
222struct rsi_plane_exit {
223 /* Exit reason */
224 SET_MEMBER(u_register_t exit_reason, 0, 0x100);/* Offset 0 */
225 SET_MEMBER(struct {
226 /* Exception Link Register */
227 u_register_t elr; /* 0x100 */
228 /* Exception Syndrome Register */
229 u_register_t esr; /* 0x108 */
230 /* Fault Address Register */
231 u_register_t far; /* 0x108 */
232 /* Hypervisor IPA Fault Address register */
233 u_register_t hpfar; /* 0x110 */
234 }, 0x100, 0x200);
235 /* General-purpose registers */
236 SET_MEMBER(u_register_t gprs[RSI_PLANE_NR_GPRS], 0x200, 0x300); /* 0x200 */
237 SET_MEMBER(struct {
238 /* GICv3 Hypervisor Control Register */
239 u_register_t gicv3_hcr; /* 0x300 */
240 /* GICv3 List Registers */
241 u_register_t gicv3_lrs[RSI_PLANE_GIC_NUM_LRS]; /* 0x308 */
242 /* GICv3 Maintenance Interrupt State Register */
243 u_register_t gicv3_misr; /* 0x388 */
244 /* GICv3 Virtual Machine Control Register */
245 u_register_t gicv3_vmcr; /* 0x390 */
246 }, 0x300, 0x600);
247};
248
249typedef struct {
250 /* Entry information */
251 SET_MEMBER(struct rsi_plane_entry enter, 0, 0x800); /* Offset 0 */
252 /* Exit information */
253 SET_MEMBER(struct rsi_plane_exit exit, 0x800, 0x1000);/* 0x800 */
254} rsi_plane_run;
255
256/*
257 * arg1 == plane index
258 * arg2 == run pointer
259 *
260 * ret0 == status
261 */
262#define RSI_PLANE_ENTER SMC_RSI_FID(0x13U)
263
264/*
265 * arg1 == plane index
266 * arg2 == register encoding
267 *
268 * ret0 == status
269 * ret1 = register value
270 */
271#define RSI_PLANE_REG_READ SMC_RSI_FID(0x1EU)
272
273/*
274 * arg1 == plane index
275 * arg2 == register encoding
276 * arg3 == register value
277 *
278 * ret0 == status
279 */
280#define RSI_PLANE_REG_WRITE SMC_RSI_FID(0x1FU)
281
282/*
283 * Function to set overlay permission value for a specified
284 * (plane index, overlay permission index) tuple
285 */
286u_register_t rsi_mem_set_perm_value(u_register_t plane_index,
287 u_register_t perm_index,
288 u_register_t perm);
289
290/*
291 * Function to Get overlay permission value for a specified
292 * (plane index, overlay permission index) tuple
293 */
294u_register_t rsi_mem_get_perm_value(u_register_t plane_index,
295 u_register_t perm_index,
296 u_register_t *perm);
297
298/* Function to Set overlay permission index for a specified IPA range See RSI_MEM_SET_PERM_INDEX */
299u_register_t rsi_mem_set_perm_index(u_register_t base,
300 u_register_t top,
301 u_register_t perm_index,
302 u_register_t cookie,
303 u_register_t *new_base,
304 u_register_t *response,
305 u_register_t *new_cookie);
306
307/* Request RIPAS of a target IPA range to be changed to a specified value. */
Shruti Guptabb772192023-10-09 16:08:28 +0100308u_register_t rsi_ipa_state_set(u_register_t base,
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100309 u_register_t top,
310 rsi_ripas_type ripas,
311 u_register_t flag,
312 u_register_t *new_base,
313 rsi_ripas_respose_type *response);
Shruti Guptabb772192023-10-09 16:08:28 +0100314
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100315/* Request RIPAS of a target IPA range */
316u_register_t rsi_ipa_state_get(u_register_t base,
317 u_register_t top,
318 u_register_t *out_top,
319 rsi_ripas_type *ripas);
nabkah01002e5692022-10-10 12:36:46 +0100320
321/* This function return RSI_ABI_VERSION */
Shruti Gupta40de8ec2023-10-12 21:45:12 +0100322u_register_t rsi_get_version(u_register_t req_ver);
nabkah01002e5692022-10-10 12:36:46 +0100323
Juan Pablo Conde88ffad22024-10-11 21:22:29 -0500324/* This function will initialize the attestation context */
325u_register_t rsi_attest_token_init(u_register_t challenge_0,
326 u_register_t challenge_1,
327 u_register_t challenge_2,
328 u_register_t challenge_3,
329 u_register_t challenge_4,
330 u_register_t challenge_5,
331 u_register_t challenge_6,
332 u_register_t challenge_7,
333 u_register_t *out_token_upper_bound);
334
335/* This function will retrieve the (or part of) attestation token */
336u_register_t rsi_attest_token_continue(u_register_t buffer_addr,
337 u_register_t offset,
338 u_register_t buffer_size,
339 u_register_t *bytes_copied);
340
nabkah01002e5692022-10-10 12:36:46 +0100341/* This function call Host and request to exit Realm with proper exit code */
Shruti Gupta91105082024-11-27 05:29:55 +0000342u_register_t rsi_exit_to_host(enum host_call_cmd exit_code);
nabkah01002e5692022-10-10 12:36:46 +0100343
Shruti Gupta5abab762024-11-27 04:57:53 +0000344/* Function to get Realm configuration. See RSI_REALM_CONFIG */
345u_register_t rsi_realm_config(struct rsi_realm_config *s);
346
347/* Function to enter aux plane. See RSI_PLANE_ENTER */
348u_register_t rsi_plane_enter(u_register_t plane_index, u_register_t run);
349
nabkah01002e5692022-10-10 12:36:46 +0100350#endif /* REALM_RSI_H */