From patchwork Tue Nov 12 10:40:24 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: 11239041 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 B64A11515 for ; Tue, 12 Nov 2019 10:40:40 +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 9DACC21783 for ; Tue, 12 Nov 2019 10:40:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DACC21783 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 EB2976EB03; Tue, 12 Nov 2019 10:40:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR02-HE1-obe.outbound.protection.outlook.com (mail-he1eur02on060d.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe05::60d]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B0066EB03 for ; Tue, 12 Nov 2019 10:40:37 +0000 (UTC) Received: from VI1PR0801CA0068.eurprd08.prod.outlook.com (2603:10a6:800:7d::12) by AM5PR0802MB2402.eurprd08.prod.outlook.com (2603:10a6:203:a1::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.22; Tue, 12 Nov 2019 10:40:34 +0000 Received: from AM5EUR03FT029.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::207) by VI1PR0801CA0068.outlook.office365.com (2603:10a6:800:7d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.20 via Frontend Transport; Tue, 12 Nov 2019 10:40:34 +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 AM5EUR03FT029.mail.protection.outlook.com (10.152.16.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.21 via Frontend Transport; Tue, 12 Nov 2019 10:40:34 +0000 Received: ("Tessian outbound 0939a6bab6b1:v33"); Tue, 12 Nov 2019 10:40:31 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 0223c4c3e8757ecc X-CR-MTA-TID: 64aa7808 Received: from de65cc25b090.2 (cr-mta-lb-1.cr-mta-net [104.47.10.51]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id F759FE6A-C118-4ADD-B299-F8CF3F1BE2B2.1; Tue, 12 Nov 2019 10:40:26 +0000 Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-db5eur03lp2051.outbound.protection.outlook.com [104.47.10.51]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id de65cc25b090.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384); Tue, 12 Nov 2019 10:40:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oLzOZrLe+GNCkmAUFv7kFffBcSZ9epXDbttamNCXgD7oDrmVKsTzsfWgD6pxAdoT4gScY311G0o5oAgJHPrNnMxQXRQeE74lRkRPOuuRe/u1lF1agKeFRpSb/SVNX5ECj0hJbiqDSGVFz+zc7ZQnBDt9WLJEu6xF9fqzZlRfkgtsOfB3aJU7fmiE7QflcES+IZ1RSx3EVtolR7F9V1cdOjrcf4BuFtbybn9jCYBsUsSixhSN3sFwAR+PmTQF6THmge3vHYbHSZFdApqw6YYlWWPww1+Kmik1dJ74g3BKlilMePr1HxMxJZ4autZC0F1B7N57cJ7p1VezH9Ht8BwiYA== 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=5xvTegslMD5L2ZURhngFfxlrPcslIxpmCTDULZVxcYM=; b=KqFg0vtulZoKcY3rAUtPXwRLL8t6VsRXhphh1OFG+6PyhUMWmc7LmgHMGyeItCiMs80/EvbUoQiOYBQe0f4GOEQBthhU/23X1jqrRujJ6gxM3+Uj7SoCAQJc26bA6SK8IXeADu/QMQVyQ6TUjDZbaHXaKW2aHELcEYgg1n8zDcLA1SVF/wqbLtsUvs4NoNi9YFPeWdnoeEf58/hRdD9CUINtJVWEhdn18P/ZJq0vA+Q0zYNdt1rZKixUReuwse2c0U9y6hX88Oxi99W/WBK7vpFQKiLkGY7C2r0i4avBVlXoXFE0OVgAeQiKEEmzykp1Oo6/mTi1uq+9D3fFdJmhWA== 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 AM0PR08MB4995.eurprd08.prod.outlook.com (10.255.30.207) by AM0PR08MB4082.eurprd08.prod.outlook.com (20.178.119.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2451.23; Tue, 12 Nov 2019 10:40:24 +0000 Received: from AM0PR08MB4995.eurprd08.prod.outlook.com ([fe80::3c0c:3112:ccbf:13d0]) by AM0PR08MB4995.eurprd08.prod.outlook.com ([fe80::3c0c:3112:ccbf:13d0%6]) with mapi id 15.20.2430.027; Tue, 12 Nov 2019 10:40:24 +0000 From: "james qian wang (Arm Technology China)" To: Liviu Dudau , "airlied@linux.ie" , Brian Starkey , "maarten.lankhorst@linux.intel.com" , "sean@poorly.run" , Mihail Atanassov , "imirkin@alum.mit.edu" Subject: [PATCH v9 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Topic: [PATCH v9 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Index: AQHVmUWWuw5SiCc2fkWBYrtItjbs1w== Date: Tue, 12 Nov 2019 10:40:24 +0000 Message-ID: <20191112103956.19074-2-james.qian.wang@arm.com> References: <20191112103956.19074-1-james.qian.wang@arm.com> In-Reply-To: <20191112103956.19074-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: HK0PR03CA0087.apcprd03.prod.outlook.com (2603:1096:203:72::27) To AM0PR08MB4995.eurprd08.prod.outlook.com (2603:10a6:208:162::15) 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: a17d7899-1e41-4200-cab4-08d7675cbf57 X-MS-TrafficTypeDiagnostic: AM0PR08MB4082:|AM0PR08MB4082:|AM5PR0802MB2402: 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: 021975AE46 X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(346002)(396003)(136003)(39860400002)(199004)(189003)(86362001)(6512007)(478600001)(66066001)(54906003)(110136005)(316002)(5660300002)(6486002)(14454004)(2171002)(11346002)(446003)(2616005)(6436002)(25786009)(476003)(2201001)(5024004)(1076003)(6506007)(8936002)(386003)(99286004)(2906002)(4326008)(55236004)(102836004)(103116003)(256004)(66946007)(66556008)(66476007)(64756008)(66446008)(6116002)(3846002)(52116002)(26005)(81166006)(81156014)(8676002)(186003)(7736002)(486006)(71190400001)(71200400001)(36756003)(305945005)(76176011)(50226002)(2501003); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB4082; H:AM0PR08MB4995.eurprd08.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX: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: ReJv4jvD7YQLbC0YnVJnn44xbYNi/jreBYFSKCUPDERxW6BYEVnTbfKfzuvIuwcOlQwa3WBAFr3tx/1jbCPU36cuQmE4qbQq4RYeGWlhC99Wd6ZH8w5rozz1xaBWsttThognlCVnN8fBlehCtj7ELL9JI+vkwvK+DNbVqUuuFlWnxd4/66HRw9aL16ahl9R6/oExbhJtP2oN8Ey6MEGBz5B/+CUDLPwnziKrhSb7CofYSxt+NLZVKH/ULXbtDqvgBsxKZx+WmdDTtDOWRyamxR9Y+Zy8ohEn1Jctrn7Smk8YXH+yBCUx4U2zNa+jnOd8vAKhVBkvi1G4n3SIsfnqOxPMNHJY4Kg8Ldyf6t2ZC7DarguxahpShWkhZQTZNWWxxAtC4tzWuUEHzs7UZubtbfR3MU9ePBdGeQJssqWq0cESobbWavLbE+JauN/IuOK5 Content-ID: MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB4082 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT029.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)(346002)(136003)(396003)(39860400002)(376002)(1110001)(339900001)(189003)(199004)(103116003)(86362001)(26826003)(2201001)(478600001)(22756006)(6486002)(107886003)(81166006)(81156014)(8676002)(6512007)(105606002)(2171002)(4326008)(36756003)(186003)(14454004)(66066001)(47776003)(99286004)(70206006)(356004)(1076003)(70586007)(102836004)(6506007)(386003)(26005)(2906002)(2501003)(126002)(2616005)(11346002)(476003)(5660300002)(50226002)(446003)(486006)(5024004)(336012)(436003)(54906003)(8936002)(76130400001)(316002)(305945005)(7736002)(23676004)(2486003)(36906005)(25786009)(3846002)(76176011)(110136005)(50466002)(6116002); DIR:OUT; SFP:1101; SCL:1; SRVR:AM5PR0802MB2402; 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: 8aa1d5c2-c8ce-41c6-da6a-08d7675cb94f NoDisclaimer: True X-Forefront-PRVS: 021975AE46 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4L4V1nW02LywWohksim4KOqOSrQvCF//Hvy+oEeNNUKV+mFLTxo2YSdaPMsUhDWW7RfZwtWEvDayvIi2Ilov2kCeJRc2YVOv7Z1QfLzgqu3BCR3RC96tJS13JgZ54ZQtREfB63M/YcucPDJzbbfDKLAs+6uHWK6ZwN5XjmJlvo96LvafQBGtspphou3kW3pK9Qq1e3WeMqVMIvGoI8nKgF4XDHawWv9zJhTLLF8gdG42i79ZVeybtOQkcSdsuwEvMy4WF17aLp6D2E6O3gDvHKemURoym7P5AkOXzn2yQ0B5j/kmh+lgitZaeR4bMT1U5VAvrhl06bqZMe7tn1ARVWPDM3M5BdmfdFrcgA7eAu7rdN0V+LIlcLU+XQRI29021faUVta3+N5cx3f99YzfpZBx/JfOpy1e6TsloNsUbCobkBUL6D02sdkpIyAa4os/ X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2019 10:40:34.0407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a17d7899-1e41-4200-cab4-08d7675cbf57 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: AM5PR0802MB2402 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=5xvTegslMD5L2ZURhngFfxlrPcslIxpmCTDULZVxcYM=; b=ryJcvghUMnexM7ge7eE8VundpyqFzbWEbOk9bopnKiSpStzppcSqhMFC82RU5tTWDJkNeXTndiYw59OOvpAEnarwQ3dqoqET/EatuoTlLfyFwIm8bS1vJ06i68MfhFL6uc3w64x3wtlrClnrZKINUhQ7ynir1Bk+tar+9Jnv0pY= 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=5xvTegslMD5L2ZURhngFfxlrPcslIxpmCTDULZVxcYM=; b=ryJcvghUMnexM7ge7eE8VundpyqFzbWEbOk9bopnKiSpStzppcSqhMFC82RU5tTWDJkNeXTndiYw59OOvpAEnarwQ3dqoqET/EatuoTlLfyFwIm8bS1vJ06i68MfhFL6uc3w64x3wtlrClnrZKINUhQ7ynir1Bk+tar+9Jnv0pY= 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\)" , 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. V7: Address Mihail's comments. V8: Use type 'u32' to replace 'uint32_t' v9: Rebase Signed-off-by: james qian wang (Arm Technology China) Reviewed-by: Mihail Atanassov Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_color_mgmt.c | 35 ++++++++++++++++++++++++++++++++ include/drm/drm_color_mgmt.h | 1 + 2 files changed, 36 insertions(+) -- 2.20.1 diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index 4ce5c6d8de99..9de10abc7a96 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -132,9 +132,44 @@ 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-1) 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 + */ +u64 drm_color_ctm_s31_32_to_qm_n(u64 user_input, u32 m, u32 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 + * * @degamma_lut_size: the size of the degamma lut (before CSC) * @has_ctm: whether to attach ctm_property for CSC matrix * @gamma_lut_size: the size of the gamma lut (after CSC) diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h index d1c662d92ab7..997a42ab29f5 100644 --- a/include/drm/drm_color_mgmt.h +++ b/include/drm/drm_color_mgmt.h @@ -30,6 +30,7 @@ struct drm_crtc; struct drm_plane; uint32_t drm_color_lut_extract(uint32_t user_input, uint32_t bit_precision); +u64 drm_color_ctm_s31_32_to_qm_n(u64 user_input, u32 m, u32 n); void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, uint degamma_lut_size,