All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Cc: platform-driver-x86@vger.kernel.org, Suma.Hegde@amd.com,
	 NaveenKrishna.Chatradhi@amd.com
Subject: Re: [PATCH 07/26] platform/x86/amd/hsmp: Add df_pstate_range sysfs file
Date: Mon, 23 Nov 2026 13:32:29 +0200 (EET)	[thread overview]
Message-ID: <2011d6bf-fe58-af5e-a28c-64b030806884@linux.intel.com> (raw)
In-Reply-To: <f441bef698cd6cdc7d6ca2067833542ab49a31b1.1793602633.git.Muthusamy.Ramalingam@amd.com>

On Mon, 2 Nov 2026, Muthusamy Ramalingam wrote:

> Expose HSMP_SET_PSTATE_MAX_MIN as a read/write socket file on both the
> ACPI and platform drivers. Read and write are differentiated by bit 31.
> Setting the bit selects a read, and resetting it selects a write. A
> read returns the minimum and maximum DF P-states. A write takes
> "min max". Each value is an 8-bit field. Extra arguments are rejected.
> Firmware rejects unsupported P-states.
> 
> Co-developed-by: Suma Hegde <Suma.Hegde@amd.com>
> Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
> Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
> ---
>  Documentation/arch/x86/amd_hsmp.rst   |   3 +
>  drivers/platform/x86/amd/hsmp/acpi.c  |   3 +
>  drivers/platform/x86/amd/hsmp/plat.c  |   5 ++
>  drivers/platform/x86/amd/hsmp/sysfs.c | 116 ++++++++++++++++++++++++++
>  drivers/platform/x86/amd/hsmp/sysfs.h |   5 ++
>  5 files changed, 132 insertions(+)
> 
> diff --git a/Documentation/arch/x86/amd_hsmp.rst b/Documentation/arch/x86/amd_hsmp.rst
> index 1fc4727b48726..694997308ffa9 100644
> --- a/Documentation/arch/x86/amd_hsmp.rst
> +++ b/Documentation/arch/x86/amd_hsmp.rst
> @@ -119,6 +119,9 @@ write-only when the platform enables only that direction of the message.
>    32-bit value. Firmware clamps it to the platform range.
>  * sdps_limit: Read/write SDPS limit in mWatts. A write uses bits [30:0].
>    Firmware clamps it to the platform range.
> +* df_pstate_range: Read/write DF P-state range as "min max". Each value
> +  is an 8-bit field. 0 is the highest performance. Extra arguments are
> +  rejected. Firmware rejects unsupported P-states.
>  * socket_power_limit_max: Maximum socket power limit in mWatts (read only).
>  * cclk_boost_limit: Socket boost limit in MHz (write only). Accepted range
>    is 100-10000 MHz.
> diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
> index 4c9f6c6843304..417fca04a722f 100644
> --- a/drivers/platform/x86/amd/hsmp/acpi.c
> +++ b/drivers/platform/x86/amd/hsmp/acpi.c
> @@ -539,6 +539,8 @@ HSMP_DEV_ATTR_RW(socket_power_limit, HSMP_GET_SOCKET_POWER_LIMIT,
>  		 hsmp_socket_power_limit_show, hsmp_socket_power_limit_store, 0644);
>  HSMP_DEV_ATTR_RW(sdps_limit, HSMP_SDPS_LIMIT, HSMP_SDPS_LIMIT,
>  		 hsmp_sdps_limit_show, hsmp_sdps_limit_store, 0644);
> +HSMP_DEV_ATTR_RW(df_pstate_range, HSMP_SET_PSTATE_MAX_MIN, HSMP_SET_PSTATE_MAX_MIN,
> +		 hsmp_df_pstate_range_show, hsmp_df_pstate_range_store, 0644);
>  HSMP_DEV_ATTR_W(cclk_boost_limit, HSMP_SET_BOOST_LIMIT_SOCKET,
>  		hsmp_cclk_boost_limit_store, 0200);
>  HSMP_DEV_ATTR_RW(apb_disable, HSMP_SET_DF_PSTATE, HSMP_SET_DF_PSTATE,
> @@ -571,6 +573,7 @@ static struct attribute *hsmp_dev_attr_list[] = {
>  	&hattr_socket_power_limit_max.dattr.attr,
>  	&hattr_socket_power_limit.dattr.attr,
>  	&hattr_sdps_limit.dattr.attr,
> +	&hattr_df_pstate_range.dattr.attr,
>  	&hattr_socket_power.dattr.attr,
>  	&hattr_cclk_boost_limit.dattr.attr,
>  	&hattr_tdelta.dattr.attr,
> diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
> index 6f4250cfc1f4a..3deb5480495dc 100644
> --- a/drivers/platform/x86/amd/hsmp/plat.c
> +++ b/drivers/platform/x86/amd/hsmp/plat.c
> @@ -373,6 +373,10 @@ HSMP_DEV_ATTR_RW_X8(socket_power_limit, HSMP_GET_SOCKET_POWER_LIMIT,
>  		    hsmp_socket_power_limit_store, 0644);
>  HSMP_DEV_ATTR_RW_X8(sdps_limit, HSMP_SDPS_LIMIT, HSMP_SDPS_LIMIT,
>  		    hsmp_sdps_limit_show, hsmp_sdps_limit_store, 0644);
> +HSMP_DEV_ATTR_RW_X8(df_pstate_range, HSMP_SET_PSTATE_MAX_MIN,
> +		    HSMP_SET_PSTATE_MAX_MIN,
> +		    hsmp_df_pstate_range_show, hsmp_df_pstate_range_store,
> +		    0644);
>  HSMP_DEV_ATTR_X8(socket_power, HSMP_GET_SOCKET_POWER, hsmp_msg_resp32_show,
>  		 0444);
>  HSMP_DEV_ATTR_W_X8(cclk_boost_limit, HSMP_SET_BOOST_LIMIT_SOCKET,
> @@ -410,6 +414,7 @@ static struct attribute _name[] = {					       \
>  	&hattr_socket_power_limit_max##_sock_ind.dattr.attr,		       \
>  	&hattr_socket_power_limit##_sock_ind.dattr.attr,		       \
>  	&hattr_sdps_limit##_sock_ind.dattr.attr,			       \
> +	&hattr_df_pstate_range##_sock_ind.dattr.attr,			       \
>  	&hattr_socket_power##_sock_ind.dattr.attr,			       \
>  	&hattr_cclk_boost_limit##_sock_ind.dattr.attr,		       \
>  	&hattr_tdelta##_sock_ind.dattr.attr,				       \
> diff --git a/drivers/platform/x86/amd/hsmp/sysfs.c b/drivers/platform/x86/amd/hsmp/sysfs.c
> index 01363b0b92fd7..8f10281cb97c1 100644
> --- a/drivers/platform/x86/amd/hsmp/sysfs.c
> +++ b/drivers/platform/x86/amd/hsmp/sysfs.c
> @@ -14,6 +14,7 @@
>  #include <linux/kstrtox.h>
>  #include <linux/limits.h>
>  #include <linux/smp.h>
> +#include <linux/string.h>
>  #include <linux/sysfs.h>
>  #include <linux/topology.h>
>  
> @@ -696,6 +697,121 @@ ssize_t hsmp_sdps_limit_store(struct device *dev,
>  	return count;
>  }
>  
> +/* Multi-field stores copy the write into this buffer before tokenizing. */
> +#define HSMP_PARSE_BUFSZ	80
> +
> +/*
> + * Parse exactly @n whitespace-separated unsigned integers. base 10 accepts
> + * decimal. base 0 also accepts 0x hex and leading-zero octal. Too few
> + * tokens, extra tokens, and a value that does not fit in u32 are rejected.
> + * On failure, *@got is the number of whitespace-separated tokens present.
> + */
> +static int hsmp_parse_u32_args(const char *buf, u32 *vals, int n,
> +			       unsigned int base, int *got)
> +{
> +	char tmp[HSMP_PARSE_BUFSZ];
> +	char *s, *tok;
> +	int i = 0;
> +
> +	*got = 0;
> +	if (strscpy(tmp, buf, sizeof(tmp)) < 0)

2-args version.

> +		return -EINVAL;
> +
> +	s = tmp;
> +	while ((tok = strsep(&s, " \t\n")) != NULL) {
> +		if (*tok == '\0')
> +			continue;
> +		(*got)++;

Can this be named better? And I really don't get why this is useful number 
to return at all if kstrtou32() fails for some tokens so care to explain?

> +		if (i < n && !kstrtou32(tok, base, &vals[i]))

What about invalid values? Shouldn't it reject the whole input with 
-EINVAL?

> +			i++;
> +	}
> +
> +	return (i == n && *got == n) ? 0 : -EINVAL;

Looks a bit complicated for me.

I'd tend to think it should just reject all invalid inputs instead of 
trying to conceal the parsing problems.

> +}
> +
> +/* DF P-state range show function - reads current min and max DF P-states */
> +ssize_t hsmp_df_pstate_range_show(struct device *dev,
> +				  struct device_attribute *attr,
> +				  char *buf)
> +{
> +	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
> +	struct hsmp_message msg = { 0 };

= {}; is enough to initialize

> +	u32 min_pstate, max_pstate;
> +	int ret;
> +
> +	/* Set bit 31 to indicate GET operation for HSMP_SET_GET type messages */
> +	msg.msg_id = HSMP_SET_PSTATE_MAX_MIN;
> +	msg.sock_ind = hsmp_sysfs_sock_ind(dev, hattr);
> +	msg.num_args = 1;
> +	msg.response_sz = 1;
> +	msg.args[0] = BIT(31);  /* GET operation */

Use define.

> +
> +	ret = hsmp_send_message(&msg);
> +	if (ret)
> +		return ret;
> +
> +	/* Extract min DF P-state[15:8] and max DF P-state[7:0] */
> +	min_pstate = (msg.args[0] >> 8) & 0xFF;
> +	max_pstate = msg.args[0] & 0xFF;

Named defines + FIELD_GET() + remove comments from here.

> +
> +	return sysfs_emit(buf, "%u %u\n", min_pstate, max_pstate);
> +}
> +
> +/* DF P-state range store function - sets min and max DF P-states */
> +ssize_t hsmp_df_pstate_range_store(struct device *dev,
> +				   struct device_attribute *attr,
> +				   const char *buf, size_t count)
> +{
> +	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
> +	struct hsmp_message msg = { 0 };

{}

> +	u32 min_pstate, max_pstate;
> +	u32 vals[2];
> +	int ret;
> +	int got;
> +
> +	/* Parse input in format: "min_pstate max_pstate" */
> +	ret = hsmp_parse_u32_args(buf, vals, 2, 10, &got);
> +	if (ret) {
> +		hsmp_err(dev, "df_pstate_range", HSMP_ERR_ARGC,
> +			 "want=2 got=%d fmt=\"min max\"", got);

Here it even lies to the user, there were not necessarily 2 valid numbers 
even if it would say want=2 got=2.

> +		return -EINVAL;
> +	}
> +	min_pstate = vals[0];
> +	max_pstate = vals[1];
> +
> +	/* Min and max are 8-bit fields. Firmware rejects unsupported P-states. */
> +	if (min_pstate > 0xFF || max_pstate > 0xFF) {

> FIELD_MAX(...)

> +		hsmp_err(dev, "df_pstate_range", HSMP_ERR_RANGE,
> +			 "min=%u max=%u valid=0-255", min_pstate, max_pstate);
> +		return -EINVAL;
> +	}
> +
> +	/* Clear bit 31 for SET operation, pack min[15:8] and max[7:0] */

Remove.

> +	msg.msg_id = HSMP_SET_PSTATE_MAX_MIN;
> +	msg.sock_ind = hsmp_sysfs_sock_ind(dev, hattr);
> +	msg.num_args = 1;
> +	msg.response_sz = 1;
> +	msg.args[0] = (min_pstate << 8) | max_pstate;

FIELD_PREP() | FIELD_PREP()

> +
> +	ret = hsmp_send_message(&msg);
> +	if (ret) {
> +		if (max_pstate > min_pstate)
> +			hsmp_err(dev, "df_pstate_range", HSMP_ERR_ORDER,
> +				 "min=%u max=%u rule=max<=min rc=%d",

This says max <= min but your code checks the opposite condition??

Should max <= min be returning -EINVAL before even attempting to send the 
message? Does that ever make sense?

Use braces for multi-line blocks even if they're just one statement.

> +				  min_pstate, max_pstate, ret);
> +		else if (min_pstate > 2 || max_pstate > 2)

This too looks -EINVAL case if there's a known "max" state like this code 
implie? And why isn't it put into a named define?

It looks very odd to do these checks only after the fact in error 
handling. It's as if you're putting cart before the horse.

> +			hsmp_err(dev, "df_pstate_range", HSMP_ERR_RANGE,
> +				 "min=%u max=%u valid=0-2 rc=%d",

%d + max state define.

> +				  min_pstate, max_pstate, ret);
> +		else
> +			hsmp_err(dev, "df_pstate_range", HSMP_ERR_HW,
> +				 "min=%u max=%u rc=%d", min_pstate, max_pstate, ret);
> +		return ret;
> +	}
> +
> +	return count;
> +}
> +
>  static ssize_t boost_limit_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf)
>  {
>  	struct hsmp_cpu_info *cpu_info = NULL;
> diff --git a/drivers/platform/x86/amd/hsmp/sysfs.h b/drivers/platform/x86/amd/hsmp/sysfs.h
> index bf5bac77102d3..9631b9067c142 100644
> --- a/drivers/platform/x86/amd/hsmp/sysfs.h
> +++ b/drivers/platform/x86/amd/hsmp/sysfs.h
> @@ -110,6 +110,11 @@ ssize_t hsmp_sdps_limit_show(struct device *dev, struct device_attribute *attr,
>  			     char *buf);
>  ssize_t hsmp_sdps_limit_store(struct device *dev, struct device_attribute *attr,
>  			      const char *buf, size_t count);
> +ssize_t hsmp_df_pstate_range_show(struct device *dev,
> +				  struct device_attribute *attr, char *buf);
> +ssize_t hsmp_df_pstate_range_store(struct device *dev,
> +				   struct device_attribute *attr,
> +				   const char *buf, size_t count);
>  
>  void hsmp_create_per_cpu_kobjects(struct device *dev, struct kobject *cpu_parent,
>  				  struct hsmp_socket *sock);
> 

-- 
 i.


  reply	other threads:[~2026-11-23 11:32 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02  7:18 [PATCH 00/26] platform/x86/amd/hsmp: Extend socket and per-CPU sysfs Muthusamy Ramalingam
2026-11-02  7:18 ` [PATCH 01/26] platform/x86/amd/hsmp: Drop _input from socket sysfs names Muthusamy Ramalingam
2026-11-23 11:36   ` Ilpo Järvinen
2026-11-02  7:19 ` [PATCH 02/26] platform/x86/amd/hsmp: Rename clk_fmax and clk_fmin sysfs files Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 03/26] platform/x86/amd/hsmp: Add hsmp_err helper for parser-friendly store errors Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 04/26] platform/x86/amd/hsmp: Treat socket_power_limit as firmware-clamped Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 05/26] platform/x86/amd/hsmp: Print protocol_version as hexadecimal Muthusamy Ramalingam
2026-11-23 11:06   ` Ilpo Järvinen
2026-11-02  7:19 ` [PATCH 06/26] platform/x86/amd/hsmp: Add sdps_limit sysfs file Muthusamy Ramalingam
2026-11-23 11:15   ` Ilpo Järvinen
2026-11-02  7:19 ` [PATCH 07/26] platform/x86/amd/hsmp: Add df_pstate_range " Muthusamy Ramalingam
2026-11-23 11:32   ` Ilpo Järvinen [this message]
2026-11-02  7:19 ` [PATCH 08/26] platform/x86/amd/hsmp: Add xgmi_width " Muthusamy Ramalingam
2026-11-23 11:35   ` Ilpo Järvinen
2026-11-02  7:19 ` [PATCH 09/26] platform/x86/amd/hsmp: Add gmi3_link_width " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 10/26] platform/x86/amd/hsmp: Add pcie_link_rate " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 11/26] platform/x86/amd/hsmp: Add lclk DPM sysfs files Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 12/26] platform/x86/amd/hsmp: Add io_bw and xgmi_bw " Muthusamy Ramalingam
2026-11-23 11:49   ` Ilpo Järvinen
2026-11-02  7:19 ` [PATCH 13/26] platform/x86/amd/hsmp: Add DIMM sideband " Muthusamy Ramalingam
2026-11-23 11:51   ` Ilpo Järvinen
2026-11-02  7:19 ` [PATCH 14/26] platform/x86/amd/hsmp: Add per-CPU floor limit " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 15/26] platform/x86/amd/hsmp: Add metric_version sysfs file Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 16/26] platform/x86/amd/hsmp: Add enabled command sysfs files Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 17/26] platform/x86/amd/hsmp: Add DIMM power and temperature " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 18/26] platform/x86/amd/hsmp: Add SVI3 " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 19/26] platform/x86/amd/hsmp: Add cclk_floor_limit sysfs file Muthusamy Ramalingam
2026-11-23 11:56   ` Ilpo Järvinen
2026-11-02  7:19 ` [PATCH 20/26] platform/x86/amd/hsmp: Add xgmi_pstate_range " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 21/26] platform/x86/amd/hsmp: Quiet probe-time firmware status dmesg spam Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 22/26] platform/x86/amd/hsmp: Add powereff_mode sysfs file Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 23/26] platform/x86/amd/hsmp: Add svi_power " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 24/26] platform/x86/amd/hsmp: Add per-CPU ccd_power " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 25/26] platform/x86/amd/hsmp: Add per-CPU freq_limit " Muthusamy Ramalingam
2026-11-02  7:19 ` [PATCH 26/26] platform/x86/amd/hsmp: Add socket_temperature " Muthusamy Ramalingam
2026-11-23 11:59 ` [PATCH 00/26] platform/x86/amd/hsmp: Extend socket and per-CPU sysfs 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=2011d6bf-fe58-af5e-a28c-64b030806884@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=Muthusamy.Ramalingam@amd.com \
    --cc=NaveenKrishna.Chatradhi@amd.com \
    --cc=Suma.Hegde@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.