]>
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 | |
ad2bdb44 MK |
1186 | /* WaInsertDummyPushConstPs:bxt */ |
1187 | if (IS_BXT_REVID(dev_priv, 0, BXT_REVID_B0)) | |
1188 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, | |
1189 | GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); | |
1190 | ||
cae0437f NH |
1191 | return 0; |
1192 | } | |
1193 | ||
e5f81d65 MK |
1194 | static int kbl_init_workarounds(struct intel_engine_cs *engine) |
1195 | { | |
e587f6cb | 1196 | struct drm_i915_private *dev_priv = engine->i915; |
e5f81d65 MK |
1197 | int ret; |
1198 | ||
1199 | ret = gen9_init_workarounds(engine); | |
1200 | if (ret) | |
1201 | return ret; | |
1202 | ||
e587f6cb MK |
1203 | /* WaEnableGapsTsvCreditFix:kbl */ |
1204 | I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) | | |
1205 | GEN9_GAPS_TSV_CREDIT_DISABLE)); | |
1206 | ||
c0b730d5 MK |
1207 | /* WaDisableDynamicCreditSharing:kbl */ |
1208 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) | |
1209 | WA_SET_BIT(GAMT_CHKN_BIT_REG, | |
1210 | GAMT_CHKN_DISABLE_DYNAMIC_CREDIT_SHARING); | |
1211 | ||
8401d42f MK |
1212 | /* WaDisableFenceDestinationToSLM:kbl (pre-prod) */ |
1213 | if (IS_KBL_REVID(dev_priv, KBL_REVID_A0, KBL_REVID_A0)) | |
1214 | WA_SET_BIT_MASKED(HDC_CHICKEN0, | |
1215 | HDC_FENCE_DEST_SLM_DISABLE); | |
1216 | ||
fe905819 MK |
1217 | /* GEN8_L3SQCREG4 has a dependency with WA batch so any new changes |
1218 | * involving this register should also be added to WA batch as required. | |
1219 | */ | |
1220 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_E0)) | |
1221 | /* WaDisableLSQCROPERFforOCL:kbl */ | |
1222 | I915_WRITE(GEN8_L3SQCREG4, I915_READ(GEN8_L3SQCREG4) | | |
1223 | GEN8_LQSC_RO_PERF_DIS); | |
1224 | ||
ad2bdb44 MK |
1225 | /* WaInsertDummyPushConstPs:kbl */ |
1226 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) | |
1227 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, | |
1228 | GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); | |
1229 | ||
4de5d7cc MK |
1230 | /* WaDisableGafsUnitClkGating:kbl */ |
1231 | WA_SET_BIT(GEN7_UCGCTL4, GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE); | |
1232 | ||
954337aa MK |
1233 | /* WaDisableSbeCacheDispatchPortSharing:kbl */ |
1234 | WA_SET_BIT_MASKED( | |
1235 | GEN7_HALF_SLICE_CHICKEN1, | |
1236 | GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE); | |
1237 | ||
fe905819 MK |
1238 | /* WaDisableLSQCROPERFforOCL:kbl */ |
1239 | ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4); | |
1240 | if (ret) | |
1241 | return ret; | |
1242 | ||
e5f81d65 MK |
1243 | return 0; |
1244 | } | |
1245 | ||
0bc40be8 | 1246 | int init_workarounds_ring(struct intel_engine_cs *engine) |
7225342a | 1247 | { |
c033666a | 1248 | struct drm_i915_private *dev_priv = engine->i915; |
7225342a | 1249 | |
0bc40be8 | 1250 | WARN_ON(engine->id != RCS); |
7225342a MK |
1251 | |
1252 | dev_priv->workarounds.count = 0; | |
33136b06 | 1253 | dev_priv->workarounds.hw_whitelist_count[RCS] = 0; |
7225342a | 1254 | |
c033666a | 1255 | if (IS_BROADWELL(dev_priv)) |
0bc40be8 | 1256 | return bdw_init_workarounds(engine); |
7225342a | 1257 | |
c033666a | 1258 | if (IS_CHERRYVIEW(dev_priv)) |
0bc40be8 | 1259 | return chv_init_workarounds(engine); |
00e1e623 | 1260 | |
c033666a | 1261 | if (IS_SKYLAKE(dev_priv)) |
0bc40be8 | 1262 | return skl_init_workarounds(engine); |
cae0437f | 1263 | |
c033666a | 1264 | if (IS_BROXTON(dev_priv)) |
0bc40be8 | 1265 | return bxt_init_workarounds(engine); |
3b106531 | 1266 | |
e5f81d65 MK |
1267 | if (IS_KABYLAKE(dev_priv)) |
1268 | return kbl_init_workarounds(engine); | |
1269 | ||
00e1e623 VS |
1270 | return 0; |
1271 | } | |
1272 | ||
0bc40be8 | 1273 | static int init_render_ring(struct intel_engine_cs *engine) |
8187a2b7 | 1274 | { |
c033666a | 1275 | struct drm_i915_private *dev_priv = engine->i915; |
0bc40be8 | 1276 | int ret = init_ring_common(engine); |
9c33baa6 KZ |
1277 | if (ret) |
1278 | return ret; | |
a69ffdbf | 1279 | |
61a563a2 | 1280 | /* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */ |
ac657f64 | 1281 | if (IS_GEN(dev_priv, 4, 6)) |
6b26c86d | 1282 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH)); |
1c8c38c5 CW |
1283 | |
1284 | /* We need to disable the AsyncFlip performance optimisations in order | |
1285 | * to use MI_WAIT_FOR_EVENT within the CS. It should already be | |
1286 | * programmed to '1' on all products. | |
8693a824 | 1287 | * |
2441f877 | 1288 | * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv |
1c8c38c5 | 1289 | */ |
ac657f64 | 1290 | if (IS_GEN(dev_priv, 6, 7)) |
1c8c38c5 CW |
1291 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(ASYNC_FLIP_PERF_DISABLE)); |
1292 | ||
f05bb0c7 | 1293 | /* Required for the hardware to program scanline values for waiting */ |
01fa0302 | 1294 | /* WaEnableFlushTlbInvalidationMode:snb */ |
c033666a | 1295 | if (IS_GEN6(dev_priv)) |
f05bb0c7 | 1296 | I915_WRITE(GFX_MODE, |
aa83e30d | 1297 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT)); |
f05bb0c7 | 1298 | |
01fa0302 | 1299 | /* WaBCSVCSTlbInvalidationMode:ivb,vlv,hsw */ |
c033666a | 1300 | if (IS_GEN7(dev_priv)) |
1c8c38c5 | 1301 | I915_WRITE(GFX_MODE_GEN7, |
01fa0302 | 1302 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT) | |
1c8c38c5 | 1303 | _MASKED_BIT_ENABLE(GFX_REPLAY_MODE)); |
78501eac | 1304 | |
c033666a | 1305 | if (IS_GEN6(dev_priv)) { |
3a69ddd6 KG |
1306 | /* From the Sandybridge PRM, volume 1 part 3, page 24: |
1307 | * "If this bit is set, STCunit will have LRA as replacement | |
1308 | * policy. [...] This bit must be reset. LRA replacement | |
1309 | * policy is not supported." | |
1310 | */ | |
1311 | I915_WRITE(CACHE_MODE_0, | |
5e13a0c5 | 1312 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
84f9f938 BW |
1313 | } |
1314 | ||
ac657f64 | 1315 | if (IS_GEN(dev_priv, 6, 7)) |
6b26c86d | 1316 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_FORCE_ORDERING)); |
84f9f938 | 1317 | |
c033666a CW |
1318 | if (HAS_L3_DPF(dev_priv)) |
1319 | I915_WRITE_IMR(engine, ~GT_PARITY_ERROR(dev_priv)); | |
15b9f80e | 1320 | |
0bc40be8 | 1321 | return init_workarounds_ring(engine); |
8187a2b7 ZN |
1322 | } |
1323 | ||
0bc40be8 | 1324 | static void render_ring_cleanup(struct intel_engine_cs *engine) |
c6df541c | 1325 | { |
c033666a | 1326 | struct drm_i915_private *dev_priv = engine->i915; |
3e78998a BW |
1327 | |
1328 | if (dev_priv->semaphore_obj) { | |
1329 | i915_gem_object_ggtt_unpin(dev_priv->semaphore_obj); | |
1330 | drm_gem_object_unreference(&dev_priv->semaphore_obj->base); | |
1331 | dev_priv->semaphore_obj = NULL; | |
1332 | } | |
b45305fc | 1333 | |
0bc40be8 | 1334 | intel_fini_pipe_control(engine); |
c6df541c CW |
1335 | } |
1336 | ||
f7169687 | 1337 | static int gen8_rcs_signal(struct drm_i915_gem_request *signaller_req, |
3e78998a BW |
1338 | unsigned int num_dwords) |
1339 | { | |
1340 | #define MBOX_UPDATE_DWORDS 8 | |
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, GFX_OP_PIPE_CONTROL(6)); |
1363 | intel_ring_emit(signaller, PIPE_CONTROL_GLOBAL_GTT_IVB | | |
1364 | PIPE_CONTROL_QW_WRITE | | |
f9a4ea35 | 1365 | PIPE_CONTROL_CS_STALL); |
3e78998a BW |
1366 | intel_ring_emit(signaller, lower_32_bits(gtt_offset)); |
1367 | intel_ring_emit(signaller, upper_32_bits(gtt_offset)); | |
6259cead | 1368 | intel_ring_emit(signaller, seqno); |
3e78998a BW |
1369 | intel_ring_emit(signaller, 0); |
1370 | intel_ring_emit(signaller, MI_SEMAPHORE_SIGNAL | | |
215a7e32 | 1371 | MI_SEMAPHORE_TARGET(waiter->hw_id)); |
3e78998a BW |
1372 | intel_ring_emit(signaller, 0); |
1373 | } | |
1374 | ||
1375 | return 0; | |
1376 | } | |
1377 | ||
f7169687 | 1378 | static int gen8_xcs_signal(struct drm_i915_gem_request *signaller_req, |
3e78998a BW |
1379 | unsigned int num_dwords) |
1380 | { | |
1381 | #define MBOX_UPDATE_DWORDS 6 | |
4a570db5 | 1382 | struct intel_engine_cs *signaller = signaller_req->engine; |
c033666a | 1383 | struct drm_i915_private *dev_priv = signaller_req->i915; |
3e78998a | 1384 | struct intel_engine_cs *waiter; |
c3232b18 DG |
1385 | enum intel_engine_id id; |
1386 | int ret, num_rings; | |
3e78998a | 1387 | |
c033666a | 1388 | num_rings = hweight32(INTEL_INFO(dev_priv)->ring_mask); |
3e78998a BW |
1389 | num_dwords += (num_rings-1) * MBOX_UPDATE_DWORDS; |
1390 | #undef MBOX_UPDATE_DWORDS | |
1391 | ||
5fb9de1a | 1392 | ret = intel_ring_begin(signaller_req, num_dwords); |
3e78998a BW |
1393 | if (ret) |
1394 | return ret; | |
1395 | ||
c3232b18 | 1396 | for_each_engine_id(waiter, dev_priv, id) { |
6259cead | 1397 | u32 seqno; |
c3232b18 | 1398 | u64 gtt_offset = signaller->semaphore.signal_ggtt[id]; |
3e78998a BW |
1399 | if (gtt_offset == MI_SEMAPHORE_SYNC_INVALID) |
1400 | continue; | |
1401 | ||
f7169687 | 1402 | seqno = i915_gem_request_get_seqno(signaller_req); |
3e78998a BW |
1403 | intel_ring_emit(signaller, (MI_FLUSH_DW + 1) | |
1404 | MI_FLUSH_DW_OP_STOREDW); | |
1405 | intel_ring_emit(signaller, lower_32_bits(gtt_offset) | | |
1406 | MI_FLUSH_DW_USE_GTT); | |
1407 | intel_ring_emit(signaller, upper_32_bits(gtt_offset)); | |
6259cead | 1408 | intel_ring_emit(signaller, seqno); |
3e78998a | 1409 | intel_ring_emit(signaller, MI_SEMAPHORE_SIGNAL | |
215a7e32 | 1410 | MI_SEMAPHORE_TARGET(waiter->hw_id)); |
3e78998a BW |
1411 | intel_ring_emit(signaller, 0); |
1412 | } | |
1413 | ||
1414 | return 0; | |
1415 | } | |
1416 | ||
f7169687 | 1417 | static int gen6_signal(struct drm_i915_gem_request *signaller_req, |
024a43e1 | 1418 | unsigned int num_dwords) |
1ec14ad3 | 1419 | { |
4a570db5 | 1420 | struct intel_engine_cs *signaller = signaller_req->engine; |
c033666a | 1421 | struct drm_i915_private *dev_priv = signaller_req->i915; |
a4872ba6 | 1422 | struct intel_engine_cs *useless; |
c3232b18 DG |
1423 | enum intel_engine_id id; |
1424 | int ret, num_rings; | |
78325f2d | 1425 | |
a1444b79 | 1426 | #define MBOX_UPDATE_DWORDS 3 |
c033666a | 1427 | num_rings = hweight32(INTEL_INFO(dev_priv)->ring_mask); |
a1444b79 BW |
1428 | num_dwords += round_up((num_rings-1) * MBOX_UPDATE_DWORDS, 2); |
1429 | #undef MBOX_UPDATE_DWORDS | |
024a43e1 | 1430 | |
5fb9de1a | 1431 | ret = intel_ring_begin(signaller_req, num_dwords); |
024a43e1 BW |
1432 | if (ret) |
1433 | return ret; | |
024a43e1 | 1434 | |
c3232b18 DG |
1435 | for_each_engine_id(useless, dev_priv, id) { |
1436 | i915_reg_t mbox_reg = signaller->semaphore.mbox.signal[id]; | |
f0f59a00 VS |
1437 | |
1438 | if (i915_mmio_reg_valid(mbox_reg)) { | |
f7169687 | 1439 | u32 seqno = i915_gem_request_get_seqno(signaller_req); |
f0f59a00 | 1440 | |
78325f2d | 1441 | intel_ring_emit(signaller, MI_LOAD_REGISTER_IMM(1)); |
f92a9162 | 1442 | intel_ring_emit_reg(signaller, mbox_reg); |
6259cead | 1443 | intel_ring_emit(signaller, seqno); |
78325f2d BW |
1444 | } |
1445 | } | |
024a43e1 | 1446 | |
a1444b79 BW |
1447 | /* If num_dwords was rounded, make sure the tail pointer is correct */ |
1448 | if (num_rings % 2 == 0) | |
1449 | intel_ring_emit(signaller, MI_NOOP); | |
1450 | ||
024a43e1 | 1451 | return 0; |
1ec14ad3 CW |
1452 | } |
1453 | ||
c8c99b0f BW |
1454 | /** |
1455 | * gen6_add_request - Update the semaphore mailbox registers | |
ee044a88 JH |
1456 | * |
1457 | * @request - request to write to the ring | |
c8c99b0f BW |
1458 | * |
1459 | * Update the mailbox registers in the *other* rings with the current seqno. | |
1460 | * This acts like a signal in the canonical semaphore. | |
1461 | */ | |
1ec14ad3 | 1462 | static int |
ee044a88 | 1463 | gen6_add_request(struct drm_i915_gem_request *req) |
1ec14ad3 | 1464 | { |
4a570db5 | 1465 | struct intel_engine_cs *engine = req->engine; |
024a43e1 | 1466 | int ret; |
52ed2325 | 1467 | |
e2f80391 TU |
1468 | if (engine->semaphore.signal) |
1469 | ret = engine->semaphore.signal(req, 4); | |
707d9cf9 | 1470 | else |
5fb9de1a | 1471 | ret = intel_ring_begin(req, 4); |
707d9cf9 | 1472 | |
1ec14ad3 CW |
1473 | if (ret) |
1474 | return ret; | |
1475 | ||
e2f80391 TU |
1476 | intel_ring_emit(engine, MI_STORE_DWORD_INDEX); |
1477 | intel_ring_emit(engine, | |
1478 | I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | |
1479 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1480 | intel_ring_emit(engine, MI_USER_INTERRUPT); | |
1481 | __intel_ring_advance(engine); | |
1ec14ad3 | 1482 | |
1ec14ad3 CW |
1483 | return 0; |
1484 | } | |
1485 | ||
a58c01aa CW |
1486 | static int |
1487 | gen8_render_add_request(struct drm_i915_gem_request *req) | |
1488 | { | |
1489 | struct intel_engine_cs *engine = req->engine; | |
1490 | int ret; | |
1491 | ||
1492 | if (engine->semaphore.signal) | |
1493 | ret = engine->semaphore.signal(req, 8); | |
1494 | else | |
1495 | ret = intel_ring_begin(req, 8); | |
1496 | if (ret) | |
1497 | return ret; | |
1498 | ||
1499 | intel_ring_emit(engine, GFX_OP_PIPE_CONTROL(6)); | |
1500 | intel_ring_emit(engine, (PIPE_CONTROL_GLOBAL_GTT_IVB | | |
1501 | PIPE_CONTROL_CS_STALL | | |
1502 | PIPE_CONTROL_QW_WRITE)); | |
1503 | intel_ring_emit(engine, intel_hws_seqno_address(req->engine)); | |
1504 | intel_ring_emit(engine, 0); | |
1505 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1506 | /* We're thrashing one dword of HWS. */ | |
1507 | intel_ring_emit(engine, 0); | |
1508 | intel_ring_emit(engine, MI_USER_INTERRUPT); | |
1509 | intel_ring_emit(engine, MI_NOOP); | |
1510 | __intel_ring_advance(engine); | |
1511 | ||
1512 | return 0; | |
1513 | } | |
1514 | ||
c033666a | 1515 | static inline bool i915_gem_has_seqno_wrapped(struct drm_i915_private *dev_priv, |
f72b3435 MK |
1516 | u32 seqno) |
1517 | { | |
f72b3435 MK |
1518 | return dev_priv->last_seqno < seqno; |
1519 | } | |
1520 | ||
c8c99b0f BW |
1521 | /** |
1522 | * intel_ring_sync - sync the waiter to the signaller on seqno | |
1523 | * | |
1524 | * @waiter - ring that is waiting | |
1525 | * @signaller - ring which has, or will signal | |
1526 | * @seqno - seqno which the waiter will block on | |
1527 | */ | |
5ee426ca BW |
1528 | |
1529 | static int | |
599d924c | 1530 | gen8_ring_sync(struct drm_i915_gem_request *waiter_req, |
5ee426ca BW |
1531 | struct intel_engine_cs *signaller, |
1532 | u32 seqno) | |
1533 | { | |
4a570db5 | 1534 | struct intel_engine_cs *waiter = waiter_req->engine; |
c033666a | 1535 | struct drm_i915_private *dev_priv = waiter_req->i915; |
6ef48d7f | 1536 | struct i915_hw_ppgtt *ppgtt; |
5ee426ca BW |
1537 | int ret; |
1538 | ||
5fb9de1a | 1539 | ret = intel_ring_begin(waiter_req, 4); |
5ee426ca BW |
1540 | if (ret) |
1541 | return ret; | |
1542 | ||
1543 | intel_ring_emit(waiter, MI_SEMAPHORE_WAIT | | |
1544 | MI_SEMAPHORE_GLOBAL_GTT | | |
1545 | MI_SEMAPHORE_SAD_GTE_SDD); | |
1546 | intel_ring_emit(waiter, seqno); | |
1547 | intel_ring_emit(waiter, | |
1548 | lower_32_bits(GEN8_WAIT_OFFSET(waiter, signaller->id))); | |
1549 | intel_ring_emit(waiter, | |
1550 | upper_32_bits(GEN8_WAIT_OFFSET(waiter, signaller->id))); | |
1551 | intel_ring_advance(waiter); | |
6ef48d7f CW |
1552 | |
1553 | /* When the !RCS engines idle waiting upon a semaphore, they lose their | |
1554 | * pagetables and we must reload them before executing the batch. | |
1555 | * We do this on the i915_switch_context() following the wait and | |
1556 | * before the dispatch. | |
1557 | */ | |
1558 | ppgtt = waiter_req->ctx->ppgtt; | |
1559 | if (ppgtt && waiter_req->engine->id != RCS) | |
1560 | ppgtt->pd_dirty_rings |= intel_engine_flag(waiter_req->engine); | |
5ee426ca BW |
1561 | return 0; |
1562 | } | |
1563 | ||
c8c99b0f | 1564 | static int |
599d924c | 1565 | gen6_ring_sync(struct drm_i915_gem_request *waiter_req, |
a4872ba6 | 1566 | struct intel_engine_cs *signaller, |
686cb5f9 | 1567 | u32 seqno) |
1ec14ad3 | 1568 | { |
4a570db5 | 1569 | struct intel_engine_cs *waiter = waiter_req->engine; |
c8c99b0f BW |
1570 | u32 dw1 = MI_SEMAPHORE_MBOX | |
1571 | MI_SEMAPHORE_COMPARE | | |
1572 | MI_SEMAPHORE_REGISTER; | |
ebc348b2 BW |
1573 | u32 wait_mbox = signaller->semaphore.mbox.wait[waiter->id]; |
1574 | int ret; | |
1ec14ad3 | 1575 | |
1500f7ea BW |
1576 | /* Throughout all of the GEM code, seqno passed implies our current |
1577 | * seqno is >= the last seqno executed. However for hardware the | |
1578 | * comparison is strictly greater than. | |
1579 | */ | |
1580 | seqno -= 1; | |
1581 | ||
ebc348b2 | 1582 | WARN_ON(wait_mbox == MI_SEMAPHORE_SYNC_INVALID); |
686cb5f9 | 1583 | |
5fb9de1a | 1584 | ret = intel_ring_begin(waiter_req, 4); |
1ec14ad3 CW |
1585 | if (ret) |
1586 | return ret; | |
1587 | ||
f72b3435 | 1588 | /* If seqno wrap happened, omit the wait with no-ops */ |
c033666a | 1589 | if (likely(!i915_gem_has_seqno_wrapped(waiter_req->i915, seqno))) { |
ebc348b2 | 1590 | intel_ring_emit(waiter, dw1 | wait_mbox); |
f72b3435 MK |
1591 | intel_ring_emit(waiter, seqno); |
1592 | intel_ring_emit(waiter, 0); | |
1593 | intel_ring_emit(waiter, MI_NOOP); | |
1594 | } else { | |
1595 | intel_ring_emit(waiter, MI_NOOP); | |
1596 | intel_ring_emit(waiter, MI_NOOP); | |
1597 | intel_ring_emit(waiter, MI_NOOP); | |
1598 | intel_ring_emit(waiter, MI_NOOP); | |
1599 | } | |
c8c99b0f | 1600 | intel_ring_advance(waiter); |
1ec14ad3 CW |
1601 | |
1602 | return 0; | |
1603 | } | |
1604 | ||
c6df541c CW |
1605 | #define PIPE_CONTROL_FLUSH(ring__, addr__) \ |
1606 | do { \ | |
fcbc34e4 KG |
1607 | intel_ring_emit(ring__, GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | \ |
1608 | PIPE_CONTROL_DEPTH_STALL); \ | |
c6df541c CW |
1609 | intel_ring_emit(ring__, (addr__) | PIPE_CONTROL_GLOBAL_GTT); \ |
1610 | intel_ring_emit(ring__, 0); \ | |
1611 | intel_ring_emit(ring__, 0); \ | |
1612 | } while (0) | |
1613 | ||
1614 | static int | |
ee044a88 | 1615 | pc_render_add_request(struct drm_i915_gem_request *req) |
c6df541c | 1616 | { |
4a570db5 | 1617 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 1618 | u32 scratch_addr = engine->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
c6df541c CW |
1619 | int ret; |
1620 | ||
1621 | /* For Ironlake, MI_USER_INTERRUPT was deprecated and apparently | |
1622 | * incoherent with writes to memory, i.e. completely fubar, | |
1623 | * so we need to use PIPE_NOTIFY instead. | |
1624 | * | |
1625 | * However, we also need to workaround the qword write | |
1626 | * incoherence by flushing the 6 PIPE_NOTIFY buffers out to | |
1627 | * memory before requesting an interrupt. | |
1628 | */ | |
5fb9de1a | 1629 | ret = intel_ring_begin(req, 32); |
c6df541c CW |
1630 | if (ret) |
1631 | return ret; | |
1632 | ||
e2f80391 TU |
1633 | intel_ring_emit(engine, |
1634 | GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | | |
9d971b37 KG |
1635 | PIPE_CONTROL_WRITE_FLUSH | |
1636 | PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE); | |
e2f80391 TU |
1637 | intel_ring_emit(engine, |
1638 | engine->scratch.gtt_offset | PIPE_CONTROL_GLOBAL_GTT); | |
1639 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1640 | intel_ring_emit(engine, 0); | |
1641 | PIPE_CONTROL_FLUSH(engine, scratch_addr); | |
18393f63 | 1642 | scratch_addr += 2 * CACHELINE_BYTES; /* write to separate cachelines */ |
e2f80391 | 1643 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1644 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1645 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1646 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1647 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1648 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1649 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
18393f63 | 1650 | scratch_addr += 2 * CACHELINE_BYTES; |
e2f80391 | 1651 | PIPE_CONTROL_FLUSH(engine, scratch_addr); |
a71d8d94 | 1652 | |
e2f80391 TU |
1653 | intel_ring_emit(engine, |
1654 | GFX_OP_PIPE_CONTROL(4) | PIPE_CONTROL_QW_WRITE | | |
9d971b37 KG |
1655 | PIPE_CONTROL_WRITE_FLUSH | |
1656 | PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | | |
c6df541c | 1657 | PIPE_CONTROL_NOTIFY); |
e2f80391 TU |
1658 | intel_ring_emit(engine, |
1659 | engine->scratch.gtt_offset | PIPE_CONTROL_GLOBAL_GTT); | |
1660 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1661 | intel_ring_emit(engine, 0); | |
1662 | __intel_ring_advance(engine); | |
c6df541c | 1663 | |
c6df541c CW |
1664 | return 0; |
1665 | } | |
1666 | ||
c04e0f3b CW |
1667 | static void |
1668 | gen6_seqno_barrier(struct intel_engine_cs *engine) | |
4cd53c0c | 1669 | { |
c033666a | 1670 | struct drm_i915_private *dev_priv = engine->i915; |
bcbdb6d0 | 1671 | |
4cd53c0c DV |
1672 | /* Workaround to force correct ordering between irq and seqno writes on |
1673 | * ivb (and maybe also on snb) by reading from a CS register (like | |
9b9ed309 CW |
1674 | * ACTHD) before reading the status page. |
1675 | * | |
1676 | * Note that this effectively stalls the read by the time it takes to | |
1677 | * do a memory transaction, which more or less ensures that the write | |
1678 | * from the GPU has sufficient time to invalidate the CPU cacheline. | |
1679 | * Alternatively we could delay the interrupt from the CS ring to give | |
1680 | * the write time to land, but that would incur a delay after every | |
1681 | * batch i.e. much more frequent than a delay when waiting for the | |
1682 | * interrupt (with the same net latency). | |
bcbdb6d0 CW |
1683 | * |
1684 | * Also note that to prevent whole machine hangs on gen7, we have to | |
1685 | * take the spinlock to guard against concurrent cacheline access. | |
9b9ed309 | 1686 | */ |
bcbdb6d0 | 1687 | spin_lock_irq(&dev_priv->uncore.lock); |
c04e0f3b | 1688 | POSTING_READ_FW(RING_ACTHD(engine->mmio_base)); |
bcbdb6d0 | 1689 | spin_unlock_irq(&dev_priv->uncore.lock); |
4cd53c0c DV |
1690 | } |
1691 | ||
8187a2b7 | 1692 | static u32 |
c04e0f3b | 1693 | ring_get_seqno(struct intel_engine_cs *engine) |
8187a2b7 | 1694 | { |
0bc40be8 | 1695 | return intel_read_status_page(engine, I915_GEM_HWS_INDEX); |
1ec14ad3 CW |
1696 | } |
1697 | ||
b70ec5bf | 1698 | static void |
0bc40be8 | 1699 | ring_set_seqno(struct intel_engine_cs *engine, u32 seqno) |
b70ec5bf | 1700 | { |
0bc40be8 | 1701 | intel_write_status_page(engine, I915_GEM_HWS_INDEX, seqno); |
b70ec5bf MK |
1702 | } |
1703 | ||
c6df541c | 1704 | static u32 |
c04e0f3b | 1705 | pc_render_get_seqno(struct intel_engine_cs *engine) |
c6df541c | 1706 | { |
0bc40be8 | 1707 | return engine->scratch.cpu_page[0]; |
c6df541c CW |
1708 | } |
1709 | ||
b70ec5bf | 1710 | static void |
0bc40be8 | 1711 | pc_render_set_seqno(struct intel_engine_cs *engine, u32 seqno) |
b70ec5bf | 1712 | { |
0bc40be8 | 1713 | engine->scratch.cpu_page[0] = seqno; |
b70ec5bf MK |
1714 | } |
1715 | ||
e48d8634 | 1716 | static bool |
0bc40be8 | 1717 | gen5_ring_get_irq(struct intel_engine_cs *engine) |
e48d8634 | 1718 | { |
c033666a | 1719 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1720 | unsigned long flags; |
e48d8634 | 1721 | |
7cd512f1 | 1722 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
e48d8634 DV |
1723 | return false; |
1724 | ||
7338aefa | 1725 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1726 | if (engine->irq_refcount++ == 0) |
1727 | gen5_enable_gt_irq(dev_priv, engine->irq_enable_mask); | |
7338aefa | 1728 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
e48d8634 DV |
1729 | |
1730 | return true; | |
1731 | } | |
1732 | ||
1733 | static void | |
0bc40be8 | 1734 | gen5_ring_put_irq(struct intel_engine_cs *engine) |
e48d8634 | 1735 | { |
c033666a | 1736 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1737 | unsigned long flags; |
e48d8634 | 1738 | |
7338aefa | 1739 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1740 | if (--engine->irq_refcount == 0) |
1741 | gen5_disable_gt_irq(dev_priv, engine->irq_enable_mask); | |
7338aefa | 1742 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
e48d8634 DV |
1743 | } |
1744 | ||
b13c2b96 | 1745 | static bool |
0bc40be8 | 1746 | i9xx_ring_get_irq(struct intel_engine_cs *engine) |
62fdfeaf | 1747 | { |
c033666a | 1748 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1749 | unsigned long flags; |
62fdfeaf | 1750 | |
7cd512f1 | 1751 | if (!intel_irqs_enabled(dev_priv)) |
b13c2b96 CW |
1752 | return false; |
1753 | ||
7338aefa | 1754 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1755 | if (engine->irq_refcount++ == 0) { |
1756 | dev_priv->irq_mask &= ~engine->irq_enable_mask; | |
f637fde4 DV |
1757 | I915_WRITE(IMR, dev_priv->irq_mask); |
1758 | POSTING_READ(IMR); | |
1759 | } | |
7338aefa | 1760 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
b13c2b96 CW |
1761 | |
1762 | return true; | |
62fdfeaf EA |
1763 | } |
1764 | ||
8187a2b7 | 1765 | static void |
0bc40be8 | 1766 | i9xx_ring_put_irq(struct intel_engine_cs *engine) |
62fdfeaf | 1767 | { |
c033666a | 1768 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1769 | unsigned long flags; |
62fdfeaf | 1770 | |
7338aefa | 1771 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1772 | if (--engine->irq_refcount == 0) { |
1773 | dev_priv->irq_mask |= engine->irq_enable_mask; | |
f637fde4 DV |
1774 | I915_WRITE(IMR, dev_priv->irq_mask); |
1775 | POSTING_READ(IMR); | |
1776 | } | |
7338aefa | 1777 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
62fdfeaf EA |
1778 | } |
1779 | ||
c2798b19 | 1780 | static bool |
0bc40be8 | 1781 | i8xx_ring_get_irq(struct intel_engine_cs *engine) |
c2798b19 | 1782 | { |
c033666a | 1783 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1784 | unsigned long flags; |
c2798b19 | 1785 | |
7cd512f1 | 1786 | if (!intel_irqs_enabled(dev_priv)) |
c2798b19 CW |
1787 | return false; |
1788 | ||
7338aefa | 1789 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1790 | if (engine->irq_refcount++ == 0) { |
1791 | dev_priv->irq_mask &= ~engine->irq_enable_mask; | |
c2798b19 CW |
1792 | I915_WRITE16(IMR, dev_priv->irq_mask); |
1793 | POSTING_READ16(IMR); | |
1794 | } | |
7338aefa | 1795 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
c2798b19 CW |
1796 | |
1797 | return true; | |
1798 | } | |
1799 | ||
1800 | static void | |
0bc40be8 | 1801 | i8xx_ring_put_irq(struct intel_engine_cs *engine) |
c2798b19 | 1802 | { |
c033666a | 1803 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1804 | unsigned long flags; |
c2798b19 | 1805 | |
7338aefa | 1806 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1807 | if (--engine->irq_refcount == 0) { |
1808 | dev_priv->irq_mask |= engine->irq_enable_mask; | |
c2798b19 CW |
1809 | I915_WRITE16(IMR, dev_priv->irq_mask); |
1810 | POSTING_READ16(IMR); | |
1811 | } | |
7338aefa | 1812 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
c2798b19 CW |
1813 | } |
1814 | ||
b72f3acb | 1815 | static int |
a84c3ae1 | 1816 | bsd_ring_flush(struct drm_i915_gem_request *req, |
78501eac CW |
1817 | u32 invalidate_domains, |
1818 | u32 flush_domains) | |
d1b851fc | 1819 | { |
4a570db5 | 1820 | struct intel_engine_cs *engine = req->engine; |
b72f3acb CW |
1821 | int ret; |
1822 | ||
5fb9de1a | 1823 | ret = intel_ring_begin(req, 2); |
b72f3acb CW |
1824 | if (ret) |
1825 | return ret; | |
1826 | ||
e2f80391 TU |
1827 | intel_ring_emit(engine, MI_FLUSH); |
1828 | intel_ring_emit(engine, MI_NOOP); | |
1829 | intel_ring_advance(engine); | |
b72f3acb | 1830 | return 0; |
d1b851fc ZN |
1831 | } |
1832 | ||
3cce469c | 1833 | static int |
ee044a88 | 1834 | i9xx_add_request(struct drm_i915_gem_request *req) |
d1b851fc | 1835 | { |
4a570db5 | 1836 | struct intel_engine_cs *engine = req->engine; |
3cce469c CW |
1837 | int ret; |
1838 | ||
5fb9de1a | 1839 | ret = intel_ring_begin(req, 4); |
3cce469c CW |
1840 | if (ret) |
1841 | return ret; | |
6f392d54 | 1842 | |
e2f80391 TU |
1843 | intel_ring_emit(engine, MI_STORE_DWORD_INDEX); |
1844 | intel_ring_emit(engine, | |
1845 | I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); | |
1846 | intel_ring_emit(engine, i915_gem_request_get_seqno(req)); | |
1847 | intel_ring_emit(engine, MI_USER_INTERRUPT); | |
1848 | __intel_ring_advance(engine); | |
d1b851fc | 1849 | |
3cce469c | 1850 | return 0; |
d1b851fc ZN |
1851 | } |
1852 | ||
0f46832f | 1853 | static bool |
0bc40be8 | 1854 | gen6_ring_get_irq(struct intel_engine_cs *engine) |
0f46832f | 1855 | { |
c033666a | 1856 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1857 | unsigned long flags; |
0f46832f | 1858 | |
7cd512f1 DV |
1859 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
1860 | return false; | |
0f46832f | 1861 | |
7338aefa | 1862 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 | 1863 | if (engine->irq_refcount++ == 0) { |
c033666a | 1864 | if (HAS_L3_DPF(dev_priv) && engine->id == RCS) |
0bc40be8 TU |
1865 | I915_WRITE_IMR(engine, |
1866 | ~(engine->irq_enable_mask | | |
c033666a | 1867 | GT_PARITY_ERROR(dev_priv))); |
15b9f80e | 1868 | else |
0bc40be8 TU |
1869 | I915_WRITE_IMR(engine, ~engine->irq_enable_mask); |
1870 | gen5_enable_gt_irq(dev_priv, engine->irq_enable_mask); | |
0f46832f | 1871 | } |
7338aefa | 1872 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
0f46832f CW |
1873 | |
1874 | return true; | |
1875 | } | |
1876 | ||
1877 | static void | |
0bc40be8 | 1878 | gen6_ring_put_irq(struct intel_engine_cs *engine) |
0f46832f | 1879 | { |
c033666a | 1880 | struct drm_i915_private *dev_priv = engine->i915; |
7338aefa | 1881 | unsigned long flags; |
0f46832f | 1882 | |
7338aefa | 1883 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 | 1884 | if (--engine->irq_refcount == 0) { |
c033666a CW |
1885 | if (HAS_L3_DPF(dev_priv) && engine->id == RCS) |
1886 | I915_WRITE_IMR(engine, ~GT_PARITY_ERROR(dev_priv)); | |
15b9f80e | 1887 | else |
0bc40be8 TU |
1888 | I915_WRITE_IMR(engine, ~0); |
1889 | gen5_disable_gt_irq(dev_priv, engine->irq_enable_mask); | |
1ec14ad3 | 1890 | } |
7338aefa | 1891 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
d1b851fc ZN |
1892 | } |
1893 | ||
a19d2933 | 1894 | static bool |
0bc40be8 | 1895 | hsw_vebox_get_irq(struct intel_engine_cs *engine) |
a19d2933 | 1896 | { |
c033666a | 1897 | struct drm_i915_private *dev_priv = engine->i915; |
a19d2933 BW |
1898 | unsigned long flags; |
1899 | ||
7cd512f1 | 1900 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
a19d2933 BW |
1901 | return false; |
1902 | ||
59cdb63d | 1903 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1904 | if (engine->irq_refcount++ == 0) { |
1905 | I915_WRITE_IMR(engine, ~engine->irq_enable_mask); | |
1906 | gen6_enable_pm_irq(dev_priv, engine->irq_enable_mask); | |
a19d2933 | 1907 | } |
59cdb63d | 1908 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
a19d2933 BW |
1909 | |
1910 | return true; | |
1911 | } | |
1912 | ||
1913 | static void | |
0bc40be8 | 1914 | hsw_vebox_put_irq(struct intel_engine_cs *engine) |
a19d2933 | 1915 | { |
c033666a | 1916 | struct drm_i915_private *dev_priv = engine->i915; |
a19d2933 BW |
1917 | unsigned long flags; |
1918 | ||
59cdb63d | 1919 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
0bc40be8 TU |
1920 | if (--engine->irq_refcount == 0) { |
1921 | I915_WRITE_IMR(engine, ~0); | |
1922 | gen6_disable_pm_irq(dev_priv, engine->irq_enable_mask); | |
a19d2933 | 1923 | } |
59cdb63d | 1924 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
a19d2933 BW |
1925 | } |
1926 | ||
abd58f01 | 1927 | static bool |
0bc40be8 | 1928 | gen8_ring_get_irq(struct intel_engine_cs *engine) |
abd58f01 | 1929 | { |
c033666a | 1930 | struct drm_i915_private *dev_priv = engine->i915; |
abd58f01 BW |
1931 | unsigned long flags; |
1932 | ||
7cd512f1 | 1933 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
abd58f01 BW |
1934 | return false; |
1935 | ||
1936 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
0bc40be8 | 1937 | if (engine->irq_refcount++ == 0) { |
c033666a | 1938 | if (HAS_L3_DPF(dev_priv) && engine->id == RCS) { |
0bc40be8 TU |
1939 | I915_WRITE_IMR(engine, |
1940 | ~(engine->irq_enable_mask | | |
abd58f01 BW |
1941 | GT_RENDER_L3_PARITY_ERROR_INTERRUPT)); |
1942 | } else { | |
0bc40be8 | 1943 | I915_WRITE_IMR(engine, ~engine->irq_enable_mask); |
abd58f01 | 1944 | } |
0bc40be8 | 1945 | POSTING_READ(RING_IMR(engine->mmio_base)); |
abd58f01 BW |
1946 | } |
1947 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
1948 | ||
1949 | return true; | |
1950 | } | |
1951 | ||
1952 | static void | |
0bc40be8 | 1953 | gen8_ring_put_irq(struct intel_engine_cs *engine) |
abd58f01 | 1954 | { |
c033666a | 1955 | struct drm_i915_private *dev_priv = engine->i915; |
abd58f01 BW |
1956 | unsigned long flags; |
1957 | ||
1958 | spin_lock_irqsave(&dev_priv->irq_lock, flags); | |
0bc40be8 | 1959 | if (--engine->irq_refcount == 0) { |
c033666a | 1960 | if (HAS_L3_DPF(dev_priv) && engine->id == RCS) { |
0bc40be8 | 1961 | I915_WRITE_IMR(engine, |
abd58f01 BW |
1962 | ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT); |
1963 | } else { | |
0bc40be8 | 1964 | I915_WRITE_IMR(engine, ~0); |
abd58f01 | 1965 | } |
0bc40be8 | 1966 | POSTING_READ(RING_IMR(engine->mmio_base)); |
abd58f01 BW |
1967 | } |
1968 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); | |
1969 | } | |
1970 | ||
d1b851fc | 1971 | static int |
53fddaf7 | 1972 | i965_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 1973 | u64 offset, u32 length, |
8e004efc | 1974 | unsigned dispatch_flags) |
d1b851fc | 1975 | { |
4a570db5 | 1976 | struct intel_engine_cs *engine = req->engine; |
e1f99ce6 | 1977 | int ret; |
78501eac | 1978 | |
5fb9de1a | 1979 | ret = intel_ring_begin(req, 2); |
e1f99ce6 CW |
1980 | if (ret) |
1981 | return ret; | |
1982 | ||
e2f80391 | 1983 | intel_ring_emit(engine, |
65f56876 CW |
1984 | MI_BATCH_BUFFER_START | |
1985 | MI_BATCH_GTT | | |
8e004efc JH |
1986 | (dispatch_flags & I915_DISPATCH_SECURE ? |
1987 | 0 : MI_BATCH_NON_SECURE_I965)); | |
e2f80391 TU |
1988 | intel_ring_emit(engine, offset); |
1989 | intel_ring_advance(engine); | |
78501eac | 1990 | |
d1b851fc ZN |
1991 | return 0; |
1992 | } | |
1993 | ||
b45305fc DV |
1994 | /* Just userspace ABI convention to limit the wa batch bo to a resonable size */ |
1995 | #define I830_BATCH_LIMIT (256*1024) | |
c4d69da1 CW |
1996 | #define I830_TLB_ENTRIES (2) |
1997 | #define I830_WA_SIZE max(I830_TLB_ENTRIES*4096, I830_BATCH_LIMIT) | |
8187a2b7 | 1998 | static int |
53fddaf7 | 1999 | i830_dispatch_execbuffer(struct drm_i915_gem_request *req, |
8e004efc JH |
2000 | u64 offset, u32 len, |
2001 | unsigned dispatch_flags) | |
62fdfeaf | 2002 | { |
4a570db5 | 2003 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 2004 | u32 cs_offset = engine->scratch.gtt_offset; |
c4e7a414 | 2005 | int ret; |
62fdfeaf | 2006 | |
5fb9de1a | 2007 | ret = intel_ring_begin(req, 6); |
c4d69da1 CW |
2008 | if (ret) |
2009 | return ret; | |
62fdfeaf | 2010 | |
c4d69da1 | 2011 | /* Evict the invalid PTE TLBs */ |
e2f80391 TU |
2012 | intel_ring_emit(engine, COLOR_BLT_CMD | BLT_WRITE_RGBA); |
2013 | intel_ring_emit(engine, BLT_DEPTH_32 | BLT_ROP_COLOR_COPY | 4096); | |
2014 | intel_ring_emit(engine, I830_TLB_ENTRIES << 16 | 4); /* load each page */ | |
2015 | intel_ring_emit(engine, cs_offset); | |
2016 | intel_ring_emit(engine, 0xdeadbeef); | |
2017 | intel_ring_emit(engine, MI_NOOP); | |
2018 | intel_ring_advance(engine); | |
b45305fc | 2019 | |
8e004efc | 2020 | if ((dispatch_flags & I915_DISPATCH_PINNED) == 0) { |
b45305fc DV |
2021 | if (len > I830_BATCH_LIMIT) |
2022 | return -ENOSPC; | |
2023 | ||
5fb9de1a | 2024 | ret = intel_ring_begin(req, 6 + 2); |
b45305fc DV |
2025 | if (ret) |
2026 | return ret; | |
c4d69da1 CW |
2027 | |
2028 | /* Blit the batch (which has now all relocs applied) to the | |
2029 | * stable batch scratch bo area (so that the CS never | |
2030 | * stumbles over its tlb invalidation bug) ... | |
2031 | */ | |
e2f80391 TU |
2032 | intel_ring_emit(engine, SRC_COPY_BLT_CMD | BLT_WRITE_RGBA); |
2033 | intel_ring_emit(engine, | |
2034 | BLT_DEPTH_32 | BLT_ROP_SRC_COPY | 4096); | |
2035 | intel_ring_emit(engine, DIV_ROUND_UP(len, 4096) << 16 | 4096); | |
2036 | intel_ring_emit(engine, cs_offset); | |
2037 | intel_ring_emit(engine, 4096); | |
2038 | intel_ring_emit(engine, offset); | |
2039 | ||
2040 | intel_ring_emit(engine, MI_FLUSH); | |
2041 | intel_ring_emit(engine, MI_NOOP); | |
2042 | intel_ring_advance(engine); | |
b45305fc DV |
2043 | |
2044 | /* ... and execute it. */ | |
c4d69da1 | 2045 | offset = cs_offset; |
b45305fc | 2046 | } |
e1f99ce6 | 2047 | |
9d611c03 | 2048 | ret = intel_ring_begin(req, 2); |
c4d69da1 CW |
2049 | if (ret) |
2050 | return ret; | |
2051 | ||
e2f80391 TU |
2052 | intel_ring_emit(engine, MI_BATCH_BUFFER_START | MI_BATCH_GTT); |
2053 | intel_ring_emit(engine, offset | (dispatch_flags & I915_DISPATCH_SECURE ? | |
2054 | 0 : MI_BATCH_NON_SECURE)); | |
2055 | intel_ring_advance(engine); | |
c4d69da1 | 2056 | |
fb3256da DV |
2057 | return 0; |
2058 | } | |
2059 | ||
2060 | static int | |
53fddaf7 | 2061 | i915_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 2062 | u64 offset, u32 len, |
8e004efc | 2063 | unsigned dispatch_flags) |
fb3256da | 2064 | { |
4a570db5 | 2065 | struct intel_engine_cs *engine = req->engine; |
fb3256da DV |
2066 | int ret; |
2067 | ||
5fb9de1a | 2068 | ret = intel_ring_begin(req, 2); |
fb3256da DV |
2069 | if (ret) |
2070 | return ret; | |
2071 | ||
e2f80391 TU |
2072 | intel_ring_emit(engine, MI_BATCH_BUFFER_START | MI_BATCH_GTT); |
2073 | intel_ring_emit(engine, offset | (dispatch_flags & I915_DISPATCH_SECURE ? | |
2074 | 0 : MI_BATCH_NON_SECURE)); | |
2075 | intel_ring_advance(engine); | |
62fdfeaf | 2076 | |
62fdfeaf EA |
2077 | return 0; |
2078 | } | |
2079 | ||
0bc40be8 | 2080 | static void cleanup_phys_status_page(struct intel_engine_cs *engine) |
7d3fdfff | 2081 | { |
c033666a | 2082 | struct drm_i915_private *dev_priv = engine->i915; |
7d3fdfff VS |
2083 | |
2084 | if (!dev_priv->status_page_dmah) | |
2085 | return; | |
2086 | ||
c033666a | 2087 | drm_pci_free(dev_priv->dev, dev_priv->status_page_dmah); |
0bc40be8 | 2088 | engine->status_page.page_addr = NULL; |
7d3fdfff VS |
2089 | } |
2090 | ||
0bc40be8 | 2091 | static void cleanup_status_page(struct intel_engine_cs *engine) |
62fdfeaf | 2092 | { |
05394f39 | 2093 | struct drm_i915_gem_object *obj; |
62fdfeaf | 2094 | |
0bc40be8 | 2095 | obj = engine->status_page.obj; |
8187a2b7 | 2096 | if (obj == NULL) |
62fdfeaf | 2097 | return; |
62fdfeaf | 2098 | |
9da3da66 | 2099 | kunmap(sg_page(obj->pages->sgl)); |
d7f46fc4 | 2100 | i915_gem_object_ggtt_unpin(obj); |
05394f39 | 2101 | drm_gem_object_unreference(&obj->base); |
0bc40be8 | 2102 | engine->status_page.obj = NULL; |
62fdfeaf EA |
2103 | } |
2104 | ||
0bc40be8 | 2105 | static int init_status_page(struct intel_engine_cs *engine) |
62fdfeaf | 2106 | { |
0bc40be8 | 2107 | struct drm_i915_gem_object *obj = engine->status_page.obj; |
62fdfeaf | 2108 | |
7d3fdfff | 2109 | if (obj == NULL) { |
1f767e02 | 2110 | unsigned flags; |
e3efda49 | 2111 | int ret; |
e4ffd173 | 2112 | |
c033666a | 2113 | obj = i915_gem_object_create(engine->i915->dev, 4096); |
fe3db79b | 2114 | if (IS_ERR(obj)) { |
e3efda49 | 2115 | DRM_ERROR("Failed to allocate status page\n"); |
fe3db79b | 2116 | return PTR_ERR(obj); |
e3efda49 | 2117 | } |
62fdfeaf | 2118 | |
e3efda49 CW |
2119 | ret = i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); |
2120 | if (ret) | |
2121 | goto err_unref; | |
2122 | ||
1f767e02 | 2123 | flags = 0; |
c033666a | 2124 | if (!HAS_LLC(engine->i915)) |
1f767e02 CW |
2125 | /* On g33, we cannot place HWS above 256MiB, so |
2126 | * restrict its pinning to the low mappable arena. | |
2127 | * Though this restriction is not documented for | |
2128 | * gen4, gen5, or byt, they also behave similarly | |
2129 | * and hang if the HWS is placed at the top of the | |
2130 | * GTT. To generalise, it appears that all !llc | |
2131 | * platforms have issues with us placing the HWS | |
2132 | * above the mappable region (even though we never | |
2133 | * actualy map it). | |
2134 | */ | |
2135 | flags |= PIN_MAPPABLE; | |
2136 | ret = i915_gem_obj_ggtt_pin(obj, 4096, flags); | |
e3efda49 CW |
2137 | if (ret) { |
2138 | err_unref: | |
2139 | drm_gem_object_unreference(&obj->base); | |
2140 | return ret; | |
2141 | } | |
2142 | ||
0bc40be8 | 2143 | engine->status_page.obj = obj; |
e3efda49 | 2144 | } |
62fdfeaf | 2145 | |
0bc40be8 TU |
2146 | engine->status_page.gfx_addr = i915_gem_obj_ggtt_offset(obj); |
2147 | engine->status_page.page_addr = kmap(sg_page(obj->pages->sgl)); | |
2148 | memset(engine->status_page.page_addr, 0, PAGE_SIZE); | |
62fdfeaf | 2149 | |
8187a2b7 | 2150 | DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", |
0bc40be8 | 2151 | engine->name, engine->status_page.gfx_addr); |
62fdfeaf EA |
2152 | |
2153 | return 0; | |
62fdfeaf EA |
2154 | } |
2155 | ||
0bc40be8 | 2156 | static int init_phys_status_page(struct intel_engine_cs *engine) |
6b8294a4 | 2157 | { |
c033666a | 2158 | struct drm_i915_private *dev_priv = engine->i915; |
6b8294a4 CW |
2159 | |
2160 | if (!dev_priv->status_page_dmah) { | |
2161 | dev_priv->status_page_dmah = | |
c033666a | 2162 | drm_pci_alloc(dev_priv->dev, PAGE_SIZE, PAGE_SIZE); |
6b8294a4 CW |
2163 | if (!dev_priv->status_page_dmah) |
2164 | return -ENOMEM; | |
2165 | } | |
2166 | ||
0bc40be8 TU |
2167 | engine->status_page.page_addr = dev_priv->status_page_dmah->vaddr; |
2168 | memset(engine->status_page.page_addr, 0, PAGE_SIZE); | |
6b8294a4 CW |
2169 | |
2170 | return 0; | |
2171 | } | |
2172 | ||
7ba717cf | 2173 | void intel_unpin_ringbuffer_obj(struct intel_ringbuffer *ringbuf) |
2919d291 | 2174 | { |
3d77e9be CW |
2175 | GEM_BUG_ON(ringbuf->vma == NULL); |
2176 | GEM_BUG_ON(ringbuf->virtual_start == NULL); | |
2177 | ||
def0c5f6 | 2178 | if (HAS_LLC(ringbuf->obj->base.dev) && !ringbuf->obj->stolen) |
0a798eb9 | 2179 | i915_gem_object_unpin_map(ringbuf->obj); |
def0c5f6 | 2180 | else |
3d77e9be | 2181 | i915_vma_unpin_iomap(ringbuf->vma); |
8305216f | 2182 | ringbuf->virtual_start = NULL; |
3d77e9be | 2183 | |
2919d291 | 2184 | i915_gem_object_ggtt_unpin(ringbuf->obj); |
3d77e9be | 2185 | ringbuf->vma = NULL; |
7ba717cf TD |
2186 | } |
2187 | ||
c033666a | 2188 | int intel_pin_and_map_ringbuffer_obj(struct drm_i915_private *dev_priv, |
7ba717cf TD |
2189 | struct intel_ringbuffer *ringbuf) |
2190 | { | |
7ba717cf | 2191 | struct drm_i915_gem_object *obj = ringbuf->obj; |
a687a43a CW |
2192 | /* Ring wraparound at offset 0 sometimes hangs. No idea why. */ |
2193 | unsigned flags = PIN_OFFSET_BIAS | 4096; | |
8305216f | 2194 | void *addr; |
7ba717cf TD |
2195 | int ret; |
2196 | ||
def0c5f6 | 2197 | if (HAS_LLC(dev_priv) && !obj->stolen) { |
a687a43a | 2198 | ret = i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, flags); |
def0c5f6 CW |
2199 | if (ret) |
2200 | return ret; | |
7ba717cf | 2201 | |
def0c5f6 | 2202 | ret = i915_gem_object_set_to_cpu_domain(obj, true); |
d2cad535 CW |
2203 | if (ret) |
2204 | goto err_unpin; | |
def0c5f6 | 2205 | |
8305216f DG |
2206 | addr = i915_gem_object_pin_map(obj); |
2207 | if (IS_ERR(addr)) { | |
2208 | ret = PTR_ERR(addr); | |
d2cad535 | 2209 | goto err_unpin; |
def0c5f6 CW |
2210 | } |
2211 | } else { | |
a687a43a CW |
2212 | ret = i915_gem_obj_ggtt_pin(obj, PAGE_SIZE, |
2213 | flags | PIN_MAPPABLE); | |
def0c5f6 CW |
2214 | if (ret) |
2215 | return ret; | |
7ba717cf | 2216 | |
def0c5f6 | 2217 | ret = i915_gem_object_set_to_gtt_domain(obj, true); |
d2cad535 CW |
2218 | if (ret) |
2219 | goto err_unpin; | |
def0c5f6 | 2220 | |
ff3dc087 DCS |
2221 | /* Access through the GTT requires the device to be awake. */ |
2222 | assert_rpm_wakelock_held(dev_priv); | |
2223 | ||
3d77e9be CW |
2224 | addr = i915_vma_pin_iomap(i915_gem_obj_to_ggtt(obj)); |
2225 | if (IS_ERR(addr)) { | |
2226 | ret = PTR_ERR(addr); | |
d2cad535 | 2227 | goto err_unpin; |
def0c5f6 | 2228 | } |
7ba717cf TD |
2229 | } |
2230 | ||
8305216f | 2231 | ringbuf->virtual_start = addr; |
0eb973d3 | 2232 | ringbuf->vma = i915_gem_obj_to_ggtt(obj); |
7ba717cf | 2233 | return 0; |
d2cad535 CW |
2234 | |
2235 | err_unpin: | |
2236 | i915_gem_object_ggtt_unpin(obj); | |
2237 | return ret; | |
7ba717cf TD |
2238 | } |
2239 | ||
01101fa7 | 2240 | static void intel_destroy_ringbuffer_obj(struct intel_ringbuffer *ringbuf) |
7ba717cf | 2241 | { |
2919d291 OM |
2242 | drm_gem_object_unreference(&ringbuf->obj->base); |
2243 | ringbuf->obj = NULL; | |
2244 | } | |
2245 | ||
01101fa7 CW |
2246 | static int intel_alloc_ringbuffer_obj(struct drm_device *dev, |
2247 | struct intel_ringbuffer *ringbuf) | |
62fdfeaf | 2248 | { |
05394f39 | 2249 | struct drm_i915_gem_object *obj; |
62fdfeaf | 2250 | |
ebc052e0 CW |
2251 | obj = NULL; |
2252 | if (!HAS_LLC(dev)) | |
93b0a4e0 | 2253 | obj = i915_gem_object_create_stolen(dev, ringbuf->size); |
ebc052e0 | 2254 | if (obj == NULL) |
d37cd8a8 | 2255 | obj = i915_gem_object_create(dev, ringbuf->size); |
fe3db79b CW |
2256 | if (IS_ERR(obj)) |
2257 | return PTR_ERR(obj); | |
8187a2b7 | 2258 | |
24f3a8cf AG |
2259 | /* mark ring buffers as read-only from GPU side by default */ |
2260 | obj->gt_ro = 1; | |
2261 | ||
93b0a4e0 | 2262 | ringbuf->obj = obj; |
e3efda49 | 2263 | |
7ba717cf | 2264 | return 0; |
e3efda49 CW |
2265 | } |
2266 | ||
01101fa7 CW |
2267 | struct intel_ringbuffer * |
2268 | intel_engine_create_ringbuffer(struct intel_engine_cs *engine, int size) | |
2269 | { | |
2270 | struct intel_ringbuffer *ring; | |
2271 | int ret; | |
2272 | ||
2273 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); | |
608c1a52 CW |
2274 | if (ring == NULL) { |
2275 | DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s\n", | |
2276 | engine->name); | |
01101fa7 | 2277 | return ERR_PTR(-ENOMEM); |
608c1a52 | 2278 | } |
01101fa7 | 2279 | |
4a570db5 | 2280 | ring->engine = engine; |
608c1a52 | 2281 | list_add(&ring->link, &engine->buffers); |
01101fa7 CW |
2282 | |
2283 | ring->size = size; | |
2284 | /* Workaround an erratum on the i830 which causes a hang if | |
2285 | * the TAIL pointer points to within the last 2 cachelines | |
2286 | * of the buffer. | |
2287 | */ | |
2288 | ring->effective_size = size; | |
c033666a | 2289 | if (IS_I830(engine->i915) || IS_845G(engine->i915)) |
01101fa7 CW |
2290 | ring->effective_size -= 2 * CACHELINE_BYTES; |
2291 | ||
2292 | ring->last_retired_head = -1; | |
2293 | intel_ring_update_space(ring); | |
2294 | ||
c033666a | 2295 | ret = intel_alloc_ringbuffer_obj(engine->i915->dev, ring); |
01101fa7 | 2296 | if (ret) { |
608c1a52 CW |
2297 | DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s: %d\n", |
2298 | engine->name, ret); | |
2299 | list_del(&ring->link); | |
01101fa7 CW |
2300 | kfree(ring); |
2301 | return ERR_PTR(ret); | |
2302 | } | |
2303 | ||
2304 | return ring; | |
2305 | } | |
2306 | ||
2307 | void | |
2308 | intel_ringbuffer_free(struct intel_ringbuffer *ring) | |
2309 | { | |
2310 | intel_destroy_ringbuffer_obj(ring); | |
608c1a52 | 2311 | list_del(&ring->link); |
01101fa7 CW |
2312 | kfree(ring); |
2313 | } | |
2314 | ||
e3efda49 | 2315 | static int intel_init_ring_buffer(struct drm_device *dev, |
0bc40be8 | 2316 | struct intel_engine_cs *engine) |
e3efda49 | 2317 | { |
c033666a | 2318 | struct drm_i915_private *dev_priv = to_i915(dev); |
bfc882b4 | 2319 | struct intel_ringbuffer *ringbuf; |
e3efda49 CW |
2320 | int ret; |
2321 | ||
0bc40be8 | 2322 | WARN_ON(engine->buffer); |
bfc882b4 | 2323 | |
c033666a | 2324 | engine->i915 = dev_priv; |
0bc40be8 TU |
2325 | INIT_LIST_HEAD(&engine->active_list); |
2326 | INIT_LIST_HEAD(&engine->request_list); | |
2327 | INIT_LIST_HEAD(&engine->execlist_queue); | |
2328 | INIT_LIST_HEAD(&engine->buffers); | |
2329 | i915_gem_batch_pool_init(dev, &engine->batch_pool); | |
2330 | memset(engine->semaphore.sync_seqno, 0, | |
2331 | sizeof(engine->semaphore.sync_seqno)); | |
e3efda49 | 2332 | |
0bc40be8 | 2333 | init_waitqueue_head(&engine->irq_queue); |
e3efda49 | 2334 | |
0bc40be8 | 2335 | ringbuf = intel_engine_create_ringbuffer(engine, 32 * PAGE_SIZE); |
b0366a54 DG |
2336 | if (IS_ERR(ringbuf)) { |
2337 | ret = PTR_ERR(ringbuf); | |
2338 | goto error; | |
2339 | } | |
0bc40be8 | 2340 | engine->buffer = ringbuf; |
01101fa7 | 2341 | |
c033666a | 2342 | if (I915_NEED_GFX_HWS(dev_priv)) { |
0bc40be8 | 2343 | ret = init_status_page(engine); |
e3efda49 | 2344 | if (ret) |
8ee14975 | 2345 | goto error; |
e3efda49 | 2346 | } else { |
0bc40be8 TU |
2347 | WARN_ON(engine->id != RCS); |
2348 | ret = init_phys_status_page(engine); | |
e3efda49 | 2349 | if (ret) |
8ee14975 | 2350 | goto error; |
e3efda49 CW |
2351 | } |
2352 | ||
c033666a | 2353 | ret = intel_pin_and_map_ringbuffer_obj(dev_priv, ringbuf); |
bfc882b4 DV |
2354 | if (ret) { |
2355 | DRM_ERROR("Failed to pin and map ringbuffer %s: %d\n", | |
0bc40be8 | 2356 | engine->name, ret); |
bfc882b4 DV |
2357 | intel_destroy_ringbuffer_obj(ringbuf); |
2358 | goto error; | |
e3efda49 | 2359 | } |
62fdfeaf | 2360 | |
0bc40be8 | 2361 | ret = i915_cmd_parser_init_ring(engine); |
44e895a8 | 2362 | if (ret) |
8ee14975 OM |
2363 | goto error; |
2364 | ||
8ee14975 | 2365 | return 0; |
351e3db2 | 2366 | |
8ee14975 | 2367 | error: |
117897f4 | 2368 | intel_cleanup_engine(engine); |
8ee14975 | 2369 | return ret; |
62fdfeaf EA |
2370 | } |
2371 | ||
117897f4 | 2372 | void intel_cleanup_engine(struct intel_engine_cs *engine) |
62fdfeaf | 2373 | { |
6402c330 | 2374 | struct drm_i915_private *dev_priv; |
33626e6a | 2375 | |
117897f4 | 2376 | if (!intel_engine_initialized(engine)) |
62fdfeaf EA |
2377 | return; |
2378 | ||
c033666a | 2379 | dev_priv = engine->i915; |
6402c330 | 2380 | |
0bc40be8 | 2381 | if (engine->buffer) { |
117897f4 | 2382 | intel_stop_engine(engine); |
c033666a | 2383 | WARN_ON(!IS_GEN2(dev_priv) && (I915_READ_MODE(engine) & MODE_IDLE) == 0); |
33626e6a | 2384 | |
0bc40be8 TU |
2385 | intel_unpin_ringbuffer_obj(engine->buffer); |
2386 | intel_ringbuffer_free(engine->buffer); | |
2387 | engine->buffer = NULL; | |
b0366a54 | 2388 | } |
78501eac | 2389 | |
0bc40be8 TU |
2390 | if (engine->cleanup) |
2391 | engine->cleanup(engine); | |
8d19215b | 2392 | |
c033666a | 2393 | if (I915_NEED_GFX_HWS(dev_priv)) { |
0bc40be8 | 2394 | cleanup_status_page(engine); |
7d3fdfff | 2395 | } else { |
0bc40be8 TU |
2396 | WARN_ON(engine->id != RCS); |
2397 | cleanup_phys_status_page(engine); | |
7d3fdfff | 2398 | } |
44e895a8 | 2399 | |
0bc40be8 TU |
2400 | i915_cmd_parser_fini_ring(engine); |
2401 | i915_gem_batch_pool_fini(&engine->batch_pool); | |
c033666a | 2402 | engine->i915 = NULL; |
62fdfeaf EA |
2403 | } |
2404 | ||
666796da | 2405 | int intel_engine_idle(struct intel_engine_cs *engine) |
3e960501 | 2406 | { |
a4b3a571 | 2407 | struct drm_i915_gem_request *req; |
3e960501 | 2408 | |
3e960501 | 2409 | /* Wait upon the last request to be completed */ |
0bc40be8 | 2410 | if (list_empty(&engine->request_list)) |
3e960501 CW |
2411 | return 0; |
2412 | ||
0bc40be8 TU |
2413 | req = list_entry(engine->request_list.prev, |
2414 | struct drm_i915_gem_request, | |
2415 | list); | |
b4716185 CW |
2416 | |
2417 | /* Make sure we do not trigger any retires */ | |
2418 | return __i915_wait_request(req, | |
c19ae989 | 2419 | req->i915->mm.interruptible, |
b4716185 | 2420 | NULL, NULL); |
3e960501 CW |
2421 | } |
2422 | ||
6689cb2b | 2423 | int intel_ring_alloc_request_extras(struct drm_i915_gem_request *request) |
9d773091 | 2424 | { |
6310346e CW |
2425 | int ret; |
2426 | ||
2427 | /* Flush enough space to reduce the likelihood of waiting after | |
2428 | * we start building the request - in which case we will just | |
2429 | * have to repeat work. | |
2430 | */ | |
a0442461 | 2431 | request->reserved_space += LEGACY_REQUEST_SIZE; |
6310346e | 2432 | |
4a570db5 | 2433 | request->ringbuf = request->engine->buffer; |
6310346e CW |
2434 | |
2435 | ret = intel_ring_begin(request, 0); | |
2436 | if (ret) | |
2437 | return ret; | |
2438 | ||
a0442461 | 2439 | request->reserved_space -= LEGACY_REQUEST_SIZE; |
6310346e | 2440 | return 0; |
9d773091 CW |
2441 | } |
2442 | ||
987046ad CW |
2443 | static int wait_for_space(struct drm_i915_gem_request *req, int bytes) |
2444 | { | |
2445 | struct intel_ringbuffer *ringbuf = req->ringbuf; | |
2446 | struct intel_engine_cs *engine = req->engine; | |
2447 | struct drm_i915_gem_request *target; | |
2448 | ||
2449 | intel_ring_update_space(ringbuf); | |
2450 | if (ringbuf->space >= bytes) | |
2451 | return 0; | |
2452 | ||
2453 | /* | |
2454 | * Space is reserved in the ringbuffer for finalising the request, | |
2455 | * as that cannot be allowed to fail. During request finalisation, | |
2456 | * reserved_space is set to 0 to stop the overallocation and the | |
2457 | * assumption is that then we never need to wait (which has the | |
2458 | * risk of failing with EINTR). | |
2459 | * | |
2460 | * See also i915_gem_request_alloc() and i915_add_request(). | |
2461 | */ | |
0251a963 | 2462 | GEM_BUG_ON(!req->reserved_space); |
987046ad CW |
2463 | |
2464 | list_for_each_entry(target, &engine->request_list, list) { | |
2465 | unsigned space; | |
2466 | ||
79bbcc29 | 2467 | /* |
987046ad CW |
2468 | * The request queue is per-engine, so can contain requests |
2469 | * from multiple ringbuffers. Here, we must ignore any that | |
2470 | * aren't from the ringbuffer we're considering. | |
79bbcc29 | 2471 | */ |
987046ad CW |
2472 | if (target->ringbuf != ringbuf) |
2473 | continue; | |
2474 | ||
2475 | /* Would completion of this request free enough space? */ | |
2476 | space = __intel_ring_space(target->postfix, ringbuf->tail, | |
2477 | ringbuf->size); | |
2478 | if (space >= bytes) | |
2479 | break; | |
79bbcc29 | 2480 | } |
29b1b415 | 2481 | |
987046ad CW |
2482 | if (WARN_ON(&target->list == &engine->request_list)) |
2483 | return -ENOSPC; | |
2484 | ||
2485 | return i915_wait_request(target); | |
29b1b415 JH |
2486 | } |
2487 | ||
987046ad | 2488 | int intel_ring_begin(struct drm_i915_gem_request *req, int num_dwords) |
cbcc80df | 2489 | { |
987046ad | 2490 | struct intel_ringbuffer *ringbuf = req->ringbuf; |
79bbcc29 | 2491 | int remain_actual = ringbuf->size - ringbuf->tail; |
987046ad CW |
2492 | int remain_usable = ringbuf->effective_size - ringbuf->tail; |
2493 | int bytes = num_dwords * sizeof(u32); | |
2494 | int total_bytes, wait_bytes; | |
79bbcc29 | 2495 | bool need_wrap = false; |
29b1b415 | 2496 | |
0251a963 | 2497 | total_bytes = bytes + req->reserved_space; |
29b1b415 | 2498 | |
79bbcc29 JH |
2499 | if (unlikely(bytes > remain_usable)) { |
2500 | /* | |
2501 | * Not enough space for the basic request. So need to flush | |
2502 | * out the remainder and then wait for base + reserved. | |
2503 | */ | |
2504 | wait_bytes = remain_actual + total_bytes; | |
2505 | need_wrap = true; | |
987046ad CW |
2506 | } else if (unlikely(total_bytes > remain_usable)) { |
2507 | /* | |
2508 | * The base request will fit but the reserved space | |
2509 | * falls off the end. So we don't need an immediate wrap | |
2510 | * and only need to effectively wait for the reserved | |
2511 | * size space from the start of ringbuffer. | |
2512 | */ | |
0251a963 | 2513 | wait_bytes = remain_actual + req->reserved_space; |
79bbcc29 | 2514 | } else { |
987046ad CW |
2515 | /* No wrapping required, just waiting. */ |
2516 | wait_bytes = total_bytes; | |
cbcc80df MK |
2517 | } |
2518 | ||
987046ad CW |
2519 | if (wait_bytes > ringbuf->space) { |
2520 | int ret = wait_for_space(req, wait_bytes); | |
cbcc80df MK |
2521 | if (unlikely(ret)) |
2522 | return ret; | |
79bbcc29 | 2523 | |
987046ad | 2524 | intel_ring_update_space(ringbuf); |
e075a32f CW |
2525 | if (unlikely(ringbuf->space < wait_bytes)) |
2526 | return -EAGAIN; | |
cbcc80df MK |
2527 | } |
2528 | ||
987046ad CW |
2529 | if (unlikely(need_wrap)) { |
2530 | GEM_BUG_ON(remain_actual > ringbuf->space); | |
2531 | GEM_BUG_ON(ringbuf->tail + remain_actual > ringbuf->size); | |
78501eac | 2532 | |
987046ad CW |
2533 | /* Fill the tail with MI_NOOP */ |
2534 | memset(ringbuf->virtual_start + ringbuf->tail, | |
2535 | 0, remain_actual); | |
2536 | ringbuf->tail = 0; | |
2537 | ringbuf->space -= remain_actual; | |
2538 | } | |
304d695c | 2539 | |
987046ad CW |
2540 | ringbuf->space -= bytes; |
2541 | GEM_BUG_ON(ringbuf->space < 0); | |
304d695c | 2542 | return 0; |
8187a2b7 | 2543 | } |
78501eac | 2544 | |
753b1ad4 | 2545 | /* Align the ring tail to a cacheline boundary */ |
bba09b12 | 2546 | int intel_ring_cacheline_align(struct drm_i915_gem_request *req) |
753b1ad4 | 2547 | { |
4a570db5 | 2548 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 2549 | int num_dwords = (engine->buffer->tail & (CACHELINE_BYTES - 1)) / sizeof(uint32_t); |
753b1ad4 VS |
2550 | int ret; |
2551 | ||
2552 | if (num_dwords == 0) | |
2553 | return 0; | |
2554 | ||
18393f63 | 2555 | num_dwords = CACHELINE_BYTES / sizeof(uint32_t) - num_dwords; |
5fb9de1a | 2556 | ret = intel_ring_begin(req, num_dwords); |
753b1ad4 VS |
2557 | if (ret) |
2558 | return ret; | |
2559 | ||
2560 | while (num_dwords--) | |
e2f80391 | 2561 | intel_ring_emit(engine, MI_NOOP); |
753b1ad4 | 2562 | |
e2f80391 | 2563 | intel_ring_advance(engine); |
753b1ad4 VS |
2564 | |
2565 | return 0; | |
2566 | } | |
2567 | ||
0bc40be8 | 2568 | void intel_ring_init_seqno(struct intel_engine_cs *engine, u32 seqno) |
498d2ac1 | 2569 | { |
c033666a | 2570 | struct drm_i915_private *dev_priv = engine->i915; |
498d2ac1 | 2571 | |
29dcb570 CW |
2572 | /* Our semaphore implementation is strictly monotonic (i.e. we proceed |
2573 | * so long as the semaphore value in the register/page is greater | |
2574 | * than the sync value), so whenever we reset the seqno, | |
2575 | * so long as we reset the tracking semaphore value to 0, it will | |
2576 | * always be before the next request's seqno. If we don't reset | |
2577 | * the semaphore value, then when the seqno moves backwards all | |
2578 | * future waits will complete instantly (causing rendering corruption). | |
2579 | */ | |
7e22dbbb | 2580 | if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) { |
0bc40be8 TU |
2581 | I915_WRITE(RING_SYNC_0(engine->mmio_base), 0); |
2582 | I915_WRITE(RING_SYNC_1(engine->mmio_base), 0); | |
d04bce48 | 2583 | if (HAS_VEBOX(dev_priv)) |
0bc40be8 | 2584 | I915_WRITE(RING_SYNC_2(engine->mmio_base), 0); |
e1f99ce6 | 2585 | } |
a058d934 CW |
2586 | if (dev_priv->semaphore_obj) { |
2587 | struct drm_i915_gem_object *obj = dev_priv->semaphore_obj; | |
2588 | struct page *page = i915_gem_object_get_dirty_page(obj, 0); | |
2589 | void *semaphores = kmap(page); | |
2590 | memset(semaphores + GEN8_SEMAPHORE_OFFSET(engine->id, 0), | |
2591 | 0, I915_NUM_ENGINES * gen8_semaphore_seqno_size); | |
2592 | kunmap(page); | |
2593 | } | |
29dcb570 CW |
2594 | memset(engine->semaphore.sync_seqno, 0, |
2595 | sizeof(engine->semaphore.sync_seqno)); | |
d97ed339 | 2596 | |
0bc40be8 | 2597 | engine->set_seqno(engine, seqno); |
01347126 | 2598 | engine->last_submitted_seqno = seqno; |
29dcb570 | 2599 | |
0bc40be8 | 2600 | engine->hangcheck.seqno = seqno; |
8187a2b7 | 2601 | } |
62fdfeaf | 2602 | |
0bc40be8 | 2603 | static void gen6_bsd_ring_write_tail(struct intel_engine_cs *engine, |
297b0c5b | 2604 | u32 value) |
881f47b6 | 2605 | { |
c033666a | 2606 | struct drm_i915_private *dev_priv = engine->i915; |
881f47b6 XH |
2607 | |
2608 | /* Every tail move must follow the sequence below */ | |
12f55818 CW |
2609 | |
2610 | /* Disable notification that the ring is IDLE. The GT | |
2611 | * will then assume that it is busy and bring it out of rc6. | |
2612 | */ | |
0206e353 | 2613 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
12f55818 CW |
2614 | _MASKED_BIT_ENABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
2615 | ||
2616 | /* Clear the context id. Here be magic! */ | |
2617 | I915_WRITE64(GEN6_BSD_RNCID, 0x0); | |
0206e353 | 2618 | |
12f55818 | 2619 | /* Wait for the ring not to be idle, i.e. for it to wake up. */ |
0206e353 | 2620 | if (wait_for((I915_READ(GEN6_BSD_SLEEP_PSMI_CONTROL) & |
12f55818 CW |
2621 | GEN6_BSD_SLEEP_INDICATOR) == 0, |
2622 | 50)) | |
2623 | DRM_ERROR("timed out waiting for the BSD ring to wake up\n"); | |
0206e353 | 2624 | |
12f55818 | 2625 | /* Now that the ring is fully powered up, update the tail */ |
0bc40be8 TU |
2626 | I915_WRITE_TAIL(engine, value); |
2627 | POSTING_READ(RING_TAIL(engine->mmio_base)); | |
12f55818 CW |
2628 | |
2629 | /* Let the ring send IDLE messages to the GT again, | |
2630 | * and so let it sleep to conserve power when idle. | |
2631 | */ | |
0206e353 | 2632 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
12f55818 | 2633 | _MASKED_BIT_DISABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
881f47b6 XH |
2634 | } |
2635 | ||
a84c3ae1 | 2636 | static int gen6_bsd_ring_flush(struct drm_i915_gem_request *req, |
ea251324 | 2637 | u32 invalidate, u32 flush) |
881f47b6 | 2638 | { |
4a570db5 | 2639 | struct intel_engine_cs *engine = req->engine; |
71a77e07 | 2640 | uint32_t cmd; |
b72f3acb CW |
2641 | int ret; |
2642 | ||
5fb9de1a | 2643 | ret = intel_ring_begin(req, 4); |
b72f3acb CW |
2644 | if (ret) |
2645 | return ret; | |
2646 | ||
71a77e07 | 2647 | cmd = MI_FLUSH_DW; |
c033666a | 2648 | if (INTEL_GEN(req->i915) >= 8) |
075b3bba | 2649 | cmd += 1; |
f0a1fb10 CW |
2650 | |
2651 | /* We always require a command barrier so that subsequent | |
2652 | * commands, such as breadcrumb interrupts, are strictly ordered | |
2653 | * wrt the contents of the write cache being flushed to memory | |
2654 | * (and thus being coherent from the CPU). | |
2655 | */ | |
2656 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; | |
2657 | ||
9a289771 JB |
2658 | /* |
2659 | * Bspec vol 1c.5 - video engine command streamer: | |
2660 | * "If ENABLED, all TLBs will be invalidated once the flush | |
2661 | * operation is complete. This bit is only valid when the | |
2662 | * Post-Sync Operation field is a value of 1h or 3h." | |
2663 | */ | |
71a77e07 | 2664 | if (invalidate & I915_GEM_GPU_DOMAINS) |
f0a1fb10 CW |
2665 | cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD; |
2666 | ||
e2f80391 TU |
2667 | intel_ring_emit(engine, cmd); |
2668 | intel_ring_emit(engine, | |
2669 | I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT); | |
c033666a | 2670 | if (INTEL_GEN(req->i915) >= 8) { |
e2f80391 TU |
2671 | intel_ring_emit(engine, 0); /* upper addr */ |
2672 | intel_ring_emit(engine, 0); /* value */ | |
075b3bba | 2673 | } else { |
e2f80391 TU |
2674 | intel_ring_emit(engine, 0); |
2675 | intel_ring_emit(engine, MI_NOOP); | |
075b3bba | 2676 | } |
e2f80391 | 2677 | intel_ring_advance(engine); |
b72f3acb | 2678 | return 0; |
881f47b6 XH |
2679 | } |
2680 | ||
1c7a0623 | 2681 | static int |
53fddaf7 | 2682 | gen8_ring_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 2683 | u64 offset, u32 len, |
8e004efc | 2684 | unsigned dispatch_flags) |
1c7a0623 | 2685 | { |
4a570db5 | 2686 | struct intel_engine_cs *engine = req->engine; |
e2f80391 | 2687 | bool ppgtt = USES_PPGTT(engine->dev) && |
8e004efc | 2688 | !(dispatch_flags & I915_DISPATCH_SECURE); |
1c7a0623 BW |
2689 | int ret; |
2690 | ||
5fb9de1a | 2691 | ret = intel_ring_begin(req, 4); |
1c7a0623 BW |
2692 | if (ret) |
2693 | return ret; | |
2694 | ||
2695 | /* FIXME(BDW): Address space and security selectors. */ | |
e2f80391 | 2696 | intel_ring_emit(engine, MI_BATCH_BUFFER_START_GEN8 | (ppgtt<<8) | |
919032ec AJ |
2697 | (dispatch_flags & I915_DISPATCH_RS ? |
2698 | MI_BATCH_RESOURCE_STREAMER : 0)); | |
e2f80391 TU |
2699 | intel_ring_emit(engine, lower_32_bits(offset)); |
2700 | intel_ring_emit(engine, upper_32_bits(offset)); | |
2701 | intel_ring_emit(engine, MI_NOOP); | |
2702 | intel_ring_advance(engine); | |
1c7a0623 BW |
2703 | |
2704 | return 0; | |
2705 | } | |
2706 | ||
d7d4eedd | 2707 | static int |
53fddaf7 | 2708 | hsw_ring_dispatch_execbuffer(struct drm_i915_gem_request *req, |
8e004efc JH |
2709 | u64 offset, u32 len, |
2710 | unsigned dispatch_flags) | |
d7d4eedd | 2711 | { |
4a570db5 | 2712 | struct intel_engine_cs *engine = req->engine; |
d7d4eedd CW |
2713 | int ret; |
2714 | ||
5fb9de1a | 2715 | ret = intel_ring_begin(req, 2); |
d7d4eedd CW |
2716 | if (ret) |
2717 | return ret; | |
2718 | ||
e2f80391 | 2719 | intel_ring_emit(engine, |
77072258 | 2720 | MI_BATCH_BUFFER_START | |
8e004efc | 2721 | (dispatch_flags & I915_DISPATCH_SECURE ? |
919032ec AJ |
2722 | 0 : MI_BATCH_PPGTT_HSW | MI_BATCH_NON_SECURE_HSW) | |
2723 | (dispatch_flags & I915_DISPATCH_RS ? | |
2724 | MI_BATCH_RESOURCE_STREAMER : 0)); | |
d7d4eedd | 2725 | /* bit0-7 is the length on GEN6+ */ |
e2f80391 TU |
2726 | intel_ring_emit(engine, offset); |
2727 | intel_ring_advance(engine); | |
d7d4eedd CW |
2728 | |
2729 | return 0; | |
2730 | } | |
2731 | ||
881f47b6 | 2732 | static int |
53fddaf7 | 2733 | gen6_ring_dispatch_execbuffer(struct drm_i915_gem_request *req, |
9bcb144c | 2734 | u64 offset, u32 len, |
8e004efc | 2735 | unsigned dispatch_flags) |
881f47b6 | 2736 | { |
4a570db5 | 2737 | struct intel_engine_cs *engine = req->engine; |
0206e353 | 2738 | int ret; |
ab6f8e32 | 2739 | |
5fb9de1a | 2740 | ret = intel_ring_begin(req, 2); |
0206e353 AJ |
2741 | if (ret) |
2742 | return ret; | |
e1f99ce6 | 2743 | |
e2f80391 | 2744 | intel_ring_emit(engine, |
d7d4eedd | 2745 | MI_BATCH_BUFFER_START | |
8e004efc JH |
2746 | (dispatch_flags & I915_DISPATCH_SECURE ? |
2747 | 0 : MI_BATCH_NON_SECURE_I965)); | |
0206e353 | 2748 | /* bit0-7 is the length on GEN6+ */ |
e2f80391 TU |
2749 | intel_ring_emit(engine, offset); |
2750 | intel_ring_advance(engine); | |
ab6f8e32 | 2751 | |
0206e353 | 2752 | return 0; |
881f47b6 XH |
2753 | } |
2754 | ||
549f7365 CW |
2755 | /* Blitter support (SandyBridge+) */ |
2756 | ||
a84c3ae1 | 2757 | static int gen6_ring_flush(struct drm_i915_gem_request *req, |
ea251324 | 2758 | u32 invalidate, u32 flush) |
8d19215b | 2759 | { |
4a570db5 | 2760 | struct intel_engine_cs *engine = req->engine; |
71a77e07 | 2761 | uint32_t cmd; |
b72f3acb CW |
2762 | int ret; |
2763 | ||
5fb9de1a | 2764 | ret = intel_ring_begin(req, 4); |
b72f3acb CW |
2765 | if (ret) |
2766 | return ret; | |
2767 | ||
71a77e07 | 2768 | cmd = MI_FLUSH_DW; |
c033666a | 2769 | if (INTEL_GEN(req->i915) >= 8) |
075b3bba | 2770 | cmd += 1; |
f0a1fb10 CW |
2771 | |
2772 | /* We always require a command barrier so that subsequent | |
2773 | * commands, such as breadcrumb interrupts, are strictly ordered | |
2774 | * wrt the contents of the write cache being flushed to memory | |
2775 | * (and thus being coherent from the CPU). | |
2776 | */ | |
2777 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; | |
2778 | ||
9a289771 JB |
2779 | /* |
2780 | * Bspec vol 1c.3 - blitter engine command streamer: | |
2781 | * "If ENABLED, all TLBs will be invalidated once the flush | |
2782 | * operation is complete. This bit is only valid when the | |
2783 | * Post-Sync Operation field is a value of 1h or 3h." | |
2784 | */ | |
71a77e07 | 2785 | if (invalidate & I915_GEM_DOMAIN_RENDER) |
f0a1fb10 | 2786 | cmd |= MI_INVALIDATE_TLB; |
e2f80391 TU |
2787 | intel_ring_emit(engine, cmd); |
2788 | intel_ring_emit(engine, | |
2789 | I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT); | |
c033666a | 2790 | if (INTEL_GEN(req->i915) >= 8) { |
e2f80391 TU |
2791 | intel_ring_emit(engine, 0); /* upper addr */ |
2792 | intel_ring_emit(engine, 0); /* value */ | |
075b3bba | 2793 | } else { |
e2f80391 TU |
2794 | intel_ring_emit(engine, 0); |
2795 | intel_ring_emit(engine, MI_NOOP); | |
075b3bba | 2796 | } |
e2f80391 | 2797 | intel_ring_advance(engine); |
fd3da6c9 | 2798 | |
b72f3acb | 2799 | return 0; |
8d19215b ZN |
2800 | } |
2801 | ||
5c1143bb XH |
2802 | int intel_init_render_ring_buffer(struct drm_device *dev) |
2803 | { | |
4640c4ff | 2804 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 2805 | struct intel_engine_cs *engine = &dev_priv->engine[RCS]; |
3e78998a BW |
2806 | struct drm_i915_gem_object *obj; |
2807 | int ret; | |
5c1143bb | 2808 | |
e2f80391 TU |
2809 | engine->name = "render ring"; |
2810 | engine->id = RCS; | |
2811 | engine->exec_id = I915_EXEC_RENDER; | |
215a7e32 | 2812 | engine->hw_id = 0; |
e2f80391 | 2813 | engine->mmio_base = RENDER_RING_BASE; |
59465b5f | 2814 | |
c033666a CW |
2815 | if (INTEL_GEN(dev_priv) >= 8) { |
2816 | if (i915_semaphore_is_enabled(dev_priv)) { | |
d37cd8a8 | 2817 | obj = i915_gem_object_create(dev, 4096); |
fe3db79b | 2818 | if (IS_ERR(obj)) { |
3e78998a BW |
2819 | DRM_ERROR("Failed to allocate semaphore bo. Disabling semaphores\n"); |
2820 | i915.semaphores = 0; | |
2821 | } else { | |
2822 | i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); | |
2823 | ret = i915_gem_obj_ggtt_pin(obj, 0, PIN_NONBLOCK); | |
2824 | if (ret != 0) { | |
2825 | drm_gem_object_unreference(&obj->base); | |
2826 | DRM_ERROR("Failed to pin semaphore bo. Disabling semaphores\n"); | |
2827 | i915.semaphores = 0; | |
2828 | } else | |
2829 | dev_priv->semaphore_obj = obj; | |
2830 | } | |
2831 | } | |
7225342a | 2832 | |
e2f80391 | 2833 | engine->init_context = intel_rcs_ctx_init; |
a58c01aa | 2834 | engine->add_request = gen8_render_add_request; |
e2f80391 TU |
2835 | engine->flush = gen8_render_ring_flush; |
2836 | engine->irq_get = gen8_ring_get_irq; | |
2837 | engine->irq_put = gen8_ring_put_irq; | |
2838 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT; | |
c04e0f3b | 2839 | engine->get_seqno = ring_get_seqno; |
e2f80391 | 2840 | engine->set_seqno = ring_set_seqno; |
c033666a | 2841 | if (i915_semaphore_is_enabled(dev_priv)) { |
3e78998a | 2842 | WARN_ON(!dev_priv->semaphore_obj); |
e2f80391 TU |
2843 | engine->semaphore.sync_to = gen8_ring_sync; |
2844 | engine->semaphore.signal = gen8_rcs_signal; | |
2845 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 | 2846 | } |
c033666a | 2847 | } else if (INTEL_GEN(dev_priv) >= 6) { |
e2f80391 TU |
2848 | engine->init_context = intel_rcs_ctx_init; |
2849 | engine->add_request = gen6_add_request; | |
2850 | engine->flush = gen7_render_ring_flush; | |
c033666a | 2851 | if (IS_GEN6(dev_priv)) |
e2f80391 TU |
2852 | engine->flush = gen6_render_ring_flush; |
2853 | engine->irq_get = gen6_ring_get_irq; | |
2854 | engine->irq_put = gen6_ring_put_irq; | |
2855 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT; | |
c04e0f3b CW |
2856 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
2857 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 2858 | engine->set_seqno = ring_set_seqno; |
c033666a | 2859 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
2860 | engine->semaphore.sync_to = gen6_ring_sync; |
2861 | engine->semaphore.signal = gen6_signal; | |
707d9cf9 BW |
2862 | /* |
2863 | * The current semaphore is only applied on pre-gen8 | |
2864 | * platform. And there is no VCS2 ring on the pre-gen8 | |
2865 | * platform. So the semaphore between RCS and VCS2 is | |
2866 | * initialized as INVALID. Gen8 will initialize the | |
2867 | * sema between VCS2 and RCS later. | |
2868 | */ | |
e2f80391 TU |
2869 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_INVALID; |
2870 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_RV; | |
2871 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_RB; | |
2872 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_RVE; | |
2873 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
2874 | engine->semaphore.mbox.signal[RCS] = GEN6_NOSYNC; | |
2875 | engine->semaphore.mbox.signal[VCS] = GEN6_VRSYNC; | |
2876 | engine->semaphore.mbox.signal[BCS] = GEN6_BRSYNC; | |
2877 | engine->semaphore.mbox.signal[VECS] = GEN6_VERSYNC; | |
2878 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 2879 | } |
c033666a | 2880 | } else if (IS_GEN5(dev_priv)) { |
e2f80391 TU |
2881 | engine->add_request = pc_render_add_request; |
2882 | engine->flush = gen4_render_ring_flush; | |
2883 | engine->get_seqno = pc_render_get_seqno; | |
2884 | engine->set_seqno = pc_render_set_seqno; | |
2885 | engine->irq_get = gen5_ring_get_irq; | |
2886 | engine->irq_put = gen5_ring_put_irq; | |
2887 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT | | |
cc609d5d | 2888 | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT; |
59465b5f | 2889 | } else { |
e2f80391 | 2890 | engine->add_request = i9xx_add_request; |
c033666a | 2891 | if (INTEL_GEN(dev_priv) < 4) |
e2f80391 | 2892 | engine->flush = gen2_render_ring_flush; |
46f0f8d1 | 2893 | else |
e2f80391 TU |
2894 | engine->flush = gen4_render_ring_flush; |
2895 | engine->get_seqno = ring_get_seqno; | |
2896 | engine->set_seqno = ring_set_seqno; | |
c033666a | 2897 | if (IS_GEN2(dev_priv)) { |
e2f80391 TU |
2898 | engine->irq_get = i8xx_ring_get_irq; |
2899 | engine->irq_put = i8xx_ring_put_irq; | |
c2798b19 | 2900 | } else { |
e2f80391 TU |
2901 | engine->irq_get = i9xx_ring_get_irq; |
2902 | engine->irq_put = i9xx_ring_put_irq; | |
c2798b19 | 2903 | } |
e2f80391 | 2904 | engine->irq_enable_mask = I915_USER_INTERRUPT; |
1ec14ad3 | 2905 | } |
e2f80391 | 2906 | engine->write_tail = ring_write_tail; |
707d9cf9 | 2907 | |
c033666a | 2908 | if (IS_HASWELL(dev_priv)) |
e2f80391 | 2909 | engine->dispatch_execbuffer = hsw_ring_dispatch_execbuffer; |
c033666a | 2910 | else if (IS_GEN8(dev_priv)) |
e2f80391 | 2911 | engine->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; |
c033666a | 2912 | else if (INTEL_GEN(dev_priv) >= 6) |
e2f80391 | 2913 | engine->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; |
c033666a | 2914 | else if (INTEL_GEN(dev_priv) >= 4) |
e2f80391 | 2915 | engine->dispatch_execbuffer = i965_dispatch_execbuffer; |
c033666a | 2916 | else if (IS_I830(dev_priv) || IS_845G(dev_priv)) |
e2f80391 | 2917 | engine->dispatch_execbuffer = i830_dispatch_execbuffer; |
fb3256da | 2918 | else |
e2f80391 TU |
2919 | engine->dispatch_execbuffer = i915_dispatch_execbuffer; |
2920 | engine->init_hw = init_render_ring; | |
2921 | engine->cleanup = render_ring_cleanup; | |
59465b5f | 2922 | |
b45305fc | 2923 | /* Workaround batchbuffer to combat CS tlb bug. */ |
c033666a | 2924 | if (HAS_BROKEN_CS_TLB(dev_priv)) { |
d37cd8a8 | 2925 | obj = i915_gem_object_create(dev, I830_WA_SIZE); |
fe3db79b | 2926 | if (IS_ERR(obj)) { |
b45305fc | 2927 | DRM_ERROR("Failed to allocate batch bo\n"); |
fe3db79b | 2928 | return PTR_ERR(obj); |
b45305fc DV |
2929 | } |
2930 | ||
be1fa129 | 2931 | ret = i915_gem_obj_ggtt_pin(obj, 0, 0); |
b45305fc DV |
2932 | if (ret != 0) { |
2933 | drm_gem_object_unreference(&obj->base); | |
2934 | DRM_ERROR("Failed to ping batch bo\n"); | |
2935 | return ret; | |
2936 | } | |
2937 | ||
e2f80391 TU |
2938 | engine->scratch.obj = obj; |
2939 | engine->scratch.gtt_offset = i915_gem_obj_ggtt_offset(obj); | |
b45305fc DV |
2940 | } |
2941 | ||
e2f80391 | 2942 | ret = intel_init_ring_buffer(dev, engine); |
99be1dfe DV |
2943 | if (ret) |
2944 | return ret; | |
2945 | ||
c033666a | 2946 | if (INTEL_GEN(dev_priv) >= 5) { |
e2f80391 | 2947 | ret = intel_init_pipe_control(engine); |
99be1dfe DV |
2948 | if (ret) |
2949 | return ret; | |
2950 | } | |
2951 | ||
2952 | return 0; | |
5c1143bb XH |
2953 | } |
2954 | ||
2955 | int intel_init_bsd_ring_buffer(struct drm_device *dev) | |
2956 | { | |
4640c4ff | 2957 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 2958 | struct intel_engine_cs *engine = &dev_priv->engine[VCS]; |
5c1143bb | 2959 | |
e2f80391 TU |
2960 | engine->name = "bsd ring"; |
2961 | engine->id = VCS; | |
2962 | engine->exec_id = I915_EXEC_BSD; | |
215a7e32 | 2963 | engine->hw_id = 1; |
58fa3835 | 2964 | |
e2f80391 | 2965 | engine->write_tail = ring_write_tail; |
c033666a | 2966 | if (INTEL_GEN(dev_priv) >= 6) { |
e2f80391 | 2967 | engine->mmio_base = GEN6_BSD_RING_BASE; |
0fd2c201 | 2968 | /* gen6 bsd needs a special wa for tail updates */ |
c033666a | 2969 | if (IS_GEN6(dev_priv)) |
e2f80391 TU |
2970 | engine->write_tail = gen6_bsd_ring_write_tail; |
2971 | engine->flush = gen6_bsd_ring_flush; | |
2972 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
2973 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
2974 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 2975 | engine->set_seqno = ring_set_seqno; |
c033666a | 2976 | if (INTEL_GEN(dev_priv) >= 8) { |
e2f80391 | 2977 | engine->irq_enable_mask = |
abd58f01 | 2978 | GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT; |
e2f80391 TU |
2979 | engine->irq_get = gen8_ring_get_irq; |
2980 | engine->irq_put = gen8_ring_put_irq; | |
2981 | engine->dispatch_execbuffer = | |
1c7a0623 | 2982 | gen8_ring_dispatch_execbuffer; |
c033666a | 2983 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
2984 | engine->semaphore.sync_to = gen8_ring_sync; |
2985 | engine->semaphore.signal = gen8_xcs_signal; | |
2986 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 | 2987 | } |
abd58f01 | 2988 | } else { |
e2f80391 TU |
2989 | engine->irq_enable_mask = GT_BSD_USER_INTERRUPT; |
2990 | engine->irq_get = gen6_ring_get_irq; | |
2991 | engine->irq_put = gen6_ring_put_irq; | |
2992 | engine->dispatch_execbuffer = | |
1c7a0623 | 2993 | gen6_ring_dispatch_execbuffer; |
c033666a | 2994 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
2995 | engine->semaphore.sync_to = gen6_ring_sync; |
2996 | engine->semaphore.signal = gen6_signal; | |
2997 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_VR; | |
2998 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_INVALID; | |
2999 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_VB; | |
3000 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_VVE; | |
3001 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
3002 | engine->semaphore.mbox.signal[RCS] = GEN6_RVSYNC; | |
3003 | engine->semaphore.mbox.signal[VCS] = GEN6_NOSYNC; | |
3004 | engine->semaphore.mbox.signal[BCS] = GEN6_BVSYNC; | |
3005 | engine->semaphore.mbox.signal[VECS] = GEN6_VEVSYNC; | |
3006 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 3007 | } |
abd58f01 | 3008 | } |
58fa3835 | 3009 | } else { |
e2f80391 TU |
3010 | engine->mmio_base = BSD_RING_BASE; |
3011 | engine->flush = bsd_ring_flush; | |
3012 | engine->add_request = i9xx_add_request; | |
3013 | engine->get_seqno = ring_get_seqno; | |
3014 | engine->set_seqno = ring_set_seqno; | |
c033666a | 3015 | if (IS_GEN5(dev_priv)) { |
e2f80391 TU |
3016 | engine->irq_enable_mask = ILK_BSD_USER_INTERRUPT; |
3017 | engine->irq_get = gen5_ring_get_irq; | |
3018 | engine->irq_put = gen5_ring_put_irq; | |
e48d8634 | 3019 | } else { |
e2f80391 TU |
3020 | engine->irq_enable_mask = I915_BSD_USER_INTERRUPT; |
3021 | engine->irq_get = i9xx_ring_get_irq; | |
3022 | engine->irq_put = i9xx_ring_put_irq; | |
e48d8634 | 3023 | } |
e2f80391 | 3024 | engine->dispatch_execbuffer = i965_dispatch_execbuffer; |
58fa3835 | 3025 | } |
e2f80391 | 3026 | engine->init_hw = init_ring_common; |
58fa3835 | 3027 | |
e2f80391 | 3028 | return intel_init_ring_buffer(dev, engine); |
5c1143bb | 3029 | } |
549f7365 | 3030 | |
845f74a7 | 3031 | /** |
62659920 | 3032 | * Initialize the second BSD ring (eg. Broadwell GT3, Skylake GT3) |
845f74a7 ZY |
3033 | */ |
3034 | int intel_init_bsd2_ring_buffer(struct drm_device *dev) | |
3035 | { | |
3036 | struct drm_i915_private *dev_priv = dev->dev_private; | |
4a570db5 | 3037 | struct intel_engine_cs *engine = &dev_priv->engine[VCS2]; |
e2f80391 TU |
3038 | |
3039 | engine->name = "bsd2 ring"; | |
3040 | engine->id = VCS2; | |
3041 | engine->exec_id = I915_EXEC_BSD; | |
215a7e32 | 3042 | engine->hw_id = 4; |
e2f80391 TU |
3043 | |
3044 | engine->write_tail = ring_write_tail; | |
3045 | engine->mmio_base = GEN8_BSD2_RING_BASE; | |
3046 | engine->flush = gen6_bsd_ring_flush; | |
3047 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
3048 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
3049 | engine->get_seqno = ring_get_seqno; | |
e2f80391 TU |
3050 | engine->set_seqno = ring_set_seqno; |
3051 | engine->irq_enable_mask = | |
845f74a7 | 3052 | GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT; |
e2f80391 TU |
3053 | engine->irq_get = gen8_ring_get_irq; |
3054 | engine->irq_put = gen8_ring_put_irq; | |
3055 | engine->dispatch_execbuffer = | |
845f74a7 | 3056 | gen8_ring_dispatch_execbuffer; |
c033666a | 3057 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
3058 | engine->semaphore.sync_to = gen8_ring_sync; |
3059 | engine->semaphore.signal = gen8_xcs_signal; | |
3060 | GEN8_RING_SEMAPHORE_INIT(engine); | |
3e78998a | 3061 | } |
e2f80391 | 3062 | engine->init_hw = init_ring_common; |
845f74a7 | 3063 | |
e2f80391 | 3064 | return intel_init_ring_buffer(dev, engine); |
845f74a7 ZY |
3065 | } |
3066 | ||
549f7365 CW |
3067 | int intel_init_blt_ring_buffer(struct drm_device *dev) |
3068 | { | |
4640c4ff | 3069 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 3070 | struct intel_engine_cs *engine = &dev_priv->engine[BCS]; |
e2f80391 TU |
3071 | |
3072 | engine->name = "blitter ring"; | |
3073 | engine->id = BCS; | |
3074 | engine->exec_id = I915_EXEC_BLT; | |
215a7e32 | 3075 | engine->hw_id = 2; |
e2f80391 TU |
3076 | |
3077 | engine->mmio_base = BLT_RING_BASE; | |
3078 | engine->write_tail = ring_write_tail; | |
3079 | engine->flush = gen6_ring_flush; | |
3080 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
3081 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
3082 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 3083 | engine->set_seqno = ring_set_seqno; |
c033666a | 3084 | if (INTEL_GEN(dev_priv) >= 8) { |
e2f80391 | 3085 | engine->irq_enable_mask = |
abd58f01 | 3086 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT; |
e2f80391 TU |
3087 | engine->irq_get = gen8_ring_get_irq; |
3088 | engine->irq_put = gen8_ring_put_irq; | |
3089 | engine->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; | |
c033666a | 3090 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
3091 | engine->semaphore.sync_to = gen8_ring_sync; |
3092 | engine->semaphore.signal = gen8_xcs_signal; | |
3093 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 | 3094 | } |
abd58f01 | 3095 | } else { |
e2f80391 TU |
3096 | engine->irq_enable_mask = GT_BLT_USER_INTERRUPT; |
3097 | engine->irq_get = gen6_ring_get_irq; | |
3098 | engine->irq_put = gen6_ring_put_irq; | |
3099 | engine->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; | |
c033666a | 3100 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
3101 | engine->semaphore.signal = gen6_signal; |
3102 | engine->semaphore.sync_to = gen6_ring_sync; | |
707d9cf9 BW |
3103 | /* |
3104 | * The current semaphore is only applied on pre-gen8 | |
3105 | * platform. And there is no VCS2 ring on the pre-gen8 | |
3106 | * platform. So the semaphore between BCS and VCS2 is | |
3107 | * initialized as INVALID. Gen8 will initialize the | |
3108 | * sema between BCS and VCS2 later. | |
3109 | */ | |
e2f80391 TU |
3110 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_BR; |
3111 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_BV; | |
3112 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_INVALID; | |
3113 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_BVE; | |
3114 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
3115 | engine->semaphore.mbox.signal[RCS] = GEN6_RBSYNC; | |
3116 | engine->semaphore.mbox.signal[VCS] = GEN6_VBSYNC; | |
3117 | engine->semaphore.mbox.signal[BCS] = GEN6_NOSYNC; | |
3118 | engine->semaphore.mbox.signal[VECS] = GEN6_VEBSYNC; | |
3119 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 3120 | } |
abd58f01 | 3121 | } |
e2f80391 | 3122 | engine->init_hw = init_ring_common; |
549f7365 | 3123 | |
e2f80391 | 3124 | return intel_init_ring_buffer(dev, engine); |
549f7365 | 3125 | } |
a7b9761d | 3126 | |
9a8a2213 BW |
3127 | int intel_init_vebox_ring_buffer(struct drm_device *dev) |
3128 | { | |
4640c4ff | 3129 | struct drm_i915_private *dev_priv = dev->dev_private; |
4a570db5 | 3130 | struct intel_engine_cs *engine = &dev_priv->engine[VECS]; |
9a8a2213 | 3131 | |
e2f80391 TU |
3132 | engine->name = "video enhancement ring"; |
3133 | engine->id = VECS; | |
3134 | engine->exec_id = I915_EXEC_VEBOX; | |
215a7e32 | 3135 | engine->hw_id = 3; |
9a8a2213 | 3136 | |
e2f80391 TU |
3137 | engine->mmio_base = VEBOX_RING_BASE; |
3138 | engine->write_tail = ring_write_tail; | |
3139 | engine->flush = gen6_ring_flush; | |
3140 | engine->add_request = gen6_add_request; | |
c04e0f3b CW |
3141 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
3142 | engine->get_seqno = ring_get_seqno; | |
e2f80391 | 3143 | engine->set_seqno = ring_set_seqno; |
abd58f01 | 3144 | |
c033666a | 3145 | if (INTEL_GEN(dev_priv) >= 8) { |
e2f80391 | 3146 | engine->irq_enable_mask = |
40c499f9 | 3147 | GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT; |
e2f80391 TU |
3148 | engine->irq_get = gen8_ring_get_irq; |
3149 | engine->irq_put = gen8_ring_put_irq; | |
3150 | engine->dispatch_execbuffer = gen8_ring_dispatch_execbuffer; | |
c033666a | 3151 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
3152 | engine->semaphore.sync_to = gen8_ring_sync; |
3153 | engine->semaphore.signal = gen8_xcs_signal; | |
3154 | GEN8_RING_SEMAPHORE_INIT(engine); | |
707d9cf9 | 3155 | } |
abd58f01 | 3156 | } else { |
e2f80391 TU |
3157 | engine->irq_enable_mask = PM_VEBOX_USER_INTERRUPT; |
3158 | engine->irq_get = hsw_vebox_get_irq; | |
3159 | engine->irq_put = hsw_vebox_put_irq; | |
3160 | engine->dispatch_execbuffer = gen6_ring_dispatch_execbuffer; | |
c033666a | 3161 | if (i915_semaphore_is_enabled(dev_priv)) { |
e2f80391 TU |
3162 | engine->semaphore.sync_to = gen6_ring_sync; |
3163 | engine->semaphore.signal = gen6_signal; | |
3164 | engine->semaphore.mbox.wait[RCS] = MI_SEMAPHORE_SYNC_VER; | |
3165 | engine->semaphore.mbox.wait[VCS] = MI_SEMAPHORE_SYNC_VEV; | |
3166 | engine->semaphore.mbox.wait[BCS] = MI_SEMAPHORE_SYNC_VEB; | |
3167 | engine->semaphore.mbox.wait[VECS] = MI_SEMAPHORE_SYNC_INVALID; | |
3168 | engine->semaphore.mbox.wait[VCS2] = MI_SEMAPHORE_SYNC_INVALID; | |
3169 | engine->semaphore.mbox.signal[RCS] = GEN6_RVESYNC; | |
3170 | engine->semaphore.mbox.signal[VCS] = GEN6_VVESYNC; | |
3171 | engine->semaphore.mbox.signal[BCS] = GEN6_BVESYNC; | |
3172 | engine->semaphore.mbox.signal[VECS] = GEN6_NOSYNC; | |
3173 | engine->semaphore.mbox.signal[VCS2] = GEN6_NOSYNC; | |
707d9cf9 | 3174 | } |
abd58f01 | 3175 | } |
e2f80391 | 3176 | engine->init_hw = init_ring_common; |
9a8a2213 | 3177 | |
e2f80391 | 3178 | return intel_init_ring_buffer(dev, engine); |
9a8a2213 BW |
3179 | } |
3180 | ||
a7b9761d | 3181 | int |
4866d729 | 3182 | intel_ring_flush_all_caches(struct drm_i915_gem_request *req) |
a7b9761d | 3183 | { |
4a570db5 | 3184 | struct intel_engine_cs *engine = req->engine; |
a7b9761d CW |
3185 | int ret; |
3186 | ||
e2f80391 | 3187 | if (!engine->gpu_caches_dirty) |
a7b9761d CW |
3188 | return 0; |
3189 | ||
e2f80391 | 3190 | ret = engine->flush(req, 0, I915_GEM_GPU_DOMAINS); |
a7b9761d CW |
3191 | if (ret) |
3192 | return ret; | |
3193 | ||
a84c3ae1 | 3194 | trace_i915_gem_ring_flush(req, 0, I915_GEM_GPU_DOMAINS); |
a7b9761d | 3195 | |
e2f80391 | 3196 | engine->gpu_caches_dirty = false; |
a7b9761d CW |
3197 | return 0; |
3198 | } | |
3199 | ||
3200 | int | |
2f20055d | 3201 | intel_ring_invalidate_all_caches(struct drm_i915_gem_request *req) |
a7b9761d | 3202 | { |
4a570db5 | 3203 | struct intel_engine_cs *engine = req->engine; |
a7b9761d CW |
3204 | uint32_t flush_domains; |
3205 | int ret; | |
3206 | ||
3207 | flush_domains = 0; | |
e2f80391 | 3208 | if (engine->gpu_caches_dirty) |
a7b9761d CW |
3209 | flush_domains = I915_GEM_GPU_DOMAINS; |
3210 | ||
e2f80391 | 3211 | ret = engine->flush(req, I915_GEM_GPU_DOMAINS, flush_domains); |
a7b9761d CW |
3212 | if (ret) |
3213 | return ret; | |
3214 | ||
a84c3ae1 | 3215 | trace_i915_gem_ring_flush(req, I915_GEM_GPU_DOMAINS, flush_domains); |
a7b9761d | 3216 | |
e2f80391 | 3217 | engine->gpu_caches_dirty = false; |
a7b9761d CW |
3218 | return 0; |
3219 | } | |
e3efda49 CW |
3220 | |
3221 | void | |
117897f4 | 3222 | intel_stop_engine(struct intel_engine_cs *engine) |
e3efda49 CW |
3223 | { |
3224 | int ret; | |
3225 | ||
117897f4 | 3226 | if (!intel_engine_initialized(engine)) |
e3efda49 CW |
3227 | return; |
3228 | ||
666796da | 3229 | ret = intel_engine_idle(engine); |
f4457ae7 | 3230 | if (ret) |
e3efda49 | 3231 | DRM_ERROR("failed to quiesce %s whilst cleaning up: %d\n", |
0bc40be8 | 3232 | engine->name, ret); |
e3efda49 | 3233 | |
0bc40be8 | 3234 | stop_ring(engine); |
e3efda49 | 3235 | } |