Received: by 10.223.164.200 with SMTP id h8csp60051wrb; Sun, 5 Nov 2017 03:05:25 -0800 (PST) X-Google-Smtp-Source: ABhQp+Ty9F8Al2d2e0EEP42nqTmm/9pjZrqjVHzIHLNvqAkjBdxH/Gc4NZEo1LmwiuzvtRDtuNFN X-Received: by 10.101.76.195 with SMTP id n3mr12774897pgt.120.1509879925221; Sun, 05 Nov 2017 03:05:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1509879925; cv=none; d=google.com; s=arc-20160816; b=HwW/0GD5AQsTg2h1zUtzpxClI8aEDj6A2gPTpObNBIv4DxJuUFjcDXaNL3PiOMjFyi F0E5lpRnQVO6b50U5IBXc5claeKv8pFrYPiRfX4QZQ7cAzaO1TwF6y58GmU0W5j34wk8 gYI9zRUTMgpaZ+/O4LbQsud90WBlP0F61M4niOo9sHSd39Z2wPBfnWJKJGcHgDpYZOmV Pe89ebW8tXHHvZSjDpMMX9XNLcoY+U8xFPWwiBiUlT9E2M9PwInAF6/A/W/UqG5HsKkC sB8Juhzbs04HmZdVyHkxIV7zfpJ2F3dcTZGnKC0FClax6j9avzwkvjLkc3ygwkzYzRcq IzjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=JaxDUSgFvanJEZ6VVirgpcaZSn5FrxxGp9BfFzWrksg=; b=wnm/MR7KDbj3+P/Zqk7iMf+bZqN2dGdGcUFdEu9Bm5VZxDi41WDCYEYhFdgtQ4LW1m E3IU8tTYNVN8AJt8ZFnF5IjkZHkA9x1bJAgJW8CcnKN3JhB+hK09stXaxrTnbdmGuHWr L/6rIc0iIclVpzZ8a+oG/gJYy6LKztJoN/4g0KJ9KWcOmLlHreMEoug9ccTnvajXJH+4 ysAcporGcKqK+Ky4ajNXWuXTe5SPbwh/5aeKr294dG7q0V+QMW71bs/ZazBN4T/CSoKV jL3w79MS2imgtgi96rQOITA6Z3QOMdJUeqWawuk5RWL7V8KQF1UIZdtLop4PsPTmVyVe yEDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kapsi.fi header.s=20161220 header.b=ojbcwmmQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f4si8488488plr.1.2017.11.05.03.05.11; Sun, 05 Nov 2017 03:05:25 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kapsi.fi header.s=20161220 header.b=ojbcwmmQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752949AbdKELDy (ORCPT + 96 others); Sun, 5 Nov 2017 06:03:54 -0500 Received: from mail.kapsi.fi ([91.232.154.25]:49807 "EHLO mail.kapsi.fi" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751434AbdKELCE (ORCPT ); Sun, 5 Nov 2017 06:02:04 -0500 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 Cc: digetx@gmail.com, dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, Mikko Perttunen 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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, -- 2.14.2 From 1585172185332323745@xxx Sun Nov 26 23:13:20 +0000 2017 X-GM-THRID: 1585172185332323745 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread