@@ -87,6 +87,7 @@ static struct cpufreq_driver amd_pstate_driver;
87
87
struct amd_cpudata {
88
88
int cpu ;
89
89
90
+ struct freq_qos_request req [2 ];
90
91
u64 cppc_req_cached ;
91
92
92
93
u32 highest_perf ;
@@ -98,6 +99,8 @@ struct amd_cpudata {
98
99
u32 min_freq ;
99
100
u32 nominal_freq ;
100
101
u32 lowest_nonlinear_freq ;
102
+
103
+ bool boost_supported ;
101
104
};
102
105
103
106
static inline int pstate_enable (bool enable )
@@ -374,6 +377,45 @@ static int amd_get_lowest_nonlinear_freq(struct amd_cpudata *cpudata)
374
377
return lowest_nonlinear_freq * 1000 ;
375
378
}
376
379
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
+
377
419
static int amd_pstate_cpu_init (struct cpufreq_policy * policy )
378
420
{
379
421
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)
392
434
393
435
ret = amd_pstate_init_perf (cpudata );
394
436
if (ret )
395
- goto free_cpudata ;
437
+ goto free_cpudata1 ;
396
438
397
439
min_freq = amd_get_min_freq (cpudata );
398
440
max_freq = amd_get_max_freq (cpudata );
@@ -403,7 +445,7 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
403
445
dev_err (dev , "min_freq(%d) or max_freq(%d) value is incorrect\n" ,
404
446
min_freq , max_freq );
405
447
ret = - EINVAL ;
406
- goto free_cpudata ;
448
+ goto free_cpudata1 ;
407
449
}
408
450
409
451
policy -> cpuinfo .transition_latency = AMD_PSTATE_TRANSITION_LATENCY ;
@@ -421,6 +463,20 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
421
463
if (boot_cpu_has (X86_FEATURE_CPPC ))
422
464
policy -> fast_switch_possible = true;
423
465
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
+
424
480
/* Initial processor data capability frequencies */
425
481
cpudata -> max_freq = max_freq ;
426
482
cpudata -> min_freq = min_freq ;
@@ -429,9 +485,13 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
429
485
430
486
policy -> driver_data = cpudata ;
431
487
488
+ amd_pstate_boost_init (cpudata );
489
+
432
490
return 0 ;
433
491
434
- free_cpudata :
492
+ free_cpudata2 :
493
+ freq_qos_remove_request (& cpudata -> req [0 ]);
494
+ free_cpudata1 :
435
495
kfree (cpudata );
436
496
return ret ;
437
497
}
@@ -442,6 +502,8 @@ static int amd_pstate_cpu_exit(struct cpufreq_policy *policy)
442
502
443
503
cpudata = policy -> driver_data ;
444
504
505
+ freq_qos_remove_request (& cpudata -> req [1 ]);
506
+ freq_qos_remove_request (& cpudata -> req [0 ]);
445
507
kfree (cpudata );
446
508
447
509
return 0 ;
@@ -453,6 +515,7 @@ static struct cpufreq_driver amd_pstate_driver = {
453
515
.target = amd_pstate_target ,
454
516
.init = amd_pstate_cpu_init ,
455
517
.exit = amd_pstate_cpu_exit ,
518
+ .set_boost = amd_pstate_set_boost ,
456
519
.name = "amd-pstate" ,
457
520
};
458
521
0 commit comments