drm/xe/hwmon: Add fan control support
Subsystems (2)
v5 cover drm/xe/hwmon: Add fan control support
This series adds Intel Xe fan control through the hwmon sysfs ABI: fan maximum speed, direct PWM control, mode selection and programmable fan curves. Supported platforms are BMG in this series.
Each fan has a stock table read from firmware and a user table cached in the driver and written back through PCODE.
Series overview
01 Initialize fan-control backend and table cache
Read the fan enable mask, max RPS, minimum PWM and stock fan tables.
02 Expose fanN_max
Maximum fan speed in RPM.
03 Add ordered write batch helper
PCODE helper that writes a fan table in order.
04 Expose pwm[1-3]
Constant duty cycle in the hwmon 0..255 range.
05 Expose pwm[1-3]_enable
0 = full speed, 1 = manual user table, 2 = firmware automatic.
06 Enable fan curve control support
pwm[1-3]_auto_point[1-10]_{temp,pwm}. 07 Restore fan user tables after resume
08 Refresh fan data after late binding
09 Expose tjmax_fan_control_enable device sysfs
10 Add kernel-doc for fan control
The ABI is documented in Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon.
Usage
Read fan speed and max RPM:
cat /sys/class/hwmon/hwmonX/fan1_input
cat /sys/class/hwmon/hwmonX/fan1_max
Manual mode with a fixed PWM:
echo 1 > /sys/class/hwmon/hwmonX/pwm1_enable
echo 120 > /sys/class/hwmon/hwmonX/pwm1
Back to firmware automatic control:
echo 2 > /sys/class/hwmon/hwmonX/pwm1_enable
Program a 3-point fan curve:
echo 1 > /sys/class/hwmon/hwmonX/pwm1_enable echo 30000 > /sys/class/hwmon/hwmonX/pwm1_auto_point1_temp echo 50 > /sys/class/hwmon/hwmonX/pwm1_auto_point1_pwm echo 60000 > /sys/class/hwmon/hwmonX/pwm1_auto_point2_temp echo 120 > /sys/class/hwmon/hwmonX/pwm1_auto_point2_pwm echo 85000 > /sys/class/hwmon/hwmonX/pwm1_auto_point3_temp echo 200 > /sys/class/hwmon/hwmonX/pwm1_auto_point3_pwm echo 0 > /sys/class/hwmon/hwmonX/pwm1_auto_point4_temp echo 0 > /sys/class/hwmon/hwmonX/pwm1_auto_point4_pwm
Notes
- Package temperature (temp2_input) is the fan table temperature reference.
- pwmN and curve point writes need pwmN_enable = 1.
- A curve has 2 to 10 points. Temperature and PWM must not decrease from one point to the next.
- Curve writes are staged and committed once point K+1 is (0, 0) or all 10 points are set.
- PWM values below the fan's minimum duty cycle are raised to it.
v2:
- Add kernel-doc for fan control.
- Save/restore the user fan table across suspend/resume.
- Refresh fan info after late binding; keep the user's PWM mode.
- Show stock table points in the curve attributes when pwmN_enable = 2.
v3:
- Address v2 review comments.
- Add an ordered PCODE write batch helper.
- Support a variable number of fan curve points.
- Add missing failure checks.
- Use only 2 fan curve points when setting pwmN.
v4:
- Address v3 https://patchwork.freedesktop.org/series/176241/ review comments. (Soham)
- Clamp oversized fan masks and stock tables; continue when one fan's stock table fails to read.
- Clear cached values on failed pcode reads.
- Use percent for fan speed and clamp min PWM to 100%.
- Fail pwmN writes if pcode reports the wrong user point count.
- Create fan curve attributes at probe time; add the (0, 0) end marker; points must not decrease.
- Document pwmN_enable values and the curve rules.
- Call the system PM hooks from xe_device_suspend()/xe_device_resume(), which also covers FLR; check d3cold only for runtime PM.
- Fix the late binding firmware ID check; start fans enabled after late binding in automatic mode.
- Rebase on drm-xe-next; update the ABI Date and KernelVersion.
v5:
- Address review comments on v4 patch
https://patchwork.freedesktop.org/series/179435/ from sashiko.
- Add new sysfs tjmax_fan_control_enable for enable/disable of tjmax fan control.
- Move CRI fan control support out of this patch series.
- Add kgdoc patch at the end of the patch series.
Karthik Poosa (10):
drm/xe/hwmon: Initialize fan-control backend and table cache drm/xe/hwmon: Expose fanN_max
drm/xe/pcode: Add ordered write batch helper drm/xe/hwmon: Expose pwm[1-3]
drm/xe/hwmon: Expose pwm[1-3]_enable
drm/xe/hwmon: Enable fan curve control support drm/xe/hwmon: Restore fan user tables after resume drm/xe/hwmon: Refresh fan data after late binding drm/xe: Expose tjmax_fan_control_enable device sysfs drm/xe/hwmon: Add kernel-doc for fan control
.../ABI/testing/sysfs-driver-intel-xe-gpu | 15 + .../ABI/testing/sysfs-driver-intel-xe-hwmon | 32 + drivers/gpu/drm/xe/regs/xe_pmt.h | 5 + drivers/gpu/drm/xe/xe_device.c | 3 + drivers/gpu/drm/xe/xe_device_sysfs.c | 76 + drivers/gpu/drm/xe/xe_hwmon.c | 1322 ++++++++++++++++- drivers/gpu/drm/xe/xe_hwmon.h | 6 + drivers/gpu/drm/xe/xe_late_bind_fw.c | 10 + drivers/gpu/drm/xe/xe_pcode.c | 39 + drivers/gpu/drm/xe/xe_pcode.h | 12 + drivers/gpu/drm/xe/xe_pcode_api.h | 10 + drivers/gpu/drm/xe/xe_pm.c | 11 +- 12 files changed, 1512 insertions(+), 29 deletions(-)
Signature · 1 line
2.34.1
PATCH v5 1/10 drm/xe/hwmon: Initialize fan-control backend and table cache
Initialize Xe hwmon fan-control support by detecting enabled fans, reading stock fan control points and min PWM.
FSC_READ_NUM_FANS returns a bitmask of enabled fans, so use it as a mask when exposing fanN_input.
v2:
- Avoid user table initialization during probe. (Badal)
- Move unused code to appropriate patches.
- Use xe helpers for dmesg logs.
v3:
- Rebase.
- Refine a few debug log messages and comments.
- Update xe_hwmon_read_fan_control_info() to return on any stock table read failures.
- Avoid returning when num_fans is 0 in xe_hwmon_get_preregistration_info(), ensuring thermal mailbox initialization is not skipped.
- Remove XE_PCODE_FAN_CONTROL_TIMEOUT_MS which is unnecessary as default timeout itself is now 10ms.
- Use xe_pcode_read() instead of xe_pcode_read_timeout().
- Rename fan_control_point_count to point_count in struct fan_table.
- Resolve kernel-doc warnings.
- Add valid check for stock table fan point count.
- Use the fan-enable bitmap reported by FSC_READ_NUM_FANS when enumerating fans. This avoids assuming contiguous fan indices and allows masks with gaps to be represented correctly in the hwmon interface.
v4:
- Clamp unsupported fan masks and oversized stock tables instead of failing initialization. (Soham)
- On stock table read failure, mark that fan's table empty and continue with the remaining fans; fan_input stays visible. (Soham)
- Clear fan enable mask and min PWM on pcode read failure. (Soham)
- Fix FCP_INDEX() type safety and clean up macro usage. (Soham)
- Use xe_hwmon_pcode_read_fan_control() for fan mailbox reads. (Soham)
- Fix kernel-doc for fan_table_type and nested fan_table members.
- Skip min PWM read for fans without a stock table.
- Make xe_hwmon_get_fan_enable_mask() return void.
v5:
- Remove min_pwm as it is no longer supported by the hardware.
- Change xe_hwmon_get_fan_enable_mask() return type from void to int.
- Copy the stock table to the fan info only if all points are read successfully.
--- drivers/gpu/drm/xe/xe_hwmon.c | 162 +++++++++++++++++++++++++++--- drivers/gpu/drm/xe/xe_pcode_api.h | 4 + 2 files changed, 151 insertions(+), 15 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +147 -15
@@ -22,6 +22,7 @@#include "xe_pcode_api.h" #include "xe_sriov.h" #include "xe_pm.h" +#include "xe_printk.h" #include "xe_vsec.h" #include "regs/xe_pmt.h"
@@ -139,13 +140,51 @@ struct xe_hwmon_energy_info { };/** -* struct xe_hwmon_fan_info - to cache previous fan reading +* enum fan_table_type - fan table types tracked per fan +*/ +enum fan_table_type { +/** @STOCK_FAN_TABLE: firmware-provided fan table */ +STOCK_FAN_TABLE , +/** @USER_FAN_TABLE: user fan table written through sysfs */ +USER_FAN_TABLE , +/** @FAN_TABLE_MAX: number of fan tables tracked per fan */ +FAN_TABLE_MAX , +}; + +/* Check if a fan is enabled based on the fan_enable_mask got from FSC_READ_NUM_FANS. */ +#define IS_FAN_ENABLED (hwmon, fan) ((hwmon)->fan_enable_mask & BIT(fan)) + +/* Maximum number of fan control points supported by each fan. */ +#define MAX_FAN_CONTROL_POINTS 10 + +/* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ +#define FCP_INDEX (table_type, point_num) (((u32)(table_type) << 31) | \ + ((u32)(point_num) & GENMASK(30, 0))) + +/** +* struct xe_hwmon_fan_info - cached fan telemetry and control state +* +* Each fan keeps the latest tachometer sampling state along with two fan +* tables: the stock table discovered from firmware and the user table managed +* by hwmon sysfs writes. */ struct xe_hwmon_fan_info {/** @reg_val_prev: previous fan reg val */ u32 reg_val_prev;/** @time_prev: previous timestamp */ u64 time_prev; +/** @fan_table: fan control tables */ +struct fan_table { +/** @fan_table.point_count: number of fan control points */ +u8 point_count; +/** @fan_table.fcp: array of fan control points */ +struct fan_control_point { +/** @fan_table.fcp.temp: temperature in degree celsius */ +u8 temp; +/** @fan_table.fcp.speed: fan speed in percentage */ +u8 speed; + } fcp[MAX_FAN_CONTROL_POINTS ]; + } fan_table[FAN_TABLE_MAX ]; };/**
@@ -194,6 +233,8 @@ struct xe_hwmon {int scl_shift_time;/** @ei: Energy info for energyN_input */ struct xe_hwmon_energy_info ei[CHANNEL_MAX ]; +/** @fan_enable_mask: bitmask of available fans */ +u32 fan_enable_mask;/** @fi: Fan info for fanN_input */ struct xe_hwmon_fan_info fi[FAN_MAX ];/** @read_power_limit_from_pcode: pcode accepted power limits write for the channel */
@@ -1084,17 +1125,106 @@ static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval) (uval & POWER_SETUP_I1_DATA_MASK)); } -static int xe_hwmon_pcode_read_fan_control (const struct xe_hwmon *hwmon,u32 subcmd,u32 *uval) +static int xe_hwmon_pcode_read_fan_control (const struct xe_hwmon *hwmon,u32 subcmd,u8 fan_num, +u32 *uval) {struct xe_tile *root_tile =xe_device_get_root_tile (hwmon->xe); +return xe_pcode_read (root_tile,PCODE_MBOX (FAN_SPEED_CONTROL , subcmd, fan_num), + uval,NULL ); +} + +static int xe_hwmon_get_fan_enable_mask (struct xe_hwmon *hwmon) +{ +int ret; +/* Platforms that don't return correct value */ -if (hwmon->xe->info.platform ==XE_DG2 && subcmd ==FSC_READ_NUM_FANS ) { - *uval =2 ; +if (hwmon->xe->info.platform ==XE_DG2 ) { + hwmon->fan_enable_mask =GENMASK (1 ,0 );return 0 ; } -return xe_pcode_read (root_tile,PCODE_MBOX (FAN_SPEED_CONTROL , subcmd,0 ), uval,NULL ); + ret =xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_NUM_FANS ,0 , + &hwmon->fan_enable_mask); +if (ret) { + hwmon->fan_enable_mask =0 ; +xe_warn (hwmon->xe,"failed to read number of fans, ret=%d\n" , ret); +return ret; + } + +/* Check if fan mask exceeds FAN_MAX and log a warning if it does */ +if (hwmon->fan_enable_mask & ~GENMASK (FAN_MAX -1 ,0 )) { +xe_warn (hwmon->xe,"Fan enable mask exceeds %d supported fans, clamping\n" , +FAN_MAX ); + hwmon->fan_enable_mask &=GENMASK (FAN_MAX -1 ,0 ); + } + +xe_info (hwmon->xe,"Number of fans detected: %u\n" ,hweight32 (hwmon->fan_enable_mask)); + +return 0 ; +} + +static int xe_hwmon_read_fan_control_info (struct xe_hwmon *hwmon) +{ +int err =0 ; +int point; +int fan; +int ret; + +for (fan =0 ; fan <FAN_MAX ; fan++) { +struct fan_control_point stock_fcp[MAX_FAN_CONTROL_POINTS ]; +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +u32 stock_fcp_count =0 ; + +if (!IS_FAN_ENABLED (hwmon, fan)) +continue ; + + ret =xe_hwmon_pcode_read_fan_control (hwmon, +FSC_READ_STOCK_FAN_CONTROL_POINTS , + fan, &stock_fcp_count); +if (ret || !stock_fcp_count) { +xe_warn (hwmon->xe, +"fan %d stock table unavailable, ret=%d, point count=%u\n" , + fan, ret, ret ?0 : stock_fcp_count); + err = ret ?: -ENODATA ; +continue ; + } + +if (stock_fcp_count >MAX_FAN_CONTROL_POINTS ) { +xe_warn (hwmon->xe, +"fan %d stock table point count %u exceeds maximum %u, clamping\n" , + fan, stock_fcp_count,MAX_FAN_CONTROL_POINTS ); + stock_fcp_count =MAX_FAN_CONTROL_POINTS ; + } + +xe_dbg (hwmon->xe,"fan %d stock table point count is %u\n" , fan, stock_fcp_count); + +/* Cache the stock fan table for later use. */ +for (point =0 ; point < stock_fcp_count; point++) { +u32 fcp =FCP_INDEX (STOCK_FAN_TABLE , point); + + ret =xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_FAN_TABLE , fan, &fcp); +if (ret) { +xe_warn (hwmon->xe,"failed to read fan %d stock point %d, ret=%d\n" , + fan, point, ret); + err = ret; +break ; + } + + stock_fcp[point].temp =REG_FIELD_GET (FAN_CONTROL_POINT_TEMP_MASK , fcp); + stock_fcp[point].speed =REG_FIELD_GET (FAN_CONTROL_POINT_SPEED_MASK , fcp); +xe_dbg (hwmon->xe,"fan %d stock point %d: temp %u C, speed %u %%\n" , + fan, point, stock_fcp[point].temp, stock_fcp[point].speed); + } + +if (point < stock_fcp_count) +continue ; + +memcpy (fi->fan_table[STOCK_FAN_TABLE ].fcp, stock_fcp, + stock_fcp_count *sizeof (stock_fcp[0 ])); + fi->fan_table[STOCK_FAN_TABLE ].point_count = stock_fcp_count; + } +return err; } static int xe_hwmon_power_curr_crit_read(struct xe_hwmon *hwmon, int channel,
@@ -1632,17 +1762,12 @@ xe_hwmon_energy_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)static umode_t xe_hwmon_fan_is_visible (struct xe_hwmon *hwmon,u32 attr,int channel) { -u32 uval =0 ; -if (!hwmon->xe->info.has_fan_control)return 0 ;switch (attr) {case hwmon_fan_input: -if (xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_NUM_FANS , &uval)) -return 0 ; - -return channel < uval ?0444 :0 ; +return IS_FAN_ENABLED (hwmon, channel) ?0444 :0 ;default :return 0 ; }
@@ -1876,11 +2001,18 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon)if (xe_hwmon_is_visible (hwmon, hwmon_energy, hwmon_energy_input, channel))xe_hwmon_energy_get (hwmon, channel, &energy); -/* Initialize 'struct xe_hwmon_fan_info' with initial fan register reading. */ -for (channel =0 ; channel <FAN_MAX ; channel++) -if (xe_hwmon_is_visible (hwmon, hwmon_fan, hwmon_fan_input, channel)) -xe_hwmon_fan_input_read (hwmon, channel, &fan_speed); +if (hwmon->xe->info.has_fan_control) { +xe_hwmon_get_fan_enable_mask (hwmon); + +/* Initialize 'struct xe_hwmon_fan_info' with initial fan register reading. */ +for (channel =0 ; channel <FAN_MAX ; channel++) +if (IS_FAN_ENABLED (hwmon, channel)) +xe_hwmon_fan_input_read (hwmon, channel, &fan_speed); +/* Fan control tables initialization */ +if (xe_hwmon_read_fan_control_info (hwmon)) +xe_warn (hwmon->xe,"Fan control tables are not available\n" ); + }return xe_hwmon_init_temp_info (hwmon); }
drivers/gpu/drm/xe/xe_pcode_api.h +4 -0
@@ -87,6 +87,10 @@#define FAN_SPEED_CONTROL 0x7D#define FSC_READ_NUM_FANS 0x4 +#define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5 +#define FSC_READ_FAN_TABLE 0x7 +#define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0) +#define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8)#define PCODE_SCRATCH (x) XE_REG(0x138320 + ((x) * 4))/* PCODE_SCRATCH0 */
Signature · 1 line
2.34.1
Re: [PATCH v5 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache
Hi Karthik,
Quoted 58 lines · Karthik Poosa
Initialize Xe hwmon fan-control support by detecting enabled fans, reading stock fan control points and min PWM.
FSC_READ_NUM_FANSreturns a bitmask of enabled fans, so use it as a mask when exposingfanN_input.v2:
- Avoid user table initialization during probe. (Badal)
- Move unused code to appropriate patches.
- Use xe helpers for dmesg logs.v3:
- Rebase.
- Refine a few debug log messages and comments.
- Updatexe_hwmon_read_fan_control_info()to return on any stock table read failures.
- Avoid returning whennum_fansis 0 inxe_hwmon_get_preregistration_info(), ensuring thermal mailbox initialization is not skipped.
- RemoveXE_PCODE_FAN_CONTROL_TIMEOUT_MSwhich is unnecessary as default timeout itself is now 10ms.
- Usexe_pcode_read()instead ofxe_pcode_read_timeout().
- Renamefan_control_point_counttopoint_countin structfan_table.
- Resolve kernel-doc warnings.
- Add valid check for stock table fan point count.
- Use the fan-enable bitmap reported byFSC_READ_NUM_FANSwhen enumerating fans. This avoids assuming contiguous fan indices and allows masks with gaps to be represented correctly in the hwmon interface.v4:
- Clamp unsupported fan masks and oversized stock tables instead of failing initialization. (Soham)
- On stock table read failure, mark that fan's table empty and continue with the remaining fans;fan_inputstays visible. (Soham)
- Clear fan enable mask and min PWM on pcode read failure. (Soham)
- FixFCP_INDEX()type safety and clean up macro usage. (Soham)
- Usexe_hwmon_pcode_read_fan_control()for fan mailbox reads. (Soham)
- Fix kernel-doc forfan_table_typeand nestedfan_tablemembers.
- Skip min PWM read for fans without a stock table.
- Makexe_hwmon_get_fan_enable_mask()return void.v5:
- Removemin_pwmas it is no longer supported by the hardware.
- Changexe_hwmon_get_fan_enable_mask()return type from void to int.
- Copy the stock table to the fan info only if all points are read successfully.Signed-off-by Karthik Poosa <[email protected]>--- drivers/gpu/drm/xe/xe_hwmon.c | 162 +++++++++++++++++++++++++++--- drivers/gpu/drm/xe/xe_pcode_api.h | 4 + 2 files changed, 151 insertions(+), 15 deletions(-)drivers/gpu/drm/xe/xe_hwmon.c +0
-0
drivers/gpu/drm/xe/xe_hwmon.c line 27
Quoted 6 lines
drivers/gpu/drm/xe/xe_hwmon.c +1
-0@@ -22,6 +22,7 @@#include "xe_pcode_api.h" #include "xe_sriov.h" #include "xe_pm.h" +#include "xe_printk.h" #include "xe_vsec.h" #include "regs/xe_pmt.h"
Maintain the alphabetical order.
Quoted 15 lines
drivers/gpu/drm/xe/xe_hwmon.c +9
-1@@ -139,13 +140,51 @@ struct xe_hwmon_energy_info { };/** -* struct xe_hwmon_fan_info - to cache previous fan reading +* enum fan_table_type - fan table types tracked per fan +*/ +enum fan_table_type { +/** @STOCK_FAN_TABLE: firmware-provided fan table */ +STOCK_FAN_TABLE , +/** @USER_FAN_TABLE: user fan table written through sysfs */ +USER_FAN_TABLE , +/** @FAN_TABLE_MAX: number of fan tables tracked per fan */ +FAN_TABLE_MAX ,
drivers/gpu/drm/xe/xe_hwmon.c struct xe_hwmon_energy_info { · line 161
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+}; + +/* Check if a fan is enabled based on the fan_enable_mask got from FSC_READ_NUM_FANS. */ +#define IS_FAN_ENABLED (hwmon, fan) ((hwmon)->fan_enable_mask & BIT(fan)) + +/* Maximum number of fan control points supported by each fan. */ +#define MAX_FAN_CONTROL_POINTS 10 + +/* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ +#define FCP_INDEX (table_type, point_num) (((u32)(table_type) << 31) | \
Should this be moved to xe_pcode_api.h ?
Quoted 40 lines
drivers/gpu/drm/xe/xe_hwmon.c +22
-0+ ((u32)(point_num) & GENMASK(30, 0))) + +/** +* struct xe_hwmon_fan_info - cached fan telemetry and control state +* +* Each fan keeps the latest tachometer sampling state along with two fan +* tables: the stock table discovered from firmware and the user table managed +* by hwmon sysfs writes. */ struct xe_hwmon_fan_info {/** @reg_val_prev: previous fan reg val */ u32 reg_val_prev;/** @time_prev: previous timestamp */ u64 time_prev; +/** @fan_table: fan control tables */ +struct fan_table { +/** @fan_table.point_count: number of fan control points */ +u8 point_count; +/** @fan_table.fcp: array of fan control points */ +struct fan_control_point { +/** @fan_table.fcp.temp: temperature in degree celsius */ +u8 temp; +/** @fan_table.fcp.speed: fan speed in percentage */ +u8 speed; + } fcp[MAX_FAN_CONTROL_POINTS ]; + } fan_table[FAN_TABLE_MAX ]; };/** @@ -194,6 +233,8 @@ struct xe_hwmon {int scl_shift_time;/** @ei: Energy info for energyN_input */ struct xe_hwmon_energy_info ei[CHANNEL_MAX ]; +/** @fan_enable_mask: bitmask of available fans */ +u32 fan_enable_mask;/** @fi: Fan info for fanN_input */ struct xe_hwmon_fan_info fi[FAN_MAX ];/** @read_power_limit_from_pcode: pcode accepted power limits write for the channel */ @@ -1084,17 +1125,106 @@ static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval) (uval & POWER_SETUP_I1_DATA_MASK));
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval) · line 1134
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +4
-1} -static int xe_hwmon_pcode_read_fan_control (const struct xe_hwmon *hwmon,u32 subcmd,u32 *uval) +static int xe_hwmon_pcode_read_fan_control (const struct xe_hwmon *hwmon,u32 subcmd,u8 fan_num, +u32 *uval) {struct xe_tile *root_tile =xe_device_get_root_tile (hwmon->xe); +return xe_pcode_read (root_tile,PCODE_MBOX (FAN_SPEED_CONTROL , subcmd, fan_num), + uval,NULL );
The continuation line is not aligned with the open parenthesis.
Quoted 48 lines
drivers/gpu/drm/xe/xe_hwmon.c +41
-3+} + +static int xe_hwmon_get_fan_enable_mask (struct xe_hwmon *hwmon) +{ +int ret; +/* Platforms that don't return correct value */ -if (hwmon->xe->info.platform ==XE_DG2 && subcmd ==FSC_READ_NUM_FANS ) { - *uval =2 ; +if (hwmon->xe->info.platform ==XE_DG2 ) { + hwmon->fan_enable_mask =GENMASK (1 ,0 );return 0 ; } -return xe_pcode_read (root_tile,PCODE_MBOX (FAN_SPEED_CONTROL , subcmd,0 ), uval,NULL ); + ret =xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_NUM_FANS ,0 , + &hwmon->fan_enable_mask); +if (ret) { + hwmon->fan_enable_mask =0 ; +xe_warn (hwmon->xe,"failed to read number of fans, ret=%d\n" , ret); +return ret; + } + +/* Check if fan mask exceeds FAN_MAX and log a warning if it does */ +if (hwmon->fan_enable_mask & ~GENMASK (FAN_MAX -1 ,0 )) { +xe_warn (hwmon->xe,"Fan enable mask exceeds %d supported fans, clamping\n" , +FAN_MAX ); + hwmon->fan_enable_mask &=GENMASK (FAN_MAX -1 ,0 ); + } + +xe_info (hwmon->xe,"Number of fans detected: %u\n" ,hweight32 (hwmon->fan_enable_mask)); + +return 0 ; +} + +static int xe_hwmon_read_fan_control_info (struct xe_hwmon *hwmon) +{ +int err =0 ; +int point; +int fan; +int ret; + +for (fan =0 ; fan <FAN_MAX ; fan++) { +struct fan_control_point stock_fcp[MAX_FAN_CONTROL_POINTS ]; +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +u32 stock_fcp_count =0 ; + +if (!IS_FAN_ENABLED (hwmon, fan))
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval) · line 1189
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+continue ; + + ret =xe_hwmon_pcode_read_fan_control (hwmon, +FSC_READ_STOCK_FAN_CONTROL_POINTS , + fan, &stock_fcp_count); +if (ret || !stock_fcp_count) { +xe_warn (hwmon->xe, +"fan %d stock table unavailable, ret=%d, point count=%u\n" , + fan, ret, ret ?0 : stock_fcp_count); + err = ret ?: -ENODATA ;
Can't either of err or ret be discarded ?
Regards,
Soham
Quoted 98 lines
drivers/gpu/drm/xe/xe_hwmon.c +50
-10+continue ; + } + +if (stock_fcp_count >MAX_FAN_CONTROL_POINTS ) { +xe_warn (hwmon->xe, +"fan %d stock table point count %u exceeds maximum %u, clamping\n" , + fan, stock_fcp_count,MAX_FAN_CONTROL_POINTS ); + stock_fcp_count =MAX_FAN_CONTROL_POINTS ; + } + +xe_dbg (hwmon->xe,"fan %d stock table point count is %u\n" , fan, stock_fcp_count); + +/* Cache the stock fan table for later use. */ +for (point =0 ; point < stock_fcp_count; point++) { +u32 fcp =FCP_INDEX (STOCK_FAN_TABLE , point); + + ret =xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_FAN_TABLE , fan, &fcp); +if (ret) { +xe_warn (hwmon->xe,"failed to read fan %d stock point %d, ret=%d\n" , + fan, point, ret); + err = ret; +break ; + } + + stock_fcp[point].temp =REG_FIELD_GET (FAN_CONTROL_POINT_TEMP_MASK , fcp); + stock_fcp[point].speed =REG_FIELD_GET (FAN_CONTROL_POINT_SPEED_MASK , fcp); +xe_dbg (hwmon->xe,"fan %d stock point %d: temp %u C, speed %u %%\n" , + fan, point, stock_fcp[point].temp, stock_fcp[point].speed); + } + +if (point < stock_fcp_count) +continue ; + +memcpy (fi->fan_table[STOCK_FAN_TABLE ].fcp, stock_fcp, + stock_fcp_count *sizeof (stock_fcp[0 ])); + fi->fan_table[STOCK_FAN_TABLE ].point_count = stock_fcp_count; + } +return err; } static int xe_hwmon_power_curr_crit_read(struct xe_hwmon *hwmon, int channel,@@ -1632,17 +1762,12 @@ xe_hwmon_energy_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)static umode_t xe_hwmon_fan_is_visible (struct xe_hwmon *hwmon,u32 attr,int channel) { -u32 uval =0 ; -if (!hwmon->xe->info.has_fan_control)return 0 ;switch (attr) {case hwmon_fan_input: -if (xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_NUM_FANS , &uval)) -return 0 ; - -return channel < uval ?0444 :0 ; +return IS_FAN_ENABLED (hwmon, channel) ?0444 :0 ;default :return 0 ; }@@ -1876,11 +2001,18 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon)if (xe_hwmon_is_visible (hwmon, hwmon_energy, hwmon_energy_input, channel))xe_hwmon_energy_get (hwmon, channel, &energy); -/* Initialize 'struct xe_hwmon_fan_info' with initial fan register reading. */ -for (channel =0 ; channel <FAN_MAX ; channel++) -if (xe_hwmon_is_visible (hwmon, hwmon_fan, hwmon_fan_input, channel)) -xe_hwmon_fan_input_read (hwmon, channel, &fan_speed); +if (hwmon->xe->info.has_fan_control) { +xe_hwmon_get_fan_enable_mask (hwmon); + +/* Initialize 'struct xe_hwmon_fan_info' with initial fan register reading. */ +for (channel =0 ; channel <FAN_MAX ; channel++) +if (IS_FAN_ENABLED (hwmon, channel)) +xe_hwmon_fan_input_read (hwmon, channel, &fan_speed); +/* Fan control tables initialization */ +if (xe_hwmon_read_fan_control_info (hwmon)) +xe_warn (hwmon->xe,"Fan control tables are not available\n" ); + }return xe_hwmon_init_temp_info (hwmon); }drivers/gpu/drm/xe/xe_pcode_api.h +4
-0@@ -87,6 +87,10 @@#define FAN_SPEED_CONTROL 0x7D#define FSC_READ_NUM_FANS 0x4 +#define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5 +#define FSC_READ_FAN_TABLE 0x7 +#define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0) +#define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8)#define PCODE_SCRATCH (x) XE_REG(0x138320 + ((x) * 4))/* PCODE_SCRATCH0 */
Re: [PATCH v5 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache
Quoted 56 lines · Soham
Hi Karthik,
Quoted 53 lines · Karthik Poosa
Initialize Xe hwmon fan-control support by detecting enabled fans, reading stock fan control points and min PWM.
FSC_READ_NUM_FANSreturns a bitmask of enabled fans, so use it as a mask when exposingfanN_input.v2:
- Avoid user table initialization during probe. (Badal)
- Move unused code to appropriate patches.
- Use xe helpers for dmesg logs.v3:
- Rebase.
- Refine a few debug log messages and comments.
- Updatexe_hwmon_read_fan_control_info()to return on any stock table read failures.
- Avoid returning whennum_fansis 0 inxe_hwmon_get_preregistration_info(), ensuring thermal mailbox initialization is not skipped.
- RemoveXE_PCODE_FAN_CONTROL_TIMEOUT_MSwhich is unnecessary as default timeout itself is now 10ms.
- Usexe_pcode_read()instead ofxe_pcode_read_timeout().
- Renamefan_control_point_counttopoint_countin structfan_table.
- Resolve kernel-doc warnings.
- Add valid check for stock table fan point count.
- Use the fan-enable bitmap reported byFSC_READ_NUM_FANSwhen enumerating fans. This avoids assuming contiguous fan indices and allows masks with gaps to be represented correctly in the hwmon interface.v4:
- Clamp unsupported fan masks and oversized stock tables instead of failing initialization. (Soham)
- On stock table read failure, mark that fan's table empty and continue with the remaining fans;fan_inputstays visible. (Soham)
- Clear fan enable mask and min PWM on pcode read failure. (Soham)
- FixFCP_INDEX()type safety and clean up macro usage. (Soham)
- Usexe_hwmon_pcode_read_fan_control()for fan mailbox reads. (Soham)
- Fix kernel-doc forfan_table_typeand nestedfan_tablemembers.
- Skip min PWM read for fans without a stock table.
- Makexe_hwmon_get_fan_enable_mask()return void.v5:
- Removemin_pwmas it is no longer supported by the hardware.
- Changexe_hwmon_get_fan_enable_mask()return type from void to int.
- Copy the stock table to the fan info only if all points are read successfully.Signed-off-by Karthik Poosa <[email protected]>---
drivers/gpu/drm/xe/xe_hwmon.c | 162 +++++++++++++++++++++++++++---drivers/gpu/drm/xe/xe_pcode_api.h| 4 +2 files changed, 151 insertions(+), 15 deletions(-)
Quoted 12 lines
drivers/gpu/drm/xe/xe_hwmon.c line 27
Quoted 11 lines
drivers/gpu/drm/xe/xe_hwmon.c +1
-0@@ -22,6 +22,7 @@ #include "xe_pcode_api.h" #include "xe_sriov.h" #include "xe_pm.h" +#include "xe_printk.h" #include "xe_vsec.h" #include "regs/xe_pmt.h"Maintain the alphabetical order.
ok
xe_printk.h will move above xe_sriov.h
Quoted 19 lines
Quoted 19 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -139,13 +140,51 @@ struct xe_hwmon_energy_info {};
/**
- * structxe_hwmon_fan_info- to cache previous fan reading
+ * enumfan_table_type- fan table types tracked per fan
+ */drivers/gpu/drm/xe/xe_hwmon.c +10
-0+enum fan_table_type { + /** @STOCK_FAN_TABLE: firmware-provided fan table */ + STOCK_FAN_TABLE, + /** @USER_FAN_TABLE: user fan table written through sysfs */ + USER_FAN_TABLE, + /** @FAN_TABLE_MAX: number of fan tables tracked per fan */ + FAN_TABLE_MAX, +}; + +/* Check if a fan is enabled based on the fan_enable_mask got from
FSC_READ_NUM_FANS. */
+#defineIS_FAN_ENABLED(hwmon, fan)((hwmon)->fan_enable_mask & BIT(fan))
Quoted 8 lines
Quoted 7 lines
drivers/gpu/drm/xe/xe_hwmon.c +5
-0+ +/* Maximum number of fan control points supported by each fan. */ +#define MAX_FAN_CONTROL_POINTS 10 + +/* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */
+#defineFCP_INDEX(table_type, point_num)(((u32)(table_type) << 31) | \Should this be moved to
xe_pcode_api.h?
Not needed, these are fan control specific, not used outside this file. No there pcode consumer use these.
Quoted 44 lines
Quoted 44 lines
+ ((u32)(point_num) &
GENMASK(30, 0)))drivers/gpu/drm/xe/xe_hwmon.c +5
-0+ +/** +* struct xe_hwmon_fan_info - cached fan telemetry and control state +* +* Each fan keeps the latest tachometer sampling state along with two fan
+ * tables: the stock table discovered from firmware and the user table managed
+ * by hwmon sysfs writes.
*/
structxe_hwmon_fan_info{
/** @reg_val_prev: previous fan reg val */
u32reg_val_prev;
/** @time_prev: previous timestamp */
u64time_prev;
+ /** @fan_table: fan control tables */
+ structfan_table{
+ /** @fan_table.point_count: number of fan control points */ + u8point_count;
+ /** @fan_table.fcp: array of fan control points */ + structfan_control_point{
+ /** @fan_table.fcp.temp: temperature in degree celsius */ + u8 temp;
+ /** @fan_table.fcp.speed: fan speed in percentage */ + u8 speed;
+ } fcp[MAX_FAN_CONTROL_POINTS];
+ } fan_table[FAN_TABLE_MAX];
};
/**drivers/gpu/drm/xe/xe_hwmon.c +2
-0@@ -194,6 +233,8 @@ struct xe_hwmon { int scl_shift_time; /** @ei: Energy info for energyN_input */ struct xe_hwmon_energy_info ei[CHANNEL_MAX]; + /** @fan_enable_mask: bitmask of available fans */ + u32 fan_enable_mask; /** @fi: Fan info for fanN_input */ struct xe_hwmon_fan_info fi[FAN_MAX]; /** @read_power_limit_from_pcode: pcode accepted power limits write for the channel */@@ -1084,17 +1125,106 @@ static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval) (uval & POWER_SETUP_I1_DATA_MASK)); } -static int xe_hwmon_pcode_read_fan_control(const struct xe_hwmon *hwmon, u32 subcmd, u32 *uval)
Quoted 8 lines
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval) · line 1134
Quoted 7 lines
drivers/gpu/drm/xe/xe_hwmon.c +3
-0+static int xe_hwmon_pcode_read_fan_control (const struct xe_hwmon *hwmon,u32 subcmd,u8 fan_num, + u32 *uval) { struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe); + return xe_pcode_read(root_tile, PCODE_MBOX(FAN_SPEED_CONTROL, subcmd, fan_num), + uval, NULL);The continuation line is not aligned with the open parenthesis.
okay, will fix this
BTW, checkpatch hasn't reported any error for this though.
Quoted 65 lines
Quoted 60 lines
drivers/gpu/drm/xe/xe_hwmon.c +17
-2+} + +static int xe_hwmon_get_fan_enable_mask (struct xe_hwmon *hwmon) +{ + int ret; + /* Platforms that don't return correct value */ - if (hwmon->xe->info.platform == XE_DG2 && subcmd == FSC_READ_NUM_FANS) { - *uval = 2; + if (hwmon->xe->info.platform == XE_DG2) { + hwmon->fan_enable_mask = GENMASK(1, 0); return 0; } - return xe_pcode_read(root_tile, PCODE_MBOX(FAN_SPEED_CONTROL, subcmd, 0), uval, NULL); + ret = xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_NUM_FANS, 0, + &hwmon->fan_enable_mask); + if (ret) { + hwmon->fan_enable_mask = 0; + xe_warn(hwmon->xe, "failed to read number of fans, ret=%d\n", ret); + return ret; + } + + /* Check if fan mask exceeds FAN_MAX and log a warning if itdoes */
+ if (hwmon->fan_enable_mask& ~GENMASK(FAN_MAX - 1, 0)) { + xe_warn(hwmon->xe, "Fan enable mask exceeds %d supported fans, clamping\n",
+FAN_MAX);
+hwmon->fan_enable_mask&=GENMASK(FAN_MAX - 1, 0); + }
+
+xe_info(hwmon->xe, "Number of fans detected: %u\n", hweight32(hwmon->fan_enable_mask));drivers/gpu/drm/xe/xe_hwmon.c +25
-0+ + return 0; +} + +static int xe_hwmon_read_fan_control_info (struct xe_hwmon *hwmon) +{ + int err = 0; + int point; + int fan; + int ret; + + for (fan = 0; fan < FAN_MAX; fan++) { + struct fan_control_point stock_fcp[MAX_FAN_CONTROL_POINTS]; + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; + u32 stock_fcp_count = 0; + + if (!IS_FAN_ENABLED(hwmon, fan)) + continue; + + ret = xe_hwmon_pcode_read_fan_control(hwmon, +FSC_READ_STOCK_FAN_CONTROL_POINTS , + fan, &stock_fcp_count); + if (ret || !stock_fcp_count) { + xe_warn(hwmon->xe, + "fan %d stock table unavailable, ret=%d, pointQuoted 3 lines
count=%u\n",
+ fan, ret, ret ? 0 :stock_fcp_count); + err = ret ?:-ENODATA;Can't either of err or ret be discarded ?
Quoted 2 lines
Regards,
Soham
I think we can.
Quoted 105 lines
Quoted 105 lines
+ continue;
+ }
+
+ if (stock_fcp_count>MAX_FAN_CONTROL_POINTS) { + xe_warn(hwmon->xe,
+ "fan %d stock table point count %u exceeds maximum %u, clamping\n",
+ fan,stock_fcp_count,MAX_FAN_CONTROL_POINTS); +stock_fcp_count=MAX_FAN_CONTROL_POINTS;
+ }
+
+xe_dbg(hwmon->xe, "fan %d stock table point count is %u\n", fan, stock_fcp_count);drivers/gpu/drm/xe/xe_hwmon.c +6
-0+ + /* Cache the stock fan table for later use. */ + for (point = 0; point < stock_fcp_count; point++) { + u32 fcp = FCP_INDEX(STOCK_FAN_TABLE, point); + + ret = xe_hwmon_pcode_read_fan_control(hwmon,
FSC_READ_FAN_TABLE, fan, &fcp);
+ if (ret) {
+ xe_warn(hwmon->xe, "failed to read fan %d stock point %d, ret=%d\n",
+ fan, point, ret);
+ err = ret;
+ break;
+ }
+
+ stock_fcp[point].temp =REG_FIELD_GET(FAN_CONTROL_POINT_TEMP_MASK, fcp);
+ stock_fcp[point].speed =REG_FIELD_GET(FAN_CONTROL_POINT_SPEED_MASK, fcp);
+ xe_dbg(hwmon->xe, "fan %d stock point %d: temp %u C, speed %u %%\n",
+ fan, point, stock_fcp[point].temp, stock_fcp[point].speed);
+ }drivers/gpu/drm/xe/xe_hwmon.c +9
-0+ + if (point < stock_fcp_count) + continue; + + memcpy(fi->fan_table[STOCK_FAN_TABLE].fcp, stock_fcp, + stock_fcp_count * sizeof(stock_fcp[0])); + fi->fan_table[STOCK_FAN_TABLE].point_count = stock_fcp_count; + } + return err;}
static int xe_hwmon_power_curr_crit_read(structxe_hwmon*hwmon, int channel,drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -1632,17 +1762,12 @@ xe_hwmon_energy_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)static
umode_t
xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel){
- u32 uval = 0;
-
if (!hwmon->xe->info.has_fan_control)
return 0;
switch (attr) {
casehwmon_fan_input:
- if (xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_NUM_FANS, &uval))
- return 0;
-
- return channel < uval ? 0444 : 0;
+ returnIS_FAN_ENABLED(hwmon, channel)? 0444 : 0; default:
return 0;
}drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -1876,11 +2001,18 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon) if (xe_hwmon_is_visible(hwmon, hwmon_energy, hwmon_energy_input, channel)) xe_hwmon_energy_get(hwmon, channel, &energy);- /* Initialize 'struct
xe_hwmon_fan_info' with initial fan register reading. */ - for (channel = 0; channel <FAN_MAX; channel++)
- if (xe_hwmon_is_visible(hwmon, hwmon_fan, hwmon_fan_input, channel))
-xe_hwmon_fan_input_read(hwmon, channel, &fan_speed);
+ if (hwmon->xe->info.has_fan_control) {
+xe_hwmon_get_fan_enable_mask(hwmon);
+
+ /* Initialize 'structxe_hwmon_fan_info' with initial fan register reading. */
+ for (channel = 0; channel <FAN_MAX; channel++)
+ if (IS_FAN_ENABLED(hwmon, channel))
+xe_hwmon_fan_input_read(hwmon, channel, &fan_speed);
+ /* Fan control tables initialization */
+ if (xe_hwmon_read_fan_control_info(hwmon))
+xe_warn(hwmon->xe, "Fan control tables are not available\n");
+ }
returnxe_hwmon_init_temp_info(hwmon);
}
diff --gita/drivers/gpu/drm/xe/xe_pcode_api.hb/drivers/gpu/drm/xe/xe_pcode_api.hindex f05846931059..387885760205 100644drivers/gpu/drm/xe/xe_pcode_api.h +4
-0@@ -87,6 +87,10 @@ #define FAN_SPEED_CONTROL 0x7D #define FSC_READ_NUM_FANS 0x4 +#define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5 +#define FSC_READ_FAN_TABLE 0x7 +#define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0) +#define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8) #define PCODE_SCRATCH(x) XE_REG(0x138320 + ((x) * 4)) /* PCODE_SCRATCH0 */
PATCH v5 2/10 drm/xe/hwmon: Expose fanN_max
In reply to Karthik PoosaExpose fan maximum RPM via fanN_max.
The value is derived from the firmware-reported maximum fan RPS and converted to RPM in the fan hwmon read path.
Update Xe hwmon ABI documentation for fanN_max.
--- .../ABI/testing/sysfs-driver-intel-xe-hwmon | 8 ++++++++ drivers/gpu/drm/xe/xe_hwmon.c | 20 ++++++++++++++++++- drivers/gpu/drm/xe/xe_pcode_api.h | 1 + 3 files changed, 28 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +8 -0
@@ -266,6 +266,14 @@ Description: RO. Fan 3 speed in RPM. Only supported for particular Intel Xe graphics platforms. +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/fan[1-3]_max +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: RO. Maximum fan speed in RPM for each fan channel. + + Only supported for particular Intel Xe graphics platforms. + What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/power1_cap Date: May 2025 KernelVersion: 6.15
drivers/gpu/drm/xe/xe_hwmon.c +19 -1
@@ -185,6 +185,8 @@ struct xe_hwmon_fan_info {u8 speed; } fcp[MAX_FAN_CONTROL_POINTS ]; } fan_table[FAN_TABLE_MAX ]; +/** @max_rps: maximum fan RPS */ +u32 max_rps; };/**
@@ -919,7 +921,8 @@ static const struct hwmon_channel_info * const hwmon_info[] = {HWMON_CHANNEL_INFO (curr,HWMON_C_LABEL ,HWMON_C_CRIT |HWMON_C_LABEL ),HWMON_CHANNEL_INFO (in,HWMON_I_INPUT |HWMON_I_LABEL ,HWMON_I_INPUT |HWMON_I_LABEL ),HWMON_CHANNEL_INFO (energy,HWMON_E_INPUT |HWMON_E_LABEL ,HWMON_E_INPUT |HWMON_E_LABEL ), -HWMON_CHANNEL_INFO (fan,HWMON_F_INPUT ,HWMON_F_INPUT ,HWMON_F_INPUT ), +HWMON_CHANNEL_INFO (fan,HWMON_F_INPUT |HWMON_F_MAX ,HWMON_F_INPUT |HWMON_F_MAX , +HWMON_F_INPUT |HWMON_F_MAX ), NULL };
@@ -1171,6 +1174,7 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)int fan;int ret; +/* Stock table failures leave fan_input and fan_max visible; they don't need it. */ for (fan =0 ; fan <FAN_MAX ; fan++) {struct fan_control_point stock_fcp[MAX_FAN_CONTROL_POINTS ];struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
@@ -1179,6 +1183,15 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)if (!IS_FAN_ENABLED (hwmon, fan))continue ; + ret =xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_MAX_FAN_RPS , fan, + &fi->max_rps); +if (ret) { + fi->max_rps =0 ; +xe_warn (hwmon->xe,"failed to read fan %d max RPS, ret=%d\n" , fan, ret); + }else { +xe_dbg (hwmon->xe,"fan %d max RPS %u\n" , fan, fi->max_rps); + } + ret =xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_STOCK_FAN_CONTROL_POINTS , fan, &stock_fcp_count);
@@ -1768,6 +1781,8 @@ xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)switch (attr) {case hwmon_fan_input:return IS_FAN_ENABLED (hwmon, channel) ?0444 :0 ; +case hwmon_fan_max: +return IS_FAN_ENABLED (hwmon, channel) && hwmon->fi[channel].max_rps ?0444 :0 ;default :return 0 ; }
@@ -1818,6 +1833,9 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)switch (attr) {case hwmon_fan_input:return xe_hwmon_fan_input_read (hwmon, channel, val); +case hwmon_fan_max: + *val =mul_u32_u32 (hwmon->fi[channel].max_rps,60 ); +return 0 ;default :return -EOPNOTSUPP ; }
drivers/gpu/drm/xe/xe_pcode_api.h +1 -0
@@ -86,6 +86,7 @@#define MEMORY_CONFIG_SUBCOMMAND_READ_MAX_FREQUENCY 0x1#define FAN_SPEED_CONTROL 0x7D +#define FSC_READ_MAX_FAN_RPS 0x3#define FSC_READ_NUM_FANS 0x4#define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5#define FSC_READ_FAN_TABLE 0x7
Signature · 1 line
2.34.1
PATCH v5 3/10 drm/xe/pcode: Add ordered write batch helper
In reply to Karthik PoosaAdd a pcode helper that issues an ordered sequence of mailbox writes while holding the pcode lock, so no other mailbox command can be interleaved.
This will be used to write fan tables atomically with respect to other pcode users.
--- drivers/gpu/drm/xe/xe_pcode.c | 39 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_pcode.h | 12 +++++++++++ 2 files changed, 51 insertions(+)
drivers/gpu/drm/xe/xe_pcode.c +39 -0
@@ -124,6 +124,45 @@ int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeoutreturn err; } +/** +* xe_pcode_write_batch - issue pcode writes in order under the mailbox lock +* @tile: tile +* @writes: mailbox/data pairs to write +* @count: number of entries in @writes +* +* Holds the pcode lock across all writes so no other mailbox command can be +* interleaved; the lock may be held for up to @count * PCODE_DEFAULT_TIMEOUT_MS. +* Stops at the first failure; earlier writes are not reverted. +* +* Return: 0 on success, negative error code otherwise. +*/ +int xe_pcode_write_batch (struct xe_tile *tile,const struct xe_pcode_write *writes, +unsigned int count) +{ +unsigned int i; +int err =0 ; + +if (!count) +return -EINVAL ; + +mutex_lock (&tile->pcode.lock); +for (i =0 ; i < count; i++) { +u32 data = writes[i].data; + + err =pcode_mailbox_rw (tile, writes[i].mbox, &data,NULL ,PCODE_DEFAULT_TIMEOUT_MS , + false, false); +if (err) { +xe_err (tile_to_xe (tile), +"pcode batch write %u/%u failed: mbox 0x%08x data 0x%08x, ret %pe\n" , + i +1 , count, writes[i].mbox, writes[i].data,ERR_PTR (err)); +break ; + } + } +mutex_unlock (&tile->pcode.lock); + +return err; +} +int xe_pcode_write64_timeout (struct xe_tile *tile,u32 mbox,u32 data0,u32 data1,int timeout) {int err;
drivers/gpu/drm/xe/xe_pcode.h +12 -0
@@ -18,6 +18,16 @@ struct xe_pcode_version {u32 engg; }; +/** +* struct xe_pcode_write - single pcode mailbox write +* @mbox: mailbox command +* @data: value written to PCODE_DATA0 +*/ +struct xe_pcode_write { +u32 mbox; +u32 data; +}; +#define PCODE_DEFAULT_TIMEOUT_MS 10int xe_pcode_init_early (struct xe_tile *tile);
@@ -28,6 +38,8 @@ int xe_pcode_init_min_freq_table(struct xe_tile *tile, u32 min_gt_freq,int xe_pcode_read (struct xe_tile *tile,u32 mbox,u32 *val0,u32 *val1);int xe_pcode_write_timeout (struct xe_tile *tile,u32 mbox,u32 val,int timeout_ms); +int xe_pcode_write_batch (struct xe_tile *tile,const struct xe_pcode_write *writes, +unsigned int count);int xe_pcode_write64_timeout (struct xe_tile *tile,u32 mbox,u32 data0,u32 data1,int timeout);int xe_get_pcode_version (struct xe_device *xe,struct xe_pcode_version *version);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 03/10] drm/xe/pcode: Add ordered write batch helper
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/xe/pcode: missing rationale and lock impact for xe_pcode_write_batch() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/xe/pcode: missing rationale and lock impact for xe_pcode_write_batch()
--
commit 357f40b2588787b30829671c174b780a0ae2ed24
Author: Karthik Poosa <[email protected]>
Quoted 36 lines
drm/xe/pcode: Add ordered write batch helper
Add a pcode helper that issues an ordered sequence of mailbox writes while holding the pcode lock, so no other mailbox command can be interleaved.
This will be used to write fan tables atomically with respect to other pcode users.
Signed-off-by Karthik Poosa <[email protected]>drivers/gpu/drm/xe/xe_pcode.c +17
-0@@ -124,6 +124,45 @@ int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeoutreturn err; } +/** +* xe_pcode_write_batch - issue pcode writes in order under the mailbox lock +* @tile: tile +* @writes: mailbox/data pairs to write +* @count: number of entries in @writes +* +* Holds the pcode lock across all writes so no other mailbox command can be +* interleaved; the lock may be held for up to @count * PCODE_DEFAULT_TIMEOUT_MS. +* Stops at the first failure; earlier writes are not reverted. +* +* Return: 0 on success, negative error code otherwise. +*/ +int xe_pcode_write_batch (struct xe_tile *tile,const struct xe_pcode_write *writes, +unsigned int count) +{ +unsigned int i; +int err =0 ;
drivers/gpu/drm/xe/xe_pcode.c int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeout · line 153
Quoted 10 lines
drivers/gpu/drm/xe/xe_pcode.c +10
-0+ +if (!count) +return -EINVAL ; + +mutex_lock (&tile->pcode.lock); +for (i =0 ; i < count; i++) { +u32 data = writes[i].data; + + err =pcode_mailbox_rw (tile, writes[i].mbox, &data,NULL ,PCODE_DEFAULT_TIMEOUT_MS , + false, false);
[Severity: Low]
As reported by Rodrigo Vivi on v4 [1], the commit message and kernel-doc still do not explain why pcode requires these writes to be issued without interleaved mailbox commands, or assess the risk of holding tile->pcode.lock for up to count * PCODE_DEFAULT_TIMEOUT_MS (110 ms for an 11-entry fan table write) and starving or causing timeouts on other pcode paths.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v5 03/10] drm/xe/pcode: Add ordered write batch helper
In reply to Karthik PoosaHi Karthik,
Quoted 3 lines · Karthik Poosa
Add a pcode helper that issues an ordered sequence of mailbox writes while holding the pcode lock, so no other mailbox command can be interleaved.
But why pcode needs that here ? kindly do mention the same here.
Quoted 16 lines
This will be used to write fan tables atomically with respect to other pcode users.
Signed-off-by Karthik Poosa <[email protected]>--- drivers/gpu/drm/xe/xe_pcode.c | 39 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_pcode.h | 12 +++++++++++ 2 files changed, 51 insertions(+)drivers/gpu/drm/xe/xe_pcode.c +0
-0@@ -124,6 +124,45 @@ int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeoutreturn err;
drivers/gpu/drm/xe/xe_pcode.c int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeout · line 134
Quoted 10 lines
drivers/gpu/drm/xe/xe_pcode.c +8
-0} +/** +* xe_pcode_write_batch - issue pcode writes in order under the mailbox lock +* @tile: tile +* @writes: mailbox/data pairs to write +* @count: number of entries in @writes +* +* Holds the pcode lock across all writes so no other mailbox command can be +* interleaved; the lock may be held for up to @count * PCODE_DEFAULT_TIMEOUT_MS.
Ditto.
drivers/gpu/drm/xe/xe_pcode.c int xe_pcode_write_timeout(struct xe_tile *tile, u32 mbox, u32 data, int timeout · line 146
Quoted 12 lines
drivers/gpu/drm/xe/xe_pcode.c +12
-0+* Stops at the first failure; earlier writes are not reverted. +* +* Return: 0 on success, negative error code otherwise. +*/ +int xe_pcode_write_batch (struct xe_tile *tile,const struct xe_pcode_write *writes, +unsigned int count) +{ +unsigned int i; +int err =0 ; + +if (!count) +return -EINVAL ;
Any log required to mention the specific reason ?
Regards,
Soham
Quoted 52 lines
drivers/gpu/drm/xe/xe_pcode.c +19
-0+ +mutex_lock (&tile->pcode.lock); +for (i =0 ; i < count; i++) { +u32 data = writes[i].data; + + err =pcode_mailbox_rw (tile, writes[i].mbox, &data,NULL ,PCODE_DEFAULT_TIMEOUT_MS , + false, false); +if (err) { +xe_err (tile_to_xe (tile), +"pcode batch write %u/%u failed: mbox 0x%08x data 0x%08x, ret %pe\n" , + i +1 , count, writes[i].mbox, writes[i].data,ERR_PTR (err)); +break ; + } + } +mutex_unlock (&tile->pcode.lock); + +return err; +} +int xe_pcode_write64_timeout (struct xe_tile *tile,u32 mbox,u32 data0,u32 data1,int timeout) {int err;drivers/gpu/drm/xe/xe_pcode.h +12
-0@@ -18,6 +18,16 @@ struct xe_pcode_version {u32 engg; }; +/** +* struct xe_pcode_write - single pcode mailbox write +* @mbox: mailbox command +* @data: value written to PCODE_DATA0 +*/ +struct xe_pcode_write { +u32 mbox; +u32 data; +}; +#define PCODE_DEFAULT_TIMEOUT_MS 10int xe_pcode_init_early (struct xe_tile *tile);@@ -28,6 +38,8 @@ int xe_pcode_init_min_freq_table(struct xe_tile *tile, u32 min_gt_freq,int xe_pcode_read (struct xe_tile *tile,u32 mbox,u32 *val0,u32 *val1);int xe_pcode_write_timeout (struct xe_tile *tile,u32 mbox,u32 val,int timeout_ms); +int xe_pcode_write_batch (struct xe_tile *tile,const struct xe_pcode_write *writes, +unsigned int count);int xe_pcode_write64_timeout (struct xe_tile *tile,u32 mbox,u32 data0,u32 data1,int timeout);int xe_get_pcode_version (struct xe_device *xe,struct xe_pcode_version *version);
PATCH v5 4/10 drm/xe/hwmon: Expose pwm[1-3]
In reply to Karthik PoosaExpose pwm[1-3] hwmon attributes for each available fan. Userspace can read PWM values in the range 0..255 and set a manual fan speed independently of the fan curve. Switching back to the stock curve is added by a later patch.
Read active PWM from PMT on BMG. On other platforms, derive PWM from the stock curve when no user table is active.
After writing the user table, read back its point count to verify firmware accepted it. If verification fails, restore stock fan control.
Document pwm[1-3] in the Xe hwmon ABI.
v2:
- Use xe helpers for dmesg logs.
- Avoid using hwmon->num_fans to get fan count in xe_hwmon_pwm_is_visible().
v3:
- Set PWM directly through the user table; avoid initializing it from the stock table. (Soham)
- Move the unused xe_hwmon_activate_user_fan_table() to the subsequent patch.
- Fail pwmN reads when no value has been written, rather than activating the user table from the stock table.
- Define MIN_FAN_CONTROL_POINTS as 2.
- Use MIN_FAN_CONTROL_POINTS for PWM configuration. (Soham)
- Use batched writes for configuring fan control points when setting pwmN.
- Add and rephrase couple debug logs.
- Update the hwmon documentation.
v4:
- Use tab indentation in ABI doc and MIN_FAN_CONTROL_POINTS. (Soham)
- Drop unused linux/delay.h include. (Soham)
- Clamp min PWM to 100% since fan table speed is in percent. (Soham)
- Log both the requested pwm and the applied percentage. (Soham)
- Fail the pwm write if pcode reports a user point count other than MIN_FAN_CONTROL_POINTS after the write. (Soham)
- Drop redundant channel range checks in pwm read/write. (Soham)
- Fix misleading comments and debug log alignment. (Soham)
- Note that the 0..255 to percent round trip is lossy. (Soham)
- Update ABI Date and KernelVersion to November 2026 and 7.5.
- Document that pwm values below the fan minimum are raised to it.
- Return -ENODATA and log at debug level when pwm has not been set.
- Invalidate the cached user table when the pwm write or verify fails.
- Clear point count on pcode read failure.
- Drop unneeded parentheses in MIN_FAN_CONTROL_POINTS and FIXED_PWM_TEMP.
- Document pcode user table write ordering.
v5:
- Expose pwm[1-3] node only if stock table is valid.
- Read current pwm from PMT for BMG and from stock table for other platforms when user table is not active.
- Read back the user point count after every PWM table write and fall back to stock table when the count is not accepted.
--- .../ABI/testing/sysfs-driver-intel-xe-hwmon | 9 + drivers/gpu/drm/xe/regs/xe_pmt.h | 5 + drivers/gpu/drm/xe/xe_hwmon.c | 312 ++++++++++++++++++ drivers/gpu/drm/xe/xe_pcode_api.h | 3 + 4 files changed, 329 insertions(+)
Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +9 -0
@@ -346,3 +346,12 @@ Description: RW. Package burst power limit interval (Tau in PL2/Tau) in milliseconds over which sustained power is averaged. Only supported for particular Intel Xe graphics platforms. + +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/pwm[1-3] +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: RW. Target fan PWM duty value in the range 0..255, where 255 + is 100% fan speed. + + Only supported for particular Intel Xe graphics platforms.
drivers/gpu/drm/xe/regs/xe_pmt.h +5 -0
@@ -15,6 +15,11 @@#define ENERGY_PKG REG_GENMASK64(31, 0)#define ENERGY_CARD REG_GENMASK64(63, 32) +#define BMG_FAN_PWM_PMT_OFFSET (0x58) +#define BMG_FAN1_PWM REG_GENMASK64(15, 0) +#define BMG_FAN2_PWM REG_GENMASK64(31, 16) +#define BMG_FAN3_PWM REG_GENMASK64(47, 32) +#define PUNIT_VERSION_OFFSET 0xA0#define XE_PMT_BASE_OFFSET 0xE0000
drivers/gpu/drm/xe/xe_hwmon.c +312 -0
360 lines not on this page · raw message
drivers/gpu/drm/xe/xe_pcode_api.h +3 -0
@@ -86,9 +86,12 @@#define MEMORY_CONFIG_SUBCOMMAND_READ_MAX_FREQUENCY 0x1#define FAN_SPEED_CONTROL 0x7D +#define FSC_WRITE_NUM_FAN_CONTROL_POINTS 0x0 +#define FSC_WRITE_FAN_TABLE 0x1#define FSC_READ_MAX_FAN_RPS 0x3#define FSC_READ_NUM_FANS 0x4#define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5 +#define FSC_READ_USER_FAN_CONTROL_POINTS 0x6#define FSC_READ_FAN_TABLE 0x7#define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0)#define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8)
Signature · 1 line
2.34.1
Re: [PATCH v5 04/10] drm/xe/hwmon: Expose pwm[1-3]
Hi Karthik,
Quoted 18 lines · Karthik Poosa
Expose pwm[1-3] hwmon attributes for each available fan. Userspace can read PWM values in the range 0..255 and set a manual fan speed independently of the fan curve. Switching back to the stock curve is added by a later patch.
Read active PWM from PMT on BMG. On other platforms, derive PWM from the stock curve when no user table is active.
After writing the user table, read back its point count to verify firmware accepted it. If verification fails, restore stock fan control.
Document pwm[1-3] in the Xe hwmon ABI.
v2:
- Use xe helpers for dmesg logs.
- Avoid usinghwmon->num_fansto get fan count inxe_hwmon_pwm_is_visible().
Quoted 7 lines
v3:
- Set PWM directly through the user table; avoid initializing it from the stock table. (Soham)
- Move the unusedxe_hwmon_activate_user_fan_table()to the subsequent patch.
- Fail pwmN reads when no value has been written, rather than activating the user table from the stock table.
Is this statement still being followed ?
Quoted 149 lines
- Define
MIN_FAN_CONTROL_POINTSas 2.
- UseMIN_FAN_CONTROL_POINTSfor PWM configuration. (Soham)
- Use batched writes for configuring fan control points when setting pwmN.
- Add and rephrase couple debug logs.
- Update the hwmon documentation.v4:
- Use tab indentation in ABI doc andMIN_FAN_CONTROL_POINTS. (Soham)
- Drop unusedlinux/delay.hinclude. (Soham)
- Clamp min PWM to 100% since fan table speed is in percent. (Soham)
- Log both the requested pwm and the applied percentage. (Soham)
- Fail the pwm write if pcode reports a user point count other thanMIN_FAN_CONTROL_POINTSafter the write. (Soham)
- Drop redundant channel range checks in pwm read/write. (Soham)
- Fix misleading comments and debug log alignment. (Soham)
- Note that the 0..255 to percent round trip is lossy. (Soham)
- Update ABI Date and KernelVersion to November 2026 and 7.5.
- Document that pwm values below the fan minimum are raised to it.
- Return-ENODATAand log at debug level when pwm has not been set.
- Invalidate the cached user table when the pwm write or verify fails.
- Clear point count on pcode read failure.
- Drop unneeded parentheses inMIN_FAN_CONTROL_POINTSandFIXED_PWM_TEMP.
- Document pcode user table write ordering.v5:
- Expose pwm[1-3] node only if stock table is valid.
- Read current pwm from PMT for BMG and from stock table for other platforms when user table is not active.
- Read back the user point count after every PWM table write and fall back to stock table when the count is not accepted.Signed-off-by Karthik Poosa <[email protected]>--- .../ABI/testing/sysfs-driver-intel-xe-hwmon | 9 + drivers/gpu/drm/xe/regs/xe_pmt.h | 5 + drivers/gpu/drm/xe/xe_hwmon.c | 312 ++++++++++++++++++ drivers/gpu/drm/xe/xe_pcode_api.h | 3 + 4 files changed, 329 insertions(+)Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +9
-0@@ -346,3 +346,12 @@ Description: RW. Package burst power limit interval (Tau in PL2/Tau) in milliseconds over which sustained power is averaged. Only supported for particular Intel Xe graphics platforms. + +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/pwm[1-3] +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: RW. Target fan PWM duty value in the range 0..255, where 255 + is 100% fan speed. + + Only supported for particular Intel Xe graphics platforms.drivers/gpu/drm/xe/regs/xe_pmt.h +5
-0@@ -15,6 +15,11 @@#define ENERGY_PKG REG_GENMASK64(31, 0)#define ENERGY_CARD REG_GENMASK64(63, 32) +#define BMG_FAN_PWM_PMT_OFFSET (0x58) +#define BMG_FAN1_PWM REG_GENMASK64(15, 0) +#define BMG_FAN2_PWM REG_GENMASK64(31, 16) +#define BMG_FAN3_PWM REG_GENMASK64(47, 32) +#define PUNIT_VERSION_OFFSET 0xA0#define XE_PMT_BASE_OFFSET 0xE0000drivers/gpu/drm/xe/xe_hwmon.c +55
-0@@ -157,6 +157,9 @@ enum fan_table_type {/* Maximum number of fan control points supported by each fan. */ #define MAX_FAN_CONTROL_POINTS 10 +/* Minimum number of points required for a user fan table. */ +#define MIN_FAN_CONTROL_POINTS 2 +/* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ #define FCP_INDEX (table_type, point_num) (((u32)(table_type) << 31) | \ ((u32)(point_num) & GENMASK(30, 0)))@@ -923,6 +926,7 @@ static const struct hwmon_channel_info * const hwmon_info[] = {HWMON_CHANNEL_INFO (energy,HWMON_E_INPUT |HWMON_E_LABEL ,HWMON_E_INPUT |HWMON_E_LABEL ),HWMON_CHANNEL_INFO (fan,HWMON_F_INPUT |HWMON_F_MAX ,HWMON_F_INPUT |HWMON_F_MAX ,HWMON_F_INPUT |HWMON_F_MAX ), +HWMON_CHANNEL_INFO (pwm,HWMON_PWM_INPUT ,HWMON_PWM_INPUT ,HWMON_PWM_INPUT ), NULL };@@ -1167,6 +1171,118 @@ static int xe_hwmon_get_fan_enable_mask(struct xe_hwmon *hwmon)return 0 ; } +static int xe_hwmon_get_fan_point_count (struct xe_hwmon *hwmon,u8 fan,u32 *point_count, +enum fan_table_type table_type) +{ +int ret; + + ret =xe_hwmon_pcode_read_fan_control (hwmon, + (table_type ==USER_FAN_TABLE ) ? +FSC_READ_USER_FAN_CONTROL_POINTS : +FSC_READ_STOCK_FAN_CONTROL_POINTS , + fan, point_count); +if (ret) { + *point_count =0 ; +xe_err (hwmon->xe,"failed to read fan %d %s point count, ret=%d\n" , fan, + (table_type ==USER_FAN_TABLE ) ?"user" :"stock" , ret); +return ret; + } + +if (*point_count >MAX_FAN_CONTROL_POINTS ) { +xe_err (hwmon->xe,"fan %d %s point count %u exceeds max %u\n" , fan, + (table_type ==USER_FAN_TABLE ) ?"user" :"stock" , *point_count, +MAX_FAN_CONTROL_POINTS ); +return -EINVAL ; + } + +return 0 ; +} + +/* +* Set the fan to automatic mode by clearing the user fan table. +* This will make the firmware run the stock fan table. +*/ +static int xe_hwmon_fan_set_auto (struct xe_hwmon *hwmon,u8 fan) +{ +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +int ret; + + ret =xe_pcode_write (xe_device_get_root_tile (hwmon->xe), +PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_NUM_FAN_CONTROL_POINTS , fan), +0 ); +if (ret) +return ret; + + fi->fan_table[USER_FAN_TABLE ].point_count =0 ; + +return 0 ; +} + +/* Temperature to set when setting the fan PWM with pwm[1-3]. */ +#define FIXED_PWM_TEMP 1 + +static int xe_hwmon_set_user_fan_pwm (struct xe_hwmon *hwmon,u8 fan,u8 pwm)
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_get_fan_enable_mask(struct xe_hwmon *hwmon) · line 1234
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+{ +struct xe_pcode_write writes[MIN_FAN_CONTROL_POINTS +1 ]; +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +int ret, write_ret, verify_ret, i; +u32 point_count =0 ; +u8 speed; + +/* Fan table speed are in percent. */ + speed =DIV_ROUND_CLOSEST (pwm *100 ,U8_MAX ); + speed =min_t (u32, speed,100 );
Is minimum fan speed not needed, or is it enforced by firmware?
Quoted 141 lines
drivers/gpu/drm/xe/xe_hwmon.c +127
-0+ +/* Fan control needs at least two points; program them all at the same speed. */ +for (i =0 ; i <MIN_FAN_CONTROL_POINTS ; i++) { + writes[i].mbox =PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_FAN_TABLE , fan); + writes[i].data =FIELD_PREP (FAN_CONTROL_POINT_TEMP_MASK ,FIXED_PWM_TEMP + i) | +FIELD_PREP (FAN_CONTROL_POINT_SPEED_MASK , speed); +xe_dbg (hwmon->xe,"prepared fan control point %d with temp=%d, speed=%u%%\n" , i, +FIXED_PWM_TEMP + i, speed); + } + +/* pcode fills the user table from point 0 in write order; the count write commits it. */ + writes[i].mbox =PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_NUM_FAN_CONTROL_POINTS , fan); + writes[i].data =MIN_FAN_CONTROL_POINTS ; + write_ret =xe_pcode_write_batch (xe_device_get_root_tile (hwmon->xe), writes, +ARRAY_SIZE (writes)); +if (write_ret) +xe_err (hwmon->xe,"failed to write pwm %u (%u%%) for fan %d, ret=%d\n" , + pwm, speed, fan, write_ret); +else +xe_dbg (hwmon->xe,"applied pwm %u (%u%%) for fan %d\n" , pwm, speed, fan); + + verify_ret =xe_hwmon_get_fan_point_count (hwmon, fan, &point_count,USER_FAN_TABLE ); +if (write_ret || verify_ret || point_count !=MIN_FAN_CONTROL_POINTS ) { +int failure_ret = write_ret ?: verify_ret ?: -EIO ; + +/* Firmware may have accepted only part of the user table. */ + fi->fan_table[USER_FAN_TABLE ].point_count =0 ; +if (verify_ret || point_count !=MIN_FAN_CONTROL_POINTS ) +xe_err (hwmon->xe, +"fan %d PWM table count verification failed: ret=%d, count=%u\n" , + fan, verify_ret, point_count); + ret =xe_hwmon_fan_set_auto (hwmon, fan); +if (ret) +xe_err (hwmon->xe,"failed to restore fan %d to auto mode ret=%d\n" , + fan, ret); +return failure_ret; + } + +/* Update the user fan table cache. */ +for (i =0 ; i <MIN_FAN_CONTROL_POINTS ; i++) { + fi->fan_table[USER_FAN_TABLE ].fcp[i].temp =FIXED_PWM_TEMP + i; + fi->fan_table[USER_FAN_TABLE ].fcp[i].speed = speed; +xe_dbg (hwmon->xe,"fan %d user table cache point %d with temp=%d, speed=%u%%\n" , + fan, i, fi->fan_table[USER_FAN_TABLE ].fcp[i].temp, + fi->fan_table[USER_FAN_TABLE ].fcp[i].speed); + } + fi->fan_table[USER_FAN_TABLE ].point_count =MIN_FAN_CONTROL_POINTS ; + +return 0 ; +} +static int xe_hwmon_read_fan_control_info (struct xe_hwmon *hwmon) {int err =0 ;@@ -1788,6 +1904,21 @@ xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) } } +static umode_t +xe_hwmon_pwm_is_visible (struct xe_hwmon *hwmon,u32 attr,int channel) +{ +if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED (hwmon, channel) || + !hwmon->fi[channel].fan_table[STOCK_FAN_TABLE ].point_count) +return 0 ; + +switch (attr) { +case hwmon_pwm_input: +return 0644 ; +default : +return 0 ; + } +} +static int xe_hwmon_fan_input_read (struct xe_hwmon *hwmon,int channel,long *val) {@@ -1841,6 +1972,180 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) } } +/** +* xe_hwmon_get_stock_table_pwm - Calculate PWM from the stock fan curve +* @hwmon: hwmon instance, with hwmon_lock held and runtime PM active +* @channel: fan channel +* @val: calculated PWM percentage +* +* Read package temperature and linearly interpolate the stock table. Temperatures +* outside the table range use the speed at the nearest endpoint. +* +* Return: 0 on success, or a negative error code. +*/ +static int xe_hwmon_get_stock_table_pwm (struct xe_hwmon *hwmon,int channel,long *val) +{ +const struct fan_table *table = &hwmon->fi[channel].fan_table[STOCK_FAN_TABLE ]; +long temperature, pwm; +int point, ret; + +lockdep_assert_held (&hwmon->hwmon_lock); + +if (!table->point_count) +return -ENODATA ; + + ret =xe_hwmon_temp_read (hwmon, hwmon_temp_input,CHANNEL_PKG , &temperature); +if (ret) +return ret; + + pwm = table->fcp[0 ].speed; +for (point =1 ; point < table->point_count; point++) { +const struct fan_control_point *lower = &table->fcp[point -1 ]; +const struct fan_control_point *upper = &table->fcp[point]; +long lower_temp = lower->temp *MILLIDEGREE_PER_DEGREE ; +long upper_temp = upper->temp *MILLIDEGREE_PER_DEGREE ; +long pwm_delta = upper->speed - lower->speed; + +/* Find the bracketing points; temperatures outside the curve use endpoints. */ +if (temperature <= lower_temp) +break ; +if (temperature < upper_temp) { + pwm +=DIV_ROUND_CLOSEST (pwm_delta * (temperature - lower_temp), + upper_temp - lower_temp); +break ; + } + pwm = upper->speed; + } + + *val = pwm; +xe_dbg (hwmon->xe,"fan %d stock table active PWM value: %ld\n" , channel, pwm); +return 0 ; +} + +/** +* xe_hwmon_get_pwm_from_pmt - Read active fan PWM from PMT telemetry +* @hwmon: hwmon instance, with hwmon_lock held and runtime PM active +* @channel: fan channel +* @val: raw PWM percentage returned by PMT +* +* Return: 0 on success, or a negative error code. +*/ +static int xe_hwmon_get_pwm_from_pmt (struct xe_hwmon *hwmon,int channel,long *val) +{ +u64 pmt_val;
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) · line 2045
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+u32 guid, pwm; +int ret; + +lockdep_assert_held (&hwmon->hwmon_lock); + +if (hwmon->xe->info.platform !=XE_BATTLEMAGE ) +return -EOPNOTSUPP ; + + ret =xe_vsec_get_guid (hwmon->xe, &guid); +if (ret)
Should here be a drm_warn() as used in xe_hwmon_energy_get()
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) · line 2050
Quoted 5 lines
drivers/gpu/drm/xe/xe_hwmon.c +5
-0+return ret; + + ret =xe_pmt_telem_read (hwmon->xe->drm.dev, guid, &pmt_val, +BMG_FAN_PWM_PMT_OFFSET ,sizeof (pmt_val)); +if (ret !=sizeof (pmt_val))
Ditto.
Regards,
Soham
Quoted 146 lines
drivers/gpu/drm/xe/xe_hwmon.c +105
-0+return ret <0 ? ret : -EIO ; + +switch (channel) { +case FAN_1 : + pwm =REG_FIELD_GET64 (BMG_FAN1_PWM , pmt_val); +break ; +case FAN_2 : + pwm =REG_FIELD_GET64 (BMG_FAN2_PWM , pmt_val); +break ; +case FAN_3 : + pwm =REG_FIELD_GET64 (BMG_FAN3_PWM , pmt_val); +break ; +default : +return -EOPNOTSUPP ; + } + +xe_dbg (hwmon->xe,"fan %d PMT active PWM value: %u\n" , channel, pwm); + + *val = pwm; +return 0 ; +} + +static int +xe_hwmon_pwm_read (struct xe_hwmon *hwmon,u32 attr,int channel,long *val) +{ +struct xe_hwmon_fan_info *fi; +long pwm; +int ret =0 ; + +mutex_lock (&hwmon->hwmon_lock); + + fi = &hwmon->fi[channel]; + +switch (attr) { +case hwmon_pwm_input: +/* If the user fan table is not populated, get active stock pwm */ +if (!fi->fan_table[USER_FAN_TABLE ].point_count) { +xe_dbg (hwmon->xe,"user fan table not active for fan %d\n" , channel); +switch (hwmon->xe->info.platform) { +case XE_BATTLEMAGE : + ret =xe_hwmon_get_pwm_from_pmt (hwmon, channel, &pwm); +break ; +default : + ret =xe_hwmon_get_stock_table_pwm (hwmon, channel, &pwm); +break ; + } +if (ret) + goto unlock; + }else { +/* +* pwmN writes set every user-table point to the same speed, +* so the first point gives the cached manual PWM percentage. +*/ + pwm = fi->fan_table[USER_FAN_TABLE ].fcp[0 ].speed; + } +if (pwm <0 || pwm >100 ) { +xe_err (hwmon->xe,"invalid PWM value %ld read for fan %d\n" , pwm, channel); + ret = -ERANGE ; + goto unlock; + } +/* Speed is cached in percent, so the 0..255 round trip may be off by a step. */ + *val =DIV_ROUND_CLOSEST (pwm *U8_MAX ,100 ); +xe_dbg (hwmon->xe,"pwm read for fan %d: %ld\n" , channel, *val); +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } + +unlock: +mutex_unlock (&hwmon->hwmon_lock); +return ret; +} + +static int +xe_hwmon_pwm_write (struct xe_hwmon *hwmon,u32 attr,int channel,long val) +{ +int ret =0 ; + +mutex_lock (&hwmon->hwmon_lock); + +switch (attr) { +case hwmon_pwm_input: +if (val <0 || val >U8_MAX ) { + ret = -EINVAL ; +break ; + } + ret =xe_hwmon_set_user_fan_pwm (hwmon, channel, (u8 )val); +break ; +default : + ret = -EOPNOTSUPP ; +break ; + } +mutex_unlock (&hwmon->hwmon_lock); + +return ret; +} +static umode_t xe_hwmon_is_visible (const void *drvdata,enum hwmon_sensor_types type,u32 attr,int channel)@@ -1867,6 +2172,9 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,case hwmon_fan: ret =xe_hwmon_fan_is_visible (hwmon, attr, channel);break ; +case hwmon_pwm: + ret =xe_hwmon_pwm_is_visible (hwmon, attr, channel); +break ;default : ret =0 ;break ;@@ -1896,6 +2204,8 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,return xe_hwmon_energy_read (hwmon, attr, channel, val);case hwmon_fan:return xe_hwmon_fan_read (hwmon, attr, channel, val); +case hwmon_pwm: +return xe_hwmon_pwm_read (hwmon, attr, channel, val);default :return -EOPNOTSUPP ; }@@ -1914,6 +2224,8 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,return xe_hwmon_power_write (hwmon, attr, channel, val);case hwmon_curr:return xe_hwmon_curr_write (hwmon, attr, channel, val); +case hwmon_pwm: +return xe_hwmon_pwm_write (hwmon, attr, channel, val);default :return -EOPNOTSUPP ; }drivers/gpu/drm/xe/xe_pcode_api.h +3
-0@@ -86,9 +86,12 @@#define MEMORY_CONFIG_SUBCOMMAND_READ_MAX_FREQUENCY 0x1#define FAN_SPEED_CONTROL 0x7D +#define FSC_WRITE_NUM_FAN_CONTROL_POINTS 0x0 +#define FSC_WRITE_FAN_TABLE 0x1#define FSC_READ_MAX_FAN_RPS 0x3#define FSC_READ_NUM_FANS 0x4#define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5 +#define FSC_READ_USER_FAN_CONTROL_POINTS 0x6#define FSC_READ_FAN_TABLE 0x7#define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0)#define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8)
Re: [PATCH v5 04/10] drm/xe/hwmon: Expose pwm[1-3]
Quoted 21 lines · Soham
Hi Karthik,
Quoted 18 lines · Karthik Poosa
Expose pwm[1-3] hwmon attributes for each available fan. Userspace can read PWM values in the range 0..255 and set a manual fan speed independently of the fan curve. Switching back to the stock curve is added by a later patch.
Read active PWM from PMT on BMG. On other platforms, derive PWM from the stock curve when no user table is active.
After writing the user table, read back its point count to verify firmware accepted it. If verification fails, restore stock fan control.
Document pwm[1-3] in the Xe hwmon ABI.
v2:
- Use xe helpers for dmesg logs.
- Avoid usinghwmon->num_fansto get fan count inxe_hwmon_pwm_is_visible().
Quoted 8 lines
Quoted 7 lines
v3:
- Set PWM directly through the user table; avoid initializing it from the stock table. (Soham)
- Move the unusedxe_hwmon_activate_user_fan_table()to the subsequent patch.
- Fail pwmN reads when no value has been written, rather than activating the user table from the stock table.Is this statement still being followed ?
No, this was in v3. Since this is a read operation, I think we don't need to set the PWM internally. We simply return the currently active PWM value.
Quoted 155 lines
Quoted 155 lines
- Define
MIN_FAN_CONTROL_POINTSas 2.
- UseMIN_FAN_CONTROL_POINTSfor PWM configuration. (Soham)
- Use batched writes for configuring fan control points when setting pwmN.
- Add and rephrase couple debug logs.
- Update the hwmon documentation.v4:
- Use tab indentation in ABI doc andMIN_FAN_CONTROL_POINTS. (Soham)
- Drop unusedlinux/delay.hinclude. (Soham)
- Clamp min PWM to 100% since fan table speed is in percent. (Soham)
- Log both the requested pwm and the applied percentage. (Soham)
- Fail the pwm write if pcode reports a user point count other thanMIN_FAN_CONTROL_POINTSafter the write. (Soham)
- Drop redundant channel range checks in pwm read/write. (Soham)
- Fix misleading comments and debug log alignment. (Soham)
- Note that the 0..255 to percent round trip is lossy. (Soham)
- Update ABI Date and KernelVersion to November 2026 and 7.5.
- Document that pwm values below the fan minimum are raised to it.
- Return-ENODATAand log at debug level when pwm has not been set.
- Invalidate the cached user table when the pwm write or verify fails.
- Clear point count on pcode read failure.
- Drop unneeded parentheses inMIN_FAN_CONTROL_POINTSandFIXED_PWM_TEMP.
- Document pcode user table write ordering.v5:
- Expose pwm[1-3] node only if stock table is valid.
- Read current pwm from PMT for BMG and from stock table for other platforms when user table is not active.
- Read back the user point count after every PWM table write and fall back to stock table when the count is not accepted.Signed-off-by Karthik Poosa <[email protected]>---
.../ABI/testing/sysfs-driver-intel-xe-hwmon | 9 + drivers/gpu/drm/xe/regs/xe_pmt.h | 5 + drivers/gpu/drm/xe/xe_hwmon.c | 312 ++++++++++++++++++ drivers/gpu/drm/xe/xe_pcode_api.h | 3 +4 files changed, 329 insertions(+)Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +0
-0@@ -346,3 +346,12 @@ Description: RW. Package burst power limitinterval (Tau in PL2/Tau) in
milliseconds over which sustained power is averaged. Only supported for particular Intel Xe graphics platforms.Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +6
-0+ +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/pwm[1-3] +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: RW. Target fan PWM duty value in the range 0..255,where 255
+ is 100% fan speed.Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +2
-0+ + Only supported for particular Intel Xe graphics platforms.drivers/gpu/drm/xe/regs/xe_pmt.h +4
-0@@ -15,6 +15,11 @@ #define ENERGY_PKG REG_GENMASK64(31, 0) #define ENERGY_CARD REG_GENMASK64(63, 32) +#define BMG_FAN_PWM_PMT_OFFSET (0x58) +#define BMG_FAN1_PWM REG_GENMASK64(15, 0) +#define BMG_FAN2_PWM REG_GENMASK64(31, 16) +#define BMG_FAN3_PWM REG_GENMASK64(47, 32) + #define PUNIT_VERSION_OFFSET 0xA0 #define XE_PMT_BASE_OFFSET 0xE0000drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -157,6 +157,9 @@ enum fan_table_type { /* Maximum number of fan control points supported by each fan. */ #define MAX_FAN_CONTROL_POINTS 10+/* Minimum number of points required for a user fan table. */
drivers/gpu/drm/xe/xe_hwmon.c +2
-0+#define MIN_FAN_CONTROL_POINTS 2 +/* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ #define
FCP_INDEX(table_type, point_num)(((u32)(table_type) << 31) | \
((u32)(point_num) &GENMASK(30, 0)))drivers/gpu/drm/xe/xe_hwmon.c +1
-0@@ -923,6 +926,7 @@ static const struct hwmon_channel_info * const hwmon_info[] = { HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT | HWMON_E_LABEL, HWMON_E_INPUT | HWMON_E_LABEL), HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_MAX, HWMON_F_INPUT | HWMON_F_MAX, HWMON_F_INPUT | HWMON_F_MAX), + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT, HWMON_PWM_INPUT, HWMON_PWM_INPUT),NULL
};
@@ -1167,6 +1171,118 @@ static intxe_hwmon_get_fan_enable_mask(struct xe_hwmon *hwmon)return 0;
}
+static int xe_hwmon_get_fan_point_count(structxe_hwmon*hwmon, u8 fan, u32*point_count, + enumfan_table_typetable_type)drivers/gpu/drm/xe/xe_hwmon.c +11
-0+{ + int ret; + + ret = xe_hwmon_pcode_read_fan_control(hwmon, + (table_type == USER_FAN_TABLE) ? + FSC_READ_USER_FAN_CONTROL_POINTS : + FSC_READ_STOCK_FAN_CONTROL_POINTS, + fan, point_count); + if (ret) { + *point_count = 0; + xe_err(hwmon->xe, "failed to read fan %d %s point count,ret=%d\n", fan,
+ (table_type==USER_FAN_TABLE) ? "user" : "stock", ret); + return ret;
+ }
+
+ if (*point_count>MAX_FAN_CONTROL_POINTS) {
+ xe_err(hwmon->xe, "fan %d %s point count %u exceeds max %u\n", fan,
+ (table_type==USER_FAN_TABLE) ? "user" : "stock",*point_count,
+MAX_FAN_CONTROL_POINTS);
+ return-EINVAL;
+ }drivers/gpu/drm/xe/xe_hwmon.c +15
-0+ + return 0; +} + +/* +* Set the fan to automatic mode by clearing the user fan table. +* This will make the firmware run the stock fan table. +*/ +static int xe_hwmon_fan_set_auto (struct xe_hwmon *hwmon,u8 fan) +{ + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; + int ret; + + ret = xe_pcode_write(xe_device_get_root_tile(hwmon->xe), + PCODE_MBOX(FAN_SPEED_CONTROL,
FSC_WRITE_NUM_FAN_CONTROL_POINTS, fan),
+ 0);
+ if (ret)
+ return ret;drivers/gpu/drm/xe/xe_hwmon.c +10
-0+ + fi->fan_table[USER_FAN_TABLE].point_count = 0; + + return 0; +} + +/* Temperature to set when setting the fan PWM with pwm[1-3]. */ +#define FIXED_PWM_TEMP 1 + +static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan,u8 pwm)
+{
+ structxe_pcode_writewrites[MIN_FAN_CONTROL_POINTS + 1]; + structxe_hwmon_fan_info*fi = &hwmon->fi[fan];
Quoted 8 lines
Quoted 7 lines
+ int ret,
write_ret,verify_ret, i;
+ u32point_count= 0;
+ u8 speed;
+
+ /* Fan table speed are in percent. */ + speed =DIV_ROUND_CLOSEST(pwm * 100, U8_MAX); + speed =min_t(u32, speed, 100);Is minimum fan speed not needed, or is it enforced by firmware?
not needed now, the command support is removed, we can set 0 pwm. earlier min_pwm also was 0.
Quoted 168 lines
Quoted 168 lines
+
+ /* Fan control needs at least two points; program them all at the same speed. */
+ for (i = 0; i <MIN_FAN_CONTROL_POINTS; i++) {
+ writes[i].mbox =PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_FAN_TABLE, fan);
+ writes[i].data =FIELD_PREP(FAN_CONTROL_POINT_TEMP_MASK, FIXED_PWM_TEMP + i)|
+FIELD_PREP(FAN_CONTROL_POINT_SPEED_MASK, speed); + xe_dbg(hwmon->xe, "prepared fan control point %d with temp=%d, speed=%u%%\n", i,
+FIXED_PWM_TEMP+ i, speed);
+ }
+
+ /* pcode fills the user table from point 0 in write order; the count write commits it. */
+ writes[i].mbox =PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, fan);
+ writes[i].data =MIN_FAN_CONTROL_POINTS;
+write_ret= xe_pcode_write_batch(xe_device_get_root_tile(hwmon->xe), writes, +ARRAY_SIZE(writes));
+ if (write_ret)
+ xe_err(hwmon->xe, "failed to write pwm %u (%u%%) for fan %d, ret=%d\n",
+ pwm, speed, fan,write_ret);
+ else
+xe_dbg(hwmon->xe, "applied pwm %u (%u%%) for fan %d\n", pwm, speed, fan);
+
+verify_ret=xe_hwmon_get_fan_point_count(hwmon, fan, &point_count, USER_FAN_TABLE);
+ if (write_ret||verify_ret||point_count!=MIN_FAN_CONTROL_POINTS) {
+ intfailure_ret=write_ret?:verify_ret?:-EIO; +
+ /* Firmware may have accepted only part of the user table. */ + fi->fan_table[USER_FAN_TABLE].point_count = 0;
+ if (verify_ret||point_count!=MIN_FAN_CONTROL_POINTS) + xe_err(hwmon->xe,
+ "fan %d PWM table count verification failed:
ret=%d, count=%u\n",
+ fan,verify_ret,point_count);
+ ret =xe_hwmon_fan_set_auto(hwmon, fan);
+ if (ret)
+ xe_err(hwmon->xe, "failed to restore fan %d to auto mode ret=%d\n",
+ fan, ret);
+ returnfailure_ret;
+ }
+
+ /* Update the user fan table cache. */
+ for (i = 0; i <MIN_FAN_CONTROL_POINTS; i++) {
+ fi->fan_table[USER_FAN_TABLE].fcp[i].temp =FIXED_PWM_TEMP+ i; + fi->fan_table[USER_FAN_TABLE].fcp[i].speed = speed; + xe_dbg(hwmon->xe, "fan %d user table cache point %d with temp=%d, speed=%u%%\n",
+ fan, i, fi->fan_table[USER_FAN_TABLE].fcp[i].temp, + fi->fan_table[USER_FAN_TABLE].fcp[i].speed); + }
+ fi->fan_table[USER_FAN_TABLE].point_count =MIN_FAN_CONTROL_POINTS;drivers/gpu/drm/xe/xe_hwmon.c +4
-0+ + return 0; +} +static int
xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon){
int err = 0;drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -1788,6 +1904,21 @@ xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) } }+static
umode_tdrivers/gpu/drm/xe/xe_hwmon.c +3
-0+xe_hwmon_pwm_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) +{ + if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED(hwmon,channel) ||
+ !hwmon->fi[channel].fan_table[STOCK_FAN_TABLE].point_count) + return 0;drivers/gpu/drm/xe/xe_hwmon.c +9
-0+ + switch (attr) { + case hwmon_pwm_input: + return 0644; + default: + return 0; + } +} +static int
xe_hwmon_fan_input_read(struct xe_hwmon *hwmon, int channel, long *val){drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -1841,6 +1972,180 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) } }+/**
+ *xe_hwmon_get_stock_table_pwm- Calculate PWM from the stock fan curve
+ * @hwmon: hwmon instance, withhwmon_lockheld and runtime PM active
+ * @channel: fan channel
+ * @val: calculated PWM percentage
+ *
+ * Read package temperature and linearly interpolate the stock table. Temperatures
+ * outside the table range use the speed at the nearest endpoint.
+ *
+ * Return: 0 on success, or a negative error code.
+ */
+static intxe_hwmon_get_stock_table_pwm(struct xe_hwmon *hwmon, int channel, long *val)
+{
+ const structfan_table*table = &hwmon->fi[channel].fan_table[STOCK_FAN_TABLE];
+ long temperature, pwm;
+ int point, ret;drivers/gpu/drm/xe/xe_hwmon.c +7
-0+ + lockdep_assert_held(&hwmon->hwmon_lock); + + if (!table->point_count) + return -ENODATA; + + ret = xe_hwmon_temp_read(hwmon, hwmon_temp_input, CHANNEL_PKG,&temperature);
+ if (ret)
+ return ret;drivers/gpu/drm/xe/xe_hwmon.c +10
-0+ + pwm = table->fcp[0].speed; + for (point = 1; point < table->point_count; point++) { + const struct fan_control_point *lower = &table->fcp[point - 1]; + const struct fan_control_point *upper = &table->fcp[point]; + long lower_temp = lower->temp * MILLIDEGREE_PER_DEGREE; + long upper_temp = upper->temp * MILLIDEGREE_PER_DEGREE; + long pwm_delta = upper->speed - lower->speed; + + /* Find the bracketing points; temperatures outside thecurve use endpoints. */
+ if (temperature <=lower_temp)
+ break;
+ if (temperature <upper_temp) {
+ pwm += DIV_ROUND_CLOSEST(pwm_delta * (temperature -lower_temp),
+upper_temp-lower_temp);
+ break;
+ }
+ pwm =upper->speed;
+ }
+
+ *val = pwm;
+xe_dbg(hwmon->xe, "fan %d stock table active PWM value: %ld\n", channel, pwm);
+ return 0;drivers/gpu/drm/xe/xe_hwmon.c +11
-0+} + +/** +* xe_hwmon_get_pwm_from_pmt - Read active fan PWM from PMT telemetry +* @hwmon: hwmon instance, with hwmon_lock held and runtime PM active +* @channel: fan channel +* @val: raw PWM percentage returned by PMT +* +* Return: 0 on success, or a negative error code. +*/ +static int xe_hwmon_get_pwm_from_pmt(struct xe_hwmon *hwmon, intchannel, long *val)
drivers/gpu/drm/xe/xe_hwmon.c +5
-0+{ + u64 pmt_val; + u32 guid, pwm; + int ret; +
Quoted 8 lines
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) · line 2045
Quoted 7 lines
+
lockdep_assert_held(&hwmon->hwmon_lock);drivers/gpu/drm/xe/xe_hwmon.c +6
-0+ + if (hwmon->xe->info.platform != XE_BATTLEMAGE) + return -EOPNOTSUPP; + + ret = xe_vsec_get_guid(hwmon->xe, &guid); + if (ret)Should here be a drm_warn() as used in
xe_hwmon_energy_get()
yeah we can add that.
Quoted 6 lines
Quoted 5 lines
+ return ret;
+
+ ret = xe_pmt_telem_read(hwmon->xe->drm.dev, guid,&pmt_val, +BMG_FAN_PWM_PMT_OFFSET,sizeof(pmt_val)); + if (ret !=sizeof(pmt_val))Ditto.
same as above
Quoted 161 lines
Regards,
SohamQuoted 158 lines
+ return ret < 0 ? ret :
-EIO;drivers/gpu/drm/xe/xe_hwmon.c +16
-0+ + switch (channel) { + case FAN_1: + pwm = REG_FIELD_GET64(BMG_FAN1_PWM, pmt_val); + break; + case FAN_2: + pwm = REG_FIELD_GET64(BMG_FAN2_PWM, pmt_val); + break; + case FAN_3: + pwm = REG_FIELD_GET64(BMG_FAN3_PWM, pmt_val); + break; + default: + return -EOPNOTSUPP; + } + + xe_dbg(hwmon->xe, "fan %d PMT active PWM value: %u\n", channel,pwm);
drivers/gpu/drm/xe/xe_hwmon.c +7
-0+ + *val = pwm; + return 0; +} + +static int +xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel,long *val)
drivers/gpu/drm/xe/xe_hwmon.c +12
-0+{ + struct xe_hwmon_fan_info *fi; + long pwm; + int ret = 0; + + mutex_lock(&hwmon->hwmon_lock); + + fi = &hwmon->fi[channel]; + + switch (attr) { + case hwmon_pwm_input: + /* If the user fan table is not populated, get active stockpwm */
+ if (!fi->fan_table[USER_FAN_TABLE].point_count) {
+xe_dbg(hwmon->xe, "user fan table not active for fan %d\n", channel);
+ switch (hwmon->xe->info.platform) {
+ caseXE_BATTLEMAGE:
+ ret =xe_hwmon_get_pwm_from_pmt(hwmon, channel, &pwm); + break;
+ default:
+ ret =xe_hwmon_get_stock_table_pwm(hwmon, channel, &pwm);
+ break;
+ }
+ if (ret)
+ goto unlock;
+ } else {
+ /*
+ * pwmN writes set every user-table point to the same speed,
+ * so the first point gives the cached manual PWM percentage.
+ */
+ pwm = fi->fan_table[USER_FAN_TABLE].fcp[0].speed; + }
+ if (pwm < 0 || pwm > 100) {
+xe_err(hwmon->xe, "invalid PWM value %ld read for fan %d\n", pwm, channel);
+ ret =-ERANGE;
+ goto unlock;
+ }
+ /* Speed is cached in percent, so the 0..255 round trip may be off by a step. */
+ *val =DIV_ROUND_CLOSEST(pwm * U8_MAX, 100);
+xe_dbg(hwmon->xe, "pwm read for fan %d: %ld\n", channel, *val); + break;
+ default:
+ ret =-EOPNOTSUPP;
+ break;
+ }drivers/gpu/drm/xe/xe_hwmon.c +8
-0+ +unlock: + mutex_unlock(&hwmon->hwmon_lock); + return ret; +} + +static int +xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel,long val)
drivers/gpu/drm/xe/xe_hwmon.c +22
-0+{ + int ret = 0; + + mutex_lock(&hwmon->hwmon_lock); + + switch (attr) { + case hwmon_pwm_input: + if (val < 0 || val > U8_MAX) { + ret = -EINVAL; + break; + } + ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val); + break; + default: + ret = -EOPNOTSUPP; + break; + } + mutex_unlock(&hwmon->hwmon_lock); + + return ret; +} +static
umode_t
xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type, u32 attr, int channel)drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -1867,6 +2172,9 @@ xe_hwmon_is_visible(const void *drvdata, enum hwmon_sensor_types type,case
hwmon_fan:
ret =xe_hwmon_fan_is_visible(hwmon, attr, channel); break;
+ casehwmon_pwm:
+ ret =xe_hwmon_pwm_is_visible(hwmon, attr, channel); + break;
default:
ret = 0;
break;drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -1896,6 +2204,8 @@ xe_hwmon_read(struct device *dev, enum hwmon_sensor_types type, u32 attr, return xe_hwmon_energy_read(hwmon, attr, channel, val);case
hwmon_fan:
returnxe_hwmon_fan_read(hwmon, attr, channel, val); + casehwmon_pwm:
+ returnxe_hwmon_pwm_read(hwmon, attr, channel, val); default:
return-EOPNOTSUPP;
}drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -1914,6 +2224,8 @@ xe_hwmon_write(struct device *dev, enum hwmon_sensor_types type, u32 attr, return xe_hwmon_power_write(hwmon, attr, channel, val);case
hwmon_curr:
returnxe_hwmon_curr_write(hwmon, attr, channel, val); + casehwmon_pwm:
+ returnxe_hwmon_pwm_write(hwmon, attr, channel, val); default:
return-EOPNOTSUPP;
}drivers/gpu/drm/xe/xe_pcode_api.h +3
-0@@ -86,9 +86,12 @@ #define MEMORY_CONFIG_SUBCOMMAND_READ_MAX_FREQUENCY 0x1 #define FAN_SPEED_CONTROL 0x7D +#define FSC_WRITE_NUM_FAN_CONTROL_POINTS 0x0 +#define FSC_WRITE_FAN_TABLE 0x1 #define FSC_READ_MAX_FAN_RPS 0x3 #define FSC_READ_NUM_FANS 0x4 #define FSC_READ_STOCK_FAN_CONTROL_POINTS 0x5 +#define FSC_READ_USER_FAN_CONTROL_POINTS 0x6 #define FSC_READ_FAN_TABLE 0x7 #define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0) #define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8)
PATCH v5 5/10 drm/xe/hwmon: Expose pwm[1-3]_enable
In reply to Karthik PoosaExpose pwm[1-3]_enable to control the fan operating mode through the hwmon interface.
Mode 0 forces the fan to run at full speed. Mode 1 enables user fan-table control.
Mode 2 restores firmware-controlled fan management.
Document pwm[1-3]_enable in the Xe hwmon ABI.
v2:
- Use xe helpers for dmesg logs.
- Update kernel version in Xe hwmon documentation.
- Correct level of some dmesg logs.
v3:
- Each pwm_enable mode now sets its own state; drop the redundant post-switch pwm_enable_mode/is_full_speed update. (Badal)
- Fix misindented dead assignment in the stock-table branch.
- Make error handling consistent across pwm_enable modes. (Badal)
- Document the pwm[1-3] manual-mode write precondition in the ABI. (Badal)
- Use xe_pcode_write() instead of the timeout variant api as it is not needed.
v4:
- Rebase on reworked pwm[1-3] patch.
- Clamp min PWM to 100% when activating the user table, since fan table speed is in percent.
- Drop redundant channel range check in pwm write.
- Use tab indentation and update Date and KernelVersion to November 2026 and 7.5 in the pwm[1-3]_enable ABI entry.
v5:
- Address review comments from sashiko.
- Avoid returning pwm[1-3]_enable as XE_FAN_PWM_MANUAL_USER_TABLE, when setting to full speed mode. (sashiko)
- Set default pwm[1-3]_enable to XE_FAN_PWM_AUTO_STOCK_TABLE after probe. (sashiko)
- Make pwm[1-3]_enable visible only if stock fan table has valid point count.
- Add flag XE_FAN_PWM_UNINITIALIZED.
- Verify user point counts after table activation and auto-mode writes.
- Fall back to the stock table if firmware does not accept a table.
--- .../ABI/testing/sysfs-driver-intel-xe-hwmon | 15 ++ drivers/gpu/drm/xe/xe_hwmon.c | 201 +++++++++++++++++- 2 files changed, 207 insertions(+), 9 deletions(-)
Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +15 -0
@@ -354,4 +354,19 @@ Contact: [email protected] Description: RW. Target fan PWM duty value in the range 0..255, where 255 is 100% fan speed. + Writing requires the corresponding pwm[1-3]_enable to be set to + 1 (manual user-table mode) first; otherwise the write is + rejected with -EINVAL. + + Only supported for particular Intel Xe graphics platforms. + +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/pwm[1-3]_enable +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: RW. Fan control mode selector. + + Use value 0 to run fans at full speed. Use value 1 to enable + user table control and value 2 to use firmware default behavior. + Only supported for particular Intel Xe graphics platforms.
drivers/gpu/drm/xe/xe_hwmon.c +192 -9
336 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/xe/hwmon: wrong pwm readback in xe_hwmon_pwm_read() for non-stock modes - [Medium]…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] drm/xe/hwmon: wrong pwm readback in xe_hwmon_pwm_read() for non-stock modes
- [Medium] drm/xe/hwmon: xe_hwmon_set_user_fan_pwm() clobbers user table in mode 0
- [Low] drm/xe/hwmon: missing point count check in xe_hwmon_fan_set_auto()
--
commit 562936f0b505f7da573995f262799f779e7aab25
Author: Karthik Poosa <[email protected]>
drm/xe/hwmon: Expose pwm[1-3]_enable
This commit exposes the pwm[1-3]_enable hwmon sysfs attributes to select between full-speed, manual user-table, and automatic firmware fan control modes, and documents them in the Xe hwmon ABI.
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0
[ ... ]
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1238
Quoted 11 lines
drivers/gpu/drm/xe/xe_hwmon.c +4
-1@@ -1209,9 +1230,88 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan)PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_NUM_FAN_CONTROL_POINTS , fan), 0);if (ret) -return ret; + goto fail; fi->fan_table[USER_FAN_TABLE ].point_count =0 ; + fi->pwm_enable_mode =XE_FAN_PWM_AUTO_STOCK_TABLE ; + fi->is_full_speed = false; +return 0 ;
[Severity: Low]
Should xe_hwmon_fan_set_auto() call xe_hwmon_get_fan_point_count() to verify that firmware cleared the user point count to 0 before marking XE_FAN_PWM_AUTO_STOCK_TABLE active? The v5 changelog notes that user point counts are verified after auto-mode writes as well as table activation, and both xe_hwmon_activate_user_fan_table() and xe_hwmon_set_user_fan_pwm() do this check.
[ ... ]
Quoted 43 lines
drivers/gpu/drm/xe/xe_hwmon.c +15
-4@@ -2054,12 +2168,20 @@ static int xe_hwmon_get_pwm_from_pmt(struct xe_hwmon *hwmon, int channel, long *return -EOPNOTSUPP ; } -xe_dbg (hwmon->xe,"fan %d PMT active PWM value: %u\n" , channel, pwm); +xe_dbg (hwmon->xe,"fan %d: active pwm from PMT: %u\n" , channel, pwm); *val = pwm;return 0 ; } +static enum fan_table_type xe_hwmon_get_active_fan_table (struct xe_hwmon *hwmon,u8 fan) +{ +if (hwmon->fi[fan].pwm_enable_mode ==XE_FAN_PWM_AUTO_STOCK_TABLE ) +return STOCK_FAN_TABLE ; +else +return USER_FAN_TABLE ; +} +static int xe_hwmon_pwm_read (struct xe_hwmon *hwmon,u32 attr,int channel,long *val) {@@ -2074,8 +2196,9 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)switch (attr) {case hwmon_pwm_input:/* If the user fan table is not populated, get active stock pwm */ -if (!fi->fan_table[USER_FAN_TABLE ].point_count) { -xe_dbg (hwmon->xe,"user fan table not active for fan %d\n" , channel); +if (xe_hwmon_get_active_fan_table (hwmon, channel) ==STOCK_FAN_TABLE ) { +xe_dbg (hwmon->xe,"getting active pwm for fan %d from stock table\n" , + channel);switch (hwmon->xe->info.platform) {case XE_BATTLEMAGE : ret =xe_hwmon_get_pwm_from_pmt (hwmon, channel, &pwm);@@ -2084,13 +2207,18 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) ret =xe_hwmon_get_stock_table_pwm (hwmon, channel, &pwm);break ; } -if (ret) +if (ret) { +xe_err (hwmon->xe,"failed to get active pwm for fan %d, ret=%d\n" , + channel, ret); goto unlock;
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) · line 2223
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +3
-0+ } }else {/* * pwmN writes set every user-table point to the same speed, * so the first point gives the cached manual PWM percentage. */ +xe_dbg (hwmon->xe,"getting active pwm for fan %d from user table cache\n" , + channel); pwm = fi->fan_table[USER_FAN_TABLE ].fcp[0 ].speed; }
[Severity: Medium]
Can reading hwmon_pwm_input return the wrong PWM duty value when pwm_enable_mode is not XE_FAN_PWM_AUTO_STOCK_TABLE?
When pwm[1-3]_enable is switched from 2 to 1 before any flat write to pwm[1-3], xe_hwmon_activate_user_fan_table() populates USER_FAN_TABLE from STOCK_FAN_TABLE with a multi-point temperature curve. In that state the points in USER_FAN_TABLE do not share a single speed, so reading fi->fan_table[USER_FAN_TABLE].fcp[0].speed always reports the lowest temperature breakpoint speed instead of reading PMT on Battlemage or interpolating the active table against package temperature.
In addition, xe_hwmon_get_active_fan_table() returns USER_FAN_TABLE when fi->pwm_enable_mode is XE_FAN_PWM_UNINITIALIZED. If a mode transition and its xe_hwmon_fan_set_auto() fallback fail after clearing fi->fan_table[USER_FAN_TABLE].point_count to 0, reading pwm[1-3] returns stale or zero fcp[0].speed instead of -ENODATA.
[ ... ]
Quoted 17 lines
drivers/gpu/drm/xe/xe_hwmon.c +12
-1@@ -2125,7 +2263,48 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) ret = -EINVAL ;break ; } - ret =xe_hwmon_set_user_fan_pwm (hwmon, channel, (u8 )val); + ret =xe_hwmon_set_user_fan_pwm (hwmon, channel, (u8 )val, false); +break ; +case hwmon_pwm_enable: +if (val ==XE_FAN_PWM_FULL_SPEED ) { + ret =xe_hwmon_set_user_fan_pwm (hwmon, channel,U8_MAX , true); +if (ret) { +xe_warn (hwmon->xe, +"full speed enable for fan %d failed, ret=%d\n" , + channel, ret); +break ; + } + }else if (val ==XE_FAN_PWM_MANUAL_USER_TABLE ) {
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) · line 2287
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+enum fan_table_type source = fi->fan_table[USER_FAN_TABLE ].point_count ? +USER_FAN_TABLE :STOCK_FAN_TABLE ; + +/* +* Manual fan speed control using user fan table. +* If user fan table is not programmed, it would be initialized with +* clamped stock points which allows manual control with some +* default points. +*/ + ret =xe_hwmon_activate_user_fan_table (hwmon, channel, false, source);
[Severity: Medium]
Does setting pwm[1-3]_enable to 0 (XE_FAN_PWM_FULL_SPEED) overwrite fi->fan_table[USER_FAN_TABLE] and leave the fan pinned at 100% when subsequently switching to mode 1 (XE_FAN_PWM_MANUAL_USER_TABLE)?
Calling xe_hwmon_set_user_fan_pwm(hwmon, channel, U8_MAX, true) replaces fi->fan_table[USER_FAN_TABLE].fcp[0..1] with 100% speed points and sets fi->fan_table[USER_FAN_TABLE].point_count to MIN_FAN_CONTROL_POINTS. When userspace later writes 1 to pwm[1-3]_enable, point_count is non-zero, so source becomes USER_FAN_TABLE instead of STOCK_FAN_TABLE (or any previously configured user table) and xe_hwmon_activate_user_fan_table() re-applies the 100% full-speed table.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v5 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable
Quoted 44 lines · On 28-11-2026 11:43, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] drm/xe/hwmon: wrong pwm readback inxe_hwmon_pwm_read()for non-stock modes
- [Medium] drm/xe/hwmon:xe_hwmon_set_user_fan_pwm()clobbers user table in mode 0
- [Low] drm/xe/hwmon: missing point count check inxe_hwmon_fan_set_auto()
--commit
562936f0b505f7da573995f262799f779e7aab25
Author: Karthik Poosa <[email protected]>drm/xe/hwmon: Expose pwm[1-3]_enable
This commit exposes the pwm[1-3]_enable hwmon sysfs attributes to select between full-speed, manual user-table, and automatic firmware fan control modes, and documents them in the Xe hwmon ABI.
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0[ ... ]
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1238
Quoted 11 lines
drivers/gpu/drm/xe/xe_hwmon.c +4
-1@@ -1209,9 +1230,88 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan)PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_NUM_FAN_CONTROL_POINTS , fan), 0);if (ret) -return ret; + goto fail; fi->fan_table[USER_FAN_TABLE ].point_count =0 ; + fi->pwm_enable_mode =XE_FAN_PWM_AUTO_STOCK_TABLE ; + fi->is_full_speed = false; +return 0 ;[Severity: Low]
Shouldxe_hwmon_fan_set_auto()callxe_hwmon_get_fan_point_count()to verify that firmware cleared the user point count to 0 before markingXE_FAN_PWM_AUTO_STOCK_TABLEactive? The v5 changelog notes that user point counts are verified after auto-mode writes as well as table activation, and bothxe_hwmon_activate_user_fan_table()andxe_hwmon_set_user_fan_pwm()do this check.
Quoted 1 line
[ ... ]
Changed will be updated, I've initally added then removed as
it was not necessary, A successful return of setting user point to 0 is enough.
Quoted 58 lines
Quoted 44 lines
drivers/gpu/drm/xe/xe_hwmon.c +15
-4@@ -2054,12 +2168,20 @@ static int xe_hwmon_get_pwm_from_pmt(struct xe_hwmon *hwmon, int channel, long *return -EOPNOTSUPP ; } -xe_dbg (hwmon->xe,"fan %d PMT active PWM value: %u\n" , channel, pwm); +xe_dbg (hwmon->xe,"fan %d: active pwm from PMT: %u\n" , channel, pwm); *val = pwm;return 0 ; } +static enum fan_table_type xe_hwmon_get_active_fan_table (struct xe_hwmon *hwmon,u8 fan) +{ +if (hwmon->fi[fan].pwm_enable_mode ==XE_FAN_PWM_AUTO_STOCK_TABLE ) +return STOCK_FAN_TABLE ; +else +return USER_FAN_TABLE ; +} +static int xe_hwmon_pwm_read (struct xe_hwmon *hwmon,u32 attr,int channel,long *val) {@@ -2074,8 +2196,9 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)switch (attr) {case hwmon_pwm_input:/* If the user fan table is not populated, get active stock pwm */ -if (!fi->fan_table[USER_FAN_TABLE ].point_count) { -xe_dbg (hwmon->xe,"user fan table not active for fan %d\n" , channel); +if (xe_hwmon_get_active_fan_table (hwmon, channel) ==STOCK_FAN_TABLE ) { +xe_dbg (hwmon->xe,"getting active pwm for fan %d from stock table\n" , + channel);switch (hwmon->xe->info.platform) {case XE_BATTLEMAGE : ret =xe_hwmon_get_pwm_from_pmt (hwmon, channel, &pwm);@@ -2084,13 +2207,18 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) ret =xe_hwmon_get_stock_table_pwm (hwmon, channel, &pwm);break ; } -if (ret) +if (ret) { +xe_err (hwmon->xe,"failed to get active pwm for fan %d, ret=%d\n" , + channel, ret); goto unlock;drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) · line 2223
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +3
-0+ } }else {/* * pwmN writes set every user-table point to the same speed, * so the first point gives the cached manual PWM percentage. */ +xe_dbg (hwmon->xe,"getting active pwm for fan %d from user table cache\n" , + channel); pwm = fi->fan_table[USER_FAN_TABLE ].fcp[0 ].speed; }[Severity: Medium]
Can readinghwmon_pwm_inputreturn the wrong PWM duty value whenpwm_enable_modeis notXE_FAN_PWM_AUTO_STOCK_TABLE?
Quoted 7 lines
When pwm[1-3]_enable is switched from 2 to 1 before any flat write to pwm[1-3],
xe_hwmon_activate_user_fan_table()populatesUSER_FAN_TABLEfromSTOCK_FAN_TABLEwith a multi-point temperature curve. In that state the points inUSER_FAN_TABLEdo not share a single speed, so reading fi->fan_table[USER_FAN_TABLE].fcp[0].speed always reports the lowest temperature breakpoint speed instead of reading PMT on Battlemage or interpolating the active table against package temperature.
okay, we can return active pwm, that fan curve is not flat.
Quoted 8 lines
In addition,
xe_hwmon_get_active_fan_table()returnsUSER_FAN_TABLEwhenfi->pwm_enable_modeisXE_FAN_PWM_UNINITIALIZED. If a mode transition and itsxe_hwmon_fan_set_auto()fallback fail after clearing fi->fan_table[USER_FAN_TABLE].point_count to 0, reading pwm[1-3] returns stale or zero fcp[0].speed instead of-ENODATA.[ ... ]
okay, XE_FAN_PWM_UNINITIALIZED state shall be added.
Quoted 23 lines
Quoted 23 lines
drivers/gpu/drm/xe/xe_hwmon.c +18
-1@@ -2125,7 +2263,48 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) ret = -EINVAL ;break ; } - ret =xe_hwmon_set_user_fan_pwm (hwmon, channel, (u8 )val); + ret =xe_hwmon_set_user_fan_pwm (hwmon, channel, (u8 )val, false); +break ; +case hwmon_pwm_enable: +if (val ==XE_FAN_PWM_FULL_SPEED ) { + ret =xe_hwmon_set_user_fan_pwm (hwmon, channel,U8_MAX , true); +if (ret) { +xe_warn (hwmon->xe, +"full speed enable for fan %d failed, ret=%d\n" , + channel, ret); +break ; + } + }else if (val ==XE_FAN_PWM_MANUAL_USER_TABLE ) { +enum fan_table_type source = fi->fan_table[USER_FAN_TABLE ].point_count ? +USER_FAN_TABLE :STOCK_FAN_TABLE ; + +/* +* Manual fan speed control using user fan table. +* If user fan table is not programmed, it would be initialized with
Quoted 8 lines
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) · line 2297
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +4
-0+* clamped stock points which allows manual control with some +* default points. +*/ + ret =xe_hwmon_activate_user_fan_table (hwmon, channel, false, source);[Severity: Medium]
Does setting pwm[1-3]_enable to 0 (XE_FAN_PWM_FULL_SPEED) overwrite fi->fan_table[USER_FAN_TABLE] and leave the fan pinned at 100% when subsequently switching to mode 1 (XE_FAN_PWM_MANUAL_USER_TABLE)?
yes, after switching to mode 1, user is expected to set the fan curve through fixed pwm ie. using pwmF or through fan curve points ie. pwmF_auto_pointX_temp or pwmF_auto_pointX_pwm
Quoted 7 lines
Calling
xe_hwmon_set_user_fan_pwm(hwmon, channel, U8_MAX, true)replaces fi->fan_table[USER_FAN_TABLE].fcp[0..1] with 100% speed points and sets fi->fan_table[USER_FAN_TABLE].point_count toMIN_FAN_CONTROL_POINTS. When userspace later writes 1 to pwm[1-3]_enable,point_countis non-zero, so source becomesUSER_FAN_TABLEinstead ofSTOCK_FAN_TABLE(or any previously configured user table) andxe_hwmon_activate_user_fan_table()re-applies the 100% full-speed table.
yes. Xe is not storing the table between the pwm1_enable mode switches. It shall be done by the UMD above it.
Re: [PATCH v5 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable
Quoted 179 lines · Karthik
Quoted 45 lines · On 28-11-2026 11:43, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] drm/xe/hwmon: wrong pwm readback inxe_hwmon_pwm_read()for non-stock modes
- [Medium] drm/xe/hwmon:xe_hwmon_set_user_fan_pwm()clobbers user table in mode 0
- [Low] drm/xe/hwmon: missing point count check inxe_hwmon_fan_set_auto()Signature · 8 lines
commit 562936f0b505f7da573995f262799f779e7aab25 Author: Karthik Poosa <[email protected]> drm/xe/hwmon: Expose pwm[1-3]_enable This commit exposes the pwm[1-3]_enable hwmon sysfs attributes to select between full-speed, manual user-table, and automatic firmware fan control modes, and documents them in the Xe hwmon ABI.Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0[ ... ]
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct · line 1238
Quoted 11 lines
drivers/gpu/drm/xe/xe_hwmon.c +4
-1@@ -1209,9 +1230,88 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, fan), 0); if (ret) - return ret; + goto fail; fi->fan_table[USER_FAN_TABLE].point_count = 0; + fi->pwm_enable_mode = XE_FAN_PWM_AUTO_STOCK_TABLE; + fi->is_full_speed = false; + return 0;[Severity: Low]
Shouldxe_hwmon_fan_set_auto()callxe_hwmon_get_fan_point_count()to verify that firmware cleared the user point count to 0 before markingXE_FAN_PWM_AUTO_STOCK_TABLEactive? The v5 changelog notes that user point counts are verified after auto-mode writes as well as table activation, and bothxe_hwmon_activate_user_fan_table()andxe_hwmon_set_user_fan_pwm()do this check.[ ... ]
Changed will be updated, I've initally added then removed as
it was not necessary, A successful return of setting user point to 0 is enough.
Quoted 64 lines
Quoted 58 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -2054,12 +2168,20 @@ static int xe_hwmon_get_pwm_from_pmt(struct
xe_hwmon*hwmon, int channel, long *
return-EOPNOTSUPP;
}
-xe_dbg(hwmon->xe, "fan %d PMT active PWM value: %u\n", channel, pwm); + xe_dbg(hwmon->xe, "fan %d: active pwm from PMT: %u\n", channel,
pwm);
*val = pwm;
return 0;
}
+static enumfan_table_typexe_hwmon_get_active_fan_table(struct xe_hwmon *hwmon, u8 fan)drivers/gpu/drm/xe/xe_hwmon.c +7
-0+{ + if (hwmon->fi[fan].pwm_enable_mode == XE_FAN_PWM_AUTO_STOCK_TABLE) + return STOCK_FAN_TABLE; + else + return USER_FAN_TABLE; +} +static int
xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val){drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -2074,8 +2196,9 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) switch (attr) {case
hwmon_pwm_input:
/* If the user fan table is not populated, get active stock pwm */ - if (!fi->fan_table[USER_FAN_TABLE].point_count) {
-xe_dbg(hwmon->xe, "user fan table not active for fan %d\n", channel);
+ if (xe_hwmon_get_active_fan_table(hwmon, channel)==STOCK_FAN_TABLE) {
+ xe_dbg(hwmon->xe, "getting active pwm for fan %d from stock table\n",
+ channel);
switch (hwmon->xe->info.platform) {
caseXE_BATTLEMAGE:
ret =xe_hwmon_get_pwm_from_pmt(hwmon, channel, &pwm);drivers/gpu/drm/xe/xe_hwmon.c +6
-1@@ -2084,13 +2207,18 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) ret = xe_hwmon_get_stock_table_pwm(hwmon, channel, &pwm); break; } - if (ret) + if (ret) { + xe_err(hwmon->xe, "failed to get active pwm for fan %d, ret=%d\n", + channel, ret); goto unlock; + } } else { /* * pwmN writes set every user-table point to the same speed, * so the first point gives the cached manual PWM percentage. */ + xe_dbg(hwmon->xe, "getting active pwm for fan %d from user table cache\n", + channel);Quoted 2 lines
pwm = fi->fan_table[USER_FAN_TABLE].fcp[0].speed; }
[Severity: Medium]
Can readinghwmon_pwm_inputreturn the wrong PWM duty value whenpwm_enable_modeis notXE_FAN_PWM_AUTO_STOCK_TABLE?Quoted 7 lines
When pwm[1-3]_enable is switched from 2 to 1 before any flat write to pwm[1-3],
xe_hwmon_activate_user_fan_table()populatesUSER_FAN_TABLEfromSTOCK_FAN_TABLEwith a multi-point temperature curve. In that state the points inUSER_FAN_TABLEdo not share a single speed, so reading fi->fan_table[USER_FAN_TABLE].fcp[0].speed always reports the lowest temperature breakpoint speed instead of reading PMT on Battlemage or interpolating the active table against package temperature.okay, we can return active pwm, that fan curve is not flat.
Quoted 8 lines
In addition,
xe_hwmon_get_active_fan_table()returnsUSER_FAN_TABLEwhenfi->pwm_enable_modeis XE_FAN_PWM_UNINITIALIZED. If a mode transition and itsxe_hwmon_fan_set_auto()fallback fail after clearing fi->fan_table[USER_FAN_TABLE].point_count to 0, reading pwm[1-3] returns stale or zero fcp[0].speed instead of-ENODATA.[ ... ]
okay,
XE_FAN_PWM_UNINITIALIZEDstate shall be added.Quoted 30 lines
Quoted 30 lines
drivers/gpu/drm/xe/xe_hwmon.c +13
-1@@ -2125,7 +2263,48 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) ret = -EINVAL; break; } - ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val); + ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val, false); + break; + case hwmon_pwm_enable: + if (val == XE_FAN_PWM_FULL_SPEED) { + ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, U8_MAX, true); + if (ret) { + xe_warn(hwmon->xe, + "full speed enable for fan %d failed, ret=%d\n", + channel, ret); + break; + } + } else if (val == XE_FAN_PWM_MANUAL_USER_TABLE) { + enum fan_table_type source =fi->fan_table[USER_FAN_TABLE].point_count ?
+USER_FAN_TABLE:STOCK_FAN_TABLE;
+
+ /*
+ * Manual fan speed control using user fan table. + * If user fan table is not programmed, it would be initialized with
+ * clamped stock points which allows manual control with someQuoted 8 lines
Quoted 4 lines
+ * default points.
+ */
+ ret =xe_hwmon_activate_user_fan_table(hwmon, channel, false, source);[Severity: Medium]
Does setting pwm[1-3]_enable to 0 (XE_FAN_PWM_FULL_SPEED) overwrite fi->fan_table[USER_FAN_TABLE] and leave the fan pinned at 100% when subsequently switching to mode 1 (XE_FAN_PWM_MANUAL_USER_TABLE)?yes, after switching to mode 1, user is expected to set the fan curve through fixed pwm ie. using pwmF or through fan curve points ie.
pwmF_auto_pointX_temporpwmF_auto_pointX_pwmQuoted 7 lines
Calling
xe_hwmon_set_user_fan_pwm(hwmon, channel, U8_MAX, true)replaces fi->fan_table[USER_FAN_TABLE].fcp[0..1] with 100% speed points and sets fi->fan_table[USER_FAN_TABLE].point_count to MIN_FAN_CONTROL_POINTS. When userspace later writes 1 to pwm[1-3]_enable,point_countis non-zero, so source becomesUSER_FAN_TABLEinstead ofSTOCK_FAN_TABLE(or any previously configured user table) andxe_hwmon_activate_user_fan_table()re-applies the 100% full-speed table.
Quoted 2 lines
yes. Xe is not storing the table between the
pwm1_enablemode switches. It shall be done by the UMD above it.
on a second look, I think we could use xe_hwmon_activate_user_fan_table() to avoid overwriting the user table cache.
Re: [PATCH v5 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable
In reply to Karthik PoosaHi Karthik,
Quoted 80 lines · Karthik Poosa
Expose pwm[1-3]_enable to control the fan operating mode through the hwmon interface.
Mode 0 forces the fan to run at full speed. Mode 1 enables user fan-table control.
Mode 2 restores firmware-controlled fan management.Document pwm[1-3]_enable in the Xe hwmon ABI.
v2:
- Use xe helpers for dmesg logs.
- Update kernel version in Xe hwmon documentation.
- Correct level of some dmesg logs.v3:
- Eachpwm_enablemode now sets its own state; drop the redundant post-switch pwm_enable_mode/is_full_speed update. (Badal)
- Fix misindented dead assignment in the stock-table branch.
- Make error handling consistent acrosspwm_enablemodes. (Badal)
- Document the pwm[1-3] manual-mode write precondition in the ABI. (Badal)
- Usexe_pcode_write()instead of the timeout variant api as it is not needed.v4:
- Rebase on reworked pwm[1-3] patch.
- Clamp min PWM to 100% when activating the user table, since fan table speed is in percent.
- Drop redundant channel range check in pwm write.
- Use tab indentation and update Date and KernelVersion to November2026 and 7.5 in the pwm[1-3]_enable ABI entry.v5:
- Address review comments from sashiko.
- Avoid returning pwm[1-3]_enable asXE_FAN_PWM_MANUAL_USER_TABLE, when setting to full speed mode. (sashiko)
- Set default pwm[1-3]_enable toXE_FAN_PWM_AUTO_STOCK_TABLEafter probe. (sashiko)
- Make pwm[1-3]_enable visible only if stock fan table has valid point count.
- Add flagXE_FAN_PWM_UNINITIALIZED.
- Verify user point counts after table activation and auto-mode writes.
- Fall back to the stock table if firmware does not accept a table.Signed-off-by Karthik Poosa <[email protected]>--- .../ABI/testing/sysfs-driver-intel-xe-hwmon | 15 ++ drivers/gpu/drm/xe/xe_hwmon.c | 201 +++++++++++++++++- 2 files changed, 207 insertions(+), 9 deletions(-)Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +15
-0@@ -354,4 +354,19 @@ Contact: [email protected] Description: RW. Target fan PWM duty value in the range 0..255, where 255 is 100% fan speed. + Writing requires the corresponding pwm[1-3]_enable to be set to + 1 (manual user-table mode) first; otherwise the write is + rejected with -EINVAL. + + Only supported for particular Intel Xe graphics platforms. + +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon<i>/pwm[1-3]_enable +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: RW. Fan control mode selector. + + Use value 0 to run fans at full speed. Use value 1 to enable + user table control and value 2 to use firmware default behavior. + Only supported for particular Intel Xe graphics platforms.drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -139,6 +139,20 @@ struct xe_hwmon_energy_info {long accum_energy; };
drivers/gpu/drm/xe/xe_hwmon.c struct xe_hwmon_energy_info { · line 150
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +9
-0+/** +* enum xe_fan_pwm_enable_mode - fan PWM enable modes +*/ +enum xe_fan_pwm_enable_mode { +/** @XE_FAN_PWM_FULL_SPEED: force all user table points to full speed */ +XE_FAN_PWM_FULL_SPEED =0 , +/** @XE_FAN_PWM_MANUAL_USER_TABLE: use the driver-managed user table */ +XE_FAN_PWM_MANUAL_USER_TABLE =1 , +/** @XE_FAN_PWM_AUTO_STOCK_TABLE: use the firmware stock table */
The wording still differs from the ABI doc ("full speed", "user table control", "firmware default behavior"). Could it be aligned ?
Quoted 9 lines
drivers/gpu/drm/xe/xe_hwmon.c +5
-0+XE_FAN_PWM_AUTO_STOCK_TABLE =2 , +/** @XE_FAN_PWM_UNINITIALIZED: fan control mode is not established */ + XE_FAN_PWM_UNINITIALIZED = 0xff, +}; +/** * enum fan_table_type - fan table types tracked per fan */
drivers/gpu/drm/xe/xe_hwmon.c struct xe_hwmon_fan_info { · line 210
Quoted 7 lines
drivers/gpu/drm/xe/xe_hwmon.c +4
-0@@ -190,6 +204,10 @@ struct xe_hwmon_fan_info { } fan_table[FAN_TABLE_MAX ];/** @max_rps: maximum fan RPS */ u32 max_rps; +/** @pwm_enable_mode: current xe_fan_pwm_enable_mode */ +u8 pwm_enable_mode; +/** @is_full_speed: flag indicating if fan is in full speed */ +bool is_full_speed;
Does it only store the value of (pwm_enable_mode == XE_FAN_PWM_FULL_SPEED) ?
Quoted 38 lines
drivers/gpu/drm/xe/xe_hwmon.c +13
-2};/** @@ -926,7 +944,9 @@ static const struct hwmon_channel_info * const hwmon_info[] = {HWMON_CHANNEL_INFO (energy,HWMON_E_INPUT |HWMON_E_LABEL ,HWMON_E_INPUT |HWMON_E_LABEL ),HWMON_CHANNEL_INFO (fan,HWMON_F_INPUT |HWMON_F_MAX ,HWMON_F_INPUT |HWMON_F_MAX ,HWMON_F_INPUT |HWMON_F_MAX ), -HWMON_CHANNEL_INFO (pwm,HWMON_PWM_INPUT ,HWMON_PWM_INPUT ,HWMON_PWM_INPUT ), +HWMON_CHANNEL_INFO (pwm,HWMON_PWM_INPUT |HWMON_PWM_ENABLE , +HWMON_PWM_INPUT |HWMON_PWM_ENABLE , +HWMON_PWM_INPUT |HWMON_PWM_ENABLE ), NULL };@@ -1176,6 +1196,7 @@ static int xe_hwmon_get_fan_point_count(struct xe_hwmon *hwmon, u8 fan, u32 *poi {int ret; + *point_count =0 ; ret = xe_hwmon_pcode_read_fan_control(hwmon, (table_type == USER_FAN_TABLE) ? FSC_READ_USER_FAN_CONTROL_POINTS :@@ -1211,9 +1232,88 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan)PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_NUM_FAN_CONTROL_POINTS , fan), 0);if (ret) -return ret; + goto fail; fi->fan_table[USER_FAN_TABLE ].point_count =0 ; + fi->pwm_enable_mode =XE_FAN_PWM_AUTO_STOCK_TABLE ; + fi->is_full_speed = false; +return 0 ; + +fail: + fi->pwm_enable_mode =XE_FAN_PWM_UNINITIALIZED ; + fi->is_full_speed = false; +return ret;
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1255
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+} + +static int xe_hwmon_activate_user_fan_table (struct xe_hwmon *hwmon,u8 fan, +bool is_full_speed,enum fan_table_type table_source) +{ +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +struct xe_pcode_write writes[MAX_FAN_CONTROL_POINTS +1 ]; +u32 expected_count, point_count; +int ret, write_ret, verify_ret; +int point;
Could point be u32, to match point_count?
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1256
Quoted 1 line
drivers/gpu/drm/xe/xe_hwmon.c +1
-0+struct fan_table *source_table = &fi->fan_table[table_source];
Reverse xmas tree order is still not followed, as noted in v3.
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1264
Quoted 8 lines
drivers/gpu/drm/xe/xe_hwmon.c +8
-0+ +xe_dbg (hwmon->xe,"activating fan %d user table from %s table\n" , fan, + (table_source ==USER_FAN_TABLE ) ?"user" :"stock" ); + + point_count = source_table->point_count; +if (!point_count || point_count >MAX_FAN_CONTROL_POINTS ) { + xe_err(hwmon->xe, + "fan %d %s table point count %d is invalid, cannot activate user table\n",
Nit: point_count is u32, so should %u be used?
Quoted 13 lines
drivers/gpu/drm/xe/xe_hwmon.c +13
-0+ fan, (table_source == USER_FAN_TABLE) ? "user" : "stock", point_count); +return -EINVAL ; + } + expected_count = point_count; + +for (point =0 ; point < point_count; point++) { +u8 temp = source_table->fcp[point].temp; +u8 speed = is_full_speed ?100 :min_t (u8, source_table->fcp[point].speed,100 ); + + writes[point].mbox =PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_FAN_TABLE , fan); + writes[point].data =FIELD_PREP (FAN_CONTROL_POINT_TEMP_MASK , temp) | +FIELD_PREP (FAN_CONTROL_POINT_SPEED_MASK , speed); + }
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1287
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+ + writes[point_count].mbox =PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_NUM_FAN_CONTROL_POINTS , + fan); + writes[point_count].data = point_count; + write_ret =xe_pcode_write_batch (xe_device_get_root_tile (hwmon->xe), writes, + point_count +1 ); +if (write_ret) +xe_dbg (hwmon->xe,"failed to write fan %d user table, ret=%d\n" , fan, write_ret); + + verify_ret =xe_hwmon_get_fan_point_count (hwmon, fan, &point_count,USER_FAN_TABLE );
The write/verify/fallback sequence is still repeated in xe_hwmon_set_user_fan_pwm() and xe_hwmon_commit_user_fan_table() as noted in v3. A shared helper might be helpful ?
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1294
Quoted 7 lines
drivers/gpu/drm/xe/xe_hwmon.c +7
-0+if (write_ret || verify_ret || point_count != expected_count) { +int failure_ret = write_ret ?: verify_ret ?: -EIO ; + + fi->fan_table[USER_FAN_TABLE ].point_count =0 ; +if (verify_ret || point_count != expected_count) + xe_err(hwmon->xe, + "fan %d user table count misatch: ret=%d, expected=%u, got=%u\n",
Typo: "misatch" should be "mismatch".
Quoted 26 lines
drivers/gpu/drm/xe/xe_hwmon.c +22
-0+ fan, verify_ret, expected_count, point_count); + ret =xe_hwmon_fan_set_auto (hwmon, fan); +if (ret) +xe_err (hwmon->xe,"failed to restore fan %d to stock mode, ret=%d\n" , fan, + ret); +return failure_ret; + } + +if (table_source ==STOCK_FAN_TABLE ) { +for (point =0 ; point < point_count; point++) { + fi->fan_table[USER_FAN_TABLE ].fcp[point].temp = + source_table->fcp[point].temp; + fi->fan_table[USER_FAN_TABLE ].fcp[point].speed = + is_full_speed ?100 :min_t (u8, source_table->fcp[point].speed, +100 ); + } + } + + fi->fan_table[USER_FAN_TABLE ].point_count = point_count; + fi->pwm_enable_mode = is_full_speed ?XE_FAN_PWM_FULL_SPEED : +XE_FAN_PWM_MANUAL_USER_TABLE ; + fi->is_full_speed = is_full_speed;return 0 ; }
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) · line 1324
Quoted 5 lines
drivers/gpu/drm/xe/xe_hwmon.c +1
-1@@ -1221,7 +1321,7 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan)/* Temperature to set when setting the fan PWM with pwm[1-3]. */ #define FIXED_PWM_TEMP 1 -static int xe_hwmon_set_user_fan_pwm (struct xe_hwmon *hwmon,u8 fan,u8 pwm) +static int xe_hwmon_set_user_fan_pwm (struct xe_hwmon *hwmon,u8 fan,u8 pwm,bool full_speed)
In v3 it was agreed to use is_full_speed, but full_speed is still used here.
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) · line 1335
Quoted 11 lines
drivers/gpu/drm/xe/xe_hwmon.c +4
-0{struct xe_pcode_write writes[MIN_FAN_CONTROL_POINTS +1 ];struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];@@ -1229,6 +1329,11 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm)u32 point_count =0 ;u8 speed; +if (!full_speed && fi->pwm_enable_mode !=XE_FAN_PWM_MANUAL_USER_TABLE ) { +xe_dbg (hwmon->xe,"fan %d manual mode is not active, cannot set pwm\n" , fan); +return -EINVAL ; + }
The default mode after probe is AUTO, so pwmN writes that worked before are now rejected until pwmN_enable=1. Is this ABI change intended? If so, could it be noted in the commit message?
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) · line 1389
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +3
-0+/* Fan table speed are in percent. */ speed =DIV_ROUND_CLOSEST (pwm *100 ,U8_MAX ); speed =min_t (u32, speed,100 );@@ -1280,6 +1385,9 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) } fi->fan_table[USER_FAN_TABLE ].point_count =MIN_FAN_CONTROL_POINTS ; + fi->pwm_enable_mode = full_speed ?XE_FAN_PWM_FULL_SPEED : +XE_FAN_PWM_MANUAL_USER_TABLE ;
Mode 0 overwrites the user table cache with 2 points at 100%. When mode 1 is selected after that, USER_FAN_TABLE is used as the source, so the fan seems to stay at full speed and the earlier user curve is lost. Is this intended?
Quoted 47 lines
drivers/gpu/drm/xe/xe_hwmon.c +6
-0+ fi->is_full_speed = full_speed;return 0 ; }@@ -1299,6 +1407,9 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)if (!IS_FAN_ENABLED (hwmon, fan))continue ; + fi->pwm_enable_mode =XE_FAN_PWM_UNINITIALIZED ; + fi->fan_table[STOCK_FAN_TABLE ].point_count =0 ; + ret =xe_hwmon_pcode_read_fan_control (hwmon,FSC_READ_MAX_FAN_RPS , fan, &fi->max_rps);if (ret) {@@ -1352,6 +1463,8 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)memcpy (fi->fan_table[STOCK_FAN_TABLE ].fcp, stock_fcp, stock_fcp_count *sizeof (stock_fcp[0 ])); fi->fan_table[STOCK_FAN_TABLE ].point_count = stock_fcp_count; +if (fi->pwm_enable_mode ==XE_FAN_PWM_UNINITIALIZED ) + fi->pwm_enable_mode =XE_FAN_PWM_AUTO_STOCK_TABLE ; }return err;}drivers/gpu/drm/xe/xe_hwmon.c +3
-2@@ -1913,6 +2026,7 @@ xe_hwmon_pwm_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)switch (attr) {case hwmon_pwm_input: +case hwmon_pwm_enable:return 0644 ;default :return 0 ;@@ -2018,7 +2132,7 @@ static int xe_hwmon_get_stock_table_pwm(struct xe_hwmon *hwmon, int channel, lon } *val = pwm; -xe_dbg (hwmon->xe,"fan %d stock table active PWM value: %ld\n" , channel, pwm); +xe_dbg (hwmon->xe,"fan %d: active pwm value from stock table cache: %ld\n" , channel, pwm);return 0 ; }@@ -2064,12 +2178,20 @@ static int xe_hwmon_get_pwm_from_pmt(struct xe_hwmon *hwmon, int channel, long *return -EOPNOTSUPP ; } -xe_dbg (hwmon->xe,"fan %d PMT active PWM value: %u\n" , channel, pwm); +xe_dbg (hwmon->xe,"fan %d: active pwm from PMT: %u\n" , channel, pwm);
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_get_pwm_from_pmt(struct xe_hwmon *hwmon, int channel, long * · line 2191
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +5
-0*val = pwm;return 0 ; } +static enum fan_table_type xe_hwmon_get_active_fan_table (struct xe_hwmon *hwmon,u8 fan) +{ +if (hwmon->fi[fan].pwm_enable_mode ==XE_FAN_PWM_AUTO_STOCK_TABLE ) +return STOCK_FAN_TABLE ; +else
Nit: the else after return is not needed.
Quoted 100 lines
drivers/gpu/drm/xe/xe_hwmon.c +53
-4+return USER_FAN_TABLE ; +} +static int xe_hwmon_pwm_read (struct xe_hwmon *hwmon,u32 attr,int channel,long *val) {@@ -2084,8 +2206,9 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)switch (attr) {case hwmon_pwm_input:/* If the user fan table is not populated, get active stock pwm */ -if (!fi->fan_table[USER_FAN_TABLE ].point_count) { -xe_dbg (hwmon->xe,"user fan table not active for fan %d\n" , channel); +if (xe_hwmon_get_active_fan_table (hwmon, channel) ==STOCK_FAN_TABLE ) { +xe_dbg (hwmon->xe,"getting active pwm for fan %d from stock table\n" , + channel);switch (hwmon->xe->info.platform) {case XE_BATTLEMAGE : ret =xe_hwmon_get_pwm_from_pmt (hwmon, channel, &pwm);@@ -2094,13 +2217,18 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) ret =xe_hwmon_get_stock_table_pwm (hwmon, channel, &pwm);break ; } -if (ret) +if (ret) { +xe_err (hwmon->xe,"failed to get active pwm for fan %d, ret=%d\n" , + channel, ret); goto unlock; + } }else {/* * pwmN writes set every user-table point to the same speed, * so the first point gives the cached manual PWM percentage. */ +xe_dbg (hwmon->xe,"getting active pwm for fan %d from user table cache\n" , + channel); pwm = fi->fan_table[USER_FAN_TABLE ].fcp[0 ].speed; }if (pwm <0 || pwm >100 ) {@@ -2112,6 +2240,13 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) *val =DIV_ROUND_CLOSEST (pwm *U8_MAX ,100 );xe_dbg (hwmon->xe,"pwm read for fan %d: %ld\n" , channel, *val);break ; +case hwmon_pwm_enable: +if (fi->pwm_enable_mode ==XE_FAN_PWM_UNINITIALIZED ) { + ret = -ENODATA ; +break ; + } + *val = fi->is_full_speed ?XE_FAN_PWM_FULL_SPEED : fi->pwm_enable_mode; +break ;default : ret = -EOPNOTSUPP ;break ;@@ -2125,8 +2260,11 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)static int xe_hwmon_pwm_write (struct xe_hwmon *hwmon,u32 attr,int channel,long val) { +struct xe_hwmon_fan_info *fi;int ret =0 ; + fi = &hwmon->fi[channel]; +mutex_lock (&hwmon->hwmon_lock);switch (attr) {@@ -2135,7 +2273,48 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) ret = -EINVAL ;break ; } - ret =xe_hwmon_set_user_fan_pwm (hwmon, channel, (u8 )val); + ret =xe_hwmon_set_user_fan_pwm (hwmon, channel, (u8 )val, false); +break ; +case hwmon_pwm_enable: +if (val ==XE_FAN_PWM_FULL_SPEED ) { + ret =xe_hwmon_set_user_fan_pwm (hwmon, channel,U8_MAX , true); +if (ret) { +xe_warn (hwmon->xe, +"full speed enable for fan %d failed, ret=%d\n" , + channel, ret); +break ; + } + }else if (val ==XE_FAN_PWM_MANUAL_USER_TABLE ) { +enum fan_table_type source = fi->fan_table[USER_FAN_TABLE ].point_count ? +USER_FAN_TABLE :STOCK_FAN_TABLE ; + +/* +* Manual fan speed control using user fan table. +* If user fan table is not programmed, it would be initialized with +* clamped stock points which allows manual control with some +* default points. +*/ + ret =xe_hwmon_activate_user_fan_table (hwmon, channel, false, source); +if (ret) { +xe_warn (hwmon->xe, +"failed to activate user fan table for fan %d, ret=%d\n" , + channel, ret); +break ; + } + }else if (val ==XE_FAN_PWM_AUTO_STOCK_TABLE ) { + ret =xe_hwmon_fan_set_auto (hwmon, channel); +if (ret) {
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) · line 2316
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+xe_warn (hwmon->xe, +"failed to switch fan %d to automatic stock control, ret=%d\n" , + channel, ret); +break ; + } +xe_dbg (hwmon->xe, +"automatic control enabled for fan %d using stock table\n" , + channel); + }else { + ret = -EINVAL ;
Rejected silently. Add a xe_dbg/xe_warn before these -EINVAL returns for clarity.
Regards,
Soham
Quoted 22 lines
drivers/gpu/drm/xe/xe_hwmon.c +5
-0+ }break ;default : ret = -EOPNOTSUPP ;@@ -2350,6 +2529,7 @@ int xe_hwmon_register(struct xe_device *xe) {struct device *dev = xe->drm.dev;struct xe_hwmon *hwmon; +int fan;int ret;/* hwmon is available only for dGfx */ @@ -2364,6 +2544,9 @@ int xe_hwmon_register(struct xe_device *xe)if (!hwmon)return -ENOMEM ; +for (fan =0 ; fan <FAN_MAX ; fan++) + hwmon->fi[fan].pwm_enable_mode =XE_FAN_PWM_UNINITIALIZED ; + ret =devm_mutex_init (dev, &hwmon->hwmon_lock);if (ret)return ret;
PATCH v5 6/10 drm/xe/hwmon: Enable fan curve control support
In reply to Karthik PoosaExpose curve-point temperature and pwm controls via pwmF_auto_point[P]_temp and pwmF_auto_point[P]_pwm, where F is the fan number and P is the fan curve point number. Each fan curve point has a temperature and a pwm attribute.
Update Xe hwmon ABI documentation for pwm auto point temperature attributes.
v2:
- Use xe helpers for dmesg logs.
- Update kernel version in Xe hwmon documentation.
- Correct debug level of some dmesg logs.
v3:
- Allow variable fan curve points from >=2 to MAX_FAN_CONTROL_POINTS.
- Expose all MAX_FAN_CONTROL_POINTS fan-curve slots so users can extend a short fan table.
- Stage temp/PWM pairs without changing the active curve. Commit at a (0, 0) end marker or after all MAX_FAN_CONTROL_POINTS pairs.
- Write the points together, verify the firmware count, then update the active cache.
v4:
- Use the two-argument IS_FAN_ENABLED() after rebase.
- Fix kernel-doc for nested staged fan_table members.
- Use "speed" for percent values and "pwm" only for the 0..255 sysfs value. (Soham)
- Use u32 for the point index in xe_hwmon_commit_user_fan_table(). (Soham)
- Fix comment to say curve points must not decrease. (Soham)
- Add debug logs before -EINVAL returns. (Soham)
- Drop inline from xe_hwmon_get_active_fan_table(). (Soham)
- Use reverse xmas tree ordering for local variables. (Soham)
- Rename xe_hwmon_get_u8_from_sysfs() to xe_hwmon_sysfs_to_hw_val(). (Soham)
- Use if/else if/else for value selection in pwm auto point show. (Soham)
- Create the fan curve sensor attributes at probe time instead of 60 static definitions. (Soham)
- Clamp min PWM to 100% and reject pwm values above 100% speed.
- Use xe helpers for logs in the auto point store functions.
v5:
- Address review comments from Sashiko.
- Remove min_pwm as it is not available.
- Read back the user point count after curve programming and fall back to stock control when firmware does not accept it.
--- drivers/gpu/drm/xe/xe_hwmon.c | 429 ++++++++++++++++++++++++++++++++-- 1 file changed, 415 insertions(+), 14 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +415 -14
@@ -174,6 +174,11 @@ enum fan_table_type {/* Minimum number of points required for a user fan table. */ #define MIN_FAN_CONTROL_POINTS 2 +/* pwmN_auto_pointM_temp and pwmN_auto_pointM_pwm for every curve point of a fan. */ +#define XE_CURVE_ATTRS_PER_FAN (2 * MAX_FAN_CONTROL_POINTS) +#define XE_CURVE_ATTRS (FAN_MAX * XE_CURVE_ATTRS_PER_FAN) +#define XE_CURVE_ATTR_NAME_LEN sizeof("pwmN_auto_pointNN_temp") +/* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ #define FCP_INDEX (table_type, point_num) (((u32)(table_type) << 31) | \ ((u32)(point_num) & GENMASK(30, 0)))
@@ -201,6 +206,12 @@ struct xe_hwmon_fan_info {/** @fan_table.fcp.speed: fan speed in percentage */ u8 speed; } fcp[MAX_FAN_CONTROL_POINTS ]; +/** @fan_table.staged_fcp: curve supplied via sysfs but not yet committed */ +struct fan_control_point staged_fcp[MAX_FAN_CONTROL_POINTS ]; +/** @fan_table.temp_staged: bitmask of temperature fields supplied via sysfs */ +u16 temp_staged; +/** @fan_table.speed_staged: bitmask of speed fields supplied via sysfs */ +u16 speed_staged; } fan_table[FAN_TABLE_MAX ];/** @max_rps: maximum fan RPS */ u32 max_rps;
@@ -268,6 +279,16 @@ struct xe_hwmon {u32 pl2_on_boot[CHANNEL_MAX ];/** @temp: Temperature info */ struct xe_hwmon_thermal_info temp; +/** @curve_sda: fan curve sensor attributes */ +struct sensor_device_attribute curve_sda[XE_CURVE_ATTRS ]; +/** @curve_names: names of the fan curve sensor attributes */ +char curve_names[XE_CURVE_ATTRS ][XE_CURVE_ATTR_NAME_LEN ]; +/** @curve_attrs: NULL-terminated list of fan curve attributes */ +struct attribute *curve_attrs[XE_CURVE_ATTRS +1 ]; +/** @curve_group: fan curve attribute group */ +struct attribute_group curve_group; +/** @groups: NULL-terminated list of extra attribute groups */ +const struct attribute_group *groups[3 ]; };static inline int prepare_power_limit_param2 (const struct xe_hwmon *hwmon,int channel)
@@ -912,11 +933,6 @@ static const struct attribute_group hwmon_attrgroup = { .is_visible = xe_hwmon_attributes_visible, }; -static const struct attribute_group *hwmon_groups[] = { - &hwmon_attrgroup, -NULL -}; -static const u32 hwmon_temp_config[CHANNEL_MAX +1 ] = { [CHANNEL_CARD ] =HWMON_T_LABEL , [CHANNEL_PKG] = HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT |
@@ -1245,6 +1261,79 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan)return ret; } +static int xe_hwmon_commit_user_fan_table (struct xe_hwmon *hwmon,u8 fan, +const struct fan_control_point *points,u32 point_count) +{ +/* The extra write is for the final write that sets the number of fan control points */ +struct xe_pcode_write writes[MAX_FAN_CONTROL_POINTS +1 ]; +u32 accepted_count =0 ; +u32 point; +int ret, write_ret, verify_ret; + +if (!point_count) { +xe_err (hwmon->xe,"no fan control points provided for fan %d\n" , fan); +return -ENODATA ; + } + +for (point =0 ; point < point_count; point++) { +u8 temp = points[point].temp; +u8 speed = points[point].speed; + +/* Temperature and speed must not decrease from one point to the next. */ +if (point >0 ) { +u8 prev_temp = points[point -1 ].temp; +u8 prev_speed = points[point -1 ].speed; + +if (temp < prev_temp || speed < prev_speed) { +xe_dbg (hwmon->xe, +"fan %d point %u decreases: %u/%u%% after %u/%u%%\n" , + fan, point, temp, speed, prev_temp, prev_speed); +return -EINVAL ; + } + } + +/* Prepare the write for this fan control point */ + writes[point].mbox =PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_FAN_TABLE , + fan); + writes[point].data =FIELD_PREP (FAN_CONTROL_POINT_TEMP_MASK , temp) | +FIELD_PREP (FAN_CONTROL_POINT_SPEED_MASK , speed); + } + +xe_dbg (hwmon->xe,"committing fan %d user table with %u points\n" , fan, point_count); + + writes[point_count].mbox =PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_NUM_FAN_CONTROL_POINTS , + fan); + writes[point_count].data = point_count; + + write_ret =xe_pcode_write_batch (xe_device_get_root_tile (hwmon->xe), writes, + point_count +1 ); +if (write_ret) +xe_dbg (hwmon->xe,"failed to write fan %d user table, ret=%d\n" , fan, write_ret); + + verify_ret =xe_hwmon_get_fan_point_count (hwmon, fan, &accepted_count,USER_FAN_TABLE ); +if (write_ret || verify_ret || accepted_count != point_count) { +int failure_ret = write_ret ?: verify_ret ?: -EIO ; + + hwmon->fi[fan].fan_table[USER_FAN_TABLE ].point_count =0 ; +if (verify_ret || accepted_count != point_count) +xe_err (hwmon->xe, +"fan %d table count verification failed: ret=%d, expected=%u, got=%u\n" , + fan, verify_ret, point_count, accepted_count); + ret =xe_hwmon_fan_set_auto (hwmon, fan); +if (ret) { + hwmon->fi[fan].pwm_enable_mode =XE_FAN_PWM_UNINITIALIZED ; + hwmon->fi[fan].is_full_speed = false; +xe_err (hwmon->xe,"failed to restore fan %d to stock mode, ret=%d\n" , fan, + ret); + } +return failure_ret; + } + +xe_dbg (hwmon->xe,"fan %d user table committed successfully with %u points\n" , fan, + point_count); +return 0 ; +} +static int xe_hwmon_activate_user_fan_table (struct xe_hwmon *hwmon,u8 fan,bool is_full_speed,enum fan_table_type table_source) {
@@ -1313,6 +1402,8 @@ static int xe_hwmon_activate_user_fan_table(struct xe_hwmon *hwmon, u8 fan, fi->fan_table[USER_FAN_TABLE ].point_count = point_count; fi->pwm_enable_mode = is_full_speed ?XE_FAN_PWM_FULL_SPEED :XE_FAN_PWM_MANUAL_USER_TABLE ; + fi->fan_table[USER_FAN_TABLE ].temp_staged =0 ; + fi->fan_table[USER_FAN_TABLE ].speed_staged =0 ; fi->is_full_speed = is_full_speed;return 0 ;
@@ -1384,6 +1475,8 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo fi->fan_table[USER_FAN_TABLE].fcp[i].speed); } fi->fan_table[USER_FAN_TABLE ].point_count =MIN_FAN_CONTROL_POINTS ; + fi->fan_table[USER_FAN_TABLE ].temp_staged =0 ; + fi->fan_table[USER_FAN_TABLE ].speed_staged =0 ; fi->pwm_enable_mode = full_speed ?XE_FAN_PWM_FULL_SPEED :XE_FAN_PWM_MANUAL_USER_TABLE ;
@@ -1391,6 +1484,312 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, booreturn 0 ; } +#define XE_CURVE_IDX (fan, point) (((fan) << 8) | (point)) +#define XE_CURVE_FAN (idx) ((u8)(((idx) >> 8) & 0xff)) +#define XE_CURVE_POINT (idx) ((u8)((idx) & 0xff)) + +static int +xe_hwmon_decode_curve_index (struct xe_hwmon *hwmon,u32 index,u8 *fan,u8 *point) +{ +u8 local_fan =XE_CURVE_FAN (index); +u8 local_point =XE_CURVE_POINT (index); + +if (local_fan >=FAN_MAX || local_point >=MAX_FAN_CONTROL_POINTS ) { +xe_dbg (hwmon->xe,"invalid fan curve index 0x%x: fan %u point %u\n" , + index, local_fan, local_point); +return -EINVAL ; + } + + *fan = local_fan; + *point = local_point; + +return 0 ; +} + +static enum fan_table_type xe_hwmon_get_active_fan_table (struct xe_hwmon *hwmon,u8 fan) +{ +if (hwmon->fi[fan].pwm_enable_mode ==XE_FAN_PWM_AUTO_STOCK_TABLE ) +return STOCK_FAN_TABLE ; +else +return USER_FAN_TABLE ; +} + +static ssize_t +xe_hwmon_pwm_auto_point_temp_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +enum fan_table_type active_table; +struct xe_hwmon_fan_info *fi; +u32 point_count; +u8 point; +u8 temp; +int ret; +u8 fan; + + ret =xe_hwmon_decode_curve_index (hwmon, sattr->index, &fan, &point); +if (ret) +return ret; + +guard (mutex)(&hwmon->hwmon_lock); + + fi = &hwmon->fi[fan]; + active_table =xe_hwmon_get_active_fan_table (hwmon, fan); + + point_count = fi->fan_table[active_table].point_count; + +if (point >= point_count) + temp =0 ; +else + temp = fi->fan_table[active_table].fcp[point].temp; +return sysfs_emit (buf,"%u\n" , temp *MILLIDEGREE_PER_DEGREE ); +} + +static int xe_hwmon_update_user_fan_point (struct xe_hwmon *hwmon,u8 fan,u32 point, +bool is_temp,u8 value) +{ +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +struct fan_table *table; +u32 point_count; +int ret; + + table = &fi->fan_table[USER_FAN_TABLE ]; + +if (is_temp) { + table->staged_fcp[point].temp = value; + table->temp_staged |=BIT (point); + }else { + table->staged_fcp[point].speed = value; + table->speed_staged |=BIT (point); + } + +/* Wait for a complete prefix; (0, 0) ends the curve without becoming a point. */ +for (point_count =0 ; point_count <MAX_FAN_CONTROL_POINTS ; point_count++) { +if (!(table->temp_staged &BIT (point_count)) || + !(table->speed_staged &BIT (point_count))) +return 0 ; +if (!table->staged_fcp[point_count].temp && + !table->staged_fcp[point_count].speed) +break ; + } + +if (point_count <MIN_FAN_CONTROL_POINTS ) { +xe_dbg (hwmon->xe,"fan %d curve needs at least %d points, got %u\n" , + fan,MIN_FAN_CONTROL_POINTS , point_count); + ret = -EINVAL ; + goto clear_staged; + } + + ret =xe_hwmon_commit_user_fan_table (hwmon, fan, table->staged_fcp, point_count); +if (ret) + goto clear_staged; + +/* Publish the new curve only after firmware accepts its point count. */ +memcpy (table->fcp, table->staged_fcp, point_count *sizeof (table->fcp[0 ])); + table->point_count = point_count; + fi->pwm_enable_mode =XE_FAN_PWM_MANUAL_USER_TABLE ; + fi->is_full_speed = false; + +clear_staged: + table->temp_staged =0 ; + table->speed_staged =0 ; +return ret; +} + +static int xe_hwmon_sysfs_to_hw_val (struct xe_hwmon *hwmon,long val,bool is_temp,u8 *out) +{ +long max = is_temp ?U8_MAX *MILLIDEGREE_PER_DEGREE :U8_MAX ; +long hw_val; + +if (val <0 || val > max) { +xe_dbg (hwmon->xe,"%s value %ld out of range\n" , is_temp ?"temp" :"pwm" , val); +return -EINVAL ; + } + +/* Temperature is in degrees Celsius, speed in percent. */ +if (is_temp) + hw_val =DIV_ROUND_CLOSEST (val,MILLIDEGREE_PER_DEGREE ); +else + hw_val =DIV_ROUND_CLOSEST (val *100 ,U8_MAX ); + +if (!is_temp && val && !hw_val) + hw_val =1 ; + + *out = hw_val; + +return 0 ; +} + +static ssize_t +xe_hwmon_pwm_auto_point_temp_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +struct xe_hwmon_fan_info *fi; +long val; +u8 point; +u8 temp; +int ret; +u8 fan; + + ret =xe_hwmon_decode_curve_index (hwmon, sattr->index, &fan, &point); +if (ret) +return ret; + + ret =kstrtol (buf,10 , &val); +if (ret) +return ret; + + ret =xe_hwmon_sysfs_to_hw_val (hwmon, val, true, &temp); +if (ret) +return ret; + +guard (xe_pm_runtime)(hwmon->xe); + +guard (mutex)(&hwmon->hwmon_lock); + fi = &hwmon->fi[fan]; + +if (fi->pwm_enable_mode !=XE_FAN_PWM_MANUAL_USER_TABLE || fi->is_full_speed) { +xe_dbg (hwmon->xe,"pwm%d_enable not in manual mode; cannot update temp point %d\n" , + fan +1 , point +1 ); +return -EINVAL ; + } + +xe_dbg (hwmon->xe,"staging fan %d point %d temp to %u\n" , fan, point, temp); + ret =xe_hwmon_update_user_fan_point (hwmon, fan, point, true, temp); + +return ret ? ret : count; +} + +static ssize_t +xe_hwmon_pwm_auto_point_pwm_show (struct device *dev, +struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +enum fan_table_type active_table; +struct xe_hwmon_fan_info *fi; +u32 point_count; +u8 point; +u8 speed; +int ret; +u8 fan; + + ret =xe_hwmon_decode_curve_index (hwmon, sattr->index, &fan, &point); +if (ret) +return ret; + +guard (mutex)(&hwmon->hwmon_lock); + + fi = &hwmon->fi[fan]; + active_table =xe_hwmon_get_active_fan_table (hwmon, fan); + + point_count = fi->fan_table[active_table].point_count; + +if (point >= point_count) + speed =0 ; +else + speed = fi->fan_table[active_table].fcp[point].speed; +return sysfs_emit (buf,"%u\n" ,DIV_ROUND_CLOSEST (speed *U8_MAX ,100 )); +} + +static ssize_t +xe_hwmon_pwm_auto_point_pwm_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t count) +{ +struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +struct xe_hwmon_fan_info *fi; +long val; +u8 point; +u8 speed; +int ret; +u8 fan; + + ret =xe_hwmon_decode_curve_index (hwmon, sattr->index, &fan, &point); +if (ret) +return ret; + + ret =kstrtol (buf,10 , &val); +if (ret) +return ret; + + ret =xe_hwmon_sysfs_to_hw_val (hwmon, val, false, &speed); +if (ret) +return ret; + +guard (xe_pm_runtime)(hwmon->xe); + +guard (mutex)(&hwmon->hwmon_lock); + fi = &hwmon->fi[fan]; + +if (fi->pwm_enable_mode !=XE_FAN_PWM_MANUAL_USER_TABLE || fi->is_full_speed) { +xe_dbg (hwmon->xe, +"pwm%d_enable is not in manual user mode, cannot update pwm point %d\n" , + fan +1 , point +1 ); +return -EINVAL ; + } + +xe_dbg (hwmon->xe,"staging fan %d point %d speed to %u%%\n" , fan, point, speed); + ret =xe_hwmon_update_user_fan_point (hwmon, fan, point, false, speed); + +return ret ? ret : count; +} + +static umode_t xe_hwmon_curve_attributes_visible (struct kobject *kobj, +struct attribute *attr,int index) +{ +struct device *dev =kobj_to_dev (kobj); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +u32 fan = index /XE_CURVE_ATTRS_PER_FAN ; + +if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED (hwmon, fan)) +return 0 ; + +/* All slots must exist at registration, before the user curve has been staged. */ +return attr->mode; +} + +static void xe_hwmon_init_curve_attrs (struct xe_hwmon *hwmon) +{ +int fan, kind, point, i =0 ; + +/* Per fan: all temp points then all pwm points; is_visible relies on this layout. */ +for (fan =0 ; fan <FAN_MAX ; fan++) { +for (kind =0 ; kind <2 ; kind++) { +bool is_temp = !kind; + +for (point =0 ; point <MAX_FAN_CONTROL_POINTS ; point++, i++) { +struct sensor_device_attribute *sda = &hwmon->curve_sda[i]; + +snprintf (hwmon->curve_names[i],XE_CURVE_ATTR_NAME_LEN , +"pwm%d_auto_point%d_%s" , fan +1 , point +1 , + is_temp ?"temp" :"pwm" ); +sysfs_attr_init (&sda->dev_attr.attr); + sda->dev_attr.attr.name = hwmon->curve_names[i]; + sda->dev_attr.attr.mode =0644 ; +if (is_temp) { + sda->dev_attr.show = xe_hwmon_pwm_auto_point_temp_show; + sda->dev_attr.store = xe_hwmon_pwm_auto_point_temp_store; + }else { + sda->dev_attr.show = xe_hwmon_pwm_auto_point_pwm_show; + sda->dev_attr.store = xe_hwmon_pwm_auto_point_pwm_store; + } + sda->index =XE_CURVE_IDX (fan, point); + hwmon->curve_attrs[i] = &sda->dev_attr.attr; + } + } + } + + hwmon->curve_group.attrs = hwmon->curve_attrs; + hwmon->curve_group.is_visible = xe_hwmon_curve_attributes_visible; +} +static int xe_hwmon_read_fan_control_info (struct xe_hwmon *hwmon) {int err =0 ;
@@ -2184,14 +2583,6 @@ static int xe_hwmon_get_pwm_from_pmt(struct xe_hwmon *hwmon, int channel, long *return 0 ; } -static enum fan_table_type xe_hwmon_get_active_fan_table (struct xe_hwmon *hwmon,u8 fan) -{ -if (hwmon->fi[fan].pwm_enable_mode ==XE_FAN_PWM_AUTO_STOCK_TABLE ) -return STOCK_FAN_TABLE ; -else -return USER_FAN_TABLE ; -} -static int xe_hwmon_pwm_read (struct xe_hwmon *hwmon,u32 attr,int channel,long *val) {
@@ -2301,6 +2692,8 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) channel, ret);break ; } + fi->fan_table[USER_FAN_TABLE ].temp_staged =0 ; + fi->fan_table[USER_FAN_TABLE ].speed_staged =0 ; }else if (val ==XE_FAN_PWM_AUTO_STOCK_TABLE ) { ret =xe_hwmon_fan_set_auto (hwmon, channel);if (ret) {
@@ -2312,6 +2705,8 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val)xe_dbg (hwmon->xe,"automatic control enabled for fan %d using stock table\n" , channel); + fi->fan_table[USER_FAN_TABLE ].temp_staged =0 ; + fi->fan_table[USER_FAN_TABLE ].speed_staged =0 ; }else { ret = -EINVAL ; }
@@ -2561,10 +2956,16 @@ int xe_hwmon_register(struct xe_device *xe)drm_dbg (&xe->drm,"Register xe hwmon interface\n" ); + hwmon->groups[0 ] = &hwmon_attrgroup; +if (xe->info.has_fan_control) { +xe_hwmon_init_curve_attrs (hwmon); + hwmon->groups[1 ] = &hwmon->curve_group; + } +/* hwmon_dev points to device hwmon<i> */ hwmon->hwmon_dev =hwmon_device_register_with_info (dev,"xe" , hwmon, &hwmon_chip_info, - hwmon_groups); + hwmon->groups);if (IS_ERR (hwmon->hwmon_dev)) { ret =PTR_ERR (hwmon->hwmon_dev);xe_log_err (xe,HWMON , ret,"Failed to register xe hwmon\n" );
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 06/10] drm/xe/hwmon: Enable fan curve control support
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] drm/xe/hwmon: missing stock table check in xe_hwmon_curve_attributes_visible() - [Medium]…
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] drm/xe/hwmon: missing stock table check in xe_hwmon_curve_attributes_visible()
- [Medium] drm/xe/hwmon: xe_hwmon_pwm_read() returns fcp[0].speed on user fan curves
- [Low] drm/xe/hwmon: missing ABI documentation update claimed in commit message
- [Low] drm/xe/hwmon: unhandled XE_FAN_PWM_UNINITIALIZED in curve show callbacks
--
commit 51f62604f9e213b63207cde46fb9f696d1728daf
Author: Karthik Poosa <[email protected]>
drm/xe/hwmon: Enable fan curve control support
This commit exposes fan curve temperature and PWM control points in hwmon sysfs via pwm[1-3]_auto_point[1-10]_temp and pwm[1-3]_auto_point[1-10]_pwm, allowing userspace to stage and commit custom fan curves to PCODE.
Quoted 6 lines
Update Xe hwmon ABI documentation for pwm auto point temperature attributes.
v2:
- Use xe helpers for dmesg logs.
- Update kernel version in Xe hwmon documentation.
[Severity: Low]
Was the Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon update dropped from this patch? The commit message says the ABI documentation is updated, but this commit only touches drivers/gpu/drm/xe/xe_hwmon.c and leaves pwm[1-3]_auto_point[1-10]_temp and pwm[1-3]_auto_point[1-10]_pwm undocumented.
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0
[ ... ]
Quoted 46 lines
drivers/gpu/drm/xe/xe_hwmon.c +42
-0@@ -1389,6 +1482,312 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, booreturn 0 ; } +#define XE_CURVE_IDX (fan, point) (((fan) << 8) | (point)) +#define XE_CURVE_FAN (idx) ((u8)(((idx) >> 8) & 0xff)) +#define XE_CURVE_POINT (idx) ((u8)((idx) & 0xff)) + +static int +xe_hwmon_decode_curve_index (struct xe_hwmon *hwmon,u32 index,u8 *fan,u8 *point) +{ +u8 local_fan =XE_CURVE_FAN (index); +u8 local_point =XE_CURVE_POINT (index); + +if (local_fan >=FAN_MAX || local_point >=MAX_FAN_CONTROL_POINTS ) { +xe_dbg (hwmon->xe,"invalid fan curve index 0x%x: fan %u point %u\n" , + index, local_fan, local_point); +return -EINVAL ; + } + + *fan = local_fan; + *point = local_point; + +return 0 ; +} + +static enum fan_table_type xe_hwmon_get_active_fan_table (struct xe_hwmon *hwmon,u8 fan) +{ +if (hwmon->fi[fan].pwm_enable_mode ==XE_FAN_PWM_AUTO_STOCK_TABLE ) +return STOCK_FAN_TABLE ; +else +return USER_FAN_TABLE ; +} + +static ssize_t +xe_hwmon_pwm_auto_point_temp_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +enum fan_table_type active_table; +struct xe_hwmon_fan_info *fi; +u32 point_count; +u8 point; +u8 temp; +int ret;
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo · line 1536
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+u8 fan; + + ret =xe_hwmon_decode_curve_index (hwmon, sattr->index, &fan, &point); +if (ret) +return ret; + +guard (mutex)(&hwmon->hwmon_lock); + + fi = &hwmon->fi[fan]; + active_table =xe_hwmon_get_active_fan_table (hwmon, fan);
[Severity: Low]
Should xe_hwmon_pwm_auto_point_temp_show() and xe_hwmon_pwm_auto_point_pwm_show() return -ENODATA when fi->pwm_enable_mode is XE_FAN_PWM_UNINITIALIZED, the same way xe_hwmon_pwm_read() does for hwmon_pwm_enable? Right now xe_hwmon_get_active_fan_table() maps XE_FAN_PWM_UNINITIALIZED to USER_FAN_TABLE, so after a failed xe_hwmon_fan_set_auto() call the show callbacks report stale user-table points or 0 instead of an error.
Quoted 44 lines
drivers/gpu/drm/xe/xe_hwmon.c +44
-0+ + point_count = fi->fan_table[active_table].point_count; + +if (point >= point_count) + temp =0 ; +else + temp = fi->fan_table[active_table].fcp[point].temp; +return sysfs_emit (buf,"%u\n" , temp *MILLIDEGREE_PER_DEGREE ); +} + +static int xe_hwmon_update_user_fan_point (struct xe_hwmon *hwmon,u8 fan,u32 point, +bool is_temp,u8 value) +{ +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +struct fan_table *table; +u32 point_count; +int ret; + + table = &fi->fan_table[USER_FAN_TABLE ]; + +if (is_temp) { + table->staged_fcp[point].temp = value; + table->temp_staged |=BIT (point); + }else { + table->staged_fcp[point].speed = value; + table->speed_staged |=BIT (point); + } + +/* Wait for a complete prefix; (0, 0) ends the curve without becoming a point. */ +for (point_count =0 ; point_count <MAX_FAN_CONTROL_POINTS ; point_count++) { +if (!(table->temp_staged &BIT (point_count)) || + !(table->speed_staged &BIT (point_count))) +return 0 ; +if (!table->staged_fcp[point_count].temp && + !table->staged_fcp[point_count].speed) +break ; + } + +if (point_count <MIN_FAN_CONTROL_POINTS ) { +xe_dbg (hwmon->xe,"fan %d curve needs at least %d points, got %u\n" , + fan,MIN_FAN_CONTROL_POINTS , point_count); + ret = -EINVAL ; + goto clear_staged; + }
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo · line 1592
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+ + ret =xe_hwmon_commit_user_fan_table (hwmon, fan, table->staged_fcp, point_count); +if (ret) + goto clear_staged; + +/* Publish the new curve only after firmware accepts its point count. */ +memcpy (table->fcp, table->staged_fcp, point_count *sizeof (table->fcp[0 ])); + table->point_count = point_count; + fi->pwm_enable_mode =XE_FAN_PWM_MANUAL_USER_TABLE ; + fi->is_full_speed = false;
[Severity: Medium]
When a multi-point user fan curve is committed here, does reading pwmN in xe_hwmon_pwm_read() return the wrong PWM value?
drivers/gpu/drm/xe/xe_hwmon.c:xe_hwmon_pwm_read() {
...
if (xe_hwmon_get_active_fan_table(hwmon, channel) == STOCK_FAN_TABLE) {
...
} else {
/*
* pwmN writes set every user-table point to the same speed,
* so the first point gives the cached manual PWM percentage.
*/
xe_dbg(hwmon->xe, "getting active pwm for fan %d from user table cache\n",
channel);
pwm = fi->fan_table[USER_FAN_TABLE].fcp[0].speed;
}
...
}For a custom curve with different speeds across temperature points, fcp[0].speed is only the speed at the lowest temperature point rather than the active PWM from PMT telemetry (on Battlemage) or interpolation across USER_FAN_TABLE. Also, if xe_hwmon_commit_user_fan_table() and its xe_hwmon_fan_set_auto() fallback both fail, point_count is reset to 0 and pwm_enable_mode is set to XE_FAN_PWM_UNINITIALIZED, yet xe_hwmon_pwm_read() still takes this USER_FAN_TABLE branch and returns stale fcp[0].speed.
[ ... ]
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo · line 1756
Quoted 13 lines
drivers/gpu/drm/xe/xe_hwmon.c +13
-0+static umode_t xe_hwmon_curve_attributes_visible (struct kobject *kobj, +struct attribute *attr,int index) +{ +struct device *dev =kobj_to_dev (kobj); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +u32 fan = index /XE_CURVE_ATTRS_PER_FAN ; + +if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED (hwmon, fan)) +return 0 ; + +/* All slots must exist at registration, before the user curve has been staged. */ +return attr->mode; +}
[Severity: Medium]
Should xe_hwmon_curve_attributes_visible() also check !hwmon->fi[fan].fan_table[STOCK_FAN_TABLE].point_count like xe_hwmon_pwm_is_visible() does?
drivers/gpu/drm/xe/xe_hwmon.c:xe_hwmon_pwm_is_visible() {
if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED(hwmon, channel) ||
!hwmon->fi[channel].fan_table[STOCK_FAN_TABLE].point_count)
return 0;
...
}When a fan channel is enabled in fan_enable_mask (such as on DG2, or when reading the stock table in xe_hwmon_read_fan_control_info() fails or returns 0 points), pwmN and pwmN_enable are hidden and fi->pwm_enable_mode stays XE_FAN_PWM_UNINITIALIZED, but all 20 pwmN_auto_point* attributes are still exposed even though every write to them will fail with -EINVAL.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v5 06/10] drm/xe/hwmon: Enable fan curve control support
Quoted 27 lines · On 28-11-2026 11:40, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 4 potential issues to consider:
- [Medium] drm/xe/hwmon: missing stock table check inxe_hwmon_curve_attributes_visible()
- [Medium] drm/xe/hwmon:xe_hwmon_pwm_read()returns fcp[0].speed on user fan curves
- [Low] drm/xe/hwmon: missing ABI documentation update claimed in commit message
- [Low] drm/xe/hwmon: unhandledXE_FAN_PWM_UNINITIALIZEDin curve show callbacks
--commit
51f62604f9e213b63207cde46fb9f696d1728daf
Author: Karthik Poosa <[email protected]>drm/xe/hwmon: Enable fan curve control support
This commit exposes fan curve temperature and PWM control points in hwmon sysfs via pwm[1-3]_auto_point[1-10]_temp and pwm[1-3]_auto_point[1-10]_pwm, allowing userspace to stage and commit custom fan curves to PCODE.
Quoted 6 lines
Update Xe hwmon ABI documentation for pwm auto point temperature attributes.
v2:
- Use xe helpers for dmesg logs.
- Update kernel version in Xe hwmon documentation.
Quoted 6 lines
[Severity: Low]
Was theDocumentation/ABI/testing/sysfs-driver-intel-xe-hwmonupdate dropped from this patch? The commit message says the ABI documentation is updated, but this commit only touchesdrivers/gpu/drm/xe/xe_hwmon.cand leaves pwm[1-3]_auto_point[1-10]_temp and pwm[1-3]_auto_point[1-10]_pwm undocumented.
Yes it is missed, I shall add it.
Quoted 62 lines
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0[ ... ]
Quoted 46 lines
drivers/gpu/drm/xe/xe_hwmon.c +42
-0@@ -1389,6 +1482,312 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, booreturn 0 ; } +#define XE_CURVE_IDX (fan, point) (((fan) << 8) | (point)) +#define XE_CURVE_FAN (idx) ((u8)(((idx) >> 8) & 0xff)) +#define XE_CURVE_POINT (idx) ((u8)((idx) & 0xff)) + +static int +xe_hwmon_decode_curve_index (struct xe_hwmon *hwmon,u32 index,u8 *fan,u8 *point) +{ +u8 local_fan =XE_CURVE_FAN (index); +u8 local_point =XE_CURVE_POINT (index); + +if (local_fan >=FAN_MAX || local_point >=MAX_FAN_CONTROL_POINTS ) { +xe_dbg (hwmon->xe,"invalid fan curve index 0x%x: fan %u point %u\n" , + index, local_fan, local_point); +return -EINVAL ; + } + + *fan = local_fan; + *point = local_point; + +return 0 ; +} + +static enum fan_table_type xe_hwmon_get_active_fan_table (struct xe_hwmon *hwmon,u8 fan) +{ +if (hwmon->fi[fan].pwm_enable_mode ==XE_FAN_PWM_AUTO_STOCK_TABLE ) +return STOCK_FAN_TABLE ; +else +return USER_FAN_TABLE ; +} + +static ssize_t +xe_hwmon_pwm_auto_point_temp_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +struct sensor_device_attribute *sattr =to_sensor_dev_attr (attr); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +enum fan_table_type active_table; +struct xe_hwmon_fan_info *fi; +u32 point_count; +u8 point; +u8 temp; +int ret;drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo · line 1536
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+u8 fan; + + ret =xe_hwmon_decode_curve_index (hwmon, sattr->index, &fan, &point); +if (ret) +return ret; + +guard (mutex)(&hwmon->hwmon_lock); + + fi = &hwmon->fi[fan]; + active_table =xe_hwmon_get_active_fan_table (hwmon, fan);
Quoted 8 lines
[Severity: Low]
Shouldxe_hwmon_pwm_auto_point_temp_show()andxe_hwmon_pwm_auto_point_pwm_show()return-ENODATAwhenfi->pwm_enable_modeisXE_FAN_PWM_UNINITIALIZED, the same wayxe_hwmon_pwm_read()does forhwmon_pwm_enable? Right nowxe_hwmon_get_active_fan_table()mapsXE_FAN_PWM_UNINITIALIZEDtoUSER_FAN_TABLE, so after a failedxe_hwmon_fan_set_auto()call the show callbacks report stale user-table points or 0 instead of an error.
yes we can return -ENODATA
Quoted 82 lines
Quoted 44 lines
drivers/gpu/drm/xe/xe_hwmon.c +44
-0+ + point_count = fi->fan_table[active_table].point_count; + +if (point >= point_count) + temp =0 ; +else + temp = fi->fan_table[active_table].fcp[point].temp; +return sysfs_emit (buf,"%u\n" , temp *MILLIDEGREE_PER_DEGREE ); +} + +static int xe_hwmon_update_user_fan_point (struct xe_hwmon *hwmon,u8 fan,u32 point, +bool is_temp,u8 value) +{ +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +struct fan_table *table; +u32 point_count; +int ret; + + table = &fi->fan_table[USER_FAN_TABLE ]; + +if (is_temp) { + table->staged_fcp[point].temp = value; + table->temp_staged |=BIT (point); + }else { + table->staged_fcp[point].speed = value; + table->speed_staged |=BIT (point); + } + +/* Wait for a complete prefix; (0, 0) ends the curve without becoming a point. */ +for (point_count =0 ; point_count <MAX_FAN_CONTROL_POINTS ; point_count++) { +if (!(table->temp_staged &BIT (point_count)) || + !(table->speed_staged &BIT (point_count))) +return 0 ; +if (!table->staged_fcp[point_count].temp && + !table->staged_fcp[point_count].speed) +break ; + } + +if (point_count <MIN_FAN_CONTROL_POINTS ) { +xe_dbg (hwmon->xe,"fan %d curve needs at least %d points, got %u\n" , + fan,MIN_FAN_CONTROL_POINTS , point_count); + ret = -EINVAL ; + goto clear_staged; + }drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo · line 1592
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+ + ret =xe_hwmon_commit_user_fan_table (hwmon, fan, table->staged_fcp, point_count); +if (ret) + goto clear_staged; + +/* Publish the new curve only after firmware accepts its point count. */ +memcpy (table->fcp, table->staged_fcp, point_count *sizeof (table->fcp[0 ])); + table->point_count = point_count; + fi->pwm_enable_mode =XE_FAN_PWM_MANUAL_USER_TABLE ; + fi->is_full_speed = false;[Severity: Medium]
When a multi-point user fan curve is committed here, does reading pwmN inxe_hwmon_pwm_read()return the wrong PWM value?drivers/gpu/drm/xe/xe_hwmon.c:xe_hwmon_pwm_read() { ... if (xe_hwmon_get_active_fan_table(hwmon, channel) == STOCK_FAN_TABLE) { ... } else { /* * pwmN writes set every user-table point to the same speed, * so the first point gives the cached manual PWM percentage. */ xe_dbg(hwmon->xe, "getting active pwm for fan %d from user table cache\n", channel); pwm = fi->fan_table[USER_FAN_TABLE].fcp[0].speed; } ... }For a custom curve with different speeds across temperature points, fcp[0].speed is only the speed at the lowest temperature point rather than the active PWM from PMT telemetry (on Battlemage) or interpolation across
USER_FAN_TABLE. Also, ifxe_hwmon_commit_user_fan_table()and itsxe_hwmon_fan_set_auto()fallback both fail,point_countis reset to 0 andpwm_enable_modeis set toXE_FAN_PWM_UNINITIALIZED, yetxe_hwmon_pwm_read()still takes thisUSER_FAN_TABLEbranch and returns stale fcp[0].speed.
Quoted 1 line
[ ... ]
This shall be addressed at next revision, We shall return active PWM instead of lowest point. For XE_FAN_PWM_UNINITIALIZED, it will -ENODATA
Quoted 19 lines
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +3
-0+static umode_t xe_hwmon_curve_attributes_visible (struct kobject *kobj, +struct attribute *attr,int index) +{drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm, boo · line 1756
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+struct device *dev =kobj_to_dev (kobj); +struct xe_hwmon *hwmon =dev_get_drvdata (dev); +u32 fan = index /XE_CURVE_ATTRS_PER_FAN ; + +if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED (hwmon, fan)) +return 0 ; + +/* All slots must exist at registration, before the user curve has been staged. */ +return attr->mode; +}[Severity: Medium]
Shouldxe_hwmon_curve_attributes_visible()also check !hwmon->fi[fan].fan_table[STOCK_FAN_TABLE].point_count likexe_hwmon_pwm_is_visible()does?
Quoted 6 lines
drivers/gpu/drm/xe/xe_hwmon.c:xe_hwmon_pwm_is_visible() {
if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED(hwmon, channel) ||
!hwmon->fi[channel].fan_table[STOCK_FAN_TABLE].point_count)
return 0;
...
}Yes I think we should, if stock table is valid only, we can use user table, as stock table is fallback option.
Quoted 6 lines
When a fan channel is enabled in
fan_enable_mask(such as on DG2, or when reading the stock table inxe_hwmon_read_fan_control_info()fails or returns 0 points), pwmN andpwmN_enableare hidden andfi->pwm_enable_modestaysXE_FAN_PWM_UNINITIALIZED, but all 20 pwmN_auto_point* attributes are still exposed even though every write to them will fail with-EINVAL.
okay, fan curve point nodes pwmN_auto_point* shall be disabled on DG2.
Quoted 1 line
PATCH v5 7/10 drm/xe/hwmon: Restore fan user tables after resume
In reply to Karthik PoosaPreserve active manual and full-speed fan tables across system suspend, runtime D3cold, and FLR.
On resume, wait for late-bound fan-control firmware to reload before restoring the cached table. If restoration fails, verify fallback to stock fan control.
v2: Use xe_pcode_read() instead of xe_pcode_read_timeout().
v3:
- Use u32 for the point index. (Soham)
- Say "user table point" in suspend warnings. (Soham)
- Sort the xe_hwmon.h include. (Soham)
- Call the system PM hooks from xe_device_suspend() and xe_device_resume() after the upstream refactor, so FLR also restores the table.
- Check d3cold.allowed only for runtime PM; system suspend always loses the table.
- Pass hwmon to IS_FAN_ENABLED().
v4:
- Avoid fan-table reads during suspend.
- Fall back to the stock fan table on user-table restore failure.
--- drivers/gpu/drm/xe/xe_device.c | 3 + drivers/gpu/drm/xe/xe_hwmon.c | 109 +++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_hwmon.h | 4 + drivers/gpu/drm/xe/xe_late_bind_fw.c | 7 ++ drivers/gpu/drm/xe/xe_pm.c | 11 ++- 5 files changed, 131 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_device.c +3 -0
@@ -1428,6 +1428,8 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr)xe_late_bind_pm_suspend (&xe->late_bind); +xe_hwmon_suspend (xe, false); +for_each_gt (gt, xe, id)xe_gt_suspend_prepare (gt);
@@ -1558,6 +1560,7 @@ int xe_device_resume(struct xe_device *xe, bool flr)xe_pxp_pm_resume (xe->pxp);xe_late_bind_pm_resume (&xe->late_bind); +xe_hwmon_resume (xe, false);return 0 ; }
drivers/gpu/drm/xe/xe_hwmon.c +109 -0
119 lines not on this page · raw message
drivers/gpu/drm/xe/xe_hwmon.h +4 -0
@@ -13,9 +13,13 @@ struct xe_device;#if IS_REACHABLE (CONFIG_HWMON )int xe_hwmon_register (struct xe_device *xe);void xe_hwmon_unregister (struct xe_device *xe); +void xe_hwmon_suspend (struct xe_device *xe,bool runtime); +void xe_hwmon_resume (struct xe_device *xe,bool runtime);#else static inline int xe_hwmon_register (struct xe_device *xe) {return 0 ; };static inline void xe_hwmon_unregister (struct xe_device *xe) { } +static inline void xe_hwmon_suspend (struct xe_device *xe,bool runtime) {} +static inline void xe_hwmon_resume (struct xe_device *xe,bool runtime) {}#endif #endif /* _XE_HWMON_H_ */
drivers/gpu/drm/xe/xe_late_bind_fw.c +7 -0
@@ -517,10 +517,17 @@ void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind)*/ void xe_late_bind_pm_resume (struct xe_late_bind *late_bind) { +struct xe_late_bind_fw *fan_control_fw; +bool fan_control_fw_pending; +if (!late_bind->component_added || late_bind->disable)return ; + fan_control_fw = &late_bind->late_bind_fw[XE_LB_FW_FAN_CONTROL ]; + fan_control_fw_pending = !!fan_control_fw->payload;xe_late_bind_fw_load (late_bind); +if (fan_control_fw_pending) +flush_work (&fan_control_fw->work); }/**
drivers/gpu/drm/xe/xe_pm.c +8 -3
@@ -20,6 +20,7 @@#include "xe_ggtt.h" #include "xe_gt.h" #include "xe_gt_idle.h" +#include "xe_hwmon.h" #include "xe_i2c.h" #include "xe_irq.h" #include "xe_late_bind_fw.h"
@@ -567,6 +568,8 @@ int xe_pm_runtime_suspend(struct xe_device *xe)if (err) goto out; +xe_hwmon_suspend (xe, true); +/* * Applying lock for entire list op as xe_ttm_bo_destroy and xe_bo_move_notify * also checks and deletes bo entry from user fault list.
@@ -683,12 +686,14 @@ int xe_pm_runtime_resume(struct xe_device *xe)xe_pxp_pm_resume (xe->pxp); -if (IS_VF_CCS_READY (xe)) -xe_sriov_vf_ccs_register_context (xe); -if (xe->d3cold.allowed)xe_late_bind_pm_resume (&xe->late_bind); +xe_hwmon_resume (xe, true); + +if (IS_VF_CCS_READY (xe)) +xe_sriov_vf_ccs_register_context (xe); + out:xe_rpm_lockmap_release (xe);xe_pm_write_callback_task (xe,NULL );
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 07/10] drm/xe/hwmon: Restore fan user tables after resume
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] drm/xe: synchronous flush_work() in xe_late_bind_pm_resume() deadlocks resume - [Medium]…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [High] drm/xe: synchronous flush_work() in xe_late_bind_pm_resume() deadlocks resume
- [Medium] drm/xe/hwmon: xe_hwmon_resume() clears staged fan curve points on resume
- [Low] drm/xe/hwmon: duplicate xe_hwmon_fan_set_auto() fallback in xe_hwmon_resume()
--
commit 487a525936d402c4983c294401d28e7b960944fa
Author: Karthik Poosa <[email protected]>
drm/xe/hwmon: Restore fan user tables after resume
This commit saves active manual and full-speed fan tables before system suspend, runtime D3cold suspend, and FLR, and restores them on resume after waiting for late-bound fan-control firmware to reload.
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0
[ ... ]
Quoted 21 lines
drivers/gpu/drm/xe/xe_hwmon.c +21
-0+void xe_hwmon_resume (struct xe_device *xe,bool runtime) +{ +struct xe_hwmon *hwmon = xe->hwmon; +int fan; + +if (!hwmon || !xe->info.has_fan_control) +return ; + +if (runtime && !xe->d3cold.allowed) { +xe_dbg (xe,"d3cold not allowed, skipping fan user-table restore\n" ); +return ; + } + +mutex_lock (&hwmon->hwmon_lock); + +for (fan =0 ; fan <FAN_MAX ; fan++) { +struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; +int ret; + +if (!IS_FAN_ENABLED (hwmon, fan)) +continue ;
drivers/gpu/drm/xe/xe_hwmon.c void xe_hwmon_unregister(struct xe_device *xe) · line 3084
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+ +if (!fi->restore_user_table) { +xe_dbg (xe,"fan %d user table restore not required\n" , fan); +continue ; + } + +/* Re-program cached user-table settings for fans active before suspend. */ + ret =xe_hwmon_activate_user_fan_table (hwmon, fan, + fi->is_full_speed, +USER_FAN_TABLE );
[Severity: Medium]
Does calling xe_hwmon_activate_user_fan_table() here discard any in-progress staged fan curve points across suspend and resume?
Each write to pwmN_auto_pointM_temp or pwmN_auto_pointM_pwm holds a runtime PM reference only for that single sysfs write while recording progress in temp_staged and speed_staged. If the device enters runtime D3cold (or system suspend) between sysfs writes while a user fan table is already active, xe_hwmon_resume() calls xe_hwmon_activate_user_fan_table(), which unconditionally clears both staged bitmasks:
drivers/gpu/drm/xe/xe_hwmon.c:xe_hwmon_activate_user_fan_table() {
...
fi->fan_table[USER_FAN_TABLE].temp_staged = 0;
fi->fan_table[USER_FAN_TABLE].speed_staged = 0;
...
}Later sysfs writes to finish the curve then see missing prefix bits in xe_hwmon_update_user_fan_point() and silently fail to commit the new curve.
drivers/gpu/drm/xe/xe_hwmon.c void xe_hwmon_unregister(struct xe_device *xe) · line 3097
Quoted 13 lines
drivers/gpu/drm/xe/xe_hwmon.c +13
-0+if (ret) { +xe_warn (xe,"failed to restore fan %d user table after resume, ret=%d\n" , + fan, ret); + fi->fan_table[USER_FAN_TABLE ].point_count =0 ; + fi->restore_user_table = false; + ret =xe_hwmon_fan_set_auto (hwmon, fan); +if (ret) { +xe_warn (xe,"fan %d stock fallback failed, state unconfirmed, ret=%d\n" , + fan, ret); +continue ; + } +continue ; + }
[Severity: Low]
Does this error path duplicate the stock fallback that xe_hwmon_activate_user_fan_table() already performs?
xe_hwmon_suspend() only sets restore_user_table when point_count is within bounds, so xe_hwmon_activate_user_fan_table() only fails here if writing or verifying the table fails, in which case it has already cleared point_count and called xe_hwmon_fan_set_auto(hwmon, fan) before returning.
[ ... ]
Quoted 10 lines
drivers/gpu/drm/xe/xe_late_bind_fw.c +2
-0@@ -517,10 +517,17 @@ void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind)*/ void xe_late_bind_pm_resume (struct xe_late_bind *late_bind) { +struct xe_late_bind_fw *fan_control_fw; +bool fan_control_fw_pending;
drivers/gpu/drm/xe/xe_late_bind_fw.c void xe_late_bind_pm_suspend(struct xe_late_bind *late_bind) · line 531
Quoted 10 lines
drivers/gpu/drm/xe/xe_late_bind_fw.c +5
-0+if (!late_bind->component_added || late_bind->disable)return ; + fan_control_fw = &late_bind->late_bind_fw[XE_LB_FW_FAN_CONTROL ]; + fan_control_fw_pending = !!fan_control_fw->payload;xe_late_bind_fw_load (late_bind); +if (fan_control_fw_pending) +flush_work (&fan_control_fw->work); }
[Severity: High]
Does flushing fan_control_fw->work inside xe_late_bind_pm_resume() deadlock against the child MEI auxiliary device during both system resume and runtime D3cold resume, ultimately timing out and freeing fan_control_fw->payload?
On platforms such as Battlemage, heci_gsc_add_device() registers the xe.mei-gscfi auxiliary device with aux_dev->dev.parent = &pdev->dev. During system suspend, mei_gsc_pm_suspend() stops the MEI bus and unbinds the late-bind component, clearing late_bind->component.ops = NULL. During system resume, the PM core runs the parent xe_device_resume() callback before the child aux_dev->dev is allowed to resume:
PM resume context kworker (late_bind->wq)xe_device_resume()
xe_late_bind_pm_resume()
xe_late_bind_fw_load()
queue_work(..., &lbfw->work)
flush_work(&fan_control_fw->work)
xe_late_bind_work()
/* waits up to 20s for component.ops */
while (!late_bind->component.ops)
msleep(100);
/* mei_gsc_pm_resume() blocked on parent */
drmm_kfree(..., lbfw->payload);
lbfw->payload = NULL; <-- firmware lostRuntime resume from D3cold hits a similar dependency cycle:xe_pm_runtime_resume() runs while pdev->dev.power.runtime_status is RPM_RESUMING and blocks in flush_work(&fan_control_fw->work). xe_late_bind_work() calls push_payload() -> mei_lb_push_payload() -> mei_cldev_enable() -> mei_cl_connect(), which calls pm_runtime_get(&aux_dev->dev) and waits 15 seconds for mei_gsc_pm_runtime_resume(), while pm_wq cannot runtime-resume aux_dev->dev until its parent pdev->dev finishes RPM_RESUMING.
In both paths, resume stalls for 15 to 20 seconds, xe_late_bind_work() permanently frees fan_control_fw->payload until reboot, and xe_hwmon_resume() runs without the fan-control firmware loaded.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v5 8/10 drm/xe/hwmon: Refresh fan data after late binding
In reply to Karthik PoosaRefresh cached stock fan tables and maximum RPM for registered fans after fan-control firmware loads.
Serialize the refresh with hwmon registration and teardown. Flush late-bind work before releasing hwmon state, and protect fanN_max reads against concurrent max_rps updates.
v2:
- Compare lbfw->id with XE_LB_FW_FAN_CONTROL. (Soham)
- Use xe already in scope. (Soham)
- Spell out "late binding" in warnings. (Soham)
- Return an error from xe_hwmon_get_fan_enable_mask() and keep the old mask if the read fails.
- Start fans enabled after late binding in automatic mode.
v3:
- Serialize the refresh with hwmon registration and teardown. Flush late-bind work before releasing hwmon state, and protect fanN_max reads against concurrent max_rps updates.
--- drivers/gpu/drm/xe/xe_hwmon.c | 71 +++++++++++++++++++++++++--- drivers/gpu/drm/xe/xe_hwmon.h | 2 + drivers/gpu/drm/xe/xe_late_bind_fw.c | 3 ++ 3 files changed, 70 insertions(+), 6 deletions(-)
drivers/gpu/drm/xe/xe_hwmon.c +65 -6
@@ -16,6 +16,7 @@#include "regs/xe_pcode_regs.h" #include "xe_device.h" #include "xe_hwmon.h" +#include "xe_late_bind_fw.h" #include "xe_log.h" #include "xe_mmio.h" #include "xe_pcode.h"
@@ -259,6 +260,8 @@ struct xe_hwmon {struct device *hwmon_dev;/** @xe: Xe device */ struct xe_device *xe; +/** @registration_lock: serialize registration with late-binding updates */ +struct mutex registration_lock;/** @hwmon_lock: lock for rw attributes*/ struct mutex hwmon_lock;/** @scl_shift_power: pkg power unit */
@@ -293,6 +296,13 @@ struct xe_hwmon {const struct attribute_group *groups[3 ]; }; +static void xe_hwmon_flush_late_bind (void *arg) +{ +struct xe_device *xe = arg; + +xe_late_bind_pm_suspend (&xe->late_bind); +} +static inline int prepare_power_limit_param2 (const struct xe_hwmon *hwmon,int channel) {if (hwmon->read_power_limit_from_pcode[channel]) {
@@ -1808,7 +1818,6 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)if (!IS_FAN_ENABLED (hwmon, fan))continue ; - fi->pwm_enable_mode =XE_FAN_PWM_UNINITIALIZED ; fi->fan_table[STOCK_FAN_TABLE ].point_count =0 ; ret = xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_MAX_FAN_RPS, fan,
@@ -2480,7 +2489,9 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)case hwmon_fan_input:return xe_hwmon_fan_input_read (hwmon, channel, val);case hwmon_fan_max: +mutex_lock (&hwmon->hwmon_lock); *val =mul_u32_u32 (hwmon->fi[channel].max_rps,60 ); +mutex_unlock (&hwmon->hwmon_lock);return 0 ;default :return -EOPNOTSUPP ;
@@ -2948,9 +2959,21 @@ int xe_hwmon_register(struct xe_device *xe)if (ret)return ret; + ret =devm_mutex_init (dev, &hwmon->registration_lock); +if (ret) +return ret; + +/* Flush late-bind work before devm releases the hwmon state it may use. */ + ret =devm_add_action_or_reset (dev, xe_hwmon_flush_late_bind, xe); +if (ret) +return ret; + +guard (mutex)(&hwmon->registration_lock); +/* There's only one instance of hwmon per device */ hwmon->xe = xe; - xe->hwmon = hwmon; +/* Pair with the acquire load in xe_hwmon_fan_update_post_lb(). */ +smp_store_release (&xe->hwmon, hwmon); ret =xe_hwmon_get_preregistration_info (hwmon);if (ret)
@@ -2977,7 +3000,7 @@ int xe_hwmon_register(struct xe_device *xe)return 0 ; err_null_hwmon: - xe->hwmon =NULL ; +WRITE_ONCE (xe->hwmon,NULL );return ret; }
@@ -2990,11 +3013,21 @@ int xe_hwmon_register(struct xe_device *xe)*/ void xe_hwmon_unregister (struct xe_device *xe) { -if (!xe->hwmon) +struct xe_hwmon *hwmon; + +/* Stop updates before unregistering hwmon or unplugging the device. */ +xe_late_bind_pm_suspend (&xe->late_bind); + + hwmon =READ_ONCE (xe->hwmon); +if (!hwmon)return ; -hwmon_device_unregister (xe->hwmon->hwmon_dev); - xe->hwmon =NULL ; +mutex_lock (&hwmon->registration_lock); +if (READ_ONCE (xe->hwmon) == hwmon) { +hwmon_device_unregister (hwmon->hwmon_dev); +WRITE_ONCE (xe->hwmon,NULL ); + } +mutex_unlock (&hwmon->registration_lock); }/**
@@ -3103,4 +3136,30 @@ void xe_hwmon_resume(struct xe_device *xe, bool runtime)mutex_unlock (&hwmon->hwmon_lock); } +/** +* xe_hwmon_fan_update_post_lb - Update fan info after late binding +* @xe: xe device instance +* +* This function reads the number of fans and their stock table after late binding. +*/ +void xe_hwmon_fan_update_post_lb (struct xe_device *xe) +{ +/* Pair with the release store in xe_hwmon_register(). */ +struct xe_hwmon *hwmon =smp_load_acquire (&xe->hwmon); + +if (!hwmon || !xe->info.has_fan_control) +return ; + +guard (mutex)(&hwmon->registration_lock); +if (READ_ONCE (xe->hwmon) != hwmon) +return ; + +mutex_lock (&hwmon->hwmon_lock); + +if (xe_hwmon_read_fan_control_info (hwmon)) +xe_warn (hwmon->xe,"failed to read stock fan tables after late binding\n" ); + +mutex_unlock (&hwmon->hwmon_lock); +} +MODULE_IMPORT_NS ("INTEL_PMT_TELEMETRY" );
drivers/gpu/drm/xe/xe_hwmon.h +2 -0
@@ -15,11 +15,13 @@ int xe_hwmon_register(struct xe_device *xe);void xe_hwmon_unregister (struct xe_device *xe);void xe_hwmon_suspend (struct xe_device *xe,bool runtime);void xe_hwmon_resume (struct xe_device *xe,bool runtime); +void xe_hwmon_fan_update_post_lb (struct xe_device *xe);#else static inline int xe_hwmon_register (struct xe_device *xe) {return 0 ; };static inline void xe_hwmon_unregister (struct xe_device *xe) { }static inline void xe_hwmon_suspend (struct xe_device *xe,bool runtime) {}static inline void xe_hwmon_resume (struct xe_device *xe,bool runtime) {} +static inline void xe_hwmon_fan_update_post_lb (struct xe_device *xe) {}#endif #endif /* _XE_HWMON_H_ */
drivers/gpu/drm/xe/xe_late_bind_fw.c +3 -0
@@ -14,6 +14,7 @@#include "xe_configfs.h" #include "xe_device.h" +#include "xe_hwmon.h" #include "xe_late_bind_fw.h" #include "xe_pcode.h" #include "xe_pcode_api.h"
@@ -298,6 +299,8 @@ static void xe_late_bind_work(struct work_struct *work)if (!ret) {drm_dbg (&xe->drm,"Load %s firmware successful\n" , fw_id_to_name[lbfw->id]); +if (lbfw->id ==XE_LB_FW_FAN_CONTROL ) +xe_hwmon_fan_update_post_lb (xe); goto out; }
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 08/10] drm/xe/hwmon: Refresh fan data after late binding
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/xe/hwmon: refresh error in xe_hwmon_read_fan_control_info() wipes state - [Medium]…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] drm/xe/hwmon: refresh error in xe_hwmon_read_fan_control_info() wipes state
- [Medium] drm/xe/hwmon: circular locking dependency in xe_hwmon_unregister()
- [Low] drm/xe/hwmon: inaccurate kernel-doc on xe_hwmon_fan_update_post_lb()
--
commit 66dd9f8eb5bcfd27c5213f0a2c07a58daa0c1bb3
Author: Karthik Poosa <[email protected]>
drm/xe/hwmon: Refresh fan data after late binding
This commit refreshes cached stock fan tables and maximum RPM after fan-control firmware loads via late binding, and serializes the refresh with hwmon registration and teardown.
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-0
[ ... ]
drivers/gpu/drm/xe/xe_hwmon.c static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon) · line 1819
Quoted 6 lines
drivers/gpu/drm/xe/xe_hwmon.c +0
-1@@ -1806,7 +1816,6 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)if (!IS_FAN_ENABLED (hwmon, fan))continue ; - fi->pwm_enable_mode =XE_FAN_PWM_UNINITIALIZED ; fi->fan_table[STOCK_FAN_TABLE ].point_count =0 ;
[Severity: Medium]
When xe_hwmon_fan_update_post_lb() calls xe_hwmon_read_fan_control_info() after hwmon registration, does a pcode failure wipe the previously cached fi->fan_table[STOCK_FAN_TABLE].point_count and fi->max_rps?
Clearing point_count and overwriting fi->max_rps in place (which also passes the old cached fi->max_rps as the PCODE_DATA0 input to xe_pcode_read()) before verifying that the refresh succeeded leaves fi->pwm_enable_mode at XE_FAN_PWM_AUTO_STOCK_TABLE and the sysfs attributes visible, so subsequent reads of fanN_max return 0 and reads of pwmN fail with -ENODATA.
[ ... ]
Quoted 13 lines
drivers/gpu/drm/xe/xe_hwmon.c +7
-1@@ -2979,11 +3002,21 @@ int xe_hwmon_register(struct xe_device *xe)*/ void xe_hwmon_unregister (struct xe_device *xe) { -if (!xe->hwmon) +struct xe_hwmon *hwmon; + +/* Stop updates before unregistering hwmon or unplugging the device. */ +xe_late_bind_pm_suspend (&xe->late_bind); + + hwmon =READ_ONCE (xe->hwmon); +if (!hwmon)return ;
drivers/gpu/drm/xe/xe_hwmon.c int xe_hwmon_register(struct xe_device *xe) · line 3020
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +6
-2-hwmon_device_unregister (xe->hwmon->hwmon_dev); - xe->hwmon =NULL ; +mutex_lock (&hwmon->registration_lock); +if (READ_ONCE (xe->hwmon) == hwmon) { +hwmon_device_unregister (hwmon->hwmon_dev); +WRITE_ONCE (xe->hwmon,NULL ); + } +mutex_unlock (&hwmon->registration_lock); }
[Severity: Medium]
Does holding hwmon->registration_lock across hwmon_device_unregister() create a circular locking dependency in lockdep?
hwmon_device_unregister() drains active sysfs attributes under kn->dep_map, while hwmon sysfs callbacks (such as xe_hwmon_read()) acquire xe_pm_runtime_d3cold_map via xe_pm_runtime_get(). On resume, xe_pm_runtime_resume() holds xe_pm_runtime_d3cold_map while calling xe_late_bind_pm_resume() -> flush_work(&fan_control_fw->work), and xe_late_bind_work() now calls xe_hwmon_fan_update_post_lb(), which takes hwmon->registration_lock:
hwmon->registration_lock -> kn->dep_map -> xe_pm_runtime_d3cold_map -> (&fan_control_fw->work) -> hwmon->registration_lock
[ ... ]
Quoted 15 lines
drivers/gpu/drm/xe/xe_hwmon.c +15
-0+/** +* xe_hwmon_fan_update_post_lb - Update fan info after late binding +* @xe: xe device instance +* +* This function reads the number of fans and their stock table after late binding. +*/ +void xe_hwmon_fan_update_post_lb (struct xe_device *xe) +{ +/* Pair with the release store in xe_hwmon_register(). */ +struct xe_hwmon *hwmon =smp_load_acquire (&xe->hwmon); + +if (!hwmon || !xe->info.has_fan_control) +return ; + +guard (mutex)(&hwmon->registration_lock);
drivers/gpu/drm/xe/xe_hwmon.c void xe_hwmon_resume(struct xe_device *xe, bool runtime) · line 3163
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+if (READ_ONCE (xe->hwmon) != hwmon) +return ; + +mutex_lock (&hwmon->hwmon_lock); + +if (xe_hwmon_read_fan_control_info (hwmon)) +xe_warn (hwmon->xe,"failed to read stock fan tables after late binding\n" ); + +mutex_unlock (&hwmon->hwmon_lock); +}
[Severity: Low]
This isn't a bug, but the kernel-doc above says xe_hwmon_fan_update_post_lb() reads the number of fans, whereas it only calls xe_hwmon_read_fan_control_info() and does not call xe_hwmon_get_fan_enable_mask(). The v2 changelog in the commit message also mentions returning an error from xe_hwmon_get_fan_enable_mask() and keeping the old mask on failure, which is not part of this patch.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH v5 08/10] drm/xe/hwmon: Refresh fan data after late binding
In reply to Karthik PoosaHi Karthik,
Quoted 40 lines · Karthik Poosa
Refresh cached stock fan tables and maximum RPM for registered fans after fan-control firmware loads.
Serialize the refresh with hwmon registration and teardown. Flush late-bind work before releasing hwmon state, and protect
fanN_maxreads against concurrentmax_rpsupdates.v2:
- Comparelbfw->idwithXE_LB_FW_FAN_CONTROL. (Soham)
- Use xe already in scope. (Soham)
- Spell out "late binding" in warnings. (Soham)
- Return an error fromxe_hwmon_get_fan_enable_mask()and keep the old mask if the read fails.
- Start fans enabled after late binding in automatic mode.v3:
- Serialize the refresh with hwmon registration and teardown. Flush late-bind work before releasing hwmon state, and protectfanN_maxreads against concurrentmax_rpsupdates.Signed-off-by Karthik Poosa <[email protected]>--- drivers/gpu/drm/xe/xe_hwmon.c | 71 +++++++++++++++++++++++++--- drivers/gpu/drm/xe/xe_hwmon.h | 2 + drivers/gpu/drm/xe/xe_late_bind_fw.c | 3 ++ 3 files changed, 70 insertions(+), 6 deletions(-)drivers/gpu/drm/xe/xe_hwmon.c +1
-0@@ -16,6 +16,7 @@#include "regs/xe_pcode_regs.h" #include "xe_device.h" #include "xe_hwmon.h" +#include "xe_late_bind_fw.h" #include "xe_log.h" #include "xe_mmio.h" #include "xe_pcode.h"
drivers/gpu/drm/xe/xe_hwmon.c struct xe_hwmon { · line 263
Quoted 4 lines
drivers/gpu/drm/xe/xe_hwmon.c +1
-0@@ -259,6 +260,8 @@ struct xe_hwmon {struct device *hwmon_dev;/** @xe: Xe device */ struct xe_device *xe; +/** @registration_lock: serialize registration with late-binding updates */
"late-binding", "late-bind", "late binding" and "lb" are all used in this patch. Could one term be used throughout?
Quoted 27 lines
drivers/gpu/drm/xe/xe_hwmon.c +8
-1+struct mutex registration_lock;/** @hwmon_lock: lock for rw attributes*/ struct mutex hwmon_lock;/** @scl_shift_power: pkg power unit */ @@ -293,6 +296,13 @@ struct xe_hwmon {const struct attribute_group *groups[3 ]; }; +static void xe_hwmon_flush_late_bind (void *arg) +{ +struct xe_device *xe = arg; + +xe_late_bind_pm_suspend (&xe->late_bind); +} +static inline int prepare_power_limit_param2 (const struct xe_hwmon *hwmon,int channel) {if (hwmon->read_power_limit_from_pcode[channel]) {@@ -1808,7 +1818,6 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)if (!IS_FAN_ENABLED (hwmon, fan))continue ; - fi->pwm_enable_mode =XE_FAN_PWM_UNINITIALIZED ; fi->fan_table[STOCK_FAN_TABLE ].point_count =0 ; ret = xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_MAX_FAN_RPS, fan,
drivers/gpu/drm/xe/xe_hwmon.c xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) · line 2494
Quoted 6 lines
drivers/gpu/drm/xe/xe_hwmon.c +2
-0@@ -2480,7 +2489,9 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)case hwmon_fan_input:return xe_hwmon_fan_input_read (hwmon, channel, val);case hwmon_fan_max: +mutex_lock (&hwmon->hwmon_lock); *val =mul_u32_u32 (hwmon->fi[channel].max_rps,60 ); +mutex_unlock (&hwmon->hwmon_lock);
Could scoped_guard(mutex, ...) be used here?
Quoted 78 lines
drivers/gpu/drm/xe/xe_hwmon.c +41
-5return 0 ;default :return -EOPNOTSUPP ;@@ -2948,9 +2959,21 @@ int xe_hwmon_register(struct xe_device *xe)if (ret)return ret; + ret =devm_mutex_init (dev, &hwmon->registration_lock); +if (ret) +return ret; + +/* Flush late-bind work before devm releases the hwmon state it may use. */ + ret =devm_add_action_or_reset (dev, xe_hwmon_flush_late_bind, xe); +if (ret) +return ret; + +guard (mutex)(&hwmon->registration_lock); +/* There's only one instance of hwmon per device */ hwmon->xe = xe; - xe->hwmon = hwmon; +/* Pair with the acquire load in xe_hwmon_fan_update_post_lb(). */ +smp_store_release (&xe->hwmon, hwmon); ret =xe_hwmon_get_preregistration_info (hwmon);if (ret)@@ -2977,7 +3000,7 @@ int xe_hwmon_register(struct xe_device *xe)return 0 ; err_null_hwmon: - xe->hwmon =NULL ; +WRITE_ONCE (xe->hwmon,NULL );return ret; }@@ -2990,11 +3013,21 @@ int xe_hwmon_register(struct xe_device *xe)*/ void xe_hwmon_unregister (struct xe_device *xe) { -if (!xe->hwmon) +struct xe_hwmon *hwmon; + +/* Stop updates before unregistering hwmon or unplugging the device. */ +xe_late_bind_pm_suspend (&xe->late_bind); + + hwmon =READ_ONCE (xe->hwmon); +if (!hwmon)return ; -hwmon_device_unregister (xe->hwmon->hwmon_dev); - xe->hwmon =NULL ; +mutex_lock (&hwmon->registration_lock); +if (READ_ONCE (xe->hwmon) == hwmon) { +hwmon_device_unregister (hwmon->hwmon_dev); +WRITE_ONCE (xe->hwmon,NULL ); + } +mutex_unlock (&hwmon->registration_lock); }/** @@ -3103,4 +3136,30 @@ void xe_hwmon_resume(struct xe_device *xe, bool runtime)mutex_unlock (&hwmon->hwmon_lock); } +/** +* xe_hwmon_fan_update_post_lb - Update fan info after late binding +* @xe: xe device instance +* +* This function reads the number of fans and their stock table after late binding. +*/ +void xe_hwmon_fan_update_post_lb (struct xe_device *xe) +{ +/* Pair with the release store in xe_hwmon_register(). */ +struct xe_hwmon *hwmon =smp_load_acquire (&xe->hwmon); + +if (!hwmon || !xe->info.has_fan_control) +return ; +
drivers/gpu/drm/xe/xe_hwmon.c void xe_hwmon_resume(struct xe_device *xe, bool runtime) · line 3162
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+guard (mutex)(&hwmon->registration_lock); +if (READ_ONCE (xe->hwmon) != hwmon) +return ; + +mutex_lock (&hwmon->hwmon_lock); + +if (xe_hwmon_read_fan_control_info (hwmon)) +xe_warn (hwmon->xe,"failed to read stock fan tables after late binding\n" ); + +mutex_unlock (&hwmon->hwmon_lock);
Could scoped_guard(mutex, ...) be used here?
Regards,
Soham
Quoted 42 lines
drivers/gpu/drm/xe/xe_hwmon.c +2
-0+} +MODULE_IMPORT_NS ("INTEL_PMT_TELEMETRY" );drivers/gpu/drm/xe/xe_hwmon.h +2
-0@@ -15,11 +15,13 @@ int xe_hwmon_register(struct xe_device *xe);void xe_hwmon_unregister (struct xe_device *xe);void xe_hwmon_suspend (struct xe_device *xe,bool runtime);void xe_hwmon_resume (struct xe_device *xe,bool runtime); +void xe_hwmon_fan_update_post_lb (struct xe_device *xe);#else static inline int xe_hwmon_register (struct xe_device *xe) {return 0 ; };static inline void xe_hwmon_unregister (struct xe_device *xe) { }static inline void xe_hwmon_suspend (struct xe_device *xe,bool runtime) {}static inline void xe_hwmon_resume (struct xe_device *xe,bool runtime) {} +static inline void xe_hwmon_fan_update_post_lb (struct xe_device *xe) {}#endif #endif /* _XE_HWMON_H_ */ drivers/gpu/drm/xe/xe_late_bind_fw.c +3
-0@@ -14,6 +14,7 @@#include "xe_configfs.h" #include "xe_device.h" +#include "xe_hwmon.h" #include "xe_late_bind_fw.h" #include "xe_pcode.h" #include "xe_pcode_api.h" @@ -298,6 +299,8 @@ static void xe_late_bind_work(struct work_struct *work)if (!ret) {drm_dbg (&xe->drm,"Load %s firmware successful\n" , fw_id_to_name[lbfw->id]); +if (lbfw->id ==XE_LB_FW_FAN_CONTROL ) +xe_hwmon_fan_update_post_lb (xe); goto out; }
PATCH v5 9/10 drm/xe: Expose tjmax_fan_control_enable device sysfs
In reply to Karthik PoosaAdd a device attribute to read and configure firmware fan control, which forces maximum acoustic PWM as SoC VR temperatures approach their critical thresholds.
--- .../ABI/testing/sysfs-driver-intel-xe-gpu | 15 ++++ drivers/gpu/drm/xe/xe_device_sysfs.c | 76 +++++++++++++++++++ drivers/gpu/drm/xe/xe_pcode_api.h | 2 + 3 files changed, 93 insertions(+)
Documentation/ABI/testing/sysfs-driver-intel-xe-gpu +15 -0
@@ -21,6 +21,21 @@ Description: This sysfs file is present only on Crescent Island devices. It is readable by all users. +What: /sys/bus/pci/drivers/xe/.../tjmax_fan_control_enable +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: + RW. Firmware thermal fan control mode. + + Write 1 to enable or 0 to disable the mode that forces maximum + acoustic PWM as SoC temperature approaches shutdown or GDDR/VR + temperature approaches its thermal maximum. Reads return the + status reported by firmware. + + This sysfs file is present only on devices that support + this command. + What: /sys/bus/pci/drivers/xe/.../tile<N>/memory/max_freq Date: October 2026 KernelVersion: 7.5
drivers/gpu/drm/xe/xe_device_sysfs.c +76 -0
93 lines not on this page · raw message
drivers/gpu/drm/xe/xe_pcode_api.h +2 -0
@@ -95,6 +95,8 @@#define FSC_READ_FAN_TABLE 0x7#define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0)#define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8) +#define FSC_WRITE_TJMAX_FAN_CONTROL_MODE 0x8 +#define FSC_READ_TJMAX_FAN_CONTROL_MODE 0x9#define PCODE_SCRATCH (x) XE_REG(0x138320 + ((x) * 4))/* PCODE_SCRATCH0 */
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v5 09/10] drm/xe: Expose tjmax_fan_control_enable device sysfs
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/xe: tjmax_fan_control_enable exposed as no-op on SR-IOV VFs - [Medium] drm/xe: uninitialized…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/xe: tjmax_fan_control_enable exposed as no-op on SR-IOV VFs
- [Medium] drm/xe: uninitialized val passed to xe_pcode_read() in fan_control_attr_is_visible()
--
commit f041e7b8d44d672ec8e023036136e0162ee46779
Author: Karthik Poosa <[email protected]>
drm/xe: Expose tjmax_fan_control_enable device sysfs
This commit adds a read-write tjmax_fan_control_enable sysfs attribute to read and configure the firmware TjMax fan control mode via PCODE mailbox commands.
Quoted 4 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +0
-0
[ ... ]
Quoted 1 line
drivers/gpu/drm/xe/xe_device_sysfs.c +0
-0@@ -203,6 +206,73 @@ static const struct attribute_group late_bind_attr_group = {
[ ... ]
Quoted 5 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +5
-0+static umode_t fan_control_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ +struct device *dev =kobj_to_dev (kobj); +struct xe_device *xe =pdev_to_xe_device (to_pci_dev (dev));
drivers/gpu/drm/xe/xe_device_sysfs.c static const struct attribute_group late_bind_attr_group = { · line 269
Quoted 10 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +10
-0+u32 val; +int ret; + +guard (xe_pm_runtime)(xe); + ret =xe_pcode_read (xe_device_get_root_tile (xe), +PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_READ_TJMAX_FAN_CONTROL_MODE ,0 ), + &val,NULL ); + +return ret ?0 : attr->mode; +}
[Severity: Medium]
Should val be initialized to 0 before calling xe_pcode_read(), as in tjmax_fan_control_enable_show()?
xe_pcode_read() -> pcode_mailbox_rw() -> __pcode_mailbox_rw() treats val0 as an in/out argument and unconditionally writes *data0 to PCODE_DATA0 before issuing the mailbox command:
drivers/gpu/drm/xe/xe_pcode.c:__pcode_mailbox_rw() {
...
xe_mmio_write32(mmio, PCODE_DATA0, *data0);
xe_mmio_write32(mmio, PCODE_DATA1, data1 ? *data1 : 0);
xe_mmio_write32(mmio, PCODE_MAILBOX, PCODE_READY | mbox);
...
}Leaving val uninitialized writes stack garbage into PCODE_DATA0 during driver probe, triggering KMSAN uninit-value warnings and risking command rejection if firmware checks the data register.
[ ... ]
drivers/gpu/drm/xe/xe_device_sysfs.c int xe_device_sysfs_init(struct xe_device *xe) · line 508
Quoted 12 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +6
-0@@ -428,5 +498,11 @@ int xe_device_sysfs_init(struct xe_device *xe)return ret; } +if (xe->info.has_fan_control) { + ret =devm_device_add_group (dev, &fan_control_attr_group); +if (ret) +return ret; + } +return 0 ; }
[Severity: Medium]
Can fan_control_attr_group be exposed on SR-IOV VFs where PCODE access is disabled?
On platforms with both has_fan_control and has_sriov (such as Battlemage), vf_update_device_info() sets xe->info.skip_pcode = 1 but leaves xe->info.has_fan_control enabled. Because pcode_mailbox_rw() immediately returns 0 when skip_pcode is set, fan_control_attr_is_visible() sees ret == 0 and exposes tjmax_fan_control_enable on VFs, where reads report a fabricated value and writes silently succeed as no-ops. Guarding registration with !IS_SRIOV_VF(xe) (or !xe->info.skip_pcode), like auto_link_downgrade_attr_group and late_bind_attr_group above, would avoid registering it on VFs.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
Re: [PATCH v5 09/10] drm/xe: Expose tjmax_fan_control_enable device sysfs
In reply to Karthik PoosaHi Karthik,
Quoted 3 lines · Karthik Poosa
Add a device attribute to read and configure firmware fan control, which forces maximum acoustic PWM as SoC VR temperatures approach their critical thresholds.
The commit message says "SoC VR temperatures", the ABI doc says "SoC temperature ... or GDDR/VR temperature", and the DOC comment says "TjMax". Since this is ABI, could one wording be used in all three places?
Quoted 57 lines
Signed-off-by Karthik Poosa <[email protected]>--- .../ABI/testing/sysfs-driver-intel-xe-gpu | 15 ++++ drivers/gpu/drm/xe/xe_device_sysfs.c | 76 +++++++++++++++++++ drivers/gpu/drm/xe/xe_pcode_api.h | 2 + 3 files changed, 93 insertions(+)Documentation/ABI/testing/sysfs-driver-intel-xe-gpu +15
-0@@ -21,6 +21,21 @@ Description: This sysfs file is present only on Crescent Island devices. It is readable by all users. +What: /sys/bus/pci/drivers/xe/.../tjmax_fan_control_enable +Date: November 2026 +KernelVersion: 7.5 +Contact: [email protected] +Description: + RW. Firmware thermal fan control mode. + + Write 1 to enable or 0 to disable the mode that forces maximum + acoustic PWM as SoC temperature approaches shutdown or GDDR/VR + temperature approaches its thermal maximum. Reads return the + status reported by firmware. + + This sysfs file is present only on devices that support + this command. + What: /sys/bus/pci/drivers/xe/.../tile<N>/memory/max_freq Date: October 2026 KernelVersion: 7.5drivers/gpu/drm/xe/xe_device_sysfs.c +8
-0@@ -35,6 +35,9 @@* lb_voltage_regulator_version - Voltage regulator version provisioned by late * binding. Exposed only if supported by the device. * +* tjmax_fan_control_enable - Report/change firmware TjMax fan control mode. +* Exposed only if supported by the device. +* * shrinker_non_purgeable_seeks - Report/change the cost, relative to * purgeable buffer objects, of recreating non-purgeable buffer objects * reclaimed by the shrinker. Higher values reduce reclaim pressure on @@ -203,6 +206,73 @@ static const struct attribute_group late_bind_attr_group = { .is_visible = late_bind_attr_is_visible, }; +static ssize_t +tjmax_fan_control_enable_show (struct device *dev,struct device_attribute *attr,char *buf) +{ +struct xe_device *xe =pdev_to_xe_device (to_pci_dev (dev)); +u32 val =0 ;
drivers/gpu/drm/xe/xe_device_sysfs.c static const struct attribute_group late_bind_attr_group = { · line 223
Quoted 10 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +10
-0+int ret; + +guard (xe_pm_runtime)(xe); + ret =xe_pcode_read (xe_device_get_root_tile (xe), +PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_READ_TJMAX_FAN_CONTROL_MODE ,0 ), + &val,NULL ); +drm_dbg (&xe->drm,"pcode READ_TJMAX_FAN_CONTROL_MODE: val %#x, ret %d\n" , + ret ?0 : val, ret); + +return ret ?:sysfs_emit (buf,"%u\n" , val);
The raw firmware value is printed as is. Can firmware set any bits other than bit 0? If so, should a mask be applied, so that the ABI reports only 0 or 1 ?
Quoted 35 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +35
-0+} + +static ssize_t +tjmax_fan_control_enable_store (struct device *dev,struct device_attribute *attr, +const char *buf,size_t count) +{ +struct xe_device *xe =pdev_to_xe_device (to_pci_dev (dev)); +u32 val; +int ret; + + ret =kstrtou32 (buf,0 , &val); +if (ret) +return ret; +if (val >1 ) +return -EINVAL ; + +guard (xe_pm_runtime)(xe); + ret =xe_pcode_write (xe_device_get_root_tile (xe), +PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_WRITE_TJMAX_FAN_CONTROL_MODE ,0 ), + val); +drm_dbg (&xe->drm,"pcode WRITE_TJMAX_FAN_CONTROL_MODE: val %u, ret %d\n" , val, ret); + +return ret ?: count; +} +static DEVICE_ATTR_RW (tjmax_fan_control_enable); + +static struct attribute *fan_control_attrs[] = { + &dev_attr_tjmax_fan_control_enable.attr, +NULL +}; + +static umode_t fan_control_attr_is_visible (struct kobject *kobj, +struct attribute *attr,int n) +{ +struct device *dev =kobj_to_dev (kobj);
drivers/gpu/drm/xe/xe_device_sysfs.c static const struct attribute_group late_bind_attr_group = { · line 268
Quoted 10 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +10
-0+struct xe_device *xe =pdev_to_xe_device (to_pci_dev (dev)); +u32 val; +int ret; + +guard (xe_pm_runtime)(xe); + ret =xe_pcode_read (xe_device_get_root_tile (xe), +PCODE_MBOX (FAN_SPEED_CONTROL ,FSC_READ_TJMAX_FAN_CONTROL_MODE ,0 ), + &val,NULL ); + +return ret ?0 : attr->mode;
Only support for the read command is checked here. Does a working read also mean that the write command is supported? If not, the attribute would show as writable, but writes would fail.
Regards,
Soham
Quoted 35 lines
drivers/gpu/drm/xe/xe_device_sysfs.c +13
-0+} + +static const struct attribute_group fan_control_attr_group = { + .attrs = fan_control_attrs, + .is_visible = fan_control_attr_is_visible, +}; +/** * DOC: PCIe Gen5 Limitations * @@ -428,5 +498,11 @@ int xe_device_sysfs_init(struct xe_device *xe)return ret; } +if (xe->info.has_fan_control) { + ret =devm_device_add_group (dev, &fan_control_attr_group); +if (ret) +return ret; + } +return 0 ; }drivers/gpu/drm/xe/xe_pcode_api.h +2
-0@@ -95,6 +95,8 @@#define FSC_READ_FAN_TABLE 0x7#define FAN_CONTROL_POINT_TEMP_MASK REG_GENMASK(7, 0)#define FAN_CONTROL_POINT_SPEED_MASK REG_GENMASK(15, 8) +#define FSC_WRITE_TJMAX_FAN_CONTROL_MODE 0x8 +#define FSC_READ_TJMAX_FAN_CONTROL_MODE 0x9#define PCODE_SCRATCH (x) XE_REG(0x138320 + ((x) * 4))/* PCODE_SCRATCH0 */
PATCH v5 10/10 drm/xe/hwmon: Add kernel-doc for fan control
In reply to Karthik PoosaAdd kernel-doc for xe hwmon fan control and describe the fan control model built around firmware stock tables and driver-managed user tables.
Document the exposed sysfs files for fan speed, maximum speed, pwm control, pwm mode selection, and per-point fan curve temperature/PWM programming.
This makes the hwmon fan control userspace interface easier to discover and understand.
v2:
- Clarify the registration-time visibility requirements.
- Document how late binding affects existing fan attributes.
--- drivers/gpu/drm/xe/xe_hwmon.c | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
drivers/gpu/drm/xe/xe_hwmon.c +56 -0
@@ -140,6 +140,62 @@ struct xe_hwmon_energy_info {long accum_energy; }; +/** +* DOC: Xe fan control +* +* Xe fan control is exposed through the hwmon pwm and fan interfaces when the +* platform advertises PCODE-backed fan management support. +* +* Attribute visibility is determined during hwmon registration. ``fanN_max`` +* requires maximum fan speed data, while ``pwmN`` and ``pwmN_enable`` require a +* readable stock fan table. Late binding refreshes cached data for existing +* fans but does not create attributes that were hidden at registration. +* +* The implementation tracks two fan tables per fan: +* +* - A stock table read from firmware through PCODE. +* - A user table cached in the driver and programmed back through PCODE. +* +* The pwmN_enable sysfs value selects how those tables are used: +* +* - 0 (``XE_FAN_PWM_FULL_SPEED``) programs a two-point user table at 100 +* percent duty cycle as a full-speed override. +* - 1 (``XE_FAN_PWM_MANUAL_USER_TABLE``) enables the user table for manual +* control. +* - 2 (``XE_FAN_PWM_AUTO_STOCK_TABLE``) restores automatic control using the +* stock firmware table. +* +* The fan-control sysfs files are: +* +* - ``fanN_input`` reports the measured fan speed in RPM. +* - ``fanN_max`` reports the maximum supported fan speed in RPM. +* - ``pwmN`` reads or sets the manual PWM duty cycle in the hwmon 0..255 +* range. +* - ``pwmN_enable`` selects the mode described above. +* - ``pwmN_auto_pointM_temp`` exposes the temperature threshold for user-table +* point ``M`` in millidegrees Celsius. +* - ``pwmN_auto_pointM_pwm`` exposes the PWM value for user-table point ``M`` +* in the hwmon 0..255 range. +* +* Writes to ``pwmN``, ``pwmN_auto_pointM_temp`` and ``pwmN_auto_pointM_pwm`` +* are accepted only while ``pwmN_enable`` is 1; otherwise they fail with +* -EINVAL. Firmware stores duty cycle in percent, so PWM values read back +* rounded to the nearest percent step. Nonzero curve PWM writes are kept at +* least 1 percent so rounding cannot turn them into an end marker. +* +* Writes to ``pwmN_auto_pointM_temp`` and ``pwmN_auto_pointM_pwm`` are staged +* in the driver, so intermediate writes never reach firmware as a partial +* curve. The staged curve is committed once points 1..K all have both a +* temperature and a PWM value and either point K+1 is set to (0, 0) or K is +* the last supported point. The (0, 0) end marker is not part of the curve. +* A curve must have at least two points, and temperature and PWM must not +* decrease from one point to the next; otherwise the completing write fails +* with -EINVAL. +* +* Writes to ``pwmN`` replace the user table with a two-point table at a +* constant duty cycle. +*/ +/** * enum xe_fan_pwm_enable_mode - fan PWM enable modes */
Signature · 1 line
2.34.1
Re: [PATCH v5 10/10] drm/xe/hwmon: Add kernel-doc for fan control
Hi Karthik,
Quoted 27 lines · Karthik Poosa
Add kernel-doc for xe hwmon fan control and describe the fan control model built around firmware stock tables and driver-managed user tables.
Document the exposed sysfs files for fan speed, maximum speed, pwm control, pwm mode selection, and per-point fan curve temperature/PWM programming.
This makes the hwmon fan control userspace interface easier to discover and understand.
v2:
- Clarify the registration-time visibility requirements.
- Document how late binding affects existing fan attributes.Signed-off-by Karthik Poosa <[email protected]>--- drivers/gpu/drm/xe/xe_hwmon.c | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)drivers/gpu/drm/xe/xe_hwmon.c +0
-0@@ -140,6 +140,62 @@ struct xe_hwmon_energy_info {long accum_energy; };
drivers/gpu/drm/xe/xe_hwmon.c struct xe_hwmon_energy_info { · line 152
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+/** +* DOC: Xe fan control +* +* Xe fan control is exposed through the hwmon pwm and fan interfaces when the +* platform advertises PCODE-backed fan management support. +* +* Attribute visibility is determined during hwmon registration. ``fanN_max`` +* requires maximum fan speed data, while ``pwmN`` and ``pwmN_enable`` require a +* readable stock fan table. Late binding refreshes cached data for existing +* fans but does not create attributes that were hidden at registration.
pwmN_auto_pointM_* stay visible without a stock table, but pwmN_enable is hidden, so writes always fail. Should they also be hidden?
Quoted 16 lines
drivers/gpu/drm/xe/xe_hwmon.c +16
-0+* +* The implementation tracks two fan tables per fan: +* +* - A stock table read from firmware through PCODE. +* - A user table cached in the driver and programmed back through PCODE. +* +* The pwmN_enable sysfs value selects how those tables are used: +* +* - 0 (``XE_FAN_PWM_FULL_SPEED``) programs a two-point user table at 100 +* percent duty cycle as a full-speed override. +* - 1 (``XE_FAN_PWM_MANUAL_USER_TABLE``) enables the user table for manual +* control. +* - 2 (``XE_FAN_PWM_AUTO_STOCK_TABLE``) restores automatic control using the +* stock firmware table. +* +* The fan-control sysfs files are:
drivers/gpu/drm/xe/xe_hwmon.c struct xe_hwmon_energy_info { · line 178
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+* +* - ``fanN_input`` reports the measured fan speed in RPM. +* - ``fanN_max`` reports the maximum supported fan speed in RPM. +* - ``pwmN`` reads or sets the manual PWM duty cycle in the hwmon 0..255 +* range. +* - ``pwmN_enable`` selects the mode described above. +* - ``pwmN_auto_pointM_temp`` exposes the temperature threshold for user-table +* point ``M`` in millidegrees Celsius. +* - ``pwmN_auto_pointM_pwm`` exposes the PWM value for user-table point ``M`` +* in the hwmon 0..255 range.
In mode 2, reads return stock-table points. Should "user-table" be "active-table"?
Quoted 5 lines
drivers/gpu/drm/xe/xe_hwmon.c +5
-0+* +* Writes to ``pwmN``, ``pwmN_auto_pointM_temp`` and ``pwmN_auto_pointM_pwm`` +* are accepted only while ``pwmN_enable`` is 1; otherwise they fail with +* -EINVAL. Firmware stores duty cycle in percent, so PWM values read back +* rounded to the nearest percent step. Nonzero curve PWM writes are kept at
drivers/gpu/drm/xe/xe_hwmon.c struct xe_hwmon_energy_info { · line 193
Quoted 10 lines
drivers/gpu/drm/xe/xe_hwmon.c +10
-0+* least 1 percent so rounding cannot turn them into an end marker. +* +* Writes to ``pwmN_auto_pointM_temp`` and ``pwmN_auto_pointM_pwm`` are staged +* in the driver, so intermediate writes never reach firmware as a partial +* curve. The staged curve is committed once points 1..K all have both a +* temperature and a PWM value and either point K+1 is set to (0, 0) or K is +* the last supported point. The (0, 0) end marker is not part of the curve. +* A curve must have at least two points, and temperature and PWM must not +* decrease from one point to the next; otherwise the completing write fails +* with -EINVAL.
Could it be noted that a failed commit drops all staged points, and a firmware reject falls back to mode 2?
Regards,
Soham
Quoted 8 lines
drivers/gpu/drm/xe/xe_hwmon.c +5
-0+* +* Writes to ``pwmN`` replace the user table with a two-point table at a +* constant duty cycle. +*/ +/** * enum xe_fan_pwm_enable_mode - fan PWM enable modes */
Patchwork
CI✗ CI.KUnit: failure for drm/xe/hwmon: Add fan control support (rev2)
In reply to Karthik Poosa== Series Details ==
== Series Details ==
Series: drm/xe/hwmon: Add fan control support (rev2)
URL : https://patchwork.freedesktop.org/series/179435/
State : failure
== Summary ==
+ trap cleanup EXIT
+ kunitconfigs=('/kernel/drivers/gpu/tests/.kunitconfig' '/kernel/drivers/gpu/drm/xe/.kunitconfig' '/kernel/drivers/gpu/drm/tests/.kunitconfig' '/kernel/drivers/gpu/drm/ttm/tests/.kunitconfig' '/kernel/drivers/dma-buf/.kunitconfig')
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/tests/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/tests/.kunitconfig
[06:13:18] Configuring KUnit Kernel ...
Generating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [06:13:23] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48 [06:13:44] Starting KUnit Kernel (1/1)... [06:13:44] ============================================================ Running tests with: $ .kunit/linux kunit.enable=1 mem=1G console=tty kunit_shutdown=halt [06:13:44] ================= gpu_buddy (15 subtests) ================== [06:13:44] [PASSED] gpu_test_buddy_alloc_limit [06:13:44] [PASSED] gpu_test_buddy_alloc_optimistic [06:13:44] [PASSED] gpu_test_buddy_alloc_pessimistic [06:13:44] [PASSED] gpu_test_buddy_alloc_pathological [06:13:44] [PASSED] gpu_test_buddy_alloc_contiguous [06:13:44] [PASSED] gpu_test_buddy_alloc_clear [06:13:44] [PASSED] gpu_test_buddy_alloc_range [06:13:44] [PASSED] gpu_test_buddy_alloc_range_bias [06:13:44] [PASSED] gpu_test_buddy_alloc_range_clear_guard [06:13:45] [PASSED] gpu_test_buddy_fragmentation_performance [06:13:46] [PASSED] gpu_test_buddy_dirty_tracker_performance [06:13:46] [PASSED] gpu_test_buddy_alloc_exceeds_max_order [06:13:46] [PASSED] gpu_test_buddy_offset_aligned_allocation [06:13:46] [PASSED] gpu_test_buddy_subtree_offset_alignment_stress [06:13:46] [PASSED] gpu_test_buddy_addr_to_block [06:13:46] ==================== [PASSED] gpu_buddy ==================== [06:13:46] ============================================================ [06:13:46] Testing complete. Ran 15 tests: passed: 15 [06:13:46] Elapsed time: 27.769s total, 5.110s configuring, 20.641s building, 1.985s running
+ for kcfg in "${kunitconfigs[@]}"
+ [[ ! -f /kernel/drivers/gpu/drm/xe/.kunitconfig ]]
+ /kernel/tools/testing/kunit/kunit.py run --kunitconfig /kernel/drivers/gpu/drm/xe/.kunitconfig ERROR:root:../drivers/gpu/drm/xe/xe_hwmon.c:3096:6: error: redefinition of ‘xe_hwmon_unregister’ 3096 | void xe_hwmon_unregister(struct xe_device *xe)
| ^~~~~~~~~~~~~~~~~~~
../drivers/gpu/drm/xe/xe_hwmon.c:3070:6: note: previous definition of ‘xe_hwmon_unregister’ with type ‘void(struct xe_device *)’
3070 | void xe_hwmon_unregister(struct xe_device *xe)
| ^~~~~~~~~~~~~~~~~~~make[7]: *** [../scripts/Makefile.build:290: drivers/gpu/drm/xe/xe_hwmon.o] Error 1 make[7]: *** Waiting for unfinished jobs....
make[6]: *** [../scripts/Makefile.build:572: drivers/gpu/drm/xe] Error 2 make[5]: *** [../scripts/Makefile.build:572: drivers/gpu/drm] Error 2 make[4]: *** [../scripts/Makefile.build:572: drivers/gpu] Error 2 make[3]: *** [../scripts/Makefile.build:572: drivers] Error 2
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [/kernel/Makefile:2244: .] Error 2
make[1]: *** [/kernel/Makefile:248: __sub-make] Error 2
make: *** [Makefile:248: __sub-make] Error 2
[06:13:46] Configuring KUnit Kernel ...
Regenerating .config ...
Populating config with:
$ make ARCH=um O=.kunit olddefconfig [06:13:48] Building KUnit Kernel ... Populating config with: $ make ARCH=um O=.kunit olddefconfig Building with: $ make all compile_commands.json scripts_gdb ARCH=um O=.kunit --jobs=48 + cleanup ++ stat -c %u:%g /kernel + chown -R 1003:1003 /kernel