X86 platform drivers
 help / color / mirror / Atom feed
* [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps
@ 2026-11-19  8:50 Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in hsmp_is_sock_attr_visible() Suma Hegde
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

This series introduces per-socket read/write enabled-message bitmaps so
the HSMP driver rejects unsupported messages before they reach the SMU.
Prep patches fix sock_ind bounds checking, move proto_ver onto
hsmp_socket, and reorder helpers for the validation path. Later patches
populate the bitmaps statically and via HSMP_GET_ENABLED_HSMP_CMDS
(6th Gen AMD EPYC Server and future platforms), and update sysfs/hwmon
file modes from the bitmaps.

Client platforms skip bitmap init, populate, and validation until
dedicated client tables exist; shared smu_fw_version and
protocol_version sysfs attributes remain visible there.

Changes since v1:
- Named HSMP_MSG_BIT() static bitmaps; zen6 PQOS bits added and
  HSMP_SET_XGMI_PSTATE_RANGE dropped from the zen6 write bitmap.
- validate_message() runs only after sock->dev is ready.
- Safer dynamic bitmap fetch helpers and default-bitmap fallback.
- Skip hwmon registration on client platforms in the plat probe path.
- Keep the short client-attribute visibility comment in the modes patch.
- Commit message / tagging cleanups (Co-developed-by, defensive
  null-check wording, typos).
- See per-patch "Changes since v1" for details.

Patch summary:
  01/11  Fix sock_ind bounds check in hsmp_is_sock_attr_visible()
  02/11  Move proto_ver to hsmp_socket structure
  03/11  Null-check drvdata in hsmp_is_sock_attr_visible()
  04/11  Move is_get_msg() before validate_message()
  05/11  Use local sock pointer in init_acpi()
  06/11  Move the sock_ind bounds check before validate_message()
  07/11  Add per-platform bitmap to validate HSMP messages
  08/11  Populate the bitmaps dynamically on 6th Gen AMD EPYC Server
  09/11  Populate the bitmaps dynamically for future platforms
  10/11  Relocate to_hsmp_sys_attr() macro
  11/11  Update sysfs and hwmon file modes based on platform capabilities

Suma Hegde (11):
  platform/x86/amd/hsmp: Fix sock_ind bounds check in
    hsmp_is_sock_attr_visible()
  platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure
  platform/x86/amd/hsmp: Null-check drvdata in
    hsmp_is_sock_attr_visible()
  platform/x86/amd/hsmp: Move is_get_msg() before validate_message()
  platform/x86/amd/hsmp: Use local sock pointer in init_acpi()
  platform/x86/amd/hsmp: Move the sock_ind bounds check before
    validate_message()
  platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP
    messages
  platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD
    EPYC Server
  platform/x86/amd/hsmp: Populate the bitmaps dynamically for future
    platforms
  platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro
  platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on
    platform capabilities

 drivers/platform/x86/amd/hsmp/acpi.c  |  94 +++++-
 drivers/platform/x86/amd/hsmp/hsmp.c  | 433 +++++++++++++++++++++++++-
 drivers/platform/x86/amd/hsmp/hsmp.h  |  29 +-
 drivers/platform/x86/amd/hsmp/hwmon.c |  24 +-
 drivers/platform/x86/amd/hsmp/plat.c  |  36 ++-
 5 files changed, 578 insertions(+), 38 deletions(-)


base-commit: c339f4010dea8b0d754f84ace70cd1b089878ef8
(rebased on platform-drivers-x86 master branch)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in hsmp_is_sock_attr_visible()
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure Suma Hegde
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

The bounds check in hsmp_is_sock_attr_visible() only ran when id == 0.
SYSFS_GROUP_INVISIBLE is only valid for the group-visibility call
(id == 0), but sock_ind must still be validated for every attribute
so a later bin attribute cannot use an out-of-range socket index.

Always bounds-check sock_ind first; return SYSFS_GROUP_INVISIBLE for
id == 0 and 0 otherwise.

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- Update subject with name hsmp_is_sock_attr_visible() instead of
  is_bin_visible.

 drivers/platform/x86/amd/hsmp/plat.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index e9b2b809c0f52..af8aee1fb22ba 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -71,8 +71,13 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
 
 	sock_ind = (uintptr_t)battr->private;
 
-	if (id == 0 && sock_ind >= hsmp_pdev->num_sockets)
-		return SYSFS_GROUP_INVISIBLE;
+	/*
+	 * Always bounds-check sock_ind. SYSFS_GROUP_INVISIBLE is only
+	 * meaningful for id == 0 (group visibility); for later attributes
+	 * just hide the file.
+	 */
+	if (sock_ind >= hsmp_pdev->num_sockets)
+		return id == 0 ? SYSFS_GROUP_INVISIBLE : 0;
 
 	if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6)
 		return battr->attr.mode;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in hsmp_is_sock_attr_visible() Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible() Suma Hegde
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde, Dhruv Gupta

From: Suma Hegde <Suma.Hegde@amd.com>

Move proto_ver from hsmp_plat_device to hsmp_socket, as the protocol
version is fetched per socket. Update all users to read the per-socket
proto_ver.

Co-developed-by: Dhruv Gupta <dhruv.gupta@amd.com>
Signed-off-by: Dhruv Gupta <dhruv.gupta@amd.com>
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- Add missing Co-developed-by for Dhruv Gupta to match his
  Signed-off-by.

 drivers/platform/x86/amd/hsmp/acpi.c | 14 +++++++++-----
 drivers/platform/x86/amd/hsmp/hsmp.c |  2 +-
 drivers/platform/x86/amd/hsmp/hsmp.h |  2 +-
 drivers/platform/x86/amd/hsmp/plat.c |  4 ++--
 4 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 167c76c13ad07..44db76308ceb9 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -286,7 +286,7 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj
 	 * Surface the unsupported case here as -EOPNOTSUPP rather than
 	 * silently truncating the snapshot.
 	 */
-	if (hsmp_pdev->proto_ver != HSMP_PROTO_VER6)
+	if (sock->proto_ver != HSMP_PROTO_VER6)
 		return -EOPNOTSUPP;
 
 	return hsmp_metric_tbl_read(sock, buf, count);
@@ -302,7 +302,10 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
 	 * pointed at HSMP_IOCTL_GET_TELEMETRY_DATA as the supported path.
 	 * Hide metrics_bin on client platforms.
 	 */
-	if (!is_client_platform() && hsmp_pdev->proto_ver >= HSMP_PROTO_VER6)
+	struct device *dev = kobj_to_dev(kobj);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+
+	if (!is_client_platform() && sock->proto_ver >= HSMP_PROTO_VER6)
 		return battr->attr.mode;
 
 	return 0;
@@ -574,8 +577,10 @@ static int init_acpi(struct device *dev)
 	 * version enum rather than relying on numeric coincidence
 	 * between the two.
 	 */
