Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp4740989ybp; Mon, 14 Oct 2019 09:17:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqy1EPs2hW3GMR54f25EtVaN7MMTvrD/X1mnpGTsNnqB3osNFtI8pNGdGcmj3+s6czSNcXuD X-Received: by 2002:a17:906:f181:: with SMTP id gs1mr26824660ejb.13.1571069855362; Mon, 14 Oct 2019 09:17:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571069855; cv=none; d=google.com; s=arc-20160816; b=DLH6xrU4tjp9GirpexBzt1iW7iHTRFe19Ry0sVm+cV8ExFOcL0fbpO4dcztdeHxb1g OlqFifdb+C1iKRHC/acme6T6gdTuHSkLy9cd35rSTmdsw+q7vBv0iwCgsw9tzHGD7eot JIivU0Xuc7BY0AgKTUfPqfS2OOr1gqJC/3+6DD8hELywfGgyej5R46PWv0AWsevpO/MB h6nqjofSeWa0s6juiqEtr6AybHA/YOB1Or5S/uQpNLaxFqKp/wTBm59l8BJJxJIyrXpJ ex/Ljvi7A0rJuZCONxFtPaMH5JWANOa6NLOXSuyOdKAaiy4ALnc1d+0W6Rlqs+UkncEr ucgw== 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:mail-followup-to :message-id:subject:cc:to:from:date:dkim-signature; bh=w9mlgI2kR839Z5/4gH9FpOIFXEfNmboTdDmci4yowm8=; b=CSCmXvneFoZSLcoAtSvW+PpNWfglU6gvQM+cMH9ZQxsZ2Kcp68j6+W1dDekkgLfVF9 IJyLQ1VwAt4wluINn+2daTBA44LQSCSM/UlkSvj9TEs2McRbrtxISTt2sUAqqWEgONDL DaSH1ESu4xA+w7pys5RNiWwu7BuGOcJyuA+pJx8+zm0+YlXAv67WGp9baudcVm1K4Vt0 M4nnAyk7Qw5b8DFNwxrHlxaU5wRaXkiOQVRYFH0sp6BtRa+fMYQPttDUzXYpkyC06kID M6PyZjiiDqAE20cgJqWHsIQ3apSz3m/iDL7pVLEP9s/RBe5TViXe4Pd2+q7MVnzh38lx AH7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b="XBpnqvo/"; 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 g31si12487266eda.399.2019.10.14.09.17.11; Mon, 14 Oct 2019 09:17:35 -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=fail header.i=@ffwll.ch header.s=google header.b="XBpnqvo/"; 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 S1730445AbfJNPde (ORCPT + 99 others); Mon, 14 Oct 2019 11:33:34 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40853 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728888AbfJNPde (ORCPT ); Mon, 14 Oct 2019 11:33:34 -0400 Received: by mail-ed1-f68.google.com with SMTP id v38so15192474edm.7 for ; Mon, 14 Oct 2019 08:33:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=sender:date:from:to:cc:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=w9mlgI2kR839Z5/4gH9FpOIFXEfNmboTdDmci4yowm8=; b=XBpnqvo/R+SLAG7D0cXXtujk7Wn+hKWHZlRrLXhUr7SQJ0NqAEJG4I4+VDKgVFKG4I S9moF74zaFswuasxTslog93qudtZdAL6ALRRP80j125m0eqnUZygTij90BgJ/RfCxTFQ /jTM/I23xTFE4LpqaEb5GAC+L34qdaXaluD0Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to:user-agent; bh=w9mlgI2kR839Z5/4gH9FpOIFXEfNmboTdDmci4yowm8=; b=iaHSqUB3cJXHuOCW4qRf2+iNfLSvrVf8NFmRv1Jxj/aH5vEG74V0CP89tsjT8UR8I8 jOnBHiqnVD6v3Hx9UvWj+OPlyfNEdxeFIZC0+K+4T0aOtw98O5Ma+vt1DK0vvaPg9JlT NdrdXtxoFBOJrZJ6+qAhjeCxExb2RIyZV/dT/0Xda4uK7GFrUJ9avSq7oyIelBq45oYf xN40eTQkbnbCvbFTqBabEXXnZGtXnv0SYtTh9Nj3++7Nil0iKt+MiqPov3wSbiHu1E+1 mDup9eJG2F2MGAmDEQr7MnhMcBCMeN42AEJnp6UcQgcM7FTEjbRHRAizXoMcKtBWGWpJ 23/A== X-Gm-Message-State: APjAAAX6lXiiZKwrOCG9nWmhg7HtozM/oVW5rpSUCuM8BrgRRWmrIfdR B3BlroY3fv7ZcDU0z2WK44FM5w== X-Received: by 2002:aa7:dd18:: with SMTP id i24mr29588611edv.239.1571067211516; Mon, 14 Oct 2019 08:33:31 -0700 (PDT) Received: from phenom.ffwll.local (212-51-149-96.fiber7.init7.net. [212.51.149.96]) by smtp.gmail.com with ESMTPSA id z20sm3235235edb.3.2019.10.14.08.33.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 08:33:30 -0700 (PDT) Date: Mon, 14 Oct 2019 17:33:27 +0200 From: Daniel Vetter To: "james qian wang (Arm Technology China)" Cc: Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "sean@poorly.run" , "imirkin@alum.mit.edu" , nd , Ayan Halder , "Oscar Zhang (Arm Technology China)" , "Tiannan Zhu (Arm Technology China)" , Mihail Atanassov , "Jonathan Chai (Arm Technology China)" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin (Arm Technology China)" , "Channing Chen (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , "Thomas Sun (Arm Technology China)" , "Lowry Li (Arm Technology China)" , Ben Davis Subject: Re: [PATCH v2 1/4] drm/komeda: Add a new helper drm_color_ctm_s31_32_to_qm_n() Message-ID: <20191014153327.GL11828@phenom.ffwll.local> Mail-Followup-To: "james qian wang (Arm Technology China)" , Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "sean@poorly.run" , "imirkin@alum.mit.edu" , nd , Ayan Halder , "Oscar Zhang (Arm Technology China)" , "Tiannan Zhu (Arm Technology China)" , Mihail Atanassov , "Jonathan Chai (Arm Technology China)" , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin (Arm Technology China)" , "Channing Chen (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , "Thomas Sun (Arm Technology China)" , "Lowry Li (Arm Technology China)" , Ben Davis References: <20191011054240.17782-1-james.qian.wang@arm.com> <20191011054240.17782-2-james.qian.wang@arm.com> <20191014085605.GF11828@phenom.ffwll.local> <20191014095813.GA15227@jamwan02-TSP300> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191014095813.GA15227@jamwan02-TSP300> X-Operating-System: Linux phenom 5.2.0-2-amd64 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 On Mon, Oct 14, 2019 at 09:58:20AM +0000, james qian wang (Arm Technology China) wrote: > On Mon, Oct 14, 2019 at 10:56:05AM +0200, Daniel Vetter wrote: > > On Fri, Oct 11, 2019 at 05:43:09AM +0000, james qian wang (Arm Technology China) wrote: > > > Add a new helper function drm_color_ctm_s31_32_to_qm_n() for driver to > > > convert S31.32 sign-magnitude to Qm.n 2's complement that supported by > > > hardware. > > > > > > Signed-off-by: james qian wang (Arm Technology China) > > > --- > > > drivers/gpu/drm/drm_color_mgmt.c | 23 +++++++++++++++++++++++ > > > include/drm/drm_color_mgmt.h | 2 ++ > > > 2 files changed, 25 insertions(+) > > > > > > diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c > > > index 4ce5c6d8de99..3d533d0b45af 100644 > > > --- a/drivers/gpu/drm/drm_color_mgmt.c > > > +++ b/drivers/gpu/drm/drm_color_mgmt.c > > > @@ -132,6 +132,29 @@ uint32_t drm_color_lut_extract(uint32_t user_input, uint32_t bit_precision) > > > } > > > EXPORT_SYMBOL(drm_color_lut_extract); > > > > > > +/** > > > + * drm_color_ctm_s31_32_to_qm_n > > > + * > > > + * @user_input: input value > > > + * @m: number of integer bits > > > + * @n: number of fractinal bits > > > + * > > > + * Convert and clamp S31.32 sign-magnitude to Qm.n 2's complement. > > > > What's the Q meaning here? Also maybe specify that the higher bits above > > m+n are cleared to all 0 or all 1. Unit test would be lovely too. Anyway: > > The Q used to represent signed two's complement. > > For detail: https://en.wikipedia.org/wiki/Q_(number_format) > > And it Q is 2's complement, so the value of higher bit equal to > sign-bit. > All 1 if it is negative > 0 if it is positive. Ah I didn't know about this notation, I think in other drm docs we just used m.n 2's complement to denote this layout. Up to you I think. -Daniel > > James > > > Reviewed-by: Daniel Vetter > > > > > + */ > > > +uint64_t drm_color_ctm_s31_32_to_qm_n(uint64_t user_input, > > > + uint32_t m, uint32_t n) > > > +{ > > > + u64 mag = (user_input & ~BIT_ULL(63)) >> (32 - n); > > > + bool negative = !!(user_input & BIT_ULL(63)); > > > + s64 val; > > > + > > > + /* the range of signed 2s complement is [-2^n+m, 2^n+m - 1] */ > > > + val = clamp_val(mag, 0, negative ? BIT(n + m) : BIT(n + m) - 1); > > > + > > > + return negative ? 0ll - val : val; > > > +} > > > +EXPORT_SYMBOL(drm_color_ctm_s31_32_to_qm_n); > > > + > > > /** > > > * drm_crtc_enable_color_mgmt - enable color management properties > > > * @crtc: DRM CRTC > > > diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h > > > index d1c662d92ab7..60fea5501886 100644 > > > --- a/include/drm/drm_color_mgmt.h > > > +++ b/include/drm/drm_color_mgmt.h > > > @@ -30,6 +30,8 @@ struct drm_crtc; > > > struct drm_plane; > > > > > > uint32_t drm_color_lut_extract(uint32_t user_input, uint32_t bit_precision); > > > +uint64_t drm_color_ctm_s31_32_to_qm_n(uint64_t user_input, > > > + uint32_t m, uint32_t n); > > > > > > void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, > > > uint degamma_lut_size, > > > -- > > > 2.20.1 > > > > > > _______________________________________________ > > > dri-devel mailing list > > > dri-devel@lists.freedesktop.org > > > https://lists.freedesktop.org/mailman/listinfo/dri-devel > > > > -- > > Daniel Vetter > > Software Engineer, Intel Corporation > > http://blog.ffwll.ch > IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you. > _______________________________________________ > dri-devel mailing list > dri-devel@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/dri-devel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch