Skip to contentSkip to conversation

drm: Test for primary plane in new drm_atomic_helper_check_crtc_state()

PATCH In review Thomas Zimmermann 2 participants 5 messages Jun 17, 2022 – Jun 24, 2022

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm: Test for primary plane in new drm_atomic_helper_check_crtc_state()

Provide drm_atomic_helper_check_crtc_state() for validating a CRTC state against common constraints. As many CRTC need a primary plane to work correctly, add this as the first test.

The simple-KMS helpers already contain related code. Convert it to the new helper. Also add this test to ast.

The simple-kms changes were tested with simpledrm. The ast changes were tested in AST2300 hardware.

Thomas Zimmermann (3):
drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state() drm/simple-kms: Use drm_atomic_helper_check_crtc_state() drm/ast: Enable primary plane with CRTC

 drivers/gpu/drm/ast/ast_mode.c          | 13 ++++--
 drivers/gpu/drm/drm_atomic_helper.c     | 55 +++++++++++++++++++++++++
 drivers/gpu/drm/drm_simple_kms_helper.c | 14 +++----
 include/drm/drm_atomic_helper.h         |  2 +
 4 files changed, 72 insertions(+), 12 deletions(-)

base-commit: 822a8442835012ce405080cb40f6317ef1e854ac

Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH 1/3 drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state()

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.

---
 drivers/gpu/drm/drm_atomic_helper.c | 55 +++++++++++++++++++++++++++++
 include/drm/drm_atomic_helper.h     |  2 ++
 2 files changed, 57 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +55 -0
index 987e4b212e9f..329d8a3c3d65 100644
@@ -875,6 +875,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
include/drm/drm_atomic_helper.h +2 -0
index 4045e2507e11..2a0b17842402 100644
@@ -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,
Signature · 1 line
2.36.1
author maintainer
#2 lore raw

PATCH 2/3 drm/simple-kms: Use drm_atomic_helper_check_crtc_state()

In reply to Thomas Zimmermann

Simple-KMS helpers guarantee that the CRTC and plane enable flags are synchronized. Implement this with atomic helpers drm_atomic_helper_check_crtc_state() on the CRTC side, and drm_atomic_helper_check_plane_state() on the plane side.

---
 drivers/gpu/drm/drm_simple_kms_helper.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/gpu/drm/drm_simple_kms_helper.c +6 -8
index 72989ed1baba..36633590ebf3 100644
@@ -100,14 +100,12 @@ drm_simple_kms_crtc_mode_valid(struct drm_crtc *crtc,
 static int drm_simple_kms_crtc_check(struct drm_crtc *crtc,
 				     struct drm_atomic_state *state)
 {
-	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
-									  crtc);
-	bool has_primary = crtc_state->plane_mask &
-			   drm_plane_mask(crtc->primary);
+	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
+	int ret;
 
-	/* We always want to have an active plane with an active CRTC */
-	if (has_primary != crtc_state->enable)
-		return -EINVAL;
+	ret = drm_atomic_helper_check_crtc_state(crtc_state, false);
+	if (ret)
+		return ret;
 
 	return drm_atomic_add_affected_planes(state, crtc);
 }
@@ -227,7 +225,7 @@ static int drm_simple_kms_plane_atomic_check(struct drm_plane *plane,
 	ret = drm_atomic_helper_check_plane_state(plane_state, crtc_state,
 						  DRM_PLANE_HELPER_NO_SCALING,
 						  DRM_PLANE_HELPER_NO_SCALING,
-						  false, true);
+						  false, false);
 	if (ret)
 		return ret;
 
Signature · 1 line
2.36.1
author maintainer
#3 lore raw

PATCH 3/3 drm/ast: Enable primary plane with CRTC

In reply to Thomas Zimmermann

As the CRTC requires a primary plane for display, ensure that the primary plane is enabled with the CRTC.

Use drm_atomic_helper_check_crtc_state(). Add all affected planes to the atomic state so that their state will be checked as well.

---
 drivers/gpu/drm/ast/ast_mode.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +9 -4
index db2010a55674..e992e07a26f9 100644
@@ -1094,15 +1094,19 @@ ast_crtc_helper_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode
 static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
 					struct drm_atomic_state *state)
 {
-	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state,
-									  crtc);
+	struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
 	struct drm_device *dev = crtc->dev;
 	struct ast_crtc_state *ast_state;
 	const struct drm_format_info *format;
 	bool succ;
+	int ret;
+
+	ret = drm_atomic_helper_check_crtc_state(crtc_state, false);
+	if (ret)
+		return ret;
 
 	if (!crtc_state->enable)
-		return 0; /* no mode checks if CRTC is being disabled */
+		goto out;
 
 	ast_state = to_ast_crtc_state(crtc_state);
 
@@ -1116,7 +1120,8 @@ static int ast_crtc_helper_atomic_check(struct drm_crtc *crtc,
 	if (!succ)
 		return -EINVAL;
 
-	return 0;
+out:
+	return drm_atomic_add_affected_planes(state, crtc);
 }
 
 static void ast_crtc_helper_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state)
Signature · 1 line
2.36.1
#4 lore raw
In reply to Thomas Zimmermann
Quoted 15 lines · Thomas Zimmermann

Provide drm_atomic_helper_check_crtc_state() for validating a CRTC state against common constraints. As many CRTC need a primary plane to work correctly, add this as the first test.

The simple-KMS helpers already contain related code. Convert it to the new helper. Also add this test to ast.

The simple-kms changes were tested with simpledrm. The ast changes were tested in AST2300 hardware.

Thomas Zimmermann (3):
drm/atomic-helper: Add helper drm_atomic_helper_check_crtc_state() drm/simple-kms: Use drm_atomic_helper_check_crtc_state() drm/ast: Enable primary plane with CRTC

Quoted 8 lines
  drivers/gpu/drm/ast/ast_mode.c          | 13 ++++--
  drivers/gpu/drm/drm_atomic_helper.c     | 55 +++++++++++++++++++++++++
  drivers/gpu/drm/drm_simple_kms_helper.c | 14 +++----
  include/drm/drm_atomic_helper.h         |  2 +
  4 files changed, 72 insertions(+), 12 deletions(-)

base-commit: 822a8442835012ce405080cb40f6317ef1e854ac

the whole serie looks good to me,

Acked-by Jocelyn Falempe <[email protected]>