xref: /openbmc/linux/drivers/gpu/drm/i915/i915_request.h (revision 0791faebfe750292a8a842b64795a390ca4a3b51)
1e61e0f51SChris Wilson /*
2e61e0f51SChris Wilson  * Copyright © 2008-2018 Intel Corporation
3e61e0f51SChris Wilson  *
4e61e0f51SChris Wilson  * Permission is hereby granted, free of charge, to any person obtaining a
5e61e0f51SChris Wilson  * copy of this software and associated documentation files (the "Software"),
6e61e0f51SChris Wilson  * to deal in the Software without restriction, including without limitation
7e61e0f51SChris Wilson  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8e61e0f51SChris Wilson  * and/or sell copies of the Software, and to permit persons to whom the
9e61e0f51SChris Wilson  * Software is furnished to do so, subject to the following conditions:
10e61e0f51SChris Wilson  *
11e61e0f51SChris Wilson  * The above copyright notice and this permission notice (including the next
12e61e0f51SChris Wilson  * paragraph) shall be included in all copies or substantial portions of the
13e61e0f51SChris Wilson  * Software.
14e61e0f51SChris Wilson  *
15e61e0f51SChris Wilson  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16e61e0f51SChris Wilson  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17e61e0f51SChris Wilson  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18e61e0f51SChris Wilson  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19e61e0f51SChris Wilson  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20e61e0f51SChris Wilson  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21e61e0f51SChris Wilson  * IN THE SOFTWARE.
22e61e0f51SChris Wilson  *
23e61e0f51SChris Wilson  */
24e61e0f51SChris Wilson 
25e61e0f51SChris Wilson #ifndef I915_REQUEST_H
26e61e0f51SChris Wilson #define I915_REQUEST_H
27e61e0f51SChris Wilson 
28e61e0f51SChris Wilson #include <linux/dma-fence.h>
299b4d0598STvrtko Ursulin #include <linux/hrtimer.h>
30209df10bSChris Wilson #include <linux/irq_work.h>
319b4d0598STvrtko Ursulin #include <linux/llist.h>
32b66ea2c2SChris Wilson #include <linux/lockdep.h>
33e61e0f51SChris Wilson 
346a8679c0SChris Wilson #include "gem/i915_gem_context_types.h"
3522b7a426SChris Wilson #include "gt/intel_context_types.h"
3678e41dddSChris Wilson #include "gt/intel_engine_types.h"
3785bedbf1SChris Wilson #include "gt/intel_timeline_types.h"
3878e41dddSChris Wilson 
39e61e0f51SChris Wilson #include "i915_gem.h"
4098ff5c78SChris Wilson #include "i915_scheduler.h"
4132eb6bcfSChris Wilson #include "i915_selftest.h"
42e61e0f51SChris Wilson #include "i915_sw_fence.h"
4360dc43d1SThomas Hellström #include "i915_vma_resource.h"
44e61e0f51SChris Wilson 
45e61e0f51SChris Wilson #include <uapi/drm/i915_drm.h>
46e61e0f51SChris Wilson 
47e61e0f51SChris Wilson struct drm_file;
48e61e0f51SChris Wilson struct drm_i915_gem_object;
491f0e785aSChris Wilson struct drm_printer;
5011930817SThomas Hellström struct i915_deps;
51e61e0f51SChris Wilson struct i915_request;
52e61e0f51SChris Wilson 
53ff20afc4SThomas Hellström #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
54e61e0f51SChris Wilson struct i915_capture_list {
5560dc43d1SThomas Hellström 	struct i915_vma_resource *vma_res;
56e61e0f51SChris Wilson 	struct i915_capture_list *next;
57e61e0f51SChris Wilson };
58e61e0f51SChris Wilson 
59ff20afc4SThomas Hellström void i915_request_free_capture_list(struct i915_capture_list *capture);
60ff20afc4SThomas Hellström #else
61ff20afc4SThomas Hellström #define i915_request_free_capture_list(_a) do {} while (0)
62ff20afc4SThomas Hellström #endif
63ff20afc4SThomas Hellström 
64639f2f24SVenkata Sandeep Dhanalakota #define RQ_TRACE(rq, fmt, ...) do {					\
65639f2f24SVenkata Sandeep Dhanalakota 	const struct i915_request *rq__ = (rq);				\
66639f2f24SVenkata Sandeep Dhanalakota 	ENGINE_TRACE(rq__->engine, "fence %llx:%lld, current %d " fmt,	\
67639f2f24SVenkata Sandeep Dhanalakota 		     rq__->fence.context, rq__->fence.seqno,		\
68639f2f24SVenkata Sandeep Dhanalakota 		     hwsp_seqno(rq__), ##__VA_ARGS__);			\
69639f2f24SVenkata Sandeep Dhanalakota } while (0)
70639f2f24SVenkata Sandeep Dhanalakota 
7152c0fdb2SChris Wilson enum {
7252c0fdb2SChris Wilson 	/*
7352c0fdb2SChris Wilson 	 * I915_FENCE_FLAG_ACTIVE - this request is currently submitted to HW.
7452c0fdb2SChris Wilson 	 *
7552c0fdb2SChris Wilson 	 * Set by __i915_request_submit() on handing over to HW, and cleared
7652c0fdb2SChris Wilson 	 * by __i915_request_unsubmit() if we preempt this request.
7752c0fdb2SChris Wilson 	 *
7852c0fdb2SChris Wilson 	 * Finally cleared for consistency on retiring the request, when
7952c0fdb2SChris Wilson 	 * we know the HW is no longer running this request.
8052c0fdb2SChris Wilson 	 *
8152c0fdb2SChris Wilson 	 * See i915_request_is_active()
8252c0fdb2SChris Wilson 	 */
8352c0fdb2SChris Wilson 	I915_FENCE_FLAG_ACTIVE = DMA_FENCE_FLAG_USER_BITS,
8452c0fdb2SChris Wilson 
8552c0fdb2SChris Wilson 	/*
86672c368fSChris Wilson 	 * I915_FENCE_FLAG_PQUEUE - this request is ready for execution
87672c368fSChris Wilson 	 *
88672c368fSChris Wilson 	 * Using the scheduler, when a request is ready for execution it is put
89672c368fSChris Wilson 	 * into the priority queue, and removed from that queue when transferred
90672c368fSChris Wilson 	 * to the HW runlists. We want to track its membership within the
91672c368fSChris Wilson 	 * priority queue so that we can easily check before rescheduling.
92672c368fSChris Wilson 	 *
93672c368fSChris Wilson 	 * See i915_request_in_priority_queue()
94672c368fSChris Wilson 	 */
95672c368fSChris Wilson 	I915_FENCE_FLAG_PQUEUE,
96672c368fSChris Wilson 
97672c368fSChris Wilson 	/*
98795d4d7fSChris Wilson 	 * I915_FENCE_FLAG_HOLD - this request is currently on hold
99795d4d7fSChris Wilson 	 *
100795d4d7fSChris Wilson 	 * This request has been suspended, pending an ongoing investigation.
101795d4d7fSChris Wilson 	 */
102795d4d7fSChris Wilson 	I915_FENCE_FLAG_HOLD,
103795d4d7fSChris Wilson 
104795d4d7fSChris Wilson 	/*
105795d4d7fSChris Wilson 	 * I915_FENCE_FLAG_INITIAL_BREADCRUMB - this request has the initial
106795d4d7fSChris Wilson 	 * breadcrumb that marks the end of semaphore waits and start of the
107795d4d7fSChris Wilson 	 * user payload.
108795d4d7fSChris Wilson 	 */
109795d4d7fSChris Wilson 	I915_FENCE_FLAG_INITIAL_BREADCRUMB,
110795d4d7fSChris Wilson 
111795d4d7fSChris Wilson 	/*
11252c0fdb2SChris Wilson 	 * I915_FENCE_FLAG_SIGNAL - this request is currently on signal_list
11352c0fdb2SChris Wilson 	 *
11452c0fdb2SChris Wilson 	 * Internal bookkeeping used by the breadcrumb code to track when
11552c0fdb2SChris Wilson 	 * a request is on the various signal_list.
11652c0fdb2SChris Wilson 	 */
11752c0fdb2SChris Wilson 	I915_FENCE_FLAG_SIGNAL,
118e1c31fb5SChris Wilson 
119e1c31fb5SChris Wilson 	/*
120e1c31fb5SChris Wilson 	 * I915_FENCE_FLAG_NOPREEMPT - this request should not be preempted
121e1c31fb5SChris Wilson 	 *
122e1c31fb5SChris Wilson 	 * The execution of some requests should not be interrupted. This is
123e1c31fb5SChris Wilson 	 * a sensitive operation as it makes the request super important,
124e1c31fb5SChris Wilson 	 * blocking other higher priority work. Abuse of this flag will
125e1c31fb5SChris Wilson 	 * lead to quality of service issues.
126e1c31fb5SChris Wilson 	 */
127e1c31fb5SChris Wilson 	I915_FENCE_FLAG_NOPREEMPT,
128e1c31fb5SChris Wilson 
129e1c31fb5SChris Wilson 	/*
130e1c31fb5SChris Wilson 	 * I915_FENCE_FLAG_SENTINEL - this request should be last in the queue
131e1c31fb5SChris Wilson 	 *
132e1c31fb5SChris Wilson 	 * A high priority sentinel request may be submitted to clear the
133e1c31fb5SChris Wilson 	 * submission queue. As it will be the only request in-flight, upon
134e1c31fb5SChris Wilson 	 * execution all other active requests will have been preempted and
135e1c31fb5SChris Wilson 	 * unsubmitted. This preemptive pulse is used to re-evaluate the
136e1c31fb5SChris Wilson 	 * in-flight requests, particularly in cases where an active context
137e1c31fb5SChris Wilson 	 * is banned and those active requests need to be cancelled.
138e1c31fb5SChris Wilson 	 */
139e1c31fb5SChris Wilson 	I915_FENCE_FLAG_SENTINEL,
140e1c31fb5SChris Wilson 
141e1c31fb5SChris Wilson 	/*
142e1c31fb5SChris Wilson 	 * I915_FENCE_FLAG_BOOST - upclock the gpu for this request
143e1c31fb5SChris Wilson 	 *
144e1c31fb5SChris Wilson 	 * Some requests are more important than others! In particular, a
145e1c31fb5SChris Wilson 	 * request that the user is waiting on is typically required for
146e1c31fb5SChris Wilson 	 * interactive latency, for which we want to minimise by upclocking
147e1c31fb5SChris Wilson 	 * the GPU. Here we track such boost requests on a per-request basis.
148e1c31fb5SChris Wilson 	 */
149e1c31fb5SChris Wilson 	I915_FENCE_FLAG_BOOST,
1506b540bf6SMatthew Brost 
1516b540bf6SMatthew Brost 	/*
1526b540bf6SMatthew Brost 	 * I915_FENCE_FLAG_SUBMIT_PARALLEL - request with a context in a
1536b540bf6SMatthew Brost 	 * parent-child relationship (parallel submission, multi-lrc) should
1546b540bf6SMatthew Brost 	 * trigger a submission to the GuC rather than just moving the context
1556b540bf6SMatthew Brost 	 * tail.
1566b540bf6SMatthew Brost 	 */
1576b540bf6SMatthew Brost 	I915_FENCE_FLAG_SUBMIT_PARALLEL,
158544460c3SMatthew Brost 
159544460c3SMatthew Brost 	/*
160544460c3SMatthew Brost 	 * I915_FENCE_FLAG_SKIP_PARALLEL - request with a context in a
161544460c3SMatthew Brost 	 * parent-child relationship (parallel submission, multi-lrc) that
162544460c3SMatthew Brost 	 * hit an error while generating requests in the execbuf IOCTL.
163544460c3SMatthew Brost 	 * Indicates this request should be skipped as another request in
164544460c3SMatthew Brost 	 * submission / relationship encoutered an error.
165544460c3SMatthew Brost 	 */
166544460c3SMatthew Brost 	I915_FENCE_FLAG_SKIP_PARALLEL,
1677647f009SMatthew Brost 
1687647f009SMatthew Brost 	/*
1697647f009SMatthew Brost 	 * I915_FENCE_FLAG_COMPOSITE - Indicates fence is part of a composite
1707647f009SMatthew Brost 	 * fence (dma_fence_array) and i915 generated for parallel submission.
1717647f009SMatthew Brost 	 */
1727647f009SMatthew Brost 	I915_FENCE_FLAG_COMPOSITE,
17352c0fdb2SChris Wilson };
17452c0fdb2SChris Wilson 
175*d7b7332cSJani Nikula /*
176e61e0f51SChris Wilson  * Request queue structure.
177e61e0f51SChris Wilson  *
178e61e0f51SChris Wilson  * The request queue allows us to note sequence numbers that have been emitted
179e61e0f51SChris Wilson  * and may be associated with active buffers to be retired.
180e61e0f51SChris Wilson  *
181e61e0f51SChris Wilson  * By keeping this list, we can avoid having to do questionable sequence
182e61e0f51SChris Wilson  * number comparisons on buffer last_read|write_seqno. It also allows an
183e61e0f51SChris Wilson  * emission time to be associated with the request for tracking how far ahead
184e61e0f51SChris Wilson  * of the GPU the submission is.
185e61e0f51SChris Wilson  *
186e61e0f51SChris Wilson  * When modifying this structure be very aware that we perform a lockless
187e61e0f51SChris Wilson  * RCU lookup of it that may race against reallocation of the struct
188e61e0f51SChris Wilson  * from the slab freelist. We intentionally do not zero the structure on
189e61e0f51SChris Wilson  * allocation so that the lookup can use the dangling pointers (and is
190e61e0f51SChris Wilson  * cogniscent that those pointers may be wrong). Instead, everything that
191e61e0f51SChris Wilson  * needs to be initialised must be done so explicitly.
192e61e0f51SChris Wilson  *
193e61e0f51SChris Wilson  * The requests are reference counted.
194e61e0f51SChris Wilson  */
195e61e0f51SChris Wilson struct i915_request {
196e61e0f51SChris Wilson 	struct dma_fence fence;
197e61e0f51SChris Wilson 	spinlock_t lock;
198e61e0f51SChris Wilson 
1997307e91bSNiranjana Vishwanathapura 	struct drm_i915_private *i915;
2007307e91bSNiranjana Vishwanathapura 
201*d7b7332cSJani Nikula 	/*
202e61e0f51SChris Wilson 	 * Context and ring buffer related to this request
203e61e0f51SChris Wilson 	 * Contexts are refcounted, so when this request is associated with a
204e61e0f51SChris Wilson 	 * context, we must increment the context's refcount, to guarantee that
205e61e0f51SChris Wilson 	 * it persists while any request is linked to it. Requests themselves
206e61e0f51SChris Wilson 	 * are also refcounted, so the request will only be freed when the last
207e61e0f51SChris Wilson 	 * reference to it is dismissed, and the code in
208e61e0f51SChris Wilson 	 * i915_request_free() will then decrement the refcount on the
209e61e0f51SChris Wilson 	 * context.
210e61e0f51SChris Wilson 	 */
211e61e0f51SChris Wilson 	struct intel_engine_cs *engine;
2129f3ccd40SChris Wilson 	struct intel_context *context;
213e61e0f51SChris Wilson 	struct intel_ring *ring;
214d19d71fcSChris Wilson 	struct intel_timeline __rcu *timeline;
2156cfe66ebSChris Wilson 
21652c0fdb2SChris Wilson 	struct list_head signal_link;
2176cfe66ebSChris Wilson 	struct llist_node signal_node;
218e61e0f51SChris Wilson 
219e61e0f51SChris Wilson 	/*
22011abf0c5SChris Wilson 	 * The rcu epoch of when this request was allocated. Used to judiciously
22111abf0c5SChris Wilson 	 * apply backpressure on future allocations to ensure that under
22211abf0c5SChris Wilson 	 * mempressure there is sufficient RCU ticks for us to reclaim our
22311abf0c5SChris Wilson 	 * RCU protected slabs.
22411abf0c5SChris Wilson 	 */
22511abf0c5SChris Wilson 	unsigned long rcustate;
22611abf0c5SChris Wilson 
22711abf0c5SChris Wilson 	/*
228b66ea2c2SChris Wilson 	 * We pin the timeline->mutex while constructing the request to
229b66ea2c2SChris Wilson 	 * ensure that no caller accidentally drops it during construction.
230b66ea2c2SChris Wilson 	 * The timeline->mutex must be held to ensure that only this caller
231b66ea2c2SChris Wilson 	 * can use the ring and manipulate the associated timeline during
232b66ea2c2SChris Wilson 	 * construction.
233b66ea2c2SChris Wilson 	 */
234b66ea2c2SChris Wilson 	struct pin_cookie cookie;
235b66ea2c2SChris Wilson 
236b66ea2c2SChris Wilson 	/*
237e61e0f51SChris Wilson 	 * Fences for the various phases in the request's lifetime.
238e61e0f51SChris Wilson 	 *
239e61e0f51SChris Wilson 	 * The submit fence is used to await upon all of the request's
240e61e0f51SChris Wilson 	 * dependencies. When it is signaled, the request is ready to run.
241e61e0f51SChris Wilson 	 * It is used by the driver to then queue the request for execution.
242e61e0f51SChris Wilson 	 */
243e61e0f51SChris Wilson 	struct i915_sw_fence submit;
244ea593dbbSChris Wilson 	union {
245e61e0f51SChris Wilson 		wait_queue_entry_t submitq;
246ea593dbbSChris Wilson 		struct i915_sw_dma_fence_cb dmaq;
247b81e4d9bSChris Wilson 		struct i915_request_duration_cb {
248b81e4d9bSChris Wilson 			struct dma_fence_cb cb;
249b81e4d9bSChris Wilson 			ktime_t emitted;
250b81e4d9bSChris Wilson 		} duration;
251ea593dbbSChris Wilson 	};
252fc0e1270SChris Wilson 	struct llist_head execute_cb;
253b7404c7eSChris Wilson 	struct i915_sw_fence semaphore;
254*d7b7332cSJani Nikula 	/*
255*d7b7332cSJani Nikula 	 * complete submit fence from an IRQ if needed for locking hierarchy
256*d7b7332cSJani Nikula 	 * reasons.
257b0d83888SMatthew Brost 	 */
258b0d83888SMatthew Brost 	struct irq_work submit_work;
259e61e0f51SChris Wilson 
260e61e0f51SChris Wilson 	/*
261e61e0f51SChris Wilson 	 * A list of everyone we wait upon, and everyone who waits upon us.
262e61e0f51SChris Wilson 	 * Even though we will not be submitted to the hardware before the
263e61e0f51SChris Wilson 	 * submit fence is signaled (it waits for all external events as well
264e61e0f51SChris Wilson 	 * as our own requests), the scheduler still needs to know the
265e61e0f51SChris Wilson 	 * dependency tree for the lifetime of the request (from execbuf
266e61e0f51SChris Wilson 	 * to retirement), i.e. bidirectional dependency information for the
267e61e0f51SChris Wilson 	 * request not tied to individual fences.
268e61e0f51SChris Wilson 	 */
2690c7112a0SChris Wilson 	struct i915_sched_node sched;
270e61e0f51SChris Wilson 	struct i915_dependency dep;
27178e41dddSChris Wilson 	intel_engine_mask_t execution_mask;
272e61e0f51SChris Wilson 
2733adac468SChris Wilson 	/*
2743adac468SChris Wilson 	 * A convenience pointer to the current breadcrumb value stored in
2753adac468SChris Wilson 	 * the HW status page (or our timeline's local equivalent). The full
2763adac468SChris Wilson 	 * path would be rq->hw_context->ring->timeline->hwsp_seqno.
2773adac468SChris Wilson 	 */
2783adac468SChris Wilson 	const u32 *hwsp_seqno;
2793adac468SChris Wilson 
280*d7b7332cSJani Nikula 	/* Position in the ring of the start of the request */
281e61e0f51SChris Wilson 	u32 head;
282e61e0f51SChris Wilson 
283*d7b7332cSJani Nikula 	/* Position in the ring of the start of the user packets */
284b3ee09a4SChris Wilson 	u32 infix;
285b3ee09a4SChris Wilson 
286*d7b7332cSJani Nikula 	/*
287e61e0f51SChris Wilson 	 * Position in the ring of the start of the postfix.
288e61e0f51SChris Wilson 	 * This is required to calculate the maximum available ring space
289e61e0f51SChris Wilson 	 * without overwriting the postfix.
290e61e0f51SChris Wilson 	 */
291e61e0f51SChris Wilson 	u32 postfix;
292e61e0f51SChris Wilson 
293*d7b7332cSJani Nikula 	/* Position in the ring of the end of the whole request */
294e61e0f51SChris Wilson 	u32 tail;
295e61e0f51SChris Wilson 
296*d7b7332cSJani Nikula 	/* Position in the ring of the end of any workarounds after the tail */
297e61e0f51SChris Wilson 	u32 wa_tail;
298e61e0f51SChris Wilson 
299*d7b7332cSJani Nikula 	/* Preallocate space in the ring for the emitting the request */
300e61e0f51SChris Wilson 	u32 reserved_space;
301e61e0f51SChris Wilson 
302*d7b7332cSJani Nikula 	/* Batch buffer pointer for selftest internal use. */
303ff20afc4SThomas Hellström 	I915_SELFTEST_DECLARE(struct i915_vma *batch);
304ff20afc4SThomas Hellström 
30560dc43d1SThomas Hellström 	struct i915_vma_resource *batch_res;
306ff20afc4SThomas Hellström 
307ff20afc4SThomas Hellström #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
308*d7b7332cSJani Nikula 	/*
309e61e0f51SChris Wilson 	 * Additional buffers requested by userspace to be captured upon
310e61e0f51SChris Wilson 	 * a GPU hang. The vma/obj on this list are protected by their
311e61e0f51SChris Wilson 	 * active reference - all objects on this list must also be
312e61e0f51SChris Wilson 	 * on the active_list (of their final request).
313e61e0f51SChris Wilson 	 */
314e61e0f51SChris Wilson 	struct i915_capture_list *capture_list;
315ff20afc4SThomas Hellström #endif
316e61e0f51SChris Wilson 
317*d7b7332cSJani Nikula 	/* Time at which this request was emitted, in jiffies. */
318e61e0f51SChris Wilson 	unsigned long emitted_jiffies;
319e61e0f51SChris Wilson 
320*d7b7332cSJani Nikula 	/* timeline->request entry for this request */
321e61e0f51SChris Wilson 	struct list_head link;
322e61e0f51SChris Wilson 
323*d7b7332cSJani Nikula 	/* Watchdog support fields. */
3249b4d0598STvrtko Ursulin 	struct i915_request_watchdog {
3259b4d0598STvrtko Ursulin 		struct llist_node link;
3269b4d0598STvrtko Ursulin 		struct hrtimer timer;
3279b4d0598STvrtko Ursulin 	} watchdog;
3289b4d0598STvrtko Ursulin 
329*d7b7332cSJani Nikula 	/*
330*d7b7332cSJani Nikula 	 * Requests may need to be stalled when using GuC submission waiting for
331*d7b7332cSJani Nikula 	 * certain GuC operations to complete. If that is the case, stalled
332*d7b7332cSJani Nikula 	 * requests are added to a per context list of stalled requests. The
333*d7b7332cSJani Nikula 	 * below list_head is the link in that list. Protected by
3344f41ddc7SMatthew Brost 	 * ce->guc_state.lock.
335b208f2d5SMatthew Brost 	 */
336b208f2d5SMatthew Brost 	struct list_head guc_fence_link;
337b208f2d5SMatthew Brost 
338*d7b7332cSJani Nikula 	/*
339*d7b7332cSJani Nikula 	 * Priority level while the request is in flight. Differs
3404f41ddc7SMatthew Brost 	 * from i915 scheduler priority. See comment above
3414f41ddc7SMatthew Brost 	 * I915_SCHEDULER_CAP_STATIC_PRIORITY_MAP for details. Protected by
3424f41ddc7SMatthew Brost 	 * ce->guc_active.lock. Two special values (GUC_PRIO_INIT and
3434f41ddc7SMatthew Brost 	 * GUC_PRIO_FINI) outside the GuC priority range are used to indicate
3444f41ddc7SMatthew Brost 	 * if the priority has not been initialized yet or if no more updates
3454f41ddc7SMatthew Brost 	 * are possible because the request has completed.
346ee242ca7SMatthew Brost 	 */
347ee242ca7SMatthew Brost #define	GUC_PRIO_INIT	0xff
348ee242ca7SMatthew Brost #define	GUC_PRIO_FINI	0xfe
349ee242ca7SMatthew Brost 	u8 guc_prio;
350ee242ca7SMatthew Brost 
351*d7b7332cSJani Nikula 	/*
352*d7b7332cSJani Nikula 	 * wait queue entry used to wait on the HuC load to complete
353e6177ec5SDaniele Ceraolo Spurio 	 */
354e6177ec5SDaniele Ceraolo Spurio 	wait_queue_entry_t hucq;
355e6177ec5SDaniele Ceraolo Spurio 
35632eb6bcfSChris Wilson 	I915_SELFTEST_DECLARE(struct {
35732eb6bcfSChris Wilson 		struct list_head link;
35832eb6bcfSChris Wilson 		unsigned long delay;
35932eb6bcfSChris Wilson 	} mock;)
360e61e0f51SChris Wilson };
361e61e0f51SChris Wilson 
362e61e0f51SChris Wilson #define I915_FENCE_GFP (GFP_KERNEL | __GFP_RETRY_MAYFAIL | __GFP_NOWARN)
363e61e0f51SChris Wilson 
364e61e0f51SChris Wilson extern const struct dma_fence_ops i915_fence_ops;
365e61e0f51SChris Wilson 
dma_fence_is_i915(const struct dma_fence * fence)366e61e0f51SChris Wilson static inline bool dma_fence_is_i915(const struct dma_fence *fence)
367e61e0f51SChris Wilson {
368e61e0f51SChris Wilson 	return fence->ops == &i915_fence_ops;
369e61e0f51SChris Wilson }
370e61e0f51SChris Wilson 
37143acd651SChris Wilson struct kmem_cache *i915_request_slab_cache(void);
37243acd651SChris Wilson 
373e61e0f51SChris Wilson struct i915_request * __must_check
3742ccdf6a1SChris Wilson __i915_request_create(struct intel_context *ce, gfp_t gfp);
3752ccdf6a1SChris Wilson struct i915_request * __must_check
3762ccdf6a1SChris Wilson i915_request_create(struct intel_context *ce);
3772ccdf6a1SChris Wilson 
37836e191f0SChris Wilson void __i915_request_skip(struct i915_request *rq);
37938b237eaSChris Wilson bool i915_request_set_error_once(struct i915_request *rq, int error);
380c10e4a79SChris Wilson struct i915_request *i915_request_mark_eio(struct i915_request *rq);
38136e191f0SChris Wilson 
3822ccdf6a1SChris Wilson struct i915_request *__i915_request_commit(struct i915_request *request);
383a79ca656SChris Wilson void __i915_request_queue(struct i915_request *rq,
384a79ca656SChris Wilson 			  const struct i915_sched_attr *attr);
38516f2941aSChris Wilson void __i915_request_queue_bh(struct i915_request *rq);
3862ccdf6a1SChris Wilson 
38766101975SChris Wilson bool i915_request_retire(struct i915_request *rq);
388e61e0f51SChris Wilson void i915_request_retire_upto(struct i915_request *rq);
389e61e0f51SChris Wilson 
390e61e0f51SChris Wilson static inline struct i915_request *
to_request(struct dma_fence * fence)391e61e0f51SChris Wilson to_request(struct dma_fence *fence)
392e61e0f51SChris Wilson {
393e61e0f51SChris Wilson 	/* We assume that NULL fence/request are interoperable */
394e61e0f51SChris Wilson 	BUILD_BUG_ON(offsetof(struct i915_request, fence) != 0);
395e61e0f51SChris Wilson 	GEM_BUG_ON(fence && !dma_fence_is_i915(fence));
396e61e0f51SChris Wilson 	return container_of(fence, struct i915_request, fence);
397e61e0f51SChris Wilson }
398e61e0f51SChris Wilson 
399e61e0f51SChris Wilson static inline struct i915_request *
i915_request_get(struct i915_request * rq)400e61e0f51SChris Wilson i915_request_get(struct i915_request *rq)
401e61e0f51SChris Wilson {
402e61e0f51SChris Wilson 	return to_request(dma_fence_get(&rq->fence));
403e61e0f51SChris Wilson }
404e61e0f51SChris Wilson 
405e61e0f51SChris Wilson static inline struct i915_request *
i915_request_get_rcu(struct i915_request * rq)406e61e0f51SChris Wilson i915_request_get_rcu(struct i915_request *rq)
407e61e0f51SChris Wilson {
408e61e0f51SChris Wilson 	return to_request(dma_fence_get_rcu(&rq->fence));
409e61e0f51SChris Wilson }
410e61e0f51SChris Wilson 
411e61e0f51SChris Wilson static inline void
i915_request_put(struct i915_request * rq)412e61e0f51SChris Wilson i915_request_put(struct i915_request *rq)
413e61e0f51SChris Wilson {
414e61e0f51SChris Wilson 	dma_fence_put(&rq->fence);
415e61e0f51SChris Wilson }
416e61e0f51SChris Wilson 
417e61e0f51SChris Wilson int i915_request_await_object(struct i915_request *to,
418e61e0f51SChris Wilson 			      struct drm_i915_gem_object *obj,
419e61e0f51SChris Wilson 			      bool write);
420e61e0f51SChris Wilson int i915_request_await_dma_fence(struct i915_request *rq,
421e61e0f51SChris Wilson 				 struct dma_fence *fence);
42211930817SThomas Hellström int i915_request_await_deps(struct i915_request *rq, const struct i915_deps *deps);
423f71e01a7SChris Wilson int i915_request_await_execution(struct i915_request *rq,
4245ac545b8SJason Ekstrand 				 struct dma_fence *fence);
425e61e0f51SChris Wilson 
426697b9a87SChris Wilson void i915_request_add(struct i915_request *rq);
427e61e0f51SChris Wilson 
428c0bb487dSChris Wilson bool __i915_request_submit(struct i915_request *request);
429e61e0f51SChris Wilson void i915_request_submit(struct i915_request *request);
430e61e0f51SChris Wilson 
431e61e0f51SChris Wilson void __i915_request_unsubmit(struct i915_request *request);
432e61e0f51SChris Wilson void i915_request_unsubmit(struct i915_request *request);
433e61e0f51SChris Wilson 
43438b237eaSChris Wilson void i915_request_cancel(struct i915_request *rq, int error);
43538b237eaSChris Wilson 
4367e2e69edSMaarten Lankhorst long i915_request_wait_timeout(struct i915_request *rq,
4377e2e69edSMaarten Lankhorst 			       unsigned int flags,
4387e2e69edSMaarten Lankhorst 			       long timeout)
4397e2e69edSMaarten Lankhorst 	__attribute__((nonnull(1)));
4407e2e69edSMaarten Lankhorst 
441e61e0f51SChris Wilson long i915_request_wait(struct i915_request *rq,
442e61e0f51SChris Wilson 		       unsigned int flags,
443e61e0f51SChris Wilson 		       long timeout)
444e61e0f51SChris Wilson 	__attribute__((nonnull(1)));
445e61e0f51SChris Wilson #define I915_WAIT_INTERRUPTIBLE	BIT(0)
4467e805762SChris Wilson #define I915_WAIT_PRIORITY	BIT(1) /* small priority bump for the request */
4477e805762SChris Wilson #define I915_WAIT_ALL		BIT(2) /* used by i915_gem_object_wait() */
448e61e0f51SChris Wilson 
4491f0e785aSChris Wilson void i915_request_show(struct drm_printer *m,
4501f0e785aSChris Wilson 		       const struct i915_request *rq,
451562675d0SChris Wilson 		       const char *prefix,
452562675d0SChris Wilson 		       int indent);
4531f0e785aSChris Wilson 
i915_request_signaled(const struct i915_request * rq)4540e21834eSChris Wilson static inline bool i915_request_signaled(const struct i915_request *rq)
4550e21834eSChris Wilson {
4565013eb8cSChris Wilson 	/* The request may live longer than its HWSP, so check flags first! */
4570e21834eSChris Wilson 	return test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &rq->fence.flags);
4580e21834eSChris Wilson }
4590e21834eSChris Wilson 
i915_request_is_active(const struct i915_request * rq)46052c0fdb2SChris Wilson static inline bool i915_request_is_active(const struct i915_request *rq)
46152c0fdb2SChris Wilson {
46252c0fdb2SChris Wilson 	return test_bit(I915_FENCE_FLAG_ACTIVE, &rq->fence.flags);
46352c0fdb2SChris Wilson }
46452c0fdb2SChris Wilson 
i915_request_in_priority_queue(const struct i915_request * rq)465672c368fSChris Wilson static inline bool i915_request_in_priority_queue(const struct i915_request *rq)
466672c368fSChris Wilson {
467672c368fSChris Wilson 	return test_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags);
468672c368fSChris Wilson }
469672c368fSChris Wilson 
470795d4d7fSChris Wilson static inline bool
i915_request_has_initial_breadcrumb(const struct i915_request * rq)471795d4d7fSChris Wilson i915_request_has_initial_breadcrumb(const struct i915_request *rq)
472795d4d7fSChris Wilson {
473795d4d7fSChris Wilson 	return test_bit(I915_FENCE_FLAG_INITIAL_BREADCRUMB, &rq->fence.flags);
474795d4d7fSChris Wilson }
475795d4d7fSChris Wilson 
476*d7b7332cSJani Nikula /*
477e61e0f51SChris Wilson  * Returns true if seq1 is later than seq2.
478e61e0f51SChris Wilson  */
i915_seqno_passed(u32 seq1,u32 seq2)479e61e0f51SChris Wilson static inline bool i915_seqno_passed(u32 seq1, u32 seq2)
480e61e0f51SChris Wilson {
481e61e0f51SChris Wilson 	return (s32)(seq1 - seq2) >= 0;
482e61e0f51SChris Wilson }
483e61e0f51SChris Wilson 
__hwsp_seqno(const struct i915_request * rq)4843adac468SChris Wilson static inline u32 __hwsp_seqno(const struct i915_request *rq)
4853adac468SChris Wilson {
48689f077abSChris Wilson 	const u32 *hwsp = READ_ONCE(rq->hwsp_seqno);
48789f077abSChris Wilson 
48889f077abSChris Wilson 	return READ_ONCE(*hwsp);
4893adac468SChris Wilson }
4903adac468SChris Wilson 
4913adac468SChris Wilson /**
4923adac468SChris Wilson  * hwsp_seqno - the current breadcrumb value in the HW status page
4933adac468SChris Wilson  * @rq: the request, to chase the relevant HW status page
4943adac468SChris Wilson  *
4953adac468SChris Wilson  * The emphasis in naming here is that hwsp_seqno() is not a property of the
4963adac468SChris Wilson  * request, but an indication of the current HW state (associated with this
4973adac468SChris Wilson  * request). Its value will change as the GPU executes more requests.
4983adac468SChris Wilson  *
4993adac468SChris Wilson  * Returns the current breadcrumb value in the associated HW status page (or
5003adac468SChris Wilson  * the local timeline's equivalent) for this request. The request itself
5013adac468SChris Wilson  * has the associated breadcrumb value of rq->fence.seqno, when the HW
5023adac468SChris Wilson  * status page has that breadcrumb or later, this request is complete.
5033adac468SChris Wilson  */
hwsp_seqno(const struct i915_request * rq)5043adac468SChris Wilson static inline u32 hwsp_seqno(const struct i915_request *rq)
5053adac468SChris Wilson {
5063adac468SChris Wilson 	u32 seqno;
5073adac468SChris Wilson 
5083adac468SChris Wilson 	rcu_read_lock(); /* the HWSP may be freed at runtime */
5093adac468SChris Wilson 	seqno = __hwsp_seqno(rq);
5103adac468SChris Wilson 	rcu_read_unlock();
5113adac468SChris Wilson 
5123adac468SChris Wilson 	return seqno;
5133adac468SChris Wilson }
5143adac468SChris Wilson 
__i915_request_has_started(const struct i915_request * rq)51552c0fdb2SChris Wilson static inline bool __i915_request_has_started(const struct i915_request *rq)
51652c0fdb2SChris Wilson {
5179bb36cf6SChris Wilson 	return i915_seqno_passed(__hwsp_seqno(rq), rq->fence.seqno - 1);
51852c0fdb2SChris Wilson }
51952c0fdb2SChris Wilson 
52097f06158SChris Wilson /**
52197f06158SChris Wilson  * i915_request_started - check if the request has begun being executed
52297f06158SChris Wilson  * @rq: the request
52397f06158SChris Wilson  *
524e8861964SChris Wilson  * If the timeline is not using initial breadcrumbs, a request is
525e8861964SChris Wilson  * considered started if the previous request on its timeline (i.e.
526e8861964SChris Wilson  * context) has been signaled.
527e8861964SChris Wilson  *
528e8861964SChris Wilson  * If the timeline is using semaphores, it will also be emitting an
529e8861964SChris Wilson  * "initial breadcrumb" after the semaphores are complete and just before
530e8861964SChris Wilson  * it began executing the user payload. A request can therefore be active
531e8861964SChris Wilson  * on the HW and not yet started as it is still busywaiting on its
532e8861964SChris Wilson  * dependencies (via HW semaphores).
533e8861964SChris Wilson  *
534e8861964SChris Wilson  * If the request has started, its dependencies will have been signaled
535e8861964SChris Wilson  * (either by fences or by semaphores) and it will have begun processing
536e8861964SChris Wilson  * the user payload.
537e8861964SChris Wilson  *
538e8861964SChris Wilson  * However, even if a request has started, it may have been preempted and
539e8861964SChris Wilson  * so no longer active, or it may have already completed.
540e8861964SChris Wilson  *
541e8861964SChris Wilson  * See also i915_request_is_active().
542e8861964SChris Wilson  *
543e8861964SChris Wilson  * Returns true if the request has begun executing the user payload, or
544e8861964SChris Wilson  * has completed:
54597f06158SChris Wilson  */
i915_request_started(const struct i915_request * rq)54697f06158SChris Wilson static inline bool i915_request_started(const struct i915_request *rq)
54797f06158SChris Wilson {
5489bb36cf6SChris Wilson 	bool result;
5499bb36cf6SChris Wilson 
5505013eb8cSChris Wilson 	if (i915_request_signaled(rq))
5515013eb8cSChris Wilson 		return true;
55297f06158SChris Wilson 
5539bb36cf6SChris Wilson 	result = true;
5549bb36cf6SChris Wilson 	rcu_read_lock(); /* the HWSP may be freed at runtime */
5559bb36cf6SChris Wilson 	if (likely(!i915_request_signaled(rq)))
55685474441SChris Wilson 		/* Remember: started but may have since been preempted! */
5579bb36cf6SChris Wilson 		result = __i915_request_has_started(rq);
5589bb36cf6SChris Wilson 	rcu_read_unlock();
5599bb36cf6SChris Wilson 
5609bb36cf6SChris Wilson 	return result;
56152c0fdb2SChris Wilson }
56252c0fdb2SChris Wilson 
56352c0fdb2SChris Wilson /**
56452c0fdb2SChris Wilson  * i915_request_is_running - check if the request may actually be executing
56552c0fdb2SChris Wilson  * @rq: the request
56652c0fdb2SChris Wilson  *
56752c0fdb2SChris Wilson  * Returns true if the request is currently submitted to hardware, has passed
56852c0fdb2SChris Wilson  * its start point (i.e. the context is setup and not busywaiting). Note that
56952c0fdb2SChris Wilson  * it may no longer be running by the time the function returns!
57052c0fdb2SChris Wilson  */
i915_request_is_running(const struct i915_request * rq)57152c0fdb2SChris Wilson static inline bool i915_request_is_running(const struct i915_request *rq)
57252c0fdb2SChris Wilson {
5739bb36cf6SChris Wilson 	bool result;
5749bb36cf6SChris Wilson 
57552c0fdb2SChris Wilson 	if (!i915_request_is_active(rq))
57652c0fdb2SChris Wilson 		return false;
57752c0fdb2SChris Wilson 
5789bb36cf6SChris Wilson 	rcu_read_lock();
5799bb36cf6SChris Wilson 	result = __i915_request_has_started(rq) && i915_request_is_active(rq);
5809bb36cf6SChris Wilson 	rcu_read_unlock();
5819bb36cf6SChris Wilson 
5829bb36cf6SChris Wilson 	return result;
583e61e0f51SChris Wilson }
584e61e0f51SChris Wilson 
58532ff621fSChris Wilson /**
586f1766e3aSChris Wilson  * i915_request_is_ready - check if the request is ready for execution
58732ff621fSChris Wilson  * @rq: the request
58832ff621fSChris Wilson  *
58932ff621fSChris Wilson  * Upon construction, the request is instructed to wait upon various
59032ff621fSChris Wilson  * signals before it is ready to be executed by the HW. That is, we do
59132ff621fSChris Wilson  * not want to start execution and read data before it is written. In practice,
59232ff621fSChris Wilson  * this is controlled with a mixture of interrupts and semaphores. Once
59332ff621fSChris Wilson  * the submit fence is completed, the backend scheduler will place the
59432ff621fSChris Wilson  * request into its queue and from there submit it for execution. So we
59532ff621fSChris Wilson  * can detect when a request is eligible for execution (and is under control
59632ff621fSChris Wilson  * of the scheduler) by querying where it is in any of the scheduler's lists.
59732ff621fSChris Wilson  *
59832ff621fSChris Wilson  * Returns true if the request is ready for execution (it may be inflight),
59932ff621fSChris Wilson  * false otherwise.
60032ff621fSChris Wilson  */
i915_request_is_ready(const struct i915_request * rq)60132ff621fSChris Wilson static inline bool i915_request_is_ready(const struct i915_request *rq)
60232ff621fSChris Wilson {
60332ff621fSChris Wilson 	return !list_empty(&rq->sched.link);
60432ff621fSChris Wilson }
60532ff621fSChris Wilson 
__i915_request_is_complete(const struct i915_request * rq)6069bb36cf6SChris Wilson static inline bool __i915_request_is_complete(const struct i915_request *rq)
6079bb36cf6SChris Wilson {
6089bb36cf6SChris Wilson 	return i915_seqno_passed(__hwsp_seqno(rq), rq->fence.seqno);
6099bb36cf6SChris Wilson }
6109bb36cf6SChris Wilson 
i915_request_completed(const struct i915_request * rq)611e61e0f51SChris Wilson static inline bool i915_request_completed(const struct i915_request *rq)
612e61e0f51SChris Wilson {
6139bb36cf6SChris Wilson 	bool result;
6149bb36cf6SChris Wilson 
6155013eb8cSChris Wilson 	if (i915_request_signaled(rq))
6165013eb8cSChris Wilson 		return true;
617e61e0f51SChris Wilson 
6189bb36cf6SChris Wilson 	result = true;
6199bb36cf6SChris Wilson 	rcu_read_lock(); /* the HWSP may be freed at runtime */
6209bb36cf6SChris Wilson 	if (likely(!i915_request_signaled(rq)))
6219bb36cf6SChris Wilson 		result = __i915_request_is_complete(rq);
6229bb36cf6SChris Wilson 	rcu_read_unlock();
6239bb36cf6SChris Wilson 
6249bb36cf6SChris Wilson 	return result;
6255013eb8cSChris Wilson }
626e61e0f51SChris Wilson 
i915_request_mark_complete(struct i915_request * rq)6275013eb8cSChris Wilson static inline void i915_request_mark_complete(struct i915_request *rq)
6285013eb8cSChris Wilson {
62989f077abSChris Wilson 	WRITE_ONCE(rq->hwsp_seqno, /* decouple from HWSP */
63089f077abSChris Wilson 		   (u32 *)&rq->fence.seqno);
631e61e0f51SChris Wilson }
632e61e0f51SChris Wilson 
i915_request_has_waitboost(const struct i915_request * rq)6332a98f4e6SLionel Landwerlin static inline bool i915_request_has_waitboost(const struct i915_request *rq)
6342a98f4e6SLionel Landwerlin {
635e1c31fb5SChris Wilson 	return test_bit(I915_FENCE_FLAG_BOOST, &rq->fence.flags);
6362a98f4e6SLionel Landwerlin }
6372a98f4e6SLionel Landwerlin 
i915_request_has_nopreempt(const struct i915_request * rq)6382a98f4e6SLionel Landwerlin static inline bool i915_request_has_nopreempt(const struct i915_request *rq)
6392a98f4e6SLionel Landwerlin {
6402a98f4e6SLionel Landwerlin 	/* Preemption should only be disabled very rarely */
641e1c31fb5SChris Wilson 	return unlikely(test_bit(I915_FENCE_FLAG_NOPREEMPT, &rq->fence.flags));
6422a98f4e6SLionel Landwerlin }
6432a98f4e6SLionel Landwerlin 
i915_request_has_sentinel(const struct i915_request * rq)644c3eb54aaSChris Wilson static inline bool i915_request_has_sentinel(const struct i915_request *rq)
645c3eb54aaSChris Wilson {
646e1c31fb5SChris Wilson 	return unlikely(test_bit(I915_FENCE_FLAG_SENTINEL, &rq->fence.flags));
647c3eb54aaSChris Wilson }
648c3eb54aaSChris Wilson 
i915_request_on_hold(const struct i915_request * rq)64932ff621fSChris Wilson static inline bool i915_request_on_hold(const struct i915_request *rq)
65032ff621fSChris Wilson {
65132ff621fSChris Wilson 	return unlikely(test_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags));
65232ff621fSChris Wilson }
65332ff621fSChris Wilson 
i915_request_set_hold(struct i915_request * rq)65432ff621fSChris Wilson static inline void i915_request_set_hold(struct i915_request *rq)
65532ff621fSChris Wilson {
65632ff621fSChris Wilson 	set_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags);
65732ff621fSChris Wilson }
65832ff621fSChris Wilson 
i915_request_clear_hold(struct i915_request * rq)65932ff621fSChris Wilson static inline void i915_request_clear_hold(struct i915_request *rq)
66032ff621fSChris Wilson {
66132ff621fSChris Wilson 	clear_bit(I915_FENCE_FLAG_HOLD, &rq->fence.flags);
66232ff621fSChris Wilson }
66332ff621fSChris Wilson 
664d19d71fcSChris Wilson static inline struct intel_timeline *
i915_request_timeline(const struct i915_request * rq)665e971fe91SChris Wilson i915_request_timeline(const struct i915_request *rq)
666d19d71fcSChris Wilson {
667d19d71fcSChris Wilson 	/* Valid only while the request is being constructed (or retired). */
668d19d71fcSChris Wilson 	return rcu_dereference_protected(rq->timeline,
669bce45c26SSebastian Andrzej Siewior 					 lockdep_is_held(&rcu_access_pointer(rq->timeline)->mutex) ||
670bce45c26SSebastian Andrzej Siewior 					 test_bit(CONTEXT_IS_PARKING, &rq->context->flags));
671d19d71fcSChris Wilson }
672d19d71fcSChris Wilson 
6736a8679c0SChris Wilson static inline struct i915_gem_context *
i915_request_gem_context(const struct i915_request * rq)674e971fe91SChris Wilson i915_request_gem_context(const struct i915_request *rq)
6756a8679c0SChris Wilson {
6766a8679c0SChris Wilson 	/* Valid only while the request is being constructed (or retired). */
6776a8679c0SChris Wilson 	return rcu_dereference_protected(rq->context->gem_context, true);
6786a8679c0SChris Wilson }
6796a8679c0SChris Wilson 
680d19d71fcSChris Wilson static inline struct intel_timeline *
i915_request_active_timeline(const struct i915_request * rq)681e971fe91SChris Wilson i915_request_active_timeline(const struct i915_request *rq)
682d19d71fcSChris Wilson {
683d19d71fcSChris Wilson 	/*
684d19d71fcSChris Wilson 	 * When in use during submission, we are protected by a guarantee that
685d19d71fcSChris Wilson 	 * the context/timeline is pinned and must remain pinned until after
686d19d71fcSChris Wilson 	 * this submission.
687d19d71fcSChris Wilson 	 */
688d19d71fcSChris Wilson 	return rcu_dereference_protected(rq->timeline,
689349a2bc5SMatthew Brost 					 lockdep_is_held(&rq->engine->sched_engine->lock));
690d19d71fcSChris Wilson }
691d19d71fcSChris Wilson 
69212ca695dSMaarten Lankhorst static inline u32
i915_request_active_seqno(const struct i915_request * rq)69312ca695dSMaarten Lankhorst i915_request_active_seqno(const struct i915_request *rq)
69412ca695dSMaarten Lankhorst {
69512ca695dSMaarten Lankhorst 	u32 hwsp_phys_base =
69612ca695dSMaarten Lankhorst 		page_mask_bits(i915_request_active_timeline(rq)->hwsp_offset);
69712ca695dSMaarten Lankhorst 	u32 hwsp_relative_offset = offset_in_page(rq->hwsp_seqno);
69812ca695dSMaarten Lankhorst 
69912ca695dSMaarten Lankhorst 	/*
70012ca695dSMaarten Lankhorst 	 * Because of wraparound, we cannot simply take tl->hwsp_offset,
70112ca695dSMaarten Lankhorst 	 * but instead use the fact that the relative for vaddr is the
70212ca695dSMaarten Lankhorst 	 * offset as for hwsp_offset. Take the top bits from tl->hwsp_offset
70312ca695dSMaarten Lankhorst 	 * and combine them with the relative offset in rq->hwsp_seqno.
70412ca695dSMaarten Lankhorst 	 *
70512ca695dSMaarten Lankhorst 	 * As rw->hwsp_seqno is rewritten when signaled, this only works
70612ca695dSMaarten Lankhorst 	 * when the request isn't signaled yet, but at that point you
70712ca695dSMaarten Lankhorst 	 * no longer need the offset.
70812ca695dSMaarten Lankhorst 	 */
70912ca695dSMaarten Lankhorst 
71012ca695dSMaarten Lankhorst 	return hwsp_phys_base + hwsp_relative_offset;
71112ca695dSMaarten Lankhorst }
71212ca695dSMaarten Lankhorst 
7137dbc19daSTvrtko Ursulin bool
7147dbc19daSTvrtko Ursulin i915_request_active_engine(struct i915_request *rq,
7157dbc19daSTvrtko Ursulin 			   struct intel_engine_cs **active);
7167dbc19daSTvrtko Ursulin 
717d1cee2d3SMatthew Brost void i915_request_notify_execute_cb_imm(struct i915_request *rq);
718d1cee2d3SMatthew Brost 
719dc0dad36SJohn Harrison enum i915_request_state {
720dc0dad36SJohn Harrison 	I915_REQUEST_UNKNOWN = 0,
721dc0dad36SJohn Harrison 	I915_REQUEST_COMPLETE,
722dc0dad36SJohn Harrison 	I915_REQUEST_PENDING,
723dc0dad36SJohn Harrison 	I915_REQUEST_QUEUED,
724dc0dad36SJohn Harrison 	I915_REQUEST_ACTIVE,
725dc0dad36SJohn Harrison };
726dc0dad36SJohn Harrison 
727dc0dad36SJohn Harrison enum i915_request_state i915_test_request_state(struct i915_request *rq);
728dc0dad36SJohn Harrison 
72947514ac7SDaniel Vetter void i915_request_module_exit(void);
73047514ac7SDaniel Vetter int i915_request_module_init(void);
73147514ac7SDaniel Vetter 
732e61e0f51SChris Wilson #endif /* I915_REQUEST_H */
733