timex.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * include/asm-xtensa/timex.h
  3. *
  4. * This file is subject to the terms and conditions of the GNU General Public
  5. * License. See the file "COPYING" in the main directory of this archive
  6. * for more details.
  7. *
  8. * Copyright (C) 2001 - 2008 Tensilica Inc.
  9. */
  10. #ifndef _XTENSA_TIMEX_H
  11. #define _XTENSA_TIMEX_H
  12. #ifdef __KERNEL__
  13. #include <asm/processor.h>
  14. #include <linux/stringify.h>
  15. #define _INTLEVEL(x) XCHAL_INT ## x ## _LEVEL
  16. #define INTLEVEL(x) _INTLEVEL(x)
  17. #if XCHAL_NUM_TIMERS > 0 && \
  18. INTLEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL
  19. # define LINUX_TIMER 0
  20. # define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
  21. #elif XCHAL_NUM_TIMERS > 1 && \
  22. INTLEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL
  23. # define LINUX_TIMER 1
  24. # define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
  25. #elif XCHAL_NUM_TIMERS > 2 && \
  26. INTLEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL
  27. # define LINUX_TIMER 2
  28. # define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
  29. #else
  30. # error "Bad timer number for Linux configurations!"
  31. #endif
  32. #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
  33. extern unsigned long ccount_freq;
  34. #define CCOUNT_PER_JIFFY (ccount_freq / HZ)
  35. #else
  36. #define CCOUNT_PER_JIFFY (CONFIG_XTENSA_CPU_CLOCK*(1000000UL/HZ))
  37. #endif
  38. typedef unsigned long long cycles_t;
  39. /*
  40. * Only used for SMP.
  41. */
  42. extern cycles_t cacheflush_time;
  43. #define get_cycles() (0)
  44. /*
  45. * Register access.
  46. */
  47. #define WSR_CCOUNT(r) asm volatile ("wsr %0, ccount" :: "a" (r))
  48. #define RSR_CCOUNT(r) asm volatile ("rsr %0, ccount" : "=a" (r))
  49. #define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
  50. #define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
  51. static inline unsigned long get_ccount (void)
  52. {
  53. unsigned long ccount;
  54. RSR_CCOUNT(ccount);
  55. return ccount;
  56. }
  57. static inline void set_ccount (unsigned long ccount)
  58. {
  59. WSR_CCOUNT(ccount);
  60. }
  61. static inline unsigned long get_linux_timer (void)
  62. {
  63. unsigned ccompare;
  64. RSR_CCOMPARE(LINUX_TIMER, ccompare);
  65. return ccompare;
  66. }
  67. static inline void set_linux_timer (unsigned long ccompare)
  68. {
  69. WSR_CCOMPARE(LINUX_TIMER, ccompare);
  70. }
  71. #endif /* __KERNEL__ */
  72. #endif /* _XTENSA_TIMEX_H */