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