arm64_user_sysreg.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: BSD-2-Clause */
  2. /*
  3. * Copyright (c) 2019, Linaro Limited
  4. */
  5. #ifndef ARM64_USER_SYSREG_H
  6. #define ARM64_USER_SYSREG_H
  7. #include <compiler.h>
  8. #include <stdint.h>
  9. /*
  10. * Templates for register read/write functions based on mrs/msr
  11. */
  12. #define DEFINE_REG_READ_FUNC_(reg, type, asmreg) \
  13. static inline __noprof type read_##reg(void) \
  14. { \
  15. uint64_t val64 = 0; \
  16. \
  17. asm volatile("mrs %0, " #asmreg : "=r" (val64)); \
  18. return val64; \
  19. }
  20. #define DEFINE_REG_WRITE_FUNC_(reg, type, asmreg) \
  21. static inline __noprof void write_##reg(type val) \
  22. { \
  23. uint64_t val64 = val; \
  24. \
  25. asm volatile("msr " #asmreg ", %0" : : "r" (val64)); \
  26. }
  27. /* ARM Generic timer functions */
  28. DEFINE_REG_READ_FUNC_(cntfrq, uint32_t, cntfrq_el0)
  29. DEFINE_REG_READ_FUNC_(cntpct, uint64_t, cntpct_el0)
  30. DEFINE_REG_READ_FUNC_(cntvct, uint64_t, cntvct_el0)
  31. DEFINE_REG_READ_FUNC_(tpidr_el0, uint64_t, tpidr_el0)
  32. DEFINE_REG_WRITE_FUNC_(tpidr_el0, uint64_t, tpidr_el0)
  33. #endif /*ARM64_USER_SYSREG_H*/