Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2556992ybp; Thu, 10 Oct 2019 09:04:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqwsREAgR4ODS2HOq3p3030TF3gYW7ccQ08owIH7y75wuUiIGdpCv22tFNhfjSFW9VpHfzm7 X-Received: by 2002:a17:906:28ce:: with SMTP id p14mr9041100ejd.164.1570723486619; Thu, 10 Oct 2019 09:04:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570723486; cv=none; d=google.com; s=arc-20160816; b=sL08I5ZAhUxHSb53K5jXGxFCMqHT4OtrVOxuPuKGTa2Br+BK5cm8ZrA3YTLMfna9QQ eZ7KayceSx4t2VFUsN6YEEPiOyhf+jEopcrhe2gf6f1QwaqngtIvMf1NlDSs4pVVOw2x ugk6IuCEcNwujlHUovku4sKeF+QRdW6NIrPGUAF8Kbn3zBQaM8gHwNAbnVyytKI06+PI bnExDAuSr7UcrQxZvikYqxppmuFbctK97G8cR/4Xf/lWhQmR405sDIAT+gL9jiqYvIOO q5yQA8Tpq7UjZoYWE7WEXCEzmDhHPkKL4SdmyQqM9dePZP0J1FrEbRqHwlAvMch5kpod 6IEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=HQEwz99zPiBamssWYWO0fAnZk+5TRNulHyEfs6Nv7lQ=; b=BbQBfndALouFQV9iSHIdCYnTJ64BDbR/jyV2O+YyCoLehbhHu5fdyvcMp2qEXW/SNd ozPswfV2bhp3IxQptQ5z0Oe/XbU3qMZ5ocprSN8vdEuhOCQsIjGsHjYmNDAwL4N3UEUb igZr6q22i2+c/yYqDj5XgZNy4YtdgiBNeRt6FKOOd+KBG9Q8su/pEkgsa6Ke83Qab5PH UCFHd8UUOICJlLq5RkAlML0mUI4S5q5hgG15xrgN3tnb0ZpTCF4qXfaC6lP5ZBYQhmsD pue4K4OleRB4S5KXx09Uvg3miWxFqbUZL2UkzFVpz2wacLj27A+iakl/Z05cMYuFoxK4 np/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=T9ZeEHxg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a30si4049629eda.39.2019.10.10.09.04.06; Thu, 10 Oct 2019 09:04:46 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@poorly.run header.s=google header.b=T9ZeEHxg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726205AbfJJQBE (ORCPT + 99 others); Thu, 10 Oct 2019 12:01:04 -0400 Received: from mail-yw1-f65.google.com ([209.85.161.65]:39012 "EHLO mail-yw1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726007AbfJJQBE (ORCPT ); Thu, 10 Oct 2019 12:01:04 -0400 Received: by mail-yw1-f65.google.com with SMTP id n11so2349306ywn.6 for ; Thu, 10 Oct 2019 09:01:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=HQEwz99zPiBamssWYWO0fAnZk+5TRNulHyEfs6Nv7lQ=; b=T9ZeEHxgqp5RV8yKHwcvwPSxswMi3KrhA4RVWCWl1lX1KjOUzEzDxOFiBlk6Vjdvxi 3CujVBdI37VPSKl11epmWWNLz5LJZFZfRCT8hkIlKvDnlK5bg/GNSqGP/TPg6e0JNj9Y 1+YjwZc8P6H9Ms9ISF+33kFd8cR+Td+TXJICnLRVjIkuV8dtzGUv19F+CrD/DhXRGFFI gBAXTZzCMiOoNFBdKUlWPc6VdOjjTmqKqdysQs8qyJZnPepivh3XXztUJCaDIO5VR9q9 wTmKBBK1RBIBUUECFCk2yaZ/0qzpMqCyPj8YoFtpQXBLSjC3+h7A7PfVmLB+AsQbzo1p JSZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=HQEwz99zPiBamssWYWO0fAnZk+5TRNulHyEfs6Nv7lQ=; b=cDNLSa36KbUoFAxXUJPnF/1/53a2KCFdfbSyLTz6AJcFasp0vWfjT34H3I/CgGQ54F 07t61YVIr1EUL0uPOhXaOToHnq+vhm4uvSWXT+wiVt5fEPRFq3CmrucIL0l5MoZH4PCJ h+y93ZWa5t+GZlM9Hby9XLjuJE23LPHSS6Kgcd4kUFHtRilMVGWzPYC/qJI14gXjfgd1 vjv4cnQzMpvqSn0+tmbtwCjINxwzstNiD68VJtScZv8Ore9SsLlJq7FPhOqEDMBkdTjz 3rdkjZit1WUn3sC9t2yThfNHBjHzt/whWaRWHBb+UNFbFsVE29CaXTyw/IK8i9DKnomn aLAA== X-Gm-Message-State: APjAAAXuG6GUrhZcrmaFCy/3elokv7tD0Dt/Nrja1/LnBIfQ5cHbEI0k s0uVZw2p7lQszZufMwyWWVEMGA== X-Received: by 2002:a81:ee11:: with SMTP id l17mr7691414ywm.72.1570723261755; Thu, 10 Oct 2019 09:01:01 -0700 (PDT) Received: from localhost ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id p204sm1555743ywp.110.2019.10.10.09.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2019 09:00:59 -0700 (PDT) Date: Thu, 10 Oct 2019 12:00:59 -0400 From: Sean Paul To: Ezequiel Garcia Cc: Sean Paul , Ezequiel Garcia , Mark Rutland , devicetree@vger.kernel.org, Jacopo Mondi , Linux Kernel Mailing List , dri-devel , Douglas Anderson , "open list:ARM/Rockchip SoC..." , Boris Brezillon , Sean Paul , Rob Herring , kernel@collabora.com Subject: Re: [PATCH v4 2/3] drm/rockchip: Add optional support for CRTC gamma LUT Message-ID: <20191010160059.GJ85762@art_vandelay> References: <20191008230038.24037-1-ezequiel@collabora.com> <20191008230038.24037-3-ezequiel@collabora.com> <20191009180136.GE85762@art_vandelay> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org /snip > > > +static void vop_crtc_write_gamma_lut(struct vop *vop, struct drm_crtc *crtc) > > > +{ > > > + struct drm_color_lut *lut = crtc->state->gamma_lut->data; > > > + unsigned int i; > > > + > > > + for (i = 0; i < crtc->gamma_size; i++) { > > > + u32 word; > > > + > > > + word = (drm_color_lut_extract(lut[i].red, 10) << 20) | > > > + (drm_color_lut_extract(lut[i].green, 10) << 10) | > > > + drm_color_lut_extract(lut[i].blue, 10); > > > + writel(word, vop->lut_regs + i * 4); > > > + } > > > +} > > > + > > > +static void vop_crtc_gamma_set(struct vop *vop, struct drm_crtc *crtc, > > > + struct drm_crtc_state *old_crtc_state) > > > +{ > > > + unsigned int idle; > > > + int ret; > > > + > > > > How about: > > > > if (!vop->lut_regs) > > return; > > > > here and then you can remove that condition above the 2 callsites > > > > Yes, sounds good. > > > > + /* > > > + * In order to write the LUT to the internal memory, > > > + * we need to first make sure the dsp_lut_en bit is cleared. > > > + */ > > > + spin_lock(&vop->reg_lock); > > > + VOP_REG_SET(vop, common, dsp_lut_en, 0); > > > + vop_cfg_done(vop); > > > + spin_unlock(&vop->reg_lock); > > > + > > > + /* > > > + * If the CRTC is not active, dsp_lut_en will not get cleared. > > > + * Apparently we still need to do the above step to for > > > + * gamma correction to be disabled. > > > + */ > > > + if (!crtc->state->active) > > > + return; > > > + > > I have realized that the above might no longer be needed, > given we are now using atomic_enable and atomic_begin. > > Not sure if the CRTC is supposed to clear its GAMMA > when disabled. > Yep, good catch. Since we use commit_tail_rpm, atomic_begin won't be called in the disable path. > > > + ret = readx_poll_timeout(vop_dsp_lut_is_enable, vop, > > > + idle, !idle, 5, 30 * 1000); > > > + if (ret) { > > > + DRM_DEV_ERROR(vop->dev, "display LUT RAM enable timeout!\n"); > > > + return; > > > + } > > > + > > > + if (crtc->state->gamma_lut && > > > + (!old_crtc_state->gamma_lut || (crtc->state->gamma_lut->base.id != > > > + old_crtc_state->gamma_lut->base.id))) { > > > > Silly question, but isn't the second part of this check redundant since you need > > color_mgmt_changed || active_changed to get into this function? > > > > So maybe invert the conditional here and exit early (to save a level of > > indentation in the block below): > > > > I took this from malidp_atomic_commit_update_gamma. I _believe_ > the rational for this is that color_mgmt_changed can be set by re-setting > the gamma property, to the same property. But I admit I haven't > tested it's the case. > > OTOH, it won't really affect much to re-write the table, if the user > requested a change. > color_mgmt_changed is based on the output of drm_property_replace_blob() which should return false if the blob is unchanged. So I don't think that case is possible. Taking this a step further, this check could even be damaging since something in the atomic check path could set color_mgmt_changed in order to explicitly trigger a lut write and we'd be skipping it with the id check. > > if (!crtc->state->gamma_lut) > > return; > > > > In any case, inverting the condition makes sense. > > > spin_lock(&vop->reg_lock); > > > > vop_crtc_write_gamma_lut(vop, crtc); > > VOP_REG_SET(vop, common, dsp_lut_en, 1); > > vop_cfg_done(vop); > > > > spin_unlock(&vop->reg_lock); > > > > > + > > > + spin_lock(&vop->reg_lock); > > > + > > > + vop_crtc_write_gamma_lut(vop, crtc); > > > + VOP_REG_SET(vop, common, dsp_lut_en, 1); > > > + vop_cfg_done(vop); > > > + > > > + spin_unlock(&vop->reg_lock); > > > + } > > > +} /snip > > > +static int vop_crtc_atomic_check(struct drm_crtc *crtc, > > > + struct drm_crtc_state *crtc_state) > > > +{ > > > + struct vop *vop = to_vop(crtc); > > > + > > > + if (vop->lut_regs && crtc_state->color_mgmt_changed && > > > + crtc_state->gamma_lut) { > > > + unsigned int len; > > > + > > > + len = drm_color_lut_size(crtc_state->gamma_lut); > > > + if (len != crtc->gamma_size) { > > > + DRM_DEBUG_KMS("Invalid LUT size; got %d, expected %d\n", > > > + len, crtc->gamma_size); > > > + return -EINVAL; > > > + } > > > > Overflow is avoided in drm_mode_gamma_set_ioctl(), so I don't think you need > > this function. > > > > But that only applies to the legacy path. Isn't this needed to ensure > a gamma blob > has the right size? Yeah, good point, we check the element size in the atomic path, but not the max size. I haven't looked at enough color lut stuff to have an opinion whether this check would be useful in a helper function or not, something to consider, I suppose. Sean > > Thanks, > Ezequiel -- Sean Paul, Software Engineer, Google / Chromium OS