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 E257D606A31C for ; Mon, 30 Nov 2026 18:49:45 +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=NuOXrRYx Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9D4CD10E039; Mon, 30 Nov 2026 18:49:40 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4961010F3A4 for ; Mon, 30 Nov 2026 18:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796064570; x=1827600570; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QBxDvXzUz5B9xlF683nnehdZhr0ZWGwoFdjh6zE5Iik=; b=NuOXrRYxyhcFWjXKl/CjHOeLOiph+H7Ejrlmen+2XuRiEhvnj3L+GANt OHues1eg8pSMpT1pftbY1ReowSSZdC8wnNcHwmU0VV5ULylkv0p1drlfr hHwKr8kas5cUwchFlutazkY2t37t3d7Kn+IN+0I9gUOqqDhI3Kk8BDFla LqNxZ21IYN0G6th+g3Q5catQer+13ZSVA2avOLugHtb/IxJcwN92ytUOp iAtYQE8/7LOv6HDXsY7RFpCCBgdjAZ1DIT9RZDtmsbsupPCckxOomy2uD +/ZVDru75aeRw27LCrnSiSPvFhf6mY+yWBcVdzlYPnsL4SngcvJAAaT0D Q==; X-CSE-ConnectionGUID: DEAWwfW9RIa7MvkmuNKi4g== X-CSE-MsgGUID: gbaObTiXRJyfSINsT2KpNg== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4814756" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4814756" 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:30 -0800 X-CSE-ConnectionGUID: I9L5NVguT4SpkERQric9Ow== X-CSE-MsgGUID: 9KNorUePQ+abL2K1xSmy0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13330408" 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:27 -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 08/10] drm/xe/hwmon: Refresh fan data after late binding Date: Tue, 1 Dec 2026 00:20:48 +0530 Message-Id: <20261130185050.36979-9-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 Refresh cached stock fan tables and maximum RPM for registered fans after fan-control firmware loads. The stock table can change with the late bound firmware; keep the previous one if a complete table cannot be read, and likewise keep the previous maximum RPM if its read fails. Re-program the user table of fans in manual or full-speed mode. Serialize the refresh with hwmon registration and teardown. Flush late binding work before releasing hwmon state, and protect fanN_max reads against concurrent max_rps updates. Signed-off-by: Karthik Poosa --- v2: - Compare lbfw->id with XE_LB_FW_FAN_CONTROL. (Soham) - Use xe already in scope. (Soham) - Spell out "late binding" in warnings. (Soham) - Start fans enabled after late binding in automatic mode. v3: - Serialize the refresh with hwmon registration and teardown. Flush late binding work before releasing hwmon state, and protect fanN_max reads against concurrent max_rps updates. v4: - Keep the previous stock table if the refresh does not read a complete one. - Re-program user tables of fans in manual or full-speed mode after late binding. - Unregister the hwmon device outside registration_lock, so sysfs callbacks resuming the device cannot deadlock with late binding work. - Keep the previous max RPM if the refresh read fails. v5: - Fix xe_hwmon_fan_late_binding_update() kernel-doc; it does not read the number of fans. (sashiko) - Drop a v2 note that does not belong to this patch. (sashiko) - Use "late binding" consistently and rename xe_hwmon_fan_update_post_lb() to xe_hwmon_fan_late_binding_update(). (Soham) - Use guards for hwmon_lock. (Soham) drivers/gpu/drm/xe/xe_hwmon.c | 99 +++++++++++++++++++++++++--- drivers/gpu/drm/xe/xe_hwmon.h | 2 + drivers/gpu/drm/xe/xe_late_bind_fw.c | 3 + 3 files changed, 96 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c index ea342f12a756..4ee51cfc9283 100644 --- a/drivers/gpu/drm/xe/xe_hwmon.c +++ b/drivers/gpu/drm/xe/xe_hwmon.c @@ -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" @@ -257,6 +258,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 */ @@ -291,6 +294,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]) { @@ -1735,16 +1745,17 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon) struct fan_control_point stock_fcp[MAX_FAN_CONTROL_POINTS]; struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; u32 stock_fcp_count = 0; + u32 max_rps = 0; if (!IS_FAN_ENABLED(hwmon, fan)) continue; ret = xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_MAX_FAN_RPS, fan, - &fi->max_rps); + &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 { + fi->max_rps = max_rps; xe_dbg(hwmon->xe, "fan %d max RPS %u\n", fan, fi->max_rps); } @@ -2409,7 +2420,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: - *val = mul_u32_u32(hwmon->fi[channel].max_rps, 60); + scoped_guard(mutex, &hwmon->hwmon_lock) { + *val = mul_u32_u32(hwmon->fi[channel].max_rps, 60); + } return 0; default: return -EOPNOTSUPP; @@ -2874,9 +2887,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 binding 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_late_binding_update(). */ + smp_store_release(&xe->hwmon, hwmon); ret = xe_hwmon_get_preregistration_info(hwmon); if (ret) @@ -2903,7 +2928,7 @@ int xe_hwmon_register(struct xe_device *xe) return 0; err_null_hwmon: - xe->hwmon = NULL; + WRITE_ONCE(xe->hwmon, NULL); return ret; } @@ -2916,11 +2941,25 @@ 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) { + mutex_unlock(&hwmon->registration_lock); + return; + } + WRITE_ONCE(xe->hwmon, NULL); + mutex_unlock(&hwmon->registration_lock); + + /* Sysfs callbacks may resume and wait on late binding work that takes registration_lock. */ + hwmon_device_unregister(hwmon->hwmon_dev); } /** @@ -3021,4 +3060,48 @@ void xe_hwmon_resume(struct xe_device *xe, bool runtime) mutex_unlock(&hwmon->hwmon_lock); } +/** + * xe_hwmon_fan_late_binding_update - Update fan info after late binding + * @xe: xe device instance + * + * Re-read the maximum fan speed and stock fan tables after late binding, and + * re-program the user table of fans in manual or full-speed mode. + */ +void xe_hwmon_fan_late_binding_update(struct xe_device *xe) +{ + /* Pair with the release store in xe_hwmon_register(). */ + struct xe_hwmon *hwmon = smp_load_acquire(&xe->hwmon); + int fan; + + if (!hwmon || !xe->info.has_fan_control) + return; + + guard(mutex)(&hwmon->registration_lock); + if (READ_ONCE(xe->hwmon) != hwmon) + return; + + guard(mutex)(&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"); + + for (fan = 0; fan < FAN_MAX; fan++) { + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; + int ret; + + if (!IS_FAN_ENABLED(hwmon, fan) || + (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE && + fi->pwm_enable_mode != XE_FAN_PWM_FULL_SPEED)) + continue; + + ret = xe_hwmon_activate_user_fan_table(hwmon, fan, + fi->pwm_enable_mode == XE_FAN_PWM_FULL_SPEED, + USER_FAN_TABLE); + if (ret) + xe_warn(hwmon->xe, + "failed to restore fan %d user table after late binding, ret=%d\n", + fan, ret); + } +} + 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 50874b6b6527..ceb3cbe93a5d 100644 --- a/drivers/gpu/drm/xe/xe_hwmon.h +++ b/drivers/gpu/drm/xe/xe_hwmon.h @@ -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_late_binding_update(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_late_binding_update(struct xe_device *xe) {} #endif #endif /* _XE_HWMON_H_ */ diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c b/drivers/gpu/drm/xe/xe_late_bind_fw.c index ad39383a7e41..b76c18f91849 100644 --- a/drivers/gpu/drm/xe/xe_late_bind_fw.c +++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c @@ -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_late_binding_update(xe); goto out; } -- 2.34.1