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