blob: fef6647835117eb7ad520afa74abfc4ba7ce0dc5 [file] [log] [blame]
johpow0181865962022-01-28 17:06:20 -06001/*
Jayanth Dodderi Chidanand118b3352024-06-18 15:22:54 +01002 * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
johpow0181865962022-01-28 17:06:20 -06003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
Jayanth Dodderi Chidanand69316752022-05-09 12:33:03 +01008#include <arch_features.h>
johpow0181865962022-01-28 17:06:20 -06009#include <arch_helpers.h>
Boyan Karatotev6468d4a2023-02-16 15:12:45 +000010#include <lib/extensions/brbe.h>
johpow0181865962022-01-28 17:06:20 -060011
Jayanth Dodderi Chidanand118b3352024-06-18 15:22:54 +010012void brbe_enable(cpu_context_t *ctx)
johpow0181865962022-01-28 17:06:20 -060013{
Jayanth Dodderi Chidanand118b3352024-06-18 15:22:54 +010014 el3_state_t *state = get_el3state_ctx(ctx);
15 u_register_t mdcr_el3_val = read_ctx_reg(state, CTX_MDCR_EL3);
johpow0181865962022-01-28 17:06:20 -060016
Andre Przywarac97c5512022-11-17 16:42:09 +000017 /*
18 * MDCR_EL3.SBRBE = 0b01
Andre Przywarac97c5512022-11-17 16:42:09 +000019 * Allows BRBE usage in non-secure world and prohibited in
20 * secure world.
Boyan Karatotev066978e2024-10-18 11:02:54 +010021 *
22 * MDCR_EL3.{E3BREW, E3BREC} = 0b00
23 * Branch recording at EL3 is disabled
Andre Przywarac97c5512022-11-17 16:42:09 +000024 */
Boyan Karatotev066978e2024-10-18 11:02:54 +010025 mdcr_el3_val &= ~((MDCR_SBRBE_MASK << MDCR_SBRBE_SHIFT) | MDCR_E3BREW | MDCR_E3BREC);
Jayanth Dodderi Chidanand118b3352024-06-18 15:22:54 +010026 mdcr_el3_val |= (0x1UL << MDCR_SBRBE_SHIFT);
27 write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
johpow0181865962022-01-28 17:06:20 -060028}