Skip to content

Commit 621c45c

Browse files
uma-intelemersion
authored andcommitted
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
1 parent ec891d8 commit 621c45c

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

drivers/gpu/drm/drm_color_mgmt.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,3 +874,46 @@ void drm_crtc_fill_palette_8(struct drm_crtc *crtc, drm_crtc_set_lut_func set_pa
874874
fill_palette_8(crtc, i, set_palette);
875875
}
876876
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);

include/drm/drm_color_mgmt.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ static inline int drm_color_lut_size(const struct drm_property_blob *blob)
7272
return blob->length / sizeof(struct drm_color_lut);
7373
}
7474

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+
7587
enum drm_color_encoding {
7688
DRM_COLOR_YCBCR_BT601,
7789
DRM_COLOR_YCBCR_BT709,
@@ -146,4 +158,5 @@ void drm_crtc_load_palette_8(struct drm_crtc *crtc, const struct drm_color_lut *
146158
void drm_crtc_fill_palette_332(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
147159
void drm_crtc_fill_palette_8(struct drm_crtc *crtc, drm_crtc_set_lut_func set_palette);
148160

161+
int drm_color_lut32_check(const struct drm_property_blob *lut, u32 tests);
149162
#endif

include/uapi/drm/drm_mode.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,18 @@ struct drm_color_lut {
872872
__u16 reserved;
873873
};
874874

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+
875887
/**
876888
* enum drm_colorop_type - Type of color operation
877889
*

0 commit comments

Comments
 (0)