trf.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. * Copyright (c) 2021-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/trf.h>
  10. void trf_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.STE = b0
  16. * Trace prohibited in Secure state unless overridden by the
  17. * IMPLEMENTATION DEFINED authentication interface.
  18. *
  19. * MDCR_EL3.TTRF = b0
  20. * Allow access of trace filter control registers from NS-EL2
  21. * and NS-EL1 when NS-EL2 is implemented but not used
  22. */
  23. mdcr_el3_val &= ~(MDCR_STE_BIT | MDCR_TTRF_BIT);
  24. write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
  25. }
  26. void trf_init_el2_unused(void)
  27. {
  28. /*
  29. * MDCR_EL2.TTRF: Set to zero so that access to Trace
  30. * Filter Control register TRFCR_EL1 at EL1 is not
  31. * trapped to EL2. This bit is RES0 in versions of
  32. * the architecture earlier than ARMv8.4.
  33. *
  34. */
  35. write_mdcr_el2(read_mdcr_el2() & ~MDCR_EL2_TTRF);
  36. }