mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mario Limonciello <mario.limonciello@amd.com>
To: Lifeng Zheng <zhenglifeng1@huawei.com>,
	rafael@kernel.org, lenb@kernel.org, robert.moore@intel.com,
	viresh.kumar@linaro.org, gautham.shenoy@amd.com,
	ray.huang@amd.com, perry.yuan@amd.com, pierre.gondois@arm.com
Cc: acpica-devel@lists.linux.dev, linux-acpi@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
	linuxarm@huawei.com, jonathan.cameron@huawei.com,
	zhanjie9@hisilicon.com, lihuisong@huawei.com,
	cenxinghai@h-partners.com, hepeng68@huawei.com
Subject: Re: [PATCH v6 8/8] ACPI: CPPC: Add three functions related to autonomous selection
Date: Wed, 9 Apr 2025 13:59:23 -0500	[thread overview]
Message-ID: <e5dc4906-2b28-4adc-8e8e-ddd5d7cc985c@amd.com> (raw)
In-Reply-To: <20250409065703.1461867-9-zhenglifeng1@huawei.com>

On 4/9/2025 1:57 AM, Lifeng Zheng wrote:
> cppc_set_epp - write energy performance preference register value, based on
> ACPI 6.5, s8.4.6.1.7
> 
> cppc_get_auto_act_window - read autonomous activity window register value,
> based on ACPI 6.5, s8.4.6.1.6
> 
> cppc_set_auto_act_window - write autonomous activity window register value,
> based on ACPI 6.5, s8.4.6.1.6
> 
> Reviewed-by: Pierre Gondois <pierre.gondois@arm.com>
> Signed-off-by: Lifeng Zheng <zhenglifeng1@huawei.com>
> ---
>   drivers/acpi/cppc_acpi.c | 80 ++++++++++++++++++++++++++++++++++++++++
>   include/acpi/cppc_acpi.h | 24 ++++++++++++
>   2 files changed, 104 insertions(+)
> 
> diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c
> index ef2394c074e3..3d5eace44af5 100644
> --- a/drivers/acpi/cppc_acpi.c
> +++ b/drivers/acpi/cppc_acpi.c
> @@ -1608,6 +1608,86 @@ int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable)
>   }
>   EXPORT_SYMBOL_GPL(cppc_set_epp_perf);
>   
> +/**
> + * cppc_set_epp() - Write the EPP register.
> + * @cpu: CPU on which to write register.
> + * @epp_val: Value to write to the EPP register.
> + */
> +int cppc_set_epp(int cpu, u64 epp_val)

Any reason this is a u64 argument when the biggest value you can support 
is 0xFF?  Presumably you could drop the the bounds check below if you 
limited the variable size.

