arch_timer.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef __ASMARM_ARCH_TIMER_H
  2. #define __ASMARM_ARCH_TIMER_H
  3. #include <asm/barrier.h>
  4. #include <asm/errno.h>
  5. #include <linux/clocksource.h>
  6. #include <linux/init.h>
  7. #include <linux/types.h>
  8. #include <clocksource/arm_arch_timer.h>
  9. #ifdef CONFIG_ARM_ARCH_TIMER
  10. int arch_timer_arch_init(void);
  11. /*
  12. * These register accessors are marked inline so the compiler can
  13. * nicely work out which register we want, and chuck away the rest of
  14. * the code. At least it does so with a recent GCC (4.6.3).
  15. */
  16. static __always_inline
  17. void arch_timer_reg_write_cp15(int access, enum arch_timer_reg reg, u32 val)
  18. {
  19. if (access == ARCH_TIMER_PHYS_ACCESS) {
  20. switch (reg) {
  21. case ARCH_TIMER_REG_CTRL:
  22. asm volatile("mcr p15, 0, %0, c14, c2, 1" : : "r" (val));
  23. break;
  24. case ARCH_TIMER_REG_TVAL:
  25. asm volatile("mcr p15, 0, %0, c14, c2, 0" : : "r" (val));
  26. break;
  27. }
  28. } else if (access == ARCH_TIMER_VIRT_ACCESS) {
  29. switch (reg) {
  30. case ARCH_TIMER_REG_CTRL:
  31. asm volatile("mcr p15, 0, %0, c14, c3, 1" : : "r" (val));
  32. break;
  33. case ARCH_TIMER_REG_TVAL:
  34. asm volatile("mcr p15, 0, %0, c14, c3, 0" : : "r" (val));
  35. break;
  36. }
  37. }
  38. isb();
  39. }
  40. static __always_inline
  41. u32 arch_timer_reg_read_cp15(int access, enum arch_timer_reg reg)
  42. {
  43. u32 val = 0;
  44. if (access == ARCH_TIMER_PHYS_ACCESS) {
  45. switch (reg) {
  46. case ARCH_TIMER_REG_CTRL:
  47. asm volatile("mrc p15, 0, %0, c14, c2, 1" : "=r" (val));
  48. break;
  49. case ARCH_TIMER_REG_TVAL:
  50. asm volatile("mrc p15, 0, %0, c14, c2, 0" : "=r" (val));
  51. break;
  52. }
  53. } else if (access == ARCH_TIMER_VIRT_ACCESS) {
  54. switch (reg) {
  55. case ARCH_TIMER_REG_CTRL:
  56. asm volatile("mrc p15, 0, %0, c14, c3, 1" : "=r" (val));
  57. break;
  58. case ARCH_TIMER_REG_TVAL:
  59. asm volatile("mrc p15, 0, %0, c14, c3, 0" : "=r" (val));
  60. break;
  61. }
  62. }
  63. return val;
  64. }
  65. static inline u32 arch_timer_get_cntfrq(void)
  66. {
  67. u32 val;
  68. asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (val));
  69. return val;
  70. }
  71. static inline u64 arch_counter_get_cntpct(void)
  72. {
  73. u64 cval;
  74. isb();
  75. asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (cval));
  76. return cval;
  77. }
  78. static inline u64 arch_counter_get_cntvct(void)
  79. {
  80. u64 cval;
  81. isb();
  82. asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (cval));
  83. return cval;
  84. }
  85. static inline u32 arch_timer_get_cntkctl(void)
  86. {
  87. u32 cntkctl;
  88. asm volatile("mrc p15, 0, %0, c14, c1, 0" : "=r" (cntkctl));
  89. return cntkctl;
  90. }
  91. static inline void arch_timer_set_cntkctl(u32 cntkctl)
  92. {
  93. asm volatile("mcr p15, 0, %0, c14, c1, 0" : : "r" (cntkctl));
  94. }
  95. #endif
  96. #endif