From patchwork Fri Apr 15 01:29:35 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 8844121 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5A2CCC0553 for ; Fri, 15 Apr 2016 01:29:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6AD98202EB for ; Fri, 15 Apr 2016 01:29:55 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 3B27C20373 for ; Fri, 15 Apr 2016 01:29:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9EAE66EB5F; Fri, 15 Apr 2016 01:29:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by gabe.freedesktop.org (Postfix) with ESMTPS id E25B06EB59 for ; Fri, 15 Apr 2016 01:29:47 +0000 (UTC) Received: by mail-pa0-f47.google.com with SMTP id er2so21541501pad.3 for ; Thu, 14 Apr 2016 18:29:47 -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=XgBJrWYLEZKuvqdyxCreetBTpFYd1aic7zqK0ZtaJcE=; b=fYljalTkTISWG6gkl0j9OHJXV93RkJuzALPu7yaGRfNtNtBDsnCPrIZJD1ltpHdl2V QWT/S983e77pEYlekbZps+T09cMr/CnmZvBdCYJla+57X0jSR+nb75RfVEROwcOPya31 3tgNQ4nEgf79FkbRynHAEp6F+m9nj7Ea6Nmb1iWDv3lmwxLz7qgvVyr2Q6e+mXwMprgS 8qm4ne7fqqXGaRccAyNNJ1MBuU4C4WeOllHORo4yb5rsufi9gnxym23nfSK2RAxH7UP9 CQLmv+fs2MpB8gILv6aaXdnmkf85glsZ+kstj/zp+lwVmGMLk73N3HTDFSojsv+ekstK tEOQ== X-Gm-Message-State: AOPr4FUDuFcFWtDyicfxclYvJXBgo5iBbJAF5a8fMNnX4pNuhXbfpvUAD3SNpuPET5nVhg== X-Received: by 10.66.63.98 with SMTP id f2mr25919705pas.123.1460683787264; Thu, 14 Apr 2016 18:29:47 -0700 (PDT) Received: from jade.localdomain (c-73-241-147-137.hsd1.ca.comcast.net. [73.241.147.137]) by smtp.gmail.com with ESMTPSA id 132sm10740538pfw.35.2016.04.14.18.29.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Apr 2016 18:29:46 -0700 (PDT) From: Gustavo Padovan To: dri-devel@lists.freedesktop.org Subject: [RFC 2/8] dma-buf/sync_file: add sync_file_fences_get() Date: Thu, 14 Apr 2016 18:29:35 -0700 Message-Id: <1460683781-22535-3-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1460683781-22535-1-git-send-email-gustavo@padovan.org> References: <1460683781-22535-1-git-send-email-gustavo@padovan.org> Cc: marcheu@google.com, Daniel Stone , seanpaul@google.com, Daniel Vetter , =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , linux-kernel@vger.kernel.org, Riley Andrews , 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-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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. 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. Signed-off-by: Gustavo Padovan --- drivers/dma-buf/sync_file.c | 37 +++++++++++++++++++++++++++++++++++++ include/linux/sync_file.h | 10 ++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 4d2af24..926fafa 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,39 @@ void sync_file_install(struct sync_file *sync_file, int fd) } EXPORT_SYMBOL(sync_file_install); +struct fence *sync_file_fences_get(int fd) +{ + struct sync_file *sync_file; + struct fence_collection *collection; + 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; + + sync_file_put(sync_file); + return fence; + } + + collection = fence_collection_init(sync_file->num_fences); + if (!collection) { + sync_file_put(sync_file); + return NULL; + } + + for (i = 0 ; i < sync_file->num_fences ; i++) + fence_collection_add(collection, sync_file->cbs[i].fence); + + sync_file->collection = collection; + sync_file_put(sync_file); + + return &collection->base; +} +EXPORT_SYMBOL(sync_file_fences_get); + static void sync_file_add_pt(struct sync_file *sync_file, int *i, struct fence *fence) { @@ -200,6 +234,9 @@ static void sync_file_free(struct kref *kref) kref); int i; + if (sync_file->collection) + fence_collection_put(sync_file->collection); + for (i = 0; i < sync_file->num_fences; ++i) { fence_remove_callback(sync_file->cbs[i].fence, &sync_file->cbs[i].cb); diff --git a/include/linux/sync_file.h b/include/linux/sync_file.h index 7b7a89d..2cb0486 100644 --- a/include/linux/sync_file.h +++ b/include/linux/sync_file.h @@ -49,6 +49,7 @@ struct sync_file { wait_queue_head_t wq; atomic_t status; + struct fence_collection *collection; struct sync_file_cb cbs[]; }; @@ -103,4 +104,13 @@ 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 related to the fd + * @fd: file descriptor to look for a fence collection + * + * Ensures @fd references a valid sync_file and returns the base object + * of the fence_collection that contains all fences in the sync_file + * or NULL in case of error. + */ +struct fence *sync_file_fences_get(int fd); #endif /* _LINUX_SYNC_H */