mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	 Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	 David Airlie <airlied@gmail.com>,
	Simona Vetter <simona@ffwll.ch>,
	 Dave Airlie <airlied@redhat.com>,
	Jocelyn Falempe <jfalempe@redhat.com>,
	 Rob Clark <robdclark@gmail.com>,
	Abhinav Kumar <quic_abhinavk@quicinc.com>,
	 Sean Paul <sean@poorly.run>,
	Marijn Suijten <marijn.suijten@somainline.org>,
	 Kalyan Thota <quic_kalyant@quicinc.com>
Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	 linux-arm-msm@vger.kernel.org, freedreno@lists.freedesktop.org
Subject: [PATCH 1/6] drm/atomic-helper: add atomic_needs_modeset callbacks
Date: Fri, 24 Jan 2025 13:14:19 +0200	[thread overview]
Message-ID: <20250124-atomic-needs-modeset-v1-1-b0c05c9eda0f@linaro.org> (raw)
In-Reply-To: <20250124-atomic-needs-modeset-v1-0-b0c05c9eda0f@linaro.org>

Despite drm_atomic_helper_check_modeset() and drm_atomic_helper_check()
documenting that the function should be run again if atomic_check()
callback changes drm_crtc_state.mode_changed some drivers ignore it and
don't rerun the helpers. To simplify such drivers and remove the need to
rerun the helper functions provide additional set of callbacks,
atomic_needs_modeset(). These callbacks are executed at a proper time,
they return a boolean which signifies that corresponding CRTC should
undergo a full modeset. This way the atomic_check() callbacks can stop
updating the drm_crtc_state.mode_changed.

Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
---
 drivers/gpu/drm/drm_atomic_helper.c      | 59 ++++++++++++++++++++
 include/drm/drm_modeset_helper_vtables.h | 92 ++++++++++++++++++++++++++++++++
 2 files changed, 151 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic_helper.c b/drivers/gpu/drm/drm_atomic_helper.c
index 3034ba09c0ee5791ffd2f4130bd84b4cc4676fae..1f689ccd9b0d7f655c6a49e642d652b815a0e8e1 100644
--- a/drivers/gpu/drm/drm_atomic_helper.c
+++ b/drivers/gpu/drm/drm_atomic_helper.c
@@ -649,6 +649,8 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
 	struct drm_crtc_state *old_crtc_state, *new_crtc_state;
 	struct drm_connector *connector;
 	struct drm_connector_state *old_connector_state, *new_connector_state;
+	struct drm_plane *plane;
+	struct drm_plane_state *new_plane_state, *old_plane_state;
 	int i, ret;
 	unsigned int connectors_mask = 0, user_connectors_mask = 0;
 
@@ -708,6 +710,9 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
 
 	for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) {
 		const struct drm_connector_helper_funcs *funcs = connector->helper_private;
+		struct drm_encoder *encoder = new_connector_state->best_encoder;
+		const struct drm_encoder_helper_funcs *enc_funcs =
+			encoder ? encoder->helper_private : NULL;
 
 		WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
 
@@ -734,6 +739,25 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
 				new_crtc_state->connectors_changed = true;
 		}
 
+		if ((funcs->atomic_needs_modeset &&
+		     funcs->atomic_needs_modeset(connector, state)) ||
+		    (enc_funcs && enc_funcs->atomic_needs_modeset &&
+		     enc_funcs->atomic_needs_modeset(encoder, state))) {
+			if (new_connector_state->crtc) {
+				new_crtc_state =
+					drm_atomic_get_new_crtc_state(state,
+								      new_connector_state->crtc);
+				new_crtc_state->mode_changed = true;
+			}
+
+			if (old_connector_state->crtc) {
+				new_crtc_state =
+					drm_atomic_get_new_crtc_state(state,
+								      old_connector_state->crtc);
+				new_crtc_state->mode_changed = true;
+			}
+		}
+
 		if (funcs->atomic_check)
 			ret = funcs->atomic_check(connector, state);
 		if (ret) {
@@ -746,6 +770,29 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
 		connectors_mask |= BIT(i);
 	}
 
