1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#ifndef __I915_GEM_CONTEXT_H__
26#define __I915_GEM_CONTEXT_H__
27
28#include <linux/bitops.h>
29#include <linux/list.h>
30#include <linux/radix-tree.h>
31
32struct pid;
33
34struct drm_device;
35struct drm_file;
36
37struct drm_i915_private;
38struct drm_i915_file_private;
39struct i915_hw_ppgtt;
40struct i915_vma;
41struct intel_ring;
42
43#define DEFAULT_CONTEXT_HANDLE 0
44
45
46
47
48
49
50
51struct i915_gem_context {
52
53 struct drm_i915_private *i915;
54
55
56 struct drm_i915_file_private *file_priv;
57
58
59
60
61
62
63
64
65
66
67 struct i915_hw_ppgtt *ppgtt;
68
69
70
71
72
73
74
75
76
77 struct pid *pid;
78
79
80
81
82
83
84
85
86 const char *name;
87
88
89 struct list_head link;
90 struct llist_node free_link;
91
92
93
94
95
96
97
98
99
100
101 struct kref ref;
102
103
104
105
106 struct rcu_head rcu;
107
108
109
110
111 unsigned long flags;
112#define CONTEXT_NO_ZEROMAP BIT(0)
113#define CONTEXT_NO_ERROR_CAPTURE 1
114#define CONTEXT_CLOSED 2
115#define CONTEXT_BANNABLE 3
116#define CONTEXT_BANNED 4
117#define CONTEXT_FORCE_SINGLE_SUBMISSION 5
118
119
120
121
122
123
124
125
126
127 unsigned int hw_id;
128
129
130
131
132
133
134
135 u32 user_handle;
136
137
138
139
140
141
142
143
144
145
146
147
148 int priority;
149
150
151 u32 ggtt_offset_bias;
152
153
154 struct intel_context {
155 struct i915_vma *state;
156 struct intel_ring *ring;
157 u32 *lrc_reg_state;
158 u64 lrc_desc;
159 int pin_count;
160 bool initialised;
161 } engine[I915_NUM_ENGINES];
162
163
164 u32 ring_size;
165
166 u32 desc_template;
167
168
169 atomic_t guilty_count;
170
171
172
173
174 atomic_t active_count;
175
176#define CONTEXT_SCORE_GUILTY 10
177#define CONTEXT_SCORE_BAN_THRESHOLD 40
178
179 atomic_t ban_score;
180
181
182 u8 remap_slice;
183
184
185
186
187
188 struct radix_tree_root handles_vma;
189
190
191
192
193
194 struct list_head handles_list;
195};
196
197static inline bool i915_gem_context_is_closed(const struct i915_gem_context *ctx)
198{
199 return test_bit(CONTEXT_CLOSED, &ctx->flags);
200}
201
202static inline void i915_gem_context_set_closed(struct i915_gem_context *ctx)
203{
204 GEM_BUG_ON(i915_gem_context_is_closed(ctx));
205 __set_bit(CONTEXT_CLOSED, &ctx->flags);
206}
207
208static inline bool i915_gem_context_no_error_capture(const struct i915_gem_context *ctx)
209{
210 return test_bit(CONTEXT_NO_ERROR_CAPTURE, &ctx->flags);
211}
212
213static inline void i915_gem_context_set_no_error_capture(struct i915_gem_context *ctx)
214{
215 __set_bit(CONTEXT_NO_ERROR_CAPTURE, &ctx->flags);
216}
217
218static inline void i915_gem_context_clear_no_error_capture(struct i915_gem_context *ctx)
219{
220 __clear_bit(CONTEXT_NO_ERROR_CAPTURE, &ctx->flags);
221}
222
223static inline bool i915_gem_context_is_bannable(const struct i915_gem_context *ctx)
224{
225 return test_bit(CONTEXT_BANNABLE, &ctx->flags);
226}
227
228static inline void i915_gem_context_set_bannable(struct i915_gem_context *ctx)
229{
230 __set_bit(CONTEXT_BANNABLE, &ctx->flags);
231}
232
233static inline void i915_gem_context_clear_bannable(struct i915_gem_context *ctx)
234{
235 __clear_bit(CONTEXT_BANNABLE, &ctx->flags);
236}
237
238static inline bool i915_gem_context_is_banned(const struct i915_gem_context *ctx)
239{
240 return test_bit(CONTEXT_BANNED, &ctx->flags);
241}
242
243static inline void i915_gem_context_set_banned(struct i915_gem_context *ctx)
244{
245 __set_bit(CONTEXT_BANNED, &ctx->flags);
246}
247
248static inline bool i915_gem_context_force_single_submission(const struct i915_gem_context *ctx)
249{
250 return test_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
251}
252
253static inline void i915_gem_context_set_force_single_submission(struct i915_gem_context *ctx)
254{
255 __set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
256}
257
258static inline bool i915_gem_context_is_default(const struct i915_gem_context *c)
259{
260 return c->user_handle == DEFAULT_CONTEXT_HANDLE;
261}
262
263static inline bool i915_gem_context_is_kernel(struct i915_gem_context *ctx)
264{
265 return !ctx->file_priv;
266}
267
268
269int __must_check i915_gem_contexts_init(struct drm_i915_private *dev_priv);
270void i915_gem_contexts_lost(struct drm_i915_private *dev_priv);
271void i915_gem_contexts_fini(struct drm_i915_private *dev_priv);
272
273int i915_gem_context_open(struct drm_i915_private *i915,
274 struct drm_file *file);
275void i915_gem_context_close(struct drm_file *file);
276
277int i915_switch_context(struct drm_i915_gem_request *req);
278int i915_gem_switch_to_kernel_context(struct drm_i915_private *dev_priv);
279
280void i915_gem_context_release(struct kref *ctx_ref);
281struct i915_gem_context *
282i915_gem_context_create_gvt(struct drm_device *dev);
283
284int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
285 struct drm_file *file);
286int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
287 struct drm_file *file);
288int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
289 struct drm_file *file_priv);
290int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
291 struct drm_file *file_priv);
292int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data,
293 struct drm_file *file);
294
295static inline struct i915_gem_context *
296i915_gem_context_get(struct i915_gem_context *ctx)
297{
298 kref_get(&ctx->ref);
299 return ctx;
300}
301
302static inline void i915_gem_context_put(struct i915_gem_context *ctx)
303{
304 kref_put(&ctx->ref, i915_gem_context_release);
305}
306
307#endif
308