blob: d82aa6f45e9c6c9f993b36ca54cbf39793c56120 [file] [log] [blame]
nabkah01002e5692022-10-10 12:36:46 +01001
2/*
3 * Copyright (c) 2022, Arm Limited. All rights reserved.
4 *
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
14static struct rsi_host_call host_cal __aligned(sizeof(struct rsi_host_call));
15
16/* This function return RSI_ABI_VERSION */
Shruti Gupta40de8ec2023-10-12 21:45:12 +010017u_register_t rsi_get_version(u_register_t req_ver)
nabkah01002e5692022-10-10 12:36:46 +010018{
19 smc_ret_values res = {};
20
21 res = tftf_smc(&(smc_args)
Shruti Gupta40de8ec2023-10-12 21:45:12 +010022 {RSI_VERSION, req_ver, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
nabkah01002e5692022-10-10 12:36:46 +010023
Shruti Gupta40de8ec2023-10-12 21:45:12 +010024 if (res.ret0 == SMC_UNKNOWN) {
25 return SMC_UNKNOWN;
26 }
27 /* Return lower version. */
28 return res.ret1;
nabkah01002e5692022-10-10 12:36:46 +010029}
30
31/* This function will call the Host to request IPA of the NS shared buffer */
32u_register_t rsi_get_ns_buffer(void)
33{
34 smc_ret_values res = {};
35
36 host_cal.imm = HOST_CALL_GET_SHARED_BUFF_CMD;
37 res = tftf_smc(&(smc_args) {RSI_HOST_CALL, (u_register_t)&host_cal,
38 0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
39 if (res.ret0 != RSI_SUCCESS) {
40 return 0U;
41 }
42 return host_cal.gprs[0];
43}
44
45/* This function call Host and request to exit Realm with proper exit code */
46void rsi_exit_to_host(enum host_call_cmd exit_code)
47{
48 host_cal.imm = exit_code;
Shruti Gupta8ce30532023-10-16 15:58:38 +010049 host_cal.gprs[0] = read_mpidr_el1() & MPID_MASK;
nabkah01002e5692022-10-10 12:36:46 +010050 tftf_smc(&(smc_args) {RSI_HOST_CALL, (u_register_t)&host_cal,
51 0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
52}