xref: /rk3399_ARM-atf/lib/extensions/brbe/brbe.c (revision 04cf04c72d403e0c057505882fac9002d39d4102)
1 /*
2  * Copyright (c) 2022-2025, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <arch.h>
8 #include <arch_features.h>
9 #include <arch_helpers.h>
10 #include <lib/extensions/brbe.h>
11 
12 void brbe_enable(cpu_context_t *ctx)
13 {
14 	el3_state_t *state = get_el3state_ctx(ctx);
15 	u_register_t mdcr_el3_val = read_ctx_reg(state, CTX_MDCR_EL3);
16 
17 	/*
18 	 * MDCR_EL3.SBRBE = 0b01
19 	 * Allows BRBE usage in non-secure world and prohibited in
20 	 * secure world. This is relied on by SMCCC_ARCH_FEATURE_AVAILABILITY.
21 	 *
22 	 * MDCR_EL3.{E3BREW, E3BREC} = 0b00
23 	 * Branch recording at EL3 is disabled
24 	 */
25 	mdcr_el3_val &= ~((MDCR_SBRBE(MDCR_SBRBE_ALL)) | MDCR_E3BREW_BIT | MDCR_E3BREC_BIT);
26 	mdcr_el3_val |= (MDCR_SBRBE(MDCR_SBRBE_NS));
27 	write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
28 }
29