arch_timer.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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/types.h>
  7. #ifdef CONFIG_ARM_ARCH_TIMER
  8. int arch_timer_of_register(void);
  9. int arch_timer_sched_clock_init(void);
  10. struct timecounter *arch_timer_get_timecounter(void);
  11. #define ARCH_TIMER_CTRL_ENABLE (1 << 0)
  12. #define ARCH_TIMER_CTRL_IT_MASK (1 << 1)
  13. #define ARCH_TIMER_CTRL_IT_STAT (1 << 2)
  14. #define ARCH_TIMER_REG_CTRL 0
  15. #define ARCH_TIMER_REG_TVAL 1
  16. #define ARCH_TIMER_PHYS_ACCESS 0
  17. #define ARCH_TIMER_VIRT_ACCESS 1
  18. /*
  19. * These register accessors are marked inline so the compiler can
  20. * nicely work out which register we want, and chuck away the rest of
  21. * the code. At least it does so with a recent GCC (4.6.3).
  22. */
  23. static inline void arch_timer_reg_write(const int access, const int reg, u32 val)
  24. {
  25. if (access == ARCH_TIMER_PHYS_ACCESS) {
  26. switch (reg) {
  27. case ARCH_TIMER_REG_CTRL:
  28. asm volatile("mcr p15, 0, %0, c14, c2, 1" : : "r" (val));
  29. break;
  30. case ARCH_TIMER_REG_TVAL:
  31. asm volatile("mcr p15, 0, %0, c14, c2, 0" : : "r" (val));
  32. break;
  33. }
  34. }
  35. if (access == ARCH_TIMER_VIRT_ACCESS) {
  36. switch (reg) {
  37. case ARCH_TIMER_REG_CTRL:
  38. asm volatile("mcr p15, 0, %0, c14, c3, 1" : : "r" (val));
  39. break;
  40. case ARCH_TIMER_REG_TVAL:
  41. asm volatile("mcr p15, 0, %0, c14, c3, 0" : : "r" (val));
  42. break;
  43. }
  44. }
  45. isb();
  46. }
  47. static inline u32 arch_timer_reg_read(const int access, const int reg)
  48. {
  49. u32 val = 0;
  50. if (access == ARCH_TIMER_PHYS_ACCESS) {
  51. switch (reg) {
  52. case ARCH_TIMER_REG_CTRL:
  53. asm volatile("mrc p15, 0, %0, c14, c2, 1" : "=r" (val));
  54. break;
  55. case ARCH_TIMER_REG_TVAL:
  56. asm volatile("mrc p15, 0, %0, c14, c2, 0" : "=r" (val));
  57. break;
  58. }
  59. }
  60. if (access == ARCH_TIMER_VIRT_ACCESS) {
  61. switch (reg) {
  62. case ARCH_TIMER_REG_CTRL:
  63. asm volatile("mrc p15, 0, %0, c14, c3, 1" : "=r" (val));
  64. break;
  65. case ARCH_TIMER_REG_TVAL:
  66. asm volatile("mrc p15, 0, %0, c14, c3, 0" : "=r" (val));
  67. break;
  68. }
  69. }
  70. return val;
  71. }
  72. static inline u32 arch_timer_get_cntfrq(void)
  73. {
  74. u32 val;
  75. asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (val));
  76. return val;
  77. }
  78. static inline u64 arch_counter_get_cntpct(void)
  79. {
  80. u64 cval;
  81. isb();
  82. asm volatile("mrrc p15, 0, %Q0, %R0, c14" : "=r" (cval));
  83. return cval;
  84. }
  85. static inline u64 arch_counter_get_cntvct(void)
  86. {
  87. u64 cval;
  88. isb();
  89. asm volatile("mrrc p15, 1, %Q0, %R0, c14" : "=r" (cval));
  90. return cval;
  91. }
  92. #else
  93. static inline int arch_timer_of_register(void)
  94. {
  95. return -ENXIO;
  96. }
  97. static inline int arch_timer_sched_clock_init(void)
  98. {
  99. return -ENXIO;
  100. }
  101. static inline struct timecounter *arch_timer_get_timecounter(void)
  102. {
  103. return NULL;
  104. }
  105. #endif
  106. #endif