From patchwork Mon Apr 25 22:33:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gustavo Padovan X-Patchwork-Id: 8933031 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 816BE9F372 for ; Mon, 25 Apr 2016 22:34:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 883C6201C7 for ; Mon, 25 Apr 2016 22:34:03 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 9BAB22013D for ; Mon, 25 Apr 2016 22:34:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B57156E60E; Mon, 25 Apr 2016 22:33:57 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw0-f196.google.com (mail-yw0-f196.google.com [209.85.161.196]) by gabe.freedesktop.org (Postfix) with ESMTPS id 52FAC6E6CD for ; Mon, 25 Apr 2016 22:33:50 +0000 (UTC) Received: by mail-yw0-f196.google.com with SMTP id o63so1366086ywe.0 for ; Mon, 25 Apr 2016 15:33:50 -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=rD+x0YaJnJpt694+DgyqbB8cf3vOLuRobh/VnEQo2UI=; b=E5FWlCijFr1CPY+F72av3ABe2qpMdJhHLq+Q+3ApJZ98fsVTwK0mpMXOyI7lHq3Bu0 cWsFuTORT2ULLgN5bE3nwKfw+Tw4tQQaDw0IqLfwflxpkT2WPE9lreCCApFaowGYsTSc rJvB5ncm2w35I591egmXdbwzzEYWBok8RQwWvX0ODUjp/UhNUhF0AYg0RfhSXbd9PO4i W49hvP2aEWm8dCAyBgjdubEol6hSpD+olrRdi7SfUXAkZqjLtk/TcI8RyftmmWYCp1HT Wg6AEPYTu8HYh3dc9QIvTSyslVmAADdL0MGDG7ZTCUaq59GVlMvnemMQnLyYt3gRdLTj 1EuQ== X-Gm-Message-State: AOPr4FUjb1t8na8XRtxOJ3nRyerMiaBD1eeL8MDTSDYeBimM46s8ZW9+wF/WG/ZjW9fXQA== X-Received: by 10.13.252.67 with SMTP id m64mr25314587ywf.67.1461623628982; Mon, 25 Apr 2016 15:33:48 -0700 (PDT) Received: from jade.localdomain ([201.82.24.203]) by smtp.gmail.com with ESMTPSA id r8sm13840742ywb.20.2016.04.25.15.33.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Apr 2016 15:33:48 -0700 (PDT) From: Gustavo Padovan To: Greg Kroah-Hartman Subject: [RFC v2 3/8] dma-buf/sync_file: add sync_file_fences_get() Date: Mon, 25 Apr 2016 19:33:23 -0300 Message-Id: <1461623608-29538-4-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1461623608-29538-1-git-send-email-gustavo@padovan.org> References: <1461623608-29538-1-git-send-email-gustavo@padovan.org> Cc: devel@driverdev.osuosl.org, Daniel Stone , Daniel Vetter , Riley Andrews , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , 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=-3.8 required=5.0 tests=BAYES_00, RCVD_IN_BL_SPAMCOP_NET, 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. v2: Comments by Daniel Vetter - Adapt to new version of fence_collection_init() - Hold a reference for the fence we return Signed-off-by: Gustavo Padovan --- drivers/dma-buf/sync_file.c | 60 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/sync_file.h | 3 +++ 2 files changed, 63 insertions(+) diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 40ee098..5dd76c0 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 @@ -147,6 +148,62 @@ void sync_file_install(struct sync_file *sync_file, int fd) } EXPORT_SYMBOL(sync_file_install); +/** + * sync_file_fences_get - get the fence(s) related to the sync_file fd + * @fd: sync_file fd to get the fence(s) 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_collection 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_fences_get(int fd) +{ + struct sync_file *sync_file; + struct fence_collection *collection; + struct fence_collection_cb *cb; + 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); + sync_file_put(sync_file); + return fence; + } + + cb = kcalloc(sync_file->num_fences, sizeof(*cb), GFP_KERNEL); + if (!cb) { + sync_file_put(sync_file); + return NULL; + } + + for (i = 0 ; i < sync_file->num_fences ; i++) + cb[i].fence = sync_file->cbs[i].fence; + + collection = fence_collection_create(sync_file->num_fences, cb); + if (!collection) { + kfree(cb); + sync_file_put(sync_file); + return NULL; + } + + sync_file->collection = collection; + fence_get(&collection->base); + 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) { @@ -234,6 +291,9 @@ static void sync_file_free(struct kref *kref) kref); int i; + if (sync_file->collection) + fence_put(&sync_file->collection->base); + 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 900fa0c..3eb3aad 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 + * @collection: collection with the fences in the sync_file * @cbs: sync_pts callback information */ struct sync_file { @@ -49,6 +50,7 @@ struct sync_file { wait_queue_head_t wq; atomic_t status; + struct fence_collection *collection; struct sync_file_cb cbs[]; }; @@ -59,4 +61,5 @@ void sync_file_install(struct sync_file *sync_file, int fd); struct sync_file *sync_file_merge(const char *name, struct sync_file *a, struct sync_file *b); +struct fence *sync_file_fences_get(int fd); #endif /* _LINUX_SYNC_H */