From patchwork Fri Nov 1 06:53:48 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: 11222445 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 573F71515 for ; Fri, 1 Nov 2019 06:54:04 +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 3DEF620862 for ; Fri, 1 Nov 2019 06:54:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3DEF620862 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 5A33B6F70B; Fri, 1 Nov 2019 06:54:03 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-eopbgr80087.outbound.protection.outlook.com [40.107.8.87]) by gabe.freedesktop.org (Postfix) with ESMTPS id B474C6F70B for ; Fri, 1 Nov 2019 06:54:01 +0000 (UTC) Received: from VI1PR0802CA0023.eurprd08.prod.outlook.com (2603:10a6:800:aa::33) by AM6PR08MB4181.eurprd08.prod.outlook.com (2603:10a6:20b:ad::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.17; Fri, 1 Nov 2019 06:53:59 +0000 Received: from AM5EUR03FT063.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e08::204) by VI1PR0802CA0023.outlook.office365.com (2603:10a6:800:aa::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.19 via Frontend Transport; Fri, 1 Nov 2019 06:53:59 +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 AM5EUR03FT063.mail.protection.outlook.com (10.152.16.226) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2387.20 via Frontend Transport; Fri, 1 Nov 2019 06:53:58 +0000 Received: ("Tessian outbound 851a1162fca7:v33"); Fri, 01 Nov 2019 06:53:55 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 92d12cd53eaa3310 X-CR-MTA-TID: 64aa7808 Received: from abe47f65ad90.2 (cr-mta-lb-1.cr-mta-net [104.47.12.52]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id B3EBD2C7-9F12-4CC4-9113-C9F60B07E2B5.1; Fri, 01 Nov 2019 06:53:50 +0000 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04lp2052.outbound.protection.outlook.com [104.47.12.52]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id abe47f65ad90.2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Fri, 01 Nov 2019 06:53:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ODPFK7WWenQsSKWZMXall798vNEwCaxsWbMh5Y7o06vGsIBBJOu3OGCONAbXi+5EGJZkNvsNjO+eSMnFgIWJcPt3A/CCMgsrd1NvU6Y2ShKnyn/OnBkLJn5/SluhhRi/xpuc0IKobTzeHvIv+edG40EvsX0XwHTxHEydTORgNWh5tX48biYNpPpPisY7fuopv04Gzpk6O/jh+r/NXOQHpZki3fT3/3visjNhkUUhMG8iYmcHJHi5YzFCl7TPsjLaRVEvDjM6Zr6hsz+V2gnzC3DxHTC//siPFptiQtsKY9YqHbohAEv9YgNp71dlqp0SKwKi/n0cHL25FHMBMHNHgQ== 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=pKQW6Eb95un6S0A37aPXjNKy9DHe+ZMM0AYifmcrwpU=; b=ed+pIRp1S+r6iXEMw3vJQofBCUQqk3rncq5Xw9DNQ1YeVs7jGzZqQqdcXAz0R2OTHzFc9AtY0PzhhFOoW39DCyhS3iN7Ub4G3M+wRwd9eakTF35goHJ4bkhrVCGaGhlukLi3oO4qe7cW9f5vR5DzCJx9LPKuz6V2Z+ifihGGt11JmbgkPPoN1OdO5eGVOqNxPAo70MjZd9w3crZZ/R2aeSxkP7Ko432ksjLJIqkNhrHydlP7r7gbSbwHmo9QZojxPCLFN4jU29K2P7Qc+z/NahY2YeRnA5EBoJkCpk1YwiA1VqRut2In6Dnn9mt5HzmH+t80guwrFOaziS6gG8Tfdg== 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 VE1SPR01MB0002.eurprd08.prod.outlook.com (20.179.193.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2408.17; Fri, 1 Nov 2019 06:53:48 +0000 Received: from VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::a809:417a:faf3:61a7]) by VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::a809:417a:faf3:61a7%6]) with mapi id 15.20.2387.030; Fri, 1 Nov 2019 06:53:48 +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 v8 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Topic: [PATCH v8 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Index: AQHVkIEc5Q+Snrdv1U6+DG7E3z5ENg== Date: Fri, 1 Nov 2019 06:53:48 +0000 Message-ID: <20191101065319.29251-2-james.qian.wang@arm.com> References: <20191101065319.29251-1-james.qian.wang@arm.com> In-Reply-To: <20191101065319.29251-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: HK2PR0302CA0022.apcprd03.prod.outlook.com (2603:1096:202::32) 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: a03592b8-8bb5-4112-e68a-08d75e98457b X-MS-TrafficTypeDiagnostic: VE1SPR01MB0002:|VE1SPR01MB0002:|AM6PR08MB4181: 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: 020877E0CB X-Forefront-Antispam-Report-Untrusted: SFV:NSPM; SFS:(10009020)(4636009)(396003)(376002)(136003)(39860400002)(346002)(366004)(199004)(189003)(66066001)(446003)(11346002)(2616005)(486006)(36756003)(8676002)(14454004)(5660300002)(476003)(103116003)(2501003)(2171002)(86362001)(3846002)(6116002)(305945005)(2201001)(25786009)(1076003)(6512007)(66476007)(52116002)(71200400001)(71190400001)(386003)(55236004)(6506007)(6436002)(102836004)(6486002)(7736002)(186003)(99286004)(8936002)(110136005)(4326008)(54906003)(50226002)(478600001)(64756008)(2906002)(66446008)(81156014)(66556008)(316002)(66946007)(81166006)(76176011)(256004)(26005); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1SPR01MB0002; 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: LA3SPFQ2Lsfv6b+GKsc2dUYuNvOgCTzXZ2Zdqdx4sOW3m2dXcV6FdA5NJBbCIwhnJXNBVp3btJzOTFwVhpP/6qe8G21BLbkBCBjJ2lfrePHsDMZsuhI0Cgwj3thQxcKe5AzZu/zerThJ31NwfLrT3oe/NsCVZOrZYmPiZxlX17j43bGfSF0l0b85Ly3vD0VaHFEe5uXoxjXdk90utCz14WRZ+ugdwKvDte7WubaO65YphbhX0/L+syY2QCsQ2GCq0+LpYLo15vzPR2x4H+/YPWtEp/XO/LDTuqL+B7PinBA8W/icZNrxnUvpWJ5tim285ANzeMGt2lWuW1TcgfZBZkz/NLXld1GE7AnB3bIFH5tjibsnwCRGh3kI5BNF57FOEGfmlbYceEG40/iUQMGE03M8OlUwV1ZH1v4KFQgpLYqxAjzmudyZRGywzhnqwyih Content-ID: <50920539A9C20C47A86B9DC6F52106ED@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1SPR01MB0002 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: AM5EUR03FT063.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)(376002)(396003)(136003)(346002)(39860400002)(1110001)(339900001)(199004)(189003)(3846002)(54906003)(81156014)(50226002)(70206006)(70586007)(103116003)(110136005)(105606002)(81166006)(107886003)(47776003)(66066001)(2171002)(8676002)(22756006)(26826003)(6512007)(36906005)(14454004)(305945005)(6486002)(316002)(4326008)(7736002)(36756003)(2201001)(2486003)(8936002)(99286004)(2501003)(50466002)(23676004)(486006)(5660300002)(86362001)(26005)(478600001)(356004)(386003)(6506007)(102836004)(2906002)(186003)(76176011)(1076003)(446003)(436003)(336012)(476003)(126002)(76130400001)(6116002)(25786009)(11346002)(2616005); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR08MB4181; H:64aa7808-outbound-1.mta.getcheckrecipient.com; FPR:; SPF:Fail; LANG:en; PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com; A:1; MX:1; X-MS-Office365-Filtering-Correlation-Id-Prvs: 51cf4374-da76-413b-1999-08d75e983ed1 NoDisclaimer: True X-Forefront-PRVS: 020877E0CB X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: G8VCM04Tr/+BOopv+J8OkDSi/RN5veqTanVIqYNSnlkbMEXyg38Exk4Pw2pqnHwgbhwGqIFTa0pNW0sViX0aoqbPebb3D4TbubTzVVGKNXsZSdh0gLXZbQeiEnf0MRsyxE+xWXGVSKfYkm5YjjD+HEXIndrINoN6N1tGEgnGWUT/oatbKO/8wFQmas/vb6w0+Vxe3bJ0Mi9cQYczVxEnLX07BdCT5OdJevY3qafuxpkl7RZqxD03LFj/m/B01PQvLLPO+55a4/RZFwz6cgfeOtQ8NJunDFd0d426RyEAvEPoBFwKsAwkZn4ioWHoRzXdQSQIYs1m4nxy7P7g+EF/MO8ze68GYlIlVtRxwm5liP3GgjJkhwPiXGb1MisSzuQkpDdd2k5lS7mENTTocKbrWIWU5rjJtYyEjuayDk0wIWrRcertHAmo03ngLeD0T/ny X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2019 06:53:58.9181 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a03592b8-8bb5-4112-e68a-08d75e98457b 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: AM6PR08MB4181 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=pKQW6Eb95un6S0A37aPXjNKy9DHe+ZMM0AYifmcrwpU=; b=hFAoCQzckQZhnxmJJfzJPLVJ7MUtUORTu+BbaZg65fa7SeD4X4TcJyKeOEe/6bgtkBNlEcEzwQLJEkZr3LpOz86dIwai7sdXY/EdWtr2R2+i97zSofLfP/WBS8V9PeLHFSvcf11MgaBOHn+be9DdO2s6+ZN5oolx8EyVezcQHkk= 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=pKQW6Eb95un6S0A37aPXjNKy9DHe+ZMM0AYifmcrwpU=; b=hFAoCQzckQZhnxmJJfzJPLVJ7MUtUORTu+BbaZg65fa7SeD4X4TcJyKeOEe/6bgtkBNlEcEzwQLJEkZr3LpOz86dIwai7sdXY/EdWtr2R2+i97zSofLfP/WBS8V9PeLHFSvcf11MgaBOHn+be9DdO2s6+ZN5oolx8EyVezcQHkk= 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' Signed-off-by: james qian wang (Arm Technology China) Reviewed-by: Mihail Atanassov Reviewed-by: Daniel Vetter --- drivers/gpu/drm/drm_color_mgmt.c | 34 ++++++++++++++++++++++++++++++++ include/drm/drm_color_mgmt.h | 1 + 2 files changed, 35 insertions(+) diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index 4ce5c6d8de99..ba71e3b827f1 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -132,6 +132,40 @@ 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 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,