1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
|
/*COPYRIGHT**
Copyright (C) 2005-2014 Intel Corporation. All Rights Reserved.
This file is part of SEP Development Kit
SEP Development Kit is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
SEP Development Kit is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SEP Development Kit; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
As a special exception, you may use this file as part of a free software
library without restriction. Specifically, if other files instantiate
templates or use macros or inline functions from this file, or you compile
this file and link it with other files to produce an executable, this
file does not by itself cause the resulting executable to be covered by
the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
**COPYRIGHT*/
#include "lwpmudrv_defines.h"
#include <linux/version.h>
#include <linux/fs.h>
#if defined(DRV_IA32) || defined(DRV_EM64T)
#include <asm/msr.h>
#endif
#include <linux/ptrace.h>
#include "lwpmudrv_types.h"
#include "rise_errors.h"
#include "lwpmudrv_ecb.h"
#include "lwpmudrv.h"
#if defined(DRV_IA32) || defined(DRV_EM64T)
#include "core2.h"
#include "perfver4.h"
#include "silvermont.h"
#include "valleyview_sochap.h"
#include "avt_unc_power.h"
#include "snb_unc_cbo.h"
#include "snb_unc_imc.h"
#include "snb_unc_power.h"
#include "snb_unc_gt.h"
#include "hsw_unc_ncu.h"
#include "hsw_unc_power.h"
#if !defined (DRV_ANDROID)
#include "corei7_unc.h"
#include "wsx_unc_imc.h"
#include "wsx_unc_qpi.h"
#include "wsx_unc_wbox.h"
#include "jkt_unc_imc.h"
#include "jkt_unc_qpill.h"
#include "jkt_unc_ubox.h"
#include "ivt_unc_cbo.h"
#include "ivt_unc_imc.h"
#include "ivt_unc_pcu.h"
#include "ivt_unc_ha.h"
#include "ivt_unc_qpill.h"
#include "ivt_unc_r3qpi.h"
#include "ivt_unc_ubox.h"
#include "ivt_unc_r2pcie.h"
#include "ivt_unc_irp.h"
#include "hsx_unc_cbo.h"
#include "hsx_unc_imc.h"
#include "hsx_unc_pcu.h"
#include "hsx_unc_ha.h"
#include "hsx_unc_qpill.h"
#include "hsx_unc_r3qpi.h"
#include "hsx_unc_ubox.h"
#include "hsx_unc_r2pcie.h"
#include "hsx_unc_sbox.h"
#include "hsx_unc_irp.h"
#include "skl_unc_cbo.h"
#include "skl_unc_ncu.h"
#include "chap.h"
#endif
#endif
#include "utility.h"
#include "lwpmudrv_chipset.h"
#include "gmch.h"
volatile int config_done;
extern CHIPSET_CONFIG pma;
extern DRV_BOOL
UTILITY_down_read_mm (
struct task_struct *p
)
{
#ifdef SUPPORTS_MMAP_READ
mmap_down_read(p->mm);
#else
down_read((struct rw_semaphore *) &p->mm->mmap_sem);
#endif
return TRUE;
}
extern VOID
UTILITY_up_read_mm (
struct task_struct *p
)
{
#ifdef SUPPORTS_MMAP_READ
mmap_up_read(p->mm);
#else
up_read((struct rw_semaphore *) &p->mm->mmap_sem);
#endif
return;
}
extern VOID
UTILITY_Read_TSC (
U64* pTsc
)
{
#if defined(DRV_IA32) || defined(DRV_EM64T)
rdtscll(*(pTsc));
#else
*(pTsc) = itp_get_itc();
#endif
return;
}
#if defined(DRV_IA32) || defined(DRV_EM64T)
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID UTILITY_Read_Cpuid
*
* @brief executes the cpuid_function of cpuid and returns values
*
* @param IN cpuid_function
* OUT rax - results of the cpuid instruction in the
* OUT rbx - corresponding registers
* OUT rcx
* OUT rdx
*
* @return none
*
* <I>Special Notes:</I>
* <NONE>
*
*/
extern VOID
UTILITY_Read_Cpuid (
U64 cpuid_function,
U64 *rax_value,
U64 *rbx_value,
U64 *rcx_value,
U64 *rdx_value
)
{
U32 function = (U32) cpuid_function;
U32 *eax = (U32 *) rax_value;
U32 *ebx = (U32 *) rbx_value;
U32 *ecx = (U32 *) rcx_value;
U32 *edx = (U32 *) rdx_value;
*eax = function;
__asm__("cpuid"
: "=a" (*eax),
"=b" (*ebx),
"=c" (*ecx),
"=d" (*edx)
: "a" (function),
"b" (*ebx),
"c" (*ecx),
"d" (*edx));
return;
}
#endif
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID UTILITY_Configure_CPU
*
* @brief Reads the CPU information from the hardware
*
* @param param dispatch_id - The id of the dispatch table.
*
* @return Pointer to the correct dispatch table for the CPU architecture
*
* <I>Special Notes:</I>
* <NONE>
*/
extern DISPATCH
UTILITY_Configure_CPU (
U32 dispatch_id
)
{
DISPATCH dispatch = NULL;
switch (dispatch_id) {
#if defined(DRV_IA32) || defined(DRV_EM64T)
case 1:
SEP_PRINT_DEBUG("Set up the Core(TM)2 processor dispatch table\n");
dispatch = &core2_dispatch;
break;
case 6:
SEP_PRINT_DEBUG("Set up the Silvermont dispatch table\n");
dispatch = &silvermont_dispatch;
break;
case 7:
SEP_PRINT_DEBUG("Set up the perfver4 HTON dispatch table such as Skylake\n");
dispatch = &perfver4_dispatch;
break;
case 8:
SEP_PRINT_DEBUG("Set up the perfver4 HTOFF dispatch table such as Skylake\n");
dispatch = &perfver4_dispatch_htoff_mode;
break;
case 700:
SEP_PRINT_DEBUG("Set up the Valleyview SA dispatch table\n");
dispatch = &valleyview_visa_dispatch;
break;
case 710:
case 800:
SEP_PRINT_DEBUG("Set up the Silvermont/Haswell Server Power dispatch table\n");
dispatch = &avoton_power_dispatch;
break;
case 2:
dispatch = &corei7_dispatch;
SEP_PRINT_DEBUG("Set up the Core i7(TM) processor dispatch table\n");
break;
case 3:
SEP_PRINT_DEBUG("Set up the Core i7(TM) dispatch table\n");
dispatch = &corei7_dispatch_htoff_mode;
break;
case 4:
dispatch = &corei7_dispatch_2;
SEP_PRINT_DEBUG("Set up the Sandybridge processor dispatch table\n");
break;
case 5:
SEP_PRINT_DEBUG("Set up the Sandybridge dispatch table\n");
dispatch = &corei7_dispatch_htoff_mode_2;
break;
case 9:
dispatch = &corei7_dispatch_nehalem;
SEP_PRINT_DEBUG("Set up the Nehalem, Westemere dispatch table\n");
break;
case 200:
SEP_PRINT_DEBUG("Set up the SNB iMC dispatch table\n");
dispatch = &snbunc_imc_dispatch;
break;
case 201:
SEP_PRINT_DEBUG("Set up the SNB Cbo dispatch table\n");
dispatch = &snbunc_cbo_dispatch;
break;
#if !defined (DRV_ANDROID)
case 100:
SEP_PRINT_DEBUG("Set up the Core i7 uncore dispatch table\n");
dispatch = &corei7_unc_dispatch;
break;
case 210:
SEP_PRINT_DEBUG("Set up the WSM-EX iMC dispatch table\n");
dispatch = &wsmexunc_imc_dispatch;
break;
case 211:
SEP_PRINT_DEBUG("Set up the WSM-EX QPI dispatch table\n");
dispatch = &wsmexunc_qpi_dispatch;
break;
case 212:
SEP_PRINT_DEBUG("Set up the WSM-EX WBOX dispatch table\n");
dispatch = &wsmexunc_wbox_dispatch;
break;
case 220:
SEP_PRINT_DEBUG("Set up the JKT IMC dispatch table\n");
dispatch = &jktunc_imc_dispatch;
break;
case 221:
SEP_PRINT_DEBUG("Set up the JKT QPILL dispatch table\n");
dispatch = &jktunc_qpill_dispatch;
break;
case 222:
SEP_PRINT_DEBUG("Set up the Jaketown UBOX dispatch table\n");
dispatch = &jaketown_ubox_dispatch;
break;
#endif
case 300:
SEP_PRINT_DEBUG("Set up the SNB Power dispatch table\n");
dispatch = &snb_power_dispatch;
break;
case 400:
SEP_PRINT_DEBUG("Set up the SNB Power dispatch table\n");
dispatch = &snbunc_gt_dispatch;
break;
case 500:
SEP_PRINT_DEBUG("Set up the Haswell UNC NCU dispatch table\n");
dispatch = &haswellunc_ncu_dispatch;
break;
#if !defined (DRV_ANDROID)
case 600:
SEP_PRINT_DEBUG("Set up the IVT UNC CBO dispatch table\n");
dispatch = &ivtunc_cbo_dispatch;
break;
case 610:
SEP_PRINT_DEBUG("Set up the IVT UNC IMC dispatch table\n");
dispatch = &ivtunc_imc_dispatch;
break;
case 620:
SEP_PRINT_DEBUG("Set up the Ivytown UNC PCU dispatch table\n");
dispatch = &ivytown_pcu_dispatch;
break;
case 630:
SEP_PRINT_DEBUG("Set up the Ivytown UNC PCU dispatch table\n");
dispatch = &ivytown_ha_dispatch;
break;
case 640:
SEP_PRINT_DEBUG("Set up the Ivytown QPI dispatch table\n");
dispatch = &ivytown_qpill_dispatch;
break;
case 650:
SEP_PRINT_DEBUG("Set up the Ivytown R3QPI dispatch table\n");
dispatch = &ivytown_r3qpi_dispatch;
break;
case 660:
SEP_PRINT_DEBUG("Set up the Ivytown UNC UBOX dispatch table\n");
dispatch = &ivytown_ubox_dispatch;
break;
case 670:
SEP_PRINT_DEBUG("Set up the Ivytown UNC R2PCIe dispatch table\n");
dispatch = &ivytown_r2pcie_dispatch;
break;
case 680:
SEP_PRINT_DEBUG("Set up the Ivytown UNC IRP dispatch table\n");
dispatch = &ivytown_irp_dispatch;
break;
#endif
case 720:
SEP_PRINT_DEBUG("Set up the Haswell Power dispatch table\n");
dispatch = &haswell_power_dispatch;
break;
#if !defined (DRV_ANDROID)
case 790:
SEP_PRINT_DEBUG("Set up the Haswell Server CBO dispatch table\n");
dispatch = &haswell_server_cbo_dispatch;
break;
case 791:
SEP_PRINT_DEBUG("Set up the Haswell Server PCU dispatch table\n");
dispatch = &haswell_server_pcu_dispatch;
break;
case 792:
SEP_PRINT_DEBUG("Set up the Haswell Server UBOX dispatch table\n");
dispatch = &haswell_server_ubox_dispatch;
break;
case 793:
SEP_PRINT_DEBUG("Set up the Haswell Server QPILL dispatch table\n");
dispatch = &haswell_server_qpill_dispatch;
break;
case 794:
SEP_PRINT_DEBUG("Set up the Haswell Server iMC dispatch table\n");
dispatch = &haswell_server_imc_dispatch;
break;
case 795:
SEP_PRINT_DEBUG("Set up the Haswell Server HA dispatch table\n");
dispatch = &haswell_server_ha_dispatch;
break;
case 796:
SEP_PRINT_DEBUG("Set up the Haswell Server R2PCIe dispatch table\n");
dispatch = &haswell_server_r2pcie_dispatch;
break;
case 797:
SEP_PRINT_DEBUG("Set up the Haswell Server R3QPI dispatch table\n");
dispatch = &haswell_server_r3qpi_dispatch;
break;
case 798:
SEP_PRINT_DEBUG("Set up the Haswell Server SBOX dispatch table\n");
dispatch = &haswell_server_sbox_dispatch;
break;
case 799:
SEP_PRINT_DEBUG("Set up the Haswell Server IRP dispatch table\n");
dispatch = &haswell_server_irp_dispatch;
break;
#endif
#endif
default:
dispatch = NULL;
SEP_PRINT_ERROR("Architecture not supported (dispatch_id=%d)\n", dispatch_id);
break;
}
return dispatch;
}
#if defined(DRV_IA32) || defined(DRV_EM64T)
extern U64
SYS_Read_MSR (
U32 msr
)
{
U64 val;
rdmsrl(msr, val);
return val;
}
/* ------------------------------------------------------------------------- */
/*!
* @fn VOID UTILITY_Configure_Chipset
*
* @brief Configures the chipset information
*
* @param none
*
* @return none
*
* <I>Special Notes:</I>
* <NONE>
*/
extern CS_DISPATCH
UTILITY_Configure_Chipset (
void
)
{
if (CHIPSET_CONFIG_gmch_chipset(pma)) {
cs_dispatch = &gmch_dispatch;
SEP_PRINT_DEBUG("UTLITY_Configure_Chipset: using GMCH dispatch table!\n");
}
#if !defined (DRV_ANDROID)
else if (CHIPSET_CONFIG_mch_chipset(pma) || CHIPSET_CONFIG_ich_chipset(pma)) {
cs_dispatch = &chap_dispatch;
SEP_PRINT_DEBUG("UTLITY_Configure_Chipset: using CHAP dispatch table!\n");
}
#endif
else {
SEP_PRINT_ERROR("UTLITY_Configure_Chipset: unable to map chipset dispatch table!\n");
}
SEP_PRINT_DEBUG("UTLITY_Configure_Chipset: exiting with cs_dispatch=0x%p\n", cs_dispatch);
return cs_dispatch;
}
#endif
|