+	for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) {
+		const struct drm_plane_helper_funcs *funcs;
+
+		funcs = plane->helper_private;
+		if (!funcs || !funcs->atomic_needs_modeset)
+			continue;
+
+		if (!funcs->atomic_needs_modeset(plane, state))
+			continue;
+
+		if (new_plane_state->crtc) {
+			new_crtc_state = drm_atomic_get_new_crtc_state(state,
+								       new_plane_state->crtc);
+			new_crtc_state->mode_changed = true;
+		}
+
+		if (old_plane_state->crtc) {
+			new_crtc_state = drm_atomic_get_new_crtc_state(state,
+								       old_plane_state->crtc);
+			new_crtc_state->mode_changed = true;
+		}
+	}
+
 	/*
 	 * After all the routing has been prepared we need to add in any
 	 * connector which is itself unchanged, but whose CRTC changes its
@@ -753,6 +800,18 @@ drm_atomic_helper_check_modeset(struct drm_device *dev,
 	 * crtc only changed its mode but has the same set of connectors.
 	 */
 	for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) {
+		const struct drm_crtc_helper_funcs *funcs;
+
+		if (!new_crtc_state->crtc)
+			continue;
+
+		funcs = crtc->helper_private;
+		if (!funcs || !funcs->atomic_needs_modeset)
+			continue;
+
+		if (funcs->atomic_needs_modeset(crtc, state))
+			new_crtc_state->mode_changed = true;
+
 		if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
 			continue;
 
diff --git a/include/drm/drm_modeset_helper_vtables.h b/include/drm/drm_modeset_helper_vtables.h
index b62f41f489625e5177bdc05eef950e6c18c219fd..a83999109a49321536956c8b1b93fb4b0d0f7ce2 100644
--- a/include/drm/drm_modeset_helper_vtables.h
+++ b/include/drm/drm_modeset_helper_vtables.h
@@ -304,6 +304,29 @@ struct drm_crtc_helper_funcs {
 	 */
 	void (*disable)(struct drm_crtc *crtc);
 
+	/**
+	 * @atomic_needs_modeset:
+	 *
+	 * This function is called at the beginning of
+	 * drm_atomic_helper_check_modeset() to verify whether the CRTC needs a
+	 * full mode set or not.
+	 *
+	 * This hook is optional.
+	 *
+	 * NOTE:
+	 *
+	 * This function is called in the check phase of an atomic update. The
+	 * driver is not allowed to change anything outside of the
+	 * &drm_atomic_state update tracking structure passed in.
+	 *
+	 * RETURNS:
+	 *
+	 * True if the corresponding CRTC should undergo a full modeset, False
+	 * otherwise.
+	 */
+	bool (*atomic_needs_modeset)(struct drm_crtc *crtc,
+				     struct drm_atomic_state *state);
+
 	/**
 	 * @atomic_check:
 	 *
@@ -800,6 +823,29 @@ struct drm_encoder_helper_funcs {
 	 */
 	void (*enable)(struct drm_encoder *encoder);
 
+	/*
+	 * @atomic_needs_modeset:
+	 *
+	 * This function is called at the beginning of
+	 * drm_atomic_helper_check_modeset() to verify whether the connected
+	 * CRTC needs a full mode set or not.
+	 *
+	 * This hook is optional.
+	 *
+	 * NOTE:
+	 *
+	 * This function is called in the check phase of an atomic update. The
+	 * driver is not allowed to change anything outside of the
+	 * &drm_atomic_state update tracking structure passed in.
+	 *
+	 * RETURNS:
+	 *
+	 * True if the corresponding CRTC should undergo a full modeset, False
+	 * otherwise.
+	 */
+	bool (*atomic_needs_modeset)(struct drm_encoder *encoder,
+				     struct drm_atomic_state *state);
+
 	/**
 	 * @atomic_check:
 	 *
@@ -1067,6 +1113,29 @@ struct drm_connector_helper_funcs {
 	struct drm_encoder *(*atomic_best_encoder)(struct drm_connector *connector,
 						   struct drm_atomic_state *state);
 
+	/**
+	 * @atomic_needs_modeset:
+	 *
+	 * This function is called at the beginning of
+	 * drm_atomic_helper_check_modeset() to verify whether the connected
+	 * CRTC needs a full mode set or not.
+	 *
+	 * This hook is optional.
+	 *
+	 * NOTE:
+	 *
+	 * This function is called in the check phase of an atomic update. The
+	 * driver is not allowed to change anything outside of the
+	 * &drm_atomic_state update tracking structure passed in.
+	 *
+	 * RETURNS:
+	 *
+	 * True if the corresponding CRTC should undergo a full modeset, False
+	 * otherwise.
+	 */
+	bool (*atomic_needs_modeset)(struct drm_connector *connector,
+				     struct drm_atomic_state *state);
+
 	/**
 	 * @atomic_check:
 	 *
@@ -1284,6 +1353,29 @@ struct drm_plane_helper_funcs {
 	 */
 	void (*end_fb_access)(struct drm_plane *plane, struct drm_plane_state *new_plane_state);
 
+	/**
+	 * @atomic_needs_modeset:
+	 *
+	 * This function is called at the beginning of
+	 * drm_atomic_helper_check_modeset() to verify whether the connected
+	 * CRTC needs a full mode set or not.
+	 *
+	 * This hook is optional.
+	 *
+	 * NOTE:
+	 *
+	 * This function is called in the check phase of an atomic update. The
+	 * driver is not allowed to change anything outside of the
+	 * &drm_atomic_state update tracking structure passed in.
+	 *
+	 * RETURNS:
+	 *
+	 * True if the corresponding CRTC should undergo a full modeset, False
+	 * otherwise.
+	 */
+	bool (*atomic_needs_modeset)(struct drm_plane *plane,
+				     struct drm_atomic_state *state);
+
 	/**
 	 * @atomic_check:
 	 *

-- 
2.39.5


  reply	other threads:[~2025-01-24 11:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-24 11:14 [PATCH 0/6] drm: introduce atomic_needs_modeset() callbacks Dmitry Baryshkov
2025-01-24 11:14 ` Dmitry Baryshkov [this message]
2025-01-24 11:14 ` [PATCH 2/6] drm/mgag200: move format check to drm_plane_helper.atomic_needs_modeset Dmitry Baryshkov
2025-01-24 11:14 ` [PATCH 3/6] drm/msm/dpu: stop upgrading commits by enabling allow_modeset Dmitry Baryshkov
2025-01-24 11:14 ` [PATCH 4/6] drm/msm/dpu: move CTM check to drm_crtc_helper.atomic_needs_modeset Dmitry Baryshkov
2025-01-24 11:14 ` [PATCH 5/6] drm/msm/dpu: use atomic_needs_modeset for CDM check Dmitry Baryshkov
2025-01-24 11:14 ` [PATCH 6/6] drm/msm: drop msm_atomic_check wrapper Dmitry Baryshkov
2025-01-24 12:10 ` [PATCH 0/6] drm: introduce atomic_needs_modeset() callbacks Ville Syrjälä
2025-01-24 12:59   ` Simona Vetter
2025-01-24 13:12     ` Ville Syrjälä
2025-01-24 15:37       ` Simona Vetter
2025-01-24 16:14         ` Ville Syrjälä
2025-01-27 20:33           ` Simona Vetter
2025-01-24 16:16       ` Dmitry Baryshkov

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=20250124-atomic-needs-modeset-v1-1-b0c05c9eda0f@linaro.org \
    --to=dmitry.baryshkov@linaro.org \
    --cc=airlied@gmail.com \
    --cc=airlied@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=jfalempe@redhat.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=marijn.suijten@somainline.org \
    --cc=mripard@kernel.org \
    --cc=quic_abhinavk@quicinc.com \
    --cc=quic_kalyant@quicinc.com \
    --cc=robdclark@gmail.com \
    --cc=sean@poorly.run \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®