timex.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. extern unsigned long ccount_freq;
  33. typedef unsigned long long cycles_t;
  34. /*
  35. * Only used for SMP.
  36. */
  37. extern cycles_t cacheflush_time;
  38. #define get_cycles() (0)
  39. /*
  40. * Register access.
  41. */
  42. #define WSR_CCOUNT(r) asm volatile ("wsr %0, ccount" :: "a" (r))
  43. #define RSR_CCOUNT(r) asm volatile ("rsr %0, ccount" : "=a" (r))
  44. #define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
  45. #define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
  46. static inline unsigned long get_ccount (void)
  47. {
  48. unsigned long ccount;
  49. RSR_CCOUNT(ccount);
  50. return ccount;
  51. }
  52. static inline void set_ccount (unsigned long ccount)
  53. {
  54. WSR_CCOUNT(ccount);
  55. }
  56. static inline unsigned long get_linux_timer (void)
  57. {
  58. unsigned ccompare;
  59. RSR_CCOMPARE(LINUX_TIMER, ccompare);
  60. return ccompare;
  61. }
  62. static inline void set_linux_timer (unsigned long ccompare)
  63. {
  64. WSR_CCOMPARE(LINUX_TIMER, ccompare);
  65. }
  66. #endif /* __KERNEL__ */
  67. #endif /* _XTENSA_TIMEX_H */