blob: 65601ddec74c834750aa8526840caebaf4666490 [file] [log] [blame]
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +01001/*
Alexei Fedorov19933552020-05-26 13:16:41 +01002 * Copyright (c) 2018-2020, 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
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010014void mpam_enable(bool el2_unused)
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010015{
Alexei Fedorov19933552020-05-26 13:16:41 +010016 /* Check if MPAM is implemented */
17 if (get_mpam_version() == 0U) {
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010018 return;
Alexei Fedorov19933552020-05-26 13:16:41 +010019 }
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010020
21 /*
22 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
23 * own MPAM registers.
24 */
25 write_mpam3_el3(MPAM3_EL3_MPAMEN_BIT);
26
27 /*
28 * If EL2 is implemented but unused, disable trapping to EL2 when lower
29 * ELs access their own MPAM registers.
Louis Mayencourtbdfa1032019-02-11 11:25:50 +000030 * If EL2 is implemented and used, enable trapping to EL2.
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010031 */
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010032 if (el2_unused) {
Alexei Fedorov19933552020-05-26 13:16:41 +010033 write_mpam2_el2(0ULL);
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010034
Alexei Fedorov19933552020-05-26 13:16:41 +010035 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
36 write_mpamhcr_el2(0ULL);
37 }
Louis Mayencourtbdfa1032019-02-11 11:25:50 +000038 } else {
39 write_mpam2_el2(MPAM2_EL2_TRAPMPAM0EL1 |
40 MPAM2_EL2_TRAPMPAM1EL1);
41
42 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
43 write_mpamhcr_el2(MPAMHCR_EL2_TRAP_MPAMIDR_EL1);
44 }
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010045 }
46}