Skip to content

Commit e9c8f59

Browse files
swatish2-linuxjnikula
authored andcommitted
drm/i915/display: Add func to compare hw/sw gamma lut
Add func intel_color_lut_equal() to compare hw/sw gamma lut values. Since hw/sw gamma lut sizes and lut entries comparison will be different for different gamma modes, add gamma mode dependent checks. v3: -Rebase v4: -Renamed intel_compare_color_lut() to intel_color_lut_equal() [Jani] -Added the default label above the correct label [Jani] -Corrected smatch warn "variable dereferenced before check" [Dan Carpenter] v5: -Added condition (!blob1 && !blob2) return true [Jani] v6: -Made patch11 as patch3 [Jani] v8: -Split patch 3 into 4 patches -Optimized blob check condition [Ville] v9: -Exclude spilt gamma mode (bdw and ivb platforms) as there is exception in way gamma values are written in hardware [Ville] -Added exception made in commit [Uma] -Dropped else, character limit and indentation [Uma] -Added multi segmented gama mode for icl+ platforms [Uma] v10: -Dropped multi segmented mode for icl+ platforms [Jani] -Removed references of sw and hw state in compare code [Jani] -Dropped inline from func [Jani] Signed-off-by: Swati Sharma <swati2.sharma@intel.com> Reviewed-by: Jani Nikula <jani.nikula@intel.com> Signed-off-by: Jani Nikula <jani.nikula@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/1567538578-4489-4-git-send-email-swati2.sharma@intel.com
1 parent 145450f commit e9c8f59

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

drivers/gpu/drm/i915/display/intel_color.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,78 @@ int intel_color_get_gamma_bit_precision(const struct intel_crtc_state *crtc_stat
14311431
return 0;
14321432
}
14331433

1434+
static bool err_check(struct drm_color_lut *lut1,
1435+
struct drm_color_lut *lut2, u32 err)
1436+
{
1437+
return ((abs((long)lut2->red - lut1->red)) <= err) &&
1438+
((abs((long)lut2->blue - lut1->blue)) <= err) &&
1439+
((abs((long)lut2->green - lut1->green)) <= err);
1440+
}
1441+
1442+
static bool intel_color_lut_entry_equal(struct drm_color_lut *lut1,
1443+
struct drm_color_lut *lut2,
1444+
int lut_size, u32 err)
1445+
{
1446+
int i;
1447+
1448+
for (i = 0; i < lut_size; i++) {
1449+
if (!err_check(&lut1[i], &lut2[i], err))
1450+
return false;
1451+
}
1452+
1453+
return true;
1454+
}
1455+
1456+
bool intel_color_lut_equal(struct drm_property_blob *blob1,
1457+
struct drm_property_blob *blob2,
1458+
u32 gamma_mode, u32 bit_precision)
1459+
{
1460+
struct drm_color_lut *lut1, *lut2;
1461+
int lut_size1, lut_size2;
1462+
u32 err;
1463+
1464+
if (!blob1 != !blob2)
1465+
return false;
1466+
1467+
if (!blob1)
1468+
return true;
1469+
1470+
lut_size1 = drm_color_lut_size(blob1);
1471+
lut_size2 = drm_color_lut_size(blob2);
1472+
1473+
/* check sw and hw lut size */
1474+
switch (gamma_mode) {
1475+
case GAMMA_MODE_MODE_8BIT:
1476+
case GAMMA_MODE_MODE_10BIT:
1477+
if (lut_size1 != lut_size2)
1478+
return false;
1479+
break;
1480+
default:
1481+
MISSING_CASE(gamma_mode);
1482+
return false;
1483+
}
1484+
1485+
lut1 = blob1->data;
1486+
lut2 = blob2->data;
1487+
1488+
err = 0xffff >> bit_precision;
1489+
1490+
/* check sw and hw lut entry to be equal */
1491+
switch (gamma_mode) {
1492+
case GAMMA_MODE_MODE_8BIT:
1493+
case GAMMA_MODE_MODE_10BIT:
1494+
if (!intel_color_lut_entry_equal(lut1, lut2,
1495+
lut_size2, err))
1496+
return false;
1497+
break;
1498+
default:
1499+
MISSING_CASE(gamma_mode);
1500+
return false;
1501+
}
1502+
1503+
return true;
1504+
}
1505+
14341506
void intel_color_init(struct intel_crtc *crtc)
14351507
{
14361508
struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);

drivers/gpu/drm/i915/display/intel_color.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@
66
#ifndef __INTEL_COLOR_H__
77
#define __INTEL_COLOR_H__
88

9+
#include <linux/types.h>
10+
911
struct intel_crtc_state;
1012
struct intel_crtc;
13+
struct drm_property_blob;
1114

1215
void intel_color_init(struct intel_crtc *crtc);
1316
int intel_color_check(struct intel_crtc_state *crtc_state);
1417
void intel_color_commit(const struct intel_crtc_state *crtc_state);
1518
void intel_color_load_luts(const struct intel_crtc_state *crtc_state);
1619
void intel_color_get_config(struct intel_crtc_state *crtc_state);
1720
int intel_color_get_gamma_bit_precision(const struct intel_crtc_state *crtc_state);
21+
bool intel_color_lut_equal(struct drm_property_blob *blob1,
22+
struct drm_property_blob *blob2,
23+
u32 gamma_mode, u32 bit_precision);
1824

1925
#endif /* __INTEL_COLOR_H__ */

0 commit comments

Comments
 (0)