blob: cd4342f6909ba8555e535ec3e86d8969fa952274 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001
2/*
AlexeiFedorovf09c77a2024-09-10 15:50:44 +01003 * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
nabkah01002e5692022-10-10 12:36:46 +01004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 */
8
9#include <host_realm_rmi.h>
10#include <lib/aarch64/arch_features.h>
11#include <realm_rsi.h>
12#include <smccc.h>
13
nabkah01002e5692022-10-10 12:36:46 +010014/* This function return RSI_ABI_VERSION */
Shruti Gupta40de8ec2023-10-12 21:45:12 +010015u_register_t rsi_get_version(u_register_t req_ver)
nabkah01002e5692022-10-10 12:36:46 +010016{
17 smc_ret_values res = {};
18
19 res = tftf_smc(&(smc_args)
Shruti Gupta40de8ec2023-10-12 21:45:12 +010020 {RSI_VERSION, req_ver, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
nabkah01002e5692022-10-10 12:36:46 +010021
Shruti Gupta40de8ec2023-10-12 21:45:12 +010022 if (res.ret0 == SMC_UNKNOWN) {
23 return SMC_UNKNOWN;
24 }
25 /* Return lower version. */
26 return res.ret1;
nabkah01002e5692022-10-10 12:36:46 +010027}
28
29/* This function will call the Host to request IPA of the NS shared buffer */
30u_register_t rsi_get_ns_buffer(void)
31{
32 smc_ret_values res = {};
Shruti Gupta43a50c32023-11-28 10:54:27 +000033 struct rsi_host_call host_cal __aligned(sizeof(struct rsi_host_call));
nabkah01002e5692022-10-10 12:36:46 +010034
35 host_cal.imm = HOST_CALL_GET_SHARED_BUFF_CMD;
36 res = tftf_smc(&(smc_args) {RSI_HOST_CALL, (u_register_t)&host_cal,
37 0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
38 if (res.ret0 != RSI_SUCCESS) {
39 return 0U;
40 }
41 return host_cal.gprs[0];
42}
43
44/* This function call Host and request to exit Realm with proper exit code */
45void rsi_exit_to_host(enum host_call_cmd exit_code)
46{
Shruti Gupta43a50c32023-11-28 10:54:27 +000047 struct rsi_host_call host_cal __aligned(sizeof(struct rsi_host_call));
48
nabkah01002e5692022-10-10 12:36:46 +010049 host_cal.imm = exit_code;
AlexeiFedorovf09c77a2024-09-10 15:50:44 +010050 host_cal.gprs[0] = read_mpidr_el1();
nabkah01002e5692022-10-10 12:36:46 +010051 tftf_smc(&(smc_args) {RSI_HOST_CALL, (u_register_t)&host_cal,
52 0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
53}
Shruti Guptabb772192023-10-09 16:08:28 +010054
55/* This function will exit to the Host to request RIPAS CHANGE of IPA range */
56u_register_t rsi_ipa_state_set(u_register_t base,
57 u_register_t top,
58 rsi_ripas_type ripas,
59 u_register_t flag,
60 u_register_t *new_base,
61 rsi_ripas_respose_type *response)
62{
63 smc_ret_values res = {};
64
65 res = tftf_smc(&(smc_args)
66 {RSI_IPA_STATE_SET, base, top, ripas, flag});
67 if (res.ret0 == RSI_SUCCESS) {
68 *new_base = res.ret1;
69 *response = res.ret2;
70 }
71 return res.ret0;
72}
73
74/* This function will return RIPAS of IPA */
75u_register_t rsi_ipa_state_get(u_register_t adr, rsi_ripas_type *ripas)
76{
77 smc_ret_values res = {};
78
79 res = tftf_smc(&(smc_args)
80 {RSI_IPA_STATE_GET, adr});
81 if (res.ret0 == RSI_SUCCESS) {
82 *ripas = res.ret1;
83 }
84 return res.ret0;
85}