@@ -85,7 +85,6 @@ static struct cpufreq_driver *current_pstate_driver;
85
85
static struct cpufreq_driver amd_pstate_driver ;
86
86
static struct cpufreq_driver amd_pstate_epp_driver ;
87
87
static int cppc_state = AMD_PSTATE_UNDEFINED ;
88
- static bool cppc_enabled ;
89
88
static bool amd_pstate_prefcore = true;
90
89
static struct quirk_entry * quirks ;
91
90
@@ -371,89 +370,21 @@ static int shmem_set_epp(struct cpufreq_policy *policy, u8 epp)
371
370
return ret ;
372
371
}
373
372
374
- static int amd_pstate_set_energy_pref_index (struct cpufreq_policy * policy ,
375
- int pref_index )
373
+ static inline int msr_cppc_enable (struct cpufreq_policy * policy )
376
374
{
377
- struct amd_cpudata * cpudata = policy -> driver_data ;
378
- u8 epp ;
379
-
380
- if (!pref_index )
381
- epp = cpudata -> epp_default ;
382
- else
383
- epp = epp_values [pref_index ];
384
-
385
- if (epp > 0 && cpudata -> policy == CPUFREQ_POLICY_PERFORMANCE ) {
386
- pr_debug ("EPP cannot be set under performance policy\n" );
387
- return - EBUSY ;
388
- }
389
-
390
- return amd_pstate_set_epp (policy , epp );
391
- }
392
-
393
- static inline int msr_cppc_enable (bool enable )
394
- {
395
- int ret , cpu ;
396
- unsigned long logical_proc_id_mask = 0 ;
397
-
398
- /*
399
- * MSR_AMD_CPPC_ENABLE is write-once, once set it cannot be cleared.
400
- */
401
- if (!enable )
402
- return 0 ;
403
-
404
- if (enable == cppc_enabled )
405
- return 0 ;
406
-
407
- for_each_present_cpu (cpu ) {
408
- unsigned long logical_id = topology_logical_package_id (cpu );
409
-
410
- if (test_bit (logical_id , & logical_proc_id_mask ))
411
- continue ;
412
-
413
- set_bit (logical_id , & logical_proc_id_mask );
414
-
415
- ret = wrmsrl_safe_on_cpu (cpu , MSR_AMD_CPPC_ENABLE ,
416
- enable );
417
- if (ret )
418
- return ret ;
419
- }
420
-
421
- cppc_enabled = enable ;
422
- return 0 ;
375
+ return wrmsrl_safe_on_cpu (policy -> cpu , MSR_AMD_CPPC_ENABLE , 1 );
423
376
}
424
377
425
- static int shmem_cppc_enable (bool enable )
378
+ static int shmem_cppc_enable (struct cpufreq_policy * policy )
426
379
{
427
- int cpu , ret = 0 ;
428
- struct cppc_perf_ctrls perf_ctrls ;
429
-
430
- if (enable == cppc_enabled )
431
- return 0 ;
432
-
433
- for_each_present_cpu (cpu ) {
434
- ret = cppc_set_enable (cpu , enable );
435
- if (ret )
436
- return ret ;
437
-
438
- /* Enable autonomous mode for EPP */
439
- if (cppc_state == AMD_PSTATE_ACTIVE ) {
440
- /* Set desired perf as zero to allow EPP firmware control */
441
- perf_ctrls .desired_perf = 0 ;
442
- ret = cppc_set_perf (cpu , & perf_ctrls );
443
- if (ret )
444
- return ret ;
445
- }
446
- }
447
-
448
- cppc_enabled = enable ;
449
- return ret ;
380
+ return cppc_set_enable (policy -> cpu , 1 );
450
381
}
451
382
452
383
DEFINE_STATIC_CALL (amd_pstate_cppc_enable , msr_cppc_enable );
453
384
454
- static inline int amd_pstate_cppc_enable (bool enable )
385
+ static inline int amd_pstate_cppc_enable (struct cpufreq_policy * policy )
455
386
{
456
- return static_call (amd_pstate_cppc_enable )(enable );
387
+ return static_call (amd_pstate_cppc_enable )(policy );
457
388
}
458
389
459
390
static int msr_init_perf (struct amd_cpudata * cpudata )
@@ -1063,6 +994,10 @@ static int amd_pstate_cpu_init(struct cpufreq_policy *policy)
1063
994
cpudata -> nominal_freq ,
1064
995
perf .highest_perf );
1065
996
997
+ ret = amd_pstate_cppc_enable (policy );
998
+ if (ret )
999
+ goto free_cpudata1 ;
1000
+
1066
1001
policy -> boost_enabled = READ_ONCE (cpudata -> boost_supported );
1067
1002
1068
1003
/* It will be updated by governor */
@@ -1110,28 +1045,6 @@ static void amd_pstate_cpu_exit(struct cpufreq_policy *policy)
1110
1045
kfree (cpudata );
1111
1046
}
1112
1047
1113
- static int amd_pstate_cpu_resume (struct cpufreq_policy * policy )
1114
- {
1115
- int ret ;
1116
-
1117
- ret = amd_pstate_cppc_enable (true);
1118
- if (ret )
1119
- pr_err ("failed to enable amd-pstate during resume, return %d\n" , ret );
1120
-
1121
- return ret ;
1122
- }
1123
-
1124
- static int amd_pstate_cpu_suspend (struct cpufreq_policy * policy )
1125
- {
1126
- int ret ;
1127
-
1128
- ret = amd_pstate_cppc_enable (false);
1129
- if (ret )
1130
- pr_err ("failed to disable amd-pstate during suspend, return %d\n" , ret );
1131
-
1132
- return ret ;
1133
- }
1134
-
1135
1048
/* Sysfs attributes */
1136
1049
1137
1050
/*
@@ -1223,8 +1136,10 @@ static ssize_t show_energy_performance_available_preferences(
1223
1136
static ssize_t store_energy_performance_preference (
1224
1137
struct cpufreq_policy * policy , const char * buf , size_t count )
1225
1138
{
1139
+ struct amd_cpudata * cpudata = policy -> driver_data ;
1226
1140
char str_preference [21 ];
1227
1141
ssize_t ret ;
1142
+ u8 epp ;
1228
1143
1229
1144
ret = sscanf (buf , "%20s" , str_preference );
1230
1145
if (ret != 1 )
@@ -1234,7 +1149,17 @@ static ssize_t store_energy_performance_preference(
1234
1149
if (ret < 0 )
1235
1150
return - EINVAL ;
1236
1151
1237
- ret = amd_pstate_set_energy_pref_index (policy , ret );
1152
+ if (!ret )
1153
+ epp = cpudata -> epp_default ;
1154
+ else
1155
+ epp = epp_values [ret ];
1156
+
1157
+ if (epp > 0 && policy -> policy == CPUFREQ_POLICY_PERFORMANCE ) {
1158
+ pr_debug ("EPP cannot be set under performance policy\n" );
1159
+ return - EBUSY ;
1160
+ }
1161
+
1162
+ ret = amd_pstate_set_epp (policy , epp );
1238
1163
1239
1164
return ret ? ret : count ;
1240
1165
}
@@ -1267,7 +1192,6 @@ static ssize_t show_energy_performance_preference(
1267
1192
1268
1193
static void amd_pstate_driver_cleanup (void )
1269
1194
{
1270
- amd_pstate_cppc_enable (false);
1271
1195
cppc_state = AMD_PSTATE_DISABLE ;
1272
1196
current_pstate_driver = NULL ;
1273
1197
}
@@ -1301,14 +1225,6 @@ static int amd_pstate_register_driver(int mode)
1301
1225
1302
1226
cppc_state = mode ;
1303
1227
1304
- ret = amd_pstate_cppc_enable (true);
1305
- if (ret ) {
1306
- pr_err ("failed to enable cppc during amd-pstate driver registration, return %d\n" ,
1307
- ret );
1308
- amd_pstate_driver_cleanup ();
1309
- return ret ;
1310
- }
1311
-
1312
1228
/* at least one CPU supports CPB */
1313
1229
current_pstate_driver -> boost_enabled = cpu_feature_enabled (X86_FEATURE_CPB );
1314
1230
@@ -1548,11 +1464,15 @@ static int amd_pstate_epp_cpu_init(struct cpufreq_policy *policy)
1548
1464
policy -> cpuinfo .max_freq = policy -> max = perf_to_freq (perf ,
1549
1465
cpudata -> nominal_freq ,
1550
1466
perf .highest_perf );
1467
+ policy -> driver_data = cpudata ;
1468
+
1469
+ ret = amd_pstate_cppc_enable (policy );
1470
+ if (ret )
1471
+ goto free_cpudata1 ;
1551
1472
1552
1473
/* It will be updated by governor */
1553
1474
policy -> cur = policy -> cpuinfo .min_freq ;
1554
1475
1555
- policy -> driver_data = cpudata ;
1556
1476
1557
1477
policy -> boost_enabled = READ_ONCE (cpudata -> boost_supported );
1558
1478
@@ -1644,31 +1564,11 @@ static int amd_pstate_epp_set_policy(struct cpufreq_policy *policy)
1644
1564
return 0 ;
1645
1565
}
1646
1566
1647
- static int amd_pstate_epp_reenable (struct cpufreq_policy * policy )
1648
- {
1649
- int ret ;
1650
-
1651
- ret = amd_pstate_cppc_enable (true);
1652
- if (ret )
1653
- pr_err ("failed to enable amd pstate during resume, return %d\n" , ret );
1654
-
1655
-
1656
- return amd_pstate_epp_update_limit (policy );
1657
- }
1658
-
1659
1567
static int amd_pstate_epp_cpu_online (struct cpufreq_policy * policy )
1660
1568
{
1661
- struct amd_cpudata * cpudata = policy -> driver_data ;
1662
- int ret ;
1663
-
1664
- pr_debug ("AMD CPU Core %d going online\n" , cpudata -> cpu );
1569
+ pr_debug ("AMD CPU Core %d going online\n" , policy -> cpu );
1665
1570
1666
- ret = amd_pstate_epp_reenable (policy );
1667
- if (ret )
1668
- return ret ;
1669
- cpudata -> suspended = false;
1670
-
1671
- return 0 ;
1571
+ return amd_pstate_cppc_enable (policy );
1672
1572
}
1673
1573
1674
1574
static int amd_pstate_epp_cpu_offline (struct cpufreq_policy * policy )
@@ -1686,23 +1586,13 @@ static int amd_pstate_epp_cpu_offline(struct cpufreq_policy *policy)
1686
1586
static int amd_pstate_epp_suspend (struct cpufreq_policy * policy )
1687
1587
{
1688
1588
struct amd_cpudata * cpudata = policy -> driver_data ;
1689
- int ret ;
1690
-
1691
- /* avoid suspending when EPP is not enabled */
1692
- if (cppc_state != AMD_PSTATE_ACTIVE )
1693
- return 0 ;
1694
1589
1695
1590
/* invalidate to ensure it's rewritten during resume */
1696
1591
cpudata -> cppc_req_cached = 0 ;
1697
1592
1698
1593
/* set this flag to avoid setting core offline*/
1699
1594
cpudata -> suspended = true;
1700
1595
1701
- /* disable CPPC in lowlevel firmware */
1702
- ret = amd_pstate_cppc_enable (false);
1703
- if (ret )
1704
- pr_err ("failed to suspend, return %d\n" , ret );
1705
-
1706
1596
return 0 ;
1707
1597
}
1708
1598
@@ -1711,8 +1601,12 @@ static int amd_pstate_epp_resume(struct cpufreq_policy *policy)
1711
1601
struct amd_cpudata * cpudata = policy -> driver_data ;
1712
1602
1713
1603
if (cpudata -> suspended ) {
1604
+ int ret ;
1605
+
1714
1606
/* enable amd pstate from suspend state*/
1715
- amd_pstate_epp_reenable (policy );
1607
+ ret = amd_pstate_epp_update_limit (policy );
1608
+ if (ret )
1609
+ return ret ;
1716
1610
1717
1611
cpudata -> suspended = false;
1718
1612
}
@@ -1727,8 +1621,6 @@ static struct cpufreq_driver amd_pstate_driver = {
1727
1621
.fast_switch = amd_pstate_fast_switch ,
1728
1622
.init = amd_pstate_cpu_init ,
1729
1623
.exit = amd_pstate_cpu_exit ,
1730
- .suspend = amd_pstate_cpu_suspend ,
1731
- .resume = amd_pstate_cpu_resume ,
1732
1624
.set_boost = amd_pstate_set_boost ,
1733
1625
.update_limits = amd_pstate_update_limits ,
1734
1626
.name = "amd-pstate" ,
@@ -1895,7 +1787,6 @@ static int __init amd_pstate_init(void)
1895
1787
1896
1788
global_attr_free :
1897
1789
cpufreq_unregister_driver (current_pstate_driver );
1898
- amd_pstate_cppc_enable (false);
1899
1790
return ret ;
1900
1791
}
1901
1792
device_initcall (amd_pstate_init );
0 commit comments