xref: /rk3399_ARM-atf/lib/extensions/mpam/mpam.c (revision 1b491eead580d7849a45a38f2c6a935a5d8d1160)
1 /*
2  * Copyright (c) 2018-2022, ARM Limited and Contributors. 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_features.h>
11 #include <arch_helpers.h>
12 #include <lib/extensions/mpam.h>
13 
14 void mpam_enable(bool el2_unused)
15 {
16 	/*
17 	 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
18 	 * own MPAM registers.
19 	 */
20 	write_mpam3_el3(MPAM3_EL3_MPAMEN_BIT);
21 
22 	/*
23 	 * If EL2 is implemented but unused, disable trapping to EL2 when lower
24 	 * ELs access their own MPAM registers.
25 	 */
26 	if (el2_unused) {
27 		write_mpam2_el2(0ULL);
28 
29 		if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
30 			write_mpamhcr_el2(0ULL);
31 		}
32 	}
33 }
34