All of lore.kernel.org
 help / color / mirror / Atom feed
From: Erwan Velu <erwanaliasr1@gmail.com>
To: platform-driver-x86@vger.kernel.org
Cc: "Naveen Krishna Chatradhi" <naveenkrishna.chatradhi@amd.com>,
	"Carlos Bilbao" <carlos.bilbao@kernel.org>,
	"Hans de Goede" <hansg@kernel.org>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 3/4] platform/x86/amd/hsmp: Expose socket attributes from the platform driver
Date: Wed,  7 Oct 2026 14:59:07 +0200	[thread overview]
Message-ID: <20261007125908.321186-4-erwanaliasr1@gmail.com> (raw)
In-Reply-To: <20261007125908.321186-1-erwanaliasr1@gmail.com>

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

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@criteo.com>
---
 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


  parent reply	other threads:[~2026-10-07 12:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-07 12:59 [PATCH 0/4] platform/x86/amd/hsmp: Unify per-socket sysfs metrics Erwan Velu
2026-10-07 12:59 ` [PATCH 1/4] platform/x86/amd/hsmp: Move per-socket sysfs attributes to common code Erwan Velu
2026-10-07 12:59 ` [PATCH 2/4] platform/x86/amd/hsmp: Add /sys/devices/amd_hsmp socket devices Erwan Velu
2026-10-07 12:59 ` Erwan Velu [this message]
2026-10-07 12:59 ` [PATCH 4/4] platform/x86/amd/hsmp: Add pwr_current_active_freq_limit_source_raw 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=20261007125908.321186-4-erwanaliasr1@gmail.com \
    --to=erwanaliasr1@gmail.com \
    --cc=carlos.bilbao@kernel.org \
    --cc=hansg@kernel.org \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naveenkrishna.chatradhi@amd.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.