Skip to contentSkip to conversation

Color Management for DRM framework

PATCH Superseded Shashank Sharma 5 participants 35 messages Oct 16, 2015 – Oct 20, 2015

Subsystems (3)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v6 cover Color Management for DRM framework

This patch set adds Color Manager implementation in DRM layer. Color Manager is an extension in DRM framework to support color correction/enhancement.

Various Hardware platforms can support several color correction capabilities. Color Manager provides abstraction of these capabilities and allows a user space UI agent to correct/enhance the display using the DRM property interface.

How is this going to work?
==========================
1. This patch series adds a few new properties in DRM framework. These properties are:
a. color_capabilities property (type blob)
b. Color Transformation Matrix property for corrections like CSC (called CTM, type blob)
c. Palette correction properties for corrections like gamma fixup (called palette_correction, type blob)
2. Also, this patch series adds few structures to indicate specifications of a property like size, no_of_samples for correction etc.
3. These properties are present in mode_config.
4. When the platform's display driver loads, it fills up the values of color_capabilities property using the standard structures (added in step 2). For example, Intel's I915 driver adds following color correction capabilities:
a. gamma correction capability as palette correction property, with 257 correction coefficients and a max/min value b. csc correction capability as CTM correction property, with 3x3 transformation matrix values and max/min values
5. Now when userspace comes up, it queries the platform's color capabilities by doing a get_property() on color_capabilities DRM property
6. Reading the blob, the userspace understands the color capabilities of the platform.
For example, userspace will understand it can support:
a. palette_correction with 257 coefficients
b. CSC correction with 3x3 = 9 values
7. To set color correction values, userspace:
a. creates a blob using the create_blob_ioctl in standard palette_correction structure format, with the correction values b. calls the set_property_ioctl with the blob_id as value for the property
8. Driver refers to the blob, gets the correction values and applies the correction in HW.
9. To get currently applied color correction values, userspace:
a. calls a get_property_ioctl on that color property
b. gets the blob_id for the currently applied correction from DRM infrastructure
c. gets the blob using get_blob_ioctl and hence the currently applied values

That's all! :)

About the patch series:
=======================
The patch series first adds the color management support in DRM layer. Then it adds the color management framework in I915 layer. After that, it implements platform specific core color correction functios.

Intel color manager registers color correction with DRM color manager in this way:
- CSC transformation is registered as CTM DRM property
- Gamma correction is registered as palette_after_ctm DRM property
- Degamma correction is registered as palette_before_ctm DRM property

Our thanks to all the reviewers who have given valuable comments in terms of design and implementation to our previous sets of patches. Special mention of thanks should go to Matt Roper for all his inputs/suggestions in implementation of this module, using DRM atomic CRTC commit path.

V2: Worked on review comments from Matt, Jim, Thierry, Rob.
V3: Worked on review comments from Matt, Jim, Rob:
- Jim, Rob:
========
Re-arranged the whole patch series in the sequence of features, currently:
First 5 patches add color management support in DRM layer
Next 7 patches add Intel color management framework in I915 driver
Next 5 patches add color correction for CHV (gamma, degamma and CSC)
Next 2 patches enable color management, by attaching the properties to CRTC(Matt) Next 4 patches add color correction for BDW (gamma, degamma)
- Matt:
=====
Patch 3: Added refernce/unreference for blob
Patch 7: return -EINVAL and added debug message
Patch 8: check for valid blob, from create blob
moved call to intel_crtc_attach_color_prop in the end of full implementation (CHV)
Patch 9: DRM_ERROR->DRM_DEBUG for NULL blob case
Patch 13: Added static for internal functions
Patch 20-24: renamed gen9_* functions to bdw_*
Added new variables in device_info structure num_samples_after_ctm and num_samples_before_ctm Added new function in patch 8 to load capabilities based on device_info across all platforms

V4: Worked on review comments from Daniel, Matt, Rob, Jim
- Rob, Jim:
=========
Patch 15, 22: Prepare CSC coeff properly(chv, bdw).
Patch 13, 20: Gamma max should be (1<<24) -1(chv, bdw).
- Daniel, Matt:
=============
Patch 2: Create separate properties to query color capabilities, not a single blob. Patch 4, 5, 10: Add set/get property interface in DRM layer, not in I915 layer.

V5: Addressed review comments from Emil, Rob.
-Emil:
======
Patch 3: Fixed changes from patch 2, which were merged in patch 3 Patch 4: Added static for drm_atomic_crtc_set_blob
Patch 13: Removed unnecessary initialization for various functions Patch 14: Removed unnecessary initialization for variables
Checked for overflow for length
Dropped variable ret, using direct returns instead
Patch 15: Fixed type of return value of function chv_prepare_csc_coeff
Fixed the type of variable csc_s3_12_format Changed the looping approach to write csc coefficients
Patch 16: Fixed typo in intel_drv.h (intel_color_manager.c) Patch 19: Made bdw_write_12_bit_gamma_precision function static
Fixed alignment problems with debug message
Patch 21: Fixed indentation of debug message
Patch 22: Removed change which belonged to another patch
Made function bdw_set_csc static

-Rob:
======
Patch 19: Clipped -> Clamped
SET_BITS in 10bit gamma was taking red_fraction variable for all channels, fixed that. Added check for MAX values in 12_bit_gamma function
Added new function for 8_bit_gamma mode (legacy) with MAX value checks
Patch 20: Fixed commit message (BDW degamma values was mentioned as 65 in it). Patch 21: Removed unused length variable
Moved mode variable closer to a place where its being used
Removed cast for correction_values
DeGamma -> degamma

V6: Addressed review comments from Emil, Daniel, Rob and Jim
-Emil:
======
Patch 10: Put definition and prototype in the same patch for function
intel_attach_color_properties_to_crtc
Patch 19: Removed extra line before every case() of switch()
Patch 13: Replace if..else in function chv_set_degamma with switch case to maintain consistency Patch 21: Replace if..else in function bdw_set_degamma with switch case to maintain consistency

-Daniel/Rob:
=============
Removed num_samples from overall palette implementation, use blob_size/sizeof(struct drm_r32g32b32)

-Jim:
=====
Patch 13: Replace if..else in function chv_set_degamma with switch case Patch 21: Replace if..else in function bdw_set_degamma with switch case

Shashank Sharma (23):
drm: Create Color Management DRM properties
drm: Create Color Management query properties
drm: Add color correction blobs in CRTC state
drm: Add set property support for color manager
drm: Add get property support for color manager
drm: Add drm structures for palette color property
drm: Add structure for CTM color property drm/i915: Add set property interface for CRTC drm/i915: Create color management files drm/i915: Register color correction capabilities drm/i915: CHV: Load gamma color correction values drm/i915: CHV: Load degamma color correction values drm/i915: CHV: Pipe level Gamma correction drm/i915: CHV: Pipe level degamma correction drm/i915: CHV: Pipe level CSC correction drm/i915: Commit color correction to CRTC drm/i915: Attach color properties to CRTC drm/i915: BDW: Load gamma correction values drm/i915: BDW: Pipe level Gamma correction drm/i915: BDW: Load degamma correction values drm/i915: BDW: Pipe level degamma correction drm/i915: BDW: Pipe level CSC correction drm/i915: disable plane gamma

 drivers/gpu/drm/drm_atomic.c               |  61 ++-
 drivers/gpu/drm/drm_atomic_helper.c        |  12 +
 drivers/gpu/drm/drm_crtc.c                 |  32 ++
 drivers/gpu/drm/i915/Makefile              |   3 +-
 drivers/gpu/drm/i915/i915_drv.c            |  17 +
 drivers/gpu/drm/i915/i915_drv.h            |   2 +
 drivers/gpu/drm/i915/i915_reg.h            |  58 +-
 drivers/gpu/drm/i915/intel_color_manager.c | 846 +++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_color_manager.h | 111 ++++
 drivers/gpu/drm/i915/intel_display.c       |   6 +-
 drivers/gpu/drm/i915/intel_drv.h           |   5 +
 drivers/gpu/drm/i915/intel_sprite.c        |   7 +-
 include/drm/drm_crtc.h                     |  14 +
 include/uapi/drm/drm.h                     |  30 +
 14 files changed, 1195 insertions(+), 9 deletions(-)
 create mode 100644 drivers/gpu/drm/i915/intel_color_manager.c
 create mode 100644 drivers/gpu/drm/i915/intel_color_manager.h
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH v6 1/23 drm: Create Color Management DRM properties

Color Management is an extension to DRM framework. It allows abstraction of hardware color correction and enhancement capabilities by virtue of DRM properties.

There are two major types of color correction supported by DRM color manager:
- CTM: color transformation matrix, properties where a correction matrix is used for color correction.
- Palette correction: Where direct LUT values are sent to be applied on a color palette.

This patch initializes color management framework by:
1. Introducing new pointers in DRM mode_config structure to carry CTM and Palette color correction properties.
2. Creating these DRM properties in DRM standard properties creation sequence.

---
 drivers/gpu/drm/drm_crtc.c | 19 +++++++++++++++++++
 include/drm/drm_crtc.h     |  5 +++++
 2 files changed, 24 insertions(+)
drivers/gpu/drm/drm_crtc.c +19 -0
index 6058f4b..24094ee 100644
@@ -1471,6 +1471,25 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.prop_mode_id = prop;
 
+	/* Color Management properties */
+	prop = drm_property_create(dev,
+			DRM_MODE_PROP_BLOB, "PALETTE_AFTER_CTM", 0);
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.cm_palette_after_ctm_property = prop;
+
+	prop = drm_property_create(dev,
+			DRM_MODE_PROP_BLOB, "PALETTE_BEFORE_CTM", 0);
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.cm_palette_before_ctm_property = prop;
+
+	prop = drm_property_create(dev,
+			DRM_MODE_PROP_BLOB, "CTM", 0);
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.cm_ctm_property = prop;
+
 	return 0;
 }
 
include/drm/drm_crtc.h +5 -0
index 33ddedd..5ddc1a2 100644
@@ -1148,6 +1148,11 @@ struct drm_mode_config {
 	struct drm_property *suggested_x_property;
 	struct drm_property *suggested_y_property;
 
+	/* Color Management Properties */
+	struct drm_property *cm_palette_before_ctm_property;
+	struct drm_property *cm_palette_after_ctm_property;
+	struct drm_property *cm_ctm_property;
+
 	/* dumb ioctl parameters */
 	uint32_t preferred_depth, prefer_shadow;
 
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH v6 2/23 drm: Create Color Management query properties

In reply to Shashank Sharma

DRM color management is written to extract the color correction capabilities of various platforms, and every platform can showcase its capabilities using the query properties.

Different hardwares can have different no of coefficients for palette correction. Also the correction can be applied after/before color transformation (CTM) unit in the display pipeline.

This patch adds two new read-only properties,
- cm_coeff_before_ctm_property: A platform driver should use this property to show supported no_of_coefficients for palette correction, which gets applied before ctm correction.
- cm_coeff_after_ctm_property: A platform driver should use this property to show supported no_of_coefficients for palette correction, which gets applied after ctm correction.

---
 drivers/gpu/drm/drm_crtc.c | 13 +++++++++++++
 include/drm/drm_crtc.h     |  4 ++++
 2 files changed, 17 insertions(+)
drivers/gpu/drm/drm_crtc.c +13 -0
index 24094ee..2ee6ec3 100644
@@ -1490,6 +1490,19 @@ static int drm_mode_create_standard_properties(struct drm_device *dev)
 		return -ENOMEM;
 	dev->mode_config.cm_ctm_property = prop;
 
+	/* DRM properties to query color capabilities */
+	prop = drm_property_create(dev, DRM_MODE_PROP_IMMUTABLE,
+			"COEFFICIENTS_BEFORE_CTM", 0);
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.cm_coeff_before_ctm_property = prop;
+
+	prop = drm_property_create(dev, DRM_MODE_PROP_IMMUTABLE,
+			"COEFFICIENTS_AFTER_CTM", 0);
+	if (!prop)
+		return -ENOMEM;
+	dev->mode_config.cm_coeff_after_ctm_property = prop;
+
 	return 0;
 }
 
