From 169b9182f192e8725c8de5d7d77f00f6ae6c7fd4 Mon Sep 17 00:00:00 2001 From: Thomas Zimmermann Date: Thu, 9 Feb 2023 16:41:02 +0100 Subject: drm/atomic-helper: Add atomic_enable plane-helper callback Add atomic_enable to struct drm_plane_helper_funcs. It enables a plane independently from updating the plane's content. As such, it is the inverse of the atomic_disable plane helper. Useful for hardware where plane enable state is independent from plane content. Signed-off-by: Thomas Zimmermann Reviewed-by: Javier Martinez Canillas Link: https://patchwork.freedesktop.org/patch/msgid/20230209154107.30680-2-tzimmermann@suse.de --- drivers/gpu/drm/drm_atomic_helper.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'drivers/gpu/drm/drm_atomic_helper.c') diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index d579fd8f7cb8..8606876f7233 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -2702,6 +2702,11 @@ void drm_atomic_helper_commit_planes(struct drm_device *dev, funcs->atomic_disable(plane, old_state); } else if (new_plane_state->crtc || disabling) { funcs->atomic_update(plane, old_state); + + if (!disabling && funcs->atomic_enable) { + if (drm_atomic_plane_enabling(old_plane_state, new_plane_state)) + funcs->atomic_enable(plane, old_state); + } } } @@ -2762,6 +2767,7 @@ drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state) struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(old_state, plane); const struct drm_plane_helper_funcs *plane_funcs; + bool disabling; plane_funcs = plane->helper_private; @@ -2771,12 +2777,18 @@ drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state) WARN_ON(new_plane_state->crtc && new_plane_state->crtc != crtc); - if (drm_atomic_plane_disabling(old_plane_state, new_plane_state) && - plane_funcs->atomic_disable) + disabling = drm_atomic_plane_disabling(old_plane_state, new_plane_state); + + if (disabling && plane_funcs->atomic_disable) { plane_funcs->atomic_disable(plane, old_state); - else if (new_plane_state->crtc || - drm_atomic_plane_disabling(old_plane_state, new_plane_state)) + } else if (new_plane_state->crtc || disabling) { plane_funcs->atomic_update(plane, old_state); + + if (!disabling && plane_funcs->atomic_enable) { + if (drm_atomic_plane_enabling(old_plane_state, new_plane_state)) + plane_funcs->atomic_enable(plane, old_state); + } + } } if (crtc_funcs && crtc_funcs->atomic_flush) -- cgit From d39e48ca80c0960b039cb38633957f0040f63e1a Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Fri, 3 Sep 2021 11:47:54 -0700 Subject: drm/atomic-helper: Set fence deadline for vblank For an atomic commit updating a single CRTC (ie. a pageflip) calculate the next vblank time, and inform the fence(s) of that deadline. v2: Comment typo fix (danvet) v3: If there are multiple CRTCs, consider the time of the soonest vblank Signed-off-by: Rob Clark Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_atomic_helper.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'drivers/gpu/drm/drm_atomic_helper.c') diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index d579fd8f7cb8..28e3f2c8917e 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1511,6 +1511,41 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, } EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables); +/* + * For atomic updates which touch just a single CRTC, calculate the time of the + * next vblank, and inform all the fences of the deadline. + */ +static void set_fence_deadline(struct drm_device *dev, + struct drm_atomic_state *state) +{ + struct drm_crtc *crtc; + struct drm_crtc_state *new_crtc_state; + struct drm_plane *plane; + struct drm_plane_state *new_plane_state; + ktime_t vbltime = 0; + int i; + + for_each_new_crtc_in_state (state, crtc, new_crtc_state, i) { + ktime_t v; + + if (drm_crtc_next_vblank_start(crtc, &v)) + continue; + + if (!vbltime || ktime_before(v, vbltime)) + vbltime = v; + } + + /* If no CRTCs updated, then nothing to do: */ + if (!vbltime) + return; + + for_each_new_plane_in_state (state, plane, new_plane_state, i) { + if (!new_plane_state->fence) + continue; + dma_fence_set_deadline(new_plane_state->fence, vbltime); + } +} + /** * drm_atomic_helper_wait_for_fences - wait for fences stashed in plane state * @dev: DRM device @@ -1540,6 +1575,8 @@ int drm_atomic_helper_wait_for_fences(struct drm_device *dev, struct drm_plane_state *new_plane_state; int i, ret; + set_fence_deadline(dev, state); + for_each_new_plane_in_state(state, plane, new_plane_state, i) { if (!new_plane_state->fence) continue; -- cgit From f2c7ca890182d24ac817fa321489346000271c5c Mon Sep 17 00:00:00 2001 From: Daniel Vetter Date: Wed, 5 Apr 2023 15:31:05 +0200 Subject: drm/atomic-helper: Don't set deadline for modesets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the crtc is being switched on or off then the semantics of computing the timestampe of the next vblank is somewhat ill-defined. And indeed, the code splats with a warning in the timestamp computation code. Specifically it hits the check to make sure that atomic drivers have full set up the timing constants in the drm_vblank structure, and that's just not the case before the crtc is actually on. For robustness it seems best to just not set deadlines for modesets. v2: Also skip on inactive crtc (Ville) Link: https://lore.kernel.org/dri-devel/dfc21f18-7e1e-48f0-c05a-d659b9c90b91@linaro.org/ Fixes: d39e48ca80c0 ("drm/atomic-helper: Set fence deadline for vblank") Cc: Ville Syrjälä Cc: Rob Clark Cc: Daniel Vetter Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Reported-by: Dmitry Baryshkov Tested-by: Dmitry Baryshkov # test patch only Cc: Dmitry Baryshkov Reviewed-by: Ville Syrjälä Reviewed-by: Rob Clark Signed-off-by: Daniel Vetter Link: https://patchwork.freedesktop.org/patch/msgid/20230405133105.947834-1-daniel.vetter@ffwll.ch --- drivers/gpu/drm/drm_atomic_helper.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/gpu/drm/drm_atomic_helper.c') diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c index d4d2a2ce40f8..2c2c9caf0be5 100644 --- a/drivers/gpu/drm/drm_atomic_helper.c +++ b/drivers/gpu/drm/drm_atomic_helper.c @@ -1528,6 +1528,12 @@ static void set_fence_deadline(struct drm_device *dev, for_each_new_crtc_in_state (state, crtc, new_crtc_state, i) { ktime_t v; + if (drm_atomic_crtc_needs_modeset(new_crtc_state)) + continue; + + if (!new_crtc_state->active) + continue; + if (drm_crtc_next_vblank_start(crtc, &v)) continue; -- cgit