All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harry Wentland <harry.wentland@amd.com>
To: <dri-devel@lists.freedesktop.org>, <amd-gfx@lists.freedesktop.org>
Cc: <wayland-devel@lists.freedesktop.org>,
	Harry Wentland <harry.wentland@amd.com>
Subject: [RFC PATCH v4 15/42] drm/plane: Add COLOR PIPELINE property
Date: Mon, 26 Feb 2024 16:10:29 -0500	[thread overview]
Message-ID: <20240226211100.100108-16-harry.wentland@amd.com> (raw)
In-Reply-To: <20240226211100.100108-1-harry.wentland@amd.com>

We're adding a new enum COLOR PIPELINE property. This
property will have entries for each COLOR PIPELINE by
referencing the DRM object ID of the first drm_colorop
of the pipeline. 0 disables the entire COLOR PIPELINE.

Userspace can use this to discover the available color
pipelines, as well as set the desired one. The color
pipelines are programmed via properties on the actual
drm_colorop objects.

v4:
 - Add pipeline property creation helper (Pekka)
 - Fix function comment for
   drm_atomic_set_colorop_for_plane (Pekka)
 - Always create Bypass pipeline (Pekka)
 - Add missing function declaration (Chaitanya Kumar Borah)

Signed-off-by: Harry Wentland <harry.wentland@amd.com>
---
 drivers/gpu/drm/drm_atomic.c              | 46 ++++++++++++++++++++
 drivers/gpu/drm/drm_atomic_state_helper.c |  5 +++
 drivers/gpu/drm/drm_atomic_uapi.c         | 42 ++++++++++++++++++
 drivers/gpu/drm/drm_plane.c               | 52 +++++++++++++++++++++++
 include/drm/drm_atomic.h                  |  3 ++
 include/drm/drm_atomic_uapi.h             |  2 +
 include/drm/drm_plane.h                   | 11 +++++
 7 files changed, 161 insertions(+)

diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c
index 3645c36d63b3..27a8805c5fa1 100644
--- a/drivers/gpu/drm/drm_atomic.c
+++ b/drivers/gpu/drm/drm_atomic.c
@@ -1458,6 +1458,52 @@ drm_atomic_add_affected_planes(struct drm_atomic_state *state,
 }
 EXPORT_SYMBOL(drm_atomic_add_affected_planes);
 
