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