From patchwork Tue Nov 12 11:09:59 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: 11239093 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 D326914ED for ; Tue, 12 Nov 2019 11:10:24 +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 B9D8221783 for ; Tue, 12 Nov 2019 11:10:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B9D8221783 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 A9BB36E22A; Tue, 12 Nov 2019 11:10:20 +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-eopbgr80041.outbound.protection.outlook.com [40.107.8.41]) by gabe.freedesktop.org (Postfix) with ESMTPS id A79A96E22A for ; Tue, 12 Nov 2019 11:10:13 +0000 (UTC) Received: from VI1PR08CA0197.eurprd08.prod.outlook.com (2603:10a6:800:d2::27) by VE1PR08MB4912.eurprd08.prod.outlook.com (2603:10a6:802:a9::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.24; Tue, 12 Nov 2019 11:10:11 +0000 Received: from VE1EUR03FT043.eop-EUR03.prod.protection.outlook.com (2a01:111:f400:7e09::206) by VI1PR08CA0197.outlook.office365.com (2603:10a6:800:d2::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2430.23 via Frontend Transport; Tue, 12 Nov 2019 11:10:11 +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 VE1EUR03FT043.mail.protection.outlook.com (10.152.19.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.2430.21 via Frontend Transport; Tue, 12 Nov 2019 11:10:11 +0000 Received: ("Tessian outbound 851a1162fca7:v33"); Tue, 12 Nov 2019 11:10:07 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 8c1b62e43d8bdea4 X-CR-MTA-TID: 64aa7808 Received: from 4b70c4a1f660.1 (cr-mta-lb-1.cr-mta-net [104.47.6.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com id 71930C17-C8E2-4B5B-8258-16B6696CBCBB.1; Tue, 12 Nov 2019 11:10:01 +0000 Received: from EUR02-VE1-obe.outbound.protection.outlook.com (mail-ve1eur02lp2054.outbound.protection.outlook.com [104.47.6.54]) by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id 4b70c4a1f660.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384); Tue, 12 Nov 2019 11:10:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AzosQRvGR0ujEQlIIoyKrrUK5Gz96sfNZttRoq6xfKGSSNaMaCVtBlDaVkSMbCmwYkDGetkMDnyPORsUVQhbQpnzfaU+9Kg8KSr2jYd+25ng0yNGHXWgfaAJgaZX7S6CIf7MahxxPSr+xOcEIWbmN3u5Q91qUwqRC+xO23v5AusjeIIV3ktR8KeJUfvxr/f82iL1C/IvLfD5+bM8lNNiQuaUEJqGIIqHj1dLepVBZmjC8EsIaH7ihJUhCaomE8Y27AlaRAGQjy17oqNWFvpMkQd4DWACAKPphJxnBhISrP417BpuvgJdIpO38ibtBgnQtbZKYBCl1sY0g06oBDnUIw== 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=4cVA01VPTm34igIPoloOoMRrAW1GGU6jFUdYSaPiuuk=; b=hY3CzOq7RXygXd7jfDlrzAeu/Jg+eko4WDS3oAWkC2MzrdDVnESnudIK4Gnl+DTMMePw72Yvbs0vY0FjNju0WRYUo5lVXsjN6wrXLWicHHJlf1X/ovoR02XEc3F831psD6OjfbaLpl5VM1Hcyms7F7iMt8NwiJQ0o/K/HwCVcYoKo8oEiqQOXVebv83p3Ga74rSVWE1INvDvYuliredYVFHr9kAjtoSCFfMGOgrLJLFyZcPCQ/MLrInhlc/w08iCvkskA0M0CcBpf8LJIcuA7yvPvNMv0INnzMnNLz50rvG2bQUuwpGn6JNWAErabAoowVs20LzRD2igNHhsiQjoUA== 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 AM0PR08MB3636.eurprd08.prod.outlook.com (20.177.43.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2430.20; Tue, 12 Nov 2019 11:10:00 +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 11:10:00 +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 v10 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Topic: [PATCH v10 1/4] drm: Add a new helper drm_color_ctm_s31_32_to_qm_n() Thread-Index: AQHVmUm5GoYUWOqrlUaBroU+1xdxlw== Date: Tue, 12 Nov 2019 11:09:59 +0000 Message-ID: <20191112110927.20931-2-james.qian.wang@arm.com> References: <20191112110927.20931-1-james.qian.wang@arm.com> In-Reply-To: <20191112110927.20931-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: HK0PR03CA0106.apcprd03.prod.outlook.com (2603:1096:203:b0::22) 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: 41e05263-a2e0-4503-f887-08d76760e2a6 X-MS-TrafficTypeDiagnostic: AM0PR08MB3636:|AM0PR08MB3636:|VE1PR08MB4912: 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)(136003)(346002)(396003)(39860400002)(376002)(366004)(199004)(189003)(2906002)(99286004)(446003)(2616005)(476003)(7736002)(66066001)(6512007)(6436002)(6486002)(11346002)(54906003)(256004)(305945005)(103116003)(110136005)(316002)(2201001)(14454004)(6116002)(2501003)(86362001)(3846002)(486006)(71200400001)(71190400001)(186003)(386003)(36756003)(1076003)(6506007)(5660300002)(81166006)(8676002)(4326008)(50226002)(26005)(76176011)(66946007)(2171002)(52116002)(81156014)(66446008)(102836004)(66476007)(64756008)(8936002)(66556008)(25786009)(55236004)(478600001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM0PR08MB3636; 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: tYu4chbxV2kejrJxKtWJI4gl3py26hLDymUJOBXoo92pdmVZqcIauhquIHPT20GYGAbJXLnzbfaM3yTz0M7sef/eNwhCmnRD0fJXkY+QopME+N5Rd75PMcDKvgxTILyLRpOaYUVEMe9kiewbVSg4IRzN8to8vzQxvmasF1Z3xrhyCPTSzn+Bw5FvxylDuKRdS4bReT6W4KYOzWRmjjwI3uby2sTdGvHhdMvccySZjMyrSApFDhJh90Z38jsvwCJmA9/Bei5rhSJmijcfrPXZXow+6ht0mAXUEzsPm+k2LEqVPlCGBzpQKgnWAhexuyDhoyKj5JqBnpQKI1JVLHe7jXq6Mj7YAG2+TgAhWgozkXi5QIGFT8G7hydscisBXFt74lWOBKRn/w0DaUd/gzeoh+exYIertVHHBtDTdna2nlDj7cwKkdP7FMIePvGqeQ2G Content-ID: <4A2532144974164FB0D33DCB16C5AE24@eurprd08.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3636 Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: VE1EUR03FT043.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)(346002)(396003)(39860400002)(376002)(1110001)(339900001)(189003)(199004)(50466002)(2501003)(36756003)(2486003)(23676004)(76176011)(486006)(26005)(25786009)(110136005)(1076003)(446003)(11346002)(54906003)(476003)(2616005)(7736002)(76130400001)(22756006)(356004)(86362001)(305945005)(70206006)(336012)(436003)(14454004)(36906005)(386003)(6506007)(2201001)(50226002)(99286004)(105606002)(3846002)(6116002)(107886003)(66066001)(81166006)(4326008)(5660300002)(478600001)(103116003)(70586007)(8676002)(102836004)(81156014)(8936002)(2906002)(2171002)(126002)(6512007)(26826003)(6486002)(316002)(186003)(47776003); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB4912; 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: ff22d156-645f-4d84-f095-08d76760dbb1 NoDisclaimer: True X-Forefront-PRVS: 021975AE46 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1ek3i3rdUuqHO999/OcFTzkGhc5k35FLOg137e4rWaFe1r6+b9TmBbjoM5T6y0CinaijNflz1rkvTvrPAIOFftsiKJXmwYqaXyhE4PVh9wMxYHOd2+W2XTg8zhMxfnVQkFPRG0xJS8/cbVM9zgtkdxB4KdRitF0H3VpRHWi9HAmQUcUgX9bbWJcxt3s3dN0qW8MJMJQx1QuccaEiPmpjUPGZ7frhosSHDm4FivOA0shki9Y0BoL5YD1nzolyDj2c+gDe9FmXKPCs2cOUvZFc156/62Al9l5abNhNl/LmCYYVWqS0JqRGoM3cf7bxQNTM9MbliOvSjtc5wx5oVRAfr3n2tdY3dTDa4EKHdayzWFRva/yAV8xT2mEgot+MnWQLMzATHeEt6hJ7RNQe94uSLQEMEZlx+X/XSopPOJR1BWQ66lPeYzUtbkP040YXzwE0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Nov 2019 11:10:11.1798 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41e05263-a2e0-4503-f887-08d76760e2a6 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: VE1PR08MB4912 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=4cVA01VPTm34igIPoloOoMRrAW1GGU6jFUdYSaPiuuk=; b=a7S8FA0ZNG+RFrvG7J9emCFOZWaTb+z/L/Kd4PePaCk4iMbgxgBCYJQSw0/fMEqd0wBBgQpKJqvMnC7nj6Ur2rniob/EDV+4JE1JR/02dCn3IUJ7BNIDxzY0HoejZQxltuDSCvD/QdXRqPeL4HO/WGavxF9c539tr2GP4lld6wQ= 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=4cVA01VPTm34igIPoloOoMRrAW1GGU6jFUdYSaPiuuk=; b=a7S8FA0ZNG+RFrvG7J9emCFOZWaTb+z/L/Kd4PePaCk4iMbgxgBCYJQSw0/fMEqd0wBBgQpKJqvMnC7nj6Ur2rniob/EDV+4JE1JR/02dCn3IUJ7BNIDxzY0HoejZQxltuDSCvD/QdXRqPeL4HO/WGavxF9c539tr2GP4lld6wQ= 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 | 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,