Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF664606A31C for ; Mon, 30 Nov 2026 18:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=JWObBnRG Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92AC010F384; Mon, 30 Nov 2026 18:49:35 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 298D510F3B5 for ; Mon, 30 Nov 2026 18:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796064567; x=1827600567; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GKsdu7pDsRC2S6vKVNUy5T0qMjXVWARtxHJ/NseBvMg=; b=JWObBnRGnq5pYipXxOtS/K19Q2BWzlm8VdydHU1Fi7n9+8WoL1F6LxVB 8H6ihIwFGE70jzRi37Nn+tovE6fUVGdVQpS1Kw0gRoCj65n7MQNI5xGvq VuEH0Z8J216RiVqWsbJApCpew1y6Co263JAJJV9pNxkQd8KlEVXu2+5eG SXpU+yfMLZulncmxQxyfKFD5dULG3oaOU/laYHfs5gynYjlBy1RGZ3+83 GcMFXZpcpcN5JO1K8GGNus9537Y0nl7iym+ZaYo8xxPcbGHPXzBt51b8O OjnZucltUdZ04iQWbAlu3j7FwYTfPdP1Pmf7ci3EqE+QhJG4bAuURpjnH w==; X-CSE-ConnectionGUID: XdL/OUcYSBGzRIaPYq76AQ== X-CSE-MsgGUID: urqd2HigQyORf6H8ZQX6xQ== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4814749" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4814749" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 10:49:27 -0800 X-CSE-ConnectionGUID: kLV63LG+QtGr21q1iBJmTQ== X-CSE-MsgGUID: I+fyJL7FQ4+oU9QkVoH2ug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13330401" Received: from sinjan-super-server.iind.intel.com ([10.190.239.39]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 10:49:24 -0800 From: Karthik Poosa To: intel-xe@lists.freedesktop.org Cc: rodrigo.vivi@intel.com, anshuman.gupta@intel.com, badal.nilawar@intel.com, raag.jadav@intel.com, riana.tauro@intel.com, sk.anirban@intel.com, mallesh.koujalagi@intel.com, soham.purkait@intel.com, ravi.kishore.koppuravuri@intel.com, Karthik Poosa Subject: [PATCH v6 07/10] drm/xe/hwmon: Restore fan user tables after resume Date: Tue, 1 Dec 2026 00:20:47 +0530 Message-Id: <20261130185050.36979-8-karthik.poosa@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261130185050.36979-1-karthik.poosa@intel.com> References: <20261130185050.36979-1-karthik.poosa@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Preserve active manual and full-speed fan tables 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. Waiting for it from the resume path can deadlock against the resume of the MEI device that loads it. If restoration fails, fall back to stock fan control. Signed-off-by: Karthik Poosa --- 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) drivers/gpu/drm/xe/xe_device.c | 3 + drivers/gpu/drm/xe/xe_hwmon.c | 101 +++++++++++++++++++++++++++++++++ drivers/gpu/drm/xe/xe_hwmon.h | 4 ++ drivers/gpu/drm/xe/xe_pm.c | 11 +++- 4 files changed, 116 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c index fccb0eff54ee..066949bee1ac 100644 --- a/drivers/gpu/drm/xe/xe_device.c +++ b/drivers/gpu/drm/xe/xe_device.c @@ -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; } diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c index 857c9d293f09..ea342f12a756 100644 --- a/drivers/gpu/drm/xe/xe_hwmon.c +++ b/drivers/gpu/drm/xe/xe_hwmon.c @@ -217,6 +217,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; }; /** @@ -2920,4 +2922,103 @@ 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 user-table snapshot\n"); + return; + } + + mutex_lock(&hwmon->hwmon_lock); + + 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); + } + + mutex_unlock(&hwmon->hwmon_lock); +} + +/** + * 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 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; + + 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); + } + + mutex_unlock(&hwmon->hwmon_lock); +} + 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_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