@@ -87,6 +87,7 @@ static struct cpufreq_driver amd_pstate_driver;
8787struct amd_cpudata {
8888 int cpu ;
8989
90+ struct freq_qos_request req [2 ];
9091 u64 cppc_req_cached ;
9192
9293 u32 highest_perf ;
@@ -98,6 +99,8 @@ struct amd_cpudata {
9899 u32 min_freq ;
99100 u32 nominal_freq ;
100101 u32 lowest_nonlinear_freq ;
102+
103+ bool boost_supported ;
101104};
102105
103106static inline int pstate_enable (bool enable )
@@ -374,6 +377,45 @@ static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata)
374377 return lowest_nonlinear_freq * 1000 ;
375378}
376379
380+ static int amd_pstate_set_boost (struct cpufreq_policy * policy , int state )
381+ {
382+ struct amd_cpudata * cpudata = policy -> driver_data ;
383+ int ret ;
384+
385+ if (!cpudata -> boost_supported ) {
386+ pr_err ("Boost mode is not supported by this processor or SBIOS\n" );
387+ return - EINVAL ;
388+ }
389+
390+ if (state )
391+ policy -> cpuinfo .max_freq = cpudata -> max_freq ;
392+ else
393+ policy -> cpuinfo .max_freq = cpudata -> nominal_freq ;
394+
395+ policy -> max = policy -> cpuinfo .max_freq ;
396+
397+ ret = freq_qos_update_request (& cpudata -> req [1 ],
398+ policy -> cpuinfo .max_freq );
399+ if (ret < 0 )
400+ return ret ;
401+
402+ return 0 ;
403+ }
404+
405+ static void amd_pstate_boost_init (struct amd_cpudata * cpudata )
406+ {
407+ u32 highest_perf , nominal_perf ;
408+
409+ highest_perf = READ_ONCE (cpudata -> highest_perf );
410+ nominal_perf = READ_ONCE (cpudata -> nominal_perf );
411+
412+ if (highest_perf <= nominal_perf )
413+ return ;
414+
415+ cpudata -> boost_supported = true;
416+ amd_pstate_driver .boost_enabled = true;
417+ }
418+
377419static int amd_pstate_cpu_init (struct cpufreq_policy * policy )
378420{
379421 int min_freq , max_freq , nominal_freq , lowest_nonlinear_freq , ret ;
@@ -392,7 +434,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
392434
393435 ret = amd_pstate_init_perf (cpudata );
394436 if (ret )
395- goto free_cpudata ;
437+ goto free_cpudata1 ;
396438
397439 min_freq = amd_get_min_freq (cpudata );
398440 max_freq = amd_get_max_freq (cpudata );
@@ -403,7 +445,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
403445 dev_err (dev , "min_freq(%d) or max_freq(%d) value is incorrect\n" ,
404446 min_freq , max_freq );
405447 ret = - EINVAL ;
406- goto free_cpudata ;
448+ goto free_cpudata1 ;
407449 }
408450
409451 policy -> cpuinfo .transition_latency = AMD_PSTATE_TRANSITION_LATENCY ;
@@ -421,6 +463,20 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
421463 if (boot_cpu_has (X86_FEATURE_CPPC ))
422464 policy -> fast_switch_possible = true;
423465
466+ ret = freq_qos_add_request (& policy -> constraints , & cpudata -> req [0 ],
467+ FREQ_QOS_MIN , policy -> cpuinfo .min_freq );
468+ if (ret < 0 ) {
469+ dev_err (dev , "Failed to add min-freq constraint (%d)\n" , ret );
470+ goto free_cpudata1 ;
471+ }
472+
473+ ret = freq_qos_add_request (& policy -> constraints , & cpudata -> req [1 ],
474+ FREQ_QOS_MAX , policy -> cpuinfo .max_freq );
475+ if (ret < 0 ) {
476+ dev_err (dev , "Failed to add max-freq constraint (%d)\n" , ret );
477+ goto free_cpudata2 ;
478+ }
479+
424480 /* Initial processor data capability frequencies */
425481 cpudata -> max_freq = max_freq ;
426482 cpudata -> min_freq = min_freq ;
@@ -429,9 +485,13 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
429485
430486 policy -> driver_data = cpudata ;
431487
488+ amd_pstate_boost_init (cpudata );
489+
432490 return 0 ;
433491
434- free_cpudata :
492+ free_cpudata2 :
493+ freq_qos_remove_request (& cpudata -> req [0 ]);
494+ free_cpudata1 :
435495 kfree (cpudata );
436496 return ret ;
437497}
@@ -442,6 +502,8 @@ static int amd_pstate_cpu_exit(struct cpufreq_policy *policy)
442502
443503 cpudata = policy -> driver_data ;
444504
505+ freq_qos_remove_request (& cpudata -> req [1 ]);
506+ freq_qos_remove_request (& cpudata -> req [0 ]);
445507 kfree (cpudata );
446508
447509 return 0 ;
@@ -453,6 +515,7 @@ static struct cpufreq_driver amd_pstate_driver = {
453515 .target = amd_pstate_target ,
454516 .init = amd_pstate_cpu_init ,
455517 .exit = amd_pstate_cpu_exit ,
518+ .set_boost = amd_pstate_set_boost ,
456519 .name = "amd-pstate" ,
457520};
458521
0 commit comments