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