If colorop TYPE requires a data blob, userspace have to set a blob
whenever enables this colorop, i.e. when setting this colorop bypass
property to false. Clarify this in the documentation and reject the
atomic commit if colorop TYPE requires a DATA but set bypass to false
and no blob submitted.
Fixes: e5719e7f1900 ("drm/colorop: Add 3x4 CTM type")
Reviewed-by: Harry Wentland <[email protected]>
Signed-off-by: Melissa Wen <[email protected]>
---
drivers/gpu/drm/drm_atomic.c | 22 ++++++++++++++++++++--
drivers/gpu/drm/drm_colorop.c | 5 ++++-
include/drm/drm_colorop.h | 6 ++++--
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 36c9550c2749..d8b56fa47d45 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -990,8 +990,13 @@ drm_atomic_add_pipeline_colorops(struct drm_atomic_commit
*state,
* drm_atomic_colorop_check - check new colorop state
* @new_colorop_state: new colorop state to check
*
- * Ensure that the colorop in @new_colorop_state belongs to an active color
- * pipeline, i.e. it's in the chain of colorops set to the color_pipeline
+ * Check that a colorop whose TYPE requires a data blob has one when it's
+ * enabled, i.e. userspace can't clear (or never set) the DATA property while
+ * taking the colorop out of bypass, since drivers would have nothing to
+ * program.
+ *
+ * Also ensure that the colorop in @new_colorop_state belongs to an active
+ * color pipeline, i.e. it's in the chain of colorops set to the color_pipeline
* property of current, old or new plane state.
*
* Userspace is allowed to finalize colorop's settings in the same commit that
@@ -1015,6 +1020,19 @@ static int drm_atomic_colorop_check(const struct
drm_colorop_state *new_colorop_
if (state->duplicated)
return 0;
+ /*
+ * Reject if colorop TYPE requires a DATA but set bypass to false and
+ * no blob submitted
+ */
+ if (new_colorop_state->colorop->data_property &&
+ !new_colorop_state->bypass && !new_colorop_state->data) {
+ drm_dbg_atomic(new_colorop_state->colorop->dev,
+ "[COLOROP:%d:%d] enabled without a DATA blob\n",
+ new_colorop_state->colorop->base.id,
+ new_colorop_state->colorop->type);
+ return -EINVAL;
+ }
+
/* Not a plane colorop */
if (!plane)
return 0;
diff --git a/drivers/gpu/drm/drm_colorop.c b/drivers/gpu/drm/drm_colorop.c
index 95da03d6c65c..842fd7dc31e6 100644
--- a/drivers/gpu/drm/drm_colorop.c
+++ b/drivers/gpu/drm/drm_colorop.c
@@ -55,7 +55,10 @@
* enumerated 1D curves, 1D LUTs, 3D LUTs, matrices, etc. See the
* &drm_colorop_type documentation for information on each type.
*
- * If a colorop advertises the BYPASS property it can be bypassed.
+ * If a colorop advertises the BYPASS property it can be bypassed. If a
+ * colorop advertises DATA and BYPASS properties, BYPASS can only be set to
+ * false if DATA contains a blob. An atomic commit that leaves such a
+ * colorop enabled without a blob will fail, returning -EINVAL.
*
* Information about colorop and color pipeline design decisions can be
* found at rfc/color_pipeline.rst, but note that this document will
diff --git a/include/drm/drm_colorop.h b/include/drm/drm_colorop.h
index 11a88e9477f1..952c30b06d83 100644
--- a/include/drm/drm_colorop.h
+++ b/include/drm/drm_colorop.h
@@ -283,8 +283,10 @@ struct drm_colorop_state {
/**
* @data:
*
- * Data blob for any TYPE that requires such a blob. The
- * interpretation of the blob is TYPE-specific.
+ * Data blob for any TYPE that requires such a blob. The interpretation
+ * of the blob is TYPE-specific. Whenever @bypass is false, @data must
+ * be provided; otherwise, the atomic check will reject an active
+ * colorop without a blob.
*
* See the &drm_colorop_type documentation for how blob is laid
* out.
--
2.53.0