Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 1 | /* |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved. |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 7 | #include <stdbool.h> |
| 8 | |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 9 | #include <arch.h> |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 10 | #include <arch_features.h> |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 11 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 12 | #include <lib/extensions/mpam.h> |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 13 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 14 | void mpam_enable(bool el2_unused) |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 15 | { |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 16 | /* Check if MPAM is implemented */ |
| 17 | if (get_mpam_version() == 0U) { |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 18 | return; |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 19 | } |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 20 | |
| 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 Mayencourt | bdfa103 | 2019-02-11 11:25:50 +0000 | [diff] [blame] | 30 | * If EL2 is implemented and used, enable trapping to EL2. |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 31 | */ |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 32 | if (el2_unused) { |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 33 | write_mpam2_el2(0ULL); |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 34 | |
Alexei Fedorov | 1993355 | 2020-05-26 13:16:41 +0100 | [diff] [blame] | 35 | if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) { |
| 36 | write_mpamhcr_el2(0ULL); |
| 37 | } |
Louis Mayencourt | bdfa103 | 2019-02-11 11:25:50 +0000 | [diff] [blame] | 38 | } 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 Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 45 | } |
| 46 | } |