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