All of lore.kernel.org
 help / color / mirror / Atom feed
From: James Lin <PingLei.Lin@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: Harry Wentland <harry.wentland@amd.com>,
	Leo Li <sunpeng.li@amd.com>,
	Aurabindo Pillai <aurabindo.pillai@amd.com>,
	Roman Li <roman.li@amd.com>, Wayne Lin <wayne.lin@amd.com>,
	Tom Chung <chiahsuan.chung@amd.com>,
	"Fangzhi Zuo" <jerry.zuo@amd.com>,
	Dan Wheeler <daniel.wheeler@amd.com>, Ray Wu <Ray.Wu@amd.com>,
	Ivan Lipski <ivan.lipski@amd.com>, Alex Hung <alex.hung@amd.com>,
	James Lin <PingLei.Lin@amd.com>,
	Chenyu Chen <Chen-Yu.Chen@amd.com>,
	George Zhang <george.zhang@amd.com>,
	James Lin <pinglei.lin@amd.com>
Subject: [PATCH 14/33] drm/amd/display: Queue vblank control work to sleepable context
Date: Tue, 17 Nov 2026 05:50:51 +0800	[thread overview]
Message-ID: <20261116215641.2800595-15-PingLei.Lin@amd.com> (raw)
In-Reply-To: <20261116215641.2800595-1-PingLei.Lin@amd.com>

From: George Zhang <george.zhang@amd.com>

[why & how]
Currently, vblank control exits idle to program HW, but it does not (and
cannot) hold dc_lock to prevent another thread from entering device-wide
idle.

Add a flag to check if we are able to use the HW vblank counter or not.
If not, assume that we are in idle, and queue a worker to enable/disable
vblank in a sleepable context. Update the value of the flag accordingly
in the ISM.

In the gap between returning from vblank_control and the worker enabling
HW, use the flag to determine if we should output a virtual vblank
counter or not.

Finally, lock DM internal callers of dm_vblank_get_counter.

Cc: Sun peng Li <sunpeng.li@amd.com>
Signed-off-by: George Zhang <george.zhang@amd.com>
Signed-off-by: James Lin <pinglei.lin@amd.com>
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |  93 +++++++-
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h |  49 ++++
 .../amd/display/amdgpu_dm/amdgpu_dm_crtc.c    | 225 ++++++++++++------
 .../display/amdgpu_dm/amdgpu_dm_irq_params.h  |   2 +
 .../drm/amd/display/amdgpu_dm/amdgpu_dm_ism.c |  20 +-
 5 files changed, 302 insertions(+), 87 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index 2f4c6a2dd4ec..29d7c87a94ef 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -172,6 +172,7 @@ static inline void amdgpu_dm_exit_ips_for_hw_access(struct dc *dc)
 STATIC_IFN_KUNIT u32 dm_vblank_get_counter(struct amdgpu_device *adev, int crtc)
 {
 	struct amdgpu_crtc *acrtc = NULL;
+	struct amdgpu_display_manager *dm = &adev->dm;
 
 	if (crtc >= adev->mode_info.num_crtc)
 		return 0;
@@ -184,7 +185,19 @@ STATIC_IFN_KUNIT u32 dm_vblank_get_counter(struct amdgpu_device *adev, int crtc)
 		return 0;
 	}
 
-	return dc_stream_get_vblank_counter(acrtc->dm_irq_params.stream);
+	guard(spinlock_irqsave)(&adev->dm.sw_counter_lock);
+
+	if (acrtc->otg_inst < 0) {
+		drm_err(adev_to_drm(adev), "dm_vblank_get_counter: no otg_inst for crtc '%d'!\n",
+			crtc);
+		return 0;
+	}
+
+	if (dm->use_sw_vblank_counter)
+		return dm->otg_sw_counter[acrtc->otg_inst].frozen;
+
+	return (dc_stream_get_vblank_counter(acrtc->dm_irq_params.stream) +
+		dm->otg_sw_counter[acrtc->otg_inst].offset) & 0xffffff;
 }
 EXPORT_IF_KUNIT(dm_vblank_get_counter);
 
