@@ -389,7 +389,8 @@ static inline int amd_pstate_cppc_enable(struct cpufreq_policy *policy)
389
389
static int msr_init_perf (struct amd_cpudata * cpudata )
390
390
{
391
391
union perf_cached perf = READ_ONCE (cpudata -> perf );
392
- u64 cap1 , numerator ;
392
+ u64 cap1 , numerator , cppc_req ;
393
+ u8 min_perf ;
393
394
394
395
int ret = rdmsrl_safe_on_cpu (cpudata -> cpu , MSR_AMD_CPPC_CAP1 ,
395
396
& cap1 );
@@ -400,6 +401,22 @@ static int msr_init_perf(struct amd_cpudata *cpudata)
400
401
if (ret )
401
402
return ret ;
402
403
404
+ ret = rdmsrl_on_cpu (cpudata -> cpu , MSR_AMD_CPPC_REQ , & cppc_req );
405
+ if (ret )
406
+ return ret ;
407
+
408
+ WRITE_ONCE (cpudata -> cppc_req_cached , cppc_req );
409
+ min_perf = FIELD_GET (AMD_CPPC_MIN_PERF_MASK , cppc_req );
410
+
411
+ /*
412
+ * Clear out the min_perf part to check if the rest of the MSR is 0, if yes, this is an
413
+ * indication that the min_perf value is the one specified through the BIOS option
414
+ */
415
+ cppc_req &= ~(AMD_CPPC_MIN_PERF_MASK );
416
+
417
+ if (!cppc_req )
418
+ perf .bios_min_perf = min_perf ;
419
+
403
420
perf .highest_perf = numerator ;
404
421
perf .max_limit_perf = numerator ;
405
422
perf .min_limit_perf = FIELD_GET (AMD_CPPC_LOWEST_PERF_MASK , cap1 );
@@ -580,20 +597,26 @@ static int amd_pstate_verify(struct cpufreq_policy_data *policy_data)
580
597
{
581
598
/*
582
599
* Initialize lower frequency limit (i.e.policy->min) with
583
- * lowest_nonlinear_frequency which is the most energy efficient
584
- * frequency. Override the initial value set by cpufreq core and
585
- * amd-pstate qos_requests.
600
+ * lowest_nonlinear_frequency or the min frequency (if) specified in BIOS,
601
+ * Override the initial value set by cpufreq core and amd-pstate qos_requests.
586
602
*/
587
603
if (policy_data -> min == FREQ_QOS_MIN_DEFAULT_VALUE ) {
588
604
struct cpufreq_policy * policy __free (put_cpufreq_policy ) =
589
605
cpufreq_cpu_get (policy_data -> cpu );
590
606
struct amd_cpudata * cpudata ;
607
+ union perf_cached perf ;
591
608
592
609
if (!policy )
593
610
return - EINVAL ;
594
611
595
612
cpudata = policy -> driver_data ;
596
- policy_data -> min = cpudata -> lowest_nonlinear_freq ;
613
+ perf = READ_ONCE (cpudata -> perf );
614
+
615
+ if (perf .bios_min_perf )
616
+ policy_data -> min = perf_to_freq (perf , cpudata -> nominal_freq ,
617
+ perf .bios_min_perf );
618
+ else
619
+ policy_data -> min = cpudata -> lowest_nonlinear_freq ;
597
620
}
598
621
599
622
cpufreq_verify_within_cpu_limits (policy_data );
@@ -1024,6 +1047,10 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
1024
1047
static void amd_pstate_cpu_exit (struct cpufreq_policy * policy )
1025
1048
{
1026
1049
struct amd_cpudata * cpudata = policy -> driver_data ;
1050
+ union perf_cached perf = READ_ONCE (cpudata -> perf );
1051
+
1052
+ /* Reset CPPC_REQ MSR to the BIOS value */
1053
+ amd_pstate_update_perf (policy , perf .bios_min_perf , 0U , 0U , 0U , false);
1027
1054
1028
1055
freq_qos_remove_request (& cpudata -> req [1 ]);
1029
1056
freq_qos_remove_request (& cpudata -> req [0 ]);
@@ -1419,7 +1446,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
1419
1446
struct amd_cpudata * cpudata ;
1420
1447
union perf_cached perf ;
1421
1448
struct device * dev ;
1422
- u64 value ;
1423
1449
int ret ;
1424
1450
1425
1451
/*
@@ -1484,12 +1510,6 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
1484
1510
cpudata -> epp_default = AMD_CPPC_EPP_BALANCE_PERFORMANCE ;
1485
1511
}
1486
1512
1487
- if (cpu_feature_enabled (X86_FEATURE_CPPC )) {
1488
- ret = rdmsrl_on_cpu (cpudata -> cpu , MSR_AMD_CPPC_REQ , & value );
1489
- if (ret )
1490
- return ret ;
1491
- WRITE_ONCE (cpudata -> cppc_req_cached , value );
1492
- }
1493
1513
ret = amd_pstate_set_epp (policy , cpudata -> epp_default );
1494
1514
if (ret )
1495
1515
return ret ;
@@ -1509,6 +1529,11 @@ static void amd_pstate_epp_cpu_exit(struct cpufreq_policy *policy)
1509
1529
struct amd_cpudata * cpudata = policy -> driver_data ;
1510
1530
1511
1531
if (cpudata ) {
1532
+ union perf_cached perf = READ_ONCE (cpudata -> perf );
1533
+
1534
+ /* Reset CPPC_REQ MSR to the BIOS value */
1535
+ amd_pstate_update_perf (policy , perf .bios_min_perf , 0U , 0U , 0U , false);
1536
+
1512
1537
kfree (cpudata );
1513
1538
policy -> driver_data = NULL ;
1514
1539
}
@@ -1566,12 +1591,31 @@ static int amd_pstate_cpu_online(struct cpufreq_policy *policy)
1566
1591
1567
1592
static int amd_pstate_cpu_offline (struct cpufreq_policy * policy )
1568
1593
{
1569
- return 0 ;
1594
+ struct amd_cpudata * cpudata = policy -> driver_data ;
1595
+ union perf_cached perf = READ_ONCE (cpudata -> perf );
1596
+
1597
+ /*
1598
+ * Reset CPPC_REQ MSR to the BIOS value, this will allow us to retain the BIOS specified
1599
+ * min_perf value across kexec reboots. If this CPU is just onlined normally after this, the
1600
+ * limits, epp and desired perf will get reset to the cached values in cpudata struct
1601
+ */
1602
+ return amd_pstate_update_perf (policy , perf .bios_min_perf , 0U , 0U , 0U , false);
1570
1603
}
1571
1604
1572
1605
static int amd_pstate_suspend (struct cpufreq_policy * policy )
1573
1606
{
1574
1607
struct amd_cpudata * cpudata = policy -> driver_data ;
1608
+ union perf_cached perf = READ_ONCE (cpudata -> perf );
1609
+ int ret ;
1610
+
1611
+ /*
1612
+ * Reset CPPC_REQ MSR to the BIOS value, this will allow us to retain the BIOS specified
1613
+ * min_perf value across kexec reboots. If this CPU is just resumed back without kexec,
1614
+ * the limits, epp and desired perf will get reset to the cached values in cpudata struct
1615
+ */
1616
+ ret = amd_pstate_update_perf (policy , perf .bios_min_perf , 0U , 0U , 0U , false);
1617
+ if (ret )
1618
+ return ret ;
1575
1619
1576
1620
/* invalidate to ensure it's rewritten during resume */
1577
1621
cpudata -> cppc_req_cached = 0 ;
@@ -1582,6 +1626,17 @@ static int amd_pstate_suspend(struct cpufreq_policy *policy)
1582
1626
return 0 ;
1583
1627
}
1584
1628
1629
+ static int amd_pstate_resume (struct cpufreq_policy * policy )
1630
+ {
1631
+ struct amd_cpudata * cpudata = policy -> driver_data ;
1632
+ union perf_cached perf = READ_ONCE (cpudata -> perf );
1633
+ int cur_perf = freq_to_perf (perf , cpudata -> nominal_freq , policy -> cur );
1634
+
1635
+ /* Set CPPC_REQ to last sane value until the governor updates it */
1636
+ return amd_pstate_update_perf (policy , perf .min_limit_perf , cur_perf , perf .max_limit_perf ,
1637
+ 0U , false);
1638
+ }
1639
+
1585
1640
static int amd_pstate_epp_resume (struct cpufreq_policy * policy )
1586
1641
{
1587
1642
struct amd_cpudata * cpudata = policy -> driver_data ;
@@ -1610,6 +1665,7 @@ static struct cpufreq_driver amd_pstate_driver = {
1610
1665
.online = amd_pstate_cpu_online ,
1611
1666
.offline = amd_pstate_cpu_offline ,
1612
1667
.suspend = amd_pstate_suspend ,
1668
+ .resume = amd_pstate_resume ,
1613
1669
.set_boost = amd_pstate_set_boost ,
1614
1670
.update_limits = amd_pstate_update_limits ,
1615
1671
.name = "amd-pstate" ,
0 commit comments