+/**
+ * drm_atomic_add_affected_colorops - add colorops for plane
+ * @state: atomic state
+ * @plane: DRM plane
+ *
+ * This function walks the current configuration and adds all colorops
+ * currently used by @plane to the atomic configuration @state. This is useful
+ * when an atomic commit also needs to check all currently enabled colorop on
+ * @plane, e.g. when changing the mode. It's also useful when re-enabling a plane
+ * to avoid special code to force-enable all colorops.
+ *
+ * Since acquiring a colorop state will always also acquire the w/w mutex of the
+ * current plane for that colorop (if there is any) adding all the colorop states for
+ * a plane will not reduce parallelism of atomic updates.
+ *
+ * Returns:
+ * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
+ * then the w/w mutex code has detected a deadlock and the entire atomic
+ * sequence must be restarted. All other errors are fatal.
+ */
+int
+drm_atomic_add_affected_colorops(struct drm_atomic_state *state,
+				 struct drm_plane *plane)
+{
+	struct drm_colorop *colorop;
+	struct drm_colorop_state *colorop_state;
+
+	WARN_ON(!drm_atomic_get_new_plane_state(state, plane));
+
+	drm_dbg_atomic(plane->dev,
+		       "Adding all current colorops for [plane:%d:%s] to %p\n",
+		       plane->base.id, plane->name, state);
+
+	drm_for_each_colorop(colorop, plane->dev) {
+		if (colorop->plane != plane)
+			continue;
+
+		colorop_state = drm_atomic_get_colorop_state(state, colorop);
+		if (IS_ERR(colorop_state))
+			return PTR_ERR(colorop_state);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_atomic_add_affected_colorops);
+
 /**
  * drm_atomic_check_only - check whether a given config would work
  * @state: atomic configuration to check
diff --git a/drivers/gpu/drm/drm_atomic_state_helper.c b/drivers/gpu/drm/drm_atomic_state_helper.c
index 519228eb1095..d1dd082b1286 100644
--- a/drivers/gpu/drm/drm_atomic_state_helper.c
+++ b/drivers/gpu/drm/drm_atomic_state_helper.c
@@ -267,6 +267,11 @@ void __drm_atomic_helper_plane_state_reset(struct drm_plane_state *plane_state,
 			plane_state->color_range = val;
 	}
 
+	if (plane->color_pipeline_property) {
+		/* default is always NULL, i.e., bypass */
+		plane_state->color_pipeline = NULL;
+	}
+
 	if (plane->zpos_property) {
 		if (!drm_object_property_get_default_value(&plane->base,
 							   plane->zpos_property,
diff --git a/drivers/gpu/drm/drm_atomic_uapi.c b/drivers/gpu/drm/drm_atomic_uapi.c
index 87f00131be11..86f77a9aa3a8 100644
--- a/drivers/gpu/drm/drm_atomic_uapi.c
+++ b/drivers/gpu/drm/drm_atomic_uapi.c
@@ -256,6 +256,36 @@ drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
 }
 EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
 
+
+/**
+ * drm_atomic_set_colorop_for_plane - set colorop for plane
+ * @plane_state: atomic state object for the plane
+ * @colorop: colorop to use for the plane
+ *
+ * Helper function to select the color pipeline on a plane by setting
+ * it to the first drm_colorop element of the pipeline.
+ */
+void
+drm_atomic_set_colorop_for_plane(struct drm_plane_state *plane_state,
+				 struct drm_colorop *colorop)
+{
+	struct drm_plane *plane = plane_state->plane;
+
+	if (colorop)
+		drm_dbg_atomic(plane->dev,
+			       "Set [COLOROP:%d] for [PLANE:%d:%s] state %p\n",
+			       colorop->base.id, plane->base.id, plane->name,
+			       plane_state);
+	else
+		drm_dbg_atomic(plane->dev,
+			       "Set [NOCOLOROP] for [PLANE:%d:%s] state %p\n",
+			       plane->base.id, plane->name, plane_state);
+
+	plane_state->color_pipeline = colorop;
+}
+EXPORT_SYMBOL(drm_atomic_set_colorop_for_plane);
+
+
 /**
  * drm_atomic_set_crtc_for_connector - set CRTC for connector
  * @conn_state: atomic state object for the connector
@@ -539,6 +569,16 @@ static int drm_atomic_plane_set_property(struct drm_plane *plane,
 		state->color_encoding = val;
 	} else if (property == plane->color_range_property) {
 		state->color_range = val;
+	} else if (property == plane->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;
+
+		/* set it on drm_plane_state */
+		drm_atomic_set_colorop_for_plane(state, colorop);
 	} else if (property == config->prop_fb_damage_clips) {
 		ret = drm_property_replace_blob_from_id(dev,
 					&state->fb_damage_clips,
@@ -621,6 +661,8 @@ drm_atomic_plane_get_property(struct drm_plane *plane,
 		*val = state->color_encoding;
 	} else if (property == plane->color_range_property) {
 		*val = state->color_range;
+	} else if (property == plane->color_pipeline_property) {
+		*val = (state->color_pipeline) ? state->color_pipeline->base.id : 0;
 	} else if (property == config->prop_fb_damage_clips) {
 		*val = (state->fb_damage_clips) ?
 			state->fb_damage_clips->base.id : 0;
diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c
index 672c655c7a8e..a747bd9eb20b 100644
--- a/drivers/gpu/drm/drm_plane.c
+++ b/drivers/gpu/drm/drm_plane.c
@@ -1729,3 +1729,55 @@ int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
 	return 0;
 }
 EXPORT_SYMBOL(drm_plane_create_scaling_filter_property);
+
+#define MAX_COLOR_PIPELINES 5
+
+/**
+ * drm_plane_create_color_pipeline_property - create a new color pipeline
+ * property
+ *
+ * @plane: drm plane
+ * @pipelines: list of pipelines
+ * @num_pipelines: number of pipelines
+ *
+ * Create the COLOR_PIPELINE plane property to specific color pipelines on
+ * the plane.
+ *
+ * RETURNS:
+ * Zero for success or -errno
+ */
+int drm_plane_create_color_pipeline_property(struct drm_plane *plane,
+					     struct drm_prop_enum_list *pipelines,
+					     int num_pipelines)
+{
+	struct drm_prop_enum_list all_pipelines[MAX_COLOR_PIPELINES];
+	int len = 0;
+	int i;
+	struct drm_property *prop;
+
+	if (num_pipelines > (MAX_COLOR_PIPELINES - 1))
+		return -EINVAL;
+
+	/* Create default Bypass color pipeline */
+	all_pipelines[len].type = 0;
+	all_pipelines[len].name = "Bypass";
+	len++;
+
+	/* Add all other color pipelines */
+	for (i = 0; i < num_pipelines; i++, len++) {
+		all_pipelines[len].type = pipelines[i].type;
+		all_pipelines[len].name = pipelines[i].name;
+	}
+
+	prop = drm_property_create_enum(plane->dev, DRM_MODE_PROP_ATOMIC,
+					"COLOR_PIPELINE",
+					all_pipelines, len);
+	if (IS_ERR(prop))
+		return PTR_ERR(prop);
+
+	drm_object_attach_property(&plane->base, prop, 0);
+	plane->color_pipeline_property = prop;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_plane_create_color_pipeline_property);
\ No newline at end of file
diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h
index 634b2827765f..2346f19eda9f 100644
--- a/include/drm/drm_atomic.h
+++ b/include/drm/drm_atomic.h
@@ -797,6 +797,9 @@ drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
 int __must_check
 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
 			       struct drm_crtc *crtc);
+int __must_check
+drm_atomic_add_affected_colorops(struct drm_atomic_state *state,
+				 struct drm_plane *plane);
 
 int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
diff --git a/include/drm/drm_atomic_uapi.h b/include/drm/drm_atomic_uapi.h
index 70a115d523cd..436315523326 100644
--- a/include/drm/drm_atomic_uapi.h
+++ b/include/drm/drm_atomic_uapi.h
@@ -50,6 +50,8 @@ drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
 			      struct drm_crtc *crtc);
 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);
 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_plane.h b/include/drm/drm_plane.h
