From: Tero Kristo <tero.kristo@linux.intel.com>
To: hdegoede@redhat.com, srinivas.pandruvada@linux.intel.com,
ilpo.jarvinen@linux.intel.com
Cc: linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org
Subject: [PATCH 2/7] platform/x86/intel-uncore-freq: Get rid of magic values
Date: Mon, 17 Jun 2024 09:04:35 +0300 [thread overview]
Message-ID: <20240617060708.892981-3-tero.kristo@linux.intel.com> (raw)
In-Reply-To: <20240617060708.892981-1-tero.kristo@linux.intel.com>
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>
---
.../intel/uncore-frequency/uncore-frequency.c | 22 ++++++++++++-------
1 file changed, 14 insertions(+), 8 deletions(-)
diff --git a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
index b89c0dda9e5d..d3fdae695bbd 100644
--- a/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
+++ b/drivers/platform/x86/intel/uncore-frequency/uncore-frequency.c
@@ -14,6 +14,7 @@
* Author: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
*/
+#include <linux/bitfield.h>
#include <linux/cpu.h>
#include <linux/module.h>
#include <linux/slab.h>
@@ -36,6 +37,11 @@ static enum cpuhp_state uncore_hp_state __read_mostly;
#define MSR_UNCORE_PERF_STATUS 0x621
#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,
unsigned int *max)
{
@@ -49,8 +55,8 @@ static int uncore_read_control_freq(struct uncore_data *data, unsigned int *min,
if (ret)
return ret;
- *max = (cap & 0x7F) * UNCORE_FREQ_KHZ_MULTIPLIER;
- *min = ((cap & GENMASK(14, 8)) >> 8) * UNCORE_FREQ_KHZ_MULTIPLIER;
+ *max = FIELD_GET(UNCORE_MAX_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
+ *min = FIELD_GET(UNCORE_MIN_RATIO_MASK, cap) * UNCORE_FREQ_KHZ_MULTIPLIER;
return 0;
}
@@ -62,7 +68,7 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
u64 cap;
input /= UNCORE_FREQ_KHZ_MULTIPLIER;
- if (!input || input > 0x7F)
+ if (!input || input > FIELD_MAX(UNCORE_MAX_RATIO_MASK))
return -EINVAL;
if (data->control_cpu < 0)
@@ -73,11 +79,11 @@ static int uncore_write_control_freq(struct uncore_data *data, unsigned int inpu
return ret;
if (min_max) {
- cap &= ~0x7F;
- cap |= input;
+ cap &= ~UNCORE_MAX_RATIO_MASK;
+ cap |= FIELD_PREP(UNCORE_MAX_RATIO_MASK, input);
} else {
- cap &= ~GENMASK(14, 8);
- cap |= (input << 8);
+ cap &= ~UNCORE_MIN_RATIO_MASK;
+ cap |= FIELD_PREP(UNCORE_MIN_RATIO_MASK, input);
}
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)
if (ret)
return ret;
- *freq = (ratio & 0x7F) * UNCORE_FREQ_KHZ_MULTIPLIER;
+ *freq = FIELD_GET(UNCORE_CURRENT_RATIO_MASK, ratio) * UNCORE_FREQ_KHZ_MULTIPLIER;
return 0;
}
--
2.43.0
next prev parent reply other threads:[~2024-06-17 6:07 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-17 6:04 [PATCH 0/7] platform/x86/inte-uncore-freq: Cleanups Tero Kristo
2024-06-17 6:04 ` [PATCH 1/7] platform/x86/intel-uncore-freq: Re-arrange bit masks Tero Kristo
2024-06-17 6:04 ` Tero Kristo [this message]
2024-06-17 6:04 ` [PATCH 3/7] platform/x86/intel-uncore-freq: Get rid of magic min_max argument Tero Kristo
2024-06-17 6:04 ` [PATCH 4/7] platform/x86/intel-uncore-freq: Use uncore_index with read_control_freq Tero Kristo
2024-06-17 6:04 ` [PATCH 5/7] platform/x86/intel-uncore-freq: Get rid of uncore_read_freq driver API Tero Kristo
2024-06-17 6:04 ` [PATCH 6/7] platform/x86/intel-uncore-freq: Rename the sysfs helper macro names Tero Kristo
2024-06-17 6:04 ` [PATCH 7/7] platform/x86/intel-uncore-freq: Use generic helpers for current frequency Tero Kristo
2024-06-17 9:06 ` [PATCH 0/7] platform/x86/inte-uncore-freq: Cleanups srinivas pandruvada
2024-06-18 10:00 ` Ilpo Järvinen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240617060708.892981-3-tero.kristo@linux.intel.com \
--to=tero.kristo@linux.intel.com \
--cc=hdegoede@redhat.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=platform-driver-x86@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox