mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2 0/5] platform/x86/amd/hsmp: Unify per-socket sysfs metrics
@ 2026-11-16 15:51 Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 1/5] platform/x86/amd/hsmp: Move per-socket sysfs attributes to common code Erwan Velu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Erwan Velu @ 2026-11-16 15:51 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi, Ilpo Järvinen, Hans de Goede
  Cc: Carlos Bilbao, Muralidhara M K, Suma Hegde, Muthusamy Ramalingam,
	platform-driver-x86, linux-kernel, Erwan Velu

From: Erwan Velu <e.velu@criteo.com>

The goal of this series is to ease server monitoring, by exposing the
HSMP metrics the same way whatever the driver, in a format that is
straightforward to integrate in metrics exporters.

The per-socket HSMP telemetry attributes (c0_residency_input,
ddr_max_bw, pwr_current_active_freq_limit, ...) are only implemented by
the ACPI driver, although they are plain HSMP messages the platform
driver can send as well. Systems probed by the platform driver therefore
only get metrics_bin.

Their location also depends on the driver: AMDI0097:0X with the ACPI
driver, amd_hsmp/socketN with the platform one. "modprobe amd_hsmp"
picks the right driver, but userspace cannot know in advance which tree
it has to read.

This series moves the attributes to common code and adds an amd_hsmp
class with one socketN device per socket, registered by both drivers.
/sys/class/amd_hsmp/socketN/ is then the same path whichever driver
probed. The existing ACPI and platform sysfs paths keep working.

Patch 1 is a pure code move. Patch 2 adds the class and wires it in the
ACPI driver, patch 3 does the same for the platform driver. Patch 4
exposes the pwr_current_active_freq_limit_source bitmask as a single
hexadecimal value, whose interpretation can be centralized in the
monitoring stack (e.g. Grafana value mappings). Patch 5 documents
/sys/class/amd_hsmp in Documentation/ABI/testing.

This v2 reworks patches 2 and 3 following Carlos' review of v1, and is
meant as a basis for discussion: I would rather know early whether this
is heading in the right direction, in particular for the class approach
and the AMDI0097:0X ABI question raised in the v1 thread, before
polishing it further.

Changes in v2:
- Replace the separate /sys/devices/amd_hsmp tree, its root device and
  its hand-rolled refcount by an amd_hsmp class, as suggested by Carlos.
  The kref.h remark from Ilpo no longer applies, as there is no shared
  object to refcount anymore.
- Platform driver: the socket devices replace the bare socketN
  attribute groups. As class devices land in an amd_hsmp glue directory
  below their parent, a socketN symlink keeps the existing
  /sys/devices/platform/amd_hsmp/socketN/metrics_bin path working.
- New patch 5: Documentation/ABI/testing/sysfs-class-amd_hsmp.
  Its content depends on the AMDI0097:0X ABI discussion with Carlos in
  the v1 thread, and can be dropped or reworked accordingly.
- Collected Acked-by from Carlos on patches 1 and 4.
- Rebased on v7.4-rc3.

Tested on a Zen4 (Family 19h, HSMP protocol 5) server with the platform
driver, and on a dual socket Zen5 (Family 1Ah) server with the ACPI
driver: attributes read through /sys/class/amd_hsmp, legacy paths
still working, and 20 unload/reload cycles of the driver while reading
the attributes in a loop.

v1: https://lore.kernel.org/platform-driver-x86/20261007125908.321186-1-erwanaliasr1@gmail.com/

Erwan Velu (5):
  platform/x86/amd/hsmp: Move per-socket sysfs attributes to common code
  platform/x86/amd/hsmp: Add amd_hsmp class with per-socket devices
  platform/x86/amd/hsmp: Expose socket attributes from the platform
    driver
  platform/x86/amd/hsmp: Add pwr_current_active_freq_limit_source_raw
  Documentation/ABI: Add sysfs-class-amd_hsmp

 .../ABI/testing/sysfs-class-amd_hsmp          | 120 +++++
 Documentation/arch/x86/amd_hsmp.rst           |  24 +-
 MAINTAINERS                                   |   1 +
 drivers/platform/x86/amd/hsmp/Makefile        |   2 +-
 drivers/platform/x86/amd/hsmp/acpi.c          | 345 +-------------
 drivers/platform/x86/amd/hsmp/hsmp.c          |  19 +
 drivers/platform/x86/amd/hsmp/hsmp.h          |   8 +
 drivers/platform/x86/amd/hsmp/plat.c          | 155 +++----
 drivers/platform/x86/amd/hsmp/sysfs.c         | 435 ++++++++++++++++++
 9 files changed, 681 insertions(+), 428 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-class-amd_hsmp
 create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.c


base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.53.0


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

* [PATCH v2 1/5] platform/x86/amd/hsmp: Move per-socket sysfs attributes to common code
  2026-11-16 15:51 [PATCH v2 0/5] platform/x86/amd/hsmp: Unify per-socket sysfs metrics Erwan Velu
