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