blob: bf47efcee24fe04fa2682b04f9f37fa6ec37e931 [file] [log] [blame]
Juan Pablo Conde88ffad22024-10-11 21:22:29 -05001/*
2 * Copyright (c) 2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <stdlib.h>
Shruti Gupta91105082024-11-27 05:29:55 +00008#include <realm_helpers.h>
9#include <realm_psi.h>
10#include <realm_rsi.h>
11#include <smccc.h>
Juan Pablo Conde88ffad22024-10-11 21:22:29 -050012
13/* Generate 64-bit random number */
14unsigned long long realm_rand64(void)
15{
16 return ((unsigned long long)rand() << 32) | rand();
17}
18
Shruti Gupta91105082024-11-27 05:29:55 +000019/* This function will call the Host to request IPA of the NS shared buffer */
20u_register_t realm_get_ns_buffer(void)
21{
22 smc_ret_values res = {};
23 struct rsi_host_call host_cal __aligned(sizeof(struct rsi_host_call));
24
25 host_cal.imm = HOST_CALL_GET_SHARED_BUFF_CMD;
26 res = tftf_smc(&(smc_args) {RSI_HOST_CALL, (u_register_t)&host_cal,
27 0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
28
29 if (res.ret0 != RSI_SUCCESS) {
30 /* retry with PSI */
31 hvc_ret_values ret = tftf_hvc(&(hvc_args) {PSI_CALL_GET_SHARED_BUFF_CMD, 0UL, 0UL,
32 0UL, 0UL, 0UL, 0UL, 0UL});
33
34 if (ret.ret0 != RSI_SUCCESS) {
35 return 0U;
36 }
37 return ret.ret1;
38 }
39
40 return host_cal.gprs[0];
41}