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