]> Gentwo Git Trees - linux/.git/commitdiff
drm: Add Enhanced LUT precision structure
authorUma Shankar <uma.shankar@intel.com>
Sat, 15 Nov 2025 00:02:00 +0000 (17:02 -0700)
committerSimon Ser <contact@emersion.fr>
Wed, 26 Nov 2025 22:03:35 +0000 (23:03 +0100)
Existing LUT precision structure drm_color_lut has only 16 bit
precision. This is not enough for upcoming enhanced hardwares
and advance usecases like HDR processing. Hence added a new
structure with 32 bit precision values.

Signed-off-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Uma Shankar <uma.shankar@intel.com>
Signed-off-by: Chaitanya Kumar Borah <chaitanya.kumar.borah@intel.com>
Reviewed-by: Sebastian Wick <sebastian.wick@redhat.com>
Signed-off-by: Simon Ser <contact@emersion.fr>
Link: https://patch.msgid.link/20251115000237.3561250-36-alex.hung@amd.com
drivers/gpu/drm/drm_color_mgmt.c
include/drm/drm_color_mgmt.h
include/uapi/drm/drm_mode.h

index 131c1c9ae92fc265bf0d56c80e3da814cce8116d..c598b99673fc15159e2e2b56563f17ce9ce81a65 100644 (file)
@@ -874,3 +874,46 @@ void drm_crtc_fill_palette_8(struct drm_crtc *crtc, drm_crtc_set_lut_func set_pa
                fill_palette_8(crtc, i, set_palette);
 }
 EXPORT_SYMBOL(drm_crtc_fill_palette_8);
+
+/**
+ * drm_color_lut32_check - check validity of extended lookup table
+ * @lut: property blob containing extended LUT to check
+ * @tests: bitmask of tests to run
+ *
+ * Helper to check whether a userspace-provided extended lookup table is valid and
+ * satisfies hardware requirements.  Drivers pass a bitmask indicating which of
+ * the tests in &drm_color_lut_tests should be performed.
+ *
+ * Returns 0 on success, -EINVAL on failure.
+ */
+int drm_color_lut32_check(const struct drm_property_blob *lut, u32 tests)
+{
+       const struct drm_color_lut32 *entry;
+       int i;
+
+       if (!lut || !tests)
+               return 0;
+
+       entry = lut->data;
+       for (i = 0; i < drm_color_lut32_size(lut); i++) {
+               if (tests & DRM_COLOR_LUT_EQUAL_CHANNELS) {
+                       if (entry[i].red != entry[i].blue ||
+                           entry[i].red != entry[i].green) {
+                               DRM_DEBUG_KMS("All LUT entries must have equal r/g/b\n");
+                               return -EINVAL;
+                       }
+               }
+
+               if (i > 0 && tests & DRM_COLOR_LUT_NON_DECREASING) {
+                       if (entry[i].red < entry[i - 1].red ||
+                           entry[i].green < entry[i - 1].green ||
+                           entry[i].blue < entry[i - 1].blue) {
+                               DRM_DEBUG_KMS("LUT entries must never decrease.\n");
+                               return -EINVAL;
+                       }
+               }
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL(drm_color_lut32_check);
index eccb71ab335ad28014885b6b1c9c901704144fa3..527582c20885c4cc2b1675ee8903e460c8992e08 100644 (file)
@@ -72,6 +72,18 @@ static inline int drm_color_lut_size(const struct drm_property_blob *blob)
        return blob->length / sizeof(struct drm_color_lut);
 }
 
+/**
+ * drm_color_lut32_size - calculate the number of entries in the extended LUT
+ * @blob: blob containing the LUT
+ *
+ * Returns:
+ * The number of entries in the color LUT stored in @blob.
+ */
+static inline int drm_color_lut32_size(const struct drm_property_blob *blob)
+{
+       return blob->length / sizeof(struct drm_color_lut32);
+}
+
 enum drm_color_encoding {
        DRM_COLOR_YCBCR_BT601,
        DRM_COLOR_YCBCR_BT709,
@@ -146,4 +158,5 @@ void drm_crtc_load_palette_8(struct drm_crtc *crtc, const struct drm_color_lut *
 void drm_crtc_fill_palette_332(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
 void drm_crtc_fill_palette_8(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
 
+int drm_color_lut32_check(const struct drm_property_blob *lut, u32 tests);
 #endif
index 054561022953a24b06d98a77908b7cca862a5661..5e637ec7b64c77200c5579a26445e23d1bce772d 100644 (file)
@@ -872,6 +872,18 @@ struct drm_color_lut {
        __u16 reserved;
 };
 
+/*
+ * struct drm_color_lut32
+ *
+ * 32-bit per channel color LUT entry, similar to drm_color_lut.
+ */
+struct drm_color_lut32 {
+       __u32 red;
+       __u32 green;
+       __u32 blue;
+       __u32 reserved;
+};
+
 /**
  * enum drm_colorop_type - Type of color operation
  *