@ 2026-11-16 15:51 ` Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 2/5] platform/x86/amd/hsmp: Add amd_hsmp class with per-socket devices Erwan Velu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Erwan Velu @ 2026-11-16 15:51 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi, Ilpo Järvinen, Hans de Goede
  Cc: Carlos Bilbao, Muralidhara M K, Suma Hegde, Muthusamy Ramalingam,
	platform-driver-x86, linux-kernel, Erwan Velu

From: Erwan Velu <e.velu@criteo.com>

The per-socket telemetry attributes (c0_residency_input, ddr_max_bw,
pwr_current_active_freq_limit, ...) are implemented in acpi.c, so only
the ACPI driver can expose them, although they are plain HSMP messages
the platform driver can send as well.

Move them to a new sysfs.c in hsmp_common and export the attribute
groups as hsmp_sock_groups, so they can be shared by both drivers. The
ACPI driver keeps exposing them on its socket devices via dev_groups.

No functional change.

Assisted-by: claude-opus-5-5
Acked-by: Carlos Bilbao <carlos.bilbao@kernel.org>
Signed-off-by: Erwan Velu <e.velu@criteo.com>
---
 drivers/platform/x86/amd/hsmp/Makefile |   2 +-
 drivers/platform/x86/amd/hsmp/acpi.c   | 331 +----------------------
 drivers/platform/x86/amd/hsmp/hsmp.h   |   1 +
 drivers/platform/x86/amd/hsmp/sysfs.c  | 348 +++++++++++++++++++++++++
 4 files changed, 351 insertions(+), 331 deletions(-)
 create mode 100644 drivers/platform/x86/amd/hsmp/sysfs.c

diff --git a/drivers/platform/x86/amd/hsmp/Makefile b/drivers/platform/x86/amd/hsmp/Makefile
index ce8342e71f50..21fc1d185550 100644
--- a/drivers/platform/x86/amd/hsmp/Makefile
+++ b/drivers/platform/x86/amd/hsmp/Makefile
@@ -5,7 +5,7 @@
 #
 
 obj-$(CONFIG_AMD_HSMP)			+= hsmp_common.o
-hsmp_common-y				:= hsmp.o
+hsmp_common-y				:= hsmp.o sysfs.o
 hsmp_common-$(CONFIG_HWMON)		+= hwmon.o
 obj-$(CONFIG_AMD_HSMP_PLAT)		+= amd_hsmp.o
 amd_hsmp-y				:= plat.o
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 167c76c13ad0..a1e13aff9c86 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -12,9 +12,6 @@
 #include <asm/amd/hsmp.h>
 
 #include <linux/acpi.h>
-#include <linux/array_size.h>
-#include <linux/bits.h>
-#include <linux/bitfield.h>
 #include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/dev_printk.h>
@@ -27,7 +24,6 @@
 #include <linux/rwsem.h>
 #include <linux/slab.h>
 #include <linux/string.h>
-#include <linux/sysfs.h>
 #include <linux/topology.h>
 #include <linux/uuid.h>
 
@@ -55,11 +51,6 @@ static struct hsmp_plat_device *hsmp_pdev;
  */
 static struct kref hsmp_acpi_sock_kref;
 
-struct hsmp_sys_attr {
-	struct device_attribute dattr;
-	u32 msg_id;
-};
-
 static int amd_hsmp_acpi_rdwr(struct hsmp_socket *sock, u32 offset,
 			      u32 *value, bool write)
 {
@@ -270,262 +261,6 @@ static int hsmp_parse_acpi_table(struct device *dev, u16 sock_ind)
 	return 0;
 }
 
-static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj,
-					 const struct bin_attribute *bin_attr, char *buf,
-					 loff_t off, size_t count)
-{
-	struct device *dev = container_of(kobj, struct device, kobj);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-
-	/*
-	 * metrics_bin is a sysfs binary attribute and is capped at PAGE_SIZE.
-	 * It can therefore only carry the protocol version 6 metric table
-	 * (struct hsmp_metric_table).  The larger tables defined from protocol
-	 * version 7 onwards do not fit; userspace on those systems must read
-	 * the snapshot through HSMP_IOCTL_GET_TELEMETRY_DATA on /dev/hsmp.
-	 * Surface the unsupported case here as -EOPNOTSUPP rather than
-	 * silently truncating the snapshot.
-	 */
-	if (hsmp_pdev->proto_ver != HSMP_PROTO_VER6)
-		return -EOPNOTSUPP;
-
-	return hsmp_metric_tbl_read(sock, buf, count);
-}
-
-static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
-					 const struct bin_attribute *battr, int id)
-{
-	/*
-	 * Keep metrics_bin visible on protocol version 7 and later as well,
-	 * so that userspace which expects the file to exist gets a clear
-	 * -EOPNOTSUPP from the read handler instead of -ENOENT, and is
-	 * 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)
-		return battr->attr.mode;
-
-	return 0;
-}
-
-/* Defined below by HSMP_DEV_ATTR() */
-static struct hsmp_sys_attr hattr_smu_fw_version;
-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)
-{
-	/* 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)
-		return 0;
-
-	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)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%u\n", data);
-}
-
-#define DDR_MAX_BW_MASK		GENMASK(31, 20)
-#define DDR_UTIL_BW_MASK	GENMASK(19, 8)
-#define DDR_UTIL_BW_PERC_MASK	GENMASK(7, 0)
-#define FW_VER_MAJOR_MASK	GENMASK(23, 16)
-#define FW_VER_MINOR_MASK	GENMASK(15, 8)
-#define FW_VER_DEBUG_MASK	GENMASK(7, 0)
-#define FMAX_MASK		GENMASK(31, 16)
-#define FMIN_MASK		GENMASK(15, 0)
-#define FREQ_LIMIT_MASK		GENMASK(31, 16)
-#define FREQ_SRC_IND_MASK	GENMASK(15, 0)
-
-static ssize_t hsmp_ddr_max_bw_show(struct device *dev, struct device_attribute *attr,
-				    char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%lu\n", FIELD_GET(DDR_MAX_BW_MASK, data));
-}
-
-static ssize_t hsmp_ddr_util_bw_show(struct device *dev, struct device_attribute *attr,
-				     char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%lu\n", FIELD_GET(DDR_UTIL_BW_MASK, data));
-}
-
-static ssize_t hsmp_ddr_util_bw_perc_show(struct device *dev, struct device_attribute *attr,
-					  char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%lu\n", FIELD_GET(DDR_UTIL_BW_PERC_MASK, data));
-}
-
-static ssize_t hsmp_msg_fw_ver_show(struct device *dev, struct device_attribute *attr,
-				    char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%lu.%lu.%lu\n",
-			  FIELD_GET(FW_VER_MAJOR_MASK, data),
-			  FIELD_GET(FW_VER_MINOR_MASK, data),
-			  FIELD_GET(FW_VER_DEBUG_MASK, data));
-}
-
-static ssize_t hsmp_fclk_show(struct device *dev, struct device_attribute *attr,
-			      char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data[2];
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, data, 2);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%u\n", data[0]);
-}
-
-static ssize_t hsmp_mclk_show(struct device *dev, struct device_attribute *attr,
-			      char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data[2];
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, data, 2);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%u\n", data[1]);
-}
-
-static ssize_t hsmp_clk_fmax_show(struct device *dev, struct device_attribute *attr,
-				  char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%lu\n", FIELD_GET(FMAX_MASK, data));
-}
-
-static ssize_t hsmp_clk_fmin_show(struct device *dev, struct device_attribute *attr,
-				  char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%lu\n", FIELD_GET(FMIN_MASK, data));
-}
-
-static ssize_t hsmp_freq_limit_show(struct device *dev, struct device_attribute *attr,
-				    char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	return sysfs_emit(buf, "%lu\n", FIELD_GET(FREQ_LIMIT_MASK, data));
-}
-
-static const char * const freqlimit_srcnames[] = {
-	"cHTC-Active",
-	"PROCHOT",
-	"TDC limit",
-	"PPT Limit",
-	"OPN Max",
-	"Reliability Limit",
-	"APML Agent",
-	"HSMP Agent",
-};
-
-static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_attribute *attr,
-					   char *buf)
-{
-	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
-	struct hsmp_socket *sock = dev_get_drvdata(dev);
-	unsigned int index;
-	int len = 0;
-	u16 src_ind;
-	u32 data;
-	int ret;
-
-	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
-	if (ret)
-		return ret;
-
-	src_ind = FIELD_GET(FREQ_SRC_IND_MASK, data);
-	for (index = 0; index < ARRAY_SIZE(freqlimit_srcnames); index++) {
-		if (!src_ind)
-			break;
-		if (src_ind & 1)
-			len += sysfs_emit_at(buf, len, "%s\n", freqlimit_srcnames[index]);
-		src_ind >>= 1;
-	}
-	return len;
-}
-
 /*
  * Bring up one ACPI HSMP socket: parse its ACPI table, run the mailbox
  * handshake and register its sysfs/hwmon interfaces.
@@ -593,70 +328,6 @@ static int init_acpi(struct device *dev)
 	return 0;
 }
 
-static const struct bin_attribute  hsmp_metric_tbl_attr = {
-	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},
-	.read = hsmp_metric_tbl_acpi_read,
-	.size = sizeof(struct hsmp_metric_table),
-};
-
-static const struct bin_attribute *hsmp_attr_list[] = {
-	&hsmp_metric_tbl_attr,
-	NULL
-};
-
-#define HSMP_DEV_ATTR(_name, _msg_id, _show, _mode)	\
-static struct hsmp_sys_attr hattr_##_name = {		\
-	.dattr = __ATTR(_name, _mode, _show, NULL),	\
-	.msg_id = _msg_id,				\
-}
-
-HSMP_DEV_ATTR(c0_residency_input, HSMP_GET_C0_PERCENT, hsmp_msg_resp32_show, 0444);
-HSMP_DEV_ATTR(prochot_status, HSMP_GET_PROC_HOT, hsmp_msg_resp32_show, 0444);
-HSMP_DEV_ATTR(smu_fw_version, HSMP_GET_SMU_VER, hsmp_msg_fw_ver_show, 0444);
-HSMP_DEV_ATTR(protocol_version, HSMP_GET_PROTO_VER, hsmp_msg_resp32_show, 0444);
-HSMP_DEV_ATTR(cclk_freq_limit_input, HSMP_GET_CCLK_THROTTLE_LIMIT, hsmp_msg_resp32_show, 0444);
-HSMP_DEV_ATTR(ddr_max_bw, HSMP_GET_DDR_BANDWIDTH, hsmp_ddr_max_bw_show, 0444);
-HSMP_DEV_ATTR(ddr_utilised_bw_input, HSMP_GET_DDR_BANDWIDTH, hsmp_ddr_util_bw_show, 0444);
-HSMP_DEV_ATTR(ddr_utilised_bw_perc_input, HSMP_GET_DDR_BANDWIDTH, hsmp_ddr_util_bw_perc_show, 0444);
-HSMP_DEV_ATTR(fclk_input, HSMP_GET_FCLK_MCLK, hsmp_fclk_show, 0444);
-HSMP_DEV_ATTR(mclk_input, HSMP_GET_FCLK_MCLK, hsmp_mclk_show, 0444);
-HSMP_DEV_ATTR(clk_fmax, HSMP_GET_SOCKET_FMAX_FMIN, hsmp_clk_fmax_show, 0444);
-HSMP_DEV_ATTR(clk_fmin, HSMP_GET_SOCKET_FMAX_FMIN, hsmp_clk_fmin_show, 0444);
-HSMP_DEV_ATTR(pwr_current_active_freq_limit, HSMP_GET_SOCKET_FREQ_LIMIT,
-	      hsmp_freq_limit_show, 0444);
-HSMP_DEV_ATTR(pwr_current_active_freq_limit_source, HSMP_GET_SOCKET_FREQ_LIMIT,
-	      hsmp_freq_limit_source_show, 0444);
-
-static struct attribute *hsmp_dev_attr_list[] = {
-	&hattr_c0_residency_input.dattr.attr,
-	&hattr_prochot_status.dattr.attr,
-	&hattr_smu_fw_version.dattr.attr,
-	&hattr_protocol_version.dattr.attr,
-	&hattr_cclk_freq_limit_input.dattr.attr,
-	&hattr_ddr_max_bw.dattr.attr,
-	&hattr_ddr_utilised_bw_input.dattr.attr,
-	&hattr_ddr_utilised_bw_perc_input.dattr.attr,
-	&hattr_fclk_input.dattr.attr,
-	&hattr_mclk_input.dattr.attr,
-	&hattr_clk_fmax.dattr.attr,
-	&hattr_clk_fmin.dattr.attr,
-	&hattr_pwr_current_active_freq_limit.dattr.attr,
-	&hattr_pwr_current_active_freq_limit_source.dattr.attr,
-	NULL
-};
-
-static const struct attribute_group hsmp_attr_grp = {
-	.bin_attrs = hsmp_attr_list,
-	.attrs = hsmp_dev_attr_list,
-	.is_bin_visible = hsmp_is_sock_attr_visible,
-	.is_visible = hsmp_is_sock_dev_attr_visible,
-};
-
-static const struct attribute_group *hsmp_groups[] = {
-	&hsmp_attr_grp,
-	NULL
-};
-
 static const struct acpi_device_id amd_hsmp_acpi_ids[] = {
 	{ACPI_HSMP_DEVICE_HID, 0},
 	{}
@@ -814,7 +485,7 @@ static struct platform_driver amd_hsmp_driver = {
 	.driver		= {
 		.name	= DRIVER_NAME,
 		.acpi_match_table = amd_hsmp_acpi_ids,
-		.dev_groups = hsmp_groups,
+		.dev_groups = hsmp_sock_groups,
 	},
 };
 
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index 3302c1517369..7a0e3af67691 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -104,6 +104,7 @@ int hsmp_create_sensor(struct device *dev, u16 sock_ind);
 static inline int hsmp_create_sensor(struct device *dev, u16 sock_ind) { return 0; }
 #endif
 int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args);
+extern const struct attribute_group *hsmp_sock_groups[];
 
 /*
  * Gates the HSMP data plane: hsmp_send_message() takes it for read; probe and
diff --git a/drivers/platform/x86/amd/hsmp/sysfs.c b/drivers/platform/x86/amd/hsmp/sysfs.c
new file mode 100644
index 000000000000..06c0a5a02ca2
--- /dev/null
+++ b/drivers/platform/x86/amd/hsmp/sysfs.c
@@ -0,0 +1,348 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * AMD HSMP sysfs support
+ * Copyright (c) 2024, AMD.
+ * All Rights Reserved.
+ *
+ * This file provides the per-socket sysfs attributes of the HSMP interface.
+ */
+
+#include <asm/amd/hsmp.h>
+
+#include <linux/array_size.h>
+#include <linux/bitfield.h>
+#include <linux/bits.h>
+#include <linux/device.h>
+#include <linux/sysfs.h>
+
+#include "hsmp.h"
+
+struct hsmp_sys_attr {
+	struct device_attribute dattr;
+	u32 msg_id;
+};
+
+static ssize_t hsmp_metric_tbl_acpi_read(struct file *filp, struct kobject *kobj,
+					 const struct bin_attribute *bin_attr, char *buf,
+					 loff_t off, size_t count)
+{
+	struct device *dev = container_of(kobj, struct device, kobj);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+
+	/*
+	 * metrics_bin is a sysfs binary attribute and is capped at PAGE_SIZE.
+	 * It can therefore only carry the protocol version 6 metric table
+	 * (struct hsmp_metric_table).  The larger tables defined from protocol
+	 * version 7 onwards do not fit; userspace on those systems must read
+	 * the snapshot through HSMP_IOCTL_GET_TELEMETRY_DATA on /dev/hsmp.
+	 * Surface the unsupported case here as -EOPNOTSUPP rather than
+	 * silently truncating the snapshot.
+	 */
+	if (get_hsmp_pdev()->proto_ver != HSMP_PROTO_VER6)
+		return -EOPNOTSUPP;
+
+	return hsmp_metric_tbl_read(sock, buf, count);
+}
+
+static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
+					 const struct bin_attribute *battr, int id)
+{
+	/*
+	 * Keep metrics_bin visible on protocol version 7 and later as well,
+	 * so that userspace which expects the file to exist gets a clear
+	 * -EOPNOTSUPP from the read handler instead of -ENOENT, and is
+	 * pointed at HSMP_IOCTL_GET_TELEMETRY_DATA as the supported path.
+	 * Hide metrics_bin on client platforms.
+	 */
+	if (!is_client_platform() && get_hsmp_pdev()->proto_ver >= HSMP_PROTO_VER6)
+		return battr->attr.mode;
+
+	return 0;
+}
+
+/* Defined below by HSMP_DEV_ATTR() */
+static struct hsmp_sys_attr hattr_smu_fw_version;
+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)
+{
+	/* 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)
+		return 0;
+
+	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)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%u\n", data);
+}
+
+#define DDR_MAX_BW_MASK		GENMASK(31, 20)
+#define DDR_UTIL_BW_MASK	GENMASK(19, 8)
+#define DDR_UTIL_BW_PERC_MASK	GENMASK(7, 0)
+#define FW_VER_MAJOR_MASK	GENMASK(23, 16)
+#define FW_VER_MINOR_MASK	GENMASK(15, 8)
+#define FW_VER_DEBUG_MASK	GENMASK(7, 0)
+#define FMAX_MASK		GENMASK(31, 16)
+#define FMIN_MASK		GENMASK(15, 0)
+#define FREQ_LIMIT_MASK		GENMASK(31, 16)
+#define FREQ_SRC_IND_MASK	GENMASK(15, 0)
+
+static ssize_t hsmp_ddr_max_bw_show(struct device *dev, struct device_attribute *attr,
+				    char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%lu\n", FIELD_GET(DDR_MAX_BW_MASK, data));
+}
+
+static ssize_t hsmp_ddr_util_bw_show(struct device *dev, struct device_attribute *attr,
+				     char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%lu\n", FIELD_GET(DDR_UTIL_BW_MASK, data));
+}
+
+static ssize_t hsmp_ddr_util_bw_perc_show(struct device *dev, struct device_attribute *attr,
+					  char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%lu\n", FIELD_GET(DDR_UTIL_BW_PERC_MASK, data));
+}
+
+static ssize_t hsmp_msg_fw_ver_show(struct device *dev, struct device_attribute *attr,
+				    char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%lu.%lu.%lu\n",
+			  FIELD_GET(FW_VER_MAJOR_MASK, data),
+			  FIELD_GET(FW_VER_MINOR_MASK, data),
+			  FIELD_GET(FW_VER_DEBUG_MASK, data));
+}
+
+static ssize_t hsmp_fclk_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data[2];
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, data, 2);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%u\n", data[0]);
+}
+
+static ssize_t hsmp_mclk_show(struct device *dev, struct device_attribute *attr,
+			      char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data[2];
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, data, 2);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%u\n", data[1]);
+}
+
+static ssize_t hsmp_clk_fmax_show(struct device *dev, struct device_attribute *attr,
+				  char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%lu\n", FIELD_GET(FMAX_MASK, data));
+}
+
+static ssize_t hsmp_clk_fmin_show(struct device *dev, struct device_attribute *attr,
+				  char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%lu\n", FIELD_GET(FMIN_MASK, data));
+}
+
+static ssize_t hsmp_freq_limit_show(struct device *dev, struct device_attribute *attr,
+				    char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "%lu\n", FIELD_GET(FREQ_LIMIT_MASK, data));
+}
+
+static const char * const freqlimit_srcnames[] = {
+	"cHTC-Active",
+	"PROCHOT",
+	"TDC limit",
+	"PPT Limit",
+	"OPN Max",
+	"Reliability Limit",
+	"APML Agent",
+	"HSMP Agent",
+};
+
+static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_attribute *attr,
+					   char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	unsigned int index;
+	int len = 0;
+	u16 src_ind;
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	src_ind = FIELD_GET(FREQ_SRC_IND_MASK, data);
+	for (index = 0; index < ARRAY_SIZE(freqlimit_srcnames); index++) {
+		if (!src_ind)
+			break;
+		if (src_ind & 1)
+			len += sysfs_emit_at(buf, len, "%s\n", freqlimit_srcnames[index]);
+		src_ind >>= 1;
+	}
+	return len;
+}
+
+static const struct bin_attribute  hsmp_metric_tbl_attr = {
+	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},
+	.read = hsmp_metric_tbl_acpi_read,
+	.size = sizeof(struct hsmp_metric_table),
+};
+
+static const struct bin_attribute *hsmp_attr_list[] = {
+	&hsmp_metric_tbl_attr,
+	NULL
+};
+
+#define HSMP_DEV_ATTR(_name, _msg_id, _show, _mode)	\
+static struct hsmp_sys_attr hattr_##_name = {		\
+	.dattr = __ATTR(_name, _mode, _show, NULL),	\
+	.msg_id = _msg_id,				\
+}
+
+HSMP_DEV_ATTR(c0_residency_input, HSMP_GET_C0_PERCENT, hsmp_msg_resp32_show, 0444);
+HSMP_DEV_ATTR(prochot_status, HSMP_GET_PROC_HOT, hsmp_msg_resp32_show, 0444);
+HSMP_DEV_ATTR(smu_fw_version, HSMP_GET_SMU_VER, hsmp_msg_fw_ver_show, 0444);
+HSMP_DEV_ATTR(protocol_version, HSMP_GET_PROTO_VER, hsmp_msg_resp32_show, 0444);
+HSMP_DEV_ATTR(cclk_freq_limit_input, HSMP_GET_CCLK_THROTTLE_LIMIT, hsmp_msg_resp32_show, 0444);
+HSMP_DEV_ATTR(ddr_max_bw, HSMP_GET_DDR_BANDWIDTH, hsmp_ddr_max_bw_show, 0444);
+HSMP_DEV_ATTR(ddr_utilised_bw_input, HSMP_GET_DDR_BANDWIDTH, hsmp_ddr_util_bw_show, 0444);
+HSMP_DEV_ATTR(ddr_utilised_bw_perc_input, HSMP_GET_DDR_BANDWIDTH, hsmp_ddr_util_bw_perc_show, 0444);
+HSMP_DEV_ATTR(fclk_input, HSMP_GET_FCLK_MCLK, hsmp_fclk_show, 0444);
+HSMP_DEV_ATTR(mclk_input, HSMP_GET_FCLK_MCLK, hsmp_mclk_show, 0444);
+HSMP_DEV_ATTR(clk_fmax, HSMP_GET_SOCKET_FMAX_FMIN, hsmp_clk_fmax_show, 0444);
+HSMP_DEV_ATTR(clk_fmin, HSMP_GET_SOCKET_FMAX_FMIN, hsmp_clk_fmin_show, 0444);
+HSMP_DEV_ATTR(pwr_current_active_freq_limit, HSMP_GET_SOCKET_FREQ_LIMIT,
+	      hsmp_freq_limit_show, 0444);
+HSMP_DEV_ATTR(pwr_current_active_freq_limit_source, HSMP_GET_SOCKET_FREQ_LIMIT,
+	      hsmp_freq_limit_source_show, 0444);
+
+static struct attribute *hsmp_dev_attr_list[] = {
+	&hattr_c0_residency_input.dattr.attr,
+	&hattr_prochot_status.dattr.attr,
+	&hattr_smu_fw_version.dattr.attr,
+	&hattr_protocol_version.dattr.attr,
+	&hattr_cclk_freq_limit_input.dattr.attr,
+	&hattr_ddr_max_bw.dattr.attr,
+	&hattr_ddr_utilised_bw_input.dattr.attr,
+	&hattr_ddr_utilised_bw_perc_input.dattr.attr,
+	&hattr_fclk_input.dattr.attr,
+	&hattr_mclk_input.dattr.attr,
+	&hattr_clk_fmax.dattr.attr,
+	&hattr_clk_fmin.dattr.attr,
+	&hattr_pwr_current_active_freq_limit.dattr.attr,
+	&hattr_pwr_current_active_freq_limit_source.dattr.attr,
+	NULL
+};
+
+static const struct attribute_group hsmp_attr_grp = {
+	.bin_attrs = hsmp_attr_list,
+	.attrs = hsmp_dev_attr_list,
+	.is_bin_visible = hsmp_is_sock_attr_visible,
+	.is_visible = hsmp_is_sock_dev_attr_visible,
+};
+
+/*
+ * Per-socket attribute groups. Every show/read handler expects the drvdata of
+ * the device carrying the group to be the struct hsmp_socket it reports on.
+ */
+const struct attribute_group *hsmp_sock_groups[] = {
+	&hsmp_attr_grp,
+	NULL
+};
+EXPORT_SYMBOL_NS_GPL(hsmp_sock_groups, "AMD_HSMP");

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.53.0


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

* [PATCH v2 2/5] platform/x86/amd/hsmp: Add amd_hsmp class with per-socket devices
  2026-11-16 15:51 [PATCH v2 0/5] platform/x86/amd/hsmp: Unify per-socket sysfs metrics Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 1/5] platform/x86/amd/hsmp: Move per-socket sysfs attributes to common code Erwan Velu
@ 2026-11-16 15:51 ` Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 3/5] platform/x86/amd/hsmp: Expose socket attributes from the platform driver Erwan Velu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Erwan Velu @ 2026-11-16 15:51 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi, Ilpo Järvinen, Hans de Goede
  Cc: Carlos Bilbao, Muralidhara M K, Suma Hegde, Muthusamy Ramalingam,
	platform-driver-x86, linux-kernel, Erwan Velu

