timex.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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) 1998, 1999, 2003 by Ralf Baechle
  7. */
  8. #ifndef _ASM_TIMEX_H
  9. #define _ASM_TIMEX_H
  10. #ifdef __KERNEL__
  11. #include <asm/cpu-features.h>
  12. #include <asm/mipsregs.h>
  13. #include <asm/cpu-type.h>
  14. /*
  15. * This is the clock rate of the i8253 PIT. A MIPS system may not have
  16. * a PIT by the symbol is used all over the kernel including some APIs.
  17. * So keeping it defined to the number for the PIT is the only sane thing
  18. * for now.
  19. */
  20. #define CLOCK_TICK_RATE 1193182
  21. /*
  22. * Standard way to access the cycle counter.
  23. * Currently only used on SMP for scheduling.
  24. *
  25. * Only the low 32 bits are available as a continuously counting entity.
  26. * But this only means we'll force a reschedule every 8 seconds or so,
  27. * which isn't an evil thing.
  28. *
  29. * We know that all SMP capable CPUs have cycle counters.
  30. */
  31. typedef unsigned int cycles_t;
  32. /*
  33. * On R4000/R4400 before version 5.0 an erratum exists such that if the
  34. * cycle counter is read in the exact moment that it is matching the
  35. * compare register, no interrupt will be generated.
  36. *
  37. * There is a suggested workaround and also the erratum can't strike if
  38. * the compare interrupt isn't being used as the clock source device.
  39. * However for now the implementaton of this function doesn't get these
  40. * fine details right.
  41. */
  42. static inline cycles_t get_cycles(void)
  43. {
  44. switch (boot_cpu_type()) {
  45. case CPU_R4400PC:
  46. case CPU_R4400SC:
  47. case CPU_R4400MC:
  48. if ((read_c0_prid() & 0xff) >= 0x0050)
  49. return read_c0_count();
  50. break;
  51. case CPU_R4000PC:
  52. case CPU_R4000SC:
  53. case CPU_R4000MC:
  54. break;
  55. default:
  56. if (cpu_has_counter)
  57. return read_c0_count();
  58. break;
  59. }
  60. return 0; /* no usable counter */
  61. }
  62. #endif /* __KERNEL__ */
  63. #endif /* _ASM_TIMEX_H */