124f90d66SChris Wilson /* SPDX-License-Identifier: MIT */
2112ed2d3SChris Wilson /*
3112ed2d3SChris Wilson  * Copyright © 2019 Intel Corporation
4112ed2d3SChris Wilson  */
5112ed2d3SChris Wilson 
6112ed2d3SChris Wilson #ifndef __INTEL_CONTEXT_H__
7112ed2d3SChris Wilson #define __INTEL_CONTEXT_H__
8112ed2d3SChris Wilson 
99f3ccd40SChris Wilson #include <linux/bitops.h>
10112ed2d3SChris Wilson #include <linux/lockdep.h>
119f3ccd40SChris Wilson #include <linux/types.h>
12112ed2d3SChris Wilson 
1312c255b5SChris Wilson #include "i915_active.h"
141883a0a4STvrtko Ursulin #include "i915_drv.h"
15112ed2d3SChris Wilson #include "intel_context_types.h"
16112ed2d3SChris Wilson #include "intel_engine_types.h"
17aa7b93ebSChris Wilson #include "intel_gt_pm.h"
182871ea85SChris Wilson #include "intel_ring_types.h"
19e5dadff4SChris Wilson #include "intel_timeline_types.h"
20ae8ac10dSMatthew Brost #include "i915_trace.h"
21112ed2d3SChris Wilson 
22639f2f24SVenkata Sandeep Dhanalakota #define CE_TRACE(ce, fmt, ...) do {					\
23639f2f24SVenkata Sandeep Dhanalakota 	const struct intel_context *ce__ = (ce);			\
24639f2f24SVenkata Sandeep Dhanalakota 	ENGINE_TRACE(ce__->engine, "context:%llx " fmt,			\
25639f2f24SVenkata Sandeep Dhanalakota 		     ce__->timeline->fence_context,			\
26639f2f24SVenkata Sandeep Dhanalakota 		     ##__VA_ARGS__);					\
27639f2f24SVenkata Sandeep Dhanalakota } while (0)
28639f2f24SVenkata Sandeep Dhanalakota 
2945c64ecfSTvrtko Ursulin #define INTEL_CONTEXT_BANNED_PREEMPT_TIMEOUT_MS (1)
3045c64ecfSTvrtko Ursulin 
3147b08693SMaarten Lankhorst struct i915_gem_ww_ctx;
3247b08693SMaarten Lankhorst 
33112ed2d3SChris Wilson void intel_context_init(struct intel_context *ce,
34112ed2d3SChris Wilson 			struct intel_engine_cs *engine);
35df8cf31eSChris Wilson void intel_context_fini(struct intel_context *ce);
36112ed2d3SChris Wilson 
372dcec7d3SDaniel Vetter void i915_context_module_exit(void);
382dcec7d3SDaniel Vetter int i915_context_module_init(void);
392dcec7d3SDaniel Vetter 
40112ed2d3SChris Wilson struct intel_context *
41e6ba7648SChris Wilson intel_context_create(struct intel_engine_cs *engine);
42112ed2d3SChris Wilson 
4389f98d63SChris Wilson int intel_context_alloc_state(struct intel_context *ce);
4489f98d63SChris Wilson 
455e2a0419SChris Wilson void intel_context_free(struct intel_context *ce);
465e2a0419SChris Wilson 
47b4d3acaaSChris Wilson int intel_context_reconfigure_sseu(struct intel_context *ce,
48b4d3acaaSChris Wilson 				   const struct intel_sseu sseu);
49b4d3acaaSChris Wilson 
50c2aa552fSMatthew Brost #define PARENT_SCRATCH_SIZE	PAGE_SIZE
51c2aa552fSMatthew Brost 
intel_context_is_child(struct intel_context * ce)523897df4cSMatthew Brost static inline bool intel_context_is_child(struct intel_context *ce)
533897df4cSMatthew Brost {
543897df4cSMatthew Brost 	return !!ce->parallel.parent;
553897df4cSMatthew Brost }
563897df4cSMatthew Brost 
intel_context_is_parent(struct intel_context * ce)573897df4cSMatthew Brost static inline bool intel_context_is_parent(struct intel_context *ce)
583897df4cSMatthew Brost {
593897df4cSMatthew Brost 	return !!ce->parallel.number_children;
603897df4cSMatthew Brost }
613897df4cSMatthew Brost 
623897df4cSMatthew Brost static inline bool intel_context_is_pinned(struct intel_context *ce);
633897df4cSMatthew Brost 
643897df4cSMatthew Brost static inline struct intel_context *
intel_context_to_parent(struct intel_context * ce)653897df4cSMatthew Brost intel_context_to_parent(struct intel_context *ce)
663897df4cSMatthew Brost {
673897df4cSMatthew Brost 	if (intel_context_is_child(ce)) {
683897df4cSMatthew Brost 		/*
693897df4cSMatthew Brost 		 * The parent holds ref count to the child so it is always safe
703897df4cSMatthew Brost 		 * for the parent to access the child, but the child has a
713897df4cSMatthew Brost 		 * pointer to the parent without a ref. To ensure this is safe
723897df4cSMatthew Brost 		 * the child should only access the parent pointer while the
733897df4cSMatthew Brost 		 * parent is pinned.
743897df4cSMatthew Brost 		 */
753897df4cSMatthew Brost 		GEM_BUG_ON(!intel_context_is_pinned(ce->parallel.parent));
763897df4cSMatthew Brost 
773897df4cSMatthew Brost 		return ce->parallel.parent;
783897df4cSMatthew Brost 	} else {
793897df4cSMatthew Brost 		return ce;
803897df4cSMatthew Brost 	}
813897df4cSMatthew Brost }
823897df4cSMatthew Brost 
intel_context_is_parallel(struct intel_context * ce)83bc955204SMatthew Brost static inline bool intel_context_is_parallel(struct intel_context *ce)
84bc955204SMatthew Brost {
85bc955204SMatthew Brost 	return intel_context_is_child(ce) || intel_context_is_parent(ce);
86bc955204SMatthew Brost }
87bc955204SMatthew Brost 
883897df4cSMatthew Brost void intel_context_bind_parent_child(struct intel_context *parent,
893897df4cSMatthew Brost 				     struct intel_context *child);
903897df4cSMatthew Brost 
913897df4cSMatthew Brost #define for_each_child(parent, ce)\
923897df4cSMatthew Brost 	list_for_each_entry(ce, &(parent)->parallel.child_list,\
933897df4cSMatthew Brost 			    parallel.child_link)
943897df4cSMatthew Brost #define for_each_child_safe(parent, ce, cn)\
953897df4cSMatthew Brost 	list_for_each_entry_safe(ce, cn, &(parent)->parallel.child_list,\
963897df4cSMatthew Brost 				 parallel.child_link)
973897df4cSMatthew Brost 
98112ed2d3SChris Wilson /**
996b736de5SChris Wilson  * intel_context_lock_pinned - Stablises the 'pinned' status of the HW context
100*71ca9b87SJani Nikula  * @ce: the context
101112ed2d3SChris Wilson  *
102112ed2d3SChris Wilson  * Acquire a lock on the pinned status of the HW context, such that the context
103112ed2d3SChris Wilson  * can neither be bound to the GPU or unbound whilst the lock is held, i.e.
104112ed2d3SChris Wilson  * intel_context_is_pinned() remains stable.
105112ed2d3SChris Wilson  */
intel_context_lock_pinned(struct intel_context * ce)1066b736de5SChris Wilson static inline int intel_context_lock_pinned(struct intel_context *ce)
1076b736de5SChris Wilson 	__acquires(ce->pin_mutex)
1086b736de5SChris Wilson {
1096b736de5SChris Wilson 	return mutex_lock_interruptible(&ce->pin_mutex);
1106b736de5SChris Wilson }
111112ed2d3SChris Wilson 
1126b736de5SChris Wilson /**
1136b736de5SChris Wilson  * intel_context_is_pinned - Reports the 'pinned' status
114*71ca9b87SJani Nikula  * @ce: the context
1156b736de5SChris Wilson  *
1166b736de5SChris Wilson  * While in use by the GPU, the context, along with its ring and page
1176b736de5SChris Wilson  * tables is pinned into memory and the GTT.
1186b736de5SChris Wilson  *
1196b736de5SChris Wilson  * Returns: true if the context is currently pinned for use by the GPU.
1206b736de5SChris Wilson  */
121112ed2d3SChris Wilson static inline bool
intel_context_is_pinned(struct intel_context * ce)122112ed2d3SChris Wilson intel_context_is_pinned(struct intel_context *ce)
123112ed2d3SChris Wilson {
124112ed2d3SChris Wilson 	return atomic_read(&ce->pin_count);
125112ed2d3SChris Wilson }
126112ed2d3SChris Wilson 
intel_context_cancel_request(struct intel_context * ce,struct i915_request * rq)12762eaf0aeSMatthew Brost static inline void intel_context_cancel_request(struct intel_context *ce,
12862eaf0aeSMatthew Brost 						struct i915_request *rq)
12962eaf0aeSMatthew Brost {
13062eaf0aeSMatthew Brost 	GEM_BUG_ON(!ce->ops->cancel_request);
13162eaf0aeSMatthew Brost 	return ce->ops->cancel_request(ce, rq);
13262eaf0aeSMatthew Brost }
13362eaf0aeSMatthew Brost 
1346b736de5SChris Wilson /**
1356b736de5SChris Wilson  * intel_context_unlock_pinned - Releases the earlier locking of 'pinned' status
136*71ca9b87SJani Nikula  * @ce: the context
1376b736de5SChris Wilson  *
1386b736de5SChris Wilson  * Releases the lock earlier acquired by intel_context_unlock_pinned().
1396b736de5SChris Wilson  */
intel_context_unlock_pinned(struct intel_context * ce)1406b736de5SChris Wilson static inline void intel_context_unlock_pinned(struct intel_context *ce)
1416b736de5SChris Wilson 	__releases(ce->pin_mutex)
1426b736de5SChris Wilson {
1436b736de5SChris Wilson 	mutex_unlock(&ce->pin_mutex);
1446b736de5SChris Wilson }
145112ed2d3SChris Wilson 
146fa9f6681SChris Wilson int __intel_context_do_pin(struct intel_context *ce);
14747b08693SMaarten Lankhorst int __intel_context_do_pin_ww(struct intel_context *ce,
14847b08693SMaarten Lankhorst 			      struct i915_gem_ww_ctx *ww);
149fa9f6681SChris Wilson 
intel_context_pin_if_active(struct intel_context * ce)150feed5c7bSChris Wilson static inline bool intel_context_pin_if_active(struct intel_context *ce)
151feed5c7bSChris Wilson {
152feed5c7bSChris Wilson 	return atomic_inc_not_zero(&ce->pin_count);
153feed5c7bSChris Wilson }
154feed5c7bSChris Wilson 
intel_context_pin(struct intel_context * ce)155fa9f6681SChris Wilson static inline int intel_context_pin(struct intel_context *ce)
156fa9f6681SChris Wilson {
157feed5c7bSChris Wilson 	if (likely(intel_context_pin_if_active(ce)))
158fa9f6681SChris Wilson 		return 0;
159fa9f6681SChris Wilson 
160fa9f6681SChris Wilson 	return __intel_context_do_pin(ce);
161fa9f6681SChris Wilson }
162112ed2d3SChris Wilson 
intel_context_pin_ww(struct intel_context * ce,struct i915_gem_ww_ctx * ww)16347b08693SMaarten Lankhorst static inline int intel_context_pin_ww(struct intel_context *ce,
16447b08693SMaarten Lankhorst 				       struct i915_gem_ww_ctx *ww)
16547b08693SMaarten Lankhorst {
16647b08693SMaarten Lankhorst 	if (likely(intel_context_pin_if_active(ce)))
16747b08693SMaarten Lankhorst 		return 0;
16847b08693SMaarten Lankhorst 
16947b08693SMaarten Lankhorst 	return __intel_context_do_pin_ww(ce, ww);
17047b08693SMaarten Lankhorst }
17147b08693SMaarten Lankhorst 
__intel_context_pin(struct intel_context * ce)172112ed2d3SChris Wilson static inline void __intel_context_pin(struct intel_context *ce)
173112ed2d3SChris Wilson {
174112ed2d3SChris Wilson 	GEM_BUG_ON(!intel_context_is_pinned(ce));
175112ed2d3SChris Wilson 	atomic_inc(&ce->pin_count);
176112ed2d3SChris Wilson }
177112ed2d3SChris Wilson 
178e0717063SMatthew Brost void __intel_context_do_unpin(struct intel_context *ce, int sub);
179e0717063SMatthew Brost 
intel_context_sched_disable_unpin(struct intel_context * ce)180e0717063SMatthew Brost static inline void intel_context_sched_disable_unpin(struct intel_context *ce)
181e0717063SMatthew Brost {
182e0717063SMatthew Brost 	__intel_context_do_unpin(ce, 2);
183e0717063SMatthew Brost }
184e0717063SMatthew Brost 
intel_context_unpin(struct intel_context * ce)185e0717063SMatthew Brost static inline void intel_context_unpin(struct intel_context *ce)
186e0717063SMatthew Brost {
187e0717063SMatthew Brost 	if (!ce->ops->sched_disable) {
188e0717063SMatthew Brost 		__intel_context_do_unpin(ce, 1);
189e0717063SMatthew Brost 	} else {
190e0717063SMatthew Brost 		/*
191e0717063SMatthew Brost 		 * Move ownership of this pin to the scheduling disable which is
192e0717063SMatthew Brost 		 * an async operation. When that operation completes the above
193e0717063SMatthew Brost 		 * intel_context_sched_disable_unpin is called potentially
194e0717063SMatthew Brost 		 * unpinning the context.
195e0717063SMatthew Brost 		 */
196e0717063SMatthew Brost 		while (!atomic_add_unless(&ce->pin_count, -1, 1)) {
197e0717063SMatthew Brost 			if (atomic_cmpxchg(&ce->pin_count, 1, 2) == 1) {
198e0717063SMatthew Brost 				ce->ops->sched_disable(ce);
199e0717063SMatthew Brost 				break;
200e0717063SMatthew Brost 			}
201e0717063SMatthew Brost 		}
202e0717063SMatthew Brost 	}
203e0717063SMatthew Brost }
204112ed2d3SChris Wilson 
2056eee33e8SChris Wilson void intel_context_enter_engine(struct intel_context *ce);
2066eee33e8SChris Wilson void intel_context_exit_engine(struct intel_context *ce);
2076eee33e8SChris Wilson 
intel_context_enter(struct intel_context * ce)2086eee33e8SChris Wilson static inline void intel_context_enter(struct intel_context *ce)
2096eee33e8SChris Wilson {
2106c69a454SChris Wilson 	lockdep_assert_held(&ce->timeline->mutex);
211aa7b93ebSChris Wilson 	if (ce->active_count++)
212aa7b93ebSChris Wilson 		return;
213aa7b93ebSChris Wilson 
2146eee33e8SChris Wilson 	ce->ops->enter(ce);
215aa7b93ebSChris Wilson 	intel_gt_pm_get(ce->vm->gt);
2166eee33e8SChris Wilson }
2176eee33e8SChris Wilson 
intel_context_mark_active(struct intel_context * ce)2186eee33e8SChris Wilson static inline void intel_context_mark_active(struct intel_context *ce)
2196eee33e8SChris Wilson {
220bce45c26SSebastian Andrzej Siewior 	lockdep_assert(lockdep_is_held(&ce->timeline->mutex) ||
221bce45c26SSebastian Andrzej Siewior 		       test_bit(CONTEXT_IS_PARKING, &ce->flags));
2226eee33e8SChris Wilson 	++ce->active_count;
2236eee33e8SChris Wilson }
2246eee33e8SChris Wilson 
intel_context_exit(struct intel_context * ce)2256eee33e8SChris Wilson static inline void intel_context_exit(struct intel_context *ce)
2266eee33e8SChris Wilson {
2276c69a454SChris Wilson 	lockdep_assert_held(&ce->timeline->mutex);
2286eee33e8SChris Wilson 	GEM_BUG_ON(!ce->active_count);
229aa7b93ebSChris Wilson 	if (--ce->active_count)
230aa7b93ebSChris Wilson 		return;
231aa7b93ebSChris Wilson 
232aa7b93ebSChris Wilson 	intel_gt_pm_put_async(ce->vm->gt);
2336eee33e8SChris Wilson 	ce->ops->exit(ce);
2346eee33e8SChris Wilson }
2356eee33e8SChris Wilson 
intel_context_get(struct intel_context * ce)236112ed2d3SChris Wilson static inline struct intel_context *intel_context_get(struct intel_context *ce)
237112ed2d3SChris Wilson {
238112ed2d3SChris Wilson 	kref_get(&ce->ref);
239112ed2d3SChris Wilson 	return ce;
240112ed2d3SChris Wilson }
241112ed2d3SChris Wilson 
intel_context_put(struct intel_context * ce)242112ed2d3SChris Wilson static inline void intel_context_put(struct intel_context *ce)
243112ed2d3SChris Wilson {
244112ed2d3SChris Wilson 	kref_put(&ce->ref, ce->ops->destroy);
245112ed2d3SChris Wilson }
246112ed2d3SChris Wilson 
247e5dadff4SChris Wilson static inline struct intel_timeline *__must_check
intel_context_timeline_lock(struct intel_context * ce)248f4d57d83SChris Wilson intel_context_timeline_lock(struct intel_context *ce)
24975d0a7f3SChris Wilson 	__acquires(&ce->timeline->mutex)
2502ccdf6a1SChris Wilson {
251e5dadff4SChris Wilson 	struct intel_timeline *tl = ce->timeline;
252e5dadff4SChris Wilson 	int err;
253e5dadff4SChris Wilson 
254544460c3SMatthew Brost 	if (intel_context_is_parent(ce))
255544460c3SMatthew Brost 		err = mutex_lock_interruptible_nested(&tl->mutex, 0);
256544460c3SMatthew Brost 	else if (intel_context_is_child(ce))
257544460c3SMatthew Brost 		err = mutex_lock_interruptible_nested(&tl->mutex,
258544460c3SMatthew Brost 						      ce->parallel.child_index + 1);
259544460c3SMatthew Brost 	else
260e5dadff4SChris Wilson 		err = mutex_lock_interruptible(&tl->mutex);
261e5dadff4SChris Wilson 	if (err)
262e5dadff4SChris Wilson 		return ERR_PTR(err);
263e5dadff4SChris Wilson 
264e5dadff4SChris Wilson 	return tl;
2652ccdf6a1SChris Wilson }
2662ccdf6a1SChris Wilson 
intel_context_timeline_unlock(struct intel_timeline * tl)267e5dadff4SChris Wilson static inline void intel_context_timeline_unlock(struct intel_timeline *tl)
268e5dadff4SChris Wilson 	__releases(&tl->mutex)
2692ccdf6a1SChris Wilson {
270e5dadff4SChris Wilson 	mutex_unlock(&tl->mutex);
2712ccdf6a1SChris Wilson }
2722ccdf6a1SChris Wilson 
273a9877da2SChris Wilson int intel_context_prepare_remote_request(struct intel_context *ce,
274a9877da2SChris Wilson 					 struct i915_request *rq);
275a9877da2SChris Wilson 
2765e2a0419SChris Wilson struct i915_request *intel_context_create_request(struct intel_context *ce);
2775e2a0419SChris Wilson 
2783700e353SJohn Harrison struct i915_request *intel_context_get_active_request(struct intel_context *ce);
279573ba126SMatthew Brost 
intel_context_is_barrier(const struct intel_context * ce)280e6ba7648SChris Wilson static inline bool intel_context_is_barrier(const struct intel_context *ce)
281e6ba7648SChris Wilson {
282e6ba7648SChris Wilson 	return test_bit(CONTEXT_BARRIER_BIT, &ce->flags);
283e6ba7648SChris Wilson }
284e6ba7648SChris Wilson 
intel_context_close(struct intel_context * ce)28583321094SMatthew Brost static inline void intel_context_close(struct intel_context *ce)
28683321094SMatthew Brost {
28783321094SMatthew Brost 	set_bit(CONTEXT_CLOSED_BIT, &ce->flags);
28883321094SMatthew Brost 
28983321094SMatthew Brost 	if (ce->ops->close)
29083321094SMatthew Brost 		ce->ops->close(ce);
29183321094SMatthew Brost }
29283321094SMatthew Brost 
intel_context_is_closed(const struct intel_context * ce)2932e46a2a0SChris Wilson static inline bool intel_context_is_closed(const struct intel_context *ce)
2942e46a2a0SChris Wilson {
2952e46a2a0SChris Wilson 	return test_bit(CONTEXT_CLOSED_BIT, &ce->flags);
2962e46a2a0SChris Wilson }
2972e46a2a0SChris Wilson 
intel_context_has_inflight(const struct intel_context * ce)298cc1557caSChris Wilson static inline bool intel_context_has_inflight(const struct intel_context *ce)
299cc1557caSChris Wilson {
300cc1557caSChris Wilson 	return test_bit(COPS_HAS_INFLIGHT_BIT, &ce->ops->flags);
301cc1557caSChris Wilson }
302cc1557caSChris Wilson 
intel_context_use_semaphores(const struct intel_context * ce)3030f100b70SChris Wilson static inline bool intel_context_use_semaphores(const struct intel_context *ce)
3040f100b70SChris Wilson {
3050f100b70SChris Wilson 	return test_bit(CONTEXT_USE_SEMAPHORES, &ce->flags);
3060f100b70SChris Wilson }
3070f100b70SChris Wilson 
intel_context_set_use_semaphores(struct intel_context * ce)3080f100b70SChris Wilson static inline void intel_context_set_use_semaphores(struct intel_context *ce)
3090f100b70SChris Wilson {
3100f100b70SChris Wilson 	set_bit(CONTEXT_USE_SEMAPHORES, &ce->flags);
3110f100b70SChris Wilson }
3120f100b70SChris Wilson 
intel_context_clear_use_semaphores(struct intel_context * ce)3130f100b70SChris Wilson static inline void intel_context_clear_use_semaphores(struct intel_context *ce)
3140f100b70SChris Wilson {
3150f100b70SChris Wilson 	clear_bit(CONTEXT_USE_SEMAPHORES, &ce->flags);
3160f100b70SChris Wilson }
3170f100b70SChris Wilson 
intel_context_is_banned(const struct intel_context * ce)3189f3ccd40SChris Wilson static inline bool intel_context_is_banned(const struct intel_context *ce)
3199f3ccd40SChris Wilson {
3209f3ccd40SChris Wilson 	return test_bit(CONTEXT_BANNED, &ce->flags);
3219f3ccd40SChris Wilson }
3229f3ccd40SChris Wilson 
intel_context_set_banned(struct intel_context * ce)3239f3ccd40SChris Wilson static inline bool intel_context_set_banned(struct intel_context *ce)
3249f3ccd40SChris Wilson {
3259f3ccd40SChris Wilson 	return test_and_set_bit(CONTEXT_BANNED, &ce->flags);
3269f3ccd40SChris Wilson }
3279f3ccd40SChris Wilson 
32845c64ecfSTvrtko Ursulin bool intel_context_ban(struct intel_context *ce, struct i915_request *rq);
32945c64ecfSTvrtko Ursulin 
intel_context_is_schedulable(const struct intel_context * ce)33045c64ecfSTvrtko Ursulin static inline bool intel_context_is_schedulable(const struct intel_context *ce)
331ae8ac10dSMatthew Brost {
33245c64ecfSTvrtko Ursulin 	return !test_bit(CONTEXT_EXITING, &ce->flags) &&
33345c64ecfSTvrtko Ursulin 	       !test_bit(CONTEXT_BANNED, &ce->flags);
334ae8ac10dSMatthew Brost }
335ae8ac10dSMatthew Brost 
intel_context_is_exiting(const struct intel_context * ce)33645c64ecfSTvrtko Ursulin static inline bool intel_context_is_exiting(const struct intel_context *ce)
33745c64ecfSTvrtko Ursulin {
33845c64ecfSTvrtko Ursulin 	return test_bit(CONTEXT_EXITING, &ce->flags);
33945c64ecfSTvrtko Ursulin }
34045c64ecfSTvrtko Ursulin 
intel_context_set_exiting(struct intel_context * ce)34145c64ecfSTvrtko Ursulin static inline bool intel_context_set_exiting(struct intel_context *ce)
34245c64ecfSTvrtko Ursulin {
34345c64ecfSTvrtko Ursulin 	return test_and_set_bit(CONTEXT_EXITING, &ce->flags);
34445c64ecfSTvrtko Ursulin }
34545c64ecfSTvrtko Ursulin 
3460add082cSTvrtko Ursulin bool intel_context_revoke(struct intel_context *ce);
34745c64ecfSTvrtko Ursulin 
3489f3ccd40SChris Wilson static inline bool
intel_context_force_single_submission(const struct intel_context * ce)3499f3ccd40SChris Wilson intel_context_force_single_submission(const struct intel_context *ce)
3509f3ccd40SChris Wilson {
3519f3ccd40SChris Wilson 	return test_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ce->flags);
3529f3ccd40SChris Wilson }
3539f3ccd40SChris Wilson 
3549f3ccd40SChris Wilson static inline void
intel_context_set_single_submission(struct intel_context * ce)3559f3ccd40SChris Wilson intel_context_set_single_submission(struct intel_context *ce)
3569f3ccd40SChris Wilson {
3579f3ccd40SChris Wilson 	__set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ce->flags);
3589f3ccd40SChris Wilson }
3599f3ccd40SChris Wilson 
3609f3ccd40SChris Wilson static inline bool
intel_context_nopreempt(const struct intel_context * ce)3619f3ccd40SChris Wilson intel_context_nopreempt(const struct intel_context *ce)
3629f3ccd40SChris Wilson {
3639f3ccd40SChris Wilson 	return test_bit(CONTEXT_NOPREEMPT, &ce->flags);
3649f3ccd40SChris Wilson }
3659f3ccd40SChris Wilson 
3669f3ccd40SChris Wilson static inline void
intel_context_set_nopreempt(struct intel_context * ce)3679f3ccd40SChris Wilson intel_context_set_nopreempt(struct intel_context *ce)
3689f3ccd40SChris Wilson {
3699f3ccd40SChris Wilson 	set_bit(CONTEXT_NOPREEMPT, &ce->flags);
3709f3ccd40SChris Wilson }
3719f3ccd40SChris Wilson 
3729f3ccd40SChris Wilson static inline void
intel_context_clear_nopreempt(struct intel_context * ce)3739f3ccd40SChris Wilson intel_context_clear_nopreempt(struct intel_context *ce)
3749f3ccd40SChris Wilson {
3759f3ccd40SChris Wilson 	clear_bit(CONTEXT_NOPREEMPT, &ce->flags);
3769f3ccd40SChris Wilson }
3779f3ccd40SChris Wilson 
3785aa857dbSUmesh Nerlige Ramappa u64 intel_context_get_total_runtime_ns(struct intel_context *ce);
379bb6287cbSTvrtko Ursulin u64 intel_context_get_avg_runtime_ns(struct intel_context *ce);
380bb6287cbSTvrtko Ursulin 
intel_context_clock(void)381bb6287cbSTvrtko Ursulin static inline u64 intel_context_clock(void)
3821883a0a4STvrtko Ursulin {
383bb6287cbSTvrtko Ursulin 	/* As we mix CS cycles with CPU clocks, use the raw monotonic clock. */
384bb6287cbSTvrtko Ursulin 	return ktime_get_raw_fast_ns();
3851883a0a4STvrtko Ursulin }
3861883a0a4STvrtko Ursulin 
387112ed2d3SChris Wilson #endif /* __INTEL_CONTEXT_H__ */
388