From mboxrd@z Thu Jan 1 00:00:00 1970 From: Mihail Atanassov Subject: Re: [PATCH v2 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Date: Fri, 11 Oct 2019 08:26:53 +0000 Message-ID: <1622787.6FTe1jSl1W@e123338-lin> References: <20191011054459.17984-1-james.qian.wang@arm.com> <20191011054459.17984-2-james.qian.wang@arm.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: In-Reply-To: <20191011054459.17984-2-james.qian.wang@arm.com> Content-Language: en-US Content-ID: <8E9A0D14D6ECF7498045A0969AF1E44E@eurprd08.prod.outlook.com> Sender: linux-kernel-owner@vger.kernel.org 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" , "Jonathan Chai (Arm Technology China)" , "Julien Yin (Arm Technology China)" , "Thomas Sun (Arm Technology China)" , "Lowry Li (Arm Technology China)" , Ayan Halder , "Tiannan Zhu (Arm Technology China)" , "Yiqi Kang (Arm Technology China)" , nd , "linux-kernel@vger.kernel.org" , dri-devel@lists.freedesktop.org List-Id: dri-devel@lists.freedesktop.org Hi James, On Friday, 11 October 2019 06:45:27 BST james qian wang (Arm Technology Chi= na) 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. >=20 > 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(+) >=20 > 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); >=20 > +/** > + * 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. > + */ > +uint64_t drm_color_ctm_s31_32_to_qm_n(uint64_t user_input, > + uint32_t m, uint32_t n) > +{ > + u64 mag =3D (user_input & ~BIT_ULL(63)) >> (32 - n); This doesn't account for n > 32, which is perfectly possible (e.g. Q1.63). > + bool negative =3D !!(user_input & BIT_ULL(63)); > + s64 val; > + > + /* the range of signed 2s complement is [-2^n+m, 2^n+m - 1] */ > + val =3D clamp_val(mag, 0, negative ? BIT(n + m) : BIT(n + m) - 1); This also doesn't account for n + m =3D=3D 64. > + > + 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; >=20 > uint32_t drm_color_lut_extract(uint32_t user_input, uint32_t bit_precisi= on); > +uint64_t drm_color_ctm_s31_32_to_qm_n(uint64_t user_input, > + uint32_t m, uint32_t n); >=20 > void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, > uint degamma_lut_size, > -- > 2.20.1 >=20 --=20 Mihail