timex.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #define _INTLEVEL(x) XCHAL_INT ## x ## _LEVEL
  13. #define INTLEVEL(x) _INTLEVEL(x)
  14. #if XCHAL_NUM_TIMERS > 0 && \
  15. INTLEVEL(XCHAL_TIMER0_INTERRUPT) <= XCHAL_EXCM_LEVEL
  16. # define LINUX_TIMER 0
  17. # define LINUX_TIMER_INT XCHAL_TIMER0_INTERRUPT
  18. #elif XCHAL_NUM_TIMERS > 1 && \
  19. INTLEVEL(XCHAL_TIMER1_INTERRUPT) <= XCHAL_EXCM_LEVEL
  20. # define LINUX_TIMER 1
  21. # define LINUX_TIMER_INT XCHAL_TIMER1_INTERRUPT
  22. #elif XCHAL_NUM_TIMERS > 2 && \
  23. INTLEVEL(XCHAL_TIMER2_INTERRUPT) <= XCHAL_EXCM_LEVEL
  24. # define LINUX_TIMER 2
  25. # define LINUX_TIMER_INT XCHAL_TIMER2_INTERRUPT
  26. #else
  27. # error "Bad timer number for Linux configurations!"
  28. #endif
  29. extern unsigned long ccount_freq;
  30. typedef unsigned long long cycles_t;
  31. #define get_cycles() (0)
  32. void local_timer_setup(unsigned cpu);
  33. /*
  34. * Register access.
  35. */
  36. #define WSR_CCOUNT(r) asm volatile ("wsr %0, ccount" :: "a" (r))
  37. #define RSR_CCOUNT(r) asm volatile ("rsr %0, ccount" : "=a" (r))
  38. #define WSR_CCOMPARE(x,r) asm volatile ("wsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) :: "a"(r))
  39. #define RSR_CCOMPARE(x,r) asm volatile ("rsr %0,"__stringify(SREG_CCOMPARE)"+"__stringify(x) : "=a"(r))
  40. static inline unsigned long get_ccount (void)
  41. {
  42. unsigned long ccount;
  43. RSR_CCOUNT(ccount);
  44. return ccount;
  45. }
  46. static inline void set_ccount (unsigned long ccount)
  47. {
  48. WSR_CCOUNT(ccount);
  49. }
  50. static inline unsigned long get_linux_timer (void)
  51. {
  52. unsigned ccompare;
  53. RSR_CCOMPARE(LINUX_TIMER, ccompare);
  54. return ccompare;
  55. }
  56. static inline void set_linux_timer (unsigned long ccompare)
  57. {
  58. WSR_CCOMPARE(LINUX_TIMER, ccompare);
  59. }
  60. #endif /* _XTENSA_TIMEX_H */