blob: bf47efcee24fe04fa2682b04f9f37fa6ec37e931 [file] [log] [blame]
/*
* Copyright (c) 2024, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdlib.h>
#include <realm_helpers.h>
#include <realm_psi.h>
#include <realm_rsi.h>
#include <smccc.h>
/* Generate 64-bit random number */
unsigned long long realm_rand64(void)
{
return ((unsigned long long)rand() << 32) | rand();
}
/* This function will call the Host to request IPA of the NS shared buffer */
u_register_t realm_get_ns_buffer(void)
{
smc_ret_values res = {};
struct rsi_host_call host_cal __aligned(sizeof(struct rsi_host_call));
host_cal.imm = HOST_CALL_GET_SHARED_BUFF_CMD;
res = tftf_smc(&(smc_args) {RSI_HOST_CALL, (u_register_t)&host_cal,
0UL, 0UL, 0UL, 0UL, 0UL, 0UL});
if (res.ret0 != RSI_SUCCESS) {
/* retry with PSI */
hvc_ret_values ret = tftf_hvc(&(hvc_args) {PSI_CALL_GET_SHARED_BUFF_CMD, 0UL, 0UL,
0UL, 0UL, 0UL, 0UL, 0UL});
if (ret.ret0 != RSI_SUCCESS) {
return 0U;
}
return ret.ret1;
}
return host_cal.gprs[0];
}