From patchwork Wed Mar 23 18:47:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 8653141 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 7624A9FB32 for ; Wed, 23 Mar 2016 18:47:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D996C203E6 for ; Wed, 23 Mar 2016 18:47:51 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 1F29A202A1 for ; Wed, 23 Mar 2016 18:47:50 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 71ECF6E905; Wed, 23 Mar 2016 18:47:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f182.google.com (mail-yw0-f182.google.com [209.85.161.182]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3E2FA6E901 for ; Wed, 23 Mar 2016 18:47:42 +0000 (UTC) Received: by mail-yw0-f182.google.com with SMTP id h65so31189921ywe.0 for ; Wed, 23 Mar 2016 11:47:42 -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=Po45tR0eaTL8IoMwp4N7NZIRrcX8DEnsGzBr4Ojjp8M=; b=T5u56whxa60jEO2X5oDnOBUsX3N25iXG7pb+t/8w2CsdLa9a+jbTWtCt1cDzdsHLH3 8xIKyB/SoVUv3Rtb7AFZlAl0slokfhd40UvVrjnlVBUYfFf2WcVd1Rqo5uYsSf4p84AB r6fzV1lzdyV7jG3yV3Ryydg1R0o4LXzJadoRUF61gCv850kjXDaIFSEzp/5aNdvUS0Fn /+o1pa7nHBZsVaymPJe1X7vi87cl3k2fFwyGAwdSkDA3elsjkbz9oce+xWDZR0bJqfzf BuYV0JLPFMU8AcHLQ983JxIMeU5KwvWIDW2bjY/lkdIX5TSdo1FchTETlhyZLO4rrpgT mCKg== X-Gm-Message-State: AD7BkJKvwxsTxb7Nfd54ShxsYo7oNN/9A5Lt9zjeYVa/c7UgrHg6KKMPASqrLz3otRgdKQ== X-Received: by 10.37.68.197 with SMTP id r188mr2125588yba.161.1458758860611; Wed, 23 Mar 2016 11:47:40 -0700 (PDT) Received: from jade.localdomain ([201.82.24.203]) by smtp.gmail.com with ESMTPSA id y138sm2146629ywa.28.2016.03.23.11.47.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 23 Mar 2016 11:47:40 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [RFC 3/6] dma-buf/sync_file: add sync_file_fences_get() Date: Wed, 23 Mar 2016 15:47:24 -0300 Message-Id: <1458758847-21170-4-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1458758847-21170-1-git-send-email-gustavo@padovan.org> References: <1458758847-21170-1-git-send-email-gustavo@padovan.org> Cc: Daniel Stone , Daniel Vetter , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , linux-kernel@vger.kernel.org, Riley Andrews , Gustavo Padovan , John Harrison 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-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org 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. Signed-off-by: Gustavo Padovan --- drivers/dma-buf/sync_file.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/sync_file.h | 8 ++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index b67876b..16a3ef7 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c @@ -122,6 +122,42 @@ void sync_file_install(struct sync_file *sync_file, int fd) } EXPORT_SYMBOL(sync_file_install); +static void sync_file_fence_collection_put(void *data) +{ + struct sync_file *sync_file = data; + + sync_file_put(sync_file); +} + +struct fence_collection *sync_file_fences_get(int fd) +{ + struct fence_collection *collection; + struct sync_file *sync_file; + int i; + + sync_file = sync_file_fdget(fd); + if (!sync_file) + return NULL; + + collection = kzalloc(offsetof(struct fence_collection, + fences[sync_file->num_fences]), + GFP_KERNEL); + if (!collection) + return NULL; + + collection->num_fences = sync_file->num_fences; + collection->user_data = sync_file; + collection->func = sync_file_fence_collection_put; + + for (i = 0; i < sync_file->num_fences; ++i) { + collection->fences[i] = sync_file->cbs[i].fence; + fence_get(collection->fences[i]); + } + + return collection; +} +EXPORT_SYMBOL(sync_file_fences_get); + static void sync_file_add_pt(struct sync_file *sync_file, int *i, struct fence *fence) { diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h index 7b7a89d..1b9386a 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -103,4 +103,12 @@ void sync_file_put(struct sync_file *sync_file); */ void sync_file_install(struct sync_file *sync_file, int fd); +/** + * sync_file_fences_get - get the fence collection related to the fd + * @fd: file descriptor to look for a fence collection + * + * Ensures @fd references a valid sync_file, increments the refcount of the + * backing file. Returns the fence_collection or NULL in case of error. + */ +struct fence_collection *sync_file_fences_get(int fd); #endif /* _LINUX_SYNC_H */