Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * acpi-cpufreq.c - ACPI Processor P-States Driver ($Revision: 1.3 $) |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> |
| 5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> |
| 6 | * Copyright (C) 2002 - 2004 Dominik Brodowski <linux@brodo.de> |
| 7 | * |
| 8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or (at |
| 13 | * your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License along |
| 21 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 22 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 23 | * |
| 24 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 25 | */ |
| 26 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/kernel.h> |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/cpufreq.h> |
| 31 | #include <linux/proc_fs.h> |
| 32 | #include <linux/seq_file.h> |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 33 | #include <linux/compiler.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 34 | #include <linux/sched.h> /* current */ |
Venkatesh Pallipadi | 8adcc0c | 2006-09-01 14:02:24 -0700 | [diff] [blame] | 35 | #include <linux/dmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <asm/io.h> |
| 37 | #include <asm/delay.h> |
| 38 | #include <asm/uaccess.h> |
| 39 | |
| 40 | #include <linux/acpi.h> |
| 41 | #include <acpi/processor.h> |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "acpi-cpufreq", msg) |
| 44 | |
| 45 | MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); |
| 46 | MODULE_DESCRIPTION("ACPI Processor P-States Driver"); |
| 47 | MODULE_LICENSE("GPL"); |
| 48 | |
| 49 | |
| 50 | struct cpufreq_acpi_io { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 51 | struct acpi_processor_performance *acpi_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | struct cpufreq_frequency_table *freq_table; |
| 53 | unsigned int resume; |
| 54 | }; |
| 55 | |
| 56 | static struct cpufreq_acpi_io *acpi_io_data[NR_CPUS]; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 57 | static struct acpi_processor_performance *acpi_perf_data[NR_CPUS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | static struct cpufreq_driver acpi_cpufreq_driver; |
| 60 | |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 61 | static unsigned int acpi_pstate_strict; |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | static int |
| 64 | acpi_processor_write_port( |
| 65 | u16 port, |
| 66 | u8 bit_width, |
| 67 | u32 value) |
| 68 | { |
| 69 | if (bit_width <= 8) { |
| 70 | outb(value, port); |
| 71 | } else if (bit_width <= 16) { |
| 72 | outw(value, port); |
| 73 | } else if (bit_width <= 32) { |
| 74 | outl(value, port); |
| 75 | } else { |
| 76 | return -ENODEV; |
| 77 | } |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static int |
| 82 | acpi_processor_read_port( |
| 83 | u16 port, |
| 84 | u8 bit_width, |
| 85 | u32 *ret) |
| 86 | { |
| 87 | *ret = 0; |
| 88 | if (bit_width <= 8) { |
| 89 | *ret = inb(port); |
| 90 | } else if (bit_width <= 16) { |
| 91 | *ret = inw(port); |
| 92 | } else if (bit_width <= 32) { |
| 93 | *ret = inl(port); |
| 94 | } else { |
| 95 | return -ENODEV; |
| 96 | } |
| 97 | return 0; |
| 98 | } |
| 99 | |
| 100 | static int |
| 101 | acpi_processor_set_performance ( |
| 102 | struct cpufreq_acpi_io *data, |
| 103 | unsigned int cpu, |
| 104 | int state) |
| 105 | { |
| 106 | u16 port = 0; |
| 107 | u8 bit_width = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | int i = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | int ret = 0; |
| 110 | u32 value = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | int retval; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 112 | struct acpi_processor_performance *perf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
| 114 | dprintk("acpi_processor_set_performance\n"); |
| 115 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 116 | retval = 0; |
| 117 | perf = data->acpi_data; |
| 118 | if (state == perf->state) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | if (unlikely(data->resume)) { |
| 120 | dprintk("Called after resume, resetting to P%d\n", state); |
| 121 | data->resume = 0; |
| 122 | } else { |
| 123 | dprintk("Already at target state (P%d)\n", state); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 124 | return (retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | } |
| 127 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 128 | dprintk("Transitioning from P%d to P%d\n", perf->state, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * First we write the target state's 'control' value to the |
| 132 | * control_register. |
| 133 | */ |
| 134 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 135 | port = perf->control_register.address; |
| 136 | bit_width = perf->control_register.bit_width; |
| 137 | value = (u32) perf->states[state].control; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | dprintk("Writing 0x%08x to port 0x%04x\n", value, port); |
| 140 | |
| 141 | ret = acpi_processor_write_port(port, bit_width, value); |
| 142 | if (ret) { |
| 143 | dprintk("Invalid port width 0x%04x\n", bit_width); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 144 | return (ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 148 | * Assume the write went through when acpi_pstate_strict is not used. |
| 149 | * As read status_register is an expensive operation and there |
| 150 | * are no specific error cases where an IO port write will fail. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | */ |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 152 | if (acpi_pstate_strict) { |
| 153 | /* Then we read the 'status_register' and compare the value |
| 154 | * with the target state's 'status' to make sure the |
| 155 | * transition was successful. |
| 156 | * Note that we'll poll for up to 1ms (100 cycles of 10us) |
| 157 | * before giving up. |
| 158 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 160 | port = perf->status_register.address; |
| 161 | bit_width = perf->status_register.bit_width; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 163 | dprintk("Looking for 0x%08x from port 0x%04x\n", |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 164 | (u32) perf->states[state].status, port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 166 | for (i = 0; i < 100; i++) { |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 167 | ret = acpi_processor_read_port(port, bit_width, &value); |
| 168 | if (ret) { |
| 169 | dprintk("Invalid port width 0x%04x\n", bit_width); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 170 | return (ret); |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 171 | } |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 172 | if (value == (u32) perf->states[state].status) |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 173 | break; |
| 174 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 176 | } else { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 177 | value = (u32) perf->states[state].status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 180 | if (unlikely(value != (u32) perf->states[state].status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | printk(KERN_WARNING "acpi-cpufreq: Transition failed\n"); |
| 182 | retval = -ENODEV; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 183 | return (retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | dprintk("Transition successful after %d microseconds\n", i * 10); |
| 187 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 188 | perf->state = state; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | return (retval); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | static int |
| 194 | acpi_cpufreq_target ( |
| 195 | struct cpufreq_policy *policy, |
| 196 | unsigned int target_freq, |
| 197 | unsigned int relation) |
| 198 | { |
| 199 | struct cpufreq_acpi_io *data = acpi_io_data[policy->cpu]; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 200 | struct acpi_processor_performance *perf; |
| 201 | struct cpufreq_freqs freqs; |
| 202 | cpumask_t online_policy_cpus; |
| 203 | cpumask_t saved_mask; |
| 204 | cpumask_t set_mask; |
| 205 | cpumask_t covered_cpus; |
| 206 | unsigned int cur_state = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | unsigned int next_state = 0; |
| 208 | unsigned int result = 0; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 209 | unsigned int j; |
| 210 | unsigned int tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | dprintk("acpi_cpufreq_setpolicy\n"); |
| 213 | |
| 214 | result = cpufreq_frequency_table_target(policy, |
| 215 | data->freq_table, |
| 216 | target_freq, |
| 217 | relation, |
| 218 | &next_state); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 219 | if (unlikely(result)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | return (result); |
| 221 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 222 | perf = data->acpi_data; |
| 223 | cur_state = perf->state; |
| 224 | freqs.old = data->freq_table[cur_state].frequency; |
| 225 | freqs.new = data->freq_table[next_state].frequency; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Andrew Morton | 7e1f19e | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 227 | #ifdef CONFIG_HOTPLUG_CPU |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 228 | /* cpufreq holds the hotplug lock, so we are safe from here on */ |
| 229 | cpus_and(online_policy_cpus, cpu_online_map, policy->cpus); |
Andrew Morton | 7e1f19e | 2006-03-28 17:03:00 -0500 | [diff] [blame] | 230 | #else |
| 231 | online_policy_cpus = policy->cpus; |
| 232 | #endif |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 233 | |
| 234 | for_each_cpu_mask(j, online_policy_cpus) { |
| 235 | freqs.cpu = j; |
| 236 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | * We need to call driver->target() on all or any CPU in |
| 241 | * policy->cpus, depending on policy->shared_type. |
| 242 | */ |
| 243 | saved_mask = current->cpus_allowed; |
| 244 | cpus_clear(covered_cpus); |
| 245 | for_each_cpu_mask(j, online_policy_cpus) { |
| 246 | /* |
| 247 | * Support for SMP systems. |
| 248 | * Make sure we are running on CPU that wants to change freq |
| 249 | */ |
| 250 | cpus_clear(set_mask); |
| 251 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) |
| 252 | cpus_or(set_mask, set_mask, online_policy_cpus); |
| 253 | else |
| 254 | cpu_set(j, set_mask); |
| 255 | |
| 256 | set_cpus_allowed(current, set_mask); |
| 257 | if (unlikely(!cpu_isset(smp_processor_id(), set_mask))) { |
| 258 | dprintk("couldn't limit to CPUs in this domain\n"); |
| 259 | result = -EAGAIN; |
| 260 | break; |
| 261 | } |
| 262 | |
| 263 | result = acpi_processor_set_performance (data, j, next_state); |
| 264 | if (result) { |
| 265 | result = -EAGAIN; |
| 266 | break; |
| 267 | } |
| 268 | |
| 269 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) |
| 270 | break; |
| 271 | |
| 272 | cpu_set(j, covered_cpus); |
| 273 | } |
| 274 | |
| 275 | for_each_cpu_mask(j, online_policy_cpus) { |
| 276 | freqs.cpu = j; |
| 277 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
| 278 | } |
| 279 | |
| 280 | if (unlikely(result)) { |
| 281 | /* |
| 282 | * We have failed halfway through the frequency change. |
| 283 | * We have sent callbacks to online_policy_cpus and |
| 284 | * acpi_processor_set_performance() has been called on |
| 285 | * coverd_cpus. Best effort undo.. |
| 286 | */ |
| 287 | |
| 288 | if (!cpus_empty(covered_cpus)) { |
| 289 | for_each_cpu_mask(j, covered_cpus) { |
| 290 | policy->cpu = j; |
| 291 | acpi_processor_set_performance (data, |
| 292 | j, |
| 293 | cur_state); |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | tmp = freqs.new; |
| 298 | freqs.new = freqs.old; |
| 299 | freqs.old = tmp; |
| 300 | for_each_cpu_mask(j, online_policy_cpus) { |
| 301 | freqs.cpu = j; |
| 302 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
| 303 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | set_cpus_allowed(current, saved_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | return (result); |
| 309 | } |
| 310 | |
| 311 | |
| 312 | static int |
| 313 | acpi_cpufreq_verify ( |
| 314 | struct cpufreq_policy *policy) |
| 315 | { |
| 316 | unsigned int result = 0; |
| 317 | struct cpufreq_acpi_io *data = acpi_io_data[policy->cpu]; |
| 318 | |
| 319 | dprintk("acpi_cpufreq_verify\n"); |
| 320 | |
| 321 | result = cpufreq_frequency_table_verify(policy, |
| 322 | data->freq_table); |
| 323 | |
| 324 | return (result); |
| 325 | } |
| 326 | |
| 327 | |
| 328 | static unsigned long |
| 329 | acpi_cpufreq_guess_freq ( |
| 330 | struct cpufreq_acpi_io *data, |
| 331 | unsigned int cpu) |
| 332 | { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 333 | struct acpi_processor_performance *perf = data->acpi_data; |
| 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | if (cpu_khz) { |
| 336 | /* search the closest match to cpu_khz */ |
| 337 | unsigned int i; |
| 338 | unsigned long freq; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 339 | unsigned long freqn = perf->states[0].core_frequency * 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 341 | for (i = 0; i < (perf->state_count - 1); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | freq = freqn; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 343 | freqn = perf->states[i+1].core_frequency * 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | if ((2 * cpu_khz) > (freqn + freq)) { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 345 | perf->state = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return (freq); |
| 347 | } |
| 348 | } |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 349 | perf->state = perf->state_count - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | return (freqn); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 351 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* assume CPU is at P0... */ |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 353 | perf->state = 0; |
| 354 | return perf->states[0].core_frequency * 1000; |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 359 | /* |
| 360 | * acpi_cpufreq_early_init - initialize ACPI P-States library |
| 361 | * |
| 362 | * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c) |
| 363 | * in order to determine correct frequency and voltage pairings. We can |
| 364 | * do _PDC and _PSD and find out the processor dependency for the |
| 365 | * actual init that will happen later... |
| 366 | */ |
| 367 | static int acpi_cpufreq_early_init_acpi(void) |
| 368 | { |
| 369 | struct acpi_processor_performance *data; |
| 370 | unsigned int i, j; |
| 371 | |
| 372 | dprintk("acpi_cpufreq_early_init\n"); |
| 373 | |
Andrew Morton | fb1bb34 | 2006-06-25 05:46:43 -0700 | [diff] [blame] | 374 | for_each_possible_cpu(i) { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 375 | data = kzalloc(sizeof(struct acpi_processor_performance), |
| 376 | GFP_KERNEL); |
| 377 | if (!data) { |
Andrew Morton | fb1bb34 | 2006-06-25 05:46:43 -0700 | [diff] [blame] | 378 | for_each_possible_cpu(j) { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 379 | kfree(acpi_perf_data[j]); |
| 380 | acpi_perf_data[j] = NULL; |
| 381 | } |
| 382 | return (-ENOMEM); |
| 383 | } |
| 384 | acpi_perf_data[i] = data; |
| 385 | } |
| 386 | |
| 387 | /* Do initialization in ACPI core */ |
bert hubert | 12e704d | 2006-07-30 21:19:32 +0200 | [diff] [blame] | 388 | return acpi_processor_preregister_performance(acpi_perf_data); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 389 | } |
| 390 | |
Venkatesh Pallipadi | 8adcc0c | 2006-09-01 14:02:24 -0700 | [diff] [blame] | 391 | /* |
| 392 | * Some BIOSes do SW_ANY coordination internally, either set it up in hw |
| 393 | * or do it in BIOS firmware and won't inform about it to OS. If not |
| 394 | * detected, this has a side effect of making CPU run at a different speed |
| 395 | * than OS intended it to run at. Detect it and handle it cleanly. |
| 396 | */ |
| 397 | static int bios_with_sw_any_bug; |
| 398 | |
Venkatesh Pallipadi | 0497c8c | 2006-09-25 11:23:32 -0700 | [diff] [blame^] | 399 | static int sw_any_bug_found(struct dmi_system_id *d) |
Venkatesh Pallipadi | 8adcc0c | 2006-09-01 14:02:24 -0700 | [diff] [blame] | 400 | { |
| 401 | bios_with_sw_any_bug = 1; |
| 402 | return 0; |
| 403 | } |
| 404 | |
Venkatesh Pallipadi | 0497c8c | 2006-09-25 11:23:32 -0700 | [diff] [blame^] | 405 | static struct dmi_system_id sw_any_bug_dmi_table[] = { |
Venkatesh Pallipadi | 8adcc0c | 2006-09-01 14:02:24 -0700 | [diff] [blame] | 406 | { |
| 407 | .callback = sw_any_bug_found, |
| 408 | .ident = "Supermicro Server X6DLP", |
| 409 | .matches = { |
| 410 | DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"), |
| 411 | DMI_MATCH(DMI_BIOS_VERSION, "080010"), |
| 412 | DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"), |
| 413 | }, |
| 414 | }, |
| 415 | { } |
| 416 | }; |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | static int |
| 419 | acpi_cpufreq_cpu_init ( |
| 420 | struct cpufreq_policy *policy) |
| 421 | { |
| 422 | unsigned int i; |
| 423 | unsigned int cpu = policy->cpu; |
| 424 | struct cpufreq_acpi_io *data; |
| 425 | unsigned int result = 0; |
Andi Kleen | 152bf8c | 2006-01-11 22:42:48 +0100 | [diff] [blame] | 426 | struct cpuinfo_x86 *c = &cpu_data[policy->cpu]; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 427 | struct acpi_processor_performance *perf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | dprintk("acpi_cpufreq_cpu_init\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 431 | if (!acpi_perf_data[cpu]) |
| 432 | return (-ENODEV); |
| 433 | |
Dave Jones | bfdc708 | 2005-10-20 15:16:15 -0700 | [diff] [blame] | 434 | data = kzalloc(sizeof(struct cpufreq_acpi_io), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | if (!data) |
| 436 | return (-ENOMEM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 438 | data->acpi_data = acpi_perf_data[cpu]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | acpi_io_data[cpu] = data; |
| 440 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 441 | result = acpi_processor_register_performance(data->acpi_data, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | if (result) |
| 444 | goto err_free; |
| 445 | |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 446 | perf = data->acpi_data; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 447 | policy->shared_type = perf->shared_type; |
Venkatesh Pallipadi | 46f18e3 | 2006-06-26 00:34:43 -0400 | [diff] [blame] | 448 | /* |
| 449 | * Will let policy->cpus know about dependency only when software |
| 450 | * coordination is required. |
| 451 | */ |
| 452 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL || |
Venkatesh Pallipadi | 8adcc0c | 2006-09-01 14:02:24 -0700 | [diff] [blame] | 453 | policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { |
Venkatesh Pallipadi | 46f18e3 | 2006-06-26 00:34:43 -0400 | [diff] [blame] | 454 | policy->cpus = perf->shared_cpu_map; |
Venkatesh Pallipadi | 8adcc0c | 2006-09-01 14:02:24 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | #ifdef CONFIG_SMP |
| 458 | dmi_check_system(sw_any_bug_dmi_table); |
| 459 | if (bios_with_sw_any_bug && cpus_weight(policy->cpus) == 1) { |
| 460 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; |
| 461 | policy->cpus = cpu_core_map[cpu]; |
| 462 | } |
| 463 | #endif |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 464 | |
Andi Kleen | 152bf8c | 2006-01-11 22:42:48 +0100 | [diff] [blame] | 465 | if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS; |
| 467 | } |
| 468 | |
| 469 | /* capability check */ |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 470 | if (perf->state_count <= 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | dprintk("No P-States\n"); |
| 472 | result = -ENODEV; |
| 473 | goto err_unreg; |
| 474 | } |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 475 | |
| 476 | if ((perf->control_register.space_id != ACPI_ADR_SPACE_SYSTEM_IO) || |
| 477 | (perf->status_register.space_id != ACPI_ADR_SPACE_SYSTEM_IO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | dprintk("Unsupported address space [%d, %d]\n", |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 479 | (u32) (perf->control_register.space_id), |
| 480 | (u32) (perf->status_register.space_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | result = -ENODEV; |
| 482 | goto err_unreg; |
| 483 | } |
| 484 | |
| 485 | /* alloc freq_table */ |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 486 | data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * (perf->state_count + 1), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | if (!data->freq_table) { |
| 488 | result = -ENOMEM; |
| 489 | goto err_unreg; |
| 490 | } |
| 491 | |
| 492 | /* detect transition latency */ |
| 493 | policy->cpuinfo.transition_latency = 0; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 494 | for (i=0; i<perf->state_count; i++) { |
| 495 | if ((perf->states[i].transition_latency * 1000) > policy->cpuinfo.transition_latency) |
| 496 | policy->cpuinfo.transition_latency = perf->states[i].transition_latency * 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | } |
| 498 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; |
| 499 | |
| 500 | /* The current speed is unknown and not detectable by ACPI... */ |
| 501 | policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu); |
| 502 | |
| 503 | /* table init */ |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 504 | for (i=0; i<=perf->state_count; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | { |
| 506 | data->freq_table[i].index = i; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 507 | if (i<perf->state_count) |
| 508 | data->freq_table[i].frequency = perf->states[i].core_frequency * 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | else |
| 510 | data->freq_table[i].frequency = CPUFREQ_TABLE_END; |
| 511 | } |
| 512 | |
| 513 | result = cpufreq_frequency_table_cpuinfo(policy, data->freq_table); |
| 514 | if (result) { |
| 515 | goto err_freqfree; |
| 516 | } |
| 517 | |
| 518 | /* notify BIOS that we exist */ |
| 519 | acpi_processor_notify_smm(THIS_MODULE); |
| 520 | |
| 521 | printk(KERN_INFO "acpi-cpufreq: CPU%u - ACPI performance management activated.\n", |
| 522 | cpu); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 523 | for (i = 0; i < perf->state_count; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | dprintk(" %cP%d: %d MHz, %d mW, %d uS\n", |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 525 | (i == perf->state?'*':' '), i, |
| 526 | (u32) perf->states[i].core_frequency, |
| 527 | (u32) perf->states[i].power, |
| 528 | (u32) perf->states[i].transition_latency); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | |
| 530 | cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu); |
Dominik Brodowski | 4b31e77 | 2005-05-18 13:49:00 -0400 | [diff] [blame] | 531 | |
| 532 | /* |
| 533 | * the first call to ->target() should result in us actually |
| 534 | * writing something to the appropriate registers. |
| 535 | */ |
| 536 | data->resume = 1; |
| 537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | return (result); |
| 539 | |
| 540 | err_freqfree: |
| 541 | kfree(data->freq_table); |
| 542 | err_unreg: |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 543 | acpi_processor_unregister_performance(perf, cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | err_free: |
| 545 | kfree(data); |
| 546 | acpi_io_data[cpu] = NULL; |
| 547 | |
| 548 | return (result); |
| 549 | } |
| 550 | |
| 551 | |
| 552 | static int |
| 553 | acpi_cpufreq_cpu_exit ( |
| 554 | struct cpufreq_policy *policy) |
| 555 | { |
| 556 | struct cpufreq_acpi_io *data = acpi_io_data[policy->cpu]; |
| 557 | |
| 558 | |
| 559 | dprintk("acpi_cpufreq_cpu_exit\n"); |
| 560 | |
| 561 | if (data) { |
| 562 | cpufreq_frequency_table_put_attr(policy->cpu); |
| 563 | acpi_io_data[policy->cpu] = NULL; |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 564 | acpi_processor_unregister_performance(data->acpi_data, policy->cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | kfree(data); |
| 566 | } |
| 567 | |
| 568 | return (0); |
| 569 | } |
| 570 | |
| 571 | static int |
| 572 | acpi_cpufreq_resume ( |
| 573 | struct cpufreq_policy *policy) |
| 574 | { |
| 575 | struct cpufreq_acpi_io *data = acpi_io_data[policy->cpu]; |
| 576 | |
| 577 | |
| 578 | dprintk("acpi_cpufreq_resume\n"); |
| 579 | |
| 580 | data->resume = 1; |
| 581 | |
| 582 | return (0); |
| 583 | } |
| 584 | |
| 585 | |
| 586 | static struct freq_attr* acpi_cpufreq_attr[] = { |
| 587 | &cpufreq_freq_attr_scaling_available_freqs, |
| 588 | NULL, |
| 589 | }; |
| 590 | |
| 591 | static struct cpufreq_driver acpi_cpufreq_driver = { |
Dave Jones | 911cb74 | 2006-06-01 11:38:28 -0400 | [diff] [blame] | 592 | .verify = acpi_cpufreq_verify, |
| 593 | .target = acpi_cpufreq_target, |
| 594 | .init = acpi_cpufreq_cpu_init, |
| 595 | .exit = acpi_cpufreq_cpu_exit, |
| 596 | .resume = acpi_cpufreq_resume, |
| 597 | .name = "acpi-cpufreq", |
| 598 | .owner = THIS_MODULE, |
| 599 | .attr = acpi_cpufreq_attr, |
| 600 | .flags = CPUFREQ_STICKY, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | }; |
| 602 | |
| 603 | |
| 604 | static int __init |
| 605 | acpi_cpufreq_init (void) |
| 606 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | dprintk("acpi_cpufreq_init\n"); |
| 608 | |
Dave Jones | a0cc621 | 2006-08-27 01:23:35 -0700 | [diff] [blame] | 609 | acpi_cpufreq_early_init_acpi(); |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 610 | |
Dave Jones | a0cc621 | 2006-08-27 01:23:35 -0700 | [diff] [blame] | 611 | return cpufreq_register_driver(&acpi_cpufreq_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | |
| 615 | static void __exit |
| 616 | acpi_cpufreq_exit (void) |
| 617 | { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 618 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | dprintk("acpi_cpufreq_exit\n"); |
| 620 | |
| 621 | cpufreq_unregister_driver(&acpi_cpufreq_driver); |
| 622 | |
Andrew Morton | fb1bb34 | 2006-06-25 05:46:43 -0700 | [diff] [blame] | 623 | for_each_possible_cpu(i) { |
Venkatesh Pallipadi | 09b4d1e | 2005-12-14 15:05:00 -0500 | [diff] [blame] | 624 | kfree(acpi_perf_data[i]); |
| 625 | acpi_perf_data[i] = NULL; |
| 626 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | return; |
| 628 | } |
| 629 | |
Venkatesh Pallipadi | d395bf1 | 2005-08-25 15:59:00 -0400 | [diff] [blame] | 630 | module_param(acpi_pstate_strict, uint, 0644); |
| 631 | MODULE_PARM_DESC(acpi_pstate_strict, "value 0 or non-zero. non-zero -> strict ACPI checks are performed during frequency changes."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | late_initcall(acpi_cpufreq_init); |
| 634 | module_exit(acpi_cpufreq_exit); |
| 635 | |
| 636 | MODULE_ALIAS("acpi"); |