Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge back cpufreq material for 6.11.

+987 -384
+17 -1
Documentation/admin-guide/pm/amd-pstate.rst
··· 281 281 firmware, if EPP feature is disabled, driver will ignore the written value 282 282 This attribute is read-write. 283 283 284 + ``boost`` 285 + The `boost` sysfs attribute provides control over the CPU core 286 + performance boost, allowing users to manage the maximum frequency limitation 287 + of the CPU. This attribute can be used to enable or disable the boost feature 288 + on individual CPUs. 289 + 290 + When the boost feature is enabled, the CPU can dynamically increase its frequency 291 + beyond the base frequency, providing enhanced performance for demanding workloads. 292 + On the other hand, disabling the boost feature restricts the CPU to operate at the 293 + base frequency, which may be desirable in certain scenarios to prioritize power 294 + efficiency or manage temperature. 295 + 296 + To manipulate the `boost` attribute, users can write a value of `0` to disable the 297 + boost or `1` to enable it, for the respective CPU using the sysfs path 298 + `/sys/devices/system/cpu/cpuX/cpufreq/boost`, where `X` represents the CPU number. 299 + 284 300 Other performance and frequency values can be read back from 285 301 ``/sys/devices/system/cpu/cpuX/acpi_cppc/``, see :ref:`cppc_sysfs`. 286 302 ··· 422 406 ``/sys/devices/system/cpu/amd_pstate/`` directory and affect all CPUs. 423 407 424 408 ``status`` 425 - Operation mode of the driver: "active", "passive" or "disable". 409 + Operation mode of the driver: "active", "passive", "guided" or "disable". 426 410 427 411 "active" 428 412 The driver is functional and in the ``active mode``
+4
Documentation/admin-guide/pm/cpufreq.rst
··· 267 267 ``related_cpus`` 268 268 List of all (online and offline) CPUs belonging to this policy. 269 269 270 + ``scaling_available_frequencies`` 271 + List of available frequencies of the CPUs belonging to this policy 272 + (in kHz). 273 + 270 274 ``scaling_available_governors`` 271 275 List of ``CPUFreq`` scaling governors present in the kernel that can 272 276 be attached to this policy or (if the |intel_pstate| scaling driver is
+1
MAINTAINERS
··· 12968 12968 F: Documentation/translations/zh_CN/arch/loongarch/ 12969 12969 F: arch/loongarch/ 12970 12970 F: drivers/*/*loongarch* 12971 + F: drivers/cpufreq/loongson3_cpufreq.c 12971 12972 12972 12973 LOONGSON GPIO DRIVER 12973 12974 M: Yinbo Zhu <zhuyinbo@loongson.cn>
+2
arch/x86/include/asm/cpufeatures.h
··· 361 361 #define X86_FEATURE_HWP_ACT_WINDOW (14*32+ 9) /* HWP Activity Window */ 362 362 #define X86_FEATURE_HWP_EPP (14*32+10) /* HWP Energy Perf. Preference */ 363 363 #define X86_FEATURE_HWP_PKG_REQ (14*32+11) /* HWP Package Level Request */ 364 + #define X86_FEATURE_HWP_HIGHEST_PERF_CHANGE (14*32+15) /* "" HWP Highest perf change */ 364 365 #define X86_FEATURE_HFI (14*32+19) /* Hardware Feedback Interface */ 365 366 366 367 /* AMD SVM Feature Identification, CPUID level 0x8000000a (EDX), word 15 */ ··· 471 470 #define X86_FEATURE_BHI_CTRL (21*32+ 2) /* "" BHI_DIS_S HW control available */ 472 471 #define X86_FEATURE_CLEAR_BHB_HW (21*32+ 3) /* "" BHI_DIS_S HW control enabled */ 473 472 #define X86_FEATURE_CLEAR_BHB_LOOP_ON_VMEXIT (21*32+ 4) /* "" Clear branch history at vmexit using SW loop */ 473 + #define X86_FEATURE_FAST_CPPC (21*32 + 5) /* "" AMD Fast CPPC */ 474 474 475 475 /* 476 476 * BUG word(s)
+2
arch/x86/include/asm/msr-index.h
··· 781 781 #define MSR_K7_HWCR_IRPERF_EN BIT_ULL(MSR_K7_HWCR_IRPERF_EN_BIT) 782 782 #define MSR_K7_FID_VID_CTL 0xc0010041 783 783 #define MSR_K7_FID_VID_STATUS 0xc0010042 784 + #define MSR_K7_HWCR_CPB_DIS_BIT 25 785 + #define MSR_K7_HWCR_CPB_DIS BIT_ULL(MSR_K7_HWCR_CPB_DIS_BIT) 784 786 785 787 /* K6 MSRs */ 786 788 #define MSR_K6_WHCR 0xc0000082
+1
arch/x86/kernel/cpu/scattered.c
··· 45 45 { X86_FEATURE_HW_PSTATE, CPUID_EDX, 7, 0x80000007, 0 }, 46 46 { X86_FEATURE_CPB, CPUID_EDX, 9, 0x80000007, 0 }, 47 47 { X86_FEATURE_PROC_FEEDBACK, CPUID_EDX, 11, 0x80000007, 0 }, 48 + { X86_FEATURE_FAST_CPPC, CPUID_EDX, 15, 0x80000007, 0 }, 48 49 { X86_FEATURE_MBA, CPUID_EBX, 6, 0x80000008, 0 }, 49 50 { X86_FEATURE_SMBA, CPUID_EBX, 2, 0x80000020, 0 }, 50 51 { X86_FEATURE_BMEC, CPUID_EBX, 3, 0x80000020, 0 },
+12
drivers/cpufreq/Kconfig
··· 262 262 If in doubt, say N. 263 263 endif 264 264 265 + if LOONGARCH 266 + config LOONGSON3_CPUFREQ 267 + tristate "Loongson3 CPUFreq Driver" 268 + help 269 + This option adds a CPUFreq driver for Loongson processors which 270 + support software configurable cpu frequency. 271 + 272 + Loongson-3 family processors support this feature. 273 + 274 + If in doubt, say N. 275 + endif 276 + 265 277 if SPARC64 266 278 config SPARC_US3_CPUFREQ 267 279 tristate "UltraSPARC-III CPU Frequency driver"
+1
drivers/cpufreq/Kconfig.x86
··· 71 71 config X86_AMD_PSTATE_UT 72 72 tristate "selftest for AMD Processor P-State driver" 73 73 depends on X86 && ACPI_PROCESSOR 74 + depends on X86_AMD_PSTATE 74 75 default n 75 76 help 76 77 This kernel module is used for testing. It's safe to say M here.
+1
drivers/cpufreq/Makefile
··· 103 103 # Other platform drivers 104 104 obj-$(CONFIG_BMIPS_CPUFREQ) += bmips-cpufreq.o 105 105 obj-$(CONFIG_LOONGSON2_CPUFREQ) += loongson2_cpufreq.o 106 + obj-$(CONFIG_LOONGSON3_CPUFREQ) += loongson3_cpufreq.o 106 107 obj-$(CONFIG_SH_CPU_FREQ) += sh-cpufreq.o 107 108 obj-$(CONFIG_SPARC_US2E_CPUFREQ) += sparc-us2e-cpufreq.o 108 109 obj-$(CONFIG_SPARC_US3_CPUFREQ) += sparc-us3-cpufreq.o
+1 -5
drivers/cpufreq/acpi-cpufreq.c
··· 50 50 #define AMD_MSR_RANGE (0x7) 51 51 #define HYGON_MSR_RANGE (0x7) 52 52 53 - #define MSR_K7_HWCR_CPB_DIS (1ULL << 25) 54 - 55 53 struct acpi_cpufreq_data { 56 54 unsigned int resume; 57 55 unsigned int cpu_feature; ··· 906 908 return result; 907 909 } 908 910 909 - static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy) 911 + static void acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy) 910 912 { 911 913 struct acpi_cpufreq_data *data = policy->driver_data; 912 914 ··· 919 921 free_cpumask_var(data->freqdomain_cpus); 920 922 kfree(policy->freq_table); 921 923 kfree(data); 922 - 923 - return 0; 924 924 } 925 925 926 926 static int acpi_cpufreq_resume(struct cpufreq_policy *policy)
+7 -5
drivers/cpufreq/amd-pstate-ut.c
··· 202 202 int cpu = 0; 203 203 struct cpufreq_policy *policy = NULL; 204 204 struct amd_cpudata *cpudata = NULL; 205 + u32 nominal_freq_khz; 205 206 206 207 for_each_possible_cpu(cpu) { 207 208 policy = cpufreq_cpu_get(cpu); ··· 210 209 break; 211 210 cpudata = policy->driver_data; 212 211 213 - if (!((cpudata->max_freq >= cpudata->nominal_freq) && 214 - (cpudata->nominal_freq > cpudata->lowest_nonlinear_freq) && 212 + nominal_freq_khz = cpudata->nominal_freq*1000; 213 + if (!((cpudata->max_freq >= nominal_freq_khz) && 214 + (nominal_freq_khz > cpudata->lowest_nonlinear_freq) && 215 215 (cpudata->lowest_nonlinear_freq > cpudata->min_freq) && 216 216 (cpudata->min_freq > 0))) { 217 217 amd_pstate_ut_cases[index].result = AMD_PSTATE_UT_RESULT_FAIL; 218 218 pr_err("%s cpu%d max=%d >= nominal=%d > lowest_nonlinear=%d > min=%d > 0, the formula is incorrect!\n", 219 - __func__, cpu, cpudata->max_freq, cpudata->nominal_freq, 219 + __func__, cpu, cpudata->max_freq, nominal_freq_khz, 220 220 cpudata->lowest_nonlinear_freq, cpudata->min_freq); 221 221 goto skip_test; 222 222 } ··· 231 229 232 230 if (cpudata->boost_supported) { 233 231 if ((policy->max == cpudata->max_freq) || 234 - (policy->max == cpudata->nominal_freq)) 232 + (policy->max == nominal_freq_khz)) 235 233 amd_pstate_ut_cases[index].result = AMD_PSTATE_UT_RESULT_PASS; 236 234 else { 237 235 amd_pstate_ut_cases[index].result = AMD_PSTATE_UT_RESULT_FAIL; 238 236 pr_err("%s cpu%d policy_max=%d should be equal cpu_max=%d or cpu_nominal=%d !\n", 239 237 __func__, cpu, policy->max, cpudata->max_freq, 240 - cpudata->nominal_freq); 238 + nominal_freq_khz); 241 239 goto skip_test; 242 240 } 243 241 } else {
+248 -113
drivers/cpufreq/amd-pstate.c
··· 51 51 52 52 #define AMD_PSTATE_TRANSITION_LATENCY 20000 53 53 #define AMD_PSTATE_TRANSITION_DELAY 1000 54 + #define AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY 600 54 55 #define CPPC_HIGHEST_PERF_PERFORMANCE 196 55 56 #define CPPC_HIGHEST_PERF_DEFAULT 166 56 57 ··· 86 85 u32 lowest_freq; 87 86 }; 88 87 89 - /* 90 - * TODO: We need more time to fine tune processors with shared memory solution 91 - * with community together. 92 - * 93 - * There are some performance drops on the CPU benchmarks which reports from 94 - * Suse. We are co-working with them to fine tune the shared memory solution. So 95 - * we disable it by default to go acpi-cpufreq on these processors and add a 96 - * module parameter to be able to enable it manually for debugging. 97 - */ 98 88 static struct cpufreq_driver *current_pstate_driver; 99 89 static struct cpufreq_driver amd_pstate_driver; 100 90 static struct cpufreq_driver amd_pstate_epp_driver; ··· 149 157 * broken BIOS lack of nominal_freq and lowest_freq capabilities 150 158 * definition in ACPI tables 151 159 */ 152 - if (boot_cpu_has(X86_FEATURE_ZEN2)) { 160 + if (cpu_feature_enabled(X86_FEATURE_ZEN2)) { 153 161 quirks = dmi->driver_data; 154 162 pr_info("Overriding nominal and lowest frequencies for %s\n", dmi->ident); 155 163 return 1; ··· 191 199 u64 epp; 192 200 int ret; 193 201 194 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 202 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 195 203 if (!cppc_req_cached) { 196 204 epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, 197 205 &cppc_req_cached); ··· 239 247 return index; 240 248 } 241 249 250 + static void pstate_update_perf(struct amd_cpudata *cpudata, u32 min_perf, 251 + u32 des_perf, u32 max_perf, bool fast_switch) 252 + { 253 + if (fast_switch) 254 + wrmsrl(MSR_AMD_CPPC_REQ, READ_ONCE(cpudata->cppc_req_cached)); 255 + else 256 + wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, 257 + READ_ONCE(cpudata->cppc_req_cached)); 258 + } 259 + 260 + DEFINE_STATIC_CALL(amd_pstate_update_perf, pstate_update_perf); 261 + 262 + static inline void amd_pstate_update_perf(struct amd_cpudata *cpudata, 263 + u32 min_perf, u32 des_perf, 264 + u32 max_perf, bool fast_switch) 265 + { 266 + static_call(amd_pstate_update_perf)(cpudata, min_perf, des_perf, 267 + max_perf, fast_switch); 268 + } 269 + 242 270 static int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp) 243 271 { 244 272 int ret; 245 273 struct cppc_perf_ctrls perf_ctrls; 246 274 247 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 275 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 248 276 u64 value = READ_ONCE(cpudata->cppc_req_cached); 249 277 250 278 value &= ~GENMASK_ULL(31, 24); ··· 275 263 if (!ret) 276 264 cpudata->epp_cached = epp; 277 265 } else { 266 + amd_pstate_update_perf(cpudata, cpudata->min_limit_perf, 0U, 267 + cpudata->max_limit_perf, false); 268 + 278 269 perf_ctrls.energy_perf = epp; 279 270 ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1); 280 271 if (ret) { ··· 296 281 int epp = -EINVAL; 297 282 int ret; 298 283 299 - if (!pref_index) { 300 - pr_debug("EPP pref_index is invalid\n"); 301 - return -EINVAL; 302 - } 284 + if (!pref_index) 285 + epp = cpudata->epp_default; 303 286 304 287 if (epp == -EINVAL) 305 288 epp = epp_values[pref_index]; ··· 465 452 return static_call(amd_pstate_init_perf)(cpudata); 466 453 } 467 454 468 - static void pstate_update_perf(struct amd_cpudata *cpudata, u32 min_perf, 469 - u32 des_perf, u32 max_perf, bool fast_switch) 470 - { 471 - if (fast_switch) 472 - wrmsrl(MSR_AMD_CPPC_REQ, READ_ONCE(cpudata->cppc_req_cached)); 473 - else 474 - wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, 475 - READ_ONCE(cpudata->cppc_req_cached)); 476 - } 477 - 478 455 static void cppc_update_perf(struct amd_cpudata *cpudata, 479 456 u32 min_perf, u32 des_perf, 480 457 u32 max_perf, bool fast_switch) ··· 476 473 perf_ctrls.desired_perf = des_perf; 477 474 478 475 cppc_set_perf(cpudata->cpu, &perf_ctrls); 479 - } 480 - 481 - DEFINE_STATIC_CALL(amd_pstate_update_perf, pstate_update_perf); 482 - 483 - static inline void amd_pstate_update_perf(struct amd_cpudata *cpudata, 484 - u32 min_perf, u32 des_perf, 485 - u32 max_perf, bool fast_switch) 486 - { 487 - static_call(amd_pstate_update_perf)(cpudata, min_perf, des_perf, 488 - max_perf, fast_switch); 489 476 } 490 477 491 478 static inline bool amd_pstate_sample(struct amd_cpudata *cpudata) ··· 514 521 static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf, 515 522 u32 des_perf, u32 max_perf, bool fast_switch, int gov_flags) 516 523 { 524 + unsigned long max_freq; 525 + struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu); 517 526 u64 prev = READ_ONCE(cpudata->cppc_req_cached); 527 + u32 nominal_perf = READ_ONCE(cpudata->nominal_perf); 518 528 u64 value = prev; 519 529 520 530 min_perf = clamp_t(unsigned long, min_perf, cpudata->min_limit_perf, ··· 525 529 max_perf = clamp_t(unsigned long, max_perf, cpudata->min_limit_perf, 526 530 cpudata->max_limit_perf); 527 531 des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf); 532 + 533 + max_freq = READ_ONCE(cpudata->max_limit_freq); 534 + policy->cur = div_u64(des_perf * max_freq, max_perf); 528 535 529 536 if ((cppc_state == AMD_PSTATE_GUIDED) && (gov_flags & CPUFREQ_GOV_DYNAMIC_SWITCHING)) { 530 537 min_perf = des_perf; ··· 539 540 540 541 value &= ~AMD_CPPC_DES_PERF(~0L); 541 542 value |= AMD_CPPC_DES_PERF(des_perf); 543 + 544 + /* limit the max perf when core performance boost feature is disabled */ 545 + if (!cpudata->boost_supported) 546 + max_perf = min_t(unsigned long, nominal_perf, max_perf); 542 547 543 548 value &= ~AMD_CPPC_MAX_PERF(~0L); 544 549 value |= AMD_CPPC_MAX_PERF(max_perf); ··· 654 651 unsigned long capacity) 655 652 { 656 653 unsigned long max_perf, min_perf, des_perf, 657 - cap_perf, lowest_nonlinear_perf, max_freq; 654 + cap_perf, lowest_nonlinear_perf; 658 655 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); 659 656 struct amd_cpudata *cpudata = policy->driver_data; 660 - unsigned int target_freq; 661 657 662 658 if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq) 663 659 amd_pstate_update_min_max_limit(policy); ··· 664 662 665 663 cap_perf = READ_ONCE(cpudata->highest_perf); 666 664 lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); 667 - max_freq = READ_ONCE(cpudata->max_freq); 668 665 669 666 des_perf = cap_perf; 670 667 if (target_perf < capacity) ··· 681 680 max_perf = min_perf; 682 681 683 682 des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf); 684 - target_freq = div_u64(des_perf * max_freq, max_perf); 685 - policy->cur = target_freq; 686 683 687 684 amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true, 688 685 policy->governor->flags); 689 686 cpufreq_cpu_put(policy); 687 + } 688 + 689 + static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on) 690 + { 691 + struct amd_cpudata *cpudata = policy->driver_data; 692 + struct cppc_perf_ctrls perf_ctrls; 693 + u32 highest_perf, nominal_perf, nominal_freq, max_freq; 694 + int ret; 695 + 696 + highest_perf = READ_ONCE(cpudata->highest_perf); 697 + nominal_perf = READ_ONCE(cpudata->nominal_perf); 698 + nominal_freq = READ_ONCE(cpudata->nominal_freq); 699 + max_freq = READ_ONCE(cpudata->max_freq); 700 + 701 + if (boot_cpu_has(X86_FEATURE_CPPC)) { 702 + u64 value = READ_ONCE(cpudata->cppc_req_cached); 703 + 704 + value &= ~GENMASK_ULL(7, 0); 705 + value |= on ? highest_perf : nominal_perf; 706 + WRITE_ONCE(cpudata->cppc_req_cached, value); 707 + 708 + wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); 709 + } else { 710 + perf_ctrls.max_perf = on ? highest_perf : nominal_perf; 711 + ret = cppc_set_perf(cpudata->cpu, &perf_ctrls); 712 + if (ret) { 713 + cpufreq_cpu_release(policy); 714 + pr_debug("Failed to set max perf on CPU:%d. ret:%d\n", 715 + cpudata->cpu, ret); 716 + return ret; 717 + } 718 + } 719 + 720 + if (on) 721 + policy->cpuinfo.max_freq = max_freq; 722 + else if (policy->cpuinfo.max_freq > nominal_freq * 1000) 723 + policy->cpuinfo.max_freq = nominal_freq * 1000; 724 + 725 + policy->max = policy->cpuinfo.max_freq; 726 + 727 + if (cppc_state == AMD_PSTATE_PASSIVE) { 728 + ret = freq_qos_update_request(&cpudata->req[1], policy->cpuinfo.max_freq); 729 + if (ret < 0) 730 + pr_debug("Failed to update freq constraint: CPU%d\n", cpudata->cpu); 731 + } 732 + 733 + return ret < 0 ? ret : 0; 690 734 } 691 735 692 736 static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state) ··· 741 695 742 696 if (!cpudata->boost_supported) { 743 697 pr_err("Boost mode is not supported by this processor or SBIOS\n"); 744 - return -EINVAL; 698 + return -EOPNOTSUPP; 745 699 } 700 + mutex_lock(&amd_pstate_driver_lock); 701 + ret = amd_pstate_cpu_boost_update(policy, state); 702 + WRITE_ONCE(cpudata->boost_state, !ret ? state : false); 703 + policy->boost_enabled = !ret ? state : false; 704 + refresh_frequency_limits(policy); 705 + mutex_unlock(&amd_pstate_driver_lock); 746 706 747 - if (state) 748 - policy->cpuinfo.max_freq = cpudata->max_freq; 749 - else 750 - policy->cpuinfo.max_freq = cpudata->nominal_freq * 1000; 751 - 752 - policy->max = policy->cpuinfo.max_freq; 753 - 754 - ret = freq_qos_update_request(&cpudata->req[1], 755 - policy->cpuinfo.max_freq); 756 - if (ret < 0) 757 - return ret; 758 - 759 - return 0; 707 + return ret; 760 708 } 761 709 762 - static void amd_pstate_boost_init(struct amd_cpudata *cpudata) 710 + static int amd_pstate_init_boost_support(struct amd_cpudata *cpudata) 763 711 { 764 - u32 highest_perf, nominal_perf; 712 + u64 boost_val; 713 + int ret = -1; 765 714 766 - highest_perf = READ_ONCE(cpudata->highest_perf); 767 - nominal_perf = READ_ONCE(cpudata->nominal_perf); 715 + /* 716 + * If platform has no CPB support or disable it, initialize current driver 717 + * boost_enabled state to be false, it is not an error for cpufreq core to handle. 718 + */ 719 + if (!cpu_feature_enabled(X86_FEATURE_CPB)) { 720 + pr_debug_once("Boost CPB capabilities not present in the processor\n"); 721 + ret = 0; 722 + goto exit_err; 723 + } 768 724 769 - if (highest_perf <= nominal_perf) 770 - return; 771 - 772 - cpudata->boost_supported = true; 725 + /* at least one CPU supports CPB, even if others fail later on to set up */ 773 726 current_pstate_driver->boost_enabled = true; 727 + 728 + ret = rdmsrl_on_cpu(cpudata->cpu, MSR_K7_HWCR, &boost_val); 729 + if (ret) { 730 + pr_err_once("failed to read initial CPU boost state!\n"); 731 + ret = -EIO; 732 + goto exit_err; 733 + } 734 + 735 + if (!(boost_val & MSR_K7_HWCR_CPB_DIS)) 736 + cpudata->boost_supported = true; 737 + 738 + return 0; 739 + 740 + exit_err: 741 + cpudata->boost_supported = false; 742 + return ret; 774 743 } 775 744 776 745 static void amd_perf_ctl_reset(unsigned int cpu) ··· 814 753 { 815 754 int ret; 816 755 817 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 756 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 818 757 u64 cap1; 819 758 820 759 ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &cap1); ··· 910 849 u32 transition_delay_ns; 911 850 912 851 transition_delay_ns = cppc_get_transition_latency(cpu); 913 - if (transition_delay_ns == CPUFREQ_ETERNAL) 914 - return AMD_PSTATE_TRANSITION_DELAY; 852 + if (transition_delay_ns == CPUFREQ_ETERNAL) { 853 + if (cpu_feature_enabled(X86_FEATURE_FAST_CPPC)) 854 + return AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY; 855 + else 856 + return AMD_PSTATE_TRANSITION_DELAY; 857 + } 915 858 916 859 return transition_delay_ns / NSEC_PER_USEC; 917 860 } ··· 986 921 WRITE_ONCE(cpudata->nominal_freq, nominal_freq); 987 922 WRITE_ONCE(cpudata->max_freq, max_freq); 988 923 924 + /** 925 + * Below values need to be initialized correctly, otherwise driver will fail to load 926 + * max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf 927 + * lowest_nonlinear_freq is a value between [min_freq, nominal_freq] 928 + * Check _CPC in ACPI table objects if any values are incorrect 929 + */ 930 + if (min_freq <= 0 || max_freq <= 0 || nominal_freq <= 0 || min_freq > max_freq) { 931 + pr_err("min_freq(%d) or max_freq(%d) or nominal_freq(%d) value is incorrect\n", 932 + min_freq, max_freq, nominal_freq * 1000); 933 + return -EINVAL; 934 + } 935 + 936 + if (lowest_nonlinear_freq <= min_freq || lowest_nonlinear_freq > nominal_freq * 1000) { 937 + pr_err("lowest_nonlinear_freq(%d) value is out of range [min_freq(%d), nominal_freq(%d)]\n", 938 + lowest_nonlinear_freq, min_freq, nominal_freq * 1000); 939 + return -EINVAL; 940 + } 941 + 989 942 return 0; 990 943 } 991 944 992 945 static int amd_pstate_cpu_init(struct cpufreq_policy *policy) 993 946 { 994 - int min_freq, max_freq, nominal_freq, ret; 947 + int min_freq, max_freq, ret; 995 948 struct device *dev; 996 949 struct amd_cpudata *cpudata; 997 950 ··· 1038 955 if (ret) 1039 956 goto free_cpudata1; 1040 957 958 + ret = amd_pstate_init_boost_support(cpudata); 959 + if (ret) 960 + goto free_cpudata1; 961 + 1041 962 min_freq = READ_ONCE(cpudata->min_freq); 1042 963 max_freq = READ_ONCE(cpudata->max_freq); 1043 - nominal_freq = READ_ONCE(cpudata->nominal_freq); 1044 - 1045 - if (min_freq <= 0 || max_freq <= 0 || 1046 - nominal_freq <= 0 || min_freq > max_freq) { 1047 - dev_err(dev, 1048 - "min_freq(%d) or max_freq(%d) or nominal_freq (%d) value is incorrect, check _CPC in ACPI tables\n", 1049 - min_freq, max_freq, nominal_freq); 1050 - ret = -EINVAL; 1051 - goto free_cpudata1; 1052 - } 1053 964 1054 965 policy->cpuinfo.transition_latency = amd_pstate_get_transition_latency(policy->cpu); 1055 966 policy->transition_delay_us = amd_pstate_get_transition_delay_us(policy->cpu); ··· 1054 977 policy->cpuinfo.min_freq = min_freq; 1055 978 policy->cpuinfo.max_freq = max_freq; 1056 979 980 + policy->boost_enabled = READ_ONCE(cpudata->boost_supported); 981 + 1057 982 /* It will be updated by governor */ 1058 983 policy->cur = policy->cpuinfo.min_freq; 1059 984 1060 - if (boot_cpu_has(X86_FEATURE_CPPC)) 985 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) 1061 986 policy->fast_switch_possible = true; 1062 987 1063 988 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0], ··· 1081 1002 1082 1003 policy->driver_data = cpudata; 1083 1004 1084 - amd_pstate_boost_init(cpudata); 1085 1005 if (!current_pstate_driver->adjust_perf) 1086 1006 current_pstate_driver->adjust_perf = amd_pstate_adjust_perf; 1087 1007 ··· 1093 1015 return ret; 1094 1016 } 1095 1017 1096 - static int amd_pstate_cpu_exit(struct cpufreq_policy *policy) 1018 + static void amd_pstate_cpu_exit(struct cpufreq_policy *policy) 1097 1019 { 1098 1020 struct amd_cpudata *cpudata = policy->driver_data; 1099 1021 ··· 1101 1023 freq_qos_remove_request(&cpudata->req[0]); 1102 1024 policy->fast_switch_possible = false; 1103 1025 kfree(cpudata); 1104 - 1105 - return 0; 1106 1026 } 1107 1027 1108 1028 static int amd_pstate_cpu_resume(struct cpufreq_policy *policy) ··· 1289 1213 1290 1214 cppc_state = mode; 1291 1215 1292 - if (boot_cpu_has(X86_FEATURE_CPPC) || cppc_state == AMD_PSTATE_ACTIVE) 1216 + if (cpu_feature_enabled(X86_FEATURE_CPPC) || cppc_state == AMD_PSTATE_ACTIVE) 1293 1217 return 0; 1294 1218 1295 1219 for_each_present_cpu(cpu) { ··· 1462 1386 1463 1387 static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy) 1464 1388 { 1465 - int min_freq, max_freq, nominal_freq, ret; 1389 + int min_freq, max_freq, ret; 1466 1390 struct amd_cpudata *cpudata; 1467 1391 struct device *dev; 1468 1392 u64 value; ··· 1493 1417 if (ret) 1494 1418 goto free_cpudata1; 1495 1419 1420 + ret = amd_pstate_init_boost_support(cpudata); 1421 + if (ret) 1422 + goto free_cpudata1; 1423 + 1496 1424 min_freq = READ_ONCE(cpudata->min_freq); 1497 1425 max_freq = READ_ONCE(cpudata->max_freq); 1498 - nominal_freq = READ_ONCE(cpudata->nominal_freq); 1499 - if (min_freq <= 0 || max_freq <= 0 || 1500 - nominal_freq <= 0 || min_freq > max_freq) { 1501 - dev_err(dev, 1502 - "min_freq(%d) or max_freq(%d) or nominal_freq(%d) value is incorrect, check _CPC in ACPI tables\n", 1503 - min_freq, max_freq, nominal_freq); 1504 - ret = -EINVAL; 1505 - goto free_cpudata1; 1506 - } 1507 1426 1508 1427 policy->cpuinfo.min_freq = min_freq; 1509 1428 policy->cpuinfo.max_freq = max_freq; ··· 1507 1436 1508 1437 policy->driver_data = cpudata; 1509 1438 1510 - cpudata->epp_cached = amd_pstate_get_epp(cpudata, 0); 1439 + cpudata->epp_cached = cpudata->epp_default = amd_pstate_get_epp(cpudata, 0); 1511 1440 1512 1441 policy->min = policy->cpuinfo.min_freq; 1513 1442 policy->max = policy->cpuinfo.max_freq; 1443 + 1444 + policy->boost_enabled = READ_ONCE(cpudata->boost_supported); 1514 1445 1515 1446 /* 1516 1447 * Set the policy to provide a valid fallback value in case ··· 1524 1451 else 1525 1452 policy->policy = CPUFREQ_POLICY_POWERSAVE; 1526 1453 1527 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 1454 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 1528 1455 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value); 1529 1456 if (ret) 1530 1457 return ret; ··· 1535 1462 return ret; 1536 1463 WRITE_ONCE(cpudata->cppc_cap1_cached, value); 1537 1464 } 1538 - amd_pstate_boost_init(cpudata); 1539 1465 1540 1466 return 0; 1541 1467 ··· 1543 1471 return ret; 1544 1472 } 1545 1473 1546 - static int amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy) 1474 + static void amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy) 1547 1475 { 1548 1476 struct amd_cpudata *cpudata = policy->driver_data; 1549 1477 ··· 1553 1481 } 1554 1482 1555 1483 pr_debug("CPU %d exiting\n", policy->cpu); 1556 - return 0; 1557 1484 } 1558 1485 1559 1486 static void amd_pstate_epp_update_limit(struct cpufreq_policy *policy) ··· 1612 1541 epp = 0; 1613 1542 1614 1543 /* Set initial EPP value */ 1615 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 1544 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 1616 1545 value &= ~GENMASK_ULL(31, 24); 1617 1546 value |= (u64)epp << 24; 1618 1547 } ··· 1635 1564 1636 1565 amd_pstate_epp_update_limit(policy); 1637 1566 1567 + /* 1568 + * policy->cur is never updated with the amd_pstate_epp driver, but it 1569 + * is used as a stale frequency value. So, keep it within limits. 1570 + */ 1571 + policy->cur = policy->min; 1572 + 1638 1573 return 0; 1639 1574 } 1640 1575 ··· 1657 1580 value = READ_ONCE(cpudata->cppc_req_cached); 1658 1581 max_perf = READ_ONCE(cpudata->highest_perf); 1659 1582 1660 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 1583 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 1661 1584 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); 1662 1585 } else { 1663 1586 perf_ctrls.max_perf = max_perf; ··· 1691 1614 value = READ_ONCE(cpudata->cppc_req_cached); 1692 1615 1693 1616 mutex_lock(&amd_pstate_limits_lock); 1694 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 1617 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 1695 1618 cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN; 1696 1619 1697 1620 /* Set max perf same as min perf */ ··· 1795 1718 .suspend = amd_pstate_epp_suspend, 1796 1719 .resume = amd_pstate_epp_resume, 1797 1720 .update_limits = amd_pstate_update_limits, 1721 + .set_boost = amd_pstate_set_boost, 1798 1722 .name = "amd-pstate-epp", 1799 1723 .attr = amd_pstate_epp_attr, 1800 1724 }; ··· 1819 1741 return -EINVAL; 1820 1742 } 1821 1743 1744 + /** 1745 + * CPPC function is not supported for family ID 17H with model_ID ranging from 0x10 to 0x2F. 1746 + * show the debug message that helps to check if the CPU has CPPC support for loading issue. 1747 + */ 1748 + static bool amd_cppc_supported(void) 1749 + { 1750 + struct cpuinfo_x86 *c = &cpu_data(0); 1751 + bool warn = false; 1752 + 1753 + if ((boot_cpu_data.x86 == 0x17) && (boot_cpu_data.x86_model < 0x30)) { 1754 + pr_debug_once("CPPC feature is not supported by the processor\n"); 1755 + return false; 1756 + } 1757 + 1758 + /* 1759 + * If the CPPC feature is disabled in the BIOS for processors that support MSR-based CPPC, 1760 + * the AMD Pstate driver may not function correctly. 1761 + * Check the CPPC flag and display a warning message if the platform supports CPPC. 1762 + * Note: below checking code will not abort the driver registeration process because of 1763 + * the code is added for debugging purposes. 1764 + */ 1765 + if (!cpu_feature_enabled(X86_FEATURE_CPPC)) { 1766 + if (cpu_feature_enabled(X86_FEATURE_ZEN1) || cpu_feature_enabled(X86_FEATURE_ZEN2)) { 1767 + if (c->x86_model > 0x60 && c->x86_model < 0xaf) 1768 + warn = true; 1769 + } else if (cpu_feature_enabled(X86_FEATURE_ZEN3) || cpu_feature_enabled(X86_FEATURE_ZEN4)) { 1770 + if ((c->x86_model > 0x10 && c->x86_model < 0x1F) || 1771 + (c->x86_model > 0x40 && c->x86_model < 0xaf)) 1772 + warn = true; 1773 + } else if (cpu_feature_enabled(X86_FEATURE_ZEN5)) { 1774 + warn = true; 1775 + } 1776 + } 1777 + 1778 + if (warn) 1779 + pr_warn_once("The CPPC feature is supported but currently disabled by the BIOS.\n" 1780 + "Please enable it if your BIOS has the CPPC option.\n"); 1781 + return true; 1782 + } 1783 + 1822 1784 static int __init amd_pstate_init(void) 1823 1785 { 1824 1786 struct device *dev_root; ··· 1867 1749 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) 1868 1750 return -ENODEV; 1869 1751 1752 + /* show debug message only if CPPC is not supported */ 1753 + if (!amd_cppc_supported()) 1754 + return -EOPNOTSUPP; 1755 + 1756 + /* show warning message when BIOS broken or ACPI disabled */ 1870 1757 if (!acpi_cpc_valid()) { 1871 1758 pr_warn_once("the _CPC object is not present in SBIOS or ACPI disabled\n"); 1872 1759 return -ENODEV; ··· 1886 1763 /* check if this machine need CPPC quirks */ 1887 1764 dmi_check_system(amd_pstate_quirks_table); 1888 1765 1889 - switch (cppc_state) { 1890 - case AMD_PSTATE_UNDEFINED: 1766 + /* 1767 + * determine the driver mode from the command line or kernel config. 1768 + * If no command line input is provided, cppc_state will be AMD_PSTATE_UNDEFINED. 1769 + * command line options will override the kernel config settings. 1770 + */ 1771 + 1772 + if (cppc_state == AMD_PSTATE_UNDEFINED) { 1891 1773 /* Disable on the following configs by default: 1892 1774 * 1. Undefined platforms 1893 1775 * 2. Server platforms 1894 - * 3. Shared memory designs 1895 1776 */ 1896 1777 if (amd_pstate_acpi_pm_profile_undefined() || 1897 - amd_pstate_acpi_pm_profile_server() || 1898 - !boot_cpu_has(X86_FEATURE_CPPC)) { 1778 + amd_pstate_acpi_pm_profile_server()) { 1899 1779 pr_info("driver load is disabled, boot with specific mode to enable this\n"); 1900 1780 return -ENODEV; 1901 1781 } 1902 - ret = amd_pstate_set_driver(CONFIG_X86_AMD_PSTATE_DEFAULT_MODE); 1903 - if (ret) 1904 - return ret; 1905 - break; 1782 + /* get driver mode from kernel config option [1:4] */ 1783 + cppc_state = CONFIG_X86_AMD_PSTATE_DEFAULT_MODE; 1784 + } 1785 + 1786 + switch (cppc_state) { 1906 1787 case AMD_PSTATE_DISABLE: 1788 + pr_info("driver load is disabled, boot with specific mode to enable this\n"); 1907 1789 return -ENODEV; 1908 1790 case AMD_PSTATE_PASSIVE: 1909 1791 case AMD_PSTATE_ACTIVE: 1910 1792 case AMD_PSTATE_GUIDED: 1793 + ret = amd_pstate_set_driver(cppc_state); 1794 + if (ret) 1795 + return ret; 1911 1796 break; 1912 1797 default: 1913 1798 return -EINVAL; 1914 1799 } 1915 1800 1916 1801 /* capability check */ 1917 - if (boot_cpu_has(X86_FEATURE_CPPC)) { 1802 + if (cpu_feature_enabled(X86_FEATURE_CPPC)) { 1918 1803 pr_debug("AMD CPPC MSR based functionality is supported\n"); 1919 1804 if (cppc_state != AMD_PSTATE_ACTIVE) 1920 1805 current_pstate_driver->adjust_perf = amd_pstate_adjust_perf; ··· 1936 1805 /* enable amd pstate feature */ 1937 1806 ret = amd_pstate_enable(true); 1938 1807 if (ret) { 1939 - pr_err("failed to enable with return %d\n", ret); 1808 + pr_err("failed to enable driver mode(%d)\n", cppc_state); 1940 1809 return ret; 1941 1810 } 1942 1811 1943 1812 ret = cpufreq_register_driver(current_pstate_driver); 1944 - if (ret) 1813 + if (ret) { 1945 1814 pr_err("failed to register with return %d\n", ret); 1815 + goto disable_driver; 1816 + } 1946 1817 1947 1818 dev_root = bus_get_dev_root(&cpu_subsys); 1948 1819 if (dev_root) { ··· 1960 1827 1961 1828 global_attr_free: 1962 1829 cpufreq_unregister_driver(current_pstate_driver); 1830 + disable_driver: 1831 + amd_pstate_enable(false); 1963 1832 return ret; 1964 1833 } 1965 1834 device_initcall(amd_pstate_init);
+2
drivers/cpufreq/amd-pstate.h
··· 99 99 u32 policy; 100 100 u64 cppc_cap1_cached; 101 101 bool suspended; 102 + s16 epp_default; 103 + bool boost_state; 102 104 }; 103 105 104 106 #endif /* _LINUX_AMD_PSTATE_H */
+1 -3
drivers/cpufreq/apple-soc-cpufreq.c
··· 305 305 return ret; 306 306 } 307 307 308 - static int apple_soc_cpufreq_exit(struct cpufreq_policy *policy) 308 + static void apple_soc_cpufreq_exit(struct cpufreq_policy *policy) 309 309 { 310 310 struct apple_cpu_priv *priv = policy->driver_data; 311 311 ··· 313 313 dev_pm_opp_remove_all_dynamic(priv->cpu_dev); 314 314 iounmap(priv->reg_base); 315 315 kfree(priv); 316 - 317 - return 0; 318 316 } 319 317 320 318 static struct cpufreq_driver apple_soc_cpufreq_driver = {
+1 -3
drivers/cpufreq/bmips-cpufreq.c
··· 121 121 return 0; 122 122 } 123 123 124 - static int bmips_cpufreq_exit(struct cpufreq_policy *policy) 124 + static void bmips_cpufreq_exit(struct cpufreq_policy *policy) 125 125 { 126 126 kfree(policy->freq_table); 127 - 128 - return 0; 129 127 } 130 128 131 129 static int bmips_cpufreq_init(struct cpufreq_policy *policy)
+3 -9
drivers/cpufreq/cppc_cpufreq.c
··· 291 291 struct cppc_cpudata *cpu_data = policy->driver_data; 292 292 unsigned int cpu = policy->cpu; 293 293 struct cpufreq_freqs freqs; 294 - u32 desired_perf; 295 294 int ret = 0; 296 295 297 - desired_perf = cppc_khz_to_perf(&cpu_data->perf_caps, target_freq); 298 - /* Return if it is exactly the same perf */ 299 - if (desired_perf == cpu_data->perf_ctrls.desired_perf) 300 - return ret; 301 - 302 - cpu_data->perf_ctrls.desired_perf = desired_perf; 296 + cpu_data->perf_ctrls.desired_perf = 297 + cppc_khz_to_perf(&cpu_data->perf_caps, target_freq); 303 298 freqs.old = policy->cur; 304 299 freqs.new = target_freq; 305 300 ··· 683 688 return ret; 684 689 } 685 690 686 - static int cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy) 691 + static void cppc_cpufreq_cpu_exit(struct cpufreq_policy *policy) 687 692 { 688 693 struct cppc_cpudata *cpu_data = policy->driver_data; 689 694 struct cppc_perf_caps *caps = &cpu_data->perf_caps; ··· 700 705 caps->lowest_perf, cpu, ret); 701 706 702 707 cppc_cpufreq_put_cpu_data(policy); 703 - return 0; 704 708 } 705 709 706 710 static inline u64 get_delta(u64 t1, u64 t0)
+1
drivers/cpufreq/cpufreq-dt-platdev.c
··· 233 233 sizeof(struct cpufreq_dt_platform_data))); 234 234 } 235 235 core_initcall(cpufreq_dt_platdev_init); 236 + MODULE_DESCRIPTION("Generic DT based cpufreq platdev driver"); 236 237 MODULE_LICENSE("GPL");
+1 -2
drivers/cpufreq/cpufreq-dt.c
··· 157 157 return 0; 158 158 } 159 159 160 - static int cpufreq_exit(struct cpufreq_policy *policy) 160 + static void cpufreq_exit(struct cpufreq_policy *policy) 161 161 { 162 162 clk_put(policy->clk); 163 - return 0; 164 163 } 165 164 166 165 static struct cpufreq_driver dt_cpufreq_driver = {
-6
drivers/cpufreq/cpufreq-nforce2.c
··· 359 359 return 0; 360 360 } 361 361 362 - static int nforce2_cpu_exit(struct cpufreq_policy *policy) 363 - { 364 - return 0; 365 - } 366 - 367 362 static struct cpufreq_driver nforce2_driver = { 368 363 .name = "nforce2", 369 364 .flags = CPUFREQ_NO_AUTO_DYNAMIC_SWITCHING, ··· 366 371 .target = nforce2_target, 367 372 .get = nforce2_get, 368 373 .init = nforce2_cpu_init, 369 - .exit = nforce2_cpu_exit, 370 374 }; 371 375 372 376 #ifdef MODULE
+24 -26
drivers/cpufreq/cpufreq.c
··· 608 608 static ssize_t show_boost(struct kobject *kobj, 609 609 struct kobj_attribute *attr, char *buf) 610 610 { 611 - return sprintf(buf, "%d\n", cpufreq_driver->boost_enabled); 611 + return sysfs_emit(buf, "%d\n", cpufreq_driver->boost_enabled); 612 612 } 613 613 614 614 static ssize_t store_boost(struct kobject *kobj, struct kobj_attribute *attr, 615 615 const char *buf, size_t count) 616 616 { 617 - int ret, enable; 617 + bool enable; 618 618 619 - ret = sscanf(buf, "%d", &enable); 620 - if (ret != 1 || enable < 0 || enable > 1) 619 + if (kstrtobool(buf, &enable)) 621 620 return -EINVAL; 622 621 623 622 if (cpufreq_boost_trigger_state(enable)) { ··· 640 641 static ssize_t store_local_boost(struct cpufreq_policy *policy, 641 642 const char *buf, size_t count) 642 643 { 643 - int ret, enable; 644 + int ret; 645 + bool enable; 644 646 645 - ret = kstrtoint(buf, 10, &enable); 646 - if (ret || enable < 0 || enable > 1) 647 + if (kstrtobool(buf, &enable)) 647 648 return -EINVAL; 648 649 649 650 if (!cpufreq_driver->boost_enabled) ··· 738 739 static ssize_t show_##file_name \ 739 740 (struct cpufreq_policy *policy, char *buf) \ 740 741 { \ 741 - return sprintf(buf, "%u\n", policy->object); \ 742 + return sysfs_emit(buf, "%u\n", policy->object); \ 742 743 } 743 744 744 745 show_one(cpuinfo_min_freq, cpuinfo.min_freq); ··· 759 760 760 761 freq = arch_freq_get_on_cpu(policy->cpu); 761 762 if (freq) 762 - ret = sprintf(buf, "%u\n", freq); 763 + ret = sysfs_emit(buf, "%u\n", freq); 763 764 else if (cpufreq_driver->setpolicy && cpufreq_driver->get) 764 - ret = sprintf(buf, "%u\n", cpufreq_driver->get(policy->cpu)); 765 + ret = sysfs_emit(buf, "%u\n", cpufreq_driver->get(policy->cpu)); 765 766 else 766 - ret = sprintf(buf, "%u\n", policy->cur); 767 + ret = sysfs_emit(buf, "%u\n", policy->cur); 767 768 return ret; 768 769 } 769 770 ··· 797 798 unsigned int cur_freq = __cpufreq_get(policy); 798 799 799 800 if (cur_freq) 800 - return sprintf(buf, "%u\n", cur_freq); 801 + return sysfs_emit(buf, "%u\n", cur_freq); 801 802 802 - return sprintf(buf, "<unknown>\n"); 803 + return sysfs_emit(buf, "<unknown>\n"); 803 804 } 804 805 805 806 /* ··· 808 809 static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf) 809 810 { 810 811 if (policy->policy == CPUFREQ_POLICY_POWERSAVE) 811 - return sprintf(buf, "powersave\n"); 812 + return sysfs_emit(buf, "powersave\n"); 812 813 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) 813 - return sprintf(buf, "performance\n"); 814 + return sysfs_emit(buf, "performance\n"); 814 815 else if (policy->governor) 815 - return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", 816 - policy->governor->name); 816 + return sysfs_emit(buf, "%s\n", policy->governor->name); 817 817 return -EINVAL; 818 818 } 819 819 ··· 871 873 struct cpufreq_governor *t; 872 874 873 875 if (!has_target()) { 874 - i += sprintf(buf, "performance powersave"); 876 + i += sysfs_emit(buf, "performance powersave"); 875 877 goto out; 876 878 } 877 879 ··· 880 882 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) 881 883 - (CPUFREQ_NAME_LEN + 2))) 882 884 break; 883 - i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name); 885 + i += sysfs_emit_at(buf, i, "%s ", t->name); 884 886 } 885 887 mutex_unlock(&cpufreq_governor_mutex); 886 888 out: 887 - i += sprintf(&buf[i], "\n"); 889 + i += sysfs_emit_at(buf, i, "\n"); 888 890 return i; 889 891 } 890 892 ··· 894 896 unsigned int cpu; 895 897 896 898 for_each_cpu(cpu, mask) { 897 - i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u ", cpu); 899 + i += sysfs_emit_at(buf, i, "%u ", cpu); 898 900 if (i >= (PAGE_SIZE - 5)) 899 901 break; 900 902 } ··· 902 904 /* Remove the extra space at the end */ 903 905 i--; 904 906 905 - i += sprintf(&buf[i], "\n"); 907 + i += sysfs_emit_at(buf, i, "\n"); 906 908 return i; 907 909 } 908 910 EXPORT_SYMBOL_GPL(cpufreq_show_cpus); ··· 945 947 static ssize_t show_scaling_setspeed(struct cpufreq_policy *policy, char *buf) 946 948 { 947 949 if (!policy->governor || !policy->governor->show_setspeed) 948 - return sprintf(buf, "<unsupported>\n"); 950 + return sysfs_emit(buf, "<unsupported>\n"); 949 951 950 952 return policy->governor->show_setspeed(policy, buf); 951 953 } ··· 959 961 int ret; 960 962 ret = cpufreq_driver->bios_limit(policy->cpu, &limit); 961 963 if (!ret) 962 - return sprintf(buf, "%u\n", limit); 963 - return sprintf(buf, "%u\n", policy->cpuinfo.max_freq); 964 + return sysfs_emit(buf, "%u\n", limit); 965 + return sysfs_emit(buf, "%u\n", policy->cpuinfo.max_freq); 964 966 } 965 967 966 968 cpufreq_freq_attr_ro_perm(cpuinfo_cur_freq, 0400); ··· 2874 2876 } 2875 2877 EXPORT_SYMBOL_GPL(cpufreq_enable_boost_support); 2876 2878 2877 - int cpufreq_boost_enabled(void) 2879 + bool cpufreq_boost_enabled(void) 2878 2880 { 2879 2881 return cpufreq_driver->boost_enabled; 2880 2882 }
+1 -2
drivers/cpufreq/e_powersaver.c
··· 360 360 return 0; 361 361 } 362 362 363 - static int eps_cpu_exit(struct cpufreq_policy *policy) 363 + static void eps_cpu_exit(struct cpufreq_policy *policy) 364 364 { 365 365 unsigned int cpu = policy->cpu; 366 366 367 367 /* Bye */ 368 368 kfree(eps_cpu[cpu]); 369 369 eps_cpu[cpu] = NULL; 370 - return 0; 371 370 } 372 371 373 372 static struct cpufreq_driver eps_driver = {
+74 -57
drivers/cpufreq/intel_pstate.c
··· 300 300 301 301 #define HYBRID_SCALING_FACTOR 78741 302 302 #define HYBRID_SCALING_FACTOR_MTL 80000 303 + #define HYBRID_SCALING_FACTOR_LNL 86957 303 304 304 305 static int hybrid_scaling_factor = HYBRID_SCALING_FACTOR; 305 306 ··· 1626 1625 static DEFINE_SPINLOCK(hwp_notify_lock); 1627 1626 static cpumask_t hwp_intr_enable_mask; 1628 1627 1628 + #define HWP_GUARANTEED_PERF_CHANGE_STATUS BIT(0) 1629 + #define HWP_HIGHEST_PERF_CHANGE_STATUS BIT(3) 1630 + 1629 1631 void notify_hwp_interrupt(void) 1630 1632 { 1631 1633 unsigned int this_cpu = smp_processor_id(); 1634 + u64 value, status_mask; 1632 1635 unsigned long flags; 1633 - u64 value; 1634 1636 1635 - if (!hwp_active || !boot_cpu_has(X86_FEATURE_HWP_NOTIFY)) 1637 + if (!hwp_active || !cpu_feature_enabled(X86_FEATURE_HWP_NOTIFY)) 1636 1638 return; 1637 1639 1640 + status_mask = HWP_GUARANTEED_PERF_CHANGE_STATUS; 1641 + if (cpu_feature_enabled(X86_FEATURE_HWP_HIGHEST_PERF_CHANGE)) 1642 + status_mask |= HWP_HIGHEST_PERF_CHANGE_STATUS; 1643 + 1638 1644 rdmsrl_safe(MSR_HWP_STATUS, &value); 1639 - if (!(value & 0x01)) 1645 + if (!(value & status_mask)) 1640 1646 return; 1641 1647 1642 1648 spin_lock_irqsave(&hwp_notify_lock, flags); ··· 1667 1659 { 1668 1660 bool cancel_work; 1669 1661 1670 - if (!boot_cpu_has(X86_FEATURE_HWP_NOTIFY)) 1662 + if (!cpu_feature_enabled(X86_FEATURE_HWP_NOTIFY)) 1671 1663 return; 1672 1664 1673 1665 /* wrmsrl_on_cpu has to be outside spinlock as this can result in IPC */ ··· 1681 1673 cancel_delayed_work_sync(&cpudata->hwp_notify_work); 1682 1674 } 1683 1675 1676 + #define HWP_GUARANTEED_PERF_CHANGE_REQ BIT(0) 1677 + #define HWP_HIGHEST_PERF_CHANGE_REQ BIT(2) 1678 + 1684 1679 static void intel_pstate_enable_hwp_interrupt(struct cpudata *cpudata) 1685 1680 { 1686 - /* Enable HWP notification interrupt for guaranteed performance change */ 1681 + /* Enable HWP notification interrupt for performance change */ 1687 1682 if (boot_cpu_has(X86_FEATURE_HWP_NOTIFY)) { 1683 + u64 interrupt_mask = HWP_GUARANTEED_PERF_CHANGE_REQ; 1684 + 1688 1685 spin_lock_irq(&hwp_notify_lock); 1689 1686 INIT_DELAYED_WORK(&cpudata->hwp_notify_work, intel_pstate_notify_work); 1690 1687 cpumask_set_cpu(cpudata->cpu, &hwp_intr_enable_mask); 1691 1688 spin_unlock_irq(&hwp_notify_lock); 1692 1689 1690 + if (cpu_feature_enabled(X86_FEATURE_HWP_HIGHEST_PERF_CHANGE)) 1691 + interrupt_mask |= HWP_HIGHEST_PERF_CHANGE_REQ; 1692 + 1693 1693 /* wrmsrl_on_cpu has to be outside spinlock as this can result in IPC */ 1694 - wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, 0x01); 1694 + wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_INTERRUPT, interrupt_mask); 1695 1695 wrmsrl_on_cpu(cpudata->cpu, MSR_HWP_STATUS, 0); 1696 1696 } 1697 1697 } ··· 2383 2367 .get_val = core_get_val, 2384 2368 }; 2385 2369 2386 - #define X86_MATCH(model, policy) \ 2387 - X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, INTEL_FAM6_##model, \ 2388 - X86_FEATURE_APERFMPERF, &policy) 2370 + #define X86_MATCH(vfm, policy) \ 2371 + X86_MATCH_VFM_FEATURE(vfm, X86_FEATURE_APERFMPERF, &policy) 2389 2372 2390 2373 static const struct x86_cpu_id intel_pstate_cpu_ids[] = { 2391 - X86_MATCH(SANDYBRIDGE, core_funcs), 2392 - X86_MATCH(SANDYBRIDGE_X, core_funcs), 2393 - X86_MATCH(ATOM_SILVERMONT, silvermont_funcs), 2394 - X86_MATCH(IVYBRIDGE, core_funcs), 2395 - X86_MATCH(HASWELL, core_funcs), 2396 - X86_MATCH(BROADWELL, core_funcs), 2397 - X86_MATCH(IVYBRIDGE_X, core_funcs), 2398 - X86_MATCH(HASWELL_X, core_funcs), 2399 - X86_MATCH(HASWELL_L, core_funcs), 2400 - X86_MATCH(HASWELL_G, core_funcs), 2401 - X86_MATCH(BROADWELL_G, core_funcs), 2402 - X86_MATCH(ATOM_AIRMONT, airmont_funcs), 2403 - X86_MATCH(SKYLAKE_L, core_funcs), 2404 - X86_MATCH(BROADWELL_X, core_funcs), 2405 - X86_MATCH(SKYLAKE, core_funcs), 2406 - X86_MATCH(BROADWELL_D, core_funcs), 2407 - X86_MATCH(XEON_PHI_KNL, knl_funcs), 2408 - X86_MATCH(XEON_PHI_KNM, knl_funcs), 2409 - X86_MATCH(ATOM_GOLDMONT, core_funcs), 2410 - X86_MATCH(ATOM_GOLDMONT_PLUS, core_funcs), 2411 - X86_MATCH(SKYLAKE_X, core_funcs), 2412 - X86_MATCH(COMETLAKE, core_funcs), 2413 - X86_MATCH(ICELAKE_X, core_funcs), 2414 - X86_MATCH(TIGERLAKE, core_funcs), 2415 - X86_MATCH(SAPPHIRERAPIDS_X, core_funcs), 2416 - X86_MATCH(EMERALDRAPIDS_X, core_funcs), 2374 + X86_MATCH(INTEL_SANDYBRIDGE, core_funcs), 2375 + X86_MATCH(INTEL_SANDYBRIDGE_X, core_funcs), 2376 + X86_MATCH(INTEL_ATOM_SILVERMONT, silvermont_funcs), 2377 + X86_MATCH(INTEL_IVYBRIDGE, core_funcs), 2378 + X86_MATCH(INTEL_HASWELL, core_funcs), 2379 + X86_MATCH(INTEL_BROADWELL, core_funcs), 2380 + X86_MATCH(INTEL_IVYBRIDGE_X, core_funcs), 2381 + X86_MATCH(INTEL_HASWELL_X, core_funcs), 2382 + X86_MATCH(INTEL_HASWELL_L, core_funcs), 2383 + X86_MATCH(INTEL_HASWELL_G, core_funcs), 2384 + X86_MATCH(INTEL_BROADWELL_G, core_funcs), 2385 + X86_MATCH(INTEL_ATOM_AIRMONT, airmont_funcs), 2386 + X86_MATCH(INTEL_SKYLAKE_L, core_funcs), 2387 + X86_MATCH(INTEL_BROADWELL_X, core_funcs), 2388 + X86_MATCH(INTEL_SKYLAKE, core_funcs), 2389 + X86_MATCH(INTEL_BROADWELL_D, core_funcs), 2390 + X86_MATCH(INTEL_XEON_PHI_KNL, knl_funcs), 2391 + X86_MATCH(INTEL_XEON_PHI_KNM, knl_funcs), 2392 + X86_MATCH(INTEL_ATOM_GOLDMONT, core_funcs), 2393 + X86_MATCH(INTEL_ATOM_GOLDMONT_PLUS, core_funcs), 2394 + X86_MATCH(INTEL_SKYLAKE_X, core_funcs), 2395 + X86_MATCH(INTEL_COMETLAKE, core_funcs), 2396 + X86_MATCH(INTEL_ICELAKE_X, core_funcs), 2397 + X86_MATCH(INTEL_TIGERLAKE, core_funcs), 2398 + X86_MATCH(INTEL_SAPPHIRERAPIDS_X, core_funcs), 2399 + X86_MATCH(INTEL_EMERALDRAPIDS_X, core_funcs), 2417 2400 {} 2418 2401 }; 2419 2402 MODULE_DEVICE_TABLE(x86cpu, intel_pstate_cpu_ids); 2420 2403 2421 2404 #ifdef CONFIG_ACPI 2422 2405 static const struct x86_cpu_id intel_pstate_cpu_oob_ids[] __initconst = { 2423 - X86_MATCH(BROADWELL_D, core_funcs), 2424 - X86_MATCH(BROADWELL_X, core_funcs), 2425 - X86_MATCH(SKYLAKE_X, core_funcs), 2426 - X86_MATCH(ICELAKE_X, core_funcs), 2427 - X86_MATCH(SAPPHIRERAPIDS_X, core_funcs), 2406 + X86_MATCH(INTEL_BROADWELL_D, core_funcs), 2407 + X86_MATCH(INTEL_BROADWELL_X, core_funcs), 2408 + X86_MATCH(INTEL_SKYLAKE_X, core_funcs), 2409 + X86_MATCH(INTEL_ICELAKE_X, core_funcs), 2410 + X86_MATCH(INTEL_SAPPHIRERAPIDS_X, core_funcs), 2411 + X86_MATCH(INTEL_EMERALDRAPIDS_X, core_funcs), 2428 2412 {} 2429 2413 }; 2430 2414 #endif 2431 2415 2432 2416 static const struct x86_cpu_id intel_pstate_cpu_ee_disable_ids[] = { 2433 - X86_MATCH(KABYLAKE, core_funcs), 2417 + X86_MATCH(INTEL_KABYLAKE, core_funcs), 2434 2418 {} 2435 2419 }; 2436 2420 ··· 2715 2699 return intel_cpufreq_cpu_offline(policy); 2716 2700 } 2717 2701 2718 - static int intel_pstate_cpu_exit(struct cpufreq_policy *policy) 2702 + static void intel_pstate_cpu_exit(struct cpufreq_policy *policy) 2719 2703 { 2720 2704 pr_debug("CPU %d exiting\n", policy->cpu); 2721 2705 2722 2706 policy->fast_switch_possible = false; 2723 - 2724 - return 0; 2725 2707 } 2726 2708 2727 2709 static int __intel_pstate_cpu_init(struct cpufreq_policy *policy) ··· 3050 3036 return ret; 3051 3037 } 3052 3038 3053 - static int intel_cpufreq_cpu_exit(struct cpufreq_policy *policy) 3039 + static void intel_cpufreq_cpu_exit(struct cpufreq_policy *policy) 3054 3040 { 3055 3041 struct freq_qos_request *req; 3056 3042 ··· 3060 3046 freq_qos_remove_request(req); 3061 3047 kfree(req); 3062 3048 3063 - return intel_pstate_cpu_exit(policy); 3049 + intel_pstate_cpu_exit(policy); 3064 3050 } 3065 3051 3066 3052 static int intel_cpufreq_suspend(struct cpufreq_policy *policy) ··· 3364 3350 3365 3351 #define INTEL_PSTATE_HWP_BROADWELL 0x01 3366 3352 3367 - #define X86_MATCH_HWP(model, hwp_mode) \ 3368 - X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, INTEL_FAM6_##model, \ 3369 - X86_FEATURE_HWP, hwp_mode) 3353 + #define X86_MATCH_HWP(vfm, hwp_mode) \ 3354 + X86_MATCH_VFM_FEATURE(vfm, X86_FEATURE_HWP, hwp_mode) 3370 3355 3371 3356 static const struct x86_cpu_id hwp_support_ids[] __initconst = { 3372 - X86_MATCH_HWP(BROADWELL_X, INTEL_PSTATE_HWP_BROADWELL), 3373 - X86_MATCH_HWP(BROADWELL_D, INTEL_PSTATE_HWP_BROADWELL), 3374 - X86_MATCH_HWP(ANY, 0), 3357 + X86_MATCH_HWP(INTEL_BROADWELL_X, INTEL_PSTATE_HWP_BROADWELL), 3358 + X86_MATCH_HWP(INTEL_BROADWELL_D, INTEL_PSTATE_HWP_BROADWELL), 3359 + X86_MATCH_HWP(INTEL_ANY, 0), 3375 3360 {} 3376 3361 }; 3377 3362 ··· 3403 3390 * which can result in one core turbo frequency for 3404 3391 * AlderLake Mobile CPUs. 3405 3392 */ 3406 - X86_MATCH_INTEL_FAM6_MODEL(ALDERLAKE_L, HWP_SET_DEF_BALANCE_PERF_EPP(102)), 3407 - X86_MATCH_INTEL_FAM6_MODEL(SAPPHIRERAPIDS_X, HWP_SET_DEF_BALANCE_PERF_EPP(32)), 3408 - X86_MATCH_INTEL_FAM6_MODEL(METEORLAKE_L, HWP_SET_EPP_VALUES(HWP_EPP_POWERSAVE, 3409 - HWP_EPP_BALANCE_POWERSAVE, 115, 16)), 3393 + X86_MATCH_VFM(INTEL_ALDERLAKE_L, HWP_SET_DEF_BALANCE_PERF_EPP(102)), 3394 + X86_MATCH_VFM(INTEL_SAPPHIRERAPIDS_X, HWP_SET_DEF_BALANCE_PERF_EPP(32)), 3395 + X86_MATCH_VFM(INTEL_METEORLAKE_L, HWP_SET_EPP_VALUES(HWP_EPP_POWERSAVE, 3396 + 179, 64, 16)), 3397 + X86_MATCH_VFM(INTEL_ARROWLAKE, HWP_SET_EPP_VALUES(HWP_EPP_POWERSAVE, 3398 + 179, 64, 16)), 3410 3399 {} 3411 3400 }; 3412 3401 3413 3402 static const struct x86_cpu_id intel_hybrid_scaling_factor[] = { 3414 - X86_MATCH_INTEL_FAM6_MODEL(METEORLAKE_L, HYBRID_SCALING_FACTOR_MTL), 3403 + X86_MATCH_VFM(INTEL_METEORLAKE_L, HYBRID_SCALING_FACTOR_MTL), 3404 + X86_MATCH_VFM(INTEL_ARROWLAKE, HYBRID_SCALING_FACTOR_MTL), 3405 + X86_MATCH_VFM(INTEL_LUNARLAKE_M, HYBRID_SCALING_FACTOR_LNL), 3415 3406 {} 3416 3407 }; 3417 3408
+3 -2
drivers/cpufreq/longhaul.c
··· 236 236 } 237 237 238 238 /** 239 - * longhaul_set_cpu_frequency() 240 - * @mults_index : bitpattern of the new multiplier. 239 + * longhaul_setstate() 240 + * @policy: cpufreq_policy structure containing the current policy. 241 + * @table_index: index of the frequency within the cpufreq_frequency_table. 241 242 * 242 243 * Sets a new clock ratio. 243 244 */
-6
drivers/cpufreq/loongson2_cpufreq.c
··· 85 85 return 0; 86 86 } 87 87 88 - static int loongson2_cpufreq_exit(struct cpufreq_policy *policy) 89 - { 90 - return 0; 91 - } 92 - 93 88 static struct cpufreq_driver loongson2_cpufreq_driver = { 94 89 .name = "loongson2", 95 90 .init = loongson2_cpufreq_cpu_init, 96 91 .verify = cpufreq_generic_frequency_table_verify, 97 92 .target_index = loongson2_cpufreq_target, 98 93 .get = cpufreq_generic_get, 99 - .exit = loongson2_cpufreq_exit, 100 94 .attr = cpufreq_generic_attr, 101 95 }; 102 96
+395
drivers/cpufreq/loongson3_cpufreq.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-only 2 + /* 3 + * CPUFreq driver for the Loongson-3 processors. 4 + * 5 + * All revisions of Loongson-3 processor support cpu_has_scalefreq feature. 6 + * 7 + * Author: Huacai Chen <chenhuacai@loongson.cn> 8 + * Copyright (C) 2024 Loongson Technology Corporation Limited 9 + */ 10 + #include <linux/cpufreq.h> 11 + #include <linux/delay.h> 12 + #include <linux/module.h> 13 + #include <linux/platform_device.h> 14 + #include <linux/units.h> 15 + 16 + #include <asm/idle.h> 17 + #include <asm/loongarch.h> 18 + #include <asm/loongson.h> 19 + 20 + /* Message */ 21 + union smc_message { 22 + u32 value; 23 + struct { 24 + u32 id : 4; 25 + u32 info : 4; 26 + u32 val : 16; 27 + u32 cmd : 6; 28 + u32 extra : 1; 29 + u32 complete : 1; 30 + }; 31 + }; 32 + 33 + /* Command return values */ 34 + #define CMD_OK 0 /* No error */ 35 + #define CMD_ERROR 1 /* Regular error */ 36 + #define CMD_NOCMD 2 /* Command does not support */ 37 + #define CMD_INVAL 3 /* Invalid Parameter */ 38 + 39 + /* Version commands */ 40 + /* 41 + * CMD_GET_VERSION - Get interface version 42 + * Input: none 43 + * Output: version 44 + */ 45 + #define CMD_GET_VERSION 0x1 46 + 47 + /* Feature commands */ 48 + /* 49 + * CMD_GET_FEATURE - Get feature state 50 + * Input: feature ID 51 + * Output: feature flag 52 + */ 53 + #define CMD_GET_FEATURE 0x2 54 + 55 + /* 56 + * CMD_SET_FEATURE - Set feature state 57 + * Input: feature ID, feature flag 58 + * output: none 59 + */ 60 + #define CMD_SET_FEATURE 0x3 61 + 62 + /* Feature IDs */ 63 + #define FEATURE_SENSOR 0 64 + #define FEATURE_FAN 1 65 + #define FEATURE_DVFS 2 66 + 67 + /* Sensor feature flags */ 68 + #define FEATURE_SENSOR_ENABLE BIT(0) 69 + #define FEATURE_SENSOR_SAMPLE BIT(1) 70 + 71 + /* Fan feature flags */ 72 + #define FEATURE_FAN_ENABLE BIT(0) 73 + #define FEATURE_FAN_AUTO BIT(1) 74 + 75 + /* DVFS feature flags */ 76 + #define FEATURE_DVFS_ENABLE BIT(0) 77 + #define FEATURE_DVFS_BOOST BIT(1) 78 + #define FEATURE_DVFS_AUTO BIT(2) 79 + #define FEATURE_DVFS_SINGLE_BOOST BIT(3) 80 + 81 + /* Sensor commands */ 82 + /* 83 + * CMD_GET_SENSOR_NUM - Get number of sensors 84 + * Input: none 85 + * Output: number 86 + */ 87 + #define CMD_GET_SENSOR_NUM 0x4 88 + 89 + /* 90 + * CMD_GET_SENSOR_STATUS - Get sensor status 91 + * Input: sensor ID, type 92 + * Output: sensor status 93 + */ 94 + #define CMD_GET_SENSOR_STATUS 0x5 95 + 96 + /* Sensor types */ 97 + #define SENSOR_INFO_TYPE 0 98 + #define SENSOR_INFO_TYPE_TEMP 1 99 + 100 + /* Fan commands */ 101 + /* 102 + * CMD_GET_FAN_NUM - Get number of fans 103 + * Input: none 104 + * Output: number 105 + */ 106 + #define CMD_GET_FAN_NUM 0x6 107 + 108 + /* 109 + * CMD_GET_FAN_INFO - Get fan status 110 + * Input: fan ID, type 111 + * Output: fan info 112 + */ 113 + #define CMD_GET_FAN_INFO 0x7 114 + 115 + /* 116 + * CMD_SET_FAN_INFO - Set fan status 117 + * Input: fan ID, type, value 118 + * Output: none 119 + */ 120 + #define CMD_SET_FAN_INFO 0x8 121 + 122 + /* Fan types */ 123 + #define FAN_INFO_TYPE_LEVEL 0 124 + 125 + /* DVFS commands */ 126 + /* 127 + * CMD_GET_FREQ_LEVEL_NUM - Get number of freq levels 128 + * Input: CPU ID 129 + * Output: number 130 + */ 131 + #define CMD_GET_FREQ_LEVEL_NUM 0x9 132 + 133 + /* 134 + * CMD_GET_FREQ_BOOST_LEVEL - Get the first boost level 135 + * Input: CPU ID 136 + * Output: number 137 + */ 138 + #define CMD_GET_FREQ_BOOST_LEVEL 0x10 139 + 140 + /* 141 + * CMD_GET_FREQ_LEVEL_INFO - Get freq level info 142 + * Input: CPU ID, level ID 143 + * Output: level info 144 + */ 145 + #define CMD_GET_FREQ_LEVEL_INFO 0x11 146 + 147 + /* 148 + * CMD_GET_FREQ_INFO - Get freq info 149 + * Input: CPU ID, type 150 + * Output: freq info 151 + */ 152 + #define CMD_GET_FREQ_INFO 0x12 153 + 154 + /* 155 + * CMD_SET_FREQ_INFO - Set freq info 156 + * Input: CPU ID, type, value 157 + * Output: none 158 + */ 159 + #define CMD_SET_FREQ_INFO 0x13 160 + 161 + /* Freq types */ 162 + #define FREQ_INFO_TYPE_FREQ 0 163 + #define FREQ_INFO_TYPE_LEVEL 1 164 + 165 + #define FREQ_MAX_LEVEL 16 166 + 167 + struct loongson3_freq_data { 168 + unsigned int def_freq_level; 169 + struct cpufreq_frequency_table table[]; 170 + }; 171 + 172 + static struct mutex cpufreq_mutex[MAX_PACKAGES]; 173 + static struct cpufreq_driver loongson3_cpufreq_driver; 174 + static DEFINE_PER_CPU(struct loongson3_freq_data *, freq_data); 175 + 176 + static inline int do_service_request(u32 id, u32 info, u32 cmd, u32 val, u32 extra) 177 + { 178 + int retries; 179 + unsigned int cpu = smp_processor_id(); 180 + unsigned int package = cpu_data[cpu].package; 181 + union smc_message msg, last; 182 + 183 + mutex_lock(&cpufreq_mutex[package]); 184 + 185 + last.value = iocsr_read32(LOONGARCH_IOCSR_SMCMBX); 186 + if (!last.complete) { 187 + mutex_unlock(&cpufreq_mutex[package]); 188 + return -EPERM; 189 + } 190 + 191 + msg.id = id; 192 + msg.info = info; 193 + msg.cmd = cmd; 194 + msg.val = val; 195 + msg.extra = extra; 196 + msg.complete = 0; 197 + 198 + iocsr_write32(msg.value, LOONGARCH_IOCSR_SMCMBX); 199 + iocsr_write32(iocsr_read32(LOONGARCH_IOCSR_MISC_FUNC) | IOCSR_MISC_FUNC_SOFT_INT, 200 + LOONGARCH_IOCSR_MISC_FUNC); 201 + 202 + for (retries = 0; retries < 10000; retries++) { 203 + msg.value = iocsr_read32(LOONGARCH_IOCSR_SMCMBX); 204 + if (msg.complete) 205 + break; 206 + 207 + usleep_range(8, 12); 208 + } 209 + 210 + if (!msg.complete || msg.cmd != CMD_OK) { 211 + mutex_unlock(&cpufreq_mutex[package]); 212 + return -EPERM; 213 + } 214 + 215 + mutex_unlock(&cpufreq_mutex[package]); 216 + 217 + return msg.val; 218 + } 219 + 220 + static unsigned int loongson3_cpufreq_get(unsigned int cpu) 221 + { 222 + int ret; 223 + 224 + ret = do_service_request(cpu, FREQ_INFO_TYPE_FREQ, CMD_GET_FREQ_INFO, 0, 0); 225 + 226 + return ret * KILO; 227 + } 228 + 229 + static int loongson3_cpufreq_target(struct cpufreq_policy *policy, unsigned int index) 230 + { 231 + int ret; 232 + 233 + ret = do_service_request(cpu_data[policy->cpu].core, 234 + FREQ_INFO_TYPE_LEVEL, CMD_SET_FREQ_INFO, index, 0); 235 + 236 + return (ret >= 0) ? 0 : ret; 237 + } 238 + 239 + static int configure_freq_table(int cpu) 240 + { 241 + int i, ret, boost_level, max_level, freq_level; 242 + struct platform_device *pdev = cpufreq_get_driver_data(); 243 + struct loongson3_freq_data *data; 244 + 245 + if (per_cpu(freq_data, cpu)) 246 + return 0; 247 + 248 + ret = do_service_request(cpu, 0, CMD_GET_FREQ_LEVEL_NUM, 0, 0); 249 + if (ret < 0) 250 + return ret; 251 + max_level = ret; 252 + 253 + ret = do_service_request(cpu, 0, CMD_GET_FREQ_BOOST_LEVEL, 0, 0); 254 + if (ret < 0) 255 + return ret; 256 + boost_level = ret; 257 + 258 + freq_level = min(max_level, FREQ_MAX_LEVEL); 259 + data = devm_kzalloc(&pdev->dev, struct_size(data, table, freq_level + 1), GFP_KERNEL); 260 + if (!data) 261 + return -ENOMEM; 262 + 263 + data->def_freq_level = boost_level - 1; 264 + 265 + for (i = 0; i < freq_level; i++) { 266 + ret = do_service_request(cpu, FREQ_INFO_TYPE_FREQ, CMD_GET_FREQ_LEVEL_INFO, i, 0); 267 + if (ret < 0) { 268 + devm_kfree(&pdev->dev, data); 269 + return ret; 270 + } 271 + 272 + data->table[i].frequency = ret * KILO; 273 + data->table[i].flags = (i >= boost_level) ? CPUFREQ_BOOST_FREQ : 0; 274 + } 275 + 276 + data->table[freq_level].flags = 0; 277 + data->table[freq_level].frequency = CPUFREQ_TABLE_END; 278 + 279 + per_cpu(freq_data, cpu) = data; 280 + 281 + return 0; 282 + } 283 + 284 + static int loongson3_cpufreq_cpu_init(struct cpufreq_policy *policy) 285 + { 286 + int i, ret, cpu = policy->cpu; 287 + 288 + ret = configure_freq_table(cpu); 289 + if (ret < 0) 290 + return ret; 291 + 292 + policy->cpuinfo.transition_latency = 10000; 293 + policy->freq_table = per_cpu(freq_data, cpu)->table; 294 + policy->suspend_freq = policy->freq_table[per_cpu(freq_data, cpu)->def_freq_level].frequency; 295 + cpumask_copy(policy->cpus, topology_sibling_cpumask(cpu)); 296 + 297 + for_each_cpu(i, policy->cpus) { 298 + if (i != cpu) 299 + per_cpu(freq_data, i) = per_cpu(freq_data, cpu); 300 + } 301 + 302 + if (policy_has_boost_freq(policy)) { 303 + ret = cpufreq_enable_boost_support(); 304 + if (ret < 0) { 305 + pr_warn("cpufreq: Failed to enable boost: %d\n", ret); 306 + return ret; 307 + } 308 + loongson3_cpufreq_driver.boost_enabled = true; 309 + } 310 + 311 + return 0; 312 + } 313 + 314 + static void loongson3_cpufreq_cpu_exit(struct cpufreq_policy *policy) 315 + { 316 + int cpu = policy->cpu; 317 + 318 + loongson3_cpufreq_target(policy, per_cpu(freq_data, cpu)->def_freq_level); 319 + } 320 + 321 + static int loongson3_cpufreq_cpu_online(struct cpufreq_policy *policy) 322 + { 323 + return 0; 324 + } 325 + 326 + static int loongson3_cpufreq_cpu_offline(struct cpufreq_policy *policy) 327 + { 328 + return 0; 329 + } 330 + 331 + static struct cpufreq_driver loongson3_cpufreq_driver = { 332 + .name = "loongson3", 333 + .flags = CPUFREQ_CONST_LOOPS, 334 + .init = loongson3_cpufreq_cpu_init, 335 + .exit = loongson3_cpufreq_cpu_exit, 336 + .online = loongson3_cpufreq_cpu_online, 337 + .offline = loongson3_cpufreq_cpu_offline, 338 + .get = loongson3_cpufreq_get, 339 + .target_index = loongson3_cpufreq_target, 340 + .attr = cpufreq_generic_attr, 341 + .verify = cpufreq_generic_frequency_table_verify, 342 + .suspend = cpufreq_generic_suspend, 343 + }; 344 + 345 + static int loongson3_cpufreq_probe(struct platform_device *pdev) 346 + { 347 + int i, ret; 348 + 349 + for (i = 0; i < MAX_PACKAGES; i++) 350 + devm_mutex_init(&pdev->dev, &cpufreq_mutex[i]); 351 + 352 + ret = do_service_request(0, 0, CMD_GET_VERSION, 0, 0); 353 + if (ret <= 0) 354 + return -EPERM; 355 + 356 + ret = do_service_request(FEATURE_DVFS, 0, CMD_SET_FEATURE, 357 + FEATURE_DVFS_ENABLE | FEATURE_DVFS_BOOST, 0); 358 + if (ret < 0) 359 + return -EPERM; 360 + 361 + loongson3_cpufreq_driver.driver_data = pdev; 362 + 363 + ret = cpufreq_register_driver(&loongson3_cpufreq_driver); 364 + if (ret) 365 + return ret; 366 + 367 + pr_info("cpufreq: Loongson-3 CPU frequency driver.\n"); 368 + 369 + return 0; 370 + } 371 + 372 + static void loongson3_cpufreq_remove(struct platform_device *pdev) 373 + { 374 + cpufreq_unregister_driver(&loongson3_cpufreq_driver); 375 + } 376 + 377 + static struct platform_device_id cpufreq_id_table[] = { 378 + { "loongson3_cpufreq", }, 379 + { /* sentinel */ } 380 + }; 381 + MODULE_DEVICE_TABLE(platform, cpufreq_id_table); 382 + 383 + static struct platform_driver loongson3_platform_driver = { 384 + .driver = { 385 + .name = "loongson3_cpufreq", 386 + }, 387 + .id_table = cpufreq_id_table, 388 + .probe = loongson3_cpufreq_probe, 389 + .remove_new = loongson3_cpufreq_remove, 390 + }; 391 + module_platform_driver(loongson3_platform_driver); 392 + 393 + MODULE_AUTHOR("Huacai Chen <chenhuacai@loongson.cn>"); 394 + MODULE_DESCRIPTION("CPUFreq driver for Loongson-3 processors"); 395 + MODULE_LICENSE("GPL");
+1 -3
drivers/cpufreq/mediatek-cpufreq-hw.c
··· 260 260 return 0; 261 261 } 262 262 263 - static int mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) 263 + static void mtk_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) 264 264 { 265 265 struct mtk_cpufreq_data *data = policy->driver_data; 266 266 struct resource *res = data->res; ··· 270 270 writel_relaxed(0x0, data->reg_bases[REG_FREQ_ENABLE]); 271 271 iounmap(base); 272 272 release_mem_region(res->start, resource_size(res)); 273 - 274 - return 0; 275 273 } 276 274 277 275 static void mtk_cpufreq_register_em(struct cpufreq_policy *policy)
+35 -41
drivers/cpufreq/mediatek-cpufreq.c
··· 390 390 int ret; 391 391 392 392 cpu_dev = get_cpu_device(cpu); 393 - if (!cpu_dev) { 394 - dev_err(cpu_dev, "failed to get cpu%d device\n", cpu); 395 - return -ENODEV; 396 - } 393 + if (!cpu_dev) 394 + return dev_err_probe(cpu_dev, -ENODEV, "failed to get cpu%d device\n", cpu); 397 395 info->cpu_dev = cpu_dev; 398 396 399 397 info->ccifreq_bound = false; 400 398 if (info->soc_data->ccifreq_supported) { 401 399 info->cci_dev = of_get_cci(info->cpu_dev); 402 - if (IS_ERR(info->cci_dev)) { 403 - ret = PTR_ERR(info->cci_dev); 404 - dev_err(cpu_dev, "cpu%d: failed to get cci device\n", cpu); 405 - return -ENODEV; 406 - } 400 + if (IS_ERR(info->cci_dev)) 401 + return dev_err_probe(cpu_dev, PTR_ERR(info->cci_dev), 402 + "cpu%d: failed to get cci device\n", 403 + cpu); 407 404 } 408 405 409 406 info->cpu_clk = clk_get(cpu_dev, "cpu"); 410 - if (IS_ERR(info->cpu_clk)) { 411 - ret = PTR_ERR(info->cpu_clk); 412 - return dev_err_probe(cpu_dev, ret, 407 + if (IS_ERR(info->cpu_clk)) 408 + return dev_err_probe(cpu_dev, PTR_ERR(info->cpu_clk), 413 409 "cpu%d: failed to get cpu clk\n", cpu); 414 - } 415 410 416 411 info->inter_clk = clk_get(cpu_dev, "intermediate"); 417 412 if (IS_ERR(info->inter_clk)) { ··· 426 431 427 432 ret = regulator_enable(info->proc_reg); 428 433 if (ret) { 429 - dev_warn(cpu_dev, "cpu%d: failed to enable vproc\n", cpu); 434 + dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable vproc\n", cpu); 430 435 goto out_free_proc_reg; 431 436 } 432 437 ··· 434 439 info->sram_reg = regulator_get_optional(cpu_dev, "sram"); 435 440 if (IS_ERR(info->sram_reg)) { 436 441 ret = PTR_ERR(info->sram_reg); 437 - if (ret == -EPROBE_DEFER) 442 + if (ret == -EPROBE_DEFER) { 443 + dev_err_probe(cpu_dev, ret, 444 + "cpu%d: Failed to get sram regulator\n", cpu); 438 445 goto out_disable_proc_reg; 446 + } 439 447 440 448 info->sram_reg = NULL; 441 449 } else { 442 450 ret = regulator_enable(info->sram_reg); 443 451 if (ret) { 444 - dev_warn(cpu_dev, "cpu%d: failed to enable vsram\n", cpu); 452 + dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable vsram\n", cpu); 445 453 goto out_free_sram_reg; 446 454 } 447 455 } ··· 452 454 /* Get OPP-sharing information from "operating-points-v2" bindings */ 453 455 ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, &info->cpus); 454 456 if (ret) { 455 - dev_err(cpu_dev, 457 + dev_err_probe(cpu_dev, ret, 456 458 "cpu%d: failed to get OPP-sharing information\n", cpu); 457 459 goto out_disable_sram_reg; 458 460 } 459 461 460 462 ret = dev_pm_opp_of_cpumask_add_table(&info->cpus); 461 463 if (ret) { 462 - dev_warn(cpu_dev, "cpu%d: no OPP table\n", cpu); 464 + dev_err_probe(cpu_dev, ret, "cpu%d: no OPP table\n", cpu); 463 465 goto out_disable_sram_reg; 464 466 } 465 467 466 468 ret = clk_prepare_enable(info->cpu_clk); 467 - if (ret) 469 + if (ret) { 470 + dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable cpu clk\n", cpu); 468 471 goto out_free_opp_table; 472 + } 469 473 470 474 ret = clk_prepare_enable(info->inter_clk); 471 - if (ret) 475 + if (ret) { 476 + dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable inter clk\n", cpu); 472 477 goto out_disable_mux_clock; 478 + } 473 479 474 480 if (info->soc_data->ccifreq_supported) { 475 481 info->vproc_on_boot = regulator_get_voltage(info->proc_reg); 476 482 if (info->vproc_on_boot < 0) { 477 - ret = info->vproc_on_boot; 478 - dev_err(info->cpu_dev, 479 - "invalid Vproc value: %d\n", info->vproc_on_boot); 483 + ret = dev_err_probe(info->cpu_dev, info->vproc_on_boot, 484 + "invalid Vproc value\n"); 480 485 goto out_disable_inter_clock; 481 486 } 482 487 } ··· 488 487 rate = clk_get_rate(info->inter_clk); 489 488 opp = dev_pm_opp_find_freq_ceil(cpu_dev, &rate); 490 489 if (IS_ERR(opp)) { 491 - dev_err(cpu_dev, "cpu%d: failed to get intermediate opp\n", cpu); 492 - ret = PTR_ERR(opp); 490 + ret = dev_err_probe(cpu_dev, PTR_ERR(opp), 491 + "cpu%d: failed to get intermediate opp\n", cpu); 493 492 goto out_disable_inter_clock; 494 493 } 495 494 info->intermediate_voltage = dev_pm_opp_get_voltage(opp); ··· 502 501 info->opp_nb.notifier_call = mtk_cpufreq_opp_notifier; 503 502 ret = dev_pm_opp_register_notifier(cpu_dev, &info->opp_nb); 504 503 if (ret) { 505 - dev_err(cpu_dev, "cpu%d: failed to register opp notifier\n", cpu); 504 + dev_err_probe(cpu_dev, ret, "cpu%d: failed to register opp notifier\n", cpu); 506 505 goto out_disable_inter_clock; 507 506 } 508 507 ··· 600 599 return 0; 601 600 } 602 601 603 - static int mtk_cpufreq_exit(struct cpufreq_policy *policy) 602 + static void mtk_cpufreq_exit(struct cpufreq_policy *policy) 604 603 { 605 604 struct mtk_cpu_dvfs_info *info = policy->driver_data; 606 605 607 606 dev_pm_opp_free_cpufreq_table(info->cpu_dev, &policy->freq_table); 608 - 609 - return 0; 610 607 } 611 608 612 609 static struct cpufreq_driver mtk_cpufreq_driver = { ··· 628 629 int cpu, ret; 629 630 630 631 data = dev_get_platdata(&pdev->dev); 631 - if (!data) { 632 - dev_err(&pdev->dev, 633 - "failed to get mtk cpufreq platform data\n"); 634 - return -ENODEV; 635 - } 632 + if (!data) 633 + return dev_err_probe(&pdev->dev, -ENODEV, 634 + "failed to get mtk cpufreq platform data\n"); 636 635 637 636 for_each_possible_cpu(cpu) { 638 637 info = mtk_cpu_dvfs_info_lookup(cpu); ··· 639 642 640 643 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); 641 644 if (!info) { 642 - ret = -ENOMEM; 645 + ret = dev_err_probe(&pdev->dev, -ENOMEM, 646 + "Failed to allocate dvfs_info\n"); 643 647 goto release_dvfs_info_list; 644 648 } 645 649 646 650 info->soc_data = data; 647 651 ret = mtk_cpu_dvfs_info_init(info, cpu); 648 - if (ret) { 649 - dev_err(&pdev->dev, 650 - "failed to initialize dvfs info for cpu%d\n", 651 - cpu); 652 + if (ret) 652 653 goto release_dvfs_info_list; 653 - } 654 654 655 655 list_add(&info->list_head, &dvfs_info_list); 656 656 } 657 657 658 658 ret = cpufreq_register_driver(&mtk_cpufreq_driver); 659 659 if (ret) { 660 - dev_err(&pdev->dev, "failed to register mtk cpufreq driver\n"); 660 + dev_err_probe(&pdev->dev, ret, "failed to register mtk cpufreq driver\n"); 661 661 goto release_dvfs_info_list; 662 662 } 663 663
+1 -2
drivers/cpufreq/omap-cpufreq.c
··· 135 135 return 0; 136 136 } 137 137 138 - static int omap_cpu_exit(struct cpufreq_policy *policy) 138 + static void omap_cpu_exit(struct cpufreq_policy *policy) 139 139 { 140 140 freq_table_free(); 141 141 clk_put(policy->clk); 142 - return 0; 143 142 } 144 143 145 144 static struct cpufreq_driver omap_driver = {
+2 -4
drivers/cpufreq/pasemi-cpufreq.c
··· 204 204 return err; 205 205 } 206 206 207 - static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy) 207 + static void pas_cpufreq_cpu_exit(struct cpufreq_policy *policy) 208 208 { 209 209 /* 210 210 * We don't support CPU hotplug. Don't unmap after the system 211 211 * has already made it to a running state. 212 212 */ 213 213 if (system_state >= SYSTEM_RUNNING) 214 - return 0; 214 + return; 215 215 216 216 if (sdcasr_mapbase) 217 217 iounmap(sdcasr_mapbase); 218 218 if (sdcpwr_mapbase) 219 219 iounmap(sdcpwr_mapbase); 220 - 221 - return 0; 222 220 } 223 221 224 222 static int pas_cpufreq_target(struct cpufreq_policy *policy,
-6
drivers/cpufreq/pcc-cpufreq.c
··· 562 562 return result; 563 563 } 564 564 565 - static int pcc_cpufreq_cpu_exit(struct cpufreq_policy *policy) 566 - { 567 - return 0; 568 - } 569 - 570 565 static struct cpufreq_driver pcc_cpufreq_driver = { 571 566 .flags = CPUFREQ_CONST_LOOPS, 572 567 .get = pcc_get_freq, 573 568 .verify = pcc_cpufreq_verify, 574 569 .target = pcc_cpufreq_target, 575 570 .init = pcc_cpufreq_cpu_init, 576 - .exit = pcc_cpufreq_cpu_exit, 577 571 .name = "pcc-cpufreq", 578 572 }; 579 573
+2 -3
drivers/cpufreq/powernow-k6.c
··· 219 219 } 220 220 221 221 222 - static int powernow_k6_cpu_exit(struct cpufreq_policy *policy) 222 + static void powernow_k6_cpu_exit(struct cpufreq_policy *policy) 223 223 { 224 224 unsigned int i; 225 225 ··· 234 234 cpufreq_freq_transition_begin(policy, &freqs); 235 235 powernow_k6_target(policy, i); 236 236 cpufreq_freq_transition_end(policy, &freqs, 0); 237 - break; 237 + return; 238 238 } 239 239 } 240 - return 0; 241 240 } 242 241 243 242 static unsigned int powernow_k6_get(unsigned int cpu)
+1 -2
drivers/cpufreq/powernow-k7.c
··· 644 644 return 0; 645 645 } 646 646 647 - static int powernow_cpu_exit(struct cpufreq_policy *policy) 647 + static void powernow_cpu_exit(struct cpufreq_policy *policy) 648 648 { 649 649 #ifdef CONFIG_X86_POWERNOW_K7_ACPI 650 650 if (acpi_processor_perf) { ··· 655 655 #endif 656 656 657 657 kfree(powernow_table); 658 - return 0; 659 658 } 660 659 661 660 static struct cpufreq_driver powernow_driver = {
+2 -4
drivers/cpufreq/powernow-k8.c
··· 1089 1089 return -ENODEV; 1090 1090 } 1091 1091 1092 - static int powernowk8_cpu_exit(struct cpufreq_policy *pol) 1092 + static void powernowk8_cpu_exit(struct cpufreq_policy *pol) 1093 1093 { 1094 1094 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); 1095 1095 int cpu; 1096 1096 1097 1097 if (!data) 1098 - return -EINVAL; 1098 + return; 1099 1099 1100 1100 powernow_k8_cpu_exit_acpi(data); 1101 1101 ··· 1104 1104 /* pol->cpus will be empty here, use related_cpus instead. */ 1105 1105 for_each_cpu(cpu, pol->related_cpus) 1106 1106 per_cpu(powernow_data, cpu) = NULL; 1107 - 1108 - return 0; 1109 1107 } 1110 1108 1111 1109 static void query_values_on_cpu(void *_err)
+1 -3
drivers/cpufreq/powernv-cpufreq.c
··· 874 874 return 0; 875 875 } 876 876 877 - static int powernv_cpufreq_cpu_exit(struct cpufreq_policy *policy) 877 + static void powernv_cpufreq_cpu_exit(struct cpufreq_policy *policy) 878 878 { 879 879 struct powernv_smp_call_data freq_data; 880 880 struct global_pstate_info *gpstates = policy->driver_data; ··· 886 886 del_timer_sync(&gpstates->timer); 887 887 888 888 kfree(policy->driver_data); 889 - 890 - return 0; 891 889 } 892 890 893 891 static int powernv_cpufreq_reboot_notifier(struct notifier_block *nb,
+1 -2
drivers/cpufreq/ppc_cbe_cpufreq.c
··· 113 113 return 0; 114 114 } 115 115 116 - static int cbe_cpufreq_cpu_exit(struct cpufreq_policy *policy) 116 + static void cbe_cpufreq_cpu_exit(struct cpufreq_policy *policy) 117 117 { 118 118 cbe_cpufreq_pmi_policy_exit(policy); 119 - return 0; 120 119 } 121 120 122 121 static int cbe_cpufreq_target(struct cpufreq_policy *policy,
+1 -3
drivers/cpufreq/qcom-cpufreq-hw.c
··· 573 573 return qcom_cpufreq_hw_lmh_init(policy, index); 574 574 } 575 575 576 - static int qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) 576 + static void qcom_cpufreq_hw_cpu_exit(struct cpufreq_policy *policy) 577 577 { 578 578 struct device *cpu_dev = get_cpu_device(policy->cpu); 579 579 struct qcom_cpufreq_data *data = policy->driver_data; ··· 583 583 qcom_cpufreq_hw_lmh_exit(data); 584 584 kfree(policy->freq_table); 585 585 kfree(data); 586 - 587 - return 0; 588 586 } 589 587 590 588 static void qcom_cpufreq_ready(struct cpufreq_policy *policy)
+4 -8
drivers/cpufreq/qcom-cpufreq-nvmem.c
··· 455 455 { 456 456 struct qcom_cpufreq_drv *drv; 457 457 struct nvmem_cell *speedbin_nvmem; 458 - struct device_node *np; 459 458 struct device *cpu_dev; 460 459 char pvs_name_buffer[] = "speedXX-pvsXX-vXX"; 461 460 char *pvs_name = pvs_name_buffer; ··· 466 467 if (!cpu_dev) 467 468 return -ENODEV; 468 469 469 - np = dev_pm_opp_of_get_opp_desc_node(cpu_dev); 470 + struct device_node *np __free(device_node) = 471 + dev_pm_opp_of_get_opp_desc_node(cpu_dev); 470 472 if (!np) 471 473 return -ENOENT; 472 474 473 475 ret = of_device_is_compatible(np, "operating-points-v2-kryo-cpu") || 474 476 of_device_is_compatible(np, "operating-points-v2-krait-cpu"); 475 - if (!ret) { 476 - of_node_put(np); 477 + if (!ret) 477 478 return -ENOENT; 478 - } 479 479 480 480 drv = devm_kzalloc(&pdev->dev, struct_size(drv, cpus, num_possible_cpus()), 481 481 GFP_KERNEL); ··· 500 502 } 501 503 nvmem_cell_put(speedbin_nvmem); 502 504 } 503 - of_node_put(np); 504 505 505 506 for_each_possible_cpu(cpu) { 506 507 struct device **virt_devs = NULL; ··· 635 638 */ 636 639 static int __init qcom_cpufreq_init(void) 637 640 { 638 - struct device_node *np = of_find_node_by_path("/"); 641 + struct device_node *np __free(device_node) = of_find_node_by_path("/"); 639 642 const struct of_device_id *match; 640 643 int ret; 641 644 ··· 643 646 return -ENODEV; 644 647 645 648 match = of_match_node(qcom_cpufreq_match_list, np); 646 - of_node_put(np); 647 649 if (!match) 648 650 return -ENODEV; 649 651
+1 -3
drivers/cpufreq/qoriq-cpufreq.c
··· 225 225 return -ENODEV; 226 226 } 227 227 228 - static int qoriq_cpufreq_cpu_exit(struct cpufreq_policy *policy) 228 + static void qoriq_cpufreq_cpu_exit(struct cpufreq_policy *policy) 229 229 { 230 230 struct cpu_data *data = policy->driver_data; 231 231 ··· 233 233 kfree(data->table); 234 234 kfree(data); 235 235 policy->driver_data = NULL; 236 - 237 - return 0; 238 236 } 239 237 240 238 static int qoriq_cpufreq_target(struct cpufreq_policy *policy,
+3 -5
drivers/cpufreq/scmi-cpufreq.c
··· 63 63 unsigned int target_freq) 64 64 { 65 65 struct scmi_data *priv = policy->driver_data; 66 + unsigned long freq = target_freq; 66 67 67 - if (!perf_ops->freq_set(ph, priv->domain_id, 68 - target_freq * 1000, true)) 68 + if (!perf_ops->freq_set(ph, priv->domain_id, freq * 1000, true)) 69 69 return target_freq; 70 70 71 71 return 0; ··· 308 308 return ret; 309 309 } 310 310 311 - static int scmi_cpufreq_exit(struct cpufreq_policy *policy) 311 + static void scmi_cpufreq_exit(struct cpufreq_policy *policy) 312 312 { 313 313 struct scmi_data *priv = policy->driver_data; 314 314 ··· 316 316 dev_pm_opp_remove_all_dynamic(priv->cpu_dev); 317 317 free_cpumask_var(priv->opp_shared_cpus); 318 318 kfree(priv); 319 - 320 - return 0; 321 319 } 322 320 323 321 static void scmi_cpufreq_register_em(struct cpufreq_policy *policy)
+1 -3
drivers/cpufreq/scpi-cpufreq.c
··· 167 167 return ret; 168 168 } 169 169 170 - static int scpi_cpufreq_exit(struct cpufreq_policy *policy) 170 + static void scpi_cpufreq_exit(struct cpufreq_policy *policy) 171 171 { 172 172 struct scpi_data *priv = policy->driver_data; 173 173 ··· 175 175 dev_pm_opp_free_cpufreq_table(priv->cpu_dev, &policy->freq_table); 176 176 dev_pm_opp_remove_all_dynamic(priv->cpu_dev); 177 177 kfree(priv); 178 - 179 - return 0; 180 178 } 181 179 182 180 static struct cpufreq_driver scpi_cpufreq_driver = {
+1 -3
drivers/cpufreq/sh-cpufreq.c
··· 135 135 return 0; 136 136 } 137 137 138 - static int sh_cpufreq_cpu_exit(struct cpufreq_policy *policy) 138 + static void sh_cpufreq_cpu_exit(struct cpufreq_policy *policy) 139 139 { 140 140 unsigned int cpu = policy->cpu; 141 141 struct clk *cpuclk = &per_cpu(sh_cpuclk, cpu); 142 142 143 143 clk_put(cpuclk); 144 - 145 - return 0; 146 144 } 147 145 148 146 static struct cpufreq_driver sh_cpufreq_driver = {
+1 -2
drivers/cpufreq/sparc-us2e-cpufreq.c
··· 296 296 return 0; 297 297 } 298 298 299 - static int us2e_freq_cpu_exit(struct cpufreq_policy *policy) 299 + static void us2e_freq_cpu_exit(struct cpufreq_policy *policy) 300 300 { 301 301 us2e_freq_target(policy, 0); 302 - return 0; 303 302 } 304 303 305 304 static struct cpufreq_driver cpufreq_us2e_driver = {
+1 -2
drivers/cpufreq/sparc-us3-cpufreq.c
··· 140 140 return 0; 141 141 } 142 142 143 - static int us3_freq_cpu_exit(struct cpufreq_policy *policy) 143 + static void us3_freq_cpu_exit(struct cpufreq_policy *policy) 144 144 { 145 145 us3_freq_target(policy, 0); 146 - return 0; 147 146 } 148 147 149 148 static struct cpufreq_driver cpufreq_us3_driver = {
+7 -11
drivers/cpufreq/speedstep-centrino.c
··· 400 400 return 0; 401 401 } 402 402 403 - static int centrino_cpu_exit(struct cpufreq_policy *policy) 403 + static void centrino_cpu_exit(struct cpufreq_policy *policy) 404 404 { 405 405 unsigned int cpu = policy->cpu; 406 406 407 - if (!per_cpu(centrino_model, cpu)) 408 - return -ENODEV; 409 - 410 - per_cpu(centrino_model, cpu) = NULL; 411 - 412 - return 0; 407 + if (per_cpu(centrino_model, cpu)) 408 + per_cpu(centrino_model, cpu) = NULL; 413 409 } 414 410 415 411 /** ··· 516 520 * or ASCII model IDs. 517 521 */ 518 522 static const struct x86_cpu_id centrino_ids[] = { 519 - X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, 9, X86_FEATURE_EST, NULL), 520 - X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 6, 13, X86_FEATURE_EST, NULL), 521 - X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 15, 3, X86_FEATURE_EST, NULL), 522 - X86_MATCH_VENDOR_FAM_MODEL_FEATURE(INTEL, 15, 4, X86_FEATURE_EST, NULL), 523 + X86_MATCH_VFM_FEATURE(IFM( 6, 9), X86_FEATURE_EST, NULL), 524 + X86_MATCH_VFM_FEATURE(IFM( 6, 13), X86_FEATURE_EST, NULL), 525 + X86_MATCH_VFM_FEATURE(IFM(15, 3), X86_FEATURE_EST, NULL), 526 + X86_MATCH_VFM_FEATURE(IFM(15, 4), X86_FEATURE_EST, NULL), 523 527 {} 524 528 }; 525 529
+2 -1
drivers/cpufreq/sti-cpufreq.c
··· 18 18 #include <linux/regmap.h> 19 19 20 20 #define VERSION_ELEMENTS 3 21 - #define MAX_PCODE_NAME_LEN 7 21 + #define MAX_PCODE_NAME_LEN 16 22 22 23 23 #define VERSION_SHIFT 28 24 24 #define HW_INFO_INDEX 1 ··· 293 293 static const struct of_device_id __maybe_unused sti_cpufreq_of_match[] = { 294 294 { .compatible = "st,stih407" }, 295 295 { .compatible = "st,stih410" }, 296 + { .compatible = "st,stih418" }, 296 297 { }, 297 298 }; 298 299 MODULE_DEVICE_TABLE(of, sti_cpufreq_of_match);
+12 -18
drivers/cpufreq/sun50i-cpufreq-nvmem.c
··· 91 91 case 0x5d00: 92 92 value = 0; 93 93 break; 94 + case 0x6c00: 95 + value = 5; 96 + break; 94 97 default: 95 98 pr_warn("sun50i-cpufreq-nvmem: unknown speed bin 0x%x, using default bin 0\n", 96 99 speedbin & 0xffff); ··· 134 131 static bool dt_has_supported_hw(void) 135 132 { 136 133 bool has_opp_supported_hw = false; 137 - struct device_node *np, *opp; 138 134 struct device *cpu_dev; 139 135 140 136 cpu_dev = get_cpu_device(0); 141 137 if (!cpu_dev) 142 138 return false; 143 139 144 - np = dev_pm_opp_of_get_opp_desc_node(cpu_dev); 140 + struct device_node *np __free(device_node) = 141 + dev_pm_opp_of_get_opp_desc_node(cpu_dev); 145 142 if (!np) 146 143 return false; 147 144 148 - for_each_child_of_node(np, opp) { 145 + for_each_child_of_node_scoped(np, opp) { 149 146 if (of_find_property(opp, "opp-supported-hw", NULL)) { 150 147 has_opp_supported_hw = true; 151 148 break; 152 149 } 153 150 } 154 - 155 - of_node_put(np); 156 151 157 152 return has_opp_supported_hw; 158 153 } ··· 166 165 const struct sunxi_cpufreq_data *opp_data; 167 166 struct nvmem_cell *speedbin_nvmem; 168 167 const struct of_device_id *match; 169 - struct device_node *np; 170 168 struct device *cpu_dev; 171 169 u32 *speedbin; 172 170 int ret; ··· 174 174 if (!cpu_dev) 175 175 return -ENODEV; 176 176 177 - np = dev_pm_opp_of_get_opp_desc_node(cpu_dev); 177 + struct device_node *np __free(device_node) = 178 + dev_pm_opp_of_get_opp_desc_node(cpu_dev); 178 179 if (!np) 179 180 return -ENOENT; 180 181 181 182 match = of_match_node(cpu_opp_match_list, np); 182 - if (!match) { 183 - of_node_put(np); 183 + if (!match) 184 184 return -ENOENT; 185 - } 185 + 186 186 opp_data = match->data; 187 187 188 188 speedbin_nvmem = of_nvmem_cell_get(np, NULL); 189 - of_node_put(np); 190 189 if (IS_ERR(speedbin_nvmem)) 191 190 return dev_err_probe(cpu_dev, PTR_ERR(speedbin_nvmem), 192 191 "Could not get nvmem cell\n"); ··· 300 301 301 302 static const struct of_device_id *sun50i_cpufreq_match_node(void) 302 303 { 303 - const struct of_device_id *match; 304 - struct device_node *np; 304 + struct device_node *np __free(device_node) = of_find_node_by_path("/"); 305 305 306 - np = of_find_node_by_path("/"); 307 - match = of_match_node(sun50i_cpufreq_match_list, np); 308 - of_node_put(np); 309 - 310 - return match; 306 + return of_match_node(sun50i_cpufreq_match_list, np); 311 307 } 312 308 313 309 /*
+1 -3
drivers/cpufreq/tegra194-cpufreq.c
··· 551 551 return 0; 552 552 } 553 553 554 - static int tegra194_cpufreq_exit(struct cpufreq_policy *policy) 554 + static void tegra194_cpufreq_exit(struct cpufreq_policy *policy) 555 555 { 556 556 struct device *cpu_dev = get_cpu_device(policy->cpu); 557 557 558 558 dev_pm_opp_remove_all_dynamic(cpu_dev); 559 559 dev_pm_opp_of_cpumask_remove_table(policy->related_cpus); 560 - 561 - return 0; 562 560 } 563 561 564 562 static int tegra194_cpufreq_set_target(struct cpufreq_policy *policy,
+93 -3
drivers/cpufreq/ti-cpufreq.c
··· 47 47 #define AM625_SUPPORT_S_MPU_OPP BIT(1) 48 48 #define AM625_SUPPORT_T_MPU_OPP BIT(2) 49 49 50 + enum { 51 + AM62A7_EFUSE_M_MPU_OPP = 13, 52 + AM62A7_EFUSE_N_MPU_OPP, 53 + AM62A7_EFUSE_O_MPU_OPP, 54 + AM62A7_EFUSE_P_MPU_OPP, 55 + AM62A7_EFUSE_Q_MPU_OPP, 56 + AM62A7_EFUSE_R_MPU_OPP, 57 + AM62A7_EFUSE_S_MPU_OPP, 58 + /* 59 + * The V, U, and T speed grade numbering is out of order 60 + * to align with the AM625 more uniformly. I promise I know 61 + * my ABCs ;) 62 + */ 63 + AM62A7_EFUSE_V_MPU_OPP, 64 + AM62A7_EFUSE_U_MPU_OPP, 65 + AM62A7_EFUSE_T_MPU_OPP, 66 + }; 67 + 68 + #define AM62A7_SUPPORT_N_MPU_OPP BIT(0) 69 + #define AM62A7_SUPPORT_R_MPU_OPP BIT(1) 70 + #define AM62A7_SUPPORT_V_MPU_OPP BIT(2) 71 + 72 + #define AM62P5_EFUSE_O_MPU_OPP 15 73 + #define AM62P5_EFUSE_S_MPU_OPP 19 74 + #define AM62P5_EFUSE_U_MPU_OPP 21 75 + 76 + #define AM62P5_SUPPORT_O_MPU_OPP BIT(0) 77 + #define AM62P5_SUPPORT_U_MPU_OPP BIT(2) 78 + 50 79 #define VERSION_COUNT 2 51 80 52 81 struct ti_cpufreq_data; ··· 139 110 { 140 111 /* OPP enable bit ("Speed Binned") */ 141 112 return BIT(efuse); 113 + } 114 + 115 + static unsigned long am62p5_efuse_xlate(struct ti_cpufreq_data *opp_data, 116 + unsigned long efuse) 117 + { 118 + unsigned long calculated_efuse = AM62P5_SUPPORT_O_MPU_OPP; 119 + 120 + switch (efuse) { 121 + case AM62P5_EFUSE_U_MPU_OPP: 122 + case AM62P5_EFUSE_S_MPU_OPP: 123 + calculated_efuse |= AM62P5_SUPPORT_U_MPU_OPP; 124 + fallthrough; 125 + case AM62P5_EFUSE_O_MPU_OPP: 126 + calculated_efuse |= AM62P5_SUPPORT_O_MPU_OPP; 127 + } 128 + 129 + return calculated_efuse; 130 + } 131 + 132 + static unsigned long am62a7_efuse_xlate(struct ti_cpufreq_data *opp_data, 133 + unsigned long efuse) 134 + { 135 + unsigned long calculated_efuse = AM62A7_SUPPORT_N_MPU_OPP; 136 + 137 + switch (efuse) { 138 + case AM62A7_EFUSE_V_MPU_OPP: 139 + case AM62A7_EFUSE_U_MPU_OPP: 140 + case AM62A7_EFUSE_T_MPU_OPP: 141 + case AM62A7_EFUSE_S_MPU_OPP: 142 + calculated_efuse |= AM62A7_SUPPORT_V_MPU_OPP; 143 + fallthrough; 144 + case AM62A7_EFUSE_R_MPU_OPP: 145 + case AM62A7_EFUSE_Q_MPU_OPP: 146 + case AM62A7_EFUSE_P_MPU_OPP: 147 + case AM62A7_EFUSE_O_MPU_OPP: 148 + calculated_efuse |= AM62A7_SUPPORT_R_MPU_OPP; 149 + fallthrough; 150 + case AM62A7_EFUSE_N_MPU_OPP: 151 + case AM62A7_EFUSE_M_MPU_OPP: 152 + calculated_efuse |= AM62A7_SUPPORT_N_MPU_OPP; 153 + } 154 + 155 + return calculated_efuse; 142 156 } 143 157 144 158 static unsigned long am625_efuse_xlate(struct ti_cpufreq_data *opp_data, ··· 306 234 .multi_regulator = false, 307 235 }; 308 236 237 + static struct ti_cpufreq_soc_data am62a7_soc_data = { 238 + .efuse_xlate = am62a7_efuse_xlate, 239 + .efuse_offset = 0x0, 240 + .efuse_mask = 0x07c0, 241 + .efuse_shift = 0x6, 242 + .rev_offset = 0x0014, 243 + .multi_regulator = false, 244 + }; 245 + 246 + static struct ti_cpufreq_soc_data am62p5_soc_data = { 247 + .efuse_xlate = am62p5_efuse_xlate, 248 + .efuse_offset = 0x0, 249 + .efuse_mask = 0x07c0, 250 + .efuse_shift = 0x6, 251 + .rev_offset = 0x0014, 252 + .multi_regulator = false, 253 + }; 254 + 309 255 /** 310 256 * ti_cpufreq_get_efuse() - Parse and return efuse value present on SoC 311 257 * @opp_data: pointer to ti_cpufreq_data context ··· 427 337 { .compatible = "ti,omap34xx", .data = &omap34xx_soc_data, }, 428 338 { .compatible = "ti,omap36xx", .data = &omap36xx_soc_data, }, 429 339 { .compatible = "ti,am625", .data = &am625_soc_data, }, 430 - { .compatible = "ti,am62a7", .data = &am625_soc_data, }, 431 - { .compatible = "ti,am62p5", .data = &am625_soc_data, }, 340 + { .compatible = "ti,am62a7", .data = &am62a7_soc_data, }, 341 + { .compatible = "ti,am62p5", .data = &am62p5_soc_data, }, 432 342 /* legacy */ 433 343 { .compatible = "ti,omap3430", .data = &omap34xx_soc_data, }, 434 344 { .compatible = "ti,omap3630", .data = &omap36xx_soc_data, }, ··· 507 417 508 418 ret = dev_pm_opp_set_config(opp_data->cpu_dev, &config); 509 419 if (ret < 0) { 510 - dev_err(opp_data->cpu_dev, "Failed to set OPP config\n"); 420 + dev_err_probe(opp_data->cpu_dev, ret, "Failed to set OPP config\n"); 511 421 goto fail_put_node; 512 422 } 513 423
+2 -3
drivers/cpufreq/vexpress-spc-cpufreq.c
··· 447 447 return 0; 448 448 } 449 449 450 - static int ve_spc_cpufreq_exit(struct cpufreq_policy *policy) 450 + static void ve_spc_cpufreq_exit(struct cpufreq_policy *policy) 451 451 { 452 452 struct device *cpu_dev; 453 453 ··· 455 455 if (!cpu_dev) { 456 456 pr_err("%s: failed to get cpu%d device\n", __func__, 457 457 policy->cpu); 458 - return -ENODEV; 458 + return; 459 459 } 460 460 461 461 put_cluster_clk_and_freq_table(cpu_dev, policy->related_cpus); 462 - return 0; 463 462 } 464 463 465 464 static struct cpufreq_driver ve_spc_cpufreq_driver = {
+4 -2
drivers/opp/ti-opp-supply.c
··· 393 393 } 394 394 395 395 ret = dev_pm_opp_set_config_regulators(cpu_dev, ti_opp_config_regulators); 396 - if (ret < 0) 396 + if (ret < 0) { 397 397 _free_optimized_voltages(dev, &opp_data); 398 + return ret; 399 + } 398 400 399 - return ret; 401 + return 0; 400 402 } 401 403 402 404 static struct platform_driver ti_opp_supply_driver = {
+4 -4
include/linux/cpufreq.h
··· 396 396 397 397 int (*online)(struct cpufreq_policy *policy); 398 398 int (*offline)(struct cpufreq_policy *policy); 399 - int (*exit)(struct cpufreq_policy *policy); 399 + void (*exit)(struct cpufreq_policy *policy); 400 400 int (*suspend)(struct cpufreq_policy *policy); 401 401 int (*resume)(struct cpufreq_policy *policy); 402 402 ··· 785 785 786 786 #ifdef CONFIG_CPU_FREQ 787 787 int cpufreq_boost_trigger_state(int state); 788 - int cpufreq_boost_enabled(void); 788 + bool cpufreq_boost_enabled(void); 789 789 int cpufreq_enable_boost_support(void); 790 790 bool policy_has_boost_freq(struct cpufreq_policy *policy); 791 791 ··· 1164 1164 { 1165 1165 return 0; 1166 1166 } 1167 - static inline int cpufreq_boost_enabled(void) 1167 + static inline bool cpufreq_boost_enabled(void) 1168 1168 { 1169 - return 0; 1169 + return false; 1170 1170 } 1171 1171 1172 1172 static inline int cpufreq_enable_boost_support(void)