···281281firmware, if EPP feature is disabled, driver will ignore the written value282282This attribute is read-write.283283284284+``boost``285285+The `boost` sysfs attribute provides control over the CPU core286286+performance boost, allowing users to manage the maximum frequency limitation287287+of the CPU. This attribute can be used to enable or disable the boost feature288288+on individual CPUs.289289+290290+When the boost feature is enabled, the CPU can dynamically increase its frequency291291+beyond the base frequency, providing enhanced performance for demanding workloads.292292+On the other hand, disabling the boost feature restricts the CPU to operate at the293293+base frequency, which may be desirable in certain scenarios to prioritize power294294+efficiency or manage temperature.295295+296296+To manipulate the `boost` attribute, users can write a value of `0` to disable the297297+boost or `1` to enable it, for the respective CPU using the sysfs path298298+`/sys/devices/system/cpu/cpuX/cpufreq/boost`, where `X` represents the CPU number.299299+284300Other performance and frequency values can be read back from285301``/sys/devices/system/cpu/cpuX/acpi_cppc/``, see :ref:`cppc_sysfs`.286302···422406``/sys/devices/system/cpu/amd_pstate/`` directory and affect all CPUs.423407424408``status``425425- Operation mode of the driver: "active", "passive" or "disable".409409+ Operation mode of the driver: "active", "passive", "guided" or "disable".426410427411 "active"428412 The driver is functional and in the ``active mode``
+4
Documentation/admin-guide/pm/cpufreq.rst
···267267``related_cpus``268268 List of all (online and offline) CPUs belonging to this policy.269269270270+``scaling_available_frequencies``271271+ List of available frequencies of the CPUs belonging to this policy272272+ (in kHz).273273+270274``scaling_available_governors``271275 List of ``CPUFreq`` scaling governors present in the kernel that can272276 be attached to this policy or (if the |intel_pstate| scaling driver is
···262262 If in doubt, say N.263263endif264264265265+if LOONGARCH266266+config LOONGSON3_CPUFREQ267267+ tristate "Loongson3 CPUFreq Driver"268268+ help269269+ This option adds a CPUFreq driver for Loongson processors which270270+ support software configurable cpu frequency.271271+272272+ Loongson-3 family processors support this feature.273273+274274+ If in doubt, say N.275275+endif276276+265277if SPARC64266278config SPARC_US3_CPUFREQ267279 tristate "UltraSPARC-III CPU Frequency driver"
+1
drivers/cpufreq/Kconfig.x86
···7171config X86_AMD_PSTATE_UT7272 tristate "selftest for AMD Processor P-State driver"7373 depends on X86 && ACPI_PROCESSOR7474+ depends on X86_AMD_PSTATE7475 default n7576 help7677 This kernel module is used for testing. It's safe to say M here.
···51515252#define AMD_PSTATE_TRANSITION_LATENCY 200005353#define AMD_PSTATE_TRANSITION_DELAY 10005454+#define AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY 6005455#define CPPC_HIGHEST_PERF_PERFORMANCE 1965556#define CPPC_HIGHEST_PERF_DEFAULT 1665657···8685 u32 lowest_freq;8786};88878989-/*9090- * TODO: We need more time to fine tune processors with shared memory solution9191- * with community together.9292- *9393- * There are some performance drops on the CPU benchmarks which reports from9494- * Suse. We are co-working with them to fine tune the shared memory solution. So9595- * we disable it by default to go acpi-cpufreq on these processors and add a9696- * module parameter to be able to enable it manually for debugging.9797- */9888static struct cpufreq_driver *current_pstate_driver;9989static struct cpufreq_driver amd_pstate_driver;10090static struct cpufreq_driver amd_pstate_epp_driver;···149157 * broken BIOS lack of nominal_freq and lowest_freq capabilities150158 * definition in ACPI tables151159 */152152- if (boot_cpu_has(X86_FEATURE_ZEN2)) {160160+ if (cpu_feature_enabled(X86_FEATURE_ZEN2)) {153161 quirks = dmi->driver_data;154162 pr_info("Overriding nominal and lowest frequencies for %s\n", dmi->ident);155163 return 1;···191199 u64 epp;192200 int ret;193201194194- if (boot_cpu_has(X86_FEATURE_CPPC)) {202202+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {195203 if (!cppc_req_cached) {196204 epp = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ,197205 &cppc_req_cached);···239247 return index;240248}241249250250+static void pstate_update_perf(struct amd_cpudata *cpudata, u32 min_perf,251251+ u32 des_perf, u32 max_perf, bool fast_switch)252252+{253253+ if (fast_switch)254254+ wrmsrl(MSR_AMD_CPPC_REQ, READ_ONCE(cpudata->cppc_req_cached));255255+ else256256+ wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ,257257+ READ_ONCE(cpudata->cppc_req_cached));258258+}259259+260260+DEFINE_STATIC_CALL(amd_pstate_update_perf, pstate_update_perf);261261+262262+static inline void amd_pstate_update_perf(struct amd_cpudata *cpudata,263263+ u32 min_perf, u32 des_perf,264264+ u32 max_perf, bool fast_switch)265265+{266266+ static_call(amd_pstate_update_perf)(cpudata, min_perf, des_perf,267267+ max_perf, fast_switch);268268+}269269+242270static int amd_pstate_set_epp(struct amd_cpudata *cpudata, u32 epp)243271{244272 int ret;245273 struct cppc_perf_ctrls perf_ctrls;246274247247- if (boot_cpu_has(X86_FEATURE_CPPC)) {275275+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {248276 u64 value = READ_ONCE(cpudata->cppc_req_cached);249277250278 value &= ~GENMASK_ULL(31, 24);···275263 if (!ret)276264 cpudata->epp_cached = epp;277265 } else {266266+ amd_pstate_update_perf(cpudata, cpudata->min_limit_perf, 0U,267267+ cpudata->max_limit_perf, false);268268+278269 perf_ctrls.energy_perf = epp;279270 ret = cppc_set_epp_perf(cpudata->cpu, &perf_ctrls, 1);280271 if (ret) {···296281 int epp = -EINVAL;297282 int ret;298283299299- if (!pref_index) {300300- pr_debug("EPP pref_index is invalid\n");301301- return -EINVAL;302302- }284284+ if (!pref_index)285285+ epp = cpudata->epp_default;303286304287 if (epp == -EINVAL)305288 epp = epp_values[pref_index];···465452 return static_call(amd_pstate_init_perf)(cpudata);466453}467454468468-static void pstate_update_perf(struct amd_cpudata *cpudata, u32 min_perf,469469- u32 des_perf, u32 max_perf, bool fast_switch)470470-{471471- if (fast_switch)472472- wrmsrl(MSR_AMD_CPPC_REQ, READ_ONCE(cpudata->cppc_req_cached));473473- else474474- wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ,475475- READ_ONCE(cpudata->cppc_req_cached));476476-}477477-478455static void cppc_update_perf(struct amd_cpudata *cpudata,479456 u32 min_perf, u32 des_perf,480457 u32 max_perf, bool fast_switch)···476473 perf_ctrls.desired_perf = des_perf;477474478475 cppc_set_perf(cpudata->cpu, &perf_ctrls);479479-}480480-481481-DEFINE_STATIC_CALL(amd_pstate_update_perf, pstate_update_perf);482482-483483-static inline void amd_pstate_update_perf(struct amd_cpudata *cpudata,484484- u32 min_perf, u32 des_perf,485485- u32 max_perf, bool fast_switch)486486-{487487- static_call(amd_pstate_update_perf)(cpudata, min_perf, des_perf,488488- max_perf, fast_switch);489476}490477491478static inline bool amd_pstate_sample(struct amd_cpudata *cpudata)···514521static void amd_pstate_update(struct amd_cpudata *cpudata, u32 min_perf,515522 u32 des_perf, u32 max_perf, bool fast_switch, int gov_flags)516523{524524+ unsigned long max_freq;525525+ struct cpufreq_policy *policy = cpufreq_cpu_get(cpudata->cpu);517526 u64 prev = READ_ONCE(cpudata->cppc_req_cached);527527+ u32 nominal_perf = READ_ONCE(cpudata->nominal_perf);518528 u64 value = prev;519529520530 min_perf = clamp_t(unsigned long, min_perf, cpudata->min_limit_perf,···525529 max_perf = clamp_t(unsigned long, max_perf, cpudata->min_limit_perf,526530 cpudata->max_limit_perf);527531 des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);532532+533533+ max_freq = READ_ONCE(cpudata->max_limit_freq);534534+ policy->cur = div_u64(des_perf * max_freq, max_perf);528535529536 if ((cppc_state == AMD_PSTATE_GUIDED) && (gov_flags & CPUFREQ_GOV_DYNAMIC_SWITCHING)) {530537 min_perf = des_perf;···539540540541 value &= ~AMD_CPPC_DES_PERF(~0L);541542 value |= AMD_CPPC_DES_PERF(des_perf);543543+544544+ /* limit the max perf when core performance boost feature is disabled */545545+ if (!cpudata->boost_supported)546546+ max_perf = min_t(unsigned long, nominal_perf, max_perf);542547543548 value &= ~AMD_CPPC_MAX_PERF(~0L);544549 value |= AMD_CPPC_MAX_PERF(max_perf);···654651 unsigned long capacity)655652{656653 unsigned long max_perf, min_perf, des_perf,657657- cap_perf, lowest_nonlinear_perf, max_freq;654654+ cap_perf, lowest_nonlinear_perf;658655 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);659656 struct amd_cpudata *cpudata = policy->driver_data;660660- unsigned int target_freq;661657662658 if (policy->min != cpudata->min_limit_freq || policy->max != cpudata->max_limit_freq)663659 amd_pstate_update_min_max_limit(policy);···664662665663 cap_perf = READ_ONCE(cpudata->highest_perf);666664 lowest_nonlinear_perf = READ_ONCE(cpudata->lowest_nonlinear_perf);667667- max_freq = READ_ONCE(cpudata->max_freq);668665669666 des_perf = cap_perf;670667 if (target_perf < capacity)···681680 max_perf = min_perf;682681683682 des_perf = clamp_t(unsigned long, des_perf, min_perf, max_perf);684684- target_freq = div_u64(des_perf * max_freq, max_perf);685685- policy->cur = target_freq;686683687684 amd_pstate_update(cpudata, min_perf, des_perf, max_perf, true,688685 policy->governor->flags);689686 cpufreq_cpu_put(policy);687687+}688688+689689+static int amd_pstate_cpu_boost_update(struct cpufreq_policy *policy, bool on)690690+{691691+ struct amd_cpudata *cpudata = policy->driver_data;692692+ struct cppc_perf_ctrls perf_ctrls;693693+ u32 highest_perf, nominal_perf, nominal_freq, max_freq;694694+ int ret;695695+696696+ highest_perf = READ_ONCE(cpudata->highest_perf);697697+ nominal_perf = READ_ONCE(cpudata->nominal_perf);698698+ nominal_freq = READ_ONCE(cpudata->nominal_freq);699699+ max_freq = READ_ONCE(cpudata->max_freq);700700+701701+ if (boot_cpu_has(X86_FEATURE_CPPC)) {702702+ u64 value = READ_ONCE(cpudata->cppc_req_cached);703703+704704+ value &= ~GENMASK_ULL(7, 0);705705+ value |= on ? highest_perf : nominal_perf;706706+ WRITE_ONCE(cpudata->cppc_req_cached, value);707707+708708+ wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);709709+ } else {710710+ perf_ctrls.max_perf = on ? highest_perf : nominal_perf;711711+ ret = cppc_set_perf(cpudata->cpu, &perf_ctrls);712712+ if (ret) {713713+ cpufreq_cpu_release(policy);714714+ pr_debug("Failed to set max perf on CPU:%d. ret:%d\n",715715+ cpudata->cpu, ret);716716+ return ret;717717+ }718718+ }719719+720720+ if (on)721721+ policy->cpuinfo.max_freq = max_freq;722722+ else if (policy->cpuinfo.max_freq > nominal_freq * 1000)723723+ policy->cpuinfo.max_freq = nominal_freq * 1000;724724+725725+ policy->max = policy->cpuinfo.max_freq;726726+727727+ if (cppc_state == AMD_PSTATE_PASSIVE) {728728+ ret = freq_qos_update_request(&cpudata->req[1], policy->cpuinfo.max_freq);729729+ if (ret < 0)730730+ pr_debug("Failed to update freq constraint: CPU%d\n", cpudata->cpu);731731+ }732732+733733+ return ret < 0 ? ret : 0;690734}691735692736static int amd_pstate_set_boost(struct cpufreq_policy *policy, int state)···741695742696 if (!cpudata->boost_supported) {743697 pr_err("Boost mode is not supported by this processor or SBIOS\n");744744- return -EINVAL;698698+ return -EOPNOTSUPP;745699 }700700+ mutex_lock(&amd_pstate_driver_lock);701701+ ret = amd_pstate_cpu_boost_update(policy, state);702702+ WRITE_ONCE(cpudata->boost_state, !ret ? state : false);703703+ policy->boost_enabled = !ret ? state : false;704704+ refresh_frequency_limits(policy);705705+ mutex_unlock(&amd_pstate_driver_lock);746706747747- if (state)748748- policy->cpuinfo.max_freq = cpudata->max_freq;749749- else750750- policy->cpuinfo.max_freq = cpudata->nominal_freq * 1000;751751-752752- policy->max = policy->cpuinfo.max_freq;753753-754754- ret = freq_qos_update_request(&cpudata->req[1],755755- policy->cpuinfo.max_freq);756756- if (ret < 0)757757- return ret;758758-759759- return 0;707707+ return ret;760708}761709762762-static void amd_pstate_boost_init(struct amd_cpudata *cpudata)710710+static int amd_pstate_init_boost_support(struct amd_cpudata *cpudata)763711{764764- u32 highest_perf, nominal_perf;712712+ u64 boost_val;713713+ int ret = -1;765714766766- highest_perf = READ_ONCE(cpudata->highest_perf);767767- nominal_perf = READ_ONCE(cpudata->nominal_perf);715715+ /*716716+ * If platform has no CPB support or disable it, initialize current driver717717+ * boost_enabled state to be false, it is not an error for cpufreq core to handle.718718+ */719719+ if (!cpu_feature_enabled(X86_FEATURE_CPB)) {720720+ pr_debug_once("Boost CPB capabilities not present in the processor\n");721721+ ret = 0;722722+ goto exit_err;723723+ }768724769769- if (highest_perf <= nominal_perf)770770- return;771771-772772- cpudata->boost_supported = true;725725+ /* at least one CPU supports CPB, even if others fail later on to set up */773726 current_pstate_driver->boost_enabled = true;727727+728728+ ret = rdmsrl_on_cpu(cpudata->cpu, MSR_K7_HWCR, &boost_val);729729+ if (ret) {730730+ pr_err_once("failed to read initial CPU boost state!\n");731731+ ret = -EIO;732732+ goto exit_err;733733+ }734734+735735+ if (!(boost_val & MSR_K7_HWCR_CPB_DIS))736736+ cpudata->boost_supported = true;737737+738738+ return 0;739739+740740+exit_err:741741+ cpudata->boost_supported = false;742742+ return ret;774743}775744776745static void amd_perf_ctl_reset(unsigned int cpu)···814753{815754 int ret;816755817817- if (boot_cpu_has(X86_FEATURE_CPPC)) {756756+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {818757 u64 cap1;819758820759 ret = rdmsrl_safe_on_cpu(cpu, MSR_AMD_CPPC_CAP1, &cap1);···910849 u32 transition_delay_ns;911850912851 transition_delay_ns = cppc_get_transition_latency(cpu);913913- if (transition_delay_ns == CPUFREQ_ETERNAL)914914- return AMD_PSTATE_TRANSITION_DELAY;852852+ if (transition_delay_ns == CPUFREQ_ETERNAL) {853853+ if (cpu_feature_enabled(X86_FEATURE_FAST_CPPC))854854+ return AMD_PSTATE_FAST_CPPC_TRANSITION_DELAY;855855+ else856856+ return AMD_PSTATE_TRANSITION_DELAY;857857+ }915858916859 return transition_delay_ns / NSEC_PER_USEC;917860}···986921 WRITE_ONCE(cpudata->nominal_freq, nominal_freq);987922 WRITE_ONCE(cpudata->max_freq, max_freq);988923924924+ /**925925+ * Below values need to be initialized correctly, otherwise driver will fail to load926926+ * max_freq is calculated according to (nominal_freq * highest_perf)/nominal_perf927927+ * lowest_nonlinear_freq is a value between [min_freq, nominal_freq]928928+ * Check _CPC in ACPI table objects if any values are incorrect929929+ */930930+ if (min_freq <= 0 || max_freq <= 0 || nominal_freq <= 0 || min_freq > max_freq) {931931+ pr_err("min_freq(%d) or max_freq(%d) or nominal_freq(%d) value is incorrect\n",932932+ min_freq, max_freq, nominal_freq * 1000);933933+ return -EINVAL;934934+ }935935+936936+ if (lowest_nonlinear_freq <= min_freq || lowest_nonlinear_freq > nominal_freq * 1000) {937937+ pr_err("lowest_nonlinear_freq(%d) value is out of range [min_freq(%d), nominal_freq(%d)]\n",938938+ lowest_nonlinear_freq, min_freq, nominal_freq * 1000);939939+ return -EINVAL;940940+ }941941+989942 return 0;990943}991944992945static int amd_pstate_cpu_init(struct cpufreq_policy *policy)993946{994994- int min_freq, max_freq, nominal_freq, ret;947947+ int min_freq, max_freq, ret;995948 struct device *dev;996949 struct amd_cpudata *cpudata;997950···1038955 if (ret)1039956 goto free_cpudata1;1040957958958+ ret = amd_pstate_init_boost_support(cpudata);959959+ if (ret)960960+ goto free_cpudata1;961961+1041962 min_freq = READ_ONCE(cpudata->min_freq);1042963 max_freq = READ_ONCE(cpudata->max_freq);10431043- nominal_freq = READ_ONCE(cpudata->nominal_freq);10441044-10451045- if (min_freq <= 0 || max_freq <= 0 ||10461046- nominal_freq <= 0 || min_freq > max_freq) {10471047- dev_err(dev,10481048- "min_freq(%d) or max_freq(%d) or nominal_freq (%d) value is incorrect, check _CPC in ACPI tables\n",10491049- min_freq, max_freq, nominal_freq);10501050- ret = -EINVAL;10511051- goto free_cpudata1;10521052- }10539641054965 policy->cpuinfo.transition_latency = amd_pstate_get_transition_latency(policy->cpu);1055966 policy->transition_delay_us = amd_pstate_get_transition_delay_us(policy->cpu);···1054977 policy->cpuinfo.min_freq = min_freq;1055978 policy->cpuinfo.max_freq = max_freq;1056979980980+ policy->boost_enabled = READ_ONCE(cpudata->boost_supported);981981+1057982 /* It will be updated by governor */1058983 policy->cur = policy->cpuinfo.min_freq;105998410601060- if (boot_cpu_has(X86_FEATURE_CPPC))985985+ if (cpu_feature_enabled(X86_FEATURE_CPPC))1061986 policy->fast_switch_possible = true;10629871063988 ret = freq_qos_add_request(&policy->constraints, &cpudata->req[0],···1081100210821003 policy->driver_data = cpudata;1083100410841084- amd_pstate_boost_init(cpudata);10851005 if (!current_pstate_driver->adjust_perf)10861006 current_pstate_driver->adjust_perf = amd_pstate_adjust_perf;10871007···10931015 return ret;10941016}1095101710961096-static int amd_pstate_cpu_exit(struct cpufreq_policy *policy)10181018+static void amd_pstate_cpu_exit(struct cpufreq_policy *policy)10971019{10981020 struct amd_cpudata *cpudata = policy->driver_data;10991021···11011023 freq_qos_remove_request(&cpudata->req[0]);11021024 policy->fast_switch_possible = false;11031025 kfree(cpudata);11041104-11051105- return 0;11061026}1107102711081028static int amd_pstate_cpu_resume(struct cpufreq_policy *policy)···1289121312901214 cppc_state = mode;1291121512921292- if (boot_cpu_has(X86_FEATURE_CPPC) || cppc_state == AMD_PSTATE_ACTIVE)12161216+ if (cpu_feature_enabled(X86_FEATURE_CPPC) || cppc_state == AMD_PSTATE_ACTIVE)12931217 return 0;1294121812951219 for_each_present_cpu(cpu) {···1462138614631387static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)14641388{14651465- int min_freq, max_freq, nominal_freq, ret;13891389+ int min_freq, max_freq, ret;14661390 struct amd_cpudata *cpudata;14671391 struct device *dev;14681392 u64 value;···14931417 if (ret)14941418 goto free_cpudata1;1495141914201420+ ret = amd_pstate_init_boost_support(cpudata);14211421+ if (ret)14221422+ goto free_cpudata1;14231423+14961424 min_freq = READ_ONCE(cpudata->min_freq);14971425 max_freq = READ_ONCE(cpudata->max_freq);14981498- nominal_freq = READ_ONCE(cpudata->nominal_freq);14991499- if (min_freq <= 0 || max_freq <= 0 ||15001500- nominal_freq <= 0 || min_freq > max_freq) {15011501- dev_err(dev,15021502- "min_freq(%d) or max_freq(%d) or nominal_freq(%d) value is incorrect, check _CPC in ACPI tables\n",15031503- min_freq, max_freq, nominal_freq);15041504- ret = -EINVAL;15051505- goto free_cpudata1;15061506- }1507142615081427 policy->cpuinfo.min_freq = min_freq;15091428 policy->cpuinfo.max_freq = max_freq;···1507143615081437 policy->driver_data = cpudata;1509143815101510- cpudata->epp_cached = amd_pstate_get_epp(cpudata, 0);14391439+ cpudata->epp_cached = cpudata->epp_default = amd_pstate_get_epp(cpudata, 0);1511144015121441 policy->min = policy->cpuinfo.min_freq;15131442 policy->max = policy->cpuinfo.max_freq;14431443+14441444+ policy->boost_enabled = READ_ONCE(cpudata->boost_supported);1514144515151446 /*15161447 * Set the policy to provide a valid fallback value in case···15241451 else15251452 policy->policy = CPUFREQ_POLICY_POWERSAVE;1526145315271527- if (boot_cpu_has(X86_FEATURE_CPPC)) {14541454+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {15281455 ret = rdmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, &value);15291456 if (ret)15301457 return ret;···15351462 return ret;15361463 WRITE_ONCE(cpudata->cppc_cap1_cached, value);15371464 }15381538- amd_pstate_boost_init(cpudata);1539146515401466 return 0;15411467···15431471 return ret;15441472}1545147315461546-static int amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy)14741474+static void amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy)15471475{15481476 struct amd_cpudata *cpudata = policy->driver_data;15491477···15531481 }1554148215551483 pr_debug("CPU %d exiting\n", policy->cpu);15561556- return 0;15571484}1558148515591486static void amd_pstate_epp_update_limit(struct cpufreq_policy *policy)···16121541 epp = 0;1613154216141543 /* Set initial EPP value */16151615- if (boot_cpu_has(X86_FEATURE_CPPC)) {15441544+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {16161545 value &= ~GENMASK_ULL(31, 24);16171546 value |= (u64)epp << 24;16181547 }···1635156416361565 amd_pstate_epp_update_limit(policy);1637156615671567+ /*15681568+ * policy->cur is never updated with the amd_pstate_epp driver, but it15691569+ * is used as a stale frequency value. So, keep it within limits.15701570+ */15711571+ policy->cur = policy->min;15721572+16381573 return 0;16391574}16401575···16571580 value = READ_ONCE(cpudata->cppc_req_cached);16581581 max_perf = READ_ONCE(cpudata->highest_perf);1659158216601660- if (boot_cpu_has(X86_FEATURE_CPPC)) {15831583+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {16611584 wrmsrl_on_cpu(cpudata->cpu, MSR_AMD_CPPC_REQ, value);16621585 } else {16631586 perf_ctrls.max_perf = max_perf;···16911614 value = READ_ONCE(cpudata->cppc_req_cached);1692161516931616 mutex_lock(&amd_pstate_limits_lock);16941694- if (boot_cpu_has(X86_FEATURE_CPPC)) {16171617+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {16951618 cpudata->epp_policy = CPUFREQ_POLICY_UNKNOWN;1696161916971620 /* Set max perf same as min perf */···17951718 .suspend = amd_pstate_epp_suspend,17961719 .resume = amd_pstate_epp_resume,17971720 .update_limits = amd_pstate_update_limits,17211721+ .set_boost = amd_pstate_set_boost,17981722 .name = "amd-pstate-epp",17991723 .attr = amd_pstate_epp_attr,18001724};···18191741 return -EINVAL;18201742}1821174317441744+/**17451745+ * CPPC function is not supported for family ID 17H with model_ID ranging from 0x10 to 0x2F.17461746+ * show the debug message that helps to check if the CPU has CPPC support for loading issue.17471747+ */17481748+static bool amd_cppc_supported(void)17491749+{17501750+ struct cpuinfo_x86 *c = &cpu_data(0);17511751+ bool warn = false;17521752+17531753+ if ((boot_cpu_data.x86 == 0x17) && (boot_cpu_data.x86_model < 0x30)) {17541754+ pr_debug_once("CPPC feature is not supported by the processor\n");17551755+ return false;17561756+ }17571757+17581758+ /*17591759+ * If the CPPC feature is disabled in the BIOS for processors that support MSR-based CPPC,17601760+ * the AMD Pstate driver may not function correctly.17611761+ * Check the CPPC flag and display a warning message if the platform supports CPPC.17621762+ * Note: below checking code will not abort the driver registeration process because of17631763+ * the code is added for debugging purposes.17641764+ */17651765+ if (!cpu_feature_enabled(X86_FEATURE_CPPC)) {17661766+ if (cpu_feature_enabled(X86_FEATURE_ZEN1) || cpu_feature_enabled(X86_FEATURE_ZEN2)) {17671767+ if (c->x86_model > 0x60 && c->x86_model < 0xaf)17681768+ warn = true;17691769+ } else if (cpu_feature_enabled(X86_FEATURE_ZEN3) || cpu_feature_enabled(X86_FEATURE_ZEN4)) {17701770+ if ((c->x86_model > 0x10 && c->x86_model < 0x1F) ||17711771+ (c->x86_model > 0x40 && c->x86_model < 0xaf))17721772+ warn = true;17731773+ } else if (cpu_feature_enabled(X86_FEATURE_ZEN5)) {17741774+ warn = true;17751775+ }17761776+ }17771777+17781778+ if (warn)17791779+ pr_warn_once("The CPPC feature is supported but currently disabled by the BIOS.\n"17801780+ "Please enable it if your BIOS has the CPPC option.\n");17811781+ return true;17821782+}17831783+18221784static int __init amd_pstate_init(void)18231785{18241786 struct device *dev_root;···18671749 if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD)18681750 return -ENODEV;1869175117521752+ /* show debug message only if CPPC is not supported */17531753+ if (!amd_cppc_supported())17541754+ return -EOPNOTSUPP;17551755+17561756+ /* show warning message when BIOS broken or ACPI disabled */18701757 if (!acpi_cpc_valid()) {18711758 pr_warn_once("the _CPC object is not present in SBIOS or ACPI disabled\n");18721759 return -ENODEV;···18861763 /* check if this machine need CPPC quirks */18871764 dmi_check_system(amd_pstate_quirks_table);1888176518891889- switch (cppc_state) {18901890- case AMD_PSTATE_UNDEFINED:17661766+ /*17671767+ * determine the driver mode from the command line or kernel config.17681768+ * If no command line input is provided, cppc_state will be AMD_PSTATE_UNDEFINED.17691769+ * command line options will override the kernel config settings.17701770+ */17711771+17721772+ if (cppc_state == AMD_PSTATE_UNDEFINED) {18911773 /* Disable on the following configs by default:18921774 * 1. Undefined platforms18931775 * 2. Server platforms18941894- * 3. Shared memory designs18951776 */18961777 if (amd_pstate_acpi_pm_profile_undefined() ||18971897- amd_pstate_acpi_pm_profile_server() ||18981898- !boot_cpu_has(X86_FEATURE_CPPC)) {17781778+ amd_pstate_acpi_pm_profile_server()) {18991779 pr_info("driver load is disabled, boot with specific mode to enable this\n");19001780 return -ENODEV;19011781 }19021902- ret = amd_pstate_set_driver(CONFIG_X86_AMD_PSTATE_DEFAULT_MODE);19031903- if (ret)19041904- return ret;19051905- break;17821782+ /* get driver mode from kernel config option [1:4] */17831783+ cppc_state = CONFIG_X86_AMD_PSTATE_DEFAULT_MODE;17841784+ }17851785+17861786+ switch (cppc_state) {19061787 case AMD_PSTATE_DISABLE:17881788+ pr_info("driver load is disabled, boot with specific mode to enable this\n");19071789 return -ENODEV;19081790 case AMD_PSTATE_PASSIVE:19091791 case AMD_PSTATE_ACTIVE:19101792 case AMD_PSTATE_GUIDED:17931793+ ret = amd_pstate_set_driver(cppc_state);17941794+ if (ret)17951795+ return ret;19111796 break;19121797 default:19131798 return -EINVAL;19141799 }1915180019161801 /* capability check */19171917- if (boot_cpu_has(X86_FEATURE_CPPC)) {18021802+ if (cpu_feature_enabled(X86_FEATURE_CPPC)) {19181803 pr_debug("AMD CPPC MSR based functionality is supported\n");19191804 if (cppc_state != AMD_PSTATE_ACTIVE)19201805 current_pstate_driver->adjust_perf = amd_pstate_adjust_perf;···19361805 /* enable amd pstate feature */19371806 ret = amd_pstate_enable(true);19381807 if (ret) {19391939- pr_err("failed to enable with return %d\n", ret);18081808+ pr_err("failed to enable driver mode(%d)\n", cppc_state);19401809 return ret;19411810 }1942181119431812 ret = cpufreq_register_driver(current_pstate_driver);19441944- if (ret)18131813+ if (ret) {19451814 pr_err("failed to register with return %d\n", ret);18151815+ goto disable_driver;18161816+ }1946181719471818 dev_root = bus_get_dev_root(&cpu_subsys);19481819 if (dev_root) {···1960182719611828global_attr_free:19621829 cpufreq_unregister_driver(current_pstate_driver);18301830+disable_driver:18311831+ amd_pstate_enable(false);19631832 return ret;19641833}19651834device_initcall(amd_pstate_init);
···236236}237237238238/**239239- * longhaul_set_cpu_frequency()240240- * @mults_index : bitpattern of the new multiplier.239239+ * longhaul_setstate()240240+ * @policy: cpufreq_policy structure containing the current policy.241241+ * @table_index: index of the frequency within the cpufreq_frequency_table.241242 *242243 * Sets a new clock ratio.243244 */
···390390 int ret;391391392392 cpu_dev = get_cpu_device(cpu);393393- if (!cpu_dev) {394394- dev_err(cpu_dev, "failed to get cpu%d device\n", cpu);395395- return -ENODEV;396396- }393393+ if (!cpu_dev)394394+ return dev_err_probe(cpu_dev, -ENODEV, "failed to get cpu%d device\n", cpu);397395 info->cpu_dev = cpu_dev;398396399397 info->ccifreq_bound = false;400398 if (info->soc_data->ccifreq_supported) {401399 info->cci_dev = of_get_cci(info->cpu_dev);402402- if (IS_ERR(info->cci_dev)) {403403- ret = PTR_ERR(info->cci_dev);404404- dev_err(cpu_dev, "cpu%d: failed to get cci device\n", cpu);405405- return -ENODEV;406406- }400400+ if (IS_ERR(info->cci_dev))401401+ return dev_err_probe(cpu_dev, PTR_ERR(info->cci_dev),402402+ "cpu%d: failed to get cci device\n",403403+ cpu);407404 }408405409406 info->cpu_clk = clk_get(cpu_dev, "cpu");410410- if (IS_ERR(info->cpu_clk)) {411411- ret = PTR_ERR(info->cpu_clk);412412- return dev_err_probe(cpu_dev, ret,407407+ if (IS_ERR(info->cpu_clk))408408+ return dev_err_probe(cpu_dev, PTR_ERR(info->cpu_clk),413409 "cpu%d: failed to get cpu clk\n", cpu);414414- }415410416411 info->inter_clk = clk_get(cpu_dev, "intermediate");417412 if (IS_ERR(info->inter_clk)) {···426431427432 ret = regulator_enable(info->proc_reg);428433 if (ret) {429429- dev_warn(cpu_dev, "cpu%d: failed to enable vproc\n", cpu);434434+ dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable vproc\n", cpu);430435 goto out_free_proc_reg;431436 }432437···434439 info->sram_reg = regulator_get_optional(cpu_dev, "sram");435440 if (IS_ERR(info->sram_reg)) {436441 ret = PTR_ERR(info->sram_reg);437437- if (ret == -EPROBE_DEFER)442442+ if (ret == -EPROBE_DEFER) {443443+ dev_err_probe(cpu_dev, ret,444444+ "cpu%d: Failed to get sram regulator\n", cpu);438445 goto out_disable_proc_reg;446446+ }439447440448 info->sram_reg = NULL;441449 } else {442450 ret = regulator_enable(info->sram_reg);443451 if (ret) {444444- dev_warn(cpu_dev, "cpu%d: failed to enable vsram\n", cpu);452452+ dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable vsram\n", cpu);445453 goto out_free_sram_reg;446454 }447455 }···452454 /* Get OPP-sharing information from "operating-points-v2" bindings */453455 ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, &info->cpus);454456 if (ret) {455455- dev_err(cpu_dev,457457+ dev_err_probe(cpu_dev, ret,456458 "cpu%d: failed to get OPP-sharing information\n", cpu);457459 goto out_disable_sram_reg;458460 }459461460462 ret = dev_pm_opp_of_cpumask_add_table(&info->cpus);461463 if (ret) {462462- dev_warn(cpu_dev, "cpu%d: no OPP table\n", cpu);464464+ dev_err_probe(cpu_dev, ret, "cpu%d: no OPP table\n", cpu);463465 goto out_disable_sram_reg;464466 }465467466468 ret = clk_prepare_enable(info->cpu_clk);467467- if (ret)469469+ if (ret) {470470+ dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable cpu clk\n", cpu);468471 goto out_free_opp_table;472472+ }469473470474 ret = clk_prepare_enable(info->inter_clk);471471- if (ret)475475+ if (ret) {476476+ dev_err_probe(cpu_dev, ret, "cpu%d: failed to enable inter clk\n", cpu);472477 goto out_disable_mux_clock;478478+ }473479474480 if (info->soc_data->ccifreq_supported) {475481 info->vproc_on_boot = regulator_get_voltage(info->proc_reg);476482 if (info->vproc_on_boot < 0) {477477- ret = info->vproc_on_boot;478478- dev_err(info->cpu_dev,479479- "invalid Vproc value: %d\n", info->vproc_on_boot);483483+ ret = dev_err_probe(info->cpu_dev, info->vproc_on_boot,484484+ "invalid Vproc value\n");480485 goto out_disable_inter_clock;481486 }482487 }···488487 rate = clk_get_rate(info->inter_clk);489488 opp = dev_pm_opp_find_freq_ceil(cpu_dev, &rate);490489 if (IS_ERR(opp)) {491491- dev_err(cpu_dev, "cpu%d: failed to get intermediate opp\n", cpu);492492- ret = PTR_ERR(opp);490490+ ret = dev_err_probe(cpu_dev, PTR_ERR(opp),491491+ "cpu%d: failed to get intermediate opp\n", cpu);493492 goto out_disable_inter_clock;494493 }495494 info->intermediate_voltage = dev_pm_opp_get_voltage(opp);···502501 info->opp_nb.notifier_call = mtk_cpufreq_opp_notifier;503502 ret = dev_pm_opp_register_notifier(cpu_dev, &info->opp_nb);504503 if (ret) {505505- dev_err(cpu_dev, "cpu%d: failed to register opp notifier\n", cpu);504504+ dev_err_probe(cpu_dev, ret, "cpu%d: failed to register opp notifier\n", cpu);506505 goto out_disable_inter_clock;507506 }508507···600599 return 0;601600}602601603603-static int mtk_cpufreq_exit(struct cpufreq_policy *policy)602602+static void mtk_cpufreq_exit(struct cpufreq_policy *policy)604603{605604 struct mtk_cpu_dvfs_info *info = policy->driver_data;606605607606 dev_pm_opp_free_cpufreq_table(info->cpu_dev, &policy->freq_table);608608-609609- return 0;610607}611608612609static struct cpufreq_driver mtk_cpufreq_driver = {···628629 int cpu, ret;629630630631 data = dev_get_platdata(&pdev->dev);631631- if (!data) {632632- dev_err(&pdev->dev,633633- "failed to get mtk cpufreq platform data\n");634634- return -ENODEV;635635- }632632+ if (!data)633633+ return dev_err_probe(&pdev->dev, -ENODEV,634634+ "failed to get mtk cpufreq platform data\n");636635637636 for_each_possible_cpu(cpu) {638637 info = mtk_cpu_dvfs_info_lookup(cpu);···639642640643 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);641644 if (!info) {642642- ret = -ENOMEM;645645+ ret = dev_err_probe(&pdev->dev, -ENOMEM,646646+ "Failed to allocate dvfs_info\n");643647 goto release_dvfs_info_list;644648 }645649646650 info->soc_data = data;647651 ret = mtk_cpu_dvfs_info_init(info, cpu);648648- if (ret) {649649- dev_err(&pdev->dev,650650- "failed to initialize dvfs info for cpu%d\n",651651- cpu);652652+ if (ret)652653 goto release_dvfs_info_list;653653- }654654655655 list_add(&info->list_head, &dvfs_info_list);656656 }657657658658 ret = cpufreq_register_driver(&mtk_cpufreq_driver);659659 if (ret) {660660- dev_err(&pdev->dev, "failed to register mtk cpufreq driver\n");660660+ dev_err_probe(&pdev->dev, ret, "failed to register mtk cpufreq driver\n");661661 goto release_dvfs_info_list;662662 }663663
···204204 return err;205205}206206207207-static int pas_cpufreq_cpu_exit(struct cpufreq_policy *policy)207207+static void pas_cpufreq_cpu_exit(struct cpufreq_policy *policy)208208{209209 /*210210 * We don't support CPU hotplug. Don't unmap after the system211211 * has already made it to a running state.212212 */213213 if (system_state >= SYSTEM_RUNNING)214214- return 0;214214+ return;215215216216 if (sdcasr_mapbase)217217 iounmap(sdcasr_mapbase);218218 if (sdcpwr_mapbase)219219 iounmap(sdcpwr_mapbase);220220-221221- return 0;222220}223221224222static int pas_cpufreq_target(struct cpufreq_policy *policy,