Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2016 Intel Corporation
0003  *
0004  * Permission to use, copy, modify, distribute, and sell this software and its
0005  * documentation for any purpose is hereby granted without fee, provided that
0006  * the above copyright notice appear in all copies and that both that copyright
0007  * notice and this permission notice appear in supporting documentation, and
0008  * that the name of the copyright holders not be used in advertising or
0009  * publicity pertaining to distribution of the software without specific,
0010  * written prior permission.  The copyright holders make no representations
0011  * about the suitability of this software for any purpose.  It is provided "as
0012  * is" without express or implied warranty.
0013  *
0014  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
0015  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
0016  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
0017  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
0018  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
0019  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
0020  * OF THIS SOFTWARE.
0021  */
0022 
0023 #include <linux/uaccess.h>
0024 
0025 #include <drm/drm_atomic.h>
0026 #include <drm/drm_color_mgmt.h>
0027 #include <drm/drm_crtc.h>
0028 #include <drm/drm_device.h>
0029 #include <drm/drm_drv.h>
0030 #include <drm/drm_print.h>
0031 
0032 #include "drm_crtc_internal.h"
0033 
0034 /**
0035  * DOC: overview
0036  *
0037  * Color management or color space adjustments is supported through a set of 5
0038  * properties on the &drm_crtc object. They are set up by calling
0039  * drm_crtc_enable_color_mgmt().
0040  *
0041  * "DEGAMMA_LUT”:
0042  *  Blob property to set the degamma lookup table (LUT) mapping pixel data
0043  *  from the framebuffer before it is given to the transformation matrix.
0044  *  The data is interpreted as an array of &struct drm_color_lut elements.
0045  *  Hardware might choose not to use the full precision of the LUT elements
0046  *  nor use all the elements of the LUT (for example the hardware might
0047  *  choose to interpolate between LUT[0] and LUT[4]).
0048  *
0049  *  Setting this to NULL (blob property value set to 0) means a
0050  *  linear/pass-thru gamma table should be used. This is generally the
0051  *  driver boot-up state too. Drivers can access this blob through
0052  *  &drm_crtc_state.degamma_lut.
0053  *
0054  * “DEGAMMA_LUT_SIZE”:
0055  *  Unsinged range property to give the size of the lookup table to be set
0056  *  on the DEGAMMA_LUT property (the size depends on the underlying
0057  *  hardware). If drivers support multiple LUT sizes then they should
0058  *  publish the largest size, and sub-sample smaller sized LUTs (e.g. for
0059  *  split-gamma modes) appropriately.
0060  *
0061  * “CTM”:
0062  *  Blob property to set the current transformation matrix (CTM) apply to
0063  *  pixel data after the lookup through the degamma LUT and before the
0064  *  lookup through the gamma LUT. The data is interpreted as a struct
0065  *  &drm_color_ctm.
0066  *
0067  *  Setting this to NULL (blob property value set to 0) means a
0068  *  unit/pass-thru matrix should be used. This is generally the driver
0069  *  boot-up state too. Drivers can access the blob for the color conversion
0070  *  matrix through &drm_crtc_state.ctm.
0071  *
0072  * “GAMMA_LUT”:
0073  *  Blob property to set the gamma lookup table (LUT) mapping pixel data
0074  *  after the transformation matrix to data sent to the connector. The
0075  *  data is interpreted as an array of &struct drm_color_lut elements.
0076  *  Hardware might choose not to use the full precision of the LUT elements
0077  *  nor use all the elements of the LUT (for example the hardware might
0078  *  choose to interpolate between LUT[0] and LUT[4]).
0079  *
0080  *  Setting this to NULL (blob property value set to 0) means a
0081  *  linear/pass-thru gamma table should be used. This is generally the
0082  *  driver boot-up state too. Drivers can access this blob through
0083  *  &drm_crtc_state.gamma_lut.
0084  *
0085  *  Note that for mostly historical reasons stemming from Xorg heritage,
0086  *  this is also used to store the color map (also sometimes color lut, CLUT
0087  *  or color palette) for indexed formats like DRM_FORMAT_C8.
0088  *
0089  * “GAMMA_LUT_SIZE”:
0090  *  Unsigned range property to give the size of the lookup table to be set
0091  *  on the GAMMA_LUT property (the size depends on the underlying hardware).
0092  *  If drivers support multiple LUT sizes then they should publish the
0093  *  largest size, and sub-sample smaller sized LUTs (e.g. for split-gamma
0094  *  modes) appropriately.
0095  *
0096  * There is also support for a legacy gamma table, which is set up by calling
0097  * drm_mode_crtc_set_gamma_size(). The DRM core will then alias the legacy gamma
0098  * ramp with "GAMMA_LUT" or, if that is unavailable, "DEGAMMA_LUT".
0099  *
0100  * Support for different non RGB color encodings is controlled through
0101  * &drm_plane specific COLOR_ENCODING and COLOR_RANGE properties. They
0102  * are set up by calling drm_plane_create_color_properties().
0103  *
0104  * "COLOR_ENCODING":
0105  *  Optional plane enum property to support different non RGB
0106  *  color encodings. The driver can provide a subset of standard
0107  *  enum values supported by the DRM plane.
0108  *
0109  * "COLOR_RANGE":
0110  *  Optional plane enum property to support different non RGB
0111  *  color parameter ranges. The driver can provide a subset of
0112  *  standard enum values supported by the DRM plane.
0113  */
0114 
0115 /**
0116  * drm_color_ctm_s31_32_to_qm_n
0117  *
0118  * @user_input: input value
0119  * @m: number of integer bits, only support m <= 32, include the sign-bit
0120  * @n: number of fractional bits, only support n <= 32
0121  *
0122  * Convert and clamp S31.32 sign-magnitude to Qm.n (signed 2's complement).
0123  * The sign-bit BIT(m+n-1) and above are 0 for positive value and 1 for negative
0124  * the range of value is [-2^(m-1), 2^(m-1) - 2^-n]
0125  *
0126  * For example
0127  * A Q3.12 format number:
0128  * - required bit: 3 + 12 = 15bits
0129  * - range: [-2^2, 2^2 - 2^−15]
0130  *
0131  * NOTE: the m can be zero if all bit_precision are used to present fractional
0132  *       bits like Q0.32
0133  */
0134 u64 drm_color_ctm_s31_32_to_qm_n(u64 user_input, u32 m, u32 n)
0135 {
0136     u64 mag = (user_input & ~BIT_ULL(63)) >> (32 - n);
0137     bool negative = !!(user_input & BIT_ULL(63));
0138     s64 val;
0139 
0140     WARN_ON(m > 32 || n > 32);
0141 
0142     val = clamp_val(mag, 0, negative ?
0143                 BIT_ULL(n + m - 1) : BIT_ULL(n + m - 1) - 1);
0144 
0145     return negative ? -val : val;
0146 }
0147 EXPORT_SYMBOL(drm_color_ctm_s31_32_to_qm_n);
0148 
0149 /**
0150  * drm_crtc_enable_color_mgmt - enable color management properties
0151  * @crtc: DRM CRTC
0152  * @degamma_lut_size: the size of the degamma lut (before CSC)
0153  * @has_ctm: whether to attach ctm_property for CSC matrix
0154  * @gamma_lut_size: the size of the gamma lut (after CSC)
0155  *
0156  * This function lets the driver enable the color correction
0157  * properties on a CRTC. This includes 3 degamma, csc and gamma
0158  * properties that userspace can set and 2 size properties to inform
0159  * the userspace of the lut sizes. Each of the properties are
0160  * optional. The gamma and degamma properties are only attached if
0161  * their size is not 0 and ctm_property is only attached if has_ctm is
0162  * true.
0163  */
0164 void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
0165                 uint degamma_lut_size,
0166                 bool has_ctm,
0167                 uint gamma_lut_size)
0168 {
0169     struct drm_device *dev = crtc->dev;
0170     struct drm_mode_config *config = &dev->mode_config;
0171 
0172     if (degamma_lut_size) {
0173         drm_object_attach_property(&crtc->base,
0174                        config->degamma_lut_property, 0);
0175         drm_object_attach_property(&crtc->base,
0176                        config->degamma_lut_size_property,
0177                        degamma_lut_size);
0178     }
0179 
0180     if (has_ctm)
0181         drm_object_attach_property(&crtc->base,
0182                        config->ctm_property, 0);
0183 
0184     if (gamma_lut_size) {
0185         drm_object_attach_property(&crtc->base,
0186                        config->gamma_lut_property, 0);
0187         drm_object_attach_property(&crtc->base,
0188                        config->gamma_lut_size_property,
0189                        gamma_lut_size);
0190     }
0191 }
0192 EXPORT_SYMBOL(drm_crtc_enable_color_mgmt);
0193 
0194 /**
0195  * drm_mode_crtc_set_gamma_size - set the gamma table size
0196  * @crtc: CRTC to set the gamma table size for
0197  * @gamma_size: size of the gamma table
0198  *
0199  * Drivers which support gamma tables should set this to the supported gamma
0200  * table size when initializing the CRTC. Currently the drm core only supports a
0201  * fixed gamma table size.
0202  *
0203  * Returns:
0204  * Zero on success, negative errno on failure.
0205  */
0206 int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
0207                  int gamma_size)
0208 {
0209     uint16_t *r_base, *g_base, *b_base;
0210     int i;
0211 
0212     crtc->gamma_size = gamma_size;
0213 
0214     crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3,
0215                     GFP_KERNEL);
0216     if (!crtc->gamma_store) {
0217         crtc->gamma_size = 0;
0218         return -ENOMEM;
0219     }
0220 
0221     r_base = crtc->gamma_store;
0222     g_base = r_base + gamma_size;
0223     b_base = g_base + gamma_size;
0224     for (i = 0; i < gamma_size; i++) {
0225         r_base[i] = i << 8;
0226         g_base[i] = i << 8;
0227         b_base[i] = i << 8;
0228     }
0229 
0230 
0231     return 0;
0232 }
0233 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
0234 
0235 /**
0236  * drm_crtc_supports_legacy_gamma - does the crtc support legacy gamma correction table
0237  * @crtc: CRTC object
0238  *
0239  * Returns true/false if the given crtc supports setting the legacy gamma
0240  * correction table.
0241  */
0242 static bool drm_crtc_supports_legacy_gamma(struct drm_crtc *crtc)
0243 {
0244     u32 gamma_id = crtc->dev->mode_config.gamma_lut_property->base.id;
0245     u32 degamma_id = crtc->dev->mode_config.degamma_lut_property->base.id;
0246 
0247     if (!crtc->gamma_size)
0248         return false;
0249 
0250     if (crtc->funcs->gamma_set)
0251         return true;
0252 
0253     return !!(drm_mode_obj_find_prop_id(&crtc->base, gamma_id) ||
0254           drm_mode_obj_find_prop_id(&crtc->base, degamma_id));
0255 }
0256 
0257 /**
0258  * drm_crtc_legacy_gamma_set - set the legacy gamma correction table
0259  * @crtc: CRTC object
0260  * @red: red correction table
0261  * @green: green correction table
0262  * @blue: blue correction table
0263  * @size: size of the tables
0264  * @ctx: lock acquire context
0265  *
0266  * Implements support for legacy gamma correction table for drivers
0267  * that have set drm_crtc_funcs.gamma_set or that support color management
0268  * through the DEGAMMA_LUT/GAMMA_LUT properties. See
0269  * drm_crtc_enable_color_mgmt() and the containing chapter for
0270  * how the atomic color management and gamma tables work.
0271  *
0272  * This function sets the gamma using drm_crtc_funcs.gamma_set if set, or
0273  * alternatively using crtc color management properties.
0274  */
0275 static int drm_crtc_legacy_gamma_set(struct drm_crtc *crtc,
0276                      u16 *red, u16 *green, u16 *blue,
0277                      u32 size,
0278                      struct drm_modeset_acquire_ctx *ctx)
0279 {
0280     struct drm_device *dev = crtc->dev;
0281     struct drm_atomic_state *state;
0282     struct drm_crtc_state *crtc_state;
0283     struct drm_property_blob *blob;
0284     struct drm_color_lut *blob_data;
0285     u32 gamma_id = dev->mode_config.gamma_lut_property->base.id;
0286     u32 degamma_id = dev->mode_config.degamma_lut_property->base.id;
0287     bool use_gamma_lut;
0288     int i, ret = 0;
0289     bool replaced;
0290 
0291     if (crtc->funcs->gamma_set)
0292         return crtc->funcs->gamma_set(crtc, red, green, blue, size, ctx);
0293 
0294     if (drm_mode_obj_find_prop_id(&crtc->base, gamma_id))
0295         use_gamma_lut = true;
0296     else if (drm_mode_obj_find_prop_id(&crtc->base, degamma_id))
0297         use_gamma_lut = false;
0298     else
0299         return -ENODEV;
0300 
0301     state = drm_atomic_state_alloc(crtc->dev);
0302     if (!state)
0303         return -ENOMEM;
0304 
0305     blob = drm_property_create_blob(dev,
0306                     sizeof(struct drm_color_lut) * size,
0307                     NULL);
0308     if (IS_ERR(blob)) {
0309         ret = PTR_ERR(blob);
0310         blob = NULL;
0311         goto fail;
0312     }
0313 
0314     /* Prepare GAMMA_LUT with the legacy values. */
0315     blob_data = blob->data;
0316     for (i = 0; i < size; i++) {
0317         blob_data[i].red = red[i];
0318         blob_data[i].green = green[i];
0319         blob_data[i].blue = blue[i];
0320     }
0321 
0322     state->acquire_ctx = ctx;
0323     crtc_state = drm_atomic_get_crtc_state(state, crtc);
0324     if (IS_ERR(crtc_state)) {
0325         ret = PTR_ERR(crtc_state);
0326         goto fail;
0327     }
0328 
0329     /* Set GAMMA_LUT and reset DEGAMMA_LUT and CTM */
0330     replaced = drm_property_replace_blob(&crtc_state->degamma_lut,
0331                          use_gamma_lut ? NULL : blob);
0332     replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL);
0333     replaced |= drm_property_replace_blob(&crtc_state->gamma_lut,
0334                           use_gamma_lut ? blob : NULL);
0335     crtc_state->color_mgmt_changed |= replaced;
0336 
0337     ret = drm_atomic_commit(state);
0338 
0339 fail:
0340     drm_atomic_state_put(state);
0341     drm_property_blob_put(blob);
0342     return ret;
0343 }
0344 
0345 /**
0346  * drm_mode_gamma_set_ioctl - set the gamma table
0347  * @dev: DRM device
0348  * @data: ioctl data
0349  * @file_priv: DRM file info
0350  *
0351  * Set the gamma table of a CRTC to the one passed in by the user. Userspace can
0352  * inquire the required gamma table size through drm_mode_gamma_get_ioctl.
0353  *
0354  * Called by the user via ioctl.
0355  *
0356  * Returns:
0357  * Zero on success, negative errno on failure.
0358  */
0359 int drm_mode_gamma_set_ioctl(struct drm_device *dev,
0360                  void *data, struct drm_file *file_priv)
0361 {
0362     struct drm_mode_crtc_lut *crtc_lut = data;
0363     struct drm_crtc *crtc;
0364     void *r_base, *g_base, *b_base;
0365     int size;
0366     struct drm_modeset_acquire_ctx ctx;
0367     int ret = 0;
0368 
0369     if (!drm_core_check_feature(dev, DRIVER_MODESET))
0370         return -EOPNOTSUPP;
0371 
0372     crtc = drm_crtc_find(dev, file_priv, crtc_lut->crtc_id);
0373     if (!crtc)
0374         return -ENOENT;
0375 
0376     if (!drm_crtc_supports_legacy_gamma(crtc))
0377         return -ENOSYS;
0378 
0379     /* memcpy into gamma store */
0380     if (crtc_lut->gamma_size != crtc->gamma_size)
0381         return -EINVAL;
0382 
0383     DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
0384 
0385     size = crtc_lut->gamma_size * (sizeof(uint16_t));
0386     r_base = crtc->gamma_store;
0387     if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
0388         ret = -EFAULT;
0389         goto out;
0390     }
0391 
0392     g_base = r_base + size;
0393     if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
0394         ret = -EFAULT;
0395         goto out;
0396     }
0397 
0398     b_base = g_base + size;
0399     if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
0400         ret = -EFAULT;
0401         goto out;
0402     }
0403 
0404     ret = drm_crtc_legacy_gamma_set(crtc, r_base, g_base, b_base,
0405                     crtc->gamma_size, &ctx);
0406 
0407 out:
0408     DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
0409     return ret;
0410 
0411 }
0412 
0413 /**
0414  * drm_mode_gamma_get_ioctl - get the gamma table
0415  * @dev: DRM device
0416  * @data: ioctl data
0417  * @file_priv: DRM file info
0418  *
0419  * Copy the current gamma table into the storage provided. This also provides
0420  * the gamma table size the driver expects, which can be used to size the
0421  * allocated storage.
0422  *
0423  * Called by the user via ioctl.
0424  *
0425  * Returns:
0426  * Zero on success, negative errno on failure.
0427  */
0428 int drm_mode_gamma_get_ioctl(struct drm_device *dev,
0429                  void *data, struct drm_file *file_priv)
0430 {
0431     struct drm_mode_crtc_lut *crtc_lut = data;
0432     struct drm_crtc *crtc;
0433     void *r_base, *g_base, *b_base;
0434     int size;
0435     int ret = 0;
0436 
0437     if (!drm_core_check_feature(dev, DRIVER_MODESET))
0438         return -EOPNOTSUPP;
0439 
0440     crtc = drm_crtc_find(dev, file_priv, crtc_lut->crtc_id);
0441     if (!crtc)
0442         return -ENOENT;
0443 
0444     /* memcpy into gamma store */
0445     if (crtc_lut->gamma_size != crtc->gamma_size)
0446         return -EINVAL;
0447 
0448     drm_modeset_lock(&crtc->mutex, NULL);
0449     size = crtc_lut->gamma_size * (sizeof(uint16_t));
0450     r_base = crtc->gamma_store;
0451     if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
0452         ret = -EFAULT;
0453         goto out;
0454     }
0455 
0456     g_base = r_base + size;
0457     if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
0458         ret = -EFAULT;
0459         goto out;
0460     }
0461 
0462     b_base = g_base + size;
0463     if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
0464         ret = -EFAULT;
0465         goto out;
0466     }
0467 out:
0468     drm_modeset_unlock(&crtc->mutex);
0469     return ret;
0470 }
0471 
0472 static const char * const color_encoding_name[] = {
0473     [DRM_COLOR_YCBCR_BT601] = "ITU-R BT.601 YCbCr",
0474     [DRM_COLOR_YCBCR_BT709] = "ITU-R BT.709 YCbCr",
0475     [DRM_COLOR_YCBCR_BT2020] = "ITU-R BT.2020 YCbCr",
0476 };
0477 
0478 static const char * const color_range_name[] = {
0479     [DRM_COLOR_YCBCR_FULL_RANGE] = "YCbCr full range",
0480     [DRM_COLOR_YCBCR_LIMITED_RANGE] = "YCbCr limited range",
0481 };
0482 
0483 /**
0484  * drm_get_color_encoding_name - return a string for color encoding
0485  * @encoding: color encoding to compute name of
0486  *
0487  * In contrast to the other drm_get_*_name functions this one here returns a
0488  * const pointer and hence is threadsafe.
0489  */
0490 const char *drm_get_color_encoding_name(enum drm_color_encoding encoding)
0491 {
0492     if (WARN_ON(encoding >= ARRAY_SIZE(color_encoding_name)))
0493         return "unknown";
0494 
0495     return color_encoding_name[encoding];
0496 }
0497 
0498 /**
0499  * drm_get_color_range_name - return a string for color range
0500  * @range: color range to compute name of
0501  *
0502  * In contrast to the other drm_get_*_name functions this one here returns a
0503  * const pointer and hence is threadsafe.
0504  */
0505 const char *drm_get_color_range_name(enum drm_color_range range)
0506 {
0507     if (WARN_ON(range >= ARRAY_SIZE(color_range_name)))
0508         return "unknown";
0509 
0510     return color_range_name[range];
0511 }
0512 
0513 /**
0514  * drm_plane_create_color_properties - color encoding related plane properties
0515  * @plane: plane object
0516  * @supported_encodings: bitfield indicating supported color encodings
0517  * @supported_ranges: bitfileld indicating supported color ranges
0518  * @default_encoding: default color encoding
0519  * @default_range: default color range
0520  *
0521  * Create and attach plane specific COLOR_ENCODING and COLOR_RANGE
0522  * properties to @plane. The supported encodings and ranges should
0523  * be provided in supported_encodings and supported_ranges bitmasks.
0524  * Each bit set in the bitmask indicates that its number as enum
0525  * value is supported.
0526  */
0527 int drm_plane_create_color_properties(struct drm_plane *plane,
0528                       u32 supported_encodings,
0529                       u32 supported_ranges,
0530                       enum drm_color_encoding default_encoding,
0531                       enum drm_color_range default_range)
0532 {
0533     struct drm_device *dev = plane->dev;
0534     struct drm_property *prop;
0535     struct drm_prop_enum_list enum_list[max_t(int, DRM_COLOR_ENCODING_MAX,
0536                                DRM_COLOR_RANGE_MAX)];
0537     int i, len;
0538 
0539     if (WARN_ON(supported_encodings == 0 ||
0540             (supported_encodings & -BIT(DRM_COLOR_ENCODING_MAX)) != 0 ||
0541             (supported_encodings & BIT(default_encoding)) == 0))
0542         return -EINVAL;
0543 
0544     if (WARN_ON(supported_ranges == 0 ||
0545             (supported_ranges & -BIT(DRM_COLOR_RANGE_MAX)) != 0 ||
0546             (supported_ranges & BIT(default_range)) == 0))
0547         return -EINVAL;
0548 
0549     len = 0;
0550     for (i = 0; i < DRM_COLOR_ENCODING_MAX; i++) {
0551         if ((supported_encodings & BIT(i)) == 0)
0552             continue;
0553 
0554         enum_list[len].type = i;
0555         enum_list[len].name = color_encoding_name[i];
0556         len++;
0557     }
0558 
0559     prop = drm_property_create_enum(dev, 0, "COLOR_ENCODING",
0560                     enum_list, len);
0561     if (!prop)
0562         return -ENOMEM;
0563     plane->color_encoding_property = prop;
0564     drm_object_attach_property(&plane->base, prop, default_encoding);
0565     if (plane->state)
0566         plane->state->color_encoding = default_encoding;
0567 
0568     len = 0;
0569     for (i = 0; i < DRM_COLOR_RANGE_MAX; i++) {
0570         if ((supported_ranges & BIT(i)) == 0)
0571             continue;
0572 
0573         enum_list[len].type = i;
0574         enum_list[len].name = color_range_name[i];
0575         len++;
0576     }
0577 
0578     prop = drm_property_create_enum(dev, 0, "COLOR_RANGE",
0579                     enum_list, len);
0580     if (!prop)
0581         return -ENOMEM;
0582     plane->color_range_property = prop;
0583     drm_object_attach_property(&plane->base, prop, default_range);
0584     if (plane->state)
0585         plane->state->color_range = default_range;
0586 
0587     return 0;
0588 }
0589 EXPORT_SYMBOL(drm_plane_create_color_properties);
0590 
0591 /**
0592  * drm_color_lut_check - check validity of lookup table
0593  * @lut: property blob containing LUT to check
0594  * @tests: bitmask of tests to run
0595  *
0596  * Helper to check whether a userspace-provided lookup table is valid and
0597  * satisfies hardware requirements.  Drivers pass a bitmask indicating which of
0598  * the tests in &drm_color_lut_tests should be performed.
0599  *
0600  * Returns 0 on success, -EINVAL on failure.
0601  */
0602 int drm_color_lut_check(const struct drm_property_blob *lut, u32 tests)
0603 {
0604     const struct drm_color_lut *entry;
0605     int i;
0606 
0607     if (!lut || !tests)
0608         return 0;
0609 
0610     entry = lut->data;
0611     for (i = 0; i < drm_color_lut_size(lut); i++) {
0612         if (tests & DRM_COLOR_LUT_EQUAL_CHANNELS) {
0613             if (entry[i].red != entry[i].blue ||
0614                 entry[i].red != entry[i].green) {
0615                 DRM_DEBUG_KMS("All LUT entries must have equal r/g/b\n");
0616                 return -EINVAL;
0617             }
0618         }
0619 
0620         if (i > 0 && tests & DRM_COLOR_LUT_NON_DECREASING) {
0621             if (entry[i].red < entry[i - 1].red ||
0622                 entry[i].green < entry[i - 1].green ||
0623                 entry[i].blue < entry[i - 1].blue) {
0624                 DRM_DEBUG_KMS("LUT entries must never decrease.\n");
0625                 return -EINVAL;
0626             }
0627         }
0628     }
0629 
0630     return 0;
0631 }
0632 EXPORT_SYMBOL(drm_color_lut_check);