Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Karthik Poosa <karthik.poosa@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <anshuman.gupta@intel.com>,
	<badal.nilawar@intel.com>, <raag.jadav@intel.com>,
	<soham.purkait@intel.com>
Subject: Re: [PATCH v9 09/11] drm/xe/hwmon: Restore fan user tables after resume
Date: Wed, 2 Dec 2026 17:29:26 -0500	[thread overview]
Message-ID: <axCbxtCjsWG_4b5i@intel.com> (raw)
In-Reply-To: <20261202195221.1862825-10-karthik.poosa@intel.com>

On Thu, Dec 03, 2026 at 01:22:19AM +0530, Karthik Poosa wrote:
> Preserve active manual and full-speed fan tables and
> tjmax_fan_control_enable across system suspend, runtime D3cold, and FLR.
> 
> On resume, restore the cached table without waiting for the late-bound
> fan-control firmware, which reloads asynchronously. If restoration fails,
> fall back to stock fan control.
> 
> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

> ---
> 
> 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.
> 
> v5:
>  - Do not flush the late-binding work from xe_late_bind_pm_resume();
>    it can deadlock against the MEI device resume. (sashiko)
>  - Drop the duplicate stock fallback in xe_hwmon_resume(). (sashiko)
> 
> v6: Preserve fan TjMax control across suspend and resume. (Soham)
> 
>  drivers/gpu/drm/xe/xe_device.c    |   3 +
>  drivers/gpu/drm/xe/xe_hwmon.c     | 145 ++++++++++++++++++++++++++++++
>  drivers/gpu/drm/xe/xe_hwmon.h     |   4 +
>  drivers/gpu/drm/xe/xe_pcode_api.h |   6 +-
>  drivers/gpu/drm/xe/xe_pm.c        |  11 ++-
>  5 files changed, 163 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
> index 86de5f183c0a..d11e01ce50ca 100644
> --- a/drivers/gpu/drm/xe/xe_device.c
> +++ b/drivers/gpu/drm/xe/xe_device.c
> @@ -1425,6 +1425,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);
>  
> @@ -1555,6 +1557,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;
>  }
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index e0a0c0ba41b7..94825d1f2928 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> @@ -153,6 +153,18 @@ enum xe_fan_pwm_enable_mode {
>  	XE_FAN_PWM_UNINITIALIZED = 0xff,
>  };
>  
> +/**
> + * enum xe_tjmax_fan_control_state - saved TjMax fan-control state
> + */
> +enum xe_tjmax_fan_control_state {
> +	/** @XE_TJMAX_FAN_CONTROL_UNKNOWN: no state to restore */
> +	XE_TJMAX_FAN_CONTROL_UNKNOWN,
> +	/** @XE_TJMAX_FAN_CONTROL_DISABLED: state was disabled before suspend */
> +	XE_TJMAX_FAN_CONTROL_DISABLED,
> +	/** @XE_TJMAX_FAN_CONTROL_ENABLED: state was enabled before suspend */
> +	XE_TJMAX_FAN_CONTROL_ENABLED,
> +};
> +
>  /**
>   * enum fan_table_type - fan table types tracked per fan
>   */
> @@ -217,6 +229,8 @@ struct xe_hwmon_fan_info {
>  	u32 max_rps;
>  	/** @pwm_enable_mode: current xe_fan_pwm_enable_mode */
>  	u8 pwm_enable_mode;
> +	/** @restore_user_table: restore user fan table on next resume */
> +	bool restore_user_table;
>  };
>  
>  /**
> @@ -277,6 +291,8 @@ struct xe_hwmon {
>  	u32 pl2_on_boot[CHANNEL_MAX];
>  	/** @temp: Temperature info */
>  	struct xe_hwmon_thermal_info temp;
> +	/** @tjmax_fan_control_state: saved TjMax fan-control state */
> +	enum xe_tjmax_fan_control_state tjmax_fan_control_state;
>  	/** @curve_sda: fan curve sensor attributes */
>  	struct sensor_device_attribute curve_sda[XE_CURVE_ATTRS];
>  	/** @curve_names: names of the fan curve sensor attributes */
> @@ -2886,6 +2902,8 @@ int xe_hwmon_register(struct xe_device *xe)
>  	if (!hwmon)
>  		return -ENOMEM;
>  
> +	hwmon->tjmax_fan_control_state = XE_TJMAX_FAN_CONTROL_UNKNOWN;
> +
>  	/* Zero is XE_FAN_PWM_FULL_SPEED; stay unset until the stock table is read. */
>  	for (fan = 0; fan < FAN_MAX; fan++)
>  		hwmon->fi[fan].pwm_enable_mode = XE_FAN_PWM_UNINITIALIZED;
> @@ -2942,4 +2960,131 @@ void xe_hwmon_unregister(struct xe_device *xe)
>  	hwmon_device_unregister(xe->hwmon->hwmon_dev);
>  	xe->hwmon = NULL;
>  }
> +
> +/**
> + * xe_hwmon_suspend - Save hwmon state before suspend
> + * @xe: xe device instance
> + * @runtime: true for runtime suspend, false for system suspend or FLR prepare
> + *
> + * Save any hwmon runtime state that must survive PM suspend transitions.
> + */
> +void xe_hwmon_suspend(struct xe_device *xe, bool runtime)
> +{
> +	struct xe_hwmon *hwmon = READ_ONCE(xe->hwmon);
> +	int fan;
> +
> +	if (!hwmon || !xe->info.has_fan_control)
> +		return;
> +
> +	/* Runtime suspend keeps the fan tables unless the device enters d3cold. */
> +	if (runtime && !xe->d3cold.allowed) {
> +		xe_dbg(xe, "d3cold not allowed, skipping fan state snapshot\n");
> +		return;
> +	}
> +
> +	guard(mutex)(&hwmon->hwmon_lock);
> +
> +	if (!runtime || xe->d3cold.allowed) {
> +		u32 val = 0;
> +		int ret;
> +
> +		hwmon->tjmax_fan_control_state = XE_TJMAX_FAN_CONTROL_UNKNOWN;
> +
> +		ret = xe_pcode_read(xe_device_get_root_tile(xe),
> +				    PCODE_MBOX(FAN_SPEED_CONTROL,
> +					       FSC_READ_TJMAX_FAN_CONTROL_MODE, 0),
> +				    &val, NULL);
> +		if (ret) {
> +			xe_warn(xe, "failed to save fan tjmax control, ret=%d\n", ret);
> +		} else {
> +			hwmon->tjmax_fan_control_state =
> +				(val & TJMAX_FAN_CONTROL_ENABLE) ?
> +				XE_TJMAX_FAN_CONTROL_ENABLED :
> +				XE_TJMAX_FAN_CONTROL_DISABLED;
> +		}
> +	}
> +
> +	for (fan = 0; fan < FAN_MAX; fan++) {
> +		struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
> +		u32 point_count = fi->fan_table[USER_FAN_TABLE].point_count;
> +
> +		if (!IS_FAN_ENABLED(hwmon, fan))
> +			continue;
> +
> +		fi->restore_user_table = false;
> +		if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE &&
> +		    fi->pwm_enable_mode != XE_FAN_PWM_FULL_SPEED)
> +			continue;
> +
> +		if (point_count < MIN_FAN_CONTROL_POINTS ||
> +		    point_count > MAX_FAN_CONTROL_POINTS)
> +			continue;
> +		fi->restore_user_table = true;
> +		xe_dbg(hwmon->xe,
> +		       "fan %d cached user table marked for restore, point_count=%u\n", fan,
> +		       point_count);
> +	}
> +}
> +
> +/**
> + * xe_hwmon_resume - Restore hwmon state after resume
> + * @xe: xe device instance
> + * @runtime: true for runtime resume, false for system resume or FLR done
> + *
> + * Restore any hwmon runtime state that was saved across suspend.
> + */
> +void xe_hwmon_resume(struct xe_device *xe, bool runtime)
> +{
> +	struct xe_hwmon *hwmon = READ_ONCE(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 state restore\n");
> +		return;
> +	}
> +
> +	guard(mutex)(&hwmon->hwmon_lock);
> +
> +	if (hwmon->tjmax_fan_control_state != XE_TJMAX_FAN_CONTROL_UNKNOWN) {
> +		bool enable = hwmon->tjmax_fan_control_state == XE_TJMAX_FAN_CONTROL_ENABLED;
> +		int ret = xe_pcode_write(xe_device_get_root_tile(xe),
> +					 PCODE_MBOX(FAN_SPEED_CONTROL,
> +						    FSC_WRITE_TJMAX_FAN_CONTROL_MODE, 0),
> +					 enable);
> +		if (ret)
> +			xe_warn(xe, "failed to restore fan tjmax control, ret=%d\n", ret);
> +		else
> +			hwmon->tjmax_fan_control_state = XE_TJMAX_FAN_CONTROL_UNKNOWN;
> +	}
> +
> +	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;
> +
> +		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->pwm_enable_mode == XE_FAN_PWM_FULL_SPEED,
> +						       USER_FAN_TABLE);
> +		fi->restore_user_table = false;
> +		if (ret) {
> +			xe_warn(xe, "failed to restore fan %d user table after resume, ret=%d\n",
> +				fan, ret);
> +			continue;
> +		}
> +
> +		xe_dbg(xe, "fan %d user table restored\n", fan);
> +	}
> +}
> +
>  MODULE_IMPORT_NS("INTEL_PMT_TELEMETRY");
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.h b/drivers/gpu/drm/xe/xe_hwmon.h
> index e67e0134f02a..50874b6b6527 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.h
> +++ b/drivers/gpu/drm/xe/xe_hwmon.h
> @@ -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_ */
> diff --git a/drivers/gpu/drm/xe/xe_pcode_api.h b/drivers/gpu/drm/xe/xe_pcode_api.h
> index a217256f9e9d..b950bb064b01 100644
> --- a/drivers/gpu/drm/xe/xe_pcode_api.h
> +++ b/drivers/gpu/drm/xe/xe_pcode_api.h
> @@ -93,11 +93,11 @@
>  #define     FSC_READ_STOCK_FAN_CONTROL_POINTS	0x5
>  #define     FSC_READ_USER_FAN_CONTROL_POINTS	0x6
>  #define     FSC_READ_FAN_TABLE			0x7
> +#define     FSC_WRITE_TJMAX_FAN_CONTROL_MODE	0x8
> +#define     FSC_READ_TJMAX_FAN_CONTROL_MODE		0x9
> +#define     TJMAX_FAN_CONTROL_ENABLE		REG_BIT(0)
>  #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       TJMAX_FAN_CONTROL_ENABLE		REG_BIT(0)
>  
>  #define PCODE_SCRATCH(x)		XE_REG(0x138320 + ((x) * 4))
>  /* PCODE_SCRATCH0 */
> diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
> index f73f68bd449b..4d4b398cbeda 100644
> --- a/drivers/gpu/drm/xe/xe_pm.c
> +++ b/drivers/gpu/drm/xe/xe_pm.c
> @@ -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);
> -- 
> 2.34.1
> 

  reply	other threads:[~2026-12-02 22:29 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02 19:52 [PATCH v9 00/11] drm/xe/hwmon: Add fan control support Karthik Poosa
2026-12-02 19:52 ` [PATCH v9 01/11] drm/xe/hwmon: Rename has_fan_control to has_fan Karthik Poosa
2026-12-02 22:29   ` Rodrigo Vivi
2026-12-02 19:52 ` [PATCH v9 02/11] drm/xe/hwmon: Initialize fan-control backend and table cache Karthik Poosa
2026-12-02 19:52 ` [PATCH v9 03/11] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-12-02 19:52 ` [PATCH v9 04/11] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
2026-12-02 19:52 ` [PATCH v9 05/11] drm/xe/hwmon: Expose pwm[1-3] Karthik Poosa
2026-12-02 19:53   ` Purkait, Soham
2026-12-02 19:52 ` [PATCH v9 06/11] drm/xe/hwmon: Expose pwm[1-3]_enable Karthik Poosa
2026-12-02 19:53   ` Purkait, Soham
2026-12-02 19:52 ` [PATCH v9 07/11] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-12-02 19:52 ` [PATCH v9 08/11] drm/xe: Expose tjmax_fan_control_enable device sysfs Karthik Poosa
2026-12-02 19:52 ` [PATCH v9 09/11] drm/xe/hwmon: Restore fan user tables after resume Karthik Poosa
2026-12-02 22:29   ` Rodrigo Vivi [this message]
2026-12-02 19:52 ` [PATCH v9 10/11] drm/xe/hwmon: Refresh fan data after late binding Karthik Poosa
2026-12-02 22:31   ` Rodrigo Vivi
2026-12-02 19:52 ` [PATCH v9 11/11] drm/xe/hwmon: Add kernel-doc for fan control Karthik Poosa
2026-12-02 19:55   ` Purkait, Soham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=axCbxtCjsWG_4b5i@intel.com \
    --to=rodrigo.vivi@intel.com \
    --cc=anshuman.gupta@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=karthik.poosa@intel.com \
    --cc=raag.jadav@intel.com \
    --cc=soham.purkait@intel.com \
    /path/to/YOUR_REPLY

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

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