1 /* 2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include <arch.h> 8 #include <arch_helpers.h> 9 #include <mpam.h> 10 #include <stdbool.h> 11 12 bool mpam_supported(void) 13 { 14 uint64_t features = read_id_aa64dfr0_el1() >> ID_AA64PFR0_MPAM_SHIFT; 15 16 return ((features & ID_AA64PFR0_MPAM_MASK) != 0U); 17 } 18 19 void mpam_enable(int el2_unused) 20 { 21 if (!mpam_supported()) 22 return; 23 24 /* 25 * Enable MPAM, and disable trapping to EL3 when lower ELs access their 26 * own MPAM registers. 27 */ 28 write_mpam3_el3(MPAM3_EL3_MPAMEN_BIT); 29 30 /* 31 * If EL2 is implemented but unused, disable trapping to EL2 when lower 32 * ELs access their own MPAM registers. 33 */ 34 if (el2_unused != 0) { 35 write_mpam2_el2(0); 36 37 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) 38 write_mpamhcr_el2(0); 39 } 40 } 41