From: Erwan Velu <e.velu@criteo.com>

The per-socket attributes live in different places depending on the
driver that probed. With the ACPI driver, they are under
/sys/devices/platform/AMDI0097:0X/. With the platform driver, the
per-socket directories are /sys/devices/platform/amd_hsmp/socketN/.
"modprobe amd_hsmp" picks the right driver, but userspace cannot know
in advance which of these trees it has to read.

Add an amd_hsmp class, and a socketN device per socket in it that
carries hsmp_sock_groups. The device is a child of the device of the
driver that probed the socket, so /sys/class/amd_hsmp/socketN/ is the
same path whichever driver is in use.

Register the socket devices from the ACPI driver. They are children of
the AMDI0097:0X devices. The attributes on AMDI0097:0X are kept, as
they are documented.

The socket device is unregistered before remove takes hsmp_sock_rwsem:
device_unregister() waits for in-flight sysfs reads, which take the
rwsem for read.

On a dual socket Zen5 (Family 1Ah) server probed by the ACPI driver,
this gives:

  $ ls -l /sys/class/amd_hsmp/
  socket0 -> ../../devices/platform/AMDI0097:00/amd_hsmp/socket0
  socket1 -> ../../devices/platform/AMDI0097:01/amd_hsmp/socket1
  $ cat /sys/class/amd_hsmp/socket0/pwr_current_active_freq_limit
  3120

