johpow01 | 8186596 | 2022-01-28 17:06:20 -0600 | [diff] [blame] | 1 | /* |
Jayanth Dodderi Chidanand | 118b335 | 2024-06-18 15:22:54 +0100 | [diff] [blame] | 2 | * Copyright (c) 2022-2024, Arm Limited. All rights reserved. |
johpow01 | 8186596 | 2022-01-28 17:06:20 -0600 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <arch.h> |
Jayanth Dodderi Chidanand | 6931675 | 2022-05-09 12:33:03 +0100 | [diff] [blame] | 8 | #include <arch_features.h> |
johpow01 | 8186596 | 2022-01-28 17:06:20 -0600 | [diff] [blame] | 9 | #include <arch_helpers.h> |
Boyan Karatotev | 6468d4a | 2023-02-16 15:12:45 +0000 | [diff] [blame] | 10 | #include <lib/extensions/brbe.h> |
johpow01 | 8186596 | 2022-01-28 17:06:20 -0600 | [diff] [blame] | 11 | |
Jayanth Dodderi Chidanand | 118b335 | 2024-06-18 15:22:54 +0100 | [diff] [blame] | 12 | void brbe_enable(cpu_context_t *ctx) |
johpow01 | 8186596 | 2022-01-28 17:06:20 -0600 | [diff] [blame] | 13 | { |
Jayanth Dodderi Chidanand | 118b335 | 2024-06-18 15:22:54 +0100 | [diff] [blame] | 14 | el3_state_t *state = get_el3state_ctx(ctx); |
| 15 | u_register_t mdcr_el3_val = read_ctx_reg(state, CTX_MDCR_EL3); |
johpow01 | 8186596 | 2022-01-28 17:06:20 -0600 | [diff] [blame] | 16 | |
Andre Przywara | c97c551 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 17 | /* |
| 18 | * MDCR_EL3.SBRBE = 0b01 |
Andre Przywara | c97c551 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 19 | * Allows BRBE usage in non-secure world and prohibited in |
| 20 | * secure world. |
Boyan Karatotev | 066978e | 2024-10-18 11:02:54 +0100 | [diff] [blame^] | 21 | * |
| 22 | * MDCR_EL3.{E3BREW, E3BREC} = 0b00 |
| 23 | * Branch recording at EL3 is disabled |
Andre Przywara | c97c551 | 2022-11-17 16:42:09 +0000 | [diff] [blame] | 24 | */ |
Boyan Karatotev | 066978e | 2024-10-18 11:02:54 +0100 | [diff] [blame^] | 25 | mdcr_el3_val &= ~((MDCR_SBRBE_MASK << MDCR_SBRBE_SHIFT) | MDCR_E3BREW | MDCR_E3BREC); |
Jayanth Dodderi Chidanand | 118b335 | 2024-06-18 15:22:54 +0100 | [diff] [blame] | 26 | mdcr_el3_val |= (0x1UL << MDCR_SBRBE_SHIFT); |
| 27 | write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val); |
johpow01 | 8186596 | 2022-01-28 17:06:20 -0600 | [diff] [blame] | 28 | } |