blob: 71390236e422ddf0542e02ea08bfb40cb4e424bc [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
Shruti Gupta55d5db82025-03-03 12:56:04 +000068#define RSI_EXIT_SYNC 0U
69
AlexeiFedorovdff904b2024-08-05 17:11:18 +010070/* Size of Realm Personalization Value */
71#define RSI_RPV_SIZE 64U
72
nabkah01002e5692022-10-10 12:36:46 +010073struct rsi_realm_config {
74 /* IPA width in bits */
AlexeiFedorovdff904b2024-08-05 17:11:18 +010075 SET_MEMBER(unsigned long ipa_width, 0, 8); /* Offset 0 */
76 /* Hash algorithm */
Shruti Gupta5abab762024-11-27 04:57:53 +000077 SET_MEMBER(unsigned long algorithm, 8, 0x10); /* Offset 8 */
78 /* Number of auxiliary Planes */
79 SET_MEMBER(unsigned long num_aux_planes, 0x10, 0x200); /* Offset 0x10 */
AlexeiFedorovdff904b2024-08-05 17:11:18 +010080 /* Realm Personalization Value */
81 SET_MEMBER(unsigned char rpv[RSI_RPV_SIZE], 0x200, 0x1000); /* Offset 0x200 */
nabkah01002e5692022-10-10 12:36:46 +010082};
83
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010084#define RSI_HOST_CALL_NR_GPRS 31U
nabkah01002e5692022-10-10 12:36:46 +010085
86struct rsi_host_call {
87 SET_MEMBER(struct {
88 /* Immediate value */
89 unsigned int imm; /* Offset 0 */
90 /* Registers */
91 unsigned long gprs[RSI_HOST_CALL_NR_GPRS];
92 }, 0, 0x100);
93};
94
95/*
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010096 * arg0 == struct rsi_host_call address
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010097 * ret0 == Status / error
nabkah01002e5692022-10-10 12:36:46 +010098 */
99#define RSI_HOST_CALL SMC_RSI_FID(9U)
100
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100101/*
102 * arg0: Requested interface version
103 * ret0: Status / error
104 * ret1: Lower implemented interface revision
105 * ret2: Higher implemented interface revision
106 */
Shruti Gupta40de8ec2023-10-12 21:45:12 +0100107#define RSI_VERSION SMC_RSI_FID(0U)
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000108
nabkah01002e5692022-10-10 12:36:46 +0100109/*
110 * arg0 == struct rsi_realm_config address
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100111 * ret0 == Status / error
nabkah01002e5692022-10-10 12:36:46 +0100112 */
113#define RSI_REALM_CONFIG SMC_RSI_FID(6U)
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100114
115/*
116 * arg0 == Base IPA address of target region
117 * arg1 == Top address of target region
118 * arg2 == RIPAS value
119 * arg3 == flags
120 * ret0 == Status / error
121 * ret1 == Base of IPA region which was not modified by the command
122 * ret2 == RSI response
123 */
Shruti Guptabb772192023-10-09 16:08:28 +0100124#define RSI_IPA_STATE_SET SMC_RSI_FID(7U)
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100125
126/*
127 * arg0 == Base of target IPA region
128 * arg1 == End of target IPA region
129 * ret0 == Status / error
130 * ret1 == Top of IPA region which has the reported RIPAS value
131 * ret2 == RIPAS value
132 */
Shruti Guptabb772192023-10-09 16:08:28 +0100133#define RSI_IPA_STATE_GET SMC_RSI_FID(8U)
134
Juan Pablo Conde88ffad22024-10-11 21:22:29 -0500135/*
136 * ret0 == Status / error
137 * ret1 == Token maximum length
138 */
139#define RSI_ATTEST_TOKEN_INIT SMC_RSI_FID(4U)
140
141/*
142 * arg0 == Base of buffer to write the token to
143 * arg1 == Offset within the buffer
144 * arg2 == Size of the buffer
145 * ret0 == Status / error
146 * ret1 == Size of received token hunk
147 */
148#define RSI_ATTEST_TOKEN_CONTINUE SMC_RSI_FID(5U)
149
Shruti Guptabb772192023-10-09 16:08:28 +0100150typedef enum {
151 RSI_EMPTY = 0U,
152 RSI_RAM,
AlexeiFedorovdff904b2024-08-05 17:11:18 +0100153 RSI_DESTROYED,
154 RSI_DEV
Shruti Guptabb772192023-10-09 16:08:28 +0100155} rsi_ripas_type;
156
157typedef enum {
158 RSI_ACCEPT = 0U,
159 RSI_REJECT
160} rsi_ripas_respose_type;
161
162#define RSI_NO_CHANGE_DESTROYED 0UL
163#define RSI_CHANGE_DESTROYED 1UL
164
Shruti Gupta5abab762024-11-27 04:57:53 +0000165/*
166 * arg1 == plane index
167 * arg2 == perm index
168 *
169 * ret0 == status
170 * ret1 == perm value
171 */
172#define RSI_MEM_GET_PERM_VALUE SMC_RSI_FID(0x10U)
173
174/*
175 * arg1 == base adr
176 * arg2 == top adr
177 * arg3 == perm index
178 * arg4 == cookie
179 *
180 * ret0 == status
181 * ret1 == new_base
182 * ret2 == response
183 * ret3 == new_cookie
184 */
185#define RSI_MEM_SET_PERM_INDEX SMC_RSI_FID(0x11U)
186
187/*
188 * arg1 == plane index
189 * arg2 == perm index
190 *
191 * ret0 == status
192 */
193#define RSI_MEM_SET_PERM_VALUE SMC_RSI_FID(0x12U)
194
195#define RSI_PLANE_NR_GPRS 31U
196#define RSI_PLANE_GIC_NUM_LRS 16U
197
198/*
199 * Flags provided by the Primary Plane to the secondary ones upon
200 * plane entry.
201 */
202#define RSI_PLANE_ENTRY_FLAG_TRAP_WFI U(1UL << 0)
203#define RSI_PLANE_ENTRY_FLAG_TRAP_WFE U(1UL << 1)
204#define RSI_PLANE_ENTRY_FLAG_TRAP_HC U(1UL << 2)
205
206/* Data structure used to pass values from P0 to the RMM on Plane entry */
207struct rsi_plane_entry {
208 /* Flags */
209 SET_MEMBER(u_register_t flags, 0, 0x8); /* Offset 0 */
210 /* PC */
211 SET_MEMBER(u_register_t pc, 0x8, 0x100); /* Offset 0x8 */
212 /* General-purpose registers */
213 SET_MEMBER(u_register_t gprs[RSI_PLANE_NR_GPRS], 0x100, 0x200); /* 0x100 */
214 /* EL1 system registers */
215 SET_MEMBER(struct {
216 /* GICv3 Hypervisor Control Register */
217 u_register_t gicv3_hcr; /* 0x200 */
218 /* GICv3 List Registers */
219 u_register_t gicv3_lrs[RSI_PLANE_GIC_NUM_LRS]; /* 0x208 */
220 }, 0x200, 0x800);
221};
222
223/* Data structure used to pass values from the RMM to P0 on Plane exit */
224struct rsi_plane_exit {
225 /* Exit reason */
226 SET_MEMBER(u_register_t exit_reason, 0, 0x100);/* Offset 0 */
227 SET_MEMBER(struct {
228 /* Exception Link Register */
229 u_register_t elr; /* 0x100 */
230 /* Exception Syndrome Register */
231 u_register_t esr; /* 0x108 */
232 /* Fault Address Register */
233 u_register_t far; /* 0x108 */
234 /* Hypervisor IPA Fault Address register */
235 u_register_t hpfar; /* 0x110 */
236 }, 0x100, 0x200);
237 /* General-purpose registers */
238 SET_MEMBER(u_register_t gprs[RSI_PLANE_NR_GPRS], 0x200, 0x300); /* 0x200 */
239 SET_MEMBER(struct {
240 /* GICv3 Hypervisor Control Register */
241 u_register_t gicv3_hcr; /* 0x300 */
242 /* GICv3 List Registers */
243 u_register_t gicv3_lrs[RSI_PLANE_GIC_NUM_LRS]; /* 0x308 */
244 /* GICv3 Maintenance Interrupt State Register */
245 u_register_t gicv3_misr; /* 0x388 */
246 /* GICv3 Virtual Machine Control Register */
247 u_register_t gicv3_vmcr; /* 0x390 */
248 }, 0x300, 0x600);
249};
250
251typedef struct {
252 /* Entry information */
253 SET_MEMBER(struct rsi_plane_entry enter, 0, 0x800); /* Offset 0 */
254 /* Exit information */
255 SET_MEMBER(struct rsi_plane_exit exit, 0x800, 0x1000);/* 0x800 */
256} rsi_plane_run;
257
258/*
259 * arg1 == plane index
260 * arg2 == run pointer
261 *
262 * ret0 == status
263 */
264#define RSI_PLANE_ENTER SMC_RSI_FID(0x13U)
265
266/*
267 * arg1 == plane index
268 * arg2 == register encoding
269 *
270 * ret0 == status
271 * ret1 = register value
272 */
273#define RSI_PLANE_REG_READ SMC_RSI_FID(0x1EU)
274
Shruti Gupta41434682024-12-05 14:57:48 +0000275u_register_t rsi_plane_reg_read(u_register_t plane_index, u_register_t register_encoding,
276 u_register_t *value);
277
278u_register_t rsi_plane_reg_write(u_register_t plane_index, u_register_t register_encoding,
279 u_register_t value);
280
Shruti Gupta5abab762024-11-27 04:57:53 +0000281/*
282 * arg1 == plane index
283 * arg2 == register encoding
284 * arg3 == register value
285 *
286 * ret0 == status
287 */
288#define RSI_PLANE_REG_WRITE SMC_RSI_FID(0x1FU)
289
290/*
291 * Function to set overlay permission value for a specified
292 * (plane index, overlay permission index) tuple
293 */
294u_register_t rsi_mem_set_perm_value(u_register_t plane_index,
295 u_register_t perm_index,
296 u_register_t perm);
297
298/*
299 * Function to Get overlay permission value for a specified
300 * (plane index, overlay permission index) tuple
301 */
302u_register_t rsi_mem_get_perm_value(u_register_t plane_index,
303 u_register_t perm_index,
304 u_register_t *perm);
305
306/* Function to Set overlay permission index for a specified IPA range See RSI_MEM_SET_PERM_INDEX */
307u_register_t rsi_mem_set_perm_index(u_register_t base,
308 u_register_t top,
309 u_register_t perm_index,
310 u_register_t cookie,
311 u_register_t *new_base,
312 u_register_t *response,
313 u_register_t *new_cookie);
314
315/* Request RIPAS of a target IPA range to be changed to a specified value. */
Shruti Guptabb772192023-10-09 16:08:28 +0100316u_register_t rsi_ipa_state_set(u_register_t base,
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100317 u_register_t top,
318 rsi_ripas_type ripas,
319 u_register_t flag,
320 u_register_t *new_base,
321 rsi_ripas_respose_type *response);
Shruti Guptabb772192023-10-09 16:08:28 +0100322
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100323/* Request RIPAS of a target IPA range */
324u_register_t rsi_ipa_state_get(u_register_t base,
325 u_register_t top,
326 u_register_t *out_top,
327 rsi_ripas_type *ripas);
nabkah01002e5692022-10-10 12:36:46 +0100328
329/* This function return RSI_ABI_VERSION */
Shruti Gupta40de8ec2023-10-12 21:45:12 +0100330u_register_t rsi_get_version(u_register_t req_ver);
nabkah01002e5692022-10-10 12:36:46 +0100331
Juan Pablo Conde88ffad22024-10-11 21:22:29 -0500332/* This function will initialize the attestation context */
333u_register_t rsi_attest_token_init(u_register_t challenge_0,
334 u_register_t challenge_1,
335 u_register_t challenge_2,
336 u_register_t challenge_3,
337 u_register_t challenge_4,
338 u_register_t challenge_5,
339 u_register_t challenge_6,
340 u_register_t challenge_7,
341 u_register_t *out_token_upper_bound);
342
343/* This function will retrieve the (or part of) attestation token */
344u_register_t rsi_attest_token_continue(u_register_t buffer_addr,
345 u_register_t offset,
346 u_register_t buffer_size,
347 u_register_t *bytes_copied);
348
nabkah01002e5692022-10-10 12:36:46 +0100349/* This function call Host and request to exit Realm with proper exit code */
Shruti Gupta91105082024-11-27 05:29:55 +0000350u_register_t rsi_exit_to_host(enum host_call_cmd exit_code);
nabkah01002e5692022-10-10 12:36:46 +0100351
Shruti Gupta5abab762024-11-27 04:57:53 +0000352/* Function to get Realm configuration. See RSI_REALM_CONFIG */
353u_register_t rsi_realm_config(struct rsi_realm_config *s);
354
355/* Function to enter aux plane. See RSI_PLANE_ENTER */
356u_register_t rsi_plane_enter(u_register_t plane_index, u_register_t run);
357
nabkah01002e5692022-10-10 12:36:46 +0100358#endif /* REALM_RSI_H */