Factor out the common code paths from the colorop helpers so they can be
reused by the post-blend colorop helpers.
Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
drivers/gpu/drm/drm_colorop.c | 145 ++++++++++++++++++++++++++++--------------
1 file changed, 99 insertions(+), 46 deletions(-)
diff --git a/drivers/gpu/drm/drm_colorop.c b/drivers/gpu/drm/drm_colorop.c
index 1384a259605fa4945aa74402901886d7e1fde0d1..db137169effa6cd9e6d5805f65bdfd1cc6882075 100644
--- a/drivers/gpu/drm/drm_colorop.c
+++ b/drivers/gpu/drm/drm_colorop.c
@@ -91,8 +91,9 @@ static const struct drm_prop_enum_list drm_colorop_lut3d_interpolation_list[] =
/* Init Helpers */
-static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *colorop,
- struct drm_plane *plane, enum drm_colorop_type type, uint32_t flags)
+static int drm_common_colorop_init(struct drm_device *dev,
+ struct drm_colorop *colorop,
+ enum drm_colorop_type type, uint32_t flags)
{
struct drm_mode_config *config = &dev->mode_config;
struct drm_property *prop;
@@ -105,7 +106,6 @@ static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *co
colorop->base.properties = &colorop->properties;
colorop->dev = dev;
colorop->type = type;
- colorop->plane = plane;
colorop->next = NULL;
list_add_tail(&colorop->head, &config->colorop_list);
@@ -154,6 +154,20 @@ static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *co
return ret;
}
+static int drm_plane_colorop_init(struct drm_device *dev,
+ struct drm_colorop *colorop,
+ struct drm_plane *plane,
+ enum drm_colorop_type type, uint32_t flags)
+{
+ int ret;
+
+ ret = drm_common_colorop_init(dev, colorop, type, flags);
+
+ colorop->plane = plane;
+
+ return ret;
+}
+
/**
* drm_colorop_cleanup - Cleanup a drm_colorop object in color_pipeline
*
@@ -206,31 +220,13 @@ EXPORT_SYMBOL(drm_colorop_pipeline_destroy);
* @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines.
* @return zero on success, -E value on failure
*/
-int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
- struct drm_plane *plane, u64 supported_tfs, uint32_t flags)
+static int drm_common_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
+ u64 supported_tfs, uint32_t flags)
{
struct drm_prop_enum_list enum_list[DRM_COLOROP_1D_CURVE_COUNT];
int i, len;
struct drm_property *prop;
- int ret;
-
- if (!supported_tfs) {
- drm_err(dev,
- "No supported TFs for new 1D curve colorop on [PLANE:%d:%s]\n",
- plane->base.id, plane->name);
- return -EINVAL;
- }
-
- if ((supported_tfs & -BIT(DRM_COLOROP_1D_CURVE_COUNT)) != 0) {
- drm_err(dev, "Unknown TF provided on [PLANE:%d:%s]\n",
- plane->base.id, plane->name);
- return -EINVAL;
- }
-
- ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_CURVE, flags);
- if (ret)
- return ret;
len = 0;
for (i = 0; i < DRM_COLOROP_1D_CURVE_COUNT; i++) {
@@ -260,6 +256,41 @@ int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *
return 0;
}
+
+static int drm_colorop_has_supported_tf(struct drm_device *dev, struct drm_mode_object *obj,
+ const char *name, u64 supported_tfs)
+{
+ if (!supported_tfs) {
+ drm_err(dev,
+ "No supported TFs for new 1D curve colorop on [PLANE:%d:%s]\n",
+ obj->id, name);
+ return -EINVAL;
+ }
+
+ if ((supported_tfs & -BIT(DRM_COLOROP_1D_CURVE_COUNT)) != 0) {
+ drm_err(dev, "Unknown TF provided on [PLANE:%d:%s]\n",
+ obj->id, name);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
+ struct drm_plane *plane, u64 supported_tfs, uint32_t flags)
+{
+ int ret;
+
+ ret = drm_colorop_has_supported_tf(dev, &plane->base, plane->name, supported_tfs);
+ if (ret)
+ return ret;
+
+ ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_CURVE, flags);
+ if (ret)
+ return ret;
+
+ return drm_common_colorop_curve_1d_init(dev, colorop, supported_tfs, flags);
+}
EXPORT_SYMBOL(drm_plane_colorop_curve_1d_init);
static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_colorop *colorop)
@@ -280,29 +311,16 @@ static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_color
return 0;
}
-/**
- * drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT
- *
- * @dev: DRM device
- * @colorop: The drm_colorop object to initialize
- * @plane: The associated drm_plane
- * @lut_size: LUT size supported by driver
- * @lut1d_interpolation: 1D LUT interpolation type
- * @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines.
- * @return zero on success, -E value on failure
- */
-int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
- struct drm_plane *plane, uint32_t lut_size,
- enum drm_colorop_lut1d_interpolation_type lut1d_interpolation,
- uint32_t flags)
+static int
+drm_common_colorop_curve_1d_lut_init(struct drm_device *dev,
+ struct drm_colorop *colorop,
+ uint32_t lut_size,
+ enum drm_colorop_lut1d_interpolation_type lut1d_interpolation,
+ uint32_t flags)
{
struct drm_property *prop;
int ret;
- ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_LUT, flags);
- if (ret)
- return ret;
-
/* initialize 1D LUT only attribute */
/* LUT size */
prop = drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ATOMIC,
@@ -334,17 +352,40 @@ int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_color
return 0;
}
-EXPORT_SYMBOL(drm_plane_colorop_curve_1d_lut_init);
-int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
- struct drm_plane *plane, uint32_t flags)
+/**
+ * drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT
+ *
+ * @dev: DRM device
+ * @colorop: The drm_colorop object to initialize
+ * @plane: The associated drm_plane
+ * @lut_size: LUT size supported by driver
+ * @lut1d_interpolation: 1D LUT interpolation type
+ * @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines.
+ * @return zero on success, -E value on failure
+ */
+int
+drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
+ struct drm_plane *plane, uint32_t lut_size,
+ enum drm_colorop_lut1d_interpolation_type lut1d_interpolation,
+ uint32_t flags)
{
int ret;
- ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_CTM_3X4, flags);
+ ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_LUT, flags);
if (ret)
return ret;
+ return drm_common_colorop_curve_1d_lut_init(dev, colorop, lut_size,
+ lut1d_interpolation, flags);
+}
+EXPORT_SYMBOL(drm_plane_colorop_curve_1d_lut_init);
+
+static int drm_common_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
+ uint32_t flags)
+{
+ int ret;
+
ret = drm_colorop_create_data_prop(dev, colorop);
if (ret)
return ret;
@@ -353,6 +394,18 @@ int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *c
return 0;
}
+
+int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
+ struct drm_plane *plane, uint32_t flags)
+{
+ int ret;
+
+ ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_CTM_3X4, flags);
+ if (ret)
+ return ret;
+
+ return drm_common_colorop_ctm_3x4_init(dev, colorop, flags);
+}
EXPORT_SYMBOL(drm_plane_colorop_ctm_3x4_init);
/**
--
2.50.1
Le 18/09/2025 à 02:43, Nícolas F. R. A. Prado a écrit :
> Factor out the common code paths from the colorop helpers so they can be
> reused by the post-blend colorop helpers.
>
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
> ---
> drivers/gpu/drm/drm_colorop.c | 145 ++++++++++++++++++++++++++++--------------
> 1 file changed, 99 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_colorop.c b/drivers/gpu/drm/drm_colorop.c
> index 1384a259605fa4945aa74402901886d7e1fde0d1..db137169effa6cd9e6d5805f65bdfd1cc6882075 100644
> --- a/drivers/gpu/drm/drm_colorop.c
> +++ b/drivers/gpu/drm/drm_colorop.c
> @@ -91,8 +91,9 @@ static const struct drm_prop_enum_list drm_colorop_lut3d_interpolation_list[] =
>
> /* Init Helpers */
>
> -static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *colorop,
> - struct drm_plane *plane, enum drm_colorop_type type, uint32_t flags)
> +static int drm_common_colorop_init(struct drm_device *dev,
> + struct drm_colorop *colorop,
> + enum drm_colorop_type type, uint32_t flags)
> {
> struct drm_mode_config *config = &dev->mode_config;
> struct drm_property *prop;
> @@ -105,7 +106,6 @@ static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *co
> colorop->base.properties = &colorop->properties;
> colorop->dev = dev;
> colorop->type = type;
> - colorop->plane = plane;
> colorop->next = NULL;
>
> list_add_tail(&colorop->head, &config->colorop_list);
> @@ -154,6 +154,20 @@ static int drm_plane_colorop_init(struct drm_device *dev, struct drm_colorop *co
> return ret;
> }
>
> +static int drm_plane_colorop_init(struct drm_device *dev,
> + struct drm_colorop *colorop,
> + struct drm_plane *plane,
> + enum drm_colorop_type type, uint32_t flags)
> +{
> + int ret;
> +
> + ret = drm_common_colorop_init(dev, colorop, type, flags);
> +
> + colorop->plane = plane;
> +
> + return ret;
> +}
> +
> /**
> * drm_colorop_cleanup - Cleanup a drm_colorop object in color_pipeline
> *
> @@ -206,31 +220,13 @@ EXPORT_SYMBOL(drm_colorop_pipeline_destroy);
> * @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines.
> * @return zero on success, -E value on failure
> */
> -int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
> - struct drm_plane *plane, u64 supported_tfs, uint32_t flags)
> +static int drm_common_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
> + u64 supported_tfs, uint32_t flags)
> {
> struct drm_prop_enum_list enum_list[DRM_COLOROP_1D_CURVE_COUNT];
> int i, len;
>
> struct drm_property *prop;
> - int ret;
> -
> - if (!supported_tfs) {
> - drm_err(dev,
> - "No supported TFs for new 1D curve colorop on [PLANE:%d:%s]\n",
> - plane->base.id, plane->name);
> - return -EINVAL;
> - }
> -
> - if ((supported_tfs & -BIT(DRM_COLOROP_1D_CURVE_COUNT)) != 0) {
> - drm_err(dev, "Unknown TF provided on [PLANE:%d:%s]\n",
> - plane->base.id, plane->name);
> - return -EINVAL;
> - }
> -
> - ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_CURVE, flags);
> - if (ret)
> - return ret;
>
> len = 0;
> for (i = 0; i < DRM_COLOROP_1D_CURVE_COUNT; i++) {
> @@ -260,6 +256,41 @@ int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *
>
> return 0;
> }
> +
> +static int drm_colorop_has_supported_tf(struct drm_device *dev, struct drm_mode_object *obj,
> + const char *name, u64 supported_tfs)
> +{
> + if (!supported_tfs) {
> + drm_err(dev,
> + "No supported TFs for new 1D curve colorop on [PLANE:%d:%s]\n",
> + obj->id, name);
> + return -EINVAL;
> + }
> +
> + if ((supported_tfs & -BIT(DRM_COLOROP_1D_CURVE_COUNT)) != 0) {
> + drm_err(dev, "Unknown TF provided on [PLANE:%d:%s]\n",
> + obj->id, name);
> + return -EINVAL;
> + }
> +
> + return 0;
> +}
> +
> +int drm_plane_colorop_curve_1d_init(struct drm_device *dev, struct drm_colorop *colorop,
> + struct drm_plane *plane, u64 supported_tfs, uint32_t flags)
> +{
> + int ret;
> +
> + ret = drm_colorop_has_supported_tf(dev, &plane->base, plane->name, supported_tfs);
> + if (ret)
> + return ret;
> +
> + ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_CURVE, flags);
> + if (ret)
> + return ret;
> +
> + return drm_common_colorop_curve_1d_init(dev, colorop, supported_tfs, flags);
> +}
> EXPORT_SYMBOL(drm_plane_colorop_curve_1d_init);
>
> static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_colorop *colorop)
> @@ -280,29 +311,16 @@ static int drm_colorop_create_data_prop(struct drm_device *dev, struct drm_color
> return 0;
> }
>
> -/**
> - * drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT
> - *
> - * @dev: DRM device
> - * @colorop: The drm_colorop object to initialize
> - * @plane: The associated drm_plane
> - * @lut_size: LUT size supported by driver
> - * @lut1d_interpolation: 1D LUT interpolation type
> - * @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines.
> - * @return zero on success, -E value on failure
> - */
> -int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
> - struct drm_plane *plane, uint32_t lut_size,
> - enum drm_colorop_lut1d_interpolation_type lut1d_interpolation,
> - uint32_t flags)
> +static int
> +drm_common_colorop_curve_1d_lut_init(struct drm_device *dev,
> + struct drm_colorop *colorop,
> + uint32_t lut_size,
> + enum drm_colorop_lut1d_interpolation_type lut1d_interpolation,
> + uint32_t flags)
> {
> struct drm_property *prop;
> int ret;
>
> - ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_LUT, flags);
> - if (ret)
> - return ret;
> -
> /* initialize 1D LUT only attribute */
> /* LUT size */
> prop = drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ATOMIC,
> @@ -334,17 +352,40 @@ int drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_color
>
> return 0;
> }
> -EXPORT_SYMBOL(drm_plane_colorop_curve_1d_lut_init);
>
> -int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
> - struct drm_plane *plane, uint32_t flags)
> +/**
> + * drm_plane_colorop_curve_1d_lut_init - Initialize a DRM_COLOROP_1D_LUT
> + *
> + * @dev: DRM device
> + * @colorop: The drm_colorop object to initialize
> + * @plane: The associated drm_plane
> + * @lut_size: LUT size supported by driver
> + * @lut1d_interpolation: 1D LUT interpolation type
> + * @flags: bitmask of misc, see DRM_COLOROP_FLAG_* defines.
> + * @return zero on success, -E value on failure
> + */
> +int
> +drm_plane_colorop_curve_1d_lut_init(struct drm_device *dev, struct drm_colorop *colorop,
> + struct drm_plane *plane, uint32_t lut_size,
> + enum drm_colorop_lut1d_interpolation_type lut1d_interpolation,
> + uint32_t flags)
> {
> int ret;
>
> - ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_CTM_3X4, flags);
> + ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_1D_LUT, flags);
> if (ret)
> return ret;
>
> + return drm_common_colorop_curve_1d_lut_init(dev, colorop, lut_size,
> + lut1d_interpolation, flags);
> +}
> +EXPORT_SYMBOL(drm_plane_colorop_curve_1d_lut_init);
> +
> +static int drm_common_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
> + uint32_t flags)
> +{
> + int ret;
> +
> ret = drm_colorop_create_data_prop(dev, colorop);
> if (ret)
> return ret;
> @@ -353,6 +394,18 @@ int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *c
>
> return 0;
> }
> +
> +int drm_plane_colorop_ctm_3x4_init(struct drm_device *dev, struct drm_colorop *colorop,
> + struct drm_plane *plane, uint32_t flags)
> +{
> + int ret;
> +
> + ret = drm_plane_colorop_init(dev, colorop, plane, DRM_COLOROP_CTM_3X4, flags);
> + if (ret)
> + return ret;
> +
> + return drm_common_colorop_ctm_3x4_init(dev, colorop, flags);
> +}
> EXPORT_SYMBOL(drm_plane_colorop_ctm_3x4_init);
>
> /**
>
--
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
© 2016 - 2026 Red Hat, Inc.