Merge tag 'mips_5.18_1' of git://git.kernel.org/pub/scm/linux/kernel/git/mips/linux
[linux-block.git] / include / linux / dma-fence-array.h
CommitLineData
1802d0be 1/* SPDX-License-Identifier: GPL-2.0-only */
f54d1867
CW
2/*
3 * fence-array: aggregates fence to be waited together
4 *
5 * Copyright (C) 2016 Collabora Ltd
6 * Copyright (C) 2016 Advanced Micro Devices, Inc.
7 * Authors:
8 * Gustavo Padovan <gustavo@padovan.org>
9 * Christian König <christian.koenig@amd.com>
f54d1867
CW
10 */
11
12#ifndef __LINUX_DMA_FENCE_ARRAY_H
13#define __LINUX_DMA_FENCE_ARRAY_H
14
15#include <linux/dma-fence.h>
03e4e0a9 16#include <linux/irq_work.h>
f54d1867
CW
17
18/**
19 * struct dma_fence_array_cb - callback helper for fence array
20 * @cb: fence callback structure for signaling
21 * @array: reference to the parent fence array object
22 */
23struct dma_fence_array_cb {
24 struct dma_fence_cb cb;
25 struct dma_fence_array *array;
26};
27
28/**
29 * struct dma_fence_array - fence to represent an array of fences
30 * @base: fence base class
31 * @lock: spinlock for fence handling
32 * @num_fences: number of fences in the array
33 * @num_pending: fences in the array still pending
34 * @fences: array of the fences
3725cd09 35 * @work: internal irq_work function
f54d1867
CW
36 */
37struct dma_fence_array {
38 struct dma_fence base;
39
40 spinlock_t lock;
41 unsigned num_fences;
42 atomic_t num_pending;
43 struct dma_fence **fences;
03e4e0a9
CW
44
45 struct irq_work work;
f54d1867
CW
46};
47
f54d1867
CW
48/**
49 * to_dma_fence_array - cast a fence to a dma_fence_array
50 * @fence: fence to cast to a dma_fence_array
51 *
52 * Returns NULL if the fence is not a dma_fence_array,
53 * or the dma_fence_array otherwise.
54 */
55static inline struct dma_fence_array *
56to_dma_fence_array(struct dma_fence *fence)
57{
976b6d97 58 if (!fence || !dma_fence_is_array(fence))
f54d1867
CW
59 return NULL;
60
61 return container_of(fence, struct dma_fence_array, base);
62}
63
64struct dma_fence_array *dma_fence_array_create(int num_fences,
65 struct dma_fence **fences,
66 u64 context, unsigned seqno,
67 bool signal_on_any);
68
d5b72a21
PZ
69bool dma_fence_match_context(struct dma_fence *fence, u64 context);
70
f54d1867 71#endif /* __LINUX_DMA_FENCE_ARRAY_H */