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 | ||
760285e7 | 30 | #include <drm/drmP.h> |
62fdfeaf | 31 | #include "i915_drv.h" |
760285e7 | 32 | #include <drm/i915_drm.h> |
62fdfeaf | 33 | #include "i915_trace.h" |
881f47b6 | 34 | #include "intel_drv.h" |
62fdfeaf | 35 | |
48d82387 OM |
36 | bool |
37 | intel_ring_initialized(struct intel_engine_cs *ring) | |
38 | { | |
39 | struct drm_device *dev = ring->dev; | |
40 | ||
41 | if (!dev) | |
42 | return false; | |
43 | ||
44 | if (i915.enable_execlists) { | |
45 | struct intel_context *dctx = ring->default_context; | |
46 | struct intel_ringbuffer *ringbuf = dctx->engine[ring->id].ringbuf; | |
47 | ||
48 | return ringbuf->obj; | |
49 | } else | |
50 | return ring->buffer && ring->buffer->obj; | |
51 | } | |
18393f63 | 52 | |
82e104cc | 53 | int __intel_ring_space(int head, int tail, int size) |
c7dca47b | 54 | { |
4f54741e DG |
55 | int space = head - tail; |
56 | if (space <= 0) | |
1cf0ba14 | 57 | space += size; |
4f54741e | 58 | return space - I915_RING_FREE_SPACE; |
c7dca47b CW |
59 | } |
60 | ||
ebd0fd4b DG |
61 | void intel_ring_update_space(struct intel_ringbuffer *ringbuf) |
62 | { | |
63 | if (ringbuf->last_retired_head != -1) { | |
64 | ringbuf->head = ringbuf->last_retired_head; | |
65 | ringbuf->last_retired_head = -1; | |
66 | } | |
67 | ||
68 | ringbuf->space = __intel_ring_space(ringbuf->head & HEAD_ADDR, | |
69 | ringbuf->tail, ringbuf->size); | |
70 | } | |
71 | ||
82e104cc | 72 | int intel_ring_space(struct intel_ringbuffer *ringbuf) |
1cf0ba14 | 73 | { |
ebd0fd4b DG |
74 | intel_ring_update_space(ringbuf); |
75 | return ringbuf->space; | |
1cf0ba14 CW |
76 | } |
77 | ||
82e104cc | 78 | bool intel_ring_stopped(struct intel_engine_cs *ring) |
09246732 CW |
79 | { |
80 | struct drm_i915_private *dev_priv = ring->dev->dev_private; | |
88b4aa87 MK |
81 | return dev_priv->gpu_error.stop_rings & intel_ring_flag(ring); |
82 | } | |
09246732 | 83 | |
a4872ba6 | 84 | void __intel_ring_advance(struct intel_engine_cs *ring) |
88b4aa87 | 85 | { |
93b0a4e0 OM |
86 | struct intel_ringbuffer *ringbuf = ring->buffer; |
87 | ringbuf->tail &= ringbuf->size - 1; | |
88b4aa87 | 88 | if (intel_ring_stopped(ring)) |
09246732 | 89 | return; |
93b0a4e0 | 90 | ring->write_tail(ring, ringbuf->tail); |
09246732 CW |
91 | } |
92 | ||
b72f3acb | 93 | static int |
a4872ba6 | 94 | gen2_render_ring_flush(struct intel_engine_cs *ring, |
46f0f8d1 CW |
95 | u32 invalidate_domains, |
96 | u32 flush_domains) | |
97 | { | |
98 | u32 cmd; | |
99 | int ret; | |
100 | ||
101 | cmd = MI_FLUSH; | |
31b14c9f | 102 | if (((invalidate_domains|flush_domains) & I915_GEM_DOMAIN_RENDER) == 0) |
46f0f8d1 CW |
103 | cmd |= MI_NO_WRITE_FLUSH; |
104 | ||
105 | if (invalidate_domains & I915_GEM_DOMAIN_SAMPLER) | |
106 | cmd |= MI_READ_FLUSH; | |
107 | ||
108 | ret = intel_ring_begin(ring, 2); | |
109 | if (ret) | |
110 | return ret; | |
111 | ||
112 | intel_ring_emit(ring, cmd); | |
113 | intel_ring_emit(ring, MI_NOOP); | |
114 | intel_ring_advance(ring); | |
115 | ||
116 | return 0; | |
117 | } | |
118 | ||
119 | static int | |
a4872ba6 | 120 | gen4_render_ring_flush(struct intel_engine_cs *ring, |
46f0f8d1 CW |
121 | u32 invalidate_domains, |
122 | u32 flush_domains) | |
62fdfeaf | 123 | { |
78501eac | 124 | struct drm_device *dev = ring->dev; |
6f392d54 | 125 | u32 cmd; |
b72f3acb | 126 | int ret; |
6f392d54 | 127 | |
36d527de CW |
128 | /* |
129 | * read/write caches: | |
130 | * | |
131 | * I915_GEM_DOMAIN_RENDER is always invalidated, but is | |
132 | * only flushed if MI_NO_WRITE_FLUSH is unset. On 965, it is | |
133 | * also flushed at 2d versus 3d pipeline switches. | |
134 | * | |
135 | * read-only caches: | |
136 | * | |
137 | * I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if | |
138 | * MI_READ_FLUSH is set, and is always flushed on 965. | |
139 | * | |
140 | * I915_GEM_DOMAIN_COMMAND may not exist? | |
141 | * | |
142 | * I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is | |
143 | * invalidated when MI_EXE_FLUSH is set. | |
144 | * | |
145 | * I915_GEM_DOMAIN_VERTEX, which exists on 965, is | |
146 | * invalidated with every MI_FLUSH. | |
147 | * | |
148 | * TLBs: | |
149 | * | |
150 | * On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND | |
151 | * and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and | |
152 | * I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER | |
153 | * are flushed at any MI_FLUSH. | |
154 | */ | |
155 | ||
156 | cmd = MI_FLUSH | MI_NO_WRITE_FLUSH; | |
46f0f8d1 | 157 | if ((invalidate_domains|flush_domains) & I915_GEM_DOMAIN_RENDER) |
36d527de | 158 | cmd &= ~MI_NO_WRITE_FLUSH; |
36d527de CW |
159 | if (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION) |
160 | cmd |= MI_EXE_FLUSH; | |
62fdfeaf | 161 | |
36d527de CW |
162 | if (invalidate_domains & I915_GEM_DOMAIN_COMMAND && |
163 | (IS_G4X(dev) || IS_GEN5(dev))) | |
164 | cmd |= MI_INVALIDATE_ISP; | |
70eac33e | 165 | |
36d527de CW |
166 | ret = intel_ring_begin(ring, 2); |
167 | if (ret) | |
168 | return ret; | |
b72f3acb | 169 | |
36d527de CW |
170 | intel_ring_emit(ring, cmd); |
171 | intel_ring_emit(ring, MI_NOOP); | |
172 | intel_ring_advance(ring); | |
b72f3acb CW |
173 | |
174 | return 0; | |
8187a2b7 ZN |
175 | } |
176 | ||
8d315287 JB |
177 | /** |
178 | * Emits a PIPE_CONTROL with a non-zero post-sync operation, for | |
179 | * implementing two workarounds on gen6. From section 1.4.7.1 | |
180 | * "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1: | |
181 | * | |
182 | * [DevSNB-C+{W/A}] Before any depth stall flush (including those | |
183 | * produced by non-pipelined state commands), software needs to first | |
184 | * send a PIPE_CONTROL with no bits set except Post-Sync Operation != | |
185 | * 0. | |
186 | * | |
187 | * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache Flush Enable | |
188 | * =1, a PIPE_CONTROL with any non-zero post-sync-op is required. | |
189 | * | |
190 | * And the workaround for these two requires this workaround first: | |
191 | * | |
192 | * [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent | |
193 | * BEFORE the pipe-control with a post-sync op and no write-cache | |
194 | * flushes. | |
195 | * | |
196 | * And this last workaround is tricky because of the requirements on | |
197 | * that bit. From section 1.4.7.2.3 "Stall" of the Sandy Bridge PRM | |
198 | * volume 2 part 1: | |
199 | * | |
200 | * "1 of the following must also be set: | |
201 | * - Render Target Cache Flush Enable ([12] of DW1) | |
202 | * - Depth Cache Flush Enable ([0] of DW1) | |
203 | * - Stall at Pixel Scoreboard ([1] of DW1) | |
204 | * - Depth Stall ([13] of DW1) | |
205 | * - Post-Sync Operation ([13] of DW1) | |
206 | * - Notify Enable ([8] of DW1)" | |
207 | * | |
208 | * The cache flushes require the workaround flush that triggered this | |
209 | * one, so we can't use it. Depth stall would trigger the same. | |
210 | * Post-sync nonzero is what triggered this second workaround, so we | |
211 | * can't use that one either. Notify enable is IRQs, which aren't | |
212 | * really our business. That leaves only stall at scoreboard. | |
213 | */ | |
214 | static int | |
a4872ba6 | 215 | intel_emit_post_sync_nonzero_flush(struct intel_engine_cs *ring) |
8d315287 | 216 | { |
18393f63 | 217 | u32 scratch_addr = ring->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
8d315287 JB |
218 | int ret; |
219 | ||
220 | ||
221 | ret = intel_ring_begin(ring, 6); | |
222 | if (ret) | |
223 | return ret; | |
224 | ||
225 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(5)); | |
226 | intel_ring_emit(ring, PIPE_CONTROL_CS_STALL | | |
227 | PIPE_CONTROL_STALL_AT_SCOREBOARD); | |
228 | intel_ring_emit(ring, scratch_addr | PIPE_CONTROL_GLOBAL_GTT); /* address */ | |
229 | intel_ring_emit(ring, 0); /* low dword */ | |
230 | intel_ring_emit(ring, 0); /* high dword */ | |
231 | intel_ring_emit(ring, MI_NOOP); | |
232 | intel_ring_advance(ring); | |
233 | ||
234 | ret = intel_ring_begin(ring, 6); | |
235 | if (ret) | |
236 | return ret; | |
237 | ||
238 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(5)); | |
239 | intel_ring_emit(ring, PIPE_CONTROL_QW_WRITE); | |
240 | intel_ring_emit(ring, scratch_addr | PIPE_CONTROL_GLOBAL_GTT); /* address */ | |
241 | intel_ring_emit(ring, 0); | |
242 | intel_ring_emit(ring, 0); | |
243 | intel_ring_emit(ring, MI_NOOP); | |
244 | intel_ring_advance(ring); | |
245 | ||
246 | return 0; | |
247 | } | |
248 | ||
249 | static int | |
a4872ba6 | 250 | gen6_render_ring_flush(struct intel_engine_cs *ring, |
8d315287 JB |
251 | u32 invalidate_domains, u32 flush_domains) |
252 | { | |
253 | u32 flags = 0; | |
18393f63 | 254 | u32 scratch_addr = ring->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
8d315287 JB |
255 | int ret; |
256 | ||
b3111509 PZ |
257 | /* Force SNB workarounds for PIPE_CONTROL flushes */ |
258 | ret = intel_emit_post_sync_nonzero_flush(ring); | |
259 | if (ret) | |
260 | return ret; | |
261 | ||
8d315287 JB |
262 | /* Just flush everything. Experiments have shown that reducing the |
263 | * number of bits based on the write domains has little performance | |
264 | * impact. | |
265 | */ | |
7d54a904 CW |
266 | if (flush_domains) { |
267 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; | |
268 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; | |
269 | /* | |
270 | * Ensure that any following seqno writes only happen | |
271 | * when the render cache is indeed flushed. | |
272 | */ | |
97f209bc | 273 | flags |= PIPE_CONTROL_CS_STALL; |
7d54a904 CW |
274 | } |
275 | if (invalidate_domains) { | |
276 | flags |= PIPE_CONTROL_TLB_INVALIDATE; | |
277 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; | |
278 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; | |
279 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; | |
280 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; | |
281 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; | |
282 | /* | |
283 | * TLB invalidate requires a post-sync write. | |
284 | */ | |
3ac78313 | 285 | flags |= PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_CS_STALL; |
7d54a904 | 286 | } |
8d315287 | 287 | |
6c6cf5aa | 288 | ret = intel_ring_begin(ring, 4); |
8d315287 JB |
289 | if (ret) |
290 | return ret; | |
291 | ||
6c6cf5aa | 292 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4)); |
8d315287 JB |
293 | intel_ring_emit(ring, flags); |
294 | intel_ring_emit(ring, scratch_addr | PIPE_CONTROL_GLOBAL_GTT); | |
6c6cf5aa | 295 | intel_ring_emit(ring, 0); |
8d315287 JB |
296 | intel_ring_advance(ring); |
297 | ||
298 | return 0; | |
299 | } | |
300 | ||
f3987631 | 301 | static int |
a4872ba6 | 302 | gen7_render_ring_cs_stall_wa(struct intel_engine_cs *ring) |
f3987631 PZ |
303 | { |
304 | int ret; | |
305 | ||
306 | ret = intel_ring_begin(ring, 4); | |
307 | if (ret) | |
308 | return ret; | |
309 | ||
310 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4)); | |
311 | intel_ring_emit(ring, PIPE_CONTROL_CS_STALL | | |
312 | PIPE_CONTROL_STALL_AT_SCOREBOARD); | |
313 | intel_ring_emit(ring, 0); | |
314 | intel_ring_emit(ring, 0); | |
315 | intel_ring_advance(ring); | |
316 | ||
317 | return 0; | |
318 | } | |
319 | ||
a4872ba6 | 320 | static int gen7_ring_fbc_flush(struct intel_engine_cs *ring, u32 value) |
fd3da6c9 RV |
321 | { |
322 | int ret; | |
323 | ||
324 | if (!ring->fbc_dirty) | |
325 | return 0; | |
326 | ||
37c1d94f | 327 | ret = intel_ring_begin(ring, 6); |
fd3da6c9 RV |
328 | if (ret) |
329 | return ret; | |
fd3da6c9 RV |
330 | /* WaFbcNukeOn3DBlt:ivb/hsw */ |
331 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); | |
332 | intel_ring_emit(ring, MSG_FBC_REND_STATE); | |
333 | intel_ring_emit(ring, value); | |
37c1d94f VS |
334 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | MI_SRM_LRM_GLOBAL_GTT); |
335 | intel_ring_emit(ring, MSG_FBC_REND_STATE); | |
336 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); | |
fd3da6c9 RV |
337 | intel_ring_advance(ring); |
338 | ||
339 | ring->fbc_dirty = false; | |
340 | return 0; | |
341 | } | |
342 | ||
4772eaeb | 343 | static int |
a4872ba6 | 344 | gen7_render_ring_flush(struct intel_engine_cs *ring, |
4772eaeb PZ |
345 | u32 invalidate_domains, u32 flush_domains) |
346 | { | |
347 | u32 flags = 0; | |
18393f63 | 348 | u32 scratch_addr = ring->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
4772eaeb PZ |
349 | int ret; |
350 | ||
f3987631 PZ |
351 | /* |
352 | * Ensure that any following seqno writes only happen when the render | |
353 | * cache is indeed flushed. | |
354 | * | |
355 | * Workaround: 4th PIPE_CONTROL command (except the ones with only | |
356 | * read-cache invalidate bits set) must have the CS_STALL bit set. We | |
357 | * don't try to be clever and just set it unconditionally. | |
358 | */ | |
359 | flags |= PIPE_CONTROL_CS_STALL; | |
360 | ||
4772eaeb PZ |
361 | /* Just flush everything. Experiments have shown that reducing the |
362 | * number of bits based on the write domains has little performance | |
363 | * impact. | |
364 | */ | |
365 | if (flush_domains) { | |
366 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; | |
367 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; | |
4772eaeb PZ |
368 | } |
369 | if (invalidate_domains) { | |
370 | flags |= PIPE_CONTROL_TLB_INVALIDATE; | |
371 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; | |
372 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; | |
373 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; | |
374 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; | |
375 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; | |
148b83d0 | 376 | flags |= PIPE_CONTROL_MEDIA_STATE_CLEAR; |
4772eaeb PZ |
377 | /* |
378 | * TLB invalidate requires a post-sync write. | |
379 | */ | |
380 | flags |= PIPE_CONTROL_QW_WRITE; | |
b9e1faa7 | 381 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; |
f3987631 | 382 | |
add284a3 CW |
383 | flags |= PIPE_CONTROL_STALL_AT_SCOREBOARD; |
384 | ||
f3987631 PZ |
385 | /* Workaround: we must issue a pipe_control with CS-stall bit |
386 | * set before a pipe_control command that has the state cache | |
387 | * invalidate bit set. */ | |
388 | gen7_render_ring_cs_stall_wa(ring); | |
4772eaeb PZ |
389 | } |
390 | ||
391 | ret = intel_ring_begin(ring, 4); | |
392 | if (ret) | |
393 | return ret; | |
394 | ||
395 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4)); | |
396 | intel_ring_emit(ring, flags); | |
b9e1faa7 | 397 | intel_ring_emit(ring, scratch_addr); |
4772eaeb PZ |
398 | intel_ring_emit(ring, 0); |
399 | intel_ring_advance(ring); | |
400 | ||
9688ecad | 401 | if (!invalidate_domains && flush_domains) |
fd3da6c9 RV |
402 | return gen7_ring_fbc_flush(ring, FBC_REND_NUKE); |
403 | ||
4772eaeb PZ |
404 | return 0; |
405 | } | |
406 | ||
884ceace KG |
407 | static int |
408 | gen8_emit_pipe_control(struct intel_engine_cs *ring, | |
409 | u32 flags, u32 scratch_addr) | |
410 | { | |
411 | int ret; | |
412 | ||
413 | ret = intel_ring_begin(ring, 6); | |
414 | if (ret) | |
415 | return ret; | |
416 | ||
417 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(6)); | |
418 | intel_ring_emit(ring, flags); | |
419 | intel_ring_emit(ring, scratch_addr); | |
420 | intel_ring_emit(ring, 0); | |
421 | intel_ring_emit(ring, 0); | |
422 | intel_ring_emit(ring, 0); | |
423 | intel_ring_advance(ring); | |
424 | ||
425 | return 0; | |
426 | } | |
427 | ||
a5f3d68e | 428 | static int |
a4872ba6 | 429 | gen8_render_ring_flush(struct intel_engine_cs *ring, |
a5f3d68e BW |
430 | u32 invalidate_domains, u32 flush_domains) |
431 | { | |
432 | u32 flags = 0; | |
18393f63 | 433 | u32 scratch_addr = ring->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
02c9f7e3 | 434 | int ret; |
a5f3d68e BW |
435 | |
436 | flags |= PIPE_CONTROL_CS_STALL; | |
437 | ||
438 | if (flush_domains) { | |
439 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; | |
440 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; | |
441 | } | |
442 | if (invalidate_domains) { | |
443 | flags |= PIPE_CONTROL_TLB_INVALIDATE; | |
444 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; | |
445 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; | |
446 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; | |
447 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; | |
448 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; | |
449 | flags |= PIPE_CONTROL_QW_WRITE; | |
450 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; | |
02c9f7e3 KG |
451 | |
452 | /* WaCsStallBeforeStateCacheInvalidate:bdw,chv */ | |
453 | ret = gen8_emit_pipe_control(ring, | |
454 | PIPE_CONTROL_CS_STALL | | |
455 | PIPE_CONTROL_STALL_AT_SCOREBOARD, | |
456 | 0); | |
457 | if (ret) | |
458 | return ret; | |
a5f3d68e BW |
459 | } |
460 | ||
c5ad011d RV |
461 | ret = gen8_emit_pipe_control(ring, flags, scratch_addr); |
462 | if (ret) | |
463 | return ret; | |
464 | ||
465 | if (!invalidate_domains && flush_domains) | |
466 | return gen7_ring_fbc_flush(ring, FBC_REND_NUKE); | |
467 | ||
468 | return 0; | |
a5f3d68e BW |
469 | } |
470 | ||
a4872ba6 | 471 | static void ring_write_tail(struct intel_engine_cs *ring, |
297b0c5b | 472 | u32 value) |
d46eefa2 | 473 | { |
4640c4ff | 474 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
297b0c5b | 475 | I915_WRITE_TAIL(ring, value); |
d46eefa2 XH |
476 | } |
477 | ||
a4872ba6 | 478 | u64 intel_ring_get_active_head(struct intel_engine_cs *ring) |
8187a2b7 | 479 | { |
4640c4ff | 480 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
50877445 | 481 | u64 acthd; |
8187a2b7 | 482 | |
50877445 CW |
483 | if (INTEL_INFO(ring->dev)->gen >= 8) |
484 | acthd = I915_READ64_2x32(RING_ACTHD(ring->mmio_base), | |
485 | RING_ACTHD_UDW(ring->mmio_base)); | |
486 | else if (INTEL_INFO(ring->dev)->gen >= 4) | |
487 | acthd = I915_READ(RING_ACTHD(ring->mmio_base)); | |
488 | else | |
489 | acthd = I915_READ(ACTHD); | |
490 | ||
491 | return acthd; | |
8187a2b7 ZN |
492 | } |
493 | ||
a4872ba6 | 494 | static void ring_setup_phys_status_page(struct intel_engine_cs *ring) |
035dc1e0 DV |
495 | { |
496 | struct drm_i915_private *dev_priv = ring->dev->dev_private; | |
497 | u32 addr; | |
498 | ||
499 | addr = dev_priv->status_page_dmah->busaddr; | |
500 | if (INTEL_INFO(ring->dev)->gen >= 4) | |
501 | addr |= (dev_priv->status_page_dmah->busaddr >> 28) & 0xf0; | |
502 | I915_WRITE(HWS_PGA, addr); | |
503 | } | |
504 | ||
a4872ba6 | 505 | static bool stop_ring(struct intel_engine_cs *ring) |
8187a2b7 | 506 | { |
9991ae78 | 507 | struct drm_i915_private *dev_priv = to_i915(ring->dev); |
8187a2b7 | 508 | |
9991ae78 CW |
509 | if (!IS_GEN2(ring->dev)) { |
510 | I915_WRITE_MODE(ring, _MASKED_BIT_ENABLE(STOP_RING)); | |
403bdd10 DV |
511 | if (wait_for((I915_READ_MODE(ring) & MODE_IDLE) != 0, 1000)) { |
512 | DRM_ERROR("%s : timed out trying to stop ring\n", ring->name); | |
9bec9b13 CW |
513 | /* Sometimes we observe that the idle flag is not |
514 | * set even though the ring is empty. So double | |
515 | * check before giving up. | |
516 | */ | |
517 | if (I915_READ_HEAD(ring) != I915_READ_TAIL(ring)) | |
518 | return false; | |
9991ae78 CW |
519 | } |
520 | } | |
b7884eb4 | 521 | |
7f2ab699 | 522 | I915_WRITE_CTL(ring, 0); |
570ef608 | 523 | I915_WRITE_HEAD(ring, 0); |
78501eac | 524 | ring->write_tail(ring, 0); |
8187a2b7 | 525 | |
9991ae78 CW |
526 | if (!IS_GEN2(ring->dev)) { |
527 | (void)I915_READ_CTL(ring); | |
528 | I915_WRITE_MODE(ring, _MASKED_BIT_DISABLE(STOP_RING)); | |
529 | } | |
a51435a3 | 530 | |
9991ae78 CW |
531 | return (I915_READ_HEAD(ring) & HEAD_ADDR) == 0; |
532 | } | |
8187a2b7 | 533 | |
a4872ba6 | 534 | static int init_ring_common(struct intel_engine_cs *ring) |
9991ae78 CW |
535 | { |
536 | struct drm_device *dev = ring->dev; | |
537 | struct drm_i915_private *dev_priv = dev->dev_private; | |
93b0a4e0 OM |
538 | struct intel_ringbuffer *ringbuf = ring->buffer; |
539 | struct drm_i915_gem_object *obj = ringbuf->obj; | |
9991ae78 CW |
540 | int ret = 0; |
541 | ||
59bad947 | 542 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
9991ae78 CW |
543 | |
544 | if (!stop_ring(ring)) { | |
545 | /* G45 ring initialization often fails to reset head to zero */ | |
6fd0d56e CW |
546 | DRM_DEBUG_KMS("%s head not reset to zero " |
547 | "ctl %08x head %08x tail %08x start %08x\n", | |
548 | ring->name, | |
549 | I915_READ_CTL(ring), | |
550 | I915_READ_HEAD(ring), | |
551 | I915_READ_TAIL(ring), | |
552 | I915_READ_START(ring)); | |
8187a2b7 | 553 | |
9991ae78 | 554 | if (!stop_ring(ring)) { |
6fd0d56e CW |
555 | DRM_ERROR("failed to set %s head to zero " |
556 | "ctl %08x head %08x tail %08x start %08x\n", | |
557 | ring->name, | |
558 | I915_READ_CTL(ring), | |
559 | I915_READ_HEAD(ring), | |
560 | I915_READ_TAIL(ring), | |
561 | I915_READ_START(ring)); | |
9991ae78 CW |
562 | ret = -EIO; |
563 | goto out; | |
6fd0d56e | 564 | } |
8187a2b7 ZN |
565 | } |
566 | ||
9991ae78 CW |
567 | if (I915_NEED_GFX_HWS(dev)) |
568 | intel_ring_setup_status_page(ring); | |
569 | else | |
570 | ring_setup_phys_status_page(ring); | |
571 | ||
ece4a17d JK |
572 | /* Enforce ordering by reading HEAD register back */ |
573 | I915_READ_HEAD(ring); | |
574 | ||
0d8957c8 DV |
575 | /* Initialize the ring. This must happen _after_ we've cleared the ring |
576 | * registers with the above sequence (the readback of the HEAD registers | |
577 | * also enforces ordering), otherwise the hw might lose the new ring | |
578 | * register values. */ | |
f343c5f6 | 579 | I915_WRITE_START(ring, i915_gem_obj_ggtt_offset(obj)); |
95468892 CW |
580 | |
581 | /* WaClearRingBufHeadRegAtInit:ctg,elk */ | |
582 | if (I915_READ_HEAD(ring)) | |
583 | DRM_DEBUG("%s initialization failed [head=%08x], fudging\n", | |
584 | ring->name, I915_READ_HEAD(ring)); | |
585 | I915_WRITE_HEAD(ring, 0); | |
586 | (void)I915_READ_HEAD(ring); | |
587 | ||
7f2ab699 | 588 | I915_WRITE_CTL(ring, |
93b0a4e0 | 589 | ((ringbuf->size - PAGE_SIZE) & RING_NR_PAGES) |
5d031e5b | 590 | | RING_VALID); |
8187a2b7 | 591 | |
8187a2b7 | 592 | /* If the head is still not zero, the ring is dead */ |
f01db988 | 593 | if (wait_for((I915_READ_CTL(ring) & RING_VALID) != 0 && |
f343c5f6 | 594 | I915_READ_START(ring) == i915_gem_obj_ggtt_offset(obj) && |
f01db988 | 595 | (I915_READ_HEAD(ring) & HEAD_ADDR) == 0, 50)) { |
e74cfed5 | 596 | DRM_ERROR("%s initialization failed " |
48e48a0b CW |
597 | "ctl %08x (valid? %d) head %08x tail %08x start %08x [expected %08lx]\n", |
598 | ring->name, | |
599 | I915_READ_CTL(ring), I915_READ_CTL(ring) & RING_VALID, | |
600 | I915_READ_HEAD(ring), I915_READ_TAIL(ring), | |
601 | I915_READ_START(ring), (unsigned long)i915_gem_obj_ggtt_offset(obj)); | |
b7884eb4 DV |
602 | ret = -EIO; |
603 | goto out; | |
8187a2b7 ZN |
604 | } |
605 | ||
ebd0fd4b | 606 | ringbuf->last_retired_head = -1; |
5c6c6003 CW |
607 | ringbuf->head = I915_READ_HEAD(ring); |
608 | ringbuf->tail = I915_READ_TAIL(ring) & TAIL_ADDR; | |
ebd0fd4b | 609 | intel_ring_update_space(ringbuf); |
1ec14ad3 | 610 | |
50f018df CW |
611 | memset(&ring->hangcheck, 0, sizeof(ring->hangcheck)); |
612 | ||
b7884eb4 | 613 | out: |
59bad947 | 614 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
b7884eb4 DV |
615 | |
616 | return ret; | |
8187a2b7 ZN |
617 | } |
618 | ||
9b1136d5 OM |
619 | void |
620 | intel_fini_pipe_control(struct intel_engine_cs *ring) | |
621 | { | |
622 | struct drm_device *dev = ring->dev; | |
623 | ||
624 | if (ring->scratch.obj == NULL) | |
625 | return; | |
626 | ||
627 | if (INTEL_INFO(dev)->gen >= 5) { | |
628 | kunmap(sg_page(ring->scratch.obj->pages->sgl)); | |
629 | i915_gem_object_ggtt_unpin(ring->scratch.obj); | |
630 | } | |
631 | ||
632 | drm_gem_object_unreference(&ring->scratch.obj->base); | |
633 | ring->scratch.obj = NULL; | |
634 | } | |
635 | ||
636 | int | |
637 | intel_init_pipe_control(struct intel_engine_cs *ring) | |
c6df541c | 638 | { |
c6df541c CW |
639 | int ret; |
640 | ||
bfc882b4 | 641 | WARN_ON(ring->scratch.obj); |
c6df541c | 642 | |
0d1aacac CW |
643 | ring->scratch.obj = i915_gem_alloc_object(ring->dev, 4096); |
644 | if (ring->scratch.obj == NULL) { | |
c6df541c CW |
645 | DRM_ERROR("Failed to allocate seqno page\n"); |
646 | ret = -ENOMEM; | |
647 | goto err; | |
648 | } | |
e4ffd173 | 649 | |
a9cc726c DV |
650 | ret = i915_gem_object_set_cache_level(ring->scratch.obj, I915_CACHE_LLC); |
651 | if (ret) | |
652 | goto err_unref; | |
c6df541c | 653 | |
1ec9e26d | 654 | ret = i915_gem_obj_ggtt_pin(ring->scratch.obj, 4096, 0); |
c6df541c CW |
655 | if (ret) |
656 | goto err_unref; | |
657 | ||
0d1aacac CW |
658 | ring->scratch.gtt_offset = i915_gem_obj_ggtt_offset(ring->scratch.obj); |
659 | ring->scratch.cpu_page = kmap(sg_page(ring->scratch.obj->pages->sgl)); | |
660 | if (ring->scratch.cpu_page == NULL) { | |
56b085a0 | 661 | ret = -ENOMEM; |
c6df541c | 662 | goto err_unpin; |
56b085a0 | 663 | } |
c6df541c | 664 | |
2b1086cc | 665 | DRM_DEBUG_DRIVER("%s pipe control offset: 0x%08x\n", |
0d1aacac | 666 | ring->name, ring->scratch.gtt_offset); |
c6df541c CW |
667 | return 0; |
668 | ||
669 | err_unpin: | |
d7f46fc4 | 670 | i915_gem_object_ggtt_unpin(ring->scratch.obj); |
c6df541c | 671 | err_unref: |
0d1aacac | 672 | drm_gem_object_unreference(&ring->scratch.obj->base); |
c6df541c | 673 | err: |
c6df541c CW |
674 | return ret; |
675 | } | |
676 | ||
771b9a53 MT |
677 | static int intel_ring_workarounds_emit(struct intel_engine_cs *ring, |
678 | struct intel_context *ctx) | |
86d7f238 | 679 | { |
7225342a | 680 | int ret, i; |
888b5995 AS |
681 | struct drm_device *dev = ring->dev; |
682 | struct drm_i915_private *dev_priv = dev->dev_private; | |
7225342a | 683 | struct i915_workarounds *w = &dev_priv->workarounds; |
888b5995 | 684 | |
e6c1abb7 | 685 | if (WARN_ON_ONCE(w->count == 0)) |
7225342a | 686 | return 0; |
888b5995 | 687 | |
7225342a MK |
688 | ring->gpu_caches_dirty = true; |
689 | ret = intel_ring_flush_all_caches(ring); | |
690 | if (ret) | |
691 | return ret; | |
888b5995 | 692 | |
22a916aa | 693 | ret = intel_ring_begin(ring, (w->count * 2 + 2)); |
7225342a MK |
694 | if (ret) |
695 | return ret; | |
696 | ||
22a916aa | 697 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(w->count)); |
7225342a | 698 | for (i = 0; i < w->count; i++) { |
7225342a MK |
699 | intel_ring_emit(ring, w->reg[i].addr); |
700 | intel_ring_emit(ring, w->reg[i].value); | |
701 | } | |
22a916aa | 702 | intel_ring_emit(ring, MI_NOOP); |
7225342a MK |
703 | |
704 | intel_ring_advance(ring); | |
705 | ||
706 | ring->gpu_caches_dirty = true; | |
707 | ret = intel_ring_flush_all_caches(ring); | |
708 | if (ret) | |
709 | return ret; | |
888b5995 | 710 | |
7225342a | 711 | DRM_DEBUG_DRIVER("Number of Workarounds emitted: %d\n", w->count); |
888b5995 | 712 | |
7225342a | 713 | return 0; |
86d7f238 AS |
714 | } |
715 | ||
8f0e2b9d DV |
716 | static int intel_rcs_ctx_init(struct intel_engine_cs *ring, |
717 | struct intel_context *ctx) | |
718 | { | |
719 | int ret; | |
720 | ||
721 | ret = intel_ring_workarounds_emit(ring, ctx); | |
722 | if (ret != 0) | |
723 | return ret; | |
724 | ||
725 | ret = i915_gem_render_state_init(ring); | |
726 | if (ret) | |
727 | DRM_ERROR("init render state: %d\n", ret); | |
728 | ||
729 | return ret; | |
730 | } | |
731 | ||
7225342a | 732 | static int wa_add(struct drm_i915_private *dev_priv, |
cf4b0de6 | 733 | const u32 addr, const u32 mask, const u32 val) |
7225342a MK |
734 | { |
735 | const u32 idx = dev_priv->workarounds.count; | |
736 | ||
737 | if (WARN_ON(idx >= I915_MAX_WA_REGS)) | |
738 | return -ENOSPC; | |
739 | ||
740 | dev_priv->workarounds.reg[idx].addr = addr; | |
741 | dev_priv->workarounds.reg[idx].value = val; | |
742 | dev_priv->workarounds.reg[idx].mask = mask; | |
743 | ||
744 | dev_priv->workarounds.count++; | |
745 | ||
746 | return 0; | |
86d7f238 AS |
747 | } |
748 | ||
cf4b0de6 DL |
749 | #define WA_REG(addr, mask, val) { \ |
750 | const int r = wa_add(dev_priv, (addr), (mask), (val)); \ | |
7225342a MK |
751 | if (r) \ |
752 | return r; \ | |
753 | } | |
754 | ||
755 | #define WA_SET_BIT_MASKED(addr, mask) \ | |
26459343 | 756 | WA_REG(addr, (mask), _MASKED_BIT_ENABLE(mask)) |
7225342a MK |
757 | |
758 | #define WA_CLR_BIT_MASKED(addr, mask) \ | |
26459343 | 759 | WA_REG(addr, (mask), _MASKED_BIT_DISABLE(mask)) |
7225342a | 760 | |
98533251 | 761 | #define WA_SET_FIELD_MASKED(addr, mask, value) \ |
cf4b0de6 | 762 | WA_REG(addr, mask, _MASKED_FIELD(mask, value)) |
7225342a | 763 | |
cf4b0de6 DL |
764 | #define WA_SET_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) | (mask)) |
765 | #define WA_CLR_BIT(addr, mask) WA_REG(addr, mask, I915_READ(addr) & ~(mask)) | |
7225342a | 766 | |
cf4b0de6 | 767 | #define WA_WRITE(addr, val) WA_REG(addr, 0xffffffff, val) |
7225342a | 768 | |
00e1e623 | 769 | static int bdw_init_workarounds(struct intel_engine_cs *ring) |
86d7f238 | 770 | { |
888b5995 AS |
771 | struct drm_device *dev = ring->dev; |
772 | struct drm_i915_private *dev_priv = dev->dev_private; | |
86d7f238 | 773 | |
86d7f238 | 774 | /* WaDisablePartialInstShootdown:bdw */ |
101b376d | 775 | /* WaDisableThreadStallDopClockGating:bdw (pre-production) */ |
7225342a MK |
776 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, |
777 | PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE | | |
778 | STALL_DOP_GATING_DISABLE); | |
86d7f238 | 779 | |
101b376d | 780 | /* WaDisableDopClockGating:bdw */ |
7225342a MK |
781 | WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2, |
782 | DOP_CLOCK_GATING_DISABLE); | |
86d7f238 | 783 | |
7225342a MK |
784 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, |
785 | GEN8_SAMPLER_POWER_BYPASS_DIS); | |
86d7f238 AS |
786 | |
787 | /* Use Force Non-Coherent whenever executing a 3D context. This is a | |
788 | * workaround for for a possible hang in the unlikely event a TLB | |
789 | * invalidation occurs during a PSD flush. | |
790 | */ | |
1a252058 | 791 | /* WaForceEnableNonCoherent:bdw */ |
f3f32360 | 792 | /* WaHdcDisableFetchWhenMasked:bdw */ |
da09654d | 793 | /* WaDisableFenceDestinationToSLM:bdw (GT3 pre-production) */ |
7225342a MK |
794 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
795 | HDC_FORCE_NON_COHERENT | | |
f3f32360 | 796 | HDC_DONOT_FETCH_MEM_WHEN_MASKED | |
7225342a | 797 | (IS_BDW_GT3(dev) ? HDC_FENCE_DEST_SLM_DISABLE : 0)); |
86d7f238 | 798 | |
2701fc43 KG |
799 | /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0: |
800 | * "The Hierarchical Z RAW Stall Optimization allows non-overlapping | |
801 | * polygons in the same 8x4 pixel/sample area to be processed without | |
802 | * stalling waiting for the earlier ones to write to Hierarchical Z | |
803 | * buffer." | |
804 | * | |
805 | * This optimization is off by default for Broadwell; turn it on. | |
806 | */ | |
807 | WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE); | |
808 | ||
86d7f238 | 809 | /* Wa4x4STCOptimizationDisable:bdw */ |
7225342a MK |
810 | WA_SET_BIT_MASKED(CACHE_MODE_1, |
811 | GEN8_4x4_STC_OPTIMIZATION_DISABLE); | |
86d7f238 AS |
812 | |
813 | /* | |
814 | * BSpec recommends 8x4 when MSAA is used, | |
815 | * however in practice 16x4 seems fastest. | |
816 | * | |
817 | * Note that PS/WM thread counts depend on the WIZ hashing | |
818 | * disable bit, which we don't touch here, but it's good | |
819 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). | |
820 | */ | |
98533251 DL |
821 | WA_SET_FIELD_MASKED(GEN7_GT_MODE, |
822 | GEN6_WIZ_HASHING_MASK, | |
823 | GEN6_WIZ_HASHING_16x4); | |
888b5995 | 824 | |
86d7f238 AS |
825 | return 0; |
826 | } | |
827 | ||
00e1e623 VS |
828 | static int chv_init_workarounds(struct intel_engine_cs *ring) |
829 | { | |
00e1e623 VS |
830 | struct drm_device *dev = ring->dev; |
831 | struct drm_i915_private *dev_priv = dev->dev_private; | |
832 | ||
00e1e623 | 833 | /* WaDisablePartialInstShootdown:chv */ |
00e1e623 | 834 | /* WaDisableThreadStallDopClockGating:chv */ |
7225342a | 835 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, |
605f1433 AS |
836 | PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE | |
837 | STALL_DOP_GATING_DISABLE); | |
00e1e623 | 838 | |
95289009 AS |
839 | /* Use Force Non-Coherent whenever executing a 3D context. This is a |
840 | * workaround for a possible hang in the unlikely event a TLB | |
841 | * invalidation occurs during a PSD flush. | |
842 | */ | |
843 | /* WaForceEnableNonCoherent:chv */ | |
844 | /* WaHdcDisableFetchWhenMasked:chv */ | |
845 | WA_SET_BIT_MASKED(HDC_CHICKEN0, | |
846 | HDC_FORCE_NON_COHERENT | | |
847 | HDC_DONOT_FETCH_MEM_WHEN_MASKED); | |
848 | ||
973a5b06 KG |
849 | /* According to the CACHE_MODE_0 default value documentation, some |
850 | * CHV platforms disable this optimization by default. Turn it on. | |
851 | */ | |
852 | WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE); | |
853 | ||
14bc16e3 VS |
854 | /* Wa4x4STCOptimizationDisable:chv */ |
855 | WA_SET_BIT_MASKED(CACHE_MODE_1, | |
856 | GEN8_4x4_STC_OPTIMIZATION_DISABLE); | |
857 | ||
d60de81d KG |
858 | /* Improve HiZ throughput on CHV. */ |
859 | WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X); | |
860 | ||
e7fc2436 VS |
861 | /* |
862 | * BSpec recommends 8x4 when MSAA is used, | |
863 | * however in practice 16x4 seems fastest. | |
864 | * | |
865 | * Note that PS/WM thread counts depend on the WIZ hashing | |
866 | * disable bit, which we don't touch here, but it's good | |
867 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). | |
868 | */ | |
869 | WA_SET_FIELD_MASKED(GEN7_GT_MODE, | |
870 | GEN6_WIZ_HASHING_MASK, | |
871 | GEN6_WIZ_HASHING_16x4); | |
872 | ||
7225342a MK |
873 | return 0; |
874 | } | |
875 | ||
3b106531 HN |
876 | static int gen9_init_workarounds(struct intel_engine_cs *ring) |
877 | { | |
878 | return 0; | |
879 | } | |
880 | ||
771b9a53 | 881 | int init_workarounds_ring(struct intel_engine_cs *ring) |
7225342a MK |
882 | { |
883 | struct drm_device *dev = ring->dev; | |
884 | struct drm_i915_private *dev_priv = dev->dev_private; | |
885 | ||
886 | WARN_ON(ring->id != RCS); | |
887 | ||
888 | dev_priv->workarounds.count = 0; | |
889 | ||
890 | if (IS_BROADWELL(dev)) | |
891 | return bdw_init_workarounds(ring); | |
892 | ||
893 | if (IS_CHERRYVIEW(dev)) | |
894 | return chv_init_workarounds(ring); | |
00e1e623 | 895 | |
3b106531 HN |
896 | if (IS_GEN9(dev)) |
897 | return gen9_init_workarounds(ring); | |
898 | ||
00e1e623 VS |
899 | return 0; |
900 | } | |
901 | ||
a4872ba6 | 902 | static int init_render_ring(struct intel_engine_cs *ring) |
8187a2b7 | 903 | { |
78501eac | 904 | struct drm_device *dev = ring->dev; |
1ec14ad3 | 905 | struct drm_i915_private *dev_priv = dev->dev_private; |
78501eac | 906 | int ret = init_ring_common(ring); |
9c33baa6 KZ |
907 | if (ret) |
908 | return ret; | |
a69ffdbf | 909 | |
61a563a2 AG |
910 | /* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */ |
911 | if (INTEL_INFO(dev)->gen >= 4 && INTEL_INFO(dev)->gen < 7) | |
6b26c86d | 912 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH)); |
1c8c38c5 CW |
913 | |
914 | /* We need to disable the AsyncFlip performance optimisations in order | |
915 | * to use MI_WAIT_FOR_EVENT within the CS. It should already be | |
916 | * programmed to '1' on all products. | |
8693a824 | 917 | * |
b3f797ac | 918 | * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv,bdw,chv |
1c8c38c5 | 919 | */ |
fbdcb068 | 920 | if (INTEL_INFO(dev)->gen >= 6 && INTEL_INFO(dev)->gen < 9) |
1c8c38c5 CW |
921 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(ASYNC_FLIP_PERF_DISABLE)); |
922 | ||
f05bb0c7 | 923 | /* Required for the hardware to program scanline values for waiting */ |
01fa0302 | 924 | /* WaEnableFlushTlbInvalidationMode:snb */ |
f05bb0c7 CW |
925 | if (INTEL_INFO(dev)->gen == 6) |
926 | I915_WRITE(GFX_MODE, | |
aa83e30d | 927 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT)); |
f05bb0c7 | 928 | |
01fa0302 | 929 | /* WaBCSVCSTlbInvalidationMode:ivb,vlv,hsw */ |
1c8c38c5 CW |
930 | if (IS_GEN7(dev)) |
931 | I915_WRITE(GFX_MODE_GEN7, | |
01fa0302 | 932 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT) | |
1c8c38c5 | 933 | _MASKED_BIT_ENABLE(GFX_REPLAY_MODE)); |
78501eac | 934 | |
5e13a0c5 | 935 | if (IS_GEN6(dev)) { |
3a69ddd6 KG |
936 | /* From the Sandybridge PRM, volume 1 part 3, page 24: |
937 | * "If this bit is set, STCunit will have LRA as replacement | |
938 | * policy. [...] This bit must be reset. LRA replacement | |
939 | * policy is not supported." | |
940 | */ | |
941 | I915_WRITE(CACHE_MODE_0, | |
5e13a0c5 | 942 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
84f9f938 BW |
943 | } |
944 | ||
6b26c86d DV |
945 | if (INTEL_INFO(dev)->gen >= 6) |
946 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_FORCE_ORDERING)); | |
84f9f938 | 947 | |
040d2baa | 948 | if (HAS_L3_DPF(dev)) |
35a85ac6 | 949 | I915_WRITE_IMR(ring, ~GT_PARITY_ERROR(dev)); |
15b9f80e | 950 | |
7225342a | 951 | return init_workarounds_ring(ring); |
8187a2b7 ZN |
952 | } |
953 | ||
a4872ba6 | 954 | static void render_ring_cleanup(struct intel_engine_cs *ring) |
c6df541c | 955 | { |
b45305fc | 956 | struct drm_device *dev = ring->dev; |
3e78998a BW |
957 | struct drm_i915_private *dev_priv = dev->dev_private; |
958 | ||
959 | if (dev_priv->semaphore_obj) { | |
960 | i915_gem_object_ggtt_unpin(dev_priv->semaphore_obj); | |
961 | drm_gem_object_unreference(&dev_priv->semaphore_obj->base); | |
962 | dev_priv->semaphore_obj = NULL; | |
963 | } | |
b45305fc | 964 | |
9b1136d5 | 965 | intel_fini_pipe_control(ring); |
c6df541c CW |
966 | } |
967 | ||
3e78998a BW |
968 | static int gen8_rcs_signal(struct intel_engine_cs *signaller, |
969 | unsigned int num_dwords) | |
970 | { | |
971 | #define MBOX_UPDATE_DWORDS 8 | |
972 | struct drm_device *dev = signaller->dev; | |
973 | struct drm_i915_private *dev_priv = dev->dev_private; | |
974 | struct intel_engine_cs *waiter; | |
975 | int i, ret, num_rings; | |
976 | ||
977 | num_rings = hweight32(INTEL_INFO(dev)->ring_mask); | |
978 | num_dwords += (num_rings-1) * MBOX_UPDATE_DWORDS; | |
979 | #undef MBOX_UPDATE_DWORDS | |
980 | ||
981 | ret = intel_ring_begin(signaller, num_dwords); | |
982 | if (ret) | |
983 | return ret; | |
984 | ||
985 | for_each_ring(waiter, dev_priv, i) { | |
6259cead | 986 | u32 seqno; |
3e78998a BW |
987 | u64 gtt_offset = signaller->semaphore.signal_ggtt[i]; |
988 | if (gtt_offset == MI_SEMAPHORE_SYNC_INVALID) | |
989 | continue; | |
990 | ||
6259cead JH |
991 | seqno = i915_gem_request_get_seqno( |
992 | signaller->outstanding_lazy_request); | |
3e78998a BW |
993 | intel_ring_emit(signaller, GFX_OP_PIPE_CONTROL(6)); |
994 | intel_ring_emit(signaller, PIPE_CONTROL_GLOBAL_GTT_IVB | | |
995 | PIPE_CONTROL_QW_WRITE | | |
996 | PIPE_CONTROL_FLUSH_ENABLE); | |
997 | intel_ring_emit(signaller, lower_32_bits(gtt_offset)); | |
998 | intel_ring_emit(signaller, upper_32_bits(gtt_offset)); | |
6259cead | 999 | intel_ring_emit(signaller, seqno); |
3e78998a BW |
1000 | intel_ring_emit(signaller, 0); |
1001 | intel_ring_emit(signaller, MI_SEMAPHORE_SIGNAL | | |
1002 | MI_SEMAPHORE_TARGET(waiter->id)); | |
1003 | intel_ring_emit(signaller, 0); | |
1004 | } | |
1005 | ||
1006 | return 0; | |
1007 | } | |
1008 | ||
1009 | static int gen8_xcs_signal(struct intel_engine_cs *signaller, | |
1010 | unsigned int num_dwords) | |
1011 | { | |
1012 | #define MBOX_UPDATE_DWORDS 6 | |
1013 | struct drm_device *dev = signaller->dev; | |
1014 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1015 | struct intel_engine_cs *waiter; | |
1016 | int i, ret, num_rings; | |
1017 | ||
1018 | num_rings = hweight32(INTEL_INFO(dev)->ring_mask); | |
1019 | num_dwords += (num_rings-1) * MBOX_UPDATE_DWORDS; | |
1020 | #undef MBOX_UPDATE_DWORDS | |
1021 | ||
1022 | ret = intel_ring_begin(signaller, num_dwords); | |
1023 | if (ret) | |
1024 | return ret; | |
1025 | ||
1026 | for_each_ring(waiter, dev_priv, i) { | |
6259cead | 1027 | u32 seqno; |
3e78998a BW |
1028 | u64 gtt_offset = signaller->semaphore.signal_ggtt[i]; |
1029 | if (gtt_offset == MI_SEMAPHORE_SYNC_INVALID) | |
1030 | continue; | |
1031 | ||
6259cead JH |
1032 | seqno = i915_gem_request_get_seqno( |
1033 | signaller->outstanding_lazy_request); | |
3e78998a BW |
1034 | intel_ring_emit(signaller, (MI_FLUSH_DW + 1) | |
1035 | MI_FLUSH_DW_OP_STOREDW); | |
1036 | intel_ring_emit(signaller, lower_32_bits(gtt_offset) | | |
1037 | MI_FLUSH_DW_USE_GTT); | |
1038 | intel_ring_emit(signaller, upper_32_bits(gtt_offset)); | |
6259cead | 1039 | intel_ring_emit(signaller, seqno); |
3e78998a BW |
1040 | intel_ring_emit(signaller, MI_SEMAPHORE_SIGNAL | |
1041 | MI_SEMAPHORE_TARGET(waiter->id)); | |
1042 | intel_ring_emit(signaller, 0); | |
1043 | } | |
1044 | ||
1045 | return 0; | |
1046 | } | |
1047 | ||
a4872ba6 | 1048 | static int gen6_signal(struct intel_engine_cs *signaller, |
024a43e1 | 1049 | unsigned int num_dwords) |
1ec14ad3 | 1050 | { |
024a43e1 BW |
1051 | struct drm_device *dev = signaller->dev; |
1052 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a4872ba6 | 1053 | struct intel_engine_cs *useless; |
a1444b79 | 1054 | int i, ret, num_rings; |
78325f2d | 1055 | |
a1444b79 BW |
1056 | #define MBOX_UPDATE_DWORDS 3 |
1057 | num_rings = hweight32(INTEL_INFO(dev)->ring_mask); | |
1058 | num_dwords += round_up((num_rings-1) * MBOX_UPDATE_DWORDS, 2); | |
1059 | #undef MBOX_UPDATE_DWORDS | |
024a43e1 BW |
1060 | |
1061 | ret = intel_ring_begin(signaller, num_dwords); | |
1062 | if (ret) | |
1063 | return ret; | |
024a43e1 | 1064 | |
78325f2d BW |
1065 | for_each_ring(useless, dev_priv, i) { |
1066 | u32 mbox_reg = signaller->semaphore.mbox.signal[i]; | |
1067 | if (mbox_reg != GEN6_NOSYNC) { | |
6259cead JH |
1068 | u32 seqno = i915_gem_request_get_seqno( |
1069 | signaller->outstanding_lazy_request); | |
78325f2d BW |
1070 | intel_ring_emit(signaller, MI_LOAD_REGISTER_IMM(1)); |
1071 | intel_ring_emit(signaller, mbox_reg); | |
6259cead | 1072 | intel_ring_emit(signaller, seqno); |
78325f2d BW |
1073 | } |
1074 | } | |
024a43e1 | 1075 | |
a1444b79 BW |
1076 | /* If num_dwords was rounded, make sure the tail pointer is correct */ |
1077 | if (num_rings % 2 == 0) | |
1078 | intel_ring_emit(signaller, MI_NOOP); | |
1079 | ||
024a43e1 | 1080 | return 0; |
1ec14ad3 CW |
1081 | } |
1082 | ||
c8c99b0f BW |
1083 | /** |
1084 | * gen6_add_request - Update the semaphore mailbox registers | |
1085 | * | |
1086 | * @ring - ring that is adding a request | |
1087 | * @seqno - return seqno stuck into the ring | |
1088 | * | |
1089 | * Update the mailbox registers in the *other* rings with the current seqno. | |
1090 | * This acts like a signal in the canonical semaphore. | |
1091 | */ | |
1ec14ad3 | 1092 | static int |
a4872ba6 | 1093 | gen6_add_request(struct intel_engine_cs *ring) |
1ec14ad3 | 1094 | { |
024a43e1 | 1095 | int ret; |
52ed2325 | 1096 | |
707d9cf9 BW |
1097 | if (ring->semaphore.signal) |
1098 | ret = ring->semaphore.signal(ring, 4); | |
1099 | else | |
1100 | ret = intel_ring_begin(ring, 4); | |
1101 | ||
1ec14ad3 CW |
1102 | if (ret) |
1103 | return ret; | |
1104 | ||
1ec14ad3 CW |
1105 | intel_ring_emit(ring, MI_STORE_DWORD_INDEX); |
1106 | intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | |
6259cead JH |
1107 | intel_ring_emit(ring, |
1108 | i915_gem_request_get_seqno(ring->outstanding_lazy_request)); | |
1ec14ad3 | 1109 | intel_ring_emit(ring, MI_USER_INTERRUPT); |
09246732 | 1110 | __intel_ring_advance(ring); |
1ec14ad3 | 1111 | |
1ec14ad3 CW |
1112 | return 0; |
1113 | } | |
1114 | ||
f72b3435 MK |
1115 | static inline bool i915_gem_has_seqno_wrapped(struct drm_device *dev, |
1116 | u32 seqno) | |
1117 | { | |
1118 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1119 | return dev_priv->last_seqno < seqno; | |
1120 | } | |
1121 | ||
c8c99b0f BW |
1122 | /** |
1123 | * intel_ring_sync - sync the waiter to the signaller on seqno | |
1124 | * | |
1125 | * @waiter - ring that is waiting | |
1126 | * @signaller - ring which has, or will signal | |
1127 | * @seqno - seqno which the waiter will block on | |
1128 | */ | |
5ee426ca BW |
1129 | |
1130 | static int | |
1131 | gen8_ring_sync(struct intel_engine_cs *waiter, | |
1132 | struct intel_engine_cs *signaller, | |
1133 | u32 seqno) | |
1134 | { | |
1135 | struct drm_i915_private *dev_priv = waiter->dev->dev_private; | |
1136 | int ret; | |
1137 | ||
1138 | ret = intel_ring_begin(waiter, 4); | |
1139 | if (ret) | |
1140 | return ret; | |
1141 | ||
1142 | intel_ring_emit(waiter, MI_SEMAPHORE_WAIT | | |
1143 | MI_SEMAPHORE_GLOBAL_GTT | | |
bae4fcd2 | 1144 | MI_SEMAPHORE_POLL | |
5ee426ca BW |
1145 | MI_SEMAPHORE_SAD_GTE_SDD); |
1146 | intel_ring_emit(waiter, seqno); | |
1147 | intel_ring_emit(waiter, | |
1148 | lower_32_bits(GEN8_WAIT_OFFSET(waiter, signaller->id))); | |
1149 | intel_ring_emit(waiter, | |
1150 | upper_32_bits(GEN8_WAIT_OFFSET(waiter, signaller->id))); | |
1151 | intel_ring_advance(waiter); | |
1152 | return 0; | |
1153 | } | |
1154 | ||
c8c99b0f | 1155 | static int |
a4872ba6 OM |
1156 | gen6_ring_sync(struct intel_engine_cs *waiter, |
1157 | struct intel_engine_cs *signaller, | |
686cb5f9 | 1158 | u32 seqno) |
1ec14ad3 | 1159 | { |
c8c99b0f BW |
1160 | u32 dw1 = MI_SEMAPHORE_MBOX | |
1161 | MI_SEMAPHORE_COMPARE | | |
1162 | MI_SEMAPHORE_REGISTER; | |
ebc348b2 BW |
1163 | u32 wait_mbox = signaller->semaphore.mbox.wait[waiter->id]; |
1164 | int ret; | |
1ec14ad3 | 1165 | |
1500f7ea BW |
1166 | /* Throughout all of the GEM code, seqno passed implies our current |
1167 | * seqno is >= the last seqno executed. However for hardware the | |
1168 | * comparison is strictly greater than. | |
1169 | */ | |
1170 | seqno -= 1; | |
1171 | ||
ebc348b2 | 1172 | WARN_ON(wait_mbox == MI_SEMAPHORE_SYNC_INVALID); |
686cb5f9 | 1173 | |
c8c99b0f | 1174 | ret = intel_ring_begin(waiter, 4); |
1ec14ad3 CW |
1175 | if (ret) |
1176 | return ret; | |
1177 | ||
f72b3435 MK |
1178 | /* If seqno wrap happened, omit the wait with no-ops */ |
1179 | if (likely(!i915_gem_has_seqno_wrapped(waiter->dev, seqno))) { | |
ebc348b2 | 1180 | intel_ring_emit(waiter, dw1 | wait_mbox); |
f72b3435 MK |
1181 | intel_ring_emit(waiter, seqno); |
1182 | intel_ring_emit(waiter, 0); | |
1183 | intel_ring_emit(waiter, MI_NOOP); | |
1184 | } else { | |
1185 | intel_ring_emit(waiter, MI_NOOP); | |
1186 | intel_ring_emit(waiter, MI_NOOP); | |
1187 | intel_ring_emit(waiter, MI_NOOP); | |
1188 | intel_ring_emit(waiter, MI_NOOP); | |
1189 | } | |
c8c99b0f | 1190 | intel_ring_advance(waiter); |
1ec14ad3 CW |
1191 | |
1192 | return 0; | |
1193 | } | |
1194 | ||
c6df541c CW |
1195 | #define PIPE_CONTROL_FLUSH(ring__, addr__) \ |
1196 | do { \ | |
fcbc34e4 KG |
1197 | intel_ring_emit(ring__, GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | \ |
1198 | PIPE_CONTROL_DEPTH_STALL); \ | |
c6df541c CW |
1199 | intel_ring_emit(ring__, (addr__) | PIPE_CONTROL_GLOBAL_GTT); \ |
1200 | intel_ring_emit(ring__, 0); \ | |
1201 | intel_ring_emit(ring__, 0); \ | |
1202 | } while (0) | |
1203 | ||
1204 | static int | |
a4872ba6 | 1205 | pc_render_add_request(struct intel_engine_cs *ring) |
c6df541c | 1206 | { |
18393f63 | 1207 | u32 scratch_addr = ring->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
c6df541c CW |
1208 | int ret; |
1209 | ||
1210 | /* For Ironlake, MI_USER_INTERRUPT was deprecated and apparently | |
1211 | * incoherent with writes to memory, i.e. completely fubar, | |
1212 | * so we need to use PIPE_NOTIFY instead. | |
1213 | * | |
1214 | * However, we also need to workaround the qword write | |
1215 | * incoherence by flushing the 6 PIPE_NOTIFY buffers out to | |
1216 | * memory before requesting an interrupt. | |
1217 | */ | |
1218 | ret = intel_ring_begin(ring, 32); | |
1219 | if (ret) | |
1220 | return ret; | |
1221 | ||
fcbc34e4 | 1222 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | |
9d971b37 KG |
1223 | PIPE_CONTROL_WRITE_FLUSH | |
1224 | PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE); | |
0d1aacac | 1225 | intel_ring_emit(ring, ring->scratch.gtt_offset | PIPE_CONTROL_GLOBAL_GTT); |
6259cead JH |
1226 | intel_ring_emit(ring, |
1227 | i915_gem_request_get_seqno(ring->outstanding_lazy_request)); | |
c6df541c CW |
1228 | intel_ring_emit(ring, 0); |
1229 | PIPE_CONTROL_FLUSH(ring, scratch_addr); | |
18393f63 | 1230 | scratch_addr += 2 * CACHELINE_BYTES; /* write to separate cachelines */ |
c6df541c | 1231 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
18393f63 | 1232 | scratch_addr += 2 * CACHELINE_BYTES; |
c6df541c | 1233 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
18393f63 | 1234 | scratch_addr += 2 * CACHELINE_BYTES; |
c6df541c | 1235 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
18393f63 | 1236 | scratch_addr += 2 * CACHELINE_BYTES; |
c6df541c | 1237 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
18393f63 | 1238 | scratch_addr += 2 * CACHELINE_BYTES; |
c6df541c | 1239 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
a71d8d94 | 1240 | |
fcbc34e4 | 1241 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | |
9d971b37 KG |
1242 | PIPE_CONTROL_WRITE_FLUSH | |
1243 | PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | | |
c6df541c | 1244 | PIPE_CONTROL_NOTIFY); |
0d1aacac | 1245 | intel_ring_emit(ring, ring->scratch.gtt_offset | PIPE_CONTROL_GLOBAL_GTT); |
6259cead JH |
1246 | intel_ring_emit(ring, |
1247 | i915_gem_request_get_seqno(ring->outstanding_lazy_request)); | |
c6df541c | 1248 | intel_ring_emit(ring, 0); |
09246732 | 1249 | __intel_ring_advance(ring); |
c6df541c | 1250 | |
c6df541c CW |
1251 | return 0; |
1252 | } | |
1253 | ||
4cd53c0c | 1254 | static u32 |
a4872ba6 | 1255 | gen6_ring_get_seqno(struct intel_engine_cs *ring, bool lazy_coherency) |
4cd53c0c | 1256 | { |
4cd53c0c DV |
1257 | /* Workaround to force correct ordering between irq and seqno writes on |
1258 | * ivb (and maybe also on snb) by reading from a CS register (like | |
1259 | * ACTHD) before reading the status page. */ | |
50877445 CW |
1260 | if (!lazy_coherency) { |
1261 | struct drm_i915_private *dev_priv = ring->dev->dev_private; | |
1262 | POSTING_READ(RING_ACTHD(ring->mmio_base)); | |
1263 | } | |
1264 | ||
4cd53c0c DV |
1265 | return intel_read_status_page(ring, I915_GEM_HWS_INDEX); |
1266 | } | |
1267 | ||
8187a2b7 | 1268 | static u32 |
a4872ba6 | 1269 | ring_get_seqno(struct intel_engine_cs *ring, bool lazy_coherency) |
8187a2b7 | 1270 | { |
1ec14ad3 CW |
1271 | return intel_read_status_page(ring, I915_GEM_HWS_INDEX); |
1272 | } | |
1273 | ||
b70ec5bf | 1274 | static void |
a4872ba6 | 1275 | ring_set_seqno(struct intel_engine_cs *ring, u32 seqno) |
b70ec5bf MK |
1276 | { |
1277 | intel_write_status_page(ring, I915_GEM_HWS_INDEX, seqno); | |
1278 | } | |
1279 | ||
c6df541c | 1280 | static u32 |
a4872ba6 | 1281 | pc_render_get_seqno(struct intel_engine_cs *ring, bool lazy_coherency) |
c6df541c | 1282 | { |
0d1aacac | 1283 | return ring->scratch.cpu_page[0]; |
c6df541c CW |
1284 | } |
1285 | ||
b70ec5bf | 1286 | static void |
a4872ba6 | 1287 | pc_render_set_seqno(struct intel_engine_cs *ring, u32 seqno) |
b70ec5bf | 1288 | { |
0d1aacac | 1289 | ring->scratch.cpu_page[0] = seqno; |
b70ec5bf MK |
1290 | } |
1291 | ||
e48d8634 | 1292 | static bool |
a4872ba6 | 1293 | gen5_ring_get_irq(struct intel_engine_cs *ring) |
e48d8634 DV |
1294 | { |
1295 | struct drm_device *dev = ring->dev; | |
4640c4ff | 1296 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1297 | unsigned long flags; |
e48d8634 | 1298 | |
7cd512f1 | 1299 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
e48d8634 DV |
1300 | return false; |
1301 | ||
7338aefa | 1302 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
43eaea13 | 1303 | if (ring->irq_refcount++ == 0) |
480c8033 | 1304 | gen5_enable_gt_irq(dev_priv, ring->irq_enable_mask); |
7338aefa | 1305 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
e48d8634 DV |
1306 | |
1307 | return true; | |
1308 | } | |
1309 | ||
1310 | static void | |
a4872ba6 | 1311 | gen5_ring_put_irq(struct intel_engine_cs *ring) |
e48d8634 DV |
1312 | { |
1313 | struct drm_device *dev = ring->dev; | |
4640c4ff | 1314 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1315 | unsigned long flags; |
e48d8634 | 1316 | |
7338aefa | 1317 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
43eaea13 | 1318 | if (--ring->irq_refcount == 0) |
480c8033 | 1319 | gen5_disable_gt_irq(dev_priv, ring->irq_enable_mask); |
7338aefa | 1320 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
e48d8634 DV |
1321 | } |
1322 | ||
b13c2b96 | 1323 | static bool |
a4872ba6 | 1324 | i9xx_ring_get_irq(struct intel_engine_cs *ring) |
62fdfeaf | 1325 | { |
78501eac | 1326 | struct drm_device *dev = ring->dev; |
4640c4ff | 1327 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1328 | unsigned long flags; |
62fdfeaf | 1329 | |
7cd512f1 | 1330 | if (!intel_irqs_enabled(dev_priv)) |
b13c2b96 CW |
1331 | return false; |
1332 | ||
7338aefa | 1333 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1334 | if (ring->irq_refcount++ == 0) { |
f637fde4 DV |
1335 | dev_priv->irq_mask &= ~ring->irq_enable_mask; |
1336 | I915_WRITE(IMR, dev_priv->irq_mask); | |
1337 | POSTING_READ(IMR); | |
1338 | } | |
7338aefa | 1339 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
b13c2b96 CW |
1340 | |
1341 | return true; | |
62fdfeaf EA |
1342 | } |
1343 | ||
8187a2b7 | 1344 | static void |
a4872ba6 | 1345 | i9xx_ring_put_irq(struct intel_engine_cs *ring) |
62fdfeaf | 1346 | { |
78501eac | 1347 | struct drm_device *dev = ring->dev; |
4640c4ff | 1348 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1349 | unsigned long flags; |
62fdfeaf | 1350 | |
7338aefa | 1351 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1352 | if (--ring->irq_refcount == 0) { |
f637fde4 DV |
1353 | dev_priv->irq_mask |= ring->irq_enable_mask; |
1354 | I915_WRITE(IMR, dev_priv->irq_mask); | |
1355 | POSTING_READ(IMR); | |
1356 | } | |
7338aefa | 1357 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
62fdfeaf EA |
1358 | } |
1359 | ||
c2798b19 | 1360 | static bool |
a4872ba6 | 1361 | i8xx_ring_get_irq(struct intel_engine_cs *ring) |
c2798b19 CW |
1362 | { |
1363 | struct drm_device *dev = ring->dev; | |
4640c4ff | 1364 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1365 | unsigned long flags; |
c2798b19 | 1366 | |
7cd512f1 | 1367 | if (!intel_irqs_enabled(dev_priv)) |
c2798b19 CW |
1368 | return false; |
1369 | ||
7338aefa | 1370 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1371 | if (ring->irq_refcount++ == 0) { |
c2798b19 CW |
1372 | dev_priv->irq_mask &= ~ring->irq_enable_mask; |
1373 | I915_WRITE16(IMR, dev_priv->irq_mask); | |
1374 | POSTING_READ16(IMR); | |
1375 | } | |
7338aefa | 1376 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
c2798b19 CW |
1377 | |
1378 | return true; | |
1379 | } | |
1380 | ||
1381 | static void | |
a4872ba6 | 1382 | i8xx_ring_put_irq(struct intel_engine_cs *ring) |
c2798b19 CW |
1383 | { |
1384 | struct drm_device *dev = ring->dev; | |
4640c4ff | 1385 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1386 | unsigned long flags; |
c2798b19 | 1387 | |
7338aefa | 1388 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1389 | if (--ring->irq_refcount == 0) { |
c2798b19 CW |
1390 | dev_priv->irq_mask |= ring->irq_enable_mask; |
1391 | I915_WRITE16(IMR, dev_priv->irq_mask); | |
1392 | POSTING_READ16(IMR); | |
1393 | } | |
7338aefa | 1394 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
c2798b19 CW |
1395 | } |
1396 | ||
a4872ba6 | 1397 | void intel_ring_setup_status_page(struct intel_engine_cs *ring) |
8187a2b7 | 1398 | { |
4593010b | 1399 | struct drm_device *dev = ring->dev; |
4640c4ff | 1400 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
4593010b EA |
1401 | u32 mmio = 0; |
1402 | ||
1403 | /* The ring status page addresses are no longer next to the rest of | |
1404 | * the ring registers as of gen7. | |
1405 | */ | |
1406 | if (IS_GEN7(dev)) { | |
1407 | switch (ring->id) { | |
96154f2f | 1408 | case RCS: |
4593010b EA |
1409 | mmio = RENDER_HWS_PGA_GEN7; |
1410 | break; | |
96154f2f | 1411 | case BCS: |
4593010b EA |
1412 | mmio = BLT_HWS_PGA_GEN7; |
1413 | break; | |
77fe2ff3 ZY |
1414 | /* |
1415 | * VCS2 actually doesn't exist on Gen7. Only shut up | |
1416 | * gcc switch check warning | |
1417 | */ | |
1418 | case VCS2: | |
96154f2f | 1419 | case VCS: |
4593010b EA |
1420 | mmio = BSD_HWS_PGA_GEN7; |
1421 | break; | |
4a3dd19d | 1422 | case VECS: |
9a8a2213 BW |
1423 | mmio = VEBOX_HWS_PGA_GEN7; |
1424 | break; | |
4593010b EA |
1425 | } |
1426 | } else if (IS_GEN6(ring->dev)) { | |
1427 | mmio = RING_HWS_PGA_GEN6(ring->mmio_base); | |
1428 | } else { | |
eb0d4b75 | 1429 | /* XXX: gen8 returns to sanity */ |
4593010b EA |
1430 | mmio = RING_HWS_PGA(ring->mmio_base); |
1431 | } | |
1432 | ||
78501eac CW |
1433 | I915_WRITE(mmio, (u32)ring->status_page.gfx_addr); |
1434 | POSTING_READ(mmio); | |
884020bf | 1435 | |
dc616b89 DL |
1436 | /* |
1437 | * Flush the TLB for this page | |
1438 | * | |
1439 | * FIXME: These two bits have disappeared on gen8, so a question | |
1440 | * arises: do we still need this and if so how should we go about | |
1441 | * invalidating the TLB? | |
1442 | */ | |
1443 | if (INTEL_INFO(dev)->gen >= 6 && INTEL_INFO(dev)->gen < 8) { | |
884020bf | 1444 | u32 reg = RING_INSTPM(ring->mmio_base); |
02f6a1e7 NKK |
1445 | |
1446 | /* ring should be idle before issuing a sync flush*/ | |
1447 | WARN_ON((I915_READ_MODE(ring) & MODE_IDLE) == 0); | |
1448 | ||
884020bf CW |
1449 | I915_WRITE(reg, |
1450 | _MASKED_BIT_ENABLE(INSTPM_TLB_INVALIDATE | | |
1451 | INSTPM_SYNC_FLUSH)); | |
1452 | if (wait_for((I915_READ(reg) & INSTPM_SYNC_FLUSH) == 0, | |
1453 | 1000)) | |
1454 | DRM_ERROR("%s: wait for SyncFlush to complete for TLB invalidation timed out\n", | |
1455 | ring->name); | |
1456 | } | |
8187a2b7 ZN |
1457 | } |
1458 | ||
b72f3acb | 1459 | static int |
a4872ba6 | 1460 | bsd_ring_flush(struct intel_engine_cs *ring, |
78501eac CW |
1461 | u32 invalidate_domains, |
1462 | u32 flush_domains) | |
d1b851fc | 1463 | { |
b72f3acb CW |
1464 | int ret; |
1465 | ||
b72f3acb CW |
1466 | ret = intel_ring_begin(ring, 2); |
1467 | if (ret) | |
1468 | return ret; | |
1469 | ||
1470 | intel_ring_emit(ring, MI_FLUSH); | |
1471 | intel_ring_emit(ring, MI_NOOP); | |
1472 | intel_ring_advance(ring); | |
1473 | return 0; | |
d1b851fc ZN |
1474 | } |
1475 | ||
3cce469c | 1476 | static int |
a4872ba6 | 1477 | i9xx_add_request(struct intel_engine_cs *ring) |
d1b851fc | 1478 | { |
3cce469c CW |
1479 | int ret; |
1480 | ||
1481 | ret = intel_ring_begin(ring, 4); | |
1482 | if (ret) | |
1483 | return ret; | |
6f392d54 | 1484 | |
3cce469c CW |
1485 | intel_ring_emit(ring, MI_STORE_DWORD_INDEX); |
1486 | intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | |
6259cead JH |
1487 | intel_ring_emit(ring, |
1488 | i915_gem_request_get_seqno(ring->outstanding_lazy_request)); | |
3cce469c | 1489 | intel_ring_emit(ring, MI_USER_INTERRUPT); |
09246732 | 1490 | __intel_ring_advance(ring); |
d1b851fc | 1491 | |
3cce469c | 1492 | return 0; |
d1b851fc ZN |
1493 | } |
1494 | ||
0f46832f | 1495 | static bool |
a4872ba6 | 1496 | gen6_ring_get_irq(struct intel_engine_cs *ring) |
0f46832f CW |
1497 | { |
1498 | struct drm_device *dev = ring->dev; | |
4640c4ff | 1499 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1500 | unsigned long flags; |
0f46832f | 1501 | |
7cd512f1 DV |
1502 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
1503 | return false; | |
0f46832f | 1504 | |
7338aefa | 1505 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1506 | if (ring->irq_refcount++ == 0) { |
040d2baa | 1507 | if (HAS_L3_DPF(dev) && ring->id == RCS) |
cc609d5d BW |
1508 | I915_WRITE_IMR(ring, |
1509 | ~(ring->irq_enable_mask | | |
35a85ac6 | 1510 | GT_PARITY_ERROR(dev))); |
15b9f80e BW |
1511 | else |
1512 | I915_WRITE_IMR(ring, ~ring->irq_enable_mask); | |
480c8033 | 1513 | gen5_enable_gt_irq(dev_priv, ring->irq_enable_mask); |
0f46832f | 1514 | } |
7338aefa | 1515 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
0f46832f CW |
1516 | |
1517 | return true; | |
1518 | } | |
1519 | ||
1520 | static void | |
a4872ba6 | 1521 | gen6_ring_put_irq(struct intel_engine_cs *ring) |
0f46832f CW |
1522 | { |
1523 | struct drm_device *dev = ring->dev; | |
4640c4ff | 1524 | struct drm_i915_private *dev_priv = dev->dev_private; |
7338aefa | 1525 | unsigned long flags; |
0f46832f | 1526 | |
7338aefa | 1527 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1528 | if (--ring->irq_refcount == 0) { |
040d2baa | 1529 | if (HAS_L3_DPF(dev) && ring->id == RCS) |
35a85ac6 | 1530 | I915_WRITE_IMR(ring, ~GT_PARITY_ERROR(dev)); |
15b9f80e BW |
1531 | else |
1532 | I915_WRITE_IMR(ring, ~0); | |
480c8033 | 1533 | gen5_disable_gt_irq(dev_priv, ring->irq_enable_mask); |
1ec14ad3 | 1534 | } |
7338aefa | 1535 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
d1b851fc ZN |
1536 | } |
1537 | ||
a19d2933 | 1538 | static bool |
a4872ba6 | 1539 | hsw_vebox_get_irq(struct intel_engine_cs *ring) |
a19d2933 BW |
1540 | { |
1541 | struct drm_device *dev = ring->dev; | |
1542 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1543 | unsigned long flags; | |
1544 | ||
7cd512f1 | 1545 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
a19d2933 BW |
1546 | return false; |
1547 | ||
59cdb63d | 1548 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1549 | if (ring->irq_refcount++ == 0) { |
a19d2933 | 1550 | I915_WRITE_IMR(ring, ~ring->irq_enable_mask); |
480c8033 | 1551 | gen6_enable_pm_irq(dev_priv, ring->irq_enable_mask); |
a19d2933 | 1552 | } |
59cdb63d | 1553 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
a19d2933 BW |
1554 | |
1555 | return true; | |
1556 | } | |
1557 | ||
1558 | static void | |
a4872ba6 | 1559 | hsw_vebox_put_irq(struct intel_engine_cs *ring) |
a19d2933 BW |
1560 | { |
1561 | struct drm_device *dev = ring->dev; | |
1562 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1563 | unsigned long flags; | |
1564 | ||
59cdb63d | 1565 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
c7113cc3 | 1566 | if (--ring->irq_refcount == 0) { |
a19d2933 | 1567 | I915_WRITE_IMR(ring, ~0); |
480c8033 | 1568 | gen6_disable_pm_irq(dev_priv, ring->irq_enable_mask); |
a19d2933 | 1569 | } |
59cdb63d | 1570 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
a19d2933 BW |
1571 | } |
1572 | ||
abd58f01 | 1573 | static bool |
a4872ba6 | 1574 | gen8_ring_get_irq(struct intel_engine_cs *ring) |
abd58f01 BW |
1575 | { |
1576 | struct drm_device *dev = ring->dev; | |
1577 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1578 | unsigned long flags; | |
1579 | ||
7cd512f1 | 1580 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
abd58f01 BW |
1581 | return false; |
1582 | ||
1583 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
1584 | if (ring->irq_refcount++ == 0) { | |
1585 | if (HAS_L3_DPF(dev) && ring->id == RCS) { | |
1586 | I915_WRITE_IMR(ring, | |
1587 | ~(ring->irq_enable_mask | | |
1588 | GT_RENDER_L3_PARITY_ERROR_INTERRUPT)); | |
1589 | } else { | |
1590 | I915_WRITE_IMR(ring, ~ring->irq_enable_mask); | |
1591 | } | |
1592 | POSTING_READ(RING_IMR(ring->mmio_base)); | |
1593 | } | |
1594 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
1595 | ||
1596 | return true; | |
1597 | } | |
1598 | ||
1599 | static void | |
a4872ba6 | 1600 | gen8_ring_put_irq(struct intel_engine_cs *ring) |
abd58f01 BW |
1601 | { |
1602 | struct drm_device *dev = ring->dev; | |
1603 | struct drm_i915_private *dev_priv = dev->dev_private; | |
1604 | unsigned long flags; | |
1605 | ||
1606 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
1607 | if (--ring->irq_refcount == 0) { | |
1608 | if (HAS_L3_DPF(dev) && ring->id == RCS) { | |
1609 | I915_WRITE_IMR(ring, | |
1610 | ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT); | |
1611 | } else { | |
1612 | I915_WRITE_IMR(ring, ~0); | |
1613 | } | |
1614 | POSTING_READ(RING_IMR(ring->mmio_base)); | |
1615 | } | |
1616 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
1617 | } | |
1618 | ||
d1b851fc | 1619 | static int |
a4872ba6 | 1620 | i965_dispatch_execbuffer(struct intel_engine_cs *ring, |
9bcb144c | 1621 | u64 offset, u32 length, |
d7d4eedd | 1622 | unsigned flags) |
d1b851fc | 1623 | { |
e1f99ce6 | 1624 | int ret; |
78501eac | 1625 | |
e1f99ce6 CW |
1626 | ret = intel_ring_begin(ring, 2); |
1627 | if (ret) | |
1628 | return ret; | |
1629 | ||
78501eac | 1630 | intel_ring_emit(ring, |
65f56876 CW |
1631 | MI_BATCH_BUFFER_START | |
1632 | MI_BATCH_GTT | | |
d7d4eedd | 1633 | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE_I965)); |
c4e7a414 | 1634 | intel_ring_emit(ring, offset); |
78501eac CW |
1635 | intel_ring_advance(ring); |
1636 | ||
d1b851fc ZN |
1637 | return 0; |
1638 | } | |
1639 | ||
b45305fc DV |
1640 | /* Just userspace ABI convention to limit the wa batch bo to a resonable size */ |
1641 | #define I830_BATCH_LIMIT (256*1024) | |
c4d69da1 CW |
1642 | #define I830_TLB_ENTRIES (2) |
1643 | #define I830_WA_SIZE max(I830_TLB_ENTRIES*4096, I830_BATCH_LIMIT) | |
8187a2b7 | 1644 | static int |
a4872ba6 | 1645 | i830_dispatch_execbuffer(struct intel_engine_cs *ring, |
9bcb144c | 1646 | u64 offset, u32 len, |
d7d4eedd | 1647 | unsigned flags) |
62fdfeaf | 1648 | { |
c4d69da1 | 1649 | u32 cs_offset = ring->scratch.gtt_offset; |
c4e7a414 | 1650 | int ret; |
62fdfeaf | 1651 | |
c4d69da1 CW |
1652 | ret = intel_ring_begin(ring, 6); |
1653 | if (ret) | |
1654 | return ret; | |
62fdfeaf | 1655 | |
c4d69da1 CW |
1656 | /* Evict the invalid PTE TLBs */ |
1657 | intel_ring_emit(ring, COLOR_BLT_CMD | BLT_WRITE_RGBA); | |
1658 | intel_ring_emit(ring, BLT_DEPTH_32 | BLT_ROP_COLOR_COPY | 4096); | |
1659 | intel_ring_emit(ring, I830_TLB_ENTRIES << 16 | 4); /* load each page */ | |
1660 | intel_ring_emit(ring, cs_offset); | |
1661 | intel_ring_emit(ring, 0xdeadbeef); | |
1662 | intel_ring_emit(ring, MI_NOOP); | |
1663 | intel_ring_advance(ring); | |
b45305fc | 1664 | |
c4d69da1 | 1665 | if ((flags & I915_DISPATCH_PINNED) == 0) { |
b45305fc DV |
1666 | if (len > I830_BATCH_LIMIT) |
1667 | return -ENOSPC; | |
1668 | ||
c4d69da1 | 1669 | ret = intel_ring_begin(ring, 6 + 2); |
b45305fc DV |
1670 | if (ret) |
1671 | return ret; | |
c4d69da1 CW |
1672 | |
1673 | /* Blit the batch (which has now all relocs applied) to the | |
1674 | * stable batch scratch bo area (so that the CS never | |
1675 | * stumbles over its tlb invalidation bug) ... | |
1676 | */ | |
1677 | intel_ring_emit(ring, SRC_COPY_BLT_CMD | BLT_WRITE_RGBA); | |
1678 | intel_ring_emit(ring, BLT_DEPTH_32 | BLT_ROP_SRC_COPY | 4096); | |
611a7a4f | 1679 | intel_ring_emit(ring, DIV_ROUND_UP(len, 4096) << 16 | 4096); |
b45305fc | 1680 | intel_ring_emit(ring, cs_offset); |
b45305fc DV |
1681 | intel_ring_emit(ring, 4096); |
1682 | intel_ring_emit(ring, offset); | |
c4d69da1 | 1683 | |
b45305fc | 1684 | intel_ring_emit(ring, MI_FLUSH); |
c4d69da1 CW |
1685 | intel_ring_emit(ring, MI_NOOP); |
1686 | intel_ring_advance(ring); | |
b45305fc DV |
1687 | |
1688 | /* ... and execute it. */ | |
c4d69da1 | 1689 | offset = cs_offset; |
b45305fc | 1690 | } |
e1f99ce6 | 1691 | |
c4d69da1 CW |
1692 | ret = intel_ring_begin(ring, 4); |
1693 | if (ret) | |
1694 | return ret; | |
1695 | ||
1696 | intel_ring_emit(ring, MI_BATCH_BUFFER); | |
1697 | intel_ring_emit(ring, offset | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE)); | |
1698 | intel_ring_emit(ring, offset + len - 8); | |
1699 | intel_ring_emit(ring, MI_NOOP); | |
1700 | intel_ring_advance(ring); | |
1701 | ||
fb3256da DV |
1702 | return 0; |
1703 | } | |
1704 | ||
1705 | static int | |
a4872ba6 | 1706 | i915_dispatch_execbuffer(struct intel_engine_cs *ring, |
9bcb144c | 1707 | u64 offset, u32 len, |
d7d4eedd | 1708 | unsigned flags) |
fb3256da DV |
1709 | { |
1710 | int ret; | |
1711 | ||
1712 | ret = intel_ring_begin(ring, 2); | |
1713 | if (ret) | |
1714 | return ret; | |
1715 | ||
65f56876 | 1716 | intel_ring_emit(ring, MI_BATCH_BUFFER_START | MI_BATCH_GTT); |
d7d4eedd | 1717 | intel_ring_emit(ring, offset | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE)); |
c4e7a414 | 1718 | intel_ring_advance(ring); |
62fdfeaf | 1719 | |
62fdfeaf EA |
1720 | return 0; |
1721 | } | |
1722 | ||
a4872ba6 | 1723 | static void cleanup_status_page(struct intel_engine_cs *ring) |
62fdfeaf | 1724 | { |
05394f39 | 1725 | struct drm_i915_gem_object *obj; |
62fdfeaf | 1726 | |
8187a2b7 ZN |
1727 | obj = ring->status_page.obj; |
1728 | if (obj == NULL) | |
62fdfeaf | 1729 | return; |
62fdfeaf | 1730 | |
9da3da66 | 1731 | kunmap(sg_page(obj->pages->sgl)); |
d7f46fc4 | 1732 | i915_gem_object_ggtt_unpin(obj); |
05394f39 | 1733 | drm_gem_object_unreference(&obj->base); |
8187a2b7 | 1734 | ring->status_page.obj = NULL; |
62fdfeaf EA |
1735 | } |
1736 | ||
a4872ba6 | 1737 | static int init_status_page(struct intel_engine_cs *ring) |
62fdfeaf | 1738 | { |
05394f39 | 1739 | struct drm_i915_gem_object *obj; |
62fdfeaf | 1740 | |
e3efda49 | 1741 | if ((obj = ring->status_page.obj) == NULL) { |
1f767e02 | 1742 | unsigned flags; |
e3efda49 | 1743 | int ret; |
e4ffd173 | 1744 | |
e3efda49 CW |
1745 | obj = i915_gem_alloc_object(ring->dev, 4096); |
1746 | if (obj == NULL) { | |
1747 | DRM_ERROR("Failed to allocate status page\n"); | |
1748 | return -ENOMEM; | |
1749 | } | |
62fdfeaf | 1750 | |
e3efda49 CW |
1751 | ret = i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); |
1752 | if (ret) | |
1753 | goto err_unref; | |
1754 | ||
1f767e02 CW |
1755 | flags = 0; |
1756 | if (!HAS_LLC(ring->dev)) | |
1757 | /* On g33, we cannot place HWS above 256MiB, so | |
1758 | * restrict its pinning to the low mappable arena. | |
1759 | * Though this restriction is not documented for | |
1760 | * gen4, gen5, or byt, they also behave similarly | |
1761 | * and hang if the HWS is placed at the top of the | |
1762 | * GTT. To generalise, it appears that all !llc | |
1763 | * platforms have issues with us placing the HWS | |
1764 | * above the mappable region (even though we never | |
1765 | * actualy map it). | |
1766 | */ | |
1767 | flags |= PIN_MAPPABLE; | |
1768 | ret = i915_gem_obj_ggtt_pin(obj, 4096, flags); | |
e3efda49 CW |
1769 | if (ret) { |
1770 | err_unref: | |
1771 | drm_gem_object_unreference(&obj->base); | |
1772 | return ret; | |
1773 | } | |
1774 | ||
1775 | ring->status_page.obj = obj; | |
1776 | } | |
62fdfeaf | 1777 | |
f343c5f6 | 1778 | ring->status_page.gfx_addr = i915_gem_obj_ggtt_offset(obj); |
9da3da66 | 1779 | ring->status_page.page_addr = kmap(sg_page(obj->pages->sgl)); |
8187a2b7 | 1780 | memset(ring->status_page.page_addr, 0, PAGE_SIZE); |
62fdfeaf | 1781 | |
8187a2b7 ZN |
1782 | DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", |
1783 | ring->name, ring->status_page.gfx_addr); | |
62fdfeaf EA |
1784 | |
1785 | return 0; | |
62fdfeaf EA |
1786 | } |
1787 | ||
a4872ba6 | 1788 | static int init_phys_status_page(struct intel_engine_cs *ring) |
6b8294a4 CW |
1789 | { |
1790 | struct drm_i915_private *dev_priv = ring->dev->dev_private; | |
6b8294a4 CW |
1791 | |
1792 | if (!dev_priv->status_page_dmah) { | |
1793 | dev_priv->status_page_dmah = | |
1794 | drm_pci_alloc(ring->dev, PAGE_SIZE, PAGE_SIZE); | |
1795 | if (!dev_priv->status_page_dmah) | |
1796 | return -ENOMEM; | |
1797 | } | |
1798 | ||
6b8294a4 CW |
1799 | ring->status_page.page_addr = dev_priv->status_page_dmah->vaddr; |
1800 | memset(ring->status_page.page_addr, 0, PAGE_SIZE); | |
1801 | ||
1802 | return 0; | |
1803 | } | |
1804 | ||
7ba717cf | 1805 | void intel_unpin_ringbuffer_obj(struct intel_ringbuffer *ringbuf) |
2919d291 | 1806 | { |
2919d291 | 1807 | iounmap(ringbuf->virtual_start); |
7ba717cf | 1808 | ringbuf->virtual_start = NULL; |
2919d291 | 1809 | i915_gem_object_ggtt_unpin(ringbuf->obj); |
7ba717cf TD |
1810 | } |
1811 | ||
1812 | int intel_pin_and_map_ringbuffer_obj(struct drm_device *dev, | |
1813 | struct intel_ringbuffer *ringbuf) | |
1814 | { | |
1815 | struct drm_i915_private *dev_priv = to_i915(dev); | |
1816 | struct drm_i915_gem_object *obj = ringbuf->obj; | |
1817 | int ret; | |
1818 | ||
1819 | ret = i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, PIN_MAPPABLE); | |
1820 | if (ret) | |
1821 | return ret; | |
1822 | ||
1823 | ret = i915_gem_object_set_to_gtt_domain(obj, true); | |
1824 | if (ret) { | |
1825 | i915_gem_object_ggtt_unpin(obj); | |
1826 | return ret; | |
1827 | } | |
1828 | ||
1829 | ringbuf->virtual_start = ioremap_wc(dev_priv->gtt.mappable_base + | |
1830 | i915_gem_obj_ggtt_offset(obj), ringbuf->size); | |
1831 | if (ringbuf->virtual_start == NULL) { | |
1832 | i915_gem_object_ggtt_unpin(obj); | |
1833 | return -EINVAL; | |
1834 | } | |
1835 | ||
1836 | return 0; | |
1837 | } | |
1838 | ||
1839 | void intel_destroy_ringbuffer_obj(struct intel_ringbuffer *ringbuf) | |
1840 | { | |
2919d291 OM |
1841 | drm_gem_object_unreference(&ringbuf->obj->base); |
1842 | ringbuf->obj = NULL; | |
1843 | } | |
1844 | ||
84c2377f OM |
1845 | int intel_alloc_ringbuffer_obj(struct drm_device *dev, |
1846 | struct intel_ringbuffer *ringbuf) | |
62fdfeaf | 1847 | { |
05394f39 | 1848 | struct drm_i915_gem_object *obj; |
62fdfeaf | 1849 | |
ebc052e0 CW |
1850 | obj = NULL; |
1851 | if (!HAS_LLC(dev)) | |
93b0a4e0 | 1852 | obj = i915_gem_object_create_stolen(dev, ringbuf->size); |
ebc052e0 | 1853 | if (obj == NULL) |
93b0a4e0 | 1854 | obj = i915_gem_alloc_object(dev, ringbuf->size); |
e3efda49 CW |
1855 | if (obj == NULL) |
1856 | return -ENOMEM; | |
8187a2b7 | 1857 | |
24f3a8cf AG |
1858 | /* mark ring buffers as read-only from GPU side by default */ |
1859 | obj->gt_ro = 1; | |
1860 | ||
93b0a4e0 | 1861 | ringbuf->obj = obj; |
e3efda49 | 1862 | |
7ba717cf | 1863 | return 0; |
e3efda49 CW |
1864 | } |
1865 | ||
1866 | static int intel_init_ring_buffer(struct drm_device *dev, | |
a4872ba6 | 1867 | struct intel_engine_cs *ring) |
e3efda49 | 1868 | { |
bfc882b4 | 1869 | struct intel_ringbuffer *ringbuf; |
e3efda49 CW |
1870 | int ret; |
1871 | ||
bfc882b4 DV |
1872 | WARN_ON(ring->buffer); |
1873 | ||
1874 | ringbuf = kzalloc(sizeof(*ringbuf), GFP_KERNEL); | |
1875 | if (!ringbuf) | |
1876 | return -ENOMEM; | |
1877 | ring->buffer = ringbuf; | |
8ee14975 | 1878 | |
e3efda49 CW |
1879 | ring->dev = dev; |
1880 | INIT_LIST_HEAD(&ring->active_list); | |
1881 | INIT_LIST_HEAD(&ring->request_list); | |
cc9130be | 1882 | INIT_LIST_HEAD(&ring->execlist_queue); |
93b0a4e0 | 1883 | ringbuf->size = 32 * PAGE_SIZE; |
0c7dd53b | 1884 | ringbuf->ring = ring; |
ebc348b2 | 1885 | memset(ring->semaphore.sync_seqno, 0, sizeof(ring->semaphore.sync_seqno)); |
e3efda49 CW |
1886 | |
1887 | init_waitqueue_head(&ring->irq_queue); | |
1888 | ||
1889 | if (I915_NEED_GFX_HWS(dev)) { | |
1890 | ret = init_status_page(ring); | |
1891 | if (ret) | |
8ee14975 | 1892 | goto error; |
e3efda49 CW |
1893 | } else { |
1894 | BUG_ON(ring->id != RCS); | |
1895 | ret = init_phys_status_page(ring); | |
1896 | if (ret) | |
8ee14975 | 1897 | goto error; |
e3efda49 CW |
1898 | } |
1899 | ||
bfc882b4 | 1900 | WARN_ON(ringbuf->obj); |
7ba717cf | 1901 | |
bfc882b4 DV |
1902 | ret = intel_alloc_ringbuffer_obj(dev, ringbuf); |
1903 | if (ret) { | |
1904 | DRM_ERROR("Failed to allocate ringbuffer %s: %d\n", | |
1905 | ring->name, ret); | |
1906 | goto error; | |
1907 | } | |
1908 | ||
1909 | ret = intel_pin_and_map_ringbuffer_obj(dev, ringbuf); | |
1910 | if (ret) { | |
1911 | DRM_ERROR("Failed to pin and map ringbuffer %s: %d\n", | |
1912 | ring->name, ret); | |
1913 | intel_destroy_ringbuffer_obj(ringbuf); | |
1914 | goto error; | |
e3efda49 | 1915 | } |
62fdfeaf | 1916 | |
55249baa CW |
1917 | /* Workaround an erratum on the i830 which causes a hang if |
1918 | * the TAIL pointer points to within the last 2 cachelines | |
1919 | * of the buffer. | |
1920 | */ | |
93b0a4e0 | 1921 | ringbuf->effective_size = ringbuf->size; |
e3efda49 | 1922 | if (IS_I830(dev) || IS_845G(dev)) |
93b0a4e0 | 1923 | ringbuf->effective_size -= 2 * CACHELINE_BYTES; |
55249baa | 1924 | |
44e895a8 BV |
1925 | ret = i915_cmd_parser_init_ring(ring); |
1926 | if (ret) | |
8ee14975 OM |
1927 | goto error; |
1928 | ||
8ee14975 | 1929 | return 0; |
351e3db2 | 1930 | |
8ee14975 OM |
1931 | error: |
1932 | kfree(ringbuf); | |
1933 | ring->buffer = NULL; | |
1934 | return ret; | |
62fdfeaf EA |
1935 | } |
1936 | ||
a4872ba6 | 1937 | void intel_cleanup_ring_buffer(struct intel_engine_cs *ring) |
62fdfeaf | 1938 | { |
6402c330 JH |
1939 | struct drm_i915_private *dev_priv; |
1940 | struct intel_ringbuffer *ringbuf; | |
33626e6a | 1941 | |
93b0a4e0 | 1942 | if (!intel_ring_initialized(ring)) |
62fdfeaf EA |
1943 | return; |
1944 | ||
6402c330 JH |
1945 | dev_priv = to_i915(ring->dev); |
1946 | ringbuf = ring->buffer; | |
1947 | ||
e3efda49 | 1948 | intel_stop_ring_buffer(ring); |
de8f0a50 | 1949 | WARN_ON(!IS_GEN2(ring->dev) && (I915_READ_MODE(ring) & MODE_IDLE) == 0); |
33626e6a | 1950 | |
7ba717cf | 1951 | intel_unpin_ringbuffer_obj(ringbuf); |
2919d291 | 1952 | intel_destroy_ringbuffer_obj(ringbuf); |
6259cead | 1953 | i915_gem_request_assign(&ring->outstanding_lazy_request, NULL); |
78501eac | 1954 | |
8d19215b ZN |
1955 | if (ring->cleanup) |
1956 | ring->cleanup(ring); | |
1957 | ||
78501eac | 1958 | cleanup_status_page(ring); |
44e895a8 BV |
1959 | |
1960 | i915_cmd_parser_fini_ring(ring); | |
8ee14975 | 1961 | |
93b0a4e0 | 1962 | kfree(ringbuf); |
8ee14975 | 1963 | ring->buffer = NULL; |
62fdfeaf EA |
1964 | } |
1965 | ||
a4872ba6 | 1966 | static int intel_ring_wait_request(struct intel_engine_cs *ring, int n) |
a71d8d94 | 1967 | { |
93b0a4e0 | 1968 | struct intel_ringbuffer *ringbuf = ring->buffer; |
a71d8d94 | 1969 | struct drm_i915_gem_request *request; |
a71d8d94 CW |
1970 | int ret; |
1971 | ||
ebd0fd4b DG |
1972 | if (intel_ring_space(ringbuf) >= n) |
1973 | return 0; | |
a71d8d94 CW |
1974 | |
1975 | list_for_each_entry(request, &ring->request_list, list) { | |
72f95afa | 1976 | if (__intel_ring_space(request->postfix, ringbuf->tail, |
82e104cc | 1977 | ringbuf->size) >= n) { |
a71d8d94 CW |
1978 | break; |
1979 | } | |
a71d8d94 CW |
1980 | } |
1981 | ||
a4b3a571 | 1982 | if (&request->list == &ring->request_list) |
a71d8d94 CW |
1983 | return -ENOSPC; |
1984 | ||
a4b3a571 | 1985 | ret = i915_wait_request(request); |
a71d8d94 CW |
1986 | if (ret) |
1987 | return ret; | |
1988 | ||
1cf0ba14 | 1989 | i915_gem_retire_requests_ring(ring); |
a71d8d94 CW |
1990 | |
1991 | return 0; | |
1992 | } | |
1993 | ||
a4872ba6 | 1994 | static int ring_wait_for_space(struct intel_engine_cs *ring, int n) |
62fdfeaf | 1995 | { |
78501eac | 1996 | struct drm_device *dev = ring->dev; |
cae5852d | 1997 | struct drm_i915_private *dev_priv = dev->dev_private; |
93b0a4e0 | 1998 | struct intel_ringbuffer *ringbuf = ring->buffer; |
78501eac | 1999 | unsigned long end; |
a71d8d94 | 2000 | int ret; |
c7dca47b | 2001 | |
a71d8d94 CW |
2002 | ret = intel_ring_wait_request(ring, n); |
2003 | if (ret != -ENOSPC) | |
2004 | return ret; | |
2005 | ||
09246732 CW |
2006 | /* force the tail write in case we have been skipping them */ |
2007 | __intel_ring_advance(ring); | |
2008 | ||
63ed2cb2 DV |
2009 | /* With GEM the hangcheck timer should kick us out of the loop, |
2010 | * leaving it early runs the risk of corrupting GEM state (due | |
2011 | * to running on almost untested codepaths). But on resume | |
2012 | * timers don't work yet, so prevent a complete hang in that | |
2013 | * case by choosing an insanely large timeout. */ | |
2014 | end = jiffies + 60 * HZ; | |
e6bfaf85 | 2015 | |
ebd0fd4b | 2016 | ret = 0; |
dcfe0506 | 2017 | trace_i915_ring_wait_begin(ring); |
8187a2b7 | 2018 | do { |
ebd0fd4b DG |
2019 | if (intel_ring_space(ringbuf) >= n) |
2020 | break; | |
93b0a4e0 | 2021 | ringbuf->head = I915_READ_HEAD(ring); |
ebd0fd4b | 2022 | if (intel_ring_space(ringbuf) >= n) |
dcfe0506 | 2023 | break; |
62fdfeaf | 2024 | |
e60a0b10 | 2025 | msleep(1); |
d6b2c790 | 2026 | |
dcfe0506 CW |
2027 | if (dev_priv->mm.interruptible && signal_pending(current)) { |
2028 | ret = -ERESTARTSYS; | |
2029 | break; | |
2030 | } | |
2031 | ||
33196ded DV |
2032 | ret = i915_gem_check_wedge(&dev_priv->gpu_error, |
2033 | dev_priv->mm.interruptible); | |
d6b2c790 | 2034 | if (ret) |
dcfe0506 CW |
2035 | break; |
2036 | ||
2037 | if (time_after(jiffies, end)) { | |
2038 | ret = -EBUSY; | |
2039 | break; | |
2040 | } | |
2041 | } while (1); | |
db53a302 | 2042 | trace_i915_ring_wait_end(ring); |
dcfe0506 | 2043 | return ret; |
8187a2b7 | 2044 | } |
62fdfeaf | 2045 | |
a4872ba6 | 2046 | static int intel_wrap_ring_buffer(struct intel_engine_cs *ring) |
3e960501 CW |
2047 | { |
2048 | uint32_t __iomem *virt; | |
93b0a4e0 OM |
2049 | struct intel_ringbuffer *ringbuf = ring->buffer; |
2050 | int rem = ringbuf->size - ringbuf->tail; | |
3e960501 | 2051 | |
93b0a4e0 | 2052 | if (ringbuf->space < rem) { |
3e960501 CW |
2053 | int ret = ring_wait_for_space(ring, rem); |
2054 | if (ret) | |
2055 | return ret; | |
2056 | } | |
2057 | ||
93b0a4e0 | 2058 | virt = ringbuf->virtual_start + ringbuf->tail; |
3e960501 CW |
2059 | rem /= 4; |
2060 | while (rem--) | |
2061 | iowrite32(MI_NOOP, virt++); | |
2062 | ||
93b0a4e0 | 2063 | ringbuf->tail = 0; |
ebd0fd4b | 2064 | intel_ring_update_space(ringbuf); |
3e960501 CW |
2065 | |
2066 | return 0; | |
2067 | } | |
2068 | ||
a4872ba6 | 2069 | int intel_ring_idle(struct intel_engine_cs *ring) |
3e960501 | 2070 | { |
a4b3a571 | 2071 | struct drm_i915_gem_request *req; |
3e960501 CW |
2072 | int ret; |
2073 | ||
2074 | /* We need to add any requests required to flush the objects and ring */ | |
6259cead | 2075 | if (ring->outstanding_lazy_request) { |
9400ae5c | 2076 | ret = i915_add_request(ring); |
3e960501 CW |
2077 | if (ret) |
2078 | return ret; | |
2079 | } | |
2080 | ||
2081 | /* Wait upon the last request to be completed */ | |
2082 | if (list_empty(&ring->request_list)) | |
2083 | return 0; | |
2084 | ||
a4b3a571 | 2085 | req = list_entry(ring->request_list.prev, |
3e960501 | 2086 | struct drm_i915_gem_request, |
a4b3a571 | 2087 | list); |
3e960501 | 2088 | |
a4b3a571 | 2089 | return i915_wait_request(req); |
3e960501 CW |
2090 | } |
2091 | ||
9d773091 | 2092 | static int |
6259cead | 2093 | intel_ring_alloc_request(struct intel_engine_cs *ring) |
9d773091 | 2094 | { |
9eba5d4a JH |
2095 | int ret; |
2096 | struct drm_i915_gem_request *request; | |
67e2937b | 2097 | struct drm_i915_private *dev_private = ring->dev->dev_private; |
9eba5d4a | 2098 | |
6259cead | 2099 | if (ring->outstanding_lazy_request) |
9d773091 | 2100 | return 0; |
3c0e234c | 2101 | |
aaeb1ba0 | 2102 | request = kzalloc(sizeof(*request), GFP_KERNEL); |
9eba5d4a JH |
2103 | if (request == NULL) |
2104 | return -ENOMEM; | |
3c0e234c | 2105 | |
abfe262a | 2106 | kref_init(&request->ref); |
ff79e857 | 2107 | request->ring = ring; |
67e2937b | 2108 | request->uniq = dev_private->request_uniq++; |
abfe262a | 2109 | |
6259cead | 2110 | ret = i915_gem_get_seqno(ring->dev, &request->seqno); |
9eba5d4a JH |
2111 | if (ret) { |
2112 | kfree(request); | |
2113 | return ret; | |
3c0e234c CW |
2114 | } |
2115 | ||
6259cead | 2116 | ring->outstanding_lazy_request = request; |
9eba5d4a | 2117 | return 0; |
9d773091 CW |
2118 | } |
2119 | ||
a4872ba6 | 2120 | static int __intel_ring_prepare(struct intel_engine_cs *ring, |
304d695c | 2121 | int bytes) |
cbcc80df | 2122 | { |
93b0a4e0 | 2123 | struct intel_ringbuffer *ringbuf = ring->buffer; |
cbcc80df MK |
2124 | int ret; |
2125 | ||
93b0a4e0 | 2126 | if (unlikely(ringbuf->tail + bytes > ringbuf->effective_size)) { |
cbcc80df MK |
2127 | ret = intel_wrap_ring_buffer(ring); |
2128 | if (unlikely(ret)) | |
2129 | return ret; | |
2130 | } | |
2131 | ||
93b0a4e0 | 2132 | if (unlikely(ringbuf->space < bytes)) { |
cbcc80df MK |
2133 | ret = ring_wait_for_space(ring, bytes); |
2134 | if (unlikely(ret)) | |
2135 | return ret; | |
2136 | } | |
2137 | ||
cbcc80df MK |
2138 | return 0; |
2139 | } | |
2140 | ||
a4872ba6 | 2141 | int intel_ring_begin(struct intel_engine_cs *ring, |
e1f99ce6 | 2142 | int num_dwords) |
8187a2b7 | 2143 | { |
4640c4ff | 2144 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
e1f99ce6 | 2145 | int ret; |
78501eac | 2146 | |
33196ded DV |
2147 | ret = i915_gem_check_wedge(&dev_priv->gpu_error, |
2148 | dev_priv->mm.interruptible); | |
de2b9985 DV |
2149 | if (ret) |
2150 | return ret; | |
21dd3734 | 2151 | |
304d695c CW |
2152 | ret = __intel_ring_prepare(ring, num_dwords * sizeof(uint32_t)); |
2153 | if (ret) | |
2154 | return ret; | |
2155 | ||
9d773091 | 2156 | /* Preallocate the olr before touching the ring */ |
6259cead | 2157 | ret = intel_ring_alloc_request(ring); |
9d773091 CW |
2158 | if (ret) |
2159 | return ret; | |
2160 | ||
ee1b1e5e | 2161 | ring->buffer->space -= num_dwords * sizeof(uint32_t); |
304d695c | 2162 | return 0; |
8187a2b7 | 2163 | } |
78501eac | 2164 | |
753b1ad4 | 2165 | /* Align the ring tail to a cacheline boundary */ |
a4872ba6 | 2166 | int intel_ring_cacheline_align(struct intel_engine_cs *ring) |
753b1ad4 | 2167 | { |
ee1b1e5e | 2168 | int num_dwords = (ring->buffer->tail & (CACHELINE_BYTES - 1)) / sizeof(uint32_t); |
753b1ad4 VS |
2169 | int ret; |
2170 | ||
2171 | if (num_dwords == 0) | |
2172 | return 0; | |
2173 | ||
18393f63 | 2174 | num_dwords = CACHELINE_BYTES / sizeof(uint32_t) - num_dwords; |
753b1ad4 VS |
2175 | ret = intel_ring_begin(ring, num_dwords); |
2176 | if (ret) | |
2177 | return ret; | |
2178 | ||
2179 | while (num_dwords--) | |
2180 | intel_ring_emit(ring, MI_NOOP); | |
2181 | ||
2182 | intel_ring_advance(ring); | |
2183 | ||
2184 | return 0; | |
2185 | } | |
2186 | ||
a4872ba6 | 2187 | void intel_ring_init_seqno(struct intel_engine_cs *ring, u32 seqno) |
498d2ac1 | 2188 | { |
3b2cc8ab OM |
2189 | struct drm_device *dev = ring->dev; |
2190 | struct drm_i915_private *dev_priv = dev->dev_private; | |
498d2ac1 | 2191 | |
6259cead | 2192 | BUG_ON(ring->outstanding_lazy_request); |
498d2ac1 | 2193 | |
3b2cc8ab | 2194 | if (INTEL_INFO(dev)->gen == 6 || INTEL_INFO(dev)->gen == 7) { |
f7e98ad4 MK |
2195 | I915_WRITE(RING_SYNC_0(ring->mmio_base), 0); |
2196 | I915_WRITE(RING_SYNC_1(ring->mmio_base), 0); | |
3b2cc8ab | 2197 | if (HAS_VEBOX(dev)) |
5020150b | 2198 | I915_WRITE(RING_SYNC_2(ring->mmio_base), 0); |
e1f99ce6 | 2199 | } |
d97ed339 | 2200 | |
f7e98ad4 | 2201 | ring->set_seqno(ring, seqno); |
92cab734 | 2202 | ring->hangcheck.seqno = seqno; |
8187a2b7 | 2203 | } |
62fdfeaf | 2204 | |
a4872ba6 | 2205 | static void gen6_bsd_ring_write_tail(struct intel_engine_cs *ring, |
297b0c5b | 2206 | u32 value) |
881f47b6 | 2207 | { |
4640c4ff | 2208 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
881f47b6 XH |
2209 | |
2210 | /* Every tail move must follow the sequence below */ | |
12f55818 CW |
2211 | |
2212 | /* Disable notification that the ring is IDLE. The GT | |
2213 | * will then assume that it is busy and bring it out of rc6. | |
2214 | */ | |
0206e353 | 2215 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
12f55818 CW |
2216 | _MASKED_BIT_ENABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
2217 | ||
2218 | /* Clear the context id. Here be magic! */ | |
2219 | I915_WRITE64(GEN6_BSD_RNCID, 0x0); | |
0206e353 | 2220 | |
12f55818 | 2221 | /* Wait for the ring not to be idle, i.e. for it to wake up. */ |
0206e353 | 2222 | if (wait_for((I915_READ(GEN6_BSD_SLEEP_PSMI_CONTROL) & |
12f55818 CW |
2223 | GEN6_BSD_SLEEP_INDICATOR) == 0, |
2224 | 50)) | |
2225 | DRM_ERROR("timed out waiting for the BSD ring to wake up\n"); | |
0206e353 | 2226 | |
12f55818 | 2227 | /* Now that the ring is fully powered up, update the tail */ |
0206e353 | 2228 | I915_WRITE_TAIL(ring, value); |
12f55818 CW |
2229 | POSTING_READ(RING_TAIL(ring->mmio_base)); |
2230 | ||
2231 | /* Let the ring send IDLE messages to the GT again, | |
2232 | * and so let it sleep to conserve power when idle. | |
2233 | */ | |
0206e353 | 2234 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
12f55818 | 2235 | _MASKED_BIT_DISABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
881f47b6 XH |
2236 | } |
2237 | ||
a4872ba6 | 2238 | static int gen6_bsd_ring_flush(struct intel_engine_cs *ring, |
ea251324 | 2239 | u32 invalidate, u32 flush) |
881f47b6 | 2240 | { |
71a77e07 | 2241 | uint32_t cmd; |
b72f3acb CW |
2242 | int ret; |
2243 | ||
b72f3acb CW |
2244 | ret = intel_ring_begin(ring, 4); |
2245 | if (ret) | |
2246 | return ret; | |
2247 | ||
71a77e07 | 2248 | cmd = MI_FLUSH_DW; |
075b3bba BW |
2249 | if (INTEL_INFO(ring->dev)->gen >= 8) |
2250 | cmd += 1; | |
9a289771 JB |
2251 | /* |
2252 | * Bspec vol 1c.5 - video engine command streamer: | |
2253 | * "If ENABLED, all TLBs will be invalidated once the flush | |
2254 | * operation is complete. This bit is only valid when the | |
2255 | * Post-Sync Operation field is a value of 1h or 3h." | |
2256 | */ | |
71a77e07 | 2257 | if (invalidate & I915_GEM_GPU_DOMAINS) |
9a289771 JB |
2258 | cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD | |
2259 | MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; | |
71a77e07 | 2260 | intel_ring_emit(ring, cmd); |
9a289771 | 2261 | intel_ring_emit(ring, I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT); |
075b3bba BW |
2262 | if (INTEL_INFO(ring->dev)->gen >= 8) { |
2263 | intel_ring_emit(ring, 0); /* upper addr */ | |
2264 | intel_ring_emit(ring, 0); /* value */ | |
2265 | } else { | |
2266 | intel_ring_emit(ring, 0); | |
2267 | intel_ring_emit(ring, MI_NOOP); | |
2268 | } | |
b72f3acb CW |
2269 | intel_ring_advance(ring); |
2270 | return 0; | |
881f47b6 XH |
2271 | } |
2272 | ||
1c7a0623 | 2273 | static int |
a4872ba6 | 2274 | gen8_ring_dispatch_execbuffer(struct intel_engine_cs *ring, |
9bcb144c | 2275 | u64 offset, u32 len, |
1c7a0623 BW |
2276 | unsigned flags) |
2277 | { | |
896ab1a5 | 2278 | bool ppgtt = USES_PPGTT(ring->dev) && !(flags & I915_DISPATCH_SECURE); |
1c7a0623 BW |
2279 | int ret; |
2280 | ||
2281 | ret = intel_ring_begin(ring, 4); | |
2282 | if (ret) | |
2283 | return ret; | |
2284 | ||
2285 | /* FIXME(BDW): Address space and security selectors. */ | |
28cf5415 | 2286 | intel_ring_emit(ring, MI_BATCH_BUFFER_START_GEN8 | (ppgtt<<8)); |
9bcb144c BW |
2287 | intel_ring_emit(ring, lower_32_bits(offset)); |
2288 | intel_ring_emit(ring, upper_32_bits(offset)); | |
1c7a0623 BW |
2289 | intel_ring_emit(ring, MI_NOOP); |
2290 | intel_ring_advance(ring); | |
2291 | ||
2292 | return 0; | |
2293 | } | |
2294 | ||
d7d4eedd | 2295 | static int |
a4872ba6 | 2296 | hsw_ring_dispatch_execbuffer(struct intel_engine_cs *ring, |
9bcb144c | 2297 | u64 offset, u32 len, |
d7d4eedd CW |
2298 | unsigned flags) |
2299 | { | |
2300 | int ret; | |
2301 | ||
2302 | ret = intel_ring_begin(ring, 2); | |
2303 | if (ret) | |
2304 | return ret; | |
2305 | ||
2306 | intel_ring_emit(ring, | |
77072258 CW |
2307 | MI_BATCH_BUFFER_START | |
2308 | (flags & I915_DISPATCH_SECURE ? | |
2309 | 0 : MI_BATCH_PPGTT_HSW | MI_BATCH_NON_SECURE_HSW)); | |
d7d4eedd CW |
2310 | /* bit0-7 is the length on GEN6+ */ |
2311 | intel_ring_emit(ring, offset); | |
2312 | intel_ring_advance(ring); | |
2313 | ||
2314 | return 0; | |
2315 | } | |
2316 | ||
881f47b6 | 2317 | static int |
a4872ba6 | 2318 | gen6_ring_dispatch_execbuffer(struct intel_engine_cs *ring, |
9bcb144c | 2319 | u64 offset, u32 len, |
d7d4eedd | 2320 | unsigned flags) |
881f47b6 | 2321 | { |
0206e353 | 2322 | int ret; |
ab6f8e32 | 2323 | |
0206e353 AJ |
2324 | ret = intel_ring_begin(ring, 2); |
2325 | if (ret) | |
2326 | return ret; | |
e1f99ce6 | 2327 | |
d7d4eedd CW |
2328 | intel_ring_emit(ring, |
2329 | MI_BATCH_BUFFER_START | | |
2330 | (flags & I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE_I965)); | |
0206e353 AJ |
2331 | /* bit0-7 is the length on GEN6+ */ |
2332 | intel_ring_emit(ring, offset); | |
2333 | intel_ring_advance(ring); | |
ab6f8e32 | 2334 | |
0206e353 | 2335 | return 0; |
881f47b6 XH |
2336 | } |
2337 | ||
549f7365 CW |
2338 | /* Blitter support (SandyBridge+) */ |
2339 | ||
a4872ba6 | 2340 | static int gen6_ring_flush(struct intel_engine_cs *ring, |
ea251324 | 2341 | u32 invalidate, u32 flush) |
8d19215b | 2342 | { |
fd3da6c9 | 2343 | struct drm_device *dev = ring->dev; |
1d73c2a8 | 2344 | struct drm_i915_private *dev_priv = dev->dev_private; |
71a77e07 | 2345 | uint32_t cmd; |
b72f3acb CW |
2346 | int ret; |
2347 | ||
6a233c78 | 2348 | ret = intel_ring_begin(ring, 4); |
b72f3acb CW |
2349 | if (ret) |
2350 | return ret; | |
2351 | ||
71a77e07 | 2352 | cmd = MI_FLUSH_DW; |
075b3bba BW |
2353 | if (INTEL_INFO(ring->dev)->gen >= 8) |
2354 | cmd += 1; | |
9a289771 JB |
2355 | /* |
2356 | * Bspec vol 1c.3 - blitter engine command streamer: | |
2357 | * "If ENABLED, all TLBs will be invalidated once the flush | |
2358 | * operation is complete. This bit is only valid when the | |
2359 | * Post-Sync Operation field is a value of 1h or 3h." | |
2360 | */ | |
71a77e07 | 2361 | if (invalidate & I915_GEM_DOMAIN_RENDER) |
9a289771 | 2362 | cmd |= MI_INVALIDATE_TLB | MI_FLUSH_DW_STORE_INDEX | |
b3fcabb1 | 2363 | MI_FLUSH_DW_OP_STOREDW; |
71a77e07 | 2364 | intel_ring_emit(ring, cmd); |
9a289771 | 2365 | intel_ring_emit(ring, I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT); |
075b3bba BW |
2366 | if (INTEL_INFO(ring->dev)->gen >= 8) { |
2367 | intel_ring_emit(ring, 0); /* upper addr */ | |
2368 | intel_ring_emit(ring, 0); /* value */ | |
2369 | } else { | |
2370 | intel_ring_emit(ring, 0); | |
2371 | intel_ring_emit(ring, MI_NOOP); | |
2372 | } | |
b72f3acb | 2373 | intel_ring_advance(ring); |
fd3da6c9 | 2374 | |
1d73c2a8 RV |
2375 | if (!invalidate && flush) { |
2376 | if (IS_GEN7(dev)) | |
2377 | return gen7_ring_fbc_flush(ring, FBC_REND_CACHE_CLEAN); | |
2378 | else if (IS_BROADWELL(dev)) | |
2379 | dev_priv->fbc.need_sw_cache_clean = true; | |
2380 | } | |
fd3da6c9 | 2381 | |
b72f3acb | 2382 | return 0; |
8d19215b ZN |
2383 | } |
2384 | ||
5c1143bb XH |
2385 | int intel_init_render_ring_buffer(struct drm_device *dev) |
2386 | { | |
4640c4ff | 2387 | struct drm_i915_private *dev_priv = dev->dev_private; |
a4872ba6 | 2388 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
3e78998a BW |
2389 | struct drm_i915_gem_object *obj; |
2390 | int ret; | |
5c1143bb | 2391 | |
59465b5f DV |
2392 | ring->name = "render ring"; |
2393 | ring->id = RCS; | |
2394 | ring->mmio_base = RENDER_RING_BASE; | |
2395 | ||
707d9cf9 | 2396 | if (INTEL_INFO(dev)->gen >= 8) { |
3e78998a BW |
2397 | if (i915_semaphore_is_enabled(dev)) { |
2398 | obj = i915_gem_alloc_object(dev, 4096); | |
2399 | if (obj == NULL) { | |
2400 | DRM_ERROR("Failed to allocate semaphore bo. Disabling semaphores\n"); | |
2401 | i915.semaphores = 0; | |
2402 | } else { | |
2403 | i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); | |
2404 | ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_NONBLOCK); | |
2405 | if (ret != 0) { | |
2406 | drm_gem_object_unreference(&obj->base); | |
2407 | DRM_ERROR("Failed to pin semaphore bo. Disabling semaphores\n"); | |
2408 | i915.semaphores = 0; | |
2409 | } else | |
2410 | dev_priv->semaphore_obj = obj; | |
2411 | } | |
2412 | } | |
7225342a | 2413 | |
8f0e2b9d | 2414 | ring->init_context = intel_rcs_ctx_init; |
707d9cf9 BW |
2415 | ring->add_request = gen6_add_request; |
2416 | ring->flush = gen8_render_ring_flush; | |
2417 | ring->irq_get = gen8_ring_get_irq; | |
2418 | ring->irq_put = gen8_ring_put_irq; | |
2419 | ring->irq_enable_mask = GT_RENDER_USER_INTERRUPT; | |
2420 | ring->get_seqno = gen6_ring_get_seqno; | |
2421 | ring->set_seqno = ring_set_seqno; | |
2422 | if (i915_semaphore_is_enabled(dev)) { | |
3e78998a | 2423 | WARN_ON(!dev_priv->semaphore_obj); |
5ee426ca | 2424 | ring->semaphore.sync_to = gen8_ring_sync; |
3e78998a BW |
2425 | ring->semaphore.signal = gen8_rcs_signal; |
2426 | GEN8_RING_SEMAPHORE_INIT; | |
707d9cf9 BW |
2427 | } |
2428 | } else if (INTEL_INFO(dev)->gen >= 6) { | |
1ec14ad3 | 2429 | ring->add_request = gen6_add_request; |
4772eaeb | 2430 | ring->flush = gen7_render_ring_flush; |
6c6cf5aa | 2431 | if (INTEL_INFO(dev)->gen == 6) |
b3111509 | 2432 | ring->flush = gen6_render_ring_flush; |
707d9cf9 BW |
2433 | ring->irq_get = gen6_ring_get_irq; |
2434 | ring->irq_put = gen6_ring_put_irq; | |
cc609d5d | 2435 | ring->irq_enable_mask = GT_RENDER_USER_INTERRUPT; |
4cd53c0c | 2436 | ring->get_seqno = gen6_ring_get_seqno; |
b70ec5bf | 2437 | ring->set_seqno = ring_set_seqno; |
707d9cf9 BW |
2438 | if (i915_semaphore_is_enabled(dev)) { |
2439 | ring->semaphore.sync_to = gen6_ring_sync; | |
2440 | ring->semaphore.signal = gen6_signal; | |
2441 | /* | |
2442 | * The current semaphore is only applied on pre-gen8 | |
2443 | * platform. And there is no VCS2 ring on the pre-gen8 | |
2444 | * platform. So the semaphore between RCS and VCS2 is | |
2445 | * initialized as INVALID. Gen8 will initialize the | |
2446 | * sema between VCS2 and RCS later. | |
2447 | */ | |
2448 | ring->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_INVALID; | |
2449 | ring->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_RV; | |
2450 | ring->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_RB; | |
2451 | ring->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_RVE; | |
2452 | ring->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
2453 | ring->semaphore.mbox.signal[RCS] = GEN6_NOSYNC; | |
2454 | ring->semaphore.mbox.signal[VCS] = GEN6_VRSYNC; | |
2455 | ring->semaphore.mbox.signal[BCS] = GEN6_BRSYNC; | |
2456 | ring->semaphore.mbox.signal[VECS] = GEN6_VERSYNC; | |
2457 | ring->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
2458 | } | |
c6df541c CW |
2459 | } else if (IS_GEN5(dev)) { |
2460 | ring->add_request = pc_render_add_request; | |
46f0f8d1 | 2461 | ring->flush = gen4_render_ring_flush; |
c6df541c | 2462 | ring->get_seqno = pc_render_get_seqno; |
b70ec5bf | 2463 | ring->set_seqno = pc_render_set_seqno; |
e48d8634 DV |
2464 | ring->irq_get = gen5_ring_get_irq; |
2465 | ring->irq_put = gen5_ring_put_irq; | |
cc609d5d BW |
2466 | ring->irq_enable_mask = GT_RENDER_USER_INTERRUPT | |
2467 | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT; | |
59465b5f | 2468 | } else { |
8620a3a9 | 2469 | ring->add_request = i9xx_add_request; |
46f0f8d1 CW |
2470 | if (INTEL_INFO(dev)->gen < 4) |
2471 | ring->flush = gen2_render_ring_flush; | |
2472 | else | |
2473 | ring->flush = gen4_render_ring_flush; | |
59465b5f | 2474 | ring->get_seqno = ring_get_seqno; |
b70ec5bf | 2475 | ring->set_seqno = ring_set_seqno; |
c2798b19 CW |
2476 | if (IS_GEN2(dev)) { |
2477 | ring->irq_get = i8xx_ring_get_irq; | |
2478 | ring->irq_put = i8xx_ring_put_irq; | |
2479 | } else { | |
2480 | ring->irq_get = i9xx_ring_get_irq; | |
2481 | ring->irq_put = i9xx_ring_put_irq; | |
2482 | } | |
e3670319 | 2483 | ring->irq_enable_mask = I915_USER_INTERRUPT; |
1ec14ad3 | 2484 | } |
59465b5f | 2485 | ring->write_tail = ring_write_tail; |
707d9cf9 | 2486 | |
d7d4eedd CW |
2487 | if (IS_HASWELL(dev)) |
2488 | ring->dispatch_execbuffer = hsw_ring_dispatch_execbuffer; | |
1c7a0623 BW |
2489 | else if (IS_GEN8(dev)) |
2490 | ring->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; | |
d7d4eedd | 2491 | else if (INTEL_INFO(dev)->gen >= 6) |
fb3256da DV |
2492 | ring->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; |
2493 | else if (INTEL_INFO(dev)->gen >= 4) | |
2494 | ring->dispatch_execbuffer = i965_dispatch_execbuffer; | |
2495 | else if (IS_I830(dev) || IS_845G(dev)) | |
2496 | ring->dispatch_execbuffer = i830_dispatch_execbuffer; | |
2497 | else | |
2498 | ring->dispatch_execbuffer = i915_dispatch_execbuffer; | |
ecfe00d8 | 2499 | ring->init_hw = init_render_ring; |
59465b5f DV |
2500 | ring->cleanup = render_ring_cleanup; |
2501 | ||
b45305fc DV |
2502 | /* Workaround batchbuffer to combat CS tlb bug. */ |
2503 | if (HAS_BROKEN_CS_TLB(dev)) { | |
c4d69da1 | 2504 | obj = i915_gem_alloc_object(dev, I830_WA_SIZE); |
b45305fc DV |
2505 | if (obj == NULL) { |
2506 | DRM_ERROR("Failed to allocate batch bo\n"); | |
2507 | return -ENOMEM; | |
2508 | } | |
2509 | ||
be1fa129 | 2510 | ret = i915_gem_obj_ggtt_pin(obj, 0, 0); |
b45305fc DV |
2511 | if (ret != 0) { |
2512 | drm_gem_object_unreference(&obj->base); | |
2513 | DRM_ERROR("Failed to ping batch bo\n"); | |
2514 | return ret; | |
2515 | } | |
2516 | ||
0d1aacac CW |
2517 | ring->scratch.obj = obj; |
2518 | ring->scratch.gtt_offset = i915_gem_obj_ggtt_offset(obj); | |
b45305fc DV |
2519 | } |
2520 | ||
99be1dfe DV |
2521 | ret = intel_init_ring_buffer(dev, ring); |
2522 | if (ret) | |
2523 | return ret; | |
2524 | ||
2525 | if (INTEL_INFO(dev)->gen >= 5) { | |
2526 | ret = intel_init_pipe_control(ring); | |
2527 | if (ret) | |
2528 | return ret; | |
2529 | } | |
2530 | ||
2531 | return 0; | |
5c1143bb XH |
2532 | } |
2533 | ||
2534 | int intel_init_bsd_ring_buffer(struct drm_device *dev) | |
2535 | { | |
4640c4ff | 2536 | struct drm_i915_private *dev_priv = dev->dev_private; |
a4872ba6 | 2537 | struct intel_engine_cs *ring = &dev_priv->ring[VCS]; |
5c1143bb | 2538 | |
58fa3835 DV |
2539 | ring->name = "bsd ring"; |
2540 | ring->id = VCS; | |
2541 | ||
0fd2c201 | 2542 | ring->write_tail = ring_write_tail; |
780f18c8 | 2543 | if (INTEL_INFO(dev)->gen >= 6) { |
58fa3835 | 2544 | ring->mmio_base = GEN6_BSD_RING_BASE; |
0fd2c201 DV |
2545 | /* gen6 bsd needs a special wa for tail updates */ |
2546 | if (IS_GEN6(dev)) | |
2547 | ring->write_tail = gen6_bsd_ring_write_tail; | |
ea251324 | 2548 | ring->flush = gen6_bsd_ring_flush; |
58fa3835 DV |
2549 | ring->add_request = gen6_add_request; |
2550 | ring->get_seqno = gen6_ring_get_seqno; | |
b70ec5bf | 2551 | ring->set_seqno = ring_set_seqno; |
abd58f01 BW |
2552 | if (INTEL_INFO(dev)->gen >= 8) { |
2553 | ring->irq_enable_mask = | |
2554 | GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT; | |
2555 | ring->irq_get = gen8_ring_get_irq; | |
2556 | ring->irq_put = gen8_ring_put_irq; | |
1c7a0623 BW |
2557 | ring->dispatch_execbuffer = |
2558 | gen8_ring_dispatch_execbuffer; | |
707d9cf9 | 2559 | if (i915_semaphore_is_enabled(dev)) { |
5ee426ca | 2560 | ring->semaphore.sync_to = gen8_ring_sync; |
3e78998a BW |
2561 | ring->semaphore.signal = gen8_xcs_signal; |
2562 | GEN8_RING_SEMAPHORE_INIT; | |
707d9cf9 | 2563 | } |
abd58f01 BW |
2564 | } else { |
2565 | ring->irq_enable_mask = GT_BSD_USER_INTERRUPT; | |
2566 | ring->irq_get = gen6_ring_get_irq; | |
2567 | ring->irq_put = gen6_ring_put_irq; | |
1c7a0623 BW |
2568 | ring->dispatch_execbuffer = |
2569 | gen6_ring_dispatch_execbuffer; | |
707d9cf9 BW |
2570 | if (i915_semaphore_is_enabled(dev)) { |
2571 | ring->semaphore.sync_to = gen6_ring_sync; | |
2572 | ring->semaphore.signal = gen6_signal; | |
2573 | ring->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_VR; | |
2574 | ring->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_INVALID; | |
2575 | ring->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_VB; | |
2576 | ring->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_VVE; | |
2577 | ring->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
2578 | ring->semaphore.mbox.signal[RCS] = GEN6_RVSYNC; | |
2579 | ring->semaphore.mbox.signal[VCS] = GEN6_NOSYNC; | |
2580 | ring->semaphore.mbox.signal[BCS] = GEN6_BVSYNC; | |
2581 | ring->semaphore.mbox.signal[VECS] = GEN6_VEVSYNC; | |
2582 | ring->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
2583 | } | |
abd58f01 | 2584 | } |
58fa3835 DV |
2585 | } else { |
2586 | ring->mmio_base = BSD_RING_BASE; | |
58fa3835 | 2587 | ring->flush = bsd_ring_flush; |
8620a3a9 | 2588 | ring->add_request = i9xx_add_request; |
58fa3835 | 2589 | ring->get_seqno = ring_get_seqno; |
b70ec5bf | 2590 | ring->set_seqno = ring_set_seqno; |
e48d8634 | 2591 | if (IS_GEN5(dev)) { |
cc609d5d | 2592 | ring->irq_enable_mask = ILK_BSD_USER_INTERRUPT; |
e48d8634 DV |
2593 | ring->irq_get = gen5_ring_get_irq; |
2594 | ring->irq_put = gen5_ring_put_irq; | |
2595 | } else { | |
e3670319 | 2596 | ring->irq_enable_mask = I915_BSD_USER_INTERRUPT; |
e48d8634 DV |
2597 | ring->irq_get = i9xx_ring_get_irq; |
2598 | ring->irq_put = i9xx_ring_put_irq; | |
2599 | } | |
fb3256da | 2600 | ring->dispatch_execbuffer = i965_dispatch_execbuffer; |
58fa3835 | 2601 | } |
ecfe00d8 | 2602 | ring->init_hw = init_ring_common; |
58fa3835 | 2603 | |
1ec14ad3 | 2604 | return intel_init_ring_buffer(dev, ring); |
5c1143bb | 2605 | } |
549f7365 | 2606 | |
845f74a7 | 2607 | /** |
62659920 | 2608 | * Initialize the second BSD ring (eg. Broadwell GT3, Skylake GT3) |
845f74a7 ZY |
2609 | */ |
2610 | int intel_init_bsd2_ring_buffer(struct drm_device *dev) | |
2611 | { | |
2612 | struct drm_i915_private *dev_priv = dev->dev_private; | |
a4872ba6 | 2613 | struct intel_engine_cs *ring = &dev_priv->ring[VCS2]; |
845f74a7 | 2614 | |
f7b64236 | 2615 | ring->name = "bsd2 ring"; |
845f74a7 ZY |
2616 | ring->id = VCS2; |
2617 | ||
2618 | ring->write_tail = ring_write_tail; | |
2619 | ring->mmio_base = GEN8_BSD2_RING_BASE; | |
2620 | ring->flush = gen6_bsd_ring_flush; | |
2621 | ring->add_request = gen6_add_request; | |
2622 | ring->get_seqno = gen6_ring_get_seqno; | |
2623 | ring->set_seqno = ring_set_seqno; | |
2624 | ring->irq_enable_mask = | |
2625 | GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT; | |
2626 | ring->irq_get = gen8_ring_get_irq; | |
2627 | ring->irq_put = gen8_ring_put_irq; | |
2628 | ring->dispatch_execbuffer = | |
2629 | gen8_ring_dispatch_execbuffer; | |
3e78998a | 2630 | if (i915_semaphore_is_enabled(dev)) { |
5ee426ca | 2631 | ring->semaphore.sync_to = gen8_ring_sync; |
3e78998a BW |
2632 | ring->semaphore.signal = gen8_xcs_signal; |
2633 | GEN8_RING_SEMAPHORE_INIT; | |
2634 | } | |
ecfe00d8 | 2635 | ring->init_hw = init_ring_common; |
845f74a7 ZY |
2636 | |
2637 | return intel_init_ring_buffer(dev, ring); | |
2638 | } | |
2639 | ||
549f7365 CW |
2640 | int intel_init_blt_ring_buffer(struct drm_device *dev) |
2641 | { | |
4640c4ff | 2642 | struct drm_i915_private *dev_priv = dev->dev_private; |
a4872ba6 | 2643 | struct intel_engine_cs *ring = &dev_priv->ring[BCS]; |
549f7365 | 2644 | |
3535d9dd DV |
2645 | ring->name = "blitter ring"; |
2646 | ring->id = BCS; | |
2647 | ||
2648 | ring->mmio_base = BLT_RING_BASE; | |
2649 | ring->write_tail = ring_write_tail; | |
ea251324 | 2650 | ring->flush = gen6_ring_flush; |
3535d9dd DV |
2651 | ring->add_request = gen6_add_request; |
2652 | ring->get_seqno = gen6_ring_get_seqno; | |
b70ec5bf | 2653 | ring->set_seqno = ring_set_seqno; |
abd58f01 BW |
2654 | if (INTEL_INFO(dev)->gen >= 8) { |
2655 | ring->irq_enable_mask = | |
2656 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT; | |
2657 | ring->irq_get = gen8_ring_get_irq; | |
2658 | ring->irq_put = gen8_ring_put_irq; | |
1c7a0623 | 2659 | ring->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; |
707d9cf9 | 2660 | if (i915_semaphore_is_enabled(dev)) { |
5ee426ca | 2661 | ring->semaphore.sync_to = gen8_ring_sync; |
3e78998a BW |
2662 | ring->semaphore.signal = gen8_xcs_signal; |
2663 | GEN8_RING_SEMAPHORE_INIT; | |
707d9cf9 | 2664 | } |
abd58f01 BW |
2665 | } else { |
2666 | ring->irq_enable_mask = GT_BLT_USER_INTERRUPT; | |
2667 | ring->irq_get = gen6_ring_get_irq; | |
2668 | ring->irq_put = gen6_ring_put_irq; | |
1c7a0623 | 2669 | ring->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; |
707d9cf9 BW |
2670 | if (i915_semaphore_is_enabled(dev)) { |
2671 | ring->semaphore.signal = gen6_signal; | |
2672 | ring->semaphore.sync_to = gen6_ring_sync; | |
2673 | /* | |
2674 | * The current semaphore is only applied on pre-gen8 | |
2675 | * platform. And there is no VCS2 ring on the pre-gen8 | |
2676 | * platform. So the semaphore between BCS and VCS2 is | |
2677 | * initialized as INVALID. Gen8 will initialize the | |
2678 | * sema between BCS and VCS2 later. | |
2679 | */ | |
2680 | ring->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_BR; | |
2681 | ring->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_BV; | |
2682 | ring->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_INVALID; | |
2683 | ring->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_BVE; | |
2684 | ring->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
2685 | ring->semaphore.mbox.signal[RCS] = GEN6_RBSYNC; | |
2686 | ring->semaphore.mbox.signal[VCS] = GEN6_VBSYNC; | |
2687 | ring->semaphore.mbox.signal[BCS] = GEN6_NOSYNC; | |
2688 | ring->semaphore.mbox.signal[VECS] = GEN6_VEBSYNC; | |
2689 | ring->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
2690 | } | |
abd58f01 | 2691 | } |
ecfe00d8 | 2692 | ring->init_hw = init_ring_common; |
549f7365 | 2693 | |
1ec14ad3 | 2694 | return intel_init_ring_buffer(dev, ring); |
549f7365 | 2695 | } |
a7b9761d | 2696 | |
9a8a2213 BW |
2697 | int intel_init_vebox_ring_buffer(struct drm_device *dev) |
2698 | { | |
4640c4ff | 2699 | struct drm_i915_private *dev_priv = dev->dev_private; |
a4872ba6 | 2700 | struct intel_engine_cs *ring = &dev_priv->ring[VECS]; |
9a8a2213 BW |
2701 | |
2702 | ring->name = "video enhancement ring"; | |
2703 | ring->id = VECS; | |
2704 | ||
2705 | ring->mmio_base = VEBOX_RING_BASE; | |
2706 | ring->write_tail = ring_write_tail; | |
2707 | ring->flush = gen6_ring_flush; | |
2708 | ring->add_request = gen6_add_request; | |
2709 | ring->get_seqno = gen6_ring_get_seqno; | |
2710 | ring->set_seqno = ring_set_seqno; | |
abd58f01 BW |
2711 | |
2712 | if (INTEL_INFO(dev)->gen >= 8) { | |
2713 | ring->irq_enable_mask = | |
40c499f9 | 2714 | GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT; |
abd58f01 BW |
2715 | ring->irq_get = gen8_ring_get_irq; |
2716 | ring->irq_put = gen8_ring_put_irq; | |
1c7a0623 | 2717 | ring->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; |
707d9cf9 | 2718 | if (i915_semaphore_is_enabled(dev)) { |
5ee426ca | 2719 | ring->semaphore.sync_to = gen8_ring_sync; |
3e78998a BW |
2720 | ring->semaphore.signal = gen8_xcs_signal; |
2721 | GEN8_RING_SEMAPHORE_INIT; | |
707d9cf9 | 2722 | } |
abd58f01 BW |
2723 | } else { |
2724 | ring->irq_enable_mask = PM_VEBOX_USER_INTERRUPT; | |
2725 | ring->irq_get = hsw_vebox_get_irq; | |
2726 | ring->irq_put = hsw_vebox_put_irq; | |
1c7a0623 | 2727 | ring->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; |
707d9cf9 BW |
2728 | if (i915_semaphore_is_enabled(dev)) { |
2729 | ring->semaphore.sync_to = gen6_ring_sync; | |
2730 | ring->semaphore.signal = gen6_signal; | |
2731 | ring->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_VER; | |
2732 | ring->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_VEV; | |
2733 | ring->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_VEB; | |
2734 | ring->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_INVALID; | |
2735 | ring->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
2736 | ring->semaphore.mbox.signal[RCS] = GEN6_RVESYNC; | |
2737 | ring->semaphore.mbox.signal[VCS] = GEN6_VVESYNC; | |
2738 | ring->semaphore.mbox.signal[BCS] = GEN6_BVESYNC; | |
2739 | ring->semaphore.mbox.signal[VECS] = GEN6_NOSYNC; | |
2740 | ring->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
2741 | } | |
abd58f01 | 2742 | } |
ecfe00d8 | 2743 | ring->init_hw = init_ring_common; |
9a8a2213 BW |
2744 | |
2745 | return intel_init_ring_buffer(dev, ring); | |
2746 | } | |
2747 | ||
a7b9761d | 2748 | int |
a4872ba6 | 2749 | intel_ring_flush_all_caches(struct intel_engine_cs *ring) |
a7b9761d CW |
2750 | { |
2751 | int ret; | |
2752 | ||
2753 | if (!ring->gpu_caches_dirty) | |
2754 | return 0; | |
2755 | ||
2756 | ret = ring->flush(ring, 0, I915_GEM_GPU_DOMAINS); | |
2757 | if (ret) | |
2758 | return ret; | |
2759 | ||
2760 | trace_i915_gem_ring_flush(ring, 0, I915_GEM_GPU_DOMAINS); | |
2761 | ||
2762 | ring->gpu_caches_dirty = false; | |
2763 | return 0; | |
2764 | } | |
2765 | ||
2766 | int | |
a4872ba6 | 2767 | intel_ring_invalidate_all_caches(struct intel_engine_cs *ring) |
a7b9761d CW |
2768 | { |
2769 | uint32_t flush_domains; | |
2770 | int ret; | |
2771 | ||
2772 | flush_domains = 0; | |
2773 | if (ring->gpu_caches_dirty) | |
2774 | flush_domains = I915_GEM_GPU_DOMAINS; | |
2775 | ||
2776 | ret = ring->flush(ring, I915_GEM_GPU_DOMAINS, flush_domains); | |
2777 | if (ret) | |
2778 | return ret; | |
2779 | ||
2780 | trace_i915_gem_ring_flush(ring, I915_GEM_GPU_DOMAINS, flush_domains); | |
2781 | ||
2782 | ring->gpu_caches_dirty = false; | |
2783 | return 0; | |
2784 | } | |
e3efda49 CW |
2785 | |
2786 | void | |
a4872ba6 | 2787 | intel_stop_ring_buffer(struct intel_engine_cs *ring) |
e3efda49 CW |
2788 | { |
2789 | int ret; | |
2790 | ||
2791 | if (!intel_ring_initialized(ring)) | |
2792 | return; | |
2793 | ||
2794 | ret = intel_ring_idle(ring); | |
2795 | if (ret && !i915_reset_in_progress(&to_i915(ring->dev)->gpu_error)) | |
2796 | DRM_ERROR("failed to quiesce %s whilst cleaning up: %d\n", | |
2797 | ring->name, ret); | |
2798 | ||
2799 | stop_ring(ring); | |
2800 | } |