Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1193222pxu; Wed, 6 Jan 2021 15:21:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwJ++mo+phII0Sna7jWrE/+S0hEugRt+bWjC8LAr7FBixdac3PhcB078+NyA58oH8fyttqk X-Received: by 2002:a50:fd10:: with SMTP id i16mr5543293eds.331.1609975262343; Wed, 06 Jan 2021 15:21:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609975262; cv=none; d=google.com; s=arc-20160816; b=p54zDSR9YKeZHjV5s+ztbsyt5peZzuRxSjtXdF9s0mFcu2E7TprZjWdf++bEdgCpQ7 boNqk53FCvVR+uvqsm7Mgpl7S+2KjrEJs23X/+8wCf7W3wxiF2ioNhn5AQAE3sYXJtBP O+gDv98oocQApC4sb83CKixVrVuZDCguwlDnxWPfkVJdsB5N4fqJsxmRidlYecQtddYZ RhAvJXMHaggVQEV/wtkJFS432nuil8qxEWB5qHGg3S/Te06tRaGU8qsUf+qGdmaHjLrQ ISnkU9EP0a+WZdFSPhHb5ZeJCFcHmlPPcq+Nvo8Z9AK/D2U8ZN3BMVxZCxpu6zcpfV6I 0DCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=EEtDR9CMOm5z3XV+re0gqGUUpr609go25F/Fwl2sVoQ=; b=AmLRRw2yOYNYfU1vIaJaK4rea3DdeaVOTNd0UD4zmJWhajihpmbbs5lq+gWu5oSD8E g8kBlB0XBYW+xd7b3IsRrxHlHkmiLcmJ+qitMNDrtj5w8wPioyksuQGpHszQUyR8BRkE uqHgnUAbQIcS+stylvxoUO6O4hGRERFHYH+NjdeLtnsfE8iFji4hGLm9AEUjjiLlO2MQ 7NgCGfgtUSoLvyXzcSFWBGRvbDOTtzLRi+1HDISA0Vkjy0PsytoduXnrqqcP5jbFlyJv QI4r4zdsU1KUq0uCVGcF661AIBLBkZeXWWkHIqFY6gUcYWYT3jhjyjo6SyqFQe3ATAiT jchg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JYytbgxz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l22si1389192ejr.379.2021.01.06.15.20.38; Wed, 06 Jan 2021 15:21:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JYytbgxz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727739AbhAFXS3 (ORCPT + 99 others); Wed, 6 Jan 2021 18:18:29 -0500 Received: from mail.kernel.org ([198.145.29.99]:48374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727648AbhAFXS2 (ORCPT ); Wed, 6 Jan 2021 18:18:28 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 00D422333C; Wed, 6 Jan 2021 23:17:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1609975067; bh=r27Vj/voz22uOFt6pt8tkfK5I1iQpalF/T3j5c4SrVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JYytbgxzXqernG57j5f4LYEqFJCsYllR3munrVz5WuKuZdGqEAHfc7KuwDLpI48Rh CVVU+VjMIOyTlxux6KOhEtNz46hx2e3Dmhmh+zSlTTsF/iRKHuyotYAWdY4r9oUBpx Rv7GomhhJnqBubtaGw1u/0Gf4RaRhh9ul1awcXbjoNHjDQurIOLRUVqKRgo1oPNSto wxOOaIcb4w9k5dYvyglwvzY7pORCqryMmH/rsiIRqLaZJUCY40IyVGhAihoUV9kbNo yjTtYFZ11PaG7LuVR2Mk/BJ5bJyGIEjOrL+8dyT13V85nL7YCppW2SZ7FTBdSJ4TeZ FMiNZFo3iVDuA== From: Chun-Kuang Hu To: Matthias Brugger , Philipp Zabel , David Airlie , Daniel Vetter Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, CK Hu , Chun-Kuang Hu Subject: [PATCH v2 4/5] drm/mediatek: Automatically search unclaimed mtk mutex in mtk_mutex_get() Date: Thu, 7 Jan 2021 07:17:28 +0800 Message-Id: <20210106231729.17173-5-chunkuang.hu@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210106231729.17173-1-chunkuang.hu@kernel.org> References: <20210106231729.17173-1-chunkuang.hu@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: CK Hu Moving mutex resource management from client driver to mutex driver could prevent client drivers negotiating for resource management. Signed-off-by: CK Hu Signed-off-by: Chun-Kuang Hu --- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 2 +- drivers/gpu/drm/mediatek/mtk_mutex.c | 16 ++++++++-------- drivers/gpu/drm/mediatek/mtk_mutex.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c index bba87a036fa8..1e3a9450680b 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c @@ -773,7 +773,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, if (!mtk_crtc->ddp_comp) return -ENOMEM; - mtk_crtc->mutex = mtk_mutex_get(priv->mutex_dev, pipe); + mtk_crtc->mutex = mtk_mutex_get(priv->mutex_dev); if (IS_ERR(mtk_crtc->mutex)) { ret = PTR_ERR(mtk_crtc->mutex); dev_err(dev, "Failed to get mutex: %d\n", ret); diff --git a/drivers/gpu/drm/mediatek/mtk_mutex.c b/drivers/gpu/drm/mediatek/mtk_mutex.c index 98a060bf225d..66344759e622 100644 --- a/drivers/gpu/drm/mediatek/mtk_mutex.c +++ b/drivers/gpu/drm/mediatek/mtk_mutex.c @@ -228,18 +228,18 @@ static const struct mtk_mutex_data mt8173_mutex_driver_data = { .mutex_sof_reg = MT2701_MUTEX0_SOF0, }; -struct mtk_mutex *mtk_mutex_get(struct device *dev, unsigned int id) +struct mtk_mutex *mtk_mutex_get(struct device *dev) { struct mtk_mutex_ctx *mtx = dev_get_drvdata(dev); + int i; - if (id >= 10) - return ERR_PTR(-EINVAL); - if (mtx->mutex[id].claimed) - return ERR_PTR(-EBUSY); - - mtx->mutex[id].claimed = true; + for (i = 0; i < 10; i++) + if (!mtx->mutex[i].claimed) { + mtx->mutex[i].claimed = true; + return &mtx->mutex[i]; + } - return &mtx->mutex[id]; + return ERR_PTR(-EBUSY); } void mtk_mutex_put(struct mtk_mutex *mutex) diff --git a/drivers/gpu/drm/mediatek/mtk_mutex.h b/drivers/gpu/drm/mediatek/mtk_mutex.h index b678e0988a37..6fe4ffbde290 100644 --- a/drivers/gpu/drm/mediatek/mtk_mutex.h +++ b/drivers/gpu/drm/mediatek/mtk_mutex.h @@ -10,7 +10,7 @@ struct regmap; struct device; struct mtk_mutex; -struct mtk_mutex *mtk_mutex_get(struct device *dev, unsigned int id); +struct mtk_mutex *mtk_mutex_get(struct device *dev); int mtk_mutex_prepare(struct mtk_mutex *mutex); void mtk_mutex_add_comp(struct mtk_mutex *mutex, enum mtk_ddp_comp_id id); -- 2.17.1