Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1053440ybp; Wed, 9 Oct 2019 08:12:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaRpC3fYAx2oATOds+uPf9/Xip/dGMbdayy3nvATuchp84LwjE4wBZzSkvHEbDiiEGCRt+ X-Received: by 2002:a17:906:615:: with SMTP id s21mr3340090ejb.276.1570633925015; Wed, 09 Oct 2019 08:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570633925; cv=none; d=google.com; s=arc-20160816; b=E82dzWDT9+IJIm+P1rHfsq62qlxwNoUwPTB2J+NCLDPPlCv7soceVPFOk3u7usq4bB iopBxL0RWBtLBQl2eN8YpeLhGFg0AWfY3DpCgw85tuj2hStyIPcbwATkWN6VATd681od bK9oJ2c19egRffZAjr/0Ui31ngdgFrlaC5GIDa9+iD9U2Jd4X5jvK9ru9J/w5i84nTlJ 2Nh8p4xVpl9MayFJcRpVJ4Ea+G7UnyAywjs/qMGpWBG5TUXddNp3Waga6YiMfvUfrmke lGXaGQbcLdd2EgMIjnBDC/mU4R8Wr5y7RCcDmTwgB6/hwyKlBXHQlteE9u2dTFvIMCUS T9ug== 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=C7vV5Ta7kiN+Jx0dsp84oi99P0gny8OqQ+rZiWxEBQk=; b=0h7Rm7tbwxebiPbvlUa5RmTSfUROmebHJPglKk6Rrw4SJVS6lon4zAMnsMGyo4wdkd 5CcCiB4XxHCAX9gQr8O5MMGoQNh83e62JFxvzx3DgtvmvsnZKap1OF2OGtJROebxAcSb tOjhRyQegSGVavs2hlK4ZM4fGD3tZyflYw+et01kYGL/XrmxxE/QO3Da9BDV6reE81SV nTerkraAgEgRNmg232xf3n2Fhs4FYKgc3FXuHc4dOfR+90cImEWUoFeN4SczaT4V4T3T ErzJHP3FAUc8Qr8v7ipOxhzxPd0MX0CgI0r4DEXpvUigptx/mcrDOmSXx5ZBBZ/QJjZ8 Y0QQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@ffwll.ch header.s=google header.b=hXnr3vL6; 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 me9si1185607ejb.280.2019.10.09.08.11.40; Wed, 09 Oct 2019 08:12:04 -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=hXnr3vL6; 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 S1731571AbfJIPLD (ORCPT + 99 others); Wed, 9 Oct 2019 11:11:03 -0400 Received: from mail-ed1-f68.google.com ([209.85.208.68]:43702 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729644AbfJIPLC (ORCPT ); Wed, 9 Oct 2019 11:11:02 -0400 Received: by mail-ed1-f68.google.com with SMTP id r9so2342156edl.10 for ; Wed, 09 Oct 2019 08:10:59 -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=C7vV5Ta7kiN+Jx0dsp84oi99P0gny8OqQ+rZiWxEBQk=; b=hXnr3vL6PO1kH7F2wkslm/RjNKmVZY3XVz7tO/PS0bz12ywGqTlC5upN53sDakhHDT sUpY7UqPN9Y3i8wY737vRCcuFbf1YUDlTXhLR8ZFofzKJM3wJVCjWUGUnfWJan8SPniv VzpE+kX1ak69oMF6G597TNJCDR99bgGvUhbS0= 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=C7vV5Ta7kiN+Jx0dsp84oi99P0gny8OqQ+rZiWxEBQk=; b=o1vWrgA0XFqYEtnbRgwGnVPJ38djw1rwOCuPZ0AaN+YWfNs8xnCl+kbJTfuJ0tci3R B4CUogjM5Z0W5NFC2ruGDI8jmuDLYstz0b5yvMr2dE9tDXIb9n2uQSRbuiOv6gWIdBZ/ CvNwlbR/PjjYLscAZOQ8WRLP2M6maQnCKMB7byN6nH2AQoeGEtbdeiLcJSGQFVBFfA2I dIMAcraLa/xT+rd/ru+ZP6RXWKXFfNGm7nxNLAefWwYBdzBkz/Ue53v87y05/+ZW1zh7 RJkzM+xOMnlJoWeewoQqNFdXLowDLY/fBgRWg86bzRhXgTbNaz5lGcByYSOctT49ql67 jGKQ== X-Gm-Message-State: APjAAAWj/ag/LD0wrc29j3mUjaN24MsAdyZlmjWe7OsKzA//25gob2o/ rjglaxI6X1NOMNoE6AzIIPeAaw== X-Received: by 2002:a50:955e:: with SMTP id v30mr3455881eda.221.1570633859068; Wed, 09 Oct 2019 08:10:59 -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 u27sm395824edb.48.2019.10.09.08.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 08:10:43 -0700 (PDT) Date: Wed, 9 Oct 2019 17:10:24 +0200 From: Daniel Vetter To: Ilia Mirkin Cc: Brian Starkey , nd , "Oscar Zhang (Arm Technology China)" , "Tiannan Zhu (Arm Technology China)" , Mihail Atanassov , "airlied@linux.ie" , "Jonathan Chai (Arm Technology China)" , Liviu Dudau , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin (Arm Technology China)" , "Channing Chen (Arm Technology China)" , "james qian wang (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , Ben Davis , "Thomas Sun (Arm Technology China)" , Ayan Halder , "sean@poorly.run" , "Lowry Li (Arm Technology China)" Subject: Re: [PATCH 2/3] drm/komeda: Add drm_ctm_to_coeffs() Message-ID: <20191009151024.GF16989@phenom.ffwll.local> Mail-Followup-To: Ilia Mirkin , Brian Starkey , nd , "Oscar Zhang (Arm Technology China)" , "Tiannan Zhu (Arm Technology China)" , Mihail Atanassov , "airlied@linux.ie" , "Jonathan Chai (Arm Technology China)" , Liviu Dudau , "linux-kernel@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , "Julien Yin (Arm Technology China)" , "Channing Chen (Arm Technology China)" , "james qian wang (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , Ben Davis , "Thomas Sun (Arm Technology China)" , Ayan Halder , "sean@poorly.run" , "Lowry Li (Arm Technology China)" References: <20190930045408.8053-1-james.qian.wang@arm.com> <20190930045408.8053-3-james.qian.wang@arm.com> <20190930110438.6w7jtw2e5s2ykwnd@DESKTOP-E1NTVVP.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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, Sep 30, 2019 at 07:56:13AM -0400, Ilia Mirkin wrote: > On Mon, Sep 30, 2019 at 7:05 AM Brian Starkey wrote: > > > > Hi James, > > > > On Mon, Sep 30, 2019 at 04:54:41AM +0000, james qian wang (Arm Technology China) wrote: > > > This function is used to convert drm_color_ctm S31.32 sign-magnitude > > > value to komeda required Q2.12 2's complement > > > > > > Signed-off-by: james qian wang (Arm Technology China) > > > --- > > > .../arm/display/komeda/komeda_color_mgmt.c | 27 +++++++++++++++++++ > > > .../arm/display/komeda/komeda_color_mgmt.h | 1 + > > > 2 files changed, 28 insertions(+) > > > > > > diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c > > > index c180ce70c26c..c92c82eebddb 100644 > > > --- a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c > > > +++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c > > > @@ -117,3 +117,30 @@ void drm_lut_to_fgamma_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs) > > > { > > > drm_lut_to_coeffs(lut_blob, coeffs, sector_tbl, ARRAY_SIZE(sector_tbl)); > > > } > > > + > > > +/* Convert from S31.32 sign-magnitude to HW Q2.12 2's complement */ > > > +static s32 drm_ctm_s31_32_to_q2_12(u64 input) > > > +{ > > > + u64 mag = (input & ~BIT_ULL(63)) >> 20; > > > + bool negative = !!(input & BIT_ULL(63)); > > > + u32 val; > > > + > > > + /* the range of signed 2s complement is [-2^n, 2^n - 1] */ > > > + val = clamp_val(mag, 0, negative ? BIT(14) : BIT(14) - 1); > > > + > > > + return negative ? 0 - val : val; > > > +} > > > > This function looks generally useful. Should it be in DRM core > > (assuming there isn't already one there)? > > > > You can use a parameter to determine the number of bits desired in the > > output. > > I suspect every driver needs to do something similar. You can see what > I did for nouveau here: > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=88b703527ba70659365d989f29579f1292ebf9c3 > > (look for csc_drm_to_base) > > Would be great to have a common helper which correctly accounts for > all the variability. Yeah the sign-bit 31.32 fixed point format is probably the most ludicrous uapi fumble we've ever done. A shared function, rolled out to drivers, to switch it to a signed 2 complements integer sounds like a _very_ good idea. -Daniel -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch