Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Unverified Commit 4babdbdc authored by Tero Kristo's avatar Tero Kristo Committed by Ilpo Järvinen
Browse files

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: default avatarTero Kristo <tero.kristo@linux.intel.com>
Acked-by: default avatarSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Link: https://lore.kernel.org/r/20240617060708.892981-3-tero.kristo@linux.intel.com


Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent 36f70045
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> * Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
*/ */
#include <linux/bitfield.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
...@@ -36,6 +37,11 @@ static enum cpuhp_state uncore_hp_state __read_mostly; ...@@ -36,6 +37,11 @@ static enum cpuhp_state uncore_hp_state __read_mostly;
#define MSR_UNCORE_PERF_STATUS 0x621 #define MSR_UNCORE_PERF_STATUS 0x621
#define UNCORE_FREQ_KHZ_MULTIPLIER 100000 #define UNCORE_FREQ_KHZ_MULTIPLIER 100000
#define UNCORE_MAX_RATIO_MASK GENMASK_ULL(6, 0)
#define UNCORE_MIN_RATIO_MASK GENMASK_ULL(14, 8)
#define UNCORE_CURRENT_RATIO_MASK GENMASK_ULL(6, 0)
static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min, static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
unsigned int *max) unsigned int *max)
{ {
...@@ -49,8 +55,8 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min, ...@@ -49,8 +55,8 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
if (ret) if (ret)
return ret; return ret;
*max = (cap & 0x7F) * UNCORE_FREQ_KHZ_MULTIPLIER; *max = FIELD_GET(UNCORE_MAX_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
*min = ((cap & GENMASK(14, 8)) >> 8) * UNCORE_FREQ_KHZ_MULTIPLIER; *min = FIELD_GET(UNCORE_MIN_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
return 0; return 0;
} }
...@@ -62,7 +68,7 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu ...@@ -62,7 +68,7 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
u64 cap; u64 cap;
input /= UNCORE_FREQ_KHZ_MULTIPLIER; input /= UNCORE_FREQ_KHZ_MULTIPLIER;
if (!input || input > 0x7F) if (!input || input > FIELD_MAX(UNCORE_MAX_RATIO_MASK))
return -EINVAL; return -EINVAL;
if (data->control_cpu < 0) if (data->control_cpu < 0)
...@@ -73,11 +79,11 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu ...@@ -73,11 +79,11 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
return ret; return ret;
if (min_max) { if (min_max) {
cap &= ~0x7F; cap &= ~UNCORE_MAX_RATIO_MASK;
cap |= input; cap |= FIELD_PREP(UNCORE_MAX_RATIO_MASK, input);
} else { } else {
cap &= ~GENMASK(14, 8); cap &= ~UNCORE_MIN_RATIO_MASK;
cap |= (input << 8); cap |= FIELD_PREP(UNCORE_MIN_RATIO_MASK, input);
} }
ret = wrmsrl_on_cpu(data->control_cpu, MSR_UNCORE_RATIO_LIMIT, cap); 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) ...@@ -101,7 +107,7 @@ static int uncore_read_freq(struct uncore_data *data, unsigned int *freq)
if (ret) if (ret)
return ret; return ret;
*freq = (ratio & 0x7F) * UNCORE_FREQ_KHZ_MULTIPLIER; *freq = FIELD_GET(UNCORE_CURRENT_RATIO_MASK, ratio) * UNCORE_FREQ_KHZ_MULTIPLIER;
return 0; return 0;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment