Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 1 | /* |
Boyan Karatotev | 6468d4a | 2023-02-16 15:12:45 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2023, 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 | |
Arvind Ram Prakash | b5d9559 | 2023-11-08 12:28:30 -0600 | [diff] [blame] | 14 | void mpam_enable_per_world(per_world_context_t *per_world_ctx) |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 15 | { |
Arvind Ram Prakash | ab28d4b | 2023-10-11 12:10:56 -0500 | [diff] [blame] | 16 | u_register_t mpam3_el3; |
| 17 | |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 18 | /* |
| 19 | * Enable MPAM, and disable trapping to EL3 when lower ELs access their |
Arvind Ram Prakash | ab28d4b | 2023-10-11 12:10:56 -0500 | [diff] [blame] | 20 | * own MPAM registers |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 21 | */ |
Arvind Ram Prakash | b5d9559 | 2023-11-08 12:28:30 -0600 | [diff] [blame] | 22 | mpam3_el3 = per_world_ctx->ctx_mpam3_el3; |
Arvind Ram Prakash | ab28d4b | 2023-10-11 12:10:56 -0500 | [diff] [blame] | 23 | mpam3_el3 = (mpam3_el3 | MPAM3_EL3_MPAMEN_BIT) & |
| 24 | ~(MPAM3_EL3_TRAPLOWER_BIT); |
Arvind Ram Prakash | b5d9559 | 2023-11-08 12:28:30 -0600 | [diff] [blame] | 25 | |
| 26 | per_world_ctx->ctx_mpam3_el3 = mpam3_el3; |
Boyan Karatotev | 6468d4a | 2023-02-16 15:12:45 +0000 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | /* |
| 30 | * If EL2 is implemented but unused, disable trapping to EL2 when lower ELs |
| 31 | * access their own MPAM registers. |
| 32 | */ |
| 33 | void mpam_init_el2_unused(void) |
| 34 | { |
| 35 | write_mpam2_el2(0ULL); |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 36 | |
Boyan Karatotev | 6468d4a | 2023-02-16 15:12:45 +0000 | [diff] [blame] | 37 | if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) { |
| 38 | write_mpamhcr_el2(0ULL); |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 39 | } |
Boyan Karatotev | 6468d4a | 2023-02-16 15:12:45 +0000 | [diff] [blame] | 40 | |
Jeenu Viswambharan | 2da918c | 2018-07-31 16:13:33 +0100 | [diff] [blame] | 41 | } |