include/drm/drm_crtc.h +4 -0
index 5ddc1a2..1a56596 100644
@@ -1153,6 +1153,10 @@ struct drm_mode_config {
 	struct drm_property *cm_palette_after_ctm_property;
 	struct drm_property *cm_ctm_property;
 
+	/* Color management capabilities query */
+	struct drm_property *cm_coeff_before_ctm_property;
+	struct drm_property *cm_coeff_after_ctm_property;
+
 	/* dumb ioctl parameters */
 	uint32_t preferred_depth, prefer_shadow;
 
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

PATCH v6 3/23 drm: Add color correction blobs in CRTC state

In reply to Shashank Sharma

This patch adds new variables in CRTC state, to hold respective color correction blobs. These blobs will be required during the atomic commit for writing the color correction values in correction registers.

---
 drivers/gpu/drm/drm_atomic_helper.c | 12 ++++++++++++
 include/drm/drm_crtc.h              |  5 +++++
 2 files changed, 17 insertions(+)
drivers/gpu/drm/drm_atomic_helper.c +12 -0
index 87a2a44..d73ca9b9 100644
@@ -2193,6 +2193,12 @@ void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
 
 	if (state->mode_blob)
 		drm_property_reference_blob(state->mode_blob);
+	if (state->ctm_blob)
+		drm_property_reference_blob(state->ctm_blob);
+	if (state->palette_after_ctm_blob)
+		drm_property_reference_blob(state->palette_after_ctm_blob);
+	if (state->palette_before_ctm_blob)
+		drm_property_reference_blob(state->palette_before_ctm_blob);
 	state->mode_changed = false;
 	state->active_changed = false;
 	state->planes_changed = false;
@@ -2238,6 +2244,12 @@ void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
 {
 	if (state->mode_blob)
 		drm_property_unreference_blob(state->mode_blob);
+	if (state->ctm_blob)
+		drm_property_unreference_blob(state->ctm_blob);
+	if (state->palette_after_ctm_blob)
+		drm_property_unreference_blob(state->palette_after_ctm_blob);
+	if (state->palette_before_ctm_blob)
+		drm_property_unreference_blob(state->palette_before_ctm_blob);
 }
 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
 
include/drm/drm_crtc.h +5 -0
index 1a56596..d416e20 100644
@@ -304,6 +304,11 @@ struct drm_crtc_state {
 	/* blob property to expose current mode to atomic userspace */
 	struct drm_property_blob *mode_blob;
 
+	/* blob properties to hold the color properties' blobs */
+	struct drm_property_blob *palette_before_ctm_blob;
+	struct drm_property_blob *palette_after_ctm_blob;
+	struct drm_property_blob *ctm_blob;
+
 	struct drm_pending_vblank_event *event;
 
 	struct drm_atomic_state *state;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#4 lore raw

PATCH v6 4/23 drm: Add set property support for color manager

In reply to Shashank Sharma

As per DRM color manager design, if a userspace wants to set a correction blob, it prepares it and sends the blob_id to kernel via set_property call. DRM framework takes this blob_id, gets the blob, and saves it in the CRTC state, so that, during the atomic_commit, the color correction values from the blob can referred and applied on display controller registers.

This patch adds this set_property support for color correction blobs in drm framework.

---
 drivers/gpu/drm/drm_atomic.c | 53 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 51 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_atomic.c +51 -2
index 7bb3845..12a34e9 100644
@@ -390,6 +390,38 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
 EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc);
 
 /**
+ * drm_atomic_crtc_set_blob - find and set a blob
+ * @state_blob: reference pointer to the color blob in the crtc_state
+ * @blob_id: blob_id coming from set_property() call
+ *
+ * Set a color correction blob (originating from a set blob property) on the
+ * desired CRTC state. This function will take reference of the blob property
+ * in the CRTC state, finds the blob based on blob_id (which comes from
+ * set_property call) and set the blob at the proper place.
+ *
+ * RETURNS:
+ * Zero on success, error code on failure.
+ */
+static int drm_atomic_crtc_set_blob(struct drm_device *dev,
+	struct drm_property_blob **state_blob, uint32_t blob_id)
+{
+	struct drm_property_blob *blob;
+
+	blob = drm_property_lookup_blob(dev, blob_id);
+	if (!blob) {
+		DRM_DEBUG_KMS("Invalid Blob ID\n");
+		return -EINVAL;
+	}
+
+	if (*state_blob)
+		drm_property_unreference_blob(*state_blob);
+
+	/* Attach the blob to be committed in state */
+	*state_blob = blob;
+	return 0;
+}
+
+/**
  * drm_atomic_crtc_set_property - set property on CRTC
  * @crtc: the drm CRTC to set a property on
  * @state: the state object to update with the new property value
@@ -422,8 +454,25 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
 		if (mode)
 			drm_property_unreference_blob(mode);
 		return ret;
-	}
-	else if (crtc->funcs->atomic_set_property)
+	} else if (property == config->cm_palette_after_ctm_property) {
+		ret = drm_atomic_crtc_set_blob(dev,
+				&state->palette_after_ctm_blob, val);
+		if (ret)
+			DRM_ERROR("Failed to load blob palette_after_ctm\n");
+		return ret;
+	} else if (property == config->cm_palette_before_ctm_property) {
+		ret = drm_atomic_crtc_set_blob(dev,
+				&state->palette_before_ctm_blob, val);
+		if (ret)
+			DRM_ERROR("Failed to load blob palette_before_ctm\n");
+		return ret;
+	} else if (property == config->cm_ctm_property) {
+		ret = drm_atomic_crtc_set_blob(dev,
+				&state->ctm_blob, val);
+		if (ret)
+			DRM_ERROR("Failed to load blob ctm\n");
+		return ret;
+	} else if (crtc->funcs->atomic_set_property)
 		return crtc->funcs->atomic_set_property(crtc, state, property, val);
 	else
 		return -EINVAL;
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH v6 5/23 drm: Add get property support for color manager

In reply to Shashank Sharma

As per the DRM get_property implementation for a blob, framework is supposed to return the blob_id to the caller. All the color management blobs are saved in CRTC state during the set call.

This patch adds get_property support for color management properties, by referring to the existing blob for the property and passing its blob_id.

---
 drivers/gpu/drm/drm_atomic.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/gpu/drm/drm_atomic.c +8 -0
index 12a34e9..b49aaeb 100644
@@ -499,6 +499,14 @@ drm_atomic_crtc_get_property(struct drm_crtc *crtc,
 		*val = state->active;
 	else if (property == config->prop_mode_id)
 		*val = (state->mode_blob) ? state->mode_blob->base.id : 0;
+	else if (property == config->cm_palette_after_ctm_property)
+		*val = (state->palette_after_ctm_blob) ?
+			state->palette_after_ctm_blob->base.id : 0;
+	else if (property == config->cm_palette_before_ctm_property)
+		*val = (state->palette_before_ctm_blob) ?
+			state->palette_before_ctm_blob->base.id : 0;
+	else if (property == config->cm_ctm_property)
+		*val = (state->ctm_blob) ? state->ctm_blob->base.id : 0;
 	else if (crtc->funcs->atomic_get_property)
 		return crtc->funcs->atomic_get_property(crtc, state, property, val);
 	else
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

PATCH v6 6/23 drm: Add drm structures for palette color property

In reply to Shashank Sharma

This patch adds new structures in DRM layer for Palette color correction.These structures will be used by user space agents to configure appropriate number of samples and Palette LUT for a platform.

---
 include/uapi/drm/drm.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
include/uapi/drm/drm.h +20 -0
index 3801584..3dce251 100644
@@ -829,6 +829,26 @@ struct drm_event_vblank {
 	__u32 reserved;
 };
 
+struct drm_r32g32b32 {
+	/*
+	 * Data is in U8.24 fixed point format.
+	 * All platforms support values within [0, 1.0] range,
+	 * for Red, Green and Blue colors.
+	 */
+	__u32 r32;
+	__u32 g32;
+	__u32 b32;
+	__u32 reserved;
+};
+
+struct drm_palette {
+	/*
+	 * Starting of palette LUT in R32G32B32 format.
+	 * Each of RGB value is in U8.24 fixed point format.
+	 */
+	struct drm_r32g32b32 lut[0];
+};
+
 /* typedef area */
 #ifndef __KERNEL__
 typedef struct drm_clip_rect drm_clip_rect_t;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#7 lore raw

PATCH v6 7/23 drm: Add structure for CTM color property

In reply to Shashank Sharma

Color Manager framework defines a DRM property for color space transformation and Gamut mapping. This property is called CTM (Color Transformation Matrix).

This patch adds a new structure in DRM layer for CTM. This structure can be used by all user space agents to configure CTM coefficients for color correction.

---
 include/uapi/drm/drm.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
include/uapi/drm/drm.h +10 -0
index 3dce251..d4de772 100644
@@ -849,6 +849,16 @@ struct drm_palette {
 	struct drm_r32g32b32 lut[0];
 };
 
+struct drm_ctm {
+	/*
+	 * Each value is in S31.32 format.
+	 * This is 3x3 matrix in row major format.
+	 * Integer part will be clipped to nearest
+	 * max/min boundary as supported by the HW platform.
+	 */
+	__s64 ctm_coeff[9];
+};
+
 /* typedef area */
 #ifndef __KERNEL__
 typedef struct drm_clip_rect drm_clip_rect_t;
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#8 lore raw

PATCH v6 8/23 drm/i915: Add set property interface for CRTC

In reply to Shashank Sharma

This patch adds set property interface for intel CRTC. This interface will be used for set operation on any DRM properties.

---
 drivers/gpu/drm/i915/intel_display.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/intel_display.c +1 -0
index 5f37f84..7cad341 100644
@@ -13241,6 +13241,7 @@ static const struct drm_crtc_funcs intel_crtc_funcs = {
 	.page_flip = intel_crtc_page_flip,
 	.atomic_duplicate_state = intel_crtc_duplicate_state,
 	.atomic_destroy_state = intel_crtc_destroy_state,
+	.set_property = drm_atomic_helper_crtc_set_property,
 };
 
 static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv,
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

PATCH v6 9/23 drm/i915: Create color management files

In reply to Shashank Sharma

This patch create new files intel_color_manager.c which will contain the core color correction code for I915 driver and its header intel_color_manager.h

The per color property patches coming up in this patch series will fill the appropriate functions in this file.

---
 drivers/gpu/drm/i915/Makefile              |  3 +-
 drivers/gpu/drm/i915/intel_color_manager.c | 33 ++++++++++++++++++++
 drivers/gpu/drm/i915/intel_color_manager.h | 50 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_drv.h           |  3 ++
 4 files changed, 88 insertions(+), 1 deletion(-)
 create mode 100644 drivers/gpu/drm/i915/intel_color_manager.c
 create mode 100644 drivers/gpu/drm/i915/intel_color_manager.h
drivers/gpu/drm/i915/Makefile +2 -1
index 44d290a..56caf9e 100644
@@ -64,7 +64,8 @@ i915-y += intel_audio.o \
 	  intel_overlay.o \
 	  intel_psr.o \
 	  intel_sideband.o \
-	  intel_sprite.o
+	  intel_sprite.o \
+	  intel_color_manager.o
 i915-$(CONFIG_ACPI)		+= intel_acpi.o intel_opregion.o
 i915-$(CONFIG_DRM_FBDEV_EMULATION)	+= intel_fbdev.o
 
drivers/gpu/drm/i915/intel_color_manager.c new file +33 -0
new file mode 100644
index 0000000..b03ee94
@@ -0,0 +1,33 @@
+/*
+ * Copyright © 2015 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ * Authors:
+ * Shashank Sharma <[email protected]>
+ * Kausal Malladi <[email protected]>
+ */
+
+#include "intel_color_manager.h"
+
+void intel_attach_color_properties_to_crtc(struct drm_device *dev,
+		struct drm_crtc *crtc)
+{
+}
drivers/gpu/drm/i915/intel_color_manager.h new file +50 -0

50 lines not on this page · raw message

drivers/gpu/drm/i915/intel_drv.h +3 -0
index 0598932..2e4e97d 100644
@@ -1477,4 +1477,7 @@ void intel_plane_destroy_state(struct drm_plane *plane,
 			       struct drm_plane_state *state);
 extern const struct drm_plane_helper_funcs intel_plane_helper_funcs;
 
+/* intel_color_manager.c */
+void intel_attach_color_properties_to_crtc(struct drm_device *dev,
+	struct drm_crtc *crtc);
 #endif /* __INTEL_DRV_H__ */
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

PATCH v6 10/23 drm/i915: Register color correction capabilities

In reply to Shashank Sharma

From DRM color management:
============================
DRM color manager supports these color properties:
1. "ctm": Color transformation matrix property, where a color transformation matrix of 9 correction values gets applied as correction.
2. "palette_before_ctm": for corrections which get applied beore color transformation matrix correction.
3. "palette_after_ctm": for corrections which get applied after color transformation matrix correction.

These color correction capabilities may differ per platform, supporting various different no. of correction coefficients. So DRM color manager support few properties using which a user space can query the platform's capability, and prepare color correction accordingly.
These query properties are:
1. cm_coeff_after_ctm_property
2. cm_coeff_before_ctm_property
(CTM is fix to 9 coefficients across industry)

