[PATCH 3/4] platform/x86/amd/hsmp: Expose socket attributes from the platform driver

From: Erwan Velu

Date: Wed Oct 07 2026 - 09:15:41 EST


From: Erwan Velu <e.velu@xxxxxxxxxx>

The platform driver only exposes metrics_bin, so on systems without the
HSMP ACPI object, attributes such as pwr_current_active_freq_limit are
missing although the driver can send the same HSMP messages as the ACPI
one.

Register the /sys/devices/amd_hsmp/socketN devices from the platform
driver too, so both drivers expose the same attributes at the same
location. The legacy amd_hsmp/socketN/metrics_bin files are kept.

The devices are torn down by a devres action added after
hsmp_pltdrv_release(), so they are gone before the socket array they
reference is released, and they are registered before /dev/hsmp so a
probe failure leaves nothing behind.

Assisted-by: claude-opus-5-5
Signed-off-by: Erwan Velu <e.velu@xxxxxxxxxx>
---
Documentation/arch/x86/amd_hsmp.rst | 16 ++++++++++------
drivers/platform/x86/amd/hsmp/plat.c | 20 ++++++++++++++++++++
2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/Documentation/arch/x86/amd_hsmp.rst b/Documentation/arch/x86/amd_hsmp.rst
index aba4a009bd8d..954e938eea3d 100644
--- a/Documentation/arch/x86/amd_hsmp.rst
+++ b/Documentation/arch/x86/amd_hsmp.rst
@@ -57,11 +57,16 @@ In-kernel integration:
HSMP sysfs interface
====================

-The ACPI driver exposes its per socket sysfs files in a per socket
-directory created at /sys/devices/amd_hsmp/socket%d/.
+Both the ACPI and plat drivers expose the same set of per socket sysfs
+files in a per socket directory created at /sys/devices/amd_hsmp/socket%d/.

-For backward compatibility, the files are also available under
-/sys/devices/platform/AMDI0097:0X/.
+For backward compatibility, the files are also available at their
+historical locations:
+
+* ACPI driver: all the files of this section under
+ /sys/devices/platform/AMDI0097:0X/.
+* plat driver: metrics_bin only, under
+ /sys/devices/platform/amd_hsmp/socket%d/.

1. Metrics table binary sysfs

@@ -69,8 +74,7 @@ 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/devices/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 e9b2b809c0f5..03317f342c69 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -222,9 +222,18 @@ static void hsmp_pltdrv_release(void *data)
hsmp_pdev->sock = NULL;
}

+static void hsmp_pltdrv_sock_devs_release(void *data)
+{
+ u16 i;
+
+ for (i = 0; i < hsmp_pdev->num_sockets; i++)
+ hsmp_sock_dev_unregister(&hsmp_pdev->sock[i]);
+}
+
static int hsmp_pltdrv_probe(struct platform_device *pdev)
{
int ret;
+ u16 i;

hsmp_pdev->sock = devm_kcalloc(&pdev->dev, hsmp_pdev->num_sockets,
sizeof(*hsmp_pdev->sock),
@@ -253,6 +262,17 @@ static int hsmp_pltdrv_probe(struct platform_device *pdev)
return ret;
}

+ ret = devm_add_action_or_reset(&pdev->dev, hsmp_pltdrv_sock_devs_release, NULL);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < hsmp_pdev->num_sockets; i++) {
+ ret = hsmp_sock_dev_register(&hsmp_pdev->sock[i]);
+ if (ret)
+ dev_warn(&pdev->dev, "Failed to register HSMP socket%u device: %d\n",
+ i, ret);
+ }
+
ret = hsmp_misc_register(&pdev->dev);
if (ret) {
dev_err(&pdev->dev, "Failed to register misc device\n");
--
2.53.0