This source file includes following definitions.
- can_use_mips_counter
- get_cycles
- random_get_entropy
1
2
3
4
5
6
7
8
9 #ifndef _ASM_TIMEX_H
10 #define _ASM_TIMEX_H
11
12 #ifdef __KERNEL__
13
14 #include <linux/compiler.h>
15
16 #include <asm/cpu.h>
17 #include <asm/cpu-features.h>
18 #include <asm/mipsregs.h>
19 #include <asm/cpu-type.h>
20
21
22
23
24
25
26
27 #define CLOCK_TICK_RATE 1193182
28
29
30
31
32
33
34
35
36
37
38
39
40 typedef unsigned int cycles_t;
41
42
43
44
45
46
47
48
49
50
51
52 static inline int can_use_mips_counter(unsigned int prid)
53 {
54 int comp = (prid & PRID_COMP_MASK) != PRID_COMP_LEGACY;
55
56 if (__builtin_constant_p(cpu_has_counter) && !cpu_has_counter)
57 return 0;
58 else if (__builtin_constant_p(cpu_has_mips_r) && cpu_has_mips_r)
59 return 1;
60 else if (likely(!__builtin_constant_p(cpu_has_mips_r) && comp))
61 return 1;
62
63 if (!__builtin_constant_p(cpu_has_counter))
64 asm volatile("" : "=m" (cpu_data[0].options));
65 if (likely(cpu_has_counter &&
66 prid >= (PRID_IMP_R4000 | PRID_REV_ENCODE_44(5, 0))))
67 return 1;
68 else
69 return 0;
70 }
71
72 static inline cycles_t get_cycles(void)
73 {
74 if (can_use_mips_counter(read_c0_prid()))
75 return read_c0_count();
76 else
77 return 0;
78 }
79
80
81
82
83
84
85
86
87 static inline unsigned long random_get_entropy(void)
88 {
89 unsigned int prid = read_c0_prid();
90 unsigned int imp = prid & PRID_IMP_MASK;
91
92 if (can_use_mips_counter(prid))
93 return read_c0_count();
94 else if (likely(imp != PRID_IMP_R6000 && imp != PRID_IMP_R6000A))
95 return read_c0_random();
96 else
97 return 0;
98 }
99 #define random_get_entropy random_get_entropy
100
101 #endif
102
103 #endif