blob: 62533fcaca12a2d25c9d90f05834a1edab833b9b [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{
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010016 /*
17 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
18 * own MPAM registers.
19 */
20 write_mpam3_el3(MPAM3_EL3_MPAMEN_BIT);
21
22 /*
23 * If EL2 is implemented but unused, disable trapping to EL2 when lower
24 * ELs access their own MPAM registers.
25 */
Antonio Nino Diaz033b4bb2018-10-25 16:52:26 +010026 if (el2_unused) {
Alexei Fedorov19933552020-05-26 13:16:41 +010027 write_mpam2_el2(0ULL);
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010028
Alexei Fedorov19933552020-05-26 13:16:41 +010029 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
30 write_mpamhcr_el2(0ULL);
31 }
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010032 }
33}