@@ -192,8 +205,8 @@ STATIC_IFN_KUNIT int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc
 					    u32 *vbl, u32 *position)
 {
 	u32 v_blank_start = 0, v_blank_end = 0, h_position = 0, v_position = 0;
+	struct amdgpu_display_manager *dm = &adev->dm;
 	struct amdgpu_crtc *acrtc = NULL;
-	struct dc *dc = adev->dm.dc;
 
 	if ((crtc < 0) || (crtc >= adev->mode_info.num_crtc))
 		return -EINVAL;
@@ -206,8 +219,20 @@ STATIC_IFN_KUNIT int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc
 		return 0;
 	}
 
-	if (dc && dc->caps.ips_support && dc->idle_optimizations_allowed)
-		dc_allow_idle_optimizations(dc, false);
+	guard(spinlock_irqsave)(&adev->dm.sw_counter_lock);
+
+	if (acrtc->otg_inst < 0) {
+		drm_err(adev_to_drm(adev), "dm_crtc_get_scanoutpos: no otg_inst for crtc '%d'!\n",
+			crtc);
+		return 0;
+	}
+
+	if (dm->use_sw_vblank_counter) {
+		*vbl = dm->otg_sw_counter[acrtc->otg_inst].vblank_start |
+		       (dm->otg_sw_counter[acrtc->otg_inst].vblank_end << 16);
+		*position = dm->otg_sw_counter[acrtc->otg_inst].vblank_end;
+		return 0;
+	}
 
 	/*
 	 * TODO rework base driver to use values directly.
@@ -226,6 +251,61 @@ STATIC_IFN_KUNIT int dm_crtc_get_scanoutpos(struct amdgpu_device *adev, int crtc
 }
 EXPORT_IF_KUNIT(dm_crtc_get_scanoutpos);
 
+/* active_vblank_irq_count must be 0 before calling this function */
+void amdgpu_dm_sw_counter_freeze(struct amdgpu_display_manager *dm)
+{
+	struct dc *dc = dm->dc;
+
+	lockdep_assert_held(&dm->dc_lock);
+
+	if (!dc->caps.ips_support || dc->config.disable_ips == DMUB_IPS_DISABLE_ALL)
+		return;
+
+	guard(spinlock_irqsave)(&dm->sw_counter_lock);
+
+	if (dm->use_sw_vblank_counter)
+		return;
+
+	for (int i = 0; i < MAX_PIPES; i++) {
+		u32 hw, h_position, v_position;
+
+		hw = dc_otg_get_vblank_counter(dc, i);
+		dm->otg_sw_counter[i].frozen = (hw + dm->otg_sw_counter[i].offset + 1) & 0xffffff;
+		dc_otg_get_scanoutpos(dc, i,
+				      &dm->otg_sw_counter[i].vblank_start,
+				      &dm->otg_sw_counter[i].vblank_end,
+				      &h_position, &v_position);
+	}
+
+	dm->use_sw_vblank_counter = true;
+
+}
+
+/* should only be called after IPS exit */
+void amdgpu_dm_sw_counter_resume(struct amdgpu_display_manager *dm)
+{
+	struct dc *dc = dm->dc;
+
+	lockdep_assert_held(&dm->dc_lock);
+
+	if (!dc->caps.ips_support || dc->config.disable_ips == DMUB_IPS_DISABLE_ALL)
+		return;
+
+	guard(spinlock_irqsave)(&dm->sw_counter_lock);
+
+	if (!dm->use_sw_vblank_counter)
+		return;
+
+	for (int i = 0; i < MAX_PIPES; i++) {
+		u32 hw;
+
+		hw = dc_otg_get_vblank_counter(dc, i);
+		dm->otg_sw_counter[i].offset = (dm->otg_sw_counter[i].frozen - hw) & 0xffffff;
+	}
+
+	dm->use_sw_vblank_counter = false;
+}
+
 STATIC_IFN_KUNIT int dm_wait_for_idle(struct amdgpu_ip_block *ip_block)
 {
 	/* XXX todo */
@@ -516,6 +596,7 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
 	mutex_init(&adev->dm.audio_lock);
 
 	spin_lock_init(&adev->dm.dmub_lock);
+	spin_lock_init(&adev->dm.sw_counter_lock);
 
 	if (amdgpu_dm_irq_init(adev)) {
 		drm_err(adev_to_drm(adev), "failed to initialize DM IRQ support.\n");
@@ -768,8 +849,10 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)
 	if (adev->dm.dc->caps.max_links > 0) {
 		adev->dm.vblank_control_workqueue =
 			create_singlethread_workqueue("dm_vblank_control_workqueue");
-		if (!adev->dm.vblank_control_workqueue)
+		if (!adev->dm.vblank_control_workqueue) {
 			drm_err(adev_to_drm(adev), "failed to initialize vblank_workqueue.\n");
+			goto error;
+		}
 	}
 
 	if (adev->dm.dc->caps.ips_support &&
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
index 761d2b40aece..63c1c2ea80aa 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
@@ -319,6 +319,28 @@ struct hpd_rx_irq_offload_work {
 	struct amdgpu_device *adev;
 };
 
+/**
+ * struct dm_otg_sw_counter - Per-OTG sw vblank counter state
+ * @frozen: Frozen vblank counter snapshot, valid while
+ *	    dm->use_sw_vblank_counter is set.
+ * @offset: Offset applied to the live hw vblank counter to keep it
+ *	    continuous across a freeze/resume cycle.
+ * @vblank_start: Frozen scanout vblank start position, valid while
+ *		  dm->use_sw_vblank_counter is set.
+ * @vblank_end: Frozen scanout vblank end position, valid while
+ *		dm->use_sw_vblank_counter is set.
+ *
+ * Indexed by otg_inst rather than by CRTC, so a value survives a CRTC's
+ * stream being reassigned to a different OTG. Guarded by
+ * dm->sw_counter_lock.
+ */
+struct dm_otg_sw_counter {
+	u32 frozen;
+	u32 offset;
+	u32 vblank_start;
+	u32 vblank_end;
+};
+
 /**
  * struct amdgpu_display_manager - Central amdgpu display manager device
  *
@@ -467,6 +489,30 @@ struct amdgpu_display_manager {
 	 */
 	struct mutex dc_lock;
 
+	/**
+	 * @sw_counter_lock
+	 *
+	 * Guards sw_vblank counter.
+	 */
+	spinlock_t sw_counter_lock;
+
+	/**
+	 * @use_sw_vblank_counter
+	 *
+	 * use sw vblank counter instead of hw vblank counter. Can only be set
+	 * under dc_lock and sw_counter_lock.
+	 * Set implies active_vblank_irq_count == 0.
+	 */
+	bool use_sw_vblank_counter;
+
+	/**
+	 * @otg_sw_counter:
+	 *
+	 * Per-OTG sw vblank counter state, indexed by otg_inst. Guarded by
+	 * sw_counter_lock. See &struct dm_otg_sw_counter.
+	 */
+	struct dm_otg_sw_counter otg_sw_counter[AMDGPU_MAX_CRTCS];
+
 	/**
 	 * @dmub_lock:
 	 *
@@ -1171,6 +1217,9 @@ bool amdgpu_dm_execute_fused_io(
 int amdgpu_dm_process_dmub_set_config_sync(struct dc_context *ctx, unsigned int link_index,
 					struct set_config_cmd_payload *payload, enum set_config_status *operation_result);
 
+void amdgpu_dm_sw_counter_freeze(struct amdgpu_display_manager *dm);
+void amdgpu_dm_sw_counter_resume(struct amdgpu_display_manager *dm);
+
 int dm_atomic_get_state(struct drm_atomic_commit *state,
 			struct dm_atomic_state **dm_state);
 
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
index 8d31c673817c..8d25b034111f 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_crtc.c
@@ -223,33 +223,6 @@ struct idle_workqueue *idle_create_workqueue(struct amdgpu_device *adev)
 }
 EXPORT_IF_KUNIT(idle_create_workqueue);
 
-STATIC_IFN_KUNIT void amdgpu_dm_crtc_vblank_control_worker(struct work_struct *work)
-{
-	struct vblank_control_work *vblank_work =
-		container_of(work, struct vblank_control_work, work);
-	struct amdgpu_display_manager *dm = vblank_work->dm;
-
-	mutex_lock(&dm->dc_lock);
-
-	if (vblank_work->enable) {
-		dm->active_vblank_irq_count++;
-		amdgpu_dm_ism_commit_event(&vblank_work->acrtc->ism,
-				DM_ISM_EVENT_EXIT_IDLE_REQUESTED);
-	} else {
-		if (dm->active_vblank_irq_count > 0)
-			dm->active_vblank_irq_count--;
-		amdgpu_dm_ism_commit_event(&vblank_work->acrtc->ism,
-				DM_ISM_EVENT_ENTER_IDLE_REQUESTED);
-	}
-
-	mutex_unlock(&dm->dc_lock);
-
-	dc_stream_release(vblank_work->stream);
-
-	kfree(vblank_work);
-}
-EXPORT_IF_KUNIT(amdgpu_dm_crtc_vblank_control_worker);
-
 #if defined(CONFIG_DRM_AMD_SECURE_DISPLAY) || IS_ENABLED(CONFIG_DRM_AMD_DC_KUNIT_TEST)
 STATIC_IFN_KUNIT int amdgpu_dm_crtc_set_vline0_irq(struct drm_crtc *crtc, int irq_type,
 						   bool enable)
@@ -274,45 +247,20 @@ STATIC_IFN_KUNIT int amdgpu_dm_crtc_set_vline0_irq(struct drm_crtc *crtc, int ir
 EXPORT_IF_KUNIT(amdgpu_dm_crtc_set_vline0_irq);
 #endif
 
-static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)
+static int amdgpu_dm_program_vblank_irq(struct amdgpu_crtc *acrtc, bool enable)
 {
-	struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
+	struct drm_crtc *crtc = &acrtc->base;
 	struct amdgpu_device *adev = drm_to_adev(crtc->dev);
-	struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
 	struct amdgpu_display_manager *dm = &adev->dm;
-	struct vblank_control_work *work;
-	int irq_type;
+	struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
 	int rc = 0;
+	int irq_type = amdgpu_display_crtc_idx_to_irq_type(adev, acrtc->crtc_id);
 
-	if (enable && !acrtc->base.enabled) {
-		drm_dbg_vbl(crtc->dev,
-				"Reject vblank enable on unconfigured CRTC %d (enabled=%d)\n",
-				acrtc->crtc_id, acrtc->base.enabled);
-		return -EINVAL;
-	}
-
-	irq_type = amdgpu_display_crtc_idx_to_irq_type(adev, acrtc->crtc_id);
-
-	if (enable && acrtc_state->stream) {
-		struct dc *dc = adev->dm.dc;
-		struct drm_vblank_crtc *vblank = drm_crtc_vblank_crtc(crtc);
-		struct psr_settings *psr = &acrtc_state->stream->link->psr_settings;
-		struct replay_settings *pr = &acrtc_state->stream->link->replay_settings;
-		bool sr_supported = (psr->psr_version != DC_PSR_VERSION_UNSUPPORTED) ||
-								pr->config.replay_supported;
-
-		/*
-		 * IPS & self-refresh feature can cause vblank counter resets between
-		 * vblank disable and enable.
-		 * It may cause system stuck due to waiting for the vblank counter.
-		 * Call this function to estimate missed vblanks by using timestamps and
-		 * update the vblank counter in DRM.
-		 */
-		if (dc->caps.ips_support &&
-			dc->config.disable_ips != DMUB_IPS_DISABLE_ALL &&
-			sr_supported && vblank->config.disable_immediate)
-			drm_crtc_vblank_restore(crtc);
-	}
+#if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
+	rc = amdgpu_dm_crtc_set_vline0_irq(crtc, irq_type, enable);
+	if (rc)
+		return rc;
+#endif
 
 	/*
 	 * On DCN, VUPDATE_NO_LOCK is the single OTG interrupt used to deliver
@@ -382,33 +330,154 @@ static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)
 			return rc;
 	}
 
-#if defined(CONFIG_DRM_AMD_SECURE_DISPLAY)
-	rc = amdgpu_dm_crtc_set_vline0_irq(crtc, irq_type, enable);
+	return 0;
+}
+
+static int amdgpu_dm_sync_vblank_irq(struct amdgpu_crtc *acrtc, bool enable)
+{
+	struct amdgpu_display_manager *dm = &drm_to_adev(acrtc->base.dev)->dm;
+	int rc = 0;
+
+	lockdep_assert_held(&dm->ddev->vbl_lock);
+
+	if (enable == acrtc->dm_irq_params.vblank_irq_programmed)
+		return 0;
+
+	rc = amdgpu_dm_program_vblank_irq(acrtc, enable);
 	if (rc)
 		return rc;
-#endif
 
-	if (amdgpu_in_reset(adev))
-		return 0;
+	acrtc->dm_irq_params.vblank_irq_programmed = enable;
 
-	if (dm->vblank_control_workqueue) {
-		work = kzalloc_obj(*work, GFP_ATOMIC);
-		if (!work)
-			return -ENOMEM;
+	if (enable)
+		dm->active_vblank_irq_count++;
+	else if (!WARN_ON(!dm->active_vblank_irq_count))
+		dm->active_vblank_irq_count--;
 
-		INIT_WORK(&work->work, amdgpu_dm_crtc_vblank_control_worker);
-		work->dm = dm;
-		work->acrtc = acrtc;
-		work->enable = enable;
+	return 0;
+}
+
+STATIC_IFN_KUNIT void amdgpu_dm_crtc_vblank_control_worker(struct work_struct *work)
+{
+	struct vblank_control_work *vblank_work =
+		container_of(work, struct vblank_control_work, work);
+	struct amdgpu_display_manager *dm = vblank_work->dm;
+	struct amdgpu_crtc *acrtc = vblank_work->acrtc;
+	bool program;
+
+	mutex_lock(&dm->dc_lock);
+
+	if (vblank_work->enable) {
+		amdgpu_dm_ism_commit_event(&vblank_work->acrtc->ism,
+				DM_ISM_EVENT_EXIT_IDLE_REQUESTED);
+	}
+
+	scoped_guard(spinlock_irqsave, &dm->sw_counter_lock) {
+		WARN_ON(!acrtc->dm_irq_params.vblank_irq_desired &&
+			acrtc->dm_irq_params.vblank_irq_programmed);
+		program = acrtc->dm_irq_params.vblank_irq_desired &&
+			  !acrtc->dm_irq_params.vblank_irq_programmed;
+	}
 
-		if (acrtc_state->stream) {
-			dc_stream_retain(acrtc_state->stream);
-			work->stream = acrtc_state->stream;
+	if (program) {
+		/*
+		 * The ISM has corner cases where an idle exit event
+		 * (EXIT_IDLE_REQUESTED, BEGIN_CURSOR_UPDATE) does not call
+		 * dc_allow_idle_optimizations(false). E.g. another CRTC's ISM
+		 * can do the release while this ISM is in FULL_POWER_RUNNING,
+		 * where EXIT commits nothing. Acquire and resume here until HW
+		 * ref counting resolves this.
+		 */
+		if (dm->use_sw_vblank_counter) {
+			dc_allow_idle_optimizations(dm->dc, false);
+			amdgpu_dm_sw_counter_resume(dm);
+		}
+
+		scoped_guard(spinlock_irqsave, &dm->ddev->vbl_lock) {
+			if (acrtc->dm_irq_params.vblank_irq_desired &&
+			    !acrtc->dm_irq_params.vblank_irq_programmed)
+				WARN_ON(amdgpu_dm_sync_vblank_irq(acrtc, true));
 		}
+	}
 
