]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/i915/intel_context.h
Merge tag 'for-linus' of git://git.armlinux.org.uk/~rmk/linux-arm
[linux.git] / drivers / gpu / drm / i915 / intel_context.h
1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2019 Intel Corporation
5  */
6
7 #ifndef __INTEL_CONTEXT_H__
8 #define __INTEL_CONTEXT_H__
9
10 #include <linux/lockdep.h>
11
12 #include "intel_context_types.h"
13 #include "intel_engine_types.h"
14
15 struct intel_context *intel_context_alloc(void);
16 void intel_context_free(struct intel_context *ce);
17
18 void intel_context_init(struct intel_context *ce,
19                         struct i915_gem_context *ctx,
20                         struct intel_engine_cs *engine);
21
22 /**
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
26  *
27  * May return NULL if the HW context hasn't been instantiated (i.e. unused).
28  */
29 struct intel_context *
30 intel_context_lookup(struct i915_gem_context *ctx,
31                      struct intel_engine_cs *engine);
32
33 /**
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
37  *
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.
41  */
42 struct intel_context *
43 intel_context_pin_lock(struct i915_gem_context *ctx,
44                        struct intel_engine_cs *engine);
45
46 static inline bool
47 intel_context_is_pinned(struct intel_context *ce)
48 {
49         return atomic_read(&ce->pin_count);
50 }
51
52 static inline void intel_context_pin_unlock(struct intel_context *ce)
53 __releases(ce->pin_mutex)
54 {
55         mutex_unlock(&ce->pin_mutex);
56 }
57
58 struct intel_context *
59 __intel_context_insert(struct i915_gem_context *ctx,
60                        struct intel_engine_cs *engine,
61                        struct intel_context *ce);
62 void
63 __intel_context_remove(struct intel_context *ce);
64
65 struct intel_context *
66 intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine);
67
68 static inline void __intel_context_pin(struct intel_context *ce)
69 {
70         GEM_BUG_ON(!intel_context_is_pinned(ce));
71         atomic_inc(&ce->pin_count);
72 }
73
74 void intel_context_unpin(struct intel_context *ce);
75
76 static inline struct intel_context *intel_context_get(struct intel_context *ce)
77 {
78         kref_get(&ce->ref);
79         return ce;
80 }
81
82 static inline void intel_context_put(struct intel_context *ce)
83 {
84         kref_put(&ce->ref, ce->ops->destroy);
85 }
86
87 #endif /* __INTEL_CONTEXT_H__ */