blob: 5285b96dea04012949479777ad5bbd7e597d09a4 [file] [log] [blame]
Jeenu Viswambharan5f835912018-07-31 16:13:33 +01001/*
Boyan Karatotev60d330d2023-02-16 15:12:45 +00002 * Copyright (c) 2018-2023, Arm Limited and Contributors. All rights reserved.
Jeenu Viswambharan5f835912018-07-31 16:13:33 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +00007#include <stdbool.h>
8
Jeenu Viswambharan5f835912018-07-31 16:13:33 +01009#include <arch.h>
Alexei Fedorovdbcc44a2020-05-26 13:16:41 +010010#include <arch_features.h>
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010011#include <arch_helpers.h>
Antonio Nino Diaz09d40e02018-12-14 00:18:21 +000012#include <lib/extensions/mpam.h>
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010013
Arvind Ram Prakashac4f6aa2023-11-08 12:28:30 -060014void mpam_enable_per_world(per_world_context_t *per_world_ctx)
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010015{
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -050016 u_register_t mpam3_el3;
17
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010018 /*
19 * Enable MPAM, and disable trapping to EL3 when lower ELs access their
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -050020 * own MPAM registers
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010021 */
Arvind Ram Prakashac4f6aa2023-11-08 12:28:30 -060022 mpam3_el3 = per_world_ctx->ctx_mpam3_el3;
Arvind Ram Prakashedebefb2023-10-11 12:10:56 -050023 mpam3_el3 = (mpam3_el3 | MPAM3_EL3_MPAMEN_BIT) &
24 ~(MPAM3_EL3_TRAPLOWER_BIT);
Arvind Ram Prakashac4f6aa2023-11-08 12:28:30 -060025
26 per_world_ctx->ctx_mpam3_el3 = mpam3_el3;
Boyan Karatotev60d330d2023-02-16 15:12:45 +000027}
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010028
Boyan Karatotev60d330d2023-02-16 15:12:45 +000029/*
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);
36
37 if ((read_mpamidr_el1() & MPAMIDR_HAS_HCR_BIT) != 0U) {
38 write_mpamhcr_el2(0ULL);
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010039 }
Boyan Karatotev60d330d2023-02-16 15:12:45 +000040
Jeenu Viswambharan5f835912018-07-31 16:13:33 +010041}