drm/i915: Initialize Color Manager
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 144 lines · Kausal Malladi
From: Kausal Malladi <[email protected]>
Color Manager is an extension in i915 driver to handle color correction and enhancements across various Intel platforms.
This patch initializes color manager framework by :
1. Adding two new files,intel_color_manager(.c/.h)
2. Introducing new pointers in DRMmode_configstructure to carry CSC and Gamma color correction properties.
3. Creating these DRM properties in Color Manager initialization sequence.Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Kausal Malladi <[email protected]>--- drivers/gpu/drm/i915/Makefile | 3 ++ drivers/gpu/drm/i915/intel_color_manager.c | 49 ++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_color_manager.h | 32 ++++++++++++++++++ drivers/gpu/drm/i915/intel_display.c | 5 +++ include/drm/drm_crtc.h | 4 +++ 5 files changed, 93 insertions(+)create mode 100644
drivers/gpu/drm/i915/intel_color_manager.ccreate mode 100644drivers/gpu/drm/i915/intel_color_manager.hdrivers/gpu/drm/i915/Makefile +3
-0@@ -89,6 +89,9 @@ i915-y += i915_vgpu.o # legacy horrors i915-y += i915_dma.o +# Color Management +i915-y += intel_color_manager.o + obj-$(CONFIG_DRM_I915) += i915.o CFLAGS_i915_trace_points.o := -I$(src)drivers/gpu/drm/i915/intel_color_manager.c new file +49
-0@@ -0,0 +1,49 @@ +/* +* 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" + +int intel_color_manager_init (struct drm_device *dev) +{ +struct drm_mode_config *config = &dev->mode_config; + +/* Create Gamma and CSC properties */ + config->gamma_property =drm_property_create (dev, +DRM_MODE_PROP_BLOB ,"gamma_property" ,0 ); +if (!config->gamma_property) +DRM_ERROR ("Gamma property creation failed\n" ); + +DRM_DEBUG_DRIVER ("Created Gamma property\n" ); + + config->csc_property =drm_property_create (dev, +DRM_MODE_PROP_BLOB ,"csc_property" ,0 ); +if (!config->csc_property) +DRM_ERROR ("CSC property creation failed\n" ); + +DRM_DEBUG_DRIVER ("Created CSC property\n" ); +return 0 ; +}drivers/gpu/drm/i915/intel_color_manager.h new file +32
-0@@ -0,0 +1,32 @@ +/* +* 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 <drm/drmP.h> +#include <drm/drm_crtc_helper.h> + +/* Generic Function prototypes */ +int intel_color_manager_init (struct drm_device *dev);drivers/gpu/drm/i915/intel_display.c +1
-0@@ -44,6 +44,7 @@#include <drm/drm_plane_helper.h> #include <drm/drm_rect.h> #include <linux/dma_remapping.h> +#include "intel_color_manager.h" /* Primary plane formats for gen <= 3 */ static const uint32_t i8xx_primary_formats[] = {
drivers/gpu/drm/i915/intel_display.c void intel_modeset_init(struct drm_device *dev) · line 14674
Quoted 4 lines
drivers/gpu/drm/i915/intel_display.c +1
-0@@ -14670,6 +14671,10 @@ void intel_modeset_init(struct drm_device *dev)intel_init_pm (dev); + ret =intel_color_manager_init (dev);
This call never fails, you might want to add returning of errors
Also, it is better to move this initialization after the num_pipes check, so that we are not initializing the color manager when modeset fails.
Quoted 11 lines
drivers/gpu/drm/i915/intel_display.c +3
-0+if (ret) +DRM_ERROR ("Color Manager initialization failed\n" ); +if (INTEL_INFO (dev)->num_pipes ==0 )return ;include/drm/drm_crtc.h +0
-0
include/drm/drm_crtc.h struct drm_mode_config { · line 1193
Quoted 7 lines
include/drm/drm_crtc.h +4
-0@@ -1187,6 +1187,10 @@ struct drm_mode_config {/* cursor size */ uint32_t cursor_width, cursor_height; + +/* Color Management Properties */ +struct drm_property *gamma_property; +struct drm_property *csc_property;
This can be moved near the property section in the same struct.
include/drm/drm_crtc.h struct drm_mode_config { · line 1196
Quoted 4 lines
include/drm/drm_crtc.h +0
-0};/**
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/7] drm/i915: Add Set property interface for CRTC
Quoted 22 lines · Kausal Malladi
From: Kausal Malladi <[email protected]>
This patch adds set property interface for Intel CRTC. This interface will be used to set color correction DRM properties.
Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Kausal Malladi <[email protected]>--- drivers/gpu/drm/i915/intel_display.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/gpu/drm/i915/intel_display.c +3
-0@@ -12978,11 +12978,19 @@ out:return ret; } +static int intel_crtc_set_property (struct drm_crtc *crtc, +struct drm_property *property,uint64_t val) +{
drivers/gpu/drm/i915/intel_display.c out: · line 12993
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +5
-0+DRM_DEBUG_KMS ("Unknown crtc property '%s'\n" , property->name); +return -EINVAL ; +} +static const struct drm_crtc_funcs intel_crtc_funcs = { .gamma_set = intel_crtc_gamma_set, .set_config = intel_crtc_set_config, .destroy = intel_crtc_destroy, .page_flip = intel_crtc_page_flip, + .set_property = intel_crtc_set_property,
I think it should be done similar to plane set property using atomic helpers.
drivers/gpu/drm/i915/intel_display.c out: · line 12996
Quoted 4 lines
drivers/gpu/drm/i915/intel_display.c +0
-0.atomic_duplicate_state = intel_crtc_duplicate_state, .atomic_destroy_state = intel_crtc_destroy_state, };
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 4/7] drm: Add Gamma correction structure
Quoted 44 lines · Kausal Malladi
From: Kausal Malladi <[email protected]>
This patch adds a new structure in DRM layer for Gamma color correction. This structure will be used by all user space agents to configure appropriate Gamma precision and Gamma level.
struct drm_intel_gamma { __u32 flags; (The flag variable will indicate if the property to be set/get is Gamma or DeGamma) __u32 gamma_level; (The gamma_level variable indicates if the Gamma correction is to be applied on Pipe/plane) __u32 gamma_precision; (The Gamma precision indicates the Gamma mode to be applied) Supported precisions are - #define I915_GAMMA_PRECISION_UNKNOWN 0 #define I915_GAMMA_PRECISION_CURRENT 0xFFFFFFFF #define I915_GAMMA_PRECISION_LEGACY (1 << 0) #define I915_GAMMA_PRECISION_10BIT (1 << 1) #define I915_GAMMA_PRECISION_12BIT (1 << 2) #define I915_GAMMA_PRECISION_14BIT (1 << 3) #define I915_GAMMA_PRECISION_16BIT (1 << 4) __u32 num_samples; (The num_samples indicates the number of Gamma correction coefficients) __u32 reserved; __u64 gamma_ptr; (Points to the raw Gamma color correction values) };Signed-off-by Shashank Sharma <[email protected]>Signed-off-by Kausal Malladi <[email protected]>--- include/uapi/drm/drm.h | 11 +++++++++++ 1 file changed, 11 insertions(+)include/uapi/drm/drm.h +0
-0
include/uapi/drm/drm.h struct drm_event_vblank { · line 833
Quoted 5 lines
include/uapi/drm/drm.h +2
-0@@ -829,6 +829,17 @@ struct drm_event_vblank {__u32 reserved; }; +/* Color Management structure for Gamma */ +struct drm_intel_gamma {
I suppose, this can be used by other drivers as well? If yes, "intel" can be removed.
include/uapi/drm/drm.h struct drm_event_vblank { · line 845
Quoted 13 lines
include/uapi/drm/drm.h +9
-0+__u32 obj_id; +__u32 flags; +__u32 gamma_level; +__u32 gamma_precision; +__u32 num_samples; +__u32 reserved; +__u64 gamma_ptr; +}; +/* typedef area */ #ifndef __KERNEL__typedef struct drm_clip_rect drm_clip_rect_t ;
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [Intel-gfx] [PATCH 4/7] drm: Add Gamma correction structure
Hi,
Quoted 21 lines · Sonika
Quoted 20 lines · Kausal Malladi
struct
drm_intel_gamma{
__u32flags;
(The flag variable will indicate if the property to be set/get is Gamma or DeGamma)
__u32gamma_level;
(Thegamma_levelvariable indicates if the Gamma correction is to
beapplied on Pipe/plane) __u32 gamma_precision; (The Gamma precision indicates the Gamma mode to be applied) Supported precisions are - #define I915_GAMMA_PRECISION_UNKNOWN 0 #define I915_GAMMA_PRECISION_CURRENT 0xFFFFFFFF #define I915_GAMMA_PRECISION_LEGACY (1 << 0) #define I915_GAMMA_PRECISION_10BIT (1 << 1) #define I915_GAMMA_PRECISION_12BIT (1 << 2) #define I915_GAMMA_PRECISION_14BIT (1 << 3) #define I915_GAMMA_PRECISION_16BIT (1 << 4)
Quoted 7 lines
Quoted 7 lines
__u32 num_samples; (The num_samples indicates the number of Gamma correction coefficients) __u32 reserved; __u64 gamma_ptr; (Points to the raw Gamma color correction values) };
Please use the atomic interface and blob properties for this instead. A user-created blob property can replace the contents of gamma_ptr, you can replace gamma_level by choosing whether you apply the properties to a CRTC (pipe) or plane, and then you just need separate properties for precision and num_samples.
Cheers,
Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 5/7] drm/i915: Add pipe level Gamma correction for CHV/BSW
Quoted 25 lines · Kausal Malladi
From: Kausal Malladi <[email protected]>
This patch does the following:
1. Adds the core function to program Gamma correction values for CHV/BSW platform
2. Adds Gamma correction macros/defines
3. Addsdrm_mode_crtc_update_color_propertyfunction, which replaces the old blob for the property with the new one
4. Adds a pointer to hold blob for Gamma property indrm_crtcSigned-off-by Shashank Sharma <[email protected]>Signed-off-by Kausal Malladi <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 14 ++ drivers/gpu/drm/i915/intel_color_manager.c | 194 ++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_color_manager.h | 61 +++++++++ drivers/gpu/drm/i915/intel_display.c | 9 +- include/drm/drm_crtc.h | 8 ++ 5 files changed, 285 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_crtc.c +0
-0
drivers/gpu/drm/drm_crtc.c int drm_mode_connector_set_tile_property(struct drm_connector *connector) · line 4698
Quoted 8 lines
drivers/gpu/drm/drm_crtc.c +5
-0@@ -4691,6 +4691,20 @@ int drm_mode_connector_set_tile_property(struct drm_connector *connector) }EXPORT_SYMBOL (drm_mode_connector_set_tile_property); +int drm_mode_crtc_update_color_property (struct drm_device *dev, +struct drm_property_blob **blob, +size_t length,const void *color_data, +struct drm_mode_object *obj_holds_id, +struct drm_property *prop_holds_id)
This can be simplified.. No need to pass so many params.
drivers/gpu/drm/drm_crtc.c int drm_mode_connector_set_tile_property(struct drm_connector *connector) · line 4707
Quoted 9 lines
drivers/gpu/drm/drm_crtc.c +9
-0+{ +int ret; + + ret =drm_property_replace_global_blob (dev, + blob, length, color_data, obj_holds_id, prop_holds_id); + +return ret; +} +
Split the patch to add drm specific changes in a separate patch. Also you need to export this function.
Will review the rest of the file in some time.
Regards,
Sonika
Quoted 319 lines
drivers/gpu/drm/drm_crtc.c +0
-0/** * drm_mode_connector_update_edid_property - update the edid property of a connector * @connector: drm connector drivers/gpu/drm/i915/intel_color_manager.c +194
-0@@ -27,6 +27,200 @@#include "intel_color_manager.h" +int chv_set_gamma (struct drm_device *dev,uint64_t blob_id, +struct drm_crtc *crtc) +{ +struct drm_intel_gamma *gamma_data; +struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_property_blob *blob; +struct drm_mode_config *config = &dev->mode_config; + +u32 cgm_control_reg =0 ; +u32 cgm_gamma_reg =0 ; +u32 reg, val, pipe; +u16 red, green, blue; +struct rgb_pixel correct_rgb; +u32 count =0 ; +struct rgb_pixel *correction_values =NULL ; +u32 num_samples; +u32 word; +u32 palette; +int ret =0 , length; + + blob =drm_property_lookup_blob (dev, blob_id); +if (!blob) { +DRM_ERROR ("Invalid Blob ID\n" ); +return -EINVAL ; + } + + gamma_data =kzalloc (sizeof (struct drm_intel_gamma ),GFP_KERNEL ); +if (!gamma_data) { +DRM_ERROR ("Memory unavailable\n" ); +return -ENOMEM ; + } + gamma_data = (struct drm_intel_gamma *)blob->data; + pipe =to_intel_crtc (crtc)->pipe; + num_samples = gamma_data->num_samples; + length = num_samples *sizeof (struct rgb_pixel ); + +if (gamma_data->gamma_precision ==I915_GAMMA_PRECISION_UNKNOWN ) { + +/* Disable Gamma functionality on Pipe - CGM Block */ + cgm_control_reg =I915_READ (_PIPE_CGM_CONTROL (pipe)); + cgm_control_reg &= ~CGM_GAMMA_EN ; +I915_WRITE (_PIPE_CGM_CONTROL (pipe), cgm_control_reg); + +DRM_DEBUG_DRIVER ("Gamma disabled on Pipe %c\n" , +pipe_name (pipe)); + ret =0 ; + goto release_memory; + } + +if (pipe >=CHV_MAX_PIPES ) { +DRM_ERROR ("Incorrect Pipe ID\n" ); + ret = -EFAULT ; + goto release_memory; + } + + correction_values =kzalloc (length,GFP_KERNEL ); +if (!correction_values) { +DRM_ERROR ("Out of Memory\n" ); + ret = -ENOMEM ; + goto release_memory; + } + + ret =copy_from_user ((void *)correction_values, + (const void __user *)gamma_data->gamma_ptr, length); +if (ret) { +DRM_ERROR ("Error copying user data\n" ); + ret = -EFAULT ; + goto release_memory; + } + + ret =drm_mode_crtc_update_color_property (dev, + &crtc->gamma_blob, length, (void *) correction_values, + &crtc->base, config->gamma_property); +if (ret) { +DRM_ERROR ("Error updating Gamma blob\n" ); + ret = -EFAULT ; + goto release_memory; + } + +if (gamma_data->gamma_precision ==I915_GAMMA_PRECISION_LEGACY ) { + +if (num_samples !=CHV_8BIT_GAMMA_MAX_VALS ) { +DRM_ERROR ("Incorrect number of samples received\n" ); + goto release_memory; + } + +/* First, disable CGM Gamma, if already set */ + cgm_control_reg =I915_READ (_PIPE_CGM_CONTROL (pipe)); + cgm_control_reg &= ~CGM_GAMMA_EN ; +I915_WRITE (_PIPE_CGM_CONTROL (pipe), cgm_control_reg); + +/* Enable (Legacy) Gamma on Pipe gamma_data.__obj_id */ + palette =_PIPE_GAMMA_BASE (pipe); + + count =0 ; +while (count < num_samples) { + correct_rgb = correction_values[count]; + blue = correct_rgb.blue; + green = correct_rgb.green; + red = correct_rgb.red; + + blue = blue >>CHV_8BIT_GAMMA_MSB_SHIFT ; + green = green >>CHV_8BIT_GAMMA_MSB_SHIFT ; + red = red >>CHV_8BIT_GAMMA_MSB_SHIFT ; + +/* Red (23:16), Green (15:8), Blue (7:0) */ + word = (red <<CHV_8BIT_GAMMA_SHIFT_RED_REG ) | + (green << +CHV_8BIT_GAMMA_SHIFT_GREEN_REG ) | + blue; +I915_WRITE (palette, word); + + palette +=4 ; + count++; + } + reg =PIPECONF (pipe); + val =I915_READ (reg) |PIPECONF_GAMMA ; +I915_WRITE (reg, val); + +DRM_DEBUG_DRIVER ("Gamma LUT loaded successfully for Pipe %c\n" , +pipe_name (pipe)); + ret =0 ; + goto release_memory; + }else if (gamma_data->gamma_precision ==I915_GAMMA_PRECISION_10BIT ) { + +if (num_samples !=CHV_10BIT_GAMMA_MAX_VALS ) { +DRM_ERROR ("Incorrect number of samples received\n" ); + ret = -EINVAL ; + goto release_memory; + } + +/* Enable (CGM) Gamma on Pipe gamma_data.__obj_id */ + cgm_gamma_reg =_PIPE_GAMMA_BASE (pipe); + + count =0 ; +while (count < num_samples) { + correct_rgb = correction_values[count]; + blue = correct_rgb.blue; + green = correct_rgb.green; + red = correct_rgb.red; + + blue = blue >>CHV_10BIT_GAMMA_MSB_SHIFT ; + green = green >>CHV_10BIT_GAMMA_MSB_SHIFT ; + red = red >>CHV_10BIT_GAMMA_MSB_SHIFT ; + +/* Green (25:16) and Blue (9:0) to be written */ + word = (green <<CHV_GAMMA_SHIFT_GREEN ) | blue; +I915_WRITE (cgm_gamma_reg, word); + cgm_gamma_reg +=4 ; + +/* Red (9:0) to be written */ + word = red; +I915_WRITE (cgm_gamma_reg, word); + + cgm_gamma_reg +=4 ; + count++; + } + +I915_WRITE (_PIPE_CGM_CONTROL (pipe), +I915_READ (_PIPE_CGM_CONTROL (pipe)) + |CGM_GAMMA_EN ); + +DRM_DEBUG_DRIVER ("Gamma LUT loaded successfully for Pipe %c\n" , +pipe_name (pipe)); + ret =0 ; + goto release_memory; + }else { +DRM_ERROR ("Invalid gamma_level received\n" ); + ret = -EFAULT ; + goto release_memory; + } + +release_memory: + +/* kfree is NULL protected */ +kfree (correction_values); +kfree (gamma_data); + +return ret; +} + +int intel_color_manager_set_gamma (struct drm_device *dev, +struct drm_mode_object *obj,uint64_t blob_id) +{ +struct drm_crtc *crtc =obj_to_crtc (obj); + +if (IS_CHERRYVIEW (dev)) +return chv_set_gamma (dev, blob_id, crtc); +else +DRM_ERROR ("This platform is not yet supported\n" ); + +return -EINVAL ; +} +void intel_color_manager_attach (struct drm_device *dev,struct drm_mode_object *mode_obj) {drivers/gpu/drm/i915/intel_color_manager.h +61
-0@@ -27,8 +27,69 @@#include <drm/drmP.h> #include <drm/drm_crtc_helper.h> +#include "i915_drv.h" + +/* Color Management macros for Gamma */ +#define I915_GAMMA_FLAG_DEGAMMA (1 << 0) +#define I915_PIPE_GAMMA (1 << 0) +#define I915_PLANE_GAMMA (1 << 1) +#define I915_GAMMA_PRECISION_UNKNOWN 0 +#define I915_GAMMA_PRECISION_CURRENT 0xFFFFFFFF +#define I915_GAMMA_PRECISION_LEGACY (1 << 0) +#define I915_GAMMA_PRECISION_10BIT (1 << 1) +#define I915_GAMMA_PRECISION_12BIT (1 << 2) +#define I915_GAMMA_PRECISION_14BIT (1 << 3) +#define I915_GAMMA_PRECISION_16BIT (1 << 4) + +#define CHV_MAX_PIPES 3 +#define CHV_DISPLAY_BASE 0x180000 + +struct rgb_pixel { +u16 red; +u16 green; +u16 blue; +}; + +/* CHV CGM Block */ +/* Bit 2 to be enabled in CGM block for CHV */ +#define CGM_GAMMA_EN 4 + +/* Gamma */ +#define CHV_GAMMA_VALS 257 +#define CHV_10BIT_GAMMA_MAX_INDEX 256 +#define CHV_8BIT_GAMMA_MAX_INDEX 255 +#define CHV_10BIT_GAMMA_MSB_SHIFT 6 +#define CHV_GAMMA_EVEN_MASK 0xFF +#define CHV_GAMMA_SHIFT_BLUE 0 +#define CHV_GAMMA_SHIFT_GREEN 16 +#define CHV_GAMMA_SHIFT_RED 0 +#define CHV_GAMMA_ODD_SHIFT 8 +#define CHV_CLRMGR_GAMMA_GCMAX_SHIFT 17 +#define CHV_GAMMA_GCMAX_MASK 0x1FFFF +#define CHV_GAMMA_GCMAX_MAX 0x400 +#define CHV_10BIT_GAMMA_MAX_VALS (CHV_10BIT_GAMMA_MAX_INDEX + 1) +#define CHV_8BIT_GAMMA_MAX_VALS (CHV_8BIT_GAMMA_MAX_INDEX + 1) +#define CHV_8BIT_GAMMA_MSB_SHIFT 8 +#define CHV_8BIT_GAMMA_SHIFT_GREEN_REG 8 +#define CHV_8BIT_GAMMA_SHIFT_RED_REG 16 + +/* CGM Registers */ +#define CGM_OFFSET 0x2000 +#define GAMMA_OFFSET 0x2000 +#define PIPEA_CGM_CONTROL (CHV_DISPLAY_BASE + 0x67A00) +#define PIPEA_CGM_GAMMA_MIN (CHV_DISPLAY_BASE + 0x67000) +#define _PIPE_CGM_CONTROL (pipe) \ + (PIPEA_CGM_CONTROL + (pipe * CGM_OFFSET)) +#define _PIPE_GAMMA_BASE (pipe) \ + (PIPEA_CGM_GAMMA_MIN + (pipe * GAMMA_OFFSET))/* Generic Function prototypes */ int intel_color_manager_init (struct drm_device *dev);void intel_color_manager_attach (struct drm_device *dev,struct drm_mode_object *mode_obj); +extern int intel_color_manager_set_gamma (struct drm_device *dev, +struct drm_mode_object *obj,uint64_t blob_id); + +/* Platform specific function prototypes */ +extern int chv_set_gamma (struct drm_device *dev, +uint64_t blob_id,struct drm_crtc *crtc);drivers/gpu/drm/i915/intel_display.c +8
-1@@ -12981,7 +12981,14 @@ out:static int intel_crtc_set_property (struct drm_crtc *crtc,struct drm_property *property,uint64_t val) { -DRM_DEBUG_KMS ("Unknown crtc property '%s'\n" , property->name); +struct drm_device *dev = crtc->dev; +struct drm_mode_config *config = &dev->mode_config; + +if (property == config->gamma_property) +return intel_color_manager_set_gamma (dev, &crtc->base, val); +else +DRM_DEBUG_KMS ("Unknown crtc property '%s'\n" , property->name); +return -EINVAL ; }include/drm/drm_crtc.h +3
-0@@ -483,6 +483,9 @@ struct drm_crtc {* acquire context. */ struct drm_modeset_acquire_ctx *acquire_ctx; + +/* Color Management Blobs */ +struct drm_property_blob *gamma_blob; };/** @@ -1341,6 +1344,11 @@ extern void drm_mode_config_cleanup(struct drm_device *dev); extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
include/drm/drm_crtc.h extern void drm_mode_config_cleanup(struct drm_device *dev); · line 1354
Quoted 10 lines
include/drm/drm_crtc.h +5
-0const char *path);int drm_mode_connector_set_tile_property (struct drm_connector *connector); +extern int drm_mode_crtc_update_color_property (struct drm_device *dev, +struct drm_property_blob **blob, +size_t length,const void *color_data, +struct drm_mode_object *obj_holds_id, +struct drm_property *prop_holds_id);extern int drm_mode_connector_update_edid_property (struct drm_connector *connector,const struct edid *edid);
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 5/7] drm/i915: Add pipe level Gamma correction for CHV/BSW
Hi,
Quoted 9 lines · Sonika
Review
Quoted 5 lines · Kausal Malladi
(quoted diff) +5
-0+int drm_mode_crtc_update_color_property(struct drm_device *dev, + struct drm_property_blob **blob, + size_t length, const void *color_data, + struct drm_mode_object *obj_holds_id, + struct drm_property *prop_holds_id)This can be simplified.. No need to pass so many params.
Quoted 1 line
Quoted 13 lines
Review
Quoted 10 lines
(quoted diff) +5
-0+{ + int ret; + + ret = drm_property_replace_global_blob(dev, + blob, length, color_data, obj_holds_id,
prop_holds_id);(quoted diff) +4
-0+ + return ret; +} +Split the patch to add drm specific changes in a separate patch. Also you need to export this function.
Or just remove the function entirely. It literally adds no value, and is just an alias for drm_property_replace_global_blob. So just use that directly.
Quoted 11 lines
Review
Quoted 11 lines
(quoted diff) +11
-0+int chv_set_gamma(struct drm_device *dev, uint64_t blob_id, + struct drm_crtc *crtc) +{ + struct drm_intel_gamma *gamma_data; + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_property_blob *blob; + struct drm_mode_config *config = &dev->mode_config; + + u32 cgm_control_reg = 0; + u32 cgm_gamma_reg = 0; + u32 reg, val, pipe;
pipe should be an enum pipe.
Quoted 1 line
Quoted 1 line
+ u16 red, green, blue;
Isn't this the literal definition of struct rgb_pixel, which you added separately in this series?
Quoted 4 lines
Quoted 4 lines
(quoted diff) +4
-0+ if (gamma_data->gamma_precision == I915_GAMMA_PRECISION_UNKNOWN) { + + /* Disable Gamma functionality on Pipe - CGM Block */ + cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe));
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ cgm_control_reg &= ~CGM_GAMMA_EN; + I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg); + + DRM_DEBUG_DRIVER("Gamma disabled on Pipe %c\n", + pipe_name(pipe)); + ret = 0; + goto release_memory; + }
This branch never updates the property.
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ if (pipe >= CHV_MAX_PIPES) { + DRM_ERROR("Incorrect Pipe ID\n"); + ret = -EFAULT; + goto release_memory; + }
How could this ever happen? This should be a WARN_ON at least.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+ correction_values = kzalloc(length, GFP_KERNEL); + if (!correction_values) { + DRM_ERROR("Out of Memory\n"); + ret = -ENOMEM; + goto release_memory; + }
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ + ret = copy_from_user((void *)correction_values, + (const void __user *)gamma_data->gamma_ptr, length); + if (ret) { + DRM_ERROR("Error copying user data\n"); + ret = -EFAULT; + goto release_memory; + }
I think I've managed to work out the userspace API now:
- allocate drm_intel_gamma structure
- allocate correction values
- insert pointer to correction values into gamma structure
- create blob with pointer to gamma structure
This seems pretty backwards. The correction values - the large data we need to avoid copying around - is what should be a blob property. With your approach, the correction data (big) will be copied quite a few times, where the supporting structure (very small) will never be copied.
At the very least, the correction data must be a blob property. I don't think there is much use in having drm_intel_gamma itself be a blob property, but I can see why you might want it to be.
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ ret = drm_mode_crtc_update_color_property(dev, + &crtc->gamma_blob, length, (void *) correction_values, + &crtc->base, config->gamma_property);
As discussed, this function is a pure alias, and can be removed.
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +4
-0+ if (gamma_data->gamma_precision == I915_GAMMA_PRECISION_LEGACY) { + + if (num_samples != CHV_8BIT_GAMMA_MAX_VALS) { + DRM_ERROR("Incorrect number of samplesreceived\n");
(quoted diff) +2
-0+ goto release_memory; + }
This should be checked before the property is updated.
Quoted 7 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ /* First, disable CGM Gamma, if already set */ + cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe)); + cgm_control_reg &= ~CGM_GAMMA_EN; + I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg); + + /* Enable (Legacy) Gamma on Pipe gamma_data.__obj_id */ + palette = _PIPE_GAMMA_BASE(pipe);
The comment is misleading. pipe is calculated from crtc->pipe, not gamma_data.__obj_id.
Also, should all these operations be performed under vblank evasion?
Quoted 9 lines
Review
Quoted 9 lines
+ } else if (
gamma_data->gamma_precision==I915_GAMMA_PRECISION_10BIT) {(quoted diff) +3
-0+ + if (num_samples != CHV_10BIT_GAMMA_MAX_VALS) { + DRM_ERROR("Incorrect number of samplesreceived\n");
(quoted diff) +3
-0+ ret = -EINVAL; + goto release_memory; + }
Same comment.
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* Enable (CGM) Gamma on Pipe gamma_data.__obj_id */ + cgm_gamma_reg = _PIPE_GAMMA_BASE(pipe);
Same comment.
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+release_memory: + + /* kfree is NULL protected */
Probably no need to comment this.
Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ kfree(correction_values); + kfree(gamma_data);
gamma_data is the blob data; you cannot free this. If you ever try to set the same gamma twice, the kernel will OOPS.
Quoted 7 lines
Quoted 7 lines
(quoted diff) +7
-0+ return ret; +} + +int intel_color_manager_set_gamma(struct drm_device *dev, + struct drm_mode_object *obj, uint64_t blob_id) +{ + struct drm_crtc *crtc = obj_to_crtc(obj);
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +8
-0+ + if (IS_CHERRYVIEW(dev)) + return chv_set_gamma(dev, blob_id, crtc); + else + DRM_ERROR("This platform is not yet supported\n"); + + return -EINVAL; +}
If a platform is not supported, then it should not export the gamma property to userspace.
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+struct rgb_pixel { + u16 red; + u16 green; + u16 blue; +};
The name of rgb_pixel here is quite generic, especially as 16bpc is still quite unusual.
Cheers,
Daniel
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 5/7] drm/i915: Add pipe level Gamma correction for CHV/BSW
Hi Daniel,
Thanks for the review.
Please find my comments inline.
Regards
Shashank
Quoted 26 lines · Daniel Stone
Hi,
Quoted 9 lines · Sonika
Review
Quoted 5 lines · Kausal Malladi
(quoted diff) +5
-0+int drm_mode_crtc_update_color_property(struct drm_device *dev, + struct drm_property_blob **blob, + size_t length, const void *color_data, + struct drm_mode_object *obj_holds_id, + struct drm_property *prop_holds_id)This can be simplified.. No need to pass so many params.
Quoted 1 line
Quoted 13 lines
Review
Quoted 10 lines
(quoted diff) +5
-0+{ + int ret; + + ret = drm_property_replace_global_blob(dev, + blob, length, color_data, obj_holds_id,
prop_holds_id);(quoted diff) +4
-0+ + return ret; +} +Split the patch to add drm specific changes in a separate patch. Also you need to export this function.
Quoted 4 lines
Or just remove the function entirely. It literally adds no value, and is just an alias for
drm_property_replace_global_blob. So just use that directly.
This function(drm_property_replace_global_blob) is a static function
and I can see few other properties have created wrapper function in this
file built around it (like path_property, edid_prop etc), so seems like that's the right way to do it. Do you still think we should remove the wrapper ?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5
-0+int chv_set_gamma(struct drm_device *dev, uint64_t blob_id, + struct drm_crtc *crtc) +{ + struct drm_intel_gamma *gamma_data; + struct drm_i915_private *dev_priv = dev->dev_private;
Quoted 8 lines
Quoted 6 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ struct drm_property_blob *blob; + struct drm_mode_config *config = &dev->mode_config; + + u32 cgm_control_reg = 0; + u32 cgm_gamma_reg = 0; + u32 reg, val, pipe;pipe should be an enum pipe.
Got it.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
+ u16 red, green, blue;
Isn't this the literal definition of struct
rgb_pixel, which you added separately in this series?
Yes, they are same, but we are using these local variables to shift/adjust according to the Palette register format, so thought it would be more readable if we make direct u16 variables
Quoted 15 lines
Quoted 13 lines
Review
Quoted 13 lines
(quoted diff) +12
-0+ if (gamma_data->gamma_precision == I915_GAMMA_PRECISION_UNKNOWN) { + + /* Disable Gamma functionality on Pipe - CGM Block */ + cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe)); + cgm_control_reg &= ~CGM_GAMMA_EN; + I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg); + + DRM_DEBUG_DRIVER("Gamma disabled on Pipe %c\n", + pipe_name(pipe)); + ret = 0; + goto release_memory; + }This branch never updates the property.
Oops, thanks for catching this.
Quoted 8 lines
Quoted 6 lines
Review
Quoted 6 lines
(quoted diff) +5
-0+ if (pipe >= CHV_MAX_PIPES) { + DRM_ERROR("Incorrect Pipe ID\n"); + ret = -EFAULT; + goto release_memory; + }How could this ever happen? This should be a
WARN_ONat least.
In the first design, user space was sending this variable, so a check was required. But then we changed the design, and kept the check :). We will remove this.
Quoted 28 lines
Quoted 15 lines
Quoted 5 lines
(quoted diff) +4
-0+ correction_values = kzalloc(length, GFP_KERNEL); + if (!correction_values) { + DRM_ERROR("Out of Memory\n"); + ret = -ENOMEM;Review
Quoted 10 lines
(quoted diff) +10
-0+ goto release_memory; + } + + ret = copy_from_user((void *)correction_values, + (const void __user *)gamma_data->gamma_ptr, length); + if (ret) { + DRM_ERROR("Error copying user data\n"); + ret = -EFAULT; + goto release_memory; + }I think I've managed to work out the userspace API now:
- allocatedrm_intel_gammastructure
- allocate correction values
- insert pointer to correction values into gamma structure
- create blob with pointer to gamma structureThis seems pretty backwards. The correction values - the large data we need to avoid copying around - is what should be a blob property. With your approach, the correction data (big) will be copied quite a few times, where the supporting structure (very small) will never be copied.
Quoted 4 lines
At the very least, the correction data must be a blob property. I don't think there is much use in having
drm_intel_gammaitself be a blob property, but I can see why you might want it to be.
Yes, right, that will be the better way. We were slightly unclear about the best way to use the whole set_blob stuff, so this dint go well. Now we are planning to do it like this:
1. set_blob_ioctl() to set the gamma_correction values, get the blob_id
2. Add a new variable blob_id in drm_intel_gamma struct
3. Pack the gamma_struct, and send that as set_porperty value.
Does it sound better to you now ?
Quoted 5 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ ret = drm_mode_crtc_update_color_property(dev, + &crtc->gamma_blob, length, (void *) correction_values, + &crtc->base, config->gamma_property);As discussed, this function is a pure alias, and can be removed.
Same explanation as previous.
Quoted 10 lines
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +4
-0+ if (gamma_data->gamma_precision == I915_GAMMA_PRECISION_LEGACY) { + + if (num_samples != CHV_8BIT_GAMMA_MAX_VALS) { + DRM_ERROR("Incorrect number of samplesreceived\n");
(quoted diff) +2
-0+ goto release_memory; + }This should be checked before the property is updated.
Yep, Got it. update property should happen in the end, after the last check.
Quoted 11 lines
Quoted 8 lines
Review
Quoted 8 lines
(quoted diff) +7
-0+ /* First, disable CGM Gamma, if already set */ + cgm_control_reg = I915_READ(_PIPE_CGM_CONTROL(pipe)); + cgm_control_reg &= ~CGM_GAMMA_EN; + I915_WRITE(_PIPE_CGM_CONTROL(pipe), cgm_control_reg); + + /* Enable (Legacy) Gamma on Pipe gamma_data.__obj_id */ + palette = _PIPE_GAMMA_BASE(pipe);The comment is misleading. pipe is calculated from
crtc->pipe, not gamma_data.__obj_id.
Yep, agree. Will change this.
Quoted 2 lines
Also, should all these operations be performed under vblank evasion?
Currently, due to missing set_crtc infrastructure, we are not planning to make the atomicity as primary target. Once the infrastructure is ready, we will move on to that, and the fwk will take care of that.
Quoted 11 lines
Quoted 10 lines
Review
Quoted 10 lines
+ } else if (
gamma_data->gamma_precision==I915_GAMMA_PRECISION_10BIT) {(quoted diff) +3
-0+ + if (num_samples != CHV_10BIT_GAMMA_MAX_VALS) { + DRM_ERROR("Incorrect number of samplesreceived\n");
(quoted diff) +3
-0+ ret = -EINVAL; + goto release_memory; + }
Quoted 1 line
Same comment.
Got it.
Quoted 5 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ /* Enable (CGM) Gamma on Pipe gamma_data.__obj_id */ + cgm_gamma_reg = _PIPE_GAMMA_BASE(pipe);Same comment.
Got it.
Quoted 6 lines
Quoted 4 lines
Review
Quoted 4 lines
(quoted diff) +3
-0+release_memory: + + /* kfree is NULL protected */Probably no need to comment this.
I remember receiving comments for this long back, but yeah. :)
Quoted 6 lines
Quoted 3 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ kfree(correction_values); + kfree(gamma_data);
gamma_datais the blob data; you cannot free this. If you ever try to set the same gamma twice, the kernel will OOPS.
Oops, yes, this was bad. There was a mistake while allocating gamma_data, it doesnt need that.
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
(quoted diff) +10
-0+ return ret; +} + +int intel_color_manager_set_gamma(struct drm_device *dev, + struct drm_mode_object *obj, uint64_t blob_id) +{ + struct drm_crtc *crtc = obj_to_crtc(obj); + + if (IS_CHERRYVIEW(dev)) + return chv_set_gamma(dev, blob_id, crtc);
Quoted 8 lines
Quoted 5 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+ else + DRM_ERROR("This platform is not yet supported\n"); + + return -EINVAL; +}If a platform is not supported, then it should not export the gamma property to userspace.
The idea is to extend this fwk to other platforms slowly. but we can remove the error message.
Quoted 9 lines
Quoted 6 lines
Review
Quoted 6 lines
(quoted diff) +5
-0+struct rgb_pixel { + u16 red; + u16 green; + u16 blue; +};The name of
rgb_pixelhere is quite generic, especially as 16bpc is still quite unusual.
mostly 10.6 gamma format or 16.16 CSC.
Quoted 4 lines
Cheers,
Daniel
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
RE: [PATCH 5/7] drm/i915: Add pipe level Gamma correction for CHV/BSW
In reply to Jindal, SonikaThanks for the review Sonika,
We will incorporate the review comments and send the updated patch set soon.
Regards
Shashank
-----Original Message-----
From: Jindal, Sonika
Sent: Tuesday, June 02, 2015 5:08 PM
To: Malladi, Kausal; Roper, Matthew D; Barnes, Jesse; Lespiau, Damien; R, Durgadoss; Purushothaman, Vijay A; [email protected]; [email protected]
Cc: Vetter, Daniel; Sharma, Shashank; Kamath, Sunil; Mukherjee, Indranil; [email protected]; R, Dhanya p; Palleti, Avinash Reddy
Subject: Re: [PATCH 5/7] drm/i915: Add pipe level Gamma correction for CHV/BSW
Quoted 25 lines · Kausal Malladi
From: Kausal Malladi <[email protected]>
This patch does the following:
1. Adds the core function to program Gamma correction values for CHV/BSW platform
2. Adds Gamma correction macros/defines 3. Addsdrm_mode_crtc_update_color_propertyfunction, which replaces the old blob for the property with the new one 4. Adds a pointer to
hold blob for Gamma property indrm_crtcSigned-off-by Shashank Sharma <[email protected]>Signed-off-by Kausal Malladi <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 14 ++ drivers/gpu/drm/i915/intel_color_manager.c | 194 ++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_color_manager.h | 61 +++++++++ drivers/gpu/drm/i915/intel_display.c | 9 +- include/drm/drm_crtc.h | 8 ++ 5 files changed, 285 insertions(+), 1 deletion(-)drivers/gpu/drm/drm_crtc.c +0
-0
drivers/gpu/drm/drm_crtc.c int drm_mode_connector_set_tile_property(struct drm_connector *connector) · line 4698
Quoted 8 lines
drivers/gpu/drm/drm_crtc.c +5
-0@@ -4691,6 +4691,20 @@ int drm_mode_connector_set_tile_property(struct drm_connector *connector) }EXPORT_SYMBOL (drm_mode_connector_set_tile_property); +int drm_mode_crtc_update_color_property (struct drm_device *dev, +struct drm_property_blob **blob, +size_t length,const void *color_data, +struct drm_mode_object *obj_holds_id, +struct drm_property *prop_holds_id)
This can be simplified.. No need to pass so many params.
drivers/gpu/drm/drm_crtc.c int drm_mode_connector_set_tile_property(struct drm_connector *connector) · line 4707
Quoted 9 lines
drivers/gpu/drm/drm_crtc.c +9
-0+{ +int ret; + + ret =drm_property_replace_global_blob (dev, + blob, length, color_data, obj_holds_id, prop_holds_id); + +return ret; +} +
Split the patch to add drm specific changes in a separate patch. Also you need to export this function.
Will review the rest of the file in some time.
Regards,
Sonika
Quoted 323 lines
drivers/gpu/drm/drm_crtc.c +0
-0/** * drm_mode_connector_update_edid_property - update the edid property of a connector * @connector: drm connector drivers/gpu/drm/i915/intel_color_manager.c +194
-0@@ -27,6 +27,200 @@#include "intel_color_manager.h" +int chv_set_gamma (struct drm_device *dev,uint64_t blob_id, +struct drm_crtc *crtc) +{ +struct drm_intel_gamma *gamma_data; +struct drm_i915_private *dev_priv = dev->dev_private; +struct drm_property_blob *blob; +struct drm_mode_config *config = &dev->mode_config; + +u32 cgm_control_reg =0 ; +u32 cgm_gamma_reg =0 ; +u32 reg, val, pipe; +u16 red, green, blue; +struct rgb_pixel correct_rgb; +u32 count =0 ; +struct rgb_pixel *correction_values =NULL ; +u32 num_samples; +u32 word; +u32 palette; +int ret =0 , length; + + blob =drm_property_lookup_blob (dev, blob_id); +if (!blob) { +DRM_ERROR ("Invalid Blob ID\n" ); +return -EINVAL ; + } + + gamma_data =kzalloc (sizeof (struct drm_intel_gamma ),GFP_KERNEL ); +if (!gamma_data) { +DRM_ERROR ("Memory unavailable\n" ); +return -ENOMEM ; + } + gamma_data = (struct drm_intel_gamma *)blob->data; + pipe =to_intel_crtc (crtc)->pipe; + num_samples = gamma_data->num_samples; + length = num_samples *sizeof (struct rgb_pixel ); + +if (gamma_data->gamma_precision ==I915_GAMMA_PRECISION_UNKNOWN ) { + +/* Disable Gamma functionality on Pipe - CGM Block */ + cgm_control_reg =I915_READ (_PIPE_CGM_CONTROL (pipe)); + cgm_control_reg &= ~CGM_GAMMA_EN ; +I915_WRITE (_PIPE_CGM_CONTROL (pipe), cgm_control_reg); + +DRM_DEBUG_DRIVER ("Gamma disabled on Pipe %c\n" , +pipe_name (pipe)); + ret =0 ; + goto release_memory; + } + +if (pipe >=CHV_MAX_PIPES ) { +DRM_ERROR ("Incorrect Pipe ID\n" ); + ret = -EFAULT ; + goto release_memory; + } + + correction_values =kzalloc (length,GFP_KERNEL ); +if (!correction_values) { +DRM_ERROR ("Out of Memory\n" ); + ret = -ENOMEM ; + goto release_memory; + } + + ret =copy_from_user ((void *)correction_values, + (const void __user *)gamma_data->gamma_ptr, length); +if (ret) { +DRM_ERROR ("Error copying user data\n" ); + ret = -EFAULT ; + goto release_memory; + } + + ret =drm_mode_crtc_update_color_property (dev, + &crtc->gamma_blob, length, (void *) correction_values, + &crtc->base, config->gamma_property); +if (ret) { +DRM_ERROR ("Error updating Gamma blob\n" ); + ret = -EFAULT ; + goto release_memory; + } + +if (gamma_data->gamma_precision ==I915_GAMMA_PRECISION_LEGACY ) { + +if (num_samples !=CHV_8BIT_GAMMA_MAX_VALS ) { +DRM_ERROR ("Incorrect number of samples received\n" ); + goto release_memory; + } + +/* First, disable CGM Gamma, if already set */ + cgm_control_reg =I915_READ (_PIPE_CGM_CONTROL (pipe)); + cgm_control_reg &= ~CGM_GAMMA_EN ; +I915_WRITE (_PIPE_CGM_CONTROL (pipe), cgm_control_reg); + +/* Enable (Legacy) Gamma on Pipe gamma_data.__obj_id */ + palette =_PIPE_GAMMA_BASE (pipe); + + count =0 ; +while (count < num_samples) { + correct_rgb = correction_values[count]; + blue = correct_rgb.blue; + green = correct_rgb.green; + red = correct_rgb.red; + + blue = blue >>CHV_8BIT_GAMMA_MSB_SHIFT ; + green = green >>CHV_8BIT_GAMMA_MSB_SHIFT ; + red = red >>CHV_8BIT_GAMMA_MSB_SHIFT ; + +/* Red (23:16), Green (15:8), Blue (7:0) */ + word = (red <<CHV_8BIT_GAMMA_SHIFT_RED_REG ) | + (green << +CHV_8BIT_GAMMA_SHIFT_GREEN_REG ) | + blue; +I915_WRITE (palette, word); + + palette +=4 ; + count++; + } + reg =PIPECONF (pipe); + val =I915_READ (reg) |PIPECONF_GAMMA ; +I915_WRITE (reg, val); + +DRM_DEBUG_DRIVER ("Gamma LUT loaded successfully for Pipe %c\n" , +pipe_name (pipe)); + ret =0 ; + goto release_memory; + }else if (gamma_data->gamma_precision == +I915_GAMMA_PRECISION_10BIT ) { + +if (num_samples !=CHV_10BIT_GAMMA_MAX_VALS ) { +DRM_ERROR ("Incorrect number of samples received\n" ); + ret = -EINVAL ; + goto release_memory; + } + +/* Enable (CGM) Gamma on Pipe gamma_data.__obj_id */ + cgm_gamma_reg =_PIPE_GAMMA_BASE (pipe); + + count =0 ; +while (count < num_samples) { + correct_rgb = correction_values[count]; + blue = correct_rgb.blue; + green = correct_rgb.green; + red = correct_rgb.red; + + blue = blue >>CHV_10BIT_GAMMA_MSB_SHIFT ; + green = green >>CHV_10BIT_GAMMA_MSB_SHIFT ; + red = red >>CHV_10BIT_GAMMA_MSB_SHIFT ; + +/* Green (25:16) and Blue (9:0) to be written */ + word = (green <<CHV_GAMMA_SHIFT_GREEN ) | blue; +I915_WRITE (cgm_gamma_reg, word); + cgm_gamma_reg +=4 ; + +/* Red (9:0) to be written */ + word = red; +I915_WRITE (cgm_gamma_reg, word); + + cgm_gamma_reg +=4 ; + count++; + } + +I915_WRITE (_PIPE_CGM_CONTROL (pipe), +I915_READ (_PIPE_CGM_CONTROL (pipe)) + |CGM_GAMMA_EN ); + +DRM_DEBUG_DRIVER ("Gamma LUT loaded successfully for Pipe %c\n" , +pipe_name (pipe)); + ret =0 ; + goto release_memory; + }else { +DRM_ERROR ("Invalid gamma_level received\n" ); + ret = -EFAULT ; + goto release_memory; + } + +release_memory: + +/* kfree is NULL protected */ +kfree (correction_values); +kfree (gamma_data); + +return ret; +} + +int intel_color_manager_set_gamma (struct drm_device *dev, +struct drm_mode_object *obj,uint64_t blob_id) { +struct drm_crtc *crtc =obj_to_crtc (obj); + +if (IS_CHERRYVIEW (dev)) +return chv_set_gamma (dev, blob_id, crtc); +else +DRM_ERROR ("This platform is not yet supported\n" ); + +return -EINVAL ; +} +void intel_color_manager_attach (struct drm_device *dev,struct drm_mode_object *mode_obj) {drivers/gpu/drm/i915/intel_color_manager.h +61
-0@@ -27,8 +27,69 @@#include <drm/drmP.h> #include <drm/drm_crtc_helper.h> +#include "i915_drv.h" + +/* Color Management macros for Gamma */ +#define I915_GAMMA_FLAG_DEGAMMA (1 << 0) +#define I915_PIPE_GAMMA (1 << 0) +#define I915_PLANE_GAMMA (1 << 1) +#define I915_GAMMA_PRECISION_UNKNOWN 0 +#define I915_GAMMA_PRECISION_CURRENT 0xFFFFFFFF +#define I915_GAMMA_PRECISION_LEGACY (1 << 0) +#define I915_GAMMA_PRECISION_10BIT (1 << 1) +#define I915_GAMMA_PRECISION_12BIT (1 << 2) +#define I915_GAMMA_PRECISION_14BIT (1 << 3) +#define I915_GAMMA_PRECISION_16BIT (1 << 4) + +#define CHV_MAX_PIPES 3 +#define CHV_DISPLAY_BASE 0x180000 + +struct rgb_pixel { +u16 red; +u16 green; +u16 blue; +}; + +/* CHV CGM Block */ +/* Bit 2 to be enabled in CGM block for CHV */ +#define CGM_GAMMA_EN 4 + +/* Gamma */ +#define CHV_GAMMA_VALS 257 +#define CHV_10BIT_GAMMA_MAX_INDEX 256 +#define CHV_8BIT_GAMMA_MAX_INDEX 255 +#define CHV_10BIT_GAMMA_MSB_SHIFT 6 +#define CHV_GAMMA_EVEN_MASK 0xFF +#define CHV_GAMMA_SHIFT_BLUE 0 +#define CHV_GAMMA_SHIFT_GREEN 16 +#define CHV_GAMMA_SHIFT_RED 0 +#define CHV_GAMMA_ODD_SHIFT 8 +#define CHV_CLRMGR_GAMMA_GCMAX_SHIFT 17 +#define CHV_GAMMA_GCMAX_MASK 0x1FFFF +#define CHV_GAMMA_GCMAX_MAX 0x400 +#define CHV_10BIT_GAMMA_MAX_VALS (CHV_10BIT_GAMMA_MAX_INDEX + 1) +#define CHV_8BIT_GAMMA_MAX_VALS (CHV_8BIT_GAMMA_MAX_INDEX + 1) +#define CHV_8BIT_GAMMA_MSB_SHIFT 8 +#define CHV_8BIT_GAMMA_SHIFT_GREEN_REG 8 +#define CHV_8BIT_GAMMA_SHIFT_RED_REG 16 + +/* CGM Registers */ +#define CGM_OFFSET 0x2000 +#define GAMMA_OFFSET 0x2000 +#define PIPEA_CGM_CONTROL (CHV_DISPLAY_BASE + 0x67A00) +#define PIPEA_CGM_GAMMA_MIN (CHV_DISPLAY_BASE + 0x67000) +#define _PIPE_CGM_CONTROL (pipe) \ + (PIPEA_CGM_CONTROL + (pipe * CGM_OFFSET)) #define +_PIPE_GAMMA_BASE (pipe) \ + (PIPEA_CGM_GAMMA_MIN + (pipe *GAMMA_OFFSET )) /* Generic Function prototypes */int intel_color_manager_init (struct drm_device *dev);void intel_color_manager_attach (struct drm_device *dev,struct drm_mode_object *mode_obj); +extern int intel_color_manager_set_gamma (struct drm_device *dev, +struct drm_mode_object *obj,uint64_t blob_id); + +/* Platform specific function prototypes */ extern int +chv_set_gamma (struct drm_device *dev, +uint64_t blob_id,struct drm_crtc *crtc);drivers/gpu/drm/i915/intel_display.c +8
-1@@ -12981,7 +12981,14 @@ out:static int intel_crtc_set_property (struct drm_crtc *crtc,struct drm_property *property,uint64_t val) { -DRM_DEBUG_KMS ("Unknown crtc property '%s'\n" , property->name); +struct drm_device *dev = crtc->dev; +struct drm_mode_config *config = &dev->mode_config; + +if (property == config->gamma_property) +return intel_color_manager_set_gamma (dev, &crtc->base, val); +else +DRM_DEBUG_KMS ("Unknown crtc property '%s'\n" , property->name); +return -EINVAL ; }include/drm/drm_crtc.h index renamed from include/drm/drm_crtc.h +0
-04085339..654c098 100644
include/drm/drm_crtc.h +3
-0@@ -483,6 +483,9 @@ struct drm_crtc {* acquire context. */ struct drm_modeset_acquire_ctx *acquire_ctx; + +/* Color Management Blobs */ +struct drm_property_blob *gamma_blob; };/** @@ -1341,6 +1344,11 @@ extern void drm_mode_config_cleanup(struct drm_device *dev); extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
include/drm/drm_crtc.h extern void drm_mode_config_cleanup(struct drm_device *dev); · line 1354
Quoted 10 lines
include/drm/drm_crtc.h +5
-0const char *path);int drm_mode_connector_set_tile_property (struct drm_connector *connector); +extern int drm_mode_crtc_update_color_property (struct drm_device *dev, +struct drm_property_blob **blob, +size_t length,const void *color_data, +struct drm_mode_object *obj_holds_id, +struct drm_property *prop_holds_id);extern int drm_mode_connector_update_edid_property (struct drm_connector *connector,const struct edid *edid);
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 0/7] Color Manager Implementation
In reply to a message not in the archiveQuoted 3 lines · Kausal Malladi
From: Kausal Malladi <[email protected]>
This patch set adds color manager implementation in drm/i915 layer.
Is anyone working on tests/test plan?
Thanks,
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 0/7] Color Manager Implementation
Hi Damien,
Yes we are getting the IGT's ready, and already we have a test tool to apply CSC/Gamma already, which we used for ULT. As discussed in the parallel forums, we will finally use Chrome UI to test the end-to-end UI level effects
Regards
Shashank
-----Original Message-----
From: Lespiau, Damien
Sent: Tuesday, June 02, 2015 5:31 PM
To: Malladi, Kausal
Cc: Roper, Matthew D; Barnes, Jesse; Jindal, Sonika; R, Durgadoss; Purushothaman, Vijay A; [email protected]; [email protected]; Vetter, Daniel; Sharma, Shashank; Kamath, Sunil; Mukherjee, Indranil; [email protected]; R, Dhanya p; Palleti, Avinash Reddy
Subject: Re: [PATCH 0/7] Color Manager Implementation
Quoted 3 lines · Kausal Malladi
From: Kausal Malladi <[email protected]>
This patch set adds color manager implementation in drm/i915 layer.
Is anyone working on tests/test plan?
Thanks,
Signature · 5 lines
Damien _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx