From patchwork Wed Oct 23 06:42:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: James Qian Wang X-Patchwork-Id: 11205751 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA138139A for ; Wed, 23 Oct 2019 06:43:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B0DFC21906 for ; Wed, 23 Oct 2019 06:43:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B0DFC21906 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EDE2C6E95F; Wed, 23 Oct 2019 06:43:10 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02on0625.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe06::625]) by gabe.freedesktop.org (Postfix) with ESMTPS id A86296E95F for ; Wed, 23 Oct 2019 06:43:09 +0000 (UTC) Received: from VI1PR08CA0175.eurprd08.prod.outlook.com (2603:10a6:800:d1::29) by HE1PR0801MB1769.eurprd08.prod.outlook.com (2603:10a6:3:7f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16; Wed, 23 Oct 2019 06:43:05 +0000 Received: from AM5EUR03FT041.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::201) by VI1PR08CA0175.outlook.office365.com (2603:10a6:800:d1::29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.21 via Frontend Transport; Wed, 23 Oct 2019 06:43:05 +0000 Received-SPF: Fail (protection.outlook.com: domain of arm.com does not designate 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT041.mail.protection.outlook.com (10.152.17.186) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2367.23 via Frontend Transport; Wed, 23 Oct 2019 06:43:05 +0000 Received: ("Tessian outbound e4042aced47b:v33"); Wed, 23 Oct 2019 06:43:03 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 1af05dff4a19bcd4 X-CR-MTA-TID: 64aa7808 Received: from 68dd3a3811af.2 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.8.56]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id FF873FE2-02A2-4B73-B53D-6B93DD935D4A.1; Wed, 23 Oct 2019 06:42:57 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-am5eur03lp2056.outbound.protection.outlook.com [104.47.8.56]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 68dd3a3811af.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 23 Oct 2019 06:42:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SUSu0OWQQHeveEFbKcYDJL3Xx3iDycHrkay6owVnOMykMv+ZFZiBYb1fcnXyA+vTswvHZ1UPRnWku9aQdvQxp5MjBMgUn/Kx5QuPh2O3yQnPeiwr5WIJsfO2z4C92KY6fC4jcK2OZ06KvaL8aFq2bRnTHttJGw28D+TMxWYFL1SQ//Ozqcftpuu9+RSom4klaiur1Bd0nf6zoLIz0//Eupaj0iudO08T2I9Hv10atYhCEFqRZZK3Fis5gPQ0kZEfMHQdKX25YMeGGyxIgec0lIxPvREQbCwAmP2g1qWVb7DblP4BKp/L5yzxbpgCj72F5EjJbCCSzQOLN/40/a2M9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FR0RtOODGwJKPGPv6sNfKERHsmalyGvuC8CCokH63Tw=; b=jRHBC4EfqFHvJPfJQlJDH/gcPUD+T8B2nO4yj1iG2zEa+ab5ZeoTrbcX7Hg7guaeBXOTdTRgM6+796+f70mWa3/pI+WNOInzdmzuhtbChvnQ39YzROabWnRRPKEMW+YObnKS8d5xwZ2dxQLutyWbaLBguwCTPGX6NKD6t7s+n9Ps7zKOB49c/t03WJn9wwar5G61z4R6SEG+pUwaKv3qsN0REP4bnySSrKdqv/4KlsmQCB8qOrI/xG7Dcg/kaCrZ4jr5bWDEyGLyDldJqmzAnv8fezspVkf741r3j/ySJk2G4J0LSZPM6UZwG+GXm3HZbxFX8Ng2xBDgoZ5klpL4Dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none Received: from VE1PR08MB5006.eurprd08.prod.outlook.com (10.255.159.31) by VE1PR08MB4672.eurprd08.prod.outlook.com (10.255.112.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.22; Wed, 23 Oct 2019 06:42:56 +0000 Received: from VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::40ed:7ed3:90cf:ece5]) by VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::40ed:7ed3:90cf:ece5%3]) with mapi id 15.20.2367.022; Wed, 23 Oct 2019 06:42:56 +0000 From: "james qian wang (Arm Technology China)" To: Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "sean@poorly.run" , "imirkin@alum.mit.edu" Subject: [PATCH v7 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Topic: [PATCH v7 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Index: AQHViW0axzrBedn3A0yRNgX73SioEQ== Date: Wed, 23 Oct 2019 06:42:55 +0000 Message-ID: <20191023064226.10969-2-james.qian.wang@arm.com> References: <20191023064226.10969-1-james.qian.wang@arm.com> In-Reply-To: <20191023064226.10969-1-james.qian.wang@arm.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [113.29.88.7] x-clientproxiedby: HK2PR02CA0184.apcprd02.prod.outlook.com (2603:1096:201:21::20) To VE1PR08MB5006.eurprd08.prod.outlook.com (2603:10a6:803:113::31) Authentication-Results-Original: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.20.1 x-ms-publictraffictype: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 9589ceb8-1707-4395-70b9-08d75784425b X-MS-TrafficTypeDiagnostic: VE1PR08MB4672:|VE1PR08MB4672:|HE1PR0801MB1769: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:6790;OLM:6790; x-forefront-prvs: 019919A9E4 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(396003)(136003)(39860400002)(366004)(376002)(346002)(189003)(199004)(7736002)(25786009)(2906002)(386003)(71200400001)(4326008)(36756003)(305945005)(6506007)(66066001)(2201001)(71190400001)(102836004)(5660300002)(26005)(478600001)(52116002)(55236004)(316002)(86362001)(186003)(6116002)(76176011)(3846002)(256004)(2171002)(66446008)(66946007)(103116003)(64756008)(6512007)(1076003)(66556008)(50226002)(66476007)(476003)(6436002)(8936002)(446003)(2501003)(11346002)(2616005)(6486002)(14454004)(486006)(54906003)(99286004)(81166006)(8676002)(81156014)(110136005); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB4672; H:VE1PR08MB5006.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: jc9qNN95z2LggFhMQUr/etJwrvoKW1S/byLD6AwTxBR+ydkc8Xjpn+WLnZn05hFXwQrdKXAUk51lVqCE942ff8DpyrY3lpOrVpFR9RnQxsPTLSTX4pbePMqx1hfhLgeJyJbv7SZBLmLs8lDCDD1PbxybUYWShuO7JoR8SxW533pINf2Iv5iHGM6XpbpgfDm7byTkmq65z7R26ioRPKqBv96whmzlH3BRXHjHEMeKvq4C0nPIQ/8AiurL7pwf0HMJKGR+YgsgX920LHuXHLvf3r1LHjYz3jaUXZ2IBRLQa4hVUcLpzMy0OSfEwVLXmo/jeMy0EAG7hSOFVq0lQ38/I0VdfhaFcq3ZZYqFIc4bdd1P4Wquo8UwWIT/you8VHNHEAmczGWFneb96wkAeiG4NBw33WxKfk0gZwifjCBz3XE= Content-ID: MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB4672 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT041.eop-EUR03.prod.protection.outlook.com X-Forefront-Antispam-Report: CIP:63.35.35.123; IPV:CAL; SCL:-1; CTRY:IE; EFV:NLI; SFV:NSPM; SFS:(10009020)(4636009)(136003)(396003)(376002)(346002)(39860400002)(1110001)(339900001)(189003)(199004)(2201001)(105606002)(1076003)(4326008)(25786009)(103116003)(107886003)(5660300002)(356004)(6486002)(2906002)(6512007)(86362001)(2171002)(14454004)(23676004)(2486003)(2501003)(478600001)(54906003)(126002)(476003)(316002)(386003)(6506007)(110136005)(76130400001)(99286004)(11346002)(66066001)(36756003)(102836004)(2616005)(81156014)(47776003)(486006)(436003)(336012)(6116002)(3846002)(446003)(8676002)(50226002)(26005)(81166006)(8936002)(186003)(76176011)(22756006)(26826003)(305945005)(36906005)(7736002)(50466002)(70206006)(70586007); DIR:OUT; SFP:1101; SCL:1; SRVR:HE1PR0801MB1769; H:64aa7808-outbound-1.mta.getcheckrecipient.com; FPR:; SPF:Fail; LANG:en; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; MX:1; A:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: 506f0e41-01e0-40d1-85a2-08d757843c58 NoDisclaimer: True X-Forefront-PRVS: 019919A9E4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B6zO0q61gK0ar5cD0FNR90umAX6yPLwDC8fIP7ZYxBVFF1qCk9CmLwnrdd75W3PhJijdV5ZMQm4OUZNCJDhSCKCtRgaX9Rm7qN7cGGjasheLdZVaQO9yPU1EUe6JAGR097EtENdDMJ2MHm+QfrBgvzX23RskSDM5TIBtXNq1yKnx/hglL9N8vHKHdwd0yqIoNt1BTLCm1t4j95eFym8e1BgFlUwf2qKc0J2VIWWwv/2pwIHALi9weTcHJLPQttCzQoFKkBXYTlliknpTSRWpVmarHZWFVvz/RaQjA8W7KE+jbx46rYWJfAdVYynhmaedTj8kzuBgeg4umF7Mgw+fb5Yd1meQDzr15n7cZDFHLeCbiyyKoStB545E3peDNw/DZQowMBao8WWN3fLyk/1AVdBX8AtuRrdPd89fSt/JKPeshvzvPLVT7bkkxBOzKcB8 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2019 06:43:05.6231 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9589ceb8-1707-4395-70b9-08d75784425b X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d; Ip=[63.35.35.123]; Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1769 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FR0RtOODGwJKPGPv6sNfKERHsmalyGvuC8CCokH63Tw=; b=YMqWKiuCELDGBTmwKU4eaufSfYSAEt0jyTGK03oTp3IqCQtaouR4aisJhXiXrOH8et0nA0Zqvm+TvRbV6pdH2kBUXjPTtHD48OXiEw+p0jF6jvBCV152lPFB6eJASf0P+rFOVFLP0uDykDVUgSZ+Q9iR+nmu9i1JmE2mZrcEVwU= X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FR0RtOODGwJKPGPv6sNfKERHsmalyGvuC8CCokH63Tw=; b=YMqWKiuCELDGBTmwKU4eaufSfYSAEt0jyTGK03oTp3IqCQtaouR4aisJhXiXrOH8et0nA0Zqvm+TvRbV6pdH2kBUXjPTtHD48OXiEw+p0jF6jvBCV152lPFB6eJASf0P+rFOVFLP0uDykDVUgSZ+Q9iR+nmu9i1JmE2mZrcEVwU= X-Mailman-Original-Authentication-Results: spf=fail (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; lists.freedesktop.org; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;lists.freedesktop.org; dmarc=none action=none header.from=arm.com; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nd , Ayan Halder , "Oscar Zhang \(Arm Technology China\)" , "Tiannan Zhu \(Arm Technology China\)" , Mihail Atanassov , Daniel Vetter , "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\)" , "james qian wang \(Arm Technology China\)" , "Yiqi Kang \(Arm Technology China\)" , "Thomas Sun \(Arm Technology China\)" , "Lowry Li \(Arm Technology China\)" , Ben Davis Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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. V4: Address Mihai, Daniel and Ilia's review comments. V5: Includes the sign bit in the value of m (Qm.n). V6: Allows m = 0 according to Mihail's comments. V6: Address Mihail's comments. Signed-off-by: james qian wang (Arm Technology China) Reviewed-by: Mihail Atanassov Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_color_mgmt.c | 36 ++++++++++++++++++++++++++++++++ include/drm/drm_color_mgmt.h | 2 ++ 2 files changed, 38 insertions(+) diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index 4ce5c6d8de99..f5fba5802a07 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -132,6 +132,42 @@ 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, only support m <= 32, include the sign-bit + * @n: number of fractional bits, only support n <= 32 + * + * Convert and clamp S31.32 sign-magnitude to Qm.n (signed 2's complement). + * The sign-bit BIT(m+n) and above are 0 for positive value and 1 for negative. + * the range of value is [-2^(m-1), 2^(m-1) - 2^-n] + * + * For example + * A Q3.12 format number: + * - required bit: 3 + 12 = 15bits + * - range: [-2^2, 2^2 - 2^−15] + * + * NOTE: the m can be zero if all bit_precision are used to present fractional + * bits like Q0.32 + */ +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; + + WARN_ON(m > 32 || n > 32); + + + val = clamp_val(mag, 0, negative ? + BIT_ULL(n + m - 1) : BIT_ULL(n + m - 1) - 1); + + return negative ? -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,