-		queue_work(dm->vblank_control_workqueue, &work->work);
+	if (!vblank_work->enable) {
+		amdgpu_dm_ism_commit_event(&vblank_work->acrtc->ism,
+				DM_ISM_EVENT_ENTER_IDLE_REQUESTED);
 	}
 
+	mutex_unlock(&dm->dc_lock);
+
+	dc_stream_release(vblank_work->stream);
+
+	kfree(vblank_work);
+}
+EXPORT_IF_KUNIT(amdgpu_dm_crtc_vblank_control_worker);
+
+static inline int amdgpu_dm_crtc_set_vblank(struct drm_crtc *crtc, bool enable)
+{
+	struct amdgpu_crtc *acrtc = to_amdgpu_crtc(crtc);
+	struct amdgpu_device *adev = drm_to_adev(crtc->dev);
+	struct dm_crtc_state *acrtc_state = to_dm_crtc_state(crtc->state);
+	struct amdgpu_display_manager *dm = &adev->dm;
+	struct vblank_control_work *work;
+	int rc = 0;
+
+	lockdep_assert_held(&crtc->dev->vbl_lock);
+
+	if (enable && !acrtc->base.enabled) {
+		drm_dbg_vbl(crtc->dev,
+				"Reject vblank enable on unconfigured CRTC %d (enabled=%d)\n",
+				acrtc->crtc_id, acrtc->base.enabled);
+		return -EINVAL;
+	}
+
+	work = kzalloc_obj(*work, GFP_ATOMIC);
+	if (!work && enable)
+		return -ENOMEM;
+
+	if (enable) {
+		if (acrtc_state->stream && dm->dc->caps.ips_support &&
+		    dm->dc->config.disable_ips != DMUB_IPS_DISABLE_ALL &&
+		    drm_crtc_vblank_crtc(crtc)->config.disable_immediate)
+			drm_crtc_vblank_restore(crtc);
+
+		acrtc->dm_irq_params.vblank_irq_desired = true;
+
+		scoped_guard(spinlock_irqsave, &dm->sw_counter_lock) {
+			if (!dm->use_sw_vblank_counter) {
+				rc = amdgpu_dm_sync_vblank_irq(acrtc, enable);
+				if (rc) {
+					acrtc->dm_irq_params.vblank_irq_desired = false;
+					kfree(work);
+					return rc;
+				}
+			}
+		}
+	} else {
+		acrtc->dm_irq_params.vblank_irq_desired = false;
+
+		scoped_guard(spinlock_irqsave, &dm->sw_counter_lock)
+			WARN_ON(dm->use_sw_vblank_counter &&
+				acrtc->dm_irq_params.vblank_irq_programmed);
+
+		amdgpu_dm_sync_vblank_irq(acrtc, enable);
+	}
+
+	if (!work)
+		return -ENOMEM;
+
+	INIT_WORK(&work->work, amdgpu_dm_crtc_vblank_control_worker);
+	work->dm = dm;
+	work->acrtc = acrtc;
+	work->enable = enable;
+
+	if (acrtc_state->stream) {
+		dc_stream_retain(acrtc_state->stream);
+		work->stream = acrtc_state->stream;
+	}
+
+	queue_work(dm->vblank_control_workqueue, &work->work);
+
 	return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq_params.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq_params.h
index f0c1b0c1faa9..94a3e2f4161c 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq_params.h
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq_params.h
@@ -36,6 +36,8 @@ struct dm_irq_params {
 	int active_planes;
 	bool allow_sr_entry;
 	struct mod_freesync_config freesync_config;
+	bool vblank_irq_desired;
+	bool vblank_irq_programmed;
 
 #ifdef CONFIG_DEBUG_FS
 	enum amdgpu_dm_pipe_crc_source crc_src;
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_ism.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_ism.c
index 127eaba4de60..74b33d9d8833 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_ism.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_ism.c
@@ -293,8 +293,10 @@ static void dm_ism_commit_idle_optimization_state(struct amdgpu_dm_ism *ism,
 	 * If there is an active vblank requestor, or if SSO is being engaged,
 	 * then disallow idle optimizations.
 	 */
-	if (vblank_enabled || allow_panel_sso)
+	if (vblank_enabled || allow_panel_sso) {
 		dc_allow_idle_optimizations(dm->dc, false);
+		amdgpu_dm_sw_counter_resume(dm);
+	}
 
 	/*
 	 * Control PSR based on vblank requirements from OS
@@ -326,9 +328,19 @@ static void dm_ism_commit_idle_optimization_state(struct amdgpu_dm_ism *ism,
 	 * optimizations at the start of this func -- we should disallow
 	 * whenever there's *an* active CRTC.
 	 */
-	if (!vblank_enabled && dm->active_vblank_irq_count == 0) {
-		dc_post_update_surfaces_to_stream(dm->dc);
-		dc_allow_idle_optimizations(dm->dc, true);
+	if (!vblank_enabled) {
+		bool allow;
+
+		scoped_guard(spinlock_irqsave, &dm->ddev->vbl_lock) {
+			allow = !dm->active_vblank_irq_count;
+			if (allow)
+				amdgpu_dm_sw_counter_freeze(dm);
+		}
+
+		if (allow) {
+			dc_post_update_surfaces_to_stream(dm->dc);
+			dc_allow_idle_optimizations(dm->dc, true);
+		}
 	}
 }
 
-- 
2.43.0


  parent reply	other threads:[~2026-11-17 17:14 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 21:50 [PATCH 00/33] DC Patches November 23, 2026 James Lin
2026-11-16 21:50 ` [PATCH 01/33] drm/amd/display: Clear OTG_AUTO_FORCE_VSYNC_MODE on OTG disable James Lin
2026-11-16 21:50 ` [PATCH 02/33] drm/amd/display: Rename DPMS to DPMS_v1 James Lin
2026-11-16 21:50 ` [PATCH 03/33] drm/amd/display: Power up eDP when detect link James Lin
2026-11-16 21:50 ` [PATCH 04/33] drm/amd/display: Add DPMS-v2 files James Lin
2026-11-16 21:50 ` [PATCH 05/33] drm/amd/display: Refactor DP retrain link HW sequence James Lin
2026-11-16 21:50 ` [PATCH 06/33] drm/amd/display: add extra 0.25 line reserved for TSetup/TCalc inefficiency James Lin
2026-11-16 21:50 ` [PATCH 07/33] drm/amd/display: Use panel luminance range for AUX backlight in power module James Lin
2026-11-16 21:50 ` [PATCH 08/33] drm/amd/display: Read PWM back linearly with the linear backlight curve James Lin
2026-11-16 21:50 ` [PATCH 09/33] drm/amd/display: Add API to set brightness percent James Lin
2026-11-16 21:50 ` [PATCH 10/33] drm/amd/display: Pass linear brightness percent to power module James Lin
2026-11-16 21:50 ` [PATCH 11/33] drm/amd/display: Add DPMS-v2 types James Lin
2026-11-16 21:50 ` [PATCH 12/33] drm/amd/display: Always apply 0ppm pixel clock adjustment James Lin
2026-11-16 21:50 ` [PATCH 13/33] drm/amd/display: Add otg versions of get_vblank_counter/scanoutpos James Lin
2026-11-16 21:50 ` James Lin [this message]
2026-11-16 21:50 ` [PATCH 15/33] drm/amd/display: Fix KUnit tests for vblank control rework James Lin
2026-11-16 21:50 ` [PATCH 16/33] drm/amd/display: Add urgent request and assertion probes James Lin
2026-11-16 21:50 ` [PATCH 17/33] drm/amd/display: Fix G7 P-state aperture addresses James Lin
2026-11-16 21:50 ` [PATCH 18/33] drm/amd/display: Set stream min/max refresh from VRR config James Lin
2026-11-16 21:50 ` [PATCH 19/33] drm/amd/display: Add DC2 wrapped initialization for DCN401 James Lin
2026-11-16 21:50 ` [PATCH 20/33] drm/amd/display: Honor the Replay stream regeneration wait event James Lin
2026-11-16 21:50 ` [PATCH 21/33] drm/amd/display: Disable Replay when link off frame count is below 2 James Lin
2026-11-16 21:50 ` [PATCH 22/33] drm/amd/display: Skip DSC padding borrow estimate for zero padding James Lin
2026-11-16 21:51 ` [PATCH 23/33] drm/amd/display: Drop unused DC interfaces James Lin
2026-11-16 21:51 ` [PATCH 24/33] drm/amd/display: Let the DC2 commit replace or keep a stream James Lin
2026-11-16 21:51 ` [PATCH 25/33] drm/amd/display: Support two streams in the dcn401 DC2 builders James Lin
2026-11-16 21:51 ` [PATCH 26/33] drm/amd/display: Add a plane beside a kept plane in DC2 update James Lin
2026-11-16 21:51 ` [PATCH 27/33] drm/amd/display: Keep an unchanged stream in the DC2 commit James Lin
2026-11-16 21:51 ` [PATCH 28/33] drm/amd/display: Change the ODM and MPC layout in DC2 update James Lin
2026-11-16 21:51 ` [PATCH 29/33] drm/amd/display: Give the DC2 builders State pipe facts James Lin
2026-11-16 21:51 ` [PATCH 30/33] drm/amd/display: Add RGBA8888 surface pixel format support James Lin
2026-11-16 21:51 ` [PATCH 31/33] drm/amd/display: Fix DCE crossbar for RGBA8888 surface format James Lin
2026-11-16 21:51 ` [PATCH 32/33] drm/amd/display: [FW Promotion] Release 0.1.85.0 James Lin
2026-11-16 21:51 ` [PATCH 33/33] drm/amd/display: Promote DC to 3.2.408 James Lin

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=20261116215641.2800595-15-PingLei.Lin@amd.com \
    --to=pinglei.lin@amd.com \
    --cc=Chen-Yu.Chen@amd.com \
    --cc=Ray.Wu@amd.com \
    --cc=alex.hung@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=aurabindo.pillai@amd.com \
    --cc=chiahsuan.chung@amd.com \
    --cc=daniel.wheeler@amd.com \
    --cc=george.zhang@amd.com \
    --cc=harry.wentland@amd.com \
    --cc=ivan.lipski@amd.com \
    --cc=jerry.zuo@amd.com \
    --cc=roman.li@amd.com \
    --cc=sunpeng.li@amd.com \
    --cc=wayne.lin@amd.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.