blob: 875ad9c2a5477df39643c417bdd2702d646cb780 [file] [log] [blame]
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +01001/*
Boyan Karatotev6468d4a2023-02-16 15:12:45 +00002 * Copyright (c) 2018-2023, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00007#include <stdbool.h>
8
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +01009#include <arch.h>
Alexei Fedorov19933552020-05-26 13:16:41 +010010#include <arch_features.h>
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010011#include <arch_helpers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000012#include <lib/extensions/mpam.h>
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010013
Arvind Ram Prakashab28d4b2023-10-11 12:10:56 -050014void mpam_enable(cpu_context_t *context)
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010015{
Arvind Ram Prakashab28d4b2023-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 Viswambharan2da918c2018-07-31 16:13:33 +010020 /*
21 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
Arvind Ram Prakashab28d4b2023-10-11 12:10:56 -050022 * own MPAM registers
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010023 */
Arvind Ram Prakashab28d4b2023-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 Karatotev6468d4a2023-02-16 15:12:45 +000027}
28
29/*
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);
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010036
Boyan Karatotev6468d4a2023-02-16 15:12:45 +000037 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
38 write_mpamhcr_el2(0ULL);
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010039 }
Boyan Karatotev6468d4a2023-02-16 15:12:45 +000040
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010041}