diff mbox

[v2,1/4] dma-fence: add dma_fence_match_context helper

Message ID 1489768492-25190-1-git-send-email-p.zabel@pengutronix.de (mailing list archive)
State New, archived
Headers show

Commit Message

Philipp Zabel March 17, 2017, 4:34 p.m. UTC
Add a helper to check if all fences in a fence array are from a given
context. For convenience, the function can also handle being given a
non-array fence.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/dma-buf/dma-fence-array.c | 26 ++++++++++++++++++++++++++
 include/linux/dma-fence-array.h   |  2 ++
 2 files changed, 28 insertions(+)

Comments

Gustavo Padovan March 17, 2017, 5:58 p.m. UTC | #1
Hi Philipp,

2017-03-17 Philipp Zabel <p.zabel@pengutronix.de>:

> Add a helper to check if all fences in a fence array are from a given
> context. For convenience, the function can also handle being given a
> non-array fence.
> 
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---
>  drivers/dma-buf/dma-fence-array.c | 26 ++++++++++++++++++++++++++
>  include/linux/dma-fence-array.h   |  2 ++
>  2 files changed, 28 insertions(+)

Looks good to me.

Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.com>

Gustavo
Sumit Semwal March 17, 2017, 6:03 p.m. UTC | #2
Hi Philipp,

thanks for the patch!

On 17 March 2017 at 22:04, Philipp Zabel <p.zabel@pengutronix.de> wrote:
> Add a helper to check if all fences in a fence array are from a given
> context. For convenience, the function can also handle being given a
> non-array fence.
>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
> ---

Looks good to me, please feel free to add my
Acked-by: Sumit Semwal <sumit.semwal@linaro.org>

>  drivers/dma-buf/dma-fence-array.c | 26 ++++++++++++++++++++++++++
>  include/linux/dma-fence-array.h   |  2 ++
>  2 files changed, 28 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
> index 67eb7c8fb88c3..0350829ba62e7 100644
> --- a/drivers/dma-buf/dma-fence-array.c
> +++ b/drivers/dma-buf/dma-fence-array.c
> @@ -144,3 +144,29 @@ struct dma_fence_array *dma_fence_array_create(int num_fences,
>         return array;
>  }
>  EXPORT_SYMBOL(dma_fence_array_create);
> +
> +/**
> + * dma_fence_match_context - Check if all fences are from the given context
> + * @fence:             [in]    fence or fence array
> + * @context:           [in]    fence context to check all fences against
> + *
> + * Checks the provided fence or, for a fence array, all fences in the array
> + * against the given context. Returns false if any fence is from a different
> + * context.
> + */
> +bool dma_fence_match_context(struct dma_fence *fence, u64 context)
> +{
> +       struct dma_fence_array *array = to_dma_fence_array(fence);
> +       unsigned i;
> +
> +       if (!dma_fence_is_array(fence))
> +               return fence->context == context;
> +
> +       for (i = 0; i < array->num_fences; i++) {
> +               if (array->fences[i]->context != context)
> +                       return false;
> +       }
> +
> +       return true;
> +}
> +EXPORT_SYMBOL(dma_fence_match_context);
> diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h
> index 5900945f962dd..332a5420243c4 100644
> --- a/include/linux/dma-fence-array.h
> +++ b/include/linux/dma-fence-array.h
> @@ -83,4 +83,6 @@ struct dma_fence_array *dma_fence_array_create(int num_fences,
>                                                u64 context, unsigned seqno,
>                                                bool signal_on_any);
>
> +bool dma_fence_match_context(struct dma_fence *fence, u64 context);
> +
>  #endif /* __LINUX_DMA_FENCE_ARRAY_H */
> --
> 2.11.0
>

