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