Now, Intel color manager registers:
======================================
1. Gamma correction property as "palette_after_ctm" property
2. Degamma correction capability as "palette_bafore_ctm" property capability as "palette_after_ctm" DRM color property hook.
3. CSC as "ctm" property.

So finally, This patch does the following:
1. Add a function which loads the platform's color correction capabilities in the cm_crtc_palette_capabilities_property structure.
2. Attaches the cm_crtc_palette_capabilities_property to every CRTC getting initiaized.
3. Adds two new parameters "num_samples_after_ctm" and "num_samples_before_ctm" in intel_device_info as gamma and degamma coefficients vary per platform basis.

---
 drivers/gpu/drm/i915/i915_drv.h            |  2 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 31 ++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)
drivers/gpu/drm/i915/i915_drv.h +2 -0
index 8afda45..613bee2 100644
@@ -789,6 +789,8 @@ struct intel_device_info {
 	u8 num_sprites[I915_MAX_PIPES];
 	u8 gen;
 	u8 ring_mask; /* Rings supported by the HW */
+	u16 num_samples_after_ctm;
+	u16 num_samples_before_ctm;
 	DEV_INFO_FOR_EACH_FLAG(DEFINE_FLAG, SEP_SEMICOLON);
 	/* Register offsets for the various display pipes and transcoders */
 	int pipe_offsets[I915_MAX_TRANSCODERS];
drivers/gpu/drm/i915/intel_color_manager.c +31 -0
index b03ee94..334bfff 100644
@@ -30,4 +30,35 @@
 void intel_attach_color_properties_to_crtc(struct drm_device *dev,
 		struct drm_crtc *crtc)
 {
+	struct drm_mode_config *config = &dev->mode_config;
+	struct drm_mode_object *mode_obj = &crtc->base;
+
+	/*
+	* Register:
+	* =========
+	* Gamma correction as palette_after_ctm property
+	* Degamma correction as palette_before_ctm property
+	*
+	* Load:
+	* =====
+	* no. of coefficients supported on this platform for gamma
+	* and degamma with the query properties. A user
+	* space agent should read these query property, and prepare
+	* the color correction values accordingly. Its expected from the
+	* driver to load the right number of coefficients during the init
+	* phase.
+	*/
+	if (config->cm_coeff_after_ctm_property) {
+		drm_object_attach_property(mode_obj,
+			config->cm_coeff_after_ctm_property,
+		INTEL_INFO(dev)->num_samples_after_ctm);
+		DRM_DEBUG_DRIVER("Gamma query property initialized\n");
+	}
+
+	if (config->cm_coeff_before_ctm_property) {
+		drm_object_attach_property(mode_obj,
+			config->cm_coeff_before_ctm_property,
+		INTEL_INFO(dev)->num_samples_before_ctm);
+		DRM_DEBUG_DRIVER("Degamma query property initialized\n");
+	}
 }
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw

PATCH v6 11/23 drm/i915: CHV: Load gamma color correction values

In reply to Shashank Sharma

DRM color manager allows the driver to showcase its best color correction capabilities using the specific query property cm_coeff_after_ctm_property. The driver must loads the no. of coefficients for color correction as per the platform capability during the init time.

This patch adds no of coefficitents for best gamma color correction modes possible in CHV, in device info structure, which is:
Gamma(10 bit, CGM HW unit): 257 coeff

These values will be loaded in cm_crtc_palette_capabilities_property during the CRTC init section, by color manager's attach function.

---
 drivers/gpu/drm/i915/i915_drv.c            | 2 ++
 drivers/gpu/drm/i915/intel_color_manager.h | 3 +++
 2 files changed, 5 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +2 -0
index 760e0ce..7780de4 100644
@@ -34,6 +34,7 @@
 #include "i915_drv.h"
 #include "i915_trace.h"
 #include "intel_drv.h"
+#include "intel_color_manager.h"
 
 #include <linux/console.h>
 #include <linux/module.h>
@@ -349,6 +350,7 @@ static const struct intel_device_info intel_cherryview_info = {
 	.gen = 8, .num_pipes = 3,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
+	.num_samples_after_ctm = CHV_10BIT_GAMMA_MAX_VALS,
 	.is_valleyview = 1,
 	.display_mmio_offset = VLV_DISPLAY_BASE,
 	GEN_CHV_PIPEOFFSETS,
drivers/gpu/drm/i915/intel_color_manager.h +3 -0
index eec52a7..a378fe1 100644
@@ -48,3 +48,6 @@
 			CLEAR_BITS(target, start_bit, no_bits); \
 			target |= (bit_pattern << start_bit);  \
 		} while (0)
+
+/* CHV */
+#define CHV_10BIT_GAMMA_MAX_VALS		257
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#12 lore raw

PATCH v6 12/23 drm/i915: CHV: Load degamma color correction values

In reply to Shashank Sharma

DRM color manager allows the driver to showcase its best color correction capabilities using the specific query property cm_coeff_before_ctm_property. The driver must loads the no. of coefficients for color correction as per the platform capability during the init time.

This patch adds no of coefficitents for degamma color correction modes possible in CHV, in device info structure, which is:
CGM Degamma(10 bit, CGM HW unit): 65 coeff

These values will be loaded in cm_crtc_palette_capabilities_property during the CRTC init section, by color manager's attach function.

---
 drivers/gpu/drm/i915/i915_drv.c            | 1 +
 drivers/gpu/drm/i915/intel_color_manager.h | 1 +
 2 files changed, 2 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +1 -0
index 7780de4..6adf002 100644
@@ -351,6 +351,7 @@ static const struct intel_device_info intel_cherryview_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
 	.num_samples_after_ctm = CHV_10BIT_GAMMA_MAX_VALS,
+	.num_samples_before_ctm = CHV_DEGAMMA_MAX_VALS,
 	.is_valleyview = 1,
 	.display_mmio_offset = VLV_DISPLAY_BASE,
 	GEN_CHV_PIPEOFFSETS,
drivers/gpu/drm/i915/intel_color_manager.h +1 -0
index a378fe1..14a1309 100644
@@ -51,3 +51,4 @@
 
 /* CHV */
 #define CHV_10BIT_GAMMA_MAX_VALS		257
+#define CHV_DEGAMMA_MAX_VALS                   65
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#13 lore raw

PATCH v6 13/23 drm/i915: CHV: Pipe level Gamma correction

In reply to Shashank Sharma

CHV/BSW platform supports two different pipe level gamma correction modes, which are:
1. Legacy 8-bit mode
2. 10-bit CGM (Color Gamut Mapping) mode

This patch does the following:
1. Attaches Gamma property to CRTC
3. Adds the core Gamma correction function for CHV/BSW
4. Adds Gamma correction macros

---
 drivers/gpu/drm/i915/i915_reg.h            | 12 ++++
 drivers/gpu/drm/i915/intel_color_manager.c | 94 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_color_manager.h | 13 +++++
 3 files changed, 119 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +12 -0
index 9ebf032..45ddd84 100644
@@ -8148,4 +8148,16 @@ enum skl_disp_power_wells {
 #define GEN9_VEBOX_MOCS_0	0xcb00	/* Video MOCS base register*/
 #define GEN9_BLT_MOCS_0		0xcc00	/* Blitter MOCS base register*/
 
+/* Color Management */
+#define PIPEA_CGM_CONTROL			(VLV_DISPLAY_BASE + 0x67A00)
+#define PIPEB_CGM_CONTROL			(VLV_DISPLAY_BASE + 0x69A00)
+#define PIPEC_CGM_CONTROL			(VLV_DISPLAY_BASE + 0x6BA00)
+#define PIPEA_CGM_GAMMA			(VLV_DISPLAY_BASE + 0x67000)
+#define PIPEB_CGM_GAMMA			(VLV_DISPLAY_BASE + 0x69000)
+#define PIPEC_CGM_GAMMA			(VLV_DISPLAY_BASE + 0x6B000)
+#define _PIPE_CGM_CONTROL(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_CONTROL, PIPEB_CGM_CONTROL, PIPEC_CGM_CONTROL))
+#define _PIPE_GAMMA_BASE(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +94 -0

104 lines not on this page · raw message

drivers/gpu/drm/i915/intel_color_manager.h +13 -0
index 14a1309..de706d9 100644
@@ -52,3 +52,16 @@
 /* CHV */
 #define CHV_10BIT_GAMMA_MAX_VALS		257
 #define CHV_DEGAMMA_MAX_VALS                   65
+
+/* No of coeff for disabling gamma is 0 */
+#define GAMMA_DISABLE_VALS			0
+
+/* Gamma on CHV */
+#define CHV_10BIT_GAMMA_MAX_VALS               257
+#define CHV_8BIT_GAMMA_MAX_VALS                256
+#define CHV_10BIT_GAMMA_MSB_SHIFT              6
+#define CHV_GAMMA_SHIFT_GREEN                  16
+#define CHV_MAX_GAMMA                          ((1 << 24) - 1)
+
+/* CHV CGM Block */
+#define CGM_GAMMA_EN                           (1 << 2)
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#14 lore raw

PATCH v6 14/23 drm/i915: CHV: Pipe level degamma correction

In reply to Shashank Sharma

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +6 -0
index 45ddd84..1e46562 100644
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {
 #define _PIPE_GAMMA_BASE(pipe) \
 	(_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA, PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +92 -0

102 lines not on this page · raw message

drivers/gpu/drm/i915/intel_color_manager.h +5 -0
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#15 lore raw

Re: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

		while (count < CHV_DEGAMMA_MAX_VALS) {
			// Do lots of caclulation
			I915_WRITE(cgm_degamma_reg, word);

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
 	(_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA, 
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0

101 lines not on this page · raw message

drivers/gpu/drm/i915/intel_color_manager.h +5 -0
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)

--
1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#16 lore raw

Re: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

		while (count < CHV_DEGAMMA_MAX_VALS) {
			// Do lots of caclulation
			I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

-Daniel

Quoted 180 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
 	(_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA, 
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+	struct drm_property_blob *blob, struct drm_crtc *crtc) {
+	u16 red_fract, green_fract, blue_fract;
+	u32 red, green, blue;
+	u32 num_samples;
+	u32 word = 0;
+	u32 count, cgm_control_reg, cgm_degamma_reg;
+	enum pipe pipe;
+	struct drm_palette *degamma_data;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_r32g32b32 *correction_values = NULL;
+	struct drm_crtc_state *state = crtc->state;
+
+	if (WARN_ON(!blob))
+		return -EINVAL;
+
+	degamma_data = (struct drm_palette *)blob->data;
+	pipe = to_intel_crtc(crtc)->pipe;
+	num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+	switch (num_samples) {
+	case GAMMA_DISABLE_VALS:
+		/* Disable DeGamma functionality on Pipe - CGM Block */
+		cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+		cgm_control_reg &= ~CGM_DEGAMMA_EN;
+		state->palette_before_ctm_blob = NULL;
+
+		I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+		DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+				pipe_name(pipe));
+		break;
+
+	case CHV_DEGAMMA_MAX_VALS:
+		cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+		count = 0;
+		correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+		while (count < CHV_DEGAMMA_MAX_VALS) {
+			blue = correction_values[count].b32;
+			green = correction_values[count].g32;
+			red = correction_values[count].r32;
+
+			if (blue > CHV_MAX_GAMMA)
+				blue = CHV_MAX_GAMMA;
+
+			if (green > CHV_MAX_GAMMA)
+				green = CHV_MAX_GAMMA;
+
+			if (red > CHV_MAX_GAMMA)
+				red = CHV_MAX_GAMMA;
+
+			blue_fract = GET_BITS(blue, 8, 14);
+			green_fract = GET_BITS(green, 8, 14);
+			red_fract = GET_BITS(red, 8, 14);
+
+			/* Green (29:16) and Blue (13:0) in DWORD1 */
+			SET_BITS(word, green_fract, 16, 14);
+			SET_BITS(word, green_fract, 0, 14);
+			I915_WRITE(cgm_degamma_reg, word);
+			cgm_degamma_reg += 4;
+
+			/* Red (13:0) to be written to DWORD2 */
+			word = red_fract;
+			I915_WRITE(cgm_degamma_reg, word);
+			cgm_degamma_reg += 4;
+			count++;
+		}
+
+		DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+				pipe_name(pipe));
+
+		/* Enable DeGamma on Pipe */
+		I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+			I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+		DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+				pipe_name(pipe));
+		break;
+
+	default:
+		DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
 		struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
 		DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
 	}
 
+	/* Degamma correction */
+	if (config->cm_palette_before_ctm_property) {
+		drm_object_attach_property(mode_obj,
+			config->cm_palette_before_ctm_property, 0);
+		DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+	}
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#17 lore raw

Re: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

		while (count < CHV_DEGAMMA_MAX_VALS) {
			// Do lots of caclulation
			I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

Jim

Quoted 177 lines
Quoted 177 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
 	(_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA, 
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+	struct drm_property_blob *blob, struct drm_crtc *crtc) {
+	u16 red_fract, green_fract, blue_fract;
+	u32 red, green, blue;
+	u32 num_samples;
+	u32 word = 0;
+	u32 count, cgm_control_reg, cgm_degamma_reg;
+	enum pipe pipe;
+	struct drm_palette *degamma_data;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_r32g32b32 *correction_values = NULL;
+	struct drm_crtc_state *state = crtc->state;
+
+	if (WARN_ON(!blob))
+		return -EINVAL;
+
+	degamma_data = (struct drm_palette *)blob->data;
+	pipe = to_intel_crtc(crtc)->pipe;
+	num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+	switch (num_samples) {
+	case GAMMA_DISABLE_VALS:
+		/* Disable DeGamma functionality on Pipe - CGM Block */
+		cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+		cgm_control_reg &= ~CGM_DEGAMMA_EN;
+		state->palette_before_ctm_blob = NULL;
+
+		I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+		DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+				pipe_name(pipe));
+		break;
+
+	case CHV_DEGAMMA_MAX_VALS:
+		cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+		count = 0;
+		correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+		while (count < CHV_DEGAMMA_MAX_VALS) {
+			blue = correction_values[count].b32;
+			green = correction_values[count].g32;
+			red = correction_values[count].r32;
+
+			if (blue > CHV_MAX_GAMMA)
+				blue = CHV_MAX_GAMMA;
+
+			if (green > CHV_MAX_GAMMA)
+				green = CHV_MAX_GAMMA;
+
+			if (red > CHV_MAX_GAMMA)
+				red = CHV_MAX_GAMMA;
+
+			blue_fract = GET_BITS(blue, 8, 14);
+			green_fract = GET_BITS(green, 8, 14);
+			red_fract = GET_BITS(red, 8, 14);
+
+			/* Green (29:16) and Blue (13:0) in DWORD1 */
+			SET_BITS(word, green_fract, 16, 14);
+			SET_BITS(word, green_fract, 0, 14);
+			I915_WRITE(cgm_degamma_reg, word);
+			cgm_degamma_reg += 4;
+
+			/* Red (13:0) to be written to DWORD2 */
+			word = red_fract;
+			I915_WRITE(cgm_degamma_reg, word);
+			cgm_degamma_reg += 4;
+			count++;
+		}
+
+		DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+				pipe_name(pipe));
+
+		/* Enable DeGamma on Pipe */
+		I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+			I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+		DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+				pipe_name(pipe));
+		break;
+
+	default:
+		DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
 		struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
 		DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
 	}
 
+	/* Degamma correction */
+	if (config->cm_palette_before_ctm_property) {
+		drm_object_attach_property(mode_obj,
+			config->cm_palette_before_ctm_property, 0);
+		DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+	}
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Quoted 5 lines
Quoted 4 lines

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#18 lore raw

Re: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

		while (count < CHV_DEGAMMA_MAX_VALS) {
			// Do lots of caclulation
			I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world.
-Daniel

Quoted 184 lines

Jim

Quoted 182 lines
Quoted 181 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
 	(_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA, 
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+	struct drm_property_blob *blob, struct drm_crtc *crtc) {
+	u16 red_fract, green_fract, blue_fract;
+	u32 red, green, blue;
+	u32 num_samples;
+	u32 word = 0;
+	u32 count, cgm_control_reg, cgm_degamma_reg;
+	enum pipe pipe;
+	struct drm_palette *degamma_data;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_r32g32b32 *correction_values = NULL;
+	struct drm_crtc_state *state = crtc->state;
+
+	if (WARN_ON(!blob))
+		return -EINVAL;
+
+	degamma_data = (struct drm_palette *)blob->data;
+	pipe = to_intel_crtc(crtc)->pipe;
+	num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+	switch (num_samples) {
+	case GAMMA_DISABLE_VALS:
+		/* Disable DeGamma functionality on Pipe - CGM Block */
+		cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+		cgm_control_reg &= ~CGM_DEGAMMA_EN;
+		state->palette_before_ctm_blob = NULL;
+
+		I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+		DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+				pipe_name(pipe));
+		break;
+
+	case CHV_DEGAMMA_MAX_VALS:
+		cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+		count = 0;
+		correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+		while (count < CHV_DEGAMMA_MAX_VALS) {
+			blue = correction_values[count].b32;
+			green = correction_values[count].g32;
+			red = correction_values[count].r32;
+
+			if (blue > CHV_MAX_GAMMA)
+				blue = CHV_MAX_GAMMA;
+
+			if (green > CHV_MAX_GAMMA)
+				green = CHV_MAX_GAMMA;
+
+			if (red > CHV_MAX_GAMMA)
+				red = CHV_MAX_GAMMA;
+
+			blue_fract = GET_BITS(blue, 8, 14);
+			green_fract = GET_BITS(green, 8, 14);
+			red_fract = GET_BITS(red, 8, 14);
+
+			/* Green (29:16) and Blue (13:0) in DWORD1 */
+			SET_BITS(word, green_fract, 16, 14);
+			SET_BITS(word, green_fract, 0, 14);
+			I915_WRITE(cgm_degamma_reg, word);
+			cgm_degamma_reg += 4;
+
+			/* Red (13:0) to be written to DWORD2 */
+			word = red_fract;
+			I915_WRITE(cgm_degamma_reg, word);
+			cgm_degamma_reg += 4;
+			count++;
+		}
+
+		DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+				pipe_name(pipe));
+
+		/* Enable DeGamma on Pipe */
+		I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+			I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+		DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+				pipe_name(pipe));
+		break;
+
+	default:
+		DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
 		struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
 		DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
 	}
 
+	/* Degamma correction */
+	if (config->cm_palette_before_ctm_property) {
+		drm_object_attach_property(mode_obj,
+			config->cm_palette_before_ctm_property, 0);
+		DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+	}
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#19 lore raw

Re: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Bear in mind that it will only happen after the property has been set. Initially there will be no clients setting the property - so I think it should be OK.

Thanks
Gary

Daniel Vetter <[email protected]> wrote:

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

            while (count < CHV_DEGAMMA_MAX_VALS) {
                    // Do lots of caclulation
                    I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world.
-Daniel

Quoted 184 lines

Jim

Quoted 182 lines
Quoted 181 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
    (_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+  (_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA,
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+  struct drm_property_blob *blob, struct drm_crtc *crtc) {
+  u16 red_fract, green_fract, blue_fract;
+  u32 red, green, blue;
+  u32 num_samples;
+  u32 word = 0;
+  u32 count, cgm_control_reg, cgm_degamma_reg;
+  enum pipe pipe;
+  struct drm_palette *degamma_data;
+  struct drm_i915_private *dev_priv = dev->dev_private;
+  struct drm_r32g32b32 *correction_values = NULL;
+  struct drm_crtc_state *state = crtc->state;
+
+  if (WARN_ON(!blob))
+          return -EINVAL;
+
+  degamma_data = (struct drm_palette *)blob->data;
+  pipe = to_intel_crtc(crtc)->pipe;
+  num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+  switch (num_samples) {
+  case GAMMA_DISABLE_VALS:
+          /* Disable DeGamma functionality on Pipe - CGM Block */
+          cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+          cgm_control_reg &= ~CGM_DEGAMMA_EN;
+          state->palette_before_ctm_blob = NULL;
+
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+          DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  case CHV_DEGAMMA_MAX_VALS:
+          cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+          count = 0;
+          correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+          while (count < CHV_DEGAMMA_MAX_VALS) {
+                  blue = correction_values[count].b32;
+                  green = correction_values[count].g32;
+                  red = correction_values[count].r32;
+
+                  if (blue > CHV_MAX_GAMMA)
+                          blue = CHV_MAX_GAMMA;
+
+                  if (green > CHV_MAX_GAMMA)
+                          green = CHV_MAX_GAMMA;
+
+                  if (red > CHV_MAX_GAMMA)
+                          red = CHV_MAX_GAMMA;
+
+                  blue_fract = GET_BITS(blue, 8, 14);
+                  green_fract = GET_BITS(green, 8, 14);
+                  red_fract = GET_BITS(red, 8, 14);
+
+                  /* Green (29:16) and Blue (13:0) in DWORD1 */
+                  SET_BITS(word, green_fract, 16, 14);
+                  SET_BITS(word, green_fract, 0, 14);
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+
+                  /* Red (13:0) to be written to DWORD2 */
+                  word = red_fract;
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+                  count++;
+          }
+
+          DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+                          pipe_name(pipe));
+
+          /* Enable DeGamma on Pipe */
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+                  I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+          DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  default:
+          DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+          return -EINVAL;
+  }
+  return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
            struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
            DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
    }
 
+  /* Degamma correction */
+  if (config->cm_palette_before_ctm_property) {
+          drm_object_attach_property(mode_obj,
+                  config->cm_palette_before_ctm_property, 0);
+          DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+  }
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#20 lore raw

Re: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Unless legacy mode enables it of course.

Thanks
Gary

"Smith, Gary K" <[email protected]> wrote:

Bear in mind that it will only happen after the property has been set. Initially there will be no clients setting the property - so I think it should be OK.

Thanks
Gary

Daniel Vetter <[email protected]> wrote:

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

            while (count < CHV_DEGAMMA_MAX_VALS) {
                    // Do lots of caclulation
                    I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world.
-Daniel

Quoted 184 lines

Jim

Quoted 182 lines
Quoted 181 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
    (_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+  (_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA,
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+  struct drm_property_blob *blob, struct drm_crtc *crtc) {
+  u16 red_fract, green_fract, blue_fract;
+  u32 red, green, blue;
+  u32 num_samples;
+  u32 word = 0;
+  u32 count, cgm_control_reg, cgm_degamma_reg;
+  enum pipe pipe;
+  struct drm_palette *degamma_data;
+  struct drm_i915_private *dev_priv = dev->dev_private;
+  struct drm_r32g32b32 *correction_values = NULL;
+  struct drm_crtc_state *state = crtc->state;
+
+  if (WARN_ON(!blob))
+          return -EINVAL;
+
+  degamma_data = (struct drm_palette *)blob->data;
+  pipe = to_intel_crtc(crtc)->pipe;
+  num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+  switch (num_samples) {
+  case GAMMA_DISABLE_VALS:
+          /* Disable DeGamma functionality on Pipe - CGM Block */
+          cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+          cgm_control_reg &= ~CGM_DEGAMMA_EN;
+          state->palette_before_ctm_blob = NULL;
+
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+          DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  case CHV_DEGAMMA_MAX_VALS:
+          cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+          count = 0;
+          correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+          while (count < CHV_DEGAMMA_MAX_VALS) {
+                  blue = correction_values[count].b32;
+                  green = correction_values[count].g32;
+                  red = correction_values[count].r32;
+
+                  if (blue > CHV_MAX_GAMMA)
+                          blue = CHV_MAX_GAMMA;
+
+                  if (green > CHV_MAX_GAMMA)
+                          green = CHV_MAX_GAMMA;
+
+                  if (red > CHV_MAX_GAMMA)
+                          red = CHV_MAX_GAMMA;
+
+                  blue_fract = GET_BITS(blue, 8, 14);
+                  green_fract = GET_BITS(green, 8, 14);
+                  red_fract = GET_BITS(red, 8, 14);
+
+                  /* Green (29:16) and Blue (13:0) in DWORD1 */
+                  SET_BITS(word, green_fract, 16, 14);
+                  SET_BITS(word, green_fract, 0, 14);
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+
+                  /* Red (13:0) to be written to DWORD2 */
+                  word = red_fract;
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+                  count++;
+          }
+
+          DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+                          pipe_name(pipe));
+
+          /* Enable DeGamma on Pipe */
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+                  I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+          DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  default:
+          DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+          return -EINVAL;
+  }
+  return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
            struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
            DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
    }
 
+  /* Degamma correction */
+  if (config->cm_palette_before_ctm_property) {
+          drm_object_attach_property(mode_obj,
+                  config->cm_palette_before_ctm_property, 0);
+          DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+  }
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#21 lore raw

RE: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Daniel?

Annie Matheson
Intel Corporation
Phone: (503) 712-0586
Email: [email protected]<mailto:[email protected]>

From: Smith, Gary K
Sent: Monday, October 19, 2015 3:27 PM
To: Daniel Vetter
Cc: Bish, Jim; Sharma, Shashank; [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Matheson, Annie J; [email protected]; Vetter, Daniel
Subject: Re: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Unless legacy mode enables it of course.

Thanks
Gary

"Smith, Gary K" <[email protected]<mailto:[email protected]>> wrote:
Bear in mind that it will only happen after the property has been set. Initially there will be no clients setting the property - so I think it should be OK.

Thanks
Gary

Daniel Vetter <[email protected]<mailto:[email protected]>> wrote:

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

            while (count < CHV_DEGAMMA_MAX_VALS) {
                    // Do lots of caclulation
                    I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world.
-Daniel

Quoted 184 lines

Jim

Quoted 182 lines
Quoted 181 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]<mailto:[email protected]>; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
    (_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+  (_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA,
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+  struct drm_property_blob *blob, struct drm_crtc *crtc) {
+  u16 red_fract, green_fract, blue_fract;
+  u32 red, green, blue;
+  u32 num_samples;
+  u32 word = 0;
+  u32 count, cgm_control_reg, cgm_degamma_reg;
+  enum pipe pipe;
+  struct drm_palette *degamma_data;
+  struct drm_i915_private *dev_priv = dev->dev_private;
+  struct drm_r32g32b32 *correction_values = NULL;
+  struct drm_crtc_state *state = crtc->state;
+
+  if (WARN_ON(!blob))
+          return -EINVAL;
+
+  degamma_data = (struct drm_palette *)blob->data;
+  pipe = to_intel_crtc(crtc)->pipe;
+  num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+  switch (num_samples) {
+  case GAMMA_DISABLE_VALS:
+          /* Disable DeGamma functionality on Pipe - CGM Block */
+          cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+          cgm_control_reg &= ~CGM_DEGAMMA_EN;
+          state->palette_before_ctm_blob = NULL;
+
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+          DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  case CHV_DEGAMMA_MAX_VALS:
+          cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+          count = 0;
+          correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+          while (count < CHV_DEGAMMA_MAX_VALS) {
+                  blue = correction_values[count].b32;
+                  green = correction_values[count].g32;
+                  red = correction_values[count].r32;
+
+                  if (blue > CHV_MAX_GAMMA)
+                          blue = CHV_MAX_GAMMA;
+
+                  if (green > CHV_MAX_GAMMA)
+                          green = CHV_MAX_GAMMA;
+
+                  if (red > CHV_MAX_GAMMA)
+                          red = CHV_MAX_GAMMA;
+
+                  blue_fract = GET_BITS(blue, 8, 14);
+                  green_fract = GET_BITS(green, 8, 14);
+                  red_fract = GET_BITS(red, 8, 14);
+
+                  /* Green (29:16) and Blue (13:0) in DWORD1 */
+                  SET_BITS(word, green_fract, 16, 14);
+                  SET_BITS(word, green_fract, 0, 14);
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+
+                  /* Red (13:0) to be written to DWORD2 */
+                  word = red_fract;
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+                  count++;
+          }
+
+          DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+                          pipe_name(pipe));
+
+          /* Enable DeGamma on Pipe */
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+                  I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+          DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  default:
+          DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+          return -EINVAL;
+  }
+  return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
            struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
            DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
    }
 
+  /* Degamma correction */
+  if (config->cm_palette_before_ctm_property) {
+          drm_object_attach_property(mode_obj,
+                  config->cm_palette_before_ctm_property, 0);
+          DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+  }
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list [email protected]<mailto:[email protected]>
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#22 lore raw

RE: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Sounds like a good suggestion to me, it would be efficient to do so.
By the time we discus on this, I would see a possibility of adding one patch on top of the series, with this optimization.

Regards
Shashank
From: Matheson, Annie J
Sent: Tuesday, October 20, 2015 5:18 AM
To: Smith, Gary K; Daniel Vetter
Cc: Bish, Jim; Sharma, Shashank; [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; [email protected]; Vetter, Daniel; Gilliam, Amy
Subject: RE: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Daniel?

Annie Matheson
Intel Corporation
Phone: (503) 712-0586
Email: [email protected]<mailto:[email protected]>

From: Smith, Gary K
Sent: Monday, October 19, 2015 3:27 PM
To: Daniel Vetter
Cc: Bish, Jim; Sharma, Shashank; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; Roper, Matthew D; Bradford, Robert; Matheson, Annie J; [email protected]<mailto:[email protected]>; Vetter, Daniel
Subject: Re: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Unless legacy mode enables it of course.

Thanks
Gary

"Smith, Gary K" <[email protected]<mailto:[email protected]>> wrote:
Bear in mind that it will only happen after the property has been set. Initially there will be no clients setting the property - so I think it should be OK.

Thanks
Gary

Daniel Vetter <[email protected]<mailto:[email protected]>> wrote:

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

            while (count < CHV_DEGAMMA_MAX_VALS) {
                    // Do lots of caclulation
                    I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world.
-Daniel

Quoted 184 lines

Jim

Quoted 182 lines
Quoted 181 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; [email protected]<mailto:[email protected]>; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]<mailto:[email protected]>; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
    (_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+  (_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA,
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+  struct drm_property_blob *blob, struct drm_crtc *crtc) {
+  u16 red_fract, green_fract, blue_fract;
+  u32 red, green, blue;
+  u32 num_samples;
+  u32 word = 0;
+  u32 count, cgm_control_reg, cgm_degamma_reg;
+  enum pipe pipe;
+  struct drm_palette *degamma_data;
+  struct drm_i915_private *dev_priv = dev->dev_private;
+  struct drm_r32g32b32 *correction_values = NULL;
+  struct drm_crtc_state *state = crtc->state;
+
+  if (WARN_ON(!blob))
+          return -EINVAL;
+
+  degamma_data = (struct drm_palette *)blob->data;
+  pipe = to_intel_crtc(crtc)->pipe;
+  num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+  switch (num_samples) {
+  case GAMMA_DISABLE_VALS:
+          /* Disable DeGamma functionality on Pipe - CGM Block */
+          cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+          cgm_control_reg &= ~CGM_DEGAMMA_EN;
+          state->palette_before_ctm_blob = NULL;
+
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+          DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  case CHV_DEGAMMA_MAX_VALS:
+          cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+          count = 0;
+          correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+          while (count < CHV_DEGAMMA_MAX_VALS) {
+                  blue = correction_values[count].b32;
+                  green = correction_values[count].g32;
+                  red = correction_values[count].r32;
+
+                  if (blue > CHV_MAX_GAMMA)
+                          blue = CHV_MAX_GAMMA;
+
+                  if (green > CHV_MAX_GAMMA)
+                          green = CHV_MAX_GAMMA;
+
+                  if (red > CHV_MAX_GAMMA)
+                          red = CHV_MAX_GAMMA;
+
+                  blue_fract = GET_BITS(blue, 8, 14);
+                  green_fract = GET_BITS(green, 8, 14);
+                  red_fract = GET_BITS(red, 8, 14);
+
+                  /* Green (29:16) and Blue (13:0) in DWORD1 */
+                  SET_BITS(word, green_fract, 16, 14);
+                  SET_BITS(word, green_fract, 0, 14);
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+
+                  /* Red (13:0) to be written to DWORD2 */
+                  word = red_fract;
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+                  count++;
+          }
+
+          DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+                          pipe_name(pipe));
+
+          /* Enable DeGamma on Pipe */
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+                  I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+          DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  default:
+          DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+          return -EINVAL;
+  }
+  return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
            struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
            DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
    }
 
+  /* Degamma correction */
+  if (config->cm_palette_before_ctm_property) {
+          drm_object_attach_property(mode_obj,
+                  config->cm_palette_before_ctm_property, 0);
+          DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+  }
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list [email protected]<mailto:[email protected]>
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#23 lore raw

Re: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

In reply to Smith, Gary K
Quoted 1 line · Gary K

Unless legacy mode enables it of course.

I thought we decided to ignore legacy gamma stuff (at least for now, until someone complains about the inconsistency). So yeah, I think we're fine. -Daniel

Quoted 253 lines

Thanks
Gary

"Smith, Gary K" <[email protected]> wrote:

Bear in mind that it will only happen after the property has been set. Initially there will be no clients setting the property - so I think it should be OK.

Thanks
Gary

Daniel Vetter <[email protected]> wrote:

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

            while (count < CHV_DEGAMMA_MAX_VALS) {
                    // Do lots of caclulation
                    I915_WRITE(cgm_degamma_reg, word);
Quoted 6 lines

Every frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where we need to commit the update. That /should/ be there really, didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world.
-Daniel

Quoted 184 lines

Jim

Quoted 182 lines
Quoted 181 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC
2. Add the core function to program DeGamma correction values for CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 ++++++++++++++++++++++++++++++  drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
    (_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+  (_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA,
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +91 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+  struct drm_property_blob *blob, struct drm_crtc *crtc) {
+  u16 red_fract, green_fract, blue_fract;
+  u32 red, green, blue;
+  u32 num_samples;
+  u32 word = 0;
+  u32 count, cgm_control_reg, cgm_degamma_reg;
+  enum pipe pipe;
+  struct drm_palette *degamma_data;
+  struct drm_i915_private *dev_priv = dev->dev_private;
+  struct drm_r32g32b32 *correction_values = NULL;
+  struct drm_crtc_state *state = crtc->state;
+
+  if (WARN_ON(!blob))
+          return -EINVAL;
+
+  degamma_data = (struct drm_palette *)blob->data;
+  pipe = to_intel_crtc(crtc)->pipe;
+  num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+  switch (num_samples) {
+  case GAMMA_DISABLE_VALS:
+          /* Disable DeGamma functionality on Pipe - CGM Block */
+          cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+          cgm_control_reg &= ~CGM_DEGAMMA_EN;
+          state->palette_before_ctm_blob = NULL;
+
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+          DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  case CHV_DEGAMMA_MAX_VALS:
+          cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+          count = 0;
+          correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+          while (count < CHV_DEGAMMA_MAX_VALS) {
+                  blue = correction_values[count].b32;
+                  green = correction_values[count].g32;
+                  red = correction_values[count].r32;
+
+                  if (blue > CHV_MAX_GAMMA)
+                          blue = CHV_MAX_GAMMA;
+
+                  if (green > CHV_MAX_GAMMA)
+                          green = CHV_MAX_GAMMA;
+
+                  if (red > CHV_MAX_GAMMA)
+                          red = CHV_MAX_GAMMA;
+
+                  blue_fract = GET_BITS(blue, 8, 14);
+                  green_fract = GET_BITS(green, 8, 14);
+                  red_fract = GET_BITS(red, 8, 14);
+
+                  /* Green (29:16) and Blue (13:0) in DWORD1 */
+                  SET_BITS(word, green_fract, 16, 14);
+                  SET_BITS(word, green_fract, 0, 14);
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+
+                  /* Red (13:0) to be written to DWORD2 */
+                  word = red_fract;
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+                  count++;
+          }
+
+          DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+                          pipe_name(pipe));
+
+          /* Enable DeGamma on Pipe */
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+                  I915_READ(_PIPE_CGM_CONTROL(pipe)) | CGM_DEGAMMA_EN);
+
+          DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  default:
+          DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+          return -EINVAL;
+  }
+  return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
            struct drm_crtc *crtc)
 {
@@ -155,4 +241,10 @@ void intel_attach_color_properties_to_crtc(struct drm_device *dev,
            DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
    }
 
+  /* Degamma correction */
+  if (config->cm_palette_before_ctm_property) {
+          drm_object_attach_property(mode_obj,
+                  config->cm_palette_before_ctm_property, 0);
+          DRM_DEBUG_DRIVER("degamma property attached to CRTC\n");
+  }
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ
VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#24 lore raw

RE: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Yes, please note that as per the discussion, the legacy gamma IOCTL is still existing, to maintain the backward compatibility, we have not broken it. And we have added provision to program legacy-8bit gamma via color manager also, so everyone should be happy :)

Regards
Shashank
-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Tuesday, October 20, 2015 12:58 PM
To: Smith, Gary K
Cc: Daniel Vetter; Bish, Jim; Sharma, Shashank; [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Matheson, Annie J; [email protected]; Vetter, Daniel
Subject: Re: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Quoted 1 line · Gary K

Unless legacy mode enables it of course.

I thought we decided to ignore legacy gamma stuff (at least for now, until someone complains about the inconsistency). So yeah, I think we're fine. -Daniel

Quoted 259 lines

Thanks
Gary

"Smith, Gary K" <[email protected]> wrote:

Bear in mind that it will only happen after the property has been set. Initially there will be no clients setting the property - so I think it should be OK.

Thanks
Gary

Daniel Vetter <[email protected]> wrote:

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

            while (count < CHV_DEGAMMA_MAX_VALS) {
                    // Do lots of caclulation
                    I915_WRITE(cgm_degamma_reg, word); Every 
Quoted 6 lines

frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where
we need to commit the update. That /should/ be there really,
didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world. -Daniel

Quoted 196 lines

Jim

Quoted 194 lines
Quoted 193 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC 2. Add the core function to program DeGamma correction values for
CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92 
++++++++++++++++++++++++++++++  
drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 45ddd84..1e46562 100644

drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
    (_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA, 
 PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+  (_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA,
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +86 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+  struct drm_property_blob *blob, struct drm_crtc *crtc) {
+  u16 red_fract, green_fract, blue_fract;
+  u32 red, green, blue;
+  u32 num_samples;
+  u32 word = 0;
+  u32 count, cgm_control_reg, cgm_degamma_reg;
+  enum pipe pipe;
+  struct drm_palette *degamma_data;
+  struct drm_i915_private *dev_priv = dev->dev_private;
+  struct drm_r32g32b32 *correction_values = NULL;
+  struct drm_crtc_state *state = crtc->state;
+
+  if (WARN_ON(!blob))
+          return -EINVAL;
+
+  degamma_data = (struct drm_palette *)blob->data;  pipe = 
+ to_intel_crtc(crtc)->pipe;  num_samples = blob->length / 
+ sizeof(struct drm_r32g32b32);
+
+  switch (num_samples) {
+  case GAMMA_DISABLE_VALS:
+          /* Disable DeGamma functionality on Pipe - CGM Block */
+          cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+          cgm_control_reg &= ~CGM_DEGAMMA_EN;
+          state->palette_before_ctm_blob = NULL;
+
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+          DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  case CHV_DEGAMMA_MAX_VALS:
+          cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+          count = 0;
+          correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+          while (count < CHV_DEGAMMA_MAX_VALS) {
+                  blue = correction_values[count].b32;
+                  green = correction_values[count].g32;
+                  red = correction_values[count].r32;
+
+                  if (blue > CHV_MAX_GAMMA)
+                          blue = CHV_MAX_GAMMA;
+
+                  if (green > CHV_MAX_GAMMA)
+                          green = CHV_MAX_GAMMA;
+
+                  if (red > CHV_MAX_GAMMA)
+                          red = CHV_MAX_GAMMA;
+
+                  blue_fract = GET_BITS(blue, 8, 14);
+                  green_fract = GET_BITS(green, 8, 14);
+                  red_fract = GET_BITS(red, 8, 14);
+
+                  /* Green (29:16) and Blue (13:0) in DWORD1 */
+                  SET_BITS(word, green_fract, 16, 14);
+                  SET_BITS(word, green_fract, 0, 14);
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+
+                  /* Red (13:0) to be written to DWORD2 */
+                  word = red_fract;
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+                  count++;
+          }
+
+          DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+                          pipe_name(pipe));
+
+          /* Enable DeGamma on Pipe */
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+                  I915_READ(_PIPE_CGM_CONTROL(pipe)) | 
+ CGM_DEGAMMA_EN);
+
+          DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  default:
+          DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+          return -EINVAL;
+  }
+  return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
            struct drm_crtc *crtc)  { @@ -155,4 +241,10 @@ void 
 intel_attach_color_properties_to_crtc(struct drm_device *dev,
            DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
    }
drivers/gpu/drm/i915/intel_color_manager.c +6 -0
+  /* Degamma correction */
+  if (config->cm_palette_before_ctm_property) {
+          drm_object_attach_property(mode_obj,
+                  config->cm_palette_before_ctm_property, 0);
+          DRM_DEBUG_DRIVER("degamma property attached to 
+ CRTC\n");  }
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

-----------------------------------------------------------------
----
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47

Quoted 5 lines

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#25 lore raw

RE: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

In reply to Daniel Vetter

We have added two patches to optimize multiple commit calls, to address Gary's comment, using one additional flag in CRTC state. We have tested this, and it's working for both Android and Linux.

I am sending this new patch set now (v7), which has these two additional patches, in total 25 in count. Please have a look.

Regards
Shashank
-----Original Message-----
From: Sharma, Shashank
Sent: Tuesday, October 20, 2015 1:46 PM
To: 'Daniel Vetter'; Smith, Gary K
Cc: Bish, Jim; [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Matheson, Annie J; [email protected]; Vetter, Daniel
Subject: RE: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Yes, please note that as per the discussion, the legacy gamma IOCTL is still existing, to maintain the backward compatibility, we have not broken it. And we have added provision to program legacy-8bit gamma via color manager also, so everyone should be happy :)

Regards
Shashank
-----Original Message-----
From: Daniel Vetter [mailto:[email protected]] On Behalf Of Daniel Vetter
Sent: Tuesday, October 20, 2015 12:58 PM
To: Smith, Gary K
Cc: Daniel Vetter; Bish, Jim; Sharma, Shashank; [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Matheson, Annie J; [email protected]; Vetter, Daniel
Subject: Re: [Intel-gfx] [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

Quoted 1 line · Gary K

Unless legacy mode enables it of course.

I thought we decided to ignore legacy gamma stuff (at least for now, until someone complains about the inconsistency). So yeah, I think we're fine. -Daniel

Quoted 259 lines

Thanks
Gary

"Smith, Gary K" <[email protected]> wrote:

Bear in mind that it will only happen after the property has been set. Initially there will be no clients setting the property - so I think it should be OK.

Thanks
Gary

Daniel Vetter <[email protected]> wrote:

Quoted 25 lines · Jim
Quoted 22 lines · Daniel Vetter
Quoted 6 lines · Gary K

FYI - this shouldn't block the commits, but should be optimized later (fairly soon).

I believe the current implementation ends up executing

            while (count < CHV_DEGAMMA_MAX_VALS) {
                    // Do lots of caclulation
                    I915_WRITE(cgm_degamma_reg, word); Every 
Quoted 6 lines

frame after you set the property, whether you change the contents of the blob or not. Clearly this is really inefficient when there are 100s of gamma values to write. Same with the Gamma and CTM. CTM is less of an issue with only 9 entries.

My suggestion here is to set a boolean when the property has been set as part of a flip and only apply it on the atomic commit after the update was received.

Yeah the usual design is to add a foo_changed boolean (or bitmask, e.g. for changed planes tracked in the crtc_state) in the state where
we need to commit the update. That /should/ be there really,
didn't ever realize it's not done. Note that that for legacy cursors we update them without waiting for vblanks and legacy userspace does that a _lot_ (*cough* X server *cough*), if the overhead is severe this might be a problem and needs to be fixed before merging.

Quoted 3 lines
Quoted 1 line

-Daniel

Severe enough to block? I wanted to get this closed out this week but... I see your point Gary but need a reading on Daniel's last sentence.

X server doing silly amounts of setcursor calls is a known issue that has bitten us in the past (with people complaining about seriously sluggish desktops). Just needs to be tested, and depending upon results either fixed before or after merging. I hope we can get away with fixing up post-merge. But writing a few kb through mmio for each cursor is a lot, so it might show up in real world. -Daniel

Quoted 196 lines

Jim

Quoted 194 lines
Quoted 193 lines

Thanks
Gary

-----Original Message-----
From: Sharma, Shashank
Sent: Friday, October 16, 2015 3:29 PM
To: [email protected]; [email protected]; [email protected]; Roper, Matthew D; Bradford, Robert; Bish, Jim
Cc: Matheson, Annie J; [email protected]; Kumar, Kiran S; Smith, Gary K; Vetter, Daniel; Mukherjee, Indranil; Palleti, Avinash Reddy; Sharma, Shashank
Subject: [PATCH v6 14/23] drm/i915: CHV: Pipe level degamma correction

CHV/BSW supports Degamma color correction, which linearizes all the non-linear color values. This will be applied before Color Transformation.

This patch does the following:
1. Attach deGamma property to CRTC 2. Add the core function to program DeGamma correction values for
CHV/BSW platform
2. Add DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  6 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 92
++++++++++++++++++++++++++++++  
drivers/gpu/drm/i915/intel_color_manager.h |  5 ++
 3 files changed, 103 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/i915/i915_reg.h index 45ddd84..1e46562 100644

drivers/gpu/drm/i915/i915_reg.h +7 -0
@@ -8160,4 +8160,10 @@ enum skl_disp_power_wells {  #define _PIPE_GAMMA_BASE(pipe) \
    (_PIPE3(pipe, PIPEA_CGM_GAMMA, PIPEB_CGM_GAMMA,
 PIPEC_CGM_GAMMA))
 
+#define PIPEA_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x66000)
+#define PIPEB_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x68000)
+#define PIPEC_CGM_DEGAMMA                      (VLV_DISPLAY_BASE + 0x6A000)
+#define _PIPE_DEGAMMA_BASE(pipe) \
+  (_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA,
+PIPEC_CGM_DEGAMMA))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +86 -0
index acb9647..1bbad79 100644
@@ -27,6 +27,92 @@
 
 #include "intel_color_manager.h"
 
+static int chv_set_degamma(struct drm_device *dev,
+  struct drm_property_blob *blob, struct drm_crtc *crtc) {
+  u16 red_fract, green_fract, blue_fract;
+  u32 red, green, blue;
+  u32 num_samples;
+  u32 word = 0;
+  u32 count, cgm_control_reg, cgm_degamma_reg;
+  enum pipe pipe;
+  struct drm_palette *degamma_data;
+  struct drm_i915_private *dev_priv = dev->dev_private;
+  struct drm_r32g32b32 *correction_values = NULL;
+  struct drm_crtc_state *state = crtc->state;
+
+  if (WARN_ON(!blob))
+          return -EINVAL;
+
+  degamma_data = (struct drm_palette *)blob->data;  pipe = 
+ to_intel_crtc(crtc)->pipe;  num_samples = blob->length / 
+ sizeof(struct drm_r32g32b32);
+
+  switch (num_samples) {
+  case GAMMA_DISABLE_VALS:
+          /* Disable DeGamma functionality on Pipe - CGM Block */
+          cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
+          cgm_control_reg &= ~CGM_DEGAMMA_EN;
+          state->palette_before_ctm_blob = NULL;
+
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg);
+          DRM_DEBUG_DRIVER("DeGamma disabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  case CHV_DEGAMMA_MAX_VALS:
+          cgm_degamma_reg = _PIPE_DEGAMMA_BASE(pipe);
+          count = 0;
+          correction_values = (struct drm_r32g32b32 *)&degamma_data->lut;
+          while (count < CHV_DEGAMMA_MAX_VALS) {
+                  blue = correction_values[count].b32;
+                  green = correction_values[count].g32;
+                  red = correction_values[count].r32;
+
+                  if (blue > CHV_MAX_GAMMA)
+                          blue = CHV_MAX_GAMMA;
+
+                  if (green > CHV_MAX_GAMMA)
+                          green = CHV_MAX_GAMMA;
+
+                  if (red > CHV_MAX_GAMMA)
+                          red = CHV_MAX_GAMMA;
+
+                  blue_fract = GET_BITS(blue, 8, 14);
+                  green_fract = GET_BITS(green, 8, 14);
+                  red_fract = GET_BITS(red, 8, 14);
+
+                  /* Green (29:16) and Blue (13:0) in DWORD1 */
+                  SET_BITS(word, green_fract, 16, 14);
+                  SET_BITS(word, green_fract, 0, 14);
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+
+                  /* Red (13:0) to be written to DWORD2 */
+                  word = red_fract;
+                  I915_WRITE(cgm_degamma_reg, word);
+                  cgm_degamma_reg += 4;
+                  count++;
+          }
+
+          DRM_DEBUG_DRIVER("DeGamma LUT loaded for Pipe %c\n",
+                          pipe_name(pipe));
+
+          /* Enable DeGamma on Pipe */
+          I915_WRITE(_PIPE_CGM_CONTROL(pipe),
+                  I915_READ(_PIPE_CGM_CONTROL(pipe)) | 
+ CGM_DEGAMMA_EN);
+
+          DRM_DEBUG_DRIVER("DeGamma correction enabled on Pipe %c\n",
+                          pipe_name(pipe));
+          break;
+
+  default:
+          DRM_ERROR("Invalid number of samples for DeGamma LUT\n");
+          return -EINVAL;
+  }
+  return 0;
+}
+
 static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
            struct drm_crtc *crtc)  { @@ -155,4 +241,10 @@ void 
 intel_attach_color_properties_to_crtc(struct drm_device *dev,
            DRM_DEBUG_DRIVER("gamma property attached to CRTC\n");
    }
drivers/gpu/drm/i915/intel_color_manager.c +6 -0
+  /* Degamma correction */
+  if (config->cm_palette_before_ctm_property) {
+          drm_object_attach_property(mode_obj,
+                  config->cm_palette_before_ctm_property, 0);
+          DRM_DEBUG_DRIVER("degamma property attached to 
+ CRTC\n");  }
 }
drivers/gpu/drm/i915/intel_color_manager.h +5 -1
index de706d9..77a2119 100644
@@ -63,5 +63,10 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/* Degamma on CHV */
+#define CHV_DEGAMMA_MSB_SHIFT                  2
+#define CHV_DEGAMMA_GREEN_SHIFT                16
+
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_DEGAMMA_EN                         (1 << 0)
--

1.9.1

-----------------------------------------------------------------
----
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
---------------------------------------------------------------------
Intel Corporation (UK) Limited
Registered No. 1134945 (England)
Registered Office: Pipers Way, Swindon SN3 1RJ VAT No: 860 2173 47

Quoted 5 lines

This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.

--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#26 lore raw

PATCH v6 15/23 drm/i915: CHV: Pipe level CSC correction

In reply to Shashank Sharma

CHV/BSW supports Color Space Conversion (CSC) using a 3x3 matrix that needs to be programmed into CGM (Color Gamut Mapping) registers.

This patch does the following:
1. Attaches CSC property to CRTC
2. Adds the core function to program CSC correction values
3. Adds CSC correction macros

---
 drivers/gpu/drm/i915/i915_reg.h            |  8 +++
 drivers/gpu/drm/i915/intel_color_manager.c | 99 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_color_manager.h | 19 ++++++
 3 files changed, 126 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +8 -0
index 1e46562..3db42f4 100644
@@ -8166,4 +8166,12 @@ enum skl_disp_power_wells {
 #define _PIPE_DEGAMMA_BASE(pipe) \
 	(_PIPE3(pipe, PIPEA_CGM_DEGAMMA, PIPEB_CGM_DEGAMMA, PIPEC_CGM_DEGAMMA))
 
+#define PIPEA_CGM_CSC				(VLV_DISPLAY_BASE + 0x67900)
+#define PIPEB_CGM_CSC				(VLV_DISPLAY_BASE + 0x69900)
+#define PIPEC_CGM_CSC				(VLV_DISPLAY_BASE + 0x6B900)
+#define _PIPE_CSC_BASE(pipe) \
+	(_PIPE3(pipe, PIPEA_CGM_CSC, PIPEB_CGM_CSC, PIPEC_CGM_CSC))
+
+
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +99 -0

109 lines not on this page · raw message

drivers/gpu/drm/i915/intel_color_manager.h +19 -0
index 77a2119..7b96512 100644
@@ -63,10 +63,29 @@
 #define CHV_GAMMA_SHIFT_GREEN                  16
 #define CHV_MAX_GAMMA                          ((1 << 24) - 1)
 
+/*
+ * CSC on CHV
+ * Fractional part is 32 bit, and we need only 12 MSBs for programming
+ * into registers. ROUNDOFF is required to minimize loss of precision.
+ */
+#define CHV_CSC_FRACT_ROUNDOFF                 (1 << 19)
+/*
+ * CSC values are 64-bit values. For CHV, the maximum CSC value that
+ * user can program is 7.99999..., which can be represented in fixed point
+ * S31.32 format like this, with all fractional bits as 1
+ */
+#define CHV_CSC_COEFF_MAX                      0x00000007FFFFFFFF
+#define CHV_CSC_COEFF_SHIFT                    32
+#define CHV_CSC_COEFF_INT_SHIFT                28
+#define CSC_COEFF_SIGN                         (1 << 31)
+#define CHV_CSC_COEFF_FRACT_SHIFT              4
+#define CSC_MAX_VALS                           9
+
 /* Degamma on CHV */
 #define CHV_DEGAMMA_MSB_SHIFT                  2
 #define CHV_DEGAMMA_GREEN_SHIFT                16
 
 /* CHV CGM Block */
 #define CGM_GAMMA_EN                           (1 << 2)
+#define CGM_CSC_EN                             (1 << 1)
 #define CGM_DEGAMMA_EN                         (1 << 0)
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#27 lore raw

PATCH v6 16/23 drm/i915: Commit color correction to CRTC

In reply to Shashank Sharma

The color correction blob values are loaded during set_property calls. This patch adds a function to find the blob and apply the correction values to the display registers, during the atomic commit call.

---
 drivers/gpu/drm/i915/intel_color_manager.c | 44 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_display.c       |  2 ++
 drivers/gpu/drm/i915/intel_drv.h           |  2 ++
 3 files changed, 48 insertions(+)
drivers/gpu/drm/i915/intel_color_manager.c +44 -0
index 6661c53..6b59531 100644
@@ -291,6 +291,50 @@ static int chv_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
 	}
 }
 
+void intel_color_manager_crtc_commit(struct drm_device *dev,
+		struct drm_crtc_state *crtc_state)
+{
+	struct drm_property_blob *blob;
+	struct drm_crtc *crtc = crtc_state->crtc;
+	int ret = -EINVAL;
+
+	blob = crtc_state->palette_after_ctm_blob;
+	if (blob) {
+		/* Gamma correction is platform specific */
+		if (IS_CHERRYVIEW(dev))
+			ret = chv_set_gamma(dev, blob, crtc);
+
+		if (ret)
+			DRM_ERROR("set Gamma correction failed\n");
+		else
+			DRM_DEBUG_DRIVER("Gamma correction success\n");
+	}
+
+	blob = crtc_state->palette_before_ctm_blob;
+	if (blob) {
+		/* Degamma correction */
+		if (IS_CHERRYVIEW(dev))
+			ret = chv_set_degamma(dev, blob, crtc);
+
+		if (ret)
+			DRM_ERROR("set degamma correction failed\n");
+		else
+			DRM_DEBUG_DRIVER("degamma correction success\n");
+	}
+
+	blob = crtc_state->ctm_blob;
+	if (blob) {
+		/* CSC correction */
+		if (IS_CHERRYVIEW(dev))
+			ret = chv_set_csc(dev, blob, crtc);
+
+		if (ret)
+			DRM_ERROR("set CSC correction failed\n");
+		else
+			DRM_DEBUG_DRIVER("CSC correction success\n");
+	}
+}
+
 void intel_attach_color_properties_to_crtc(struct drm_device *dev,
 		struct drm_crtc *crtc)
 {
drivers/gpu/drm/i915/intel_display.c +2 -0
index 7cad341..f94ed6d 100644
@@ -13530,6 +13530,8 @@ static void intel_begin_crtc_commit(struct drm_crtc *crtc,
 		intel_update_pipe_config(intel_crtc, old_intel_state);
 	else if (INTEL_INFO(dev)->gen >= 9)
 		skl_detach_scalers(intel_crtc);
+
+	intel_color_manager_crtc_commit(dev, crtc->state);
 }
 
 static void intel_finish_crtc_commit(struct drm_crtc *crtc,
drivers/gpu/drm/i915/intel_drv.h +2 -0
index 2e4e97d..4b24496 100644
@@ -1480,4 +1480,6 @@ extern const struct drm_plane_helper_funcs intel_plane_helper_funcs;
 /* intel_color_manager.c */
 void intel_attach_color_properties_to_crtc(struct drm_device *dev,
 	struct drm_crtc *crtc);
+void intel_color_manager_crtc_commit(struct drm_device *dev,
+	struct drm_crtc_state *crtc_state);
 #endif /* __INTEL_DRV_H__ */
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#28 lore raw

PATCH v6 17/23 drm/i915: Attach color properties to CRTC

In reply to Shashank Sharma

Function intel_attach_color_properties_to_crtc attaches a color property to its CRTC object. This patch calls this function from crtc initialization sequence.

---
 drivers/gpu/drm/i915/intel_display.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/intel_display.c +1 -0
index f94ed6d..61562a3 100644
@@ -13861,6 +13861,7 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
 	intel_crtc->cursor_size = ~0;
 
 	intel_crtc->wm.cxsr_allowed = true;
+	intel_attach_color_properties_to_crtc(dev, &intel_crtc->base);
 
 	BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
 	       dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#29 lore raw

PATCH v6 18/23 drm/i915: BDW: Load gamma correction values

In reply to Shashank Sharma

I915 color manager registers pipe gamma correction as palette correction after CTM property.

For BDW and higher platforms, split gamma correction is the best gamma correction. This patch adds the no of coefficients(512) for split gamma correction as "num_samples_after_ctm" parameter in device info structures, for all of those.

---
 drivers/gpu/drm/i915/i915_drv.c            | 7 +++++++
 drivers/gpu/drm/i915/intel_color_manager.h | 3 +++
 2 files changed, 10 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +7 -0
index 6adf002..8beac5c 100644
@@ -302,6 +302,7 @@ static const struct intel_device_info intel_broadwell_d_info = {
 	.gen = 8, .num_pipes = 3,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
+	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -314,6 +315,7 @@ static const struct intel_device_info intel_broadwell_m_info = {
 	.gen = 8, .is_mobile = 1, .num_pipes = 3,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
+	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -326,6 +328,7 @@ static const struct intel_device_info intel_broadwell_gt3d_info = {
 	.gen = 8, .num_pipes = 3,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
+	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -338,6 +341,7 @@ static const struct intel_device_info intel_broadwell_gt3m_info = {
 	.gen = 8, .is_mobile = 1, .num_pipes = 3,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
+	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -363,6 +367,7 @@ static const struct intel_device_info intel_skylake_info = {
 	.gen = 9, .num_pipes = 3,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
+	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -376,6 +381,7 @@ static const struct intel_device_info intel_skylake_gt3_info = {
 	.gen = 9, .num_pipes = 3,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
+	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -389,6 +395,7 @@ static const struct intel_device_info intel_broxton_info = {
 	.gen = 9,
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
+	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
 	.num_pipes = 3,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
drivers/gpu/drm/i915/intel_color_manager.h +3 -0
index 7b96512..271246a 100644
@@ -89,3 +89,6 @@
 #define CGM_GAMMA_EN                           (1 << 2)
 #define CGM_CSC_EN                             (1 << 1)
 #define CGM_DEGAMMA_EN                         (1 << 0)
+
+/* Gamma on BDW */
+#define BDW_SPLITGAMMA_MAX_VALS                512
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#30 lore raw

PATCH v6 19/23 drm/i915: BDW: Pipe level Gamma correction

In reply to Shashank Sharma

BDW/SKL/BXT platforms support various Gamma correction modes which are:
1. Legacy 8-bit mode
2. 10-bit mode
3. Split mode
4. 12-bit mode

This patch does the following:
1. Adds the core function to program Gamma correction values for BDW/SKL/BXT platforms
2. Adds Gamma correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |  25 ++-
 drivers/gpu/drm/i915/intel_color_manager.c | 281 +++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_color_manager.h |   6 +
 3 files changed, 310 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_reg.h +23 -2
index 3db42f4..39fbafc 100644
@@ -5685,11 +5685,15 @@ enum skl_disp_power_wells {
 /* legacy palette */
 #define _LGC_PALETTE_A           0x4a000
 #define _LGC_PALETTE_B           0x4a800
-#define LGC_PALETTE(pipe, i) (_PIPE(pipe, _LGC_PALETTE_A, _LGC_PALETTE_B) + (i) * 4)
+#define _LGC_PALETTE_C           0x4b000
+#define LGC_PALETTE(pipe, i) (_PIPE3(pipe, _LGC_PALETTE_A, _LGC_PALETTE_B, \
+			 _LGC_PALETTE_C) + (i) * 4)
 
 #define _GAMMA_MODE_A		0x4a480
 #define _GAMMA_MODE_B		0x4ac80
-#define GAMMA_MODE(pipe) _PIPE(pipe, _GAMMA_MODE_A, _GAMMA_MODE_B)
+#define _GAMMA_MODE_C		0x4b480
+#define GAMMA_MODE(pipe) \
+	_PIPE3(pipe, _GAMMA_MODE_A, _GAMMA_MODE_B, _GAMMA_MODE_C)
 #define GAMMA_MODE_MODE_MASK	(3 << 0)
 #define GAMMA_MODE_MODE_8BIT	(0 << 0)
 #define GAMMA_MODE_MODE_10BIT	(1 << 0)
@@ -8172,6 +8176,23 @@ enum skl_disp_power_wells {
 #define _PIPE_CSC_BASE(pipe) \
 	(_PIPE3(pipe, PIPEA_CGM_CSC, PIPEB_CGM_CSC, PIPEC_CGM_CSC))
 
+/* BDW gamma correction */
+#define PAL_PREC_INDEX_A                       0x4A400
+#define PAL_PREC_INDEX_B                       0x4AC00
+#define PAL_PREC_INDEX_C                       0x4B400
+#define PAL_PREC_DATA_A                        0x4A404
+#define PAL_PREC_DATA_B                        0x4AC04
+#define PAL_PREC_DATA_C                        0x4B404
+#define PAL_PREC_GCMAX_A			0x4A410
+#define PAL_PREC_GCMAX_B			0x4AC10
+#define PAL_PREC_GCMAX_C			0x4B410
+
+#define _PREC_PAL_INDEX(pipe) \
+	(_PIPE3(pipe, PAL_PREC_INDEX_A, PAL_PREC_INDEX_B, PAL_PREC_INDEX_C))
+#define _PREC_PAL_DATA(pipe) \
+	(_PIPE3(pipe, PAL_PREC_DATA_A, PAL_PREC_DATA_B, PAL_PREC_DATA_C))
+#define _PREC_PAL_GCMAX(pipe) \
+	(_PIPE3(pipe, PAL_PREC_GCMAX_A, PAL_PREC_GCMAX_B, PAL_PREC_GCMAX_C))
 
 
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +281 -0

293 lines not on this page · raw message

drivers/gpu/drm/i915/intel_color_manager.h +6 -0
index 271246a..6c7cb08 100644
@@ -92,3 +92,9 @@
 
 /* Gamma on BDW */
 #define BDW_SPLITGAMMA_MAX_VALS                512
+#define BDW_8BIT_GAMMA_MAX_VALS		256
+#define BDW_10BIT_GAMMA_MAX_VALS		1024
+#define BDW_12BIT_GAMMA_MAX_VALS		513
+#define BDW_MAX_GAMMA                         ((1 << 24) - 1)
+#define BDW_INDEX_AUTO_INCREMENT               (1 << 15)
+#define BDW_INDEX_SPLIT_MODE                   (1 << 31)
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#31 lore raw

PATCH v6 20/23 drm/i915: BDW: Load degamma correction values

In reply to Shashank Sharma

I915 color manager registers pipe degamma correction as palette correction before CTM, DRM property.

This patch adds the no of coefficients(512) for degamma correction as "num_samples_before_ctm" parameter in device info structures, for BDW and higher platforms.

---
 drivers/gpu/drm/i915/i915_drv.c            | 7 +++++++
 drivers/gpu/drm/i915/intel_color_manager.h | 3 +++
 2 files changed, 10 insertions(+)
drivers/gpu/drm/i915/i915_drv.c +7 -0
index 8beac5c..1c68e91 100644
@@ -303,6 +303,7 @@ static const struct intel_device_info intel_broadwell_d_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
 	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
+	.num_samples_before_ctm = BDW_DEGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -316,6 +317,7 @@ static const struct intel_device_info intel_broadwell_m_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
 	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
+	.num_samples_before_ctm = BDW_DEGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -329,6 +331,7 @@ static const struct intel_device_info intel_broadwell_gt3d_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
 	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
+	.num_samples_before_ctm = BDW_DEGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -342,6 +345,7 @@ static const struct intel_device_info intel_broadwell_gt3m_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
 	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
+	.num_samples_before_ctm = BDW_DEGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -368,6 +372,7 @@ static const struct intel_device_info intel_skylake_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
 	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
+	.num_samples_before_ctm = BDW_DEGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -382,6 +387,7 @@ static const struct intel_device_info intel_skylake_gt3_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING,
 	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
+	.num_samples_before_ctm = BDW_DEGAMMA_MAX_VALS,
 	.has_llc = 1,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
@@ -396,6 +402,7 @@ static const struct intel_device_info intel_broxton_info = {
 	.need_gfx_hws = 1, .has_hotplug = 1,
 	.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING,
 	.num_samples_after_ctm = BDW_SPLITGAMMA_MAX_VALS,
+	.num_samples_before_ctm = BDW_DEGAMMA_MAX_VALS,
 	.num_pipes = 3,
 	.has_ddi = 1,
 	.has_fpga_dbg = 1,
drivers/gpu/drm/i915/intel_color_manager.h +3 -0
index 6c7cb08..e0c486e 100644
@@ -98,3 +98,6 @@
 #define BDW_MAX_GAMMA                         ((1 << 24) - 1)
 #define BDW_INDEX_AUTO_INCREMENT               (1 << 15)
 #define BDW_INDEX_SPLIT_MODE                   (1 << 31)
+
+/* Degamma on BDW */
+#define BDW_DEGAMMA_MAX_VALS                   512
Signature · 6 lines
1.9.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#32 lore raw

PATCH v6 21/23 drm/i915: BDW: Pipe level degamma correction

In reply to Shashank Sharma

BDW/SKL/BXT supports Degamma color correction feature, which linearizes the non-linearity due to gamma encoded color values. This will be applied before Color Transformation.

This patch does the following:
1. Adds the core function to program DeGamma correction values for BDW/SKL/BXT platform
2. Adds DeGamma correction macros/defines

---
 drivers/gpu/drm/i915/intel_color_manager.c | 59 ++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)
drivers/gpu/drm/i915/intel_color_manager.c +59 -0
index 44f99be..3d792b2 100644
@@ -306,6 +306,63 @@ static int bdw_set_gamma(struct drm_device *dev, struct drm_property_blob *blob,
 	return 0;
 }
 
+static int bdw_set_degamma(struct drm_device *dev,
+	struct drm_property_blob *blob, struct drm_crtc *crtc)
+{
+	enum pipe pipe;
+	int num_samples;
+	u32 index, mode;
+	u32 pal_prec_index, pal_prec_data;
+	struct drm_palette *degamma_data;
+	struct drm_crtc_state *state = crtc->state;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_r32g32b32 *correction_values = NULL;
+
+	if (WARN_ON(!blob))
+		return -EINVAL;
+
+	degamma_data = (struct drm_palette *)blob->data;
+	pipe = to_intel_crtc(crtc)->pipe;
+	num_samples = blob->length / sizeof(struct drm_r32g32b32);
+
+	switch (num_samples) {
+	case GAMMA_DISABLE_VALS:
+		/* Disable degamma on Pipe */
+		mode = I915_READ(GAMMA_MODE(pipe)) & ~GAMMA_MODE_MODE_MASK;
+		I915_WRITE(GAMMA_MODE(pipe), mode | GAMMA_MODE_MODE_8BIT);
+
+		state->palette_before_ctm_blob = NULL;
+		DRM_DEBUG_DRIVER("Disabling degamma on Pipe %c\n",
+			pipe_name(pipe));
+		break;
+
+	case BDW_SPLITGAMMA_MAX_VALS:
+		pal_prec_index = _PREC_PAL_INDEX(pipe);
+		pal_prec_data = _PREC_PAL_DATA(pipe);
+		correction_values = degamma_data->lut;
+
+		index = I915_READ(pal_prec_index);
+		index |= BDW_INDEX_AUTO_INCREMENT | BDW_INDEX_SPLIT_MODE;
+		I915_WRITE(pal_prec_index, index);
+
+		bdw_write_10bit_gamma_precision(dev, correction_values,
+		pal_prec_data, BDW_SPLITGAMMA_MAX_VALS);
+
+		/* Enable degamma on Pipe */
+		mode = I915_READ(GAMMA_MODE(pipe));
+		mode &= ~GAMMA_MODE_MODE_MASK;
+		I915_WRITE(GAMMA_MODE(pipe), mode | GAMMA_MODE_MODE_SPLIT);
+		DRM_DEBUG_DRIVER("degamma correction enabled on Pipe %c\n",
+			pipe_name(pipe));
+		break;
+
+	default:
+		DRM_ERROR("Invalid number of samples\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static s32 chv_prepare_csc_coeff(s64 csc_value)
 {
 	s32 csc_int_value;
@@ -596,6 +653,8 @@ void intel_color_manager_crtc_commit(struct drm_device *dev,
 		/* Degamma correction */
 		if (IS_CHERRYVIEW(dev))
 			ret = chv_set_degamma(dev, blob, crtc);
+		else if (IS_BROADWELL(dev) || IS_GEN9(dev))
+			ret = bdw_set_degamma(dev, blob, crtc);
 
 		if (ret)
 			DRM_ERROR("set degamma correction failed\n");
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#33 lore raw

PATCH v6 22/23 drm/i915: BDW: Pipe level CSC correction

In reply to Shashank Sharma

BDW/SKL/BXT support Color Space Conversion (CSC) using a 3x3 matrix that needs to be programmed into respective CSC registers.

This patch does the following:
1. Adds the core function to program CSC correction values for BDW/SKL/BXT platform
2. Adds CSC correction macros/defines

---
 drivers/gpu/drm/i915/i915_reg.h            |   7 ++
 drivers/gpu/drm/i915/intel_color_manager.c | 113 +++++++++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_color_manager.h |   8 ++
 3 files changed, 128 insertions(+)
drivers/gpu/drm/i915/i915_reg.h +7 -0
index 39fbafc..9838afc 100644
@@ -8195,4 +8195,11 @@ enum skl_disp_power_wells {
 	(_PIPE3(pipe, PAL_PREC_GCMAX_A, PAL_PREC_GCMAX_B, PAL_PREC_GCMAX_C))
 
 
+/* BDW CSC correction */
+#define CSC_COEFF_A				0x49010
+#define CSC_COEFF_B				0x49110
+#define CSC_COEFF_C				0x49210
+#define _PIPE_CSC_COEFF(pipe) \
+	(_PIPE3(pipe, CSC_COEFF_A, CSC_COEFF_B, CSC_COEFF_C))
+
 #endif /* _I915_REG_H_ */
drivers/gpu/drm/i915/intel_color_manager.c +113 -0

125 lines not on this page · raw message

drivers/gpu/drm/i915/intel_color_manager.h +8 -0
index e0c486e..6c20cf0 100644
@@ -90,6 +90,14 @@
 #define CGM_CSC_EN                             (1 << 1)
 #define CGM_DEGAMMA_EN                         (1 << 0)
 
+/* BDW CSC */
+/* 1.0000000 in S31.32 format */
+#define BDW_CSC_COEFF_UNITY_VAL	0x100000000
+/* 3.9921875 in S31.32 format */
+#define BDW_CSC_COEFF_MAX_VAL	0x3FE000000
+/*-4.000000 in S31.32 format */
+#define BDW_CSC_COEFF_MIN_VAL	0xFFFFFFFC00000000
+
 /* Gamma on BDW */
 #define BDW_SPLITGAMMA_MAX_VALS                512
 #define BDW_8BIT_GAMMA_MAX_VALS		256
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#34 lore raw

PATCH v6 23/23 drm/i915: disable plane gamma

In reply to Shashank Sharma

In plane enabling sequence, plane gamma bit is by default enabled. Plane gamma gets higher priority than pipe gamma, if both enabled.

This patch disables plane gamma from sequence. If required, plane gamma can be enabled via the color manager drm interface.

---
 drivers/gpu/drm/i915/intel_display.c | 2 +-
 drivers/gpu/drm/i915/intel_sprite.c  | 7 ++++---
 2 files changed, 5 insertions(+), 4 deletions(-)
drivers/gpu/drm/i915/intel_display.c +1 -1
index 61562a3..72b701a 100644
@@ -2820,7 +2820,7 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
 
 	pixel_size = drm_format_plane_cpp(fb->pixel_format, 0);
 
-	dspcntr = DISPPLANE_GAMMA_ENABLE;
+	dspcntr = (DISPPLANE_GAMMA_ENABLE | PLANE_CTL_PLANE_GAMMA_DISABLE);
 
 	dspcntr |= DISPLAY_PLANE_ENABLE;
 
drivers/gpu/drm/i915/intel_sprite.c +4 -3
index 56dc132..6e2be1c 100644
@@ -204,7 +204,8 @@ skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
 
 	plane_ctl = PLANE_CTL_ENABLE |
 		PLANE_CTL_PIPE_GAMMA_ENABLE |
-		PLANE_CTL_PIPE_CSC_ENABLE;
+		PLANE_CTL_PIPE_CSC_ENABLE |
+		PLANE_CTL_PLANE_GAMMA_DISABLE;
 
 	plane_ctl |= skl_plane_ctl_format(fb->pixel_format);
 	plane_ctl |= skl_plane_ctl_tiling(fb->modifier[0]);
@@ -409,7 +410,7 @@ vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
 	 * Enable gamma to match primary/cursor plane behaviour.
 	 * FIXME should be user controllable via propertiesa.
 	 */
-	sprctl |= SP_GAMMA_ENABLE;
+	sprctl |= (SP_GAMMA_ENABLE | PLANE_CTL_PLANE_GAMMA_DISABLE);
 
 	if (obj->tiling_mode != I915_TILING_NONE)
 		sprctl |= SP_TILED;
@@ -528,7 +529,7 @@ ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
 	 * Enable gamma to match primary/cursor plane behaviour.
 	 * FIXME should be user controllable via propertiesa.
 	 */
-	sprctl |= SPRITE_GAMMA_ENABLE;
+	sprctl |= (SPRITE_GAMMA_ENABLE | PLANE_CTL_PLANE_GAMMA_DISABLE);
 
 	if (obj->tiling_mode != I915_TILING_NONE)
 		sprctl |= SPRITE_TILED;
Signature · 6 lines
1.9.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel