From: Ankit Nautiyal Date: Wed, 24 Sep 2025 14:15:38 +0000 (+0530) Subject: drm/i915/display: Wait for scl start instead of dsb_wait_vblanks X-Git-Tag: v6.19-rc1~157^2~17^2~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e5c033cfe851625908b2121bf2c01eadabc4906;p=thirdparty%2Fkernel%2Fstable.git drm/i915/display: Wait for scl start instead of dsb_wait_vblanks Until LNL, intel_dsb_wait_vblanks() used to wait for the undelayed vblank start. However, from PTL onwards, it waits for the start of the safe-window defined by the number of lines programmed in the register TRANS_SET_CONTEXT_LATENCY. This change was introduced to move the SCL window out of the vblank region, supporting modes with higher refresh rates and smaller vblanks. This change introduces a "safe window" a scanline range from (undelayed vblank - SCL) to (delayed vblank - SCL). As a result, on PTL+ platforms, the DSB wait for vblank completes exactly SCL lines earlier than the undelayed vblank start (safe window start). If the flip occurs in the active region and the push happens before the vmin decision boundary, the DSB wait fires early, and the push is sent inside this safe window. In such cases, the push bit is cleared at the delayed vblank, but our wait logic does not account for the early trigger, leading to DSB poll errors. To fix this, we add an explicit wait for the end of the safe window i.e., the scanline range from (undelayed vblank - SCL) to (delayed vblank - SCL). Once past this window, we are exactly SCL lines away from the delayed vblank, and our existing wait logic works as intended. This additional wait is only effective if the push occurs before the vmin decision boundary. If the push happens after the boundary, the hardware already guarantees we're SCL lines away from the delayed vblank, and the extra wait becomes a no-op. v2: - Use helpers for safe window start/end. (Ville) - Move the extra wait inside the helper to wait for delayed vblank. (Ville) - Update the commit message. v3: - Add more documentation for explanation for the wait. (Ville) - Rename intel_vrr_vmin_safe_window_start/end as this is vmin safe window. (Ville) - Minor refactoring to align with the code. (Ville) - Update the commit message for more clarity. v4: - Retain name for intel_vrr_safe_window_start as it doesn't change with vmin/vmax etc. (Ville) Signed-off-by: Ankit Nautiyal Reviewed-by: Ville Syrjälä Link: https://lore.kernel.org/r/20250924141542.3122126-7-ankit.k.nautiyal@intel.com --- diff --git a/drivers/gpu/drm/i915/display/intel_dsb.c b/drivers/gpu/drm/i915/display/intel_dsb.c index 135d40852e4cd..1d9379a3240bc 100644 --- a/drivers/gpu/drm/i915/display/intel_dsb.c +++ b/drivers/gpu/drm/i915/display/intel_dsb.c @@ -824,6 +824,22 @@ void intel_dsb_wait_for_delayed_vblank(struct intel_atomic_state *state, int usecs = intel_scanlines_to_usecs(&crtc_state->hw.adjusted_mode, dsb_vblank_delay(state, crtc)); + /* + * If the push happened before the vmin decision boundary + * we don't know how far we are from the undelayed vblank. + * Wait until we're past the vmin safe window, at which + * point we're SCL lines away from the delayed vblank. + * + * If the push happened after the vmin decision boundary + * the hardware itself guarantees that we're SCL lines + * away from the delayed vblank, and we won't be inside + * the vmin safe window so this extra wait does nothing. + */ + if (pre_commit_is_vrr_active(state, crtc)) + intel_dsb_wait_scanline_out(state, dsb, + intel_vrr_safe_window_start(crtc_state), + intel_vrr_vmin_safe_window_end(crtc_state)); + intel_dsb_wait_usec(dsb, usecs); } diff --git a/drivers/gpu/drm/i915/display/intel_vrr.c b/drivers/gpu/drm/i915/display/intel_vrr.c index e414fb53552f0..5f78b1af5fd56 100644 --- a/drivers/gpu/drm/i915/display/intel_vrr.c +++ b/drivers/gpu/drm/i915/display/intel_vrr.c @@ -807,3 +807,20 @@ void intel_vrr_get_config(struct intel_crtc_state *crtc_state) if (crtc_state->vrr.enable) crtc_state->mode_flags |= I915_MODE_FLAG_VRR; } + +int intel_vrr_safe_window_start(const struct intel_crtc_state *crtc_state) +{ + struct intel_display *display = to_intel_display(crtc_state); + + if (DISPLAY_VER(display) >= 30) + return crtc_state->hw.adjusted_mode.crtc_vdisplay - + crtc_state->set_context_latency; + else + return crtc_state->hw.adjusted_mode.crtc_vdisplay; +} + +int intel_vrr_vmin_safe_window_end(const struct intel_crtc_state *crtc_state) +{ + return intel_vrr_vmin_vblank_start(crtc_state) - + crtc_state->set_context_latency; +} diff --git a/drivers/gpu/drm/i915/display/intel_vrr.h b/drivers/gpu/drm/i915/display/intel_vrr.h index 38bf9996b8831..32f8644fc369f 100644 --- a/drivers/gpu/drm/i915/display/intel_vrr.h +++ b/drivers/gpu/drm/i915/display/intel_vrr.h @@ -41,5 +41,7 @@ void intel_vrr_transcoder_enable(const struct intel_crtc_state *crtc_state); void intel_vrr_transcoder_disable(const struct intel_crtc_state *crtc_state); void intel_vrr_set_fixed_rr_timings(const struct intel_crtc_state *crtc_state); bool intel_vrr_always_use_vrr_tg(struct intel_display *display); +int intel_vrr_safe_window_start(const struct intel_crtc_state *crtc_state); +int intel_vrr_vmin_safe_window_end(const struct intel_crtc_state *crtc_state); #endif /* __INTEL_VRR_H__ */