From patchwork Tue May 21 09:34:42 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: 10953231 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 F3C91924 for ; Tue, 21 May 2019 09:34:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3041289C4 for ; Tue, 21 May 2019 09:34:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7058289BA; Tue, 21 May 2019 09:34:47 +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 4E6B528931 for ; Tue, 21 May 2019 09:34:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4D66E89270; Tue, 21 May 2019 09:34:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-eopbgr130042.outbound.protection.outlook.com [40.107.13.42]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0628389270 for ; Tue, 21 May 2019 09:34:45 +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:42 +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:42 +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 1/4] drm/komeda: Introduce komeda_coeffs_table/manager Thread-Topic: [PATCH 1/4] drm/komeda: Introduce komeda_coeffs_table/manager Thread-Index: AQHVD7hqo4Z2mU7NqU6hxzw6Ux+tpA== Date: Tue, 21 May 2019 09:34:42 +0000 Message-ID: <20190521093411.26609-2-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: 0c1318a5-6a4c-446e-7de3-08d6ddcf8d26 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:3968; 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: K4T9Zo4t2XyCRKT6Yo2BSOJiPQ97Z2vifw6EvxpZez/Ab7ojFrYT50eqXP58zvH/wVHa/QGjrRqgiEZre7xY6osVb2yn0C5kkzxyf+kwOJLAC8jGnSdybwvwsNRvfkDJGctLklsbr5+hmqzyekG68GGmr08K38nBI+eEp0huZie/Cu8r/0io+oFhwA9Oe+t9/P6VcOuUZ/9KlSrD/mCJM9gTmLsE/OiInJX7F2TrXVLQFp/ofVf632D3uhSDhCAdzyfuQ2FttRC0qmyeJOFGXLrpSslOEMMp6XxM2EFK0jV9iOyYYm766ujJZIvrchY7ozB8ldqIiDylPGtvkCIOGqpinVGIIyNuBf9AOdp9FTgP8PmRjZviXcBEb/A2lJJx5bfDoP+Weqr/ZuNKerT9NXgOXqQHLE+sckOugonKCfs= MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c1318a5-6a4c-446e-7de3-08d6ddcf8d26 X-MS-Exchange-CrossTenant-originalarrivaltime: 21 May 2019 09:34:42.0170 (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=tCamK8Kw1yh2QgLK36V/ig8gEG5VDB6ohB5VfLQrQjA=; b=JgiPCSXPAVFzOErak3XNc97PKX2CrmPJZ741T2XOtPByjeI5thiWOgVS1MWVASq8HEo9q960a9NJCfmBvTuyEyuOKu9bLv8Jsg4w+RN/4a/BhRt4/KqcUYqkal4XyYp5AwFaETQueLqq3tcLUybqQin0Oob/iYO0EghCHPeU+3g= 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 komeda display HWs have kinds of coefficient tables for various purposes like gamma/degamma. ususally these tables are shared by multiple HW component and have limited number. Introduce komeda_coeffs_table/manager for describing and managing these tables, like table reuse, racing. Signed-off-by: James Qian Wang (Arm Technology China) --- drivers/gpu/drm/arm/display/komeda/Makefile | 1 + .../drm/arm/display/komeda/komeda_coeffs.c | 119 ++++++++++++++++++ .../drm/arm/display/komeda/komeda_coeffs.h | 74 +++++++++++ 3 files changed, 194 insertions(+) create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_coeffs.c create mode 100644 drivers/gpu/drm/arm/display/komeda/komeda_coeffs.h -- 2.17.1 diff --git a/drivers/gpu/drm/arm/display/komeda/Makefile b/drivers/gpu/drm/arm/display/komeda/Makefile index 73b8e8be1862..e853c1c499c9 100644 --- a/drivers/gpu/drm/arm/display/komeda/Makefile +++ b/drivers/gpu/drm/arm/display/komeda/Makefile @@ -8,6 +8,7 @@ komeda-y := \ komeda_drv.o \ komeda_dev.o \ komeda_format_caps.o \ + komeda_coeffs.o \ komeda_color_mgmt.o \ komeda_pipeline.o \ komeda_pipeline_state.o \ diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_coeffs.c b/drivers/gpu/drm/arm/display/komeda/komeda_coeffs.c new file mode 100644 index 000000000000..d9d35e23003c --- /dev/null +++ b/drivers/gpu/drm/arm/display/komeda/komeda_coeffs.c @@ -0,0 +1,119 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * (C) COPYRIGHT 2019 ARM Limited. All rights reserved. + * Author: James.Qian.Wang + * + */ +#include +#include "komeda_coeffs.h" + +static inline bool is_table_in_using(struct komeda_coeffs_table *table) +{ + return refcount_read(&table->refcount) > 1; +} + +/* request a coeffs table for the coeffs data specified by argument coeffs */ +struct komeda_coeffs_table * +komeda_coeffs_request(struct komeda_coeffs_manager *mgr, void *coeffs) +{ + struct komeda_coeffs_table *table; + u32 i; + + mutex_lock(&mgr->mutex); + + /* search table list to find if there is a in-using table with the + * same coefficient content, if find, reuse this table. + */ + for (i = 0; i < mgr->n_tables; i++) { + table = mgr->tables[i]; + + /* skip the unused table */ + if (!is_table_in_using(table)) + continue; + + if (!memcmp(table->coeffs, coeffs, mgr->coeffs_sz)) + goto found; + } + + /* can not reuse the existing in-using table, loop for a new one */ + for (i = 0; i < mgr->n_tables; i++) { + table = mgr->tables[i]; + + if (!is_table_in_using(table)) { + memcpy(table->coeffs, coeffs, mgr->coeffs_sz); + table->needs_update = true; + goto found; + } + } + + /* Since previous two search loop will directly goto found if found an + * available table, so once program ran here means search failed. + * clear the table to NULL, unlock(mgr->mutex) and return NULL. + */ + table = NULL; + +found: + komeda_coeffs_get(table); + mutex_unlock(&mgr->mutex); + return table; +} + +/* Add a coeffs table to manager */ +int komeda_coeffs_add(struct komeda_coeffs_manager *mgr, + u32 hw_id, u32 __iomem *reg, + void (*update)(struct komeda_coeffs_table *table)) +{ + struct komeda_coeffs_table *table; + + if (mgr->n_tables >= ARRAY_SIZE(mgr->tables)) + return -ENOSPC; + + table = kzalloc(sizeof(*table), GFP_KERNEL); + if (!table) + return -ENOMEM; + + table->coeffs = kzalloc(mgr->coeffs_sz, GFP_KERNEL); + if (!table->coeffs) { + kfree(table); + return -ENOMEM; + } + + refcount_set(&table->refcount, 1); + table->mgr = mgr; + table->hw_id = hw_id; + table->update = update; + table->reg = reg; + + mgr->tables[mgr->n_tables++] = table; + return 0; +} + +struct komeda_coeffs_manager *komeda_coeffs_create_manager(u32 coeffs_sz) +{ + struct komeda_coeffs_manager *mgr; + + mgr = kzalloc(sizeof(*mgr), GFP_KERNEL); + if (!mgr) + return ERR_PTR(-ENOMEM); + + mutex_init(&mgr->mutex); + mgr->coeffs_sz = coeffs_sz; + + return mgr; +} + +void komeda_coeffs_destroy_manager(struct komeda_coeffs_manager *mgr) +{ + u32 i; + + if (!mgr) + return; + + for (i = 0; i < mgr->n_tables; i++) { + WARN_ON(is_table_in_using(mgr->tables[i])); + kfree(mgr->tables[i]->coeffs); + kfree(mgr->tables[i]); + } + + kfree(mgr); +} diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_coeffs.h b/drivers/gpu/drm/arm/display/komeda/komeda_coeffs.h new file mode 100644 index 000000000000..172ac2ea17ba --- /dev/null +++ b/drivers/gpu/drm/arm/display/komeda/komeda_coeffs.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * (C) COPYRIGHT 2019 ARM Limited. All rights reserved. + * Author: James.Qian.Wang + * + */ +#ifndef _KOMEDA_COEFFS_H_ +#define _KOMEDA_COEFFS_H_ + +#include + +/* Komeda display HWs have kinds of coefficient tables for various purposes, + * like gamma/degamma. ususally these tables are shared by multiple HW component + * and limited number. + * The komeda_coeffs_table/manager are imported for describing and managing + * these tables for table reuse and racing. + */ +struct komeda_coeffs_table { + struct komeda_coeffs_manager *mgr; + refcount_t refcount; + bool needs_update; + u32 hw_id; + void *coeffs; + u32 __iomem *reg; + void (*update)(struct komeda_coeffs_table *table); +}; + +struct komeda_coeffs_manager { + struct mutex mutex; /* for tables accessing */ + u32 n_tables; + u32 coeffs_sz; + struct komeda_coeffs_table *tables[8]; +}; + +static inline struct komeda_coeffs_table * +komeda_coeffs_get(struct komeda_coeffs_table *table) +{ + if (table) + refcount_inc(&table->refcount); + + return table; +} + +static inline void __komeda_coeffs_put(struct komeda_coeffs_table *table) +{ + if (table) + refcount_dec(&table->refcount); +} + +#define komeda_coeffs_put(table) \ +do { \ + __komeda_coeffs_put(table); \ + (table) = NULL; \ +} while (0) + +static inline void komeda_coeffs_update(struct komeda_coeffs_table *table) +{ + if (!table || !table->needs_update) + return; + + table->update(table); + table->needs_update = false; +} + +struct komeda_coeffs_manager *komeda_coeffs_create_manager(u32 coeffs_sz); +void komeda_coeffs_destroy_manager(struct komeda_coeffs_manager *mgr); + +int komeda_coeffs_add(struct komeda_coeffs_manager *mgr, + u32 hw_id, u32 __iomem *reg, + void (*update)(struct komeda_coeffs_table *table)); +struct komeda_coeffs_table * +komeda_coeffs_request(struct komeda_coeffs_manager *mgr, void *coeffs); + +#endif /*_KOMEDA_COEFFS_H_*/