From patchwork Wed Oct 16 10:34:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Qian Wang X-Patchwork-Id: 11192923 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 BF3B917E1 for ; Wed, 16 Oct 2019 10:34:29 +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 A17D520872 for ; Wed, 16 Oct 2019 10:34:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A17D520872 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 E65C46E92B; Wed, 16 Oct 2019 10:34:28 +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-eopbgr20056.outbound.protection.outlook.com [40.107.2.56]) by gabe.freedesktop.org (Postfix) with ESMTPS id 04B026E932 for ; Wed, 16 Oct 2019 10:34:27 +0000 (UTC) Received: from VI1PR08CA0146.eurprd08.prod.outlook.com (2603:10a6:800:d5::24) by DB8PR08MB5066.eurprd08.prod.outlook.com (2603:10a6:10:e4::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16; Wed, 16 Oct 2019 10:34:23 +0000 Received: from AM5EUR03FT048.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::206) by VI1PR08CA0146.outlook.office365.com (2603:10a6:800:d5::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2347.16 via Frontend Transport; Wed, 16 Oct 2019 10:34:23 +0000 Received-SPF: TempError (protection.outlook.com: error in processing during lookup of arm.com: DNS Timeout) Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by AM5EUR03FT048.mail.protection.outlook.com (10.152.17.177) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2305.15 via Frontend Transport; Wed, 16 Oct 2019 10:34:21 +0000 Received: ("Tessian outbound 0939a6bab6b1:v33"); Wed, 16 Oct 2019 10:34:16 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 99346b773049ac19 X-CR-MTA-TID: 64aa7808 Received: from 4cddd178ccbc.2 (ip-172-16-0-2.eu-west-1.compute.internal [104.47.4.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 34A94619-5420-4B7C-A6B7-977AAED1B35D.1; Wed, 16 Oct 2019 10:34:10 +0000 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-am5eur02lp2054.outbound.protection.outlook.com [104.47.4.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4cddd178ccbc.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Wed, 16 Oct 2019 10:34:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kXf/QUlr4G3hZYPvJDdPHGY9wideFWLUnAnXMFIBPiS87pRC7GPSCmeHOjOhVjHtMrP4X2WbV8UePddjOGeG8jfuxGpF0rcbpUf+l1VZ3WWHG/MwqfTYAyRpHrXkpHWw2kU6O9zBWQfQg5EwUq+4qZH6+ViNmvsq8KRkCxzA+H10G4wf+P+vjOcAjOhellxtbzK3qbINeLxzuXT9u14WlPOorXjIouNAXvPWB0oB+jyzz+mUMmeOvEIlmdTK6RwC/boXXQ5iO38vpAt2pyNaNxrq6loh5q4AdGtqZ3aC7nT8fh0ohDu8549KQYDCzpLXPe5P2Sg+sUoB+C9QtWQMOQ== 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=XwNLApKNkl72Wy0e6O+y5NOzqaHS2uIq08CitOENDfA=; b=gyvtHpIv4cauAZDYIDkhbMXffAIf1ncW4VLAcd9N2SSe3fiYGHfCf0v6AyOCmfqWUjH0PVcXLa5OP8aEDW4oqVXblctRmtws1B9MTX+wkT1wgjZSaGsLwcZaC7Qq/H8FGzUE0hq0iKlye8r5AooKdEo2L8wF8R46ofYtU+Y3loDOMxLYqfRQwEBpspl+vHWajM/nYCPzM3rmqmUZXnBtkJx7aIS7yny75mspJl2CuPvhmaXvnUwc9bfEW+BvFMaSJi2XghK5nPUeRO9nMgbN3DQQUNJahgmtK4m6/NLXX8UW9w9Ibas67v7yYWrX1B8K5iNPhPeT9PSDpOCBNa3lwA== 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 VE1PR08MB5182.eurprd08.prod.outlook.com (20.179.31.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2347.16; Wed, 16 Oct 2019 10:34:08 +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.2347.023; Wed, 16 Oct 2019 10:34:08 +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 v5 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Topic: [PATCH v5 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Index: AQHVhA09wVtvHgqrOkmWUho1ovfOOQ== Date: Wed, 16 Oct 2019 10:34:08 +0000 Message-ID: <20191016103339.25858-2-james.qian.wang@arm.com> References: <20191016103339.25858-1-james.qian.wang@arm.com> In-Reply-To: <20191016103339.25858-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: HK0PR04CA0006.apcprd04.prod.outlook.com (2603:1096:203:36::18) 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-Correlation-Id: 1b85811c-c757-490c-91c1-08d75224684a X-MS-Office365-Filtering-HT: Tenant X-MS-TrafficTypeDiagnostic: VE1PR08MB5182:|VE1PR08MB5182:|DB8PR08MB5066: x-ms-exchange-transport-forked: True X-Microsoft-Antispam-PRVS: x-checkrecipientrouted: true x-ms-oob-tlc-oobclassifiers: OLM:4941;OLM:4941; x-forefront-prvs: 0192E812EC X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(376002)(366004)(39860400002)(396003)(346002)(136003)(199004)(189003)(1076003)(64756008)(66446008)(66946007)(66556008)(66476007)(2171002)(6486002)(66066001)(71190400001)(8676002)(2201001)(14454004)(6436002)(71200400001)(5660300002)(76176011)(81166006)(81156014)(36756003)(2501003)(52116002)(386003)(6506007)(86362001)(25786009)(256004)(476003)(2616005)(305945005)(3846002)(8936002)(186003)(103116003)(11346002)(446003)(6512007)(478600001)(6116002)(55236004)(2906002)(486006)(54906003)(50226002)(4326008)(7736002)(110136005)(26005)(316002)(102836004)(99286004); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB5182; H:VE1PR08MB5006.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: hBWEbJzky5IBufOc+HQF2LPlVDayfB7/yOzKhZfznZwRF6QawGbPfdj1f4MPREYCL4O8LG5uJMPN5rkxkSQ79Y4HlYq+JwpShnFKVYBYSCVJGVvKPsBqGikQtNuBtt0XpNBCIlKGV0byx1bX+JcLWaEDaDiOrxftbch5SdgtZKhTZBvRRmG0jiud4wTb8YoYP8qgngU7Bl8DS9w+j+7YDZJge1bAuD86+fKKRIdSUrT2umOf/YbNcGgYeLEcDD/CchpdVHjwd9vByK3bSDN+mkoyAoM1BvFxAk/WUVxnsJcTbFaRzAsBjEwJA7nWKksRgSLk3zkVPRwBCzB/8/96QWsTNfmNzkTzDiS1ap4d4ImtD+evZD6ZyxMugw1ZFP6VPLg5FcJvVVc+3sRpUpnACchwUQHnSmMnZ53J+Q8jXbA= MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5182 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT048.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)(39860400002)(136003)(396003)(376002)(189003)(199004)(305945005)(1076003)(3846002)(22756006)(6116002)(26826003)(478600001)(2501003)(25786009)(4326008)(103116003)(23756003)(5660300002)(26005)(2906002)(356004)(110136005)(316002)(54906003)(14454004)(102836004)(36906005)(76130400001)(7736002)(186003)(6512007)(66066001)(70206006)(76176011)(6506007)(70586007)(386003)(486006)(8936002)(50466002)(36756003)(50226002)(2171002)(6486002)(336012)(81166006)(11346002)(446003)(2616005)(476003)(126002)(86362001)(81156014)(8746002)(2201001)(63350400001)(107886003)(47776003)(8676002)(99286004); DIR:OUT; SFP:1101; SCL:1; SRVR:DB8PR08MB5066; H:64aa7808-outbound-1.mta.getcheckrecipient.com; FPR:; SPF:TempError; 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: aeac93ca-8c58-47e9-a67d-08d752246034 NoDisclaimer: True X-Forefront-PRVS: 0192E812EC X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TJx0lPE0BZwsengIylt9z/80Tjp6TvH6G/aIh+IsBxFoHIYsztxA+TGWu0rarLNvaMzYAlegmwYZ4m69Adhu2f64t8r1J4c7XWjsh1sIjsubjPsoMGqMf7G5oyObA/xoofuFWTtb39PWVa3BYQ7cKVED8FXvXEHBeC1PlXD/h4URhGtGsCdmpGTUg9IpWmH4S+gsiva3YStoszYVOJ2y90+RtnYducENFzJfxm6kntiy9Z7Po4sPScRdUv2ZSriqj4wygOX8w9Sgx1QWWZePPxqQYewKv15x/YCgjgmkhe/gCAuId11aJ9sLKPXIcWJ0ETUl9pI2QfkasoDS2z+1KKr/nEms3l89G4/7X10eSEBQTBSF7vAgXj7/3sAuCK3SFXK6MYvegktU3u8kMeWhNbJTKY63HpPiGfxZcedQrSQ= X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2019 10:34:21.7641 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1b85811c-c757-490c-91c1-08d75224684a 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: DB8PR08MB5066 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=XwNLApKNkl72Wy0e6O+y5NOzqaHS2uIq08CitOENDfA=; b=qyYw51jIRqHS3M75guWYLGoq3R0k0OelhTBsqbEbij1wgXcotnO2ia1p1uY7iH0PhYIHDmbaEpnChU1bZGfxgc1M33nQ4r45n82Vqse4N6zbME2xatHo2kZMp2ek4Rgqo9Lj6EJsAk61+ESk9FcNb/nwPdDiXSWrEOIcpPjGMIE= 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=XwNLApKNkl72Wy0e6O+y5NOzqaHS2uIq08CitOENDfA=; b=qyYw51jIRqHS3M75guWYLGoq3R0k0OelhTBsqbEbij1wgXcotnO2ia1p1uY7iH0PhYIHDmbaEpnChU1bZGfxgc1M33nQ4r45n82Vqse4N6zbME2xatHo2kZMp2ek4Rgqo9Lj6EJsAk61+ESk9FcNb/nwPdDiXSWrEOIcpPjGMIE= X-Mailman-Original-Authentication-Results: spf=temperror (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). Signed-off-by: james qian wang (Arm Technology China) Reviewed-by: Mihail Atanassov Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_color_mgmt.c | 27 +++++++++++++++++++++++++++ include/drm/drm_color_mgmt.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index 4ce5c6d8de99..d313f194f1ec 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -132,6 +132,33 @@ 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, include the sign-bit, support range is [1, 32] + * @n: number of fractional bits, only support n <= 32 + * + * Convert and clamp S31.32 sign-magnitude to Qm.n (signed 2's complement). The + * higher bits that above m + n are cleared or equal to sign-bit BIT(m+n). + */ +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 < 1 || m > 32 || n > 32); + + /* the range of signed 2's complement is [-2^(m-1), 2^(m-1) - 2^-n] */ + 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,