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 <nfrapr...@collabora.com>
---
 drivers/gpu/drm/drm_atomic_uapi.c | 49 +++++++++++++++++++++++++++++++++++----
 drivers/gpu/drm/drm_crtc.c        | 33 ++++++++++++++++++++++++++
 include/drm/drm_atomic_uapi.h     |  2 ++
 include/drm/drm_crtc.h            | 11 +++++++++
 4 files changed, 91 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_atomic_uapi.c 
b/drivers/gpu/drm/drm_atomic_uapi.c
index 
b7cc6945864274bedd21dd5b73494f9aae216888..063c142fd9b656e228cfc660d005a3fbb4640d32
 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -287,6 +287,33 @@ 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
@@ -396,8 +423,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;
@@ -406,7 +433,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);
@@ -487,6 +524,8 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
                *val = 0;
        else if (property == crtc->scaling_filter_property)
                *val = state->scaling_filter;
+       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 {
@@ -1047,6 +1086,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);
@@ -1204,7 +1245,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 
94e60cffd29972aa979ac2f1932be7a6a97f3ada..94238163ff1254c721df39c030bc99a31d3bb92a
 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -1003,3 +1003,36 @@ drm_common_create_color_pipeline_property(struct 
drm_device *dev, struct drm_mod
        kfree(all_pipelines);
        return prop;
 }
+
+/**
+ * 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_common_create_color_pipeline_property(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 
4363155233267b93767c895fa6085544e2277442..4dc191f6f929d73deee9812025c48275a33cf770
 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 
77c0c04a5910a2263923e06cf37535697e20e1c9..df03637ca25abd45e96b5944229297f776fd046d
 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -1096,6 +1096,14 @@ struct drm_crtc {
         */
        struct drm_property *scaling_filter_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:
         *
@@ -1331,5 +1339,8 @@ 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);
 #endif /* __DRM_CRTC_H__ */

-- 
2.50.1

Reply via email to