Skip to content

Commit b4cc466

Browse files
committed
cpufreq/amd-pstate: Replace all AMD_CPPC_* macros with masks
Bitfield masks are easier to follow and less error prone. Reviewed-by: Dhananjay Ugwekar <[email protected]> Reviewed-by: Gautham R. Shenoy <[email protected]> Signed-off-by: Mario Limonciello <[email protected]>
1 parent c630458 commit b4cc466

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -701,15 +701,17 @@
701701
#define MSR_AMD_CPPC_REQ 0xc00102b3
702702
#define MSR_AMD_CPPC_STATUS 0xc00102b4
703703

704-
#define AMD_CPPC_LOWEST_PERF(x) (((x) >> 0) & 0xff)
705-
#define AMD_CPPC_LOWNONLIN_PERF(x) (((x) >> 8) & 0xff)
706-
#define AMD_CPPC_NOMINAL_PERF(x) (((x) >> 16) & 0xff)
707-
#define AMD_CPPC_HIGHEST_PERF(x) (((x) >> 24) & 0xff)
708-
709-
#define AMD_CPPC_MAX_PERF(x) (((x) & 0xff) << 0)
710-
#define AMD_CPPC_MIN_PERF(x) (((x) & 0xff) << 8)
711-
#define AMD_CPPC_DES_PERF(x) (((x) & 0xff) << 16)
712-
#define AMD_CPPC_ENERGY_PERF_PREF(x) (((x) & 0xff) << 24)
704+
/* Masks for use with MSR_AMD_CPPC_CAP1 */
705+
#define AMD_CPPC_LOWEST_PERF_MASK GENMASK(7, 0)
706+
#define AMD_CPPC_LOWNONLIN_PERF_MASK GENMASK(15, 8)
707+
#define AMD_CPPC_NOMINAL_PERF_MASK GENMASK(23, 16)
708+
#define AMD_CPPC_HIGHEST_PERF_MASK GENMASK(31, 24)
709+
710+
/* Masks for use with MSR_AMD_CPPC_REQ */
711+
#define AMD_CPPC_MAX_PERF_MASK GENMASK(7, 0)
712+
#define AMD_CPPC_MIN_PERF_MASK GENMASK(15, 8)
713+
#define AMD_CPPC_DES_PERF_MASK GENMASK(23, 16)
714+
#define AMD_CPPC_EPP_PERF_MASK GENMASK(31, 24)
713715

714716
/* AMD Performance Counter Global Status and Control MSRs */
715717
#define MSR_AMD64_PERF_CNTR_GLOBAL_STATUS 0xc0000300

arch/x86/kernel/acpi/cppc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Copyright (c) 2016, Intel Corporation.
55
*/
66

7+
#include <linux/bitfield.h>
8+
79
#include <acpi/cppc_acpi.h>
810
#include <asm/msr.h>
911
#include <asm/processor.h>
@@ -149,7 +151,7 @@ int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
149151
if (ret)
150152
goto out;
151153

152-
val = AMD_CPPC_HIGHEST_PERF(val);
154+
val = FIELD_GET(AMD_CPPC_HIGHEST_PERF_MASK, val);
153155
} else {
154156
ret = cppc_get_highest_perf(cpu, &val);
155157
if (ret)

drivers/cpufreq/amd-pstate-ut.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2424

25+
#include <linux/bitfield.h>
2526
#include <linux/kernel.h>
2627
#include <linux/module.h>
2728
#include <linux/moduleparam.h>
@@ -142,10 +143,10 @@ static int amd_pstate_ut_check_perf(u32 index)
142143
return ret;
143144
}
144145

145-
highest_perf = AMD_CPPC_HIGHEST_PERF(cap1);
146-
nominal_perf = AMD_CPPC_NOMINAL_PERF(cap1);
147-
lowest_nonlinear_perf = AMD_CPPC_LOWNONLIN_PERF(cap1);
148-
lowest_perf = AMD_CPPC_LOWEST_PERF(cap1);
146+
highest_perf = FIELD_GET(AMD_CPPC_HIGHEST_PERF_MASK, cap1);
147+
nominal_perf = FIELD_GET(AMD_CPPC_NOMINAL_PERF_MASK, cap1);
148+
lowest_nonlinear_perf = FIELD_GET(AMD_CPPC_LOWNONLIN_PERF_MASK, cap1);
149+
lowest_perf = FIELD_GET(AMD_CPPC_LOWEST_PERF_MASK, cap1);
149150
}
150151

151152
cur_perf = READ_ONCE(cpudata->perf);

drivers/cpufreq/amd-pstate.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,6 @@ static bool cppc_enabled;
8989
static bool amd_pstate_prefcore = true;
9090
static struct quirk_entry *quirks;
9191

92-
#define AMD_CPPC_MAX_PERF_MASK GENMASK(7, 0)
93-
#define AMD_CPPC_MIN_PERF_MASK GENMASK(15, 8)
94-
#define AMD_CPPC_DES_PERF_MASK GENMASK(23, 16)
95-
#define AMD_CPPC_EPP_PERF_MASK GENMASK(31, 24)
96-
9792
/*
9893
* AMD Energy Preference Performance (EPP)
9994
* The EPP is used in the CCLK DPM controller to drive
@@ -439,12 +434,13 @@ static int msr_init_perf(struct amd_cpudata *cpudata)
439434

440435
perf.highest_perf = numerator;
441436
perf.max_limit_perf = numerator;
442-
perf.min_limit_perf = AMD_CPPC_LOWEST_PERF(cap1);
443-
perf.nominal_perf = AMD_CPPC_NOMINAL_PERF(cap1);
444-
perf.lowest_nonlinear_perf = AMD_CPPC_LOWNONLIN_PERF(cap1);
445-
perf.lowest_perf = AMD_CPPC_LOWEST_PERF(cap1);
437+
perf.min_limit_perf = FIELD_GET(AMD_CPPC_LOWEST_PERF_MASK, cap1);
438+
perf.nominal_perf = FIELD_GET(AMD_CPPC_NOMINAL_PERF_MASK, cap1);
439+
perf.lowest_nonlinear_perf = FIELD_GET(AMD_CPPC_LOWNONLIN_PERF_MASK, cap1);
440+
perf.lowest_perf = FIELD_GET(AMD_CPPC_LOWEST_PERF_MASK, cap1);
446441
WRITE_ONCE(cpudata->perf, perf);
447-
WRITE_ONCE(cpudata->prefcore_ranking, AMD_CPPC_HIGHEST_PERF(cap1));
442+
WRITE_ONCE(cpudata->prefcore_ranking, FIELD_GET(AMD_CPPC_HIGHEST_PERF_MASK, cap1));
443+
448444
return 0;
449445
}
450446

0 commit comments

Comments
 (0)