trbe.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/trbe.h>
  10. void trbe_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.NSTBE = 0b0
  16. * Trace Buffer owning Security state is Non-secure state. If FEAT_RME
  17. * is not implemented, this field is RES0.
  18. *
  19. * MDCR_EL3.NSTB = 0b11
  20. * Allow access of trace buffer control registers from NS-EL1 and
  21. * NS-EL2, tracing is prohibited in Secure and Realm state (if
  22. * implemented).
  23. */
  24. mdcr_el3_val |= MDCR_NSTB(MDCR_NSTB_EL1);
  25. mdcr_el3_val &= ~(MDCR_NSTBE_BIT);
  26. write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
  27. }
  28. void trbe_disable(cpu_context_t *ctx)
  29. {
  30. el3_state_t *state = get_el3state_ctx(ctx);
  31. u_register_t mdcr_el3_val = read_ctx_reg(state, CTX_MDCR_EL3);
  32. /*
  33. * MDCR_EL3.NSTBE = 0b0
  34. * Trace Buffer owning Security state is secure state. If FEAT_RME
  35. * is not implemented, this field is RES0.
  36. *
  37. * MDCR_EL3.NSTB = 0b00
  38. * Clear these bits to disable access of trace buffer control registers
  39. * from lower ELs in any security state.
  40. */
  41. mdcr_el3_val &= ~(MDCR_NSTB(MDCR_NSTB_EL1));
  42. mdcr_el3_val &= ~(MDCR_NSTBE_BIT);
  43. write_ctx_reg(state, CTX_MDCR_EL3, mdcr_el3_val);
  44. }
  45. void trbe_init_el2_unused(void)
  46. {
  47. /*
  48. * MDCR_EL2.E2TB: Set to zero so that the trace Buffer
  49. * owning exception level is NS-EL1 and, tracing is
  50. * prohibited at NS-EL2. These bits are RES0 when
  51. * FEAT_TRBE is not implemented.
  52. */
  53. write_mdcr_el2(read_mdcr_el2() & ~MDCR_EL2_E2TB(MDCR_EL2_E2TB_EL1));
  54. }