blob: 5285b96dea04012949479777ad5bbd7e597d09a4 [file] [log] [blame]
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +01001/*
Boyan Karatotev6468d4a2023-02-16 15:12:45 +00002 * Copyright (c) 2018-2023, 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
Arvind Ram Prakashb5d95592023-11-08 12:28:30 -060014void mpam_enable_per_world(per_world_context_t *per_world_ctx)
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010015{
Arvind Ram Prakashab28d4b2023-10-11 12:10:56 -050016 u_register_t mpam3_el3;
17
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010018 /*
19 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
Arvind Ram Prakashab28d4b2023-10-11 12:10:56 -050020 * own MPAM registers
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010021 */
Arvind Ram Prakashb5d95592023-11-08 12:28:30 -060022 mpam3_el3 = per_world_ctx->ctx_mpam3_el3;
Arvind Ram Prakashab28d4b2023-10-11 12:10:56 -050023 mpam3_el3 = (mpam3_el3 | MPAM3_EL3_MPAMEN_BIT) &
24 ~(MPAM3_EL3_TRAPLOWER_BIT);
Arvind Ram Prakashb5d95592023-11-08 12:28:30 -060025
26 per_world_ctx->ctx_mpam3_el3 = mpam3_el3;
Boyan Karatotev6468d4a2023-02-16 15:12:45 +000027}
28
29/*
30 * If EL2 is implemented but unused, disable trapping to EL2 when lower ELs
31 * access their own MPAM registers.
32 */
33void mpam_init_el2_unused(void)
34{
35 write_mpam2_el2(0ULL);
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010036
Boyan Karatotev6468d4a2023-02-16 15:12:45 +000037 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
38 write_mpamhcr_el2(0ULL);
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010039 }
Boyan Karatotev6468d4a2023-02-16 15:12:45 +000040
Jeenu Viswambharan2da918c2018-07-31 16:13:33 +010041}