From: "NĂ­colas F. R. A. Prado" <[email protected]>

Add a COLOR_PIPELINE property to the CRTC to allow userspace to set a
post-blend color pipeline analogously to how pre-blend color pipelines
are set on planes.

Signed-off-by: NĂ­colas F. R. A. Prado <[email protected]>
Co-developed-by: Ariel D'Alessandro <[email protected]>
Signed-off-by: Ariel D'Alessandro <[email protected]>
---
 drivers/gpu/drm/drm_atomic_uapi.c | 50 +++++++++++++++++++++++++++++++++++----
 drivers/gpu/drm/drm_crtc.c        | 31 ++++++++++++++++++++++++
 include/drm/drm_atomic_uapi.h     |  2 ++
 include/drm/drm_crtc.h            | 11 +++++++++
 4 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_uapi.c 
b/drivers/gpu/drm/drm_atomic_uapi.c
index 7320db4b8489f..07d0d224fe58c 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -286,6 +286,34 @@ drm_atomic_set_colorop_for_plane(struct drm_plane_state 
*plane_state,
 }
 EXPORT_SYMBOL(drm_atomic_set_colorop_for_plane);
 
+/**
+ * drm_atomic_set_colorop_for_crtc - set colorop for crtc
+ * @crtc_state: atomic state object for the crtc
+ * @colorop: colorop to use for the crtc
+ *
+ * Helper function to select the color pipeline on a crtc by setting
+ * it to the first drm_colorop element of the pipeline.
+ */
+void
+drm_atomic_set_colorop_for_crtc(struct drm_crtc_state *crtc_state,
+                                struct drm_colorop *colorop)
+{
+       struct drm_crtc *crtc = crtc_state->crtc;
+
+       if (colorop)
+               drm_dbg_atomic(crtc->dev,
+                              "Set [COLOROP:%d] for [CRTC:%d:%s] state %p\n",
+                              colorop->base.id, crtc->base.id, crtc->name,
+                              crtc_state);
+       else
+               drm_dbg_atomic(crtc->dev,
+                              "Set [NOCOLOROP] for [CRTC:%d:%s] state %p\n",
+                              crtc->base.id, crtc->name, crtc_state);
+
+       crtc_state->color_pipeline = colorop;
+}
+EXPORT_SYMBOL(drm_atomic_set_colorop_for_crtc);
+
 /**
  * drm_atomic_set_crtc_for_connector - set CRTC for connector
  * @conn_state: atomic state object for the connector
@@ -394,8 +422,8 @@ static s32 __user *get_out_fence_for_connector(struct 
drm_atomic_state *state,
 }
 
 static int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
-               struct drm_crtc_state *state, struct drm_property *property,
-               uint64_t val)
+               struct drm_crtc_state *state, struct drm_file *file_priv,
+               struct drm_property *property, uint64_t val)
 {
        struct drm_device *dev = crtc->dev;
        struct drm_mode_config *config = &dev->mode_config;
@@ -404,7 +432,17 @@ static int drm_atomic_crtc_set_property(struct drm_crtc 
*crtc,
 
        if (property == config->prop_active)
                state->active = val;
-       else if (property == config->prop_mode_id) {
+       else if (property == crtc->color_pipeline_property) {
+               /* find DRM colorop object */
+               struct drm_colorop *colorop = NULL;
+
+               colorop = drm_colorop_find(dev, file_priv, val);
+
+               if (val && !colorop)
+                       return -EACCES;
+
+               drm_atomic_set_colorop_for_crtc(state, colorop);
+       } else if (property == config->prop_mode_id) {
                struct drm_property_blob *mode =
                        drm_property_lookup_blob(dev, val);
                ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
@@ -489,6 +527,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
                *val = state->scaling_filter;
        else if (property == crtc->sharpness_strength_property)
                *val = state->sharpness_strength;
+       else if (property == crtc->color_pipeline_property)
+               *val = (state->color_pipeline) ? state->color_pipeline->base.id 
: 0;
        else if (crtc->funcs->atomic_get_property)
                return crtc->funcs->atomic_get_property(crtc, state, property, 
val);
        else {
@@ -1050,6 +1090,8 @@ int drm_atomic_get_property(struct drm_mode_object *obj,
 
                if (colorop->plane)
                        WARN_ON(!drm_modeset_is_locked(&colorop->plane->mutex));
+               else if (colorop->crtc)
+                       WARN_ON(!drm_modeset_is_locked(&colorop->crtc->mutex));
 
                ret = drm_atomic_colorop_get_property(colorop, colorop->state, 
property, val);
                break;
@@ -1206,7 +1248,7 @@ int drm_atomic_set_property(struct drm_atomic_state 
*state,
                }
 
                ret = drm_atomic_crtc_set_property(crtc,
-                               crtc_state, prop, prop_value);
+                               crtc_state, file_priv, prop, prop_value);
                break;
        }
        case DRM_MODE_OBJECT_PLANE: {
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index a7797d260f1e2..133ff9212fbc4 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -994,3 +994,34 @@ bool drm_crtc_in_clone_mode(struct drm_crtc_state 
*crtc_state)
        return hweight32(crtc_state->encoder_mask) > 1;
 }
 EXPORT_SYMBOL(drm_crtc_in_clone_mode);
+
+/**
+ * drm_crtc_create_color_pipeline_property - create a new color pipeline
+ * property
+ *
+ * @crtc: drm CRTC
+ * @pipelines: list of pipelines
+ * @num_pipelines: number of pipelines
+ *
+ * Create the COLOR_PIPELINE CRTC property to specify color pipelines on
+ * the CRTC.
+ *
+ * RETURNS:
+ * Zero for success or -errno
+ */
+int drm_crtc_create_color_pipeline_property(struct drm_crtc *crtc,
+                                           const struct drm_prop_enum_list 
*pipelines,
+                                           int num_pipelines)
+{
+       struct drm_property *prop;
+
+       prop = drm_property_create_color_pipeline(crtc->dev, &crtc->base,
+                                                 pipelines, num_pipelines);
+       if (IS_ERR(prop))
+               return PTR_ERR(prop);
+
+       crtc->color_pipeline_property = prop;
+
+       return 0;
+}
+EXPORT_SYMBOL(drm_crtc_create_color_pipeline_property);
diff --git a/include/drm/drm_atomic_uapi.h b/include/drm/drm_atomic_uapi.h
index 4363155233267..4dc191f6f929d 100644
--- a/include/drm/drm_atomic_uapi.h
+++ b/include/drm/drm_atomic_uapi.h
@@ -52,6 +52,8 @@ void drm_atomic_set_fb_for_plane(struct drm_plane_state 
*plane_state,
                                 struct drm_framebuffer *fb);
 void drm_atomic_set_colorop_for_plane(struct drm_plane_state *plane_state,
                                      struct drm_colorop *colorop);
+void drm_atomic_set_colorop_for_crtc(struct drm_crtc_state *crtc_state,
+                                    struct drm_colorop *colorop);
 int __must_check
 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
                                  struct drm_crtc *crtc);
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 8490f4bc31260..b3c9818715851 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -1113,6 +1113,14 @@ struct drm_crtc {
         */
        struct drm_property *sharpness_strength_property;
 
+       /**
+        * @color_pipeline_property:
+        *
+        * Optional "COLOR_PIPELINE" enum property for specifying
+        * a color pipeline to use on the CRTC.
+        */
+       struct drm_property *color_pipeline_property;
+
        /**
         * @state:
         *
@@ -1348,6 +1356,9 @@ static inline struct drm_crtc *drm_crtc_find(struct 
drm_device *dev,
 
 int drm_crtc_create_scaling_filter_property(struct drm_crtc *crtc,
                                            unsigned int supported_filters);
+int drm_crtc_create_color_pipeline_property(struct drm_crtc *crtc,
+                                            const struct drm_prop_enum_list 
*pipelines,
+                                            int num_pipelines);
 bool drm_crtc_in_clone_mode(struct drm_crtc_state *crtc_state);
 int drm_crtc_create_sharpness_strength_property(struct drm_crtc *crtc);
 #endif /* __DRM_CRTC_H__ */

-- 
2.51.0

Reply via email to