Merge tag 'fsdax-fix-5.1-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/nvdimm...
[linux-block.git] / include / linux / dma-fence-array.h
CommitLineData
f54d1867
CW
1/*
2 * fence-array: aggregates fence to be waited together
3 *
4 * Copyright (C) 2016 Collabora Ltd
5 * Copyright (C) 2016 Advanced Micro Devices, Inc.
6 * Authors:
7 * Gustavo Padovan <gustavo@padovan.org>
8 * Christian König <christian.koenig@amd.com>
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * more details.
18 */
19
20#ifndef __LINUX_DMA_FENCE_ARRAY_H
21#define __LINUX_DMA_FENCE_ARRAY_H
22
23#include <linux/dma-fence.h>
03e4e0a9 24#include <linux/irq_work.h>
f54d1867
CW
25
26/**
27 * struct dma_fence_array_cb - callback helper for fence array
28 * @cb: fence callback structure for signaling
29 * @array: reference to the parent fence array object
30 */
31struct dma_fence_array_cb {
32 struct dma_fence_cb cb;
33 struct dma_fence_array *array;
34};
35
36/**
37 * struct dma_fence_array - fence to represent an array of fences
38 * @base: fence base class
39 * @lock: spinlock for fence handling
40 * @num_fences: number of fences in the array
41 * @num_pending: fences in the array still pending
42 * @fences: array of the fences
3725cd09 43 * @work: internal irq_work function
f54d1867
CW
44 */
45struct dma_fence_array {
46 struct dma_fence base;
47
48 spinlock_t lock;
49 unsigned num_fences;
50 atomic_t num_pending;
51 struct dma_fence **fences;
03e4e0a9
CW
52
53 struct irq_work work;
f54d1867
CW
54};
55
56extern const struct dma_fence_ops dma_fence_array_ops;
57
58/**
59 * dma_fence_is_array - check if a fence is from the array subsclass
60 * @fence: fence to test
61 *
62 * Return true if it is a dma_fence_array and false otherwise.
63 */
64static inline bool dma_fence_is_array(struct dma_fence *fence)
65{
66 return fence->ops == &dma_fence_array_ops;
67}
68
69/**
70 * to_dma_fence_array - cast a fence to a dma_fence_array
71 * @fence: fence to cast to a dma_fence_array
72 *
73 * Returns NULL if the fence is not a dma_fence_array,
74 * or the dma_fence_array otherwise.
75 */
76static inline struct dma_fence_array *
77to_dma_fence_array(struct dma_fence *fence)
78{
79 if (fence->ops != &dma_fence_array_ops)
80 return NULL;
81
82 return container_of(fence, struct dma_fence_array, base);
83}
84
85struct dma_fence_array *dma_fence_array_create(int num_fences,
86 struct dma_fence **fences,
87 u64 context, unsigned seqno,
88 bool signal_on_any);
89
d5b72a21
PZ
90bool dma_fence_match_context(struct dma_fence *fence, u64 context);
91
f54d1867 92#endif /* __LINUX_DMA_FENCE_ARRAY_H */