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