blob: 34721cd99f1b4d42c146f75dcc1c17c4d35cd9d9 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001/*
2 * Copyright (c) 2022, Arm Limited. All rights reserved.
3 *
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>
12#include <tftf_lib.h>
13
14#define SMC_RSI_CALL_BASE 0xC4000190
15#define SMC_RSI_FID(_x) (SMC_RSI_CALL_BASE + (_x))
16/*
17 * This file describes the Realm Services Interface (RSI) Application Binary
18 * Interface (ABI) for SMC calls made from within the Realm to the RMM and
19 * serviced by the RMM.
20 *
21 * See doc/rmm_interface.md for more details.
22 */
23
24/*
25 * The major version number of the RSI implementation. Increase this whenever
26 * the binary format or semantics of the SMC calls change.
27 */
28#define RSI_ABI_VERSION_MAJOR 12U
29
30/*
31 * The minor version number of the RSI implementation. Increase this when
32 * a bug is fixed, or a feature is added without breaking binary compatibility.
33 */
34#define RSI_ABI_VERSION_MINOR 0U
35
36#define RSI_ABI_VERSION_VAL ((RSI_ABI_VERSION_MAJOR << 16U) | \
37 RSI_ABI_VERSION_MINOR)
38
39#define RSI_ABI_VERSION_GET_MAJOR(_version) ((_version) >> 16U)
40#define RSI_ABI_VERSION_GET_MINOR(_version) ((_version) & 0xFFFFU)
41
42
43/* RSI Status code enumeration as per Section D4.3.6 of the RMM Spec */
44typedef enum {
45 /* Command completed successfully */
46 RSI_SUCCESS = 0U,
47
48 /*
49 * The value of a command input value
50 * caused the command to fail
51 */
52 RSI_ERROR_INPUT = 1U,
53
54 /*
55 * The state of the current Realm or current REC
56 * does not match the state expected by the command
57 */
58 RSI_ERROR_STATE = 2U,
59
60 /* The operation requested by the command is not complete */
61 RSI_INCOMPLETE = 3U,
62
63 RSI_ERROR_COUNT
64} rsi_status_t;
65
66enum host_call_cmd {
67 HOST_CALL_GET_SHARED_BUFF_CMD = 1U,
68 HOST_CALL_EXIT_SUCCESS_CMD,
69 HOST_CALL_EXIT_FAILED_CMD
70};
71
72struct rsi_realm_config {
73 /* IPA width in bits */
74 SET_MEMBER(unsigned long ipa_width, 0, 0x1000); /* Offset 0 */
75};
76
77/*
78 * arg0 == IPA address of target region
79 * arg1 == Size of target region in bytes
80 * arg2 == RIPAS value
81 * ret0 == Status / error
82 * ret1 == Top of modified IPA range
83 */
84
85#define RSI_HOST_CALL_NR_GPRS 7U
86
87struct rsi_host_call {
88 SET_MEMBER(struct {
89 /* Immediate value */
90 unsigned int imm; /* Offset 0 */
91 /* Registers */
92 unsigned long gprs[RSI_HOST_CALL_NR_GPRS];
93 }, 0, 0x100);
94};
95
96/*
97 * arg0 == struct rsi_host_call addr
98 */
99#define RSI_HOST_CALL SMC_RSI_FID(9U)
100
101
102#define RSI_ABI_VERSION SMC_RSI_FID(0U)
103/*
104 * arg0 == struct rsi_realm_config address
105 */
106#define RSI_REALM_CONFIG SMC_RSI_FID(6U)
107
108/* This function return RSI_ABI_VERSION */
109u_register_t rsi_get_version(void);
110
111/* This function will call the Host to request IPA of the NS shared buffer */
112u_register_t rsi_get_ns_buffer(void);
113
114/* This function call Host and request to exit Realm with proper exit code */
115void rsi_exit_to_host(enum host_call_cmd exit_code);
116
117#endif /* REALM_RSI_H */