xref: /linux/drivers/gpu/drm/xe/xe_exec_queue.h (revision c0d6f52f9b62479d61f8cd4faf9fb2f8bce6e301)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2021 Intel Corporation
4  */
5 
6 #ifndef _XE_EXEC_QUEUE_H_
7 #define _XE_EXEC_QUEUE_H_
8 
9 #include "xe_exec_queue_types.h"
10 #include "xe_vm_types.h"
11 
12 struct drm_device;
13 struct drm_file;
14 struct xe_device;
15 struct xe_file;
16 
17 #define for_each_tlb_inval(__i)	\
18 	for (__i = XE_EXEC_QUEUE_TLB_INVAL_PRIMARY_GT; \
19 	     __i <= XE_EXEC_QUEUE_TLB_INVAL_MEDIA_GT; ++__i)
20 
21 struct xe_exec_queue *xe_exec_queue_create(struct xe_device *xe, struct xe_vm *vm,
22 					   u32 logical_mask, u16 width,
23 					   struct xe_hw_engine *hw_engine, u32 flags,
24 					   u64 extensions);
25 struct xe_exec_queue *xe_exec_queue_create_class(struct xe_device *xe, struct xe_gt *gt,
26 						 struct xe_vm *vm,
27 						 enum xe_engine_class class,
28 						 u32 flags, u64 extensions);
29 struct xe_exec_queue *xe_exec_queue_create_bind(struct xe_device *xe,
30 						struct xe_tile *tile,
31 						u32 flags, u64 extensions);
32 
33 void xe_exec_queue_fini(struct xe_exec_queue *q);
34 void xe_exec_queue_destroy(struct kref *ref);
35 void xe_exec_queue_assign_name(struct xe_exec_queue *q, u32 instance);
36 
37 static inline struct xe_exec_queue *
38 xe_exec_queue_get_unless_zero(struct xe_exec_queue *q)
39 {
40 	if (kref_get_unless_zero(&q->refcount))
41 		return q;
42 
43 	return NULL;
44 }
45 
46 struct xe_exec_queue *xe_exec_queue_lookup(struct xe_file *xef, u32 id);
47 
48 static inline struct xe_exec_queue *xe_exec_queue_get(struct xe_exec_queue *q)
49 {
50 	kref_get(&q->refcount);
51 	return q;
52 }
53 
54 static inline void xe_exec_queue_put(struct xe_exec_queue *q)
55 {
56 	kref_put(&q->refcount, xe_exec_queue_destroy);
57 }
58 
59 static inline bool xe_exec_queue_is_parallel(struct xe_exec_queue *q)
60 {
61 	return q->width > 1;
62 }
63 
64 static inline bool xe_exec_queue_uses_pxp(struct xe_exec_queue *q)
65 {
66 	return q->pxp.type;
67 }
68 
69 /**
70  * xe_exec_queue_is_multi_queue() - Whether an exec_queue is part of a queue group.
71  * @q: The exec_queue
72  *
73  * Return: True if the exec_queue is part of a queue group, false otherwise.
74  */
75 static inline bool xe_exec_queue_is_multi_queue(struct xe_exec_queue *q)
76 {
77 	return q->multi_queue.valid;
78 }
79 
80 /**
81  * xe_exec_queue_is_multi_queue_primary() - Whether an exec_queue is primary queue
82  * of a multi queue group.
83  * @q: The exec_queue
84  *
85  * Return: True if @q is primary queue of a queue group, false otherwise.
86  */
87 static inline bool xe_exec_queue_is_multi_queue_primary(struct xe_exec_queue *q)
88 {
89 	return q->multi_queue.is_primary;
90 }
91 
92 /**
93  * xe_exec_queue_is_multi_queue_secondary() - Whether an exec_queue is secondary queue
94  * of a multi queue group.
95  * @q: The exec_queue
96  *
97  * Return: True if @q is secondary queue of a queue group, false otherwise.
98  */
99 static inline bool xe_exec_queue_is_multi_queue_secondary(struct xe_exec_queue *q)
100 {
101 	return xe_exec_queue_is_multi_queue(q) && !xe_exec_queue_is_multi_queue_primary(q);
102 }
103 
104 /**
105  * xe_exec_queue_multi_queue_primary() - Get multi queue group's primary queue
106  * @q: The exec_queue
107  *
108  * If @q belongs to a multi queue group, then the primary queue of the group will
109  * be returned. Otherwise, @q will be returned.
110  */
111 static inline struct xe_exec_queue *xe_exec_queue_multi_queue_primary(struct xe_exec_queue *q)
112 {
113 	return xe_exec_queue_is_multi_queue(q) ? q->multi_queue.group->primary : q;
114 }
115 
116 bool xe_exec_queue_is_lr(struct xe_exec_queue *q);
117 
118 bool xe_exec_queue_is_idle(struct xe_exec_queue *q);
119 
120 void xe_exec_queue_kill(struct xe_exec_queue *q);
121 
122 int xe_exec_queue_create_ioctl(struct drm_device *dev, void *data,
123 			       struct drm_file *file);
124 int xe_exec_queue_destroy_ioctl(struct drm_device *dev, void *data,
125 				struct drm_file *file);
126 int xe_exec_queue_get_property_ioctl(struct drm_device *dev, void *data,
127 				     struct drm_file *file);
128 int xe_exec_queue_set_property_ioctl(struct drm_device *dev, void *data,
129 				     struct drm_file *file);
130 enum xe_exec_queue_priority xe_exec_queue_device_get_max_priority(struct xe_device *xe);
131 
132 void xe_exec_queue_last_fence_put(struct xe_exec_queue *e, struct xe_vm *vm);
133 void xe_exec_queue_last_fence_put_unlocked(struct xe_exec_queue *e);
134 struct dma_fence *xe_exec_queue_last_fence_get(struct xe_exec_queue *e,
135 					       struct xe_vm *vm);
136 struct dma_fence *xe_exec_queue_last_fence_get_for_resume(struct xe_exec_queue *e,
137 							  struct xe_vm *vm);
138 void xe_exec_queue_last_fence_set(struct xe_exec_queue *e, struct xe_vm *vm,
139 				  struct dma_fence *fence);
140 
141 void xe_exec_queue_tlb_inval_last_fence_put(struct xe_exec_queue *q,
142 					    struct xe_vm *vm,
143 					    unsigned int type);
144 
145 void xe_exec_queue_tlb_inval_last_fence_put_unlocked(struct xe_exec_queue *q,
146 						     unsigned int type);
147 
148 struct dma_fence *xe_exec_queue_tlb_inval_last_fence_get(struct xe_exec_queue *q,
149 							 struct xe_vm *vm,
150 							 unsigned int type);
151 
152 void xe_exec_queue_tlb_inval_last_fence_set(struct xe_exec_queue *q,
153 					    struct xe_vm *vm,
154 					    struct dma_fence *fence,
155 					    unsigned int type);
156 
157 void xe_exec_queue_update_run_ticks(struct xe_exec_queue *q);
158 
159 int xe_exec_queue_contexts_hwsp_rebase(struct xe_exec_queue *q, void *scratch);
160 
161 struct xe_lrc *xe_exec_queue_lrc(struct xe_exec_queue *q);
162 
163 /**
164  * xe_exec_queue_idle_skip_suspend() - Can exec queue skip suspend
165  * @q: The exec_queue
166  *
167  * If an exec queue is not parallel and is idle, the suspend steps can be
168  * skipped in the submission backend immediatley signaling the suspend fence.
169  * Parallel queues cannot skip this step due to limitations in the submission
170  * backend.
171  *
172  * Return: True if exec queue is idle and can skip suspend steps, False
173  * otherwise
174  */
175 static inline bool xe_exec_queue_idle_skip_suspend(struct xe_exec_queue *q)
176 {
177 	return !xe_exec_queue_is_parallel(q) && xe_exec_queue_is_idle(q);
178 }
179 
180 #endif
181