xref: /rk3399_ARM-atf/plat/arm/board/tc/tc_rng_trap.c (revision e7e231d39c68083e870cdaaa89ecc4e5045fdd64)
1 /*
2  * Copyright (c) 2025-2026, Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <assert.h>
8 
9 #include <bl31/sync_handle.h>
10 #include <context.h>
11 #include <plat/common/plat_trng.h>
12 
plat_handle_rng_trap(uint8_t rt,bool rndrrs,cpu_context_t * ctx)13 int plat_handle_rng_trap(uint8_t rt, bool rndrrs, cpu_context_t *ctx)
14 {
15 	uint64_t entropy;
16 
17 	if (!plat_get_entropy(&entropy)) {
18 		ERROR("Failed to get entropy\n");
19 		panic();
20 	}
21 
22 	/* Emulate RNDR and RNDRRS */
23 	gp_regs_t *gpregs = get_gpregs_ctx(ctx);
24 
25 	gpregs->ctx_regs[rt] = entropy;
26 
27 	return TRAP_RET_CONTINUE;
28 }
29