pmuv3.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2023, 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/pmuv3.h>
  10. static u_register_t mtpmu_disable_el3(u_register_t sdcr)
  11. {
  12. if (!is_feat_mtpmu_supported()) {
  13. return sdcr;
  14. }
  15. /*
  16. * SDCR.MTPME = 0
  17. * FEAT_MTPMU is disabled. The Effective value of PMEVTYPER<n>.MT is
  18. * zero.
  19. */
  20. sdcr &= ~SDCR_MTPME_BIT;
  21. return sdcr;
  22. }
  23. void pmuv3_init_el3(void)
  24. {
  25. u_register_t sdcr = read_sdcr();
  26. /* ---------------------------------------------------------------------
  27. * Initialise SDCR, setting all the fields rather than relying on hw.
  28. *
  29. * SDCR.SCCD: Set to one so that cycle counting by PMCCNTR is prohibited
  30. * in Secure state. This bit is RES0 in versions of the architecture
  31. * earlier than ARMv8.5
  32. *
  33. * SDCR.SPME: Set to zero so that event counting is prohibited in Secure
  34. * state (and explicitly EL3 with later revisions). If ARMv8.2 Debug is
  35. * not implemented this bit does not have any effect on the counters
  36. * unless there is support for the implementation defined
  37. * authentication interface ExternalSecureNoninvasiveDebugEnabled().
  38. * ---------------------------------------------------------------------
  39. */
  40. sdcr = (sdcr | SDCR_SCCD_BIT) & ~SDCR_SPME_BIT;
  41. sdcr = mtpmu_disable_el3(sdcr);
  42. write_sdcr(sdcr);
  43. /* ---------------------------------------------------------------------
  44. * Initialise PMCR, setting all fields rather than relying
  45. * on hw. Some fields are architecturally UNKNOWN on reset.
  46. *
  47. * PMCR.DP: Set to one to prohibit cycle counting whilst in Secure mode.
  48. *
  49. * PMCR.X: Set to zero to disable export of events.
  50. *
  51. * PMCR.C: Set to one to reset PMCCNTR.
  52. *
  53. * PMCR.P: Set to one to reset each event counter PMEVCNTR<n> to zero.
  54. *
  55. * PMCR.E: Set to zero to disable cycle and event counters.
  56. * ---------------------------------------------------------------------
  57. */
  58. write_pmcr(read_pmcr() | PMCR_DP_BIT | PMCR_C_BIT | PMCR_P_BIT |
  59. ~(PMCR_X_BIT | PMCR_E_BIT));
  60. }