drm/atomic-helper: Replace drm_atomic_helper_check_crtc_state()
authorThomas Zimmermann <tzimmermann@suse.de>
Fri, 7 Oct 2022 12:43:38 +0000 (14:43 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Sat, 8 Oct 2022 13:26:55 +0000 (15:26 +0200)
Rename the atomic helper function drm_atomic_helper_check_crtc_state()
to drm_atomic_helper_check_crtc_primary_plane() and only check for an
attached primary plane. Adapt callers.

Instead of having one big function to check for various CRTC state
conditions, we rather want smaller functions that drivers can pick
individually.

v5:
* rebase on top of udl changes

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20221007124338.24152-3-tzimmermann@suse.de
drivers/gpu/drm/ast/ast_mode.c
drivers/gpu/drm/drm_atomic_helper.c
drivers/gpu/drm/drm_simple_kms_helper.c
drivers/gpu/drm/mgag200/mgag200_mode.c
drivers/gpu/drm/solomon/ssd130x.c
drivers/gpu/drm/tiny/simpledrm.c
drivers/gpu/drm/udl/udl_modeset.c
include/drm/drm_atomic_helper.h

index 8ff998da71ef5754d9a700487923fbe05c8f3884..d5ee3ad538a8c5e671f985112288e4746892487e 100644 (file)
@@ -1161,13 +1161,13 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
        bool succ;
        int ret;
 
-       ret = drm_atomic_helper_check_crtc_state(crtc_state, false);
-       if (ret)
-               return ret;
-
        if (!crtc_state->enable)
                goto out;
 
+       ret = drm_atomic_helper_check_crtc_primary_plane(crtc_state);
+       if (ret)
+               return ret;
+
        ast_state = to_ast_crtc_state(crtc_state);
 
        format = ast_state->format;
index 02b4a7dc92f5e4f3069935cffc996bf31558e57a..1a586b3c454b49e110bacb18856e654558555336 100644 (file)
@@ -924,51 +924,35 @@ int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
 EXPORT_SYMBOL(drm_atomic_helper_check_plane_state);
 
 /**
- * drm_atomic_helper_check_crtc_state() - Check CRTC state for validity
+ * drm_atomic_helper_check_crtc_primary_plane() - Check CRTC state for primary plane
  * @crtc_state: CRTC state to check
- * @can_disable_primary_planes: can the CRTC be enabled without a primary plane?
  *
- * Checks that a desired CRTC update is valid. Drivers that provide
- * their own CRTC handling rather than helper-provided implementations may
- * still wish to call this function to avoid duplication of error checking
- * code.
- *
- * Note that @can_disable_primary_planes only tests if the CRTC can be
- * enabled without a primary plane. To test if a primary plane can be updated
- * without a CRTC, use drm_atomic_helper_check_plane_state() in the plane's
- * atomic check.
+ * Checks that a CRTC has at least one primary plane attached to it, which is
+ * a requirement on some hardware. Note that this only involves the CRTC side
+ * of the test. To test if the primary plane is visible or if it can be updated
+ * without the CRTC being enabled, use drm_atomic_helper_check_plane_state() in
+ * the plane's atomic check.
  *
  * RETURNS:
- * Zero if update appears valid, error code on failure
+ * 0 if a primary plane is attached to the CRTC, or an error code otherwise
  */
-int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
-                                      bool can_disable_primary_planes)
+int drm_atomic_helper_check_crtc_primary_plane(struct drm_crtc_state *crtc_state)
 {
-       struct drm_device *dev = crtc_state->crtc->dev;
-
-       if (!crtc_state->enable)
-               return 0;
+       struct drm_crtc *crtc = crtc_state->crtc;
+       struct drm_device *dev = crtc->dev;
+       struct drm_plane *plane;
 
        /* needs at least one primary plane to be enabled */
-       if (!can_disable_primary_planes) {
-               bool has_primary_plane = false;
-               struct drm_plane *plane;
-
-               drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
-                       if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
-                               has_primary_plane = true;
-                               break;
-                       }
-               }
-               if (!has_primary_plane) {
-                       drm_dbg_kms(dev, "Cannot enable CRTC without a primary plane.\n");
-                       return -EINVAL;
-               }
+       drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) {
+               if (plane->type == DRM_PLANE_TYPE_PRIMARY)
+                       return 0;
        }
 
-       return 0;
+       drm_dbg_atomic(dev, "[CRTC:%d:%s] primary plane missing\n", crtc->base.id, crtc->name);
+
+       return -EINVAL;
 }
