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