12ae197acSLeo Yan /* 22ae197acSLeo Yan * Copyright (c) 2025, ARM Limited and Contributors. All rights reserved. 32ae197acSLeo Yan * 42ae197acSLeo Yan * SPDX-License-Identifier: BSD-3-Clause 52ae197acSLeo Yan */ 62ae197acSLeo Yan 72ae197acSLeo Yan #include <assert.h> 82ae197acSLeo Yan 92ae197acSLeo Yan #include <bl31/sync_handle.h> 102ae197acSLeo Yan #include <context.h> 112ae197acSLeo Yan #include <plat/common/plat_trng.h> 122ae197acSLeo Yan 132ae197acSLeo Yan #define XZR_REG_NUM 31 142ae197acSLeo Yan 152ae197acSLeo Yan plat_handle_rng_trap(uint64_t esr_el3,cpu_context_t * ctx)162ae197acSLeo Yanint plat_handle_rng_trap(uint64_t esr_el3, cpu_context_t *ctx) 172ae197acSLeo Yan { 182ae197acSLeo Yan uint64_t entropy; 192ae197acSLeo Yan 202ae197acSLeo Yan /* extract the target register number from the exception syndrome */ 212ae197acSLeo Yan unsigned int rt = get_sysreg_iss_rt(esr_el3); 222ae197acSLeo Yan 232ae197acSLeo Yan /* ignore XZR accesses and writes to the register */ 242ae197acSLeo Yan assert(rt != XZR_REG_NUM && !is_sysreg_iss_write(esr_el3)); 252ae197acSLeo Yan 262ae197acSLeo Yan if (!plat_get_entropy(&entropy)) { 272ae197acSLeo Yan ERROR("Failed to get entropy\n"); 282ae197acSLeo Yan panic(); 292ae197acSLeo Yan } 302ae197acSLeo Yan 312ae197acSLeo Yan /* Emulate RNDR and RNDRRS */ 322ae197acSLeo Yan gp_regs_t *gpregs = get_gpregs_ctx(ctx); 332ae197acSLeo Yan 34*cfbfe390SAditya Deshpande gpregs->ctx_regs[rt] = entropy; 352ae197acSLeo Yan 362ae197acSLeo Yan /* 372ae197acSLeo Yan * We successfully handled the trap, continue with the next 382ae197acSLeo Yan * instruction. 392ae197acSLeo Yan */ 402ae197acSLeo Yan return TRAP_RET_CONTINUE; 412ae197acSLeo Yan } 42