From patchwork Sun Nov 5 11:01:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikko Perttunen X-Patchwork-Id: 10042097 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 A760660244 for ; Sun, 5 Nov 2017 11:23:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DA09292D1 for ; Sun, 5 Nov 2017 11:23:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 823DD292E1; Sun, 5 Nov 2017 11:23:13 +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 35930292FC for ; Sun, 5 Nov 2017 11:23:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F30106E182; Sun, 5 Nov 2017 11:23:11 +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 AAA116E182 for ; Sun, 5 Nov 2017 11:23:10 +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=I2lpSW2mPPNqjnrMXllBrO7RPFXISFVzdO377G+RRLU=; b=PBe9LL7ZCERbIMmnFD7bogvPB6sB4saq9tRK27kYKHVe7nS1g+sAOoddesGk9/MPR/+CywSDeAEST5b6s2xpUXKlvot9tbZXD6BpKMdZcD10xp8G1ixwBU1JcwJ0y//DEzMlaDvKwb5Yut4M/3ZgGFsdEr1YINmPsy+5uYmc+lkLeC+yCsz7bqw9tLlG1qsjIxUIw3Yse6Gr+osYerwU28dzGIWR9T+oYaO1cm3BZTJ+nw799snTFMyy8yS1rZOgf0VsfkpZc+dnRDy+9dQOlOPsGpezZPwDYE8htqjEFvsU8utNj5oQjgqwWyrTDLLqDFL+As17RCUbKxkSbo/hWA==; 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-FA; Sun, 05 Nov 2017 13:02:02 +0200 From: Mikko Perttunen To: thierry.reding@gmail.com, jonathanh@nvidia.com Subject: [PATCH 05/10] gpu: host1x: Add job done callback Date: Sun, 5 Nov 2017 13:01:13 +0200 Message-Id: <20171105110118.15142-6-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 Allow job submitters to set a callback to be called when the job has completed. The jobs are stored and the callbacks called outside the CDMA lock area to allow the callbacks to do CDMA-requiring operations like freeing channels. Signed-off-by: Mikko Perttunen --- drivers/gpu/host1x/cdma.c | 44 +++++++++++++++++++++++++++++++++----------- include/linux/host1x.h | 4 ++++ 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/host1x/cdma.c b/drivers/gpu/host1x/cdma.c index f787cfe69c11..57221d199d33 100644 --- a/drivers/gpu/host1x/cdma.c +++ b/drivers/gpu/host1x/cdma.c @@ -251,17 +251,24 @@ static void stop_cdma_timer_locked(struct host1x_cdma *cdma) cdma->timeout.client = 0; } -/* - * For all sync queue entries that have already finished according to the - * current sync point registers: - * - unpin & unref their mems - * - pop their push buffer slots - * - remove them from the sync queue +/** + * update_cdma_locked() - Update CDMA sync queue + * @cdma: CDMA instance to update + * @done_jobs: List that finished jobs will be added to + * + * Go through the CDMA's sync queue, and for each job that has been finished, + * - unpin it + * - pop its push buffer slots + * - remove it from the sync queue + * - add it to the done_jobs list. + * * This is normally called from the host code's worker thread, but can be * called manually if necessary. - * Must be called with the cdma lock held. + * + * Must be called with the CDMA lock held. */ -static void update_cdma_locked(struct host1x_cdma *cdma) +static void update_cdma_locked(struct host1x_cdma *cdma, + struct list_head *done_jobs) { bool signal = false; struct host1x *host1x = cdma_to_host1x(cdma); @@ -305,8 +312,7 @@ static void update_cdma_locked(struct host1x_cdma *cdma) signal = true; } - list_del(&job->list); - host1x_job_put(job); + list_move_tail(&job->list, done_jobs); } if (cdma->event == CDMA_EVENT_SYNC_QUEUE_EMPTY && @@ -542,7 +548,23 @@ void host1x_cdma_end(struct host1x_cdma *cdma, */ void host1x_cdma_update(struct host1x_cdma *cdma) { + struct host1x_job *job, *tmp; + LIST_HEAD(done_jobs); + mutex_lock(&cdma->lock); - update_cdma_locked(cdma); + update_cdma_locked(cdma, &done_jobs); mutex_unlock(&cdma->lock); + + /* + * The done callback may want to free the channel, which requires + * taking the CDMA lock, so we need to do it outside the above lock + * region. + */ + list_for_each_entry_safe(job, tmp, &done_jobs, list) { + if (job->done) + job->done(job); + + list_del(&job->list); + host1x_job_put(job); + } } diff --git a/include/linux/host1x.h b/include/linux/host1x.h index 630b1a98ab58..f931d28a68ff 100644 --- a/include/linux/host1x.h +++ b/include/linux/host1x.h @@ -253,6 +253,10 @@ struct host1x_job { /* Check if class belongs to the unit */ int (*is_valid_class)(u32 class); + /* Job done callback */ + void (*done)(struct host1x_job *job); + void *callback_data; + /* Request a SETCLASS to this class */ u32 class;