From: Ville Syrjälä Date: Fri, 10 Mar 2023 23:58:26 +0000 (+0200) Subject: drm/i915: Add belts and suspenders locking for seamless M/N changes X-Git-Tag: v6.6.7~1918^2~17^2~443 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e8acb6686d805ac5d127fb691e28e742248c523;p=platform%2Fkernel%2Flinux-starfive.git drm/i915: Add belts and suspenders locking for seamless M/N changes Add some (probably overkill) locking to protect the vblank timestamping constants updates during seamless M/N fastsets. As everything should be naturally aligned I think the individual pieces should probably end up updating atomically enough. So this is only really meant to guarantee everyone sees a consistent whole. All the drm_vblank.c usage is covered by vblank_time_lock, and uncore.lock will take care of __intel_get_crtc_scanline() that can also be called from outside the core vblank functionality. Currently only crtc_clock and framedur_ns can change, but in the future might fastset also across eg. vtotal/vblank_end changes, so let's just grab the locks across the whole thing. Reviewed-by: Jani Nikula Signed-off-by: Ville Syrjälä Link: https://patchwork.freedesktop.org/patch/msgid/20230310235828.17439-2-ville.syrjala@linux.intel.com --- diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c index 7305ad6..4fd64dc 100644 --- a/drivers/gpu/drm/i915/display/intel_display.c +++ b/drivers/gpu/drm/i915/display/intel_display.c @@ -5907,6 +5907,8 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state) struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc); struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); struct drm_display_mode adjusted_mode; + int vmax_vblank_start = 0; + unsigned long irqflags; drm_mode_init(&adjusted_mode, &crtc_state->hw.adjusted_mode); @@ -5914,11 +5916,28 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state) adjusted_mode.crtc_vtotal = crtc_state->vrr.vmax; adjusted_mode.crtc_vblank_end = crtc_state->vrr.vmax; adjusted_mode.crtc_vblank_start = intel_vrr_vmin_vblank_start(crtc_state); - crtc->vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state); + vmax_vblank_start = intel_vrr_vmax_vblank_start(crtc_state); } + /* + * Belts and suspenders locking to guarantee everyone sees 100% + * consistent state during fastset seamless refresh rate changes. + * + * vblank_time_lock takes care of all drm_vblank.c stuff, and + * uncore.lock takes care of __intel_get_crtc_scanline() which + * may get called elsewhere as well. + * + * TODO maybe just protect everything (including + * __intel_get_crtc_scanline()) with vblank_time_lock? + * Need to audit everything to make sure it's safe. + */ + spin_lock_irqsave(&dev_priv->drm.vblank_time_lock, irqflags); + spin_lock(&dev_priv->uncore.lock); + drm_calc_timestamping_constants(&crtc->base, &adjusted_mode); + crtc->vmax_vblank_start = vmax_vblank_start; + crtc->mode_flags = crtc_state->mode_flags; /* @@ -5962,6 +5981,9 @@ void intel_crtc_update_active_timings(const struct intel_crtc_state *crtc_state) } else { crtc->scanline_offset = 1; } + + spin_unlock(&dev_priv->uncore.lock); + spin_unlock_irqrestore(&dev_priv->drm.vblank_time_lock, irqflags); } /*