This source file includes following definitions.
- cpu_khz_from_msr
1
2
3
4
5
6
7
8
9 #include <linux/kernel.h>
10
11 #include <asm/apic.h>
12 #include <asm/cpu_device_id.h>
13 #include <asm/intel-family.h>
14 #include <asm/msr.h>
15 #include <asm/param.h>
16 #include <asm/tsc.h>
17
18 #define MAX_NUM_FREQS 16
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #define TSC_REFERENCE_KHZ 100000
36
37 struct muldiv {
38 u32 multiplier;
39 u32 divider;
40 };
41
42
43
44
45
46
47
48
49 struct freq_desc {
50 bool use_msr_plat;
51 struct muldiv muldiv[MAX_NUM_FREQS];
52
53
54
55
56 u32 freqs[MAX_NUM_FREQS];
57 u32 mask;
58 };
59
60
61
62
63
64
65 static const struct freq_desc freq_desc_pnw = {
66 .use_msr_plat = false,
67 .freqs = { 0, 0, 0, 0, 0, 99840, 0, 83200 },
68 .mask = 0x07,
69 };
70
71 static const struct freq_desc freq_desc_clv = {
72 .use_msr_plat = false,
73 .freqs = { 0, 133200, 0, 0, 0, 99840, 0, 83200 },
74 .mask = 0x07,
75 };
76
77
78
79
80
81
82
83
84
85 static const struct freq_desc freq_desc_byt = {
86 .use_msr_plat = true,
87 .muldiv = { { 5, 6 }, { 1, 1 }, { 4, 3 }, { 7, 6 },
88 { 4, 5 } },
89 .mask = 0x07,
90 };
91
92
93
94
95
96
97
98
99
100
101
102
103
104 static const struct freq_desc freq_desc_cht = {
105 .use_msr_plat = true,
106 .muldiv = { { 5, 6 }, { 1, 1 }, { 4, 3 }, { 7, 6 },
107 { 4, 5 }, { 14, 15 }, { 9, 10 }, { 8, 9 },
108 { 7, 8 } },
109 .mask = 0x0f,
110 };
111
112
113
114
115
116
117 static const struct freq_desc freq_desc_tng = {
118 .use_msr_plat = true,
119 .muldiv = { { 0, 0 }, { 1, 1 }, { 4, 3 } },
120 .mask = 0x07,
121 };
122
123
124
125
126
127
128
129
130 static const struct freq_desc freq_desc_ann = {
131 .use_msr_plat = true,
132 .muldiv = { { 5, 6 }, { 1, 1 }, { 4, 3 }, { 1, 1 } },
133 .mask = 0x0f,
134 };
135
136
137 static const struct freq_desc freq_desc_lgm = {
138 .use_msr_plat = true,
139 .freqs = { 78000, 78000, 78000, 78000, 78000, 78000, 78000, 78000 },
140 .mask = 0x0f,
141 };
142
143 static const struct x86_cpu_id tsc_msr_cpu_ids[] = {
144 INTEL_CPU_FAM6(ATOM_SALTWELL_MID, freq_desc_pnw),
145 INTEL_CPU_FAM6(ATOM_SALTWELL_TABLET, freq_desc_clv),
146 INTEL_CPU_FAM6(ATOM_SILVERMONT, freq_desc_byt),
147 INTEL_CPU_FAM6(ATOM_SILVERMONT_MID, freq_desc_tng),
148 INTEL_CPU_FAM6(ATOM_AIRMONT, freq_desc_cht),
149 INTEL_CPU_FAM6(ATOM_AIRMONT_MID, freq_desc_ann),
150 INTEL_CPU_FAM6(ATOM_AIRMONT_NP, freq_desc_lgm),
151 {}
152 };
153
154
155
156
157
158
159
160 unsigned long cpu_khz_from_msr(void)
161 {
162 u32 lo, hi, ratio, freq, tscref;
163 const struct freq_desc *freq_desc;
164 const struct x86_cpu_id *id;
165 const struct muldiv *md;
166 unsigned long res;
167 int index;
168
169 id = x86_match_cpu(tsc_msr_cpu_ids);
170 if (!id)
171 return 0;
172
173 freq_desc = (struct freq_desc *)id->driver_data;
174 if (freq_desc->use_msr_plat) {
175 rdmsr(MSR_PLATFORM_INFO, lo, hi);
176 ratio = (lo >> 8) & 0xff;
177 } else {
178 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
179 ratio = (hi >> 8) & 0x1f;
180 }
181
182
183 rdmsr(MSR_FSB_FREQ, lo, hi);
184 index = lo & freq_desc->mask;
185 md = &freq_desc->muldiv[index];
186
187
188
189
190
191 if (md->divider) {
192 tscref = TSC_REFERENCE_KHZ * md->multiplier;
193 freq = DIV_ROUND_CLOSEST(tscref, md->divider);
194
195
196
197
198 res = DIV_ROUND_CLOSEST(tscref * ratio, md->divider);
199 } else {
200 freq = freq_desc->freqs[index];
201 res = freq * ratio;
202 }
203
204 if (freq == 0)
205 pr_err("Error MSR_FSB_FREQ index %d is unknown\n", index);
206
207 #ifdef CONFIG_X86_LOCAL_APIC
208 lapic_timer_period = (freq * 1000) / HZ;
209 #endif
210
211
212
213
214
215
216
217 setup_force_cpu_cap(X86_FEATURE_TSC_KNOWN_FREQ);
218
219
220
221
222
223
224
225
226
227 setup_force_cpu_cap(X86_FEATURE_TSC_RELIABLE);
228
229 return res;
230 }