blob: b2a49d42cc8ad7d06abe38c447f3ab34173f146d [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 }
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010025 /* Return lower version */
Shruti Gupta40de8ec2023-10-12 21:45:12 +010026 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
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010074/* This function will return RIPAS of IPA range */
75u_register_t rsi_ipa_state_get(u_register_t base,
76 u_register_t top,
77 u_register_t *out_top,
78 rsi_ripas_type *ripas)
Shruti Guptabb772192023-10-09 16:08:28 +010079{
80 smc_ret_values res = {};
81
82 res = tftf_smc(&(smc_args)
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010083 {RSI_IPA_STATE_GET, base, top});
Shruti Guptabb772192023-10-09 16:08:28 +010084 if (res.ret0 == RSI_SUCCESS) {
AlexeiFedorov9a60ecb2024-08-06 16:39:00 +010085 *out_top = res.ret1;
86 *ripas = res.ret2;
Shruti Guptabb772192023-10-09 16:08:28 +010087 }
88 return res.ret0;
89}