blob: ba60ba87c3031f0ec9ab92d04d21468efa3b79a5 [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
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;
Shruti Gupta8ce30532023-10-16 15:58:38 +010050 host_cal.gprs[0] = read_mpidr_el1() & MPID_MASK;
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}