xref: /rk3399_ARM-atf/lib/extensions/trf/aarch64/trf.c (revision 1727d690d29ef604f1fcf183e35c06d33d974e63)
1 /*
2  * Copyright (c) 2021-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/trf.h>
11 
12 void trf_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.STE = b0
19 	 * Trace prohibited in Secure state unless overridden by the
20 	 * IMPLEMENTATION DEFINED authentication interface.
21 	 *
22 	 * MDCR_EL3.TTRF = b0
23 	 * Allow access of trace filter control registers from NS-EL2
24 	 * and NS-EL1 when NS-EL2 is implemented but not used
25 	 *
26 	 * MDCR_EL3.RLTE = b0
27 	 * Trace prohibited in Realm state, unless overridden by the
28 	 * IMPLEMENTATION DEFINED authentication interface.
29 	 */
30 	mdcr_el3_val &= ~(MDCR_STE_BIT | MDCR_TTRF_BIT | MDCR_RLTE_BIT);
31 	write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
32 }
33 
34 void trf_init_el2_unused(void)
35 {
36 	/*
37 	 * MDCR_EL2.TTRF: Set to zero so that access to Trace
38 	 *  Filter Control register TRFCR_EL1 at EL1 is not
39 	 *  trapped to EL2. This bit is RES0 in versions of
40 	 *  the architecture earlier than ARMv8.4.
41 	 *
42 	 */
43 	write_mdcr_el2(read_mdcr_el2() & ~MDCR_EL2_TTRF);
44 }
45