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