> +{
> +	if (epp_val > CPPC_ENERGY_PERF_MAX)
> +		return -EINVAL;
> +
> +	return cppc_set_reg_val(cpu, ENERGY_PERF, epp_val);
> +}
> +EXPORT_SYMBOL_GPL(cppc_set_epp);
> +
> +/**
> + * cppc_get_auto_act_window() - Read autonomous activity window register.
> + * @cpu: CPU from which to read register.
> + * @auto_act_window: Return address.
> + *
> + * According to ACPI 6.5, s8.4.6.1.6, the value read from the autonomous
> + * activity window register consists of two parts: a 7 bits value indicate
> + * significand and a 3 bits value indicate exponent.
> + */
> +int cppc_get_auto_act_window(int cpu, u64 *auto_act_window)
> +{
> +	unsigned int exp;
> +	u64 val, sig;
> +	int ret;
> +
> +	ret = cppc_get_reg_val(cpu, AUTO_ACT_WINDOW, &val);
> +	if (ret)
> +		return ret;
> +
> +	sig = val & CPPC_AUTO_ACT_WINDOW_MAX_SIG;
> +	exp = (val >> CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE) & CPPC_AUTO_ACT_WINDOW_MAX_EXP;
> +	*auto_act_window = sig * int_pow(10, exp);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(cppc_get_auto_act_window);

Since this is exported code, do you perhaps want a check that 
auto_act_window is not NULL to avoid a possible accidental NULL pointer 
dereference?

> +
> +/**
> + * cppc_set_auto_act_window() - Write autonomous activity window register.
> + * @cpu: CPU on which to write register.
> + * @auto_act_window: usec value to write to the autonomous activity window register.
> + *
> + * According to ACPI 6.5, s8.4.6.1.6, the value to write to the autonomous
> + * activity window register consists of two parts: a 7 bits value indicate
> + * significand and a 3 bits value indicate exponent.
> + */
> +int cppc_set_auto_act_window(int cpu, u64 auto_act_window)
> +{
> +	/* The max value to stroe is 1270000000 */

store

> +	u64 max_val = CPPC_AUTO_ACT_WINDOW_MAX_SIG * int_pow(10, CPPC_AUTO_ACT_WINDOW_MAX_EXP);
> +	int exp = 0;
> +	u64 val;
> +
> +	if (auto_act_window > max_val)
> +		return -EINVAL;
> +
> +	/*
> +	 * The max significand is 127, when auto_act_window is larger than
> +	 * 129, discard the precision of the last digit and increase the
> +	 * exponent by 1.
> +	 */
> +	while (auto_act_window > CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH) {
> +		auto_act_window /= 10;
> +		exp += 1;
> +	}
> +
> +	/* For 128 and 129, cut it to 127. */
> +	if (auto_act_window > CPPC_AUTO_ACT_WINDOW_MAX_SIG)
> +		auto_act_window = CPPC_AUTO_ACT_WINDOW_MAX_SIG;
> +
> +	val = (exp << CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE) + auto_act_window;
> +
> +	return cppc_set_reg_val(cpu, AUTO_ACT_WINDOW, val);
> +}
> +EXPORT_SYMBOL_GPL(cppc_set_auto_act_window);
> +
>   /**
>    * cppc_get_auto_sel() - Read autonomous selection register.
>    * @cpu: CPU from which to read register.
> diff --git a/include/acpi/cppc_acpi.h b/include/acpi/cppc_acpi.h
> index 31767c65be20..325e9543e08f 100644
> --- a/include/acpi/cppc_acpi.h
> +++ b/include/acpi/cppc_acpi.h
> @@ -32,6 +32,15 @@
>   #define	CMD_READ 0
>   #define	CMD_WRITE 1
>   
> +#define CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE	(7)
> +#define CPPC_AUTO_ACT_WINDOW_EXP_BIT_SIZE	(3)
> +#define CPPC_AUTO_ACT_WINDOW_MAX_SIG	((1 << CPPC_AUTO_ACT_WINDOW_SIG_BIT_SIZE) - 1)
> +#define CPPC_AUTO_ACT_WINDOW_MAX_EXP	((1 << CPPC_AUTO_ACT_WINDOW_EXP_BIT_SIZE) - 1)
> +/* CPPC_AUTO_ACT_WINDOW_MAX_SIG is 127, so 128 and 129 will decay to 127 when writing */
> +#define CPPC_AUTO_ACT_WINDOW_SIG_CARRY_THRESH 129
> +
> +#define CPPC_ENERGY_PERF_MAX	(0xFF)
> +
>   /* Each register has the folowing format. */
>   struct cpc_reg {
>   	u8 descriptor;
> @@ -159,6 +168,9 @@ extern int cpc_read_ffh(int cpunum, struct cpc_reg *reg, u64 *val);
>   extern int cpc_write_ffh(int cpunum, struct cpc_reg *reg, u64 val);
>   extern int cppc_get_epp_perf(int cpunum, u64 *epp_perf);
>   extern int cppc_set_epp_perf(int cpu, struct cppc_perf_ctrls *perf_ctrls, bool enable);
> +extern int cppc_set_epp(int cpu, u64 epp_val);
> +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 amd_get_highest_perf(unsigned int cpu, u32 *highest_perf);
> @@ -229,6 +241,18 @@ static inline int cppc_get_epp_perf(int cpunum, u64 *epp_perf)
>   {
>   	return -EOPNOTSUPP;
>   }
> +static inline int cppc_set_epp(int cpu, u64 epp_val)
> +{
> +	return -EOPNOTSUPP;
> +}
> +static inline int cppc_get_auto_act_window(int cpu, u64 *auto_act_window)
> +{
> +	return -EOPNOTSUPP;
> +}
> +static inline int cppc_set_auto_act_window(int cpu, u64 auto_act_window)
> +{
> +	return -EOPNOTSUPP;
> +}
>   static inline int cppc_get_auto_sel(int cpu, bool *enable)
>   {
>   	return -EOPNOTSUPP;


  reply	other threads:[~2025-04-09 18:59 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-09  6:56 [PATCH v6 0/8] Add functions for getting and setting registers related to autonomous selection in cppc_acpi Lifeng Zheng
2025-04-09  6:56 ` [PATCH v6 1/8] ACPI: CPPC: Add IS_OPTIONAL_CPC_REG macro to judge if a cpc_reg is optional Lifeng Zheng
2025-04-09 18:53   ` Mario Limonciello
2025-04-10  8:21     ` zhenglifeng (A)
2025-04-09  6:56 ` [PATCH v6 2/8] ACPI: CPPC: Optimize cppc_get_perf() Lifeng Zheng
2025-04-09 17:10   ` Rafael J. Wysocki
2025-04-10  8:23     ` zhenglifeng (A)
2025-04-09  6:56 ` [PATCH v6 3/8] ACPI: CPPC: Rename cppc_get_perf() to cppc_get_reg_val() Lifeng Zheng
2025-04-09  6:56 ` [PATCH v6 4/8] ACPI: CPPC: Extract cppc_get_reg_val_in_pcc() Lifeng Zheng
2025-04-09  6:57 ` [PATCH v6 5/8] ACPI: CPPC: Add cppc_set_reg_val() Lifeng Zheng
2025-04-09  6:57 ` [PATCH v6 6/8] ACPI: CPPC: Refactor register value get and set ABIs Lifeng Zheng
2025-04-09  6:57 ` [PATCH v6 7/8] ACPI: CPPC: Modify cppc_get_auto_sel_caps() to cppc_get_auto_sel() Lifeng Zheng
2025-04-09  6:57 ` [PATCH v6 8/8] ACPI: CPPC: Add three functions related to autonomous selection Lifeng Zheng
2025-04-09 18:59   ` Mario Limonciello [this message]
2025-04-10  8:31     ` zhenglifeng (A)

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=e5dc4906-2b28-4adc-8e8e-ddd5d7cc985c@amd.com \
    --to=mario.limonciello@amd.com \
    --cc=acpica-devel@lists.linux.dev \
    --cc=cenxinghai@h-partners.com \
    --cc=gautham.shenoy@amd.com \
    --cc=hepeng68@huawei.com \
    --cc=jonathan.cameron@huawei.com \
    --cc=lenb@kernel.org \
    --cc=lihuisong@huawei.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=perry.yuan@amd.com \
    --cc=pierre.gondois@arm.com \
    --cc=rafael@kernel.org \
    --cc=ray.huang@amd.com \
    --cc=robert.moore@intel.com \
    --cc=viresh.kumar@linaro.org \
    --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

all inboxes | Powered by JetHome®