The amd_hsmp directory below AMDI0097:0X is the glue directory the
driver core creates for class devices whose parent is not a class
device. The attributes directly under AMDI0097:0X are unchanged.

Assisted-by: claude-opus-5-5
Signed-off-by: Erwan Velu <e.velu@criteo.com>
---
 Documentation/arch/x86/amd_hsmp.rst   | 12 ++++-
 drivers/platform/x86/amd/hsmp/acpi.c  | 14 ++++++
 drivers/platform/x86/amd/hsmp/hsmp.c  | 19 +++++++
 drivers/platform/x86/amd/hsmp/hsmp.h  |  6 +++
 drivers/platform/x86/amd/hsmp/sysfs.c | 71 ++++++++++++++++++++++++++-
 5 files changed, 120 insertions(+), 2 deletions(-)

diff --git a/Documentation/arch/x86/amd_hsmp.rst b/Documentation/arch/x86/amd_hsmp.rst
index c483c68dcfad..f145ea12af99 100644
--- a/Documentation/arch/x86/amd_hsmp.rst
+++ b/Documentation/arch/x86/amd_hsmp.rst
@@ -65,6 +65,16 @@ In-kernel integration:
 HSMP sysfs interface
 ====================
 
+Each socket has a socket%d device in the amd_hsmp class, whose parent is the
+device of the driver that probed the socket. Its per socket sysfs files are
+therefore available at /sys/class/amd_hsmp/socket%d/, whichever driver
+probed.
+
+With the ACPI driver, the socket devices are children of the ACPI devices,
+e.g. /sys/devices/platform/AMDI0097:00/amd_hsmp/socket0/. For backward
+compatibility, the files are also available directly under
+/sys/devices/platform/AMDI0097:0X/.
+
 1. Metrics table binary sysfs
 
 AMD MI300A MCM provides GET_METRICS_TABLE message to retrieve
