misc: amd-sbi: add DIMM thermal sensors to sbrmi
cover misc: amd-sbi: add DIMM thermal sensors to sbrmi
The sbrmi hwmon device reports socket power. SB-RMI can also read the TS0 and TS1 thermal sensors on each DIMM, which a BMC needs beside the power attributes. This series reports those sensors as temperature channels on the same hwmon device.
The read is mailbox command 0x48 with a Mode 1 DIMM_ADDRESS:
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
Up to 16 DIMMs are reported, two sensors each. DIMM n is temp(n+1) for TS0 and temp(n+17) for TS1. Each channel is labelled DIMM_TS<t>_UMC<n>. With one DIMM per channel, n is the memory channel. With two, n is channel * 2 + slot, and the addresses interleave (0x80, 0x90, 0x81, ...). The temp index is the DIMM number, so a DIMM keeps the same tempN when other sensors are left out of the map.
DataOut[31:21] is an 11-bit two's complement value in steps of 0.25 degC. The driver reports it to hwmon in millidegrees Celsius.
Boards differ in how many DIMMs are fitted per memory channel and in which sensors are populated. Two optional firmware properties describe that:
amd,dpc DIMMs per channel, 1 or 2. The default is 1.
amd,dimm-ids Mode 1 address of each sensor to expose. Only those
channels are visible. If the property is absent, all 32 channels are exposed, and a read of a sensor that is not fitted returns the firmware error.
The binding and the driver reject an address without bit[7], with the reserved bit[5], with the slot bit set when amd,dpc is 1, with a memory channel above 7 when amd,dpc is 2, or listed twice. An empty or unreadable amd,dimm-ids property is rejected as well. With one DIMM per channel the allowed values are 0x80-0x8f and 0xc0-0xcf. With two they are 0x80-0x87, 0x90-0x97, 0xc0-0xc7 and 0xd0-0xd7.
The mailbox transaction and the existing hwmon registration both live in drivers/misc/amd-sbi, so the new channels are added there, on the hwmon device the driver already publishes.
Patches:
1. Switch sbrmi_data->lock to guard(). No functional change. The DIMM reads go through rmi_mailbox_xfer(), and this lets the error paths in that function return directly. The patch stands on its own.
2. Add amd,dpc and amd,dimm-ids to the amd,sbrmi binding, and mention the DIMM sensors in the title, description and example.
3. Report the sensors from rmi-hwmon: tempX_input and tempX_label, visibility taken from the DIMM map, and the 0.25 degC conversion.
4. Document the temperature attributes and the DIMM-to-temp mapping in Documentation/hwmon/sbrmi.rst, and point to it from the SB-RMI section of Documentation/misc-devices/amd-sbi.rst.
Thanks,
Akshay Gupta
Prathima Lk (4):
misc: amd-sbi: use guard() for data->lock mutex
dt-bindings: hwmon: add DIMM thermal sensor properties
misc: amd-sbi: add DIMM thermal sensor support
Documentation: hwmon: document DIMM thermal sensor channels
.../devicetree/bindings/hwmon/amd,sbrmi.yaml | 59 ++++- Documentation/hwmon/sbrmi.rst | 37 +++ Documentation/misc-devices/amd-sbi.rst | 4 +- drivers/misc/amd-sbi/rmi-core.c | 148 ++++++----- drivers/misc/amd-sbi/rmi-core.h | 10 + drivers/misc/amd-sbi/rmi-hwmon.c | 236 ++++++++++++++++-- 6 files changed, 395 insertions(+), 99 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/4 misc: amd-sbi: use guard() for data->lock mutex
From: Prathima Lk <[email protected]>
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.
--- drivers/misc/amd-sbi/rmi-core.c | 148 ++++++++++++++++---------------- 1 file changed, 72 insertions(+), 76 deletions(-)
drivers/misc/amd-sbi/rmi-core.c +72 -76
@@ -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 ;
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v1 1/4] misc: amd-sbi: use guard() for data->lock mutex
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…
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 <[email protected]>
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.
Quoted 4 lines
drivers/misc/amd-sbi/rmi-core.c +0
-0
[ ... ]
Quoted 48 lines
drivers/misc/amd-sbi/rmi-core.c +17
-19@@ -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
drivers/misc/amd-sbi/rmi-core.c int rmi_mailbox_xfer(struct sbrmi_data *data, · line 461
Quoted 8 lines
drivers/misc/amd-sbi/rmi-core.c +1
-2@@ -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
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH 2/4 dt-bindings: hwmon: add DIMM thermal sensor properties
In reply to Akshay GuptaFrom: Prathima Lk <[email protected]>
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.
--- .../devicetree/bindings/hwmon/amd,sbrmi.yaml | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/hwmon/amd,sbrmi.yaml +55 -4
@@ -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 <[email protected]>
@@ -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>; }; }; ...
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v1 2/4] dt-bindings: hwmon: add DIMM thermal sensor properties
Sashiko has reviewed this patch and found no issues.
Quoted 22 lines
From: Prathima Lk <[email protected]>
The SB-RMI mailbox also reports the temperature of the TS0/TS1 thermal sensors on each DIMM (command
0x48, Mode 1DIMM_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_ADDRESSvalues, 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.
Quoted 5 lines
Also mention the DIMM sensors in the title and description and extend the example.
Signed-off-by Prathima Lk <[email protected]>Signed-off-by Akshay Gupta <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH 3/4 misc: amd-sbi: add DIMM thermal sensor support
In reply to Akshay GuptaFrom: Prathima Lk <[email protected]>
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.
--- drivers/misc/amd-sbi/rmi-core.h | 10 ++ drivers/misc/amd-sbi/rmi-hwmon.c | 236 ++++++++++++++++++++++++++++--- 2 files changed, 228 insertions(+), 18 deletions(-)
drivers/misc/amd-sbi/rmi-core.h +10 -0
@@ -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;
drivers/misc/amd-sbi/rmi-hwmon.c +218 -18
291 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v1 3/4] misc: amd-sbi: add DIMM thermal sensor support
Sashiko has reviewed this patch and found no issues.
Quoted 19 lines
From: Prathima Lk <[email protected]>
Report the TS0 and TS1 thermal sensors of up to 16 DIMMs as 32 hwmon temperature channels using SB-RMI mailbox command
0x48with the Mode 1DIMM_ADDRESSencoding:bit[7] 1 (Mode 1) bit[6] sensor select (0 = TS0, 1 = TS1) bit[5] reserved bit[4] DIMM slotbit[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.
Quoted 2 lines
Signed-off-by Prathima Lk <[email protected]>Signed-off-by Akshay Gupta <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH 4/4 Documentation: hwmon: document DIMM thermal sensor channels
In reply to Akshay GuptaFrom: Prathima Lk <[email protected]>
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.
--- Documentation/hwmon/sbrmi.rst | 37 ++++++++++++++++++++++++++ Documentation/misc-devices/amd-sbi.rst | 4 ++- 2 files changed, 40 insertions(+), 1 deletion(-)
Documentation/hwmon/sbrmi.rst +37 -0
@@ -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
Documentation/misc-devices/amd-sbi.rst +3 -1
@@ -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:
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v1 4/4] Documentation: hwmon: document DIMM thermal sensor channels
Sashiko has reviewed this patch and found no issues.
Quoted 8 lines
From: Prathima Lk <[email protected]>
sbrmi.rstdescribed only the power1_* attributes. Document thetempX_inputandtempX_labelattributes 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.
Quoted 6 lines
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 <[email protected]>Signed-off-by Akshay Gupta <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4