Juan Pablo Conde | 88ffad2 | 2024-10-11 21:22:29 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2024, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <stdlib.h> |
Shruti Gupta | 9110508 | 2024-11-27 05:29:55 +0000 | [diff] [blame] | 8 | #include <realm_helpers.h> |
| 9 | #include <realm_psi.h> |
| 10 | #include <realm_rsi.h> |
| 11 | #include <smccc.h> |
Juan Pablo Conde | 88ffad2 | 2024-10-11 21:22:29 -0500 | [diff] [blame] | 12 | |
| 13 | /* Generate 64-bit random number */ |
| 14 | unsigned long long realm_rand64(void) |
| 15 | { |
| 16 | return ((unsigned long long)rand() << 32) | rand(); |
| 17 | } |
| 18 | |
Shruti Gupta | 9110508 | 2024-11-27 05:29:55 +0000 | [diff] [blame] | 19 | /* This function will call the Host to request IPA of the NS shared buffer */ |
| 20 | u_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 | } |