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