From: Erwan Velu <erwanaliasr1@gmail.com>
To: "Naveen Krishna Chatradhi" <naveenkrishna.chatradhi@amd.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Hans de Goede" <hansg@kernel.org>
Cc: Carlos Bilbao <carlos.bilbao@kernel.org>,
Muralidhara M K <muralidhara.mk@amd.com>,
Suma Hegde <suma.hegde@amd.com>,
Muthusamy Ramalingam <muthusamy.ramalingam@amd.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org, Erwan Velu <e.velu@criteo.com>
Subject: [PATCH v2 3/5] platform/x86/amd/hsmp: Expose socket attributes from the platform driver
Date: Mon, 16 Nov 2026 16:51:45 +0100 [thread overview]
Message-ID: <20261116155147.769630-4-erwanaliasr1@gmail.com> (raw)
In-Reply-To: <20261116155147.769630-1-erwanaliasr1@gmail.com>
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
next prev parent reply other threads:[~2026-11-16 15:52 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261116155147.769630-4-erwanaliasr1@gmail.com \
--to=erwanaliasr1@gmail.com \
--cc=carlos.bilbao@kernel.org \
--cc=e.velu@criteo.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=muralidhara.mk@amd.com \
--cc=muthusamy.ramalingam@amd.com \
--cc=naveenkrishna.chatradhi@amd.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=suma.hegde@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®