Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
1f729e06 | 2 | * (c) 2003-2006 Advanced Micro Devices, Inc. |
1da177e4 LT |
3 | * Your use of this code is subject to the terms and conditions of the |
4 | * GNU general public license version 2. See "COPYING" or | |
5 | * http://www.gnu.org/licenses/gpl.html | |
6 | */ | |
7 | ||
8 | struct powernow_k8_data { | |
9 | unsigned int cpu; | |
10 | ||
11 | u32 numps; /* number of p-states */ | |
12 | u32 batps; /* number of p-states supported on battery */ | |
c5829cd0 | 13 | u32 max_hw_pstate; /* maximum legal hardware pstate */ |
1da177e4 LT |
14 | |
15 | /* these values are constant when the PSB is used to determine | |
16 | * vid/fid pairings, but are modified during the ->target() call | |
17 | * when ACPI is used */ | |
18 | u32 rvo; /* ramp voltage offset */ | |
19 | u32 irt; /* isochronous relief time */ | |
20 | u32 vidmvs; /* usable value calculated from mvs */ | |
21 | u32 vstable; /* voltage stabilization time, units 20 us */ | |
22 | u32 plllock; /* pll lock time, units 1 us */ | |
841e40b3 | 23 | u32 exttype; /* extended interface = 1 */ |
1da177e4 | 24 | |
c5829cd0 ML |
25 | /* keep track of the current fid / vid or pstate */ |
26 | u32 currvid, currfid, currpstate; | |
1da177e4 LT |
27 | |
28 | /* the powernow_table includes all frequency and vid/fid pairings: | |
29 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. | |
30 | * frequency is in kHz */ | |
31 | struct cpufreq_frequency_table *powernow_table; | |
32 | ||
33 | #ifdef CONFIG_X86_POWERNOW_K8_ACPI | |
34 | /* the acpi table needs to be kept. it's only available if ACPI was | |
35 | * used to determine valid frequency/vid/fid states */ | |
34ae7f35 | 36 | struct acpi_processor_performance *acpi_data; |
1da177e4 | 37 | #endif |
1f729e06 DJ |
38 | /* we need to keep track of associated cores, but let cpufreq |
39 | * handle hotplug events - so just point at cpufreq pol->cpus | |
40 | * structure */ | |
41 | cpumask_t *available_cores; | |
34ae7f35 | 42 | cpumask_t starting_core_affinity; |
1da177e4 LT |
43 | }; |
44 | ||
45 | ||
46 | /* processor's cpuid instruction support */ | |
47 | #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */ | |
48 | #define CPUID_XFAM 0x0ff00000 /* extended family */ | |
49 | #define CPUID_XFAM_K8 0 | |
50 | #define CPUID_XMOD 0x000f0000 /* extended model */ | |
6c9cda78 | 51 | #define CPUID_XMOD_REV_MASK 0x000c0000 |
30046e58 | 52 | #define CPUID_XFAM_10H 0x00100000 /* family 0x10 */ |
1da177e4 LT |
53 | #define CPUID_USE_XFAM_XMOD 0x00000f00 |
54 | #define CPUID_GET_MAX_CAPABILITIES 0x80000000 | |
55 | #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007 | |
56 | #define P_STATE_TRANSITION_CAPABLE 6 | |
57 | ||
58 | /* Model Specific Registers for p-state transitions. MSRs are 64-bit. For */ | |
59 | /* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and */ | |
60 | /* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */ | |
61 | /* the register number is placed in ecx, and the data is returned in edx:eax. */ | |
62 | ||
63 | #define MSR_FIDVID_CTL 0xc0010041 | |
64 | #define MSR_FIDVID_STATUS 0xc0010042 | |
65 | ||
66 | /* Field definitions within the FID VID Low Control MSR : */ | |
67 | #define MSR_C_LO_INIT_FID_VID 0x00010000 | |
841e40b3 DJ |
68 | #define MSR_C_LO_NEW_VID 0x00003f00 |
69 | #define MSR_C_LO_NEW_FID 0x0000003f | |
1da177e4 LT |
70 | #define MSR_C_LO_VID_SHIFT 8 |
71 | ||
72 | /* Field definitions within the FID VID High Control MSR : */ | |
32ee8c3e | 73 | #define MSR_C_HI_STP_GNT_TO 0x000fffff |
1da177e4 LT |
74 | |
75 | /* Field definitions within the FID VID Low Status MSR : */ | |
841e40b3 DJ |
76 | #define MSR_S_LO_CHANGE_PENDING 0x80000000 /* cleared when completed */ |
77 | #define MSR_S_LO_MAX_RAMP_VID 0x3f000000 | |
1da177e4 LT |
78 | #define MSR_S_LO_MAX_FID 0x003f0000 |
79 | #define MSR_S_LO_START_FID 0x00003f00 | |
80 | #define MSR_S_LO_CURRENT_FID 0x0000003f | |
81 | ||
82 | /* Field definitions within the FID VID High Status MSR : */ | |
841e40b3 DJ |
83 | #define MSR_S_HI_MIN_WORKING_VID 0x3f000000 |
84 | #define MSR_S_HI_MAX_WORKING_VID 0x003f0000 | |
85 | #define MSR_S_HI_START_VID 0x00003f00 | |
86 | #define MSR_S_HI_CURRENT_VID 0x0000003f | |
87 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 | |
1da177e4 | 88 | |
1f729e06 DJ |
89 | |
90 | /* Hardware Pstate _PSS and MSR definitions */ | |
91 | #define USE_HW_PSTATE 0x00000080 | |
1f729e06 DJ |
92 | #define HW_PSTATE_MASK 0x00000007 |
93 | #define HW_PSTATE_VALID_MASK 0x80000000 | |
c5829cd0 ML |
94 | #define HW_PSTATE_MAX_MASK 0x000000f0 |
95 | #define HW_PSTATE_MAX_SHIFT 4 | |
1f729e06 DJ |
96 | #define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */ |
97 | #define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */ | |
98 | #define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */ | |
c5829cd0 | 99 | #define MSR_PSTATE_CUR_LIMIT 0xc0010061 /* pstate current limit MSR */ |
1f729e06 DJ |
100 | |
101 | /* define the two driver architectures */ | |
102 | #define CPU_OPTERON 0 | |
103 | #define CPU_HW_PSTATE 1 | |
104 | ||
105 | ||
1da177e4 LT |
106 | /* |
107 | * There are restrictions frequencies have to follow: | |
108 | * - only 1 entry in the low fid table ( <=1.4GHz ) | |
109 | * - lowest entry in the high fid table must be >= 2 * the entry in the | |
110 | * low fid table | |
111 | * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry | |
112 | * in the low fid table | |
019a61b9 LM |
113 | * - the parts can only step at <= 200 MHz intervals, odd fid values are |
114 | * supported in revision G and later revisions. | |
1da177e4 LT |
115 | * - lowest frequency must be >= interprocessor hypertransport link speed |
116 | * (only applies to MP systems obviously) | |
117 | */ | |
118 | ||
119 | /* fids (frequency identifiers) are arranged in 2 tables - lo and hi */ | |
019a61b9 | 120 | #define LO_FID_TABLE_TOP 7 /* fid values marking the boundary */ |
1da177e4 LT |
121 | #define HI_FID_TABLE_BOTTOM 8 /* between the low and high tables */ |
122 | ||
123 | #define LO_VCOFREQ_TABLE_TOP 1400 /* corresponding vco frequency values */ | |
124 | #define HI_VCOFREQ_TABLE_BOTTOM 1600 | |
125 | ||
126 | #define MIN_FREQ_RESOLUTION 200 /* fids jump by 2 matching freq jumps by 200 */ | |
127 | ||
128 | #define MAX_FID 0x2a /* Spec only gives FID values as far as 5 GHz */ | |
841e40b3 | 129 | #define LEAST_VID 0x3e /* Lowest (numerically highest) useful vid value */ |
1da177e4 LT |
130 | |
131 | #define MIN_FREQ 800 /* Min and max freqs, per spec */ | |
132 | #define MAX_FREQ 5000 | |
133 | ||
019a61b9 | 134 | #define INVALID_FID_MASK 0xffffffc0 /* not a valid fid if these bits are set */ |
841e40b3 DJ |
135 | #define INVALID_VID_MASK 0xffffffc0 /* not a valid vid if these bits are set */ |
136 | ||
137 | #define VID_OFF 0x3f | |
1da177e4 LT |
138 | |
139 | #define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */ | |
140 | ||
141 | #define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */ | |
142 | ||
143 | #define MAXIMUM_VID_STEPS 1 /* Current cpus only allow a single step of 25mV */ | |
27b46d76 | 144 | #define VST_UNITS_20US 20 /* Voltage Stabilization Time is in units of 20us */ |
1da177e4 LT |
145 | |
146 | /* | |
27b46d76 | 147 | * Most values of interest are encoded in a single field of the _PSS |
1da177e4 LT |
148 | * entries: the "control" value. |
149 | */ | |
32ee8c3e | 150 | |
1da177e4 LT |
151 | #define IRT_SHIFT 30 |
152 | #define RVO_SHIFT 28 | |
2bcad935 | 153 | #define EXT_TYPE_SHIFT 27 |
1da177e4 LT |
154 | #define PLL_L_SHIFT 20 |
155 | #define MVS_SHIFT 18 | |
156 | #define VST_SHIFT 11 | |
157 | #define VID_SHIFT 6 | |
158 | #define IRT_MASK 3 | |
159 | #define RVO_MASK 3 | |
2bcad935 | 160 | #define EXT_TYPE_MASK 1 |
1da177e4 LT |
161 | #define PLL_L_MASK 0x7f |
162 | #define MVS_MASK 3 | |
163 | #define VST_MASK 0x7f | |
164 | #define VID_MASK 0x1f | |
6cad647d LM |
165 | #define FID_MASK 0x1f |
166 | #define EXT_VID_MASK 0x3f | |
167 | #define EXT_FID_MASK 0x3f | |
1da177e4 LT |
168 | |
169 | ||
170 | /* | |
171 | * Version 1.4 of the PSB table. This table is constructed by BIOS and is | |
172 | * to tell the OS's power management driver which VIDs and FIDs are | |
173 | * supported by this particular processor. | |
174 | * If the data in the PSB / PST is wrong, then this driver will program the | |
175 | * wrong values into hardware, which is very likely to lead to a crash. | |
176 | */ | |
177 | ||
178 | #define PSB_ID_STRING "AMDK7PNOW!" | |
179 | #define PSB_ID_STRING_LEN 10 | |
180 | ||
181 | #define PSB_VERSION_1_4 0x14 | |
182 | ||
183 | struct psb_s { | |
184 | u8 signature[10]; | |
185 | u8 tableversion; | |
186 | u8 flags1; | |
187 | u16 vstable; | |
188 | u8 flags2; | |
189 | u8 num_tables; | |
190 | u32 cpuid; | |
191 | u8 plllocktime; | |
192 | u8 maxfid; | |
193 | u8 maxvid; | |
194 | u8 numps; | |
195 | }; | |
196 | ||
197 | /* Pairs of fid/vid values are appended to the version 1.4 PSB table. */ | |
198 | struct pst_s { | |
199 | u8 fid; | |
200 | u8 vid; | |
201 | }; | |
202 | ||
203 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k8", msg) | |
204 | ||
205 | static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid); | |
206 | static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid); | |
207 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid); | |
208 | ||
209 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); | |
065b807c | 210 | |
b96e80e3 | 211 | #ifdef CONFIG_X86_POWERNOW_K8_ACPI |
1f729e06 DJ |
212 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); |
213 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | |
b96e80e3 | 214 | #endif |
1f729e06 | 215 | |
065b807c DJ |
216 | #ifdef CONFIG_SMP |
217 | static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[]) | |
218 | { | |
219 | } | |
220 | #else | |
221 | static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[]) | |
222 | { | |
223 | cpu_set(0, cpu_sharedcore_mask[0]); | |
224 | } | |
225 | #endif |