From patchwork Tue May 21 09:34:48 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: 10953233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA6F51390 for ; Tue, 21 May 2019 09:34:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DAC5E1FFF9 for ; Tue, 21 May 2019 09:34:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEAA6289BD; Tue, 21 May 2019 09:34:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 56F3C1FFF9 for ; Tue, 21 May 2019 09:34:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1977D8928F; Tue, 21 May 2019 09:34:53 +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-eopbgr10066.outbound.protection.outlook.com [40.107.1.66]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5A4CC8928F for ; Tue, 21 May 2019 09:34:51 +0000 (UTC) Received: from VE1PR08MB5006.eurprd08.prod.outlook.com (10.255.159.31) by VE1PR08MB5134.eurprd08.prod.outlook.com (20.179.30.93) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.16; Tue, 21 May 2019 09:34:48 +0000 Received: from VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::206b:5cf6:97e:1358]) by VE1PR08MB5006.eurprd08.prod.outlook.com ([fe80::206b:5cf6:97e:1358%7]) with mapi id 15.20.1900.020; Tue, 21 May 2019 09:34: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" , "ezequiel@collabora.com" , "uma.shankar@intel.com" Subject: [PATCH 2/4] drm/komeda: Introduce komeda_color_manager/state Thread-Topic: [PATCH 2/4] drm/komeda: Introduce komeda_color_manager/state Thread-Index: AQHVD7huQH3p8BmTy0SztNn0GEsDBw== Date: Tue, 21 May 2019 09:34:48 +0000 Message-ID: <20190521093411.26609-3-james.qian.wang@arm.com> References: <20190521093411.26609-1-james.qian.wang@arm.com> In-Reply-To: <20190521093411.26609-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: HK0PR03CA0002.apcprd03.prod.outlook.com (2603:1096:203:2e::14) To VE1PR08MB5006.eurprd08.prod.outlook.com (2603:10a6:803:113::31) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.17.1 x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 303d5890-5b47-4f87-a689-08d6ddcf90e4 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(7168020)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VE1PR08MB5134; x-ms-traffictypediagnostic: VE1PR08MB5134: nodisclaimer: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:3276; x-forefront-prvs: 0044C17179 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(39860400002)(346002)(376002)(366004)(396003)(199004)(189003)(54906003)(486006)(68736007)(110136005)(4326008)(103116003)(2501003)(66446008)(64756008)(66066001)(73956011)(66946007)(50226002)(11346002)(66556008)(66476007)(36756003)(8676002)(2906002)(81156014)(25786009)(8936002)(186003)(26005)(446003)(81166006)(476003)(86362001)(3846002)(99286004)(256004)(14444005)(478600001)(76176011)(52116002)(5660300002)(2616005)(6116002)(305945005)(7736002)(53936002)(6512007)(2201001)(71190400001)(6486002)(316002)(6436002)(71200400001)(55236004)(14454004)(1076003)(6506007)(102836004)(386003); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR08MB5134; 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-message-info: sIhhLPl405iQ7WM7alS+hJgqrnhpQ0HlTV705jsVkXxjVdRc4s5hFHlINq/ouyyskx+93vlz3YarYfuDHt8XPRh0jgV+9Qex6kcX0w/aVvcB9xUPF0lkzkq9VXdO66YmCaZu6DwnDGxo31ZTosKTjEC8uZgHE4pk3mMdb5zWaEye9Lya5hc++ZcR4fveJzJX1CKaOoRoPcfl/BQL7N6LybG0twF2iFZu2zut5rkm0ywRXVXNJvpH8denxAHBInBAQcWotXOWK9VWesuveVFFzbIJ+zG49SBMFWKTx9JRYNogixvaIWRxX9nWBG6fAQcIuNmnapUhpcqWCkcQhmoCt2SnxpR/jI+X86B0PMXzx9gs4AbcY+s2aU0dn4iiTe4TJLGXidtH+a5PqFDeWImHz83fqhGoeC8T3g/Wyi1Nz+Y= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 303d5890-5b47-4f87-a689-08d6ddcf90e4 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 May 2019 09:34:48.1444 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR08MB5134 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=SACDZ4hTbum31xpttgLhpCCzbxxM7a+7/P0m7NjhbWw=; b=coCCW0tvPgLMNgG0BUrnWuH7LVm5We0uEHa+llNgammgC6/BKdFdAxKYkCaHTtTcfNOabJ7Xn7jma2xu4GKRG+i1skow1TsRUhIB5eMqmVSm/QoRxzUHr5RUhUKsn5oDimD2kcAuQVnKR0G1xbelgxD1VdiC0nAKtIKNDNXAPyc= X-Mailman-Original-Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=james.qian.wang@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\)" , "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" X-Virus-Scanned: ClamAV using ClamSMTP Many komeda component support color management like layer and IPS, so komeda_color_manager/state are introduced to manager gamma, csc and degamma together for easily share it to multiple componpent. And for komeda_color_manager which: - convert drm 3d gamma lut to komeda specific gamma coeffs - gamma table management and hide the HW difference for komeda-CORE Signed-off-by: James Qian Wang (Arm Technology China) --- .../arm/display/komeda/komeda_color_mgmt.c | 126 ++++++++++++++++++ .../arm/display/komeda/komeda_color_mgmt.h | 32 ++++- 2 files changed, 156 insertions(+), 2 deletions(-) -- 2.17.1 diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c index 9d14a92dbb17..bf2388d641b9 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.c @@ -4,7 +4,9 @@ * Author: James.Qian.Wang * */ +#include +#include "malidp_utils.h" #include "komeda_color_mgmt.h" /* 10bit precision YUV2RGB matrix */ @@ -65,3 +67,127 @@ const s32 *komeda_select_yuv2rgb_coeffs(u32 color_encoding, u32 color_range) return coeffs; } + +struct gamma_curve_sector { + u32 boundary_start; + u32 num_of_segments; + u32 segment_width; +}; + +struct gamma_curve_segment { + u32 start; + u32 end; +}; + +static struct gamma_curve_sector sector_tbl[] = { + { 0, 4, 4 }, + { 16, 4, 4 }, + { 32, 4, 8 }, + { 64, 4, 16 }, + { 128, 4, 32 }, + { 256, 4, 64 }, + { 512, 16, 32 }, + { 1024, 24, 128 }, +}; + +static struct gamma_curve_sector igamma_sector_tbl[] = { + {0, 64, 64}, +}; + +static void +drm_lut_to_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs, + struct gamma_curve_sector *sector_tbl, u32 num_sectors) +{ + struct drm_color_lut *lut; + u32 i, j, in, num = 0; + + if (!lut_blob) + return; + + lut = lut_blob->data; + + for (i = 0; i < num_sectors; i++) { + for (j = 0; j < sector_tbl[i].num_of_segments; j++) { + in = sector_tbl[i].boundary_start + + j * sector_tbl[i].segment_width; + + coeffs[num++] = drm_color_lut_extract(lut[in].red, + KOMEDA_COLOR_PRECISION); + } + } + + coeffs[num] = BIT(KOMEDA_COLOR_PRECISION); +} + +void drm_lut_to_igamma_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs) +{ + drm_lut_to_coeffs(lut_blob, coeffs, + igamma_sector_tbl, ARRAY_SIZE(igamma_sector_tbl)); +} + +void drm_lut_to_fgamma_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs) +{ + drm_lut_to_coeffs(lut_blob, coeffs, + sector_tbl, ARRAY_SIZE(sector_tbl)); +} + +void drm_ctm_to_coeffs(struct drm_property_blob *ctm_blob, u32 *coeffs) +{ + struct drm_color_ctm *ctm; + u32 i; + + if (!ctm_blob) + return; + + ctm = ctm_blob->data; + + for (i = 0; i < KOMEDA_N_CTM_COEFFS; ++i) { + /* Convert from S31.32 to Q3.12. */ + s64 v = ctm->matrix[i]; + + coeffs[i] = clamp_val(v, 1 - (1LL << 34), (1LL << 34) - 1) >> 20; + } +} + +void komeda_color_duplicate_state(struct komeda_color_state *new, + struct komeda_color_state *old) +{ + new->igamma = komeda_coeffs_get(old->igamma); + new->fgamma = komeda_coeffs_get(old->fgamma); +} + +void komeda_color_cleanup_state(struct komeda_color_state *color_st) +{ + komeda_coeffs_put(color_st->igamma); + komeda_coeffs_put(color_st->fgamma); +} + +int komeda_color_validate(struct komeda_color_manager *mgr, + struct komeda_color_state *st, + struct drm_property_blob *igamma_blob, + struct drm_property_blob *fgamma_blob) +{ + u32 coeffs[KOMEDA_N_GAMMA_COEFFS]; + + komeda_color_cleanup_state(st); + + if (igamma_blob) { + drm_lut_to_igamma_coeffs(igamma_blob, coeffs); + st->igamma = komeda_coeffs_request(mgr->igamma_mgr, coeffs); + if (!st->igamma) { + DRM_DEBUG_ATOMIC("request igamma table failed.\n"); + return -EBUSY; + } + } + + if (fgamma_blob) { + drm_lut_to_fgamma_coeffs(fgamma_blob, coeffs); + st->fgamma = komeda_coeffs_request(mgr->fgamma_mgr, coeffs); + if (!st->fgamma) { + DRM_DEBUG_ATOMIC("request fgamma table failed.\n"); + return -EBUSY; + } + } + + return 0; +} diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h index a2df218f58e7..41a96b3b540f 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_color_mgmt.h @@ -4,14 +4,42 @@ * Author: James.Qian.Wang * */ - #ifndef _KOMEDA_COLOR_MGMT_H_ #define _KOMEDA_COLOR_MGMT_H_ #include +#include "komeda_coeffs.h" #define KOMEDA_N_YUV2RGB_COEFFS 12 +#define KOMEDA_N_RGB2YUV_COEFFS 12 +#define KOMEDA_COLOR_PRECISION 12 +#define KOMEDA_N_GAMMA_COEFFS 65 +#define KOMEDA_COLOR_LUT_SIZE BIT(KOMEDA_COLOR_PRECISION) +#define KOMEDA_N_CTM_COEFFS 9 + +struct komeda_color_manager { + struct komeda_coeffs_manager *igamma_mgr; + struct komeda_coeffs_manager *fgamma_mgr; + bool has_ctm; +}; + +struct komeda_color_state { + struct komeda_coeffs_table *igamma; + struct komeda_coeffs_table *fgamma; +}; + +void komeda_color_duplicate_state(struct komeda_color_state *new, + struct komeda_color_state *old); +void komeda_color_cleanup_state(struct komeda_color_state *color_st); +int komeda_color_validate(struct komeda_color_manager *mgr, + struct komeda_color_state *st, + struct drm_property_blob *igamma_blob, + struct drm_property_blob *fgamma_blob); + +void drm_lut_to_igamma_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs); +void drm_lut_to_fgamma_coeffs(struct drm_property_blob *lut_blob, u32 *coeffs); +void drm_ctm_to_coeffs(struct drm_property_blob *ctm_blob, u32 *coeffs); const s32 *komeda_select_yuv2rgb_coeffs(u32 color_encoding, u32 color_range); -#endif +#endif /*_KOMEDA_COLOR_MGMT_H_*/