Commit | Line | Data |
---|---|---|
62fdfeaf EA |
1 | /* |
2 | * Copyright © 2008-2010 Intel Corporation | |
3 | * | |
4 | * Permission is hereby granted, free of charge, to any person obtaining a | |
5 | * copy of this software and associated documentation files (the "Software"), | |
6 | * to deal in the Software without restriction, including without limitation | |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
8 | * and/or sell copies of the Software, and to permit persons to whom the | |
9 | * Software is furnished to do so, subject to the following conditions: | |
10 | * | |
11 | * The above copyright notice and this permission notice (including the next | |
12 | * paragraph) shall be included in all copies or substantial portions of the | |
13 | * Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | |
21 | * IN THE SOFTWARE. | |
22 | * | |
23 | * Authors: | |
24 | * Eric Anholt <eric@anholt.net> | |
25 | * Zou Nan hai <nanhai.zou@intel.com> | |
26 | * Xiang Hai hao<haihao.xiang@intel.com> | |
27 | * | |
28 | */ | |
29 | ||
a4d8a0fe | 30 | #include <linux/log2.h> |
760285e7 | 31 | #include <drm/drmP.h> |
62fdfeaf | 32 | #include "i915_drv.h" |
760285e7 | 33 | #include <drm/i915_drm.h> |
62fdfeaf | 34 | #include "i915_trace.h" |
881f47b6 | 35 | #include "intel_drv.h" |
62fdfeaf | 36 | |
a0442461 CW |
37 | /* Rough estimate of the typical request size, performing a flush, |
38 | * set-context and then emitting the batch. | |
39 | */ | |
40 | #define LEGACY_REQUEST_SIZE 200 | |
41 | ||
82e104cc | 42 | int __intel_ring_space(int head, int tail, int size) |
c7dca47b | 43 | { |
4f54741e DG |
44 | int space = head - tail; |
45 | if (space <= 0) | |
1cf0ba14 | 46 | space += size; |
4f54741e | 47 | return space - I915_RING_FREE_SPACE; |
c7dca47b CW |
48 | } |
49 | ||
ebd0fd4b DG |
50 | void intel_ring_update_space(struct intel_ringbuffer *ringbuf) |
51 | { | |
52 | if (ringbuf->last_retired_head != -1) { | |
53 | ringbuf->head = ringbuf->last_retired_head; | |
54 | ringbuf->last_retired_head = -1; | |
55 | } | |
56 | ||
57 | ringbuf->space = __intel_ring_space(ringbuf->head & HEAD_ADDR, | |
58 | ringbuf->tail, ringbuf->size); | |
59 | } | |
60 | ||
117897f4 | 61 | bool intel_engine_stopped(struct intel_engine_cs *engine) |
09246732 | 62 | { |
0bc40be8 | 63 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
666796da | 64 | return dev_priv->gpu_error.stop_rings & intel_engine_flag(engine); |
88b4aa87 | 65 | } |
09246732 | 66 | |
0bc40be8 | 67 | static void __intel_ring_advance(struct intel_engine_cs *engine) |
88b4aa87 | 68 | { |
0bc40be8 | 69 | struct intel_ringbuffer *ringbuf = engine->buffer; |
93b0a4e0 | 70 | ringbuf->tail &= ringbuf->size - 1; |
117897f4 | 71 | if (intel_engine_stopped(engine)) |
09246732 | 72 | return; |
0bc40be8 | 73 | engine->write_tail(engine, ringbuf->tail); |
09246732 CW |
74 | } |
75 | ||
b72f3acb | 76 | static int |
a84c3ae1 | 77 | gen2_render_ring_flush(struct drm_i915_gem_request *req, |
46f0f8d1 CW |
78 | u32 invalidate_domains, |
79 | u32 flush_domains) | |
80 | { | |
4a570db5 | 81 | struct intel_engine_cs *engine = req->engine; |
46f0f8d1 CW |
82 | u32 cmd; |
83 | int ret; | |
84 | ||
85 | cmd = MI_FLUSH; | |
31b14c9f | 86 | if (((invalidate_domains|flush_domains) & I915_GEM_DOMAIN_RENDER) == 0) |
46f0f8d1 CW |
87 | cmd |= MI_NO_WRITE_FLUSH; |
88 | ||
89 | if (invalidate_domains & I915_GEM_DOMAIN_SAMPLER) | |
90 | cmd |= MI_READ_FLUSH; | |
91 | ||
5fb9de1a | 92 | ret = intel_ring_begin(req, 2); |
46f0f8d1 CW |
93 | if (ret) |
94 | return ret; | |
95 | ||
e2f80391 TU |
96 | intel_ring_emit(engine, cmd); |
97 | intel_ring_emit(engine, MI_NOOP); | |
98 | intel_ring_advance(engine); | |
46f0f8d1 CW |
99 | |
100 | return 0; | |
101 | } | |
102 | ||
103 | static int | |
a84c3ae1 | 104 | gen4_render_ring_flush(struct drm_i915_gem_request *req, |
46f0f8d1 CW |
105 | u32 invalidate_domains, |
106 | u32 flush_domains) | |
62fdfeaf | 107 | { |
4a570db5 | 108 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 109 | struct drm_device *dev = engine->dev; |
6f392d54 | 110 | u32 cmd; |
b72f3acb | 111 | int ret; |
6f392d54 | 112 | |
36d527de CW |
113 | /* |
114 | * read/write caches: | |
115 | * | |
116 | * I915_GEM_DOMAIN_RENDER is always invalidated, but is | |
117 | * only flushed if MI_NO_WRITE_FLUSH is unset. On 965, it is | |
118 | * also flushed at 2d versus 3d pipeline switches. | |
119 | * | |
120 | * read-only caches: | |
121 | * | |
122 | * I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if | |
123 | * MI_READ_FLUSH is set, and is always flushed on 965. | |
124 | * | |
125 | * I915_GEM_DOMAIN_COMMAND may not exist? | |
126 | * | |
127 | * I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is | |
128 | * invalidated when MI_EXE_FLUSH is set. | |
129 | * | |
130 | * I915_GEM_DOMAIN_VERTEX, which exists on 965, is | |
131 | * invalidated with every MI_FLUSH. | |
132 | * | |
133 | * TLBs: | |
134 | * | |
135 | * On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND | |
136 | * and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and | |
137 | * I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER | |
138 | * are flushed at any MI_FLUSH. | |
139 | */ | |
140 | ||
141 | cmd = MI_FLUSH | MI_NO_WRITE_FLUSH; | |
46f0f8d1 | 142 | if ((invalidate_domains|flush_domains) & I915_GEM_DOMAIN_RENDER) |
36d527de | 143 | cmd &= ~MI_NO_WRITE_FLUSH; |
36d527de CW |
144 | if (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION) |
145 | cmd |= MI_EXE_FLUSH; | |
62fdfeaf | 146 | |
36d527de CW |
147 | if (invalidate_domains & I915_GEM_DOMAIN_COMMAND && |
148 | (IS_G4X(dev) || IS_GEN5(dev))) | |
149 | cmd |= MI_INVALIDATE_ISP; | |
70eac33e | 150 | |
5fb9de1a | 151 | ret = intel_ring_begin(req, 2); |
36d527de CW |
152 | if (ret) |
153 | return ret; | |
b72f3acb | 154 | |
e2f80391 TU |
155 | intel_ring_emit(engine, cmd); |
156 | intel_ring_emit(engine, MI_NOOP); | |
157 | intel_ring_advance(engine); | |
b72f3acb CW |
158 | |
159 | return 0; | |
8187a2b7 ZN |
160 | } |
161 | ||
8d315287 JB |
162 | /** |
163 | * Emits a PIPE_CONTROL with a non-zero post-sync operation, for | |
164 | * implementing two workarounds on gen6. From section 1.4.7.1 | |
165 | * "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1: | |
166 | * | |
167 | * [DevSNB-C+{W/A}] Before any depth stall flush (including those | |
168 | * produced by non-pipelined state commands), software needs to first | |
169 | * send a PIPE_CONTROL with no bits set except Post-Sync Operation != | |
170 | * 0. | |
171 | * | |
172 | * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache Flush Enable | |
173 | * =1, a PIPE_CONTROL with any non-zero post-sync-op is required. | |
174 | * | |
175 | * And the workaround for these two requires this workaround first: | |
176 | * | |
177 | * [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent | |
178 | * BEFORE the pipe-control with a post-sync op and no write-cache | |
179 | * flushes. | |
180 | * | |
181 | * And this last workaround is tricky because of the requirements on | |
182 | * that bit. From section 1.4.7.2.3 "Stall" of the Sandy Bridge PRM | |
183 | * volume 2 part 1: | |
184 | * | |
185 | * "1 of the following must also be set: | |
186 | * - Render Target Cache Flush Enable ([12] of DW1) | |
187 | * - Depth Cache Flush Enable ([0] of DW1) | |
188 | * - Stall at Pixel Scoreboard ([1] of DW1) | |
189 | * - Depth Stall ([13] of DW1) | |
190 | * - Post-Sync Operation ([13] of DW1) | |
191 | * - Notify Enable ([8] of DW1)" | |
192 | * | |
193 | * The cache flushes require the workaround flush that triggered this | |
194 | * one, so we can't use it. Depth stall would trigger the same. | |
195 | * Post-sync nonzero is what triggered this second workaround, so we | |
196 | * can't use that one either. Notify enable is IRQs, which aren't | |
197 | * really our business. That leaves only stall at scoreboard. | |
198 | */ | |
199 | static int | |
f2cf1fcc | 200 | intel_emit_post_sync_nonzero_flush(struct drm_i915_gem_request *req) |
8d315287 | 201 | { |
4a570db5 | 202 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 203 | u32 scratch_addr = engine->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
8d315287 JB |
204 | int ret; |
205 | ||
5fb9de1a | 206 | ret = intel_ring_begin(req, 6); |
8d315287 JB |
207 | if (ret) |
208 | return ret; | |
209 | ||
e2f80391 TU |
210 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(5)); |
211 | intel_ring_emit(engine, PIPE_CONTROL_CS_STALL | | |
8d315287 | 212 | PIPE_CONTROL_STALL_AT_SCOREBOARD); |
e2f80391 TU |
213 | intel_ring_emit(engine, scratch_addr | PIPE_CONTROL_GLOBAL_GTT); /* address */ |
214 | intel_ring_emit(engine, 0); /* low dword */ | |
215 | intel_ring_emit(engine, 0); /* high dword */ | |
216 | intel_ring_emit(engine, MI_NOOP); | |
217 | intel_ring_advance(engine); | |
8d315287 | 218 | |
5fb9de1a | 219 | ret = intel_ring_begin(req, 6); |
8d315287 JB |
220 | if (ret) |
221 | return ret; | |
222 | ||
e2f80391 TU |
223 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(5)); |
224 | intel_ring_emit(engine, PIPE_CONTROL_QW_WRITE); | |
225 | intel_ring_emit(engine, scratch_addr | PIPE_CONTROL_GLOBAL_GTT); /* address */ | |
226 | intel_ring_emit(engine, 0); | |
227 | intel_ring_emit(engine, 0); | |
228 | intel_ring_emit(engine, MI_NOOP); | |
229 | intel_ring_advance(engine); | |
8d315287 JB |
230 | |
231 | return 0; | |
232 | } | |
233 | ||
234 | static int | |
a84c3ae1 JH |
235 | gen6_render_ring_flush(struct drm_i915_gem_request *req, |
236 | u32 invalidate_domains, u32 flush_domains) | |
8d315287 | 237 | { |
4a570db5 | 238 | struct intel_engine_cs *engine = req->engine; |
8d315287 | 239 | u32 flags = 0; |
e2f80391 | 240 | u32 scratch_addr = engine->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
8d315287 JB |
241 | int ret; |
242 | ||
b3111509 | 243 | /* Force SNB workarounds for PIPE_CONTROL flushes */ |
f2cf1fcc | 244 | ret = intel_emit_post_sync_nonzero_flush(req); |
b3111509 PZ |
245 | if (ret) |
246 | return ret; | |
247 | ||
8d315287 JB |
248 | /* Just flush everything. Experiments have shown that reducing the |
249 | * number of bits based on the write domains has little performance | |
250 | * impact. | |
251 | */ | |
7d54a904 CW |
252 | if (flush_domains) { |
253 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; | |
254 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; | |
255 | /* | |
256 | * Ensure that any following seqno writes only happen | |
257 | * when the render cache is indeed flushed. | |
258 | */ | |
97f209bc | 259 | flags |= PIPE_CONTROL_CS_STALL; |
7d54a904 CW |
260 | } |
261 | if (invalidate_domains) { | |
262 | flags |= PIPE_CONTROL_TLB_INVALIDATE; | |
263 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; | |
264 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; | |
265 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; | |
266 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; | |
267 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; | |
268 | /* | |
269 | * TLB invalidate requires a post-sync write. | |
270 | */ | |
3ac78313 | 271 | flags |= PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_CS_STALL; |
7d54a904 | 272 | } |
8d315287 | 273 | |
5fb9de1a | 274 | ret = intel_ring_begin(req, 4); |
8d315287 JB |
275 | if (ret) |
276 | return ret; | |
277 | ||
e2f80391 TU |
278 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(4)); |
279 | intel_ring_emit(engine, flags); | |
280 | intel_ring_emit(engine, scratch_addr | PIPE_CONTROL_GLOBAL_GTT); | |
281 | intel_ring_emit(engine, 0); | |
282 | intel_ring_advance(engine); | |
8d315287 JB |
283 | |
284 | return 0; | |
285 | } | |
286 | ||
f3987631 | 287 | static int |
f2cf1fcc | 288 | gen7_render_ring_cs_stall_wa(struct drm_i915_gem_request *req) |
f3987631 | 289 | { |
4a570db5 | 290 | struct intel_engine_cs *engine = req->engine; |
f3987631 PZ |
291 | int ret; |
292 | ||
5fb9de1a | 293 | ret = intel_ring_begin(req, 4); |
f3987631 PZ |
294 | if (ret) |
295 | return ret; | |
296 | ||
e2f80391 TU |
297 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(4)); |
298 | intel_ring_emit(engine, PIPE_CONTROL_CS_STALL | | |
f3987631 | 299 | PIPE_CONTROL_STALL_AT_SCOREBOARD); |
e2f80391 TU |
300 | intel_ring_emit(engine, 0); |
301 | intel_ring_emit(engine, 0); | |
302 | intel_ring_advance(engine); | |
f3987631 PZ |
303 | |
304 | return 0; | |
305 | } | |
306 | ||
4772eaeb | 307 | static int |
a84c3ae1 | 308 | gen7_render_ring_flush(struct drm_i915_gem_request *req, |
4772eaeb PZ |
309 | u32 invalidate_domains, u32 flush_domains) |
310 | { | |
4a570db5 | 311 | struct intel_engine_cs *engine = req->engine; |
4772eaeb | 312 | u32 flags = 0; |
e2f80391 | 313 | u32 scratch_addr = engine->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
4772eaeb PZ |
314 | int ret; |
315 | ||
f3987631 PZ |
316 | /* |
317 | * Ensure that any following seqno writes only happen when the render | |
318 | * cache is indeed flushed. | |
319 | * | |
320 | * Workaround: 4th PIPE_CONTROL command (except the ones with only | |
321 | * read-cache invalidate bits set) must have the CS_STALL bit set. We | |
322 | * don't try to be clever and just set it unconditionally. | |
323 | */ | |
324 | flags |= PIPE_CONTROL_CS_STALL; | |
325 | ||
4772eaeb PZ |
326 | /* Just flush everything. Experiments have shown that reducing the |
327 | * number of bits based on the write domains has little performance | |
328 | * impact. | |
329 | */ | |
330 | if (flush_domains) { | |
331 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; | |
332 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; | |
965fd602 | 333 | flags |= PIPE_CONTROL_DC_FLUSH_ENABLE; |
40a24488 | 334 | flags |= PIPE_CONTROL_FLUSH_ENABLE; |
4772eaeb PZ |
335 | } |
336 | if (invalidate_domains) { | |
337 | flags |= PIPE_CONTROL_TLB_INVALIDATE; | |
338 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; | |
339 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; | |
340 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; | |
341 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; | |
342 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; | |
148b83d0 | 343 | flags |= PIPE_CONTROL_MEDIA_STATE_CLEAR; |
4772eaeb PZ |
344 | /* |
345 | * TLB invalidate requires a post-sync write. | |
346 | */ | |
347 | flags |= PIPE_CONTROL_QW_WRITE; | |
b9e1faa7 | 348 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; |
f3987631 | 349 | |
add284a3 CW |
350 | flags |= PIPE_CONTROL_STALL_AT_SCOREBOARD; |
351 | ||
f3987631 PZ |
352 | /* Workaround: we must issue a pipe_control with CS-stall bit |
353 | * set before a pipe_control command that has the state cache | |
354 | * invalidate bit set. */ | |
f2cf1fcc | 355 | gen7_render_ring_cs_stall_wa(req); |
4772eaeb PZ |
356 | } |
357 | ||
5fb9de1a | 358 | ret = intel_ring_begin(req, 4); |
4772eaeb PZ |
359 | if (ret) |
360 | return ret; | |
361 | ||
e2f80391 TU |
362 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(4)); |
363 | intel_ring_emit(engine, flags); | |
364 | intel_ring_emit(engine, scratch_addr); | |
365 | intel_ring_emit(engine, 0); | |
366 | intel_ring_advance(engine); | |
4772eaeb PZ |
367 | |
368 | return 0; | |
369 | } | |
370 | ||
884ceace | 371 | static int |
f2cf1fcc | 372 | gen8_emit_pipe_control(struct drm_i915_gem_request *req, |
884ceace KG |
373 | u32 flags, u32 scratch_addr) |
374 | { | |
4a570db5 | 375 | struct intel_engine_cs *engine = req->engine; |
884ceace KG |
376 | int ret; |
377 | ||
5fb9de1a | 378 | ret = intel_ring_begin(req, 6); |
884ceace KG |
379 | if (ret) |
380 | return ret; | |
381 | ||
e2f80391 TU |
382 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(6)); |
383 | intel_ring_emit(engine, flags); | |
384 | intel_ring_emit(engine, scratch_addr); | |
385 | intel_ring_emit(engine, 0); | |
386 | intel_ring_emit(engine, 0); | |
387 | intel_ring_emit(engine, 0); | |
388 | intel_ring_advance(engine); | |
884ceace KG |
389 | |
390 | return 0; | |
391 | } | |
392 | ||
a5f3d68e | 393 | static int |
a84c3ae1 | 394 | gen8_render_ring_flush(struct drm_i915_gem_request *req, |
a5f3d68e BW |
395 | u32 invalidate_domains, u32 flush_domains) |
396 | { | |
397 | u32 flags = 0; | |
4a570db5 | 398 | u32 scratch_addr = req->engine->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
02c9f7e3 | 399 | int ret; |
a5f3d68e BW |
400 | |
401 | flags |= PIPE_CONTROL_CS_STALL; | |
402 | ||
403 | if (flush_domains) { | |
404 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; | |
405 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; | |
965fd602 | 406 | flags |= PIPE_CONTROL_DC_FLUSH_ENABLE; |
40a24488 | 407 | flags |= PIPE_CONTROL_FLUSH_ENABLE; |
a5f3d68e BW |
408 | } |
409 | if (invalidate_domains) { | |
410 | flags |= PIPE_CONTROL_TLB_INVALIDATE; | |
411 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; | |
412 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; | |
413 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; | |
414 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; | |
415 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; | |
416 | flags |= PIPE_CONTROL_QW_WRITE; | |
417 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; | |
02c9f7e3 KG |
418 | |
419 | /* WaCsStallBeforeStateCacheInvalidate:bdw,chv */ | |
f2cf1fcc | 420 | ret = gen8_emit_pipe_control(req, |
02c9f7e3 KG |
421 | PIPE_CONTROL_CS_STALL | |
422 | PIPE_CONTROL_STALL_AT_SCOREBOARD, | |
423 | 0); | |
424 | if (ret) | |
425 | return ret; | |
a5f3d68e BW |
426 | } |
427 | ||
f2cf1fcc | 428 | return gen8_emit_pipe_control(req, flags, scratch_addr); |
a5f3d68e BW |
429 | } |
430 | ||
0bc40be8 | 431 | static void ring_write_tail(struct intel_engine_cs *engine, |
297b0c5b | 432 | u32 value) |
d46eefa2 | 433 | { |
0bc40be8 TU |
434 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
435 | I915_WRITE_TAIL(engine, value); | |
d46eefa2 XH |
436 | } |
437 | ||
0bc40be8 | 438 | u64 intel_ring_get_active_head(struct intel_engine_cs *engine) |
8187a2b7 | 439 | { |
0bc40be8 | 440 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
50877445 | 441 | u64 acthd; |
8187a2b7 | 442 | |
0bc40be8 TU |
443 | if (INTEL_INFO(engine->dev)->gen >= 8) |
444 | acthd = I915_READ64_2x32(RING_ACTHD(engine->mmio_base), | |
445 | RING_ACTHD_UDW(engine->mmio_base)); | |
446 | else if (INTEL_INFO(engine->dev)->gen >= 4) | |
447 | acthd = I915_READ(RING_ACTHD(engine->mmio_base)); | |
50877445 CW |
448 | else |
449 | acthd = I915_READ(ACTHD); | |
450 | ||
451 | return acthd; | |
8187a2b7 ZN |
452 | } |
453 | ||
0bc40be8 | 454 | static void ring_setup_phys_status_page(struct intel_engine_cs *engine) |
035dc1e0 | 455 | { |
0bc40be8 | 456 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
035dc1e0 DV |
457 | u32 addr; |
458 | ||
459 | addr = dev_priv->status_page_dmah->busaddr; | |
0bc40be8 | 460 | if (INTEL_INFO(engine->dev)->gen >= 4) |
035dc1e0 DV |
461 | addr |= (dev_priv->status_page_dmah->busaddr >> 28) & 0xf0; |
462 | I915_WRITE(HWS_PGA, addr); | |
463 | } | |
464 | ||
0bc40be8 | 465 | static void intel_ring_setup_status_page(struct intel_engine_cs *engine) |
af75f269 | 466 | { |
0bc40be8 TU |
467 | struct drm_device *dev = engine->dev; |
468 | struct drm_i915_private *dev_priv = engine->dev->dev_private; | |
f0f59a00 | 469 | i915_reg_t mmio; |
af75f269 DL |
470 | |
471 | /* The ring status page addresses are no longer next to the rest of | |
472 | * the ring registers as of gen7. | |
473 | */ | |
474 | if (IS_GEN7(dev)) { | |
0bc40be8 | 475 | switch (engine->id) { |
af75f269 DL |
476 | case RCS: |
477 | mmio = RENDER_HWS_PGA_GEN7; | |
478 | break; | |
479 | case BCS: | |
480 | mmio = BLT_HWS_PGA_GEN7; | |
481 | break; | |
482 | /* | |
483 | * VCS2 actually doesn't exist on Gen7. Only shut up | |
484 | * gcc switch check warning | |
485 | */ | |
486 | case VCS2: | |
487 | case VCS: | |
488 | mmio = BSD_HWS_PGA_GEN7; | |
489 | break; | |
490 | case VECS: | |
491 | mmio = VEBOX_HWS_PGA_GEN7; | |
492 | break; | |
493 | } | |
0bc40be8 TU |
494 | } else if (IS_GEN6(engine->dev)) { |
495 | mmio = RING_HWS_PGA_GEN6(engine->mmio_base); | |
af75f269 DL |
496 | } else { |
497 | /* XXX: gen8 returns to sanity */ | |
0bc40be8 | 498 | mmio = RING_HWS_PGA(engine->mmio_base); |
af75f269 DL |
499 | } |
500 | ||
0bc40be8 | 501 | I915_WRITE(mmio, (u32)engine->status_page.gfx_addr); |
af75f269 DL |
502 | POSTING_READ(mmio); |
503 | ||
504 | /* | |
505 | * Flush the TLB for this page | |
506 | * | |
507 | * FIXME: These two bits have disappeared on gen8, so a question | |
508 | * arises: do we still need this and if so how should we go about | |
509 | * invalidating the TLB? | |
510 | */ | |
511 | if (INTEL_INFO(dev)->gen >= 6 && INTEL_INFO(dev)->gen < 8) { | |
0bc40be8 | 512 | i915_reg_t reg = RING_INSTPM(engine->mmio_base); |
af75f269 DL |
513 | |
514 | /* ring should be idle before issuing a sync flush*/ | |
0bc40be8 | 515 | WARN_ON((I915_READ_MODE(engine) & MODE_IDLE) == 0); |
af75f269 DL |
516 | |
517 | I915_WRITE(reg, | |
518 | _MASKED_BIT_ENABLE(INSTPM_TLB_INVALIDATE | | |
519 | INSTPM_SYNC_FLUSH)); | |
520 | if (wait_for((I915_READ(reg) & INSTPM_SYNC_FLUSH) == 0, | |
521 | 1000)) | |
522 | DRM_ERROR("%s: wait for SyncFlush to complete for TLB invalidation timed out\n", | |
0bc40be8 | 523 | engine->name); |
af75f269 DL |
524 | } |
525 | } | |
526 | ||
0bc40be8 | 527 | static bool stop_ring(struct intel_engine_cs *engine) |
8187a2b7 | 528 | { |
0bc40be8 | 529 | struct drm_i915_private *dev_priv = to_i915(engine->dev); |
8187a2b7 | 530 | |
0bc40be8 TU |
531 | if (!IS_GEN2(engine->dev)) { |
532 | I915_WRITE_MODE(engine, _MASKED_BIT_ENABLE(STOP_RING)); | |
533 | if (wait_for((I915_READ_MODE(engine) & MODE_IDLE) != 0, 1000)) { | |
534 | DRM_ERROR("%s : timed out trying to stop ring\n", | |
535 | engine->name); | |
9bec9b13 CW |
536 | /* Sometimes we observe that the idle flag is not |
537 | * set even though the ring is empty. So double | |
538 | * check before giving up. | |
539 | */ | |
0bc40be8 | 540 | if (I915_READ_HEAD(engine) != I915_READ_TAIL(engine)) |
9bec9b13 | 541 | return false; |
9991ae78 CW |
542 | } |
543 | } | |
b7884eb4 | 544 | |
0bc40be8 TU |
545 | I915_WRITE_CTL(engine, 0); |
546 | I915_WRITE_HEAD(engine, 0); | |
547 | engine->write_tail(engine, 0); | |
8187a2b7 | 548 | |
0bc40be8 TU |
549 | if (!IS_GEN2(engine->dev)) { |
550 | (void)I915_READ_CTL(engine); | |
551 | I915_WRITE_MODE(engine, _MASKED_BIT_DISABLE(STOP_RING)); | |
9991ae78 | 552 | } |
a51435a3 | 553 | |
0bc40be8 | 554 | return (I915_READ_HEAD(engine) & HEAD_ADDR) == 0; |
9991ae78 | 555 | } |
8187a2b7 | 556 | |
fc0768ce TE |
557 | void intel_engine_init_hangcheck(struct intel_engine_cs *engine) |
558 | { | |
559 | memset(&engine->hangcheck, 0, sizeof(engine->hangcheck)); | |
560 | } | |
561 | ||
0bc40be8 | 562 | static int init_ring_common(struct intel_engine_cs *engine) |
9991ae78 | 563 | { |
0bc40be8 | 564 | struct drm_device *dev = engine->dev; |
9991ae78 | 565 | struct drm_i915_private *dev_priv = dev->dev_private; |
0bc40be8 | 566 | struct intel_ringbuffer *ringbuf = engine->buffer; |
93b0a4e0 | 567 | struct drm_i915_gem_object *obj = ringbuf->obj; |
9991ae78 CW |
568 | int ret = 0; |
569 | ||
59bad947 | 570 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
9991ae78 | 571 | |
0bc40be8 | 572 | if (!stop_ring(engine)) { |
9991ae78 | 573 | /* G45 ring initialization often fails to reset head to zero */ |
6fd0d56e CW |
574 | DRM_DEBUG_KMS("%s head not reset to zero " |
575 | "ctl %08x head %08x tail %08x start %08x\n", | |
0bc40be8 TU |
576 | engine->name, |
577 | I915_READ_CTL(engine), | |
578 | I915_READ_HEAD(engine), | |
579 | I915_READ_TAIL(engine), | |
580 | I915_READ_START(engine)); | |
8187a2b7 | 581 | |
0bc40be8 | 582 | if (!stop_ring(engine)) { |
6fd0d56e CW |
583 | DRM_ERROR("failed to set %s head to zero " |
584 | "ctl %08x head %08x tail %08x start %08x\n", | |
0bc40be8 TU |
585 | engine->name, |
586 | I915_READ_CTL(engine), | |
587 | I915_READ_HEAD(engine), | |
588 | I915_READ_TAIL(engine), | |
589 | I915_READ_START(engine)); | |
9991ae78 CW |
590 | ret = -EIO; |
591 | goto out; | |
6fd0d56e | 592 | } |
8187a2b7 ZN |
593 | } |
594 | ||
9991ae78 | 595 | if (I915_NEED_GFX_HWS(dev)) |
0bc40be8 | 596 | intel_ring_setup_status_page(engine); |
9991ae78 | 597 | else |
0bc40be8 | 598 | ring_setup_phys_status_page(engine); |
9991ae78 | 599 | |
ece4a17d | 600 | /* Enforce ordering by reading HEAD register back */ |
0bc40be8 | 601 | I915_READ_HEAD(engine); |
ece4a17d | 602 | |
0d8957c8 DV |
603 | /* Initialize the ring. This must happen _after_ we've cleared the ring |
604 | * registers with the above sequence (the readback of the HEAD registers | |
605 | * also enforces ordering), otherwise the hw might lose the new ring | |
606 | * register values. */ | |
0bc40be8 | 607 | I915_WRITE_START(engine, i915_gem_obj_ggtt_offset(obj)); |
95468892 CW |
608 | |
609 | /* WaClearRingBufHeadRegAtInit:ctg,elk */ | |
0bc40be8 | 610 | if (I915_READ_HEAD(engine)) |
95468892 | 611 | DRM_DEBUG("%s initialization failed [head=%08x], fudging\n", |
0bc40be8 TU |
612 | engine->name, I915_READ_HEAD(engine)); |
613 | I915_WRITE_HEAD(engine, 0); | |
614 | (void)I915_READ_HEAD(engine); | |
95468892 | 615 | |
0bc40be8 | 616 | I915_WRITE_CTL(engine, |
93b0a4e0 | 617 | ((ringbuf->size - PAGE_SIZE) & RING_NR_PAGES) |
5d031e5b | 618 | | RING_VALID); |
8187a2b7 | 619 | |
8187a2b7 | 620 | /* If the head is still not zero, the ring is dead */ |
0bc40be8 TU |
621 | if (wait_for((I915_READ_CTL(engine) & RING_VALID) != 0 && |
622 | I915_READ_START(engine) == i915_gem_obj_ggtt_offset(obj) && | |
623 | (I915_READ_HEAD(engine) & HEAD_ADDR) == 0, 50)) { | |
e74cfed5 | 624 | DRM_ERROR("%s initialization failed " |
48e48a0b | 625 | "ctl %08x (valid? %d) head %08x tail %08x start %08x [expected %08lx]\n", |
0bc40be8 TU |
626 | engine->name, |
627 | I915_READ_CTL(engine), | |
628 | I915_READ_CTL(engine) & RING_VALID, | |
629 | I915_READ_HEAD(engine), I915_READ_TAIL(engine), | |
630 | I915_READ_START(engine), | |
631 | (unsigned long)i915_gem_obj_ggtt_offset(obj)); | |
b7884eb4 DV |
632 | ret = -EIO; |
633 | goto out; | |
8187a2b7 ZN |
634 | } |
635 | ||
ebd0fd4b | 636 | ringbuf->last_retired_head = -1; |
0bc40be8 TU |
637 | ringbuf->head = I915_READ_HEAD(engine); |
638 | ringbuf->tail = I915_READ_TAIL(engine) & TAIL_ADDR; | |
ebd0fd4b | 639 | intel_ring_update_space(ringbuf); |
1ec14ad3 | 640 | |
fc0768ce | 641 | intel_engine_init_hangcheck(engine); |
50f018df | 642 | |
b7884eb4 | 643 | out: |
59bad947 | 644 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b7884eb4 DV |
645 | |
646 | return ret; | |
8187a2b7 ZN |
647 | } |
648 | ||
9b1136d5 | 649 | void |
0bc40be8 | 650 | intel_fini_pipe_control(struct intel_engine_cs *engine) |
9b1136d5 | 651 | { |
0bc40be8 | 652 | struct drm_device *dev = engine->dev; |
9b1136d5 | 653 | |
0bc40be8 | 654 | if (engine->scratch.obj == NULL) |
9b1136d5 OM |
655 | return; |
656 | ||
657 | if (INTEL_INFO(dev)->gen >= 5) { | |
0bc40be8 TU |
658 | kunmap(sg_page(engine->scratch.obj->pages->sgl)); |
659 | i915_gem_object_ggtt_unpin(engine->scratch.obj); | |
9b1136d5 OM |
660 | } |
661 | ||
0bc40be8 TU |
662 | drm_gem_object_unreference(&engine->scratch.obj->base); |
663 | engine->scratch.obj = NULL; | |
9b1136d5 OM |
664 | } |
665 | ||
666 | int | |
0bc40be8 | 667 | intel_init_pipe_control(struct intel_engine_cs *engine) |
c6df541c | 668 | { |
c6df541c CW |
669 | int ret; |
670 | ||
0bc40be8 | 671 | WARN_ON(engine->scratch.obj); |
c6df541c | 672 | |
d37cd8a8 | 673 | engine->scratch.obj = i915_gem_object_create(engine->dev, 4096); |
fe3db79b | 674 | if (IS_ERR(engine->scratch.obj)) { |
c6df541c | 675 | DRM_ERROR("Failed to allocate seqno page\n"); |
fe3db79b CW |
676 | ret = PTR_ERR(engine->scratch.obj); |
677 | engine->scratch.obj = NULL; | |
c6df541c CW |
678 | goto err; |
679 | } | |
e4ffd173 | 680 | |
0bc40be8 TU |
681 | ret = i915_gem_object_set_cache_level(engine->scratch.obj, |
682 | I915_CACHE_LLC); | |
a9cc726c DV |
683 | if (ret) |
684 | goto err_unref; | |
c6df541c | 685 | |
0bc40be8 | 686 | ret = i915_gem_obj_ggtt_pin(engine->scratch.obj, 4096, 0); |
c6df541c CW |
687 | if (ret) |
688 | goto err_unref; | |
689 | ||
0bc40be8 TU |
690 | engine->scratch.gtt_offset = i915_gem_obj_ggtt_offset(engine->scratch.obj); |
691 | engine->scratch.cpu_page = kmap(sg_page(engine->scratch.obj->pages->sgl)); | |
692 | if (engine->scratch.cpu_page == NULL) { | |
56b085a0 | 693 | ret = -ENOMEM; |
c6df541c | 694 | goto err_unpin; |
56b085a0 | 695 | } |
c6df541c | 696 | |
2b1086cc | 697 | DRM_DEBUG_DRIVER("%s pipe control offset: 0x%08x\n", |
0bc40be8 | 698 | engine->name, engine->scratch.gtt_offset); |
c6df541c CW |
699 | return 0; |
700 | ||
701 | err_unpin: | |
0bc40be8 | 702 | i915_gem_object_ggtt_unpin(engine->scratch.obj); |
c6df541c | 703 | err_unref: |
0bc40be8 | 704 | drm_gem_object_unreference(&engine->scratch.obj->base); |
c6df541c | 705 | err: |
c6df541c CW |
706 | return ret; |
707 | } | |
708 | ||
e2be4faf | 709 | static int intel_ring_workarounds_emit(struct drm_i915_gem_request *req) |
86d7f238 | 710 | { |
7225342a | 711 | int ret, i; |
4a570db5 | 712 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 713 | struct drm_device *dev = engine->dev; |
888b5995 | 714 | struct drm_i915_private *dev_priv = dev->dev_private; |
7225342a | 715 | struct i915_workarounds *w = &dev_priv->workarounds; |
888b5995 | 716 | |
02235808 | 717 | if (w->count == 0) |
7225342a | 718 | return 0; |
888b5995 | 719 | |
e2f80391 | 720 | engine->gpu_caches_dirty = true; |
4866d729 | 721 | ret = intel_ring_flush_all_caches(req); |
7225342a MK |
722 | if (ret) |
723 | return ret; | |
888b5995 | 724 | |
5fb9de1a | 725 | ret = intel_ring_begin(req, (w->count * 2 + 2)); |
7225342a MK |
726 | if (ret) |
727 | return ret; | |
728 | ||
e2f80391 | 729 | intel_ring_emit(engine, MI_LOAD_REGISTER_IMM(w->count)); |
7225342a | 730 | for (i = 0; i < w->count; i++) { |
e2f80391 TU |
731 | intel_ring_emit_reg(engine, w->reg[i].addr); |
732 | intel_ring_emit(engine, w->reg[i].value); | |
7225342a | 733 | } |
e2f80391 | 734 | intel_ring_emit(engine, MI_NOOP); |
7225342a | 735 | |
e2f80391 | 736 | intel_ring_advance(engine); |
7225342a | 737 | |
e2f80391 | 738 | engine->gpu_caches_dirty = true; |
4866d729 | 739 | ret = intel_ring_flush_all_caches(req); |
7225342a MK |
740 | if (ret) |
741 | return ret; | |
888b5995 | 742 | |
7225342a | 743 | DRM_DEBUG_DRIVER("Number of Workarounds emitted: %d\n", w->count); |
888b5995 | 744 | |
7225342a | 745 | return 0; |
86d7f238 AS |
746 | } |
747 | ||
8753181e | 748 | static int intel_rcs_ctx_init(struct drm_i915_gem_request *req) |
8f0e2b9d DV |
749 | { |
750 | int ret; | |
751 | ||
e2be4faf | 752 | ret = intel_ring_workarounds_emit(req); |
8f0e2b9d DV |
753 | if (ret != 0) |
754 | return ret; | |
755 | ||
be01363f | 756 | ret = i915_gem_render_state_init(req); |
8f0e2b9d | 757 | if (ret) |
e26e1b97 | 758 | return ret; |
8f0e2b9d | 759 | |
e26e1b97 | 760 | return 0; |
8f0e2b9d DV |
761 | } |
762 | ||
7225342a | 763 | static int wa_add(struct drm_i915_private *dev_priv, |
f0f59a00 VS |
764 | i915_reg_t addr, |
765 | const u32 mask, const u32 val) | |
7225342a MK |
766 | { |
767 | const u32 idx = dev_priv->workarounds.count; | |
768 | ||
769 | if (WARN_ON(idx >= I915_MAX_WA_REGS)) | |
770 | return -ENOSPC; | |
771 | ||
772 | dev_priv->workarounds.reg[idx].addr = addr; | |
773 | dev_priv->workarounds.reg[idx].value = val; | |
774 | dev_priv->workarounds.reg[idx].mask = mask; | |
775 | ||
776 | dev_priv->workarounds.count++; | |
777 | ||
778 | return 0; | |
86d7f238 AS |
779 | } |
780 | ||
ca5a0fbd | 781 | #define WA_REG(addr, mask, val) do { \ |
cf4b0de6 | 782 | const int r = wa_add(dev_priv, (addr), (mask), (val)); \ |
7225342a MK |
783 | if (r) \ |
784 | return r; \ | |
ca5a0fbd | 785 | } while (0) |
7225342a MK |
786 | |
787 | #define WA_SET_BIT_MASKED(addr, mask) \ | |
26459343 | 788 | WA_REG(addr, (mask), _MASKED_BIT_ENABLE(mask)) |
7225342a MK |
789 | |
790 | #define WA_CLR_BIT_MASKED(addr, mask) \ | |
26459343 | 791 | WA_REG(addr, (mask), _MASKED_BIT_DISABLE(mask)) |
7225342a | 792 | |
98533251 | 793 | #define WA_SET_FIELD_MASKED(addr, mask, value) \ |
cf4b0de6 | 794 | WA_REG(addr, mask, _MASKED_FIELD(mask, value)) |
7225342a | 795 | |
cf4b0de6 DL |
796 | #define WA_SET_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) | (mask)) |
797 | #define WA_CLR_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) & ~(mask)) | |
7225342a | 798 | |
cf4b0de6 | 799 | #define WA_WRITE(addr, val) WA_REG(addr, 0xffffffff, val) |
7225342a | 800 | |
0bc40be8 TU |
801 | static int wa_ring_whitelist_reg(struct intel_engine_cs *engine, |
802 | i915_reg_t reg) | |
33136b06 | 803 | { |
0bc40be8 | 804 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
33136b06 | 805 | struct i915_workarounds *wa = &dev_priv->workarounds; |
0bc40be8 | 806 | const uint32_t index = wa->hw_whitelist_count[engine->id]; |
33136b06 AS |
807 | |
808 | if (WARN_ON(index >= RING_MAX_NONPRIV_SLOTS)) | |
809 | return -EINVAL; | |
810 | ||
0bc40be8 | 811 | WA_WRITE(RING_FORCE_TO_NONPRIV(engine->mmio_base, index), |
33136b06 | 812 | i915_mmio_reg_offset(reg)); |
0bc40be8 | 813 | wa->hw_whitelist_count[engine->id]++; |
33136b06 AS |
814 | |
815 | return 0; | |
816 | } | |
817 | ||
0bc40be8 | 818 | static int gen8_init_workarounds(struct intel_engine_cs *engine) |
e9a64ada | 819 | { |
0bc40be8 | 820 | struct drm_device *dev = engine->dev; |
68c6198b AS |
821 | struct drm_i915_private *dev_priv = dev->dev_private; |
822 | ||
823 | WA_SET_BIT_MASKED(INSTPM, INSTPM_FORCE_ORDERING); | |
e9a64ada | 824 | |
717d84d6 AS |
825 | /* WaDisableAsyncFlipPerfMode:bdw,chv */ |
826 | WA_SET_BIT_MASKED(MI_MODE, ASYNC_FLIP_PERF_DISABLE); | |
827 | ||
d0581194 AS |
828 | /* WaDisablePartialInstShootdown:bdw,chv */ |
829 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, | |
830 | PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE); | |
831 | ||
a340af58 AS |
832 | /* Use Force Non-Coherent whenever executing a 3D context. This is a |
833 | * workaround for for a possible hang in the unlikely event a TLB | |
834 | * invalidation occurs during a PSD flush. | |
835 | */ | |
836 | /* WaForceEnableNonCoherent:bdw,chv */ | |
120f5d28 | 837 | /* WaHdcDisableFetchWhenMasked:bdw,chv */ |
a340af58 | 838 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
120f5d28 | 839 | HDC_DONOT_FETCH_MEM_WHEN_MASKED | |
a340af58 AS |
840 | HDC_FORCE_NON_COHERENT); |
841 | ||
6def8fdd AS |
842 | /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0: |
843 | * "The Hierarchical Z RAW Stall Optimization allows non-overlapping | |
844 | * polygons in the same 8x4 pixel/sample area to be processed without | |
845 | * stalling waiting for the earlier ones to write to Hierarchical Z | |
846 | * buffer." | |
847 | * | |
848 | * This optimization is off by default for BDW and CHV; turn it on. | |
849 | */ | |
850 | WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE); | |
851 | ||
48404636 AS |
852 | /* Wa4x4STCOptimizationDisable:bdw,chv */ |
853 | WA_SET_BIT_MASKED(CACHE_MODE_1, GEN8_4x4_STC_OPTIMIZATION_DISABLE); | |
854 | ||
7eebcde6 AS |
855 | /* |
856 | * BSpec recommends 8x4 when MSAA is used, | |
857 | * however in practice 16x4 seems fastest. | |
858 | * | |
859 | * Note that PS/WM thread counts depend on the WIZ hashing | |
860 | * disable bit, which we don't touch here, but it's good | |
861 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). | |
862 | */ | |
863 | WA_SET_FIELD_MASKED(GEN7_GT_MODE, | |
864 | GEN6_WIZ_HASHING_MASK, | |
865 | GEN6_WIZ_HASHING_16x4); | |
866 | ||
e9a64ada AS |
867 | return 0; |
868 | } | |
869 | ||
0bc40be8 | 870 | static int bdw_init_workarounds(struct intel_engine_cs *engine) |
86d7f238 | 871 | { |
e9a64ada | 872 | int ret; |
0bc40be8 | 873 | struct drm_device *dev = engine->dev; |
888b5995 | 874 | struct drm_i915_private *dev_priv = dev->dev_private; |
86d7f238 | 875 | |
0bc40be8 | 876 | ret = gen8_init_workarounds(engine); |
e9a64ada AS |
877 | if (ret) |
878 | return ret; | |
879 | ||
101b376d | 880 | /* WaDisableThreadStallDopClockGating:bdw (pre-production) */ |
d0581194 | 881 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE); |
86d7f238 | 882 | |
101b376d | 883 | /* WaDisableDopClockGating:bdw */ |
7225342a MK |
884 | WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2, |
885 | DOP_CLOCK_GATING_DISABLE); | |
86d7f238 | 886 | |
7225342a MK |
887 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, |
888 | GEN8_SAMPLER_POWER_BYPASS_DIS); | |
86d7f238 | 889 | |
7225342a | 890 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
35cb6f3b DL |
891 | /* WaForceContextSaveRestoreNonCoherent:bdw */ |
892 | HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT | | |
35cb6f3b | 893 | /* WaDisableFenceDestinationToSLM:bdw (pre-prod) */ |
7225342a | 894 | (IS_BDW_GT3(dev) ? HDC_FENCE_DEST_SLM_DISABLE : 0)); |
86d7f238 | 895 | |
86d7f238 AS |
896 | return 0; |
897 | } | |
898 | ||
0bc40be8 | 899 | static int chv_init_workarounds(struct intel_engine_cs *engine) |
00e1e623 | 900 | { |
e9a64ada | 901 | int ret; |
0bc40be8 | 902 | struct drm_device *dev = engine->dev; |
00e1e623 VS |
903 | struct drm_i915_private *dev_priv = dev->dev_private; |
904 | ||
0bc40be8 | 905 | ret = gen8_init_workarounds(engine); |
e9a64ada AS |
906 | if (ret) |
907 | return ret; | |
908 | ||
00e1e623 | 909 | /* WaDisableThreadStallDopClockGating:chv */ |
d0581194 | 910 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE); |
00e1e623 | 911 | |
d60de81d KG |
912 | /* Improve HiZ throughput on CHV. */ |
913 | WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X); | |
914 | ||
7225342a MK |
915 | return 0; |
916 | } | |
917 | ||
0bc40be8 | 918 | static int gen9_init_workarounds(struct intel_engine_cs *engine) |
3b106531 | 919 | { |
0bc40be8 | 920 | struct drm_device *dev = engine->dev; |
ab0dfafe | 921 | struct drm_i915_private *dev_priv = dev->dev_private; |
8ea6f892 | 922 | uint32_t tmp; |
e0f3fa09 | 923 | int ret; |
ab0dfafe | 924 | |
9c4cbf82 MK |
925 | /* WaEnableLbsSlaRetryTimerDecrement:skl */ |
926 | I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) | | |
927 | GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE); | |
928 | ||
929 | /* WaDisableKillLogic:bxt,skl */ | |
930 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | | |
931 | ECOCHK_DIS_TLB); | |
932 | ||
950b2aae | 933 | /* WaClearFlowControlGpgpuContextSave:skl,bxt */ |
b0e6f6d4 | 934 | /* WaDisablePartialInstShootdown:skl,bxt */ |
ab0dfafe | 935 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, |
950b2aae | 936 | FLOW_CONTROL_ENABLE | |
ab0dfafe HN |
937 | PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE); |
938 | ||
a119a6e6 | 939 | /* Syncing dependencies between camera and graphics:skl,bxt */ |
8424171e NH |
940 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, |
941 | GEN9_DISABLE_OCL_OOB_SUPPRESS_LOGIC); | |
942 | ||
e87a005d JN |
943 | /* WaDisableDgMirrorFixInHalfSliceChicken5:skl,bxt */ |
944 | if (IS_SKL_REVID(dev, 0, SKL_REVID_B0) || | |
945 | IS_BXT_REVID(dev, 0, BXT_REVID_A1)) | |
a86eb582 DL |
946 | WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5, |
947 | GEN9_DG_MIRROR_FIX_ENABLE); | |
1de4582f | 948 | |
e87a005d JN |
949 | /* WaSetDisablePixMaskCammingAndRhwoInCommonSliceChicken:skl,bxt */ |
950 | if (IS_SKL_REVID(dev, 0, SKL_REVID_B0) || | |
951 | IS_BXT_REVID(dev, 0, BXT_REVID_A1)) { | |
183c6dac DL |
952 | WA_SET_BIT_MASKED(GEN7_COMMON_SLICE_CHICKEN1, |
953 | GEN9_RHWO_OPTIMIZATION_DISABLE); | |
9b01435d AS |
954 | /* |
955 | * WA also requires GEN9_SLICE_COMMON_ECO_CHICKEN0[14:14] to be set | |
956 | * but we do that in per ctx batchbuffer as there is an issue | |
957 | * with this register not getting restored on ctx restore | |
958 | */ | |
183c6dac DL |
959 | } |
960 | ||
e87a005d | 961 | /* WaEnableYV12BugFixInHalfSliceChicken7:skl,bxt */ |
bfd8ad4e TG |
962 | /* WaEnableSamplerGPGPUPreemptionSupport:skl,bxt */ |
963 | WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7, | |
964 | GEN9_ENABLE_YV12_BUGFIX | | |
965 | GEN9_ENABLE_GPGPU_PREEMPTION); | |
cac23df4 | 966 | |
5068368c | 967 | /* Wa4x4STCOptimizationDisable:skl,bxt */ |
27160c96 | 968 | /* WaDisablePartialResolveInVc:skl,bxt */ |
60294683 AS |
969 | WA_SET_BIT_MASKED(CACHE_MODE_1, (GEN8_4x4_STC_OPTIMIZATION_DISABLE | |
970 | GEN9_PARTIAL_RESOLVE_IN_VC_DISABLE)); | |
9370cd98 | 971 | |
16be17af | 972 | /* WaCcsTlbPrefetchDisable:skl,bxt */ |
e2db7071 DL |
973 | WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5, |
974 | GEN9_CCS_TLB_PREFETCH_ENABLE); | |
975 | ||
5a2ae95e | 976 | /* WaDisableMaskBasedCammingInRCC:skl,bxt */ |
e87a005d JN |
977 | if (IS_SKL_REVID(dev, SKL_REVID_C0, SKL_REVID_C0) || |
978 | IS_BXT_REVID(dev, 0, BXT_REVID_A1)) | |
38a39a7b BW |
979 | WA_SET_BIT_MASKED(SLICE_ECO_CHICKEN0, |
980 | PIXEL_MASK_CAMMING_DISABLE); | |
981 | ||
8ea6f892 ID |
982 | /* WaForceContextSaveRestoreNonCoherent:skl,bxt */ |
983 | tmp = HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT; | |
97ea6be1 | 984 | if (IS_SKL_REVID(dev, SKL_REVID_F0, REVID_FOREVER) || |
e87a005d | 985 | IS_BXT_REVID(dev, BXT_REVID_B0, REVID_FOREVER)) |
8ea6f892 ID |
986 | tmp |= HDC_FORCE_CSR_NON_COHERENT_OVR_DISABLE; |
987 | WA_SET_BIT_MASKED(HDC_CHICKEN0, tmp); | |
988 | ||
8c761609 | 989 | /* WaDisableSamplerPowerBypassForSOPingPong:skl,bxt */ |
e87a005d | 990 | if (IS_SKYLAKE(dev) || IS_BXT_REVID(dev, 0, BXT_REVID_B0)) |
8c761609 AS |
991 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, |
992 | GEN8_SAMPLER_POWER_BYPASS_DIS); | |
8c761609 | 993 | |
6b6d5626 RB |
994 | /* WaDisableSTUnitPowerOptimization:skl,bxt */ |
995 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN2, GEN8_ST_PO_DISABLE); | |
996 | ||
6ecf56ae AS |
997 | /* WaOCLCoherentLineFlush:skl,bxt */ |
998 | I915_WRITE(GEN8_L3SQCREG4, (I915_READ(GEN8_L3SQCREG4) | | |
999 | GEN8_LQSC_FLUSH_COHERENT_LINES)); | |
1000 | ||
e0f3fa09 | 1001 | /* WaEnablePreemptionGranularityControlByUMD:skl,bxt */ |
0bc40be8 | 1002 | ret= wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1); |
e0f3fa09 AS |
1003 | if (ret) |
1004 | return ret; | |
1005 | ||
3669ab61 | 1006 | /* WaAllowUMDToModifyHDCChicken1:skl,bxt */ |
0bc40be8 | 1007 | ret = wa_ring_whitelist_reg(engine, GEN8_HDC_CHICKEN1); |
3669ab61 AS |
1008 | if (ret) |
1009 | return ret; | |
1010 | ||
3b106531 HN |
1011 | return 0; |
1012 | } | |
1013 | ||
0bc40be8 | 1014 | static int skl_tune_iz_hashing(struct intel_engine_cs *engine) |
b7668791 | 1015 | { |
0bc40be8 | 1016 | struct drm_device *dev = engine->dev; |
b7668791 DL |
1017 | struct drm_i915_private *dev_priv = dev->dev_private; |
1018 | u8 vals[3] = { 0, 0, 0 }; | |
1019 | unsigned int i; | |
1020 | ||
1021 | for (i = 0; i < 3; i++) { | |
1022 | u8 ss; | |
1023 | ||
1024 | /* | |
1025 | * Only consider slices where one, and only one, subslice has 7 | |
1026 | * EUs | |
1027 | */ | |
a4d8a0fe | 1028 | if (!is_power_of_2(dev_priv->info.subslice_7eu[i])) |
b7668791 DL |
1029 | continue; |
1030 | ||
1031 | /* | |
1032 | * subslice_7eu[i] != 0 (because of the check above) and | |
1033 | * ss_max == 4 (maximum number of subslices possible per slice) | |
1034 | * | |
1035 | * -> 0 <= ss <= 3; | |
1036 | */ | |
1037 | ss = ffs(dev_priv->info.subslice_7eu[i]) - 1; | |
1038 | vals[i] = 3 - ss; | |
1039 | } | |
1040 | ||
1041 | if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0) | |
1042 | return 0; | |
1043 | ||
1044 | /* Tune IZ hashing. See intel_device_info_runtime_init() */ | |
1045 | WA_SET_FIELD_MASKED(GEN7_GT_MODE, | |
1046 | GEN9_IZ_HASHING_MASK(2) | | |
1047 | GEN9_IZ_HASHING_MASK(1) | | |
1048 | GEN9_IZ_HASHING_MASK(0), | |
1049 | GEN9_IZ_HASHING(2, vals[2]) | | |
1050 | GEN9_IZ_HASHING(1, vals[1]) | | |
1051 | GEN9_IZ_HASHING(0, vals[0])); | |
1052 | ||
1053 | return 0; | |
1054 | } | |
1055 | ||
0bc40be8 | 1056 | static int skl_init_workarounds(struct intel_engine_cs *engine) |
8d205494 | 1057 | { |
aa0011a8 | 1058 | int ret; |
0bc40be8 | 1059 | struct drm_device *dev = engine->dev; |
d0bbbc4f DL |
1060 | struct drm_i915_private *dev_priv = dev->dev_private; |
1061 | ||
0bc40be8 | 1062 | ret = gen9_init_workarounds(engine); |
aa0011a8 AS |
1063 | if (ret) |
1064 | return ret; | |
8d205494 | 1065 | |
a78536e7 AS |
1066 | /* |
1067 | * Actual WA is to disable percontext preemption granularity control | |
1068 | * until D0 which is the default case so this is equivalent to | |
1069 | * !WaDisablePerCtxtPreemptionGranularityControl:skl | |
1070 | */ | |
1071 | if (IS_SKL_REVID(dev, SKL_REVID_E0, REVID_FOREVER)) { | |
1072 | I915_WRITE(GEN7_FF_SLICE_CS_CHICKEN1, | |
1073 | _MASKED_BIT_ENABLE(GEN9_FFSC_PERCTX_PREEMPT_CTRL)); | |
1074 | } | |
1075 | ||
e87a005d | 1076 | if (IS_SKL_REVID(dev, 0, SKL_REVID_D0)) { |
9c4cbf82 MK |
1077 | /* WaDisableChickenBitTSGBarrierAckForFFSliceCS:skl */ |
1078 | I915_WRITE(FF_SLICE_CS_CHICKEN2, | |
1079 | _MASKED_BIT_ENABLE(GEN9_TSG_BARRIER_ACK_DISABLE)); | |
1080 | } | |
1081 | ||
1082 | /* GEN8_L3SQCREG4 has a dependency with WA batch so any new changes | |
1083 | * involving this register should also be added to WA batch as required. | |
1084 | */ | |
e87a005d | 1085 | if (IS_SKL_REVID(dev, 0, SKL_REVID_E0)) |
9c4cbf82 MK |
1086 | /* WaDisableLSQCROPERFforOCL:skl */ |
1087 | I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) | | |
1088 | GEN8_LQSC_RO_PERF_DIS); | |
1089 | ||
1090 | /* WaEnableGapsTsvCreditFix:skl */ | |
e87a005d | 1091 | if (IS_SKL_REVID(dev, SKL_REVID_C0, REVID_FOREVER)) { |
9c4cbf82 MK |
1092 | I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) | |
1093 | GEN9_GAPS_TSV_CREDIT_DISABLE)); | |
1094 | } | |
1095 | ||
d0bbbc4f | 1096 | /* WaDisablePowerCompilerClockGating:skl */ |
e87a005d | 1097 | if (IS_SKL_REVID(dev, SKL_REVID_B0, SKL_REVID_B0)) |
d0bbbc4f DL |
1098 | WA_SET_BIT_MASKED(HIZ_CHICKEN, |
1099 | BDW_HIZ_POWER_COMPILER_CLOCK_GATING_DISABLE); | |
1100 | ||
97ea6be1 MK |
1101 | /* This is tied to WaForceContextSaveRestoreNonCoherent */ |
1102 | if (IS_SKL_REVID(dev, 0, REVID_FOREVER)) { | |
b62adbd1 NH |
1103 | /* |
1104 | *Use Force Non-Coherent whenever executing a 3D context. This | |
1105 | * is a workaround for a possible hang in the unlikely event | |
1106 | * a TLB invalidation occurs during a PSD flush. | |
1107 | */ | |
1108 | /* WaForceEnableNonCoherent:skl */ | |
1109 | WA_SET_BIT_MASKED(HDC_CHICKEN0, | |
1110 | HDC_FORCE_NON_COHERENT); | |
e238659d MK |
1111 | |
1112 | /* WaDisableHDCInvalidation:skl */ | |
1113 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | | |
1114 | BDW_DISABLE_HDC_INVALIDATION); | |
b62adbd1 NH |
1115 | } |
1116 | ||
e87a005d JN |
1117 | /* WaBarrierPerformanceFixDisable:skl */ |
1118 | if (IS_SKL_REVID(dev, SKL_REVID_C0, SKL_REVID_D0)) | |
5b6fd12a VS |
1119 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
1120 | HDC_FENCE_DEST_SLM_DISABLE | | |
1121 | HDC_BARRIER_PERFORMANCE_DISABLE); | |
1122 | ||
9bd9dfb4 | 1123 | /* WaDisableSbeCacheDispatchPortSharing:skl */ |
e87a005d | 1124 | if (IS_SKL_REVID(dev, 0, SKL_REVID_F0)) |
9bd9dfb4 MK |
1125 | WA_SET_BIT_MASKED( |
1126 | GEN7_HALF_SLICE_CHICKEN1, | |
1127 | GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE); | |
9bd9dfb4 | 1128 | |
6107497e | 1129 | /* WaDisableLSQCROPERFforOCL:skl */ |
0bc40be8 | 1130 | ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4); |
6107497e AS |
1131 | if (ret) |
1132 | return ret; | |
1133 | ||
0bc40be8 | 1134 | return skl_tune_iz_hashing(engine); |
7225342a MK |
1135 | } |
1136 | ||
0bc40be8 | 1137 | static int bxt_init_workarounds(struct intel_engine_cs *engine) |
cae0437f | 1138 | { |
aa0011a8 | 1139 | int ret; |
0bc40be8 | 1140 | struct drm_device *dev = engine->dev; |
dfb601e6 NH |
1141 | struct drm_i915_private *dev_priv = dev->dev_private; |
1142 | ||
0bc40be8 | 1143 | ret = gen9_init_workarounds(engine); |
aa0011a8 AS |
1144 | if (ret) |
1145 | return ret; | |
cae0437f | 1146 | |
9c4cbf82 MK |
1147 | /* WaStoreMultiplePTEenable:bxt */ |
1148 | /* This is a requirement according to Hardware specification */ | |
cbdc12a9 | 1149 | if (IS_BXT_REVID(dev, 0, BXT_REVID_A1)) |
9c4cbf82 MK |
1150 | I915_WRITE(TILECTL, I915_READ(TILECTL) | TILECTL_TLBPF); |
1151 | ||
1152 | /* WaSetClckGatingDisableMedia:bxt */ | |
cbdc12a9 | 1153 | if (IS_BXT_REVID(dev, 0, BXT_REVID_A1)) { |
9c4cbf82 MK |
1154 | I915_WRITE(GEN7_MISCCPCTL, (I915_READ(GEN7_MISCCPCTL) & |
1155 | ~GEN8_DOP_CLOCK_GATE_MEDIA_ENABLE)); | |
1156 | } | |
1157 | ||
dfb601e6 NH |
1158 | /* WaDisableThreadStallDopClockGating:bxt */ |
1159 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, | |
1160 | STALL_DOP_GATING_DISABLE); | |
1161 | ||
983b4b9d | 1162 | /* WaDisableSbeCacheDispatchPortSharing:bxt */ |
e87a005d | 1163 | if (IS_BXT_REVID(dev, 0, BXT_REVID_B0)) { |
983b4b9d NH |
1164 | WA_SET_BIT_MASKED( |
1165 | GEN7_HALF_SLICE_CHICKEN1, | |
1166 | GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE); | |
1167 | } | |
1168 | ||
2c8580e4 AS |
1169 | /* WaDisableObjectLevelPreemptionForTrifanOrPolygon:bxt */ |
1170 | /* WaDisableObjectLevelPreemptionForInstancedDraw:bxt */ | |
1171 | /* WaDisableObjectLevelPreemtionForInstanceId:bxt */ | |
a786d53a | 1172 | /* WaDisableLSQCROPERFforOCL:bxt */ |
2c8580e4 | 1173 | if (IS_BXT_REVID(dev, 0, BXT_REVID_A1)) { |
0bc40be8 | 1174 | ret = wa_ring_whitelist_reg(engine, GEN9_CS_DEBUG_MODE1); |
2c8580e4 AS |
1175 | if (ret) |
1176 | return ret; | |
a786d53a | 1177 | |
0bc40be8 | 1178 | ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4); |
a786d53a AS |
1179 | if (ret) |
1180 | return ret; | |
2c8580e4 AS |
1181 | } |
1182 | ||
050fc465 TG |
1183 | /* WaProgramL3SqcReg1DefaultForPerf:bxt */ |
1184 | if (IS_BXT_REVID(dev, BXT_REVID_B0, REVID_FOREVER)) | |
36579cb6 ID |
1185 | I915_WRITE(GEN8_L3SQCREG1, L3_GENERAL_PRIO_CREDITS(62) | |
1186 | L3_HIGH_PRIO_CREDITS(2)); | |
050fc465 | 1187 | |
cae0437f NH |
1188 | return 0; |
1189 | } | |
1190 | ||
0bc40be8 | 1191 | int init_workarounds_ring(struct intel_engine_cs *engine) |
7225342a | 1192 | { |
0bc40be8 | 1193 | struct drm_device *dev = engine->dev; |
7225342a MK |
1194 | struct drm_i915_private *dev_priv = dev->dev_private; |
1195 | ||
0bc40be8 | 1196 | WARN_ON(engine->id != RCS); |
7225342a MK |
1197 | |
1198 | dev_priv->workarounds.count = 0; | |
33136b06 | 1199 | dev_priv->workarounds.hw_whitelist_count[RCS] = 0; |
7225342a MK |
1200 | |
1201 | if (IS_BROADWELL(dev)) | |
0bc40be8 | 1202 | return bdw_init_workarounds(engine); |
7225342a MK |
1203 | |
1204 | if (IS_CHERRYVIEW(dev)) | |
0bc40be8 | 1205 | return chv_init_workarounds(engine); |
00e1e623 | 1206 | |
8d205494 | 1207 | if (IS_SKYLAKE(dev)) |
0bc40be8 | 1208 | return skl_init_workarounds(engine); |
cae0437f NH |
1209 | |
1210 | if (IS_BROXTON(dev)) | |
0bc40be8 | 1211 | return bxt_init_workarounds(engine); |
3b106531 | 1212 | |
00e1e623 VS |
1213 | return 0; |
1214 | } | |
1215 | ||
0bc40be8 | 1216 | static int init_render_ring(struct intel_engine_cs *engine) |
8187a2b7 | 1217 | { |
0bc40be8 | 1218 | struct drm_device *dev = engine->dev; |
1ec14ad3 | 1219 | struct drm_i915_private *dev_priv = dev->dev_private; |
0bc40be8 | 1220 | int ret = init_ring_common(engine); |
9c33baa6 KZ |
1221 | if (ret) |
1222 | return ret; | |
a69ffdbf | 1223 | |
61a563a2 AG |
1224 | /* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */ |
1225 | if (INTEL_INFO(dev)->gen >= 4 && INTEL_INFO(dev)->gen < 7) | |
6b26c86d | 1226 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH)); |
1c8c38c5 CW |
1227 | |
1228 | /* We need to disable the AsyncFlip performance optimisations in order | |
1229 | * to use MI_WAIT_FOR_EVENT within the CS. It should already be | |
1230 | * programmed to '1' on all products. | |
8693a824 | 1231 | * |
2441f877 | 1232 | * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv |
1c8c38c5 | 1233 | */ |
2441f877 | 1234 | if (INTEL_INFO(dev)->gen >= 6 && INTEL_INFO(dev)->gen < 8) |
1c8c38c5 CW |
1235 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(ASYNC_FLIP_PERF_DISABLE)); |
1236 | ||
f05bb0c7 | 1237 | /* Required for the hardware to program scanline values for waiting */ |
01fa0302 | 1238 | /* WaEnableFlushTlbInvalidationMode:snb */ |
f05bb0c7 CW |
1239 | if (INTEL_INFO(dev)->gen == 6) |
1240 | I915_WRITE(GFX_MODE, | |
aa83e30d | 1241 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT)); |
f05bb0c7 | 1242 | |
01fa0302 | 1243 | /* WaBCSVCSTlbInvalidationMode:ivb,vlv,hsw */ |
1c8c38c5 CW |
1244 | if (IS_GEN7(dev)) |
1245 | I915_WRITE(GFX_MODE_GEN7, | |
01fa0302 | 1246 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT) | |
1c8c38c5 | 1247 | _MASKED_BIT_ENABLE(GFX_REPLAY_MODE)); |
78501eac | 1248 | |
5e13a0c5 | 1249 | if (IS_GEN6(dev)) { |
3a69ddd6 KG |
1250 | /* From the Sandybridge PRM, volume 1 part 3, page 24: |
1251 | * "If this bit is set, STCunit will have LRA as replacement | |
1252 | * policy. [...] This bit must be reset. LRA replacement | |
1253 | * policy is not supported." | |
1254 | */ | |
1255 | I915_WRITE(CACHE_MODE_0, | |
5e13a0c5 | 1256 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
84f9f938 BW |
1257 | } |
1258 | ||
9cc83020 | 1259 | if (INTEL_INFO(dev)->gen >= 6 && INTEL_INFO(dev)->gen < 8) |
6b26c86d | 1260 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_FORCE_ORDERING)); |
84f9f938 | 1261 | |
040d2baa | 1262 | if (HAS_L3_DPF(dev)) |
0bc40be8 | 1263 | I915_WRITE_IMR(engine, ~GT_PARITY_ERROR(dev)); |
15b9f80e | 1264 | |
0bc40be8 | 1265 | return init_workarounds_ring(engine); |
8187a2b7 ZN |
1266 | } |
1267 | ||
0bc40be8 | 1268 | static void render_ring_cleanup(struct intel_engine_cs *engine) |
c6df541c | 1269 | { |
0bc40be8 | 1270 | struct drm_device *dev = engine->dev; |
3e78998a BW |
1271 | struct drm_i915_private *dev_priv = dev->dev_private; |
1272 | ||
1273 | if (dev_priv->semaphore_obj) { | |
1274 | i915_gem_object_ggtt_unpin(dev_priv->semaphore_obj); | |
1275 | drm_gem_object_unreference(&dev_priv->semaphore_obj->base); | |
1276 | dev_priv->semaphore_obj = NULL; | |
1277 | } | |
b45305fc | 1278 | |
0bc40be8 | 1279 | intel_fini_pipe_control(engine); |
c6df541c CW |
1280 | } |
1281 | ||
f7169687 | 1282 | static int gen8_rcs_signal(struct drm_i915_gem_request *signaller_req, |
3e78998a BW |
1283 | unsigned int num_dwords) |
1284 | { | |
1285 | #define MBOX_UPDATE_DWORDS 8 | |
4a570db5 | 1286 | struct intel_engine_cs *signaller = signaller_req->engine; |
3e78998a BW |
1287 | struct drm_device *dev = signaller->dev; |
1288 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1289 | struct intel_engine_cs *waiter; | |
c3232b18 DG |
1290 | enum intel_engine_id id; |
1291 | int ret, num_rings; | |
3e78998a BW |
1292 | |
1293 | num_rings = hweight32(INTEL_INFO(dev)->ring_mask); | |
1294 | num_dwords += (num_rings-1) * MBOX_UPDATE_DWORDS; | |
1295 | #undef MBOX_UPDATE_DWORDS | |
1296 | ||
5fb9de1a | 1297 | ret = intel_ring_begin(signaller_req, num_dwords); |
3e78998a BW |
1298 | if (ret) |
1299 | return ret; | |
1300 | ||
c3232b18 | 1301 | for_each_engine_id(waiter, dev_priv, id) { |
6259cead | 1302 | u32 seqno; |
c3232b18 | 1303 | u64 gtt_offset = signaller->semaphore.signal_ggtt[id]; |
3e78998a BW |
1304 | if (gtt_offset == MI_SEMAPHORE_SYNC_INVALID) |
1305 | continue; | |
1306 | ||
f7169687 | 1307 | seqno = i915_gem_request_get_seqno(signaller_req); |
3e78998a BW |
1308 | intel_ring_emit(signaller, GFX_OP_PIPE_CONTROL(6)); |
1309 | intel_ring_emit(signaller, PIPE_CONTROL_GLOBAL_GTT_IVB | | |
1310 | PIPE_CONTROL_QW_WRITE | | |
f9a4ea35 | 1311 | PIPE_CONTROL_CS_STALL); |
3e78998a BW |
1312 | intel_ring_emit(signaller, lower_32_bits(gtt_offset)); |
1313 | intel_ring_emit(signaller, upper_32_bits(gtt_offset)); | |
6259cead | 1314 | intel_ring_emit(signaller, seqno); |
3e78998a BW |
1315 | intel_ring_emit(signaller, 0); |
1316 | intel_ring_emit(signaller, MI_SEMAPHORE_SIGNAL | | |
215a7e32 | 1317 | MI_SEMAPHORE_TARGET(waiter->hw_id)); |
3e78998a BW |
1318 | intel_ring_emit(signaller, 0); |
1319 | } | |
1320 | ||
1321 | return 0; | |
1322 | } | |
1323 | ||
f7169687 | 1324 | static int gen8_xcs_signal(struct drm_i915_gem_request *signaller_req, |
3e78998a BW |
1325 | unsigned int num_dwords) |
1326 | { | |
1327 | #define MBOX_UPDATE_DWORDS 6 | |
4a570db5 | 1328 | struct intel_engine_cs *signaller = signaller_req->engine; |
3e78998a BW |
1329 | struct drm_device *dev = signaller->dev; |
1330 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1331 | struct intel_engine_cs *waiter; | |
c3232b18 DG |
1332 | enum intel_engine_id id; |
1333 | int ret, num_rings; | |
3e78998a BW |
1334 | |
1335 | num_rings = hweight32(INTEL_INFO(dev)->ring_mask); | |
1336 | num_dwords += (num_rings-1) * MBOX_UPDATE_DWORDS; | |
1337 | #undef MBOX_UPDATE_DWORDS | |
1338 | ||
5fb9de1a | 1339 | ret = intel_ring_begin(signaller_req, num_dwords); |
3e78998a BW |
1340 | if (ret) |
1341 | return ret; | |
1342 | ||
c3232b18 | 1343 | for_each_engine_id(waiter, dev_priv, id) { |
6259cead | 1344 | u32 seqno; |
c3232b18 | 1345 | u64 gtt_offset = signaller->semaphore.signal_ggtt[id]; |
3e78998a BW |
1346 | if (gtt_offset == MI_SEMAPHORE_SYNC_INVALID) |
1347 | continue; | |
1348 | ||
f7169687 | 1349 | seqno = i915_gem_request_get_seqno(signaller_req); |
3e78998a BW |
1350 | intel_ring_emit(signaller, (MI_FLUSH_DW + 1) | |
1351 | MI_FLUSH_DW_OP_STOREDW); | |
1352 | intel_ring_emit(signaller, lower_32_bits(gtt_offset) | | |
1353 | MI_FLUSH_DW_USE_GTT); | |
1354 | intel_ring_emit(signaller, upper_32_bits(gtt_offset)); | |
6259cead | 1355 | intel_ring_emit(signaller, seqno); |
3e78998a | 1356 | intel_ring_emit(signaller, MI_SEMAPHORE_SIGNAL | |
215a7e32 | 1357 | MI_SEMAPHORE_TARGET(waiter->hw_id)); |
3e78998a BW |
1358 | intel_ring_emit(signaller, 0); |
1359 | } | |
1360 | ||
1361 | return 0; | |
1362 | } | |
1363 | ||
f7169687 | 1364 | static int gen6_signal(struct drm_i915_gem_request *signaller_req, |
024a43e1 | 1365 | unsigned int num_dwords) |
1ec14ad3 | 1366 | { |
4a570db5 | 1367 | struct intel_engine_cs *signaller = signaller_req->engine; |
024a43e1 BW |
1368 | struct drm_device *dev = signaller->dev; |
1369 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a4872ba6 | 1370 | struct intel_engine_cs *useless; |
c3232b18 DG |
1371 | enum intel_engine_id id; |
1372 | int ret, num_rings; | |
78325f2d | 1373 | |
a1444b79 BW |
1374 | #define MBOX_UPDATE_DWORDS 3 |
1375 | num_rings = hweight32(INTEL_INFO(dev)->ring_mask); | |
1376 | num_dwords += round_up((num_rings-1) * MBOX_UPDATE_DWORDS, 2); | |
1377 | #undef MBOX_UPDATE_DWORDS | |
024a43e1 | 1378 | |
5fb9de1a | 1379 | ret = intel_ring_begin(signaller_req, num_dwords); |
024a43e1 BW |
1380 | if (ret) |
1381 | return ret; | |
024a43e1 | 1382 | |
c3232b18 DG |
1383 | for_each_engine_id(useless, dev_priv, id) { |
1384 | i915_reg_t mbox_reg = signaller->semaphore.mbox.signal[id]; | |
f0f59a00 VS |
1385 | |
1386 | if (i915_mmio_reg_valid(mbox_reg)) { | |
f7169687 | 1387 | u32 seqno = i915_gem_request_get_seqno(signaller_req); |
f0f59a00 | 1388 | |
78325f2d | 1389 | intel_ring_emit(signaller, MI_LOAD_REGISTER_IMM(1)); |
f92a9162 | 1390 | intel_ring_emit_reg(signaller, mbox_reg); |
6259cead | 1391 | intel_ring_emit(signaller, seqno); |
78325f2d BW |
1392 | } |
1393 | } | |
024a43e1 | 1394 | |
a1444b79 BW |
1395 | /* If num_dwords was rounded, make sure the tail pointer is correct */ |
1396 | if (num_rings % 2 == 0) | |
1397 | intel_ring_emit(signaller, MI_NOOP); | |
1398 | ||
024a43e1 | 1399 | return 0; |
1ec14ad3 CW |
1400 | } |
1401 | ||
c8c99b0f BW |
1402 | /** |
1403 | * gen6_add_request - Update the semaphore mailbox registers | |
ee044a88 JH |
1404 | * |
1405 | * @request - request to write to the ring | |
c8c99b0f BW |
1406 | * |
1407 | * Update the mailbox registers in the *other* rings with the current seqno. | |
1408 | * This acts like a signal in the canonical semaphore. | |
1409 | */ | |
1ec14ad3 | 1410 | static int |
ee044a88 | 1411 | gen6_add_request(struct drm_i915_gem_request *req) |
1ec14ad3 | 1412 | { |
4a570db5 | 1413 | struct intel_engine_cs *engine = req->engine; |
024a43e1 | 1414 | int ret; |
52ed2325 | 1415 | |
e2f80391 TU |
1416 | if (engine->semaphore.signal) |
1417 | ret = engine->semaphore.signal(req, 4); | |
707d9cf9 | 1418 | else |
5fb9de1a | 1419 | ret = intel_ring_begin(req, 4); |
707d9cf9 | 1420 | |
1ec14ad3 CW |
1421 | if (ret) |
1422 | return ret; | |
1423 | ||
e2f80391 TU |
1424 | intel_ring_emit(engine, MI_STORE_DWORD_INDEX); |
1425 | intel_ring_emit(engine, | |
1426 | I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | |
1427 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1428 | intel_ring_emit(engine, MI_USER_INTERRUPT); | |
1429 | __intel_ring_advance(engine); | |
1ec14ad3 | 1430 | |
1ec14ad3 CW |
1431 | return 0; |
1432 | } | |
1433 | ||
a58c01aa CW |
1434 | static int |
1435 | gen8_render_add_request(struct drm_i915_gem_request *req) | |
1436 | { | |
1437 | struct intel_engine_cs *engine = req->engine; | |
1438 | int ret; | |
1439 | ||
1440 | if (engine->semaphore.signal) | |
1441 | ret = engine->semaphore.signal(req, 8); | |
1442 | else | |
1443 | ret = intel_ring_begin(req, 8); | |
1444 | if (ret) | |
1445 | return ret; | |
1446 | ||
1447 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(6)); | |
1448 | intel_ring_emit(engine, (PIPE_CONTROL_GLOBAL_GTT_IVB | | |
1449 | PIPE_CONTROL_CS_STALL | | |
1450 | PIPE_CONTROL_QW_WRITE)); | |
1451 | intel_ring_emit(engine, intel_hws_seqno_address(req->engine)); | |
1452 | intel_ring_emit(engine, 0); | |
1453 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1454 | /* We're thrashing one dword of HWS. */ | |
1455 | intel_ring_emit(engine, 0); | |
1456 | intel_ring_emit(engine, MI_USER_INTERRUPT); | |
1457 | intel_ring_emit(engine, MI_NOOP); | |
1458 | __intel_ring_advance(engine); | |
1459 | ||
1460 | return 0; | |
1461 | } | |
1462 | ||
f72b3435 MK |
1463 | static inline bool i915_gem_has_seqno_wrapped(struct drm_device *dev, |
1464 | u32 seqno) | |
1465 | { | |
1466 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1467 | return dev_priv->last_seqno < seqno; | |
1468 | } | |
1469 | ||
c8c99b0f BW |
1470 | /** |
1471 | * intel_ring_sync - sync the waiter to the signaller on seqno | |
1472 | * | |
1473 | * @waiter - ring that is waiting | |
1474 | * @signaller - ring which has, or will signal | |
1475 | * @seqno - seqno which the waiter will block on | |
1476 | */ | |
5ee426ca BW |
1477 | |
1478 | static int | |
599d924c | 1479 | gen8_ring_sync(struct drm_i915_gem_request *waiter_req, |
5ee426ca BW |
1480 | struct intel_engine_cs *signaller, |
1481 | u32 seqno) | |
1482 | { | |
4a570db5 | 1483 | struct intel_engine_cs *waiter = waiter_req->engine; |
5ee426ca | 1484 | struct drm_i915_private *dev_priv = waiter->dev->dev_private; |
6ef48d7f | 1485 | struct i915_hw_ppgtt *ppgtt; |
5ee426ca BW |
1486 | int ret; |
1487 | ||
5fb9de1a | 1488 | ret = intel_ring_begin(waiter_req, 4); |
5ee426ca BW |
1489 | if (ret) |
1490 | return ret; | |
1491 | ||
1492 | intel_ring_emit(waiter, MI_SEMAPHORE_WAIT | | |
1493 | MI_SEMAPHORE_GLOBAL_GTT | | |
1494 | MI_SEMAPHORE_SAD_GTE_SDD); | |
1495 | intel_ring_emit(waiter, seqno); | |
1496 | intel_ring_emit(waiter, | |
1497 | lower_32_bits(GEN8_WAIT_OFFSET(waiter, signaller->id))); | |
1498 | intel_ring_emit(waiter, | |
1499 | upper_32_bits(GEN8_WAIT_OFFSET(waiter, signaller->id))); | |
1500 | intel_ring_advance(waiter); | |
6ef48d7f CW |
1501 | |
1502 | /* When the !RCS engines idle waiting upon a semaphore, they lose their | |
1503 | * pagetables and we must reload them before executing the batch. | |
1504 | * We do this on the i915_switch_context() following the wait and | |
1505 | * before the dispatch. | |
1506 | */ | |
1507 | ppgtt = waiter_req->ctx->ppgtt; | |
1508 | if (ppgtt && waiter_req->engine->id != RCS) | |
1509 | ppgtt->pd_dirty_rings |= intel_engine_flag(waiter_req->engine); | |
5ee426ca BW |
1510 | return 0; |
1511 | } | |
1512 | ||
c8c99b0f | 1513 | static int |
599d924c | 1514 | gen6_ring_sync(struct drm_i915_gem_request *waiter_req, |
a4872ba6 | 1515 | struct intel_engine_cs *signaller, |
686cb5f9 | 1516 | u32 seqno) |
1ec14ad3 | 1517 | { |
4a570db5 | 1518 | struct intel_engine_cs *waiter = waiter_req->engine; |
c8c99b0f BW |
1519 | u32 dw1 = MI_SEMAPHORE_MBOX | |
1520 | MI_SEMAPHORE_COMPARE | | |
1521 | MI_SEMAPHORE_REGISTER; | |
ebc348b2 BW |
1522 | u32 wait_mbox = signaller->semaphore.mbox.wait[waiter->id]; |
1523 | int ret; | |
1ec14ad3 | 1524 | |
1500f7ea BW |
1525 | /* Throughout all of the GEM code, seqno passed implies our current |
1526 | * seqno is >= the last seqno executed. However for hardware the | |
1527 | * comparison is strictly greater than. | |
1528 | */ | |
1529 | seqno -= 1; | |
1530 | ||
ebc348b2 | 1531 | WARN_ON(wait_mbox == MI_SEMAPHORE_SYNC_INVALID); |
686cb5f9 | 1532 | |
5fb9de1a | 1533 | ret = intel_ring_begin(waiter_req, 4); |
1ec14ad3 CW |
1534 | if (ret) |
1535 | return ret; | |
1536 | ||
f72b3435 MK |
1537 | /* If seqno wrap happened, omit the wait with no-ops */ |
1538 | if (likely(!i915_gem_has_seqno_wrapped(waiter->dev, seqno))) { | |
ebc348b2 | 1539 | intel_ring_emit(waiter, dw1 | wait_mbox); |
f72b3435 MK |
1540 | intel_ring_emit(waiter, seqno); |
1541 | intel_ring_emit(waiter, 0); | |
1542 | intel_ring_emit(waiter, MI_NOOP); | |
1543 | } else { | |
1544 | intel_ring_emit(waiter, MI_NOOP); | |
1545 | intel_ring_emit(waiter, MI_NOOP); | |
1546 | intel_ring_emit(waiter, MI_NOOP); | |
1547 | intel_ring_emit(waiter, MI_NOOP); | |
1548 | } | |
c8c99b0f | 1549 | intel_ring_advance(waiter); |
1ec14ad3 CW |
1550 | |
1551 | return 0; | |
1552 | } | |
1553 | ||
c6df541c CW |
1554 | #define PIPE_CONTROL_FLUSH(ring__, addr__) \ |
1555 | do { \ | |
fcbc34e4 KG |
1556 | intel_ring_emit(ring__, GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | \ |
1557 | PIPE_CONTROL_DEPTH_STALL); \ | |
c6df541c CW |
1558 | intel_ring_emit(ring__, (addr__) | PIPE_CONTROL_GLOBAL_GTT); \ |
1559 | intel_ring_emit(ring__, 0); \ | |
1560 | intel_ring_emit(ring__, 0); \ | |
1561 | } while (0) | |
1562 | ||
1563 | static int | |
ee044a88 | 1564 | pc_render_add_request(struct drm_i915_gem_request *req) |
c6df541c | 1565 | { |
4a570db5 | 1566 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 1567 | u32 scratch_addr = engine->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
c6df541c CW |
1568 | int ret; |
1569 | ||
1570 | /* For Ironlake, MI_USER_INTERRUPT was deprecated and apparently | |
1571 | * incoherent with writes to memory, i.e. completely fubar, | |
1572 | * so we need to use PIPE_NOTIFY instead. | |
1573 | * | |
1574 | * However, we also need to workaround the qword write | |
1575 | * incoherence by flushing the 6 PIPE_NOTIFY buffers out to | |
1576 | * memory before requesting an interrupt. | |
1577 | */ | |
5fb9de1a | 1578 | ret = intel_ring_begin(req, 32); |
c6df541c CW |
1579 | if (ret) |
1580 | return ret; | |
1581 | ||
e2f80391 TU |
1582 | intel_ring_emit(engine, |
1583 | GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | | |
9d971b37 KG |
1584 | PIPE_CONTROL_WRITE_FLUSH | |
1585 | PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE); | |
e2f80391 TU |
1586 | intel_ring_emit(engine, |
1587 | engine->scratch.gtt_offset | PIPE_CONTROL_GLOBAL_GTT); | |
1588 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1589 | intel_ring_emit(engine, 0); | |
1590 | PIPE_CONTROL_FLUSH(engine, scratch_addr); | |
18393f63 | 1591 | scratch_addr += 2 * CACHELINE_BYTES; /* write to separate cachelines */ |
e2f80391 | 1592 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1593 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1594 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1595 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1596 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1597 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1598 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1599 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1600 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
a71d8d94 | 1601 | |
e2f80391 TU |
1602 | intel_ring_emit(engine, |
1603 | GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | | |
9d971b37 KG |
1604 | PIPE_CONTROL_WRITE_FLUSH | |
1605 | PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | | |
c6df541c | 1606 | PIPE_CONTROL_NOTIFY); |
e2f80391 TU |
1607 | intel_ring_emit(engine, |
1608 | engine->scratch.gtt_offset | PIPE_CONTROL_GLOBAL_GTT); | |
1609 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1610 | intel_ring_emit(engine, 0); | |
1611 | __intel_ring_advance(engine); | |
c6df541c | 1612 | |
c6df541c CW |
1613 | return 0; |
1614 | } | |
1615 | ||
c04e0f3b CW |
1616 | static void |
1617 | gen6_seqno_barrier(struct intel_engine_cs *engine) | |
4cd53c0c | 1618 | { |
bcbdb6d0 CW |
1619 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
1620 | ||
4cd53c0c DV |
1621 | /* Workaround to force correct ordering between irq and seqno writes on |
1622 | * ivb (and maybe also on snb) by reading from a CS register (like | |
9b9ed309 CW |
1623 | * ACTHD) before reading the status page. |
1624 | * | |
1625 | * Note that this effectively stalls the read by the time it takes to | |
1626 | * do a memory transaction, which more or less ensures that the write | |
1627 | * from the GPU has sufficient time to invalidate the CPU cacheline. | |
1628 | * Alternatively we could delay the interrupt from the CS ring to give | |
1629 | * the write time to land, but that would incur a delay after every | |
1630 | * batch i.e. much more frequent than a delay when waiting for the | |
1631 | * interrupt (with the same net latency). | |
bcbdb6d0 CW |
1632 | * |
1633 | * Also note that to prevent whole machine hangs on gen7, we have to | |
1634 | * take the spinlock to guard against concurrent cacheline access. | |
9b9ed309 | 1635 | */ |
bcbdb6d0 | 1636 | spin_lock_irq(&dev_priv->uncore.lock); |
c04e0f3b | 1637 | POSTING_READ_FW(RING_ACTHD(engine->mmio_base)); |
bcbdb6d0 | 1638 | spin_unlock_irq(&dev_priv->uncore.lock); |
4cd53c0c DV |
1639 | } |
1640 | ||
8187a2b7 | 1641 | static u32 |
c04e0f3b | 1642 | ring_get_seqno(struct intel_engine_cs *engine) |
8187a2b7 | 1643 | { |
0bc40be8 | 1644 | return intel_read_status_page(engine, I915_GEM_HWS_INDEX); |
1ec14ad3 CW |
1645 | } |
1646 | ||
b70ec5bf | 1647 | static void |
0bc40be8 | 1648 | ring_set_seqno(struct intel_engine_cs *engine, u32 seqno) |
b70ec5bf | 1649 | { |
0bc40be8 | 1650 | intel_write_status_page(engine, I915_GEM_HWS_INDEX, seqno); |
b70ec5bf MK |
1651 | } |
1652 | ||
c6df541c | 1653 | static u32 |
c04e0f3b | 1654 | pc_render_get_seqno(struct intel_engine_cs *engine) |
c6df541c | 1655 | { |
0bc40be8 | 1656 | return engine->scratch.cpu_page[0]; |
c6df541c CW |
1657 | } |
1658 | ||
b70ec5bf | 1659 | static void |
0bc40be8 | 1660 | pc_render_set_seqno(struct intel_engine_cs *engine, u32 seqno) |
b70ec5bf | 1661 | { |
0bc40be8 | 1662 | engine->scratch.cpu_page[0] = seqno; |
b70ec5bf MK |
1663 | } |
1664 | ||
e48d8634 | 1665 | static bool |
0bc40be8 | 1666 | gen5_ring_get_irq(struct intel_engine_cs *engine) |
e48d8634 | 1667 | { |
0bc40be8 | 1668 | struct drm_device *dev = engine->dev; |
4640c4ff | 1669 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1670 | unsigned long flags; |
e48d8634 | 1671 | |
7cd512f1 | 1672 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
e48d8634 DV |
1673 | return false; |
1674 | ||
7338aefa | 1675 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1676 | if (engine->irq_refcount++ == 0) |
1677 | gen5_enable_gt_irq(dev_priv, engine->irq_enable_mask); | |
7338aefa | 1678 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
e48d8634 DV |
1679 | |
1680 | return true; | |
1681 | } | |
1682 | ||
1683 | static void | |
0bc40be8 | 1684 | gen5_ring_put_irq(struct intel_engine_cs *engine) |
e48d8634 | 1685 | { |
0bc40be8 | 1686 | struct drm_device *dev = engine->dev; |
4640c4ff | 1687 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1688 | unsigned long flags; |
e48d8634 | 1689 | |
7338aefa | 1690 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1691 | if (--engine->irq_refcount == 0) |
1692 | gen5_disable_gt_irq(dev_priv, engine->irq_enable_mask); | |
7338aefa | 1693 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
e48d8634 DV |
1694 | } |
1695 | ||
b13c2b96 | 1696 | static bool |
0bc40be8 | 1697 | i9xx_ring_get_irq(struct intel_engine_cs *engine) |
62fdfeaf | 1698 | { |
0bc40be8 | 1699 | struct drm_device *dev = engine->dev; |
4640c4ff | 1700 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1701 | unsigned long flags; |
62fdfeaf | 1702 | |
7cd512f1 | 1703 | if (!intel_irqs_enabled(dev_priv)) |
b13c2b96 CW |
1704 | return false; |
1705 | ||
7338aefa | 1706 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1707 | if (engine->irq_refcount++ == 0) { |
1708 | dev_priv->irq_mask &= ~engine->irq_enable_mask; | |
f637fde4 DV |
1709 | I915_WRITE(IMR, dev_priv->irq_mask); |
1710 | POSTING_READ(IMR); | |
1711 | } | |
7338aefa | 1712 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
b13c2b96 CW |
1713 | |
1714 | return true; | |
62fdfeaf EA |
1715 | } |
1716 | ||
8187a2b7 | 1717 | static void |
0bc40be8 | 1718 | i9xx_ring_put_irq(struct intel_engine_cs *engine) |
62fdfeaf | 1719 | { |
0bc40be8 | 1720 | struct drm_device *dev = engine->dev; |
4640c4ff | 1721 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1722 | unsigned long flags; |
62fdfeaf | 1723 | |
7338aefa | 1724 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1725 | if (--engine->irq_refcount == 0) { |
1726 | dev_priv->irq_mask |= engine->irq_enable_mask; | |
f637fde4 DV |
1727 | I915_WRITE(IMR, dev_priv->irq_mask); |
1728 | POSTING_READ(IMR); | |
1729 | } | |
7338aefa | 1730 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
62fdfeaf EA |
1731 | } |
1732 | ||
c2798b19 | 1733 | static bool |
0bc40be8 | 1734 | i8xx_ring_get_irq(struct intel_engine_cs *engine) |
c2798b19 | 1735 | { |
0bc40be8 | 1736 | struct drm_device *dev = engine->dev; |
4640c4ff | 1737 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1738 | unsigned long flags; |
c2798b19 | 1739 | |
7cd512f1 | 1740 | if (!intel_irqs_enabled(dev_priv)) |
c2798b19 CW |
1741 | return false; |
1742 | ||
7338aefa | 1743 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1744 | if (engine->irq_refcount++ == 0) { |
1745 | dev_priv->irq_mask &= ~engine->irq_enable_mask; | |
c2798b19 CW |
1746 | I915_WRITE16(IMR, dev_priv->irq_mask); |
1747 | POSTING_READ16(IMR); | |
1748 | } | |
7338aefa | 1749 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
c2798b19 CW |
1750 | |
1751 | return true; | |
1752 | } | |
1753 | ||
1754 | static void | |
0bc40be8 | 1755 | i8xx_ring_put_irq(struct intel_engine_cs *engine) |
c2798b19 | 1756 | { |
0bc40be8 | 1757 | struct drm_device *dev = engine->dev; |
4640c4ff | 1758 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1759 | unsigned long flags; |
c2798b19 | 1760 | |
7338aefa | 1761 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1762 | if (--engine->irq_refcount == 0) { |
1763 | dev_priv->irq_mask |= engine->irq_enable_mask; | |
c2798b19 CW |
1764 | I915_WRITE16(IMR, dev_priv->irq_mask); |
1765 | POSTING_READ16(IMR); | |
1766 | } | |
7338aefa | 1767 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
c2798b19 CW |
1768 | } |
1769 | ||
b72f3acb | 1770 | static int |
a84c3ae1 | 1771 | bsd_ring_flush(struct drm_i915_gem_request *req, |
78501eac CW |
1772 | u32 invalidate_domains, |
1773 | u32 flush_domains) | |
d1b851fc | 1774 | { |
4a570db5 | 1775 | struct intel_engine_cs *engine = req->engine; |
b72f3acb CW |
1776 | int ret; |
1777 | ||
5fb9de1a | 1778 | ret = intel_ring_begin(req, 2); |
b72f3acb CW |
1779 | if (ret) |
1780 | return ret; | |
1781 | ||
e2f80391 TU |
1782 | intel_ring_emit(engine, MI_FLUSH); |
1783 | intel_ring_emit(engine, MI_NOOP); | |
1784 | intel_ring_advance(engine); | |
b72f3acb | 1785 | return 0; |
d1b851fc ZN |
1786 | } |
1787 | ||
3cce469c | 1788 | static int |
ee044a88 | 1789 | i9xx_add_request(struct drm_i915_gem_request *req) |
d1b851fc | 1790 | { |
4a570db5 | 1791 | struct intel_engine_cs *engine = req->engine; |
3cce469c CW |
1792 | int ret; |
1793 | ||
5fb9de1a | 1794 | ret = intel_ring_begin(req, 4); |
3cce469c CW |
1795 | if (ret) |
1796 | return ret; | |
6f392d54 | 1797 | |
e2f80391 TU |
1798 | intel_ring_emit(engine, MI_STORE_DWORD_INDEX); |
1799 | intel_ring_emit(engine, | |
1800 | I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | |
1801 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1802 | intel_ring_emit(engine, MI_USER_INTERRUPT); | |
1803 | __intel_ring_advance(engine); | |
d1b851fc | 1804 | |
3cce469c | 1805 | return 0; |
d1b851fc ZN |
1806 | } |
1807 | ||
0f46832f | 1808 | static bool |
0bc40be8 | 1809 | gen6_ring_get_irq(struct intel_engine_cs *engine) |
0f46832f | 1810 | { |
0bc40be8 | 1811 | struct drm_device *dev = engine->dev; |
4640c4ff | 1812 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1813 | unsigned long flags; |
0f46832f | 1814 | |
7cd512f1 DV |
1815 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
1816 | return false; | |
0f46832f | 1817 | |
7338aefa | 1818 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1819 | if (engine->irq_refcount++ == 0) { |
1820 | if (HAS_L3_DPF(dev) && engine->id == RCS) | |
1821 | I915_WRITE_IMR(engine, | |
1822 | ~(engine->irq_enable_mask | | |
35a85ac6 | 1823 | GT_PARITY_ERROR(dev))); |
15b9f80e | 1824 | else |
0bc40be8 TU |
1825 | I915_WRITE_IMR(engine, ~engine->irq_enable_mask); |
1826 | gen5_enable_gt_irq(dev_priv, engine->irq_enable_mask); | |
0f46832f | 1827 | } |
7338aefa | 1828 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
0f46832f CW |
1829 | |
1830 | return true; | |
1831 | } | |
1832 | ||
1833 | static void | |
0bc40be8 | 1834 | gen6_ring_put_irq(struct intel_engine_cs *engine) |
0f46832f | 1835 | { |
0bc40be8 | 1836 | struct drm_device *dev = engine->dev; |
4640c4ff | 1837 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1838 | unsigned long flags; |
0f46832f | 1839 | |
7338aefa | 1840 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1841 | if (--engine->irq_refcount == 0) { |
1842 | if (HAS_L3_DPF(dev) && engine->id == RCS) | |
1843 | I915_WRITE_IMR(engine, ~GT_PARITY_ERROR(dev)); | |
15b9f80e | 1844 | else |
0bc40be8 TU |
1845 | I915_WRITE_IMR(engine, ~0); |
1846 | gen5_disable_gt_irq(dev_priv, engine->irq_enable_mask); | |
1ec14ad3 | 1847 | } |
7338aefa | 1848 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
d1b851fc ZN |
1849 | } |
1850 | ||
a19d2933 | 1851 | static bool |
0bc40be8 | 1852 | hsw_vebox_get_irq(struct intel_engine_cs *engine) |
a19d2933 | 1853 | { |
0bc40be8 | 1854 | struct drm_device *dev = engine->dev; |
a19d2933 BW |
1855 | struct drm_i915_private *dev_priv = dev->dev_private; |
1856 | unsigned long flags; | |
1857 | ||
7cd512f1 | 1858 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
a19d2933 BW |
1859 | return false; |
1860 | ||
59cdb63d | 1861 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1862 | if (engine->irq_refcount++ == 0) { |
1863 | I915_WRITE_IMR(engine, ~engine->irq_enable_mask); | |
1864 | gen6_enable_pm_irq(dev_priv, engine->irq_enable_mask); | |
a19d2933 | 1865 | } |
59cdb63d | 1866 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
a19d2933 BW |
1867 | |
1868 | return true; | |
1869 | } | |
1870 | ||
1871 | static void | |
0bc40be8 | 1872 | hsw_vebox_put_irq(struct intel_engine_cs *engine) |
a19d2933 | 1873 | { |
0bc40be8 | 1874 | struct drm_device *dev = engine->dev; |
a19d2933 BW |
1875 | struct drm_i915_private *dev_priv = dev->dev_private; |
1876 | unsigned long flags; | |
1877 | ||
59cdb63d | 1878 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1879 | if (--engine->irq_refcount == 0) { |
1880 | I915_WRITE_IMR(engine, ~0); | |
1881 | gen6_disable_pm_irq(dev_priv, engine->irq_enable_mask); | |
a19d2933 | 1882 | } |
59cdb63d | 1883 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
a19d2933 BW |
1884 | } |
1885 | ||
abd58f01 | 1886 | static bool |
0bc40be8 | 1887 | gen8_ring_get_irq(struct intel_engine_cs *engine) |
abd58f01 | 1888 | { |
0bc40be8 | 1889 | struct drm_device *dev = engine->dev; |
abd58f01 BW |
1890 | struct drm_i915_private *dev_priv = dev->dev_private; |
1891 | unsigned long flags; | |
1892 | ||
7cd512f1 | 1893 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
abd58f01 BW |
1894 | return false; |
1895 | ||
1896 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
0bc40be8 TU |
1897 | if (engine->irq_refcount++ == 0) { |
1898 | if (HAS_L3_DPF(dev) && engine->id == RCS) { | |
1899 | I915_WRITE_IMR(engine, | |
1900 | ~(engine->irq_enable_mask | | |
abd58f01 BW |
1901 | GT_RENDER_L3_PARITY_ERROR_INTERRUPT)); |
1902 | } else { | |
0bc40be8 | 1903 | I915_WRITE_IMR(engine, ~engine->irq_enable_mask); |
abd58f01 | 1904 | } |
0bc40be8 | 1905 | POSTING_READ(RING_IMR(engine->mmio_base)); |
abd58f01 BW |
1906 | } |
1907 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
1908 | ||
1909 | return true; | |
1910 | } | |
1911 | ||
1912 | static void | |
0bc40be8 | 1913 | gen8_ring_put_irq(struct intel_engine_cs *engine) |
abd58f01 | 1914 | { |
0bc40be8 | 1915 | struct drm_device *dev = engine->dev; |
abd58f01 BW |
1916 | struct drm_i915_private *dev_priv = dev->dev_private; |
1917 | unsigned long flags; | |
1918 | ||
1919 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
0bc40be8 TU |
1920 | if (--engine->irq_refcount == 0) { |
1921 | if (HAS_L3_DPF(dev) && engine->id == RCS) { | |
1922 | I915_WRITE_IMR(engine, | |
abd58f01 BW |
1923 | ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT); |
1924 | } else { | |
0bc40be8 | 1925 | I915_WRITE_IMR(engine, ~0); |
abd58f01 | 1926 | } |
0bc40be8 | 1927 | POSTING_READ(RING_IMR(engine->mmio_base)); |
abd58f01 BW |
1928 | } |
1929 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
1930 | } | |
1931 | ||
d1b851fc | 1932 | static int |
53fddaf7 | 1933 | i965_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 1934 | u64 offset, u32 length, |
8e004efc | 1935 | unsigned dispatch_flags) |
d1b851fc | 1936 | { |
4a570db5 | 1937 | struct intel_engine_cs *engine = req->engine; |
e1f99ce6 | 1938 | int ret; |
78501eac | 1939 | |
5fb9de1a | 1940 | ret = intel_ring_begin(req, 2); |
e1f99ce6 CW |
1941 | if (ret) |
1942 | return ret; | |
1943 | ||
e2f80391 | 1944 | intel_ring_emit(engine, |
65f56876 CW |
1945 | MI_BATCH_BUFFER_START | |
1946 | MI_BATCH_GTT | | |
8e004efc JH |
1947 | (dispatch_flags & I915_DISPATCH_SECURE ? |
1948 | 0 : MI_BATCH_NON_SECURE_I965)); | |
e2f80391 TU |
1949 | intel_ring_emit(engine, offset); |
1950 | intel_ring_advance(engine); | |
78501eac | 1951 | |
d1b851fc ZN |
1952 | return 0; |
1953 | } | |
1954 | ||
b45305fc DV |
1955 | /* Just userspace ABI convention to limit the wa batch bo to a resonable size */ |
1956 | #define I830_BATCH_LIMIT (256*1024) | |
c4d69da1 CW |
1957 | #define I830_TLB_ENTRIES (2) |
1958 | #define I830_WA_SIZE max(I830_TLB_ENTRIES*4096, I830_BATCH_LIMIT) | |
8187a2b7 | 1959 | static int |
53fddaf7 | 1960 | i830_dispatch_execbuffer(struct drm_i915_gem_request *req, |
8e004efc JH |
1961 | u64 offset, u32 len, |
1962 | unsigned dispatch_flags) | |
62fdfeaf | 1963 | { |
4a570db5 | 1964 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 1965 | u32 cs_offset = engine->scratch.gtt_offset; |
c4e7a414 | 1966 | int ret; |
62fdfeaf | 1967 | |
5fb9de1a | 1968 | ret = intel_ring_begin(req, 6); |
c4d69da1 CW |
1969 | if (ret) |
1970 | return ret; | |
62fdfeaf | 1971 | |
c4d69da1 | 1972 | /* Evict the invalid PTE TLBs */ |
e2f80391 TU |
1973 | intel_ring_emit(engine, COLOR_BLT_CMD | BLT_WRITE_RGBA); |
1974 | intel_ring_emit(engine, BLT_DEPTH_32 | BLT_ROP_COLOR_COPY | 4096); | |
1975 | intel_ring_emit(engine, I830_TLB_ENTRIES << 16 | 4); /* load each page */ | |
1976 | intel_ring_emit(engine, cs_offset); | |
1977 | intel_ring_emit(engine, 0xdeadbeef); | |
1978 | intel_ring_emit(engine, MI_NOOP); | |
1979 | intel_ring_advance(engine); | |
b45305fc | 1980 | |
8e004efc | 1981 | if ((dispatch_flags & I915_DISPATCH_PINNED) == 0) { |
b45305fc DV |
1982 | if (len > I830_BATCH_LIMIT) |
1983 | return -ENOSPC; | |
1984 | ||
5fb9de1a | 1985 | ret = intel_ring_begin(req, 6 + 2); |
b45305fc DV |
1986 | if (ret) |
1987 | return ret; | |
c4d69da1 CW |
1988 | |
1989 | /* Blit the batch (which has now all relocs applied) to the | |
1990 | * stable batch scratch bo area (so that the CS never | |
1991 | * stumbles over its tlb invalidation bug) ... | |
1992 | */ | |
e2f80391 TU |
1993 | intel_ring_emit(engine, SRC_COPY_BLT_CMD | BLT_WRITE_RGBA); |
1994 | intel_ring_emit(engine, | |
1995 | BLT_DEPTH_32 | BLT_ROP_SRC_COPY | 4096); | |
1996 | intel_ring_emit(engine, DIV_ROUND_UP(len, 4096) << 16 | 4096); | |
1997 | intel_ring_emit(engine, cs_offset); | |
1998 | intel_ring_emit(engine, 4096); | |
1999 | intel_ring_emit(engine, offset); | |
2000 | ||
2001 | intel_ring_emit(engine, MI_FLUSH); | |
2002 | intel_ring_emit(engine, MI_NOOP); | |
2003 | intel_ring_advance(engine); | |
b45305fc DV |
2004 | |
2005 | /* ... and execute it. */ | |
c4d69da1 | 2006 | offset = cs_offset; |
b45305fc | 2007 | } |
e1f99ce6 | 2008 | |
9d611c03 | 2009 | ret = intel_ring_begin(req, 2); |
c4d69da1 CW |
2010 | if (ret) |
2011 | return ret; | |
2012 | ||
e2f80391 TU |
2013 | intel_ring_emit(engine, MI_BATCH_BUFFER_START | MI_BATCH_GTT); |
2014 | intel_ring_emit(engine, offset | (dispatch_flags & I915_DISPATCH_SECURE ? | |
2015 | 0 : MI_BATCH_NON_SECURE)); | |
2016 | intel_ring_advance(engine); | |
c4d69da1 | 2017 | |
fb3256da DV |
2018 | return 0; |
2019 | } | |
2020 | ||
2021 | static int | |
53fddaf7 | 2022 | i915_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 2023 | u64 offset, u32 len, |
8e004efc | 2024 | unsigned dispatch_flags) |
fb3256da | 2025 | { |
4a570db5 | 2026 | struct intel_engine_cs *engine = req->engine; |
fb3256da DV |
2027 | int ret; |
2028 | ||
5fb9de1a | 2029 | ret = intel_ring_begin(req, 2); |
fb3256da DV |
2030 | if (ret) |
2031 | return ret; | |
2032 | ||
e2f80391 TU |
2033 | intel_ring_emit(engine, MI_BATCH_BUFFER_START | MI_BATCH_GTT); |
2034 | intel_ring_emit(engine, offset | (dispatch_flags & I915_DISPATCH_SECURE ? | |
2035 | 0 : MI_BATCH_NON_SECURE)); | |
2036 | intel_ring_advance(engine); | |
62fdfeaf | 2037 | |
62fdfeaf EA |
2038 | return 0; |
2039 | } | |
2040 | ||
0bc40be8 | 2041 | static void cleanup_phys_status_page(struct intel_engine_cs *engine) |
7d3fdfff | 2042 | { |
0bc40be8 | 2043 | struct drm_i915_private *dev_priv = to_i915(engine->dev); |
7d3fdfff VS |
2044 | |
2045 | if (!dev_priv->status_page_dmah) | |
2046 | return; | |
2047 | ||
0bc40be8 TU |
2048 | drm_pci_free(engine->dev, dev_priv->status_page_dmah); |
2049 | engine->status_page.page_addr = NULL; | |
7d3fdfff VS |
2050 | } |
2051 | ||
0bc40be8 | 2052 | static void cleanup_status_page(struct intel_engine_cs *engine) |
62fdfeaf | 2053 | { |
05394f39 | 2054 | struct drm_i915_gem_object *obj; |
62fdfeaf | 2055 | |
0bc40be8 | 2056 | obj = engine->status_page.obj; |
8187a2b7 | 2057 | if (obj == NULL) |
62fdfeaf | 2058 | return; |
62fdfeaf | 2059 | |
9da3da66 | 2060 | kunmap(sg_page(obj->pages->sgl)); |
d7f46fc4 | 2061 | i915_gem_object_ggtt_unpin(obj); |
05394f39 | 2062 | drm_gem_object_unreference(&obj->base); |
0bc40be8 | 2063 | engine->status_page.obj = NULL; |
62fdfeaf EA |
2064 | } |
2065 | ||
0bc40be8 | 2066 | static int init_status_page(struct intel_engine_cs *engine) |
62fdfeaf | 2067 | { |
0bc40be8 | 2068 | struct drm_i915_gem_object *obj = engine->status_page.obj; |
62fdfeaf | 2069 | |
7d3fdfff | 2070 | if (obj == NULL) { |
1f767e02 | 2071 | unsigned flags; |
e3efda49 | 2072 | int ret; |
e4ffd173 | 2073 | |
d37cd8a8 | 2074 | obj = i915_gem_object_create(engine->dev, 4096); |
fe3db79b | 2075 | if (IS_ERR(obj)) { |
e3efda49 | 2076 | DRM_ERROR("Failed to allocate status page\n"); |
fe3db79b | 2077 | return PTR_ERR(obj); |
e3efda49 | 2078 | } |
62fdfeaf | 2079 | |
e3efda49 CW |
2080 | ret = i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); |
2081 | if (ret) | |
2082 | goto err_unref; | |
2083 | ||
1f767e02 | 2084 | flags = 0; |
0bc40be8 | 2085 | if (!HAS_LLC(engine->dev)) |
1f767e02 CW |
2086 | /* On g33, we cannot place HWS above 256MiB, so |
2087 | * restrict its pinning to the low mappable arena. | |
2088 | * Though this restriction is not documented for | |
2089 | * gen4, gen5, or byt, they also behave similarly | |
2090 | * and hang if the HWS is placed at the top of the | |
2091 | * GTT. To generalise, it appears that all !llc | |
2092 | * platforms have issues with us placing the HWS | |
2093 | * above the mappable region (even though we never | |
2094 | * actualy map it). | |
2095 | */ | |
2096 | flags |= PIN_MAPPABLE; | |
2097 | ret = i915_gem_obj_ggtt_pin(obj, 4096, flags); | |
e3efda49 CW |
2098 | if (ret) { |
2099 | err_unref: | |
2100 | drm_gem_object_unreference(&obj->base); | |
2101 | return ret; | |
2102 | } | |
2103 | ||
0bc40be8 | 2104 | engine->status_page.obj = obj; |
e3efda49 | 2105 | } |
62fdfeaf | 2106 | |
0bc40be8 TU |
2107 | engine->status_page.gfx_addr = i915_gem_obj_ggtt_offset(obj); |
2108 | engine->status_page.page_addr = kmap(sg_page(obj->pages->sgl)); | |
2109 | memset(engine->status_page.page_addr, 0, PAGE_SIZE); | |
62fdfeaf | 2110 | |
8187a2b7 | 2111 | DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", |
0bc40be8 | 2112 | engine->name, engine->status_page.gfx_addr); |
62fdfeaf EA |
2113 | |
2114 | return 0; | |
62fdfeaf EA |
2115 | } |
2116 | ||
0bc40be8 | 2117 | static int init_phys_status_page(struct intel_engine_cs *engine) |
6b8294a4 | 2118 | { |
0bc40be8 | 2119 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
6b8294a4 CW |
2120 | |
2121 | if (!dev_priv->status_page_dmah) { | |
2122 | dev_priv->status_page_dmah = | |
0bc40be8 | 2123 | drm_pci_alloc(engine->dev, PAGE_SIZE, PAGE_SIZE); |
6b8294a4 CW |
2124 | if (!dev_priv->status_page_dmah) |
2125 | return -ENOMEM; | |
2126 | } | |
2127 | ||
0bc40be8 TU |
2128 | engine->status_page.page_addr = dev_priv->status_page_dmah->vaddr; |
2129 | memset(engine->status_page.page_addr, 0, PAGE_SIZE); | |
6b8294a4 CW |
2130 | |
2131 | return 0; | |
2132 | } | |
2133 | ||
7ba717cf | 2134 | void intel_unpin_ringbuffer_obj(struct intel_ringbuffer *ringbuf) |
2919d291 | 2135 | { |
3d77e9be CW |
2136 | GEM_BUG_ON(ringbuf->vma == NULL); |
2137 | GEM_BUG_ON(ringbuf->virtual_start == NULL); | |
2138 | ||
def0c5f6 | 2139 | if (HAS_LLC(ringbuf->obj->base.dev) && !ringbuf->obj->stolen) |
0a798eb9 | 2140 | i915_gem_object_unpin_map(ringbuf->obj); |
def0c5f6 | 2141 | else |
3d77e9be | 2142 | i915_vma_unpin_iomap(ringbuf->vma); |
8305216f | 2143 | ringbuf->virtual_start = NULL; |
3d77e9be | 2144 | |
2919d291 | 2145 | i915_gem_object_ggtt_unpin(ringbuf->obj); |
3d77e9be | 2146 | ringbuf->vma = NULL; |
7ba717cf TD |
2147 | } |
2148 | ||
2149 | int intel_pin_and_map_ringbuffer_obj(struct drm_device *dev, | |
2150 | struct intel_ringbuffer *ringbuf) | |
2151 | { | |
2152 | struct drm_i915_private *dev_priv = to_i915(dev); | |
2153 | struct drm_i915_gem_object *obj = ringbuf->obj; | |
a687a43a CW |
2154 | /* Ring wraparound at offset 0 sometimes hangs. No idea why. */ |
2155 | unsigned flags = PIN_OFFSET_BIAS | 4096; | |
8305216f | 2156 | void *addr; |
7ba717cf TD |
2157 | int ret; |
2158 | ||
def0c5f6 | 2159 | if (HAS_LLC(dev_priv) && !obj->stolen) { |
a687a43a | 2160 | ret = i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, flags); |
def0c5f6 CW |
2161 | if (ret) |
2162 | return ret; | |
7ba717cf | 2163 | |
def0c5f6 | 2164 | ret = i915_gem_object_set_to_cpu_domain(obj, true); |
d2cad535 CW |
2165 | if (ret) |
2166 | goto err_unpin; | |
def0c5f6 | 2167 | |
8305216f DG |
2168 | addr = i915_gem_object_pin_map(obj); |
2169 | if (IS_ERR(addr)) { | |
2170 | ret = PTR_ERR(addr); | |
d2cad535 | 2171 | goto err_unpin; |
def0c5f6 CW |
2172 | } |
2173 | } else { | |
a687a43a CW |
2174 | ret = i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, |
2175 | flags | PIN_MAPPABLE); | |
def0c5f6 CW |
2176 | if (ret) |
2177 | return ret; | |
7ba717cf | 2178 | |
def0c5f6 | 2179 | ret = i915_gem_object_set_to_gtt_domain(obj, true); |
d2cad535 CW |
2180 | if (ret) |
2181 | goto err_unpin; | |
def0c5f6 | 2182 | |
ff3dc087 DCS |
2183 | /* Access through the GTT requires the device to be awake. */ |
2184 | assert_rpm_wakelock_held(dev_priv); | |
2185 | ||
3d77e9be CW |
2186 | addr = i915_vma_pin_iomap(i915_gem_obj_to_ggtt(obj)); |
2187 | if (IS_ERR(addr)) { | |
2188 | ret = PTR_ERR(addr); | |
d2cad535 | 2189 | goto err_unpin; |
def0c5f6 | 2190 | } |
7ba717cf TD |
2191 | } |
2192 | ||
8305216f | 2193 | ringbuf->virtual_start = addr; |
0eb973d3 | 2194 | ringbuf->vma = i915_gem_obj_to_ggtt(obj); |
7ba717cf | 2195 | return 0; |
d2cad535 CW |
2196 | |
2197 | err_unpin: | |
2198 | i915_gem_object_ggtt_unpin(obj); | |
2199 | return ret; | |
7ba717cf TD |
2200 | } |
2201 | ||
01101fa7 | 2202 | static void intel_destroy_ringbuffer_obj(struct intel_ringbuffer *ringbuf) |
7ba717cf | 2203 | { |
2919d291 OM |
2204 | drm_gem_object_unreference(&ringbuf->obj->base); |
2205 | ringbuf->obj = NULL; | |
2206 | } | |
2207 | ||
01101fa7 CW |
2208 | static int intel_alloc_ringbuffer_obj(struct drm_device *dev, |
2209 | struct intel_ringbuffer *ringbuf) | |
62fdfeaf | 2210 | { |
05394f39 | 2211 | struct drm_i915_gem_object *obj; |
62fdfeaf | 2212 | |
ebc052e0 CW |
2213 | obj = NULL; |
2214 | if (!HAS_LLC(dev)) | |
93b0a4e0 | 2215 | obj = i915_gem_object_create_stolen(dev, ringbuf->size); |
ebc052e0 | 2216 | if (obj == NULL) |
d37cd8a8 | 2217 | obj = i915_gem_object_create(dev, ringbuf->size); |
fe3db79b CW |
2218 | if (IS_ERR(obj)) |
2219 | return PTR_ERR(obj); | |
8187a2b7 | 2220 | |
24f3a8cf AG |
2221 | /* mark ring buffers as read-only from GPU side by default */ |
2222 | obj->gt_ro = 1; | |
2223 | ||
93b0a4e0 | 2224 | ringbuf->obj = obj; |
e3efda49 | 2225 | |
7ba717cf | 2226 | return 0; |
e3efda49 CW |
2227 | } |
2228 | ||
01101fa7 CW |
2229 | struct intel_ringbuffer * |
2230 | intel_engine_create_ringbuffer(struct intel_engine_cs *engine, int size) | |
2231 | { | |
2232 | struct intel_ringbuffer *ring; | |
2233 | int ret; | |
2234 | ||
2235 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); | |
608c1a52 CW |
2236 | if (ring == NULL) { |
2237 | DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s\n", | |
2238 | engine->name); | |
01101fa7 | 2239 | return ERR_PTR(-ENOMEM); |
608c1a52 | 2240 | } |
01101fa7 | 2241 | |
4a570db5 | 2242 | ring->engine = engine; |
608c1a52 | 2243 | list_add(&ring->link, &engine->buffers); |
01101fa7 CW |
2244 | |
2245 | ring->size = size; | |
2246 | /* Workaround an erratum on the i830 which causes a hang if | |
2247 | * the TAIL pointer points to within the last 2 cachelines | |
2248 | * of the buffer. | |
2249 | */ | |
2250 | ring->effective_size = size; | |
2251 | if (IS_I830(engine->dev) || IS_845G(engine->dev)) | |
2252 | ring->effective_size -= 2 * CACHELINE_BYTES; | |
2253 | ||
2254 | ring->last_retired_head = -1; | |
2255 | intel_ring_update_space(ring); | |
2256 | ||
2257 | ret = intel_alloc_ringbuffer_obj(engine->dev, ring); | |
2258 | if (ret) { | |
608c1a52 CW |
2259 | DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s: %d\n", |
2260 | engine->name, ret); | |
2261 | list_del(&ring->link); | |
01101fa7 CW |
2262 | kfree(ring); |
2263 | return ERR_PTR(ret); | |
2264 | } | |
2265 | ||
2266 | return ring; | |
2267 | } | |
2268 | ||
2269 | void | |
2270 | intel_ringbuffer_free(struct intel_ringbuffer *ring) | |
2271 | { | |
2272 | intel_destroy_ringbuffer_obj(ring); | |
608c1a52 | 2273 | list_del(&ring->link); |
01101fa7 CW |
2274 | kfree(ring); |
2275 | } | |
2276 | ||
e3efda49 | 2277 | static int intel_init_ring_buffer(struct drm_device *dev, |
0bc40be8 | 2278 | struct intel_engine_cs *engine) |
e3efda49 | 2279 | { |
bfc882b4 | 2280 | struct intel_ringbuffer *ringbuf; |
e3efda49 CW |
2281 | int ret; |
2282 | ||
0bc40be8 | 2283 | WARN_ON(engine->buffer); |
bfc882b4 | 2284 | |
0bc40be8 TU |
2285 | engine->dev = dev; |
2286 | INIT_LIST_HEAD(&engine->active_list); | |
2287 | INIT_LIST_HEAD(&engine->request_list); | |
2288 | INIT_LIST_HEAD(&engine->execlist_queue); | |
2289 | INIT_LIST_HEAD(&engine->buffers); | |
2290 | i915_gem_batch_pool_init(dev, &engine->batch_pool); | |
2291 | memset(engine->semaphore.sync_seqno, 0, | |
2292 | sizeof(engine->semaphore.sync_seqno)); | |
e3efda49 | 2293 | |
0bc40be8 | 2294 | init_waitqueue_head(&engine->irq_queue); |
e3efda49 | 2295 | |
0bc40be8 | 2296 | ringbuf = intel_engine_create_ringbuffer(engine, 32 * PAGE_SIZE); |
b0366a54 DG |
2297 | if (IS_ERR(ringbuf)) { |
2298 | ret = PTR_ERR(ringbuf); | |
2299 | goto error; | |
2300 | } | |
0bc40be8 | 2301 | engine->buffer = ringbuf; |
01101fa7 | 2302 | |
e3efda49 | 2303 | if (I915_NEED_GFX_HWS(dev)) { |
0bc40be8 | 2304 | ret = init_status_page(engine); |
e3efda49 | 2305 | if (ret) |
8ee14975 | 2306 | goto error; |
e3efda49 | 2307 | } else { |
0bc40be8 TU |
2308 | WARN_ON(engine->id != RCS); |
2309 | ret = init_phys_status_page(engine); | |
e3efda49 | 2310 | if (ret) |
8ee14975 | 2311 | goto error; |
e3efda49 CW |
2312 | } |
2313 | ||
bfc882b4 DV |
2314 | ret = intel_pin_and_map_ringbuffer_obj(dev, ringbuf); |
2315 | if (ret) { | |
2316 | DRM_ERROR("Failed to pin and map ringbuffer %s: %d\n", | |
0bc40be8 | 2317 | engine->name, ret); |
bfc882b4 DV |
2318 | intel_destroy_ringbuffer_obj(ringbuf); |
2319 | goto error; | |
e3efda49 | 2320 | } |
62fdfeaf | 2321 | |
0bc40be8 | 2322 | ret = i915_cmd_parser_init_ring(engine); |
44e895a8 | 2323 | if (ret) |
8ee14975 OM |
2324 | goto error; |
2325 | ||
8ee14975 | 2326 | return 0; |
351e3db2 | 2327 | |
8ee14975 | 2328 | error: |
117897f4 | 2329 | intel_cleanup_engine(engine); |
8ee14975 | 2330 | return ret; |
62fdfeaf EA |
2331 | } |
2332 | ||
117897f4 | 2333 | void intel_cleanup_engine(struct intel_engine_cs *engine) |
62fdfeaf | 2334 | { |
6402c330 | 2335 | struct drm_i915_private *dev_priv; |
33626e6a | 2336 | |
117897f4 | 2337 | if (!intel_engine_initialized(engine)) |
62fdfeaf EA |
2338 | return; |
2339 | ||
0bc40be8 | 2340 | dev_priv = to_i915(engine->dev); |
6402c330 | 2341 | |
0bc40be8 | 2342 | if (engine->buffer) { |
117897f4 | 2343 | intel_stop_engine(engine); |
0bc40be8 | 2344 | WARN_ON(!IS_GEN2(engine->dev) && (I915_READ_MODE(engine) & MODE_IDLE) == 0); |
33626e6a | 2345 | |
0bc40be8 TU |
2346 | intel_unpin_ringbuffer_obj(engine->buffer); |
2347 | intel_ringbuffer_free(engine->buffer); | |
2348 | engine->buffer = NULL; | |
b0366a54 | 2349 | } |
78501eac | 2350 | |
0bc40be8 TU |
2351 | if (engine->cleanup) |
2352 | engine->cleanup(engine); | |
8d19215b | 2353 | |
0bc40be8 TU |
2354 | if (I915_NEED_GFX_HWS(engine->dev)) { |
2355 | cleanup_status_page(engine); | |
7d3fdfff | 2356 | } else { |
0bc40be8 TU |
2357 | WARN_ON(engine->id != RCS); |
2358 | cleanup_phys_status_page(engine); | |
7d3fdfff | 2359 | } |
44e895a8 | 2360 | |
0bc40be8 TU |
2361 | i915_cmd_parser_fini_ring(engine); |
2362 | i915_gem_batch_pool_fini(&engine->batch_pool); | |
2363 | engine->dev = NULL; | |
62fdfeaf EA |
2364 | } |
2365 | ||
666796da | 2366 | int intel_engine_idle(struct intel_engine_cs *engine) |
3e960501 | 2367 | { |
a4b3a571 | 2368 | struct drm_i915_gem_request *req; |
3e960501 | 2369 | |
3e960501 | 2370 | /* Wait upon the last request to be completed */ |
0bc40be8 | 2371 | if (list_empty(&engine->request_list)) |
3e960501 CW |
2372 | return 0; |
2373 | ||
0bc40be8 TU |
2374 | req = list_entry(engine->request_list.prev, |
2375 | struct drm_i915_gem_request, | |
2376 | list); | |
b4716185 CW |
2377 | |
2378 | /* Make sure we do not trigger any retires */ | |
2379 | return __i915_wait_request(req, | |
c19ae989 | 2380 | req->i915->mm.interruptible, |
b4716185 | 2381 | NULL, NULL); |
3e960501 CW |
2382 | } |
2383 | ||
6689cb2b | 2384 | int intel_ring_alloc_request_extras(struct drm_i915_gem_request *request) |
9d773091 | 2385 | { |
6310346e CW |
2386 | int ret; |
2387 | ||
2388 | /* Flush enough space to reduce the likelihood of waiting after | |
2389 | * we start building the request - in which case we will just | |
2390 | * have to repeat work. | |
2391 | */ | |
a0442461 | 2392 | request->reserved_space += LEGACY_REQUEST_SIZE; |
6310346e | 2393 | |
4a570db5 | 2394 | request->ringbuf = request->engine->buffer; |
6310346e CW |
2395 | |
2396 | ret = intel_ring_begin(request, 0); | |
2397 | if (ret) | |
2398 | return ret; | |
2399 | ||
a0442461 | 2400 | request->reserved_space -= LEGACY_REQUEST_SIZE; |
6310346e | 2401 | return 0; |
9d773091 CW |
2402 | } |
2403 | ||
987046ad CW |
2404 | static int wait_for_space(struct drm_i915_gem_request *req, int bytes) |
2405 | { | |
2406 | struct intel_ringbuffer *ringbuf = req->ringbuf; | |
2407 | struct intel_engine_cs *engine = req->engine; | |
2408 | struct drm_i915_gem_request *target; | |
2409 | ||
2410 | intel_ring_update_space(ringbuf); | |
2411 | if (ringbuf->space >= bytes) | |
2412 | return 0; | |
2413 | ||
2414 | /* | |
2415 | * Space is reserved in the ringbuffer for finalising the request, | |
2416 | * as that cannot be allowed to fail. During request finalisation, | |
2417 | * reserved_space is set to 0 to stop the overallocation and the | |
2418 | * assumption is that then we never need to wait (which has the | |
2419 | * risk of failing with EINTR). | |
2420 | * | |
2421 | * See also i915_gem_request_alloc() and i915_add_request(). | |
2422 | */ | |
0251a963 | 2423 | GEM_BUG_ON(!req->reserved_space); |
987046ad CW |
2424 | |
2425 | list_for_each_entry(target, &engine->request_list, list) { | |
2426 | unsigned space; | |
2427 | ||
79bbcc29 | 2428 | /* |
987046ad CW |
2429 | * The request queue is per-engine, so can contain requests |
2430 | * from multiple ringbuffers. Here, we must ignore any that | |
2431 | * aren't from the ringbuffer we're considering. | |
79bbcc29 | 2432 | */ |
987046ad CW |
2433 | if (target->ringbuf != ringbuf) |
2434 | continue; | |
2435 | ||
2436 | /* Would completion of this request free enough space? */ | |
2437 | space = __intel_ring_space(target->postfix, ringbuf->tail, | |
2438 | ringbuf->size); | |
2439 | if (space >= bytes) | |
2440 | break; | |
79bbcc29 | 2441 | } |
29b1b415 | 2442 | |
987046ad CW |
2443 | if (WARN_ON(&target->list == &engine->request_list)) |
2444 | return -ENOSPC; | |
2445 | ||
2446 | return i915_wait_request(target); | |
29b1b415 JH |
2447 | } |
2448 | ||
987046ad | 2449 | int intel_ring_begin(struct drm_i915_gem_request *req, int num_dwords) |
cbcc80df | 2450 | { |
987046ad | 2451 | struct intel_ringbuffer *ringbuf = req->ringbuf; |
79bbcc29 | 2452 | int remain_actual = ringbuf->size - ringbuf->tail; |
987046ad CW |
2453 | int remain_usable = ringbuf->effective_size - ringbuf->tail; |
2454 | int bytes = num_dwords * sizeof(u32); | |
2455 | int total_bytes, wait_bytes; | |
79bbcc29 | 2456 | bool need_wrap = false; |
29b1b415 | 2457 | |
0251a963 | 2458 | total_bytes = bytes + req->reserved_space; |
29b1b415 | 2459 | |
79bbcc29 JH |
2460 | if (unlikely(bytes > remain_usable)) { |
2461 | /* | |
2462 | * Not enough space for the basic request. So need to flush | |
2463 | * out the remainder and then wait for base + reserved. | |
2464 | */ | |
2465 | wait_bytes = remain_actual + total_bytes; | |
2466 | need_wrap = true; | |
987046ad CW |
2467 | } else if (unlikely(total_bytes > remain_usable)) { |
2468 | /* | |
2469 | * The base request will fit but the reserved space | |
2470 | * falls off the end. So we don't need an immediate wrap | |
2471 | * and only need to effectively wait for the reserved | |
2472 | * size space from the start of ringbuffer. | |
2473 | */ | |
0251a963 | 2474 | wait_bytes = remain_actual + req->reserved_space; |
79bbcc29 | 2475 | } else { |
987046ad CW |
2476 | /* No wrapping required, just waiting. */ |
2477 | wait_bytes = total_bytes; | |
cbcc80df MK |
2478 | } |
2479 | ||
987046ad CW |
2480 | if (wait_bytes > ringbuf->space) { |
2481 | int ret = wait_for_space(req, wait_bytes); | |
cbcc80df MK |
2482 | if (unlikely(ret)) |
2483 | return ret; | |
79bbcc29 | 2484 | |
987046ad | 2485 | intel_ring_update_space(ringbuf); |
cbcc80df MK |
2486 | } |
2487 | ||
987046ad CW |
2488 | if (unlikely(need_wrap)) { |
2489 | GEM_BUG_ON(remain_actual > ringbuf->space); | |
2490 | GEM_BUG_ON(ringbuf->tail + remain_actual > ringbuf->size); | |
78501eac | 2491 | |
987046ad CW |
2492 | /* Fill the tail with MI_NOOP */ |
2493 | memset(ringbuf->virtual_start + ringbuf->tail, | |
2494 | 0, remain_actual); | |
2495 | ringbuf->tail = 0; | |
2496 | ringbuf->space -= remain_actual; | |
2497 | } | |
304d695c | 2498 | |
987046ad CW |
2499 | ringbuf->space -= bytes; |
2500 | GEM_BUG_ON(ringbuf->space < 0); | |
304d695c | 2501 | return 0; |
8187a2b7 | 2502 | } |
78501eac | 2503 | |
753b1ad4 | 2504 | /* Align the ring tail to a cacheline boundary */ |
bba09b12 | 2505 | int intel_ring_cacheline_align(struct drm_i915_gem_request *req) |
753b1ad4 | 2506 | { |
4a570db5 | 2507 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 2508 | int num_dwords = (engine->buffer->tail & (CACHELINE_BYTES - 1)) / sizeof(uint32_t); |
753b1ad4 VS |
2509 | int ret; |
2510 | ||
2511 | if (num_dwords == 0) | |
2512 | return 0; | |
2513 | ||
18393f63 | 2514 | num_dwords = CACHELINE_BYTES / sizeof(uint32_t) - num_dwords; |
5fb9de1a | 2515 | ret = intel_ring_begin(req, num_dwords); |
753b1ad4 VS |
2516 | if (ret) |
2517 | return ret; | |
2518 | ||
2519 | while (num_dwords--) | |
e2f80391 | 2520 | intel_ring_emit(engine, MI_NOOP); |
753b1ad4 | 2521 | |
e2f80391 | 2522 | intel_ring_advance(engine); |
753b1ad4 VS |
2523 | |
2524 | return 0; | |
2525 | } | |
2526 | ||
0bc40be8 | 2527 | void intel_ring_init_seqno(struct intel_engine_cs *engine, u32 seqno) |
498d2ac1 | 2528 | { |
d04bce48 | 2529 | struct drm_i915_private *dev_priv = to_i915(engine->dev); |
498d2ac1 | 2530 | |
29dcb570 CW |
2531 | /* Our semaphore implementation is strictly monotonic (i.e. we proceed |
2532 | * so long as the semaphore value in the register/page is greater | |
2533 | * than the sync value), so whenever we reset the seqno, | |
2534 | * so long as we reset the tracking semaphore value to 0, it will | |
2535 | * always be before the next request's seqno. If we don't reset | |
2536 | * the semaphore value, then when the seqno moves backwards all | |
2537 | * future waits will complete instantly (causing rendering corruption). | |
2538 | */ | |
d04bce48 | 2539 | if (INTEL_INFO(dev_priv)->gen == 6 || INTEL_INFO(dev_priv)->gen == 7) { |
0bc40be8 TU |
2540 | I915_WRITE(RING_SYNC_0(engine->mmio_base), 0); |
2541 | I915_WRITE(RING_SYNC_1(engine->mmio_base), 0); | |
d04bce48 | 2542 | if (HAS_VEBOX(dev_priv)) |
0bc40be8 | 2543 | I915_WRITE(RING_SYNC_2(engine->mmio_base), 0); |
e1f99ce6 | 2544 | } |
a058d934 CW |
2545 | if (dev_priv->semaphore_obj) { |
2546 | struct drm_i915_gem_object *obj = dev_priv->semaphore_obj; | |
2547 | struct page *page = i915_gem_object_get_dirty_page(obj, 0); | |
2548 | void *semaphores = kmap(page); | |
2549 | memset(semaphores + GEN8_SEMAPHORE_OFFSET(engine->id, 0), | |
2550 | 0, I915_NUM_ENGINES * gen8_semaphore_seqno_size); | |
2551 | kunmap(page); | |
2552 | } | |
29dcb570 CW |
2553 | memset(engine->semaphore.sync_seqno, 0, |
2554 | sizeof(engine->semaphore.sync_seqno)); | |
d97ed339 | 2555 | |
0bc40be8 | 2556 | engine->set_seqno(engine, seqno); |
01347126 | 2557 | engine->last_submitted_seqno = seqno; |
29dcb570 | 2558 | |
0bc40be8 | 2559 | engine->hangcheck.seqno = seqno; |
8187a2b7 | 2560 | } |
62fdfeaf | 2561 | |
0bc40be8 | 2562 | static void gen6_bsd_ring_write_tail(struct intel_engine_cs *engine, |
297b0c5b | 2563 | u32 value) |
881f47b6 | 2564 | { |
0bc40be8 | 2565 | struct drm_i915_private *dev_priv = engine->dev->dev_private; |
881f47b6 XH |
2566 | |
2567 | /* Every tail move must follow the sequence below */ | |
12f55818 CW |
2568 | |
2569 | /* Disable notification that the ring is IDLE. The GT | |
2570 | * will then assume that it is busy and bring it out of rc6. | |
2571 | */ | |
0206e353 | 2572 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
12f55818 CW |
2573 | _MASKED_BIT_ENABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
2574 | ||
2575 | /* Clear the context id. Here be magic! */ | |
2576 | I915_WRITE64(GEN6_BSD_RNCID, 0x0); | |
0206e353 | 2577 | |
12f55818 | 2578 | /* Wait for the ring not to be idle, i.e. for it to wake up. */ |
0206e353 | 2579 | if (wait_for((I915_READ(GEN6_BSD_SLEEP_PSMI_CONTROL) & |
12f55818 CW |
2580 | GEN6_BSD_SLEEP_INDICATOR) == 0, |
2581 | 50)) | |
2582 | DRM_ERROR("timed out waiting for the BSD ring to wake up\n"); | |
0206e353 | 2583 | |
12f55818 | 2584 | /* Now that the ring is fully powered up, update the tail */ |
0bc40be8 TU |
2585 | I915_WRITE_TAIL(engine, value); |
2586 | POSTING_READ(RING_TAIL(engine->mmio_base)); | |
12f55818 CW |
2587 | |
2588 | /* Let the ring send IDLE messages to the GT again, | |
2589 | * and so let it sleep to conserve power when idle. | |
2590 | */ | |
0206e353 | 2591 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
12f55818 | 2592 | _MASKED_BIT_DISABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
881f47b6 XH |
2593 | } |
2594 | ||
a84c3ae1 | 2595 | static int gen6_bsd_ring_flush(struct drm_i915_gem_request *req, |
ea251324 | 2596 | u32 invalidate, u32 flush) |
881f47b6 | 2597 | { |
4a570db5 | 2598 | struct intel_engine_cs *engine = req->engine; |
71a77e07 | 2599 | uint32_t cmd; |
b72f3acb CW |
2600 | int ret; |
2601 | ||
5fb9de1a | 2602 | ret = intel_ring_begin(req, 4); |
b72f3acb CW |
2603 | if (ret) |
2604 | return ret; | |
2605 | ||
71a77e07 | 2606 | cmd = MI_FLUSH_DW; |
e2f80391 | 2607 | if (INTEL_INFO(engine->dev)->gen >= 8) |
075b3bba | 2608 | cmd += 1; |
f0a1fb10 CW |
2609 | |
2610 | /* We always require a command barrier so that subsequent | |
2611 | * commands, such as breadcrumb interrupts, are strictly ordered | |
2612 | * wrt the contents of the write cache being flushed to memory | |
2613 | * (and thus being coherent from the CPU). | |
2614 | */ | |
2615 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; | |
2616 | ||
9a289771 JB |
2617 | /* |
2618 | * Bspec vol 1c.5 - video engine command streamer: | |
2619 | * "If ENABLED, all TLBs will be invalidated once the flush | |
2620 | * operation is complete. This bit is only valid when the | |
2621 | * Post-Sync Operation field is a value of 1h or 3h." | |
2622 | */ | |
71a77e07 | 2623 | if (invalidate & I915_GEM_GPU_DOMAINS) |
f0a1fb10 CW |
2624 | cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD; |
2625 | ||
e2f80391 TU |
2626 | intel_ring_emit(engine, cmd); |
2627 | intel_ring_emit(engine, | |
2628 | I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT); | |
2629 | if (INTEL_INFO(engine->dev)->gen >= 8) { | |
2630 | intel_ring_emit(engine, 0); /* upper addr */ | |
2631 | intel_ring_emit(engine, 0); /* value */ | |
075b3bba | 2632 | } else { |
e2f80391 TU |
2633 | intel_ring_emit(engine, 0); |
2634 | intel_ring_emit(engine, MI_NOOP); | |
075b3bba | 2635 | } |
e2f80391 | 2636 | intel_ring_advance(engine); |
b72f3acb | 2637 | return 0; |
881f47b6 XH |
2638 | } |
2639 | ||
1c7a0623 | 2640 | static int |
53fddaf7 | 2641 | gen8_ring_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 2642 | u64 offset, u32 len, |
8e004efc | 2643 | unsigned dispatch_flags) |
1c7a0623 | 2644 | { |
4a570db5 | 2645 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 2646 | bool ppgtt = USES_PPGTT(engine->dev) && |
8e004efc | 2647 | !(dispatch_flags & I915_DISPATCH_SECURE); |
1c7a0623 BW |
2648 | int ret; |
2649 | ||
5fb9de1a | 2650 | ret = intel_ring_begin(req, 4); |
1c7a0623 BW |
2651 | if (ret) |
2652 | return ret; | |
2653 | ||
2654 | /* FIXME(BDW): Address space and security selectors. */ | |
e2f80391 | 2655 | intel_ring_emit(engine, MI_BATCH_BUFFER_START_GEN8 | (ppgtt<<8) | |
919032ec AJ |
2656 | (dispatch_flags & I915_DISPATCH_RS ? |
2657 | MI_BATCH_RESOURCE_STREAMER : 0)); | |
e2f80391 TU |
2658 | intel_ring_emit(engine, lower_32_bits(offset)); |
2659 | intel_ring_emit(engine, upper_32_bits(offset)); | |
2660 | intel_ring_emit(engine, MI_NOOP); | |
2661 | intel_ring_advance(engine); | |
1c7a0623 BW |
2662 | |
2663 | return 0; | |
2664 | } | |
2665 | ||
d7d4eedd | 2666 | static int |
53fddaf7 | 2667 | hsw_ring_dispatch_execbuffer(struct drm_i915_gem_request *req, |
8e004efc JH |
2668 | u64 offset, u32 len, |
2669 | unsigned dispatch_flags) | |
d7d4eedd | 2670 | { |
4a570db5 | 2671 | struct intel_engine_cs *engine = req->engine; |
d7d4eedd CW |
2672 | int ret; |
2673 | ||
5fb9de1a | 2674 | ret = intel_ring_begin(req, 2); |
d7d4eedd CW |
2675 | if (ret) |
2676 | return ret; | |
2677 | ||
e2f80391 | 2678 | intel_ring_emit(engine, |
77072258 | 2679 | MI_BATCH_BUFFER_START | |
8e004efc | 2680 | (dispatch_flags & I915_DISPATCH_SECURE ? |
919032ec AJ |
2681 | 0 : MI_BATCH_PPGTT_HSW | MI_BATCH_NON_SECURE_HSW) | |
2682 | (dispatch_flags & I915_DISPATCH_RS ? | |
2683 | MI_BATCH_RESOURCE_STREAMER : 0)); | |
d7d4eedd | 2684 | /* bit0-7 is the length on GEN6+ */ |
e2f80391 TU |
2685 | intel_ring_emit(engine, offset); |
2686 | intel_ring_advance(engine); | |
d7d4eedd CW |
2687 | |
2688 | return 0; | |
2689 | } | |
2690 | ||
881f47b6 | 2691 | static int |
53fddaf7 | 2692 | gen6_ring_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 2693 | u64 offset, u32 len, |
8e004efc | 2694 | unsigned dispatch_flags) |
881f47b6 | 2695 | { |
4a570db5 | 2696 | struct intel_engine_cs *engine = req->engine; |
0206e353 | 2697 | int ret; |
ab6f8e32 | 2698 | |
5fb9de1a | 2699 | ret = intel_ring_begin(req, 2); |
0206e353 AJ |
2700 | if (ret) |
2701 | return ret; | |
e1f99ce6 | 2702 | |
e2f80391 | 2703 | intel_ring_emit(engine, |
d7d4eedd | 2704 | MI_BATCH_BUFFER_START | |
8e004efc JH |
2705 | (dispatch_flags & I915_DISPATCH_SECURE ? |
2706 | 0 : MI_BATCH_NON_SECURE_I965)); | |
0206e353 | 2707 | /* bit0-7 is the length on GEN6+ */ |
e2f80391 TU |
2708 | intel_ring_emit(engine, offset); |
2709 | intel_ring_advance(engine); | |
ab6f8e32 | 2710 | |
0206e353 | 2711 | return 0; |
881f47b6 XH |
2712 | } |
2713 | ||
549f7365 CW |
2714 | /* Blitter support (SandyBridge+) */ |
2715 | ||
a84c3ae1 | 2716 | static int gen6_ring_flush(struct drm_i915_gem_request *req, |
ea251324 | 2717 | u32 invalidate, u32 flush) |
8d19215b | 2718 | { |
4a570db5 | 2719 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 2720 | struct drm_device *dev = engine->dev; |
71a77e07 | 2721 | uint32_t cmd; |
b72f3acb CW |
2722 | int ret; |
2723 | ||
5fb9de1a | 2724 | ret = intel_ring_begin(req, 4); |
b72f3acb CW |
2725 | if (ret) |
2726 | return ret; | |
2727 | ||
71a77e07 | 2728 | cmd = MI_FLUSH_DW; |
dbef0f15 | 2729 | if (INTEL_INFO(dev)->gen >= 8) |
075b3bba | 2730 | cmd += 1; |
f0a1fb10 CW |
2731 | |
2732 | /* We always require a command barrier so that subsequent | |
2733 | * commands, such as breadcrumb interrupts, are strictly ordered | |
2734 | * wrt the contents of the write cache being flushed to memory | |
2735 | * (and thus being coherent from the CPU). | |
2736 | */ | |
2737 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; | |
2738 | ||
9a289771 JB |
2739 | /* |
2740 | * Bspec vol 1c.3 - blitter engine command streamer: | |
2741 | * "If ENABLED, all TLBs will be invalidated once the flush | |
2742 | * operation is complete. This bit is only valid when the | |
2743 | * Post-Sync Operation field is a value of 1h or 3h." | |
2744 | */ | |
71a77e07 | 2745 | if (invalidate & I915_GEM_DOMAIN_RENDER) |
f0a1fb10 | 2746 | cmd |= MI_INVALIDATE_TLB; |
e2f80391 TU |
2747 | intel_ring_emit(engine, cmd); |
2748 | intel_ring_emit(engine, | |
2749 | I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT); | |
dbef0f15 | 2750 | if (INTEL_INFO(dev)->gen >= 8) { |
e2f80391 TU |
2751 | intel_ring_emit(engine, 0); /* upper addr */ |
2752 | intel_ring_emit(engine, 0); /* value */ | |
075b3bba | 2753 | } else { |
e2f80391 TU |
2754 | intel_ring_emit(engine, 0); |
2755 | intel_ring_emit(engine, MI_NOOP); | |
075b3bba | 2756 | } |
e2f80391 | 2757 | intel_ring_advance(engine); |
fd3da6c9 | 2758 | |
b72f3acb | 2759 | return 0; |
8d19215b ZN |
2760 | } |
2761 | ||
5c1143bb XH |
2762 | int intel_init_render_ring_buffer(struct drm_device *dev) |
2763 | { | |
4640c4ff | 2764 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 2765 | struct intel_engine_cs *engine = &dev_priv->engine[RCS]; |
3e78998a BW |
2766 | struct drm_i915_gem_object *obj; |
2767 | int ret; | |
5c1143bb | 2768 | |
e2f80391 TU |
2769 | engine->name = "render ring"; |
2770 | engine->id = RCS; | |
2771 | engine->exec_id = I915_EXEC_RENDER; | |
215a7e32 | 2772 | engine->hw_id = 0; |
e2f80391 | 2773 | engine->mmio_base = RENDER_RING_BASE; |
59465b5f | 2774 | |
707d9cf9 | 2775 | if (INTEL_INFO(dev)->gen >= 8) { |
3e78998a | 2776 | if (i915_semaphore_is_enabled(dev)) { |
d37cd8a8 | 2777 | obj = i915_gem_object_create(dev, 4096); |
fe3db79b | 2778 | if (IS_ERR(obj)) { |
3e78998a BW |
2779 | DRM_ERROR("Failed to allocate semaphore bo. Disabling semaphores\n"); |
2780 | i915.semaphores = 0; | |
2781 | } else { | |
2782 | i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); | |
2783 | ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_NONBLOCK); | |
2784 | if (ret != 0) { | |
2785 | drm_gem_object_unreference(&obj->base); | |
2786 | DRM_ERROR("Failed to pin semaphore bo. Disabling semaphores\n"); | |
2787 | i915.semaphores = 0; | |
2788 | } else | |
2789 | dev_priv->semaphore_obj = obj; | |
2790 | } | |
2791 | } | |
7225342a | 2792 | |
e2f80391 | 2793 | engine->init_context = intel_rcs_ctx_init; |
a58c01aa | 2794 | engine->add_request = gen8_render_add_request; |
e2f80391 TU |
2795 | engine->flush = gen8_render_ring_flush; |
2796 | engine->irq_get = gen8_ring_get_irq; | |
2797 | engine->irq_put = gen8_ring_put_irq; | |
2798 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT; | |
c04e0f3b | 2799 | engine->get_seqno = ring_get_seqno; |
e2f80391 | 2800 | engine->set_seqno = ring_set_seqno; |
707d9cf9 | 2801 | if (i915_semaphore_is_enabled(dev)) { |
3e78998a | 2802 | WARN_ON(!dev_priv->semaphore_obj); |
e2f80391 TU |
2803 | engine->semaphore.sync_to = gen8_ring_sync; |
2804 | engine->semaphore.signal = gen8_rcs_signal; | |
2805 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 BW |
2806 | } |
2807 | } else if (INTEL_INFO(dev)->gen >= 6) { | |
e2f80391 TU |
2808 | engine->init_context = intel_rcs_ctx_init; |
2809 | engine->add_request = gen6_add_request; | |
2810 | engine->flush = gen7_render_ring_flush; | |
6c6cf5aa | 2811 | if (INTEL_INFO(dev)->gen == 6) |
e2f80391 TU |
2812 | engine->flush = gen6_render_ring_flush; |
2813 | engine->irq_get = gen6_ring_get_irq; | |
2814 | engine->irq_put = gen6_ring_put_irq; | |
2815 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT; | |
c04e0f3b CW |
2816 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
2817 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 2818 | engine->set_seqno = ring_set_seqno; |
707d9cf9 | 2819 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
2820 | engine->semaphore.sync_to = gen6_ring_sync; |
2821 | engine->semaphore.signal = gen6_signal; | |
707d9cf9 BW |
2822 | /* |
2823 | * The current semaphore is only applied on pre-gen8 | |
2824 | * platform. And there is no VCS2 ring on the pre-gen8 | |
2825 | * platform. So the semaphore between RCS and VCS2 is | |
2826 | * initialized as INVALID. Gen8 will initialize the | |
2827 | * sema between VCS2 and RCS later. | |
2828 | */ | |
e2f80391 TU |
2829 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_INVALID; |
2830 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_RV; | |
2831 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_RB; | |
2832 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_RVE; | |
2833 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
2834 | engine->semaphore.mbox.signal[RCS] = GEN6_NOSYNC; | |
2835 | engine->semaphore.mbox.signal[VCS] = GEN6_VRSYNC; | |
2836 | engine->semaphore.mbox.signal[BCS] = GEN6_BRSYNC; | |
2837 | engine->semaphore.mbox.signal[VECS] = GEN6_VERSYNC; | |
2838 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 2839 | } |
c6df541c | 2840 | } else if (IS_GEN5(dev)) { |
e2f80391 TU |
2841 | engine->add_request = pc_render_add_request; |
2842 | engine->flush = gen4_render_ring_flush; | |
2843 | engine->get_seqno = pc_render_get_seqno; | |
2844 | engine->set_seqno = pc_render_set_seqno; | |
2845 | engine->irq_get = gen5_ring_get_irq; | |
2846 | engine->irq_put = gen5_ring_put_irq; | |
2847 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT | | |
cc609d5d | 2848 | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT; |
59465b5f | 2849 | } else { |
e2f80391 | 2850 | engine->add_request = i9xx_add_request; |
46f0f8d1 | 2851 | if (INTEL_INFO(dev)->gen < 4) |
e2f80391 | 2852 | engine->flush = gen2_render_ring_flush; |
46f0f8d1 | 2853 | else |
e2f80391 TU |
2854 | engine->flush = gen4_render_ring_flush; |
2855 | engine->get_seqno = ring_get_seqno; | |
2856 | engine->set_seqno = ring_set_seqno; | |
c2798b19 | 2857 | if (IS_GEN2(dev)) { |
e2f80391 TU |
2858 | engine->irq_get = i8xx_ring_get_irq; |
2859 | engine->irq_put = i8xx_ring_put_irq; | |
c2798b19 | 2860 | } else { |
e2f80391 TU |
2861 | engine->irq_get = i9xx_ring_get_irq; |
2862 | engine->irq_put = i9xx_ring_put_irq; | |
c2798b19 | 2863 | } |
e2f80391 | 2864 | engine->irq_enable_mask = I915_USER_INTERRUPT; |
1ec14ad3 | 2865 | } |
e2f80391 | 2866 | engine->write_tail = ring_write_tail; |
707d9cf9 | 2867 | |
d7d4eedd | 2868 | if (IS_HASWELL(dev)) |
e2f80391 | 2869 | engine->dispatch_execbuffer = hsw_ring_dispatch_execbuffer; |
1c7a0623 | 2870 | else if (IS_GEN8(dev)) |
e2f80391 | 2871 | engine->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; |
d7d4eedd | 2872 | else if (INTEL_INFO(dev)->gen >= 6) |
e2f80391 | 2873 | engine->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; |
fb3256da | 2874 | else if (INTEL_INFO(dev)->gen >= 4) |
e2f80391 | 2875 | engine->dispatch_execbuffer = i965_dispatch_execbuffer; |
fb3256da | 2876 | else if (IS_I830(dev) || IS_845G(dev)) |
e2f80391 | 2877 | engine->dispatch_execbuffer = i830_dispatch_execbuffer; |
fb3256da | 2878 | else |
e2f80391 TU |
2879 | engine->dispatch_execbuffer = i915_dispatch_execbuffer; |
2880 | engine->init_hw = init_render_ring; | |
2881 | engine->cleanup = render_ring_cleanup; | |
59465b5f | 2882 | |
b45305fc DV |
2883 | /* Workaround batchbuffer to combat CS tlb bug. */ |
2884 | if (HAS_BROKEN_CS_TLB(dev)) { | |
d37cd8a8 | 2885 | obj = i915_gem_object_create(dev, I830_WA_SIZE); |
fe3db79b | 2886 | if (IS_ERR(obj)) { |
b45305fc | 2887 | DRM_ERROR("Failed to allocate batch bo\n"); |
fe3db79b | 2888 | return PTR_ERR(obj); |
b45305fc DV |
2889 | } |
2890 | ||
be1fa129 | 2891 | ret = i915_gem_obj_ggtt_pin(obj, 0, 0); |
b45305fc DV |
2892 | if (ret != 0) { |
2893 | drm_gem_object_unreference(&obj->base); | |
2894 | DRM_ERROR("Failed to ping batch bo\n"); | |
2895 | return ret; | |
2896 | } | |
2897 | ||
e2f80391 TU |
2898 | engine->scratch.obj = obj; |
2899 | engine->scratch.gtt_offset = i915_gem_obj_ggtt_offset(obj); | |
b45305fc DV |
2900 | } |
2901 | ||
e2f80391 | 2902 | ret = intel_init_ring_buffer(dev, engine); |
99be1dfe DV |
2903 | if (ret) |
2904 | return ret; | |
2905 | ||
2906 | if (INTEL_INFO(dev)->gen >= 5) { | |
e2f80391 | 2907 | ret = intel_init_pipe_control(engine); |
99be1dfe DV |
2908 | if (ret) |
2909 | return ret; | |
2910 | } | |
2911 | ||
2912 | return 0; | |
5c1143bb XH |
2913 | } |
2914 | ||
2915 | int intel_init_bsd_ring_buffer(struct drm_device *dev) | |
2916 | { | |
4640c4ff | 2917 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 2918 | struct intel_engine_cs *engine = &dev_priv->engine[VCS]; |
5c1143bb | 2919 | |
e2f80391 TU |
2920 | engine->name = "bsd ring"; |
2921 | engine->id = VCS; | |
2922 | engine->exec_id = I915_EXEC_BSD; | |
215a7e32 | 2923 | engine->hw_id = 1; |
58fa3835 | 2924 | |
e2f80391 | 2925 | engine->write_tail = ring_write_tail; |
780f18c8 | 2926 | if (INTEL_INFO(dev)->gen >= 6) { |
e2f80391 | 2927 | engine->mmio_base = GEN6_BSD_RING_BASE; |
0fd2c201 DV |
2928 | /* gen6 bsd needs a special wa for tail updates */ |
2929 | if (IS_GEN6(dev)) | |
e2f80391 TU |
2930 | engine->write_tail = gen6_bsd_ring_write_tail; |
2931 | engine->flush = gen6_bsd_ring_flush; | |
2932 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
2933 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
2934 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 2935 | engine->set_seqno = ring_set_seqno; |
abd58f01 | 2936 | if (INTEL_INFO(dev)->gen >= 8) { |
e2f80391 | 2937 | engine->irq_enable_mask = |
abd58f01 | 2938 | GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT; |
e2f80391 TU |
2939 | engine->irq_get = gen8_ring_get_irq; |
2940 | engine->irq_put = gen8_ring_put_irq; | |
2941 | engine->dispatch_execbuffer = | |
1c7a0623 | 2942 | gen8_ring_dispatch_execbuffer; |
707d9cf9 | 2943 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
2944 | engine->semaphore.sync_to = gen8_ring_sync; |
2945 | engine->semaphore.signal = gen8_xcs_signal; | |
2946 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 | 2947 | } |
abd58f01 | 2948 | } else { |
e2f80391 TU |
2949 | engine->irq_enable_mask = GT_BSD_USER_INTERRUPT; |
2950 | engine->irq_get = gen6_ring_get_irq; | |
2951 | engine->irq_put = gen6_ring_put_irq; | |
2952 | engine->dispatch_execbuffer = | |
1c7a0623 | 2953 | gen6_ring_dispatch_execbuffer; |
707d9cf9 | 2954 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
2955 | engine->semaphore.sync_to = gen6_ring_sync; |
2956 | engine->semaphore.signal = gen6_signal; | |
2957 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_VR; | |
2958 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_INVALID; | |
2959 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_VB; | |
2960 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_VVE; | |
2961 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
2962 | engine->semaphore.mbox.signal[RCS] = GEN6_RVSYNC; | |
2963 | engine->semaphore.mbox.signal[VCS] = GEN6_NOSYNC; | |
2964 | engine->semaphore.mbox.signal[BCS] = GEN6_BVSYNC; | |
2965 | engine->semaphore.mbox.signal[VECS] = GEN6_VEVSYNC; | |
2966 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 2967 | } |
abd58f01 | 2968 | } |
58fa3835 | 2969 | } else { |
e2f80391 TU |
2970 | engine->mmio_base = BSD_RING_BASE; |
2971 | engine->flush = bsd_ring_flush; | |
2972 | engine->add_request = i9xx_add_request; | |
2973 | engine->get_seqno = ring_get_seqno; | |
2974 | engine->set_seqno = ring_set_seqno; | |
e48d8634 | 2975 | if (IS_GEN5(dev)) { |
e2f80391 TU |
2976 | engine->irq_enable_mask = ILK_BSD_USER_INTERRUPT; |
2977 | engine->irq_get = gen5_ring_get_irq; | |
2978 | engine->irq_put = gen5_ring_put_irq; | |
e48d8634 | 2979 | } else { |
e2f80391 TU |
2980 | engine->irq_enable_mask = I915_BSD_USER_INTERRUPT; |
2981 | engine->irq_get = i9xx_ring_get_irq; | |
2982 | engine->irq_put = i9xx_ring_put_irq; | |
e48d8634 | 2983 | } |
e2f80391 | 2984 | engine->dispatch_execbuffer = i965_dispatch_execbuffer; |
58fa3835 | 2985 | } |
e2f80391 | 2986 | engine->init_hw = init_ring_common; |
58fa3835 | 2987 | |
e2f80391 | 2988 | return intel_init_ring_buffer(dev, engine); |
5c1143bb | 2989 | } |
549f7365 | 2990 | |
845f74a7 | 2991 | /** |
62659920 | 2992 | * Initialize the second BSD ring (eg. Broadwell GT3, Skylake GT3) |
845f74a7 ZY |
2993 | */ |
2994 | int intel_init_bsd2_ring_buffer(struct drm_device *dev) | |
2995 | { | |
2996 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4a570db5 | 2997 | struct intel_engine_cs *engine = &dev_priv->engine[VCS2]; |
e2f80391 TU |
2998 | |
2999 | engine->name = "bsd2 ring"; | |
3000 | engine->id = VCS2; | |
3001 | engine->exec_id = I915_EXEC_BSD; | |
215a7e32 | 3002 | engine->hw_id = 4; |
e2f80391 TU |
3003 | |
3004 | engine->write_tail = ring_write_tail; | |
3005 | engine->mmio_base = GEN8_BSD2_RING_BASE; | |
3006 | engine->flush = gen6_bsd_ring_flush; | |
3007 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
3008 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
3009 | engine->get_seqno = ring_get_seqno; | |
e2f80391 TU |
3010 | engine->set_seqno = ring_set_seqno; |
3011 | engine->irq_enable_mask = | |
845f74a7 | 3012 | GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT; |
e2f80391 TU |
3013 | engine->irq_get = gen8_ring_get_irq; |
3014 | engine->irq_put = gen8_ring_put_irq; | |
3015 | engine->dispatch_execbuffer = | |
845f74a7 | 3016 | gen8_ring_dispatch_execbuffer; |
3e78998a | 3017 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
3018 | engine->semaphore.sync_to = gen8_ring_sync; |
3019 | engine->semaphore.signal = gen8_xcs_signal; | |
3020 | GEN8_RING_SEMAPHORE_INIT(engine); | |
3e78998a | 3021 | } |
e2f80391 | 3022 | engine->init_hw = init_ring_common; |
845f74a7 | 3023 | |
e2f80391 | 3024 | return intel_init_ring_buffer(dev, engine); |
845f74a7 ZY |
3025 | } |
3026 | ||
549f7365 CW |
3027 | int intel_init_blt_ring_buffer(struct drm_device *dev) |
3028 | { | |
4640c4ff | 3029 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 3030 | struct intel_engine_cs *engine = &dev_priv->engine[BCS]; |
e2f80391 TU |
3031 | |
3032 | engine->name = "blitter ring"; | |
3033 | engine->id = BCS; | |
3034 | engine->exec_id = I915_EXEC_BLT; | |
215a7e32 | 3035 | engine->hw_id = 2; |
e2f80391 TU |
3036 | |
3037 | engine->mmio_base = BLT_RING_BASE; | |
3038 | engine->write_tail = ring_write_tail; | |
3039 | engine->flush = gen6_ring_flush; | |
3040 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
3041 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
3042 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 3043 | engine->set_seqno = ring_set_seqno; |
abd58f01 | 3044 | if (INTEL_INFO(dev)->gen >= 8) { |
e2f80391 | 3045 | engine->irq_enable_mask = |
abd58f01 | 3046 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT; |
e2f80391 TU |
3047 | engine->irq_get = gen8_ring_get_irq; |
3048 | engine->irq_put = gen8_ring_put_irq; | |
3049 | engine->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; | |
707d9cf9 | 3050 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
3051 | engine->semaphore.sync_to = gen8_ring_sync; |
3052 | engine->semaphore.signal = gen8_xcs_signal; | |
3053 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 | 3054 | } |
abd58f01 | 3055 | } else { |
e2f80391 TU |
3056 | engine->irq_enable_mask = GT_BLT_USER_INTERRUPT; |
3057 | engine->irq_get = gen6_ring_get_irq; | |
3058 | engine->irq_put = gen6_ring_put_irq; | |
3059 | engine->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; | |
707d9cf9 | 3060 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
3061 | engine->semaphore.signal = gen6_signal; |
3062 | engine->semaphore.sync_to = gen6_ring_sync; | |
707d9cf9 BW |
3063 | /* |
3064 | * The current semaphore is only applied on pre-gen8 | |
3065 | * platform. And there is no VCS2 ring on the pre-gen8 | |
3066 | * platform. So the semaphore between BCS and VCS2 is | |
3067 | * initialized as INVALID. Gen8 will initialize the | |
3068 | * sema between BCS and VCS2 later. | |
3069 | */ | |
e2f80391 TU |
3070 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_BR; |
3071 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_BV; | |
3072 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_INVALID; | |
3073 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_BVE; | |
3074 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
3075 | engine->semaphore.mbox.signal[RCS] = GEN6_RBSYNC; | |
3076 | engine->semaphore.mbox.signal[VCS] = GEN6_VBSYNC; | |
3077 | engine->semaphore.mbox.signal[BCS] = GEN6_NOSYNC; | |
3078 | engine->semaphore.mbox.signal[VECS] = GEN6_VEBSYNC; | |
3079 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 3080 | } |
abd58f01 | 3081 | } |
e2f80391 | 3082 | engine->init_hw = init_ring_common; |
549f7365 | 3083 | |
e2f80391 | 3084 | return intel_init_ring_buffer(dev, engine); |
549f7365 | 3085 | } |
a7b9761d | 3086 | |
9a8a2213 BW |
3087 | int intel_init_vebox_ring_buffer(struct drm_device *dev) |
3088 | { | |
4640c4ff | 3089 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 3090 | struct intel_engine_cs *engine = &dev_priv->engine[VECS]; |
9a8a2213 | 3091 | |
e2f80391 TU |
3092 | engine->name = "video enhancement ring"; |
3093 | engine->id = VECS; | |
3094 | engine->exec_id = I915_EXEC_VEBOX; | |
215a7e32 | 3095 | engine->hw_id = 3; |
9a8a2213 | 3096 | |
e2f80391 TU |
3097 | engine->mmio_base = VEBOX_RING_BASE; |
3098 | engine->write_tail = ring_write_tail; | |
3099 | engine->flush = gen6_ring_flush; | |
3100 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
3101 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
3102 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 3103 | engine->set_seqno = ring_set_seqno; |
abd58f01 BW |
3104 | |
3105 | if (INTEL_INFO(dev)->gen >= 8) { | |
e2f80391 | 3106 | engine->irq_enable_mask = |
40c499f9 | 3107 | GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT; |
e2f80391 TU |
3108 | engine->irq_get = gen8_ring_get_irq; |
3109 | engine->irq_put = gen8_ring_put_irq; | |
3110 | engine->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; | |
707d9cf9 | 3111 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
3112 | engine->semaphore.sync_to = gen8_ring_sync; |
3113 | engine->semaphore.signal = gen8_xcs_signal; | |
3114 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 | 3115 | } |
abd58f01 | 3116 | } else { |
e2f80391 TU |
3117 | engine->irq_enable_mask = PM_VEBOX_USER_INTERRUPT; |
3118 | engine->irq_get = hsw_vebox_get_irq; | |
3119 | engine->irq_put = hsw_vebox_put_irq; | |
3120 | engine->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; | |
707d9cf9 | 3121 | if (i915_semaphore_is_enabled(dev)) { |
e2f80391 TU |
3122 | engine->semaphore.sync_to = gen6_ring_sync; |
3123 | engine->semaphore.signal = gen6_signal; | |
3124 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_VER; | |
3125 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_VEV; | |
3126 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_VEB; | |
3127 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_INVALID; | |
3128 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
3129 | engine->semaphore.mbox.signal[RCS] = GEN6_RVESYNC; | |
3130 | engine->semaphore.mbox.signal[VCS] = GEN6_VVESYNC; | |
3131 | engine->semaphore.mbox.signal[BCS] = GEN6_BVESYNC; | |
3132 | engine->semaphore.mbox.signal[VECS] = GEN6_NOSYNC; | |
3133 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 3134 | } |
abd58f01 | 3135 | } |
e2f80391 | 3136 | engine->init_hw = init_ring_common; |
9a8a2213 | 3137 | |
e2f80391 | 3138 | return intel_init_ring_buffer(dev, engine); |
9a8a2213 BW |
3139 | } |
3140 | ||
a7b9761d | 3141 | int |
4866d729 | 3142 | intel_ring_flush_all_caches(struct drm_i915_gem_request *req) |
a7b9761d | 3143 | { |
4a570db5 | 3144 | struct intel_engine_cs *engine = req->engine; |
a7b9761d CW |
3145 | int ret; |
3146 | ||
e2f80391 | 3147 | if (!engine->gpu_caches_dirty) |
a7b9761d CW |
3148 | return 0; |
3149 | ||
e2f80391 | 3150 | ret = engine->flush(req, 0, I915_GEM_GPU_DOMAINS); |
a7b9761d CW |
3151 | if (ret) |
3152 | return ret; | |
3153 | ||
a84c3ae1 | 3154 | trace_i915_gem_ring_flush(req, 0, I915_GEM_GPU_DOMAINS); |
a7b9761d | 3155 | |
e2f80391 | 3156 | engine->gpu_caches_dirty = false; |
a7b9761d CW |
3157 | return 0; |
3158 | } | |
3159 | ||
3160 | int | |
2f20055d | 3161 | intel_ring_invalidate_all_caches(struct drm_i915_gem_request *req) |
a7b9761d | 3162 | { |
4a570db5 | 3163 | struct intel_engine_cs *engine = req->engine; |
a7b9761d CW |
3164 | uint32_t flush_domains; |
3165 | int ret; | |
3166 | ||
3167 | flush_domains = 0; | |
e2f80391 | 3168 | if (engine->gpu_caches_dirty) |
a7b9761d CW |
3169 | flush_domains = I915_GEM_GPU_DOMAINS; |
3170 | ||
e2f80391 | 3171 | ret = engine->flush(req, I915_GEM_GPU_DOMAINS, flush_domains); |
a7b9761d CW |
3172 | if (ret) |
3173 | return ret; | |
3174 | ||
a84c3ae1 | 3175 | trace_i915_gem_ring_flush(req, I915_GEM_GPU_DOMAINS, flush_domains); |
a7b9761d | 3176 | |
e2f80391 | 3177 | engine->gpu_caches_dirty = false; |
a7b9761d CW |
3178 | return 0; |
3179 | } | |
e3efda49 CW |
3180 | |
3181 | void | |
117897f4 | 3182 | intel_stop_engine(struct intel_engine_cs *engine) |
e3efda49 CW |
3183 | { |
3184 | int ret; | |
3185 | ||
117897f4 | 3186 | if (!intel_engine_initialized(engine)) |
e3efda49 CW |
3187 | return; |
3188 | ||
666796da | 3189 | ret = intel_engine_idle(engine); |
f4457ae7 | 3190 | if (ret) |
e3efda49 | 3191 | DRM_ERROR("failed to quiesce %s whilst cleaning up: %d\n", |
0bc40be8 | 3192 | engine->name, ret); |
e3efda49 | 3193 | |
0bc40be8 | 3194 | stop_ring(engine); |
e3efda49 | 3195 | } |