Commit | Line | Data |
---|---|---|
39e2f501 CW |
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 | ||
08819549 CW |
10 | #include <linux/lockdep.h> |
11 | ||
39e2f501 CW |
12 | #include "intel_context_types.h" |
13 | #include "intel_engine_types.h" | |
14 | ||
c4d52feb CW |
15 | struct intel_context *intel_context_alloc(void); |
16 | void intel_context_free(struct intel_context *ce); | |
17 | ||
39e2f501 CW |
18 | void intel_context_init(struct intel_context *ce, |
19 | struct i915_gem_context *ctx, | |
20 | struct intel_engine_cs *engine); | |
21 | ||
c4d52feb CW |
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 | /** | |
08819549 | 34 | * intel_context_pin_lock - Stablises the 'pinned' status of the HW context |
c4d52feb CW |
35 | * @ctx - the parent GEM context |
36 | * @engine - the target HW engine | |
37 | * | |
08819549 CW |
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. | |
c4d52feb CW |
41 | */ |
42 | struct intel_context * | |
08819549 | 43 | intel_context_pin_lock(struct i915_gem_context *ctx, |
c4d52feb CW |
44 | struct intel_engine_cs *engine); |
45 | ||
08819549 CW |
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 | ||
c4d52feb CW |
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); | |
39e2f501 | 64 | |
95f697eb CW |
65 | struct intel_context * |
66 | intel_context_pin(struct i915_gem_context *ctx, struct intel_engine_cs *engine); | |
39e2f501 CW |
67 | |
68 | static inline void __intel_context_pin(struct intel_context *ce) | |
69 | { | |
08819549 CW |
70 | GEM_BUG_ON(!intel_context_is_pinned(ce)); |
71 | atomic_inc(&ce->pin_count); | |
39e2f501 CW |
72 | } |
73 | ||
08819549 | 74 | void intel_context_unpin(struct intel_context *ce); |
39e2f501 | 75 | |
6eee33e8 CW |
76 | void intel_context_enter_engine(struct intel_context *ce); |
77 | void intel_context_exit_engine(struct intel_context *ce); | |
78 | ||
79 | static inline void intel_context_enter(struct intel_context *ce) | |
80 | { | |
81 | if (!ce->active_count++) | |
82 | ce->ops->enter(ce); | |
83 | } | |
84 | ||
85 | static inline void intel_context_mark_active(struct intel_context *ce) | |
86 | { | |
87 | ++ce->active_count; | |
88 | } | |
89 | ||
90 | static inline void intel_context_exit(struct intel_context *ce) | |
91 | { | |
92 | GEM_BUG_ON(!ce->active_count); | |
93 | if (!--ce->active_count) | |
94 | ce->ops->exit(ce); | |
95 | } | |
96 | ||
4c5896dc CW |
97 | static inline struct intel_context *intel_context_get(struct intel_context *ce) |
98 | { | |
99 | kref_get(&ce->ref); | |
100 | return ce; | |
101 | } | |
102 | ||
103 | static inline void intel_context_put(struct intel_context *ce) | |
104 | { | |
105 | kref_put(&ce->ref, ce->ops->destroy); | |
106 | } | |
107 | ||
39e2f501 | 108 | #endif /* __INTEL_CONTEXT_H__ */ |