Skip to content

Commit 4babdbd

Browse files
Tero Kristoij-intel
authored andcommitted
platform/x86/intel-uncore-freq: Get rid of magic values
Get rid of any magic bitmasks from the code. Define proper macros for these, and use the bitfield operations to access them. No functional change intended. Signed-off-by: Tero Kristo <tero.kristo@linux.intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Link: https://lore.kernel.org/r/20240617060708.892981-3-tero.kristo@linux.intel.com Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 36f7004 commit 4babdbd

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
1515
*/
1616

17+
#include <linux/bitfield.h>
1718
#include <linux/cpu.h>
1819
#include <linux/module.h>
1920
#include <linux/slab.h>
@@ -36,6 +37,11 @@ static enum cpuhp_state uncore_hp_state __read_mostly;
3637
#define MSR_UNCORE_PERF_STATUS 0x621
3738
#define UNCORE_FREQ_KHZ_MULTIPLIER 100000
3839

40+
#define UNCORE_MAX_RATIO_MASK GENMASK_ULL(6, 0)
41+
#define UNCORE_MIN_RATIO_MASK GENMASK_ULL(14, 8)
42+
43+
#define UNCORE_CURRENT_RATIO_MASK GENMASK_ULL(6, 0)
44+
3945
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
4046
unsigned int *max)
4147
{
@@ -49,8 +55,8 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
4955
if (ret)
5056
return ret;
5157

52-
*max = (cap & 0x7F) * UNCORE_FREQ_KHZ_MULTIPLIER;
53-
*min = ((cap & GENMASK(14, 8)) >> 8) * UNCORE_FREQ_KHZ_MULTIPLIER;
58+
*max = FIELD_GET(UNCORE_MAX_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
59+
*min = FIELD_GET(UNCORE_MIN_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
5460

5561
return 0;
5662
}
@@ -62,7 +68,7 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
6268
u64 cap;
6369

6470
input /= UNCORE_FREQ_KHZ_MULTIPLIER;
65-
if (!input || input > 0x7F)
71+
if (!input || input > FIELD_MAX(UNCORE_MAX_RATIO_MASK))
6672
return -EINVAL;
6773

6874
if (data->control_cpu < 0)
@@ -73,11 +79,11 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
7379
return ret;
7480

7581
if (min_max) {
76-
cap &= ~0x7F;
77-
cap |= input;
82+
cap &= ~UNCORE_MAX_RATIO_MASK;
83+
cap |= FIELD_PREP(UNCORE_MAX_RATIO_MASK, input);
7884
} else {
79-
cap &= ~GENMASK(14, 8);
80-
cap |= (input << 8);
85+
cap &= ~UNCORE_MIN_RATIO_MASK;
86+
cap |= FIELD_PREP(UNCORE_MIN_RATIO_MASK, input);
8187
}
8288

8389
ret = wrmsrl_on_cpu(data->control_cpu, MSR_UNCORE_RATIO_LIMIT, cap);
@@ -101,7 +107,7 @@ static int uncore_read_freq(struct uncore_data *data, unsigned int *freq)
101107
if (ret)
102108
return ret;
103109

104-
*freq = (ratio & 0x7F) * UNCORE_FREQ_KHZ_MULTIPLIER;
110+
*freq = FIELD_GET(UNCORE_CURRENT_RATIO_MASK, ratio) * UNCORE_FREQ_KHZ_MULTIPLIER;
105111

106112
return 0;
107113
}

0 commit comments

Comments
 (0)