blob: 8436db963816e8fd3d7a2c7276edfbd4534711d3 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
AlexeiFedorov3d3dea22023-04-06 15:36:27 +01002 * Copyright (c) 2022-2023, 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
nabkah01002e5692022-10-10 12:36:46 +010067struct rsi_realm_config {
68 /* IPA width in bits */
69 SET_MEMBER(unsigned long ipa_width, 0, 0x1000); /* Offset 0 */
70};
71
72/*
73 * arg0 == IPA address of target region
74 * arg1 == Size of target region in bytes
75 * arg2 == RIPAS value
76 * ret0 == Status / error
77 * ret1 == Top of modified IPA range
78 */
79
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010080#define RSI_HOST_CALL_NR_GPRS 31U
nabkah01002e5692022-10-10 12:36:46 +010081
82struct rsi_host_call {
83 SET_MEMBER(struct {
84 /* Immediate value */
85 unsigned int imm; /* Offset 0 */
86 /* Registers */
87 unsigned long gprs[RSI_HOST_CALL_NR_GPRS];
88 }, 0, 0x100);
89};
90
91/*
AlexeiFedorov3d3dea22023-04-06 15:36:27 +010092 * arg0 == struct rsi_host_call address
nabkah01002e5692022-10-10 12:36:46 +010093 */
94#define RSI_HOST_CALL SMC_RSI_FID(9U)
95
96
Shruti Gupta40de8ec2023-10-12 21:45:12 +010097#define RSI_VERSION SMC_RSI_FID(0U)
AlexeiFedorov2f30f102023-03-13 19:37:46 +000098
nabkah01002e5692022-10-10 12:36:46 +010099/*
100 * arg0 == struct rsi_realm_config address
101 */
102#define RSI_REALM_CONFIG SMC_RSI_FID(6U)
Shruti Guptabb772192023-10-09 16:08:28 +0100103#define RSI_IPA_STATE_SET SMC_RSI_FID(7U)
104#define RSI_IPA_STATE_GET SMC_RSI_FID(8U)
105
106typedef enum {
107 RSI_EMPTY = 0U,
108 RSI_RAM,
109 RSI_DESTROYED
110} rsi_ripas_type;
111
112typedef enum {
113 RSI_ACCEPT = 0U,
114 RSI_REJECT
115} rsi_ripas_respose_type;
116
117#define RSI_NO_CHANGE_DESTROYED 0UL
118#define RSI_CHANGE_DESTROYED 1UL
119
120/* Request RIPAS of a target IPA range to be changed to a specified value. */
121u_register_t rsi_ipa_state_set(u_register_t base,
122 u_register_t top,
123 rsi_ripas_type ripas,
124 u_register_t flag,
125 u_register_t *new_base,
126 rsi_ripas_respose_type *response);
127
128/* Request RIPAS of a target IPA */
129u_register_t rsi_ipa_state_get(u_register_t adr, rsi_ripas_type *ripas);
nabkah01002e5692022-10-10 12:36:46 +0100130
131/* This function return RSI_ABI_VERSION */
Shruti Gupta40de8ec2023-10-12 21:45:12 +0100132u_register_t rsi_get_version(u_register_t req_ver);
nabkah01002e5692022-10-10 12:36:46 +0100133
134/* This function will call the Host to request IPA of the NS shared buffer */
135u_register_t rsi_get_ns_buffer(void);
136
137/* This function call Host and request to exit Realm with proper exit code */
138void rsi_exit_to_host(enum host_call_cmd exit_code);
139
140#endif /* REALM_RSI_H */