Lines Matching +full:boost +full:- +full:low +full:- +full:freq
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * amd-pstate.c - AMD Processor P-state Frequency Driver
9 * AMD P-State introduces a new CPU performance scaling design for AMD
12 * frequency control range. It is to replace the legacy ACPI P-States control,
13 * allows a flexible, low-latency interface for the Linux kernel to directly
16 * AMD P-State is supported on recent AMD Zen base CPU series include some of
18 * P-State supported system. And there are two types of hardware implementations
19 * for AMD P-State: 1) Full MSR Solution and 2) Shared Memory Solution.
49 #include "amd-pstate.h"
50 #include "amd-pstate-trace.h"
100 *-------------------------------------
147 quirks = dmi->driver_data; in dmi_matched_7k62_bios_bug()
148 pr_info("Overriding nominal and lowest frequencies for %s\n", dmi->ident); in dmi_matched_7k62_bios_bug()
177 return -EINVAL; in get_mode_idx_from_str()
190 epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, in amd_pstate_get_epp()
197 ret = cppc_get_epp_perf(cpudata->cpu, &epp); in amd_pstate_get_epp()
200 return -EIO; in amd_pstate_get_epp()
210 int index = -EINVAL; in amd_pstate_get_energy_pref_index()
240 wrmsrl(MSR_AMD_CPPC_REQ, READ_ONCE(cpudata->cppc_req_cached)); in pstate_update_perf()
242 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, in pstate_update_perf()
243 READ_ONCE(cpudata->cppc_req_cached)); in pstate_update_perf()
262 u64 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_set_epp()
266 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_set_epp()
268 ret = wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_set_epp()
270 cpudata->epp_cached = epp; in amd_pstate_set_epp()
272 amd_pstate_update_perf(cpudata, cpudata->min_limit_perf, 0U, in amd_pstate_set_epp()
273 cpudata->max_limit_perf, false); in amd_pstate_set_epp()
276 ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1); in amd_pstate_set_epp()
281 cpudata->epp_cached = epp; in amd_pstate_set_epp()
290 int epp = -EINVAL; in amd_pstate_set_energy_pref_index()
294 epp = cpudata->epp_default; in amd_pstate_set_energy_pref_index()
296 if (epp == -EINVAL) in amd_pstate_set_energy_pref_index()
299 if (epp > 0 && cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) { in amd_pstate_set_energy_pref_index()
301 return -EBUSY; in amd_pstate_set_energy_pref_index()
373 int ret = rdmsrl_safe_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, in pstate_init_perf()
378 WRITE_ONCE(cpudata->highest_perf, AMD_CPPC_HIGHEST_PERF(cap1)); in pstate_init_perf()
379 WRITE_ONCE(cpudata->max_limit_perf, AMD_CPPC_HIGHEST_PERF(cap1)); in pstate_init_perf()
380 WRITE_ONCE(cpudata->nominal_perf, AMD_CPPC_NOMINAL_PERF(cap1)); in pstate_init_perf()
381 WRITE_ONCE(cpudata->lowest_nonlinear_perf, AMD_CPPC_LOWNONLIN_PERF(cap1)); in pstate_init_perf()
382 WRITE_ONCE(cpudata->lowest_perf, AMD_CPPC_LOWEST_PERF(cap1)); in pstate_init_perf()
383 WRITE_ONCE(cpudata->prefcore_ranking, AMD_CPPC_HIGHEST_PERF(cap1)); in pstate_init_perf()
384 WRITE_ONCE(cpudata->min_limit_perf, AMD_CPPC_LOWEST_PERF(cap1)); in pstate_init_perf()
392 int ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in cppc_init_perf()
396 WRITE_ONCE(cpudata->highest_perf, cppc_perf.highest_perf); in cppc_init_perf()
397 WRITE_ONCE(cpudata->max_limit_perf, cppc_perf.highest_perf); in cppc_init_perf()
398 WRITE_ONCE(cpudata->nominal_perf, cppc_perf.nominal_perf); in cppc_init_perf()
399 WRITE_ONCE(cpudata->lowest_nonlinear_perf, in cppc_init_perf()
401 WRITE_ONCE(cpudata->lowest_perf, cppc_perf.lowest_perf); in cppc_init_perf()
402 WRITE_ONCE(cpudata->prefcore_ranking, cppc_perf.highest_perf); in cppc_init_perf()
403 WRITE_ONCE(cpudata->min_limit_perf, cppc_perf.lowest_perf); in cppc_init_perf()
408 ret = cppc_get_auto_sel_caps(cpudata->cpu, &cppc_perf); in cppc_init_perf()
414 ret = cppc_set_auto_sel(cpudata->cpu, in cppc_init_perf()
440 cppc_set_perf(cpudata->cpu, &perf_ctrls); in cppc_update_perf()
453 if (cpudata->prev.mperf == mperf || cpudata->prev.tsc == tsc) { in amd_pstate_sample()
460 cpudata->cur.aperf = aperf; in amd_pstate_sample()
461 cpudata->cur.mperf = mperf; in amd_pstate_sample()
462 cpudata->cur.tsc = tsc; in amd_pstate_sample()
463 cpudata->cur.aperf -= cpudata->prev.aperf; in amd_pstate_sample()
464 cpudata->cur.mperf -= cpudata->prev.mperf; in amd_pstate_sample()
465 cpudata->cur.tsc -= cpudata->prev.tsc; in amd_pstate_sample()
467 cpudata->prev.aperf = aperf; in amd_pstate_sample()
468 cpudata->prev.mperf = mperf; in amd_pstate_sample()
469 cpudata->prev.tsc = tsc; in amd_pstate_sample()
471 cpudata->freq = div64_u64((cpudata->cur.aperf * cpu_khz), cpudata->cur.mperf); in amd_pstate_sample()
480 struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu); in amd_pstate_update()
481 u64 prev = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_update()
482 u32 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_pstate_update()
485 min_perf = clamp_t(unsigned long, min_perf, cpudata->min_limit_perf, in amd_pstate_update()
486 cpudata->max_limit_perf); in amd_pstate_update()
487 max_perf = clamp_t(unsigned long, max_perf, cpudata->min_limit_perf, in amd_pstate_update()
488 cpudata->max_limit_perf); in amd_pstate_update()
491 max_freq = READ_ONCE(cpudata->max_limit_freq); in amd_pstate_update()
492 policy->cur = div_u64(des_perf * max_freq, max_perf); in amd_pstate_update()
505 /* limit the max perf when core performance boost feature is disabled */ in amd_pstate_update()
506 if (!cpudata->boost_supported) in amd_pstate_update()
513 trace_amd_pstate_perf(min_perf, des_perf, max_perf, cpudata->freq, in amd_pstate_update()
514 cpudata->cur.mperf, cpudata->cur.aperf, cpudata->cur.tsc, in amd_pstate_update()
515 cpudata->cpu, (value != prev), fast_switch); in amd_pstate_update()
521 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_update()
540 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_update_min_max_limit()
542 if (cpudata->boost_supported && !policy->boost_enabled) in amd_pstate_update_min_max_limit()
543 max_perf = READ_ONCE(cpudata->nominal_perf); in amd_pstate_update_min_max_limit()
545 max_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_update_min_max_limit()
547 max_limit_perf = div_u64(policy->max * max_perf, policy->cpuinfo.max_freq); in amd_pstate_update_min_max_limit()
548 min_limit_perf = div_u64(policy->min * max_perf, policy->cpuinfo.max_freq); in amd_pstate_update_min_max_limit()
550 lowest_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_update_min_max_limit()
557 WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf); in amd_pstate_update_min_max_limit()
558 WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf); in amd_pstate_update_min_max_limit()
559 WRITE_ONCE(cpudata->max_limit_freq, policy->max); in amd_pstate_update_min_max_limit()
560 WRITE_ONCE(cpudata->min_limit_freq, policy->min); in amd_pstate_update_min_max_limit()
569 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_update_freq()
572 if (!cpudata->max_freq) in amd_pstate_update_freq()
573 return -ENODEV; in amd_pstate_update_freq()
575 if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq) in amd_pstate_update_freq()
578 cap_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_update_freq()
579 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_update_freq()
582 freqs.old = policy->cur; in amd_pstate_update_freq()
586 cpudata->max_freq); in amd_pstate_update_freq()
588 WARN_ON(fast_switch && !policy->fast_switch_enabled); in amd_pstate_update_freq()
598 max_perf, fast_switch, policy->governor->flags); in amd_pstate_update_freq()
618 return policy->cur; in amd_pstate_fast_switch()
634 cpudata = policy->driver_data; in amd_pstate_adjust_perf()
636 if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq) in amd_pstate_adjust_perf()
640 cap_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_adjust_perf()
641 lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); in amd_pstate_adjust_perf()
647 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_adjust_perf()
661 policy->governor->flags); in amd_pstate_adjust_perf()
667 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_cpu_boost_update()
672 highest_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_cpu_boost_update()
673 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_pstate_cpu_boost_update()
674 nominal_freq = READ_ONCE(cpudata->nominal_freq); in amd_pstate_cpu_boost_update()
675 max_freq = READ_ONCE(cpudata->max_freq); in amd_pstate_cpu_boost_update()
678 u64 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_cpu_boost_update()
682 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_cpu_boost_update()
684 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_cpu_boost_update()
687 ret = cppc_set_perf(cpudata->cpu, &perf_ctrls); in amd_pstate_cpu_boost_update()
691 cpudata->cpu, ret); in amd_pstate_cpu_boost_update()
697 policy->cpuinfo.max_freq = max_freq; in amd_pstate_cpu_boost_update()
698 else if (policy->cpuinfo.max_freq > nominal_freq * 1000) in amd_pstate_cpu_boost_update()
699 policy->cpuinfo.max_freq = nominal_freq * 1000; in amd_pstate_cpu_boost_update()
701 policy->max = policy->cpuinfo.max_freq; in amd_pstate_cpu_boost_update()
704 ret = freq_qos_update_request(&cpudata->req[1], policy->cpuinfo.max_freq); in amd_pstate_cpu_boost_update()
706 pr_debug("Failed to update freq constraint: CPU%d\n", cpudata->cpu); in amd_pstate_cpu_boost_update()
714 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_set_boost()
717 if (!cpudata->boost_supported) { in amd_pstate_set_boost()
718 pr_err("Boost mode is not supported by this processor or SBIOS\n"); in amd_pstate_set_boost()
719 return -EOPNOTSUPP; in amd_pstate_set_boost()
723 WRITE_ONCE(cpudata->boost_state, !ret ? state : false); in amd_pstate_set_boost()
724 policy->boost_enabled = !ret ? state : false; in amd_pstate_set_boost()
734 int ret = -1; in amd_pstate_init_boost_support()
741 pr_debug_once("Boost CPB capabilities not present in the processor\n"); in amd_pstate_init_boost_support()
747 current_pstate_driver->boost_enabled = true; in amd_pstate_init_boost_support()
749 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_K7_HWCR, &boost_val); in amd_pstate_init_boost_support()
751 pr_err_once("failed to read initial CPU boost state!\n"); in amd_pstate_init_boost_support()
752 ret = -EIO; in amd_pstate_init_boost_support()
757 cpudata->boost_supported = true; in amd_pstate_init_boost_support()
762 cpudata->boost_supported = false; in amd_pstate_init_boost_support()
772 * Set amd-pstate preferred core enable can't be done directly from cpufreq callbacks
789 cpudata->hw_prefcore = true; in amd_pstate_init_prefcore()
796 sched_set_itmt_core_prio((int)READ_ONCE(cpudata->highest_perf), cpudata->cpu); in amd_pstate_init_prefcore()
812 cpudata = policy->driver_data; in amd_pstate_update_limits()
822 prev_high = READ_ONCE(cpudata->prefcore_ranking); in amd_pstate_update_limits()
825 WRITE_ONCE(cpudata->prefcore_ranking, cur_high); in amd_pstate_update_limits()
883 * Returns 0 on success, non-zero value on failure.
895 ret = cppc_get_perf_caps(cpudata->cpu, &cppc_perf); in amd_pstate_init_freq()
899 if (quirks && quirks->lowest_freq) in amd_pstate_init_freq()
900 min_freq = quirks->lowest_freq * 1000; in amd_pstate_init_freq()
904 if (quirks && quirks->nominal_freq) in amd_pstate_init_freq()
905 nominal_freq = quirks->nominal_freq ; in amd_pstate_init_freq()
909 nominal_perf = READ_ONCE(cpudata->nominal_perf); in amd_pstate_init_freq()
911 ret = amd_get_boost_ratio_numerator(cpudata->cpu, &numerator); in amd_pstate_init_freq()
917 lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf); in amd_pstate_init_freq()
922 WRITE_ONCE(cpudata->min_freq, min_freq); in amd_pstate_init_freq()
923 WRITE_ONCE(cpudata->lowest_nonlinear_freq, lowest_nonlinear_freq); in amd_pstate_init_freq()
924 WRITE_ONCE(cpudata->nominal_freq, nominal_freq); in amd_pstate_init_freq()
925 WRITE_ONCE(cpudata->max_freq, max_freq); in amd_pstate_init_freq()
936 return -EINVAL; in amd_pstate_init_freq()
942 return -EINVAL; in amd_pstate_init_freq()
958 amd_perf_ctl_reset(policy->cpu); in amd_pstate_cpu_init()
959 dev = get_cpu_device(policy->cpu); in amd_pstate_cpu_init()
961 return -ENODEV; in amd_pstate_cpu_init()
965 return -ENOMEM; in amd_pstate_cpu_init()
967 cpudata->cpu = policy->cpu; in amd_pstate_cpu_init()
983 min_freq = READ_ONCE(cpudata->min_freq); in amd_pstate_cpu_init()
984 max_freq = READ_ONCE(cpudata->max_freq); in amd_pstate_cpu_init()
986 policy->cpuinfo.transition_latency = amd_pstate_get_transition_latency(policy->cpu); in amd_pstate_cpu_init()
987 policy->transition_delay_us = amd_pstate_get_transition_delay_us(policy->cpu); in amd_pstate_cpu_init()
989 policy->min = min_freq; in amd_pstate_cpu_init()
990 policy->max = max_freq; in amd_pstate_cpu_init()
992 policy->cpuinfo.min_freq = min_freq; in amd_pstate_cpu_init()
993 policy->cpuinfo.max_freq = max_freq; in amd_pstate_cpu_init()
995 policy->boost_enabled = READ_ONCE(cpudata->boost_supported); in amd_pstate_cpu_init()
998 policy->cur = policy->cpuinfo.min_freq; in amd_pstate_cpu_init()
1001 policy->fast_switch_possible = true; in amd_pstate_cpu_init()
1003 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0], in amd_pstate_cpu_init()
1004 FREQ_QOS_MIN, policy->cpuinfo.min_freq); in amd_pstate_cpu_init()
1006 dev_err(dev, "Failed to add min-freq constraint (%d)\n", ret); in amd_pstate_cpu_init()
1010 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[1], in amd_pstate_cpu_init()
1011 FREQ_QOS_MAX, policy->cpuinfo.max_freq); in amd_pstate_cpu_init()
1013 dev_err(dev, "Failed to add max-freq constraint (%d)\n", ret); in amd_pstate_cpu_init()
1017 cpudata->max_limit_freq = max_freq; in amd_pstate_cpu_init()
1018 cpudata->min_limit_freq = min_freq; in amd_pstate_cpu_init()
1020 policy->driver_data = cpudata; in amd_pstate_cpu_init()
1022 if (!current_pstate_driver->adjust_perf) in amd_pstate_cpu_init()
1023 current_pstate_driver->adjust_perf = amd_pstate_adjust_perf; in amd_pstate_cpu_init()
1028 freq_qos_remove_request(&cpudata->req[0]); in amd_pstate_cpu_init()
1036 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_cpu_exit()
1038 freq_qos_remove_request(&cpudata->req[1]); in amd_pstate_cpu_exit()
1039 freq_qos_remove_request(&cpudata->req[0]); in amd_pstate_cpu_exit()
1040 policy->fast_switch_possible = false; in amd_pstate_cpu_exit()
1050 pr_err("failed to enable amd-pstate during resume, return %d\n", ret); in amd_pstate_cpu_resume()
1061 pr_err("failed to disable amd-pstate during suspend, return %d\n", ret); in amd_pstate_cpu_suspend()
1070 * If boost is not active but supported, the frequency will be larger than the
1077 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_max_freq()
1079 max_freq = READ_ONCE(cpudata->max_freq); in show_amd_pstate_max_freq()
1089 int freq; in show_amd_pstate_lowest_nonlinear_freq() local
1090 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_lowest_nonlinear_freq()
1092 freq = READ_ONCE(cpudata->lowest_nonlinear_freq); in show_amd_pstate_lowest_nonlinear_freq()
1093 if (freq < 0) in show_amd_pstate_lowest_nonlinear_freq()
1094 return freq; in show_amd_pstate_lowest_nonlinear_freq()
1096 return sysfs_emit(buf, "%u\n", freq); in show_amd_pstate_lowest_nonlinear_freq()
1107 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_highest_perf()
1109 perf = READ_ONCE(cpudata->highest_perf); in show_amd_pstate_highest_perf()
1118 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_prefcore_ranking()
1120 perf = READ_ONCE(cpudata->prefcore_ranking); in show_amd_pstate_prefcore_ranking()
1129 struct amd_cpudata *cpudata = policy->driver_data; in show_amd_pstate_hw_prefcore()
1131 hw_prefcore = READ_ONCE(cpudata->hw_prefcore); in show_amd_pstate_hw_prefcore()
1141 struct amd_cpudata *cpudata = policy->driver_data; in show_energy_performance_available_preferences()
1143 if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) in show_energy_performance_available_preferences()
1158 struct amd_cpudata *cpudata = policy->driver_data; in store_energy_performance_preference()
1164 return -EINVAL; in store_energy_performance_preference()
1166 ret = match_string(energy_perf_strings, -1, str_preference); in store_energy_performance_preference()
1168 return -EINVAL; in store_energy_performance_preference()
1180 struct amd_cpudata *cpudata = policy->driver_data; in show_energy_performance_preference()
1206 return -EINVAL; in amd_pstate_register_driver()
1212 pr_err("failed to enable cppc during amd-pstate driver registration, return %d\n", in amd_pstate_register_driver()
1305 return -EINVAL; in amd_pstate_update_status()
1310 return -EINVAL; in amd_pstate_update_status()
1338 ret = amd_pstate_update_status(buf, p ? p - buf : count); in status_store()
1423 amd_perf_ctl_reset(policy->cpu); in amd_pstate_epp_cpu_init()
1424 dev = get_cpu_device(policy->cpu); in amd_pstate_epp_cpu_init()
1426 return -ENODEV; in amd_pstate_epp_cpu_init()
1430 return -ENOMEM; in amd_pstate_epp_cpu_init()
1432 cpudata->cpu = policy->cpu; in amd_pstate_epp_cpu_init()
1433 cpudata->epp_policy = 0; in amd_pstate_epp_cpu_init()
1449 min_freq = READ_ONCE(cpudata->min_freq); in amd_pstate_epp_cpu_init()
1450 max_freq = READ_ONCE(cpudata->max_freq); in amd_pstate_epp_cpu_init()
1452 policy->cpuinfo.min_freq = min_freq; in amd_pstate_epp_cpu_init()
1453 policy->cpuinfo.max_freq = max_freq; in amd_pstate_epp_cpu_init()
1455 policy->cur = policy->cpuinfo.min_freq; in amd_pstate_epp_cpu_init()
1457 policy->driver_data = cpudata; in amd_pstate_epp_cpu_init()
1459 cpudata->epp_cached = cpudata->epp_default = amd_pstate_get_epp(cpudata, 0); in amd_pstate_epp_cpu_init()
1461 policy->min = policy->cpuinfo.min_freq; in amd_pstate_epp_cpu_init()
1462 policy->max = policy->cpuinfo.max_freq; in amd_pstate_epp_cpu_init()
1464 policy->boost_enabled = READ_ONCE(cpudata->boost_supported); in amd_pstate_epp_cpu_init()
1472 policy->policy = CPUFREQ_POLICY_PERFORMANCE; in amd_pstate_epp_cpu_init()
1474 policy->policy = CPUFREQ_POLICY_POWERSAVE; in amd_pstate_epp_cpu_init()
1477 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value); in amd_pstate_epp_cpu_init()
1480 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_epp_cpu_init()
1482 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_CAP1, &value); in amd_pstate_epp_cpu_init()
1485 WRITE_ONCE(cpudata->cppc_cap1_cached, value); in amd_pstate_epp_cpu_init()
1497 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_cpu_exit()
1501 policy->driver_data = NULL; in amd_pstate_epp_cpu_exit()
1504 pr_debug("CPU %d exiting\n", policy->cpu); in amd_pstate_epp_cpu_exit()
1509 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_update_limit()
1514 if (cpudata->boost_supported && !policy->boost_enabled) in amd_pstate_epp_update_limit()
1515 max_perf = READ_ONCE(cpudata->nominal_perf); in amd_pstate_epp_update_limit()
1517 max_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_epp_update_limit()
1518 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_epp_update_limit()
1519 max_limit_perf = div_u64(policy->max * max_perf, policy->cpuinfo.max_freq); in amd_pstate_epp_update_limit()
1520 min_limit_perf = div_u64(policy->min * max_perf, policy->cpuinfo.max_freq); in amd_pstate_epp_update_limit()
1528 WRITE_ONCE(cpudata->max_limit_perf, max_limit_perf); in amd_pstate_epp_update_limit()
1529 WRITE_ONCE(cpudata->min_limit_perf, min_limit_perf); in amd_pstate_epp_update_limit()
1531 max_perf = clamp_t(unsigned long, max_perf, cpudata->min_limit_perf, in amd_pstate_epp_update_limit()
1532 cpudata->max_limit_perf); in amd_pstate_epp_update_limit()
1533 min_perf = clamp_t(unsigned long, min_perf, cpudata->min_limit_perf, in amd_pstate_epp_update_limit()
1534 cpudata->max_limit_perf); in amd_pstate_epp_update_limit()
1535 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_update_limit()
1537 if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) in amd_pstate_epp_update_limit()
1551 cpudata->epp_policy = cpudata->policy; in amd_pstate_epp_update_limit()
1553 /* Get BIOS pre-defined epp value */ in amd_pstate_epp_update_limit()
1563 if (cpudata->policy == CPUFREQ_POLICY_PERFORMANCE) in amd_pstate_epp_update_limit()
1572 WRITE_ONCE(cpudata->cppc_req_cached, value); in amd_pstate_epp_update_limit()
1578 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_set_policy()
1581 if (!policy->cpuinfo.max_freq) in amd_pstate_epp_set_policy()
1582 return -ENODEV; in amd_pstate_epp_set_policy()
1584 pr_debug("set_policy: cpuinfo.max %u policy->max %u\n", in amd_pstate_epp_set_policy()
1585 policy->cpuinfo.max_freq, policy->max); in amd_pstate_epp_set_policy()
1587 cpudata->policy = policy->policy; in amd_pstate_epp_set_policy()
1594 * policy->cur is never updated with the amd_pstate_epp driver, but it in amd_pstate_epp_set_policy()
1597 policy->cur = policy->min; in amd_pstate_epp_set_policy()
1612 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_reenable()
1613 max_perf = READ_ONCE(cpudata->highest_perf); in amd_pstate_epp_reenable()
1616 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_epp_reenable()
1619 perf_ctrls.energy_perf = AMD_CPPC_ENERGY_PERF_PREF(cpudata->epp_cached); in amd_pstate_epp_reenable()
1620 cppc_set_perf(cpudata->cpu, &perf_ctrls); in amd_pstate_epp_reenable()
1626 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_cpu_online()
1628 pr_debug("AMD CPU Core %d going online\n", cpudata->cpu); in amd_pstate_epp_cpu_online()
1632 cpudata->suspended = false; in amd_pstate_epp_cpu_online()
1640 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_offline()
1645 min_perf = READ_ONCE(cpudata->lowest_perf); in amd_pstate_epp_offline()
1646 value = READ_ONCE(cpudata->cppc_req_cached); in amd_pstate_epp_offline()
1650 cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN; in amd_pstate_epp_offline()
1657 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value); in amd_pstate_epp_offline()
1662 cppc_set_perf(cpudata->cpu, &perf_ctrls); in amd_pstate_epp_offline()
1669 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_cpu_offline()
1671 pr_debug("AMD CPU Core %d going offline\n", cpudata->cpu); in amd_pstate_epp_cpu_offline()
1673 if (cpudata->suspended) in amd_pstate_epp_cpu_offline()
1685 pr_debug("policy_max =%d, policy_min=%d\n", policy->max, policy->min); in amd_pstate_epp_verify_policy()
1691 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_suspend()
1699 cpudata->suspended = true; in amd_pstate_epp_suspend()
1711 struct amd_cpudata *cpudata = policy->driver_data; in amd_pstate_epp_resume()
1713 if (cpudata->suspended) { in amd_pstate_epp_resume()
1721 cpudata->suspended = false; in amd_pstate_epp_resume()
1738 .name = "amd-pstate",
1754 .name = "amd-pstate-epp",
1774 return -EINVAL; in amd_pstate_set_driver()
1793 * that support MSR-based CPPC, the AMD Pstate driver may not in amd_cppc_supported()
1802 * the driver to work using the shared-memory mechanism. in amd_cppc_supported()
1806 switch (c->x86_model) { in amd_cppc_supported()
1814 switch (c->x86_model) { in amd_cppc_supported()
1837 return -ENODEV; in amd_pstate_init()
1841 return -EOPNOTSUPP; in amd_pstate_init()
1846 return -ENODEV; in amd_pstate_init()
1851 return -EEXIST; in amd_pstate_init()
1872 return -ENODEV; in amd_pstate_init()
1881 return -ENODEV; in amd_pstate_init()
1890 return -EINVAL; in amd_pstate_init()
1897 current_pstate_driver->adjust_perf = amd_pstate_adjust_perf; in amd_pstate_init()
1926 ret = sysfs_create_group(&dev_root->kobj, &amd_pstate_global_attr_group); in amd_pstate_init()
1950 return -EINVAL; in amd_pstate_param()
1970 MODULE_DESCRIPTION("AMD Processor P-state Frequency Driver");