Luis Henriques | 21335d0 | 2009-04-23 19:45:04 +0100 | [diff] [blame] | 1 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 3 | * (c) 2003-2006 Advanced Micro Devices, Inc. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * Your use of this code is subject to the terms and conditions of the |
| 5 | * GNU general public license version 2. See "COPYING" or |
| 6 | * http://www.gnu.org/licenses/gpl.html |
| 7 | * |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 8 | * Support : mark.langsdorf@amd.com |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * |
| 10 | * Based on the powernow-k7.c module written by Dave Jones. |
Dave Jones | f4432c5 | 2008-10-20 13:31:45 -0400 | [diff] [blame] | 11 | * (C) 2003 Dave Jones on behalf of SuSE Labs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * (C) 2004 Dominik Brodowski <linux@brodo.de> |
| 13 | * (C) 2004 Pavel Machek <pavel@suse.cz> |
| 14 | * Licensed under the terms of the GNU GPL License version 2. |
| 15 | * Based upon datasheets & sample CPUs kindly provided by AMD. |
| 16 | * |
| 17 | * Valuable input gratefully received from Dave Jones, Pavel Machek, |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 18 | * Dominik Brodowski, Jacob Shin, and others. |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 19 | * Originally developed by Paul Devriendt. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | * Processor information obtained from Chapter 9 (Power and Thermal Management) |
| 21 | * of the "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD |
| 22 | * Opteron Processors" available for download from www.amd.com |
| 23 | * |
Dave Jones | 2e3f8fa | 2006-05-30 17:25:14 -0400 | [diff] [blame] | 24 | * Tables for specific CPUs can be inferred from |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 25 | * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/30430.pdf |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | */ |
| 27 | |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/smp.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
| 32 | #include <linux/cpufreq.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/string.h> |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 35 | #include <linux/cpumask.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 36 | #include <linux/sched.h> /* for current / set_cpus_allowed() */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 37 | #include <linux/io.h> |
| 38 | #include <linux/delay.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | #include <asm/msr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | #include <linux/acpi.h> |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 43 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
| 46 | #define PFX "powernow-k8: " |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 47 | #define VERSION "version 2.20.00" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include "powernow-k8.h" |
| 49 | |
| 50 | /* serialize freq changes */ |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 51 | static DEFINE_MUTEX(fidvid_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
travis@sgi.com | 2c6b8c0 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 53 | static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 55 | static int cpu_family = CPU_OPTERON; |
| 56 | |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 57 | #ifndef CONFIG_SMP |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 58 | static inline const struct cpumask *cpu_core_mask(int cpu) |
| 59 | { |
| 60 | return cpumask_of(0); |
| 61 | } |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 62 | #endif |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* Return a frequency in MHz, given an input fid */ |
| 65 | static u32 find_freq_from_fid(u32 fid) |
| 66 | { |
| 67 | return 800 + (fid * 100); |
| 68 | } |
| 69 | |
| 70 | /* Return a frequency in KHz, given an input fid */ |
| 71 | static u32 find_khz_freq_from_fid(u32 fid) |
| 72 | { |
| 73 | return 1000 * find_freq_from_fid(fid); |
| 74 | } |
| 75 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 76 | static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data, |
| 77 | u32 pstate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 79 | return data[pstate].frequency; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* Return the vco fid for an input fid |
| 83 | * |
| 84 | * Each "low" fid has corresponding "high" fid, and you can get to "low" fids |
| 85 | * only from corresponding high fids. This returns "high" fid corresponding to |
| 86 | * "low" one. |
| 87 | */ |
| 88 | static u32 convert_fid_to_vco_fid(u32 fid) |
| 89 | { |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 90 | if (fid < HI_FID_TABLE_BOTTOM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | return 8 + (2 * fid); |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 92 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | return fid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /* |
| 97 | * Return 1 if the pending bit is set. Unless we just instructed the processor |
| 98 | * to transition to a new state, seeing this bit set is really bad news. |
| 99 | */ |
| 100 | static int pending_bit_stuck(void) |
| 101 | { |
| 102 | u32 lo, hi; |
| 103 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 104 | if (cpu_family == CPU_HW_PSTATE) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 105 | return 0; |
| 106 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | rdmsr(MSR_FIDVID_STATUS, lo, hi); |
| 108 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; |
| 109 | } |
| 110 | |
| 111 | /* |
| 112 | * Update the global current fid / vid values from the status msr. |
| 113 | * Returns 1 on error. |
| 114 | */ |
| 115 | static int query_current_values_with_pending_wait(struct powernow_k8_data *data) |
| 116 | { |
| 117 | u32 lo, hi; |
| 118 | u32 i = 0; |
| 119 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 120 | if (cpu_family == CPU_HW_PSTATE) { |
Andreas Herrmann | a266d9f | 2008-11-21 14:49:25 +0100 | [diff] [blame] | 121 | if (data->currpstate == HW_PSTATE_INVALID) { |
| 122 | /* read (initial) hw pstate if not yet set */ |
| 123 | rdmsr(MSR_PSTATE_STATUS, lo, hi); |
| 124 | i = lo & HW_PSTATE_MASK; |
| 125 | |
| 126 | /* |
| 127 | * a workaround for family 11h erratum 311 might cause |
| 128 | * an "out-of-range Pstate if the core is in Pstate-0 |
| 129 | */ |
| 130 | if (i >= data->numps) |
| 131 | data->currpstate = HW_PSTATE_0; |
| 132 | else |
| 133 | data->currpstate = i; |
| 134 | } |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 135 | return 0; |
| 136 | } |
Dave Jones | 7153d96 | 2005-07-28 09:45:10 -0700 | [diff] [blame] | 137 | do { |
Dave Jones | 0213df7 | 2005-10-21 17:21:03 -0400 | [diff] [blame] | 138 | if (i++ > 10000) { |
| 139 | dprintk("detected change pending stuck\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | return 1; |
| 141 | } |
| 142 | rdmsr(MSR_FIDVID_STATUS, lo, hi); |
Dave Jones | 7153d96 | 2005-07-28 09:45:10 -0700 | [diff] [blame] | 143 | } while (lo & MSR_S_LO_CHANGE_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | data->currvid = hi & MSR_S_HI_CURRENT_VID; |
| 146 | data->currfid = lo & MSR_S_LO_CURRENT_FID; |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | /* the isochronous relief time */ |
| 152 | static void count_off_irt(struct powernow_k8_data *data) |
| 153 | { |
| 154 | udelay((1 << data->irt) * 10); |
| 155 | return; |
| 156 | } |
| 157 | |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 158 | /* the voltage stabilization time */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | static void count_off_vst(struct powernow_k8_data *data) |
| 160 | { |
| 161 | udelay(data->vstable * VST_UNITS_20US); |
| 162 | return; |
| 163 | } |
| 164 | |
| 165 | /* need to init the control msr to a safe value (for each cpu) */ |
| 166 | static void fidvid_msr_init(void) |
| 167 | { |
| 168 | u32 lo, hi; |
| 169 | u8 fid, vid; |
| 170 | |
| 171 | rdmsr(MSR_FIDVID_STATUS, lo, hi); |
| 172 | vid = hi & MSR_S_HI_CURRENT_VID; |
| 173 | fid = lo & MSR_S_LO_CURRENT_FID; |
| 174 | lo = fid | (vid << MSR_C_LO_VID_SHIFT); |
| 175 | hi = MSR_C_HI_STP_GNT_BENIGN; |
| 176 | dprintk("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), lo, hi); |
| 177 | wrmsr(MSR_FIDVID_CTL, lo, hi); |
| 178 | } |
| 179 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | /* write the new fid value along with the other control fields to the msr */ |
| 181 | static int write_new_fid(struct powernow_k8_data *data, u32 fid) |
| 182 | { |
| 183 | u32 lo; |
| 184 | u32 savevid = data->currvid; |
Dave Jones | 0213df7 | 2005-10-21 17:21:03 -0400 | [diff] [blame] | 185 | u32 i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) { |
| 188 | printk(KERN_ERR PFX "internal error - overflow on fid write\n"); |
| 189 | return 1; |
| 190 | } |
| 191 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 192 | lo = fid; |
| 193 | lo |= (data->currvid << MSR_C_LO_VID_SHIFT); |
| 194 | lo |= MSR_C_LO_INIT_FID_VID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
| 196 | dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n", |
| 197 | fid, lo, data->plllock * PLL_LOCK_CONVERSION); |
| 198 | |
Dave Jones | 0213df7 | 2005-10-21 17:21:03 -0400 | [diff] [blame] | 199 | do { |
| 200 | wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); |
| 201 | if (i++ > 100) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 202 | printk(KERN_ERR PFX |
| 203 | "Hardware error - pending bit very stuck - " |
| 204 | "no further pstate changes possible\n"); |
Chris Wright | 63172cb | 2005-10-21 16:56:08 -0700 | [diff] [blame] | 205 | return 1; |
Dave Jones | 32ee8c3 | 2006-02-28 00:43:23 -0500 | [diff] [blame] | 206 | } |
Dave Jones | 0213df7 | 2005-10-21 17:21:03 -0400 | [diff] [blame] | 207 | } while (query_current_values_with_pending_wait(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | count_off_irt(data); |
| 210 | |
| 211 | if (savevid != data->currvid) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 212 | printk(KERN_ERR PFX |
| 213 | "vid change on fid trans, old 0x%x, new 0x%x\n", |
| 214 | savevid, data->currvid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | return 1; |
| 216 | } |
| 217 | |
| 218 | if (fid != data->currfid) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 219 | printk(KERN_ERR PFX |
| 220 | "fid trans failed, fid 0x%x, curr 0x%x\n", fid, |
| 221 | data->currfid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | return 1; |
| 223 | } |
| 224 | |
| 225 | return 0; |
| 226 | } |
| 227 | |
| 228 | /* Write a new vid to the hardware */ |
| 229 | static int write_new_vid(struct powernow_k8_data *data, u32 vid) |
| 230 | { |
| 231 | u32 lo; |
| 232 | u32 savefid = data->currfid; |
Dave Jones | 0213df7 | 2005-10-21 17:21:03 -0400 | [diff] [blame] | 233 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
| 235 | if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) { |
| 236 | printk(KERN_ERR PFX "internal error - overflow on vid write\n"); |
| 237 | return 1; |
| 238 | } |
| 239 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 240 | lo = data->currfid; |
| 241 | lo |= (vid << MSR_C_LO_VID_SHIFT); |
| 242 | lo |= MSR_C_LO_INIT_FID_VID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
| 244 | dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n", |
| 245 | vid, lo, STOP_GRANT_5NS); |
| 246 | |
Dave Jones | 0213df7 | 2005-10-21 17:21:03 -0400 | [diff] [blame] | 247 | do { |
| 248 | wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS); |
Dave Jones | 6df8900 | 2005-11-30 13:33:30 -0800 | [diff] [blame] | 249 | if (i++ > 100) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 250 | printk(KERN_ERR PFX "internal error - pending bit " |
| 251 | "very stuck - no further pstate " |
| 252 | "changes possible\n"); |
Dave Jones | 6df8900 | 2005-11-30 13:33:30 -0800 | [diff] [blame] | 253 | return 1; |
| 254 | } |
Dave Jones | 0213df7 | 2005-10-21 17:21:03 -0400 | [diff] [blame] | 255 | } while (query_current_values_with_pending_wait(data)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | if (savefid != data->currfid) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 258 | printk(KERN_ERR PFX "fid changed on vid trans, old " |
| 259 | "0x%x new 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | savefid, data->currfid); |
| 261 | return 1; |
| 262 | } |
| 263 | |
| 264 | if (vid != data->currvid) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 265 | printk(KERN_ERR PFX "vid trans failed, vid 0x%x, " |
| 266 | "curr 0x%x\n", |
| 267 | vid, data->currvid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | return 1; |
| 269 | } |
| 270 | |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | /* |
| 275 | * Reduce the vid by the max of step or reqvid. |
| 276 | * Decreasing vid codes represent increasing voltages: |
Dave Jones | 841e40b | 2005-07-28 09:40:04 -0700 | [diff] [blame] | 277 | * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 279 | static int decrease_vid_code_by_step(struct powernow_k8_data *data, |
| 280 | u32 reqvid, u32 step) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | { |
| 282 | if ((data->currvid - reqvid) > step) |
| 283 | reqvid = data->currvid - step; |
| 284 | |
| 285 | if (write_new_vid(data, reqvid)) |
| 286 | return 1; |
| 287 | |
| 288 | count_off_vst(data); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 293 | /* Change hardware pstate by single MSR write */ |
| 294 | static int transition_pstate(struct powernow_k8_data *data, u32 pstate) |
| 295 | { |
| 296 | wrmsr(MSR_PSTATE_CTRL, pstate, 0); |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 297 | data->currpstate = pstate; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 302 | static int transition_fid_vid(struct powernow_k8_data *data, |
| 303 | u32 reqfid, u32 reqvid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | { |
| 305 | if (core_voltage_pre_transition(data, reqvid)) |
| 306 | return 1; |
| 307 | |
| 308 | if (core_frequency_transition(data, reqfid)) |
| 309 | return 1; |
| 310 | |
| 311 | if (core_voltage_post_transition(data, reqvid)) |
| 312 | return 1; |
| 313 | |
| 314 | if (query_current_values_with_pending_wait(data)) |
| 315 | return 1; |
| 316 | |
| 317 | if ((reqfid != data->currfid) || (reqvid != data->currvid)) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 318 | printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, " |
| 319 | "curr 0x%x 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | smp_processor_id(), |
| 321 | reqfid, reqvid, data->currfid, data->currvid); |
| 322 | return 1; |
| 323 | } |
| 324 | |
| 325 | dprintk("transitioned (cpu%d): new fid 0x%x, vid 0x%x\n", |
| 326 | smp_processor_id(), data->currfid, data->currvid); |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | /* Phase 1 - core voltage transition ... setup voltage */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 332 | static int core_voltage_pre_transition(struct powernow_k8_data *data, |
| 333 | u32 reqvid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
| 335 | u32 rvosteps = data->rvo; |
| 336 | u32 savefid = data->currfid; |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 337 | u32 maxvid, lo; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 339 | dprintk("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, " |
| 340 | "reqvid 0x%x, rvo 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | smp_processor_id(), |
| 342 | data->currfid, data->currvid, reqvid, data->rvo); |
| 343 | |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 344 | rdmsr(MSR_FIDVID_STATUS, lo, maxvid); |
| 345 | maxvid = 0x1f & (maxvid >> 16); |
| 346 | dprintk("ph1 maxvid=0x%x\n", maxvid); |
| 347 | if (reqvid < maxvid) /* lower numbers are higher voltages */ |
| 348 | reqvid = maxvid; |
| 349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | while (data->currvid > reqvid) { |
| 351 | dprintk("ph1: curr 0x%x, req vid 0x%x\n", |
| 352 | data->currvid, reqvid); |
| 353 | if (decrease_vid_code_by_step(data, reqvid, data->vidmvs)) |
| 354 | return 1; |
| 355 | } |
| 356 | |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 357 | while ((rvosteps > 0) && ((data->rvo + data->currvid) > reqvid)) { |
| 358 | if (data->currvid == maxvid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | rvosteps = 0; |
| 360 | } else { |
| 361 | dprintk("ph1: changing vid for rvo, req 0x%x\n", |
| 362 | data->currvid - 1); |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 363 | if (decrease_vid_code_by_step(data, data->currvid-1, 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | return 1; |
| 365 | rvosteps--; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | if (query_current_values_with_pending_wait(data)) |
| 370 | return 1; |
| 371 | |
| 372 | if (savefid != data->currfid) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 373 | printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n", |
| 374 | data->currfid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return 1; |
| 376 | } |
| 377 | |
| 378 | dprintk("ph1 complete, currfid 0x%x, currvid 0x%x\n", |
| 379 | data->currfid, data->currvid); |
| 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* Phase 2 - core frequency transition */ |
| 385 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid) |
| 386 | { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 387 | u32 vcoreqfid, vcocurrfid, vcofiddiff; |
| 388 | u32 fid_interval, savevid = data->currvid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 390 | if ((reqfid < HI_FID_TABLE_BOTTOM) && |
| 391 | (data->currfid < HI_FID_TABLE_BOTTOM)) { |
| 392 | printk(KERN_ERR PFX "ph2: illegal lo-lo transition " |
| 393 | "0x%x 0x%x\n", reqfid, data->currfid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | return 1; |
| 395 | } |
| 396 | |
| 397 | if (data->currfid == reqfid) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 398 | printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", |
| 399 | data->currfid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return 0; |
| 401 | } |
| 402 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 403 | dprintk("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, " |
| 404 | "reqfid 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | smp_processor_id(), |
| 406 | data->currfid, data->currvid, reqfid); |
| 407 | |
| 408 | vcoreqfid = convert_fid_to_vco_fid(reqfid); |
| 409 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); |
| 410 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid |
| 411 | : vcoreqfid - vcocurrfid; |
| 412 | |
| 413 | while (vcofiddiff > 2) { |
Langsdorf, Mark | 019a61b | 2005-11-29 14:18:03 -0600 | [diff] [blame] | 414 | (data->currfid & 1) ? (fid_interval = 1) : (fid_interval = 2); |
| 415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | if (reqfid > data->currfid) { |
| 417 | if (data->currfid > LO_FID_TABLE_TOP) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 418 | if (write_new_fid(data, |
| 419 | data->currfid + fid_interval)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | } else { |
| 422 | if (write_new_fid |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 423 | (data, |
| 424 | 2 + convert_fid_to_vco_fid(data->currfid))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | } else { |
Langsdorf, Mark | 019a61b | 2005-11-29 14:18:03 -0600 | [diff] [blame] | 428 | if (write_new_fid(data, data->currfid - fid_interval)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return 1; |
| 430 | } |
| 431 | |
| 432 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); |
| 433 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid |
| 434 | : vcoreqfid - vcocurrfid; |
| 435 | } |
| 436 | |
| 437 | if (write_new_fid(data, reqfid)) |
| 438 | return 1; |
| 439 | |
| 440 | if (query_current_values_with_pending_wait(data)) |
| 441 | return 1; |
| 442 | |
| 443 | if (data->currfid != reqfid) { |
| 444 | printk(KERN_ERR PFX |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 445 | "ph2: mismatch, failed fid transition, " |
| 446 | "curr 0x%x, req 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | data->currfid, reqfid); |
| 448 | return 1; |
| 449 | } |
| 450 | |
| 451 | if (savevid != data->currvid) { |
| 452 | printk(KERN_ERR PFX "ph2: vid changed, save 0x%x, curr 0x%x\n", |
| 453 | savevid, data->currvid); |
| 454 | return 1; |
| 455 | } |
| 456 | |
| 457 | dprintk("ph2 complete, currfid 0x%x, currvid 0x%x\n", |
| 458 | data->currfid, data->currvid); |
| 459 | |
| 460 | return 0; |
| 461 | } |
| 462 | |
| 463 | /* Phase 3 - core voltage transition flow ... jump to the final vid. */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 464 | static int core_voltage_post_transition(struct powernow_k8_data *data, |
| 465 | u32 reqvid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | { |
| 467 | u32 savefid = data->currfid; |
| 468 | u32 savereqvid = reqvid; |
| 469 | |
| 470 | dprintk("ph3 (cpu%d): starting, currfid 0x%x, currvid 0x%x\n", |
| 471 | smp_processor_id(), |
| 472 | data->currfid, data->currvid); |
| 473 | |
| 474 | if (reqvid != data->currvid) { |
| 475 | if (write_new_vid(data, reqvid)) |
| 476 | return 1; |
| 477 | |
| 478 | if (savefid != data->currfid) { |
| 479 | printk(KERN_ERR PFX |
| 480 | "ph3: bad fid change, save 0x%x, curr 0x%x\n", |
| 481 | savefid, data->currfid); |
| 482 | return 1; |
| 483 | } |
| 484 | |
| 485 | if (data->currvid != reqvid) { |
| 486 | printk(KERN_ERR PFX |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 487 | "ph3: failed vid transition\n, " |
| 488 | "req 0x%x, curr 0x%x", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | reqvid, data->currvid); |
| 490 | return 1; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | if (query_current_values_with_pending_wait(data)) |
| 495 | return 1; |
| 496 | |
| 497 | if (savereqvid != data->currvid) { |
| 498 | dprintk("ph3 failed, currvid 0x%x\n", data->currvid); |
| 499 | return 1; |
| 500 | } |
| 501 | |
| 502 | if (savefid != data->currfid) { |
| 503 | dprintk("ph3 failed, currfid changed 0x%x\n", |
| 504 | data->currfid); |
| 505 | return 1; |
| 506 | } |
| 507 | |
| 508 | dprintk("ph3 complete, currfid 0x%x, currvid 0x%x\n", |
| 509 | data->currfid, data->currvid); |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
| 514 | static int check_supported_cpu(unsigned int cpu) |
| 515 | { |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 516 | cpumask_t oldmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | u32 eax, ebx, ecx, edx; |
| 518 | unsigned int rc = 0; |
| 519 | |
| 520 | oldmask = current->cpus_allowed; |
Mike Travis | 0bc3cc0 | 2008-07-24 18:21:31 -0700 | [diff] [blame] | 521 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | if (smp_processor_id() != cpu) { |
Jacob Shin | 8aae828 | 2005-11-21 07:23:08 -0800 | [diff] [blame] | 524 | printk(KERN_ERR PFX "limiting to cpu %u failed\n", cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | goto out; |
| 526 | } |
| 527 | |
| 528 | if (current_cpu_data.x86_vendor != X86_VENDOR_AMD) |
| 529 | goto out; |
| 530 | |
| 531 | eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 532 | if (((eax & CPUID_XFAM) != CPUID_XFAM_K8) && |
| 533 | ((eax & CPUID_XFAM) < CPUID_XFAM_10H)) |
Dave Jones | 2c906ae | 2006-02-28 00:36:32 -0500 | [diff] [blame] | 534 | goto out; |
| 535 | |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 536 | if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { |
| 537 | if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || |
Dave Jones | 99fbe1a | 2007-05-14 18:27:29 -0400 | [diff] [blame] | 538 | ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 539 | printk(KERN_INFO PFX |
| 540 | "Processor cpuid %x not supported\n", eax); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 541 | goto out; |
| 542 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 544 | eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES); |
| 545 | if (eax < CPUID_FREQ_VOLT_CAPABILITIES) { |
| 546 | printk(KERN_INFO PFX |
| 547 | "No frequency change capabilities detected\n"); |
| 548 | goto out; |
| 549 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 551 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 552 | if ((edx & P_STATE_TRANSITION_CAPABLE) |
| 553 | != P_STATE_TRANSITION_CAPABLE) { |
| 554 | printk(KERN_INFO PFX |
| 555 | "Power state transitions not supported\n"); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 556 | goto out; |
| 557 | } |
| 558 | } else { /* must be a HW Pstate capable processor */ |
| 559 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); |
| 560 | if ((edx & USE_HW_PSTATE) == USE_HW_PSTATE) |
| 561 | cpu_family = CPU_HW_PSTATE; |
| 562 | else |
| 563 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | rc = 1; |
| 567 | |
| 568 | out: |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 569 | set_cpus_allowed_ptr(current, &oldmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 573 | static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, |
| 574 | u8 maxvid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
| 576 | unsigned int j; |
| 577 | u8 lastfid = 0xff; |
| 578 | |
| 579 | for (j = 0; j < data->numps; j++) { |
| 580 | if (pst[j].vid > LEAST_VID) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 581 | printk(KERN_ERR FW_BUG PFX "vid %d invalid : 0x%x\n", |
| 582 | j, pst[j].vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | return -EINVAL; |
| 584 | } |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 585 | if (pst[j].vid < data->rvo) { |
| 586 | /* vid + rvo >= 0 */ |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 587 | printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate" |
| 588 | " %d\n", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | return -ENODEV; |
| 590 | } |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 591 | if (pst[j].vid < maxvid + data->rvo) { |
| 592 | /* vid + rvo >= maxvid */ |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 593 | printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate" |
| 594 | " %d\n", j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | return -ENODEV; |
| 596 | } |
Jacob Shin | 8aae828 | 2005-11-21 07:23:08 -0800 | [diff] [blame] | 597 | if (pst[j].fid > MAX_FID) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 598 | printk(KERN_ERR FW_BUG PFX "maxfid exceeded with pstate" |
| 599 | " %d\n", j); |
Jacob Shin | 8aae828 | 2005-11-21 07:23:08 -0800 | [diff] [blame] | 600 | return -ENODEV; |
| 601 | } |
Jacob Shin | 8aae828 | 2005-11-21 07:23:08 -0800 | [diff] [blame] | 602 | if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | /* Only first fid is allowed to be in "low" range */ |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 604 | printk(KERN_ERR FW_BUG PFX "two low fids - %d : " |
| 605 | "0x%x\n", j, pst[j].fid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | return -EINVAL; |
| 607 | } |
| 608 | if (pst[j].fid < lastfid) |
| 609 | lastfid = pst[j].fid; |
| 610 | } |
| 611 | if (lastfid & 1) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 612 | printk(KERN_ERR FW_BUG PFX "lastfid invalid\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | return -EINVAL; |
| 614 | } |
| 615 | if (lastfid > LO_FID_TABLE_TOP) |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 616 | printk(KERN_INFO FW_BUG PFX |
| 617 | "first fid not from lo freq table\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | return 0; |
| 620 | } |
| 621 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 622 | static void invalidate_entry(struct powernow_k8_data *data, unsigned int entry) |
| 623 | { |
| 624 | data->powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID; |
| 625 | } |
| 626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | static void print_basics(struct powernow_k8_data *data) |
| 628 | { |
| 629 | int j; |
| 630 | for (j = 0; j < data->numps; j++) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 631 | if (data->powernow_table[j].frequency != |
| 632 | CPUFREQ_ENTRY_INVALID) { |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 633 | if (cpu_family == CPU_HW_PSTATE) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 634 | printk(KERN_INFO PFX |
| 635 | " %d : pstate %d (%d MHz)\n", j, |
Yinghai Lu | 4ae5c49 | 2007-11-20 19:38:27 -0800 | [diff] [blame] | 636 | data->powernow_table[j].index, |
Dave Jones | 9a60ddb | 2007-07-13 01:34:10 -0400 | [diff] [blame] | 637 | data->powernow_table[j].frequency/1000); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 638 | } else { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 639 | printk(KERN_INFO PFX |
| 640 | " %d : fid 0x%x (%d MHz), vid 0x%x\n", |
Dave Jones | 9a60ddb | 2007-07-13 01:34:10 -0400 | [diff] [blame] | 641 | j, |
| 642 | data->powernow_table[j].index & 0xff, |
| 643 | data->powernow_table[j].frequency/1000, |
| 644 | data->powernow_table[j].index >> 8); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 645 | } |
| 646 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | } |
| 648 | if (data->batps) |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 649 | printk(KERN_INFO PFX "Only %d pstates on battery\n", |
| 650 | data->batps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | } |
| 652 | |
Andreas Herrmann | ca446d0 | 2009-04-22 13:48:33 +0200 | [diff] [blame] | 653 | static u32 freq_from_fid_did(u32 fid, u32 did) |
| 654 | { |
| 655 | u32 mhz = 0; |
| 656 | |
| 657 | if (boot_cpu_data.x86 == 0x10) |
| 658 | mhz = (100 * (fid + 0x10)) >> did; |
| 659 | else if (boot_cpu_data.x86 == 0x11) |
| 660 | mhz = (100 * (fid + 8)) >> did; |
| 661 | else |
| 662 | BUG(); |
| 663 | |
| 664 | return mhz * 1000; |
| 665 | } |
| 666 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 667 | static int fill_powernow_table(struct powernow_k8_data *data, |
| 668 | struct pst_s *pst, u8 maxvid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | { |
| 670 | struct cpufreq_frequency_table *powernow_table; |
| 671 | unsigned int j; |
| 672 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 673 | if (data->batps) { |
| 674 | /* use ACPI support to get full speed on mains power */ |
| 675 | printk(KERN_WARNING PFX |
| 676 | "Only %d pstates usable (use ACPI driver for full " |
| 677 | "range\n", data->batps); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | data->numps = data->batps; |
| 679 | } |
| 680 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 681 | for (j = 1; j < data->numps; j++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | if (pst[j-1].fid >= pst[j].fid) { |
| 683 | printk(KERN_ERR PFX "PST out of sequence\n"); |
| 684 | return -EINVAL; |
| 685 | } |
| 686 | } |
| 687 | |
| 688 | if (data->numps < 2) { |
| 689 | printk(KERN_ERR PFX "no p states to transition\n"); |
| 690 | return -ENODEV; |
| 691 | } |
| 692 | |
| 693 | if (check_pst_table(data, pst, maxvid)) |
| 694 | return -EINVAL; |
| 695 | |
| 696 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) |
| 697 | * (data->numps + 1)), GFP_KERNEL); |
| 698 | if (!powernow_table) { |
| 699 | printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); |
| 700 | return -ENOMEM; |
| 701 | } |
| 702 | |
| 703 | for (j = 0; j < data->numps; j++) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 704 | int freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | powernow_table[j].index = pst[j].fid; /* lower 8 bits */ |
| 706 | powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 707 | freq = find_khz_freq_from_fid(pst[j].fid); |
| 708 | powernow_table[j].frequency = freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | powernow_table[data->numps].frequency = CPUFREQ_TABLE_END; |
| 711 | powernow_table[data->numps].index = 0; |
| 712 | |
| 713 | if (query_current_values_with_pending_wait(data)) { |
| 714 | kfree(powernow_table); |
| 715 | return -EIO; |
| 716 | } |
| 717 | |
| 718 | dprintk("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid); |
| 719 | data->powernow_table = powernow_table; |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 720 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) |
Mark Langsdorf | 2e49762 | 2007-04-30 14:15:05 -0500 | [diff] [blame] | 721 | print_basics(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | for (j = 0; j < data->numps; j++) |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 724 | if ((pst[j].fid == data->currfid) && |
| 725 | (pst[j].vid == data->currvid)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | return 0; |
| 727 | |
| 728 | dprintk("currfid/vid do not match PST, ignoring\n"); |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | /* Find and validate the PSB/PST table in BIOS. */ |
| 733 | static int find_psb_table(struct powernow_k8_data *data) |
| 734 | { |
| 735 | struct psb_s *psb; |
| 736 | unsigned int i; |
| 737 | u32 mvs; |
| 738 | u8 maxvid; |
| 739 | u32 cpst = 0; |
| 740 | u32 thiscpuid; |
| 741 | |
| 742 | for (i = 0xc0000; i < 0xffff0; i += 0x10) { |
| 743 | /* Scan BIOS looking for the signature. */ |
| 744 | /* It can not be at ffff0 - it is too big. */ |
| 745 | |
| 746 | psb = phys_to_virt(i); |
| 747 | if (memcmp(psb, PSB_ID_STRING, PSB_ID_STRING_LEN) != 0) |
| 748 | continue; |
| 749 | |
| 750 | dprintk("found PSB header at 0x%p\n", psb); |
| 751 | |
| 752 | dprintk("table vers: 0x%x\n", psb->tableversion); |
| 753 | if (psb->tableversion != PSB_VERSION_1_4) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 754 | printk(KERN_ERR FW_BUG PFX "PSB table is not v1.4\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | return -ENODEV; |
| 756 | } |
| 757 | |
| 758 | dprintk("flags: 0x%x\n", psb->flags1); |
| 759 | if (psb->flags1) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 760 | printk(KERN_ERR FW_BUG PFX "unknown flags\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | return -ENODEV; |
| 762 | } |
| 763 | |
| 764 | data->vstable = psb->vstable; |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 765 | dprintk("voltage stabilization time: %d(*20us)\n", |
| 766 | data->vstable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
| 768 | dprintk("flags2: 0x%x\n", psb->flags2); |
| 769 | data->rvo = psb->flags2 & 3; |
| 770 | data->irt = ((psb->flags2) >> 2) & 3; |
| 771 | mvs = ((psb->flags2) >> 4) & 3; |
| 772 | data->vidmvs = 1 << mvs; |
| 773 | data->batps = ((psb->flags2) >> 6) & 3; |
| 774 | |
| 775 | dprintk("ramp voltage offset: %d\n", data->rvo); |
| 776 | dprintk("isochronous relief time: %d\n", data->irt); |
| 777 | dprintk("maximum voltage step: %d - 0x%x\n", mvs, data->vidmvs); |
| 778 | |
| 779 | dprintk("numpst: 0x%x\n", psb->num_tables); |
| 780 | cpst = psb->num_tables; |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 781 | if ((psb->cpuid == 0x00000fc0) || |
| 782 | (psb->cpuid == 0x00000fe0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 784 | if ((thiscpuid == 0x00000fc0) || |
| 785 | (thiscpuid == 0x00000fe0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | cpst = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | } |
| 788 | if (cpst != 1) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 789 | printk(KERN_ERR FW_BUG PFX "numpst must be 1\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | return -ENODEV; |
| 791 | } |
| 792 | |
| 793 | data->plllock = psb->plllocktime; |
| 794 | dprintk("plllocktime: 0x%x (units 1us)\n", psb->plllocktime); |
| 795 | dprintk("maxfid: 0x%x\n", psb->maxfid); |
| 796 | dprintk("maxvid: 0x%x\n", psb->maxvid); |
| 797 | maxvid = psb->maxvid; |
| 798 | |
| 799 | data->numps = psb->numps; |
| 800 | dprintk("numpstates: 0x%x\n", data->numps); |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 801 | return fill_powernow_table(data, |
| 802 | (struct pst_s *)(psb+1), maxvid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | /* |
| 805 | * If you see this message, complain to BIOS manufacturer. If |
| 806 | * he tells you "we do not support Linux" or some similar |
| 807 | * nonsense, remember that Windows 2000 uses the same legacy |
| 808 | * mechanism that the old Linux PSB driver uses. Tell them it |
| 809 | * is broken with Windows 2000. |
| 810 | * |
| 811 | * The reference to the AMD documentation is chapter 9 in the |
| 812 | * BIOS and Kernel Developer's Guide, which is available on |
| 813 | * www.amd.com |
| 814 | */ |
Thomas Renninger | 79cc56a | 2009-02-04 11:56:11 +0100 | [diff] [blame] | 815 | printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | return -ENODEV; |
| 817 | } |
| 818 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 819 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, |
| 820 | unsigned int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 822 | acpi_integer control; |
| 823 | |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 824 | if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | return; |
| 826 | |
Luis Henriques | 21335d0 | 2009-04-23 19:45:04 +0100 | [diff] [blame] | 827 | control = data->acpi_data.states[index].control; |
| 828 | data->irt = (control >> IRT_SHIFT) & IRT_MASK; |
| 829 | data->rvo = (control >> RVO_SHIFT) & RVO_MASK; |
| 830 | data->exttype = (control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK; |
| 831 | data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK; |
| 832 | data->vidmvs = 1 << ((control >> MVS_SHIFT) & MVS_MASK); |
| 833 | data->vstable = (control >> VST_SHIFT) & VST_MASK; |
| 834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | |
| 836 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) |
| 837 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | struct cpufreq_frequency_table *powernow_table; |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 839 | int ret_val = -ENODEV; |
Dave Jones | 2c701b1 | 2009-06-05 12:37:07 -0400 | [diff] [blame] | 840 | acpi_integer control, status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 842 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 843 | dprintk("register performance failed: bad ACPI data\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | return -EIO; |
| 845 | } |
| 846 | |
| 847 | /* verify the data contained in the ACPI structures */ |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 848 | if (data->acpi_data.state_count <= 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | dprintk("No ACPI P-States\n"); |
| 850 | goto err_out; |
| 851 | } |
| 852 | |
Dave Jones | 2c701b1 | 2009-06-05 12:37:07 -0400 | [diff] [blame] | 853 | control = data->acpi_data.control_register.space_id; |
| 854 | status = data->acpi_data.status_register.space_id; |
| 855 | |
| 856 | if ((control != ACPI_ADR_SPACE_FIXED_HARDWARE) || |
| 857 | (status != ACPI_ADR_SPACE_FIXED_HARDWARE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | dprintk("Invalid control/status registers (%x - %x)\n", |
Dave Jones | 2c701b1 | 2009-06-05 12:37:07 -0400 | [diff] [blame] | 859 | control, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | goto err_out; |
| 861 | } |
| 862 | |
| 863 | /* fill in data->powernow_table */ |
| 864 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 865 | * (data->acpi_data.state_count + 1)), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | if (!powernow_table) { |
| 867 | dprintk("powernow_table memory alloc failure\n"); |
| 868 | goto err_out; |
| 869 | } |
| 870 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 871 | if (cpu_family == CPU_HW_PSTATE) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 872 | ret_val = fill_powernow_table_pstate(data, powernow_table); |
| 873 | else |
| 874 | ret_val = fill_powernow_table_fidvid(data, powernow_table); |
| 875 | if (ret_val) |
| 876 | goto err_out_mem; |
| 877 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 878 | powernow_table[data->acpi_data.state_count].frequency = |
| 879 | CPUFREQ_TABLE_END; |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 880 | powernow_table[data->acpi_data.state_count].index = 0; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 881 | data->powernow_table = powernow_table; |
| 882 | |
| 883 | /* fill in data */ |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 884 | data->numps = data->acpi_data.state_count; |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 885 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) |
Mark Langsdorf | 2e49762 | 2007-04-30 14:15:05 -0500 | [diff] [blame] | 886 | print_basics(data); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 887 | powernow_k8_acpi_pst_values(data, 0); |
| 888 | |
| 889 | /* notify BIOS that we exist */ |
| 890 | acpi_processor_notify_smm(THIS_MODULE); |
| 891 | |
Yinghai Lu | eaa9584 | 2009-06-06 14:51:36 -0700 | [diff] [blame] | 892 | if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) { |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 893 | printk(KERN_ERR PFX |
| 894 | "unable to alloc powernow_k8_data cpumask\n"); |
| 895 | ret_val = -ENOMEM; |
| 896 | goto err_out_mem; |
| 897 | } |
| 898 | |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 899 | return 0; |
| 900 | |
| 901 | err_out_mem: |
| 902 | kfree(powernow_table); |
| 903 | |
| 904 | err_out: |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 905 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 906 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 907 | /* data->acpi_data.state_count informs us at ->exit() |
| 908 | * whether ACPI was used */ |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 909 | data->acpi_data.state_count = 0; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 910 | |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 911 | return ret_val; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 912 | } |
| 913 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 914 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, |
| 915 | struct cpufreq_frequency_table *powernow_table) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 916 | { |
| 917 | int i; |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 918 | u32 hi = 0, lo = 0; |
| 919 | rdmsr(MSR_PSTATE_CUR_LIMIT, hi, lo); |
| 920 | data->max_hw_pstate = (hi & HW_PSTATE_MAX_MASK) >> HW_PSTATE_MAX_SHIFT; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 921 | |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 922 | for (i = 0; i < data->acpi_data.state_count; i++) { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 923 | u32 index; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 924 | |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 925 | index = data->acpi_data.states[i].control & HW_PSTATE_MASK; |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 926 | if (index > data->max_hw_pstate) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 927 | printk(KERN_ERR PFX "invalid pstate %d - " |
| 928 | "bad value %d.\n", i, index); |
| 929 | printk(KERN_ERR PFX "Please report to BIOS " |
| 930 | "manufacturer\n"); |
| 931 | invalidate_entry(data, i); |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 932 | continue; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 933 | } |
| 934 | rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi); |
| 935 | if (!(hi & HW_PSTATE_VALID_MASK)) { |
| 936 | dprintk("invalid pstate %d, ignoring\n", index); |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 937 | invalidate_entry(data, i); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 938 | continue; |
| 939 | } |
| 940 | |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 941 | powernow_table[i].index = index; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 942 | |
Andreas Herrmann | ca446d0 | 2009-04-22 13:48:33 +0200 | [diff] [blame] | 943 | /* Frequency may be rounded for these */ |
| 944 | if (boot_cpu_data.x86 == 0x10 || boot_cpu_data.x86 == 0x11) { |
| 945 | powernow_table[i].frequency = |
| 946 | freq_from_fid_did(lo & 0x3f, (lo >> 6) & 7); |
| 947 | } else |
| 948 | powernow_table[i].frequency = |
| 949 | data->acpi_data.states[i].core_frequency * 1000; |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 950 | } |
| 951 | return 0; |
| 952 | } |
| 953 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 954 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, |
| 955 | struct cpufreq_frequency_table *powernow_table) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 956 | { |
| 957 | int i; |
| 958 | int cntlofreq = 0; |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 959 | |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 960 | for (i = 0; i < data->acpi_data.state_count; i++) { |
Dave Jones | 094ce7f | 2005-07-29 12:55:40 -0700 | [diff] [blame] | 961 | u32 fid; |
| 962 | u32 vid; |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 963 | u32 freq, index; |
| 964 | acpi_integer status, control; |
Dave Jones | 094ce7f | 2005-07-29 12:55:40 -0700 | [diff] [blame] | 965 | |
| 966 | if (data->exttype) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 967 | status = data->acpi_data.states[i].status; |
| 968 | fid = status & EXT_FID_MASK; |
| 969 | vid = (status >> VID_SHIFT) & EXT_VID_MASK; |
Dave Jones | 841e40b | 2005-07-28 09:40:04 -0700 | [diff] [blame] | 970 | } else { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 971 | control = data->acpi_data.states[i].control; |
| 972 | fid = control & FID_MASK; |
| 973 | vid = (control >> VID_SHIFT) & VID_MASK; |
Dave Jones | 841e40b | 2005-07-28 09:40:04 -0700 | [diff] [blame] | 974 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
| 976 | dprintk(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid); |
| 977 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 978 | index = fid | (vid<<8); |
| 979 | powernow_table[i].index = index; |
| 980 | |
| 981 | freq = find_khz_freq_from_fid(fid); |
| 982 | powernow_table[i].frequency = freq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | /* verify frequency is OK */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 985 | if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) { |
| 986 | dprintk("invalid freq %u kHz, ignoring\n", freq); |
| 987 | invalidate_entry(data, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | continue; |
| 989 | } |
| 990 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 991 | /* verify voltage is OK - |
| 992 | * BIOSs are using "off" to indicate invalid */ |
Dave Jones | 841e40b | 2005-07-28 09:40:04 -0700 | [diff] [blame] | 993 | if (vid == VID_OFF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | dprintk("invalid vid %u, ignoring\n", vid); |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 995 | invalidate_entry(data, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | continue; |
| 997 | } |
| 998 | |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 999 | /* verify only 1 entry from the lo frequency table */ |
| 1000 | if (fid < HI_FID_TABLE_BOTTOM) { |
| 1001 | if (cntlofreq) { |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1002 | /* if both entries are the same, |
| 1003 | * ignore this one ... */ |
| 1004 | if ((freq != powernow_table[cntlofreq].frequency) || |
| 1005 | (index != powernow_table[cntlofreq].index)) { |
| 1006 | printk(KERN_ERR PFX |
| 1007 | "Too many lo freq table " |
| 1008 | "entries\n"); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1009 | return 1; |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1012 | dprintk("double low frequency table entry, " |
| 1013 | "ignoring it.\n"); |
| 1014 | invalidate_entry(data, i); |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1015 | continue; |
| 1016 | } else |
| 1017 | cntlofreq = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1020 | if (freq != (data->acpi_data.states[i].core_frequency * 1000)) { |
| 1021 | printk(KERN_INFO PFX "invalid freq entries " |
| 1022 | "%u kHz vs. %u kHz\n", freq, |
| 1023 | (unsigned int) |
| 1024 | (data->acpi_data.states[i].core_frequency |
| 1025 | * 1000)); |
| 1026 | invalidate_entry(data, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | continue; |
| 1028 | } |
| 1029 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) |
| 1034 | { |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 1035 | if (data->acpi_data.state_count) |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1036 | acpi_processor_unregister_performance(&data->acpi_data, |
| 1037 | data->cpu); |
Rusty Russell | 2fdf66b | 2008-12-31 18:08:47 -0800 | [diff] [blame] | 1038 | free_cpumask_var(data->acpi_data.shared_cpu_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | } |
| 1040 | |
Mark Langsdorf | 732553e | 2009-02-03 17:46:43 +0100 | [diff] [blame] | 1041 | static int get_transition_latency(struct powernow_k8_data *data) |
| 1042 | { |
| 1043 | int max_latency = 0; |
| 1044 | int i; |
| 1045 | for (i = 0; i < data->acpi_data.state_count; i++) { |
| 1046 | int cur_latency = data->acpi_data.states[i].transition_latency |
| 1047 | + data->acpi_data.states[i].bus_master_latency; |
| 1048 | if (cur_latency > max_latency) |
| 1049 | max_latency = cur_latency; |
| 1050 | } |
Thomas Renninger | 86e1368 | 2009-04-22 13:48:30 +0200 | [diff] [blame] | 1051 | if (max_latency == 0) { |
| 1052 | /* |
| 1053 | * Fam 11h always returns 0 as transition latency. |
| 1054 | * This is intended and means "very fast". While cpufreq core |
| 1055 | * and governors currently can handle that gracefully, better |
| 1056 | * set it to 1 to avoid problems in the future. |
| 1057 | * For all others it's a BIOS bug. |
| 1058 | */ |
| 1059 | if (!boot_cpu_data.x86 == 0x11) |
| 1060 | printk(KERN_ERR FW_WARN PFX "Invalid zero transition " |
| 1061 | "latency\n"); |
| 1062 | max_latency = 1; |
| 1063 | } |
Mark Langsdorf | 732553e | 2009-02-03 17:46:43 +0100 | [diff] [blame] | 1064 | /* value in usecs, needs to be in nanoseconds */ |
| 1065 | return 1000 * max_latency; |
| 1066 | } |
| 1067 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | /* Take a frequency, and issue the fid/vid transition command */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1069 | static int transition_frequency_fidvid(struct powernow_k8_data *data, |
| 1070 | unsigned int index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1072 | u32 fid = 0; |
| 1073 | u32 vid = 0; |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1074 | int res, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | struct cpufreq_freqs freqs; |
| 1076 | |
| 1077 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); |
| 1078 | |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1079 | /* fid/vid correctness check for k8 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | /* fid are the lower 8 bits of the index we stored into |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1081 | * the cpufreq frequency table in find_psb_table, vid |
| 1082 | * are the upper 8 bits. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | fid = data->powernow_table[index].index & 0xFF; |
| 1085 | vid = (data->powernow_table[index].index & 0xFF00) >> 8; |
| 1086 | |
| 1087 | dprintk("table matched fid 0x%x, giving vid 0x%x\n", fid, vid); |
| 1088 | |
| 1089 | if (query_current_values_with_pending_wait(data)) |
| 1090 | return 1; |
| 1091 | |
| 1092 | if ((data->currvid == vid) && (data->currfid == fid)) { |
| 1093 | dprintk("target matches current values (fid 0x%x, vid 0x%x)\n", |
| 1094 | fid, vid); |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1098 | if ((fid < HI_FID_TABLE_BOTTOM) && |
| 1099 | (data->currfid < HI_FID_TABLE_BOTTOM)) { |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1100 | printk(KERN_ERR PFX |
| 1101 | "ignoring illegal change in lo freq table-%x to 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | data->currfid, fid); |
| 1103 | return 1; |
| 1104 | } |
| 1105 | |
| 1106 | dprintk("cpu %d, changing to fid 0x%x, vid 0x%x\n", |
| 1107 | smp_processor_id(), fid, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1108 | freqs.old = find_khz_freq_from_fid(data->currfid); |
| 1109 | freqs.new = find_khz_freq_from_fid(fid); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1110 | |
Mike Travis | 334ef7a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1111 | for_each_cpu_mask_nr(i, *(data->available_cores)) { |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1112 | freqs.cpu = i; |
| 1113 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
| 1114 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | res = transition_fid_vid(data, fid, vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | freqs.new = find_khz_freq_from_fid(data->currfid); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1118 | |
Mike Travis | 334ef7a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1119 | for_each_cpu_mask_nr(i, *(data->available_cores)) { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1120 | freqs.cpu = i; |
| 1121 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
| 1122 | } |
| 1123 | return res; |
| 1124 | } |
| 1125 | |
| 1126 | /* Take a frequency, and issue the hardware pstate transition command */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1127 | static int transition_frequency_pstate(struct powernow_k8_data *data, |
| 1128 | unsigned int index) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1129 | { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1130 | u32 pstate = 0; |
| 1131 | int res, i; |
| 1132 | struct cpufreq_freqs freqs; |
| 1133 | |
| 1134 | dprintk("cpu %d transition to index %u\n", smp_processor_id(), index); |
| 1135 | |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 1136 | /* get MSR index for hardware pstate transition */ |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1137 | pstate = index & HW_PSTATE_MASK; |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 1138 | if (pstate > data->max_hw_pstate) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1139 | return 0; |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1140 | freqs.old = find_khz_freq_from_pstate(data->powernow_table, |
| 1141 | data->currpstate); |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 1142 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1143 | |
Mike Travis | 334ef7a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1144 | for_each_cpu_mask_nr(i, *(data->available_cores)) { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1145 | freqs.cpu = i; |
| 1146 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
| 1147 | } |
| 1148 | |
| 1149 | res = transition_pstate(data, pstate); |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 1150 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1151 | |
Mike Travis | 334ef7a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1152 | for_each_cpu_mask_nr(i, *(data->available_cores)) { |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1153 | freqs.cpu = i; |
| 1154 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
Dave Jones | 2e3f8fa | 2006-05-30 17:25:14 -0400 | [diff] [blame] | 1155 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | return res; |
| 1157 | } |
| 1158 | |
| 1159 | /* Driver entry point to switch to the target frequency */ |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1160 | static int powernowk8_target(struct cpufreq_policy *pol, |
| 1161 | unsigned targfreq, unsigned relation) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | { |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 1163 | cpumask_t oldmask; |
travis@sgi.com | 2c6b8c0 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 1164 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); |
Adrian Bunk | 9180053 | 2006-04-19 00:07:28 +0200 | [diff] [blame] | 1165 | u32 checkfid; |
| 1166 | u32 checkvid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | unsigned int newstate; |
| 1168 | int ret = -EIO; |
| 1169 | |
Jacob Shin | 4211a30 | 2006-04-07 19:49:51 +0200 | [diff] [blame] | 1170 | if (!data) |
| 1171 | return -EINVAL; |
| 1172 | |
Adrian Bunk | 9180053 | 2006-04-19 00:07:28 +0200 | [diff] [blame] | 1173 | checkfid = data->currfid; |
| 1174 | checkvid = data->currvid; |
| 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | /* only run on specific CPU from here on */ |
| 1177 | oldmask = current->cpus_allowed; |
Mike Travis | 0bc3cc0 | 2008-07-24 18:21:31 -0700 | [diff] [blame] | 1178 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(pol->cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | |
| 1180 | if (smp_processor_id() != pol->cpu) { |
Jacob Shin | 8aae828 | 2005-11-21 07:23:08 -0800 | [diff] [blame] | 1181 | printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | goto err_out; |
| 1183 | } |
| 1184 | |
| 1185 | if (pending_bit_stuck()) { |
| 1186 | printk(KERN_ERR PFX "failing targ, change pending bit set\n"); |
| 1187 | goto err_out; |
| 1188 | } |
| 1189 | |
| 1190 | dprintk("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n", |
| 1191 | pol->cpu, targfreq, pol->min, pol->max, relation); |
| 1192 | |
Dave Jones | 8384451 | 2006-05-30 17:43:54 -0400 | [diff] [blame] | 1193 | if (query_current_values_with_pending_wait(data)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
Mark Langsdorf | c5829cd | 2007-10-17 16:52:08 -0500 | [diff] [blame] | 1196 | if (cpu_family != CPU_HW_PSTATE) { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1197 | dprintk("targ: curr fid 0x%x, vid 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | data->currfid, data->currvid); |
| 1199 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1200 | if ((checkvid != data->currvid) || |
| 1201 | (checkfid != data->currfid)) { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1202 | printk(KERN_INFO PFX |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1203 | "error - out of sync, fix 0x%x 0x%x, " |
| 1204 | "vid 0x%x 0x%x\n", |
| 1205 | checkfid, data->currfid, |
| 1206 | checkvid, data->currvid); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | } |
| 1209 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1210 | if (cpufreq_frequency_table_target(pol, data->powernow_table, |
| 1211 | targfreq, relation, &newstate)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | goto err_out; |
| 1213 | |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 1214 | mutex_lock(&fidvid_mutex); |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | powernow_k8_acpi_pst_values(data, newstate); |
| 1217 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 1218 | if (cpu_family == CPU_HW_PSTATE) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1219 | ret = transition_frequency_pstate(data, newstate); |
| 1220 | else |
| 1221 | ret = transition_frequency_fidvid(data, newstate); |
| 1222 | if (ret) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | printk(KERN_ERR PFX "transition frequency failed\n"); |
| 1224 | ret = 1; |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 1225 | mutex_unlock(&fidvid_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | goto err_out; |
| 1227 | } |
Ingo Molnar | 14cc3e2 | 2006-03-26 01:37:14 -0800 | [diff] [blame] | 1228 | mutex_unlock(&fidvid_mutex); |
Dave Jones | 065b807 | 2005-05-31 19:03:46 -0700 | [diff] [blame] | 1229 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 1230 | if (cpu_family == CPU_HW_PSTATE) |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1231 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, |
| 1232 | newstate); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1233 | else |
| 1234 | pol->cur = find_khz_freq_from_fid(data->currfid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | ret = 0; |
| 1236 | |
| 1237 | err_out: |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 1238 | set_cpus_allowed_ptr(current, &oldmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | return ret; |
| 1240 | } |
| 1241 | |
| 1242 | /* Driver entry point to verify the policy and range of frequencies */ |
| 1243 | static int powernowk8_verify(struct cpufreq_policy *pol) |
| 1244 | { |
travis@sgi.com | 2c6b8c0 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 1245 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | |
Jacob Shin | 4211a30 | 2006-04-07 19:49:51 +0200 | [diff] [blame] | 1247 | if (!data) |
| 1248 | return -EINVAL; |
| 1249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | return cpufreq_frequency_table_verify(pol, data->powernow_table); |
| 1251 | } |
| 1252 | |
| 1253 | /* per CPU init entry point to the driver */ |
Andi Kleen | aa41eb9 | 2006-01-16 01:56:36 +0100 | [diff] [blame] | 1254 | static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | { |
Andrew Morton | b394f1d | 2009-06-10 12:41:37 -0700 | [diff] [blame^] | 1256 | static const char ACPI_PSS_BIOS_BUG_MSG[] = |
| 1257 | KERN_ERR FW_BUG PFX "No compatible ACPI _PSS objects found.\n" |
| 1258 | KERN_ERR FW_BUG PFX "Try again with latest BIOS.\n"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | struct powernow_k8_data *data; |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 1260 | cpumask_t oldmask; |
Andi Kleen | d7fa706 | 2006-04-07 19:49:48 +0200 | [diff] [blame] | 1261 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | |
Jacob Shin | 8aae828 | 2005-11-21 07:23:08 -0800 | [diff] [blame] | 1263 | if (!cpu_online(pol->cpu)) |
| 1264 | return -ENODEV; |
| 1265 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | if (!check_supported_cpu(pol->cpu)) |
| 1267 | return -ENODEV; |
| 1268 | |
Dave Jones | bfdc708 | 2005-10-20 15:16:15 -0700 | [diff] [blame] | 1269 | data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | if (!data) { |
| 1271 | printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); |
| 1272 | return -ENOMEM; |
| 1273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | |
| 1275 | data->cpu = pol->cpu; |
Andreas Herrmann | a266d9f | 2008-11-21 14:49:25 +0100 | [diff] [blame] | 1276 | data->currpstate = HW_PSTATE_INVALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
Rusty Russell | a0abd52 | 2009-02-16 17:31:58 -0600 | [diff] [blame] | 1278 | if (powernow_k8_cpu_init_acpi(data)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | /* |
| 1280 | * Use the PSB BIOS structure. This is only availabe on |
| 1281 | * an UP version, and is deprecated by AMD. |
| 1282 | */ |
Randy Dunlap | 9ed059e | 2006-06-20 22:32:56 -0700 | [diff] [blame] | 1283 | if (num_online_cpus() != 1) { |
Thomas Renninger | df18297 | 2009-04-22 13:48:32 +0200 | [diff] [blame] | 1284 | printk_once(ACPI_PSS_BIOS_BUG_MSG); |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1285 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | } |
| 1287 | if (pol->cpu != 0) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 1288 | printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " |
| 1289 | "CPU other than CPU0. Complain to your BIOS " |
| 1290 | "vendor.\n"); |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1291 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | } |
| 1293 | rc = find_psb_table(data); |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1294 | if (rc) |
| 1295 | goto err_out; |
| 1296 | |
Mark Langsdorf | 732553e | 2009-02-03 17:46:43 +0100 | [diff] [blame] | 1297 | /* Take a crude guess here. |
| 1298 | * That guess was in microseconds, so multiply with 1000 */ |
| 1299 | pol->cpuinfo.transition_latency = ( |
| 1300 | ((data->rvo + 8) * data->vstable * VST_UNITS_20US) + |
| 1301 | ((1 << data->irt) * 30)) * 1000; |
| 1302 | } else /* ACPI _PSS objects available */ |
| 1303 | pol->cpuinfo.transition_latency = get_transition_latency(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
| 1305 | /* only run on specific CPU from here on */ |
| 1306 | oldmask = current->cpus_allowed; |
Mike Travis | 0bc3cc0 | 2008-07-24 18:21:31 -0700 | [diff] [blame] | 1307 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(pol->cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
| 1309 | if (smp_processor_id() != pol->cpu) { |
Jacob Shin | 8aae828 | 2005-11-21 07:23:08 -0800 | [diff] [blame] | 1310 | printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu); |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1311 | goto err_out_unmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | if (pending_bit_stuck()) { |
| 1315 | printk(KERN_ERR PFX "failing init, change pending bit set\n"); |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1316 | goto err_out_unmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | if (query_current_values_with_pending_wait(data)) |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1320 | goto err_out_unmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 1322 | if (cpu_family == CPU_OPTERON) |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1323 | fidvid_msr_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | |
| 1325 | /* run on any CPU again */ |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 1326 | set_cpus_allowed_ptr(current, &oldmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 1328 | if (cpu_family == CPU_HW_PSTATE) |
Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 1329 | cpumask_copy(pol->cpus, cpumask_of(pol->cpu)); |
Linus Torvalds | f607e3a | 2008-08-19 13:34:59 -0700 | [diff] [blame] | 1330 | else |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 1331 | cpumask_copy(pol->cpus, cpu_core_mask(pol->cpu)); |
Rusty Russell | 835481d | 2009-01-04 05:18:06 -0800 | [diff] [blame] | 1332 | data->available_cores = pol->cpus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 1334 | if (cpu_family == CPU_HW_PSTATE) |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1335 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, |
| 1336 | data->currpstate); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1337 | else |
| 1338 | pol->cur = find_khz_freq_from_fid(data->currfid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | dprintk("policy current frequency %d kHz\n", pol->cur); |
| 1340 | |
| 1341 | /* min/max the cpu is capable of */ |
| 1342 | if (cpufreq_frequency_table_cpuinfo(pol, data->powernow_table)) { |
Thomas Renninger | 2fd4709 | 2008-09-01 14:27:03 +0200 | [diff] [blame] | 1343 | printk(KERN_ERR FW_BUG PFX "invalid powernow_table\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | powernow_k8_cpu_exit_acpi(data); |
| 1345 | kfree(data->powernow_table); |
| 1346 | kfree(data); |
| 1347 | return -EINVAL; |
| 1348 | } |
| 1349 | |
| 1350 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); |
| 1351 | |
Langsdorf, Mark | e7bdd7a | 2006-06-08 10:30:17 -0500 | [diff] [blame] | 1352 | if (cpu_family == CPU_HW_PSTATE) |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1353 | dprintk("cpu_init done, current pstate 0x%x\n", |
| 1354 | data->currpstate); |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1355 | else |
| 1356 | dprintk("cpu_init done, current fid 0x%x, vid 0x%x\n", |
| 1357 | data->currfid, data->currvid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
travis@sgi.com | 2c6b8c0 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 1359 | per_cpu(powernow_data, pol->cpu) = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | |
| 1361 | return 0; |
| 1362 | |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1363 | err_out_unmask: |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 1364 | set_cpus_allowed_ptr(current, &oldmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | powernow_k8_cpu_exit_acpi(data); |
| 1366 | |
Dave Jones | 0cb8bc2 | 2009-02-18 14:11:00 -0500 | [diff] [blame] | 1367 | err_out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | kfree(data); |
| 1369 | return -ENODEV; |
| 1370 | } |
| 1371 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1372 | static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | { |
travis@sgi.com | 2c6b8c0 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 1374 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | |
| 1376 | if (!data) |
| 1377 | return -EINVAL; |
| 1378 | |
| 1379 | powernow_k8_cpu_exit_acpi(data); |
| 1380 | |
| 1381 | cpufreq_frequency_table_put_attr(pol->cpu); |
| 1382 | |
| 1383 | kfree(data->powernow_table); |
| 1384 | kfree(data); |
| 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1389 | static unsigned int powernowk8_get(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | { |
shin, jacob | eef5167 | 2006-03-27 09:57:20 -0600 | [diff] [blame] | 1391 | struct powernow_k8_data *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | cpumask_t oldmask = current->cpus_allowed; |
| 1393 | unsigned int khz = 0; |
Dave Jones | 89c0484 | 2008-02-06 21:55:26 -0500 | [diff] [blame] | 1394 | unsigned int first; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1395 | |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 1396 | first = cpumask_first(cpu_core_mask(cpu)); |
Dave Jones | 89c0484 | 2008-02-06 21:55:26 -0500 | [diff] [blame] | 1397 | data = per_cpu(powernow_data, first); |
shin, jacob | eef5167 | 2006-03-27 09:57:20 -0600 | [diff] [blame] | 1398 | |
| 1399 | if (!data) |
| 1400 | return -EINVAL; |
| 1401 | |
Mike Travis | 0bc3cc0 | 2008-07-24 18:21:31 -0700 | [diff] [blame] | 1402 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | if (smp_processor_id() != cpu) { |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 1404 | printk(KERN_ERR PFX |
| 1405 | "limiting to CPU %d failed in powernowk8_get\n", cpu); |
| 1406 | set_cpus_allowed_ptr(current, &oldmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | return 0; |
| 1408 | } |
Dave Jones | b9111b7 | 2005-09-23 11:10:42 -0700 | [diff] [blame] | 1409 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | if (query_current_values_with_pending_wait(data)) |
| 1411 | goto out; |
| 1412 | |
Joachim Deguara | 58389a8 | 2007-01-30 16:53:54 +0100 | [diff] [blame] | 1413 | if (cpu_family == CPU_HW_PSTATE) |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 1414 | khz = find_khz_freq_from_pstate(data->powernow_table, |
| 1415 | data->currpstate); |
Joachim Deguara | 58389a8 | 2007-01-30 16:53:54 +0100 | [diff] [blame] | 1416 | else |
| 1417 | khz = find_khz_freq_from_fid(data->currfid); |
| 1418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | |
Dave Jones | b9111b7 | 2005-09-23 11:10:42 -0700 | [diff] [blame] | 1420 | out: |
Mike Travis | fc0e474 | 2008-04-04 18:11:05 -0700 | [diff] [blame] | 1421 | set_cpus_allowed_ptr(current, &oldmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | return khz; |
| 1423 | } |
| 1424 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1425 | static struct freq_attr *powernow_k8_attr[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | &cpufreq_freq_attr_scaling_available_freqs, |
| 1427 | NULL, |
| 1428 | }; |
| 1429 | |
Linus Torvalds | 221dee2 | 2007-02-26 14:55:48 -0800 | [diff] [blame] | 1430 | static struct cpufreq_driver cpufreq_amd64_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | .verify = powernowk8_verify, |
| 1432 | .target = powernowk8_target, |
| 1433 | .init = powernowk8_cpu_init, |
| 1434 | .exit = __devexit_p(powernowk8_cpu_exit), |
| 1435 | .get = powernowk8_get, |
| 1436 | .name = "powernow-k8", |
| 1437 | .owner = THIS_MODULE, |
| 1438 | .attr = powernow_k8_attr, |
| 1439 | }; |
| 1440 | |
| 1441 | /* driver entry point for init */ |
Andi Kleen | aa41eb9 | 2006-01-16 01:56:36 +0100 | [diff] [blame] | 1442 | static int __cpuinit powernowk8_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | { |
| 1444 | unsigned int i, supported_cpus = 0; |
| 1445 | |
Andrew Morton | a720115 | 2006-03-24 03:15:07 -0800 | [diff] [blame] | 1446 | for_each_online_cpu(i) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | if (check_supported_cpu(i)) |
| 1448 | supported_cpus++; |
| 1449 | } |
| 1450 | |
| 1451 | if (supported_cpus == num_online_cpus()) { |
Dave Jones | 1f729e0 | 2006-06-04 19:37:58 -0400 | [diff] [blame] | 1452 | printk(KERN_INFO PFX "Found %d %s " |
Dave Jones | 904f7a3 | 2007-05-18 13:22:28 -0400 | [diff] [blame] | 1453 | "processors (%d cpu cores) (" VERSION ")\n", |
Yinghai Lu | c925401 | 2007-08-22 18:44:20 -0700 | [diff] [blame] | 1454 | num_online_nodes(), |
Dave Jones | 904f7a3 | 2007-05-18 13:22:28 -0400 | [diff] [blame] | 1455 | boot_cpu_data.x86_model_id, supported_cpus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | return cpufreq_register_driver(&cpufreq_amd64_driver); |
| 1457 | } |
| 1458 | |
| 1459 | return -ENODEV; |
| 1460 | } |
| 1461 | |
| 1462 | /* driver entry point for term */ |
| 1463 | static void __exit powernowk8_exit(void) |
| 1464 | { |
| 1465 | dprintk("exit\n"); |
| 1466 | |
| 1467 | cpufreq_unregister_driver(&cpufreq_amd64_driver); |
| 1468 | } |
| 1469 | |
Dave Jones | 0e64a0c | 2009-02-04 14:37:50 -0500 | [diff] [blame] | 1470 | MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and " |
| 1471 | "Mark Langsdorf <mark.langsdorf@amd.com>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver."); |
| 1473 | MODULE_LICENSE("GPL"); |
| 1474 | |
| 1475 | late_initcall(powernowk8_init); |
| 1476 | module_exit(powernowk8_exit); |