-	if ((is_client_platform() && hsmp_pdev->proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
-	    (!is_client_platform() && hsmp_pdev->proto_ver >= HSMP_PROTO_VER6)) {
+	if ((is_client_platform() &&
+	     hsmp_pdev->sock[sock_ind].proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
+	    (!is_client_platform() &&
+	     hsmp_pdev->sock[sock_ind].proto_ver >= HSMP_PROTO_VER6)) {
 		ret = hsmp_get_tbl_dram_base(sock_ind);
 		if (ret)
 			dev_info(dev, "Failed to init metric table\n");
@@ -684,7 +689,6 @@ static void hsmp_acpi_sock_release(struct kref *kref)
 	kfree(hsmp_pdev->sock);
 	hsmp_pdev->sock = NULL;
 	hsmp_pdev->num_sockets = 0;
-	hsmp_pdev->proto_ver = 0;
 }
 
 /**
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 45d20beda9464..3a8b8697e62b9 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -805,7 +805,7 @@ int hsmp_cache_proto_ver(u16 sock_ind)
 
 	ret = hsmp_send_message_locked(&msg);
 	if (!ret)
-		hsmp_pdev.proto_ver = msg.args[0];
+		hsmp_pdev.sock[sock_ind].proto_ver = msg.args[0];
 
 	return ret;
 }
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index 3302c15173695..5b05dcb074846 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -77,13 +77,13 @@ struct hsmp_socket {
 	char name[HSMP_ATTR_GRP_NAME_SIZE];
 	struct device *dev;
 	u16 sock_ind;
+	u32 proto_ver;
 	int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw);
 };
 
 struct hsmp_plat_device {
 	struct miscdevice mdev;
 	struct hsmp_socket *sock;
-	u32 proto_ver;
 	u16 num_sockets;
 };
 
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index af8aee1fb22ba..40c98d9c66d4f 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -79,7 +79,7 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
 	if (sock_ind >= hsmp_pdev->num_sockets)
 		return id == 0 ? SYSFS_GROUP_INVISIBLE : 0;
 
-	if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6)
+	if (hsmp_pdev->sock[sock_ind].proto_ver == HSMP_PROTO_VER6)
 		return battr->attr.mode;
 
 	return 0;
@@ -193,7 +193,7 @@ static int init_platform_device(struct device *dev)
 			return ret;
 		}
 
-		if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6) {
+		if (sock->proto_ver == HSMP_PROTO_VER6) {
 			ret = hsmp_get_tbl_dram_base(i);
 			if (ret)
 				dev_info(dev, "Failed to init metric table\n");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible()
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in hsmp_is_sock_attr_visible() Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message() Suma Hegde
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

dev_get_drvdata() is not expected to return NULL when this visibility
callback runs: the driver core evaluates it from really_probe() via
device_add_groups() after probe has set the socket pointer. Check for
NULL anyway before reading sock->proto_ver.

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- Align the commit message with the defensive null-check comment:
  note that drvdata is not expected to be NULL when the visibility
  callback runs from really_probe()/device_add_groups(), but still
  check it.
- Assign sock from dev_get_drvdata() next to the null check
  instead of in the declaration as per review comment.

 drivers/platform/x86/amd/hsmp/acpi.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 44db76308ceb9..223dece3b91e0 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -303,7 +303,16 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
 	 * Hide metrics_bin on client platforms.
 	 */
 	struct device *dev = kobj_to_dev(kobj);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	struct hsmp_socket *sock;
+
+	/*
+	 * Defensive only: the driver core evaluates this callback from
+	 * really_probe() via device_add_groups(), after probe has already
+	 * set the driver data, so sock is never NULL here in practice.
+	 */
+	sock = dev_get_drvdata(dev);
+	if (!sock)
+		return 0;
 
 	if (!is_client_platform() && sock->proto_ver >= HSMP_PROTO_VER6)
 		return battr->attr.mode;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message()
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (2 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible() Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi() Suma Hegde
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

An upcoming patch invokes is_get_msg() inside validate_message().

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- None.

 drivers/platform/x86/amd/hsmp/hsmp.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 3a8b8697e62b9..ad5b3fde54caf 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -277,6 +277,17 @@ static int __hsmp_send_message(struct hsmp_socket *sock, struct hsmp_message *ms
 	return ret;
 }
 
+static bool is_get_msg(const struct hsmp_msg_desc *desc, struct hsmp_message *msg)
+{
+	if (desc->type == HSMP_GET)
+		return true;
+
+	if (desc->type == HSMP_SET_GET && (msg->args[0] & CHECK_GET_BIT))
+		return true;
+
+	return false;
+}
+
 static int validate_message(struct hsmp_message *msg)
 {
 	const struct hsmp_plat_desc *plat_desc = hsmp_desc();
@@ -449,17 +460,6 @@ int hsmp_test(u16 sock_ind, u32 value)
 }
 EXPORT_SYMBOL_NS_GPL(hsmp_test, "AMD_HSMP");
 
-static bool is_get_msg(const struct hsmp_msg_desc *desc, struct hsmp_message *msg)
-{
-	if (desc->type == HSMP_GET)
-		return true;
-
-	if (desc->type == HSMP_SET_GET && (msg->args[0] & CHECK_GET_BIT))
-		return true;
-
-	return false;
-}
-
 static long hsmp_ioctl_msg(struct file *fp, unsigned long arg)
 {
 	int __user *arguser = (int  __user *)arg;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi()
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (3 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message() Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 06/11] platform/x86/amd/hsmp: Move the sock_ind bounds check before validate_message() Suma Hegde
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

Introduce a local struct hsmp_socket *sock pointer in init_acpi() to avoid
repeated use of &hsmp_pdev->sock[sock_ind]. The subsequent patch adds more
users of this pointer beyond dev_set_drvdata().

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- None.

 drivers/platform/x86/amd/hsmp/acpi.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 223dece3b91e0..eee66825eb904 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -547,6 +547,7 @@ static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_att
  */
 static int init_acpi(struct device *dev)
 {
+	struct hsmp_socket *sock;
 	u16 sock_ind;
 	int ret;
 
@@ -564,6 +565,8 @@ static int init_acpi(struct device *dev)
 		return ret;
 	}
 
+	sock = &hsmp_pdev->sock[sock_ind];
+
 	/* Test the hsmp interface */
 	ret = hsmp_test(sock_ind, 0xDEADBEEF);
 	if (ret) {
@@ -587,9 +590,9 @@ static int init_acpi(struct device *dev)
 	 * between the two.
 	 */
 	if ((is_client_platform() &&
-	     hsmp_pdev->sock[sock_ind].proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
+	     sock->proto_ver >= RYZEN_MASTER_PROTO_VER1) ||
 	    (!is_client_platform() &&
-	     hsmp_pdev->sock[sock_ind].proto_ver >= HSMP_PROTO_VER6)) {
+	     sock->proto_ver >= HSMP_PROTO_VER6)) {
 		ret = hsmp_get_tbl_dram_base(sock_ind);
 		if (ret)
 			dev_info(dev, "Failed to init metric table\n");
@@ -602,7 +605,7 @@ static int init_acpi(struct device *dev)
 			dev_info(dev, "Failed to register HSMP sensors with hwmon\n");
 	}
 
-	dev_set_drvdata(dev, &hsmp_pdev->sock[sock_ind]);
+	dev_set_drvdata(dev, sock);
 
 	return 0;
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 06/11] platform/x86/amd/hsmp: Move the sock_ind bounds check before validate_message()
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (4 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi() Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages Suma Hegde
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

Move validate_message() in hsmp_send_message_locked() to after the
socket index / hsmp_pdev.sock NULL checks and the existing sock->dev
readiness check, so an out-of-range or unready socket is rejected with
-ENODEV before validation runs.

The subsequent patch uses sock_ind inside validate_message().

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- Run validate_message() after the existing sock->dev readiness
  check, so an unready socket is rejected with -ENODEV before
  validation.
- Clarify the commit message accordingly; fix "bound" -> "bounds" in
  the subject.

 drivers/platform/x86/amd/hsmp/hsmp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index ad5b3fde54caf..9516cf182917b 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -351,9 +351,6 @@ static int hsmp_send_message_locked(struct hsmp_message *msg)
 
 	if (!msg)
 		return -EINVAL;
-	ret = validate_message(msg);
-	if (ret)
-		return ret;
 
 	if (!hsmp_pdev.sock || msg->sock_ind >= hsmp_pdev.num_sockets)
 		return -ENODEV;
@@ -381,6 +378,10 @@ static int hsmp_send_message_locked(struct hsmp_message *msg)
 	if (!smp_load_acquire(&sock->dev))
 		return -ENODEV;
 
+	ret = validate_message(msg);
+	if (ret)
+		return ret;
+
 	ret = down_interruptible(&sock->hsmp_sem);
 	if (ret < 0)
 		return ret;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (5 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 06/11] platform/x86/amd/hsmp: Move the sock_ind bounds check before validate_message() Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server Suma Hegde
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde, Dhruv Gupta

From: Suma Hegde <Suma.Hegde@amd.com>

The HSMP driver previously allowed sending any message defined in
amd_hsmp.h, including ones not supported on the running platform.

Add read and write bitmaps per socket to store which HSMP messages
are enabled on the platform. Add validation in validate_message()
to reject unsupported messages before they reach the SMU.

Key changes:
- Introduce enabled_read_msg_ids and enabled_write_msg_ids bitmaps in
  struct hsmp_socket.
- Add is_read_msg_enabled() and is_write_msg_enabled() helpers in
  hsmp.h.
- Use is_get_msg() to distinguish read and write HSMP messages.
- Mark HSMP_TEST, HSMP_GET_PROTO_VER, and HSMP_GET_SMU_VER as always
  enabled during bitmap initialization, as these cannot be masked by
  BIOS.
- Skip bitmap init, populate, and validation on client platforms; the
  client message set has no per-platform bitmaps yet.
- Skip hwmon registration on client platforms in the plat probe path.

Co-developed-by: Dhruv Gupta <dhruv.gupta@amd.com>
Signed-off-by: Dhruv Gupta <dhruv.gupta@amd.com>
Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- Express static bitmaps with named HSMP_MSG_BIT()/BIT() entries
  instead of opaque hex constants, and add blank lines after the
  array initializers.
- Update the 6th Gen AMD EPYC Server bitmaps: add
  HSMP_PQOS_TRAFFIC_PRIORITY and HSMP_PQOS_FLOATING_BW; drop
  HSMP_SET_XGMI_PSTATE_RANGE from the write bitmap.
- Soften the static-table comment so it does not forward-reference
  hsmp_set_default_msg_bitmap() before that helper exists.
- Skip hwmon registration on client platforms in the plat probe path.

 drivers/platform/x86/amd/hsmp/acpi.c |  13 ++
 drivers/platform/x86/amd/hsmp/hsmp.c | 312 +++++++++++++++++++++++++++
 drivers/platform/x86/amd/hsmp/hsmp.h |  27 +++
 drivers/platform/x86/amd/hsmp/plat.c |  23 +-
 4 files changed, 371 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index eee66825eb904..893ae7be05b4b 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -567,6 +567,11 @@ static int init_acpi(struct device *dev)
 
 	sock = &hsmp_pdev->sock[sock_ind];
 
+	if (!is_client_platform()) {
+		init_read_enabled_msg_bitmap(sock);
+		init_write_enabled_msg_bitmap(sock);
+	}
+
 	/* Test the hsmp interface */
 	ret = hsmp_test(sock_ind, 0xDEADBEEF);
 	if (ret) {
@@ -582,6 +587,14 @@ static int init_acpi(struct device *dev)
 		return ret;
 	}
 
+	if (!is_client_platform()) {
+		ret = hsmp_populate_msg_bitmaps(sock_ind);
+		if (ret) {
+			dev_err(dev, "Failed to get enabled HSMP messages on this platform\n");
+			return ret;
+		}
+	}
+
 	/*
 	 * proto_ver holds the Ryzen Master interface version on client
 	 * platforms, a separate numbering space from enum
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 9516cf182917b..085edd2ed3d6f 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -11,6 +11,8 @@
 
 #include <linux/acpi.h>
 #include <linux/array_size.h>
+#include <linux/bitmap.h>
+#include <linux/bits.h>
 #include <linux/build_bug.h>
 #include <linux/cleanup.h>
 #include <linux/compiler.h>
@@ -292,6 +294,8 @@ static int validate_message(struct hsmp_message *msg)
 {
 	const struct hsmp_plat_desc *plat_desc = hsmp_desc();
 	const struct hsmp_msg_desc *desc;
+	struct hsmp_socket *sock;
+	unsigned int sock_ind;
 
 	if (!plat_desc->msg_desc) {
 		/*
@@ -314,6 +318,17 @@ static int validate_message(struct hsmp_message *msg)
 	if (!desc)
 		return -ENOMSG;
 
+	sock_ind = array_index_nospec(msg->sock_ind, hsmp_pdev.num_sockets);
+	sock = &hsmp_pdev.sock[sock_ind];
+
+	if (is_get_msg(desc, msg)) {
+		if (!is_read_msg_enabled(sock, msg->msg_id))
+			return -ENOMSG;
+	} else {
+		if (!is_write_msg_enabled(sock, msg->msg_id))
+			return -ENOMSG;
+	}
+
 	/*
 	 * num_args passed by user should match the num_args specified in
 	 * message description table.
@@ -812,6 +827,303 @@ int hsmp_cache_proto_ver(u16 sock_ind)
 }
 EXPORT_SYMBOL_NS_GPL(hsmp_cache_proto_ver, "AMD_HSMP");
 
+/*
+ * Predefined read and write enabled-message bitmaps for platforms where
+ * HSMP_GET_ENABLED_HSMP_CMDS (37h) is not available. Each bit is the named
+ * HSMP_MSG_BIT(msg_id) for a supported message in that direction.
+ *
+ * Newer and future platforms that implement 37h do not need new entries
+ * here. Unknown family/model currently returns -ENODEV from
+ * hsmp_populate_msg_bitmaps(); a later patch adds a firmware query
+ * fallback for those platforms.
+ */
+#define HSMP_MSG_BIT(id)	BIT((unsigned int)(id) % 32)
+
+static const u32 read_bitmap_f19h_m00h_0fh[] = {
+	HSMP_MSG_BIT(HSMP_TEST) |
+	HSMP_MSG_BIT(HSMP_GET_SMU_VER) |
+	HSMP_MSG_BIT(HSMP_GET_PROTO_VER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT_MAX) |
+	HSMP_MSG_BIT(HSMP_GET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_PROC_HOT) |
+	HSMP_MSG_BIT(HSMP_GET_FCLK_MCLK) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_THROTTLE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_C0_PERCENT) |
+	HSMP_MSG_BIT(HSMP_GET_NBIO_DPM_LEVEL) |
+	HSMP_MSG_BIT(HSMP_GET_DDR_BANDWIDTH),
+	0,
+	0,
+};
+
+static const u32 write_bitmap_f19h_m00h_0fh[] = {
+	HSMP_MSG_BIT(HSMP_SET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT_SOCKET) |
+	HSMP_MSG_BIT(HSMP_SET_XGMI_LINK_WIDTH) |
+	HSMP_MSG_BIT(HSMP_SET_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_AUTO_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_NBIO_DPM_LEVEL),
+	0,
+	0,
+};
+
+static const u32 read_bitmap_zen4_variants[] = {
+	HSMP_MSG_BIT(HSMP_TEST) |
+	HSMP_MSG_BIT(HSMP_GET_SMU_VER) |
+	HSMP_MSG_BIT(HSMP_GET_PROTO_VER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT_MAX) |
+	HSMP_MSG_BIT(HSMP_GET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_PROC_HOT) |
+	HSMP_MSG_BIT(HSMP_GET_FCLK_MCLK) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_THROTTLE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_C0_PERCENT) |
+	HSMP_MSG_BIT(HSMP_GET_NBIO_DPM_LEVEL) |
+	HSMP_MSG_BIT(HSMP_GET_DDR_BANDWIDTH) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_TEMP_RANGE) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_THERMAL) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FREQ_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_CORE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_RAILS_SVI) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FMAX_FMIN) |
+	HSMP_MSG_BIT(HSMP_GET_IOLINK_BANDWITH) |
+	HSMP_MSG_BIT(HSMP_GET_XGMI_BANDWITH),
+	0,
+	0,
+};
+
+static const u32 write_bitmap_zen4_variants[] = {
+	HSMP_MSG_BIT(HSMP_SET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT_SOCKET) |
+	HSMP_MSG_BIT(HSMP_SET_XGMI_LINK_WIDTH) |
+	HSMP_MSG_BIT(HSMP_SET_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_AUTO_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_NBIO_DPM_LEVEL) |
+	HSMP_MSG_BIT(HSMP_SET_GMI3_WIDTH),
+	HSMP_MSG_BIT(HSMP_SET_PCI_RATE) |
+	HSMP_MSG_BIT(HSMP_SET_POWER_MODE) |
+	HSMP_MSG_BIT(HSMP_SET_PSTATE_MAX_MIN),
+	0,
+};
+
+static const u32 read_bitmap_f19h_m80h_9fh[] = {
+	HSMP_MSG_BIT(HSMP_TEST) |
+	HSMP_MSG_BIT(HSMP_GET_SMU_VER) |
+	HSMP_MSG_BIT(HSMP_GET_PROTO_VER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT_MAX) |
+	HSMP_MSG_BIT(HSMP_GET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_PROC_HOT) |
+	HSMP_MSG_BIT(HSMP_GET_FCLK_MCLK) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_THROTTLE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_C0_PERCENT) |
+	HSMP_MSG_BIT(HSMP_GET_NBIO_DPM_LEVEL) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FREQ_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_CORE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_RAILS_SVI) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FMAX_FMIN) |
+	HSMP_MSG_BIT(HSMP_GET_IOLINK_BANDWITH) |
+	HSMP_MSG_BIT(HSMP_GET_XGMI_BANDWITH),
+	HSMP_MSG_BIT(HSMP_GET_METRIC_TABLE_VER) |
+	HSMP_MSG_BIT(HSMP_GET_METRIC_TABLE) |
+	HSMP_MSG_BIT(HSMP_GET_METRIC_TABLE_DRAM_ADDR),
+	0,
+};
+
+static const u32 write_bitmap_f19h_m80h_9fh[] = {
+	HSMP_MSG_BIT(HSMP_SET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT_SOCKET) |
+	HSMP_MSG_BIT(HSMP_SET_NBIO_DPM_LEVEL),
+	0,
+	0,
+};
+
+static const u32 read_bitmap_f1ah_m00h_1fh[] = {
+	HSMP_MSG_BIT(HSMP_TEST) |
+	HSMP_MSG_BIT(HSMP_GET_SMU_VER) |
+	HSMP_MSG_BIT(HSMP_GET_PROTO_VER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT_MAX) |
+	HSMP_MSG_BIT(HSMP_GET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_PROC_HOT) |
+	HSMP_MSG_BIT(HSMP_GET_FCLK_MCLK) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_THROTTLE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_C0_PERCENT) |
+	HSMP_MSG_BIT(HSMP_GET_NBIO_DPM_LEVEL) |
+	HSMP_MSG_BIT(HSMP_GET_DDR_BANDWIDTH) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_TEMP_RANGE) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_THERMAL) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FREQ_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_CORE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_RAILS_SVI) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FMAX_FMIN) |
+	HSMP_MSG_BIT(HSMP_GET_IOLINK_BANDWITH) |
+	HSMP_MSG_BIT(HSMP_GET_XGMI_BANDWITH),
+	HSMP_MSG_BIT(HSMP_SET_POWER_MODE) |
+	HSMP_MSG_BIT(HSMP_CPU_RAIL_ISO_FREQ_POLICY) |
+	HSMP_MSG_BIT(HSMP_DFC_ENABLE_CTRL) |
+	HSMP_MSG_BIT(HSMP_GET_RAPL_UNITS) |
+	HSMP_MSG_BIT(HSMP_GET_RAPL_CORE_COUNTER) |
+	HSMP_MSG_BIT(HSMP_GET_RAPL_PACKAGE_COUNTER),
+	0,
+};
+
+static const u32 write_bitmap_f1ah_m00h_1fh[] = {
+	HSMP_MSG_BIT(HSMP_SET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT_SOCKET) |
+	HSMP_MSG_BIT(HSMP_SET_XGMI_LINK_WIDTH) |
+	HSMP_MSG_BIT(HSMP_SET_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_AUTO_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_NBIO_DPM_LEVEL) |
+	HSMP_MSG_BIT(HSMP_SET_GMI3_WIDTH),
+	HSMP_MSG_BIT(HSMP_SET_POWER_MODE) |
+	HSMP_MSG_BIT(HSMP_SET_PSTATE_MAX_MIN) |
+	HSMP_MSG_BIT(HSMP_SET_XGMI_PSTATE_RANGE) |
+	HSMP_MSG_BIT(HSMP_CPU_RAIL_ISO_FREQ_POLICY) |
+	HSMP_MSG_BIT(HSMP_DFC_ENABLE_CTRL),
+	0,
+};
+
+/*
+ * Family 0x1A model 0x50-0x5f, family 0x1A model 0xC0-0xCF,
+ * family 0x1A model 0x90-0x9B and family 0x1A model 0xA0-0xAB
+ * belong to 6th Gen AMD EPYC Server family.
+ */
+static const u32 read_bitmap_zen6_variants[] = {
+	HSMP_MSG_BIT(HSMP_TEST) |
+	HSMP_MSG_BIT(HSMP_GET_SMU_VER) |
+	HSMP_MSG_BIT(HSMP_GET_PROTO_VER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_POWER_LIMIT_MAX) |
+	HSMP_MSG_BIT(HSMP_GET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_PROC_HOT) |
+	HSMP_MSG_BIT(HSMP_SET_XGMI_LINK_WIDTH) |
+	HSMP_MSG_BIT(HSMP_SET_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_GET_FCLK_MCLK) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_THROTTLE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_C0_PERCENT) |
+	HSMP_MSG_BIT(HSMP_GET_NBIO_DPM_LEVEL) |
+	HSMP_MSG_BIT(HSMP_GET_DDR_BANDWIDTH) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_TEMP_RANGE) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_POWER) |
+	HSMP_MSG_BIT(HSMP_GET_DIMM_THERMAL) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FREQ_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_CCLK_CORE_LIMIT) |
+	HSMP_MSG_BIT(HSMP_GET_RAILS_SVI) |
+	HSMP_MSG_BIT(HSMP_GET_SOCKET_FMAX_FMIN) |
+	HSMP_MSG_BIT(HSMP_GET_IOLINK_BANDWITH) |
+	HSMP_MSG_BIT(HSMP_GET_XGMI_BANDWITH),
+	HSMP_MSG_BIT(HSMP_SET_POWER_MODE) |
+	HSMP_MSG_BIT(HSMP_SET_PSTATE_MAX_MIN) |
+	HSMP_MSG_BIT(HSMP_GET_METRIC_TABLE_VER) |
+	HSMP_MSG_BIT(HSMP_GET_METRIC_TABLE) |
+	HSMP_MSG_BIT(HSMP_GET_METRIC_TABLE_DRAM_ADDR) |
+	HSMP_MSG_BIT(HSMP_CPU_RAIL_ISO_FREQ_POLICY) |
+	HSMP_MSG_BIT(HSMP_DFC_ENABLE_CTRL) |
+	HSMP_MSG_BIT(HSMP_PC6_ENABLE) |
+	HSMP_MSG_BIT(HSMP_CC6_ENABLE) |
+	HSMP_MSG_BIT(HSMP_GET_RAPL_UNITS) |
+	HSMP_MSG_BIT(HSMP_GET_RAPL_CORE_COUNTER) |
+	HSMP_MSG_BIT(HSMP_GET_RAPL_PACKAGE_COUNTER) |
+	HSMP_MSG_BIT(HSMP_DIMM_SB_RD) |
+	HSMP_MSG_BIT(HSMP_READ_CCD_POWER) |
+	HSMP_MSG_BIT(HSMP_READ_TDELTA) |
+	HSMP_MSG_BIT(HSMP_GET_SVI3_VR_CTRL_TEMP) |
+	HSMP_MSG_BIT(HSMP_GET_ENABLED_HSMP_CMDS) |
+	HSMP_MSG_BIT(HSMP_SET_GET_FLOOR_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SDPS_LIMIT) |
+	HSMP_MSG_BIT(HSMP_PQOS_TRAFFIC_PRIORITY) |
+	HSMP_MSG_BIT(HSMP_PQOS_FLOATING_BW),
+	0,
+};
+
+static const u32 write_bitmap_zen6_variants[] = {
+	HSMP_MSG_BIT(HSMP_SET_SOCKET_POWER_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT) |
+	HSMP_MSG_BIT(HSMP_SET_BOOST_LIMIT_SOCKET) |
+	HSMP_MSG_BIT(HSMP_SET_XGMI_LINK_WIDTH) |
+	HSMP_MSG_BIT(HSMP_SET_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_AUTO_DF_PSTATE) |
+	HSMP_MSG_BIT(HSMP_SET_NBIO_DPM_LEVEL),
+	HSMP_MSG_BIT(HSMP_SET_POWER_MODE) |
+	HSMP_MSG_BIT(HSMP_SET_PSTATE_MAX_MIN) |
+	HSMP_MSG_BIT(HSMP_CPU_RAIL_ISO_FREQ_POLICY) |
+	HSMP_MSG_BIT(HSMP_DFC_ENABLE_CTRL) |
+	HSMP_MSG_BIT(HSMP_PC6_ENABLE) |
+	HSMP_MSG_BIT(HSMP_CC6_ENABLE) |
+	HSMP_MSG_BIT(HSMP_SET_GET_FLOOR_LIMIT) |
+	HSMP_MSG_BIT(HSMP_DIMM_SB_WR) |
+	HSMP_MSG_BIT(HSMP_SDPS_LIMIT) |
+	HSMP_MSG_BIT(HSMP_PQOS_TRAFFIC_PRIORITY) |
+	HSMP_MSG_BIT(HSMP_PQOS_FLOATING_BW),
+	0,
+};
+
+#define set_read_enabled_msg_bitmap(sock, src)	\
+	bitmap_from_arr32((sock)->enabled_read_msg_ids, (src), HSMP_MAX_MSGS)
+#define set_write_enabled_msg_bitmap(sock, src)	\
+	bitmap_from_arr32((sock)->enabled_write_msg_ids, (src), HSMP_MAX_MSGS)
+
+int hsmp_populate_msg_bitmaps(u16 sock_ind)
+{
+	struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
+
+	switch (boot_cpu_data.x86) {
+	case 0x19:
+		switch (boot_cpu_data.x86_model) {
+		case 0x00 ... 0x0F:
+			set_read_enabled_msg_bitmap(sock, read_bitmap_f19h_m00h_0fh);
+			set_write_enabled_msg_bitmap(sock, write_bitmap_f19h_m00h_0fh);
+			return 0;
+		case 0x10 ... 0x1F:
+		case 0xA0 ... 0xAF:
+			set_read_enabled_msg_bitmap(sock, read_bitmap_zen4_variants);
+			set_write_enabled_msg_bitmap(sock, write_bitmap_zen4_variants);
+			return 0;
+		case 0x80 ... 0x9F:
+			set_read_enabled_msg_bitmap(sock, read_bitmap_f19h_m80h_9fh);
+			set_write_enabled_msg_bitmap(sock, write_bitmap_f19h_m80h_9fh);
+			return 0;
+		}
+		break;
+	case 0x1A:
+		switch (boot_cpu_data.x86_model) {
+		case 0x00 ... 0x1F:
+			set_read_enabled_msg_bitmap(sock, read_bitmap_f1ah_m00h_1fh);
+			set_write_enabled_msg_bitmap(sock, write_bitmap_f1ah_m00h_1fh);
+			return 0;
+		case 0x50 ... 0x5F:
+		case 0x90 ... 0x9B:
+		case 0xA0 ... 0xAB:
+		case 0xC0 ... 0xCF:
+			set_read_enabled_msg_bitmap(sock, read_bitmap_zen6_variants);
+			set_write_enabled_msg_bitmap(sock, write_bitmap_zen6_variants);
+			/*
+			 * PC6 control (msg 0x29) is not supported from
+			 * protocol 0x70002 onwards on these models.
+			 */
+			if (sock->proto_ver >= 0x70002) {
+				clear_bit(HSMP_PC6_ENABLE, sock->enabled_read_msg_ids);
+				clear_bit(HSMP_PC6_ENABLE, sock->enabled_write_msg_ids);
+			}
+			return 0;
+		}
+	}
+	return -ENODEV;
+}
+EXPORT_SYMBOL_NS_GPL(hsmp_populate_msg_bitmaps, "AMD_HSMP");
+
 static const struct file_operations hsmp_fops = {
 	.owner		= THIS_MODULE,
 	.unlocked_ioctl	= hsmp_ioctl,
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index 5b05dcb074846..ee2bb95b66221 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -13,6 +13,8 @@
 #include <asm/amd/hsmp.h>
 
 #include <linux/acpi.h>
+#include <linux/bitmap.h>
+#include <linux/bitops.h>
 #include <linux/compiler_types.h>
 #include <linux/device.h>
 #include <linux/hwmon.h>
@@ -26,6 +28,8 @@
 #include <linux/sysfs.h>
 #include <linux/types.h>
 
+#define HSMP_MAX_MSGS			96
+
 #define HSMP_METRICS_TABLE_NAME	"metrics_bin"
 
 #define HSMP_ATTR_GRP_NAME_SIZE	10
@@ -78,6 +82,8 @@ struct hsmp_socket {
 	struct device *dev;
 	u16 sock_ind;
 	u32 proto_ver;
+	DECLARE_BITMAP(enabled_read_msg_ids, HSMP_MAX_MSGS);
+	DECLARE_BITMAP(enabled_write_msg_ids, HSMP_MAX_MSGS);
 	int (*amd_hsmp_rdwr)(struct hsmp_socket *sock, u32 off, u32 *val, bool rw);
 };
 
@@ -87,7 +93,28 @@ struct hsmp_plat_device {
 	u16 num_sockets;
 };
 
+/* HSMP_TEST, HSMP_GET_PROTO_VER, HSMP_GET_SMU_VER are always enabled in
+ * all the platforms and can't be masked by BIOS. Set those bits in the
+ * bitmap during bitmap initialization.
+ */
+#define init_read_enabled_msg_bitmap(sock)					\
+	do {									\
+		bitmap_zero((sock)->enabled_read_msg_ids, HSMP_MAX_MSGS);	\
+		bitmap_set((sock)->enabled_read_msg_ids, HSMP_TEST, 1);		\
+		bitmap_set((sock)->enabled_read_msg_ids, HSMP_GET_PROTO_VER, 1);\
+		bitmap_set((sock)->enabled_read_msg_ids, HSMP_GET_SMU_VER, 1);	\
+	} while (0)
+
+#define init_write_enabled_msg_bitmap(sock)	\
+	bitmap_zero((sock)->enabled_write_msg_ids, HSMP_MAX_MSGS)
+
+#define is_read_msg_enabled(sock, msg_id)	\
+	test_bit((msg_id), (sock)->enabled_read_msg_ids)
+#define is_write_msg_enabled(sock, msg_id)	\
+	test_bit((msg_id), (sock)->enabled_write_msg_ids)
+
 int hsmp_cache_proto_ver(u16 sock_ind);
+int hsmp_populate_msg_bitmaps(u16 sock_ind);
 int hsmp_test(u16 sock_ind, u32 value);
 long hsmp_ioctl(struct file *fp, unsigned int cmd, unsigned long arg);
 void hsmp_misc_deregister(void);
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index 40c98d9c66d4f..a0b1cac8225bc 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -178,6 +178,11 @@ static int init_platform_device(struct device *dev)
 		sock->mbinfo.msg_arg_off	= SMN_HSMP_MSG_DATA;
 		sema_init(&sock->hsmp_sem, 1);
 
+		if (!is_client_platform()) {
+			init_read_enabled_msg_bitmap(sock);
+			init_write_enabled_msg_bitmap(sock);
+		}
+
 		/* Test the hsmp interface on each socket */
 		ret = hsmp_test(i, 0xDEADBEEF);
 		if (ret) {
@@ -193,16 +198,26 @@ static int init_platform_device(struct device *dev)
 			return ret;
 		}
 
+		if (!is_client_platform()) {
+			ret = hsmp_populate_msg_bitmaps(i);
+			if (ret) {
+				dev_err(dev, "Failed to get enabled HSMP messages on this platform\n");
+				return ret;
+			}
+		}
+
 		if (sock->proto_ver == HSMP_PROTO_VER6) {
 			ret = hsmp_get_tbl_dram_base(i);
 			if (ret)
 				dev_info(dev, "Failed to init metric table\n");
 		}
 
-		/* Register with hwmon interface for reporting power */
-		ret = hsmp_create_sensor(dev, i);
-		if (ret)
-			dev_info(dev, "Failed to register HSMP sensors with hwmon\n");
+		/* Skip hwmon registration on client platforms */
+		if (!is_client_platform()) {
+			ret = hsmp_create_sensor(dev, i);
+			if (ret)
+				dev_info(dev, "Failed to register HSMP sensors with hwmon\n");
+		}
 	}
 
 	return 0;
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (6 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms Suma Hegde
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

HSMP_GET_ENABLED_HSMP_CMDS(0x37) returns the read/get and write/set
messages supported on the running platform, and correctly reflects
BIOS-masked messages in its bitmap.

6th Gen AMD EPYC Server supports this HSMP_GET_ENABLED_HSMP_CMDS
message. On this generation, SMU returns only BIOS-masked message
info, so AND the firmware bitmap with the static table. If the
firmware query fails, keep the static bitmap.

Use hsmp_send_message_locked() when fetching the bitmaps during probe,
as the caller already holds hsmp_sock_rwsem for write.

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- Replace separate read/write fetch helpers with a single
  hsmp_fetch_enabled_msgs() helper parameterized by mask select.
- Clarify the commit message: zen6 AND-with-static workaround, and
  keep the static bitmap if the firmware query fails.

 drivers/platform/x86/amd/hsmp/hsmp.c | 47 ++++++++++++++++++++++++++++
 1 file changed, 47 insertions(+)

diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 085edd2ed3d6f..ccd874334468e 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -1075,6 +1075,52 @@ static const u32 write_bitmap_zen6_variants[] = {
 #define set_write_enabled_msg_bitmap(sock, src)	\
 	bitmap_from_arr32((sock)->enabled_write_msg_ids, (src), HSMP_MAX_MSGS)
 
+#define HSMP_GET_ENABLED_CMD_READ_MASK	1
+#define HSMP_GET_ENABLED_CMD_WRITE_MASK	0
+
+static int hsmp_fetch_enabled_msgs(u16 sock_ind, u32 mask_sel, unsigned long *msg_bmap)
+{
+	struct hsmp_message msg = {};
+	int ret;
+
+	msg.msg_id      = HSMP_GET_ENABLED_HSMP_CMDS;
+	msg.num_args    = hsmp_msg_desc_table[HSMP_GET_ENABLED_HSMP_CMDS].num_args;
+	msg.response_sz = hsmp_msg_desc_table[HSMP_GET_ENABLED_HSMP_CMDS].response_sz;
+	msg.args[0]     = mask_sel;
+	msg.sock_ind    = sock_ind;
+	ret = hsmp_send_message_locked(&msg);
+	if (!ret)
+		bitmap_from_arr32(msg_bmap, msg.args, HSMP_MAX_MSGS);
+
+	return ret;
+}
+
+static void hsmp_dynamic_bitmap_zen6(u16 sock_ind)
+{
+	struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
+	DECLARE_BITMAP(read_msgs_bmap, HSMP_MAX_MSGS);
+	DECLARE_BITMAP(write_msgs_bmap, HSMP_MAX_MSGS);
+
+	bitmap_zero(read_msgs_bmap, HSMP_MAX_MSGS);
+	bitmap_zero(write_msgs_bmap, HSMP_MAX_MSGS);
+	/*
+	 * On 6th Gen AMD EPYC Server variants, the SMU firmware only reports
+	 * which features are disabled by BIOS — all other bits are set to 1.
+	 * Combine the static bitmap with the SMU-returned bitmap using
+	 * bitwise AND to produce the correct feature mask.
+	 */
+	if (!hsmp_fetch_enabled_msgs(sock_ind, HSMP_GET_ENABLED_CMD_READ_MASK, read_msgs_bmap)) {
+		bitmap_and(read_msgs_bmap, read_msgs_bmap,
+			   sock->enabled_read_msg_ids, HSMP_MAX_MSGS);
+		bitmap_copy(sock->enabled_read_msg_ids, read_msgs_bmap, HSMP_MAX_MSGS);
+	}
+	if (!hsmp_fetch_enabled_msgs(sock_ind, HSMP_GET_ENABLED_CMD_WRITE_MASK, write_msgs_bmap)) {
+		bitmap_and(write_msgs_bmap, write_msgs_bmap,
+			   sock->enabled_write_msg_ids, HSMP_MAX_MSGS);
+		bitmap_copy(sock->enabled_write_msg_ids, write_msgs_bmap, HSMP_MAX_MSGS);
+	}
+}
+
 int hsmp_populate_msg_bitmaps(u16 sock_ind)
 {
 	struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
@@ -1117,6 +1163,7 @@ int hsmp_populate_msg_bitmaps(u16 sock_ind)
 				clear_bit(HSMP_PC6_ENABLE, sock->enabled_read_msg_ids);
 				clear_bit(HSMP_PC6_ENABLE, sock->enabled_write_msg_ids);
 			}
+			hsmp_dynamic_bitmap_zen6(sock_ind);
 			return 0;
 		}
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (7 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities Suma Hegde
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

Future AMD server platforms are expected to support the
HSMP_GET_ENABLED_HSMP_CMDS (0x37) message for reporting
which HSMP messages are available. This also handles
detection of BIOS-enabled and BIOS-disabled messages.
Instead of returning -ENODEV when no static bitmap
matches the running CPU family/model, fall back to
dynamically querying the enabled read and write message
bitmaps via 0x37.

Add hsmp_set_default_msg_bitmap() which temporarily enables the
HSMP_GET_ENABLED_HSMP_CMDS bit so that validate_message() allows
the query, then fetches the read and write bitmaps from the
firmware.

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- In hsmp_set_default_msg_bitmap(), fetch data into temporary
  bitmaps, query the write mask before committing the read mask, and
  force-enable HSMP_TEST / PROTO_VER / SMU_VER / GET_ENABLED_HSMP_CMDS.

 drivers/platform/x86/amd/hsmp/hsmp.c | 51 +++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index ccd874334468e..937e7168adef9 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -833,9 +833,8 @@ EXPORT_SYMBOL_NS_GPL(hsmp_cache_proto_ver, "AMD_HSMP");
  * HSMP_MSG_BIT(msg_id) for a supported message in that direction.
  *
  * Newer and future platforms that implement 37h do not need new entries
- * here. Unknown family/model currently returns -ENODEV from
- * hsmp_populate_msg_bitmaps(); a later patch adds a firmware query
- * fallback for those platforms.
+ * here: hsmp_populate_msg_bitmaps() falls back to querying the firmware
+ * via hsmp_set_default_msg_bitmap() when no static table matches.
  */
 #define HSMP_MSG_BIT(id)	BIT((unsigned int)(id) % 32)
 
@@ -1095,6 +1094,50 @@ static int hsmp_fetch_enabled_msgs(u16 sock_ind, u32 mask_sel, unsigned long *ms
 	return ret;
 }
 
+static int hsmp_set_default_msg_bitmap(u16 sock_ind)
+{
+	struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
+	DECLARE_BITMAP(read_msgs_bmap, HSMP_MAX_MSGS);
+	DECLARE_BITMAP(write_msgs_bmap, HSMP_MAX_MSGS);
+	int ret;
+
+	/* Set HSMP_GET_ENABLED_HSMP_CMDS bit to ensure validate_message() doesn't fail */
+	bitmap_set(sock->enabled_read_msg_ids, HSMP_GET_ENABLED_HSMP_CMDS, 1);
+
+	ret = hsmp_fetch_enabled_msgs(sock_ind, HSMP_GET_ENABLED_CMD_READ_MASK, read_msgs_bmap);
+	if (ret)
+		return ret;
+
+	/*
+	 * Fetch the write mask before committing the read mask to
+	 * sock->enabled_read_msg_ids: both queries use
+	 * HSMP_GET_ENABLED_HSMP_CMDS, so if the fetched read mask happened
+	 * to clear that message's own bit, committing it early would make
+	 * validate_message() reject this write query.
+	 */
+	ret = hsmp_fetch_enabled_msgs(sock_ind, HSMP_GET_ENABLED_CMD_WRITE_MASK, write_msgs_bmap);
+	if (ret)
+		return ret;
+
+	/*
+	 * HSMP_TEST, HSMP_GET_PROTO_VER and HSMP_GET_SMU_VER can't be masked
+	 * by BIOS (see init_read_enabled_msg_bitmap()), and this function
+	 * itself depends on HSMP_GET_ENABLED_HSMP_CMDS being read-enabled.
+	 * Keep all four set regardless of what firmware's reply says, so a
+	 * firmware that omits them from its reply doesn't break later
+	 * users of these messages.
+	 */
+	bitmap_set(read_msgs_bmap, HSMP_TEST, 1);
+	bitmap_set(read_msgs_bmap, HSMP_GET_PROTO_VER, 1);
+	bitmap_set(read_msgs_bmap, HSMP_GET_SMU_VER, 1);
+	bitmap_set(read_msgs_bmap, HSMP_GET_ENABLED_HSMP_CMDS, 1);
+
+	bitmap_copy(sock->enabled_read_msg_ids, read_msgs_bmap, HSMP_MAX_MSGS);
+	bitmap_copy(sock->enabled_write_msg_ids, write_msgs_bmap, HSMP_MAX_MSGS);
+
+	return 0;
+}
+
 static void hsmp_dynamic_bitmap_zen6(u16 sock_ind)
 {
 	struct hsmp_socket *sock = &hsmp_pdev.sock[sock_ind];
@@ -1167,7 +1210,7 @@ int hsmp_populate_msg_bitmaps(u16 sock_ind)
 			return 0;
 		}
 	}
-	return -ENODEV;
+	return hsmp_set_default_msg_bitmap(sock_ind);
 }
 EXPORT_SYMBOL_NS_GPL(hsmp_populate_msg_bitmaps, "AMD_HSMP");
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (8 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  2026-11-19  8:50 ` [PATCH v2 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities Suma Hegde
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

Move the to_hsmp_sys_attr() macro definition above
hsmp_is_sock_attr_visible() so it is available before its first use
in a subsequent patch that adds bitmap based visibility checks.

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- None.

 drivers/platform/x86/amd/hsmp/acpi.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 893ae7be05b4b..a9d6da5572a39 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -292,6 +292,8 @@ static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj
 	return hsmp_metric_tbl_read(sock, buf, count);
 }
 
+#define to_hsmp_sys_attr(_attr) container_of(_attr, struct hsmp_sys_attr, dattr)
+
 static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
 					 const struct bin_attribute *battr, int id)
 {
@@ -335,8 +337,6 @@ static umode_t hsmp_is_sock_dev_attr_visible(struct kobject *kobj,
 	return attr->mode;
 }
 
-#define to_hsmp_sys_attr(_attr) container_of(_attr, struct hsmp_sys_attr, dattr)
-
 static ssize_t hsmp_msg_resp32_show(struct device *dev, struct device_attribute *attr,
 				    char *buf)
 {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH v2 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities
  2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
                   ` (9 preceding siblings ...)
  2026-11-19  8:50 ` [PATCH v2 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro Suma Hegde
@ 2026-11-19  8:50 ` Suma Hegde
  10 siblings, 0 replies; 12+ messages in thread
From: Suma Hegde @ 2026-11-19  8:50 UTC (permalink / raw)
  To: platform-driver-x86
  Cc: ilpo.jarvinen, Muthusamy.Ramalingam, NaveenKrishna.Chatradhi,
	Anand.Umarji, Suma Hegde

From: Suma Hegde <Suma.Hegde@amd.com>

HSMP messages can be read-only, write-only, or read-write. The set of
supported operations varies across AMD platforms. Older platforms may
only support write, while newer ones support both read and write.

Currently, sysfs and hwmon files are created with a fixed mode based on
what the latest platform supports, regardless of what the running
platform actually provides.

Update the sysfs visibility callback hsmp_is_sock_dev_attr_visible()
to check the per-socket read/write enabled message bitmaps and return
only the permission bits corresponding to operations supported on the
running platform. For files that are both readable and writable, each
direction is checked independently so the mode reflects actual support.

Apply the same logic to the hwmon visibility callback
hsmp_hwmon_is_visble(). Check the enabled bitmaps and
return the updated mode for each power attribute.

On client platforms, keep fixed modes for the shared smu_fw_version and
protocol_version attributes and hide the rest; client platforms have no
enabled-message bitmaps yet.

Co-developed-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <Muthusamy.Ramalingam@amd.com>
Signed-off-by: Suma Hegde <Suma.Hegde@amd.com>
---

Changes since v1:
- Keep the existing short client-attribute visibility comment instead
  of replacing it with the longer message-table comment.

 drivers/platform/x86/amd/hsmp/acpi.c  | 49 +++++++++++++++++++++++++--
 drivers/platform/x86/amd/hsmp/hwmon.c | 24 +++++++++++--
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index a9d6da5572a39..52e77c8bda58b 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -16,6 +16,7 @@
 #include <linux/bits.h>
 #include <linux/bitfield.h>
 #include <linux/cleanup.h>
+#include <linux/container_of.h>
 #include <linux/device.h>
 #include <linux/dev_printk.h>
 #include <linux/ioport.h>
@@ -329,12 +330,54 @@ static struct hsmp_sys_attr hattr_protocol_version;
 static umode_t hsmp_is_sock_dev_attr_visible(struct kobject *kobj,
 					     struct attribute *attr, int id)
 {
+	struct device_attribute *dattr = container_of(attr, struct device_attribute, attr);
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(dattr);
+	struct device *dev = kobj_to_dev(kobj);
+	umode_t mode = attr->mode;
+	umode_t mode_updated = 0;
+	struct hsmp_socket *sock;
+	bool readable, writable;
+
 	/* Hide every attribute except smu_fw_version and protocol_version on client platforms */
-	if (is_client_platform() && attr != &hattr_smu_fw_version.dattr.attr &&
-	    attr != &hattr_protocol_version.dattr.attr)
+	if (is_client_platform()) {
+		if (attr == &hattr_smu_fw_version.dattr.attr ||
+		    attr == &hattr_protocol_version.dattr.attr)
+			return mode;
 		return 0;
+	}
+
+	sock = dev_get_drvdata(dev);
+	if (!sock)
+		return 0;
+
+	readable = !!(mode & 0444);
+	writable = !!(mode & 0200);
 
-	return attr->mode;
+	/*
+	 * File is both readable and writeable. Some platforms support only set/write operation.
+	 * Some platforms support only get/read operation. Update the file mode accordingly.
+	 */
+	if (readable && writable) {
+		if (is_read_msg_enabled(sock, hattr->msg_id))
+			mode_updated |= mode & 0444;
+		if (is_write_msg_enabled(sock, hattr->msg_id))
+			mode_updated |= 0200;
+		return mode_updated;
+	}
+
+	/* Read-only attribute */
+	if (readable) {
+		if (is_read_msg_enabled(sock, hattr->msg_id))
+			return mode;
+	}
+
+	/* Write-only attribute */
+	if (writable) {
+		if (is_write_msg_enabled(sock, hattr->msg_id))
+			return mode;
+	}
+
+	return 0;
 }
 
 static ssize_t hsmp_msg_resp32_show(struct device *dev, struct device_attribute *attr,
diff --git a/drivers/platform/x86/amd/hsmp/hwmon.c b/drivers/platform/x86/amd/hsmp/hwmon.c
index c8314eee06f4f..b0da511f03774 100644
--- a/drivers/platform/x86/amd/hsmp/hwmon.c
+++ b/drivers/platform/x86/amd/hsmp/hwmon.c
@@ -80,16 +80,34 @@ static umode_t hsmp_hwmon_is_visble(const void *data,
 				    enum hwmon_sensor_types type,
 				    u32 attr, int channel)
 {
+	struct hsmp_plat_device *pdev = get_hsmp_pdev();
+	u16 sock_ind = (uintptr_t)data;
+	struct hsmp_socket *sock;
+	umode_t mode_updated = 0;
+
+	if (!pdev || !pdev->sock || sock_ind >= pdev->num_sockets)
+		return 0;
+
+	sock = &pdev->sock[sock_ind];
+
 	if (type != hwmon_power)
 		return 0;
 
 	switch (attr) {
 	case hwmon_power_input:
-		return 0444;
+		if (is_read_msg_enabled(sock, HSMP_GET_SOCKET_POWER))
+			mode_updated |= 0444;
+		return mode_updated;
 	case hwmon_power_cap:
-		return 0644;
+		if (is_read_msg_enabled(sock, HSMP_GET_SOCKET_POWER_LIMIT))
+			mode_updated |= 0444;
+		if (is_write_msg_enabled(sock, HSMP_SET_SOCKET_POWER_LIMIT))
+			mode_updated |= 0200;
+		return mode_updated;
 	case hwmon_power_cap_max:
-		return 0444;
+		if (is_read_msg_enabled(sock, HSMP_GET_SOCKET_POWER_LIMIT_MAX))
+			mode_updated |= 0444;
+		return mode_updated;
 	default:
 		return 0;
 	}
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-19  8:51 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19  8:50 [PATCH v2 00/11] platform/x86/amd/hsmp: Per-platform enabled-message bitmaps Suma Hegde
2026-11-19  8:50 ` [PATCH v2 01/11] platform/x86/amd/hsmp: Fix sock_ind bounds check in hsmp_is_sock_attr_visible() Suma Hegde
2026-11-19  8:50 ` [PATCH v2 02/11] platform/x86/amd/hsmp: Move proto_ver to hsmp_socket structure Suma Hegde
2026-11-19  8:50 ` [PATCH v2 03/11] platform/x86/amd/hsmp: Null-check drvdata in hsmp_is_sock_attr_visible() Suma Hegde
2026-11-19  8:50 ` [PATCH v2 04/11] platform/x86/amd/hsmp: Move is_get_msg() before validate_message() Suma Hegde
2026-11-19  8:50 ` [PATCH v2 05/11] platform/x86/amd/hsmp: Use local sock pointer in init_acpi() Suma Hegde
2026-11-19  8:50 ` [PATCH v2 06/11] platform/x86/amd/hsmp: Move the sock_ind bounds check before validate_message() Suma Hegde
2026-11-19  8:50 ` [PATCH v2 07/11] platform/x86/amd/hsmp: Add per-platform bitmap to validate HSMP messages Suma Hegde
2026-11-19  8:50 ` [PATCH v2 08/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically on 6th Gen AMD EPYC Server Suma Hegde
2026-11-19  8:50 ` [PATCH v2 09/11] platform/x86/amd/hsmp: Populate the bitmaps dynamically for future platforms Suma Hegde
2026-11-19  8:50 ` [PATCH v2 10/11] platform/x86/amd/hsmp: Relocate to_hsmp_sys_attr() macro Suma Hegde
2026-11-19  8:50 ` [PATCH v2 11/11] platform/x86/amd/hsmp: Update sysfs and hwmon file modes based on platform capabilities Suma Hegde

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox