From: Sumit Gupta <sumitg@nvidia.com>
To: <rafael@kernel.org>, <viresh.kumar@linaro.org>, <lenb@kernel.org>,
<robert.moore@intel.com>, <corbet@lwn.net>,
<pierre.gondois@arm.com>, <zhenglifeng1@huawei.com>,
<rdunlap@infradead.org>, <ray.huang@amd.com>,
<gautham.shenoy@amd.com>, <mario.limonciello@amd.com>,
<perry.yuan@amd.com>, <ionela.voinescu@arm.com>,
<zhanjie9@hisilicon.com>, <linux-pm@vger.kernel.org>,
<linux-acpi@vger.kernel.org>, <linux-doc@vger.kernel.org>,
<acpica-devel@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Cc: <linux-tegra@vger.kernel.org>, <treding@nvidia.com>,
<jonathanh@nvidia.com>, <vsethi@nvidia.com>,
<ksitaraman@nvidia.com>, <sanjayc@nvidia.com>,
<nhartman@nvidia.com>, <bbasu@nvidia.com>, <sumitg@nvidia.com>
Subject: [PATCH v5 05/11] ACPI: CPPC: add APIs and sysfs interface for min/max_perf
Date: Tue, 23 Dec 2025 17:43:01 +0530 [thread overview]
Message-ID: <20251223121307.711773-6-sumitg@nvidia.com> (raw)
In-Reply-To: <20251223121307.711773-1-sumitg@nvidia.com>
Add cppc_get/set_min_perf() and cppc_get/set_max_perf() APIs to read and
write the MIN_PERF and MAX_PERF registers.
Also add sysfs interfaces (min_perf, max_perf) in cppc_cpufreq driver
to expose these controls to userspace. The sysfs values are in frequency
(kHz) for consistency with other cpufreq sysfs files.
A mutex is used to serialize sysfs store operations to ensure hardware
register writes and perf_ctrls updates are atomic.
Signed-off-by: Sumit Gupta <sumitg@nvidia.com>
---
drivers/acpi/cppc_acpi.c | 44 +++++++++
drivers/cpufreq/cppc_cpufreq.c | 160 +++++++++++++++++++++++++++++++++
include/acpi/cppc_acpi.h | 20 +++++
3 files changed, 224 insertions(+)
diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
index 403ee988a8c6..9f28c20d902d 100644
--- a/drivers/acpi/cppc_acpi.c
+++ b/drivers/acpi/cppc_acpi.c
@@ -1742,6 +1742,50 @@ int cppc_set_auto_sel(int cpu, bool enable)
}
EXPORT_SYMBOL_GPL(cppc_set_auto_sel);
+/**
+ * cppc_get_min_perf - Read minimum performance register.
+ * @cpu: CPU from which to read register.
+ * @min_perf: Return address.
+ */
+int cppc_get_min_perf(int cpu, u64 *min_perf)
+{
+ return cppc_get_reg_val(cpu, MIN_PERF, min_perf);
+}
+EXPORT_SYMBOL_GPL(cppc_get_min_perf);
+
+/**
+ * cppc_set_min_perf - Write minimum performance register.
+ * @cpu: CPU to which to write register.
+ * @min_perf: the desired minimum performance value to be updated.
+ */
+int cppc_set_min_perf(int cpu, u32 min_perf)
+{
+ return cppc_set_reg_val(cpu, MIN_PERF, min_perf);
+}
+EXPORT_SYMBOL_GPL(cppc_set_min_perf);
+
+/**
+ * cppc_get_max_perf - Read maximum performance register.
+ * @cpu: CPU from which to read register.
+ * @max_perf: Return address.
+ */
+int cppc_get_max_perf(int cpu, u64 *max_perf)
+{
+ return cppc_get_reg_val(cpu, MAX_PERF, max_perf);
+}
+EXPORT_SYMBOL_GPL(cppc_get_max_perf);
+
+/**
+ * cppc_set_max_perf - Write maximum performance register.
+ * @cpu: CPU to which to write register.
+ * @max_perf: the desired maximum performance value to be updated.
+ */
+int cppc_set_max_perf(int cpu, u32 max_perf)
+{
+ return cppc_set_reg_val(cpu, MAX_PERF, max_perf);
+}
+EXPORT_SYMBOL_GPL(cppc_set_max_perf);
+
/**
* cppc_set_enable - Set to enable CPPC on the processor by writing the
* Continuous Performance Control package EnableRegister field.
diff --git a/drivers/cpufreq/cppc_cpufreq.c b/drivers/cpufreq/cppc_cpufreq.c
index a87e7bb2e2f1..1e282dfabc76 100644
--- a/drivers/cpufreq/cppc_cpufreq.c
+++ b/drivers/cpufreq/cppc_cpufreq.c
@@ -28,6 +28,8 @@
static struct cpufreq_driver cppc_cpufreq_driver;
+static DEFINE_MUTEX(cppc_cpufreq_update_autosel_config_lock);
+
#ifdef CONFIG_ACPI_CPPC_CPUFREQ_FIE
static enum {
FIE_UNSET = -1,
@@ -538,6 +540,46 @@ static void populate_efficiency_class(void)
}
#endif
+/**
+ * cppc_cpufreq_set_mperf_limit - Set min/max performance limit
+ * @policy: cpufreq policy
+ * @val: performance value to set
+ * @is_min: true for min_perf, false for max_perf
+ */
+static int cppc_cpufreq_set_mperf_limit(struct cpufreq_policy *policy, u64 val,
+ bool is_min)
+{
+ struct cppc_cpudata *cpu_data = policy->driver_data;
+ struct cppc_perf_caps *caps = &cpu_data->perf_caps;
+ unsigned int cpu = policy->cpu;
+ u32 perf;
+ int ret;
+
+ perf = clamp(val, caps->lowest_perf, caps->highest_perf);
+
+ ret = is_min ? cppc_set_min_perf(cpu, perf) :
+ cppc_set_max_perf(cpu, perf);
+ if (ret) {
+ if (ret != -EOPNOTSUPP)
+ pr_warn("Failed to set %s_perf (%llu) on CPU%d (%d)\n",
+ is_min ? "min" : "max", (u64)perf, cpu, ret);
+ return ret;
+ }
+
+ if (is_min)
+ cpu_data->perf_ctrls.min_perf = perf;
+ else
+ cpu_data->perf_ctrls.max_perf = perf;
+
+ return 0;
+}
+
+#define cppc_cpufreq_set_min_perf(policy, val) \
+ cppc_cpufreq_set_mperf_limit(policy, val, true)
+
+#define cppc_cpufreq_set_max_perf(policy, val) \
+ cppc_cpufreq_set_mperf_limit(policy, val, false)
+
static struct cppc_cpudata *cppc_cpufreq_get_cpu_data(unsigned int cpu)
{
struct cppc_cpudata *cpu_data;
@@ -896,16 +938,134 @@ store_energy_performance_preference_val(struct cpufreq_policy *policy,
buf, count);
}
+/**
+ * show_min_perf - Show minimum performance as frequency (kHz)
+ * @policy: cpufreq policy
+ * @buf: buffer to write the frequency value to
+ *
+ * Reads the MIN_PERF register and converts the performance value to
+ * frequency (kHz).
+ */
+static ssize_t show_min_perf(struct cpufreq_policy *policy, char *buf)
+{
+ struct cppc_cpudata *cpu_data = policy->driver_data;
+ u64 perf;
+ int ret;
+
+ ret = cppc_get_min_perf(policy->cpu, &perf);
+ if (ret == -EOPNOTSUPP)
+ return sysfs_emit(buf, "<unsupported>\n");
+ if (ret)
+ return ret;
+
+ /* Convert performance to frequency (kHz) for user */
+ return sysfs_emit(buf, "%u\n",
+ cppc_perf_to_khz(&cpu_data->perf_caps, perf));
+}
+
+/**
+ * store_min_perf - Set minimum performance from frequency (kHz)
+ * @policy: cpufreq policy
+ * @buf: buffer containing the frequency value
+ * @count: size of @buf
+ *
+ * Converts the user-provided frequency (kHz) to a performance value
+ * and writes it to the MIN_PERF register.
+ */
+static ssize_t store_min_perf(struct cpufreq_policy *policy, const char *buf,
+ size_t count)
+{
+ struct cppc_cpudata *cpu_data = policy->driver_data;
+ unsigned int freq_khz;
+ u64 perf;
+ int ret;
+
+ ret = kstrtouint(buf, 0, &freq_khz);
+ if (ret)
+ return ret;
+
+ /* Convert frequency (kHz) to performance value */
+ perf = cppc_khz_to_perf(&cpu_data->perf_caps, freq_khz);
+
+ guard(mutex)(&cppc_cpufreq_update_autosel_config_lock);
+ ret = cppc_cpufreq_set_min_perf(policy, perf);
+ if (ret)
+ return ret;
+
+ return count;
+}
+
+/**
+ * show_max_perf - Show maximum performance as frequency (kHz)
+ * @policy: cpufreq policy
+ * @buf: buffer to write the frequency value to
+ *
+ * Reads the MAX_PERF register and converts the performance value to
+ * frequency (kHz).
+ */
+static ssize_t show_max_perf(struct cpufreq_policy *policy, char *buf)
+{
+ struct cppc_cpudata *cpu_data = policy->driver_data;
+ u64 perf;
+ int ret;
+
+ ret = cppc_get_max_perf(policy->cpu, &perf);
+ if (ret == -EOPNOTSUPP)
+ return sysfs_emit(buf, "<unsupported>\n");
+ if (ret)
+ return ret;
+
+ /* Convert performance to frequency (kHz) for user */
+ return sysfs_emit(buf, "%u\n",
+ cppc_perf_to_khz(&cpu_data->perf_caps, perf));
+}
+
+/**
+ * store_max_perf - Set maximum performance from frequency (kHz)
+ * @policy: cpufreq policy
+ * @buf: buffer containing the frequency value
+ * @count: size of @buf
+ *
+ * Converts the user-provided frequency (kHz) to a performance value
+ * and writes it to the MAX_PERF register.
+ */
+static ssize_t store_max_perf(struct cpufreq_policy *policy, const char *buf,
+ size_t count)
+{
+ struct cppc_cpudata *cpu_data = policy->driver_data;
+ unsigned int freq_khz;
+ u64 perf;
+ int ret;
+
+ ret = kstrtouint(buf, 0, &freq_khz);
+ if (ret)
+ return ret;
+
+ /* Convert frequency (kHz) to performance value */
+ perf = cppc_khz_to_perf(&cpu_data->perf_caps, freq_khz);
+
+ guard(mutex)(&cppc_cpufreq_update_autosel_config_lock);
+ ret = cppc_cpufreq_set_max_perf(policy, perf);
+ if (ret)
+ return ret;
+
+ return count;
+}
+
cpufreq_freq_attr_ro(freqdomain_cpus);
cpufreq_freq_attr_rw(auto_select);
cpufreq_freq_attr_rw(auto_act_window);
cpufreq_freq_attr_rw(energy_performance_preference_val);
+cpufreq_freq_attr_rw(min_perf);
+cpufreq_freq_attr_rw(max_perf);
static struct freq_attr *cppc_cpufreq_attr[] = {
&freqdomain_cpus,
&auto_select,
&auto_act_window,
&energy_performance_preference_val,
+ &min_perf,
+ &max_perf,
NULL,
};
diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
index 2860a0252313..a49b50bddaf9 100644
--- a/include/acpi/cppc_acpi.h
+++ b/include/acpi/cppc_acpi.h
@@ -173,6 +173,10 @@ extern int cppc_get_auto_act_window(int cpu, u64 *auto_act_window);
extern int cppc_set_auto_act_window(int cpu, u64 auto_act_window);
extern int cppc_get_auto_sel(int cpu, bool *enable);
extern int cppc_set_auto_sel(int cpu, bool enable);
+extern int cppc_get_min_perf(int cpu, u64 *min_perf);
+extern int cppc_set_min_perf(int cpu, u32 min_perf);
+extern int cppc_get_max_perf(int cpu, u64 *max_perf);
+extern int cppc_set_max_perf(int cpu, u32 max_perf);
extern int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
extern int amd_get_boost_ratio_numerator(unsigned int cpu, u64 *numerator);
extern int amd_detect_prefcore(bool *detected);
@@ -265,6 +269,22 @@ static inline int cppc_set_auto_sel(int cpu, bool enable)
{
return -EOPNOTSUPP;
}
+static inline int cppc_get_min_perf(int cpu, u64 *min_perf)
+{
+ return -EOPNOTSUPP;
+}
+static inline int cppc_set_min_perf(int cpu, u32 min_perf)
+{
+ return -EOPNOTSUPP;
+}
+static inline int cppc_get_max_perf(int cpu, u64 *max_perf)
+{
+ return -EOPNOTSUPP;
+}
+static inline int cppc_set_max_perf(int cpu, u32 max_perf)
+{
+ return -EOPNOTSUPP;
+}
static inline int amd_get_highest_perf(unsigned int cpu, u32 *highest_perf)
{
return -ENODEV;
--
2.34.1
next prev parent reply other threads:[~2025-12-23 12:14 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-23 12:12 [PATCH v5 00/11] Enhanced autonomous selection and improvements Sumit Gupta
2025-12-23 12:12 ` [PATCH v5 01/11] cpufreq: CPPC: Add generic helpers for sysfs show/store Sumit Gupta
2025-12-25 3:41 ` zhenglifeng (A)
2026-01-08 13:31 ` Sumit Gupta
2025-12-23 12:12 ` [PATCH v5 02/11] ACPI: CPPC: Clean up cppc_perf_caps and cppc_perf_ctrls structs Sumit Gupta
2026-01-08 13:43 ` Pierre Gondois
2025-12-23 12:12 ` [PATCH v5 03/11] ACPI: CPPC: Add cppc_get_perf() API to read performance controls Sumit Gupta
2025-12-25 8:21 ` zhenglifeng (A)
2026-01-08 13:36 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 04/11] ACPI: CPPC: Extend cppc_set_epp_perf() to support auto_sel and epp Sumit Gupta
2025-12-25 3:56 ` zhenglifeng (A)
2026-01-08 13:39 ` Sumit Gupta
2026-01-16 15:59 ` Pierre Gondois
2025-12-23 12:13 ` Sumit Gupta [this message]
2025-12-25 9:03 ` [PATCH v5 05/11] ACPI: CPPC: add APIs and sysfs interface for min/max_perf zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 06/11] ACPI: CPPC: add APIs and sysfs interface for perf_limited Sumit Gupta
2025-12-25 12:06 ` zhenglifeng (A)
2026-01-08 14:38 ` Sumit Gupta
2026-01-15 8:01 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 07/11] cpufreq: CPPC: Add sysfs for min/max_perf and perf_limited Sumit Gupta
2025-12-24 18:32 ` kernel test robot
2025-12-26 0:20 ` Bagas Sanjaya
2026-01-08 14:30 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 08/11] cpufreq: CPPC: sync policy limits when updating min/max_perf Sumit Gupta
2025-12-25 13:56 ` zhenglifeng (A)
2026-01-08 13:53 ` Sumit Gupta
2026-01-15 8:20 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 09/11] cpufreq: CPPC: sync policy limits when toggling auto_select Sumit Gupta
2025-12-26 2:55 ` zhenglifeng (A)
2026-01-08 14:21 ` Sumit Gupta
2026-01-15 8:57 ` zhenglifeng (A)
2025-12-23 12:13 ` [PATCH v5 10/11] cpufreq: CPPC: make scaling_min/max_freq read-only when auto_sel enabled Sumit Gupta
2025-12-26 3:26 ` zhenglifeng (A)
2026-01-08 14:01 ` Sumit Gupta
2026-01-08 16:46 ` Pierre Gondois
2026-01-09 14:37 ` Sumit Gupta
2026-01-12 11:44 ` Pierre Gondois
2026-01-15 12:32 ` zhenglifeng (A)
2026-01-15 15:22 ` Sumit Gupta
2026-01-16 17:05 ` Pierre Gondois
2026-01-15 15:15 ` Sumit Gupta
2025-12-23 12:13 ` [PATCH v5 11/11] cpufreq: CPPC: add autonomous mode boot parameter support Sumit Gupta
2025-12-26 8:03 ` zhenglifeng (A)
2026-01-08 14:04 ` Sumit Gupta
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=20251223121307.711773-6-sumitg@nvidia.com \
--to=sumitg@nvidia.com \
--cc=acpica-devel@lists.linux.dev \
--cc=bbasu@nvidia.com \
--cc=corbet@lwn.net \
--cc=gautham.shenoy@amd.com \
--cc=ionela.voinescu@arm.com \
--cc=jonathanh@nvidia.com \
--cc=ksitaraman@nvidia.com \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=nhartman@nvidia.com \
--cc=perry.yuan@amd.com \
--cc=pierre.gondois@arm.com \
--cc=rafael@kernel.org \
--cc=ray.huang@amd.com \
--cc=rdunlap@infradead.org \
--cc=robert.moore@intel.com \
--cc=sanjayc@nvidia.com \
--cc=treding@nvidia.com \
--cc=viresh.kumar@linaro.org \
--cc=vsethi@nvidia.com \
--cc=zhanjie9@hisilicon.com \
--cc=zhenglifeng1@huawei.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