1 /*
2  * Copyright (c) 2018-2023, 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 
mpam_enable_per_world(per_world_context_t * per_world_ctx)14 void mpam_enable_per_world(per_world_context_t *per_world_ctx)
15 {
16 	u_register_t mpam3_el3;
17 
18 	/*
19 	 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
20 	 * own MPAM registers
21 	 */
22 	mpam3_el3 = per_world_ctx->ctx_mpam3_el3;
23 	mpam3_el3 = (mpam3_el3 | MPAM3_EL3_MPAMEN_BIT) &
24 				~(MPAM3_EL3_TRAPLOWER_BIT);
25 
26 	per_world_ctx->ctx_mpam3_el3 = mpam3_el3;
27 }
28 
29 /*
30  * If EL2 is implemented but unused, disable trapping to EL2 when lower ELs
31  * access their own MPAM registers.
32  */
mpam_init_el2_unused(void)33 void mpam_init_el2_unused(void)
34 {
35 	write_mpam2_el2(0ULL);
36 
37 	if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
38 		write_mpamhcr_el2(0ULL);
39 	}
40 
41 }
42