@@ -88,7 +98,7 @@ The same is defined in the amd_hsmp.h header.
 
 2. HSMP telemetry sysfs files
 
-Following sysfs files are available at /sys/devices/platform/AMDI0097:0X/.
+Following sysfs files are available at /sys/class/amd_hsmp/socket%d/.
 
 * c0_residency_input: Percentage of cores in C0 state.
 * prochot_status: Reports 1 if the processor is at thermal threshold value,
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index a1e13aff9c86..2c9389b8f139 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -452,6 +452,14 @@ static int hsmp_acpi_probe(struct platform_device *pdev)
 		dev_dbg(&pdev->dev, "AMD HSMP ACPI misc device registered\n");
 	}
 
+	/*
+	 * The attributes stay available on the ACPI device itself, so a
+	 * failure here is not fatal to the probe.
+	 */
+	ret = hsmp_sock_dev_register(&pdev->dev, dev_get_drvdata(&pdev->dev));
+	if (ret)
+		dev_warn(&pdev->dev, "Failed to register HSMP socket device: %d\n", ret);
+
 	return 0;
 }
 
@@ -459,6 +467,12 @@ static void hsmp_acpi_remove(struct platform_device *pdev)
 {
 	struct hsmp_socket *sock = dev_get_drvdata(&pdev->dev);
 
+	/*
+	 * Must run before taking hsmp_sock_rwsem below: unregistering the
+	 * class device waits for in-flight sysfs reads, which take it for read.
+	 */
+	hsmp_sock_dev_unregister(sock);
+
 	/*
 	 * Serialize the kref_put() and any release it triggers against a
 	 * concurrent probe, and drain the data plane for the whole
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 45d20beda946..a498f904f900 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -16,7 +16,9 @@
 #include <linux/compiler.h>
 #include <linux/delay.h>
 #include <linux/device.h>
+#include <linux/init.h>
 #include <linux/io.h>
+#include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/nospec.h>
 #include <linux/rwsem.h>
@@ -857,6 +859,23 @@ struct hsmp_plat_device *get_hsmp_pdev(void)
 }
 EXPORT_SYMBOL_NS_GPL(get_hsmp_pdev, "AMD_HSMP");
 
+/*
+ * The amd_hsmp class must exist before the ACPI or platform driver probes a
+ * socket. When built in, subsys_initcall() runs it ahead of their
+ * device_initcall()s.
+ */
+static int __init hsmp_common_init(void)
+{
+	return hsmp_sock_class_register();
+}
+subsys_initcall(hsmp_common_init);
+
+static void __exit hsmp_common_exit(void)
+{
+	hsmp_sock_class_unregister();
+}
+module_exit(hsmp_common_exit);
+
 MODULE_DESCRIPTION("AMD HSMP Common driver");
 MODULE_VERSION(DRIVER_VERSION);
 MODULE_LICENSE("GPL");
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index 7a0e3af67691..35b4e2312bf2 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -32,6 +32,7 @@
 
 #define HSMP_CDEV_NAME		"hsmp_cdev"
 #define HSMP_DEVNODE_NAME	"hsmp"
+#define HSMP_CLASS_NAME		"amd_hsmp"
 #define ACPI_HSMP_DEVICE_HID    "AMDI0097"
 
 #define DRIVER_VERSION		"2.6"
@@ -71,6 +72,7 @@ struct hsmp_socket {
 	/* Size of the region mapped at @metric_tbl_addr, as reported by SMU */
 	size_t metric_tbl_size;
 	void __iomem *virt_base_addr;
+	struct device *sysfs_dev;
 	struct semaphore hsmp_sem;
 	/* Serializes HSMP_GET_METRIC_TABLE fill-and-copy for this socket */
 	struct mutex metric_read_lock;
@@ -104,6 +106,10 @@ int hsmp_create_sensor(struct device *dev, u16 sock_ind);
 static inline int hsmp_create_sensor(struct device *dev, u16 sock_ind) { return 0; }
 #endif
 int hsmp_msg_get_nargs(u16 sock_ind, u32 msg_id, u32 *data, u8 num_args);
+int hsmp_sock_class_register(void);
+void hsmp_sock_class_unregister(void);
+int hsmp_sock_dev_register(struct device *parent, struct hsmp_socket *sock);
+void hsmp_sock_dev_unregister(struct hsmp_socket *sock);
 extern const struct attribute_group *hsmp_sock_groups[];
 
 /*
diff --git a/drivers/platform/x86/amd/hsmp/sysfs.c b/drivers/platform/x86/amd/hsmp/sysfs.c
index 06c0a5a02ca2..94670c8e689b 100644
--- a/drivers/platform/x86/amd/hsmp/sysfs.c
+++ b/drivers/platform/x86/amd/hsmp/sysfs.c
@@ -4,7 +4,8 @@
  * Copyright (c) 2024, AMD.
  * All Rights Reserved.
  *
- * This file provides the per-socket sysfs attributes of the HSMP interface.
+ * This file provides the per-socket sysfs attributes of the HSMP interface
+ * and the amd_hsmp class devices carrying them.
  */
 
 #include <asm/amd/hsmp.h>
@@ -13,6 +14,9 @@
 #include <linux/bitfield.h>
 #include <linux/bits.h>
 #include <linux/device.h>
+#include <linux/err.h>
+#include <linux/kdev_t.h>
+#include <linux/lockdep.h>
 #include <linux/sysfs.h>
 
 #include "hsmp.h"
@@ -346,3 +350,68 @@ const struct attribute_group *hsmp_sock_groups[] = {
 	NULL
 };
 EXPORT_SYMBOL_NS_GPL(hsmp_sock_groups, "AMD_HSMP");
+
+/*
+ * Every socket gets a socket%u device in this class, parented to the device of
+ * the driver that probed it, whichever that driver is. This gives userspace a
+ * single /sys/class/amd_hsmp/socket%u path to the per-socket attributes.
+ */
+static const struct class hsmp_class = {
+	.name = HSMP_CLASS_NAME,
+};
+
+int hsmp_sock_class_register(void)
+{
+	return class_register(&hsmp_class);
+}
+
+void hsmp_sock_class_unregister(void)
+{
+	class_unregister(&hsmp_class);
+}
+
+/**
+ * hsmp_sock_dev_register() - Create the amd_hsmp class device of @sock.
+ * @parent: device of the driver that probed @sock.
+ * @sock: fully probed HSMP socket.
+ *
+ * The device is named socket%u after @sock's index, is a child of @parent and
+ * carries hsmp_sock_groups with @sock as its drvdata, so @sock must stay valid
+ * until hsmp_sock_dev_unregister() returns.
+ *
+ * Return: 0 on success, a negative error code otherwise.
+ */
+int hsmp_sock_dev_register(struct device *parent, struct hsmp_socket *sock)
+{
+	struct device *dev;
+
+	dev = device_create_with_groups(&hsmp_class, parent, MKDEV(0, 0), sock,
+					hsmp_sock_groups, "socket%u", sock->sock_ind);
+	if (IS_ERR(dev))
+		return PTR_ERR(dev);
+
+	sock->sysfs_dev = dev;
+
+	return 0;
+}
+EXPORT_SYMBOL_NS_GPL(hsmp_sock_dev_register, "AMD_HSMP");
+
+/**
+ * hsmp_sock_dev_unregister() - Remove the amd_hsmp class device of @sock.
+ * @sock: HSMP socket; a no-op if its device was never registered.
+ *
+ * device_unregister() waits for in-flight show/read handlers, which take
+ * hsmp_sock_rwsem for read. The caller must therefore not hold it, or a
+ * concurrent sysfs read would deadlock the teardown.
+ */
+void hsmp_sock_dev_unregister(struct hsmp_socket *sock)
+{
+	lockdep_assert_not_held(&hsmp_sock_rwsem);
+
+	if (!sock->sysfs_dev)
+		return;
+
+	device_unregister(sock->sysfs_dev);
+	sock->sysfs_dev = NULL;
+}
+EXPORT_SYMBOL_NS_GPL(hsmp_sock_dev_unregister, "AMD_HSMP");
-- 
2.53.0


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

* [PATCH v2 3/5] platform/x86/amd/hsmp: Expose socket attributes from the platform driver
  2026-11-16 15:51 [PATCH v2 0/5] platform/x86/amd/hsmp: Unify per-socket sysfs metrics Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 1/5] platform/x86/amd/hsmp: Move per-socket sysfs attributes to common code Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 2/5] platform/x86/amd/hsmp: Add amd_hsmp class with per-socket devices Erwan Velu
