Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved. |
| 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> |
| 10 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <lib/extensions/mpam.h> |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 12 | |
| 13 | bool mpam_supported(void) |
| 14 | { |
| 15 | uint64_t features = read_id_aa64dfr0_el1() >> ID_AA64PFR0_MPAM_SHIFT; |
| 16 | |
| 17 | return ((features & ID_AA64PFR0_MPAM_MASK) != 0U); |
| 18 | } |
| 19 | |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 20 | void mpam_enable(bool el2_unused) |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 21 | { |
| 22 | if (!mpam_supported()) |
| 23 | return; |
| 24 | |
| 25 | /* |
| 26 | * Enable MPAM, and disable trapping to EL3 when lower ELs access their |
| 27 | * own MPAM registers. |
| 28 | */ |
| 29 | write_mpam3_el3(MPAM3_EL3_MPAMEN_BIT); |
| 30 | |
| 31 | /* |
| 32 | * If EL2 is implemented but unused, disable trapping to EL2 when lower |
| 33 | * ELs access their own MPAM registers. |
Louis Mayencourt | bdfa103 | 2019-02-11 11:25:50 +0000 | [diff] [blame] | 34 | * If EL2 is implemented and used, enable trapping to EL2. |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 35 | */ |
Antonio Nino Diaz | 033b4bb | 2018-10-25 16:52:26 +0100 | [diff] [blame] | 36 | if (el2_unused) { |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 37 | write_mpam2_el2(0); |
| 38 | |
| 39 | if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) |
| 40 | write_mpamhcr_el2(0); |
Louis Mayencourt | bdfa103 | 2019-02-11 11:25:50 +0000 | [diff] [blame] | 41 | } else { |
| 42 | write_mpam2_el2(MPAM2_EL2_TRAPMPAM0EL1 | |
| 43 | MPAM2_EL2_TRAPMPAM1EL1); |
| 44 | |
| 45 | if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) { |
| 46 | write_mpamhcr_el2(MPAMHCR_EL2_TRAP_MPAMIDR_EL1); |
| 47 | } |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 48 | } |
| 49 | } |