-EXPORT_SYMBOL(drm_atomic_helper_check_crtc_state);
+EXPORT_SYMBOL(drm_atomic_helper_check_crtc_primary_plane);
 
 /**
  * drm_atomic_helper_check_planes - validate state object for planes changes
index e9f782119d3db4f27dfec6cad15716c0564f49c2..31233c6ae3c42bee6e499ada1f2411afe7aab746 100644 (file)
@@ -102,10 +102,14 @@ static int drm_simple_kms_crtc_check(struct drm_crtc *crtc,
        struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
        int ret;
 
-       ret = drm_atomic_helper_check_crtc_state(crtc_state, false);
+       if (!crtc_state->enable)
+               goto out;
+
+       ret = drm_atomic_helper_check_crtc_primary_plane(crtc_state);
        if (ret)
                return ret;
 
+out:
        return drm_atomic_add_affected_planes(state, crtc);
 }
 
index bbab2549243abceebf5a4bf6a033b6edcebd925b..5f7eb642f0c6ee4cbaa6dac05241e68e916e4f65 100644 (file)
@@ -579,13 +579,13 @@ int mgag200_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic_st
        struct drm_property_blob *new_gamma_lut = new_crtc_state->gamma_lut;
        int ret;
 
-       ret = drm_atomic_helper_check_crtc_state(new_crtc_state, false);
-       if (ret)
-               return ret;
-
        if (!new_crtc_state->enable)
                return 0;
 
+       ret = drm_atomic_helper_check_crtc_primary_plane(new_crtc_state);
+       if (ret)
+               return ret;
+
        if (new_crtc_state->mode_changed) {
                if (funcs->pixpllc_atomic_check) {
                        ret = funcs->pixpllc_atomic_check(crtc, new_state);
index f456b233d2e7353187bb1ed43f9df9f8548876ba..57e48355c008cd3bc2047101d5a8d1cbb3eb199d 100644 (file)
@@ -651,10 +651,14 @@ static int ssd130x_crtc_helper_atomic_check(struct drm_crtc *crtc,
        struct drm_crtc_state *new_crtc_state = drm_atomic_get_new_crtc_state(new_state, crtc);
        int ret;
 
-       ret = drm_atomic_helper_check_crtc_state(new_crtc_state, false);
+       if (!new_crtc_state->enable)
+               goto out;
+
+       ret = drm_atomic_helper_check_crtc_primary_plane(new_crtc_state);
        if (ret)
                return ret;
 
+out:
        return drm_atomic_add_affected_planes(new_state, crtc);
 }
 
index 18489779fb8aa335948f1222f9c04226cb7f8663..ecd49a8f33340a66c85e49f7149aad55044c1834 100644 (file)
@@ -551,10 +551,14 @@ static int simpledrm_crtc_helper_atomic_check(struct drm_crtc *crtc,
        struct drm_crtc_state *new_crtc_state = drm_atomic_get_new_crtc_state(new_state, crtc);
        int ret;
 
-       ret = drm_atomic_helper_check_crtc_state(new_crtc_state, false);
+       if (!new_crtc_state->enable)
+               goto out;
+
+       ret = drm_atomic_helper_check_crtc_primary_plane(new_crtc_state);
        if (ret)
                return ret;
 
+out:
        return drm_atomic_add_affected_planes(new_state, crtc);
 }
 
index 3a25f3fc2b22af84c363d58e47193ac46d7ca3cd..4b79d44752c9215bbd2ad94abdd081648653e46f 100644 (file)
@@ -315,7 +315,10 @@ static int udl_crtc_helper_atomic_check(struct drm_crtc *crtc, struct drm_atomic
 {
        struct drm_crtc_state *new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 
-       return drm_atomic_helper_check_crtc_state(new_crtc_state, false);
+       if (!new_crtc_state->enable)
+               return 0;
+
+       return drm_atomic_helper_check_crtc_primary_plane(new_crtc_state);
 }
 
 static void udl_crtc_helper_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
index 06d8902a809722b8c5e8a1351c22da54eda46ffc..33f982cd1a27748804241fef68f319e9b722737c 100644 (file)
@@ -58,10 +58,9 @@ int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
                                        int max_scale,
                                        bool can_position,
                                        bool can_update_disabled);
-int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
-                                      bool can_disable_primary_plane);
 int drm_atomic_helper_check_planes(struct drm_device *dev,
                               struct drm_atomic_state *state);
+int drm_atomic_helper_check_crtc_primary_plane(struct drm_crtc_state *crtc_state);
 int drm_atomic_helper_check(struct drm_device *dev,
                            struct drm_atomic_state *state);
 void drm_atomic_helper_commit_tail(struct drm_atomic_state *state);