brbe.c 748 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2022-2024, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <arch.h>
  7. #include <arch_features.h>
  8. #include <arch_helpers.h>
  9. #include <lib/extensions/brbe.h>
  10. void brbe_enable(cpu_context_t *ctx)
  11. {
  12. el3_state_t *state = get_el3state_ctx(ctx);
  13. u_register_t mdcr_el3_val = read_ctx_reg(state, CTX_MDCR_EL3);
  14. /*
  15. * MDCR_EL3.SBRBE = 0b01
  16. * Allows BRBE usage in non-secure world and prohibited in
  17. * secure world.
  18. *
  19. * MDCR_EL3.{E3BREW, E3BREC} = 0b00
  20. * Branch recording at EL3 is disabled
  21. */
  22. mdcr_el3_val &= ~((MDCR_SBRBE_MASK << MDCR_SBRBE_SHIFT) | MDCR_E3BREW | MDCR_E3BREC);
  23. mdcr_el3_val |= (0x1UL << MDCR_SBRBE_SHIFT);
  24. write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
  25. }