]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()
authorThomas Zimmermann <tzimmermann@suse.de>
Fri, 17 Jun 2022 10:32:24 +0000 (12:32 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Mon, 27 Jun 2022 09:10:43 +0000 (11:10 +0200)
Add drm_atomic_helper_check_crtc_state(), which contains tests common
to many CRTCs. The first added test verifies that an enabled CRTC has
at least one enabled primary plane.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220617103226.25617-2-tzimmermann@suse.de
drivers/gpu/drm/drm_atomic_helper.c
include/drm/drm_atomic_helper.h

index 0f685f4b29113258550d8a732e8fe6eb8cfa8522..8bf41aa240687e50aa1bbbcc850cc7bc224a5d7b 100644 (file)
@@ -877,6 +877,61 @@ 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
+ * @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.
+ *
+ * RETURNS:
+ * Zero if update appears valid, error code on failure
+ */
+int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
+                                      bool can_disable_primary_planes)
+{
+       struct drm_device *dev = crtc_state->crtc->dev;
+       struct drm_atomic_state *state = crtc_state->state;
+
+       if (!crtc_state->enable)
+               return 0;
+
+       /* 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) {
+                       struct drm_plane_state *plane_state;
+
+                       if (plane->type != DRM_PLANE_TYPE_PRIMARY)
+                               continue;
+                       plane_state = drm_atomic_get_plane_state(state, plane);
+                       if (IS_ERR(plane_state))
+                               return PTR_ERR(plane_state);
+                       if (plane_state->fb && plane_state->crtc) {
+                               has_primary_plane = true;
+                               break;
+                       }
+               }
+               if (!has_primary_plane) {
+                       drm_dbg_kms(dev, "Cannot enable CRTC without a primary plane.\n");
+                       return -EINVAL;
+               }
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(drm_atomic_helper_check_crtc_state);
+
 /**
  * drm_atomic_helper_check_planes - validate state object for planes changes
  * @dev: DRM device
index 4045e2507e11c438340f2ec61662fc5571c53a21..2a0b17842402c6af82b6cab2f2fbed1dba8eb2d5 100644 (file)
@@ -46,6 +46,8 @@ 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(struct drm_device *dev,