@ 2026-11-16 15:51 ` Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 4/5] platform/x86/amd/hsmp: Add pwr_current_active_freq_limit_source_raw Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 5/5] Documentation/ABI: Add sysfs-class-amd_hsmp Erwan Velu
  4 siblings, 0 replies; 6+ messages in thread
From: Erwan Velu @ 2026-11-16 15:51 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi, Ilpo Järvinen, Hans de Goede
  Cc: Carlos Bilbao, Muralidhara M K, Suma Hegde, Muthusamy Ramalingam,
	platform-driver-x86, linux-kernel, Erwan Velu

From: Erwan Velu <e.velu@criteo.com>

The platform driver creates bare socketN attribute groups on the
amd_hsmp platform device, which only hold metrics_bin. On systems
without the HSMP ACPI object, attributes such as
pwr_current_active_freq_limit are therefore missing, although the
driver can send the same HSMP messages as the ACPI one.

Register the amd_hsmp class socketN devices from the platform driver,
as children of the amd_hsmp platform device, and drop the socketN
attribute groups they replace. The socket devices carry
hsmp_sock_groups, metrics_bin included, so all the per-socket
attributes are now available under /sys/class/amd_hsmp/socketN/.

As class devices, they are placed by the driver core in an amd_hsmp
glue directory below their parent, i.e. in
/sys/devices/platform/amd_hsmp/amd_hsmp/socketN/. To keep the existing
/sys/devices/platform/amd_hsmp/socketN/metrics_bin path working, add a
socketN symlink from the platform device to each socket device.

As the socket devices and their symlinks are now the only way
metrics_bin is exposed, failing to create one fails the probe. They are
torn down by a devres action added after hsmp_pltdrv_release(), so they
are gone before the socket array they reference is released.

Systems running HSMP protocol version 7 or later with the platform
driver (Family 1Ah model 0x00-0x0F without the HSMP ACPI object) now
see metrics_bin, as with the ACPI driver: reads return -EOPNOTSUPP and
point userspace to HSMP_IOCTL_GET_TELEMETRY_DATA, as the version 7
table does not fit in a sysfs binary attribute. It used to be hidden
there.

On a single socket Zen4 (Family 19h) server probed by the platform
driver, this gives:

  $ ls -l /sys/devices/platform/amd_hsmp/
  drwxr-xr-x amd_hsmp
  ...
  lrwxrwxrwx socket0 -> amd_hsmp/socket0
  $ ls -l /sys/class/amd_hsmp/
  socket0 -> ../../devices/platform/amd_hsmp/amd_hsmp/socket0
  $ cat /sys/class/amd_hsmp/socket0/pwr_current_active_freq_limit
  3100

This system runs HSMP protocol version 5, so metrics_bin is not
visible, as before this change.

Assisted-by: claude-opus-5-5
Signed-off-by: Erwan Velu <e.velu@criteo.com>
---
 Documentation/arch/x86/amd_hsmp.rst  |   8 +-
 drivers/platform/x86/amd/hsmp/plat.c | 155 +++++++++++----------------
 2 files changed, 67 insertions(+), 96 deletions(-)

diff --git a/Documentation/arch/x86/amd_hsmp.rst b/Documentation/arch/x86/amd_hsmp.rst
index f145ea12af99..c4459a9dddc6 100644
--- a/Documentation/arch/x86/amd_hsmp.rst
+++ b/Documentation/arch/x86/amd_hsmp.rst
@@ -75,14 +75,18 @@ e.g. /sys/devices/platform/AMDI0097:00/amd_hsmp/socket0/. For backward
 compatibility, the files are also available directly under
 /sys/devices/platform/AMDI0097:0X/.
 
+With the plat driver, the socket devices are children of the amd_hsmp
+platform device, i.e. /sys/devices/platform/amd_hsmp/amd_hsmp/socket%d/.
+For backward compatibility, /sys/devices/platform/amd_hsmp/socket%d is a
+symlink to it.
+
 1. Metrics table binary sysfs
 
 AMD MI300A MCM provides GET_METRICS_TABLE message to retrieve
 most of the system management information from SMU in one go.
 
 The metrics table is made available as hexadecimal sysfs binary file
-under per socket sysfs directory created at
-/sys/devices/platform/amd_hsmp/socket%d/metrics_bin
+/sys/class/amd_hsmp/socket%d/metrics_bin
 
 Note: lseek() is not supported as entire metrics table is read.
 
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index c3dc7c9f45ac..edcfe82aab2a 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -12,7 +12,6 @@
 #include <asm/amd/hsmp.h>
 
 #include <linux/acpi.h>
-#include <linux/build_bug.h>
 #include <linux/cleanup.h>
 #include <linux/device.h>
 #include <linux/dev_printk.h>
@@ -48,98 +47,6 @@ static int amd_hsmp_pci_rdwr(struct hsmp_socket *sock, u32 offset,
 	return amd_smn_hsmp_rdwr(sock->sock_ind, sock->mbinfo.base_addr + offset, value, write);
 }
 
-static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj,
-					 const struct bin_attribute *bin_attr, char *buf,
-					 loff_t off, size_t count)
-{
-	struct hsmp_socket *sock;
-	u16 sock_ind;
-
-	sock_ind = (uintptr_t)bin_attr->private;
-	if (sock_ind >= hsmp_pdev->num_sockets)
-		return -EINVAL;
-
-	sock = &hsmp_pdev->sock[sock_ind];
-
-	return hsmp_metric_tbl_read(sock, buf, count);
-}
-
-static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
-					 const struct bin_attribute *battr, int id)
-{
-	u16 sock_ind;
-
-	sock_ind = (uintptr_t)battr->private;
-
-	if (id == 0 && sock_ind >= hsmp_pdev->num_sockets)
-		return SYSFS_GROUP_INVISIBLE;
-
-	if (hsmp_pdev->proto_ver == HSMP_PROTO_VER6)
-		return battr->attr.mode;
-
-	return 0;
-}
-
-/*
- * AMD supports maximum of 8 sockets in a system.
- * Static array of 8 + 1(for NULL) elements is created below
- * to create sysfs groups for sockets.
- * is_bin_visible function is used to show / hide the necessary groups.
- *
- * Validate the maximum number against MAX_AMD_NUM_NODES. If this changes,
- * then the attributes and groups below must be adjusted.
- */
-static_assert(MAX_AMD_NUM_NODES == 8);
-
-#define HSMP_BIN_ATTR(index, _list)					\
-static const struct bin_attribute attr##index = {			\
-	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},	\
-	.private = (void *)index,					\
-	.read = hsmp_metric_tbl_plat_read,				\
-	.size = sizeof(struct hsmp_metric_table),			\
-};									\
-static const struct bin_attribute _list[] = {				\
-	&attr##index,							\
-	NULL								\
-}
-
-HSMP_BIN_ATTR(0, *sock0_attr_list);
-HSMP_BIN_ATTR(1, *sock1_attr_list);
-HSMP_BIN_ATTR(2, *sock2_attr_list);
-HSMP_BIN_ATTR(3, *sock3_attr_list);
-HSMP_BIN_ATTR(4, *sock4_attr_list);
-HSMP_BIN_ATTR(5, *sock5_attr_list);
-HSMP_BIN_ATTR(6, *sock6_attr_list);
-HSMP_BIN_ATTR(7, *sock7_attr_list);
-
-#define HSMP_BIN_ATTR_GRP(index, _list, _name)			\
-static const struct attribute_group sock##index##_attr_grp = {	\
-	.bin_attrs = _list,					\
-	.is_bin_visible = hsmp_is_sock_attr_visible,		\
-	.name = #_name,						\
-}
-
-HSMP_BIN_ATTR_GRP(0, sock0_attr_list, socket0);
-HSMP_BIN_ATTR_GRP(1, sock1_attr_list, socket1);
-HSMP_BIN_ATTR_GRP(2, sock2_attr_list, socket2);
-HSMP_BIN_ATTR_GRP(3, sock3_attr_list, socket3);
-HSMP_BIN_ATTR_GRP(4, sock4_attr_list, socket4);
-HSMP_BIN_ATTR_GRP(5, sock5_attr_list, socket5);
-HSMP_BIN_ATTR_GRP(6, sock6_attr_list, socket6);
-HSMP_BIN_ATTR_GRP(7, sock7_attr_list, socket7);
-
-static const struct attribute_group *hsmp_groups[] = {
-	&sock0_attr_grp,
-	&sock1_attr_grp,
-	&sock2_attr_grp,
-	&sock3_attr_grp,
-	&sock4_attr_grp,
-	&sock5_attr_grp,
-	&sock6_attr_grp,
-	&sock7_attr_grp,
-	NULL
-};
-
 static inline bool is_f1a_m0h(void)
 {
 	if (boot_cpu_data.x86 == 0x1A && boot_cpu_data.x86_model <= 0x0F)
@@ -222,9 +129,49 @@ static void hsmp_pltdrv_release(void *data)
 	hsmp_pdev->sock = NULL;
 }
 
+/*
+ * The amd_hsmp class devices live in an amd_hsmp glue directory below the
+ * platform device, i.e. /sys/devices/platform/amd_hsmp/amd_hsmp/socket%u.
+ * /sys/devices/platform/amd_hsmp/socket%u used to be a plain attribute group
+ * holding metrics_bin, so keep that path working with a symlink to the socket
+ * device.
+ */
+static int hsmp_pltdrv_sock_dev_register(struct device *dev, struct hsmp_socket *sock)
+{
+	int ret;
+
+	ret = hsmp_sock_dev_register(dev, sock);
+	if (ret)
+		return ret;
+
+	ret = sysfs_create_link(&dev->kobj, &sock->sysfs_dev->kobj,
+				dev_name(sock->sysfs_dev));
+	if (ret)
+		hsmp_sock_dev_unregister(sock);
+
+	return ret;
+}
+
+static void hsmp_pltdrv_sock_devs_release(void *data)
+{
+	struct device *dev = data;
+	struct hsmp_socket *sock;
+	u16 i;
+
+	for (i = 0; i < hsmp_pdev->num_sockets; i++) {
+		sock = &hsmp_pdev->sock[i];
+		if (!sock->sysfs_dev)
+			continue;
+
+		sysfs_remove_link(&dev->kobj, dev_name(sock->sysfs_dev));
+		hsmp_sock_dev_unregister(sock);
+	}
+}
+
 static int hsmp_pltdrv_probe(struct platform_device *pdev)
 {
 	int ret;
+	u16 i;
 
 	hsmp_pdev->sock = devm_kzalloc_objs(&pdev->dev, *hsmp_pdev->sock,
 					    hsmp_pdev->num_sockets);
@@ -252,6 +199,27 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)
 		return ret;
 	}
 
+	/*
+	 * Added after hsmp_pltdrv_release() so that devres removes the socket
+	 * devices before the socket array they reference is released.
+	 */
+	ret = devm_add_action_or_reset(&pdev->dev, hsmp_pltdrv_sock_devs_release, &pdev->dev);
+	if (ret)
+		return ret;
+
+	/*
+	 * The socket devices and their symlinks are the only way this driver
+	 * exposes metrics_bin, so failing to create one fails the probe.
+	 */
+	for (i = 0; i < hsmp_pdev->num_sockets; i++) {
+		ret = hsmp_pltdrv_sock_dev_register(&pdev->dev, &hsmp_pdev->sock[i]);
+		if (ret) {
+			dev_err(&pdev->dev, "Failed to register HSMP socket%u device: %d\n",
+				i, ret);
+			return ret;
+		}
+	}
+
 	ret = hsmp_misc_register(&pdev->dev);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register misc device\n");
@@ -272,7 +240,6 @@ static struct platform_driver amd_hsmp_driver = {
 	.remove		= hsmp_pltdrv_remove,
 	.driver		= {
 		.name	= DRIVER_NAME,
-		.dev_groups = hsmp_groups,
 	},
 };
 
-- 
2.53.0


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

* [PATCH v2 4/5] platform/x86/amd/hsmp: Add pwr_current_active_freq_limit_source_raw
  2026-11-16 15:51 [PATCH v2 0/5] platform/x86/amd/hsmp: Unify per-socket sysfs metrics Erwan Velu
                   ` (2 preceding siblings ...)
  2026-11-16 15:51 ` [PATCH v2 3/5] platform/x86/amd/hsmp: Expose socket attributes from the platform driver Erwan Velu
@ 2026-11-16 15:51 ` Erwan Velu
  2026-11-16 15:51 ` [PATCH v2 5/5] Documentation/ABI: Add sysfs-class-amd_hsmp Erwan Velu
  4 siblings, 0 replies; 6+ messages in thread
From: Erwan Velu @ 2026-11-16 15:51 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi, Ilpo Järvinen, Hans de Goede
  Cc: Carlos Bilbao, Muralidhara M K, Suma Hegde, Muthusamy Ramalingam,
	platform-driver-x86, linux-kernel, Erwan Velu

From: Erwan Velu <e.velu@criteo.com>

pwr_current_active_freq_limit_source reports the active frequency limit
sources as a list of names, one per line, which metrics exporters have
to parse and map back to a value.

Add pwr_current_active_freq_limit_source_raw, reporting the same source
bitmask as a single hexadecimal value. Exporters only need a plain
integer conversion, and its interpretation can be centralized in the
monitoring stack, e.g. with Grafana value mappings, instead of being
decoded on each server.

The bit assignment is defined by the HSMP specification and is stable:
new limit sources are only appended, existing bits never change meaning.
A given value therefore has a single interpretation, whatever the
platform or kernel version it comes from.

Assisted-by: claude-opus-5-5
Acked-by: Carlos Bilbao <carlos.bilbao@kernel.org>
Signed-off-by: Erwan Velu <e.velu@criteo.com>
---
 Documentation/arch/x86/amd_hsmp.rst   |  4 ++++
 drivers/platform/x86/amd/hsmp/sysfs.c | 18 ++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/Documentation/arch/x86/amd_hsmp.rst b/Documentation/arch/x86/amd_hsmp.rst
index c4459a9dddc6..6156d50362cf 100644
--- a/Documentation/arch/x86/amd_hsmp.rst
+++ b/Documentation/arch/x86/amd_hsmp.rst
@@ -121,6 +121,10 @@ Following sysfs files are available at /sys/class/amd_hsmp/socket%d/.
   in MHz.
 * pwr_current_active_freq_limit_source: Source of current active frequency
   limit.
+* pwr_current_active_freq_limit_source_raw: Source of current active
+  frequency limit, as a hexadecimal bitmask. Bits 0 to 7 are, in order:
+  cHTC-Active, PROCHOT, TDC limit, PPT Limit, OPN Max, Reliability Limit,
+  APML Agent, HSMP Agent.
 
 ACPI device object format
 =========================
diff --git a/drivers/platform/x86/amd/hsmp/sysfs.c b/drivers/platform/x86/amd/hsmp/sysfs.c
index 94670c8e689b..5615b0385477 100644
--- a/drivers/platform/x86/amd/hsmp/sysfs.c
+++ b/drivers/platform/x86/amd/hsmp/sysfs.c
@@ -282,6 +282,21 @@ static ssize_t hsmp_freq_limit_source_show(struct device *dev, struct device_att
 	return len;
 }
 
+static ssize_t hsmp_freq_limit_source_raw_show(struct device *dev,
+					       struct device_attribute *attr, char *buf)
+{
+	struct hsmp_sys_attr *hattr = to_hsmp_sys_attr(attr);
+	struct hsmp_socket *sock = dev_get_drvdata(dev);
+	u32 data;
+	int ret;
+
+	ret = hsmp_msg_get_nargs(sock->sock_ind, hattr->msg_id, &data, 1);
+	if (ret)
+		return ret;
+
+	return sysfs_emit(buf, "0x%04lx\n", FIELD_GET(FREQ_SRC_IND_MASK, data));
+}
+
 static const struct bin_attribute  hsmp_metric_tbl_attr = {
 	.attr = { .name = HSMP_METRICS_TABLE_NAME, .mode = 0444},
 	.read = hsmp_metric_tbl_acpi_read,
@@ -315,6 +330,8 @@ HSMP_DEV_ATTR(pwr_current_active_freq_limit, HSMP_GET_SOCKET_FREQ_LIMIT,
 	      hsmp_freq_limit_show, 0444);
 HSMP_DEV_ATTR(pwr_current_active_freq_limit_source, HSMP_GET_SOCKET_FREQ_LIMIT,
 	      hsmp_freq_limit_source_show, 0444);
+HSMP_DEV_ATTR(pwr_current_active_freq_limit_source_raw, HSMP_GET_SOCKET_FREQ_LIMIT,
+	      hsmp_freq_limit_source_raw_show, 0444);
 
 static struct attribute *hsmp_dev_attr_list[] = {
 	&hattr_c0_residency_input.dattr.attr,
@@ -331,6 +348,7 @@ static struct attribute *hsmp_dev_attr_list[] = {
 	&hattr_clk_fmin.dattr.attr,
 	&hattr_pwr_current_active_freq_limit.dattr.attr,
 	&hattr_pwr_current_active_freq_limit_source.dattr.attr,
+	&hattr_pwr_current_active_freq_limit_source_raw.dattr.attr,
 	NULL
 };
 
-- 
2.53.0


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

* [PATCH v2 5/5] Documentation/ABI: Add sysfs-class-amd_hsmp
  2026-11-16 15:51 [PATCH v2 0/5] platform/x86/amd/hsmp: Unify per-socket sysfs metrics Erwan Velu
                   ` (3 preceding siblings ...)
  2026-11-16 15:51 ` [PATCH v2 4/5] platform/x86/amd/hsmp: Add pwr_current_active_freq_limit_source_raw Erwan Velu
@ 2026-11-16 15:51 ` Erwan Velu
  4 siblings, 0 replies; 6+ messages in thread
