blob: 04d9d9a946a77d31fb7c185ed809bcdb39cdd566 [file] [log] [blame]
Eric Anholt62fdfea2010-05-21 13:26:39 -07001/*
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
Zeng Zhaoxiua4d8a0f2015-12-06 18:26:30 +080030#include <linux/log2.h>
Chris Wilson7c2fa7f2017-11-10 14:26:34 +000031
David Howells760285e2012-10-02 18:01:07 +010032#include <drm/drmP.h>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/i915_drm.h>
Chris Wilson7c2fa7f2017-11-10 14:26:34 +000034
35#include "i915_drv.h"
36#include "i915_gem_render_state.h"
Eric Anholt62fdfea2010-05-21 13:26:39 -070037#include "i915_trace.h"
Xiang, Haihao881f47b2010-09-19 14:40:43 +010038#include "intel_drv.h"
Eric Anholt62fdfea2010-05-21 13:26:39 -070039
Chris Wilsona0442462016-04-29 09:07:05 +010040/* Rough estimate of the typical request size, performing a flush,
41 * set-context and then emitting the batch.
42 */
43#define LEGACY_REQUEST_SIZE 200
44
Chris Wilson605d5b32017-05-04 14:08:44 +010045static unsigned int __intel_ring_space(unsigned int head,
46 unsigned int tail,
47 unsigned int size)
Chris Wilson1cf0ba12014-05-05 09:07:33 +010048{
Chris Wilson605d5b32017-05-04 14:08:44 +010049 /*
50 * "If the Ring Buffer Head Pointer and the Tail Pointer are on the
51 * same cacheline, the Head Pointer must not be greater than the Tail
52 * Pointer."
53 */
54 GEM_BUG_ON(!is_power_of_2(size));
55 return (head - tail - CACHELINE_BYTES) & (size - 1);
Chris Wilson1cf0ba12014-05-05 09:07:33 +010056}
57
Chris Wilson95aebcb2017-05-04 14:08:45 +010058unsigned int intel_ring_update_space(struct intel_ring *ring)
Dave Gordonebd0fd42014-11-27 11:22:49 +000059{
Chris Wilson95aebcb2017-05-04 14:08:45 +010060 unsigned int space;
61
62 space = __intel_ring_space(ring->head, ring->emit, ring->size);
63
64 ring->space = space;
65 return space;
Dave Gordonebd0fd42014-11-27 11:22:49 +000066}
67
Chris Wilsonb72f3ac2011-01-04 17:34:02 +000068static int
Chris Wilsone61e0f52018-02-21 09:56:36 +000069gen2_render_ring_flush(struct i915_request *rq, u32 mode)
Chris Wilson46f0f8d2012-04-18 11:12:11 +010070{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +000071 u32 cmd, *cs;
Chris Wilson46f0f8d2012-04-18 11:12:11 +010072
73 cmd = MI_FLUSH;
Chris Wilson46f0f8d2012-04-18 11:12:11 +010074
Chris Wilson7c9cf4e2016-08-02 22:50:25 +010075 if (mode & EMIT_INVALIDATE)
Chris Wilson46f0f8d2012-04-18 11:12:11 +010076 cmd |= MI_READ_FLUSH;
77
Chris Wilsone61e0f52018-02-21 09:56:36 +000078 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +000079 if (IS_ERR(cs))
80 return PTR_ERR(cs);
Chris Wilson46f0f8d2012-04-18 11:12:11 +010081
Tvrtko Ursulin73dec952017-02-14 11:32:42 +000082 *cs++ = cmd;
83 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +000084 intel_ring_advance(rq, cs);
Chris Wilson46f0f8d2012-04-18 11:12:11 +010085
86 return 0;
87}
88
89static int
Chris Wilsone61e0f52018-02-21 09:56:36 +000090gen4_render_ring_flush(struct i915_request *rq, u32 mode)
Eric Anholt62fdfea2010-05-21 13:26:39 -070091{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +000092 u32 cmd, *cs;
Chris Wilson6f392d52010-08-07 11:01:22 +010093
Chris Wilson36d527d2011-03-19 22:26:49 +000094 /*
95 * read/write caches:
96 *
97 * I915_GEM_DOMAIN_RENDER is always invalidated, but is
98 * only flushed if MI_NO_WRITE_FLUSH is unset. On 965, it is
99 * also flushed at 2d versus 3d pipeline switches.
100 *
101 * read-only caches:
102 *
103 * I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if
104 * MI_READ_FLUSH is set, and is always flushed on 965.
105 *
106 * I915_GEM_DOMAIN_COMMAND may not exist?
107 *
108 * I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is
109 * invalidated when MI_EXE_FLUSH is set.
110 *
111 * I915_GEM_DOMAIN_VERTEX, which exists on 965, is
112 * invalidated with every MI_FLUSH.
113 *
114 * TLBs:
115 *
116 * On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND
117 * and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and
118 * I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER
119 * are flushed at any MI_FLUSH.
120 */
121
Chris Wilsonb5321f32016-08-02 22:50:18 +0100122 cmd = MI_FLUSH;
Chris Wilson7c9cf4e2016-08-02 22:50:25 +0100123 if (mode & EMIT_INVALIDATE) {
Chris Wilson36d527d2011-03-19 22:26:49 +0000124 cmd |= MI_EXE_FLUSH;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000125 if (IS_G4X(rq->i915) || IS_GEN5(rq->i915))
Chris Wilsonb5321f32016-08-02 22:50:18 +0100126 cmd |= MI_INVALIDATE_ISP;
127 }
Chris Wilson36d527d2011-03-19 22:26:49 +0000128
Chris Wilsone61e0f52018-02-21 09:56:36 +0000129 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000130 if (IS_ERR(cs))
131 return PTR_ERR(cs);
Chris Wilson36d527d2011-03-19 22:26:49 +0000132
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000133 *cs++ = cmd;
134 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000135 intel_ring_advance(rq, cs);
Chris Wilsonb72f3ac2011-01-04 17:34:02 +0000136
137 return 0;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800138}
139
Chris Wilson179f4022018-02-08 11:12:20 +0000140/*
Jesse Barnes8d315282011-10-16 10:23:31 +0200141 * Emits a PIPE_CONTROL with a non-zero post-sync operation, for
142 * implementing two workarounds on gen6. From section 1.4.7.1
143 * "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1:
144 *
145 * [DevSNB-C+{W/A}] Before any depth stall flush (including those
146 * produced by non-pipelined state commands), software needs to first
147 * send a PIPE_CONTROL with no bits set except Post-Sync Operation !=
148 * 0.
149 *
150 * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache Flush Enable
151 * =1, a PIPE_CONTROL with any non-zero post-sync-op is required.
152 *
153 * And the workaround for these two requires this workaround first:
154 *
155 * [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent
156 * BEFORE the pipe-control with a post-sync op and no write-cache
157 * flushes.
158 *
159 * And this last workaround is tricky because of the requirements on
160 * that bit. From section 1.4.7.2.3 "Stall" of the Sandy Bridge PRM
161 * volume 2 part 1:
162 *
163 * "1 of the following must also be set:
164 * - Render Target Cache Flush Enable ([12] of DW1)
165 * - Depth Cache Flush Enable ([0] of DW1)
166 * - Stall at Pixel Scoreboard ([1] of DW1)
167 * - Depth Stall ([13] of DW1)
168 * - Post-Sync Operation ([13] of DW1)
169 * - Notify Enable ([8] of DW1)"
170 *
171 * The cache flushes require the workaround flush that triggered this
172 * one, so we can't use it. Depth stall would trigger the same.
173 * Post-sync nonzero is what triggered this second workaround, so we
174 * can't use that one either. Notify enable is IRQs, which aren't
175 * really our business. That leaves only stall at scoreboard.
176 */
177static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000178intel_emit_post_sync_nonzero_flush(struct i915_request *rq)
Jesse Barnes8d315282011-10-16 10:23:31 +0200179{
Chris Wilsonb5321f32016-08-02 22:50:18 +0100180 u32 scratch_addr =
Chris Wilsone61e0f52018-02-21 09:56:36 +0000181 i915_ggtt_offset(rq->engine->scratch) + 2 * CACHELINE_BYTES;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000182 u32 *cs;
Jesse Barnes8d315282011-10-16 10:23:31 +0200183
Chris Wilsone61e0f52018-02-21 09:56:36 +0000184 cs = intel_ring_begin(rq, 6);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000185 if (IS_ERR(cs))
186 return PTR_ERR(cs);
Jesse Barnes8d315282011-10-16 10:23:31 +0200187
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000188 *cs++ = GFX_OP_PIPE_CONTROL(5);
189 *cs++ = PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD;
190 *cs++ = scratch_addr | PIPE_CONTROL_GLOBAL_GTT;
191 *cs++ = 0; /* low dword */
192 *cs++ = 0; /* high dword */
193 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000194 intel_ring_advance(rq, cs);
Jesse Barnes8d315282011-10-16 10:23:31 +0200195
Chris Wilsone61e0f52018-02-21 09:56:36 +0000196 cs = intel_ring_begin(rq, 6);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000197 if (IS_ERR(cs))
198 return PTR_ERR(cs);
Jesse Barnes8d315282011-10-16 10:23:31 +0200199
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000200 *cs++ = GFX_OP_PIPE_CONTROL(5);
201 *cs++ = PIPE_CONTROL_QW_WRITE;
202 *cs++ = scratch_addr | PIPE_CONTROL_GLOBAL_GTT;
203 *cs++ = 0;
204 *cs++ = 0;
205 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000206 intel_ring_advance(rq, cs);
Jesse Barnes8d315282011-10-16 10:23:31 +0200207
208 return 0;
209}
210
211static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000212gen6_render_ring_flush(struct i915_request *rq, u32 mode)
Jesse Barnes8d315282011-10-16 10:23:31 +0200213{
Chris Wilsonb5321f32016-08-02 22:50:18 +0100214 u32 scratch_addr =
Chris Wilsone61e0f52018-02-21 09:56:36 +0000215 i915_ggtt_offset(rq->engine->scratch) + 2 * CACHELINE_BYTES;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000216 u32 *cs, flags = 0;
Jesse Barnes8d315282011-10-16 10:23:31 +0200217 int ret;
218
Paulo Zanonib3111502012-08-17 18:35:42 -0300219 /* Force SNB workarounds for PIPE_CONTROL flushes */
Chris Wilsone61e0f52018-02-21 09:56:36 +0000220 ret = intel_emit_post_sync_nonzero_flush(rq);
Paulo Zanonib3111502012-08-17 18:35:42 -0300221 if (ret)
222 return ret;
223
Jesse Barnes8d315282011-10-16 10:23:31 +0200224 /* Just flush everything. Experiments have shown that reducing the
225 * number of bits based on the write domains has little performance
226 * impact.
227 */
Chris Wilson7c9cf4e2016-08-02 22:50:25 +0100228 if (mode & EMIT_FLUSH) {
Chris Wilson7d54a902012-08-10 10:18:10 +0100229 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 */
Daniel Vetter97f209b2012-06-28 09:48:42 +0200235 flags |= PIPE_CONTROL_CS_STALL;
Chris Wilson7d54a902012-08-10 10:18:10 +0100236 }
Chris Wilson7c9cf4e2016-08-02 22:50:25 +0100237 if (mode & EMIT_INVALIDATE) {
Chris Wilson7d54a902012-08-10 10:18:10 +0100238 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 */
Jesse Barnes3ac78312012-10-25 12:15:47 -0700247 flags |= PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_CS_STALL;
Chris Wilson7d54a902012-08-10 10:18:10 +0100248 }
Jesse Barnes8d315282011-10-16 10:23:31 +0200249
Chris Wilsone61e0f52018-02-21 09:56:36 +0000250 cs = intel_ring_begin(rq, 4);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000251 if (IS_ERR(cs))
252 return PTR_ERR(cs);
Jesse Barnes8d315282011-10-16 10:23:31 +0200253
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000254 *cs++ = GFX_OP_PIPE_CONTROL(4);
255 *cs++ = flags;
256 *cs++ = scratch_addr | PIPE_CONTROL_GLOBAL_GTT;
257 *cs++ = 0;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000258 intel_ring_advance(rq, cs);
Jesse Barnes8d315282011-10-16 10:23:31 +0200259
260 return 0;
261}
262
Chris Wilson6c6cf5a2012-07-20 18:02:28 +0100263static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000264gen7_render_ring_cs_stall_wa(struct i915_request *rq)
Paulo Zanonif3987632012-08-17 18:35:43 -0300265{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000266 u32 *cs;
Paulo Zanonif3987632012-08-17 18:35:43 -0300267
Chris Wilsone61e0f52018-02-21 09:56:36 +0000268 cs = intel_ring_begin(rq, 4);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000269 if (IS_ERR(cs))
270 return PTR_ERR(cs);
Paulo Zanonif3987632012-08-17 18:35:43 -0300271
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000272 *cs++ = GFX_OP_PIPE_CONTROL(4);
273 *cs++ = PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD;
274 *cs++ = 0;
275 *cs++ = 0;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000276 intel_ring_advance(rq, cs);
Paulo Zanonif3987632012-08-17 18:35:43 -0300277
278 return 0;
279}
280
281static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000282gen7_render_ring_flush(struct i915_request *rq, u32 mode)
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300283{
Chris Wilsonb5321f32016-08-02 22:50:18 +0100284 u32 scratch_addr =
Chris Wilsone61e0f52018-02-21 09:56:36 +0000285 i915_ggtt_offset(rq->engine->scratch) + 2 * CACHELINE_BYTES;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000286 u32 *cs, flags = 0;
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300287
Paulo Zanonif3987632012-08-17 18:35:43 -0300288 /*
289 * Ensure that any following seqno writes only happen when the render
290 * cache is indeed flushed.
291 *
292 * Workaround: 4th PIPE_CONTROL command (except the ones with only
293 * read-cache invalidate bits set) must have the CS_STALL bit set. We
294 * don't try to be clever and just set it unconditionally.
295 */
296 flags |= PIPE_CONTROL_CS_STALL;
297
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300298 /* Just flush everything. Experiments have shown that reducing the
299 * number of bits based on the write domains has little performance
300 * impact.
301 */
Chris Wilson7c9cf4e2016-08-02 22:50:25 +0100302 if (mode & EMIT_FLUSH) {
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300303 flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH;
304 flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH;
Francisco Jerez965fd602016-01-13 18:59:39 -0800305 flags |= PIPE_CONTROL_DC_FLUSH_ENABLE;
Chris Wilson40a24482015-08-21 16:08:41 +0100306 flags |= PIPE_CONTROL_FLUSH_ENABLE;
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300307 }
Chris Wilson7c9cf4e2016-08-02 22:50:25 +0100308 if (mode & EMIT_INVALIDATE) {
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300309 flags |= PIPE_CONTROL_TLB_INVALIDATE;
310 flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE;
311 flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE;
312 flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE;
313 flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE;
314 flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE;
Chris Wilson148b83d2014-12-16 08:44:31 +0000315 flags |= PIPE_CONTROL_MEDIA_STATE_CLEAR;
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300316 /*
317 * TLB invalidate requires a post-sync write.
318 */
319 flags |= PIPE_CONTROL_QW_WRITE;
Ville Syrjäläb9e1faa2013-02-14 21:53:51 +0200320 flags |= PIPE_CONTROL_GLOBAL_GTT_IVB;
Paulo Zanonif3987632012-08-17 18:35:43 -0300321
Chris Wilsonadd284a2014-12-16 08:44:32 +0000322 flags |= PIPE_CONTROL_STALL_AT_SCOREBOARD;
323
Paulo Zanonif3987632012-08-17 18:35:43 -0300324 /* Workaround: we must issue a pipe_control with CS-stall bit
325 * set before a pipe_control command that has the state cache
326 * invalidate bit set. */
Chris Wilsone61e0f52018-02-21 09:56:36 +0000327 gen7_render_ring_cs_stall_wa(rq);
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300328 }
329
Chris Wilsone61e0f52018-02-21 09:56:36 +0000330 cs = intel_ring_begin(rq, 4);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000331 if (IS_ERR(cs))
332 return PTR_ERR(cs);
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300333
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000334 *cs++ = GFX_OP_PIPE_CONTROL(4);
335 *cs++ = flags;
336 *cs++ = scratch_addr;
337 *cs++ = 0;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000338 intel_ring_advance(rq, cs);
Paulo Zanoni4772eae2012-08-17 18:35:41 -0300339
340 return 0;
341}
342
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000343static void ring_setup_phys_status_page(struct intel_engine_cs *engine)
Daniel Vetter035dc1e2013-07-03 12:56:54 +0200344{
Chris Wilsonc0336662016-05-06 15:40:21 +0100345 struct drm_i915_private *dev_priv = engine->i915;
Daniel Vetter035dc1e2013-07-03 12:56:54 +0200346 u32 addr;
347
348 addr = dev_priv->status_page_dmah->busaddr;
Chris Wilsonc0336662016-05-06 15:40:21 +0100349 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter035dc1e2013-07-03 12:56:54 +0200350 addr |= (dev_priv->status_page_dmah->busaddr >> 28) & 0xf0;
351 I915_WRITE(HWS_PGA, addr);
352}
353
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000354static void intel_ring_setup_status_page(struct intel_engine_cs *engine)
Damien Lespiauaf75f262015-02-10 19:32:17 +0000355{
Chris Wilsonc0336662016-05-06 15:40:21 +0100356 struct drm_i915_private *dev_priv = engine->i915;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200357 i915_reg_t mmio;
Damien Lespiauaf75f262015-02-10 19:32:17 +0000358
359 /* The ring status page addresses are no longer next to the rest of
360 * the ring registers as of gen7.
361 */
Chris Wilsonc0336662016-05-06 15:40:21 +0100362 if (IS_GEN7(dev_priv)) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000363 switch (engine->id) {
Michel Thierrya2d3d262017-08-30 11:01:15 -0700364 /*
365 * No more rings exist on Gen7. Default case is only to shut up
366 * gcc switch check warning.
367 */
368 default:
369 GEM_BUG_ON(engine->id);
Damien Lespiauaf75f262015-02-10 19:32:17 +0000370 case RCS:
371 mmio = RENDER_HWS_PGA_GEN7;
372 break;
373 case BCS:
374 mmio = BLT_HWS_PGA_GEN7;
375 break;
Damien Lespiauaf75f262015-02-10 19:32:17 +0000376 case VCS:
377 mmio = BSD_HWS_PGA_GEN7;
378 break;
379 case VECS:
380 mmio = VEBOX_HWS_PGA_GEN7;
381 break;
382 }
Chris Wilsonc0336662016-05-06 15:40:21 +0100383 } else if (IS_GEN6(dev_priv)) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000384 mmio = RING_HWS_PGA_GEN6(engine->mmio_base);
Damien Lespiauaf75f262015-02-10 19:32:17 +0000385 } else {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000386 mmio = RING_HWS_PGA(engine->mmio_base);
Damien Lespiauaf75f262015-02-10 19:32:17 +0000387 }
388
Ville Syrjäläc54980892017-08-18 21:37:01 +0300389 if (INTEL_GEN(dev_priv) >= 6)
390 I915_WRITE(RING_HWSTAM(engine->mmio_base), 0xffffffff);
391
Chris Wilson57e88532016-08-15 10:48:57 +0100392 I915_WRITE(mmio, engine->status_page.ggtt_offset);
Damien Lespiauaf75f262015-02-10 19:32:17 +0000393 POSTING_READ(mmio);
394
Chris Wilson79e67702017-11-20 20:55:01 +0000395 /* Flush the TLB for this page */
Tvrtko Ursulinac657f62016-05-10 10:57:08 +0100396 if (IS_GEN(dev_priv, 6, 7)) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000397 i915_reg_t reg = RING_INSTPM(engine->mmio_base);
Damien Lespiauaf75f262015-02-10 19:32:17 +0000398
399 /* ring should be idle before issuing a sync flush*/
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000400 WARN_ON((I915_READ_MODE(engine) & MODE_IDLE) == 0);
Damien Lespiauaf75f262015-02-10 19:32:17 +0000401
402 I915_WRITE(reg,
403 _MASKED_BIT_ENABLE(INSTPM_TLB_INVALIDATE |
404 INSTPM_SYNC_FLUSH));
Chris Wilson25ab57f2016-06-30 15:33:29 +0100405 if (intel_wait_for_register(dev_priv,
406 reg, INSTPM_SYNC_FLUSH, 0,
407 1000))
Damien Lespiauaf75f262015-02-10 19:32:17 +0000408 DRM_ERROR("%s: wait for SyncFlush to complete for TLB invalidation timed out\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000409 engine->name);
Damien Lespiauaf75f262015-02-10 19:32:17 +0000410 }
411}
412
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000413static bool stop_ring(struct intel_engine_cs *engine)
Chris Wilson9991ae72014-04-02 16:36:07 +0100414{
Chris Wilsonc0336662016-05-06 15:40:21 +0100415 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson9991ae72014-04-02 16:36:07 +0100416
Chris Wilson21a2c582016-08-15 10:49:11 +0100417 if (INTEL_GEN(dev_priv) > 2) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000418 I915_WRITE_MODE(engine, _MASKED_BIT_ENABLE(STOP_RING));
Chris Wilson3d808eb2016-06-30 15:33:30 +0100419 if (intel_wait_for_register(dev_priv,
420 RING_MI_MODE(engine->mmio_base),
421 MODE_IDLE,
422 MODE_IDLE,
423 1000)) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000424 DRM_ERROR("%s : timed out trying to stop ring\n",
425 engine->name);
Chris Wilson9bec9b12014-08-11 09:21:35 +0100426 /* Sometimes we observe that the idle flag is not
427 * set even though the ring is empty. So double
428 * check before giving up.
429 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000430 if (I915_READ_HEAD(engine) != I915_READ_TAIL(engine))
Chris Wilson9bec9b12014-08-11 09:21:35 +0100431 return false;
Chris Wilson9991ae72014-04-02 16:36:07 +0100432 }
433 }
434
Chris Wilson11caf552017-10-27 10:43:11 +0100435 I915_WRITE_HEAD(engine, I915_READ_TAIL(engine));
436
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000437 I915_WRITE_HEAD(engine, 0);
Chris Wilsonc5efa1a2016-08-02 22:50:29 +0100438 I915_WRITE_TAIL(engine, 0);
Chris Wilson9991ae72014-04-02 16:36:07 +0100439
Chris Wilson11caf552017-10-27 10:43:11 +0100440 /* The ring must be empty before it is disabled */
441 I915_WRITE_CTL(engine, 0);
442
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000443 return (I915_READ_HEAD(engine) & HEAD_ADDR) == 0;
Chris Wilson9991ae72014-04-02 16:36:07 +0100444}
445
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000446static int init_ring_common(struct intel_engine_cs *engine)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800447{
Chris Wilsonc0336662016-05-06 15:40:21 +0100448 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson7e37f882016-08-02 22:50:21 +0100449 struct intel_ring *ring = engine->buffer;
Daniel Vetterb7884eb2012-06-04 11:18:15 +0200450 int ret = 0;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800451
Mika Kuoppala59bad942015-01-16 11:34:40 +0200452 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
Daniel Vetterb7884eb2012-06-04 11:18:15 +0200453
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000454 if (!stop_ring(engine)) {
Chris Wilson9991ae72014-04-02 16:36:07 +0100455 /* G45 ring initialization often fails to reset head to zero */
Chris Wilson8177e112018-02-07 11:15:45 +0000456 DRM_DEBUG_DRIVER("%s head not reset to zero "
457 "ctl %08x head %08x tail %08x start %08x\n",
458 engine->name,
459 I915_READ_CTL(engine),
460 I915_READ_HEAD(engine),
461 I915_READ_TAIL(engine),
462 I915_READ_START(engine));
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800463
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000464 if (!stop_ring(engine)) {
Chris Wilson6fd0d562010-12-05 20:42:33 +0000465 DRM_ERROR("failed to set %s head to zero "
466 "ctl %08x head %08x tail %08x start %08x\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000467 engine->name,
468 I915_READ_CTL(engine),
469 I915_READ_HEAD(engine),
470 I915_READ_TAIL(engine),
471 I915_READ_START(engine));
Chris Wilson9991ae72014-04-02 16:36:07 +0100472 ret = -EIO;
473 goto out;
Chris Wilson6fd0d562010-12-05 20:42:33 +0000474 }
Eric Anholt62fdfea2010-05-21 13:26:39 -0700475 }
476
Carlos Santa31776592016-08-17 12:30:56 -0700477 if (HWS_NEEDS_PHYSICAL(dev_priv))
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000478 ring_setup_phys_status_page(engine);
Carlos Santa31776592016-08-17 12:30:56 -0700479 else
480 intel_ring_setup_status_page(engine);
Chris Wilson9991ae72014-04-02 16:36:07 +0100481
Chris Wilsonad07dfc2016-10-07 07:53:26 +0100482 intel_engine_reset_breadcrumbs(engine);
Chris Wilson821ed7d2016-09-09 14:11:53 +0100483
Jiri Kosinaece4a172014-08-07 16:29:53 +0200484 /* Enforce ordering by reading HEAD register back */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000485 I915_READ_HEAD(engine);
Jiri Kosinaece4a172014-08-07 16:29:53 +0200486
Daniel Vetter0d8957c2012-08-07 09:54:14 +0200487 /* Initialize the ring. This must happen _after_ we've cleared the ring
488 * registers with the above sequence (the readback of the HEAD registers
489 * also enforces ordering), otherwise the hw might lose the new ring
490 * register values. */
Chris Wilsonbde13eb2016-08-15 10:49:07 +0100491 I915_WRITE_START(engine, i915_ggtt_offset(ring->vma));
Chris Wilson95468892014-08-07 15:39:54 +0100492
493 /* WaClearRingBufHeadRegAtInit:ctg,elk */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000494 if (I915_READ_HEAD(engine))
Chris Wilson8177e112018-02-07 11:15:45 +0000495 DRM_DEBUG_DRIVER("%s initialization failed [head=%08x], fudging\n",
496 engine->name, I915_READ_HEAD(engine));
Chris Wilson821ed7d2016-09-09 14:11:53 +0100497
498 intel_ring_update_space(ring);
499 I915_WRITE_HEAD(engine, ring->head);
500 I915_WRITE_TAIL(engine, ring->tail);
501 (void)I915_READ_TAIL(engine);
Chris Wilson95468892014-08-07 15:39:54 +0100502
Chris Wilson62ae14b2016-10-04 21:11:25 +0100503 I915_WRITE_CTL(engine, RING_CTL_SIZE(ring->size) | RING_VALID);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800504
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800505 /* If the head is still not zero, the ring is dead */
Chris Wilsonf42bb652017-04-11 11:13:40 +0100506 if (intel_wait_for_register(dev_priv, RING_CTL(engine->mmio_base),
507 RING_VALID, RING_VALID,
508 50)) {
Chris Wilsone74cfed2010-11-09 10:16:56 +0000509 DRM_ERROR("%s initialization failed "
Chris Wilson821ed7d2016-09-09 14:11:53 +0100510 "ctl %08x (valid? %d) head %08x [%08x] tail %08x [%08x] start %08x [expected %08x]\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000511 engine->name,
512 I915_READ_CTL(engine),
513 I915_READ_CTL(engine) & RING_VALID,
Chris Wilson821ed7d2016-09-09 14:11:53 +0100514 I915_READ_HEAD(engine), ring->head,
515 I915_READ_TAIL(engine), ring->tail,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000516 I915_READ_START(engine),
Chris Wilsonbde13eb2016-08-15 10:49:07 +0100517 i915_ggtt_offset(ring->vma));
Daniel Vetterb7884eb2012-06-04 11:18:15 +0200518 ret = -EIO;
519 goto out;
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800520 }
521
Tomas Elffc0768c2016-03-21 16:26:59 +0000522 intel_engine_init_hangcheck(engine);
Chris Wilson50f018d2013-06-10 11:20:19 +0100523
Chris Wilson7836cd02017-10-13 14:12:17 +0100524 if (INTEL_GEN(dev_priv) > 2)
525 I915_WRITE_MODE(engine, _MASKED_BIT_DISABLE(STOP_RING));
526
Daniel Vetterb7884eb2012-06-04 11:18:15 +0200527out:
Mika Kuoppala59bad942015-01-16 11:34:40 +0200528 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Daniel Vetterb7884eb2012-06-04 11:18:15 +0200529
530 return ret;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700531}
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800532
Chris Wilson821ed7d2016-09-09 14:11:53 +0100533static void reset_ring_common(struct intel_engine_cs *engine,
Chris Wilsone61e0f52018-02-21 09:56:36 +0000534 struct i915_request *request)
Chris Wilson821ed7d2016-09-09 14:11:53 +0100535{
Chris Wilson67e64562017-10-09 12:03:01 +0100536 /*
537 * RC6 must be prevented until the reset is complete and the engine
538 * reinitialised. If it occurs in the middle of this sequence, the
539 * state written to/loaded from the power context is ill-defined (e.g.
540 * the PP_BASE_DIR may be lost).
541 */
542 assert_forcewakes_active(engine->i915, FORCEWAKE_ALL);
543
544 /*
545 * Try to restore the logical GPU state to match the continuation
Chris Wilsonc0dcb202017-02-07 15:24:37 +0000546 * of the request queue. If we skip the context/PD restore, then
547 * the next request may try to execute assuming that its context
548 * is valid and loaded on the GPU and so may try to access invalid
549 * memory, prompting repeated GPU hangs.
550 *
551 * If the request was guilty, we still restore the logical state
552 * in case the next request requires it (e.g. the aliasing ppgtt),
553 * but skip over the hung batch.
554 *
555 * If the request was innocent, we try to replay the request with
556 * the restored context.
557 */
558 if (request) {
559 struct drm_i915_private *dev_priv = request->i915;
560 struct intel_context *ce = &request->ctx->engine[engine->id];
561 struct i915_hw_ppgtt *ppgtt;
Chris Wilson821ed7d2016-09-09 14:11:53 +0100562
Chris Wilsonc0dcb202017-02-07 15:24:37 +0000563 if (ce->state) {
564 I915_WRITE(CCID,
565 i915_ggtt_offset(ce->state) |
566 BIT(8) /* must be set! */ |
567 CCID_EXTENDED_STATE_SAVE |
568 CCID_EXTENDED_STATE_RESTORE |
569 CCID_EN);
570 }
571
572 ppgtt = request->ctx->ppgtt ?: engine->i915->mm.aliasing_ppgtt;
573 if (ppgtt) {
574 u32 pd_offset = ppgtt->pd.base.ggtt_offset << 10;
575
576 I915_WRITE(RING_PP_DIR_DCLV(engine), PP_DIR_DCLV_2G);
577 I915_WRITE(RING_PP_DIR_BASE(engine), pd_offset);
578
579 /* Wait for the PD reload to complete */
580 if (intel_wait_for_register(dev_priv,
581 RING_PP_DIR_BASE(engine),
582 BIT(0), 0,
583 10))
584 DRM_ERROR("Wait for reload of ppgtt page-directory timed out\n");
585
586 ppgtt->pd_dirty_rings &= ~intel_engine_flag(engine);
587 }
588
589 /* If the rq hung, jump to its breadcrumb and skip the batch */
Chris Wilsonfe085f12017-03-21 10:25:52 +0000590 if (request->fence.error == -EIO)
591 request->ring->head = request->postfix;
Chris Wilsonc0dcb202017-02-07 15:24:37 +0000592 } else {
593 engine->legacy_active_context = NULL;
Chris Wilsonb1c24a62017-11-23 15:26:30 +0000594 engine->legacy_active_ppgtt = NULL;
Chris Wilsonc0dcb202017-02-07 15:24:37 +0000595 }
Chris Wilson821ed7d2016-09-09 14:11:53 +0100596}
597
Chris Wilsone61e0f52018-02-21 09:56:36 +0000598static int intel_rcs_ctx_init(struct i915_request *rq)
Daniel Vetter8f0e2b92014-12-02 16:19:07 +0100599{
600 int ret;
601
Chris Wilsone61e0f52018-02-21 09:56:36 +0000602 ret = intel_ring_workarounds_emit(rq);
Daniel Vetter8f0e2b92014-12-02 16:19:07 +0100603 if (ret != 0)
604 return ret;
605
Chris Wilsone61e0f52018-02-21 09:56:36 +0000606 ret = i915_gem_render_state_emit(rq);
Daniel Vetter8f0e2b92014-12-02 16:19:07 +0100607 if (ret)
Chris Wilsone26e1b92016-01-29 16:49:05 +0000608 return ret;
Daniel Vetter8f0e2b92014-12-02 16:19:07 +0100609
Chris Wilsone26e1b92016-01-29 16:49:05 +0000610 return 0;
Daniel Vetter8f0e2b92014-12-02 16:19:07 +0100611}
612
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000613static int init_render_ring(struct intel_engine_cs *engine)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800614{
Chris Wilsonc0336662016-05-06 15:40:21 +0100615 struct drm_i915_private *dev_priv = engine->i915;
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000616 int ret = init_ring_common(engine);
Konrad Zapalowicz9c33baa2014-06-19 19:07:15 +0200617 if (ret)
618 return ret;
Zhenyu Wanga69ffdb2010-08-30 16:12:42 +0800619
Akash Goel61a563a2014-03-25 18:01:50 +0530620 /* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */
Tvrtko Ursulinac657f62016-05-10 10:57:08 +0100621 if (IS_GEN(dev_priv, 4, 6))
Daniel Vetter6b26c862012-04-24 14:04:12 +0200622 I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH));
Chris Wilson1c8c38c2013-01-20 16:11:20 +0000623
624 /* We need to disable the AsyncFlip performance optimisations in order
625 * to use MI_WAIT_FOR_EVENT within the CS. It should already be
626 * programmed to '1' on all products.
Damien Lespiau8693a822013-05-03 18:48:11 +0100627 *
Ville Syrjälä2441f872015-06-02 15:37:37 +0300628 * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv
Chris Wilson1c8c38c2013-01-20 16:11:20 +0000629 */
Tvrtko Ursulinac657f62016-05-10 10:57:08 +0100630 if (IS_GEN(dev_priv, 6, 7))
Chris Wilson1c8c38c2013-01-20 16:11:20 +0000631 I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(ASYNC_FLIP_PERF_DISABLE));
632
Chris Wilsonf05bb0c2013-01-20 16:33:32 +0000633 /* Required for the hardware to program scanline values for waiting */
Akash Goel01fa0302014-03-24 23:00:04 +0530634 /* WaEnableFlushTlbInvalidationMode:snb */
Chris Wilsonc0336662016-05-06 15:40:21 +0100635 if (IS_GEN6(dev_priv))
Chris Wilsonf05bb0c2013-01-20 16:33:32 +0000636 I915_WRITE(GFX_MODE,
Chris Wilsonaa83e302014-03-21 17:18:54 +0000637 _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT));
Chris Wilsonf05bb0c2013-01-20 16:33:32 +0000638
Akash Goel01fa0302014-03-24 23:00:04 +0530639 /* WaBCSVCSTlbInvalidationMode:ivb,vlv,hsw */
Chris Wilsonc0336662016-05-06 15:40:21 +0100640 if (IS_GEN7(dev_priv))
Chris Wilson1c8c38c2013-01-20 16:11:20 +0000641 I915_WRITE(GFX_MODE_GEN7,
Akash Goel01fa0302014-03-24 23:00:04 +0530642 _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT) |
Chris Wilson1c8c38c2013-01-20 16:11:20 +0000643 _MASKED_BIT_ENABLE(GFX_REPLAY_MODE));
Chris Wilson78501ea2010-10-27 12:18:21 +0100644
Chris Wilsonc0336662016-05-06 15:40:21 +0100645 if (IS_GEN6(dev_priv)) {
Kenneth Graunke3a69ddd2012-04-27 12:44:41 -0700646 /* From the Sandybridge PRM, volume 1 part 3, page 24:
647 * "If this bit is set, STCunit will have LRA as replacement
648 * policy. [...] This bit must be reset. LRA replacement
649 * policy is not supported."
650 */
651 I915_WRITE(CACHE_MODE_0,
Daniel Vetter5e13a0c2012-05-08 13:39:59 +0200652 _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB));
Ben Widawsky84f9f932011-12-12 19:21:58 -0800653 }
654
Tvrtko Ursulinac657f62016-05-10 10:57:08 +0100655 if (IS_GEN(dev_priv, 6, 7))
Daniel Vetter6b26c862012-04-24 14:04:12 +0200656 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_FORCE_ORDERING));
Chris Wilsonc6df5412010-12-15 09:56:50 +0000657
Tvrtko Ursulinc56b89f2018-02-09 21:58:46 +0000658 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä035ea402016-07-12 19:24:47 +0300659 I915_WRITE_IMR(engine, ~engine->irq_keep_mask);
Ben Widawsky15b9f802012-05-25 16:56:23 -0700660
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000661 return init_workarounds_ring(engine);
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800662}
663
Chris Wilsone61e0f52018-02-21 09:56:36 +0000664static u32 *gen6_signal(struct i915_request *rq, u32 *cs)
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000665{
Chris Wilsone61e0f52018-02-21 09:56:36 +0000666 struct drm_i915_private *dev_priv = rq->i915;
Tvrtko Ursulin318f89c2016-08-16 17:04:21 +0100667 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530668 enum intel_engine_id id;
Chris Wilsoncaddfe72016-10-28 13:58:52 +0100669 int num_rings = 0;
Ben Widawsky024a43e2014-04-29 14:52:30 -0700670
Akash Goel3b3f1652016-10-13 22:44:48 +0530671 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursulin318f89c2016-08-16 17:04:21 +0100672 i915_reg_t mbox_reg;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200673
Tvrtko Ursulin318f89c2016-08-16 17:04:21 +0100674 if (!(BIT(engine->hw_id) & GEN6_SEMAPHORES_MASK))
675 continue;
676
Chris Wilsone61e0f52018-02-21 09:56:36 +0000677 mbox_reg = rq->engine->semaphore.mbox.signal[engine->hw_id];
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200678 if (i915_mmio_reg_valid(mbox_reg)) {
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000679 *cs++ = MI_LOAD_REGISTER_IMM(1);
680 *cs++ = i915_mmio_reg_offset(mbox_reg);
Chris Wilsone61e0f52018-02-21 09:56:36 +0000681 *cs++ = rq->global_seqno;
Chris Wilsoncaddfe72016-10-28 13:58:52 +0100682 num_rings++;
Ben Widawsky78325f22014-04-29 14:52:29 -0700683 }
684 }
Chris Wilsoncaddfe72016-10-28 13:58:52 +0100685 if (num_rings & 1)
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000686 *cs++ = MI_NOOP;
Ben Widawsky024a43e2014-04-29 14:52:30 -0700687
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000688 return cs;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000689}
690
Chris Wilson27a5f612017-09-15 18:31:00 +0100691static void cancel_requests(struct intel_engine_cs *engine)
692{
Chris Wilsone61e0f52018-02-21 09:56:36 +0000693 struct i915_request *request;
Chris Wilson27a5f612017-09-15 18:31:00 +0100694 unsigned long flags;
695
696 spin_lock_irqsave(&engine->timeline->lock, flags);
697
698 /* Mark all submitted requests as skipped. */
699 list_for_each_entry(request, &engine->timeline->requests, link) {
700 GEM_BUG_ON(!request->global_seqno);
Chris Wilsone61e0f52018-02-21 09:56:36 +0000701 if (!i915_request_completed(request))
Chris Wilson27a5f612017-09-15 18:31:00 +0100702 dma_fence_set_error(&request->fence, -EIO);
703 }
704 /* Remaining _unready_ requests will be nop'ed when submitted */
705
706 spin_unlock_irqrestore(&engine->timeline->lock, flags);
707}
708
Chris Wilsone61e0f52018-02-21 09:56:36 +0000709static void i9xx_submit_request(struct i915_request *request)
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000710{
Chris Wilsonb0411e72016-08-02 22:50:34 +0100711 struct drm_i915_private *dev_priv = request->i915;
712
Chris Wilsone61e0f52018-02-21 09:56:36 +0000713 i915_request_submit(request);
Chris Wilsond55ac5b2016-11-14 20:40:59 +0000714
Chris Wilsone6ba9992017-04-25 14:00:49 +0100715 I915_WRITE_TAIL(request->engine,
716 intel_ring_set_tail(request->ring, request->tail));
Chris Wilsonb0411e72016-08-02 22:50:34 +0100717}
718
Chris Wilsone61e0f52018-02-21 09:56:36 +0000719static void i9xx_emit_breadcrumb(struct i915_request *rq, u32 *cs)
Chris Wilsonb0411e72016-08-02 22:50:34 +0100720{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000721 *cs++ = MI_STORE_DWORD_INDEX;
722 *cs++ = I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000723 *cs++ = rq->global_seqno;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000724 *cs++ = MI_USER_INTERRUPT;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000725
Chris Wilsone61e0f52018-02-21 09:56:36 +0000726 rq->tail = intel_ring_offset(rq, cs);
727 assert_ring_tail_valid(rq->ring, rq->tail);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000728}
729
Chris Wilson98f29e82016-10-28 13:58:51 +0100730static const int i9xx_emit_breadcrumb_sz = 4;
731
Chris Wilsone61e0f52018-02-21 09:56:36 +0000732static void gen6_sema_emit_breadcrumb(struct i915_request *rq, u32 *cs)
Chris Wilsonb0411e72016-08-02 22:50:34 +0100733{
Chris Wilsone61e0f52018-02-21 09:56:36 +0000734 return i9xx_emit_breadcrumb(rq, rq->engine->semaphore.signal(rq, cs));
Chris Wilsonb0411e72016-08-02 22:50:34 +0100735}
736
Ben Widawskyc8c99b02011-09-14 20:32:47 -0700737static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000738gen6_ring_sync_to(struct i915_request *rq, struct i915_request *signal)
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000739{
Ben Widawskyc8c99b02011-09-14 20:32:47 -0700740 u32 dw1 = MI_SEMAPHORE_MBOX |
741 MI_SEMAPHORE_COMPARE |
742 MI_SEMAPHORE_REGISTER;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000743 u32 wait_mbox = signal->engine->semaphore.mbox.wait[rq->engine->hw_id];
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000744 u32 *cs;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000745
Chris Wilsonddf07be2016-08-02 22:50:39 +0100746 WARN_ON(wait_mbox == MI_SEMAPHORE_SYNC_INVALID);
747
Chris Wilsone61e0f52018-02-21 09:56:36 +0000748 cs = intel_ring_begin(rq, 4);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000749 if (IS_ERR(cs))
750 return PTR_ERR(cs);
Chris Wilsonddf07be2016-08-02 22:50:39 +0100751
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000752 *cs++ = dw1 | wait_mbox;
Ben Widawsky1500f7e2012-04-11 11:18:21 -0700753 /* Throughout all of the GEM code, seqno passed implies our current
754 * seqno is >= the last seqno executed. However for hardware the
755 * comparison is strictly greater than.
756 */
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000757 *cs++ = signal->global_seqno - 1;
758 *cs++ = 0;
759 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000760 intel_ring_advance(rq, cs);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000761
762 return 0;
763}
764
Chris Wilsonf8973c22016-07-01 17:23:21 +0100765static void
Dave Gordon38a0f2d2016-07-20 18:16:06 +0100766gen5_seqno_barrier(struct intel_engine_cs *engine)
Chris Wilsonc6df5412010-12-15 09:56:50 +0000767{
Chris Wilsonf8973c22016-07-01 17:23:21 +0100768 /* MI_STORE are internally buffered by the GPU and not flushed
769 * either by MI_FLUSH or SyncFlush or any other combination of
770 * MI commands.
Chris Wilsonc6df5412010-12-15 09:56:50 +0000771 *
Chris Wilsonf8973c22016-07-01 17:23:21 +0100772 * "Only the submission of the store operation is guaranteed.
773 * The write result will be complete (coherent) some time later
774 * (this is practically a finite period but there is no guaranteed
775 * latency)."
776 *
777 * Empirically, we observe that we need a delay of at least 75us to
778 * be sure that the seqno write is visible by the CPU.
Chris Wilsonc6df5412010-12-15 09:56:50 +0000779 */
Chris Wilsonf8973c22016-07-01 17:23:21 +0100780 usleep_range(125, 250);
Chris Wilsonc6df5412010-12-15 09:56:50 +0000781}
782
Chris Wilsonc04e0f32016-04-09 10:57:54 +0100783static void
784gen6_seqno_barrier(struct intel_engine_cs *engine)
Daniel Vetter4cd53c02012-12-14 16:01:25 +0100785{
Chris Wilsonc0336662016-05-06 15:40:21 +0100786 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilsonbcbdb6d2016-04-27 09:02:01 +0100787
Daniel Vetter4cd53c02012-12-14 16:01:25 +0100788 /* Workaround to force correct ordering between irq and seqno writes on
789 * ivb (and maybe also on snb) by reading from a CS register (like
Chris Wilson9b9ed302016-04-09 10:57:53 +0100790 * ACTHD) before reading the status page.
791 *
792 * Note that this effectively stalls the read by the time it takes to
793 * do a memory transaction, which more or less ensures that the write
794 * from the GPU has sufficient time to invalidate the CPU cacheline.
795 * Alternatively we could delay the interrupt from the CS ring to give
796 * the write time to land, but that would incur a delay after every
797 * batch i.e. much more frequent than a delay when waiting for the
798 * interrupt (with the same net latency).
Chris Wilsonbcbdb6d2016-04-27 09:02:01 +0100799 *
800 * Also note that to prevent whole machine hangs on gen7, we have to
801 * take the spinlock to guard against concurrent cacheline access.
Chris Wilson9b9ed302016-04-09 10:57:53 +0100802 */
Chris Wilsonbcbdb6d2016-04-27 09:02:01 +0100803 spin_lock_irq(&dev_priv->uncore.lock);
Chris Wilsonc04e0f32016-04-09 10:57:54 +0100804 POSTING_READ_FW(RING_ACTHD(engine->mmio_base));
Chris Wilsonbcbdb6d2016-04-27 09:02:01 +0100805 spin_unlock_irq(&dev_priv->uncore.lock);
Daniel Vetter4cd53c02012-12-14 16:01:25 +0100806}
807
Chris Wilson31bb59c2016-07-01 17:23:27 +0100808static void
809gen5_irq_enable(struct intel_engine_cs *engine)
Daniel Vettere48d8632012-04-11 22:12:54 +0200810{
Chris Wilson31bb59c2016-07-01 17:23:27 +0100811 gen5_enable_gt_irq(engine->i915, engine->irq_enable_mask);
Daniel Vettere48d8632012-04-11 22:12:54 +0200812}
813
814static void
Chris Wilson31bb59c2016-07-01 17:23:27 +0100815gen5_irq_disable(struct intel_engine_cs *engine)
Daniel Vettere48d8632012-04-11 22:12:54 +0200816{
Chris Wilson31bb59c2016-07-01 17:23:27 +0100817 gen5_disable_gt_irq(engine->i915, engine->irq_enable_mask);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700818}
819
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800820static void
Chris Wilson31bb59c2016-07-01 17:23:27 +0100821i9xx_irq_enable(struct intel_engine_cs *engine)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700822{
Chris Wilsonc0336662016-05-06 15:40:21 +0100823 struct drm_i915_private *dev_priv = engine->i915;
Eric Anholt62fdfea2010-05-21 13:26:39 -0700824
Chris Wilson31bb59c2016-07-01 17:23:27 +0100825 dev_priv->irq_mask &= ~engine->irq_enable_mask;
826 I915_WRITE(IMR, dev_priv->irq_mask);
827 POSTING_READ_FW(RING_IMR(engine->mmio_base));
Chris Wilsonc2798b12012-04-22 21:13:57 +0100828}
829
830static void
Chris Wilson31bb59c2016-07-01 17:23:27 +0100831i9xx_irq_disable(struct intel_engine_cs *engine)
Chris Wilsonc2798b12012-04-22 21:13:57 +0100832{
Chris Wilsonc0336662016-05-06 15:40:21 +0100833 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilsonc2798b12012-04-22 21:13:57 +0100834
Chris Wilson31bb59c2016-07-01 17:23:27 +0100835 dev_priv->irq_mask |= engine->irq_enable_mask;
836 I915_WRITE(IMR, dev_priv->irq_mask);
837}
838
839static void
840i8xx_irq_enable(struct intel_engine_cs *engine)
841{
842 struct drm_i915_private *dev_priv = engine->i915;
843
844 dev_priv->irq_mask &= ~engine->irq_enable_mask;
845 I915_WRITE16(IMR, dev_priv->irq_mask);
846 POSTING_READ16(RING_IMR(engine->mmio_base));
847}
848
849static void
850i8xx_irq_disable(struct intel_engine_cs *engine)
851{
852 struct drm_i915_private *dev_priv = engine->i915;
853
854 dev_priv->irq_mask |= engine->irq_enable_mask;
855 I915_WRITE16(IMR, dev_priv->irq_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +0100856}
857
Chris Wilsonb72f3ac2011-01-04 17:34:02 +0000858static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000859bsd_ring_flush(struct i915_request *rq, u32 mode)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800860{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000861 u32 *cs;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000862
Chris Wilsone61e0f52018-02-21 09:56:36 +0000863 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000864 if (IS_ERR(cs))
865 return PTR_ERR(cs);
Chris Wilsonb72f3ac2011-01-04 17:34:02 +0000866
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000867 *cs++ = MI_FLUSH;
868 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000869 intel_ring_advance(rq, cs);
Chris Wilsonb72f3ac2011-01-04 17:34:02 +0000870 return 0;
Zou Nan haid1b851f2010-05-21 09:08:57 +0800871}
872
Chris Wilson0f468322011-01-04 17:35:21 +0000873static void
Chris Wilson31bb59c2016-07-01 17:23:27 +0100874gen6_irq_enable(struct intel_engine_cs *engine)
Chris Wilson0f468322011-01-04 17:35:21 +0000875{
Chris Wilsonc0336662016-05-06 15:40:21 +0100876 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson0f468322011-01-04 17:35:21 +0000877
Chris Wilson61ff75a2016-07-01 17:23:28 +0100878 I915_WRITE_IMR(engine,
879 ~(engine->irq_enable_mask |
880 engine->irq_keep_mask));
Chris Wilson31bb59c2016-07-01 17:23:27 +0100881 gen5_enable_gt_irq(dev_priv, engine->irq_enable_mask);
Ben Widawskya19d2932013-05-28 19:22:30 -0700882}
883
884static void
Chris Wilson31bb59c2016-07-01 17:23:27 +0100885gen6_irq_disable(struct intel_engine_cs *engine)
Ben Widawskya19d2932013-05-28 19:22:30 -0700886{
Chris Wilsonc0336662016-05-06 15:40:21 +0100887 struct drm_i915_private *dev_priv = engine->i915;
Ben Widawskya19d2932013-05-28 19:22:30 -0700888
Chris Wilson61ff75a2016-07-01 17:23:28 +0100889 I915_WRITE_IMR(engine, ~engine->irq_keep_mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100890 gen5_disable_gt_irq(dev_priv, engine->irq_enable_mask);
Ben Widawskyabd58f02013-11-02 21:07:09 -0700891}
892
893static void
Chris Wilson31bb59c2016-07-01 17:23:27 +0100894hsw_vebox_irq_enable(struct intel_engine_cs *engine)
Ben Widawskyabd58f02013-11-02 21:07:09 -0700895{
Chris Wilsonc0336662016-05-06 15:40:21 +0100896 struct drm_i915_private *dev_priv = engine->i915;
Ben Widawskyabd58f02013-11-02 21:07:09 -0700897
Chris Wilson31bb59c2016-07-01 17:23:27 +0100898 I915_WRITE_IMR(engine, ~engine->irq_enable_mask);
Akash Goelf4e9af42016-10-12 21:54:30 +0530899 gen6_unmask_pm_irq(dev_priv, engine->irq_enable_mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100900}
901
902static void
903hsw_vebox_irq_disable(struct intel_engine_cs *engine)
904{
905 struct drm_i915_private *dev_priv = engine->i915;
906
907 I915_WRITE_IMR(engine, ~0);
Akash Goelf4e9af42016-10-12 21:54:30 +0530908 gen6_mask_pm_irq(dev_priv, engine->irq_enable_mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100909}
910
Zou Nan haid1b851f2010-05-21 09:08:57 +0800911static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000912i965_emit_bb_start(struct i915_request *rq,
Chris Wilson803688b2016-08-02 22:50:27 +0100913 u64 offset, u32 length,
914 unsigned int dispatch_flags)
Zou Nan haid1b851f2010-05-21 09:08:57 +0800915{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000916 u32 *cs;
Chris Wilson78501ea2010-10-27 12:18:21 +0100917
Chris Wilsone61e0f52018-02-21 09:56:36 +0000918 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000919 if (IS_ERR(cs))
920 return PTR_ERR(cs);
Chris Wilsone1f99ce2010-10-27 12:45:26 +0100921
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000922 *cs++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT | (dispatch_flags &
923 I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE_I965);
924 *cs++ = offset;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000925 intel_ring_advance(rq, cs);
Chris Wilson78501ea2010-10-27 12:18:21 +0100926
Zou Nan haid1b851f2010-05-21 09:08:57 +0800927 return 0;
928}
929
Daniel Vetterb45305f2012-12-17 16:21:27 +0100930/* Just userspace ABI convention to limit the wa batch bo to a resonable size */
931#define I830_BATCH_LIMIT (256*1024)
Chris Wilsonc4d69da2014-09-08 14:25:41 +0100932#define I830_TLB_ENTRIES (2)
933#define I830_WA_SIZE max(I830_TLB_ENTRIES*4096, I830_BATCH_LIMIT)
Zou Nan hai8187a2b2010-05-21 09:08:55 +0800934static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000935i830_emit_bb_start(struct i915_request *rq,
Chris Wilson803688b2016-08-02 22:50:27 +0100936 u64 offset, u32 len,
937 unsigned int dispatch_flags)
Eric Anholt62fdfea2010-05-21 13:26:39 -0700938{
Chris Wilsone61e0f52018-02-21 09:56:36 +0000939 u32 *cs, cs_offset = i915_ggtt_offset(rq->engine->scratch);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700940
Chris Wilsone61e0f52018-02-21 09:56:36 +0000941 cs = intel_ring_begin(rq, 6);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000942 if (IS_ERR(cs))
943 return PTR_ERR(cs);
Eric Anholt62fdfea2010-05-21 13:26:39 -0700944
Chris Wilsonc4d69da2014-09-08 14:25:41 +0100945 /* Evict the invalid PTE TLBs */
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000946 *cs++ = COLOR_BLT_CMD | BLT_WRITE_RGBA;
947 *cs++ = BLT_DEPTH_32 | BLT_ROP_COLOR_COPY | 4096;
948 *cs++ = I830_TLB_ENTRIES << 16 | 4; /* load each page */
949 *cs++ = cs_offset;
950 *cs++ = 0xdeadbeef;
951 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000952 intel_ring_advance(rq, cs);
Daniel Vetterb45305f2012-12-17 16:21:27 +0100953
John Harrison8e004ef2015-02-13 11:48:10 +0000954 if ((dispatch_flags & I915_DISPATCH_PINNED) == 0) {
Daniel Vetterb45305f2012-12-17 16:21:27 +0100955 if (len > I830_BATCH_LIMIT)
956 return -ENOSPC;
957
Chris Wilsone61e0f52018-02-21 09:56:36 +0000958 cs = intel_ring_begin(rq, 6 + 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000959 if (IS_ERR(cs))
960 return PTR_ERR(cs);
Chris Wilsonc4d69da2014-09-08 14:25:41 +0100961
962 /* Blit the batch (which has now all relocs applied) to the
963 * stable batch scratch bo area (so that the CS never
964 * stumbles over its tlb invalidation bug) ...
965 */
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000966 *cs++ = SRC_COPY_BLT_CMD | BLT_WRITE_RGBA;
967 *cs++ = BLT_DEPTH_32 | BLT_ROP_SRC_COPY | 4096;
968 *cs++ = DIV_ROUND_UP(len, 4096) << 16 | 4096;
969 *cs++ = cs_offset;
970 *cs++ = 4096;
971 *cs++ = offset;
Chris Wilsonc4d69da2014-09-08 14:25:41 +0100972
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000973 *cs++ = MI_FLUSH;
974 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +0000975 intel_ring_advance(rq, cs);
Daniel Vetterb45305f2012-12-17 16:21:27 +0100976
977 /* ... and execute it. */
Chris Wilsonc4d69da2014-09-08 14:25:41 +0100978 offset = cs_offset;
Daniel Vetterb45305f2012-12-17 16:21:27 +0100979 }
Chris Wilsone1f99ce2010-10-27 12:45:26 +0100980
Chris Wilsone61e0f52018-02-21 09:56:36 +0000981 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000982 if (IS_ERR(cs))
983 return PTR_ERR(cs);
Chris Wilsonc4d69da2014-09-08 14:25:41 +0100984
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000985 *cs++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT;
986 *cs++ = offset | (dispatch_flags & I915_DISPATCH_SECURE ? 0 :
987 MI_BATCH_NON_SECURE);
Chris Wilsone61e0f52018-02-21 09:56:36 +0000988 intel_ring_advance(rq, cs);
Chris Wilsonc4d69da2014-09-08 14:25:41 +0100989
Daniel Vetterfb3256d2012-04-11 22:12:56 +0200990 return 0;
991}
992
993static int
Chris Wilsone61e0f52018-02-21 09:56:36 +0000994i915_emit_bb_start(struct i915_request *rq,
Chris Wilson803688b2016-08-02 22:50:27 +0100995 u64 offset, u32 len,
996 unsigned int dispatch_flags)
Daniel Vetterfb3256d2012-04-11 22:12:56 +0200997{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +0000998 u32 *cs;
Daniel Vetterfb3256d2012-04-11 22:12:56 +0200999
Chris Wilsone61e0f52018-02-21 09:56:36 +00001000 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001001 if (IS_ERR(cs))
1002 return PTR_ERR(cs);
Daniel Vetterfb3256d2012-04-11 22:12:56 +02001003
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001004 *cs++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT;
1005 *cs++ = offset | (dispatch_flags & I915_DISPATCH_SECURE ? 0 :
1006 MI_BATCH_NON_SECURE);
Chris Wilsone61e0f52018-02-21 09:56:36 +00001007 intel_ring_advance(rq, cs);
Eric Anholt62fdfea2010-05-21 13:26:39 -07001008
Eric Anholt62fdfea2010-05-21 13:26:39 -07001009 return 0;
1010}
1011
Ville Syrjälä7d3fdff2016-01-11 20:48:32 +02001012
Chris Wilson6b8294a2012-11-16 11:43:20 +00001013
Chris Wilsond822bb12017-04-03 12:34:25 +01001014int intel_ring_pin(struct intel_ring *ring,
1015 struct drm_i915_private *i915,
1016 unsigned int offset_bias)
Thomas Daniel7ba717c2014-11-13 10:28:56 +00001017{
Chris Wilsond822bb12017-04-03 12:34:25 +01001018 enum i915_map_type map = HAS_LLC(i915) ? I915_MAP_WB : I915_MAP_WC;
Chris Wilson57e88532016-08-15 10:48:57 +01001019 struct i915_vma *vma = ring->vma;
Chris Wilsond822bb12017-04-03 12:34:25 +01001020 unsigned int flags;
Dave Gordon83052162016-04-12 14:46:16 +01001021 void *addr;
Thomas Daniel7ba717c2014-11-13 10:28:56 +00001022 int ret;
1023
Chris Wilson57e88532016-08-15 10:48:57 +01001024 GEM_BUG_ON(ring->vaddr);
1025
Chris Wilson9d808412016-08-18 17:16:56 +01001026
Daniele Ceraolo Spuriod3ef1af2016-12-23 15:56:21 -08001027 flags = PIN_GLOBAL;
1028 if (offset_bias)
1029 flags |= PIN_OFFSET_BIAS | offset_bias;
Chris Wilson9d808412016-08-18 17:16:56 +01001030 if (vma->obj->stolen)
Chris Wilson57e88532016-08-15 10:48:57 +01001031 flags |= PIN_MAPPABLE;
1032
1033 if (!(vma->flags & I915_VMA_GLOBAL_BIND)) {
Chris Wilson9d808412016-08-18 17:16:56 +01001034 if (flags & PIN_MAPPABLE || map == I915_MAP_WC)
Chris Wilson57e88532016-08-15 10:48:57 +01001035 ret = i915_gem_object_set_to_gtt_domain(vma->obj, true);
1036 else
1037 ret = i915_gem_object_set_to_cpu_domain(vma->obj, true);
1038 if (unlikely(ret))
Chris Wilsondef0c5f2015-10-08 13:39:54 +01001039 return ret;
Thomas Daniel7ba717c2014-11-13 10:28:56 +00001040 }
1041
Chris Wilson57e88532016-08-15 10:48:57 +01001042 ret = i915_vma_pin(vma, 0, PAGE_SIZE, flags);
1043 if (unlikely(ret))
1044 return ret;
1045
Chris Wilson9d808412016-08-18 17:16:56 +01001046 if (i915_vma_is_map_and_fenceable(vma))
Chris Wilson57e88532016-08-15 10:48:57 +01001047 addr = (void __force *)i915_vma_pin_iomap(vma);
1048 else
Chris Wilson9d808412016-08-18 17:16:56 +01001049 addr = i915_gem_object_pin_map(vma->obj, map);
Chris Wilson57e88532016-08-15 10:48:57 +01001050 if (IS_ERR(addr))
1051 goto err;
1052
Chris Wilson3d574a62017-10-13 21:26:16 +01001053 vma->obj->pin_global++;
1054
Chris Wilson32c04f12016-08-02 22:50:22 +01001055 ring->vaddr = addr;
Thomas Daniel7ba717c2014-11-13 10:28:56 +00001056 return 0;
Chris Wilsond2cad532016-04-08 12:11:10 +01001057
Chris Wilson57e88532016-08-15 10:48:57 +01001058err:
1059 i915_vma_unpin(vma);
1060 return PTR_ERR(addr);
Thomas Daniel7ba717c2014-11-13 10:28:56 +00001061}
1062
Chris Wilsone6ba9992017-04-25 14:00:49 +01001063void intel_ring_reset(struct intel_ring *ring, u32 tail)
1064{
1065 GEM_BUG_ON(!list_empty(&ring->request_list));
1066 ring->tail = tail;
1067 ring->head = tail;
1068 ring->emit = tail;
1069 intel_ring_update_space(ring);
1070}
1071
Chris Wilsonaad29fb2016-08-02 22:50:23 +01001072void intel_ring_unpin(struct intel_ring *ring)
1073{
1074 GEM_BUG_ON(!ring->vma);
1075 GEM_BUG_ON(!ring->vaddr);
1076
Chris Wilsone6ba9992017-04-25 14:00:49 +01001077 /* Discard any unused bytes beyond that submitted to hw. */
1078 intel_ring_reset(ring, ring->tail);
1079
Chris Wilson9d808412016-08-18 17:16:56 +01001080 if (i915_vma_is_map_and_fenceable(ring->vma))
Chris Wilsonaad29fb2016-08-02 22:50:23 +01001081 i915_vma_unpin_iomap(ring->vma);
Chris Wilson57e88532016-08-15 10:48:57 +01001082 else
1083 i915_gem_object_unpin_map(ring->vma->obj);
Chris Wilsonaad29fb2016-08-02 22:50:23 +01001084 ring->vaddr = NULL;
1085
Chris Wilson3d574a62017-10-13 21:26:16 +01001086 ring->vma->obj->pin_global--;
Chris Wilson57e88532016-08-15 10:48:57 +01001087 i915_vma_unpin(ring->vma);
Chris Wilsonaad29fb2016-08-02 22:50:23 +01001088}
1089
Chris Wilson57e88532016-08-15 10:48:57 +01001090static struct i915_vma *
1091intel_ring_create_vma(struct drm_i915_private *dev_priv, int size)
Oscar Mateo2919d292014-07-03 16:28:02 +01001092{
Chris Wilsone3efda42014-04-09 09:19:41 +01001093 struct drm_i915_gem_object *obj;
Chris Wilson57e88532016-08-15 10:48:57 +01001094 struct i915_vma *vma;
Chris Wilsone3efda42014-04-09 09:19:41 +01001095
Tvrtko Ursulin187685c2016-12-01 14:16:36 +00001096 obj = i915_gem_object_create_stolen(dev_priv, size);
Chris Wilsonc58b7352016-08-18 17:16:57 +01001097 if (!obj)
Chris Wilson2d6c4c82017-04-20 11:17:09 +01001098 obj = i915_gem_object_create_internal(dev_priv, size);
Chris Wilson57e88532016-08-15 10:48:57 +01001099 if (IS_ERR(obj))
1100 return ERR_CAST(obj);
Chris Wilsone3efda42014-04-09 09:19:41 +01001101
Akash Goel24f3a8c2014-06-17 10:59:42 +05301102 /* mark ring buffers as read-only from GPU side by default */
1103 obj->gt_ro = 1;
1104
Chris Wilsona01cb372017-01-16 15:21:30 +00001105 vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL);
Chris Wilson57e88532016-08-15 10:48:57 +01001106 if (IS_ERR(vma))
1107 goto err;
Chris Wilsone3efda42014-04-09 09:19:41 +01001108
Chris Wilson57e88532016-08-15 10:48:57 +01001109 return vma;
1110
1111err:
1112 i915_gem_object_put(obj);
1113 return vma;
Chris Wilsone3efda42014-04-09 09:19:41 +01001114}
1115
Chris Wilson7e37f882016-08-02 22:50:21 +01001116struct intel_ring *
1117intel_engine_create_ring(struct intel_engine_cs *engine, int size)
Chris Wilson01101fa2015-09-03 13:01:39 +01001118{
Chris Wilson7e37f882016-08-02 22:50:21 +01001119 struct intel_ring *ring;
Chris Wilson57e88532016-08-15 10:48:57 +01001120 struct i915_vma *vma;
Chris Wilson01101fa2015-09-03 13:01:39 +01001121
Chris Wilson8f942012016-08-02 22:50:30 +01001122 GEM_BUG_ON(!is_power_of_2(size));
Chris Wilson62ae14b2016-10-04 21:11:25 +01001123 GEM_BUG_ON(RING_CTL_SIZE(size) & ~RING_NR_PAGES);
Chris Wilson8f942012016-08-02 22:50:30 +01001124
Chris Wilson01101fa2015-09-03 13:01:39 +01001125 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
Chris Wilson57e88532016-08-15 10:48:57 +01001126 if (!ring)
Chris Wilson01101fa2015-09-03 13:01:39 +01001127 return ERR_PTR(-ENOMEM);
1128
Chris Wilson675d9ad2016-08-04 07:52:36 +01001129 INIT_LIST_HEAD(&ring->request_list);
1130
Chris Wilson01101fa2015-09-03 13:01:39 +01001131 ring->size = size;
1132 /* Workaround an erratum on the i830 which causes a hang if
1133 * the TAIL pointer points to within the last 2 cachelines
1134 * of the buffer.
1135 */
1136 ring->effective_size = size;
Jani Nikula2a307c22016-11-30 17:43:04 +02001137 if (IS_I830(engine->i915) || IS_I845G(engine->i915))
Chris Wilson01101fa2015-09-03 13:01:39 +01001138 ring->effective_size -= 2 * CACHELINE_BYTES;
1139
Chris Wilson01101fa2015-09-03 13:01:39 +01001140 intel_ring_update_space(ring);
1141
Chris Wilson57e88532016-08-15 10:48:57 +01001142 vma = intel_ring_create_vma(engine->i915, size);
1143 if (IS_ERR(vma)) {
Chris Wilson01101fa2015-09-03 13:01:39 +01001144 kfree(ring);
Chris Wilson57e88532016-08-15 10:48:57 +01001145 return ERR_CAST(vma);
Chris Wilson01101fa2015-09-03 13:01:39 +01001146 }
Chris Wilson57e88532016-08-15 10:48:57 +01001147 ring->vma = vma;
Chris Wilson01101fa2015-09-03 13:01:39 +01001148
1149 return ring;
1150}
1151
1152void
Chris Wilson7e37f882016-08-02 22:50:21 +01001153intel_ring_free(struct intel_ring *ring)
Chris Wilson01101fa2015-09-03 13:01:39 +01001154{
Chris Wilsonf8a7fde2016-10-28 13:58:29 +01001155 struct drm_i915_gem_object *obj = ring->vma->obj;
1156
1157 i915_vma_close(ring->vma);
1158 __i915_gem_object_release_unless_active(obj);
1159
Chris Wilson01101fa2015-09-03 13:01:39 +01001160 kfree(ring);
1161}
1162
Chris Wilson72b72ae2017-02-10 10:14:22 +00001163static int context_pin(struct i915_gem_context *ctx)
Chris Wilsone8a9c582016-12-18 15:37:20 +00001164{
1165 struct i915_vma *vma = ctx->engine[RCS].state;
1166 int ret;
1167
Chris Wilsonf4e15af2017-11-10 14:26:32 +00001168 /*
1169 * Clear this page out of any CPU caches for coherent swap-in/out.
Chris Wilsone8a9c582016-12-18 15:37:20 +00001170 * We only want to do this on the first bind so that we do not stall
1171 * on an active context (which by nature is already on the GPU).
1172 */
1173 if (!(vma->flags & I915_VMA_GLOBAL_BIND)) {
Chris Wilsonf4e15af2017-11-10 14:26:32 +00001174 ret = i915_gem_object_set_to_gtt_domain(vma->obj, true);
Chris Wilsone8a9c582016-12-18 15:37:20 +00001175 if (ret)
1176 return ret;
1177 }
1178
Chris Wilsonafeddf52017-02-27 13:59:13 +00001179 return i915_vma_pin(vma, 0, I915_GTT_MIN_ALIGNMENT,
1180 PIN_GLOBAL | PIN_HIGH);
Chris Wilsone8a9c582016-12-18 15:37:20 +00001181}
1182
Chris Wilson3204c342017-04-27 11:46:51 +01001183static struct i915_vma *
1184alloc_context_vma(struct intel_engine_cs *engine)
1185{
1186 struct drm_i915_private *i915 = engine->i915;
1187 struct drm_i915_gem_object *obj;
1188 struct i915_vma *vma;
Chris Wilsond2b4b972017-11-10 14:26:33 +00001189 int err;
Chris Wilson3204c342017-04-27 11:46:51 +01001190
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +03001191 obj = i915_gem_object_create(i915, engine->context_size);
Chris Wilson3204c342017-04-27 11:46:51 +01001192 if (IS_ERR(obj))
1193 return ERR_CAST(obj);
1194
Chris Wilsond2b4b972017-11-10 14:26:33 +00001195 if (engine->default_state) {
1196 void *defaults, *vaddr;
1197
1198 vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
1199 if (IS_ERR(vaddr)) {
1200 err = PTR_ERR(vaddr);
1201 goto err_obj;
1202 }
1203
1204 defaults = i915_gem_object_pin_map(engine->default_state,
1205 I915_MAP_WB);
1206 if (IS_ERR(defaults)) {
1207 err = PTR_ERR(defaults);
1208 goto err_map;
1209 }
1210
1211 memcpy(vaddr, defaults, engine->context_size);
1212
1213 i915_gem_object_unpin_map(engine->default_state);
1214 i915_gem_object_unpin_map(obj);
1215 }
1216
Chris Wilson3204c342017-04-27 11:46:51 +01001217 /*
1218 * Try to make the context utilize L3 as well as LLC.
1219 *
1220 * On VLV we don't have L3 controls in the PTEs so we
1221 * shouldn't touch the cache level, especially as that
1222 * would make the object snooped which might have a
1223 * negative performance impact.
1224 *
1225 * Snooping is required on non-llc platforms in execlist
1226 * mode, but since all GGTT accesses use PAT entry 0 we
1227 * get snooping anyway regardless of cache_level.
1228 *
1229 * This is only applicable for Ivy Bridge devices since
1230 * later platforms don't have L3 control bits in the PTE.
1231 */
1232 if (IS_IVYBRIDGE(i915)) {
1233 /* Ignore any error, regard it as a simple optimisation */
1234 i915_gem_object_set_cache_level(obj, I915_CACHE_L3_LLC);
1235 }
1236
1237 vma = i915_vma_instance(obj, &i915->ggtt.base, NULL);
Chris Wilsond2b4b972017-11-10 14:26:33 +00001238 if (IS_ERR(vma)) {
1239 err = PTR_ERR(vma);
1240 goto err_obj;
1241 }
Chris Wilson3204c342017-04-27 11:46:51 +01001242
1243 return vma;
Chris Wilsond2b4b972017-11-10 14:26:33 +00001244
1245err_map:
1246 i915_gem_object_unpin_map(obj);
1247err_obj:
1248 i915_gem_object_put(obj);
1249 return ERR_PTR(err);
Chris Wilson3204c342017-04-27 11:46:51 +01001250}
1251
Chris Wilson266a2402017-05-04 10:33:08 +01001252static struct intel_ring *
1253intel_ring_context_pin(struct intel_engine_cs *engine,
1254 struct i915_gem_context *ctx)
Chris Wilson0cb26a82016-06-24 14:55:53 +01001255{
1256 struct intel_context *ce = &ctx->engine[engine->id];
1257 int ret;
1258
Chris Wilson91c8a322016-07-05 10:40:23 +01001259 lockdep_assert_held(&ctx->i915->drm.struct_mutex);
Chris Wilson0cb26a82016-06-24 14:55:53 +01001260
Chris Wilson266a2402017-05-04 10:33:08 +01001261 if (likely(ce->pin_count++))
1262 goto out;
Chris Wilsona533b4b2017-03-16 17:16:28 +00001263 GEM_BUG_ON(!ce->pin_count); /* no overflow please! */
Chris Wilson0cb26a82016-06-24 14:55:53 +01001264
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +03001265 if (!ce->state && engine->context_size) {
Chris Wilson3204c342017-04-27 11:46:51 +01001266 struct i915_vma *vma;
1267
1268 vma = alloc_context_vma(engine);
1269 if (IS_ERR(vma)) {
1270 ret = PTR_ERR(vma);
Chris Wilson266a2402017-05-04 10:33:08 +01001271 goto err;
Chris Wilson3204c342017-04-27 11:46:51 +01001272 }
1273
1274 ce->state = vma;
1275 }
1276
Chris Wilson0cb26a82016-06-24 14:55:53 +01001277 if (ce->state) {
Chris Wilson72b72ae2017-02-10 10:14:22 +00001278 ret = context_pin(ctx);
Chris Wilsone8a9c582016-12-18 15:37:20 +00001279 if (ret)
Chris Wilson266a2402017-05-04 10:33:08 +01001280 goto err;
Chris Wilson5d4bac52017-03-22 20:59:30 +00001281
Chris Wilson3d574a62017-10-13 21:26:16 +01001282 ce->state->obj->pin_global++;
Chris Wilson0cb26a82016-06-24 14:55:53 +01001283 }
1284
Chris Wilson9a6feaf2016-07-20 13:31:50 +01001285 i915_gem_context_get(ctx);
Chris Wilson0cb26a82016-06-24 14:55:53 +01001286
Chris Wilson266a2402017-05-04 10:33:08 +01001287out:
1288 /* One ringbuffer to rule them all */
1289 return engine->buffer;
1290
1291err:
Chris Wilson0cb26a82016-06-24 14:55:53 +01001292 ce->pin_count = 0;
Chris Wilson266a2402017-05-04 10:33:08 +01001293 return ERR_PTR(ret);
Chris Wilson0cb26a82016-06-24 14:55:53 +01001294}
1295
Chris Wilsone8a9c582016-12-18 15:37:20 +00001296static void intel_ring_context_unpin(struct intel_engine_cs *engine,
1297 struct i915_gem_context *ctx)
Chris Wilson0cb26a82016-06-24 14:55:53 +01001298{
1299 struct intel_context *ce = &ctx->engine[engine->id];
1300
Chris Wilson91c8a322016-07-05 10:40:23 +01001301 lockdep_assert_held(&ctx->i915->drm.struct_mutex);
Chris Wilsone8a9c582016-12-18 15:37:20 +00001302 GEM_BUG_ON(ce->pin_count == 0);
Chris Wilson0cb26a82016-06-24 14:55:53 +01001303
1304 if (--ce->pin_count)
1305 return;
1306
Chris Wilson3d574a62017-10-13 21:26:16 +01001307 if (ce->state) {
1308 ce->state->obj->pin_global--;
Chris Wilsonbf3783e2016-08-15 10:48:54 +01001309 i915_vma_unpin(ce->state);
Chris Wilson3d574a62017-10-13 21:26:16 +01001310 }
Chris Wilson0cb26a82016-06-24 14:55:53 +01001311
Chris Wilson9a6feaf2016-07-20 13:31:50 +01001312 i915_gem_context_put(ctx);
Chris Wilson0cb26a82016-06-24 14:55:53 +01001313}
1314
Tvrtko Ursulinacd27842016-07-13 16:03:39 +01001315static int intel_init_ring_buffer(struct intel_engine_cs *engine)
Eric Anholt62fdfea2010-05-21 13:26:39 -07001316{
Chris Wilson32c04f12016-08-02 22:50:22 +01001317 struct intel_ring *ring;
Chris Wilson1a5788b2017-04-03 12:34:26 +01001318 int err;
Daniel Vetterbfc882b2014-11-20 00:33:08 +01001319
Tvrtko Ursulin019bf272016-07-13 16:03:41 +01001320 intel_engine_setup_common(engine);
1321
Chris Wilson1a5788b2017-04-03 12:34:26 +01001322 err = intel_engine_init_common(engine);
1323 if (err)
1324 goto err;
Eric Anholt62fdfea2010-05-21 13:26:39 -07001325
Chris Wilsond822bb12017-04-03 12:34:25 +01001326 ring = intel_engine_create_ring(engine, 32 * PAGE_SIZE);
1327 if (IS_ERR(ring)) {
Chris Wilson1a5788b2017-04-03 12:34:26 +01001328 err = PTR_ERR(ring);
Daniele Ceraolo Spurio486e93f2017-09-13 09:56:02 +01001329 goto err;
Chris Wilsond822bb12017-04-03 12:34:25 +01001330 }
1331
Daniele Ceraolo Spuriod3ef1af2016-12-23 15:56:21 -08001332 /* Ring wraparound at offset 0 sometimes hangs. No idea why. */
Chris Wilson1a5788b2017-04-03 12:34:26 +01001333 err = intel_ring_pin(ring, engine->i915, I915_GTT_PAGE_SIZE);
1334 if (err)
1335 goto err_ring;
1336
1337 GEM_BUG_ON(engine->buffer);
Chris Wilson57e88532016-08-15 10:48:57 +01001338 engine->buffer = ring;
Eric Anholt62fdfea2010-05-21 13:26:39 -07001339
Oscar Mateo8ee14972014-05-22 14:13:34 +01001340 return 0;
1341
Chris Wilson1a5788b2017-04-03 12:34:26 +01001342err_ring:
1343 intel_ring_free(ring);
Chris Wilson1a5788b2017-04-03 12:34:26 +01001344err:
1345 intel_engine_cleanup_common(engine);
1346 return err;
Eric Anholt62fdfea2010-05-21 13:26:39 -07001347}
1348
Chris Wilson7e37f882016-08-02 22:50:21 +01001349void intel_engine_cleanup(struct intel_engine_cs *engine)
Eric Anholt62fdfea2010-05-21 13:26:39 -07001350{
Chris Wilson1a5788b2017-04-03 12:34:26 +01001351 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson33626e62010-10-29 16:18:36 +01001352
Chris Wilson1a5788b2017-04-03 12:34:26 +01001353 WARN_ON(INTEL_GEN(dev_priv) > 2 &&
1354 (I915_READ_MODE(engine) & MODE_IDLE) == 0);
John Harrison6402c332014-10-31 12:00:26 +00001355
Chris Wilson1a5788b2017-04-03 12:34:26 +01001356 intel_ring_unpin(engine->buffer);
1357 intel_ring_free(engine->buffer);
Chris Wilson78501ea2010-10-27 12:18:21 +01001358
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001359 if (engine->cleanup)
1360 engine->cleanup(engine);
Zou Nan hai8d192152010-11-02 16:31:01 +08001361
Chris Wilson96a945a2016-08-03 13:19:16 +01001362 intel_engine_cleanup_common(engine);
Chris Wilson0cb26a82016-06-24 14:55:53 +01001363
Akash Goel3b3f1652016-10-13 22:44:48 +05301364 dev_priv->engine[engine->id] = NULL;
1365 kfree(engine);
Eric Anholt62fdfea2010-05-21 13:26:39 -07001366}
1367
Chris Wilson821ed7d2016-09-09 14:11:53 +01001368void intel_legacy_submission_resume(struct drm_i915_private *dev_priv)
1369{
1370 struct intel_engine_cs *engine;
Akash Goel3b3f1652016-10-13 22:44:48 +05301371 enum intel_engine_id id;
Chris Wilson821ed7d2016-09-09 14:11:53 +01001372
Chris Wilsone6ba9992017-04-25 14:00:49 +01001373 /* Restart from the beginning of the rings for convenience */
Chris Wilsonfe085f12017-03-21 10:25:52 +00001374 for_each_engine(engine, dev_priv, id)
Chris Wilsone6ba9992017-04-25 14:00:49 +01001375 intel_ring_reset(engine->buffer, 0);
Chris Wilson821ed7d2016-09-09 14:11:53 +01001376}
1377
Chris Wilsone61e0f52018-02-21 09:56:36 +00001378static inline int mi_set_context(struct i915_request *rq, u32 flags)
Chris Wilson8911a312017-11-23 15:26:31 +00001379{
1380 struct drm_i915_private *i915 = rq->i915;
1381 struct intel_engine_cs *engine = rq->engine;
1382 enum intel_engine_id id;
1383 const int num_rings =
1384 /* Use an extended w/a on gen7 if signalling from other rings */
1385 (HAS_LEGACY_SEMAPHORES(i915) && IS_GEN7(i915)) ?
1386 INTEL_INFO(i915)->num_rings - 1 :
1387 0;
1388 int len;
1389 u32 *cs;
1390
1391 flags |= MI_MM_SPACE_GTT;
1392 if (IS_HASWELL(i915))
1393 /* These flags are for resource streamer on HSW+ */
1394 flags |= HSW_MI_RS_SAVE_STATE_EN | HSW_MI_RS_RESTORE_STATE_EN;
1395 else
1396 flags |= MI_SAVE_EXT_STATE_EN | MI_RESTORE_EXT_STATE_EN;
1397
1398 len = 4;
1399 if (IS_GEN7(i915))
1400 len += 2 + (num_rings ? 4*num_rings + 6 : 0);
1401
1402 cs = intel_ring_begin(rq, len);
1403 if (IS_ERR(cs))
1404 return PTR_ERR(cs);
1405
1406 /* WaProgramMiArbOnOffAroundMiSetContext:ivb,vlv,hsw,bdw,chv */
1407 if (IS_GEN7(i915)) {
1408 *cs++ = MI_ARB_ON_OFF | MI_ARB_DISABLE;
1409 if (num_rings) {
1410 struct intel_engine_cs *signaller;
1411
1412 *cs++ = MI_LOAD_REGISTER_IMM(num_rings);
1413 for_each_engine(signaller, i915, id) {
1414 if (signaller == engine)
1415 continue;
1416
1417 *cs++ = i915_mmio_reg_offset(
1418 RING_PSMI_CTL(signaller->mmio_base));
1419 *cs++ = _MASKED_BIT_ENABLE(
1420 GEN6_PSMI_SLEEP_MSG_DISABLE);
1421 }
1422 }
1423 }
1424
1425 *cs++ = MI_NOOP;
1426 *cs++ = MI_SET_CONTEXT;
1427 *cs++ = i915_ggtt_offset(rq->ctx->engine[RCS].state) | flags;
1428 /*
1429 * w/a: MI_SET_CONTEXT must always be followed by MI_NOOP
1430 * WaMiSetContext_Hang:snb,ivb,vlv
1431 */
1432 *cs++ = MI_NOOP;
1433
1434 if (IS_GEN7(i915)) {
1435 if (num_rings) {
1436 struct intel_engine_cs *signaller;
1437 i915_reg_t last_reg = {}; /* keep gcc quiet */
1438
1439 *cs++ = MI_LOAD_REGISTER_IMM(num_rings);
1440 for_each_engine(signaller, i915, id) {
1441 if (signaller == engine)
1442 continue;
1443
1444 last_reg = RING_PSMI_CTL(signaller->mmio_base);
1445 *cs++ = i915_mmio_reg_offset(last_reg);
1446 *cs++ = _MASKED_BIT_DISABLE(
1447 GEN6_PSMI_SLEEP_MSG_DISABLE);
1448 }
1449
1450 /* Insert a delay before the next switch! */
1451 *cs++ = MI_STORE_REGISTER_MEM | MI_SRM_LRM_GLOBAL_GTT;
1452 *cs++ = i915_mmio_reg_offset(last_reg);
1453 *cs++ = i915_ggtt_offset(engine->scratch);
1454 *cs++ = MI_NOOP;
1455 }
1456 *cs++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
1457 }
1458
1459 intel_ring_advance(rq, cs);
1460
1461 return 0;
1462}
1463
Chris Wilsone61e0f52018-02-21 09:56:36 +00001464static int remap_l3(struct i915_request *rq, int slice)
Chris Wilson8911a312017-11-23 15:26:31 +00001465{
1466 u32 *cs, *remap_info = rq->i915->l3_parity.remap_info[slice];
1467 int i;
1468
1469 if (!remap_info)
1470 return 0;
1471
1472 cs = intel_ring_begin(rq, GEN7_L3LOG_SIZE/4 * 2 + 2);
1473 if (IS_ERR(cs))
1474 return PTR_ERR(cs);
1475
1476 /*
1477 * Note: We do not worry about the concurrent register cacheline hang
1478 * here because no other code should access these registers other than
1479 * at initialization time.
1480 */
1481 *cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4);
1482 for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
1483 *cs++ = i915_mmio_reg_offset(GEN7_L3LOG(slice, i));
1484 *cs++ = remap_info[i];
1485 }
1486 *cs++ = MI_NOOP;
1487 intel_ring_advance(rq, cs);
1488
1489 return 0;
1490}
1491
Chris Wilsone61e0f52018-02-21 09:56:36 +00001492static int switch_context(struct i915_request *rq)
Chris Wilson8911a312017-11-23 15:26:31 +00001493{
1494 struct intel_engine_cs *engine = rq->engine;
1495 struct i915_gem_context *to_ctx = rq->ctx;
1496 struct i915_hw_ppgtt *to_mm =
1497 to_ctx->ppgtt ?: rq->i915->mm.aliasing_ppgtt;
1498 struct i915_gem_context *from_ctx = engine->legacy_active_context;
1499 struct i915_hw_ppgtt *from_mm = engine->legacy_active_ppgtt;
1500 u32 hw_flags = 0;
1501 int ret, i;
1502
1503 lockdep_assert_held(&rq->i915->drm.struct_mutex);
1504 GEM_BUG_ON(HAS_EXECLISTS(rq->i915));
1505
1506 if (to_mm != from_mm ||
1507 (to_mm && intel_engine_flag(engine) & to_mm->pd_dirty_rings)) {
1508 trace_switch_mm(engine, to_ctx);
1509 ret = to_mm->switch_mm(to_mm, rq);
1510 if (ret)
1511 goto err;
1512
1513 to_mm->pd_dirty_rings &= ~intel_engine_flag(engine);
1514 engine->legacy_active_ppgtt = to_mm;
1515 hw_flags = MI_FORCE_RESTORE;
1516 }
1517
1518 if (to_ctx->engine[engine->id].state &&
1519 (to_ctx != from_ctx || hw_flags & MI_FORCE_RESTORE)) {
1520 GEM_BUG_ON(engine->id != RCS);
1521
1522 /*
1523 * The kernel context(s) is treated as pure scratch and is not
1524 * expected to retain any state (as we sacrifice it during
1525 * suspend and on resume it may be corrupted). This is ok,
1526 * as nothing actually executes using the kernel context; it
1527 * is purely used for flushing user contexts.
1528 */
1529 if (i915_gem_context_is_kernel(to_ctx))
1530 hw_flags = MI_RESTORE_INHIBIT;
1531
1532 ret = mi_set_context(rq, hw_flags);
1533 if (ret)
1534 goto err_mm;
1535
1536 engine->legacy_active_context = to_ctx;
1537 }
1538
1539 if (to_ctx->remap_slice) {
1540 for (i = 0; i < MAX_L3_SLICES; i++) {
1541 if (!(to_ctx->remap_slice & BIT(i)))
1542 continue;
1543
1544 ret = remap_l3(rq, i);
1545 if (ret)
1546 goto err_ctx;
1547 }
1548
1549 to_ctx->remap_slice = 0;
1550 }
1551
1552 return 0;
1553
1554err_ctx:
1555 engine->legacy_active_context = from_ctx;
1556err_mm:
1557 engine->legacy_active_ppgtt = from_mm;
1558err:
1559 return ret;
1560}
1561
Chris Wilsone61e0f52018-02-21 09:56:36 +00001562static int ring_request_alloc(struct i915_request *request)
Chris Wilson9d7730912012-11-27 16:22:52 +00001563{
Chris Wilsonfd138212017-11-15 15:12:04 +00001564 int ret;
Chris Wilson63103462016-04-28 09:56:49 +01001565
Chris Wilsone8a9c582016-12-18 15:37:20 +00001566 GEM_BUG_ON(!request->ctx->engine[request->engine->id].pin_count);
1567
Chris Wilson63103462016-04-28 09:56:49 +01001568 /* Flush enough space to reduce the likelihood of waiting after
1569 * we start building the request - in which case we will just
1570 * have to repeat work.
1571 */
Chris Wilsona0442462016-04-29 09:07:05 +01001572 request->reserved_space += LEGACY_REQUEST_SIZE;
Chris Wilson63103462016-04-28 09:56:49 +01001573
Chris Wilsonfd138212017-11-15 15:12:04 +00001574 ret = intel_ring_wait_for_space(request->ring, request->reserved_space);
1575 if (ret)
1576 return ret;
Chris Wilson63103462016-04-28 09:56:49 +01001577
Chris Wilson8911a312017-11-23 15:26:31 +00001578 ret = switch_context(request);
Chris Wilson3fef5cd2017-11-20 10:20:02 +00001579 if (ret)
1580 return ret;
1581
Chris Wilsona0442462016-04-29 09:07:05 +01001582 request->reserved_space -= LEGACY_REQUEST_SIZE;
Chris Wilson63103462016-04-28 09:56:49 +01001583 return 0;
Chris Wilson9d7730912012-11-27 16:22:52 +00001584}
1585
Chris Wilsonfd138212017-11-15 15:12:04 +00001586static noinline int wait_for_space(struct intel_ring *ring, unsigned int bytes)
Mika Kuoppalacbcc80d2012-12-04 15:12:03 +02001587{
Chris Wilsone61e0f52018-02-21 09:56:36 +00001588 struct i915_request *target;
Chris Wilsone95433c2016-10-28 13:58:27 +01001589 long timeout;
1590
Chris Wilsonfd138212017-11-15 15:12:04 +00001591 lockdep_assert_held(&ring->vma->vm->i915->drm.struct_mutex);
Chris Wilson987046a2016-04-28 09:56:46 +01001592
Chris Wilson95aebcb2017-05-04 14:08:45 +01001593 if (intel_ring_update_space(ring) >= bytes)
Chris Wilson987046a2016-04-28 09:56:46 +01001594 return 0;
1595
Chris Wilson36620032018-03-07 13:42:23 +00001596 GEM_BUG_ON(list_empty(&ring->request_list));
Chris Wilson675d9ad2016-08-04 07:52:36 +01001597 list_for_each_entry(target, &ring->request_list, ring_link) {
Chris Wilson987046a2016-04-28 09:56:46 +01001598 /* Would completion of this request free enough space? */
Chris Wilson605d5b32017-05-04 14:08:44 +01001599 if (bytes <= __intel_ring_space(target->postfix,
1600 ring->emit, ring->size))
Chris Wilson987046a2016-04-28 09:56:46 +01001601 break;
1602 }
1603
Chris Wilson675d9ad2016-08-04 07:52:36 +01001604 if (WARN_ON(&target->ring_link == &ring->request_list))
Chris Wilson987046a2016-04-28 09:56:46 +01001605 return -ENOSPC;
1606
Chris Wilsone61e0f52018-02-21 09:56:36 +00001607 timeout = i915_request_wait(target,
Chris Wilsone95433c2016-10-28 13:58:27 +01001608 I915_WAIT_INTERRUPTIBLE | I915_WAIT_LOCKED,
1609 MAX_SCHEDULE_TIMEOUT);
1610 if (timeout < 0)
1611 return timeout;
Chris Wilson7da844c2016-08-04 07:52:38 +01001612
Chris Wilsone61e0f52018-02-21 09:56:36 +00001613 i915_request_retire_upto(target);
Chris Wilson7da844c2016-08-04 07:52:38 +01001614
1615 intel_ring_update_space(ring);
1616 GEM_BUG_ON(ring->space < bytes);
1617 return 0;
Chris Wilson987046a2016-04-28 09:56:46 +01001618}
1619
Chris Wilsonfd138212017-11-15 15:12:04 +00001620int intel_ring_wait_for_space(struct intel_ring *ring, unsigned int bytes)
1621{
1622 GEM_BUG_ON(bytes > ring->effective_size);
1623 if (unlikely(bytes > ring->effective_size - ring->emit))
1624 bytes += ring->size - ring->emit;
1625
1626 if (unlikely(bytes > ring->space)) {
1627 int ret = wait_for_space(ring, bytes);
1628 if (unlikely(ret))
1629 return ret;
1630 }
1631
1632 GEM_BUG_ON(ring->space < bytes);
1633 return 0;
1634}
1635
Chris Wilsone61e0f52018-02-21 09:56:36 +00001636u32 *intel_ring_begin(struct i915_request *rq, unsigned int num_dwords)
Chris Wilson987046a2016-04-28 09:56:46 +01001637{
Chris Wilsone61e0f52018-02-21 09:56:36 +00001638 struct intel_ring *ring = rq->ring;
Chris Wilson5e5655c2017-05-04 14:08:46 +01001639 const unsigned int remain_usable = ring->effective_size - ring->emit;
1640 const unsigned int bytes = num_dwords * sizeof(u32);
1641 unsigned int need_wrap = 0;
1642 unsigned int total_bytes;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001643 u32 *cs;
Mika Kuoppalacbcc80d2012-12-04 15:12:03 +02001644
Chris Wilson6492ca72017-07-21 17:11:01 +01001645 /* Packets must be qword aligned. */
1646 GEM_BUG_ON(num_dwords & 1);
1647
Chris Wilsone61e0f52018-02-21 09:56:36 +00001648 total_bytes = bytes + rq->reserved_space;
Chris Wilson5e5655c2017-05-04 14:08:46 +01001649 GEM_BUG_ON(total_bytes > ring->effective_size);
John Harrison29b1b412015-06-18 13:10:09 +01001650
Chris Wilson5e5655c2017-05-04 14:08:46 +01001651 if (unlikely(total_bytes > remain_usable)) {
1652 const int remain_actual = ring->size - ring->emit;
1653
1654 if (bytes > remain_usable) {
1655 /*
1656 * Not enough space for the basic request. So need to
1657 * flush out the remainder and then wait for
1658 * base + reserved.
1659 */
1660 total_bytes += remain_actual;
1661 need_wrap = remain_actual | 1;
1662 } else {
1663 /*
1664 * The base request will fit but the reserved space
1665 * falls off the end. So we don't need an immediate
1666 * wrap and only need to effectively wait for the
1667 * reserved size from the start of ringbuffer.
1668 */
Chris Wilsone61e0f52018-02-21 09:56:36 +00001669 total_bytes = rq->reserved_space + remain_actual;
Chris Wilson5e5655c2017-05-04 14:08:46 +01001670 }
Mika Kuoppalacbcc80d2012-12-04 15:12:03 +02001671 }
1672
Chris Wilson5e5655c2017-05-04 14:08:46 +01001673 if (unlikely(total_bytes > ring->space)) {
Chris Wilsonfd138212017-11-15 15:12:04 +00001674 int ret;
1675
1676 /*
1677 * Space is reserved in the ringbuffer for finalising the
1678 * request, as that cannot be allowed to fail. During request
1679 * finalisation, reserved_space is set to 0 to stop the
1680 * overallocation and the assumption is that then we never need
1681 * to wait (which has the risk of failing with EINTR).
1682 *
Chris Wilsone61e0f52018-02-21 09:56:36 +00001683 * See also i915_request_alloc() and i915_request_add().
Chris Wilsonfd138212017-11-15 15:12:04 +00001684 */
Chris Wilsone61e0f52018-02-21 09:56:36 +00001685 GEM_BUG_ON(!rq->reserved_space);
Chris Wilsonfd138212017-11-15 15:12:04 +00001686
1687 ret = wait_for_space(ring, total_bytes);
Mika Kuoppalacbcc80d2012-12-04 15:12:03 +02001688 if (unlikely(ret))
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001689 return ERR_PTR(ret);
Mika Kuoppalacbcc80d2012-12-04 15:12:03 +02001690 }
1691
Chris Wilson987046a2016-04-28 09:56:46 +01001692 if (unlikely(need_wrap)) {
Chris Wilson5e5655c2017-05-04 14:08:46 +01001693 need_wrap &= ~1;
1694 GEM_BUG_ON(need_wrap > ring->space);
1695 GEM_BUG_ON(ring->emit + need_wrap > ring->size);
Chris Wilson46b86332018-03-19 12:35:28 +00001696 GEM_BUG_ON(!IS_ALIGNED(need_wrap, sizeof(u64)));
Mika Kuoppalacbcc80d2012-12-04 15:12:03 +02001697
Chris Wilson987046a2016-04-28 09:56:46 +01001698 /* Fill the tail with MI_NOOP */
Chris Wilson46b86332018-03-19 12:35:28 +00001699 memset64(ring->vaddr + ring->emit, 0, need_wrap / sizeof(u64));
Chris Wilson5e5655c2017-05-04 14:08:46 +01001700 ring->space -= need_wrap;
Chris Wilson46b86332018-03-19 12:35:28 +00001701 ring->emit = 0;
Chris Wilson987046a2016-04-28 09:56:46 +01001702 }
Chris Wilson78501ea2010-10-27 12:18:21 +01001703
Chris Wilsone6ba9992017-04-25 14:00:49 +01001704 GEM_BUG_ON(ring->emit > ring->size - bytes);
Chris Wilson605d5b32017-05-04 14:08:44 +01001705 GEM_BUG_ON(ring->space < bytes);
Chris Wilsone6ba9992017-04-25 14:00:49 +01001706 cs = ring->vaddr + ring->emit;
Chris Wilson46b86332018-03-19 12:35:28 +00001707 GEM_DEBUG_EXEC(memset32(cs, POISON_INUSE, bytes / sizeof(*cs)));
Chris Wilsone6ba9992017-04-25 14:00:49 +01001708 ring->emit += bytes;
Chris Wilson1dae2df2016-08-02 22:50:19 +01001709 ring->space -= bytes;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001710
1711 return cs;
Zou Nan hai8187a2b2010-05-21 09:08:55 +08001712}
1713
Ville Syrjälä753b1ad2014-02-11 19:52:05 +02001714/* Align the ring tail to a cacheline boundary */
Chris Wilsone61e0f52018-02-21 09:56:36 +00001715int intel_ring_cacheline_align(struct i915_request *rq)
Ville Syrjälä753b1ad2014-02-11 19:52:05 +02001716{
Chris Wilsone61e0f52018-02-21 09:56:36 +00001717 int num_dwords = (rq->ring->emit & (CACHELINE_BYTES - 1)) / sizeof(u32);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001718 u32 *cs;
Ville Syrjälä753b1ad2014-02-11 19:52:05 +02001719
1720 if (num_dwords == 0)
1721 return 0;
1722
Chris Wilsone61e0f52018-02-21 09:56:36 +00001723 num_dwords = CACHELINE_BYTES / sizeof(u32) - num_dwords;
1724 cs = intel_ring_begin(rq, num_dwords);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001725 if (IS_ERR(cs))
1726 return PTR_ERR(cs);
Ville Syrjälä753b1ad2014-02-11 19:52:05 +02001727
1728 while (num_dwords--)
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001729 *cs++ = MI_NOOP;
Ville Syrjälä753b1ad2014-02-11 19:52:05 +02001730
Chris Wilsone61e0f52018-02-21 09:56:36 +00001731 intel_ring_advance(rq, cs);
Ville Syrjälä753b1ad2014-02-11 19:52:05 +02001732
1733 return 0;
1734}
1735
Chris Wilsone61e0f52018-02-21 09:56:36 +00001736static void gen6_bsd_submit_request(struct i915_request *request)
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001737{
Chris Wilsonc5efa1a2016-08-02 22:50:29 +01001738 struct drm_i915_private *dev_priv = request->i915;
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001739
Chris Wilson76f84212016-06-30 15:33:45 +01001740 intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL);
1741
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001742 /* Every tail move must follow the sequence below */
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001743
Chris Wilson12f55812012-07-05 17:14:01 +01001744 /* Disable notification that the ring is IDLE. The GT
1745 * will then assume that it is busy and bring it out of rc6.
1746 */
Chris Wilson76f84212016-06-30 15:33:45 +01001747 I915_WRITE_FW(GEN6_BSD_SLEEP_PSMI_CONTROL,
1748 _MASKED_BIT_ENABLE(GEN6_BSD_SLEEP_MSG_DISABLE));
Chris Wilson12f55812012-07-05 17:14:01 +01001749
1750 /* Clear the context id. Here be magic! */
Chris Wilson76f84212016-06-30 15:33:45 +01001751 I915_WRITE64_FW(GEN6_BSD_RNCID, 0x0);
Chris Wilson12f55812012-07-05 17:14:01 +01001752
1753 /* Wait for the ring not to be idle, i.e. for it to wake up. */
Chris Wilson02b312d2017-04-11 11:13:37 +01001754 if (__intel_wait_for_register_fw(dev_priv,
1755 GEN6_BSD_SLEEP_PSMI_CONTROL,
1756 GEN6_BSD_SLEEP_INDICATOR,
1757 0,
1758 1000, 0, NULL))
Chris Wilson12f55812012-07-05 17:14:01 +01001759 DRM_ERROR("timed out waiting for the BSD ring to wake up\n");
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001760
Chris Wilson12f55812012-07-05 17:14:01 +01001761 /* Now that the ring is fully powered up, update the tail */
Chris Wilsonb0411e72016-08-02 22:50:34 +01001762 i9xx_submit_request(request);
Chris Wilson12f55812012-07-05 17:14:01 +01001763
1764 /* Let the ring send IDLE messages to the GT again,
1765 * and so let it sleep to conserve power when idle.
1766 */
Chris Wilson76f84212016-06-30 15:33:45 +01001767 I915_WRITE_FW(GEN6_BSD_SLEEP_PSMI_CONTROL,
1768 _MASKED_BIT_DISABLE(GEN6_BSD_SLEEP_MSG_DISABLE));
1769
1770 intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL);
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001771}
1772
Chris Wilsone61e0f52018-02-21 09:56:36 +00001773static int gen6_bsd_ring_flush(struct i915_request *rq, u32 mode)
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001774{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001775 u32 cmd, *cs;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001776
Chris Wilsone61e0f52018-02-21 09:56:36 +00001777 cs = intel_ring_begin(rq, 4);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001778 if (IS_ERR(cs))
1779 return PTR_ERR(cs);
Chris Wilsonb72f3ac2011-01-04 17:34:02 +00001780
Chris Wilson71a77e02011-02-02 12:13:49 +00001781 cmd = MI_FLUSH_DW;
Chris Wilsonf0a1fb12015-01-22 13:42:00 +00001782
1783 /* We always require a command barrier so that subsequent
1784 * commands, such as breadcrumb interrupts, are strictly ordered
1785 * wrt the contents of the write cache being flushed to memory
1786 * (and thus being coherent from the CPU).
1787 */
1788 cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW;
1789
Jesse Barnes9a289772012-10-26 09:42:42 -07001790 /*
1791 * Bspec vol 1c.5 - video engine command streamer:
1792 * "If ENABLED, all TLBs will be invalidated once the flush
1793 * operation is complete. This bit is only valid when the
1794 * Post-Sync Operation field is a value of 1h or 3h."
1795 */
Chris Wilson7c9cf4e2016-08-02 22:50:25 +01001796 if (mode & EMIT_INVALIDATE)
Chris Wilsonf0a1fb12015-01-22 13:42:00 +00001797 cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD;
1798
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001799 *cs++ = cmd;
1800 *cs++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
Chris Wilson79e67702017-11-20 20:55:01 +00001801 *cs++ = 0;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001802 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +00001803 intel_ring_advance(rq, cs);
Ben Widawsky1c7a0622013-11-02 21:07:12 -07001804 return 0;
1805}
1806
1807static int
Chris Wilsone61e0f52018-02-21 09:56:36 +00001808hsw_emit_bb_start(struct i915_request *rq,
Chris Wilson803688b2016-08-02 22:50:27 +01001809 u64 offset, u32 len,
1810 unsigned int dispatch_flags)
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001811{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001812 u32 *cs;
Chris Wilsonab6f8e32010-09-19 17:53:44 +01001813
Chris Wilsone61e0f52018-02-21 09:56:36 +00001814 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001815 if (IS_ERR(cs))
1816 return PTR_ERR(cs);
Chris Wilsone1f99ce2010-10-27 12:45:26 +01001817
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001818 *cs++ = MI_BATCH_BUFFER_START | (dispatch_flags & I915_DISPATCH_SECURE ?
1819 0 : MI_BATCH_PPGTT_HSW | MI_BATCH_NON_SECURE_HSW) |
1820 (dispatch_flags & I915_DISPATCH_RS ?
1821 MI_BATCH_RESOURCE_STREAMER : 0);
Chris Wilsond7d4eed2012-10-17 12:09:54 +01001822 /* bit0-7 is the length on GEN6+ */
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001823 *cs++ = offset;
Chris Wilsone61e0f52018-02-21 09:56:36 +00001824 intel_ring_advance(rq, cs);
Chris Wilsond7d4eed2012-10-17 12:09:54 +01001825
1826 return 0;
1827}
1828
1829static int
Chris Wilsone61e0f52018-02-21 09:56:36 +00001830gen6_emit_bb_start(struct i915_request *rq,
Chris Wilson803688b2016-08-02 22:50:27 +01001831 u64 offset, u32 len,
1832 unsigned int dispatch_flags)
Chris Wilsond7d4eed2012-10-17 12:09:54 +01001833{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001834 u32 *cs;
Chris Wilsond7d4eed2012-10-17 12:09:54 +01001835
Chris Wilsone61e0f52018-02-21 09:56:36 +00001836 cs = intel_ring_begin(rq, 2);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001837 if (IS_ERR(cs))
1838 return PTR_ERR(cs);
Chris Wilsond7d4eed2012-10-17 12:09:54 +01001839
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001840 *cs++ = MI_BATCH_BUFFER_START | (dispatch_flags & I915_DISPATCH_SECURE ?
1841 0 : MI_BATCH_NON_SECURE_I965);
Akshay Joshi0206e352011-08-16 15:34:10 -04001842 /* bit0-7 is the length on GEN6+ */
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001843 *cs++ = offset;
Chris Wilsone61e0f52018-02-21 09:56:36 +00001844 intel_ring_advance(rq, cs);
Chris Wilsonab6f8e32010-09-19 17:53:44 +01001845
Akshay Joshi0206e352011-08-16 15:34:10 -04001846 return 0;
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001847}
1848
Chris Wilson549f7362010-10-19 11:19:32 +01001849/* Blitter support (SandyBridge+) */
1850
Chris Wilsone61e0f52018-02-21 09:56:36 +00001851static int gen6_ring_flush(struct i915_request *rq, u32 mode)
Zou Nan hai8d192152010-11-02 16:31:01 +08001852{
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001853 u32 cmd, *cs;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001854
Chris Wilsone61e0f52018-02-21 09:56:36 +00001855 cs = intel_ring_begin(rq, 4);
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001856 if (IS_ERR(cs))
1857 return PTR_ERR(cs);
Chris Wilsonb72f3ac2011-01-04 17:34:02 +00001858
Chris Wilson71a77e02011-02-02 12:13:49 +00001859 cmd = MI_FLUSH_DW;
Chris Wilsonf0a1fb12015-01-22 13:42:00 +00001860
1861 /* We always require a command barrier so that subsequent
1862 * commands, such as breadcrumb interrupts, are strictly ordered
1863 * wrt the contents of the write cache being flushed to memory
1864 * (and thus being coherent from the CPU).
1865 */
1866 cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW;
1867
Jesse Barnes9a289772012-10-26 09:42:42 -07001868 /*
1869 * Bspec vol 1c.3 - blitter engine command streamer:
1870 * "If ENABLED, all TLBs will be invalidated once the flush
1871 * operation is complete. This bit is only valid when the
1872 * Post-Sync Operation field is a value of 1h or 3h."
1873 */
Chris Wilson7c9cf4e2016-08-02 22:50:25 +01001874 if (mode & EMIT_INVALIDATE)
Chris Wilsonf0a1fb12015-01-22 13:42:00 +00001875 cmd |= MI_INVALIDATE_TLB;
Tvrtko Ursulin73dec952017-02-14 11:32:42 +00001876 *cs++ = cmd;
1877 *cs++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT;
Chris Wilson79e67702017-11-20 20:55:01 +00001878 *cs++ = 0;
1879 *cs++ = MI_NOOP;
Chris Wilsone61e0f52018-02-21 09:56:36 +00001880 intel_ring_advance(rq, cs);
Rodrigo Vivifd3da6c2013-06-06 16:58:16 -03001881
Chris Wilsonb72f3ac2011-01-04 17:34:02 +00001882 return 0;
Zou Nan hai8d192152010-11-02 16:31:01 +08001883}
1884
Tvrtko Ursulind9a64612016-06-29 16:09:27 +01001885static void intel_ring_init_semaphores(struct drm_i915_private *dev_priv,
1886 struct intel_engine_cs *engine)
1887{
Chris Wilson79e67702017-11-20 20:55:01 +00001888 int i;
Tvrtko Ursulindb3d4012016-06-29 16:09:28 +01001889
Chris Wilson93c6e962017-11-20 20:55:04 +00001890 if (!HAS_LEGACY_SEMAPHORES(dev_priv))
Tvrtko Ursulindb3d4012016-06-29 16:09:28 +01001891 return;
1892
Chris Wilson79e67702017-11-20 20:55:01 +00001893 GEM_BUG_ON(INTEL_GEN(dev_priv) < 6);
1894 engine->semaphore.sync_to = gen6_ring_sync_to;
1895 engine->semaphore.signal = gen6_signal;
Chris Wilson51d545d2016-08-15 10:49:02 +01001896
Chris Wilson79e67702017-11-20 20:55:01 +00001897 /*
1898 * The current semaphore is only applied on pre-gen8
1899 * platform. And there is no VCS2 ring on the pre-gen8
1900 * platform. So the semaphore between RCS and VCS2 is
1901 * initialized as INVALID.
1902 */
1903 for (i = 0; i < GEN6_NUM_SEMAPHORES; i++) {
1904 static const struct {
Tvrtko Ursulin4b8e38a2016-06-29 16:09:31 +01001905 u32 wait_mbox;
1906 i915_reg_t mbox_reg;
Chris Wilson79e67702017-11-20 20:55:01 +00001907 } sem_data[GEN6_NUM_SEMAPHORES][GEN6_NUM_SEMAPHORES] = {
1908 [RCS_HW] = {
1909 [VCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_RV, .mbox_reg = GEN6_VRSYNC },
1910 [BCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_RB, .mbox_reg = GEN6_BRSYNC },
1911 [VECS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_RVE, .mbox_reg = GEN6_VERSYNC },
1912 },
1913 [VCS_HW] = {
1914 [RCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VR, .mbox_reg = GEN6_RVSYNC },
1915 [BCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VB, .mbox_reg = GEN6_BVSYNC },
1916 [VECS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VVE, .mbox_reg = GEN6_VEVSYNC },
1917 },
1918 [BCS_HW] = {
1919 [RCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_BR, .mbox_reg = GEN6_RBSYNC },
1920 [VCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_BV, .mbox_reg = GEN6_VBSYNC },
1921 [VECS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_BVE, .mbox_reg = GEN6_VEBSYNC },
1922 },
1923 [VECS_HW] = {
1924 [RCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VER, .mbox_reg = GEN6_RVESYNC },
1925 [VCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VEV, .mbox_reg = GEN6_VVESYNC },
1926 [BCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VEB, .mbox_reg = GEN6_BVESYNC },
1927 },
1928 };
1929 u32 wait_mbox;
1930 i915_reg_t mbox_reg;
Tvrtko Ursulin4b8e38a2016-06-29 16:09:31 +01001931
Chris Wilson79e67702017-11-20 20:55:01 +00001932 if (i == engine->hw_id) {
1933 wait_mbox = MI_SEMAPHORE_SYNC_INVALID;
1934 mbox_reg = GEN6_NOSYNC;
1935 } else {
1936 wait_mbox = sem_data[engine->hw_id][i].wait_mbox;
1937 mbox_reg = sem_data[engine->hw_id][i].mbox_reg;
Tvrtko Ursulin4b8e38a2016-06-29 16:09:31 +01001938 }
Chris Wilson79e67702017-11-20 20:55:01 +00001939
1940 engine->semaphore.mbox.wait[i] = wait_mbox;
1941 engine->semaphore.mbox.signal[i] = mbox_reg;
Tvrtko Ursulind9a64612016-06-29 16:09:27 +01001942 }
1943}
1944
Chris Wilsoned003072016-07-01 09:18:13 +01001945static void intel_ring_init_irq(struct drm_i915_private *dev_priv,
1946 struct intel_engine_cs *engine)
1947{
Chris Wilson79e67702017-11-20 20:55:01 +00001948 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilson31bb59c2016-07-01 17:23:27 +01001949 engine->irq_enable = gen6_irq_enable;
1950 engine->irq_disable = gen6_irq_disable;
Chris Wilsoned003072016-07-01 09:18:13 +01001951 engine->irq_seqno_barrier = gen6_seqno_barrier;
1952 } else if (INTEL_GEN(dev_priv) >= 5) {
Chris Wilson31bb59c2016-07-01 17:23:27 +01001953 engine->irq_enable = gen5_irq_enable;
1954 engine->irq_disable = gen5_irq_disable;
Chris Wilsonf8973c22016-07-01 17:23:21 +01001955 engine->irq_seqno_barrier = gen5_seqno_barrier;
Chris Wilsoned003072016-07-01 09:18:13 +01001956 } else if (INTEL_GEN(dev_priv) >= 3) {
Chris Wilson31bb59c2016-07-01 17:23:27 +01001957 engine->irq_enable = i9xx_irq_enable;
1958 engine->irq_disable = i9xx_irq_disable;
Chris Wilsoned003072016-07-01 09:18:13 +01001959 } else {
Chris Wilson31bb59c2016-07-01 17:23:27 +01001960 engine->irq_enable = i8xx_irq_enable;
1961 engine->irq_disable = i8xx_irq_disable;
Chris Wilsoned003072016-07-01 09:18:13 +01001962 }
1963}
1964
Chris Wilsonff44ad52017-03-16 17:13:03 +00001965static void i9xx_set_default_submission(struct intel_engine_cs *engine)
1966{
1967 engine->submit_request = i9xx_submit_request;
Chris Wilson27a5f612017-09-15 18:31:00 +01001968 engine->cancel_requests = cancel_requests;
Chris Wilsonaba5e272017-10-25 15:39:41 +01001969
1970 engine->park = NULL;
1971 engine->unpark = NULL;
Chris Wilsonff44ad52017-03-16 17:13:03 +00001972}
1973
1974static void gen6_bsd_set_default_submission(struct intel_engine_cs *engine)
1975{
Chris Wilsonaba5e272017-10-25 15:39:41 +01001976 i9xx_set_default_submission(engine);
Chris Wilsonff44ad52017-03-16 17:13:03 +00001977 engine->submit_request = gen6_bsd_submit_request;
1978}
1979
Tvrtko Ursulin06a2fe22016-06-29 16:09:20 +01001980static void intel_ring_default_vfuncs(struct drm_i915_private *dev_priv,
1981 struct intel_engine_cs *engine)
1982{
Chris Wilson79e67702017-11-20 20:55:01 +00001983 /* gen8+ are only supported with execlists */
1984 GEM_BUG_ON(INTEL_GEN(dev_priv) >= 8);
1985
Chris Wilson618e4ca2016-08-02 22:50:35 +01001986 intel_ring_init_irq(dev_priv, engine);
1987 intel_ring_init_semaphores(dev_priv, engine);
1988
Tvrtko Ursulin1d8a1332016-06-29 16:09:25 +01001989 engine->init_hw = init_ring_common;
Chris Wilson821ed7d2016-09-09 14:11:53 +01001990 engine->reset_hw = reset_ring_common;
Tvrtko Ursulin7445a2a2016-06-29 16:09:21 +01001991
Chris Wilsone8a9c582016-12-18 15:37:20 +00001992 engine->context_pin = intel_ring_context_pin;
1993 engine->context_unpin = intel_ring_context_unpin;
1994
Chris Wilsonf73e7392016-12-18 15:37:24 +00001995 engine->request_alloc = ring_request_alloc;
1996
Chris Wilson9b81d552016-10-28 13:58:50 +01001997 engine->emit_breadcrumb = i9xx_emit_breadcrumb;
Chris Wilson98f29e82016-10-28 13:58:51 +01001998 engine->emit_breadcrumb_sz = i9xx_emit_breadcrumb_sz;
Chris Wilson93c6e962017-11-20 20:55:04 +00001999 if (HAS_LEGACY_SEMAPHORES(dev_priv)) {
Chris Wilson98f29e82016-10-28 13:58:51 +01002000 int num_rings;
2001
Chris Wilson9b81d552016-10-28 13:58:50 +01002002 engine->emit_breadcrumb = gen6_sema_emit_breadcrumb;
Chris Wilson98f29e82016-10-28 13:58:51 +01002003
Tvrtko Ursulinc58949f2017-06-19 11:59:17 +01002004 num_rings = INTEL_INFO(dev_priv)->num_rings - 1;
Chris Wilson79e67702017-11-20 20:55:01 +00002005 engine->emit_breadcrumb_sz += num_rings * 3;
2006 if (num_rings & 1)
2007 engine->emit_breadcrumb_sz++;
Chris Wilson98f29e82016-10-28 13:58:51 +01002008 }
Chris Wilsonff44ad52017-03-16 17:13:03 +00002009
2010 engine->set_default_submission = i9xx_set_default_submission;
Chris Wilson6f7bef72016-07-01 09:18:12 +01002011
Chris Wilson79e67702017-11-20 20:55:01 +00002012 if (INTEL_GEN(dev_priv) >= 6)
Chris Wilson803688b2016-08-02 22:50:27 +01002013 engine->emit_bb_start = gen6_emit_bb_start;
Chris Wilson6f7bef72016-07-01 09:18:12 +01002014 else if (INTEL_GEN(dev_priv) >= 4)
Chris Wilson803688b2016-08-02 22:50:27 +01002015 engine->emit_bb_start = i965_emit_bb_start;
Jani Nikula2a307c22016-11-30 17:43:04 +02002016 else if (IS_I830(dev_priv) || IS_I845G(dev_priv))
Chris Wilson803688b2016-08-02 22:50:27 +01002017 engine->emit_bb_start = i830_emit_bb_start;
Chris Wilson6f7bef72016-07-01 09:18:12 +01002018 else
Chris Wilson803688b2016-08-02 22:50:27 +01002019 engine->emit_bb_start = i915_emit_bb_start;
Tvrtko Ursulin06a2fe22016-06-29 16:09:20 +01002020}
2021
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002022int intel_init_render_ring_buffer(struct intel_engine_cs *engine)
Xiang, Haihao5c1143b2010-09-16 10:43:11 +08002023{
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002024 struct drm_i915_private *dev_priv = engine->i915;
Ben Widawsky3e789982014-06-30 09:53:37 -07002025 int ret;
Xiang, Haihao5c1143b2010-09-16 10:43:11 +08002026
Tvrtko Ursulin06a2fe22016-06-29 16:09:20 +01002027 intel_ring_default_vfuncs(dev_priv, engine);
2028
Chris Wilson61ff75a2016-07-01 17:23:28 +01002029 if (HAS_L3_DPF(dev_priv))
2030 engine->irq_keep_mask = GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
Chris Wilsonf8973c22016-07-01 17:23:21 +01002031
Daniele Ceraolo Spuriofa6f0712018-03-14 11:26:53 -07002032 engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT;
2033
Chris Wilson79e67702017-11-20 20:55:01 +00002034 if (INTEL_GEN(dev_priv) >= 6) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002035 engine->init_context = intel_rcs_ctx_init;
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002036 engine->emit_flush = gen7_render_ring_flush;
Chris Wilsonc0336662016-05-06 15:40:21 +01002037 if (IS_GEN6(dev_priv))
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002038 engine->emit_flush = gen6_render_ring_flush;
Chris Wilsonc0336662016-05-06 15:40:21 +01002039 } else if (IS_GEN5(dev_priv)) {
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002040 engine->emit_flush = gen4_render_ring_flush;
Daniel Vetter59465b52012-04-11 22:12:48 +02002041 } else {
Chris Wilsonc0336662016-05-06 15:40:21 +01002042 if (INTEL_GEN(dev_priv) < 4)
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002043 engine->emit_flush = gen2_render_ring_flush;
Chris Wilson46f0f8d2012-04-18 11:12:11 +01002044 else
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002045 engine->emit_flush = gen4_render_ring_flush;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002046 engine->irq_enable_mask = I915_USER_INTERRUPT;
Xiang, Haihao5c1143b2010-09-16 10:43:11 +08002047 }
Ben Widawsky707d9cf2014-06-30 09:53:36 -07002048
Chris Wilsonc0336662016-05-06 15:40:21 +01002049 if (IS_HASWELL(dev_priv))
Chris Wilson803688b2016-08-02 22:50:27 +01002050 engine->emit_bb_start = hsw_emit_bb_start;
Chris Wilson6f7bef72016-07-01 09:18:12 +01002051
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002052 engine->init_hw = init_render_ring;
Daniel Vetter59465b52012-04-11 22:12:48 +02002053
Tvrtko Ursulinacd27842016-07-13 16:03:39 +01002054 ret = intel_init_ring_buffer(engine);
Daniel Vetter99be1df2014-11-20 00:33:06 +01002055 if (ret)
2056 return ret;
2057
Chris Wilsonf8973c22016-07-01 17:23:21 +01002058 if (INTEL_GEN(dev_priv) >= 6) {
Chris Wilsonf51455d2017-01-10 14:47:34 +00002059 ret = intel_engine_create_scratch(engine, PAGE_SIZE);
Chris Wilson7d5ea802016-07-01 17:23:20 +01002060 if (ret)
2061 return ret;
2062 } else if (HAS_BROKEN_CS_TLB(dev_priv)) {
Chris Wilson56c0f1a2016-08-15 10:48:58 +01002063 ret = intel_engine_create_scratch(engine, I830_WA_SIZE);
Daniel Vetter99be1df2014-11-20 00:33:06 +01002064 if (ret)
2065 return ret;
2066 }
2067
2068 return 0;
Xiang, Haihao5c1143b2010-09-16 10:43:11 +08002069}
2070
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002071int intel_init_bsd_ring_buffer(struct intel_engine_cs *engine)
Xiang, Haihao5c1143b2010-09-16 10:43:11 +08002072{
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002073 struct drm_i915_private *dev_priv = engine->i915;
Daniel Vetter58fa3832012-04-11 22:12:49 +02002074
Tvrtko Ursulin06a2fe22016-06-29 16:09:20 +01002075 intel_ring_default_vfuncs(dev_priv, engine);
2076
Chris Wilsonc0336662016-05-06 15:40:21 +01002077 if (INTEL_GEN(dev_priv) >= 6) {
Daniel Vetter0fd2c202012-04-11 22:12:55 +02002078 /* gen6 bsd needs a special wa for tail updates */
Chris Wilsonc0336662016-05-06 15:40:21 +01002079 if (IS_GEN6(dev_priv))
Chris Wilsonff44ad52017-03-16 17:13:03 +00002080 engine->set_default_submission = gen6_bsd_set_default_submission;
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002081 engine->emit_flush = gen6_bsd_ring_flush;
Chris Wilson79e67702017-11-20 20:55:01 +00002082 engine->irq_enable_mask = GT_BSD_USER_INTERRUPT;
Daniel Vetter58fa3832012-04-11 22:12:49 +02002083 } else {
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002084 engine->emit_flush = bsd_ring_flush;
Tvrtko Ursulin8d228912016-06-29 16:09:32 +01002085 if (IS_GEN5(dev_priv))
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002086 engine->irq_enable_mask = ILK_BSD_USER_INTERRUPT;
Tvrtko Ursulin8d228912016-06-29 16:09:32 +01002087 else
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002088 engine->irq_enable_mask = I915_BSD_USER_INTERRUPT;
Daniel Vetter58fa3832012-04-11 22:12:49 +02002089 }
Daniel Vetter58fa3832012-04-11 22:12:49 +02002090
Tvrtko Ursulinacd27842016-07-13 16:03:39 +01002091 return intel_init_ring_buffer(engine);
Xiang, Haihao5c1143b2010-09-16 10:43:11 +08002092}
Chris Wilson549f7362010-10-19 11:19:32 +01002093
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002094int intel_init_blt_ring_buffer(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01002095{
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002096 struct drm_i915_private *dev_priv = engine->i915;
Tvrtko Ursulin06a2fe22016-06-29 16:09:20 +01002097
2098 intel_ring_default_vfuncs(dev_priv, engine);
2099
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002100 engine->emit_flush = gen6_ring_flush;
Chris Wilson79e67702017-11-20 20:55:01 +00002101 engine->irq_enable_mask = GT_BLT_USER_INTERRUPT;
Chris Wilson549f7362010-10-19 11:19:32 +01002102
Tvrtko Ursulinacd27842016-07-13 16:03:39 +01002103 return intel_init_ring_buffer(engine);
Chris Wilson549f7362010-10-19 11:19:32 +01002104}
Chris Wilsona7b97612012-07-20 12:41:08 +01002105
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002106int intel_init_vebox_ring_buffer(struct intel_engine_cs *engine)
Ben Widawsky9a8a2212013-05-28 19:22:23 -07002107{
Tvrtko Ursulin8b3e2d32016-07-13 16:03:37 +01002108 struct drm_i915_private *dev_priv = engine->i915;
Tvrtko Ursulin06a2fe22016-06-29 16:09:20 +01002109
2110 intel_ring_default_vfuncs(dev_priv, engine);
2111
Chris Wilsonc7fe7d22016-08-02 22:50:24 +01002112 engine->emit_flush = gen6_ring_flush;
Chris Wilson79e67702017-11-20 20:55:01 +00002113 engine->irq_enable_mask = PM_VEBOX_USER_INTERRUPT;
2114 engine->irq_enable = hsw_vebox_irq_enable;
2115 engine->irq_disable = hsw_vebox_irq_disable;
Ben Widawsky9a8a2212013-05-28 19:22:23 -07002116
Tvrtko Ursulinacd27842016-07-13 16:03:39 +01002117 return intel_init_ring_buffer(engine);
Ben Widawsky9a8a2212013-05-28 19:22:23 -07002118}