Best,
Sumit.
Christian König March 17, 2017, 6:23 p.m. UTC | #3
Am 17.03.2017 um 17:34 schrieb Philipp Zabel:
> Add a helper to check if all fences in a fence array are from a given
> context. For convenience, the function can also handle being given a
> non-array fence.
>
> Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/dma-buf/dma-fence-array.c | 26 ++++++++++++++++++++++++++
>   include/linux/dma-fence-array.h   |  2 ++
>   2 files changed, 28 insertions(+)
>
> diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
> index 67eb7c8fb88c3..0350829ba62e7 100644
> --- a/drivers/dma-buf/dma-fence-array.c
> +++ b/drivers/dma-buf/dma-fence-array.c
> @@ -144,3 +144,29 @@ struct dma_fence_array *dma_fence_array_create(int num_fences,
>   	return array;
>   }
>   EXPORT_SYMBOL(dma_fence_array_create);
> +
> +/**
> + * dma_fence_match_context - Check if all fences are from the given context
> + * @fence:		[in]	fence or fence array
> + * @context:		[in]	fence context to check all fences against
> + *
> + * Checks the provided fence or, for a fence array, all fences in the array
> + * against the given context. Returns false if any fence is from a different
> + * context.
> + */
> +bool dma_fence_match_context(struct dma_fence *fence, u64 context)
> +{
> +	struct dma_fence_array *array = to_dma_fence_array(fence);
> +	unsigned i;
> +
> +	if (!dma_fence_is_array(fence))
> +		return fence->context == context;
> +
> +	for (i = 0; i < array->num_fences; i++) {
> +		if (array->fences[i]->context != context)
> +			return false;
> +	}
> +
> +	return true;
> +}
> +EXPORT_SYMBOL(dma_fence_match_context);
> diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h
> index 5900945f962dd..332a5420243c4 100644
> --- a/include/linux/dma-fence-array.h
> +++ b/include/linux/dma-fence-array.h
> @@ -83,4 +83,6 @@ struct dma_fence_array *dma_fence_array_create(int num_fences,
>   					       u64 context, unsigned seqno,
>   					       bool signal_on_any);
>   
> +bool dma_fence_match_context(struct dma_fence *fence, u64 context);
> +
>   #endif /* __LINUX_DMA_FENCE_ARRAY_H */
diff mbox

Patch

diff --git a/drivers/dma-buf/dma-fence-array.c b/drivers/dma-buf/dma-fence-array.c
index 67eb7c8fb88c3..0350829ba62e7 100644
--- a/drivers/dma-buf/dma-fence-array.c
+++ b/drivers/dma-buf/dma-fence-array.c
@@ -144,3 +144,29 @@  struct dma_fence_array *dma_fence_array_create(int num_fences,
 	return array;
 }
 EXPORT_SYMBOL(dma_fence_array_create);
+
+/**
+ * dma_fence_match_context - Check if all fences are from the given context
+ * @fence:		[in]	fence or fence array
+ * @context:		[in]	fence context to check all fences against
+ *
+ * Checks the provided fence or, for a fence array, all fences in the array
+ * against the given context. Returns false if any fence is from a different
+ * context.
+ */
+bool dma_fence_match_context(struct dma_fence *fence, u64 context)
+{
+	struct dma_fence_array *array = to_dma_fence_array(fence);
+	unsigned i;
+
+	if (!dma_fence_is_array(fence))
+		return fence->context == context;
+
+	for (i = 0; i < array->num_fences; i++) {
+		if (array->fences[i]->context != context)
+			return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL(dma_fence_match_context);
diff --git a/include/linux/dma-fence-array.h b/include/linux/dma-fence-array.h
index 5900945f962dd..332a5420243c4 100644
--- a/include/linux/dma-fence-array.h
+++ b/include/linux/dma-fence-array.h
@@ -83,4 +83,6 @@  struct dma_fence_array *dma_fence_array_create(int num_fences,
 					       u64 context, unsigned seqno,
 					       bool signal_on_any);
 
+bool dma_fence_match_context(struct dma_fence *fence, u64 context);
+
 #endif /* __LINUX_DMA_FENCE_ARRAY_H */