From patchwork Thu Jun 9 15:05:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 9167261 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 6CDE160467 for ; Thu, 9 Jun 2016 15:07:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D98E2835D for ; Thu, 9 Jun 2016 15:07:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 40C8C28368; Thu, 9 Jun 2016 15:07: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.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 86AB128372 for ; Thu, 9 Jun 2016 15:07:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CC4726EBFC; Thu, 9 Jun 2016 15:07:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f194.google.com (mail-yw0-f194.google.com [209.85.161.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7B0F76EBFB for ; Thu, 9 Jun 2016 15:07:46 +0000 (UTC) Received: by mail-yw0-f194.google.com with SMTP id l126so5070261ywe.3 for ; Thu, 09 Jun 2016 08:07:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=sVFr0BE/FcxJSYKXd/+iR8KFu5ngItJrcoTkbZQ+3GE=; b=NYeNhMrcQYRuvqJbswnwfREBs2E+Fi5kks6K69OZ6G0fZI6jn/5ZNVX8Vj+/ac6jb4 H5O5sjRaF6gz0iroVWlI8I/yNfSQ72nAn4aokpxT5vTIXs/dsYquGdI7pH7YLKc8Nm/S IsdvsEcmrgBozQ3a8QNan2pb6EPUblvzbs+QqSktBGapJFT6xzRzanp17pTpwCLbwyrh Y0OCnFbQJqr/h9Ye77ImBtKx/h/4/f6HCTXOde4L8rvUI5y4D4lW4d2ovtsLmLDrUD0R 9/QHvHT68MmjtimvjjvooUL4CY5mWfxviAxnLzAlCTJ8+6wbEdC50D3qT7ivPP977dBr HOIg== X-Gm-Message-State: ALyK8tJ/65zCa1jEWDuNeRjJxUEmzNmHQQm59/hpqQQqQ0mXznG8TptxQjAgU3WQjic+0w== X-Received: by 10.13.237.130 with SMTP id w124mr5991422ywe.248.1465484865010; Thu, 09 Jun 2016 08:07:45 -0700 (PDT) Received: from jade.localdomain ([201.82.24.203]) by smtp.gmail.com with ESMTPSA id n10sm3465619ywd.7.2016.06.09.08.07.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Jun 2016 08:07:44 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [PATCH 2/3] dma-buf/sync_file: add sync_file_get_fence() Date: Thu, 9 Jun 2016 12:05:29 -0300 Message-Id: <1465484730-8128-2-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1465484730-8128-1-git-send-email-gustavo@padovan.org> References: <1465484730-8128-1-git-send-email-gustavo@padovan.org> Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , linux-kernel@vger.kernel.org, laurent.pinchart@ideasonboard.com, Gustavo Padovan , John Harrison , m.chehab@samsung.com 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 From: Gustavo Padovan Creates a function that given an sync file descriptor returns a fence_collection containing all fences in the sync_file. If there is only one fence in the sync_file this fence itself is returned, however if there is more than one, a fence_collection fence is returned. v2: Comments by Daniel Vetter - Adapt to new version of fence_collection_init() - Hold a reference for the fence we return v3: - Adapt to use fput() directly - rename to sync_file_get_fence() as we always return one fence v4: Adapt to use fence_array Signed-off-by: Gustavo Padovan --- drivers/dma-buf/sync_file.c | 61 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/sync_file.h | 4 ++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 59f3445..daaf411 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -122,6 +123,63 @@ err: return NULL; } +/** + * sync_file_get_fence - get the fence related to the sync_file fd + * @fd: sync_file fd to get the fence from + * + * Ensures @fd references a valid sync_file and returns a fence that + * represents all fence in the sync_file. + * + * If there is only one fence in the sync_file, this fence is returned. + * If there is more than one, a fence_array containing all fences + * is created and its base fence object is returned. + * On both cases a reference to the returned fence is held. On error + * NULL is returned. + */ +struct fence *sync_file_get_fence(int fd) +{ + struct sync_file *sync_file; + struct fence_array *fence_array; + struct fence **fences; + int i; + + sync_file = sync_file_fdget(fd); + if (!sync_file) + return NULL; + + if (sync_file->num_fences == 1) { + struct fence *fence = sync_file->cbs[0].fence; + + fence_get(fence); + fput(sync_file->file); + return fence; + } + + fences = kcalloc(sync_file->num_fences, sizeof(**fences), GFP_KERNEL); + if (!fences) { + fput(sync_file->file); + return NULL; + } + + for (i = 0 ; i < sync_file->num_fences ; i++) + fences[i] = sync_file->cbs[i].fence; + + fence_array = fence_array_create(sync_file->num_fences, fences, + fence_context_alloc(1), 1, false); + if (!fence_array) { + kfree(fences); + fput(sync_file->file); + return NULL; + } + + sync_file->fence_array = fence_array; + fence_get(&fence_array->base); + fput(sync_file->file); + + return &fence_array->base; +} +EXPORT_SYMBOL(sync_file_get_fence); + static void sync_file_add_pt(struct sync_file *sync_file, int *i, struct fence *fence) { @@ -209,6 +267,9 @@ static void sync_file_free(struct kref *kref) kref); int i; + if (sync_file->fence_array) + fence_put(&sync_file->fence_array->base); + for (i = 0; i < sync_file->num_fences; ++i) fence_put(sync_file->cbs[i].fence); diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h index c6ffe8b..33cb3d6 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -35,6 +35,7 @@ struct sync_file_cb { * @num_fences: number of sync_pts in the fence * @wq: wait queue for fence signaling * @status: 0: signaled, >0:active, <0: error + * @fence_array: array with the fences in the sync_file * @cbs: sync_pts callback information */ struct sync_file { @@ -49,9 +50,10 @@ struct sync_file { wait_queue_head_t wq; atomic_t status; + struct fence_array *fence_array; struct sync_file_cb cbs[]; }; struct sync_file *sync_file_create(struct fence *fence); - +struct fence *sync_file_get_fence(int fd); #endif /* _LINUX_SYNC_H */