xref: /linux/drivers/gpu/drm/xe/xe_range_fence.h (revision e6a901a00822659181c93c86d8bbc2a17779fddc)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2023 Intel Corporation
4  */
5 
6 #ifndef _XE_RANGE_FENCE_H_
7 #define _XE_RANGE_FENCE_H_
8 
9 #include <linux/dma-fence.h>
10 #include <linux/rbtree.h>
11 #include <linux/types.h>
12 
13 struct xe_range_fence_tree;
14 struct xe_range_fence;
15 
16 /** struct xe_range_fence_ops - XE range fence ops */
17 struct xe_range_fence_ops {
18 	/** @free: free range fence op */
19 	void (*free)(struct xe_range_fence *rfence);
20 };
21 
22 /** struct xe_range_fence - XE range fence (address conflict tracking) */
23 struct xe_range_fence {
24 	/** @rb: RB tree node inserted into interval tree */
25 	struct rb_node rb;
26 	/** @start: start address of range fence is interval tree */
27 	u64 start;
28 	/** @last: last address (inclusive) of range fence is interval tree */
29 	u64 last;
30 	/** @__subtree_last: interval tree internal usage */
31 	u64 __subtree_last;
32 	/**
33 	 * @fence: fence signals address in range fence no longer has conflict
34 	 */
35 	struct dma_fence *fence;
36 	/** @tree: interval tree which range fence belongs to */
37 	struct xe_range_fence_tree *tree;
38 	/**
39 	 * @cb: callback when fence signals to remove range fence free from interval tree
40 	 */
41 	struct dma_fence_cb cb;
42 	/** @link: used to defer free of range fence to non-irq context */
43 	struct llist_node link;
44 	/** @ops: range fence ops */
45 	const struct xe_range_fence_ops *ops;
46 };
47 
48 /** struct xe_range_fence_tree - interval tree to store range fences */
49 struct xe_range_fence_tree {
50 	/** @root: interval tree root */
51 	struct rb_root_cached root;
52 	/** @list: list of pending range fences to be freed */
53 	struct llist_head list;
54 };
55 
56 extern const struct xe_range_fence_ops xe_range_fence_kfree_ops;
57 
58 struct xe_range_fence *
59 xe_range_fence_tree_first(struct xe_range_fence_tree *tree, u64 start,
60 			  u64 last);
61 
62 struct xe_range_fence *
63 xe_range_fence_tree_next(struct xe_range_fence *rfence, u64 start, u64 last);
64 
65 void xe_range_fence_tree_init(struct xe_range_fence_tree *tree);
66 
67 void xe_range_fence_tree_fini(struct xe_range_fence_tree *tree);
68 
69 int xe_range_fence_insert(struct xe_range_fence_tree *tree,
70 			  struct xe_range_fence *rfence,
71 			  const struct xe_range_fence_ops *ops,
72 			  u64 start, u64 end,
73 			  struct dma_fence *fence);
74 
75 #endif
76