From: Erwan Velu @ 2026-11-16 15:51 UTC (permalink / raw)
  To: Naveen Krishna Chatradhi, Ilpo Järvinen, Hans de Goede
  Cc: Carlos Bilbao, Muralidhara M K, Suma Hegde, Muthusamy Ramalingam,
	platform-driver-x86, linux-kernel, Erwan Velu

From: Erwan Velu <e.velu@criteo.com>

The per-socket HSMP attributes are only described in
Documentation/arch/x86/amd_hsmp.rst, and have no entry in
Documentation/ABI/.

Document /sys/class/amd_hsmp/socketX/ and its attributes as the
interface for userspace, whichever driver probed. The historical
/sys/devices/platform/AMDI0097:0X/ and
/sys/devices/platform/amd_hsmp/socketX/ locations keep working.

Assisted-by: claude-opus-5-5
Signed-off-by: Erwan Velu <e.velu@criteo.com>
---
 .../ABI/testing/sysfs-class-amd_hsmp          | 120 ++++++++++++++++++
 MAINTAINERS                                   |   1 +
 2 files changed, 121 insertions(+)
 create mode 100644 Documentation/ABI/testing/sysfs-class-amd_hsmp

diff --git a/Documentation/ABI/testing/sysfs-class-amd_hsmp b/Documentation/ABI/testing/sysfs-class-amd_hsmp
new file mode 100644
index 000000000000..32da798dd2ad
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-class-amd_hsmp
@@ -0,0 +1,120 @@
+What:		/sys/class/amd_hsmp/socketX/
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	One directory per CPU socket exposing the AMD Host System
+		Management Port (HSMP) per-socket attributes. X is the socket
+		index, starting at 0.
+
+		The directory is a link to a device whose parent is the device
+		of the driver that probed the socket, so the attributes below
+		are the same whichever driver is in use:
+
+		- ACPI driver:
+		  /sys/devices/platform/AMDI0097:0X/amd_hsmp/socketX/
+		- plat driver:
+		  /sys/devices/platform/amd_hsmp/amd_hsmp/socketX/
+
+		The historical /sys/devices/platform/AMDI0097:0X/ attributes
+		and /sys/devices/platform/amd_hsmp/socketX/ (now a symlink to
+		the socket device) keep working.
+
+		On client platforms, only smu_fw_version and protocol_version
+		are visible.
+
+What:		/sys/class/amd_hsmp/socketX/metrics_bin
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Binary HSMP metrics table of the socket, as defined by
+		struct hsmp_metric_table in arch/x86/include/uapi/asm/amd_hsmp.h.
+
+		Only supported with HSMP protocol version 6. On protocol version
+		7 and later, a read returns -EOPNOTSUPP and the table must be
+		read with the HSMP_IOCTL_GET_TELEMETRY_DATA ioctl on /dev/hsmp.
+		lseek() is not supported, the whole table is read at once.
+
+What:		/sys/class/amd_hsmp/socketX/smu_fw_version
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) SMU firmware version, as "major.minor.debug".
+
+What:		/sys/class/amd_hsmp/socketX/protocol_version
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) HSMP interface version.
+
+What:		/sys/class/amd_hsmp/socketX/c0_residency_input
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Percentage of cores in C0 state.
+
+What:		/sys/class/amd_hsmp/socketX/prochot_status
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) 1 if the processor is at its thermal threshold value
+		(PROCHOT asserted), 0 otherwise.
+
+What:		/sys/class/amd_hsmp/socketX/ddr_max_bw
+What:		/sys/class/amd_hsmp/socketX/ddr_utilised_bw_input
+What:		/sys/class/amd_hsmp/socketX/ddr_utilised_bw_perc_input
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) DDR bandwidth of the socket:
+
+		==========================	=================================
+		ddr_max_bw			Theoretical maximum, in GB/s
+		ddr_utilised_bw_input		Currently utilized, in GB/s
+		ddr_utilised_bw_perc_input	Currently utilized, in percent
+		==========================	=================================
+
+What:		/sys/class/amd_hsmp/socketX/mclk_input
+What:		/sys/class/amd_hsmp/socketX/fclk_input
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Memory clock (mclk_input) and fabric clock (fclk_input),
+		in MHz.
+
+What:		/sys/class/amd_hsmp/socketX/clk_fmax
+What:		/sys/class/amd_hsmp/socketX/clk_fmin
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Maximum (clk_fmax) and minimum (clk_fmin) frequency of
+		the socket, in MHz.
+
+What:		/sys/class/amd_hsmp/socketX/cclk_freq_limit_input
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Core clock frequency limit of the socket, in MHz.
+
+What:		/sys/class/amd_hsmp/socketX/pwr_current_active_freq_limit
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Current active frequency limit of the socket, in MHz.
+
+What:		/sys/class/amd_hsmp/socketX/pwr_current_active_freq_limit_source
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Sources of the current active frequency limit, one name
+		per line, among: cHTC-Active, PROCHOT, TDC limit, PPT Limit,
+		OPN Max, Reliability Limit, APML Agent, HSMP Agent.
+
+What:		/sys/class/amd_hsmp/socketX/pwr_current_active_freq_limit_source_raw
+Date:		November 2026
+KernelVersion:	7.5
+Contact:	platform-driver-x86@vger.kernel.org
+Description:	(RO) Sources of the current active frequency limit, as a
+		hexadecimal bitmask (e.g. "0x0003"). Bits 0 to 7 are, in order:
+		cHTC-Active, PROCHOT, TDC limit, PPT Limit, OPN Max, Reliability
+		Limit, APML Agent, HSMP Agent. The bit assignment comes from the
+		HSMP specification: new sources are only appended.
diff --git a/MAINTAINERS b/MAINTAINERS
index ccbcdc0799b9..1e23f4e5c902 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1193,6 +1193,7 @@ M:	Naveen Krishna Chatradhi <naveenkrishna.chatradhi@amd.com>
 R:	Carlos Bilbao <carlos.bilbao@kernel.org>
 L:	platform-driver-x86@vger.kernel.org
 S:	Maintained
