@@ -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;
@@ -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:
*
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(+)