drm: automatic legacy gamma support
Subsystems (23)
v4 cover drm: automatic legacy gamma support
Hi,
Yet another try. This time I don't touch the drm_fb_helper.c at all, except adding a FIXME comment. Now everything is inside drm_color_mgmt.c.
Tomi
Tomi Valkeinen (2):
drm: automatic legacy gamma support
drm: add legacy support for using degamma for gamma
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 1 - .../gpu/drm/arm/display/komeda/komeda_crtc.c | 1 - drivers/gpu/drm/arm/malidp_crtc.c | 1 - drivers/gpu/drm/armada/armada_crtc.c | 1 - drivers/gpu/drm/ast/ast_mode.c | 1 - .../gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c | 1 - drivers/gpu/drm/drm_atomic_helper.c | 70 ---------- drivers/gpu/drm/drm_color_mgmt.c | 125 ++++++++++++++++-- drivers/gpu/drm/drm_fb_helper.c | 5 + drivers/gpu/drm/i915/display/intel_display.c | 1 - drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 - drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 1 - drivers/gpu/drm/nouveau/dispnv50/head.c | 2 - drivers/gpu/drm/omapdrm/omap_crtc.c | 1 - drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 - drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 1 - drivers/gpu/drm/stm/ltdc.c | 1 - drivers/gpu/drm/vc4/vc4_crtc.c | 1 - drivers/gpu/drm/vc4/vc4_txp.c | 1 - include/drm/drm_atomic_helper.h | 4 - 20 files changed, 121 insertions(+), 101 deletions(-)
Signature · 7 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 1/2 drm: automatic legacy gamma support
To support legacy gamma ioctls the drivers need to set drm_crtc_funcs.gamma_set either to a custom implementation or to drm_atomic_helper_legacy_gamma_set. Most of the atomic drivers do the latter.
We can simplify this by making the core handle it automatically.
Move the drm_atomic_helper_legacy_gamma_set() functionality into drm_color_mgmt.c to make drm_mode_gamma_set_ioctl() use drm_crtc_funcs.gamma_set if set or GAMMA_LUT property if not.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 1 - .../gpu/drm/arm/display/komeda/komeda_crtc.c | 1 - drivers/gpu/drm/arm/malidp_crtc.c | 1 - drivers/gpu/drm/armada/armada_crtc.c | 1 - drivers/gpu/drm/ast/ast_mode.c | 1 - .../gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c | 1 - drivers/gpu/drm/drm_atomic_helper.c | 70 ----------- drivers/gpu/drm/drm_color_mgmt.c | 111 ++++++++++++++++-- drivers/gpu/drm/i915/display/intel_display.c | 1 - drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 - drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 1 - drivers/gpu/drm/nouveau/dispnv50/head.c | 2 - drivers/gpu/drm/omapdrm/omap_crtc.c | 1 - drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 - drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 1 - drivers/gpu/drm/stm/ltdc.c | 1 - drivers/gpu/drm/vc4/vc4_crtc.c | 1 - drivers/gpu/drm/vc4/vc4_txp.c | 1 - include/drm/drm_atomic_helper.h | 4 - 19 files changed, 102 insertions(+), 101 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0 -1
@@ -5396,7 +5396,6 @@ static void dm_disable_vblank(struct drm_crtc *crtc)static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = { .reset = dm_crtc_reset_state, .destroy = amdgpu_dm_crtc_destroy, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .atomic_duplicate_state = dm_crtc_duplicate_state,
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +0 -1
@@ -550,7 +550,6 @@ static void komeda_crtc_vblank_disable(struct drm_crtc *crtc) }static const struct drm_crtc_funcs komeda_crtc_funcs = { - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,
drivers/gpu/drm/arm/malidp_crtc.c +0 -1
@@ -510,7 +510,6 @@ static void malidp_crtc_disable_vblank(struct drm_crtc *crtc) }static const struct drm_crtc_funcs malidp_crtc_funcs = { - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,
drivers/gpu/drm/armada/armada_crtc.c +0 -1
@@ -820,7 +820,6 @@ static const struct drm_crtc_funcs armada_crtc_funcs = { .cursor_set = armada_drm_crtc_cursor_set, .cursor_move = armada_drm_crtc_cursor_move, .destroy = armada_drm_crtc_destroy, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,
drivers/gpu/drm/ast/ast_mode.c +0 -1
@@ -903,7 +903,6 @@ static void ast_crtc_atomic_destroy_state(struct drm_crtc *crtc,static const struct drm_crtc_funcs ast_crtc_funcs = { .reset = ast_crtc_reset, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c +0 -1
@@ -473,7 +473,6 @@ static const struct drm_crtc_funcs atmel_hlcdc_crtc_funcs = { .atomic_destroy_state = atmel_hlcdc_crtc_destroy_state, .enable_vblank = atmel_hlcdc_crtc_enable_vblank, .disable_vblank = atmel_hlcdc_crtc_disable_vblank, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };int atmel_hlcdc_crtc_create (struct drm_device *dev)
drivers/gpu/drm/drm_atomic_helper.c +0 -70
76 lines not on this page · raw message
drivers/gpu/drm/drm_color_mgmt.c +102 -9
147 lines not on this page · raw message
drivers/gpu/drm/i915/display/intel_display.c +0 -1
@@ -16879,7 +16879,6 @@ intel_cursor_plane_create(struct drm_i915_private *dev_priv, }#define INTEL_CRTC_FUNCS \ - .gamma_set = drm_atomic_helper_legacy_gamma_set, \ .set_config = drm_atomic_helper_set_config, \ .destroy = intel_crtc_destroy, \ .page_flip = drm_atomic_helper_page_flip, \
drivers/gpu/drm/ingenic/ingenic-drm-drv.c +0 -2
@@ -774,8 +774,6 @@ static const struct drm_crtc_funcs ingenic_drm_crtc_funcs = { .enable_vblank = ingenic_drm_enable_vblank, .disable_vblank = ingenic_drm_disable_vblank, - - .gamma_set = drm_atomic_helper_legacy_gamma_set, };static const struct drm_plane_helper_funcs ingenic_drm_plane_helper_funcs = {
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +0 -1
@@ -619,7 +619,6 @@ static const struct drm_crtc_funcs mtk_crtc_funcs = { .reset = mtk_drm_crtc_reset, .atomic_duplicate_state = mtk_drm_crtc_duplicate_state, .atomic_destroy_state = mtk_drm_crtc_destroy_state, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .enable_vblank = mtk_drm_crtc_enable_vblank, .disable_vblank = mtk_drm_crtc_disable_vblank, };
drivers/gpu/drm/nouveau/dispnv50/head.c +0 -2
@@ -503,7 +503,6 @@ nv50_head_destroy(struct drm_crtc *crtc)static const struct drm_crtc_funcs nv50_head_func = { .reset = nv50_head_reset, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = nv50_head_destroy, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,
@@ -518,7 +517,6 @@ nv50_head_func = {static const struct drm_crtc_funcs nvd9_head_func = { .reset = nv50_head_reset, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = nv50_head_destroy, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,
drivers/gpu/drm/omapdrm/omap_crtc.c +0 -1
@@ -741,7 +741,6 @@ static const struct drm_crtc_funcs omap_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .destroy = omap_crtc_destroy, .page_flip = drm_atomic_helper_page_flip, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .atomic_duplicate_state = omap_crtc_duplicate_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, .atomic_set_property = omap_crtc_atomic_set_property,
drivers/gpu/drm/rcar-du/rcar_du_crtc.c +0 -1
@@ -1144,7 +1144,6 @@ static const struct drm_crtc_funcs crtc_funcs_gen3 = { .set_crc_source = rcar_du_crtc_set_crc_source, .verify_crc_source = rcar_du_crtc_verify_crc_source, .get_crc_sources = rcar_du_crtc_get_crc_sources, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };/* -----------------------------------------------------------------------------
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +0 -1
@@ -1643,7 +1643,6 @@ static const struct drm_crtc_funcs vop_crtc_funcs = { .disable_vblank = vop_crtc_disable_vblank, .set_crc_source = vop_crtc_set_crc_source, .verify_crc_source = vop_crtc_verify_crc_source, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };static void vop_fb_unref_worker (struct drm_flip_work *work,void *val)
drivers/gpu/drm/stm/ltdc.c +0 -1
@@ -713,7 +713,6 @@ static const struct drm_crtc_funcs ltdc_crtc_funcs = { .enable_vblank = ltdc_crtc_enable_vblank, .disable_vblank = ltdc_crtc_disable_vblank, .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };/*
drivers/gpu/drm/vc4/vc4_crtc.c +0 -1
@@ -884,7 +884,6 @@ static const struct drm_crtc_funcs vc4_crtc_funcs = { .reset = vc4_crtc_reset, .atomic_duplicate_state = vc4_crtc_duplicate_state, .atomic_destroy_state = vc4_crtc_destroy_state, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .enable_vblank = vc4_enable_vblank, .disable_vblank = vc4_disable_vblank, .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,
drivers/gpu/drm/vc4/vc4_txp.c +0 -1
@@ -382,7 +382,6 @@ static const struct drm_crtc_funcs vc4_txp_crtc_funcs = { .reset = vc4_crtc_reset, .atomic_duplicate_state = vc4_crtc_duplicate_state, .atomic_destroy_state = vc4_crtc_destroy_state, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .enable_vblank = vc4_txp_enable_vblank, .disable_vblank = vc4_txp_disable_vblank, };
include/drm/drm_atomic_helper.h +0 -4
@@ -147,10 +147,6 @@ int drm_atomic_helper_page_flip_target(uint32_t flags, uint32_t target, struct drm_modeset_acquire_ctx *ctx); -int drm_atomic_helper_legacy_gamma_set (struct drm_crtc *crtc, -u16 *red,u16 *green,u16 *blue, -uint32_t size, -struct drm_modeset_acquire_ctx *ctx);/** * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
Signature · 7 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Tomi,
Thank you for the patch.
Quoted 5 lines · Tomi Valkeinen
To support legacy gamma ioctls the drivers need to set drm_crtc_funcs.gamma_set either to a custom implementation or to
drm_atomic_helper_legacy_gamma_set. Most of the atomic drivers do the latter.
Quoted 7 lines
We can simplify this by making the core handle it automatically.
Move the
drm_atomic_helper_legacy_gamma_set()functionality intodrm_color_mgmt.cto makedrm_mode_gamma_set_ioctl()use drm_crtc_funcs.gamma_set if set orGAMMA_LUTproperty if not.Signed-off-by Tomi Valkeinen <[email protected]>
Quoted 476 lines
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 1 - .../gpu/drm/arm/display/komeda/komeda_crtc.c | 1 - drivers/gpu/drm/arm/malidp_crtc.c | 1 - drivers/gpu/drm/armada/armada_crtc.c | 1 - drivers/gpu/drm/ast/ast_mode.c | 1 - .../gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c | 1 - drivers/gpu/drm/drm_atomic_helper.c | 70 ----------- drivers/gpu/drm/drm_color_mgmt.c | 111 ++++++++++++++++-- drivers/gpu/drm/i915/display/intel_display.c | 1 - drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 - drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 1 - drivers/gpu/drm/nouveau/dispnv50/head.c | 2 - drivers/gpu/drm/omapdrm/omap_crtc.c | 1 - drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 - drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 1 - drivers/gpu/drm/stm/ltdc.c | 1 - drivers/gpu/drm/vc4/vc4_crtc.c | 1 - drivers/gpu/drm/vc4/vc4_txp.c | 1 - include/drm/drm_atomic_helper.h | 4 - 19 files changed, 102 insertions(+), 101 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-1@@ -5396,7 +5396,6 @@ static void dm_disable_vblank(struct drm_crtc *crtc)static const struct drm_crtc_funcs amdgpu_dm_crtc_funcs = { .reset = dm_crtc_reset_state, .destroy = amdgpu_dm_crtc_destroy, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .atomic_duplicate_state = dm_crtc_duplicate_state,drivers/gpu/drm/arm/display/komeda/komeda_crtc.c +0
-1@@ -550,7 +550,6 @@ static void komeda_crtc_vblank_disable(struct drm_crtc *crtc) }static const struct drm_crtc_funcs komeda_crtc_funcs = { - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,drivers/gpu/drm/arm/malidp_crtc.c +0
-1@@ -510,7 +510,6 @@ static void malidp_crtc_disable_vblank(struct drm_crtc *crtc) }static const struct drm_crtc_funcs malidp_crtc_funcs = { - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,drivers/gpu/drm/armada/armada_crtc.c +0
-1@@ -820,7 +820,6 @@ static const struct drm_crtc_funcs armada_crtc_funcs = { .cursor_set = armada_drm_crtc_cursor_set, .cursor_move = armada_drm_crtc_cursor_move, .destroy = armada_drm_crtc_destroy, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip, .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state,drivers/gpu/drm/ast/ast_mode.c +0
-1@@ -903,7 +903,6 @@ static void ast_crtc_atomic_destroy_state(struct drm_crtc *crtc,static const struct drm_crtc_funcs ast_crtc_funcs = { .reset = ast_crtc_reset, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = drm_crtc_cleanup, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c +0
-1@@ -473,7 +473,6 @@ static const struct drm_crtc_funcs atmel_hlcdc_crtc_funcs = { .atomic_destroy_state = atmel_hlcdc_crtc_destroy_state, .enable_vblank = atmel_hlcdc_crtc_enable_vblank, .disable_vblank = atmel_hlcdc_crtc_disable_vblank, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };int atmel_hlcdc_crtc_create (struct drm_device *dev)drivers/gpu/drm/drm_atomic_helper.c +0
-70@@ -3499,76 +3499,6 @@ int drm_atomic_helper_page_flip_target(struct drm_crtc *crtc, }EXPORT_SYMBOL (drm_atomic_helper_page_flip_target); -/** -* drm_atomic_helper_legacy_gamma_set - set the legacy gamma correction table -* @crtc: CRTC object -* @red: red correction table -* @green: green correction table -* @blue: green correction table -* @size: size of the tables -* @ctx: lock acquire context -* -* Implements support for legacy gamma correction table for drivers -* that support color management through the DEGAMMA_LUT/GAMMA_LUT -* properties. See drm_crtc_enable_color_mgmt() and the containing chapter for -* how the atomic color management and gamma tables work. -*/ -int drm_atomic_helper_legacy_gamma_set (struct drm_crtc *crtc, -u16 *red,u16 *green,u16 *blue, -uint32_t size, -struct drm_modeset_acquire_ctx *ctx) -{ -struct drm_device *dev = crtc->dev; -struct drm_atomic_state *state; -struct drm_crtc_state *crtc_state; -struct drm_property_blob *blob =NULL ; -struct drm_color_lut *blob_data; -int i, ret =0 ; -bool replaced; - - state =drm_atomic_state_alloc (crtc->dev); -if (!state) -return -ENOMEM ; - - blob =drm_property_create_blob (dev, -sizeof (struct drm_color_lut ) * size, -NULL ); -if (IS_ERR (blob)) { - ret =PTR_ERR (blob); - blob =NULL ; - goto fail; - } - -/* Prepare GAMMA_LUT with the legacy values. */ - blob_data = blob->data; -for (i =0 ; i < size; i++) { - blob_data[i].red = red[i]; - blob_data[i].green = green[i]; - blob_data[i].blue = blue[i]; - } - - state->acquire_ctx = ctx; - crtc_state =drm_atomic_get_crtc_state (state, crtc); -if (IS_ERR (crtc_state)) { - ret =PTR_ERR (crtc_state); - goto fail; - } - -/* Reset DEGAMMA_LUT and CTM properties. */ - replaced =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); - replaced |=drm_property_replace_blob (&crtc_state->ctm,NULL ); - replaced |=drm_property_replace_blob (&crtc_state->gamma_lut, blob); - crtc_state->color_mgmt_changed |= replaced; - - ret =drm_atomic_commit (state); - -fail: -drm_atomic_state_put (state); -drm_property_blob_put (blob); -return ret; -} -EXPORT_SYMBOL (drm_atomic_helper_legacy_gamma_set); -/** * drm_atomic_helper_bridge_propagate_bus_fmt() - Propagate output format to * the input end of a bridge drivers/gpu/drm/drm_color_mgmt.c +102
-9@@ -22,6 +22,7 @@#include <linux/uaccess.h> +#include <drm/drm_atomic.h> #include <drm/drm_color_mgmt.h> #include <drm/drm_crtc.h> #include <drm/drm_device.h> @@ -89,9 +90,8 @@* modes) appropriately. * * There is also support for a legacy gamma table, which is set up by calling -* drm_mode_crtc_set_gamma_size(). Drivers which support both should use -* drm_atomic_helper_legacy_gamma_set() to alias the legacy gamma ramp with the -* "GAMMA_LUT" property above. +* drm_mode_crtc_set_gamma_size(). The DRM core will then alias the legacy gamma +* ramp with "GAMMA_LUT". * * Support for different non RGB color encodings is controlled through * &drm_plane specific COLOR_ENCODING and COLOR_RANGE properties. They @@ -156,9 +156,6 @@ EXPORT_SYMBOL(drm_color_ctm_s31_32_to_qm_n);* optional. The gamma and degamma properties are only attached if * their size is not 0 and ctm_property is only attached if has_ctm is * true. -* -* Drivers should use drm_atomic_helper_legacy_gamma_set() to implement the -* legacy &drm_crtc_funcs.gamma_set callback. */ void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, uint degamma_lut_size,@@ -231,6 +228,102 @@ int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, }EXPORT_SYMBOL (drm_mode_crtc_set_gamma_size); +/** +* drm_crtc_supports_legacy_gamma - does the crtc support legacy gamma correction table +* @crtc: CRTC object +* +* Returns true/false if the given crtc supports setting the legacy gamma +* correction table. +*/ +static bool drm_crtc_supports_legacy_gamma (struct drm_crtc *crtc) +{ +uint32_t gamma_id = crtc->dev->mode_config.gamma_lut_property->base.id; + +if (!crtc->gamma_size) +return false; + +if (crtc->funcs->gamma_set) +return true; + +return !!drm_mode_obj_find_prop_id (&crtc->base, gamma_id); +} + +/** +* drm_crtc_legacy_gamma_set - set the legacy gamma correction table +* @crtc: CRTC object +* @red: red correction table +* @green: green correction table +* @blue: green correction table +* @size: size of the tables +* @ctx: lock acquire context +* +* Implements support for legacy gamma correction table for drivers +* that have set drm_crtc_funcs.gamma_set or that support color management +* through the DEGAMMA_LUT/GAMMA_LUT properties. See +* drm_crtc_enable_color_mgmt() and the containing chapter for +* how the atomic color management and gamma tables work. +* +* This function sets the gamma using drm_crtc_funcs.gamma_set if set, or +* alternatively using crtc color management properties. +*/ +static int drm_crtc_legacy_gamma_set (struct drm_crtc *crtc, +u16 *red,u16 *green,u16 *blue, +uint32_t size, +struct drm_modeset_acquire_ctx *ctx) +{ +struct drm_device *dev = crtc->dev; +struct drm_atomic_state *state; +struct drm_crtc_state *crtc_state; +struct drm_property_blob *blob; +struct drm_color_lut *blob_data; +int i, ret =0 ; +bool replaced; + +if (crtc->funcs->gamma_set) +return crtc->funcs->gamma_set (crtc, red, green, blue, size, ctx); + + state =drm_atomic_state_alloc (crtc->dev); +if (!state) +return -ENOMEM ; + + blob =drm_property_create_blob (dev, +sizeof (struct drm_color_lut ) * size, +NULL ); +if (IS_ERR (blob)) { + ret =PTR_ERR (blob); + blob =NULL ; + goto fail; + } + +/* Prepare GAMMA_LUT with the legacy values. */ + blob_data = blob->data; +for (i =0 ; i < size; i++) { + blob_data[i].red = red[i]; + blob_data[i].green = green[i]; + blob_data[i].blue = blue[i]; + } + + state->acquire_ctx = ctx; + crtc_state =drm_atomic_get_crtc_state (state, crtc); +if (IS_ERR (crtc_state)) { + ret =PTR_ERR (crtc_state); + goto fail; + } + +/* Set GAMMA_LUT and reset DEGAMMA_LUT and CTM */ + replaced =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); + replaced |=drm_property_replace_blob (&crtc_state->ctm,NULL ); + replaced |=drm_property_replace_blob (&crtc_state->gamma_lut, blob); + crtc_state->color_mgmt_changed |= replaced; + + ret =drm_atomic_commit (state); + +fail: +drm_atomic_state_put (state); +drm_property_blob_put (blob); +return ret; +} +/** * drm_mode_gamma_set_ioctl - set the gamma table * @dev: DRM device @@ -262,7 +355,7 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev,if (!crtc)return -ENOENT ; -if (crtc->funcs->gamma_set ==NULL ) +if (!drm_crtc_supports_legacy_gamma (crtc))return -ENOSYS ;/* memcpy into gamma store */ @@ -290,8 +383,8 @@ int drm_mode_gamma_set_ioctl(struct drm_device *dev, goto out; } - ret = crtc->funcs->gamma_set (crtc, r_base, g_base, b_base, - crtc->gamma_size, &ctx); + ret =drm_crtc_legacy_gamma_set (crtc, r_base, g_base, b_base, + crtc->gamma_size, &ctx); out:DRM_MODESET_LOCK_ALL_END (dev, ctx, ret);drivers/gpu/drm/i915/display/intel_display.c +0
-1@@ -16879,7 +16879,6 @@ intel_cursor_plane_create(struct drm_i915_private *dev_priv, }#define INTEL_CRTC_FUNCS \ - .gamma_set = drm_atomic_helper_legacy_gamma_set, \ .set_config = drm_atomic_helper_set_config, \ .destroy = intel_crtc_destroy, \ .page_flip = drm_atomic_helper_page_flip, \drivers/gpu/drm/ingenic/ingenic-drm-drv.c +0
-2@@ -774,8 +774,6 @@ static const struct drm_crtc_funcs ingenic_drm_crtc_funcs = { .enable_vblank = ingenic_drm_enable_vblank, .disable_vblank = ingenic_drm_disable_vblank, - - .gamma_set = drm_atomic_helper_legacy_gamma_set, };static const struct drm_plane_helper_funcs ingenic_drm_plane_helper_funcs = {drivers/gpu/drm/mediatek/mtk_drm_crtc.c +0
-1@@ -619,7 +619,6 @@ static const struct drm_crtc_funcs mtk_crtc_funcs = { .reset = mtk_drm_crtc_reset, .atomic_duplicate_state = mtk_drm_crtc_duplicate_state, .atomic_destroy_state = mtk_drm_crtc_destroy_state, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .enable_vblank = mtk_drm_crtc_enable_vblank, .disable_vblank = mtk_drm_crtc_disable_vblank, };drivers/gpu/drm/nouveau/dispnv50/head.c +0
-2@@ -503,7 +503,6 @@ nv50_head_destroy(struct drm_crtc *crtc)static const struct drm_crtc_funcs nv50_head_func = { .reset = nv50_head_reset, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = nv50_head_destroy, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,@@ -518,7 +517,6 @@ nv50_head_func = {static const struct drm_crtc_funcs nvd9_head_func = { .reset = nv50_head_reset, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .destroy = nv50_head_destroy, .set_config = drm_atomic_helper_set_config, .page_flip = drm_atomic_helper_page_flip,drivers/gpu/drm/omapdrm/omap_crtc.c +0
-1@@ -741,7 +741,6 @@ static const struct drm_crtc_funcs omap_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .destroy = omap_crtc_destroy, .page_flip = drm_atomic_helper_page_flip, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .atomic_duplicate_state = omap_crtc_duplicate_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, .atomic_set_property = omap_crtc_atomic_set_property,drivers/gpu/drm/rcar-du/rcar_du_crtc.c +0
-1@@ -1144,7 +1144,6 @@ static const struct drm_crtc_funcs crtc_funcs_gen3 = { .set_crc_source = rcar_du_crtc_set_crc_source, .verify_crc_source = rcar_du_crtc_verify_crc_source, .get_crc_sources = rcar_du_crtc_get_crc_sources, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };/* ----------------------------------------------------------------------------- drivers/gpu/drm/rockchip/rockchip_drm_vop.c +0
-1@@ -1643,7 +1643,6 @@ static const struct drm_crtc_funcs vop_crtc_funcs = { .disable_vblank = vop_crtc_disable_vblank, .set_crc_source = vop_crtc_set_crc_source, .verify_crc_source = vop_crtc_verify_crc_source, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };static void vop_fb_unref_worker (struct drm_flip_work *work,void *val)drivers/gpu/drm/stm/ltdc.c +0
-1@@ -713,7 +713,6 @@ static const struct drm_crtc_funcs ltdc_crtc_funcs = { .enable_vblank = ltdc_crtc_enable_vblank, .disable_vblank = ltdc_crtc_disable_vblank, .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp, - .gamma_set = drm_atomic_helper_legacy_gamma_set, };/* drivers/gpu/drm/vc4/vc4_crtc.c +0
-1@@ -884,7 +884,6 @@ static const struct drm_crtc_funcs vc4_crtc_funcs = { .reset = vc4_crtc_reset, .atomic_duplicate_state = vc4_crtc_duplicate_state, .atomic_destroy_state = vc4_crtc_destroy_state, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .enable_vblank = vc4_enable_vblank, .disable_vblank = vc4_disable_vblank, .get_vblank_timestamp = drm_crtc_vblank_helper_get_vblank_timestamp,drivers/gpu/drm/vc4/vc4_txp.c +0
-1@@ -382,7 +382,6 @@ static const struct drm_crtc_funcs vc4_txp_crtc_funcs = { .reset = vc4_crtc_reset, .atomic_duplicate_state = vc4_crtc_duplicate_state, .atomic_destroy_state = vc4_crtc_destroy_state, - .gamma_set = drm_atomic_helper_legacy_gamma_set, .enable_vblank = vc4_txp_enable_vblank, .disable_vblank = vc4_txp_disable_vblank, };include/drm/drm_atomic_helper.h +0
-4@@ -147,10 +147,6 @@ int drm_atomic_helper_page_flip_target(uint32_t flags, uint32_t target, struct drm_modeset_acquire_ctx *ctx); -int drm_atomic_helper_legacy_gamma_set (struct drm_crtc *crtc, -u16 *red,u16 *green,u16 *blue, -uint32_t size, -struct drm_modeset_acquire_ctx *ctx);/** * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
Signature · 7 lines
Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 12 lines · Laurent Pinchart
Hi Tomi,
Thank you for the patch.
Quoted 7 lines · Tomi Valkeinen
To support legacy gamma ioctls the drivers need to set drm_crtc_funcs.gamma_set either to a custom implementation or to
drm_atomic_helper_legacy_gamma_set. Most of the atomic drivers do the latter.We can simplify this by making the core handle it automatically.
Quoted 7 lines
Quoted 5 lines
Move the
drm_atomic_helper_legacy_gamma_set()functionality intodrm_color_mgmt.cto makedrm_mode_gamma_set_ioctl()use drm_crtc_funcs.gamma_set if set orGAMMA_LUTproperty if not.Signed-off-by Tomi Valkeinen <[email protected]>Reviewed-by Laurent Pinchart <[email protected]>
Thanks Laurent! If there are no objections, I'd like to push these to drm-misc-next tomorrow (along with the omapdrm gamma + CTM patches).
Tomi
Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Tomi,
Quoted 21 lines · Tomi Valkeinen
To support legacy gamma ioctls the drivers need to set drm_crtc_funcs.gamma_set either to a custom implementation or to
drm_atomic_helper_legacy_gamma_set. Most of the atomic drivers do the latter.We can simplify this by making the core handle it automatically.
Move the
drm_atomic_helper_legacy_gamma_set()functionality intodrm_color_mgmt.cto makedrm_mode_gamma_set_ioctl()use drm_crtc_funcs.gamma_set if set orGAMMA_LUTproperty if not.Signed-off-by Tomi Valkeinen <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 1 - .../gpu/drm/arm/display/komeda/komeda_crtc.c | 1 - drivers/gpu/drm/arm/malidp_crtc.c | 1 - drivers/gpu/drm/armada/armada_crtc.c | 1 - drivers/gpu/drm/ast/ast_mode.c | 1 - .../gpu/drm/atmel-hlcdc/atmel_hlcdc_crtc.c | 1 - drivers/gpu/drm/drm_atomic_helper.c | 70 ----------- drivers/gpu/drm/drm_color_mgmt.c | 111 ++++++++++++++++--
Quoted 8 lines
drivers/gpu/drm/i915/display/intel_display.c | 1 - drivers/gpu/drm/ingenic/ingenic-drm-drv.c | 2 - drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 1 - drivers/gpu/drm/nouveau/dispnv50/head.c | 2 - drivers/gpu/drm/omapdrm/omap_crtc.c | 1 - drivers/gpu/drm/rcar-du/rcar_du_crtc.c | 1 - drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 1 - drivers/gpu/drm/stm/ltdc.c | 1 -
For the stm part,
Thank you
Philippe :-)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
drivers/gpu/drm/drm_color_mgmt.c int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, · line 240
Quoted 10 lines · Tomi Valkeinen
drivers/gpu/drm/drm_color_mgmt.c +10
-0+/** +* drm_crtc_supports_legacy_gamma - does the crtc support legacy gamma correction table +* @crtc: CRTC object +* +* Returns true/false if the given crtc supports setting the legacy gamma +* correction table. +*/ +static bool drm_crtc_supports_legacy_gamma (struct drm_crtc *crtc) +{ +uint32_t gamma_id = crtc->dev->mode_config.gamma_lut_property->base.id;
Userspace-mode strikes again... I'll change uint32_t's to u32 while applying. (But in my defense, there were uint32_t uses already in the code touched by these patches, and drm seems to have lots of uint32_t all around...)
Tomi
Signature · 6 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v4 2/2 drm: add legacy support for using degamma for gamma
In reply to Tomi ValkeinenThe DRM core handles legacy gamma-set ioctl by setting GAMMA_LUT and clearing CTM and DEGAMMA_LUT.
This works fine on HW where we have either:
degamma -> ctm -> gamma -> out
or
ctm -> gamma -> out
However, if the HW has gamma table before ctm, the atomic property should be DEGAMMA_LUT, and thus we have:
degamma -> ctm -> out
This is fine for userspace which sets gamma table using the properties, as the userspace can check for the existence of gamma & degamma, but the legacy gamma-set ioctl does not work.
Change the DRM core to use DEGAMMA_LUT instead of GAMMA_LUT when the latter is unavailable.
--- drivers/gpu/drm/drm_color_mgmt.c | 22 ++++++++++++++++++---- drivers/gpu/drm/drm_fb_helper.c | 5 +++++ 2 files changed, 23 insertions(+), 4 deletions(-)
drivers/gpu/drm/drm_color_mgmt.c +18 -4
@@ -91,7 +91,7 @@* * There is also support for a legacy gamma table, which is set up by calling * drm_mode_crtc_set_gamma_size(). The DRM core will then alias the legacy gamma -* ramp with "GAMMA_LUT". +* ramp with "GAMMA_LUT" or, if that is unavailable, "DEGAMMA_LUT". * * Support for different non RGB color encodings is controlled through * &drm_plane specific COLOR_ENCODING and COLOR_RANGE properties. They
@@ -238,6 +238,7 @@ EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);static bool drm_crtc_supports_legacy_gamma (struct drm_crtc *crtc) {uint32_t gamma_id = crtc->dev->mode_config.gamma_lut_property->base.id; +uint32_t degamma_id = crtc->dev->mode_config.degamma_lut_property->base.id;if (!crtc->gamma_size)return false;
@@ -245,7 +246,8 @@ static bool drm_crtc_supports_legacy_gamma(struct drm_crtc *crtc)if (crtc->funcs->gamma_set)return true; -return !!drm_mode_obj_find_prop_id (&crtc->base, gamma_id); +return !!(drm_mode_obj_find_prop_id (&crtc->base, gamma_id) || +drm_mode_obj_find_prop_id (&crtc->base, degamma_id)); }/**
@@ -276,12 +278,22 @@ static int drm_crtc_legacy_gamma_set(struct drm_crtc *crtc,struct drm_crtc_state *crtc_state;struct drm_property_blob *blob;struct drm_color_lut *blob_data; +uint32_t gamma_id = dev->mode_config.gamma_lut_property->base.id; +uint32_t degamma_id = dev->mode_config.degamma_lut_property->base.id; +bool use_gamma_lut;int i, ret =0 ;bool replaced;if (crtc->funcs->gamma_set)return crtc->funcs->gamma_set (crtc, red, green, blue, size, ctx); +if (drm_mode_obj_find_prop_id (&crtc->base, gamma_id)) + use_gamma_lut = true; +else if (drm_mode_obj_find_prop_id (&crtc->base, degamma_id)) + use_gamma_lut = false; +else +return -ENODEV ; + state =drm_atomic_state_alloc (crtc->dev);if (!state)return -ENOMEM ;
@@ -311,9 +323,11 @@ static int drm_crtc_legacy_gamma_set(struct drm_crtc *crtc, }/* Set GAMMA_LUT and reset DEGAMMA_LUT and CTM */ - replaced =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); + replaced =drm_property_replace_blob (&crtc_state->degamma_lut, + use_gamma_lut ?NULL : blob); replaced |=drm_property_replace_blob (&crtc_state->ctm,NULL ); - replaced |=drm_property_replace_blob (&crtc_state->gamma_lut, blob); + replaced |=drm_property_replace_blob (&crtc_state->gamma_lut, + use_gamma_lut ? blob :NULL ); crtc_state->color_mgmt_changed |= replaced; ret =drm_atomic_commit (state);
drivers/gpu/drm/drm_fb_helper.c +5 -0
@@ -1059,6 +1059,11 @@ static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info) goto out_state; } +/* +* FIXME: This always uses gamma_lut. Some HW have only +* degamma_lut, in which case we should reset gamma_lut and set +* degamma_lut. See drm_crtc_legacy_gamma_set(). +*/ replaced =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); replaced |=drm_property_replace_blob (&crtc_state->ctm,NULL );
Signature · 7 lines
Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH v4 2/2] drm: add legacy support for using degamma for gamma
Hi Tomi,
Thank you for the patch.
Quoted 16 lines · Tomi Valkeinen
The DRM core handles legacy gamma-set ioctl by setting
GAMMA_LUTand clearing CTM andDEGAMMA_LUT.This works fine on HW where we have either:
degamma -> ctm -> gamma -> out
or
ctm -> gamma -> out
However, if the HW has gamma table before ctm, the atomic property should be
DEGAMMA_LUT, and thus we have:degamma -> ctm -> out
Quoted 8 lines
This is fine for userspace which sets gamma table using the properties, as the userspace can check for the existence of gamma & degamma, but the legacy gamma-set ioctl does not work.
Change the DRM core to use
DEGAMMA_LUTinstead ofGAMMA_LUTwhen the latter is unavailable.Signed-off-by Tomi Valkeinen <[email protected]>
Quoted 89 lines
--- drivers/gpu/drm/drm_color_mgmt.c | 22 ++++++++++++++++++---- drivers/gpu/drm/drm_fb_helper.c | 5 +++++ 2 files changed, 23 insertions(+), 4 deletions(-)drivers/gpu/drm/drm_color_mgmt.c +18
-4@@ -91,7 +91,7 @@* * There is also support for a legacy gamma table, which is set up by calling * drm_mode_crtc_set_gamma_size(). The DRM core will then alias the legacy gamma -* ramp with "GAMMA_LUT". +* ramp with "GAMMA_LUT" or, if that is unavailable, "DEGAMMA_LUT". * * Support for different non RGB color encodings is controlled through * &drm_plane specific COLOR_ENCODING and COLOR_RANGE properties. They @@ -238,6 +238,7 @@ EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);static bool drm_crtc_supports_legacy_gamma (struct drm_crtc *crtc) {uint32_t gamma_id = crtc->dev->mode_config.gamma_lut_property->base.id; +uint32_t degamma_id = crtc->dev->mode_config.degamma_lut_property->base.id;if (!crtc->gamma_size)return false;@@ -245,7 +246,8 @@ static bool drm_crtc_supports_legacy_gamma(struct drm_crtc *crtc)if (crtc->funcs->gamma_set)return true; -return !!drm_mode_obj_find_prop_id (&crtc->base, gamma_id); +return !!(drm_mode_obj_find_prop_id (&crtc->base, gamma_id) || +drm_mode_obj_find_prop_id (&crtc->base, degamma_id)); }/** @@ -276,12 +278,22 @@ static int drm_crtc_legacy_gamma_set(struct drm_crtc *crtc,struct drm_crtc_state *crtc_state;struct drm_property_blob *blob;struct drm_color_lut *blob_data; +uint32_t gamma_id = dev->mode_config.gamma_lut_property->base.id; +uint32_t degamma_id = dev->mode_config.degamma_lut_property->base.id; +bool use_gamma_lut;int i, ret =0 ;bool replaced;if (crtc->funcs->gamma_set)return crtc->funcs->gamma_set (crtc, red, green, blue, size, ctx); +if (drm_mode_obj_find_prop_id (&crtc->base, gamma_id)) + use_gamma_lut = true; +else if (drm_mode_obj_find_prop_id (&crtc->base, degamma_id)) + use_gamma_lut = false; +else +return -ENODEV ; + state =drm_atomic_state_alloc (crtc->dev);if (!state)return -ENOMEM ;@@ -311,9 +323,11 @@ static int drm_crtc_legacy_gamma_set(struct drm_crtc *crtc, }/* Set GAMMA_LUT and reset DEGAMMA_LUT and CTM */ - replaced =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); + replaced =drm_property_replace_blob (&crtc_state->degamma_lut, + use_gamma_lut ?NULL : blob); replaced |=drm_property_replace_blob (&crtc_state->ctm,NULL ); - replaced |=drm_property_replace_blob (&crtc_state->gamma_lut, blob); + replaced |=drm_property_replace_blob (&crtc_state->gamma_lut, + use_gamma_lut ? blob :NULL ); crtc_state->color_mgmt_changed |= replaced; ret =drm_atomic_commit (state);drivers/gpu/drm/drm_fb_helper.c +5
-0@@ -1059,6 +1059,11 @@ static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info) goto out_state; } +/* +* FIXME: This always uses gamma_lut. Some HW have only +* degamma_lut, in which case we should reset gamma_lut and set +* degamma_lut. See drm_crtc_legacy_gamma_set(). +*/ replaced =drm_property_replace_blob (&crtc_state->degamma_lut,NULL ); replaced |=drm_property_replace_blob (&crtc_state->ctm,NULL );
Signature · 7 lines
Regards, Laurent Pinchart _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel