[PATCH] gpu/drm: set gamma_lut or degamma_lut based on HW in setcmap_atomic

From: Vamsi Krishna Brahmajosyula
Date: Thu Oct 03 2024 - 08:07:10 EST


setcmap_atomic always sets gamma_lut in setcmap_atomic

Address the following FIXME to set gamma or degamma lut
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().

Tested by calling setcmap_atomic in drm_fb_helper_setcmap with out
the condition check.

Signed-off-by: Vamsi Krishna Brahmajosyula <vamsikrishna.brahmajosyula@xxxxxxxxx>
---
drivers/gpu/drm/drm_fb_helper.c | 50 ++++++++++++++++++++-------------
1 file changed, 31 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c
index 29c53f9f449c..48f053f7ac89 100644
--- a/drivers/gpu/drm/drm_fb_helper.c
+++ b/drivers/gpu/drm/drm_fb_helper.c
@@ -871,11 +871,11 @@ static int setcmap_legacy(struct fb_cmap *cmap, struct fb_info *info)
return ret;
}

-static struct drm_property_blob *setcmap_new_gamma_lut(struct drm_crtc *crtc,
+static struct drm_property_blob *setcmap_new_blob_lut(struct drm_crtc *crtc,
struct fb_cmap *cmap)
{
struct drm_device *dev = crtc->dev;
- struct drm_property_blob *gamma_lut;
+ struct drm_property_blob *blob;
struct drm_color_lut *lut;
int size = crtc->gamma_size;
int i;
@@ -883,11 +883,11 @@ static struct drm_property_blob *setcmap_new_gamma_lut(struct drm_crtc *crtc,
if (!size || cmap->start + cmap->len > size)
return ERR_PTR(-EINVAL);

- gamma_lut = drm_property_create_blob(dev, sizeof(*lut) * size, NULL);
- if (IS_ERR(gamma_lut))
- return gamma_lut;
+ blob = drm_property_create_blob(dev, sizeof(*lut) * size, NULL);
+ if (IS_ERR(blob))
+ return blob;

- lut = gamma_lut->data;
+ lut = blob->data;
if (cmap->start || cmap->len != size) {
u16 *r = crtc->gamma_store;
u16 *g = r + crtc->gamma_size;
@@ -911,14 +911,14 @@ static struct drm_property_blob *setcmap_new_gamma_lut(struct drm_crtc *crtc,
lut[cmap->start + i].blue = cmap->blue[i];
}

- return gamma_lut;
+ return blob;
}

static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info)
{
struct drm_fb_helper *fb_helper = info->par;
struct drm_device *dev = fb_helper->dev;
- struct drm_property_blob *gamma_lut = NULL;
+ struct drm_property_blob *blob = NULL;
struct drm_modeset_acquire_ctx ctx;
struct drm_crtc_state *crtc_state;
struct drm_atomic_state *state;
@@ -926,6 +926,9 @@ static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info)
struct drm_crtc *crtc;
u16 *r, *g, *b;
bool replaced;
+ u32 gamma_id = dev->mode_config.gamma_lut_property->base.id;
+ u32 degamma_id = dev->mode_config.degamma_lut_property->base.id;
+ bool use_gamma_lut;
int ret = 0;

drm_modeset_acquire_init(&ctx, 0);
@@ -941,11 +944,21 @@ static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info)
drm_client_for_each_modeset(modeset, &fb_helper->client) {
crtc = modeset->crtc;

- if (!gamma_lut)
- gamma_lut = setcmap_new_gamma_lut(crtc, cmap);
- if (IS_ERR(gamma_lut)) {
- ret = PTR_ERR(gamma_lut);
- gamma_lut = NULL;
+ 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 {
+ ret = -ENODEV;
+ blob = NULL;
+ goto out_state;
+ }
+
+ if (!blob)
+ blob = setcmap_new_blob_lut(crtc, cmap);
+ if (IS_ERR(blob)) {
+ ret = PTR_ERR(blob);
+ blob = NULL;
goto out_state;
}

@@ -956,15 +969,14 @@ static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info)
}

/*
- * 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().
+ * Some HW have only degamma_lut, in which case we should
+ * reset gamma_lut and set degamma_lut.
*/
replaced = drm_property_replace_blob(&crtc_state->degamma_lut,
- NULL);
+ use_gamma_lut ? NULL : blob);
replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL);
replaced |= drm_property_replace_blob(&crtc_state->gamma_lut,
- gamma_lut);
+ use_gamma_lut ? blob : NULL);
crtc_state->color_mgmt_changed |= replaced;
}

@@ -988,7 +1000,7 @@ static int setcmap_atomic(struct fb_cmap *cmap, struct fb_info *info)
if (ret == -EDEADLK)
goto backoff;

- drm_property_blob_put(gamma_lut);
+ drm_property_blob_put(blob);
drm_atomic_state_put(state);
out_ctx:
drm_modeset_drop_locks(&ctx);

base-commit: 7ec462100ef9142344ddbf86f2c3008b97acddbe
--
2.46.2