xref: /rk3399_ARM-atf/lib/extensions/brbe/brbe.c (revision 123002f9171384d976d95935b7f566740d69cc68)
1744ad974Sjohpow01 /*
2*123002f9SJayanth Dodderi Chidanand  * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
3744ad974Sjohpow01  *
4744ad974Sjohpow01  * SPDX-License-Identifier: BSD-3-Clause
5744ad974Sjohpow01  */
6744ad974Sjohpow01 
7744ad974Sjohpow01 #include <arch.h>
81298f2f1SJayanth Dodderi Chidanand #include <arch_features.h>
9744ad974Sjohpow01 #include <arch_helpers.h>
1060d330dcSBoyan Karatotev #include <lib/extensions/brbe.h>
11744ad974Sjohpow01 
12*123002f9SJayanth Dodderi Chidanand void brbe_enable(cpu_context_t *ctx)
13744ad974Sjohpow01 {
14*123002f9SJayanth Dodderi Chidanand 	el3_state_t *state = get_el3state_ctx(ctx);
15*123002f9SJayanth Dodderi Chidanand 	u_register_t mdcr_el3_val = read_ctx_reg(state, CTX_MDCR_EL3);
16744ad974Sjohpow01 
17744ad974Sjohpow01 	/*
18744ad974Sjohpow01 	 * MDCR_EL3.SBRBE = 0b01
19744ad974Sjohpow01 	 *
20744ad974Sjohpow01 	 * Allows BRBE usage in non-secure world and prohibited in
21744ad974Sjohpow01 	 * secure world.
22744ad974Sjohpow01 	 */
23*123002f9SJayanth Dodderi Chidanand 	mdcr_el3_val &= ~(MDCR_SBRBE_MASK << MDCR_SBRBE_SHIFT);
24*123002f9SJayanth Dodderi Chidanand 	mdcr_el3_val |= (0x1UL << MDCR_SBRBE_SHIFT);
25*123002f9SJayanth Dodderi Chidanand 	write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
26744ad974Sjohpow01 }
27