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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/init.h>
33 #include <linux/smp.h>
34 #include <linux/sched.h>
35 #include <linux/cpufreq.h>
36 #include <linux/compiler.h>
37 #include <linux/dmi.h>
38 #include <linux/slab.h>
40 #include <linux/acpi.h>
42 #include <linux/delay.h>
43 #include <linux/uaccess.h>
45 #include <acpi/processor.h>
48 #include <asm/processor.h>
49 #include <asm/cpufeature.h>
50 #include <asm/cpu_device_id.h>
52 MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
53 MODULE_DESCRIPTION("ACPI Processor P-States Driver");
54 MODULE_LICENSE("GPL");
57 UNDEFINED_CAPABLE = 0,
58 SYSTEM_INTEL_MSR_CAPABLE,
59 SYSTEM_AMD_MSR_CAPABLE,
63 #define INTEL_MSR_RANGE (0xffff)
64 #define AMD_MSR_RANGE (0x7)
66 #define MSR_K7_HWCR_CPB_DIS (1ULL << 25)
68 struct acpi_cpufreq_data {
70 unsigned int cpu_feature;
71 unsigned int acpi_perf_cpu;
72 cpumask_var_t freqdomain_cpus;
73 void (*cpu_freq_write)(struct acpi_pct_register *reg, u32 val);
74 u32 (*cpu_freq_read)(struct acpi_pct_register *reg);
77 /* acpi_perf_data is a pointer to percpu data. */
78 static struct acpi_processor_performance __percpu *acpi_perf_data;
80 static inline struct acpi_processor_performance *to_perf_data(struct acpi_cpufreq_data *data)
82 return per_cpu_ptr(acpi_perf_data, data->acpi_perf_cpu);
85 static struct cpufreq_driver acpi_cpufreq_driver;
87 static unsigned int acpi_pstate_strict;
89 static bool boost_state(unsigned int cpu)
94 switch (boot_cpu_data.x86_vendor) {
95 case X86_VENDOR_INTEL:
96 rdmsr_on_cpu(cpu, MSR_IA32_MISC_ENABLE, &lo, &hi);
97 msr = lo | ((u64)hi << 32);
98 return !(msr & MSR_IA32_MISC_ENABLE_TURBO_DISABLE);
100 rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi);
101 msr = lo | ((u64)hi << 32);
102 return !(msr & MSR_K7_HWCR_CPB_DIS);
107 static int boost_set_msr(bool enable)
112 switch (boot_cpu_data.x86_vendor) {
113 case X86_VENDOR_INTEL:
114 msr_addr = MSR_IA32_MISC_ENABLE;
115 msr_mask = MSR_IA32_MISC_ENABLE_TURBO_DISABLE;
118 msr_addr = MSR_K7_HWCR;
119 msr_mask = MSR_K7_HWCR_CPB_DIS;
125 rdmsrl(msr_addr, val);
132 wrmsrl(msr_addr, val);
136 static void boost_set_msr_each(void *p_en)
138 bool enable = (bool) p_en;
140 boost_set_msr(enable);
143 static int set_boost(int val)
146 on_each_cpu(boost_set_msr_each, (void *)(long)val, 1);
148 pr_debug("Core Boosting %sabled.\n", val ? "en" : "dis");
153 static ssize_t show_freqdomain_cpus(struct cpufreq_policy *policy, char *buf)
155 struct acpi_cpufreq_data *data = policy->driver_data;
160 return cpufreq_show_cpus(data->freqdomain_cpus, buf);
163 cpufreq_freq_attr_ro(freqdomain_cpus);
165 #ifdef CONFIG_X86_ACPI_CPUFREQ_CPB
166 static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf,
170 unsigned int val = 0;
172 if (!acpi_cpufreq_driver.set_boost)
175 ret = kstrtouint(buf, 10, &val);
184 static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf)
186 return sprintf(buf, "%u\n", acpi_cpufreq_driver.boost_enabled);
189 cpufreq_freq_attr_rw(cpb);
192 static int check_est_cpu(unsigned int cpuid)
194 struct cpuinfo_x86 *cpu = &cpu_data(cpuid);
196 return cpu_has(cpu, X86_FEATURE_EST);
199 static int check_amd_hwpstate_cpu(unsigned int cpuid)
201 struct cpuinfo_x86 *cpu = &cpu_data(cpuid);
203 return cpu_has(cpu, X86_FEATURE_HW_PSTATE);
206 static unsigned extract_io(struct cpufreq_policy *policy, u32 value)
208 struct acpi_cpufreq_data *data = policy->driver_data;
209 struct acpi_processor_performance *perf;
212 perf = to_perf_data(data);
214 for (i = 0; i < perf->state_count; i++) {
215 if (value == perf->states[i].status)
216 return policy->freq_table[i].frequency;
221 static unsigned extract_msr(struct cpufreq_policy *policy, u32 msr)
223 struct acpi_cpufreq_data *data = policy->driver_data;
224 struct cpufreq_frequency_table *pos;
225 struct acpi_processor_performance *perf;
227 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD)
228 msr &= AMD_MSR_RANGE;
230 msr &= INTEL_MSR_RANGE;
232 perf = to_perf_data(data);
234 cpufreq_for_each_entry(pos, policy->freq_table)
235 if (msr == perf->states[pos->driver_data].status)
236 return pos->frequency;
237 return policy->freq_table[0].frequency;
240 static unsigned extract_freq(struct cpufreq_policy *policy, u32 val)
242 struct acpi_cpufreq_data *data = policy->driver_data;
244 switch (data->cpu_feature) {
245 case SYSTEM_INTEL_MSR_CAPABLE:
246 case SYSTEM_AMD_MSR_CAPABLE:
247 return extract_msr(policy, val);
248 case SYSTEM_IO_CAPABLE:
249 return extract_io(policy, val);
255 static u32 cpu_freq_read_intel(struct acpi_pct_register *not_used)
259 rdmsr(MSR_IA32_PERF_CTL, val, dummy);
263 static void cpu_freq_write_intel(struct acpi_pct_register *not_used, u32 val)
267 rdmsr(MSR_IA32_PERF_CTL, lo, hi);
268 lo = (lo & ~INTEL_MSR_RANGE) | (val & INTEL_MSR_RANGE);
269 wrmsr(MSR_IA32_PERF_CTL, lo, hi);
272 static u32 cpu_freq_read_amd(struct acpi_pct_register *not_used)
276 rdmsr(MSR_AMD_PERF_CTL, val, dummy);
280 static void cpu_freq_write_amd(struct acpi_pct_register *not_used, u32 val)
282 wrmsr(MSR_AMD_PERF_CTL, val, 0);
285 static u32 cpu_freq_read_io(struct acpi_pct_register *reg)
289 acpi_os_read_port(reg->address, &val, reg->bit_width);
293 static void cpu_freq_write_io(struct acpi_pct_register *reg, u32 val)
295 acpi_os_write_port(reg->address, val, reg->bit_width);
299 struct acpi_pct_register *reg;
302 void (*write)(struct acpi_pct_register *reg, u32 val);
303 u32 (*read)(struct acpi_pct_register *reg);
307 /* Called via smp_call_function_single(), on the target CPU */
308 static void do_drv_read(void *_cmd)
310 struct drv_cmd *cmd = _cmd;
312 cmd->val = cmd->func.read(cmd->reg);
315 static u32 drv_read(struct acpi_cpufreq_data *data, const struct cpumask *mask)
317 struct acpi_processor_performance *perf = to_perf_data(data);
318 struct drv_cmd cmd = {
319 .reg = &perf->control_register,
320 .func.read = data->cpu_freq_read,
324 err = smp_call_function_any(mask, do_drv_read, &cmd, 1);
325 WARN_ON_ONCE(err); /* smp_call_function_any() was buggy? */
329 /* Called via smp_call_function_many(), on the target CPUs */
330 static void do_drv_write(void *_cmd)
332 struct drv_cmd *cmd = _cmd;
334 cmd->func.write(cmd->reg, cmd->val);
337 static void drv_write(struct acpi_cpufreq_data *data,
338 const struct cpumask *mask, u32 val)
340 struct acpi_processor_performance *perf = to_perf_data(data);
341 struct drv_cmd cmd = {
342 .reg = &perf->control_register,
344 .func.write = data->cpu_freq_write,
348 this_cpu = get_cpu();
349 if (cpumask_test_cpu(this_cpu, mask))
352 smp_call_function_many(mask, do_drv_write, &cmd, 1);
356 static u32 get_cur_val(const struct cpumask *mask, struct acpi_cpufreq_data *data)
360 if (unlikely(cpumask_empty(mask)))
363 val = drv_read(data, mask);
365 pr_debug("get_cur_val = %u\n", val);
370 static unsigned int get_cur_freq_on_cpu(unsigned int cpu)
372 struct acpi_cpufreq_data *data;
373 struct cpufreq_policy *policy;
375 unsigned int cached_freq;
377 pr_debug("get_cur_freq_on_cpu (%d)\n", cpu);
379 policy = cpufreq_cpu_get_raw(cpu);
380 if (unlikely(!policy))
383 data = policy->driver_data;
384 if (unlikely(!data || !policy->freq_table))
387 cached_freq = policy->freq_table[to_perf_data(data)->state].frequency;
388 freq = extract_freq(policy, get_cur_val(cpumask_of(cpu), data));
389 if (freq != cached_freq) {
391 * The dreaded BIOS frequency change behind our back.
392 * Force set the frequency on next target call.
397 pr_debug("cur freq = %u\n", freq);
402 static unsigned int check_freqs(struct cpufreq_policy *policy,
403 const struct cpumask *mask, unsigned int freq)
405 struct acpi_cpufreq_data *data = policy->driver_data;
406 unsigned int cur_freq;
409 for (i = 0; i < 100; i++) {
410 cur_freq = extract_freq(policy, get_cur_val(mask, data));
411 if (cur_freq == freq)
418 static int acpi_cpufreq_target(struct cpufreq_policy *policy,
421 struct acpi_cpufreq_data *data = policy->driver_data;
422 struct acpi_processor_performance *perf;
423 const struct cpumask *mask;
424 unsigned int next_perf_state = 0; /* Index into perf table */
427 if (unlikely(!data)) {
431 perf = to_perf_data(data);
432 next_perf_state = policy->freq_table[index].driver_data;
433 if (perf->state == next_perf_state) {
434 if (unlikely(data->resume)) {
435 pr_debug("Called after resume, resetting to P%d\n",
439 pr_debug("Already at target state (P%d)\n",
446 * The core won't allow CPUs to go away until the governor has been
447 * stopped, so we can rely on the stability of policy->cpus.
449 mask = policy->shared_type == CPUFREQ_SHARED_TYPE_ANY ?
450 cpumask_of(policy->cpu) : policy->cpus;
452 drv_write(data, mask, perf->states[next_perf_state].control);
454 if (acpi_pstate_strict) {
455 if (!check_freqs(policy, mask,
456 policy->freq_table[index].frequency)) {
457 pr_debug("acpi_cpufreq_target failed (%d)\n",
464 perf->state = next_perf_state;
469 static unsigned int acpi_cpufreq_fast_switch(struct cpufreq_policy *policy,
470 unsigned int target_freq)
472 struct acpi_cpufreq_data *data = policy->driver_data;
473 struct acpi_processor_performance *perf;
474 struct cpufreq_frequency_table *entry;
475 unsigned int next_perf_state, next_freq, index;
478 * Find the closest frequency above target_freq.
480 if (policy->cached_target_freq == target_freq)
481 index = policy->cached_resolved_idx;
483 index = cpufreq_table_find_index_dl(policy, target_freq);
485 entry = &policy->freq_table[index];
486 next_freq = entry->frequency;
487 next_perf_state = entry->driver_data;
489 perf = to_perf_data(data);
490 if (perf->state == next_perf_state) {
491 if (unlikely(data->resume))
497 data->cpu_freq_write(&perf->control_register,
498 perf->states[next_perf_state].control);
499 perf->state = next_perf_state;
504 acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu)
506 struct acpi_processor_performance *perf;
508 perf = to_perf_data(data);
510 /* search the closest match to cpu_khz */
513 unsigned long freqn = perf->states[0].core_frequency * 1000;
515 for (i = 0; i < (perf->state_count-1); i++) {
517 freqn = perf->states[i+1].core_frequency * 1000;
518 if ((2 * cpu_khz) > (freqn + freq)) {
523 perf->state = perf->state_count-1;
526 /* assume CPU is at P0... */
528 return perf->states[0].core_frequency * 1000;
532 static void free_acpi_perf_data(void)
536 /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */
537 for_each_possible_cpu(i)
538 free_cpumask_var(per_cpu_ptr(acpi_perf_data, i)
540 free_percpu(acpi_perf_data);
543 static int cpufreq_boost_online(unsigned int cpu)
546 * On the CPU_UP path we simply keep the boost-disable flag
547 * in sync with the current global state.
549 return boost_set_msr(acpi_cpufreq_driver.boost_enabled);
552 static int cpufreq_boost_down_prep(unsigned int cpu)
555 * Clear the boost-disable bit on the CPU_DOWN path so that
556 * this cpu cannot block the remaining ones from boosting.
558 return boost_set_msr(1);
562 * acpi_cpufreq_early_init - initialize ACPI P-States library
564 * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c)
565 * in order to determine correct frequency and voltage pairings. We can
566 * do _PDC and _PSD and find out the processor dependency for the
567 * actual init that will happen later...
569 static int __init acpi_cpufreq_early_init(void)
572 pr_debug("acpi_cpufreq_early_init\n");
574 acpi_perf_data = alloc_percpu(struct acpi_processor_performance);
575 if (!acpi_perf_data) {
576 pr_debug("Memory allocation error for acpi_perf_data.\n");
579 for_each_possible_cpu(i) {
580 if (!zalloc_cpumask_var_node(
581 &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map,
582 GFP_KERNEL, cpu_to_node(i))) {
584 /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */
585 free_acpi_perf_data();
590 /* Do initialization in ACPI core */
591 acpi_processor_preregister_performance(acpi_perf_data);
597 * Some BIOSes do SW_ANY coordination internally, either set it up in hw
598 * or do it in BIOS firmware and won't inform about it to OS. If not
599 * detected, this has a side effect of making CPU run at a different speed
600 * than OS intended it to run at. Detect it and handle it cleanly.
602 static int bios_with_sw_any_bug;
604 static int sw_any_bug_found(const struct dmi_system_id *d)
606 bios_with_sw_any_bug = 1;
610 static const struct dmi_system_id sw_any_bug_dmi_table[] = {
612 .callback = sw_any_bug_found,
613 .ident = "Supermicro Server X6DLP",
615 DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
616 DMI_MATCH(DMI_BIOS_VERSION, "080010"),
617 DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
623 static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c)
625 /* Intel Xeon Processor 7100 Series Specification Update
626 * http://www.intel.com/Assets/PDF/specupdate/314554.pdf
627 * AL30: A Machine Check Exception (MCE) Occurring during an
628 * Enhanced Intel SpeedStep Technology Ratio Change May Cause
629 * Both Processor Cores to Lock Up. */
630 if (c->x86_vendor == X86_VENDOR_INTEL) {
631 if ((c->x86 == 15) &&
632 (c->x86_model == 6) &&
633 (c->x86_stepping == 8)) {
634 pr_info("Intel(R) Xeon(R) 7100 Errata AL30, processors may lock up on frequency changes: disabling acpi-cpufreq\n");
642 static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
645 unsigned int valid_states = 0;
646 unsigned int cpu = policy->cpu;
647 struct acpi_cpufreq_data *data;
648 unsigned int result = 0;
649 struct cpuinfo_x86 *c = &cpu_data(policy->cpu);
650 struct acpi_processor_performance *perf;
651 struct cpufreq_frequency_table *freq_table;
653 static int blacklisted;
656 pr_debug("acpi_cpufreq_cpu_init\n");
661 blacklisted = acpi_cpufreq_blacklist(c);
666 data = kzalloc(sizeof(*data), GFP_KERNEL);
670 if (!zalloc_cpumask_var(&data->freqdomain_cpus, GFP_KERNEL)) {
675 perf = per_cpu_ptr(acpi_perf_data, cpu);
676 data->acpi_perf_cpu = cpu;
677 policy->driver_data = data;
679 if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
680 acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
682 result = acpi_processor_register_performance(perf, cpu);
686 policy->shared_type = perf->shared_type;
689 * Will let policy->cpus know about dependency only when software
690 * coordination is required.
692 if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL ||
693 policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) {
694 cpumask_copy(policy->cpus, perf->shared_cpu_map);
696 cpumask_copy(data->freqdomain_cpus, perf->shared_cpu_map);
699 dmi_check_system(sw_any_bug_dmi_table);
700 if (bios_with_sw_any_bug && !policy_is_shared(policy)) {
701 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
702 cpumask_copy(policy->cpus, topology_core_cpumask(cpu));
705 if (check_amd_hwpstate_cpu(cpu) && boot_cpu_data.x86 < 0x19 &&
706 !acpi_pstate_strict) {
707 cpumask_clear(policy->cpus);
708 cpumask_set_cpu(cpu, policy->cpus);
709 cpumask_copy(data->freqdomain_cpus,
710 topology_sibling_cpumask(cpu));
711 policy->shared_type = CPUFREQ_SHARED_TYPE_HW;
712 pr_info_once("overriding BIOS provided _PSD data\n");
716 /* capability check */
717 if (perf->state_count <= 1) {
718 pr_debug("No P-States\n");
723 if (perf->control_register.space_id != perf->status_register.space_id) {
728 switch (perf->control_register.space_id) {
729 case ACPI_ADR_SPACE_SYSTEM_IO:
730 if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD &&
731 boot_cpu_data.x86 == 0xf) {
732 pr_debug("AMD K8 systems must use native drivers.\n");
736 pr_debug("SYSTEM IO addr space\n");
737 data->cpu_feature = SYSTEM_IO_CAPABLE;
738 data->cpu_freq_read = cpu_freq_read_io;
739 data->cpu_freq_write = cpu_freq_write_io;
741 case ACPI_ADR_SPACE_FIXED_HARDWARE:
742 pr_debug("HARDWARE addr space\n");
743 if (check_est_cpu(cpu)) {
744 data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE;
745 data->cpu_freq_read = cpu_freq_read_intel;
746 data->cpu_freq_write = cpu_freq_write_intel;
749 if (check_amd_hwpstate_cpu(cpu)) {
750 data->cpu_feature = SYSTEM_AMD_MSR_CAPABLE;
751 data->cpu_freq_read = cpu_freq_read_amd;
752 data->cpu_freq_write = cpu_freq_write_amd;
758 pr_debug("Unknown addr space %d\n",
759 (u32) (perf->control_register.space_id));
764 freq_table = kcalloc(perf->state_count + 1, sizeof(*freq_table),
771 /* detect transition latency */
772 policy->cpuinfo.transition_latency = 0;
773 for (i = 0; i < perf->state_count; i++) {
774 if ((perf->states[i].transition_latency * 1000) >
775 policy->cpuinfo.transition_latency)
776 policy->cpuinfo.transition_latency =
777 perf->states[i].transition_latency * 1000;
780 /* Check for high latency (>20uS) from buggy BIOSes, like on T42 */
781 if (perf->control_register.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE &&
782 policy->cpuinfo.transition_latency > 20 * 1000) {
783 policy->cpuinfo.transition_latency = 20 * 1000;
784 pr_info_once("P-state transition latency capped at 20 uS\n");
788 for (i = 0; i < perf->state_count; i++) {
789 if (i > 0 && perf->states[i].core_frequency >=
790 freq_table[valid_states-1].frequency / 1000)
793 freq_table[valid_states].driver_data = i;
794 freq_table[valid_states].frequency =
795 perf->states[i].core_frequency * 1000;
798 freq_table[valid_states].frequency = CPUFREQ_TABLE_END;
799 policy->freq_table = freq_table;
802 switch (perf->control_register.space_id) {
803 case ACPI_ADR_SPACE_SYSTEM_IO:
805 * The core will not set policy->cur, because
806 * cpufreq_driver->get is NULL, so we need to set it here.
807 * However, we have to guess it, because the current speed is
808 * unknown and not detectable via IO ports.
810 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
812 case ACPI_ADR_SPACE_FIXED_HARDWARE:
813 acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
819 /* notify BIOS that we exist */
820 acpi_processor_notify_smm(THIS_MODULE);
822 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
823 for (i = 0; i < perf->state_count; i++)
824 pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n",
825 (i == perf->state ? '*' : ' '), i,
826 (u32) perf->states[i].core_frequency,
827 (u32) perf->states[i].power,
828 (u32) perf->states[i].transition_latency);
831 * the first call to ->target() should result in us actually
832 * writing something to the appropriate registers.
836 policy->fast_switch_possible = !acpi_pstate_strict &&
837 !(policy_is_shared(policy) && policy->shared_type != CPUFREQ_SHARED_TYPE_ANY);
842 acpi_processor_unregister_performance(cpu);
844 free_cpumask_var(data->freqdomain_cpus);
847 policy->driver_data = NULL;
852 static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
854 struct acpi_cpufreq_data *data = policy->driver_data;
856 pr_debug("acpi_cpufreq_cpu_exit\n");
858 policy->fast_switch_possible = false;
859 policy->driver_data = NULL;
860 acpi_processor_unregister_performance(data->acpi_perf_cpu);
861 free_cpumask_var(data->freqdomain_cpus);
862 kfree(policy->freq_table);
868 static void acpi_cpufreq_cpu_ready(struct cpufreq_policy *policy)
870 struct acpi_processor_performance *perf = per_cpu_ptr(acpi_perf_data,
873 if (perf->states[0].core_frequency * 1000 != policy->cpuinfo.max_freq)
874 pr_warn(FW_WARN "P-state 0 is not max freq\n");
877 static int acpi_cpufreq_resume(struct cpufreq_policy *policy)
879 struct acpi_cpufreq_data *data = policy->driver_data;
881 pr_debug("acpi_cpufreq_resume\n");
888 static struct freq_attr *acpi_cpufreq_attr[] = {
889 &cpufreq_freq_attr_scaling_available_freqs,
891 #ifdef CONFIG_X86_ACPI_CPUFREQ_CPB
897 static struct cpufreq_driver acpi_cpufreq_driver = {
898 .verify = cpufreq_generic_frequency_table_verify,
899 .target_index = acpi_cpufreq_target,
900 .fast_switch = acpi_cpufreq_fast_switch,
901 .bios_limit = acpi_processor_get_bios_limit,
902 .init = acpi_cpufreq_cpu_init,
903 .exit = acpi_cpufreq_cpu_exit,
904 .ready = acpi_cpufreq_cpu_ready,
905 .resume = acpi_cpufreq_resume,
906 .name = "acpi-cpufreq",
907 .attr = acpi_cpufreq_attr,
910 static enum cpuhp_state acpi_cpufreq_online;
912 static void __init acpi_cpufreq_boost_init(void)
916 if (!(boot_cpu_has(X86_FEATURE_CPB) || boot_cpu_has(X86_FEATURE_IDA))) {
917 pr_debug("Boost capabilities not present in the processor\n");
921 acpi_cpufreq_driver.set_boost = set_boost;
922 acpi_cpufreq_driver.boost_enabled = boost_state(0);
925 * This calls the online callback on all online cpu and forces all
926 * MSRs to the same value.
928 ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "cpufreq/acpi:online",
929 cpufreq_boost_online, cpufreq_boost_down_prep);
931 pr_err("acpi_cpufreq: failed to register hotplug callbacks\n");
934 acpi_cpufreq_online = ret;
937 static void acpi_cpufreq_boost_exit(void)
939 if (acpi_cpufreq_online > 0)
940 cpuhp_remove_state_nocalls(acpi_cpufreq_online);
943 static int __init acpi_cpufreq_init(void)
950 /* don't keep reloading if cpufreq_driver exists */
951 if (cpufreq_get_current_driver())
954 pr_debug("acpi_cpufreq_init\n");
956 ret = acpi_cpufreq_early_init();
960 #ifdef CONFIG_X86_ACPI_CPUFREQ_CPB
961 /* this is a sysfs file with a strange name and an even stranger
962 * semantic - per CPU instantiation, but system global effect.
963 * Lets enable it only on AMD CPUs for compatibility reasons and
964 * only if configured. This is considered legacy code, which
965 * will probably be removed at some point in the future.
967 if (!check_amd_hwpstate_cpu(0)) {
968 struct freq_attr **attr;
970 pr_debug("CPB unsupported, do not expose it\n");
972 for (attr = acpi_cpufreq_attr; *attr; attr++)
979 acpi_cpufreq_boost_init();
981 ret = cpufreq_register_driver(&acpi_cpufreq_driver);
983 free_acpi_perf_data();
984 acpi_cpufreq_boost_exit();
989 static void __exit acpi_cpufreq_exit(void)
991 pr_debug("acpi_cpufreq_exit\n");
993 acpi_cpufreq_boost_exit();
995 cpufreq_unregister_driver(&acpi_cpufreq_driver);
997 free_acpi_perf_data();
1000 module_param(acpi_pstate_strict, uint, 0644);
1001 MODULE_PARM_DESC(acpi_pstate_strict,
1002 "value 0 or non-zero. non-zero -> strict ACPI checks are "
1003 "performed during frequency changes.");
1005 late_initcall(acpi_cpufreq_init);
1006 module_exit(acpi_cpufreq_exit);
1008 static const struct x86_cpu_id acpi_cpufreq_ids[] = {
1009 X86_FEATURE_MATCH(X86_FEATURE_ACPI),
1010 X86_FEATURE_MATCH(X86_FEATURE_HW_PSTATE),
1013 MODULE_DEVICE_TABLE(x86cpu, acpi_cpufreq_ids);
1015 static const struct acpi_device_id processor_device_ids[] = {
1016 {ACPI_PROCESSOR_OBJECT_HID, },
1017 {ACPI_PROCESSOR_DEVICE_HID, },
1020 MODULE_DEVICE_TABLE(acpi, processor_device_ids);
1022 MODULE_ALIAS("acpi");