Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: Add Enhanced LUT precision structure

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

authored by

Uma Shankar and committed by
Simon Ser
621c45ca ec891d8b

+68
+43
drivers/gpu/drm/drm_color_mgmt.c
··· 874 874 fill_palette_8(crtc, i, set_palette); 875 875 } 876 876 EXPORT_SYMBOL(drm_crtc_fill_palette_8); 877 + 878 + /** 879 + * drm_color_lut32_check - check validity of extended lookup table 880 + * @lut: property blob containing extended LUT to check 881 + * @tests: bitmask of tests to run 882 + * 883 + * Helper to check whether a userspace-provided extended lookup table is valid and 884 + * satisfies hardware requirements. Drivers pass a bitmask indicating which of 885 + * the tests in &drm_color_lut_tests should be performed. 886 + * 887 + * Returns 0 on success, -EINVAL on failure. 888 + */ 889 + int drm_color_lut32_check(const struct drm_property_blob *lut, u32 tests) 890 + { 891 + const struct drm_color_lut32 *entry; 892 + int i; 893 + 894 + if (!lut || !tests) 895 + return 0; 896 + 897 + entry = lut->data; 898 + for (i = 0; i < drm_color_lut32_size(lut); i++) { 899 + if (tests & DRM_COLOR_LUT_EQUAL_CHANNELS) { 900 + if (entry[i].red != entry[i].blue || 901 + entry[i].red != entry[i].green) { 902 + DRM_DEBUG_KMS("All LUT entries must have equal r/g/b\n"); 903 + return -EINVAL; 904 + } 905 + } 906 + 907 + if (i > 0 && tests & DRM_COLOR_LUT_NON_DECREASING) { 908 + if (entry[i].red < entry[i - 1].red || 909 + entry[i].green < entry[i - 1].green || 910 + entry[i].blue < entry[i - 1].blue) { 911 + DRM_DEBUG_KMS("LUT entries must never decrease.\n"); 912 + return -EINVAL; 913 + } 914 + } 915 + } 916 + 917 + return 0; 918 + } 919 + EXPORT_SYMBOL(drm_color_lut32_check);
+13
include/drm/drm_color_mgmt.h
··· 72 72 return blob->length / sizeof(struct drm_color_lut); 73 73 } 74 74 75 + /** 76 + * drm_color_lut32_size - calculate the number of entries in the extended LUT 77 + * @blob: blob containing the LUT 78 + * 79 + * Returns: 80 + * The number of entries in the color LUT stored in @blob. 81 + */ 82 + static inline int drm_color_lut32_size(const struct drm_property_blob *blob) 83 + { 84 + return blob->length / sizeof(struct drm_color_lut32); 85 + } 86 + 75 87 enum drm_color_encoding { 76 88 DRM_COLOR_YCBCR_BT601, 77 89 DRM_COLOR_YCBCR_BT709, ··· 158 146 void drm_crtc_fill_palette_332(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette); 159 147 void drm_crtc_fill_palette_8(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette); 160 148 149 + int drm_color_lut32_check(const struct drm_property_blob *lut, u32 tests); 161 150 #endif
+12
include/uapi/drm/drm_mode.h
··· 872 872 __u16 reserved; 873 873 }; 874 874 875 + /* 876 + * struct drm_color_lut32 877 + * 878 + * 32-bit per channel color LUT entry, similar to drm_color_lut. 879 + */ 880 + struct drm_color_lut32 { 881 + __u32 red; 882 + __u32 green; 883 + __u32 blue; 884 + __u32 reserved; 885 + }; 886 + 875 887 /** 876 888 * enum drm_colorop_type - Type of color operation 877 889 *