* [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex
2026-11-16 12:02 [PATCH v1 0/4] misc: amd-sbi: add DIMM thermal sensors to sbrmi Akshay Gupta
@ 2026-11-16 12:02 ` Akshay Gupta
2026-11-16 12:15 ` sashiko-bot
2026-11-16 12:02 ` [PATCH v1 2/4] dt-bindings: hwmon: add DIMM thermal sensor properties Akshay Gupta
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Akshay Gupta @ 2026-11-16 12:02 UTC (permalink / raw)
To: linux-hwmon, devicetree, linux-kernel, linux-doc
Cc: linux, robh, krzk+dt, conor+dt, corbet, skhan, rdunlap, arnd,
gregkh, naveenkrishna.chatradhi, Anand.Umarji, Prathima Lk,
Akshay Gupta
From: Prathima Lk <Prathima.Lk@amd.com>
Convert the manual mutex_lock()/mutex_unlock() pairs protecting
sbrmi_data->lock to guard() from <linux/cleanup.h>. The lock is released
automatically on return, so the exit_unlock labels and their trailing
mutex_unlock() calls are removed and error paths return directly.
rmi_cpuid_read() clears msg->cpu_in_out on every error path, which the
exit_unlock label used to do. Move the body into __rmi_cpuid_read() and
keep the clearing in the locked wrapper. In rmi_mailbox_xfer(), the goto
to exit_clear_alert becomes an if block.
No functional change intended.
Signed-off-by: Prathima Lk <Prathima.Lk@amd.com>
Signed-off-by: Akshay Gupta <Akshay.Gupta@amd.com>
---
drivers/misc/amd-sbi/rmi-core.c | 148 ++++++++++++++++----------------
1 file changed, 72 insertions(+), 76 deletions(-)
diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c
index 95c9109101b5..277f12140972 100644
--- a/drivers/misc/amd-sbi/rmi-core.c
+++ b/drivers/misc/amd-sbi/rmi-core.c
@@ -5,6 +5,7 @@
*
* Copyright (C) 2025 Advanced Micro Devices, Inc.
*/
+#include <linux/cleanup.h>
#include <linux/delay.h>
#include <linux/err.h>
#include <linux/fs.h>
@@ -185,19 +186,18 @@ static int rmi_cpuid_input_ext(struct sbrmi_data *data, struct apml_cpuid_msg *m
}
/* Read CPUID function protocol */
-static int rmi_cpuid_read(struct sbrmi_data *data,
- struct apml_cpuid_msg *msg)
+static int __rmi_cpuid_read(struct sbrmi_data *data,
+ struct apml_cpuid_msg *msg)
{
struct cpu_msr_outdata output = {0};
int ret, hw_status;
u16 thread;
- mutex_lock(&data->lock);
/* cache the rev value to identify if protocol is supported or not */
if (!data->rev) {
ret = sbrmi_get_rev(data);
if (ret < 0)
- goto exit_unlock;
+ return ret;
}
/* Extract thread from the input msg structure */
@@ -206,22 +206,20 @@ static int rmi_cpuid_read(struct sbrmi_data *data,
switch (data->rev) {
case 0x10:
/* CPUID protocol for REV 0x10 is not supported*/
- ret = -EOPNOTSUPP;
- goto exit_unlock;
+ return -EOPNOTSUPP;
case 0x20:
ret = rmi_cpuid_input(data, msg, thread);
if (ret)
- goto exit_unlock;
+ return ret;
break;
case 0x21:
case 0x31:
ret = rmi_cpuid_input_ext(data, msg, thread);
if (ret)
- goto exit_unlock;
+ return ret;
break;
default:
- ret = -EOPNOTSUPP;
- goto exit_unlock;
+ return -EOPNOTSUPP;
}
/*
@@ -233,32 +231,40 @@ static int rmi_cpuid_read(struct sbrmi_data *data,
ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, hw_status,
hw_status & HW_ALERT_MASK, 500, 2000000);
if (ret)
- goto exit_unlock;
+ return ret;
ret = regmap_bulk_read(data->regmap, CPUID_MCA_CMD,
&output, CPUID_RD_REG_LEN);
if (ret < 0)
- goto exit_unlock;
+ return ret;
ret = regmap_write(data->regmap, SBRMI_STATUS,
HW_ALERT_MASK);
if (ret < 0)
- goto exit_unlock;
+ return ret;
- if (output.num_bytes != CPUID_RD_REG_LEN - 1) {
- ret = -EMSGSIZE;
- goto exit_unlock;
- }
+ if (output.num_bytes != CPUID_RD_REG_LEN - 1)
+ return -EMSGSIZE;
if (output.status) {
- ret = -EPROTOTYPE;
msg->fw_ret_code = output.status;
- goto exit_unlock;
+ return -EPROTOTYPE;
}
msg->cpu_in_out = output.value;
-exit_unlock:
+
+ return 0;
+}
+
+static int rmi_cpuid_read(struct sbrmi_data *data,
+ struct apml_cpuid_msg *msg)
+{
+ int ret;
+
+ guard(mutex)(&data->lock);
+
+ ret = __rmi_cpuid_read(data, msg);
if (ret < 0)
msg->cpu_in_out = 0;
- mutex_unlock(&data->lock);
+
return ret;
}
@@ -306,12 +312,13 @@ static int rmi_mca_msr_read(struct sbrmi_data *data,
int hw_status;
u16 thread;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
+
/* cache the rev value to identify if protocol is supported or not */
if (!data->rev) {
ret = sbrmi_get_rev(data);
if (ret < 0)
- goto exit_unlock;
+ return ret;
}
/* Extract thread from the input msg structure */
@@ -320,22 +327,20 @@ static int rmi_mca_msr_read(struct sbrmi_data *data,
switch (data->rev) {
case 0x10:
/* MCAMSR protocol for REV 0x10 is not supported*/
- ret = -EOPNOTSUPP;
- goto exit_unlock;
+ return -EOPNOTSUPP;
case 0x20:
ret = rmi_mcamsr_input(data, msg, thread);
if (ret)
- goto exit_unlock;
+ return ret;
break;
case 0x21:
case 0x31:
ret = rmi_mcamsr_input_ext(data, msg, thread);
if (ret)
- goto exit_unlock;
+ return ret;
break;
default:
- ret = -EOPNOTSUPP;
- goto exit_unlock;
+ return -EOPNOTSUPP;
}
/*
@@ -347,32 +352,27 @@ static int rmi_mca_msr_read(struct sbrmi_data *data,
ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, hw_status,
hw_status & HW_ALERT_MASK, 500, 2000000);
if (ret)
- goto exit_unlock;
+ return ret;
ret = regmap_bulk_read(data->regmap, CPUID_MCA_CMD,
&output, MSR_RD_REG_LEN);
if (ret < 0)
- goto exit_unlock;
+ return ret;
ret = regmap_write(data->regmap, SBRMI_STATUS,
HW_ALERT_MASK);
if (ret < 0)
- goto exit_unlock;
+ return ret;
- if (output.num_bytes != MSR_RD_REG_LEN - 1) {
- ret = -EMSGSIZE;
- goto exit_unlock;
- }
+ if (output.num_bytes != MSR_RD_REG_LEN - 1)
+ return -EMSGSIZE;
if (output.status) {
- ret = -EPROTOTYPE;
msg->fw_ret_code = output.status;
- goto exit_unlock;
+ return -EPROTOTYPE;
}
msg->mcamsr_in_out = output.value;
-exit_unlock:
- mutex_unlock(&data->lock);
- return ret;
+ return 0;
}
int rmi_mailbox_xfer(struct sbrmi_data *data,
@@ -383,19 +383,19 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
int sw_status;
u8 byte;
- mutex_lock(&data->lock);
+ guard(mutex)(&data->lock);
msg->fw_ret_code = 0;
/* Indicate firmware a command is to be serviced */
ret = regmap_write(data->regmap, SBRMI_INBNDMSG7, START_CMD);
if (ret < 0)
- goto exit_unlock;
+ return ret;
/* Write the command to SBRMI::InBndMsg_inst0 */
ret = regmap_write(data->regmap, SBRMI_INBNDMSG0, msg->cmd);
if (ret < 0)
- goto exit_unlock;
+ return ret;
/*
* For both read and write the initiator (BMC) writes
@@ -406,7 +406,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
byte = (msg->mb_in_out >> i * 8) & 0xff;
ret = regmap_write(data->regmap, SBRMI_INBNDMSG1 + i, byte);
if (ret < 0)
- goto exit_unlock;
+ return ret;
}
/*
@@ -415,7 +415,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
*/
ret = regmap_write(data->regmap, SBRMI_SW_INTERRUPT, TRIGGER_MAILBOX);
if (ret < 0)
- goto exit_unlock;
+ return ret;
/*
* Firmware will write SBRMI::Status[SwAlertSts]=1 to generate
@@ -425,29 +425,27 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, sw_status,
sw_status & SW_ALERT_MASK, 500, 2000000);
if (ret)
- goto exit_unlock;
+ return ret;
ret = regmap_read(data->regmap, SBRMI_OUTBNDMSG7, &ec);
- if (ret || ec)
- goto exit_clear_alert;
-
- /* Clear the input value before updating the output data */
- msg->mb_in_out = 0;
-
- /*
- * For a read operation, the initiator (BMC) reads the firmware
- * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1]
- * {SBRMI_x34(MSB):SBRMI_x31(LSB)}.
- */
- for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) {
- ret = regmap_read(data->regmap,
- SBRMI_OUTBNDMSG1 + i, &bytes);
- if (ret < 0)
- break;
- msg->mb_in_out |= bytes << i * 8;
+ if (!ret && !ec) {
+ /* Clear the input value before updating the output data */
+ msg->mb_in_out = 0;
+
+ /*
+ * For a read operation, the initiator (BMC) reads the firmware
+ * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1]
+ * {SBRMI_x34(MSB):SBRMI_x31(LSB)}.
+ */
+ for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) {
+ ret = regmap_read(data->regmap,
+ SBRMI_OUTBNDMSG1 + i, &bytes);
+ if (ret < 0)
+ break;
+ msg->mb_in_out |= bytes << i * 8;
+ }
}
-exit_clear_alert:
/*
* BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the
* ALERT to initiator
@@ -458,8 +456,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
ret = -EPROTOTYPE;
msg->fw_ret_code = ec;
}
-exit_unlock:
- mutex_unlock(&data->lock);
+
return ret;
}
@@ -474,17 +471,16 @@ static int apml_rmi_reg_xfer(struct sbrmi_data *data,
if (copy_from_user(&msg, arg, sizeof(struct apml_reg_xfer_msg)))
return -EFAULT;
- mutex_lock(&data->lock);
- if (msg.rflag) {
- ret = regmap_read(data->regmap, msg.reg_addr, &data_read);
- if (!ret)
- msg.data_in_out = data_read;
- } else {
- ret = regmap_write(data->regmap, msg.reg_addr, msg.data_in_out);
+ scoped_guard(mutex, &data->lock) {
+ if (msg.rflag) {
+ ret = regmap_read(data->regmap, msg.reg_addr, &data_read);
+ if (!ret)
+ msg.data_in_out = data_read;
+ } else {
+ ret = regmap_write(data->regmap, msg.reg_addr, msg.data_in_out);
+ }
}
- mutex_unlock(&data->lock);
-
if (msg.rflag && !ret)
if (copy_to_user(arg, &msg, sizeof(struct apml_reg_xfer_msg)))
return -EFAULT;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex
2026-11-16 12:02 ` [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex Akshay Gupta
@ 2026-11-16 12:15 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-16 12:15 UTC (permalink / raw)
To: Akshay Gupta, linux-hwmon, devicetree; +Cc: robh, conor+dt
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] misc: amd-sbi: uninitialized ec and error overwrite in
rmi_mailbox_xfer() [1]
--
commit 8e0c735b23732b6b78100642d3a437c0cd3041c0
Author: Prathima Lk <Prathima.Lk@amd.com>
misc: amd-sbi: use guard() for data->lock mutex
This commit converts manual mutex_lock() and mutex_unlock() calls on
data->lock in drivers/misc/amd-sbi/rmi-core.c to guard() and
scoped_guard(), simplifying the error-return paths.
> diff --git a/drivers/misc/amd-sbi/rmi-core.c b/drivers/misc/amd-sbi/rmi-core.c
> index 95c9109101b53..277f121409728 100644
> --- a/drivers/misc/amd-sbi/rmi-core.c
> +++ b/drivers/misc/amd-sbi/rmi-core.c
[ ... ]
> @@ -425,29 +425,27 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
> ret = regmap_read_poll_timeout(data->regmap, SBRMI_STATUS, sw_status,
> sw_status & SW_ALERT_MASK, 500, 2000000);
> if (ret)
> - goto exit_unlock;
> + return ret;
>
> ret = regmap_read(data->regmap, SBRMI_OUTBNDMSG7, &ec);
> - if (ret || ec)
> - goto exit_clear_alert;
> -
> - /* Clear the input value before updating the output data */
> - msg->mb_in_out = 0;
> -
> - /*
> - * For a read operation, the initiator (BMC) reads the firmware
> - * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1]
> - * {SBRMI_x34(MSB):SBRMI_x31(LSB)}.
> - */
> - for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) {
> - ret = regmap_read(data->regmap,
> - SBRMI_OUTBNDMSG1 + i, &bytes);
> - if (ret < 0)
> - break;
> - msg->mb_in_out |= bytes << i * 8;
> + if (!ret && !ec) {
> + /* Clear the input value before updating the output data */
> + msg->mb_in_out = 0;
> +
> + /*
> + * For a read operation, the initiator (BMC) reads the firmware
> + * response Command Data Out[31:0] from SBRMI::OutBndMsg_inst[4:1]
> + * {SBRMI_x34(MSB):SBRMI_x31(LSB)}.
> + */
> + for (i = 0; i < AMD_SBI_MB_DATA_SIZE; i++) {
> + ret = regmap_read(data->regmap,
> + SBRMI_OUTBNDMSG1 + i, &bytes);
> + if (ret < 0)
> + break;
> + msg->mb_in_out |= bytes << i * 8;
> + }
> }
>
> -exit_clear_alert:
> /*
> * BMC must write 1'b1 to SBRMI::Status[SwAlertSts] to clear the
> * ALERT to initiator
> @@ -458,8 +456,7 @@ int rmi_mailbox_xfer(struct sbrmi_data *data,
> ret = -EPROTOTYPE;
> msg->fw_ret_code = ec;
> }
> -exit_unlock:
> - mutex_unlock(&data->lock);
> +
> return ret;
> }
[Severity: High]
This problem wasn't introduced by this patch [1], but what happens
if regmap_read() fails when reading SBRMI_OUTBNDMSG7 or
SBRMI_OUTBNDMSG1..4?
ec is declared on the stack without initialization in rmi_mailbox_xfer().
If reading SBRMI_OUTBNDMSG7 fails, ec remains uninitialized when checked
at "if (ec)" at the end of the function; if it happens to be non-zero, the
uninitialized value is stored into msg->fw_ret_code and copied to
userspace by apml_mailbox_xfer().
In addition, the regmap_write() to SBRMI_STATUS unconditionally overwrites
ret, so a failed read of SBRMI_OUTBNDMSG7 (when ec happens to be 0) or
SBRMI_OUTBNDMSG1..4 returns 0 when clearing the alert succeeds, leaving
callers with stale or partial msg->mb_in_out data.
[1] https://sashiko.dev/#/bug/linux-37f3c6ab-ea0e-4ada-a81e-e6c232558ae3
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116120228.865196-1-Akshay.Gupta@amd.com?part=1
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 2/4] dt-bindings: hwmon: add DIMM thermal sensor properties
2026-11-16 12:02 [PATCH v1 0/4] misc: amd-sbi: add DIMM thermal sensors to sbrmi Akshay Gupta
2026-11-16 12:02 ` [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex Akshay Gupta
@ 2026-11-16 12:02 ` Akshay Gupta
2026-11-16 12:11 ` sashiko-bot
2026-11-16 12:02 ` [PATCH v1 3/4] misc: amd-sbi: add DIMM thermal sensor support Akshay Gupta
2026-11-16 12:02 ` [PATCH v1 4/4] Documentation: hwmon: document DIMM thermal sensor channels Akshay Gupta
3 siblings, 1 reply; 9+ messages in thread
From: Akshay Gupta @ 2026-11-16 12:02 UTC (permalink / raw)
To: linux-hwmon, devicetree, linux-kernel, linux-doc
Cc: linux, robh, krzk+dt, conor+dt, corbet, skhan, rdunlap, arnd,
gregkh, naveenkrishna.chatradhi, Anand.Umarji, Prathima Lk,
Akshay Gupta
From: Prathima Lk <Prathima.Lk@amd.com>
The SB-RMI mailbox also reports the temperature of the TS0/TS1 thermal
sensors on each DIMM (command 0x48, Mode 1 DIMM_ADDRESS). Boards differ
in how many DIMMs are fitted per memory channel and which sensors are
populated, so describe both in the binding.
Add two optional properties:
- amd,dpc: uint8, DIMMs per channel, 1 or 2 (default 1).
- amd,dimm-ids: uint8 array of 1 to 32 unique Mode 1 DIMM_ADDRESS
values, one per sensor to report. Encoding: bit[7]=1 (Mode 1),
bit[6] sensor (0=TS0, 1=TS1), bit[5] reserved, bit[4] DIMM slot,
bit[3:0] memory channel. When absent, the TS0 and TS1 sensors of
all 16 DIMMs are reported.
The allowed amd,dimm-ids values depend on amd,dpc: with one DIMM per
channel 0x80-0x8f and 0xc0-0xcf; with two, 0x80-0x87, 0x90-0x97,
0xc0-0xc7 and 0xd0-0xd7. This rejects the reserved bit, a slot bit
without a second DIMM, and channels above 7 with two DIMMs per channel.
Also mention the DIMM sensors in the title and description and extend
the example.
Signed-off-by: Prathima Lk <Prathima.Lk@amd.com>
Signed-off-by: Akshay Gupta <Akshay.Gupta@amd.com>
---
.../devicetree/bindings/hwmon/amd,sbrmi.yaml | 59 +++++++++++++++++--
1 file changed, 55 insertions(+), 4 deletions(-)
diff --git a/Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml b/Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml
index 353d81d89bf5..f08b62133996 100644
--- a/Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml
+++ b/Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml
@@ -4,9 +4,7 @@
$id: http://devicetree.org/schemas/hwmon/amd,sbrmi.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
-title: >
- Sideband Remote Management Interface (SB-RMI) compliant
- AMD SoC power device.
+title: AMD SoC SB-RMI power and DIMM thermal sensor
maintainers:
- Akshay Gupta <Akshay.Gupta@amd.com>
@@ -16,7 +14,8 @@ description: |
interface that reports AMD SoC's Power (normalized Power) using,
Mailbox Service Request and resembles a typical 8-pin remote power
sensor's I2C interface to BMC. The power attributes in hwmon
- reports power in microwatts.
+ reports power in microwatts. The same mailbox also reports the
+ temperature of the TS0/TS1 thermal sensors on each populated DIMM.
properties:
compatible:
@@ -33,10 +32,60 @@ properties:
\[open source SoC register reference\]
https://www.amd.com/en/support/tech-docs?keyword=55898
+ amd,dpc:
+ $ref: /schemas/types.yaml#/definitions/uint8
+ enum: [1, 2]
+ default: 1
+ description:
+ DIMMs per channel (dimms-per-channel), the number of DIMM slots per
+ memory channel.
+
+ amd,dimm-ids:
+ $ref: /schemas/types.yaml#/definitions/uint8-array
+ minItems: 1
+ maxItems: 32
+ uniqueItems: true
+ description: |
+ Mode 1 SB-RMI DIMM_ADDRESS of each DIMM thermal sensor to report.
+ Encoding: bit[7]=1 (Mode 1), bit[6] sensor (0=TS0, 1=TS1), bit[5]
+ reserved, bit[4] DIMM slot, bit[3:0] memory channel ID. With one DIMM
+ per channel bit[4] is 0; with two, the memory channel ID is 0-7.
+ When absent, the TS0 and TS1 sensors of all 16 DIMMs are reported.
+
required:
- compatible
- reg
+allOf:
+ - if:
+ required:
+ - amd,dpc
+ properties:
+ amd,dpc:
+ const: 2
+ then:
+ properties:
+ amd,dimm-ids:
+ items:
+ anyOf:
+ - minimum: 0x80
+ maximum: 0x87
+ - minimum: 0x90
+ maximum: 0x97
+ - minimum: 0xc0
+ maximum: 0xc7
+ - minimum: 0xd0
+ maximum: 0xd7
+ else:
+ properties:
+ amd,dimm-ids:
+ items:
+ anyOf:
+ - minimum: 0x80
+ maximum: 0x8f
+ - minimum: 0xc0
+ maximum: 0xcf
+
additionalProperties: false
examples:
@@ -48,6 +97,8 @@ examples:
sbrmi@3c {
compatible = "amd,sbrmi";
reg = <0x3c>;
+ /* TS0 sensors of the DIMMs on memory channels 0-7 */
+ amd,dimm-ids = /bits/ 8 <0x80 0x81 0x82 0x83 0x84 0x85 0x86 0x87>;
};
};
...
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v1 2/4] dt-bindings: hwmon: add DIMM thermal sensor properties
2026-11-16 12:02 ` [PATCH v1 2/4] dt-bindings: hwmon: add DIMM thermal sensor properties Akshay Gupta
@ 2026-11-16 12:11 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-16 12:11 UTC (permalink / raw)
To: Akshay Gupta, linux-hwmon
> From: Prathima Lk <Prathima.Lk@amd.com>
>
> The SB-RMI mailbox also reports the temperature of the TS0/TS1 thermal
> sensors on each DIMM (command 0x48, Mode 1 DIMM_ADDRESS). Boards differ
> in how many DIMMs are fitted per memory channel and which sensors are
> populated, so describe both in the binding.
>
> Add two optional properties:
>
> - amd,dpc: uint8, DIMMs per channel, 1 or 2 (default 1).
>
> - amd,dimm-ids: uint8 array of 1 to 32 unique Mode 1 DIMM_ADDRESS
> values, one per sensor to report. Encoding: bit[7]=1 (Mode 1),
> bit[6] sensor (0=TS0, 1=TS1), bit[5] reserved, bit[4] DIMM slot,
> bit[3:0] memory channel. When absent, the TS0 and TS1 sensors of
> all 16 DIMMs are reported.
>
> The allowed amd,dimm-ids values depend on amd,dpc: with one DIMM per
> channel 0x80-0x8f and 0xc0-0xcf; with two, 0x80-0x87, 0x90-0x97,
> 0xc0-0xc7 and 0xd0-0xd7. This rejects the reserved bit, a slot bit
> without a second DIMM, and channels above 7 with two DIMMs per channel.
>
> Also mention the DIMM sensors in the title and description and extend
> the example.
>
> Signed-off-by: Prathima Lk <Prathima.Lk@amd.com>
> Signed-off-by: Akshay Gupta <Akshay.Gupta@amd.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116120228.865196-1-Akshay.Gupta@amd.com?part=2
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 3/4] misc: amd-sbi: add DIMM thermal sensor support
2026-11-16 12:02 [PATCH v1 0/4] misc: amd-sbi: add DIMM thermal sensors to sbrmi Akshay Gupta
2026-11-16 12:02 ` [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex Akshay Gupta
2026-11-16 12:02 ` [PATCH v1 2/4] dt-bindings: hwmon: add DIMM thermal sensor properties Akshay Gupta
@ 2026-11-16 12:02 ` Akshay Gupta
2026-11-16 12:13 ` sashiko-bot
2026-11-16 12:02 ` [PATCH v1 4/4] Documentation: hwmon: document DIMM thermal sensor channels Akshay Gupta
3 siblings, 1 reply; 9+ messages in thread
From: Akshay Gupta @ 2026-11-16 12:02 UTC (permalink / raw)
To: linux-hwmon, devicetree, linux-kernel, linux-doc
Cc: linux, robh, krzk+dt, conor+dt, corbet, skhan, rdunlap, arnd,
gregkh, naveenkrishna.chatradhi, Anand.Umarji, Prathima Lk,
Akshay Gupta
From: Prathima Lk <Prathima.Lk@amd.com>
Report the TS0 and TS1 thermal sensors of up to 16 DIMMs as 32 hwmon
temperature channels using SB-RMI mailbox command 0x48 with the Mode 1
DIMM_ADDRESS encoding:
bit[7] 1 (Mode 1)
bit[6] sensor select (0 = TS0, 1 = TS1)
bit[5] reserved
bit[4] DIMM slot
bit[3:0] memory channel
Board DIMM n is reported on temp(n+1) (TS0) and temp(n+17) (TS1), where
n = memory channel * DIMMs-per-channel + slot. With one DIMM per channel
n is the memory channel; with two, the slots interleave (0x80, 0x90,
0x81, ...). Each channel is labelled DIMM_TS<t>_UMC<n>.
The layout comes from two optional firmware properties:
- amd,dpc: DIMMs per channel, 1 or 2 (default 1).
- amd,dimm-ids: the DIMM_ADDRESS of each sensor to report. Only the
listed sensors are exposed. Entries without bit[7], with the
reserved bit[5], with a slot bit when amd,dpc is 1, with a memory
channel above 7 when amd,dpc is 2, or listed twice are rejected,
as is an empty or unreadable property.
Without amd,dimm-ids all 32 channels are exposed, and reading a sensor
that is not fitted returns the firmware error.
The temperature is returned in DataOut[31:21] as an 11-bit two's
complement value in 0.25 degC steps and is reported in millidegrees
Celsius.
Signed-off-by: Prathima Lk <Prathima.Lk@amd.com>
Signed-off-by: Akshay Gupta <Akshay.Gupta@amd.com>
---
drivers/misc/amd-sbi/rmi-core.h | 10 ++
drivers/misc/amd-sbi/rmi-hwmon.c | 236 ++++++++++++++++++++++++++++---
2 files changed, 228 insertions(+), 18 deletions(-)
diff --git a/drivers/misc/amd-sbi/rmi-core.h b/drivers/misc/amd-sbi/rmi-core.h
index 975ae858e9fd..15a0efa5dd02 100644
--- a/drivers/misc/amd-sbi/rmi-core.h
+++ b/drivers/misc/amd-sbi/rmi-core.h
@@ -48,6 +48,14 @@ enum sbrmi_msg_id {
SBRMI_WRITE_PKG_PWR_LIMIT,
SBRMI_READ_PKG_PWR_LIMIT,
SBRMI_READ_PKG_MAX_PWR_LIMIT,
+ SBRMI_READ_DIMM_THERMAL_SENSOR = 0x48,
+};
+
+/* DIMM thermal config; dimm_ids[] is indexed by hwmon channel */
+struct sbrmi_dimm_config {
+ u8 *dimm_ids;
+ const char **labels;
+ u8 dpc; /* DIMMs per memory channel */
};
/* Each client has this additional data */
@@ -56,6 +64,8 @@ struct sbrmi_data {
struct regmap *regmap;
/* Mutex locking */
struct mutex lock;
+ /* DIMM thermal config (hwmon) */
+ struct sbrmi_dimm_config dimm;
u32 pwr_limit_max;
u8 dev_static_addr;
u8 rev;
diff --git a/drivers/misc/amd-sbi/rmi-hwmon.c b/drivers/misc/amd-sbi/rmi-hwmon.c
index f4f015605daa..f4a64a4a33a8 100644
--- a/drivers/misc/amd-sbi/rmi-hwmon.c
+++ b/drivers/misc/amd-sbi/rmi-hwmon.c
@@ -4,14 +4,109 @@
*
* Copyright (C) 2025 Advanced Micro Devices, Inc.
*/
+#include <linux/bitfield.h>
+#include <linux/bits.h>
#include <linux/err.h>
#include <linux/hwmon.h>
+#include <linux/property.h>
#include <uapi/misc/amd-apml.h>
#include "rmi-core.h"
/* Do not allow setting negative power limit */
#define SBRMI_PWR_MIN 0
+/* DIMM temperature (SB-RMI Mode 1 DIMM_ADDRESS) */
+#define DIMM_BASE_ID 0x80 /* Mode 1: Bit[7]=1 */
+#define DIMM_TS_SELECT_BIT BIT(6) /* 0 = TS0, 1 = TS1 */
+#define DIMM_RSVD_BIT BIT(5)
+#define DIMM_SLOT_BIT BIT(4)
+#define DIMM_CHAN_MASK GENMASK(3, 0)
+#define DIMM_TEMP_MASK GENMASK(31, 21)
+#define DIMM_CHANNELS_PER_TS 16
+#define SBRMI_MAX_DIMMS DIMM_CHANNELS_PER_TS
+#define SBRMI_NUM_DIMM_CHANNELS (DIMM_CHANNELS_PER_TS * 2) /* TS0 + TS1 */
+
+static bool sbrmi_dimm_channel_valid(const struct sbrmi_data *data, int channel)
+{
+ return data->dimm.dimm_ids && data->dimm.dimm_ids[channel];
+}
+
+/* Fill dimm_ids[] from the "amd,dimm-ids" entries, one sensor per entry */
+static int sbrmi_read_dimm_ids(struct device *dev, struct sbrmi_data *data)
+{
+ u8 raw_ids[SBRMI_NUM_DIMM_CHANNELS];
+ int count, i, ret, ch;
+ u8 addr;
+
+ count = device_property_count_u8(dev, "amd,dimm-ids");
+ if (count <= 0 || count > SBRMI_NUM_DIMM_CHANNELS) {
+ dev_err(dev, "amd,dimm-ids must have 1..%d entries, got %d\n",
+ SBRMI_NUM_DIMM_CHANNELS, count);
+ return -EINVAL;
+ }
+
+ ret = device_property_read_u8_array(dev, "amd,dimm-ids", raw_ids, count);
+ if (ret) {
+ dev_err(dev, "failed to read amd,dimm-ids: %d\n", ret);
+ return ret;
+ }
+
+ for (i = 0; i < count; i++) {
+ addr = raw_ids[i];
+ /* Board DIMM n = memory channel * dpc + slot */
+ ch = (addr & DIMM_CHAN_MASK) * data->dimm.dpc + FIELD_GET(DIMM_SLOT_BIT, addr);
+
+ if (!(addr & DIMM_BASE_ID) || (addr & DIMM_RSVD_BIT) ||
+ ch >= SBRMI_MAX_DIMMS ||
+ (data->dimm.dpc == 1 && (addr & DIMM_SLOT_BIT))) {
+ dev_err(dev, "invalid amd,dimm-ids[%d] = 0x%x for %u DIMM(s) per channel\n",
+ i, addr, data->dimm.dpc);
+ return -EINVAL;
+ }
+
+ if (addr & DIMM_TS_SELECT_BIT)
+ ch += DIMM_CHANNELS_PER_TS;
+ if (data->dimm.dimm_ids[ch]) {
+ dev_err(dev, "amd,dimm-ids[%d] = 0x%x duplicates 0x%x\n",
+ i, addr, data->dimm.dimm_ids[ch]);
+ return -EINVAL;
+ }
+
+ data->dimm.dimm_ids[ch] = addr;
+ }
+
+ return 0;
+}
+
+/*
+ * Build dimm_ids[], indexed by hwmon channel (TS0 0-15, TS1 16-31), from
+ * "amd,dimm-ids" or, when absent, for all 16 DIMMs.
+ */
+static int sbrmi_init_dimm_config(struct device *dev, struct sbrmi_data *data)
+{
+ int i;
+ u8 addr;
+
+ data->dimm.dimm_ids = devm_kcalloc(dev, SBRMI_NUM_DIMM_CHANNELS,
+ sizeof(*data->dimm.dimm_ids), GFP_KERNEL);
+ if (!data->dimm.dimm_ids)
+ return -ENOMEM;
+
+ if (device_property_present(dev, "amd,dimm-ids"))
+ return sbrmi_read_dimm_ids(dev, data);
+
+ for (i = 0; i < SBRMI_MAX_DIMMS; i++) {
+ addr = DIMM_BASE_ID | i;
+ if (data->dimm.dpc == 2)
+ addr = DIMM_BASE_ID | (i & 1 ? DIMM_SLOT_BIT : 0) | (i / 2);
+
+ data->dimm.dimm_ids[i] = addr;
+ data->dimm.dimm_ids[i + DIMM_CHANNELS_PER_TS] = addr | DIMM_TS_SELECT_BIT;
+ }
+
+ return 0;
+}
+
static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
@@ -22,29 +117,52 @@ static int sbrmi_read(struct device *dev, enum hwmon_sensor_types type,
if (!data)
return -ENODEV;
- if (type != hwmon_power)
+ if (type != hwmon_power && type != hwmon_temp)
return -EINVAL;
- switch (attr) {
- case hwmon_power_input:
- msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION;
- ret = rmi_mailbox_xfer(data, &msg);
- break;
- case hwmon_power_cap:
- msg.cmd = SBRMI_READ_PKG_PWR_LIMIT;
- ret = rmi_mailbox_xfer(data, &msg);
- break;
- case hwmon_power_cap_max:
- msg.mb_in_out = data->pwr_limit_max;
- ret = 0;
- break;
- default:
- return -EINVAL;
+ if (type == hwmon_power) {
+ switch (attr) {
+ case hwmon_power_input:
+ msg.cmd = SBRMI_READ_PKG_PWR_CONSUMPTION;
+ ret = rmi_mailbox_xfer(data, &msg);
+ break;
+ case hwmon_power_cap:
+ msg.cmd = SBRMI_READ_PKG_PWR_LIMIT;
+ ret = rmi_mailbox_xfer(data, &msg);
+ break;
+ case hwmon_power_cap_max:
+ msg.mb_in_out = data->pwr_limit_max;
+ ret = 0;
+ break;
+ default:
+ return -EINVAL;
+ }
+ } else {
+ switch (attr) {
+ case hwmon_temp_input:
+ if (!sbrmi_dimm_channel_valid(data, channel))
+ return -EINVAL;
+ msg.cmd = SBRMI_READ_DIMM_THERMAL_SENSOR;
+ msg.mb_in_out = data->dimm.dimm_ids[channel];
+ ret = rmi_mailbox_xfer(data, &msg);
+ if (ret == -EPROTOTYPE)
+ dev_dbg(dev, "FW error code:0x%x\n",
+ msg.fw_ret_code);
+ break;
+ default:
+ return -EINVAL;
+ }
}
if (ret < 0)
return ret;
- /* hwmon power attributes are in microWatt */
- *val = (long)msg.mb_in_out * 1000;
+
+ if (type == hwmon_power) {
+ /* hwmon power attributes are in microWatt */
+ *val = (long)msg.mb_in_out * 1000;
+ } else {
+ /* 11-bit two's complement in bits 31:21, 0.25 degC per LSB */
+ *val = sign_extend32(FIELD_GET(DIMM_TEMP_MASK, msg.mb_in_out), 10) * 250;
+ }
return ret;
}
@@ -87,21 +205,55 @@ static umode_t sbrmi_is_visible(const void *data,
return 0644;
}
break;
+ case hwmon_temp:
+ if (!sbrmi_dimm_channel_valid(data, channel))
+ return 0;
+ switch (attr) {
+ case hwmon_temp_input:
+ case hwmon_temp_label:
+ return 0444;
+ }
+ break;
default:
break;
}
return 0;
}
+static const u32 sbrmi_temp_config[SBRMI_NUM_DIMM_CHANNELS + 1] = {
+ [0 ... (SBRMI_NUM_DIMM_CHANNELS - 1)] = HWMON_T_INPUT | HWMON_T_LABEL,
+};
+
+static const struct hwmon_channel_info sbrmi_temp_channel_info = {
+ .type = hwmon_temp,
+ .config = sbrmi_temp_config,
+};
+
static const struct hwmon_channel_info * const sbrmi_info[] = {
HWMON_CHANNEL_INFO(power,
HWMON_P_INPUT | HWMON_P_CAP | HWMON_P_CAP_MAX),
+ &sbrmi_temp_channel_info,
NULL
};
+static int sbrmi_read_string(struct device *dev,
+ enum hwmon_sensor_types type,
+ u32 attr, int channel, const char **str)
+{
+ struct sbrmi_data *data = dev_get_drvdata(dev);
+
+ if (type != hwmon_temp || attr != hwmon_temp_label)
+ return -EOPNOTSUPP;
+ if (!sbrmi_dimm_channel_valid(data, channel))
+ return -EINVAL;
+ *str = data->dimm.labels[channel];
+ return 0;
+}
+
static const struct hwmon_ops sbrmi_hwmon_ops = {
.is_visible = sbrmi_is_visible,
.read = sbrmi_read,
+ .read_string = sbrmi_read_string,
.write = sbrmi_write,
};
@@ -110,9 +262,57 @@ static const struct hwmon_chip_info sbrmi_chip_info = {
.info = sbrmi_info,
};
+/* Label each channel by its DIMM number, not by the address it queries */
+static int sbrmi_init_dimm_labels(struct device *dev, struct sbrmi_data *data)
+{
+ int ch;
+
+ data->dimm.labels = devm_kcalloc(dev, SBRMI_NUM_DIMM_CHANNELS,
+ sizeof(*data->dimm.labels), GFP_KERNEL);
+ if (!data->dimm.labels)
+ return -ENOMEM;
+
+ for (ch = 0; ch < SBRMI_NUM_DIMM_CHANNELS; ch++) {
+ if (!data->dimm.dimm_ids[ch])
+ continue;
+ data->dimm.labels[ch] =
+ devm_kasprintf(dev, GFP_KERNEL, "DIMM_TS%d_UMC%d",
+ ch / DIMM_CHANNELS_PER_TS,
+ ch % DIMM_CHANNELS_PER_TS);
+ if (!data->dimm.labels[ch])
+ return -ENOMEM;
+ }
+
+ return 0;
+}
+
int create_hwmon_sensor_device(struct device *dev, struct sbrmi_data *data)
{
struct device *hwmon_dev;
+ int ret;
+
+ /* amd,dpc: dimms-per-channel, default 1 */
+ data->dimm.dpc = 1;
+ if (device_property_present(dev, "amd,dpc")) {
+ ret = device_property_read_u8(dev, "amd,dpc", &data->dimm.dpc);
+ if (ret) {
+ dev_err(dev, "failed to read amd,dpc: %d\n", ret);
+ return ret;
+ }
+ }
+ if (data->dimm.dpc != 1 && data->dimm.dpc != 2) {
+ dev_err(dev, "amd,dpc must be 1 or 2, got %u\n",
+ data->dimm.dpc);
+ return -EINVAL;
+ }
+
+ ret = sbrmi_init_dimm_config(dev, data);
+ if (ret)
+ return ret;
+
+ ret = sbrmi_init_dimm_labels(dev, data);
+ if (ret)
+ return ret;
hwmon_dev = devm_hwmon_device_register_with_info(dev, "sbrmi", data,
&sbrmi_chip_info, NULL);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH v1 3/4] misc: amd-sbi: add DIMM thermal sensor support
2026-11-16 12:02 ` [PATCH v1 3/4] misc: amd-sbi: add DIMM thermal sensor support Akshay Gupta
@ 2026-11-16 12:13 ` sashiko-bot
0 siblings, 0 replies; 9+ messages in thread
From: sashiko-bot @ 2026-11-16 12:13 UTC (permalink / raw)
To: Akshay Gupta, linux-hwmon
> From: Prathima Lk <Prathima.Lk@amd.com>
>
> Report the TS0 and TS1 thermal sensors of up to 16 DIMMs as 32 hwmon
> temperature channels using SB-RMI mailbox command 0x48 with the Mode 1
> DIMM_ADDRESS encoding:
>
> bit[7] 1 (Mode 1)
> bit[6] sensor select (0 = TS0, 1 = TS1)
> bit[5] reserved
> bit[4] DIMM slot
> bit[3:0] memory channel
>
> Board DIMM n is reported on temp(n+1) (TS0) and temp(n+17) (TS1), where
> n = memory channel * DIMMs-per-channel + slot. With one DIMM per channel
> n is the memory channel; with two, the slots interleave (0x80, 0x90,
> [ ... ]
> complement value in 0.25 degC steps and is reported in millidegrees
> Celsius.
>
> Signed-off-by: Prathima Lk <Prathima.Lk@amd.com>
> Signed-off-by: Akshay Gupta <Akshay.Gupta@amd.com>
Sashiko has reviewed this patch and found no issues.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116120228.865196-1-Akshay.Gupta@amd.com?part=3
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v1 4/4] Documentation: hwmon: document DIMM thermal sensor channels
2026-11-16 12:02 [PATCH v1 0/4] misc: amd-sbi: add DIMM thermal sensors to sbrmi Akshay Gupta
` (2 preceding siblings ...)
2026-11-16 12:02 ` [PATCH v1 3/4] misc: amd-sbi: add DIMM thermal sensor support Akshay Gupta
@ 2026-11-16 12:02 ` Akshay Gupta
2026-11-16 12:08 ` sashiko-bot
3 siblings, 1 reply; 9+ messages in thread
From: Akshay Gupta @ 2026-11-16 12:02 UTC (permalink / raw)
To: linux-hwmon, devicetree, linux-kernel, linux-doc
Cc: linux, robh, krzk+dt, conor+dt, corbet, skhan, rdunlap, arnd,
gregkh, naveenkrishna.chatradhi, Anand.Umarji, Prathima Lk,
Akshay Gupta
From: Prathima Lk <Prathima.Lk@amd.com>
sbrmi.rst described only the power1_* attributes. Document the
tempX_input and tempX_label attributes for the DIMM thermal sensors,
the DIMM to temp index mapping for one and two DIMMs per channel, the
DIMM_TS<t>_UMC<n> labels and the effect of amd,dimm-ids, and add a
sysfs read example.
Also point to it from the SB-RMI section of
Documentation/misc-devices/amd-sbi.rst, which listed only the power
attributes.
Signed-off-by: Prathima Lk <Prathima.Lk@amd.com>
Signed-off-by: Akshay Gupta <Akshay.Gupta@amd.com>
---
Documentation/hwmon/sbrmi.rst | 37 ++++++++++++++++++++++++++
Documentation/misc-devices/amd-sbi.rst | 4 ++-
2 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/Documentation/hwmon/sbrmi.rst b/Documentation/hwmon/sbrmi.rst
index 296049e13ac9..08859763658b 100644
--- a/Documentation/hwmon/sbrmi.rst
+++ b/Documentation/hwmon/sbrmi.rst
@@ -41,6 +41,8 @@ power on AMD platforms using mailbox command and resembles a typical 8-pin remot
power sensor's I2C interface to BMC.
This driver implements current power with power cap and power cap max.
+It also reports DIMM thermal sensor (TS0 and TS1) temperatures read with
+the SB-RMI DIMM thermal mailbox command.
sysfs-Interface
---------------
@@ -57,6 +59,28 @@ power1_cap RW Power limit can be set between 0 and power1_cap_max
power1_cap_max RO Maximum powerlimit calculated and reported by the SMU FW
================ ===== ========================================================
+DIMM thermal sensors are reported as temperature channels:
+
+================ ===== ========================================================
+Name Perm Description
+================ ===== ========================================================
+tempX_input RO DIMM thermal sensor temperature in milli-degrees Celsius
+tempX_label RO Channel label, ``DIMM_TS0_UMCn`` or ``DIMM_TS1_UMCn``
+ (n = 0..15)
+================ ===== ========================================================
+
+Each DIMM has two sensors, TS0 and TS1. DIMM ``n`` (0-15) is reported on
+``temp(n+1)_*`` (TS0) and ``temp(n+17)_*`` (TS1). With one DIMM per memory
+channel (the default), ``n`` is the memory channel and the labels are
+``DIMM_TS0_UMCn`` and ``DIMM_TS1_UMCn``. With two
+(``amd,dpc = /bits/ 8 <2>``), ``n`` is memory channel * 2 + slot,
+the DIMM number on the board, with the same labels.
+
+The optional ``amd,dimm-ids`` firmware property lists the DIMM_ADDRESS of
+each sensor (TS0 or TS1) and only those sensors are reported; without it,
+all 16 DIMMs are reported. A read fails with an error if the DIMM or sensor
+is not present or the firmware rejects the command.
+
The following example show how the 'Power' attribute from the i2c-addresses
can be monitored using the userspace utilities like ``sensors`` binary::
@@ -77,3 +101,16 @@ Also, Below shows how get and set the values from sysfs entries individually::
# echo 180000000 > /sys/class/hwmon/hwmon1/power1_cap
# cat /sys/class/hwmon/hwmon1/power1_cap
180000000
+
+Reading the TS0 and TS1 sensors of the first DIMM without ``amd,dimm-ids``
+(temperatures are in milli-degrees Celsius)::
+
+ # cat /sys/class/hwmon/hwmonN/temp1_label
+ DIMM_TS0_UMC0
+ # cat /sys/class/hwmon/hwmonN/temp1_input
+ 42000
+
+ # cat /sys/class/hwmon/hwmonN/temp17_label
+ DIMM_TS1_UMC0
+ # cat /sys/class/hwmon/hwmonN/temp17_input
+ 41750
diff --git a/Documentation/misc-devices/amd-sbi.rst b/Documentation/misc-devices/amd-sbi.rst
index 648d743903b7..a1ef4872c90f 100644
--- a/Documentation/misc-devices/amd-sbi.rst
+++ b/Documentation/misc-devices/amd-sbi.rst
@@ -34,7 +34,9 @@ among protocols as transactions may create race condition.
crw------- 1 root root 10, 53 Jul 10 11:13 /dev/sbrmi-3c
apml_sbrmi driver registers hwmon sensors for monitoring power_cap_max,
-current power consumption and managing power_cap.
+current power consumption and managing power_cap. It also reports the
+TS0/TS1 DIMM thermal sensors as temperature channels; see
+Documentation/hwmon/sbrmi.rst.
Characteristics of the dev node:
* Differnet xfer protocols are defined:
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread