2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
7 #ifndef __INTEL_CONTEXT_H__
8 #define __INTEL_CONTEXT_H__
10 #include <linux/lockdep.h>
12 #include "intel_context_types.h"
13 #include "intel_engine_types.h"
15 struct intel_context *intel_context_alloc(void);
16 void intel_context_free(struct intel_context *ce);
18 void intel_context_init(struct intel_context *ce,
19 struct i915_gem_context *ctx,
20 struct intel_engine_cs *engine);
23 * intel_context_lookup - Find the matching HW context for this (ctx, engine)
24 * @ctx - the parent GEM context
25 * @engine - the target HW engine
27 * May return NULL if the HW context hasn't been instantiated (i.e. unused).
29 struct intel_context *
30 intel_context_lookup(struct i915_gem_context *ctx,
31 struct intel_engine_cs *engine);
34 * intel_context_pin_lock - Stablises the 'pinned' status of the HW context
35 * @ctx - the parent GEM context
36 * @engine - the target HW engine
38 * Acquire a lock on the pinned status of the HW context, such that the context
39 * can neither be bound to the GPU or unbound whilst the lock is held, i.e.
40 * intel_context_is_pinned() remains stable.
42 struct intel_context *
43 intel_context_pin_lock(struct i915_gem_context *ctx,
44 struct intel_engine_cs *engine);
47 intel_context_is_pinned(struct intel_context *ce)
49 return atomic_read(&ce->pin_count);
52 static inline void intel_context_pin_unlock(struct intel_context *ce)
53 __releases(ce->pin_mutex)
55 mutex_unlock(&ce->pin_mutex);
58 struct intel_context *
59 __intel_context_insert(struct i915_gem_context *ctx,
60 struct intel_engine_cs *engine,
61 struct intel_context *ce);
63 __intel_context_remove(struct intel_context *ce);
65 struct intel_context *
66 intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine);
68 static inline void __intel_context_pin(struct intel_context *ce)
70 GEM_BUG_ON(!intel_context_is_pinned(ce));
71 atomic_inc(&ce->pin_count);
74 void intel_context_unpin(struct intel_context *ce);
76 static inline struct intel_context *intel_context_get(struct intel_context *ce)
82 static inline void intel_context_put(struct intel_context *ce)
84 kref_put(&ce->ref, ce->ops->destroy);
87 #endif /* __INTEL_CONTEXT_H__ */