blob: 92a078b5fc51eded740190f8bbb70ed1fbcfa706 [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
11#include <stdint.h>
AlexeiFedorov2f30f102023-03-13 19:37:46 +000012#include <host_shared_data.h>
nabkah01002e5692022-10-10 12:36:46 +010013#include <tftf_lib.h>
14
15#define SMC_RSI_CALL_BASE 0xC4000190
16#define SMC_RSI_FID(_x) (SMC_RSI_CALL_BASE + (_x))
17/*
18 * This file describes the Realm Services Interface (RSI) Application Binary
19 * Interface (ABI) for SMC calls made from within the Realm to the RMM and
20 * serviced by the RMM.
21 *
22 * See doc/rmm_interface.md for more details.
23 */
24
25/*
26 * The major version number of the RSI implementation. Increase this whenever
27 * the binary format or semantics of the SMC calls change.
28 */
Shruti Gupta40de8ec2023-10-12 21:45:12 +010029#define RSI_ABI_VERSION_MAJOR 1U
nabkah01002e5692022-10-10 12:36:46 +010030
31/*
32 * The minor version number of the RSI implementation. Increase this when
33 * a bug is fixed, or a feature is added without breaking binary compatibility.
34 */
35#define RSI_ABI_VERSION_MINOR 0U
36
37#define RSI_ABI_VERSION_VAL ((RSI_ABI_VERSION_MAJOR << 16U) | \
38 RSI_ABI_VERSION_MINOR)
39
40#define RSI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> 16U)
41#define RSI_ABI_VERSION_GET_MINOR(_version) ((_version) & 0xFFFFU)
42
43
44/* RSI Status code enumeration as per Section D4.3.6 of the RMM Spec */
45typedef enum {
46 /* Command completed successfully */
47 RSI_SUCCESS = 0U,
48
49 /*
50 * The value of a command input value
51 * caused the command to fail
52 */
53 RSI_ERROR_INPUT = 1U,
54
55 /*
56 * The state of the current Realm or current REC
57 * does not match the state expected by the command
58 */
59 RSI_ERROR_STATE = 2U,
60
61 /* The operation requested by the command is not complete */
62 RSI_INCOMPLETE = 3U,
63
64 RSI_ERROR_COUNT
65} rsi_status_t;
66
AlexeiFedorovdff904b2024-08-05 17:11:18 +010067/* Size of Realm Personalization Value */
68#define RSI_RPV_SIZE 64U
69
nabkah01002e5692022-10-10 12:36:46 +010070struct rsi_realm_config {
71 /* IPA width in bits */
AlexeiFedorovdff904b2024-08-05 17:11:18 +010072 SET_MEMBER(unsigned long ipa_width, 0, 8); /* Offset 0 */
73 /* Hash algorithm */
74 SET_MEMBER(unsigned long algorithm, 8, 0x200); /* Offset 8 */
75 /* Realm Personalization Value */
76 SET_MEMBER(unsigned char rpv[RSI_RPV_SIZE], 0x200, 0x1000); /* Offset 0x200 */
nabkah01002e5692022-10-10 12:36:46 +010077};
78
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010079#define RSI_HOST_CALL_NR_GPRS 31U
nabkah01002e5692022-10-10 12:36:46 +010080
81struct rsi_host_call {
82 SET_MEMBER(struct {
83 /* Immediate value */
84 unsigned int imm; /* Offset 0 */
85 /* Registers */
86 unsigned long gprs[RSI_HOST_CALL_NR_GPRS];
87 }, 0, 0x100);
88};
89
90/*
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010091 * arg0 == struct rsi_host_call address
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010092 * ret0 == Status / error
nabkah01002e5692022-10-10 12:36:46 +010093 */
94#define RSI_HOST_CALL SMC_RSI_FID(9U)
95
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010096/*
97 * arg0: Requested interface version
98 * ret0: Status / error
99 * ret1: Lower implemented interface revision
100 * ret2: Higher implemented interface revision
101 */
Shruti Gupta40de8ec2023-10-12 21:45:12 +0100102#define RSI_VERSION SMC_RSI_FID(0U)
AlexeiFedorov2f30f102023-03-13 19:37:46 +0000103
nabkah01002e5692022-10-10 12:36:46 +0100104/*
105 * arg0 == struct rsi_realm_config address
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100106 * ret0 == Status / error
nabkah01002e5692022-10-10 12:36:46 +0100107 */
108#define RSI_REALM_CONFIG SMC_RSI_FID(6U)
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100109
110/*
111 * arg0 == Base IPA address of target region
112 * arg1 == Top address of target region
113 * arg2 == RIPAS value
114 * arg3 == flags
115 * ret0 == Status / error
116 * ret1 == Base of IPA region which was not modified by the command
117 * ret2 == RSI response
118 */
Shruti Guptabb772192023-10-09 16:08:28 +0100119#define RSI_IPA_STATE_SET SMC_RSI_FID(7U)
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100120
121/*
122 * arg0 == Base of target IPA region
123 * arg1 == End of target IPA region
124 * ret0 == Status / error
125 * ret1 == Top of IPA region which has the reported RIPAS value
126 * ret2 == RIPAS value
127 */
Shruti Guptabb772192023-10-09 16:08:28 +0100128#define RSI_IPA_STATE_GET SMC_RSI_FID(8U)
129
130typedef enum {
131 RSI_EMPTY = 0U,
132 RSI_RAM,
AlexeiFedorovdff904b2024-08-05 17:11:18 +0100133 RSI_DESTROYED,
134 RSI_DEV
Shruti Guptabb772192023-10-09 16:08:28 +0100135} rsi_ripas_type;
136
137typedef enum {
138 RSI_ACCEPT = 0U,
139 RSI_REJECT
140} rsi_ripas_respose_type;
141
142#define RSI_NO_CHANGE_DESTROYED 0UL
143#define RSI_CHANGE_DESTROYED 1UL
144
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100145/* Request RIPAS of a target IPA range to be changed to a specified value */
Shruti Guptabb772192023-10-09 16:08:28 +0100146u_register_t rsi_ipa_state_set(u_register_t base,
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100147 u_register_t top,
148 rsi_ripas_type ripas,
149 u_register_t flag,
150 u_register_t *new_base,
151 rsi_ripas_respose_type *response);
Shruti Guptabb772192023-10-09 16:08:28 +0100152
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +0100153/* Request RIPAS of a target IPA range */
154u_register_t rsi_ipa_state_get(u_register_t base,
155 u_register_t top,
156 u_register_t *out_top,
157 rsi_ripas_type *ripas);
nabkah01002e5692022-10-10 12:36:46 +0100158
159/* This function return RSI_ABI_VERSION */
Shruti Gupta40de8ec2023-10-12 21:45:12 +0100160u_register_t rsi_get_version(u_register_t req_ver);
nabkah01002e5692022-10-10 12:36:46 +0100161
162/* This function will call the Host to request IPA of the NS shared buffer */
163u_register_t rsi_get_ns_buffer(void);
164
165/* This function call Host and request to exit Realm with proper exit code */
166void rsi_exit_to_host(enum host_call_cmd exit_code);
167
168#endif /* REALM_RSI_H */