From patchwork Sun Nov 5 11:01:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Perttunen X-Patchwork-Id: 10042089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 674B160244 for ; Sun, 5 Nov 2017 11:20:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F6A8292A3 for ; Sun, 5 Nov 2017 11:20:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 43A04292E1; Sun, 5 Nov 2017 11:20:56 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 D476D292A3 for ; Sun, 5 Nov 2017 11:20:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 46E376E195; Sun, 5 Nov 2017 11:20:55 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kapsi.fi (mail.kapsi.fi [IPv6:2001:67c:1be8::25]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2B3826E190 for ; Sun, 5 Nov 2017 11:20:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=kapsi.fi; s=20161220; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=JaxDUSgFvanJEZ6VVirgpcaZSn5FrxxGp9BfFzWrksg=; b=ojbcwmmQOiVyGPyhnDSOkYkwIfcXrFm42ff63w3u6Cah2BG/fpmW/C7D+gv0VvQoGrWr6qsWWT6ZCbAfELBH1hGqOAAlVvc4mi6LsuRioembRD0J20Ix6yhlUDbtKLB8sBLAVuAeB3X4JcKd584tS6hTkToB3RkeXLxH3Vx8MZ1DPtHiwzfBydw4jzBFm02obNioWPaJNSueCOLk6zWIIdT3/pXfgzgqCwLsTiifiWGesKqHBbPEJk8sGDLAKJiOzC0QrqESOg3KDfcL9E9Pq3HpcueFp4FIy7liwk6HvBaHXV/0ThuO2w7l9gzeADz685pxu1nBjNXEZ10/cPqzlQ==; Received: from dsl-hkibng22-54f983-249.dhcp.inet.fi ([84.249.131.249] helo=localhost.localdomain) by mail.kapsi.fi with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1eBIgk-0006dR-Ht; Sun, 05 Nov 2017 13:02:02 +0200 From: Mikko Perttunen To: thierry.reding@gmail.com, jonathanh@nvidia.com Subject: [PATCH 06/10] drm/tegra: Deliver job completion callback to client Date: Sun, 5 Nov 2017 13:01:14 +0200 Message-Id: <20171105110118.15142-7-mperttunen@nvidia.com> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171105110118.15142-1-mperttunen@nvidia.com> References: <20171105110118.15142-1-mperttunen@nvidia.com> X-SA-Exim-Connect-IP: 84.249.131.249 X-SA-Exim-Mail-From: mperttunen@nvidia.com X-SA-Exim-Scanned: No (on mail.kapsi.fi); SAEximRunCond expanded to false Cc: linux-tegra@vger.kernel.org, digetx@gmail.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Mikko Perttunen X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP To allow client drivers to free resources when jobs have completed, deliver job completion callbacks to them. This requires adding reference counting to context objects, as job completion can happen after the userspace application has closed the context. As such, also add kref-based refcounting for contexts. Signed-off-by: Mikko Perttunen --- drivers/gpu/drm/tegra/drm.c | 27 ++++++++++++++++++++++++--- drivers/gpu/drm/tegra/drm.h | 4 ++++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/tegra/drm.c b/drivers/gpu/drm/tegra/drm.c index 2cdd054520bf..3e2a4a19412e 100644 --- a/drivers/gpu/drm/tegra/drm.c +++ b/drivers/gpu/drm/tegra/drm.c @@ -281,8 +281,11 @@ static int tegra_drm_open(struct drm_device *drm, struct drm_file *filp) return 0; } -static void tegra_drm_context_free(struct tegra_drm_context *context) +static void tegra_drm_context_free(struct kref *ref) { + struct tegra_drm_context *context = + container_of(ref, struct tegra_drm_context, ref); + context->client->ops->close_channel(context); kfree(context); } @@ -379,6 +382,16 @@ static int host1x_waitchk_copy_from_user(struct host1x_waitchk *dest, return 0; } +static void tegra_drm_job_done(struct host1x_job *job) +{ + struct tegra_drm_context *context = job->callback_data; + + if (context->client->ops->submit_done) + context->client->ops->submit_done(context); + + kref_put(&context->ref, tegra_drm_context_free); +} + int tegra_drm_submit(struct tegra_drm_context *context, struct drm_tegra_submit *args, struct drm_device *drm, struct drm_file *file) @@ -560,6 +573,9 @@ int tegra_drm_submit(struct tegra_drm_context *context, job->syncpt_id = syncpt.id; job->timeout = 10000; + job->done = tegra_drm_job_done; + job->callback_data = context; + if (args->timeout && args->timeout < 10000) job->timeout = args->timeout; @@ -567,8 +583,11 @@ int tegra_drm_submit(struct tegra_drm_context *context, if (err) goto fail; + kref_get(&context->ref); + err = host1x_job_submit(job); if (err) { + kref_put(&context->ref, tegra_drm_context_free); host1x_job_unpin(job); goto fail; } @@ -717,6 +736,8 @@ static int tegra_open_channel(struct drm_device *drm, void *data, if (err < 0) kfree(context); + kref_init(&context->ref); + mutex_unlock(&fpriv->lock); return err; } @@ -738,7 +759,7 @@ static int tegra_close_channel(struct drm_device *drm, void *data, } idr_remove(&fpriv->contexts, context->id); - tegra_drm_context_free(context); + kref_put(&context->ref, tegra_drm_context_free); unlock: mutex_unlock(&fpriv->lock); @@ -1026,7 +1047,7 @@ static int tegra_drm_context_cleanup(int id, void *p, void *data) { struct tegra_drm_context *context = p; - tegra_drm_context_free(context); + kref_put(&context->ref, tegra_drm_context_free); return 0; } diff --git a/drivers/gpu/drm/tegra/drm.h b/drivers/gpu/drm/tegra/drm.h index 063f5d397526..079aebb3fb38 100644 --- a/drivers/gpu/drm/tegra/drm.h +++ b/drivers/gpu/drm/tegra/drm.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -74,6 +75,8 @@ struct tegra_drm { struct tegra_drm_client; struct tegra_drm_context { + struct kref ref; + struct tegra_drm_client *client; struct host1x_channel *channel; unsigned int id; @@ -88,6 +91,7 @@ struct tegra_drm_client_ops { int (*submit)(struct tegra_drm_context *context, struct drm_tegra_submit *args, struct drm_device *drm, struct drm_file *file); + void (*submit_done)(struct tegra_drm_context *context); }; int tegra_drm_submit(struct tegra_drm_context *context,