+F:	Documentation/ABI/testing/sysfs-class-amd_hsmp
 F:	Documentation/arch/x86/amd_hsmp.rst
 F:	arch/x86/include/asm/amd/hsmp.h
 F:	arch/x86/include/uapi/asm/amd_hsmp.h
-- 
2.53.0


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

end of thread, other threads:[~2026-11-16 15:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 15:51 [PATCH v2 0/5] platform/x86/amd/hsmp: Unify per-socket sysfs metrics Erwan Velu
2026-11-16 15:51 ` [PATCH v2 1/5] platform/x86/amd/hsmp: Move per-socket sysfs attributes to common code Erwan Velu
2026-11-16 15:51 ` [PATCH v2 2/5] platform/x86/amd/hsmp: Add amd_hsmp class with per-socket devices Erwan Velu
2026-11-16 15:51 ` [PATCH v2 3/5] platform/x86/amd/hsmp: Expose socket attributes from the platform driver Erwan Velu
2026-11-16 15:51 ` [PATCH v2 4/5] platform/x86/amd/hsmp: Add pwr_current_active_freq_limit_source_raw Erwan Velu
2026-11-16 15:51 ` [PATCH v2 5/5] Documentation/ABI: Add sysfs-class-amd_hsmp Erwan Velu

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®