From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932169AbcAOO7d (ORCPT ); Fri, 15 Jan 2016 09:59:33 -0500 Received: from mail-yk0-f175.google.com ([209.85.160.175]:35594 "EHLO mail-yk0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755061AbcAOO5G (ORCPT ); Fri, 15 Jan 2016 09:57:06 -0500 From: Gustavo Padovan To: Greg Kroah-Hartman Cc: linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org, dri-devel@lists.freedesktop.org, daniels@collabora.com, =?UTF-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= , Riley Andrews , Daniel Vetter , Rob Clark , Greg Hackmann , John Harrison , Maarten Lankhorst , Gustavo Padovan Subject: [RFC 21/29] dma-buf/fence: add fence_create_on_timeline() Date: Fri, 15 Jan 2016 12:55:31 -0200 Message-Id: <1452869739-3304-22-git-send-email-gustavo@padovan.org> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1452869739-3304-1-git-send-email-gustavo@padovan.org> References: <1452869739-3304-1-git-send-email-gustavo@padovan.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gustavo Padovan This functions in intended to replace sync_pt_create() and it does exactly the same thing sync_pt_create() did. Signed-off-by: Gustavo Padovan --- drivers/dma-buf/fence.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/staging/android/sync.c | 20 ++------------------ include/linux/fence.h | 3 +++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/drivers/dma-buf/fence.c b/drivers/dma-buf/fence.c index ec51146..0a07fcb 100644 --- a/drivers/dma-buf/fence.c +++ b/drivers/dma-buf/fence.c @@ -768,6 +768,44 @@ err_free_cb: EXPORT_SYMBOL(fence_wait_any_timeout); /** + * fence_create_on_timeline - create a fence and add it to the timeline + * or until timeout elapses + * @obj: [in] timeline object + * @ops: [in] fence_ops to use + * @size: [in] size to allocate struct fence + * @value: [in] value of this fence + * + * This function allocates a new fence and initialize it as a child of the + * fence_timeline provided. The value received is the seqno used to know + * when the fence is signaled. + * + * Returns NULL if fails to allocate memory or size is too small. + */ +struct fence *fence_create_on_timeline(struct fence_timeline *obj, + const struct fence_ops *ops, int size, + unsigned int value) +{ + unsigned long flags; + struct fence *fence; + + if (size < sizeof(*fence)) + return NULL; + + fence = kzalloc(size, GFP_KERNEL); + if (!fence) + return NULL; + + spin_lock_irqsave(&obj->lock, flags); + fence_timeline_get(obj); + fence_init(fence, ops, &obj->lock, obj->context, value); + list_add_tail(&fence->child_list, &obj->child_list_head); + INIT_LIST_HEAD(&fence->active_list); + spin_unlock_irqrestore(&obj->lock, flags); + return fence; +} +EXPORT_SYMBOL(fence_create_on_timeline); + +/** * fence_init - Initialize a custom fence. * @fence: [in] the fence to initialize * @ops: [in] the fence_ops for operations on this fence diff --git a/drivers/staging/android/sync.c b/drivers/staging/android/sync.c index a275108..2365db7 100644 --- a/drivers/staging/android/sync.c +++ b/drivers/staging/android/sync.c @@ -36,24 +36,8 @@ static const struct file_operations sync_fence_fops; struct fence *sync_pt_create(struct fence_timeline *obj, int size, u32 value) { - unsigned long flags; - struct fence *fence; - - if (size < sizeof(*fence)) - return NULL; - - fence = kzalloc(size, GFP_KERNEL); - if (!fence) - return NULL; - - spin_lock_irqsave(&obj->lock, flags); - fence_timeline_get(obj); - fence_init(fence, &sync_fence_ops, &obj->lock, - obj->context, value); - list_add_tail(&fence->child_list, &obj->child_list_head); - INIT_LIST_HEAD(&fence->active_list); - spin_unlock_irqrestore(&obj->lock, flags); - return fence; + return fence_create_on_timeline(obj, &sync_fence_ops, + sizeof(struct fence), value); } EXPORT_SYMBOL(sync_pt_create); diff --git a/include/linux/fence.h b/include/linux/fence.h index 8908433..adece43 100644 --- a/include/linux/fence.h +++ b/include/linux/fence.h @@ -212,6 +212,9 @@ struct fence_ops { void (*timeline_value_str)(struct fence *fence, char *str, int size); }; +struct fence *fence_create_on_timeline(struct fence_timeline *obj, + const struct fence_ops *ops, int size, + unsigned int value); void fence_init(struct fence *fence, const struct fence_ops *ops, spinlock_t *lock, unsigned context, unsigned seqno); -- 2.5.0