Fix quilt merge error in acpi-cpufreq.c
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / kernel / cpu / cpufreq / acpi-cpufreq.c
blob837c2c4cc20305dc695b4b681512c8a5dcd2dc76
1 /*
2 * acpi-cpufreq.c - ACPI Processor P-States Driver
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 * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com>
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
25 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28 #include <linux/kernel.h>
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/smp.h>
32 #include <linux/sched.h>
33 #include <linux/cpufreq.h>
34 #include <linux/compiler.h>
35 #include <linux/dmi.h>
36 #include <trace/power.h>
38 #include <linux/acpi.h>
39 #include <linux/io.h>
40 #include <linux/delay.h>
41 #include <linux/uaccess.h>
43 #include <acpi/processor.h>
45 #include <asm/msr.h>
46 #include <asm/processor.h>
47 #include <asm/cpufeature.h>
49 #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
50 "acpi-cpufreq", msg)
52 MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
53 MODULE_DESCRIPTION("ACPI Processor P-States Driver");
54 MODULE_LICENSE("GPL");
56 enum {
57 UNDEFINED_CAPABLE = 0,
58 SYSTEM_INTEL_MSR_CAPABLE,
59 SYSTEM_IO_CAPABLE,
62 #define INTEL_MSR_RANGE (0xffff)
63 #define CPUID_6_ECX_APERFMPERF_CAPABILITY (0x1)
65 struct acpi_cpufreq_data {
66 struct acpi_processor_performance *acpi_data;
67 struct cpufreq_frequency_table *freq_table;
68 unsigned int max_freq;
69 unsigned int resume;
70 unsigned int cpu_feature;
71 u64 saved_aperf, saved_mperf;
74 static DEFINE_PER_CPU(struct acpi_cpufreq_data *, drv_data);
76 DEFINE_TRACE(power_mark);
78 /* acpi_perf_data is a pointer to percpu data. */
79 static struct acpi_processor_performance *acpi_perf_data;
81 static struct cpufreq_driver acpi_cpufreq_driver;
83 static unsigned int acpi_pstate_strict;
85 static int check_est_cpu(unsigned int cpuid)
87 struct cpuinfo_x86 *cpu = &cpu_data(cpuid);
89 if (cpu->x86_vendor != X86_VENDOR_INTEL ||
90 !cpu_has(cpu, X86_FEATURE_EST))
91 return 0;
93 return 1;
96 static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data)
98 struct acpi_processor_performance *perf;
99 int i;
101 perf = data->acpi_data;
103 for (i = 0; i < perf->state_count; i++) {
104 if (value == perf->states[i].status)
105 return data->freq_table[i].frequency;
107 return 0;
110 static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
112 int i;
113 struct acpi_processor_performance *perf;
115 msr &= INTEL_MSR_RANGE;
116 perf = data->acpi_data;
118 for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
119 if (msr == perf->states[data->freq_table[i].index].status)
120 return data->freq_table[i].frequency;
122 return data->freq_table[0].frequency;
125 static unsigned extract_freq(u32 val, struct acpi_cpufreq_data *data)
127 switch (data->cpu_feature) {
128 case SYSTEM_INTEL_MSR_CAPABLE:
129 return extract_msr(val, data);
130 case SYSTEM_IO_CAPABLE:
131 return extract_io(val, data);
132 default:
133 return 0;
137 struct msr_addr {
138 u32 reg;
141 struct io_addr {
142 u16 port;
143 u8 bit_width;
146 struct drv_cmd {
147 unsigned int type;
148 const struct cpumask *mask;
149 union {
150 struct msr_addr msr;
151 struct io_addr io;
152 } addr;
153 u32 val;
156 /* Called via smp_call_function_single(), on the target CPU */
157 static void do_drv_read(void *_cmd)
159 struct drv_cmd *cmd = _cmd;
160 u32 h;
162 switch (cmd->type) {
163 case SYSTEM_INTEL_MSR_CAPABLE:
164 rdmsr(cmd->addr.msr.reg, cmd->val, h);
165 break;
166 case SYSTEM_IO_CAPABLE:
167 acpi_os_read_port((acpi_io_address)cmd->addr.io.port,
168 &cmd->val,
169 (u32)cmd->addr.io.bit_width);
170 break;
171 default:
172 break;
176 /* Called via smp_call_function_many(), on the target CPUs */
177 static void do_drv_write(void *_cmd)
179 struct drv_cmd *cmd = _cmd;
180 u32 lo, hi;
182 switch (cmd->type) {
183 case SYSTEM_INTEL_MSR_CAPABLE:
184 rdmsr(cmd->addr.msr.reg, lo, hi);
185 lo = (lo & ~INTEL_MSR_RANGE) | (cmd->val & INTEL_MSR_RANGE);
186 wrmsr(cmd->addr.msr.reg, lo, hi);
187 break;
188 case SYSTEM_IO_CAPABLE:
189 acpi_os_write_port((acpi_io_address)cmd->addr.io.port,
190 cmd->val,
191 (u32)cmd->addr.io.bit_width);
192 break;
193 default:
194 break;
198 static void drv_read(struct drv_cmd *cmd)
200 cmd->val = 0;
202 smp_call_function_single(cpumask_any(cmd->mask), do_drv_read, cmd, 1);
205 static void drv_write(struct drv_cmd *cmd)
207 smp_call_function_many(cmd->mask, do_drv_write, cmd, 1);
210 static u32 get_cur_val(const struct cpumask *mask)
212 struct acpi_processor_performance *perf;
213 struct drv_cmd cmd;
215 if (unlikely(cpumask_empty(mask)))
216 return 0;
218 switch (per_cpu(drv_data, cpumask_first(mask))->cpu_feature) {
219 case SYSTEM_INTEL_MSR_CAPABLE:
220 cmd.type = SYSTEM_INTEL_MSR_CAPABLE;
221 cmd.addr.msr.reg = MSR_IA32_PERF_STATUS;
222 break;
223 case SYSTEM_IO_CAPABLE:
224 cmd.type = SYSTEM_IO_CAPABLE;
225 perf = per_cpu(drv_data, cpumask_first(mask))->acpi_data;
226 cmd.addr.io.port = perf->control_register.address;
227 cmd.addr.io.bit_width = perf->control_register.bit_width;
228 break;
229 default:
230 return 0;
233 cmd.mask = mask;
234 drv_read(&cmd);
236 dprintk("get_cur_val = %u\n", cmd.val);
238 return cmd.val;
241 struct perf_pair {
242 union {
243 struct {
244 u32 lo;
245 u32 hi;
246 } split;
247 u64 whole;
248 } aperf, mperf;
251 /* Called via smp_call_function_single(), on the target CPU */
252 static void read_measured_perf_ctrs(void *_cur)
254 struct perf_pair *cur = _cur;
256 rdmsr(MSR_IA32_APERF, cur->aperf.split.lo, cur->aperf.split.hi);
257 rdmsr(MSR_IA32_MPERF, cur->mperf.split.lo, cur->mperf.split.hi);
261 * Return the measured active (C0) frequency on this CPU since last call
262 * to this function.
263 * Input: cpu number
264 * Return: Average CPU frequency in terms of max frequency (zero on error)
266 * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance
267 * over a period of time, while CPU is in C0 state.
268 * IA32_MPERF counts at the rate of max advertised frequency
269 * IA32_APERF counts at the rate of actual CPU frequency
270 * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and
271 * no meaning should be associated with absolute values of these MSRs.
273 static unsigned int get_measured_perf(struct cpufreq_policy *policy,
274 unsigned int cpu)
276 struct perf_pair readin, cur;
277 unsigned int perf_percent;
278 unsigned int retval;
280 if (smp_call_function_single(cpu, read_measured_perf_ctrs, &readin, 1))
281 return 0;
283 cur.aperf.whole = readin.aperf.whole -
284 per_cpu(drv_data, cpu)->saved_aperf;
285 cur.mperf.whole = readin.mperf.whole -
286 per_cpu(drv_data, cpu)->saved_mperf;
287 per_cpu(drv_data, cpu)->saved_aperf = readin.aperf.whole;
288 per_cpu(drv_data, cpu)->saved_mperf = readin.mperf.whole;
290 #ifdef __i386__
292 * We dont want to do 64 bit divide with 32 bit kernel
293 * Get an approximate value. Return failure in case we cannot get
294 * an approximate value.
296 if (unlikely(cur.aperf.split.hi || cur.mperf.split.hi)) {
297 int shift_count;
298 u32 h;
300 h = max_t(u32, cur.aperf.split.hi, cur.mperf.split.hi);
301 shift_count = fls(h);
303 cur.aperf.whole >>= shift_count;
304 cur.mperf.whole >>= shift_count;
307 if (((unsigned long)(-1) / 100) < cur.aperf.split.lo) {
308 int shift_count = 7;
309 cur.aperf.split.lo >>= shift_count;
310 cur.mperf.split.lo >>= shift_count;
313 if (cur.aperf.split.lo && cur.mperf.split.lo)
314 perf_percent = (cur.aperf.split.lo * 100) / cur.mperf.split.lo;
315 else
316 perf_percent = 0;
318 #else
319 if (unlikely(((unsigned long)(-1) / 100) < cur.aperf.whole)) {
320 int shift_count = 7;
321 cur.aperf.whole >>= shift_count;
322 cur.mperf.whole >>= shift_count;
325 if (cur.aperf.whole && cur.mperf.whole)
326 perf_percent = (cur.aperf.whole * 100) / cur.mperf.whole;
327 else
328 perf_percent = 0;
330 #endif
332 retval = per_cpu(drv_data, policy->cpu)->max_freq * perf_percent / 100;
334 return retval;
337 static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
339 struct acpi_cpufreq_data *data = per_cpu(drv_data, cpu);
340 unsigned int freq;
341 unsigned int cached_freq;
343 dprintk("get_cur_freq_on_cpu (%d)\n", cpu);
345 if (unlikely(data == NULL ||
346 data->acpi_data == NULL || data->freq_table == NULL)) {
347 return 0;
350 cached_freq = data->freq_table[data->acpi_data->state].frequency;
351 freq = extract_freq(get_cur_val(cpumask_of(cpu)), data);
352 if (freq != cached_freq) {
354 * The dreaded BIOS frequency change behind our back.
355 * Force set the frequency on next target call.
357 data->resume = 1;
360 dprintk("cur freq = %u\n", freq);
362 return freq;
365 static unsigned int check_freqs(const struct cpumask *mask, unsigned int freq,
366 struct acpi_cpufreq_data *data)
368 unsigned int cur_freq;
369 unsigned int i;
371 for (i = 0; i < 100; i++) {
372 cur_freq = extract_freq(get_cur_val(mask), data);
373 if (cur_freq == freq)
374 return 1;
375 udelay(10);
377 return 0;
380 static int acpi_cpufreq_target(struct cpufreq_policy *policy,
381 unsigned int target_freq, unsigned int relation)
383 struct acpi_cpufreq_data *data = per_cpu(drv_data, policy->cpu);
384 struct acpi_processor_performance *perf;
385 struct cpufreq_freqs freqs;
386 struct drv_cmd cmd;
387 unsigned int next_state = 0; /* Index into freq_table */
388 unsigned int next_perf_state = 0; /* Index into perf table */
389 unsigned int i;
390 int result = 0;
391 struct power_trace it;
393 dprintk("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu);
395 if (unlikely(data == NULL ||
396 data->acpi_data == NULL || data->freq_table == NULL)) {
397 return -ENODEV;
400 perf = data->acpi_data;
401 result = cpufreq_frequency_table_target(policy,
402 data->freq_table,
403 target_freq,
404 relation, &next_state);
405 if (unlikely(result)) {
406 result = -ENODEV;
407 goto out;
410 next_perf_state = data->freq_table[next_state].index;
411 if (perf->state == next_perf_state) {
412 if (unlikely(data->resume)) {
413 dprintk("Called after resume, resetting to P%d\n",
414 next_perf_state);
415 data->resume = 0;
416 } else {
417 dprintk("Already at target state (P%d)\n",
418 next_perf_state);
419 goto out;
423 trace_power_mark(&it, POWER_PSTATE, next_perf_state);
425 switch (data->cpu_feature) {
426 case SYSTEM_INTEL_MSR_CAPABLE:
427 cmd.type = SYSTEM_INTEL_MSR_CAPABLE;
428 cmd.addr.msr.reg = MSR_IA32_PERF_CTL;
429 cmd.val = (u32) perf->states[next_perf_state].control;
430 break;
431 case SYSTEM_IO_CAPABLE:
432 cmd.type = SYSTEM_IO_CAPABLE;
433 cmd.addr.io.port = perf->control_register.address;
434 cmd.addr.io.bit_width = perf->control_register.bit_width;
435 cmd.val = (u32) perf->states[next_perf_state].control;
436 break;
437 default:
438 result = -ENODEV;
439 goto out;
442 /* cpufreq holds the hotplug lock, so we are safe from here on */
443 if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY)
444 cmd.mask = policy->cpus;
445 else
446 cmd.mask = cpumask_of(policy->cpu);
448 freqs.old = perf->states[perf->state].core_frequency * 1000;
449 freqs.new = data->freq_table[next_state].frequency;
450 for_each_cpu(i, cmd.mask) {
451 freqs.cpu = i;
452 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
455 drv_write(&cmd);
457 if (acpi_pstate_strict) {
458 if (!check_freqs(cmd.mask, freqs.new, data)) {
459 dprintk("acpi_cpufreq_target failed (%d)\n",
460 policy->cpu);
461 result = -EAGAIN;
462 goto out;
466 for_each_cpu(i, cmd.mask) {
467 freqs.cpu = i;
468 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
470 perf->state = next_perf_state;
472 out:
473 return result;
476 static int acpi_cpufreq_verify(struct cpufreq_policy *policy)
478 struct acpi_cpufreq_data *data = per_cpu(drv_data, policy->cpu);
480 dprintk("acpi_cpufreq_verify\n");
482 return cpufreq_frequency_table_verify(policy, data->freq_table);
485 static unsigned long
486 acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu)
488 struct acpi_processor_performance *perf = data->acpi_data;
490 if (cpu_khz) {
491 /* search the closest match to cpu_khz */
492 unsigned int i;
493 unsigned long freq;
494 unsigned long freqn = perf->states[0].core_frequency * 1000;
496 for (i = 0; i < (perf->state_count-1); i++) {
497 freq = freqn;
498 freqn = perf->states[i+1].core_frequency * 1000;
499 if ((2 * cpu_khz) > (freqn + freq)) {
500 perf->state = i;
501 return freq;
504 perf->state = perf->state_count-1;
505 return freqn;
506 } else {
507 /* assume CPU is at P0... */
508 perf->state = 0;
509 return perf->states[0].core_frequency * 1000;
513 static void free_acpi_perf_data(void)
515 unsigned int i;
517 /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */
518 for_each_possible_cpu(i)
519 free_cpumask_var(per_cpu_ptr(acpi_perf_data, i)
520 ->shared_cpu_map);
521 free_percpu(acpi_perf_data);
525 * acpi_cpufreq_early_init - initialize ACPI P-States library
527 * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c)
528 * in order to determine correct frequency and voltage pairings. We can
529 * do _PDC and _PSD and find out the processor dependency for the
530 * actual init that will happen later...
532 static int __init acpi_cpufreq_early_init(void)
534 unsigned int i;
535 dprintk("acpi_cpufreq_early_init\n");
537 acpi_perf_data = alloc_percpu(struct acpi_processor_performance);
538 if (!acpi_perf_data) {
539 dprintk("Memory allocation error for acpi_perf_data.\n");
540 return -ENOMEM;
542 for_each_possible_cpu(i) {
543 if (!alloc_cpumask_var_node(
544 &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map,
545 GFP_KERNEL, cpu_to_node(i))) {
547 /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */
548 free_acpi_perf_data();
549 return -ENOMEM;
553 /* Do initialization in ACPI core */
554 acpi_processor_preregister_performance(acpi_perf_data);
555 return 0;
558 #ifdef CONFIG_SMP
560 * Some BIOSes do SW_ANY coordination internally, either set it up in hw
561 * or do it in BIOS firmware and won't inform about it to OS. If not
562 * detected, this has a side effect of making CPU run at a different speed
563 * than OS intended it to run at. Detect it and handle it cleanly.
565 static int bios_with_sw_any_bug;
567 static int sw_any_bug_found(const struct dmi_system_id *d)
569 bios_with_sw_any_bug = 1;
570 return 0;
573 static const struct dmi_system_id sw_any_bug_dmi_table[] = {
575 .callback = sw_any_bug_found,
576 .ident = "Supermicro Server X6DLP",
577 .matches = {
578 DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
579 DMI_MATCH(DMI_BIOS_VERSION, "080010"),
580 DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
585 #endif
587 static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
589 unsigned int i;
590 unsigned int valid_states = 0;
591 unsigned int cpu = policy->cpu;
592 struct acpi_cpufreq_data *data;
593 unsigned int result = 0;
594 struct cpuinfo_x86 *c = &cpu_data(policy->cpu);
595 struct acpi_processor_performance *perf;
597 dprintk("acpi_cpufreq_cpu_init\n");
599 data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL);
600 if (!data)
601 return -ENOMEM;
603 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
604 per_cpu(drv_data, cpu) = data;
606 if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
607 acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
609 result = acpi_processor_register_performance(data->acpi_data, cpu);
610 if (result)
611 goto err_free;
613 perf = data->acpi_data;
614 policy->shared_type = perf->shared_type;
617 * Will let policy->cpus know about dependency only when software
618 * coordination is required.
620 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
621 policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
622 cpumask_copy(policy->cpus, perf->shared_cpu_map);
624 cpumask_copy(policy->related_cpus, perf->shared_cpu_map);
626 #ifdef CONFIG_SMP
627 dmi_check_system(sw_any_bug_dmi_table);
628 if (bios_with_sw_any_bug && cpumask_weight(policy->cpus) == 1) {
629 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
630 cpumask_copy(policy->cpus, cpu_core_mask(cpu));
632 #endif
634 /* capability check */
635 if (perf->state_count <= 1) {
636 dprintk("No P-States\n");
637 result = -ENODEV;
638 goto err_unreg;
641 if (perf->control_register.space_id != perf->status_register.space_id) {
642 result = -ENODEV;
643 goto err_unreg;
646 switch (perf->control_register.space_id) {
647 case ACPI_ADR_SPACE_SYSTEM_IO:
648 dprintk("SYSTEM IO addr space\n");
649 data->cpu_feature = SYSTEM_IO_CAPABLE;
650 break;
651 case ACPI_ADR_SPACE_FIXED_HARDWARE:
652 dprintk("HARDWARE addr space\n");
653 if (!check_est_cpu(cpu)) {
654 result = -ENODEV;
655 goto err_unreg;
657 data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE;
658 break;
659 default:
660 dprintk("Unknown addr space %d\n",
661 (u32) (perf->control_register.space_id));
662 result = -ENODEV;
663 goto err_unreg;
666 data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) *
667 (perf->state_count+1), GFP_KERNEL);
668 if (!data->freq_table) {
669 result = -ENOMEM;
670 goto err_unreg;
673 /* detect transition latency */
674 policy->cpuinfo.transition_latency = 0;
675 for (i = 0; i < perf->state_count; i++) {
676 if ((perf->states[i].transition_latency * 1000) >
677 policy->cpuinfo.transition_latency)
678 policy->cpuinfo.transition_latency =
679 perf->states[i].transition_latency * 1000;
682 /* Check for high latency (>20uS) from buggy BIOSes, like on T42 */
683 if (perf->control_register.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE &&
684 policy->cpuinfo.transition_latency > 20 * 1000) {
685 static int print_once;
686 policy->cpuinfo.transition_latency = 20 * 1000;
687 if (!print_once) {
688 print_once = 1;
689 printk(KERN_INFO "Capping off P-state tranision latency"
690 " at 20 uS\n");
694 data->max_freq = perf->states[0].core_frequency * 1000;
695 /* table init */
696 for (i = 0; i < perf->state_count; i++) {
697 if (i > 0 && perf->states[i].core_frequency >=
698 data->freq_table[valid_states-1].frequency / 1000)
699 continue;
701 data->freq_table[valid_states].index = i;
702 data->freq_table[valid_states].frequency =
703 perf->states[i].core_frequency * 1000;
704 valid_states++;
706 data->freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
707 perf->state = 0;
709 result = cpufreq_frequency_table_cpuinfo(policy, data->freq_table);
710 if (result)
711 goto err_freqfree;
713 switch (perf->control_register.space_id) {
714 case ACPI_ADR_SPACE_SYSTEM_IO:
715 /* Current speed is unknown and not detectable by IO port */
716 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
717 break;
718 case ACPI_ADR_SPACE_FIXED_HARDWARE:
719 acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
720 policy->cur = get_cur_freq_on_cpu(cpu);
721 break;
722 default:
723 break;
726 /* notify BIOS that we exist */
727 acpi_processor_notify_smm(THIS_MODULE);
729 /* Check for APERF/MPERF support in hardware */
730 if (c->x86_vendor == X86_VENDOR_INTEL && c->cpuid_level >= 6) {
731 unsigned int ecx;
732 ecx = cpuid_ecx(6);
733 if (ecx & CPUID_6_ECX_APERFMPERF_CAPABILITY)
734 acpi_cpufreq_driver.getavg = get_measured_perf;
737 dprintk("CPU%u - ACPI performance management activated.\n", cpu);
738 for (i = 0; i < perf->state_count; i++)
739 dprintk(" %cP%d: %d MHz, %d mW, %d uS\n",
740 (i == perf->state ? '*' : ' '), i,
741 (u32) perf->states[i].core_frequency,
742 (u32) perf->states[i].power,
743 (u32) perf->states[i].transition_latency);
745 cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu);
748 * the first call to ->target() should result in us actually
749 * writing something to the appropriate registers.
751 data->resume = 1;
753 return result;
755 err_freqfree:
756 kfree(data->freq_table);
757 err_unreg:
758 acpi_processor_unregister_performance(perf, cpu);
759 err_free:
760 kfree(data);
761 per_cpu(drv_data, cpu) = NULL;
763 return result;
766 static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
768 struct acpi_cpufreq_data *data = per_cpu(drv_data, policy->cpu);
770 dprintk("acpi_cpufreq_cpu_exit\n");
772 if (data) {
773 cpufreq_frequency_table_put_attr(policy->cpu);
774 per_cpu(drv_data, policy->cpu) = NULL;
775 acpi_processor_unregister_performance(data->acpi_data,
776 policy->cpu);
777 kfree(data);
780 return 0;
783 static int acpi_cpufreq_resume(struct cpufreq_policy *policy)
785 struct acpi_cpufreq_data *data = per_cpu(drv_data, policy->cpu);
787 dprintk("acpi_cpufreq_resume\n");
789 data->resume = 1;
791 return 0;
794 static struct freq_attr *acpi_cpufreq_attr[] = {
795 &cpufreq_freq_attr_scaling_available_freqs,
796 NULL,
799 static struct cpufreq_driver acpi_cpufreq_driver = {
800 .verify = acpi_cpufreq_verify,
801 .target = acpi_cpufreq_target,
802 .init = acpi_cpufreq_cpu_init,
803 .exit = acpi_cpufreq_cpu_exit,
804 .resume = acpi_cpufreq_resume,
805 .name = "acpi-cpufreq",
806 .owner = THIS_MODULE,
807 .attr = acpi_cpufreq_attr,
810 static int __init acpi_cpufreq_init(void)
812 int ret;
814 if (acpi_disabled)
815 return 0;
817 dprintk("acpi_cpufreq_init\n");
819 ret = acpi_cpufreq_early_init();
820 if (ret)
821 return ret;
823 ret = cpufreq_register_driver(&acpi_cpufreq_driver);
824 if (ret)
825 free_acpi_perf_data();
827 return ret;
830 static void __exit acpi_cpufreq_exit(void)
832 dprintk("acpi_cpufreq_exit\n");
834 cpufreq_unregister_driver(&acpi_cpufreq_driver);
836 free_percpu(acpi_perf_data);
839 module_param(acpi_pstate_strict, uint, 0644);
840 MODULE_PARM_DESC(acpi_pstate_strict,
841 "value 0 or non-zero. non-zero -> strict ACPI checks are "
842 "performed during frequency changes.");
844 late_initcall(acpi_cpufreq_init);
845 module_exit(acpi_cpufreq_exit);
847 MODULE_ALIAS("acpi");