timex.h 1.8 KB

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