This source file includes following definitions.
- k6_powernow_init
- k6_powernow_setperf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 #include <sys/param.h>
25 #include <sys/sysctl.h>
26
27 #include <machine/cpu.h>
28 #include <machine/cpufunc.h>
29 #include <machine/specialreg.h>
30 #include <machine/pio.h>
31
32
33 struct {
34 int mult;
35 int magic;
36 } k6_multipliers[] = {
37 { 20, 4 },
38 { 30, 5 },
39 { 35, 7 },
40 { 40, 2 },
41 { 45, 0 },
42 { 55, 3 },
43 { 50, 1 },
44 { 60, 6 },
45 };
46 #define NUM_K6_ENTRIES (sizeof k6_multipliers / sizeof k6_multipliers[0])
47
48 int k6_maxindex;
49
50
51 #define K6PORT 0xfff0
52
53 void
54 k6_powernow_init(void)
55 {
56 uint64_t msrval;
57 uint32_t portval;
58 int i;
59
60
61 msrval = K6PORT | 0x1;
62 wrmsr(MSR_K6_EPMR, msrval);
63
64 portval = inl(K6PORT + 8);
65
66 wrmsr(MSR_K6_EPMR, 0LL);
67
68 portval = (portval >> 5) & 7;
69
70 for (i = 0; i < NUM_K6_ENTRIES; i++)
71 if (portval == k6_multipliers[i].magic) {
72 k6_maxindex = i;
73 break;
74 }
75 if (i == NUM_K6_ENTRIES) {
76 printf("bad value for current multiplier\n");
77 return;
78 }
79
80 cpu_setperf = k6_powernow_setperf;
81 }
82
83 void
84 k6_powernow_setperf(int level)
85 {
86 uint64_t msrval;
87 uint32_t portval;
88 int index;
89
90 index = level * k6_maxindex / 100;
91
92
93 msrval = K6PORT | 0x1;
94 wrmsr(MSR_K6_EPMR, msrval);
95
96 portval = inl(K6PORT + 8);
97 portval &= 0xf;
98 portval |= 1 << 12 | 1 << 10 | 1 << 9 |
99 k6_multipliers[index].magic << 5;
100 outl(K6PORT + 8, portval);
101
102 wrmsr(MSR_K6_EPMR, 0LL);
103 }