0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _ASM_TIMEX_H
0010 #define _ASM_TIMEX_H
0011
0012 #ifdef __KERNEL__
0013
0014 #include <linux/compiler.h>
0015
0016 #include <asm/cpu.h>
0017 #include <asm/cpu-features.h>
0018 #include <asm/mipsregs.h>
0019 #include <asm/cpu-type.h>
0020
0021
0022
0023
0024
0025
0026
0027 #define CLOCK_TICK_RATE 1193182
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 typedef unsigned int cycles_t;
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052 static inline int can_use_mips_counter(unsigned int prid)
0053 {
0054 int comp = (prid & PRID_COMP_MASK) != PRID_COMP_LEGACY;
0055
0056 if (__builtin_constant_p(cpu_has_counter) && !cpu_has_counter)
0057 return 0;
0058 else if (__builtin_constant_p(cpu_has_mips_r) && cpu_has_mips_r)
0059 return 1;
0060 else if (likely(!__builtin_constant_p(cpu_has_mips_r) && comp))
0061 return 1;
0062
0063 if (!__builtin_constant_p(cpu_has_counter))
0064 asm volatile("" : "=m" (cpu_data[0].options));
0065 if (likely(cpu_has_counter &&
0066 prid > (PRID_IMP_R4000 | PRID_REV_ENCODE_44(15, 15))))
0067 return 1;
0068 else
0069 return 0;
0070 }
0071
0072 static inline cycles_t get_cycles(void)
0073 {
0074 if (can_use_mips_counter(read_c0_prid()))
0075 return read_c0_count();
0076 else
0077 return 0;
0078 }
0079 #define get_cycles get_cycles
0080
0081
0082
0083
0084
0085 static inline unsigned long random_get_entropy(void)
0086 {
0087 unsigned int c0_random;
0088
0089 if (can_use_mips_counter(read_c0_prid()))
0090 return read_c0_count();
0091
0092 if (cpu_has_3kex)
0093 c0_random = (read_c0_random() >> 8) & 0x3f;
0094 else
0095 c0_random = read_c0_random() & 0x3f;
0096 return (random_get_entropy_fallback() << 6) | (0x3f - c0_random);
0097 }
0098 #define random_get_entropy random_get_entropy
0099
0100 #endif
0101
0102 #endif