15f835918SJeenu Viswambharan /* 260d330dcSBoyan Karatotev * Copyright (c) 2018-2023, Arm Limited and Contributors. All rights reserved. 35f835918SJeenu Viswambharan * 45f835918SJeenu Viswambharan * SPDX-License-Identifier: BSD-3-Clause 55f835918SJeenu Viswambharan */ 65f835918SJeenu Viswambharan 709d40e0eSAntonio Nino Diaz #include <stdbool.h> 809d40e0eSAntonio Nino Diaz 95f835918SJeenu Viswambharan #include <arch.h> 10dbcc44a1SAlexei Fedorov #include <arch_features.h> 115f835918SJeenu Viswambharan #include <arch_helpers.h> 1209d40e0eSAntonio Nino Diaz #include <lib/extensions/mpam.h> 135f835918SJeenu Viswambharan 14*edebefbcSArvind Ram Prakash void mpam_enable(cpu_context_t *context) 155f835918SJeenu Viswambharan { 16*edebefbcSArvind Ram Prakash u_register_t mpam3_el3; 17*edebefbcSArvind Ram Prakash 18*edebefbcSArvind Ram Prakash mpam3_el3 = read_ctx_reg(get_el3state_ctx(context), CTX_MPAM3_EL3); 19*edebefbcSArvind Ram Prakash 205f835918SJeenu Viswambharan /* 215f835918SJeenu Viswambharan * Enable MPAM, and disable trapping to EL3 when lower ELs access their 22*edebefbcSArvind Ram Prakash * own MPAM registers 235f835918SJeenu Viswambharan */ 24*edebefbcSArvind Ram Prakash mpam3_el3 = (mpam3_el3 | MPAM3_EL3_MPAMEN_BIT) & 25*edebefbcSArvind Ram Prakash ~(MPAM3_EL3_TRAPLOWER_BIT); 26*edebefbcSArvind Ram Prakash write_ctx_reg(get_el3state_ctx(context), CTX_MPAM3_EL3, mpam3_el3); 2760d330dcSBoyan Karatotev } 2860d330dcSBoyan Karatotev 295f835918SJeenu Viswambharan /* 3060d330dcSBoyan Karatotev * If EL2 is implemented but unused, disable trapping to EL2 when lower ELs 3160d330dcSBoyan Karatotev * access their own MPAM registers. 325f835918SJeenu Viswambharan */ 3360d330dcSBoyan Karatotev void mpam_init_el2_unused(void) 3460d330dcSBoyan Karatotev { 35dbcc44a1SAlexei Fedorov write_mpam2_el2(0ULL); 365f835918SJeenu Viswambharan 37dbcc44a1SAlexei Fedorov if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) { 38dbcc44a1SAlexei Fedorov write_mpamhcr_el2(0ULL); 39dbcc44a1SAlexei Fedorov } 4060d330dcSBoyan Karatotev 415f835918SJeenu Viswambharan } 42