blob: 303dd712220fdf4fe55b4b3a1c9a5e38c36b9e52 [file] [log] [blame]
Thomas Gleixner1802d0b2019-05-27 08:55:21 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Chris Wilsonf54d1862016-10-25 13:00:45 +01002/*
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>
Chris Wilsonf54d1862016-10-25 13:00:45 +010010 */
11
12#ifndef __LINUX_DMA_FENCE_ARRAY_H
13#define __LINUX_DMA_FENCE_ARRAY_H
14
15#include <linux/dma-fence.h>
Chris Wilson03e4e0a2017-11-14 16:27:19 +000016#include <linux/irq_work.h>
Chris Wilsonf54d1862016-10-25 13:00:45 +010017
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
Jonathan Corbet3725cd02019-01-16 15:34:36 -070035 * @work: internal irq_work function
Chris Wilsonf54d1862016-10-25 13:00:45 +010036 */
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;
Chris Wilson03e4e0a2017-11-14 16:27:19 +000044
45 struct irq_work work;
Chris Wilsonf54d1862016-10-25 13:00:45 +010046};
47
48extern const struct dma_fence_ops dma_fence_array_ops;
49
50/**
51 * dma_fence_is_array - check if a fence is from the array subsclass
52 * @fence: fence to test
53 *
54 * Return true if it is a dma_fence_array and false otherwise.
55 */
56static inline bool dma_fence_is_array(struct dma_fence *fence)
57{
58 return fence->ops == &dma_fence_array_ops;
59}
60
61/**
62 * to_dma_fence_array - cast a fence to a dma_fence_array
63 * @fence: fence to cast to a dma_fence_array
64 *
65 * Returns NULL if the fence is not a dma_fence_array,
66 * or the dma_fence_array otherwise.
67 */
68static inline struct dma_fence_array *
69to_dma_fence_array(struct dma_fence *fence)
70{
71 if (fence->ops != &dma_fence_array_ops)
72 return NULL;
73
74 return container_of(fence, struct dma_fence_array, base);
75}
76
77struct dma_fence_array *dma_fence_array_create(int num_fences,
78 struct dma_fence **fences,
79 u64 context, unsigned seqno,
80 bool signal_on_any);
81
Philipp Zabeld5b72a22017-03-17 17:34:49 +010082bool dma_fence_match_context(struct dma_fence *fence, u64 context);
83
Chris Wilsonf54d1862016-10-25 13:00:45 +010084#endif /* __LINUX_DMA_FENCE_ARRAY_H */