index 9c8c1322f0a6..c270bc640df8 100644
--- a/include/drm/drm_plane.h
+++ b/include/drm/drm_plane.h
@@ -766,6 +766,14 @@ struct drm_plane {
 	 */
 	struct drm_property *color_range_property;
 
+	/**
+	 * @color_pipeline_property:
+	 *
+	 * Optional "COLOR_PIPELINE" enum property for specifying
+	 * a color pipeline to use on the plane.
+	 */
+	struct drm_property *color_pipeline_property;
+
 	/**
 	 * @scaling_filter_property: property to apply a particular filter while
 	 * scaling.
@@ -979,4 +987,7 @@ drm_plane_get_damage_clips(const struct drm_plane_state *state);
 int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
 					     unsigned int supported_filters);
 
+int drm_plane_create_color_pipeline_property(struct drm_plane *plane,
+					     struct drm_prop_enum_list *pipelines,
+					     int num_pipelines);
 #endif
-- 
2.44.0


  parent reply	other threads:[~2024-02-26 21:12 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-26 21:10 [RFC PATCH v4 00/42] Color Pipeline API w/ VKMS Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 01/42] drm: Don't treat 0 as -1 in drm_fixp2int_ceil Harry Wentland
2024-03-14 13:41   ` Melissa Wen
2024-02-26 21:10 ` [RFC PATCH v4 02/42] drm: Add helper for conversion from signed-magnitude Harry Wentland
2024-03-14 13:16   ` Melissa Wen
2024-02-26 21:10 ` [RFC PATCH v4 03/42] drm: Correctly round for fixp2int_round Harry Wentland
2024-03-11 13:11   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 04/42] drm/vkms: Round fixp2int conversion in lerp_u16 Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 05/42] drm/vkms: Create separate Kconfig file for VKMS Harry Wentland
2024-03-12 18:49   ` Melissa Wen
2024-02-26 21:10 ` [RFC PATCH v4 06/42] drm/vkms: Add kunit tests for VKMS LUT handling Harry Wentland
2024-02-27 12:14   ` Arthur Grillo
2024-02-27 14:09     ` Harry Wentland
2024-03-11 13:45   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 07/42] drm/vkms: Avoid reading beyond LUT array Harry Wentland
2024-03-12 18:54   ` Melissa Wen
2024-02-26 21:10 ` [RFC PATCH v4 08/42] drm/doc/rfc: Describe why prescriptive color pipeline is needed Harry Wentland
2024-03-11 15:11   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 09/42] drm/colorop: Introduce new drm_colorop mode object Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 10/42] drm/colorop: Add TYPE property Harry Wentland
2024-03-12 15:02   ` Pekka Paalanen
2024-03-12 15:15     ` Simon Ser
2024-03-12 15:55       ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 11/42] drm/colorop: Add 1D Curve subtype Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 12/42] drm/colorop: Add BYPASS property Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 13/42] drm/colorop: Add NEXT property Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 14/42] drm/colorop: Add atomic state print for drm_colorop Harry Wentland
2024-02-26 21:10 ` Harry Wentland [this message]
2024-02-26 21:10 ` [RFC PATCH v4 16/42] drm/colorop: Add NEXT to colorop state print Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 17/42] drm/vkms: Add enumerated 1D curve colorop Harry Wentland
2024-03-12 15:27   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 18/42] drm/vkms: Add kunit tests for linear and sRGB LUTs Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 19/42] drm/colorop: Introduce DRM_CLIENT_CAP_PLANE_COLOR_PIPELINE Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 20/42] drm/colorop: Add 3x4 CTM type Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 21/42] drm/vkms: Pull apply_colorop out of pre_blend_color_transform Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 22/42] drm/vkms: Use s32 for internal color pipeline precision Harry Wentland
2024-03-12 15:50   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 23/42] drm/vkms: add 3x4 matrix in color pipeline Harry Wentland
2024-03-14 15:23   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 24/42] drm/tests: Add a few tests around drm_fixed.h Harry Wentland
2024-03-14 15:36   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 25/42] drm/vkms: Add tests for CTM handling Harry Wentland
2024-03-14 16:02   ` Pekka Paalanen
2024-02-26 21:10 ` [RFC PATCH v4 26/42] drm/colorop: pass plane_color_pipeline client cap to atomic check Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 27/42] drm/colorop: define a new macro for_each_new_colorop_in_state Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 28/42] drm/amd/display: Ignore deprecated props when plane_color_pipeline set Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 29/42] drm/amd/display: Add bypass COLOR PIPELINE Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 30/42] drm/amd/display: Skip color pipeline initialization for cursor plane Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 31/42] drm/amd/display: Add support for sRGB EOTF in DEGAM block Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 32/42] drm/amd/display: Add support for sRGB Inverse EOTF in SHAPER block Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 33/42] drm/amd/display: Add support for sRGB EOTF in BLND block Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 34/42] drm/colorop: Add PQ 125 EOTF and its inverse Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 35/42] drm/amd/display: Enable support for PQ 125 EOTF and Inverse Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 36/42] drm/colorop: add BT2020/BT709 OETF and Inverse OETF Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 37/42] drm/amd/display: Add support for BT.709 and BT.2020 TFs Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 38/42] drm/colorop: Add 1D Curve Custom LUT type Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 39/42] drm/amd/display: add shaper and blend colorops for 1D Curve Custom LUT Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 40/42] drm/amd/display: add 3x4 matrix colorop Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 41/42] drm/colorop: Add mutliplier type Harry Wentland
2024-02-26 21:10 ` [RFC PATCH v4 42/42] drm/amd/display: add multiplier colorop Harry Wentland
2024-02-27 10:26 ` [RFC PATCH v4 00/42] Color Pipeline API w/ VKMS Joshua Ashton
2024-02-27 14:00   ` Harry Wentland
2024-02-29 10:43 ` Daniel Vetter
2024-02-29 15:31   ` Joshua Ashton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240226211100.100108-16-harry.wentland@amd.com \
    --to=harry.wentland@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=wayland-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.