1 /*
2  * Copyright (c) 2021, Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #include <stdbool.h>
8 
9 #include <arch.h>
10 #include <arch_helpers.h>
11 #include <lib/extensions/trf.h>
12 
trf_supported(void)13 static bool trf_supported(void)
14 {
15 	uint64_t features;
16 
17 	features = read_id_aa64dfr0_el1() >> ID_AA64DFR0_TRACEFILT_SHIFT;
18 	return ((features & ID_AA64DFR0_TRACEFILT_MASK) ==
19 		ID_AA64DFR0_TRACEFILT_SUPPORTED);
20 }
21 
trf_enable(void)22 void trf_enable(void)
23 {
24 	uint64_t val;
25 
26 	if (trf_supported()) {
27 		/*
28 		 * MDCR_EL3.TTRF = b0
29 		 * Allow access of trace filter control registers from NS-EL2
30 		 * and NS-EL1 when NS-EL2 is implemented but not used
31 		 */
32 		val = read_mdcr_el3();
33 		val &= ~MDCR_TTRF_BIT;
34 		write_mdcr_el3(val);
35 	}
36 }
37