blob: d57bb470bf9f6268cba25c398eb22bd6be30cd92 [file] [log] [blame]
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +01001/*
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
12bool 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
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010019void mpam_enable(bool el2_unused)
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010020{
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 */
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010034 if (el2_unused) {
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010035 write_mpam2_el2(0);
36
37 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U)
38 write_mpamhcr_el2(0);
39 }
40}