blob: fea0af0476b96371f4c71fabcb463ab65d74fc89 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -07002 * acpi-cpufreq.c - ACPI Processor P-States Driver ($Revision: 1.4 $)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
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 Pallipadife27cb32006-10-03 12:29:15 -07007 * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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 Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/init.h>
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -070031#include <linux/smp.h>
32#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/cpufreq.h>
Venkatesh Pallipadid395bf12005-08-25 15:59:00 -040034#include <linux/compiler.h>
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -070035#include <linux/dmi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37#include <linux/acpi.h>
38#include <acpi/processor.h>
39
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -070040#include <asm/io.h>
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -070041#include <asm/msr.h>
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -070042#include <asm/processor.h>
43#include <asm/cpufeature.h>
44#include <asm/delay.h>
45#include <asm/uaccess.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "acpi-cpufreq", msg)
48
49MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
50MODULE_DESCRIPTION("ACPI Processor P-States Driver");
51MODULE_LICENSE("GPL");
52
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -070053enum {
54 UNDEFINED_CAPABLE = 0,
55 SYSTEM_INTEL_MSR_CAPABLE,
56 SYSTEM_IO_CAPABLE,
57};
58
59#define INTEL_MSR_RANGE (0xffff)
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -070060#define CPUID_6_ECX_APERFMPERF_CAPABILITY (0x1)
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -070061
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -070062struct acpi_cpufreq_data {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -070063 struct acpi_processor_performance *acpi_data;
64 struct cpufreq_frequency_table *freq_table;
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -070065 unsigned int max_freq;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -070066 unsigned int resume;
67 unsigned int cpu_feature;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068};
69
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -070070static struct acpi_cpufreq_data *drv_data[NR_CPUS];
Fenghua Yu50109292007-08-07 18:40:30 -040071/* acpi_perf_data is a pointer to percpu data. */
72static struct acpi_processor_performance *acpi_perf_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74static struct cpufreq_driver acpi_cpufreq_driver;
75
Venkatesh Pallipadid395bf12005-08-25 15:59:00 -040076static unsigned int acpi_pstate_strict;
77
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -070078static int check_est_cpu(unsigned int cpuid)
79{
Mike Travis92cb7612007-10-19 20:35:04 +020080 struct cpuinfo_x86 *cpu = &cpu_data(cpuid);
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -070081
82 if (cpu->x86_vendor != X86_VENDOR_INTEL ||
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -070083 !cpu_has(cpu, X86_FEATURE_EST))
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -070084 return 0;
85
86 return 1;
87}
88
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -070089static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data)
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -070090{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -070091 struct acpi_processor_performance *perf;
92 int i;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -070093
94 perf = data->acpi_data;
95
Dave Jones95dd7222006-10-18 00:41:48 -040096 for (i=0; i<perf->state_count; i++) {
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -070097 if (value == perf->states[i].status)
98 return data->freq_table[i].frequency;
99 }
100 return 0;
101}
102
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700103static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
104{
105 int i;
Venkatesh Pallipadia6f6e6e62006-10-03 12:37:42 -0700106 struct acpi_processor_performance *perf;
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700107
108 msr &= INTEL_MSR_RANGE;
Venkatesh Pallipadia6f6e6e62006-10-03 12:37:42 -0700109 perf = data->acpi_data;
110
Dave Jones95dd7222006-10-18 00:41:48 -0400111 for (i=0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
Venkatesh Pallipadia6f6e6e62006-10-03 12:37:42 -0700112 if (msr == perf->states[data->freq_table[i].index].status)
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700113 return data->freq_table[i].frequency;
114 }
115 return data->freq_table[0].frequency;
116}
117
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700118static unsigned extract_freq(u32 val, struct acpi_cpufreq_data *data)
119{
120 switch (data->cpu_feature) {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700121 case SYSTEM_INTEL_MSR_CAPABLE:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700122 return extract_msr(val, data);
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700123 case SYSTEM_IO_CAPABLE:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700124 return extract_io(val, data);
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700125 default:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700126 return 0;
127 }
128}
129
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700130struct msr_addr {
131 u32 reg;
132};
133
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700134struct io_addr {
135 u16 port;
136 u8 bit_width;
137};
138
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700139typedef union {
140 struct msr_addr msr;
141 struct io_addr io;
142} drv_addr_union;
143
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700144struct drv_cmd {
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700145 unsigned int type;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700146 cpumask_t mask;
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700147 drv_addr_union addr;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700148 u32 val;
149};
150
151static void do_drv_read(struct drv_cmd *cmd)
152{
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700153 u32 h;
154
155 switch (cmd->type) {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700156 case SYSTEM_INTEL_MSR_CAPABLE:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700157 rdmsr(cmd->addr.msr.reg, cmd->val, h);
158 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700159 case SYSTEM_IO_CAPABLE:
Venkatesh Pallipadi4e581ff2006-12-13 10:41:16 -0800160 acpi_os_read_port((acpi_io_address)cmd->addr.io.port,
161 &cmd->val,
162 (u32)cmd->addr.io.bit_width);
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700163 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700164 default:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700165 break;
166 }
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700167}
168
169static void do_drv_write(struct drv_cmd *cmd)
170{
Venki Pallipadi13424f62007-05-23 15:42:13 -0700171 u32 lo, hi;
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700172
173 switch (cmd->type) {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700174 case SYSTEM_INTEL_MSR_CAPABLE:
Venki Pallipadi13424f62007-05-23 15:42:13 -0700175 rdmsr(cmd->addr.msr.reg, lo, hi);
176 lo = (lo & ~INTEL_MSR_RANGE) | (cmd->val & INTEL_MSR_RANGE);
177 wrmsr(cmd->addr.msr.reg, lo, hi);
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700178 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700179 case SYSTEM_IO_CAPABLE:
Venkatesh Pallipadi4e581ff2006-12-13 10:41:16 -0800180 acpi_os_write_port((acpi_io_address)cmd->addr.io.port,
181 cmd->val,
182 (u32)cmd->addr.io.bit_width);
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700183 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700184 default:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700185 break;
186 }
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700187}
188
Dave Jones95dd7222006-10-18 00:41:48 -0400189static void drv_read(struct drv_cmd *cmd)
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700190{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700191 cpumask_t saved_mask = current->cpus_allowed;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700192 cmd->val = 0;
193
194 set_cpus_allowed(current, cmd->mask);
195 do_drv_read(cmd);
196 set_cpus_allowed(current, saved_mask);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700197}
198
199static void drv_write(struct drv_cmd *cmd)
200{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700201 cpumask_t saved_mask = current->cpus_allowed;
202 unsigned int i;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700203
204 for_each_cpu_mask(i, cmd->mask) {
205 set_cpus_allowed(current, cpumask_of_cpu(i));
206 do_drv_write(cmd);
207 }
208
209 set_cpus_allowed(current, saved_mask);
210 return;
211}
212
213static u32 get_cur_val(cpumask_t mask)
214{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700215 struct acpi_processor_performance *perf;
216 struct drv_cmd cmd;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700217
218 if (unlikely(cpus_empty(mask)))
219 return 0;
220
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700221 switch (drv_data[first_cpu(mask)]->cpu_feature) {
222 case SYSTEM_INTEL_MSR_CAPABLE:
223 cmd.type = SYSTEM_INTEL_MSR_CAPABLE;
224 cmd.addr.msr.reg = MSR_IA32_PERF_STATUS;
225 break;
226 case SYSTEM_IO_CAPABLE:
227 cmd.type = SYSTEM_IO_CAPABLE;
228 perf = drv_data[first_cpu(mask)]->acpi_data;
229 cmd.addr.io.port = perf->control_register.address;
230 cmd.addr.io.bit_width = perf->control_register.bit_width;
231 break;
232 default:
233 return 0;
234 }
235
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700236 cmd.mask = mask;
237
238 drv_read(&cmd);
239
240 dprintk("get_cur_val = %u\n", cmd.val);
241
242 return cmd.val;
243}
244
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700245/*
246 * Return the measured active (C0) frequency on this CPU since last call
247 * to this function.
248 * Input: cpu number
249 * Return: Average CPU frequency in terms of max frequency (zero on error)
250 *
251 * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
252 * over a period of time, while CPU is in C0 state.
253 * IA32_MPERF counts at the rate of max advertised frequency
254 * IA32_APERF counts at the rate of actual CPU frequency
255 * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
256 * no meaning should be associated with absolute values of these MSRs.
257 */
258static unsigned int get_measured_perf(unsigned int cpu)
259{
260 union {
261 struct {
262 u32 lo;
263 u32 hi;
264 } split;
265 u64 whole;
266 } aperf_cur, mperf_cur;
267
268 cpumask_t saved_mask;
269 unsigned int perf_percent;
270 unsigned int retval;
271
272 saved_mask = current->cpus_allowed;
273 set_cpus_allowed(current, cpumask_of_cpu(cpu));
274 if (get_cpu() != cpu) {
275 /* We were not able to run on requested processor */
276 put_cpu();
277 return 0;
278 }
279
280 rdmsr(MSR_IA32_APERF, aperf_cur.split.lo, aperf_cur.split.hi);
281 rdmsr(MSR_IA32_MPERF, mperf_cur.split.lo, mperf_cur.split.hi);
282
283 wrmsr(MSR_IA32_APERF, 0,0);
284 wrmsr(MSR_IA32_MPERF, 0,0);
285
286#ifdef __i386__
287 /*
288 * We dont want to do 64 bit divide with 32 bit kernel
289 * Get an approximate value. Return failure in case we cannot get
290 * an approximate value.
291 */
292 if (unlikely(aperf_cur.split.hi || mperf_cur.split.hi)) {
293 int shift_count;
294 u32 h;
295
296 h = max_t(u32, aperf_cur.split.hi, mperf_cur.split.hi);
297 shift_count = fls(h);
298
299 aperf_cur.whole >>= shift_count;
300 mperf_cur.whole >>= shift_count;
301 }
302
303 if (((unsigned long)(-1) / 100) < aperf_cur.split.lo) {
304 int shift_count = 7;
305 aperf_cur.split.lo >>= shift_count;
306 mperf_cur.split.lo >>= shift_count;
307 }
308
Dave Jones95dd7222006-10-18 00:41:48 -0400309 if (aperf_cur.split.lo && mperf_cur.split.lo)
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700310 perf_percent = (aperf_cur.split.lo * 100) / mperf_cur.split.lo;
Dave Jones95dd7222006-10-18 00:41:48 -0400311 else
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700312 perf_percent = 0;
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700313
314#else
315 if (unlikely(((unsigned long)(-1) / 100) < aperf_cur.whole)) {
316 int shift_count = 7;
317 aperf_cur.whole >>= shift_count;
318 mperf_cur.whole >>= shift_count;
319 }
320
Dave Jones95dd7222006-10-18 00:41:48 -0400321 if (aperf_cur.whole && mperf_cur.whole)
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700322 perf_percent = (aperf_cur.whole * 100) / mperf_cur.whole;
Dave Jones95dd7222006-10-18 00:41:48 -0400323 else
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700324 perf_percent = 0;
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700325
326#endif
327
328 retval = drv_data[cpu]->max_freq * perf_percent / 100;
329
330 put_cpu();
331 set_cpus_allowed(current, saved_mask);
332
333 dprintk("cpu %d: performance percent %d\n", cpu, perf_percent);
334 return retval;
335}
336
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700337static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
338{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700339 struct acpi_cpufreq_data *data = drv_data[cpu];
340 unsigned int freq;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700341
342 dprintk("get_cur_freq_on_cpu (%d)\n", cpu);
343
344 if (unlikely(data == NULL ||
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700345 data->acpi_data == NULL || data->freq_table == NULL)) {
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700346 return 0;
347 }
348
349 freq = extract_freq(get_cur_val(cpumask_of_cpu(cpu)), data);
350 dprintk("cur freq = %u\n", freq);
351
352 return freq;
353}
354
355static unsigned int check_freqs(cpumask_t mask, unsigned int freq,
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700356 struct acpi_cpufreq_data *data)
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700357{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700358 unsigned int cur_freq;
359 unsigned int i;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700360
Dave Jones95dd7222006-10-18 00:41:48 -0400361 for (i=0; i<100; i++) {
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700362 cur_freq = extract_freq(get_cur_val(mask), data);
363 if (cur_freq == freq)
364 return 1;
365 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 }
367 return 0;
368}
369
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700370static int acpi_cpufreq_target(struct cpufreq_policy *policy,
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700371 unsigned int target_freq, unsigned int relation)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700373 struct acpi_cpufreq_data *data = drv_data[policy->cpu];
374 struct acpi_processor_performance *perf;
375 struct cpufreq_freqs freqs;
376 cpumask_t online_policy_cpus;
377 struct drv_cmd cmd;
Venkatesh Pallipadi8edc59d92006-12-19 12:58:55 -0800378 unsigned int next_state = 0; /* Index into freq_table */
379 unsigned int next_perf_state = 0; /* Index into perf table */
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700380 unsigned int i;
381 int result = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700383 dprintk("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700385 if (unlikely(data == NULL ||
Dave Jones95dd7222006-10-18 00:41:48 -0400386 data->acpi_data == NULL || data->freq_table == NULL)) {
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700387 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 }
389
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500390 perf = data->acpi_data;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700391 result = cpufreq_frequency_table_target(policy,
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700392 data->freq_table,
393 target_freq,
394 relation, &next_state);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700395 if (unlikely(result))
396 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Andrew Morton7e1f19e2006-03-28 17:03:00 -0500398#ifdef CONFIG_HOTPLUG_CPU
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500399 /* cpufreq holds the hotplug lock, so we are safe from here on */
400 cpus_and(online_policy_cpus, cpu_online_map, policy->cpus);
Andrew Morton7e1f19e2006-03-28 17:03:00 -0500401#else
402 online_policy_cpus = policy->cpus;
403#endif
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500404
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700405 next_perf_state = data->freq_table[next_state].index;
Venkatesh Pallipadi7650b282006-10-03 12:36:30 -0700406 if (perf->state == next_perf_state) {
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700407 if (unlikely(data->resume)) {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700408 dprintk("Called after resume, resetting to P%d\n",
409 next_perf_state);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700410 data->resume = 0;
411 } else {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700412 dprintk("Already at target state (P%d)\n",
413 next_perf_state);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700414 return 0;
415 }
416 }
417
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700418 switch (data->cpu_feature) {
419 case SYSTEM_INTEL_MSR_CAPABLE:
420 cmd.type = SYSTEM_INTEL_MSR_CAPABLE;
421 cmd.addr.msr.reg = MSR_IA32_PERF_CTL;
Venki Pallipadi13424f62007-05-23 15:42:13 -0700422 cmd.val = (u32) perf->states[next_perf_state].control;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700423 break;
424 case SYSTEM_IO_CAPABLE:
425 cmd.type = SYSTEM_IO_CAPABLE;
426 cmd.addr.io.port = perf->control_register.address;
427 cmd.addr.io.bit_width = perf->control_register.bit_width;
428 cmd.val = (u32) perf->states[next_perf_state].control;
429 break;
430 default:
431 return -ENODEV;
432 }
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700433
434 cpus_clear(cmd.mask);
435
436 if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
437 cmd.mask = online_policy_cpus;
438 else
439 cpu_set(policy->cpu, cmd.mask);
440
Venkatesh Pallipadi8edc59d92006-12-19 12:58:55 -0800441 freqs.old = perf->states[perf->state].core_frequency * 1000;
442 freqs.new = data->freq_table[next_state].frequency;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700443 for_each_cpu_mask(i, cmd.mask) {
444 freqs.cpu = i;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500445 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
446 }
447
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700448 drv_write(&cmd);
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500449
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700450 if (acpi_pstate_strict) {
451 if (!check_freqs(cmd.mask, freqs.new, data)) {
452 dprintk("acpi_cpufreq_target failed (%d)\n",
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700453 policy->cpu);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700454 return -EAGAIN;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500455 }
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500456 }
457
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700458 for_each_cpu_mask(i, cmd.mask) {
459 freqs.cpu = i;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500460 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
461 }
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700462 perf->state = next_perf_state;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500463
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700464 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465}
466
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700467static int acpi_cpufreq_verify(struct cpufreq_policy *policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700469 struct acpi_cpufreq_data *data = drv_data[policy->cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
471 dprintk("acpi_cpufreq_verify\n");
472
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700473 return cpufreq_frequency_table_verify(policy, data->freq_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476static unsigned long
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700477acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700479 struct acpi_processor_performance *perf = data->acpi_data;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (cpu_khz) {
482 /* search the closest match to cpu_khz */
483 unsigned int i;
484 unsigned long freq;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500485 unsigned long freqn = perf->states[0].core_frequency * 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Dave Jones95dd7222006-10-18 00:41:48 -0400487 for (i=0; i<(perf->state_count-1); i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 freq = freqn;
Dave Jones95dd7222006-10-18 00:41:48 -0400489 freqn = perf->states[i+1].core_frequency * 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if ((2 * cpu_khz) > (freqn + freq)) {
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500491 perf->state = i;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700492 return freq;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 }
494 }
Dave Jones95dd7222006-10-18 00:41:48 -0400495 perf->state = perf->state_count-1;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700496 return freqn;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500497 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 /* assume CPU is at P0... */
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500499 perf->state = 0;
500 return perf->states[0].core_frequency * 1000;
501 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500504/*
505 * acpi_cpufreq_early_init - initialize ACPI P-States library
506 *
507 * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c)
508 * in order to determine correct frequency and voltage pairings. We can
509 * do _PDC and _PSD and find out the processor dependency for the
510 * actual init that will happen later...
511 */
Fenghua Yu50109292007-08-07 18:40:30 -0400512static int __init acpi_cpufreq_early_init(void)
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500513{
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500514 dprintk("acpi_cpufreq_early_init\n");
515
Fenghua Yu50109292007-08-07 18:40:30 -0400516 acpi_perf_data = alloc_percpu(struct acpi_processor_performance);
517 if (!acpi_perf_data) {
518 dprintk("Memory allocation error for acpi_perf_data.\n");
519 return -ENOMEM;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500520 }
521
522 /* Do initialization in ACPI core */
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700523 acpi_processor_preregister_performance(acpi_perf_data);
524 return 0;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500525}
526
Dave Jones95625b82006-10-21 01:37:39 -0400527#ifdef CONFIG_SMP
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -0700528/*
529 * Some BIOSes do SW_ANY coordination internally, either set it up in hw
530 * or do it in BIOS firmware and won't inform about it to OS. If not
531 * detected, this has a side effect of making CPU run at a different speed
532 * than OS intended it to run at. Detect it and handle it cleanly.
533 */
534static int bios_with_sw_any_bug;
535
Jeff Garzik18552562007-10-03 15:15:40 -0400536static int sw_any_bug_found(const struct dmi_system_id *d)
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -0700537{
538 bios_with_sw_any_bug = 1;
539 return 0;
540}
541
Jeff Garzik18552562007-10-03 15:15:40 -0400542static const struct dmi_system_id sw_any_bug_dmi_table[] = {
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -0700543 {
544 .callback = sw_any_bug_found,
545 .ident = "Supermicro Server X6DLP",
546 .matches = {
547 DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
548 DMI_MATCH(DMI_BIOS_VERSION, "080010"),
549 DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
550 },
551 },
552 { }
553};
Dave Jones95625b82006-10-21 01:37:39 -0400554#endif
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -0700555
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700556static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557{
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700558 unsigned int i;
559 unsigned int valid_states = 0;
560 unsigned int cpu = policy->cpu;
561 struct acpi_cpufreq_data *data;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700562 unsigned int result = 0;
Mike Travis92cb7612007-10-19 20:35:04 +0200563 struct cpuinfo_x86 *c = &cpu_data(policy->cpu);
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700564 struct acpi_processor_performance *perf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 dprintk("acpi_cpufreq_cpu_init\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700568 data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 if (!data)
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700570 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Fenghua Yu50109292007-08-07 18:40:30 -0400572 data->acpi_data = percpu_ptr(acpi_perf_data, cpu);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700573 drv_data[cpu] = data;
574
Dave Jones95dd7222006-10-18 00:41:48 -0400575 if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700576 acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500578 result = acpi_processor_register_performance(data->acpi_data, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 if (result)
580 goto err_free;
581
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500582 perf = data->acpi_data;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500583 policy->shared_type = perf->shared_type;
Dave Jones95dd7222006-10-18 00:41:48 -0400584
Venkatesh Pallipadi46f18e32006-06-26 00:34:43 -0400585 /*
Dave Jones95dd7222006-10-18 00:41:48 -0400586 * Will let policy->cpus know about dependency only when software
Venkatesh Pallipadi46f18e32006-06-26 00:34:43 -0400587 * coordination is required.
588 */
589 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -0700590 policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
Venkatesh Pallipadi46f18e32006-06-26 00:34:43 -0400591 policy->cpus = perf->shared_cpu_map;
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -0700592 }
593
594#ifdef CONFIG_SMP
595 dmi_check_system(sw_any_bug_dmi_table);
596 if (bios_with_sw_any_bug && cpus_weight(policy->cpus) == 1) {
597 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
Mike Travis08357612007-10-16 01:24:04 -0700598 policy->cpus = per_cpu(cpu_core_map, cpu);
Venkatesh Pallipadi8adcc0c2006-09-01 14:02:24 -0700599 }
600#endif
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500601
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 /* capability check */
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500603 if (perf->state_count <= 1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 dprintk("No P-States\n");
605 result = -ENODEV;
606 goto err_unreg;
607 }
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500608
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700609 if (perf->control_register.space_id != perf->status_register.space_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 result = -ENODEV;
611 goto err_unreg;
612 }
613
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700614 switch (perf->control_register.space_id) {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700615 case ACPI_ADR_SPACE_SYSTEM_IO:
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700616 dprintk("SYSTEM IO addr space\n");
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700617 data->cpu_feature = SYSTEM_IO_CAPABLE;
618 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700619 case ACPI_ADR_SPACE_FIXED_HARDWARE:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700620 dprintk("HARDWARE addr space\n");
621 if (!check_est_cpu(cpu)) {
622 result = -ENODEV;
623 goto err_unreg;
624 }
625 data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700626 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700627 default:
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700628 dprintk("Unknown addr space %d\n",
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700629 (u32) (perf->control_register.space_id));
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700630 result = -ENODEV;
631 goto err_unreg;
632 }
633
Dave Jones95dd7222006-10-18 00:41:48 -0400634 data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) *
635 (perf->state_count+1), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 if (!data->freq_table) {
637 result = -ENOMEM;
638 goto err_unreg;
639 }
640
641 /* detect transition latency */
642 policy->cpuinfo.transition_latency = 0;
Dave Jones95dd7222006-10-18 00:41:48 -0400643 for (i=0; i<perf->state_count; i++) {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700644 if ((perf->states[i].transition_latency * 1000) >
645 policy->cpuinfo.transition_latency)
646 policy->cpuinfo.transition_latency =
647 perf->states[i].transition_latency * 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700650 data->max_freq = perf->states[0].core_frequency * 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 /* table init */
Dave Jones95dd7222006-10-18 00:41:48 -0400652 for (i=0; i<perf->state_count; i++) {
Zhang Rui3cdf5522007-06-13 21:24:02 -0400653 if (i>0 && perf->states[i].core_frequency >=
654 data->freq_table[valid_states-1].frequency / 1000)
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700655 continue;
656
657 data->freq_table[valid_states].index = i;
658 data->freq_table[valid_states].frequency =
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700659 perf->states[i].core_frequency * 1000;
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700660 valid_states++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 }
Venkatesh Pallipadi3d4a7ef2006-11-13 17:47:44 -0800662 data->freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
Venkatesh Pallipadi8edc59d92006-12-19 12:58:55 -0800663 perf->state = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
665 result = cpufreq_frequency_table_cpuinfo(policy, data->freq_table);
Dave Jones95dd7222006-10-18 00:41:48 -0400666 if (result)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 goto err_freqfree;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
Mattia Dongilia507ac42006-12-15 19:52:45 +0100669 switch (perf->control_register.space_id) {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700670 case ACPI_ADR_SPACE_SYSTEM_IO:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700671 /* Current speed is unknown and not detectable by IO port */
672 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
673 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700674 case ACPI_ADR_SPACE_FIXED_HARDWARE:
Venkatesh Pallipadi7650b282006-10-03 12:36:30 -0700675 acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
Mattia Dongilia507ac42006-12-15 19:52:45 +0100676 policy->cur = get_cur_freq_on_cpu(cpu);
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700677 break;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700678 default:
Venkatesh Pallipadidde9f7b2006-10-03 12:33:14 -0700679 break;
680 }
681
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* notify BIOS that we exist */
683 acpi_processor_notify_smm(THIS_MODULE);
684
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700685 /* Check for APERF/MPERF support in hardware */
686 if (c->x86_vendor == X86_VENDOR_INTEL && c->cpuid_level >= 6) {
687 unsigned int ecx;
688 ecx = cpuid_ecx(6);
Dave Jones95dd7222006-10-18 00:41:48 -0400689 if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY)
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700690 acpi_cpufreq_driver.getavg = get_measured_perf;
Venkatesh Pallipadidfde5d62006-10-03 12:38:45 -0700691 }
692
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700693 dprintk("CPU%u - ACPI performance management activated.\n", cpu);
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500694 for (i = 0; i < perf->state_count; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 dprintk(" %cP%d: %d MHz, %d mW, %d uS\n",
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700696 (i == perf->state ? '*' : ' '), i,
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500697 (u32) perf->states[i].core_frequency,
698 (u32) perf->states[i].power,
699 (u32) perf->states[i].transition_latency);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu);
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700702
Dominik Brodowski4b31e772005-05-18 13:49:00 -0400703 /*
704 * the first call to ->target() should result in us actually
705 * writing something to the appropriate registers.
706 */
707 data->resume = 1;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700708
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700709 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
Dave Jones95dd7222006-10-18 00:41:48 -0400711err_freqfree:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 kfree(data->freq_table);
Dave Jones95dd7222006-10-18 00:41:48 -0400713err_unreg:
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500714 acpi_processor_unregister_performance(perf, cpu);
Dave Jones95dd7222006-10-18 00:41:48 -0400715err_free:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 kfree(data);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700717 drv_data[cpu] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700719 return result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720}
721
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700722static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723{
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700724 struct acpi_cpufreq_data *data = drv_data[policy->cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726 dprintk("acpi_cpufreq_cpu_exit\n");
727
728 if (data) {
729 cpufreq_frequency_table_put_attr(policy->cpu);
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700730 drv_data[policy->cpu] = NULL;
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700731 acpi_processor_unregister_performance(data->acpi_data,
732 policy->cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 kfree(data);
734 }
735
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700736 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737}
738
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700739static int acpi_cpufreq_resume(struct cpufreq_policy *policy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740{
Venkatesh Pallipadife27cb32006-10-03 12:29:15 -0700741 struct acpi_cpufreq_data *data = drv_data[policy->cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 dprintk("acpi_cpufreq_resume\n");
744
745 data->resume = 1;
746
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700747 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748}
749
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700750static struct freq_attr *acpi_cpufreq_attr[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 &cpufreq_freq_attr_scaling_available_freqs,
752 NULL,
753};
754
755static struct cpufreq_driver acpi_cpufreq_driver = {
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700756 .verify = acpi_cpufreq_verify,
757 .target = acpi_cpufreq_target,
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700758 .init = acpi_cpufreq_cpu_init,
759 .exit = acpi_cpufreq_cpu_exit,
760 .resume = acpi_cpufreq_resume,
761 .name = "acpi-cpufreq",
762 .owner = THIS_MODULE,
763 .attr = acpi_cpufreq_attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764};
765
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700766static int __init acpi_cpufreq_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Fenghua Yu50109292007-08-07 18:40:30 -0400768 int ret;
769
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770 dprintk("acpi_cpufreq_init\n");
771
Fenghua Yu50109292007-08-07 18:40:30 -0400772 ret = acpi_cpufreq_early_init();
773 if (ret)
774 return ret;
Venkatesh Pallipadi09b4d1e2005-12-14 15:05:00 -0500775
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700776 return cpufreq_register_driver(&acpi_cpufreq_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777}
778
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700779static void __exit acpi_cpufreq_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780{
781 dprintk("acpi_cpufreq_exit\n");
782
783 cpufreq_unregister_driver(&acpi_cpufreq_driver);
784
Fenghua Yu50109292007-08-07 18:40:30 -0400785 free_percpu(acpi_perf_data);
786
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787 return;
788}
789
Venkatesh Pallipadid395bf12005-08-25 15:59:00 -0400790module_param(acpi_pstate_strict, uint, 0644);
Venkatesh Pallipadi64be7ee2006-10-03 12:35:23 -0700791MODULE_PARM_DESC(acpi_pstate_strict,
Dave Jones95dd7222006-10-18 00:41:48 -0400792 "value 0 or non-zero. non-zero -> strict ACPI checks are "
793 "performed during frequency changes.");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795late_initcall(acpi_cpufreq_init);
796module_exit(acpi_cpufreq_exit);
797
798MODULE_ALIAS("acpi");