From: Muralidhara M K <muralidhara.mk@amd.com>
To: <ilpo.jarvinen@linux.intel.com>, <gregkh@linuxfoundation.org>,
<rafael@kernel.org>
Cc: <platform-driver-x86@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <driver-core@lists.linux.dev>,
Muralidhara M K <muralidhara.mk@amd.com>,
Muthusamy Ramalingam <muthusamy.ramalingam@amd.com>
Subject: [PATCH v2 5/7] platform/x86/amd/hsmp: Add dynamic table size for metric table
Date: Mon, 27 Apr 2026 21:21:27 +0530 [thread overview]
Message-ID: <20260427155129.545327-6-muralidhara.mk@amd.com> (raw)
In-Reply-To: <20260427155129.545327-1-muralidhara.mk@amd.com>
Prepare the metric table infrastructure for supporting variable-sized
tables used by different processor families.
- Add hsmp_table_size to hsmp_plat_device for runtime table size
configuration.
- Update the HSMP_GET_METRIC_TABLE_DRAM_ADDR message descriptor
response_sz from 2 to 3 to read the new args[2] field that carries
the DRAM region size in bytes.
- Use msg.args[2] from SMU to set hsmp_pdev.hsmp_table_size directly.
For older firmware that does not populate args[2] (returns 0), fall
back to sizeof(struct hsmp_metric_table) for backward compatibility.
- Use hsmp_pdev.hsmp_table_size for ioremap and size validation
instead of hard-coding sizeof(struct hsmp_metric_table).
- Add a bin_size callback in both acpi.c and plat.c that returns
hsmp_table_size, overriding the static bin_attribute .size at sysfs
group registration time so that i_size reflects the actual table
size reported by SMU.
This makes future processor support automatic as long as SMU reports
the correct DRAM size.
Co-developed-by: Muthusamy Ramalingam <muthusamy.ramalingam@amd.com>
Signed-off-by: Muthusamy Ramalingam <muthusamy.ramalingam@amd.com>
Signed-off-by: Muralidhara M K <muralidhara.mk@amd.com>
---
Changes v1->v2: New Patch
arch/x86/include/uapi/asm/amd_hsmp.h | 5 +++--
drivers/platform/x86/amd/hsmp/acpi.c | 7 +++++++
drivers/platform/x86/amd/hsmp/hsmp.c | 10 +++++++---
drivers/platform/x86/amd/hsmp/hsmp.h | 1 +
drivers/platform/x86/amd/hsmp/plat.c | 7 +++++++
5 files changed, 25 insertions(+), 5 deletions(-)
diff --git a/arch/x86/include/uapi/asm/amd_hsmp.h b/arch/x86/include/uapi/asm/amd_hsmp.h
index da3e3bbfa33e..b86bbc929395 100644
--- a/arch/x86/include/uapi/asm/amd_hsmp.h
+++ b/arch/x86/include/uapi/asm/amd_hsmp.h
@@ -342,11 +342,12 @@ static const struct hsmp_msg_desc hsmp_msg_desc_table[]
{0, 0, HSMP_GET},
/*
- * HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args = 0, response_sz = 2
+ * HSMP_GET_METRIC_TABLE_DRAM_ADDR, num_args = 0, response_sz = 3
* output: args[0] = lower 32 bits of the address
* output: args[1] = upper 32 bits of the address
+ * output: args[2] = DRAM region size in bytes
*/
- {0, 2, HSMP_GET},
+ {0, 3, HSMP_GET},
/*
* HSMP_SET_XGMI_PSTATE_RANGE, num_args = 1, response_sz = 0/1
diff --git a/drivers/platform/x86/amd/hsmp/acpi.c b/drivers/platform/x86/amd/hsmp/acpi.c
index 8044df862275..f3cfc99ef73d 100644
--- a/drivers/platform/x86/amd/hsmp/acpi.c
+++ b/drivers/platform/x86/amd/hsmp/acpi.c
@@ -250,6 +250,12 @@ static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
return 0;
}
+static size_t hsmp_metric_tbl_bin_size(struct kobject *kobj,
+ const struct bin_attribute *battr, int id)
+{
+ return hsmp_pdev->hsmp_table_size;
+}
+
static umode_t hsmp_is_sock_dev_attr_visible(struct kobject *kobj,
struct attribute *attr, int id)
{
@@ -563,6 +569,7 @@ static const struct attribute_group hsmp_attr_grp = {
.attrs = hsmp_dev_attr_list,
.is_bin_visible = hsmp_is_sock_attr_visible,
.is_visible = hsmp_is_sock_dev_attr_visible,
+ .bin_size = hsmp_metric_tbl_bin_size,
};
static const struct attribute_group *hsmp_groups[] = {
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.c b/drivers/platform/x86/amd/hsmp/hsmp.c
index 9bad58fef304..d6e377078182 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.c
+++ b/drivers/platform/x86/amd/hsmp/hsmp.c
@@ -356,8 +356,7 @@ ssize_t hsmp_metric_tbl_read(struct hsmp_socket *sock, char *buf, size_t size)
return -ENOMEM;
}
- /* Do not support lseek(), also don't allow more than the size of metric table */
- if (size != sizeof(struct hsmp_metric_table)) {
+ if (size != hsmp_pdev.hsmp_table_size) {
dev_err(sock->dev, "Wrong buffer size\n");
return -EINVAL;
}
@@ -398,8 +397,13 @@ int hsmp_get_tbl_dram_base(u16 sock_ind)
dev_err(sock->dev, "Invalid DRAM address for metric table\n");
return -ENOMEM;
}
+ /* SMU returns table size from Family 1Ah Model 50h and forward */
+ if (msg.args[2])
+ hsmp_pdev.hsmp_table_size = msg.args[2];
+ else
+ hsmp_pdev.hsmp_table_size = sizeof(struct hsmp_metric_table);
sock->metric_tbl_addr = devm_ioremap(sock->dev, dram_addr,
- sizeof(struct hsmp_metric_table));
+ hsmp_pdev.hsmp_table_size);
if (!sock->metric_tbl_addr) {
dev_err(sock->dev, "Failed to ioremap metric table addr\n");
return -ENOMEM;
diff --git a/drivers/platform/x86/amd/hsmp/hsmp.h b/drivers/platform/x86/amd/hsmp/hsmp.h
index b153527e0a0d..e7f051475728 100644
--- a/drivers/platform/x86/amd/hsmp/hsmp.h
+++ b/drivers/platform/x86/amd/hsmp/hsmp.h
@@ -55,6 +55,7 @@ struct hsmp_plat_device {
u32 proto_ver;
u16 num_sockets;
bool is_probed;
+ size_t hsmp_table_size;
};
int hsmp_cache_proto_ver(u16 sock_ind);
diff --git a/drivers/platform/x86/amd/hsmp/plat.c b/drivers/platform/x86/amd/hsmp/plat.c
index e07f68575055..d8dd90dfeb4e 100644
--- a/drivers/platform/x86/amd/hsmp/plat.c
+++ b/drivers/platform/x86/amd/hsmp/plat.c
@@ -62,6 +62,12 @@ static ssize_t hsmp_metric_tbl_plat_read(struct file *filp, struct kobject *kobj
return hsmp_metric_tbl_read(sock, buf, count);
}
+static size_t hsmp_metric_tbl_bin_size(struct kobject *kobj,
+ const struct bin_attribute *battr, int id)
+{
+ return hsmp_pdev->hsmp_table_size;
+}
+
static umode_t hsmp_is_sock_attr_visible(struct kobject *kobj,
const struct bin_attribute *battr, int id)
{
@@ -114,6 +120,7 @@ HSMP_BIN_ATTR(7, *sock7_attr_list);
static const struct attribute_group sock##index##_attr_grp = { \
.bin_attrs = _list, \
.is_bin_visible = hsmp_is_sock_attr_visible, \
+ .bin_size = hsmp_metric_tbl_bin_size, \
.name = #_name, \
}
--
2.34.1
next prev parent reply other threads:[~2026-04-27 15:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-27 15:51 [PATCH v2 0/7] AMD HSMP: metrics table improvements and Family 1Ah Model 50h-5Fh support Muralidhara M K
2026-04-27 15:51 ` [PATCH v2 1/7] platform/x86/amd/hsmp: Add new HSMP messages for Family 1Ah, Model 50h-5Fh Muralidhara M K
2026-04-27 15:51 ` [PATCH v2 2/7] platform/x86/amd/hsmp: Add metrics table support for Family 1Ah " Muralidhara M K
2026-04-27 15:51 ` [PATCH v2 3/7] platform/x86/amd/hsmp: Unify response_sz validation to an upper-bound check Muralidhara M K
2026-04-27 15:51 ` [PATCH v2 4/7] sysfs: Add SYSFS_HUGE_BIN_FILE flag for binary attributes larger than PAGE_SIZE Muralidhara M K
2026-04-28 7:20 ` K Prateek Nayak
2026-04-27 15:51 ` Muralidhara M K [this message]
2026-04-27 15:51 ` [PATCH v2 6/7] platform/x86/amd/hsmp: Make metric table read locking use guard(mutex) Muralidhara M K
2026-04-27 15:51 ` [PATCH v2 7/7] platform/x86/amd/hsmp: Support SYSFS_HUGE_BIN_FILE for metric table reads Muralidhara M K
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=20260427155129.545327-6-muralidhara.mk@amd.com \
--to=muralidhara.mk@amd.com \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=muthusamy.ramalingam@amd.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=rafael@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox