blob: 875ad9c2a5477df39643c417bdd2702d646cb780 [file] [log] [blame]
Jeenu Viswambharan5f835912018-07-31 16:13:33 +01001/*
Boyan Karatotev60d330d2023-02-16 15:12:45 +00002 * Copyright (c) 2018-2023, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharan5f835912018-07-31 16:13:33 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00007#include <stdbool.h>
8
Jeenu Viswambharan5f835912018-07-31 16:13:33 +01009#include <arch.h>
Alexei Fedorovdbcc44a2020-05-26 13:16:41 +010010#include <arch_features.h>
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010011#include <arch_helpers.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000012#include <lib/extensions/mpam.h>
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010013
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -050014void mpam_enable(cpu_context_t *context)
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010015{
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -050016 u_register_t mpam3_el3;
17
18 mpam3_el3 = read_ctx_reg(get_el3state_ctx(context), CTX_MPAM3_EL3);
19
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010020 /*
21 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -050022 * own MPAM registers
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010023 */
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -050024 mpam3_el3 = (mpam3_el3 | MPAM3_EL3_MPAMEN_BIT) &
25 ~(MPAM3_EL3_TRAPLOWER_BIT);
26 write_ctx_reg(get_el3state_ctx(context), CTX_MPAM3_EL3, mpam3_el3);
Boyan Karatotev60d330d2023-02-16 15:12:45 +000027}
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010028
Boyan Karatotev60d330d2023-02-16 15:12:45 +000029/*
30 * If EL2 is implemented but unused, disable trapping to EL2 when lower ELs
31 * access their own MPAM registers.
32 */
33void 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);
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010039 }
Boyan Karatotev60d330d2023-02-16 15:12:45 +000040
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010041}