blob: 884d480d5df05ae9993932faa9654e410935f494 [file] [log] [blame]
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +01001/*
Zelalem Aweke14dbc702022-02-02 15:29:13 -06002 * Copyright (c) 2018-2022, 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.
30 */
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010031 if (el2_unused) {
Alexei Fedorov19933552020-05-26 13:16:41 +010032 write_mpam2_el2(0ULL);
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010033
Alexei Fedorov19933552020-05-26 13:16:41 +010034 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
35 write_mpamhcr_el2(0ULL);
36 }
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010037 }
38}