nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 1 | |
| 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 | |
| 14 | static struct rsi_host_call host_cal __aligned(sizeof(struct rsi_host_call)); |
| 15 | |
| 16 | /* This function return RSI_ABI_VERSION */ |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 17 | u_register_t rsi_get_version(u_register_t req_ver) |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 18 | { |
| 19 | smc_ret_values res = {}; |
| 20 | |
| 21 | res = tftf_smc(&(smc_args) |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 22 | {RSI_VERSION, req_ver, 0UL, 0UL, 0UL, 0UL, 0UL, 0UL}); |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 23 | |
Shruti Gupta | 40de8ec | 2023-10-12 21:45:12 +0100 | [diff] [blame] | 24 | if (res.ret0 == SMC_UNKNOWN) { |
| 25 | return SMC_UNKNOWN; |
| 26 | } |
| 27 | /* Return lower version. */ |
| 28 | return res.ret1; |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | /* This function will call the Host to request IPA of the NS shared buffer */ |
| 32 | u_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 */ |
| 46 | void rsi_exit_to_host(enum host_call_cmd exit_code) |
| 47 | { |
| 48 | host_cal.imm = exit_code; |
Shruti Gupta | 8ce3053 | 2023-10-16 15:58:38 +0100 | [diff] [blame] | 49 | host_cal.gprs[0] = read_mpidr_el1() & MPID_MASK; |
nabkah01 | 002e569 | 2022-10-10 12:36:46 +0100 | [diff] [blame] | 50 | tftf_smc(&(smc_args) {RSI_HOST_CALL, (u_register_t)&host_cal, |
| 51 | 0UL, 0UL, 0UL, 0UL, 0UL, 0UL}); |
| 52 | } |