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 | |
Tvrtko Ursulin | 2f35afe | 2017-02-16 12:23:21 +0000 | [diff] [blame] | 42 | static 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 | fe085f1 | 2017-03-21 10:25:52 +0000 | [diff] [blame] | 52 | ring->space = __intel_ring_space(ring->head, ring->tail, ring->size); |
Dave Gordon | ebd0fd4 | 2014-11-27 11:22:49 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 55 | static int |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 56 | gen2_render_ring_flush(struct drm_i915_gem_request *req, u32 mode) |
Chris Wilson | 46f0f8d | 2012-04-18 11:12:11 +0100 | [diff] [blame] | 57 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 58 | u32 cmd, *cs; |
Chris Wilson | 46f0f8d | 2012-04-18 11:12:11 +0100 | [diff] [blame] | 59 | |
| 60 | cmd = MI_FLUSH; |
Chris Wilson | 46f0f8d | 2012-04-18 11:12:11 +0100 | [diff] [blame] | 61 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 62 | if (mode & EMIT_INVALIDATE) |
Chris Wilson | 46f0f8d | 2012-04-18 11:12:11 +0100 | [diff] [blame] | 63 | cmd |= MI_READ_FLUSH; |
| 64 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 65 | cs = intel_ring_begin(req, 2); |
| 66 | if (IS_ERR(cs)) |
| 67 | return PTR_ERR(cs); |
Chris Wilson | 46f0f8d | 2012-04-18 11:12:11 +0100 | [diff] [blame] | 68 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 69 | *cs++ = cmd; |
| 70 | *cs++ = MI_NOOP; |
| 71 | intel_ring_advance(req, cs); |
Chris Wilson | 46f0f8d | 2012-04-18 11:12:11 +0100 | [diff] [blame] | 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static int |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 77 | gen4_render_ring_flush(struct drm_i915_gem_request *req, u32 mode) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 78 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 79 | u32 cmd, *cs; |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 80 | |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 81 | /* |
| 82 | * read/write caches: |
| 83 | * |
| 84 | * I915_GEM_DOMAIN_RENDER is always invalidated, but is |
| 85 | * only flushed if MI_NO_WRITE_FLUSH is unset. On 965, it is |
| 86 | * also flushed at 2d versus 3d pipeline switches. |
| 87 | * |
| 88 | * read-only caches: |
| 89 | * |
| 90 | * I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if |
| 91 | * MI_READ_FLUSH is set, and is always flushed on 965. |
| 92 | * |
| 93 | * I915_GEM_DOMAIN_COMMAND may not exist? |
| 94 | * |
| 95 | * I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is |
| 96 | * invalidated when MI_EXE_FLUSH is set. |
| 97 | * |
| 98 | * I915_GEM_DOMAIN_VERTEX, which exists on 965, is |
| 99 | * invalidated with every MI_FLUSH. |
| 100 | * |
| 101 | * TLBs: |
| 102 | * |
| 103 | * On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND |
| 104 | * and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and |
| 105 | * I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER |
| 106 | * are flushed at any MI_FLUSH. |
| 107 | */ |
| 108 | |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 109 | cmd = MI_FLUSH; |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 110 | if (mode & EMIT_INVALIDATE) { |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 111 | cmd |= MI_EXE_FLUSH; |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 112 | if (IS_G4X(req->i915) || IS_GEN5(req->i915)) |
| 113 | cmd |= MI_INVALIDATE_ISP; |
| 114 | } |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 115 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 116 | cs = intel_ring_begin(req, 2); |
| 117 | if (IS_ERR(cs)) |
| 118 | return PTR_ERR(cs); |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 119 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 120 | *cs++ = cmd; |
| 121 | *cs++ = MI_NOOP; |
| 122 | intel_ring_advance(req, cs); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 123 | |
| 124 | return 0; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 125 | } |
| 126 | |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 127 | /** |
| 128 | * Emits a PIPE_CONTROL with a non-zero post-sync operation, for |
| 129 | * implementing two workarounds on gen6. From section 1.4.7.1 |
| 130 | * "PIPE_CONTROL" of the Sandy Bridge PRM volume 2 part 1: |
| 131 | * |
| 132 | * [DevSNB-C+{W/A}] Before any depth stall flush (including those |
| 133 | * produced by non-pipelined state commands), software needs to first |
| 134 | * send a PIPE_CONTROL with no bits set except Post-Sync Operation != |
| 135 | * 0. |
| 136 | * |
| 137 | * [Dev-SNB{W/A}]: Before a PIPE_CONTROL with Write Cache Flush Enable |
| 138 | * =1, a PIPE_CONTROL with any non-zero post-sync-op is required. |
| 139 | * |
| 140 | * And the workaround for these two requires this workaround first: |
| 141 | * |
| 142 | * [Dev-SNB{W/A}]: Pipe-control with CS-stall bit set must be sent |
| 143 | * BEFORE the pipe-control with a post-sync op and no write-cache |
| 144 | * flushes. |
| 145 | * |
| 146 | * And this last workaround is tricky because of the requirements on |
| 147 | * that bit. From section 1.4.7.2.3 "Stall" of the Sandy Bridge PRM |
| 148 | * volume 2 part 1: |
| 149 | * |
| 150 | * "1 of the following must also be set: |
| 151 | * - Render Target Cache Flush Enable ([12] of DW1) |
| 152 | * - Depth Cache Flush Enable ([0] of DW1) |
| 153 | * - Stall at Pixel Scoreboard ([1] of DW1) |
| 154 | * - Depth Stall ([13] of DW1) |
| 155 | * - Post-Sync Operation ([13] of DW1) |
| 156 | * - Notify Enable ([8] of DW1)" |
| 157 | * |
| 158 | * The cache flushes require the workaround flush that triggered this |
| 159 | * one, so we can't use it. Depth stall would trigger the same. |
| 160 | * Post-sync nonzero is what triggered this second workaround, so we |
| 161 | * can't use that one either. Notify enable is IRQs, which aren't |
| 162 | * really our business. That leaves only stall at scoreboard. |
| 163 | */ |
| 164 | static int |
John Harrison | f2cf1fc | 2015-05-29 17:43:58 +0100 | [diff] [blame] | 165 | intel_emit_post_sync_nonzero_flush(struct drm_i915_gem_request *req) |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 166 | { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 167 | u32 scratch_addr = |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 168 | i915_ggtt_offset(req->engine->scratch) + 2 * CACHELINE_BYTES; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 169 | u32 *cs; |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 170 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 171 | cs = intel_ring_begin(req, 6); |
| 172 | if (IS_ERR(cs)) |
| 173 | return PTR_ERR(cs); |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 174 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 175 | *cs++ = GFX_OP_PIPE_CONTROL(5); |
| 176 | *cs++ = PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD; |
| 177 | *cs++ = scratch_addr | PIPE_CONTROL_GLOBAL_GTT; |
| 178 | *cs++ = 0; /* low dword */ |
| 179 | *cs++ = 0; /* high dword */ |
| 180 | *cs++ = MI_NOOP; |
| 181 | intel_ring_advance(req, cs); |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 182 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 183 | cs = intel_ring_begin(req, 6); |
| 184 | if (IS_ERR(cs)) |
| 185 | return PTR_ERR(cs); |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 186 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 187 | *cs++ = GFX_OP_PIPE_CONTROL(5); |
| 188 | *cs++ = PIPE_CONTROL_QW_WRITE; |
| 189 | *cs++ = scratch_addr | PIPE_CONTROL_GLOBAL_GTT; |
| 190 | *cs++ = 0; |
| 191 | *cs++ = 0; |
| 192 | *cs++ = MI_NOOP; |
| 193 | intel_ring_advance(req, cs); |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | static int |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 199 | gen6_render_ring_flush(struct drm_i915_gem_request *req, u32 mode) |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 200 | { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 201 | u32 scratch_addr = |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 202 | i915_ggtt_offset(req->engine->scratch) + 2 * CACHELINE_BYTES; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 203 | u32 *cs, flags = 0; |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 204 | int ret; |
| 205 | |
Paulo Zanoni | b311150 | 2012-08-17 18:35:42 -0300 | [diff] [blame] | 206 | /* Force SNB workarounds for PIPE_CONTROL flushes */ |
John Harrison | f2cf1fc | 2015-05-29 17:43:58 +0100 | [diff] [blame] | 207 | ret = intel_emit_post_sync_nonzero_flush(req); |
Paulo Zanoni | b311150 | 2012-08-17 18:35:42 -0300 | [diff] [blame] | 208 | if (ret) |
| 209 | return ret; |
| 210 | |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 211 | /* Just flush everything. Experiments have shown that reducing the |
| 212 | * number of bits based on the write domains has little performance |
| 213 | * impact. |
| 214 | */ |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 215 | if (mode & EMIT_FLUSH) { |
Chris Wilson | 7d54a90 | 2012-08-10 10:18:10 +0100 | [diff] [blame] | 216 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; |
| 217 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
| 218 | /* |
| 219 | * Ensure that any following seqno writes only happen |
| 220 | * when the render cache is indeed flushed. |
| 221 | */ |
Daniel Vetter | 97f209b | 2012-06-28 09:48:42 +0200 | [diff] [blame] | 222 | flags |= PIPE_CONTROL_CS_STALL; |
Chris Wilson | 7d54a90 | 2012-08-10 10:18:10 +0100 | [diff] [blame] | 223 | } |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 224 | if (mode & EMIT_INVALIDATE) { |
Chris Wilson | 7d54a90 | 2012-08-10 10:18:10 +0100 | [diff] [blame] | 225 | flags |= PIPE_CONTROL_TLB_INVALIDATE; |
| 226 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; |
| 227 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 228 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 229 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; |
| 230 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; |
| 231 | /* |
| 232 | * TLB invalidate requires a post-sync write. |
| 233 | */ |
Jesse Barnes | 3ac7831 | 2012-10-25 12:15:47 -0700 | [diff] [blame] | 234 | flags |= PIPE_CONTROL_QW_WRITE | PIPE_CONTROL_CS_STALL; |
Chris Wilson | 7d54a90 | 2012-08-10 10:18:10 +0100 | [diff] [blame] | 235 | } |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 236 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 237 | cs = intel_ring_begin(req, 4); |
| 238 | if (IS_ERR(cs)) |
| 239 | return PTR_ERR(cs); |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 240 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 241 | *cs++ = GFX_OP_PIPE_CONTROL(4); |
| 242 | *cs++ = flags; |
| 243 | *cs++ = scratch_addr | PIPE_CONTROL_GLOBAL_GTT; |
| 244 | *cs++ = 0; |
| 245 | intel_ring_advance(req, cs); |
Jesse Barnes | 8d31528 | 2011-10-16 10:23:31 +0200 | [diff] [blame] | 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
Chris Wilson | 6c6cf5a | 2012-07-20 18:02:28 +0100 | [diff] [blame] | 250 | static int |
John Harrison | f2cf1fc | 2015-05-29 17:43:58 +0100 | [diff] [blame] | 251 | gen7_render_ring_cs_stall_wa(struct drm_i915_gem_request *req) |
Paulo Zanoni | f398763 | 2012-08-17 18:35:43 -0300 | [diff] [blame] | 252 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 253 | u32 *cs; |
Paulo Zanoni | f398763 | 2012-08-17 18:35:43 -0300 | [diff] [blame] | 254 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 255 | cs = intel_ring_begin(req, 4); |
| 256 | if (IS_ERR(cs)) |
| 257 | return PTR_ERR(cs); |
Paulo Zanoni | f398763 | 2012-08-17 18:35:43 -0300 | [diff] [blame] | 258 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 259 | *cs++ = GFX_OP_PIPE_CONTROL(4); |
| 260 | *cs++ = PIPE_CONTROL_CS_STALL | PIPE_CONTROL_STALL_AT_SCOREBOARD; |
| 261 | *cs++ = 0; |
| 262 | *cs++ = 0; |
| 263 | intel_ring_advance(req, cs); |
Paulo Zanoni | f398763 | 2012-08-17 18:35:43 -0300 | [diff] [blame] | 264 | |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static int |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 269 | gen7_render_ring_flush(struct drm_i915_gem_request *req, u32 mode) |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 270 | { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 271 | u32 scratch_addr = |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 272 | i915_ggtt_offset(req->engine->scratch) + 2 * CACHELINE_BYTES; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 273 | u32 *cs, flags = 0; |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 274 | |
Paulo Zanoni | f398763 | 2012-08-17 18:35:43 -0300 | [diff] [blame] | 275 | /* |
| 276 | * Ensure that any following seqno writes only happen when the render |
| 277 | * cache is indeed flushed. |
| 278 | * |
| 279 | * Workaround: 4th PIPE_CONTROL command (except the ones with only |
| 280 | * read-cache invalidate bits set) must have the CS_STALL bit set. We |
| 281 | * don't try to be clever and just set it unconditionally. |
| 282 | */ |
| 283 | flags |= PIPE_CONTROL_CS_STALL; |
| 284 | |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 285 | /* Just flush everything. Experiments have shown that reducing the |
| 286 | * number of bits based on the write domains has little performance |
| 287 | * impact. |
| 288 | */ |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 289 | if (mode & EMIT_FLUSH) { |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 290 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; |
| 291 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
Francisco Jerez | 965fd60 | 2016-01-13 18:59:39 -0800 | [diff] [blame] | 292 | flags |= PIPE_CONTROL_DC_FLUSH_ENABLE; |
Chris Wilson | 40a2448 | 2015-08-21 16:08:41 +0100 | [diff] [blame] | 293 | flags |= PIPE_CONTROL_FLUSH_ENABLE; |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 294 | } |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 295 | if (mode & EMIT_INVALIDATE) { |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 296 | flags |= PIPE_CONTROL_TLB_INVALIDATE; |
| 297 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; |
| 298 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 299 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 300 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; |
| 301 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; |
Chris Wilson | 148b83d | 2014-12-16 08:44:31 +0000 | [diff] [blame] | 302 | flags |= PIPE_CONTROL_MEDIA_STATE_CLEAR; |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 303 | /* |
| 304 | * TLB invalidate requires a post-sync write. |
| 305 | */ |
| 306 | flags |= PIPE_CONTROL_QW_WRITE; |
Ville Syrjälä | b9e1faa | 2013-02-14 21:53:51 +0200 | [diff] [blame] | 307 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; |
Paulo Zanoni | f398763 | 2012-08-17 18:35:43 -0300 | [diff] [blame] | 308 | |
Chris Wilson | add284a | 2014-12-16 08:44:32 +0000 | [diff] [blame] | 309 | flags |= PIPE_CONTROL_STALL_AT_SCOREBOARD; |
| 310 | |
Paulo Zanoni | f398763 | 2012-08-17 18:35:43 -0300 | [diff] [blame] | 311 | /* Workaround: we must issue a pipe_control with CS-stall bit |
| 312 | * set before a pipe_control command that has the state cache |
| 313 | * invalidate bit set. */ |
John Harrison | f2cf1fc | 2015-05-29 17:43:58 +0100 | [diff] [blame] | 314 | gen7_render_ring_cs_stall_wa(req); |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 315 | } |
| 316 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 317 | cs = intel_ring_begin(req, 4); |
| 318 | if (IS_ERR(cs)) |
| 319 | return PTR_ERR(cs); |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 320 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 321 | *cs++ = GFX_OP_PIPE_CONTROL(4); |
| 322 | *cs++ = flags; |
| 323 | *cs++ = scratch_addr; |
| 324 | *cs++ = 0; |
| 325 | intel_ring_advance(req, cs); |
Paulo Zanoni | 4772eae | 2012-08-17 18:35:41 -0300 | [diff] [blame] | 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
Ben Widawsky | a5f3d68 | 2013-11-02 21:07:27 -0700 | [diff] [blame] | 330 | static int |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 331 | gen8_render_ring_flush(struct drm_i915_gem_request *req, u32 mode) |
Kenneth Graunke | 884ceac | 2014-06-28 02:04:20 +0300 | [diff] [blame] | 332 | { |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 333 | u32 flags; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 334 | u32 *cs; |
Kenneth Graunke | 884ceac | 2014-06-28 02:04:20 +0300 | [diff] [blame] | 335 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 336 | cs = intel_ring_begin(req, mode & EMIT_INVALIDATE ? 12 : 6); |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 337 | if (IS_ERR(cs)) |
| 338 | return PTR_ERR(cs); |
Kenneth Graunke | 884ceac | 2014-06-28 02:04:20 +0300 | [diff] [blame] | 339 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 340 | flags = PIPE_CONTROL_CS_STALL; |
Ben Widawsky | a5f3d68 | 2013-11-02 21:07:27 -0700 | [diff] [blame] | 341 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 342 | if (mode & EMIT_FLUSH) { |
Ben Widawsky | a5f3d68 | 2013-11-02 21:07:27 -0700 | [diff] [blame] | 343 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; |
| 344 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
Francisco Jerez | 965fd60 | 2016-01-13 18:59:39 -0800 | [diff] [blame] | 345 | flags |= PIPE_CONTROL_DC_FLUSH_ENABLE; |
Chris Wilson | 40a2448 | 2015-08-21 16:08:41 +0100 | [diff] [blame] | 346 | flags |= PIPE_CONTROL_FLUSH_ENABLE; |
Ben Widawsky | a5f3d68 | 2013-11-02 21:07:27 -0700 | [diff] [blame] | 347 | } |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 348 | if (mode & EMIT_INVALIDATE) { |
Ben Widawsky | a5f3d68 | 2013-11-02 21:07:27 -0700 | [diff] [blame] | 349 | flags |= PIPE_CONTROL_TLB_INVALIDATE; |
| 350 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; |
| 351 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 352 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 353 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; |
| 354 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; |
| 355 | flags |= PIPE_CONTROL_QW_WRITE; |
| 356 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; |
Kenneth Graunke | 02c9f7e | 2014-01-27 14:20:16 -0800 | [diff] [blame] | 357 | |
| 358 | /* WaCsStallBeforeStateCacheInvalidate:bdw,chv */ |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 359 | cs = gen8_emit_pipe_control(cs, |
| 360 | PIPE_CONTROL_CS_STALL | |
| 361 | PIPE_CONTROL_STALL_AT_SCOREBOARD, |
| 362 | 0); |
Ben Widawsky | a5f3d68 | 2013-11-02 21:07:27 -0700 | [diff] [blame] | 363 | } |
| 364 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 365 | cs = gen8_emit_pipe_control(cs, flags, |
| 366 | i915_ggtt_offset(req->engine->scratch) + |
| 367 | 2 * CACHELINE_BYTES); |
| 368 | |
| 369 | intel_ring_advance(req, cs); |
| 370 | |
| 371 | return 0; |
Ben Widawsky | a5f3d68 | 2013-11-02 21:07:27 -0700 | [diff] [blame] | 372 | } |
| 373 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 374 | static void ring_setup_phys_status_page(struct intel_engine_cs *engine) |
Daniel Vetter | 035dc1e | 2013-07-03 12:56:54 +0200 | [diff] [blame] | 375 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 376 | struct drm_i915_private *dev_priv = engine->i915; |
Daniel Vetter | 035dc1e | 2013-07-03 12:56:54 +0200 | [diff] [blame] | 377 | u32 addr; |
| 378 | |
| 379 | addr = dev_priv->status_page_dmah->busaddr; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 380 | if (INTEL_GEN(dev_priv) >= 4) |
Daniel Vetter | 035dc1e | 2013-07-03 12:56:54 +0200 | [diff] [blame] | 381 | addr |= (dev_priv->status_page_dmah->busaddr >> 28) & 0xf0; |
| 382 | I915_WRITE(HWS_PGA, addr); |
| 383 | } |
| 384 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 385 | static void intel_ring_setup_status_page(struct intel_engine_cs *engine) |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 386 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 387 | struct drm_i915_private *dev_priv = engine->i915; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 388 | i915_reg_t mmio; |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 389 | |
| 390 | /* The ring status page addresses are no longer next to the rest of |
| 391 | * the ring registers as of gen7. |
| 392 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 393 | if (IS_GEN7(dev_priv)) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 394 | switch (engine->id) { |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 395 | case RCS: |
| 396 | mmio = RENDER_HWS_PGA_GEN7; |
| 397 | break; |
| 398 | case BCS: |
| 399 | mmio = BLT_HWS_PGA_GEN7; |
| 400 | break; |
| 401 | /* |
| 402 | * VCS2 actually doesn't exist on Gen7. Only shut up |
| 403 | * gcc switch check warning |
| 404 | */ |
| 405 | case VCS2: |
| 406 | case VCS: |
| 407 | mmio = BSD_HWS_PGA_GEN7; |
| 408 | break; |
| 409 | case VECS: |
| 410 | mmio = VEBOX_HWS_PGA_GEN7; |
| 411 | break; |
| 412 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 413 | } else if (IS_GEN6(dev_priv)) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 414 | mmio = RING_HWS_PGA_GEN6(engine->mmio_base); |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 415 | } else { |
| 416 | /* XXX: gen8 returns to sanity */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 417 | mmio = RING_HWS_PGA(engine->mmio_base); |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 420 | I915_WRITE(mmio, engine->status_page.ggtt_offset); |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 421 | POSTING_READ(mmio); |
| 422 | |
| 423 | /* |
| 424 | * Flush the TLB for this page |
| 425 | * |
| 426 | * FIXME: These two bits have disappeared on gen8, so a question |
| 427 | * arises: do we still need this and if so how should we go about |
| 428 | * invalidating the TLB? |
| 429 | */ |
Tvrtko Ursulin | ac657f6 | 2016-05-10 10:57:08 +0100 | [diff] [blame] | 430 | if (IS_GEN(dev_priv, 6, 7)) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 431 | i915_reg_t reg = RING_INSTPM(engine->mmio_base); |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 432 | |
| 433 | /* ring should be idle before issuing a sync flush*/ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 434 | WARN_ON((I915_READ_MODE(engine) & MODE_IDLE) == 0); |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 435 | |
| 436 | I915_WRITE(reg, |
| 437 | _MASKED_BIT_ENABLE(INSTPM_TLB_INVALIDATE | |
| 438 | INSTPM_SYNC_FLUSH)); |
Chris Wilson | 25ab57f | 2016-06-30 15:33:29 +0100 | [diff] [blame] | 439 | if (intel_wait_for_register(dev_priv, |
| 440 | reg, INSTPM_SYNC_FLUSH, 0, |
| 441 | 1000)) |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 442 | 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] | 443 | engine->name); |
Damien Lespiau | af75f26 | 2015-02-10 19:32:17 +0000 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 447 | static bool stop_ring(struct intel_engine_cs *engine) |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 448 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 449 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 450 | |
Chris Wilson | 21a2c58 | 2016-08-15 10:49:11 +0100 | [diff] [blame] | 451 | if (INTEL_GEN(dev_priv) > 2) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 452 | I915_WRITE_MODE(engine, _MASKED_BIT_ENABLE(STOP_RING)); |
Chris Wilson | 3d808eb | 2016-06-30 15:33:30 +0100 | [diff] [blame] | 453 | if (intel_wait_for_register(dev_priv, |
| 454 | RING_MI_MODE(engine->mmio_base), |
| 455 | MODE_IDLE, |
| 456 | MODE_IDLE, |
| 457 | 1000)) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 458 | DRM_ERROR("%s : timed out trying to stop ring\n", |
| 459 | engine->name); |
Chris Wilson | 9bec9b1 | 2014-08-11 09:21:35 +0100 | [diff] [blame] | 460 | /* Sometimes we observe that the idle flag is not |
| 461 | * set even though the ring is empty. So double |
| 462 | * check before giving up. |
| 463 | */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 464 | if (I915_READ_HEAD(engine) != I915_READ_TAIL(engine)) |
Chris Wilson | 9bec9b1 | 2014-08-11 09:21:35 +0100 | [diff] [blame] | 465 | return false; |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 466 | } |
| 467 | } |
| 468 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 469 | I915_WRITE_CTL(engine, 0); |
| 470 | I915_WRITE_HEAD(engine, 0); |
Chris Wilson | c5efa1a | 2016-08-02 22:50:29 +0100 | [diff] [blame] | 471 | I915_WRITE_TAIL(engine, 0); |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 472 | |
Chris Wilson | 21a2c58 | 2016-08-15 10:49:11 +0100 | [diff] [blame] | 473 | if (INTEL_GEN(dev_priv) > 2) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 474 | (void)I915_READ_CTL(engine); |
| 475 | I915_WRITE_MODE(engine, _MASKED_BIT_DISABLE(STOP_RING)); |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 476 | } |
| 477 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 478 | return (I915_READ_HEAD(engine) & HEAD_ADDR) == 0; |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 481 | static int init_ring_common(struct intel_engine_cs *engine) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [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 | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 484 | struct intel_ring *ring = engine->buffer; |
Daniel Vetter | b7884eb | 2012-06-04 11:18:15 +0200 | [diff] [blame] | 485 | int ret = 0; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 486 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 487 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Daniel Vetter | b7884eb | 2012-06-04 11:18:15 +0200 | [diff] [blame] | 488 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 489 | if (!stop_ring(engine)) { |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 490 | /* G45 ring initialization often fails to reset head to zero */ |
Chris Wilson | 6fd0d56 | 2010-12-05 20:42:33 +0000 | [diff] [blame] | 491 | DRM_DEBUG_KMS("%s head not reset to zero " |
| 492 | "ctl %08x head %08x tail %08x start %08x\n", |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 493 | engine->name, |
| 494 | I915_READ_CTL(engine), |
| 495 | I915_READ_HEAD(engine), |
| 496 | I915_READ_TAIL(engine), |
| 497 | I915_READ_START(engine)); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 498 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 499 | if (!stop_ring(engine)) { |
Chris Wilson | 6fd0d56 | 2010-12-05 20:42:33 +0000 | [diff] [blame] | 500 | DRM_ERROR("failed to set %s head to zero " |
| 501 | "ctl %08x head %08x tail %08x start %08x\n", |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 502 | engine->name, |
| 503 | I915_READ_CTL(engine), |
| 504 | I915_READ_HEAD(engine), |
| 505 | I915_READ_TAIL(engine), |
| 506 | I915_READ_START(engine)); |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 507 | ret = -EIO; |
| 508 | goto out; |
Chris Wilson | 6fd0d56 | 2010-12-05 20:42:33 +0000 | [diff] [blame] | 509 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Carlos Santa | 3177659 | 2016-08-17 12:30:56 -0700 | [diff] [blame] | 512 | if (HWS_NEEDS_PHYSICAL(dev_priv)) |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 513 | ring_setup_phys_status_page(engine); |
Carlos Santa | 3177659 | 2016-08-17 12:30:56 -0700 | [diff] [blame] | 514 | else |
| 515 | intel_ring_setup_status_page(engine); |
Chris Wilson | 9991ae7 | 2014-04-02 16:36:07 +0100 | [diff] [blame] | 516 | |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 517 | intel_engine_reset_breadcrumbs(engine); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 518 | |
Jiri Kosina | ece4a17 | 2014-08-07 16:29:53 +0200 | [diff] [blame] | 519 | /* Enforce ordering by reading HEAD register back */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 520 | I915_READ_HEAD(engine); |
Jiri Kosina | ece4a17 | 2014-08-07 16:29:53 +0200 | [diff] [blame] | 521 | |
Daniel Vetter | 0d8957c | 2012-08-07 09:54:14 +0200 | [diff] [blame] | 522 | /* Initialize the ring. This must happen _after_ we've cleared the ring |
| 523 | * registers with the above sequence (the readback of the HEAD registers |
| 524 | * also enforces ordering), otherwise the hw might lose the new ring |
| 525 | * register values. */ |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 526 | I915_WRITE_START(engine, i915_ggtt_offset(ring->vma)); |
Chris Wilson | 9546889 | 2014-08-07 15:39:54 +0100 | [diff] [blame] | 527 | |
| 528 | /* WaClearRingBufHeadRegAtInit:ctg,elk */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 529 | if (I915_READ_HEAD(engine)) |
Chris Wilson | 9546889 | 2014-08-07 15:39:54 +0100 | [diff] [blame] | 530 | DRM_DEBUG("%s initialization failed [head=%08x], fudging\n", |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 531 | engine->name, I915_READ_HEAD(engine)); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 532 | |
| 533 | intel_ring_update_space(ring); |
| 534 | I915_WRITE_HEAD(engine, ring->head); |
| 535 | I915_WRITE_TAIL(engine, ring->tail); |
| 536 | (void)I915_READ_TAIL(engine); |
Chris Wilson | 9546889 | 2014-08-07 15:39:54 +0100 | [diff] [blame] | 537 | |
Chris Wilson | 62ae14b | 2016-10-04 21:11:25 +0100 | [diff] [blame] | 538 | I915_WRITE_CTL(engine, RING_CTL_SIZE(ring->size) | RING_VALID); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 539 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 540 | /* If the head is still not zero, the ring is dead */ |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 541 | if (intel_wait_for_register_fw(dev_priv, RING_CTL(engine->mmio_base), |
| 542 | RING_VALID, RING_VALID, |
| 543 | 50)) { |
Chris Wilson | e74cfed | 2010-11-09 10:16:56 +0000 | [diff] [blame] | 544 | DRM_ERROR("%s initialization failed " |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 545 | "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] | 546 | engine->name, |
| 547 | I915_READ_CTL(engine), |
| 548 | I915_READ_CTL(engine) & RING_VALID, |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 549 | I915_READ_HEAD(engine), ring->head, |
| 550 | I915_READ_TAIL(engine), ring->tail, |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 551 | I915_READ_START(engine), |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 552 | i915_ggtt_offset(ring->vma)); |
Daniel Vetter | b7884eb | 2012-06-04 11:18:15 +0200 | [diff] [blame] | 553 | ret = -EIO; |
| 554 | goto out; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 555 | } |
| 556 | |
Tomas Elf | fc0768c | 2016-03-21 16:26:59 +0000 | [diff] [blame] | 557 | intel_engine_init_hangcheck(engine); |
Chris Wilson | 50f018d | 2013-06-10 11:20:19 +0100 | [diff] [blame] | 558 | |
Daniel Vetter | b7884eb | 2012-06-04 11:18:15 +0200 | [diff] [blame] | 559 | out: |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 560 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Daniel Vetter | b7884eb | 2012-06-04 11:18:15 +0200 | [diff] [blame] | 561 | |
| 562 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 563 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 564 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 565 | static void reset_ring_common(struct intel_engine_cs *engine, |
| 566 | struct drm_i915_gem_request *request) |
| 567 | { |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 568 | /* Try to restore the logical GPU state to match the continuation |
| 569 | * of the request queue. If we skip the context/PD restore, then |
| 570 | * the next request may try to execute assuming that its context |
| 571 | * is valid and loaded on the GPU and so may try to access invalid |
| 572 | * memory, prompting repeated GPU hangs. |
| 573 | * |
| 574 | * If the request was guilty, we still restore the logical state |
| 575 | * in case the next request requires it (e.g. the aliasing ppgtt), |
| 576 | * but skip over the hung batch. |
| 577 | * |
| 578 | * If the request was innocent, we try to replay the request with |
| 579 | * the restored context. |
| 580 | */ |
| 581 | if (request) { |
| 582 | struct drm_i915_private *dev_priv = request->i915; |
| 583 | struct intel_context *ce = &request->ctx->engine[engine->id]; |
| 584 | struct i915_hw_ppgtt *ppgtt; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 585 | |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 586 | /* FIXME consider gen8 reset */ |
| 587 | |
| 588 | if (ce->state) { |
| 589 | I915_WRITE(CCID, |
| 590 | i915_ggtt_offset(ce->state) | |
| 591 | BIT(8) /* must be set! */ | |
| 592 | CCID_EXTENDED_STATE_SAVE | |
| 593 | CCID_EXTENDED_STATE_RESTORE | |
| 594 | CCID_EN); |
| 595 | } |
| 596 | |
| 597 | ppgtt = request->ctx->ppgtt ?: engine->i915->mm.aliasing_ppgtt; |
| 598 | if (ppgtt) { |
| 599 | u32 pd_offset = ppgtt->pd.base.ggtt_offset << 10; |
| 600 | |
| 601 | I915_WRITE(RING_PP_DIR_DCLV(engine), PP_DIR_DCLV_2G); |
| 602 | I915_WRITE(RING_PP_DIR_BASE(engine), pd_offset); |
| 603 | |
| 604 | /* Wait for the PD reload to complete */ |
| 605 | if (intel_wait_for_register(dev_priv, |
| 606 | RING_PP_DIR_BASE(engine), |
| 607 | BIT(0), 0, |
| 608 | 10)) |
| 609 | DRM_ERROR("Wait for reload of ppgtt page-directory timed out\n"); |
| 610 | |
| 611 | ppgtt->pd_dirty_rings &= ~intel_engine_flag(engine); |
| 612 | } |
| 613 | |
| 614 | /* If the rq hung, jump to its breadcrumb and skip the batch */ |
Chris Wilson | fe085f1 | 2017-03-21 10:25:52 +0000 | [diff] [blame] | 615 | if (request->fence.error == -EIO) |
| 616 | request->ring->head = request->postfix; |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 617 | } else { |
| 618 | engine->legacy_active_context = NULL; |
| 619 | } |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 620 | } |
| 621 | |
John Harrison | 8753181 | 2015-05-29 17:43:44 +0100 | [diff] [blame] | 622 | static int intel_rcs_ctx_init(struct drm_i915_gem_request *req) |
Daniel Vetter | 8f0e2b9 | 2014-12-02 16:19:07 +0100 | [diff] [blame] | 623 | { |
| 624 | int ret; |
| 625 | |
John Harrison | e2be4fa | 2015-05-29 17:43:54 +0100 | [diff] [blame] | 626 | ret = intel_ring_workarounds_emit(req); |
Daniel Vetter | 8f0e2b9 | 2014-12-02 16:19:07 +0100 | [diff] [blame] | 627 | if (ret != 0) |
| 628 | return ret; |
| 629 | |
Chris Wilson | 4e50f08 | 2016-10-28 13:58:31 +0100 | [diff] [blame] | 630 | ret = i915_gem_render_state_emit(req); |
Daniel Vetter | 8f0e2b9 | 2014-12-02 16:19:07 +0100 | [diff] [blame] | 631 | if (ret) |
Chris Wilson | e26e1b9 | 2016-01-29 16:49:05 +0000 | [diff] [blame] | 632 | return ret; |
Daniel Vetter | 8f0e2b9 | 2014-12-02 16:19:07 +0100 | [diff] [blame] | 633 | |
Chris Wilson | e26e1b9 | 2016-01-29 16:49:05 +0000 | [diff] [blame] | 634 | return 0; |
Daniel Vetter | 8f0e2b9 | 2014-12-02 16:19:07 +0100 | [diff] [blame] | 635 | } |
| 636 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 637 | static int init_render_ring(struct intel_engine_cs *engine) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 638 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 639 | struct drm_i915_private *dev_priv = engine->i915; |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 640 | int ret = init_ring_common(engine); |
Konrad Zapalowicz | 9c33baa | 2014-06-19 19:07:15 +0200 | [diff] [blame] | 641 | if (ret) |
| 642 | return ret; |
Zhenyu Wang | a69ffdb | 2010-08-30 16:12:42 +0800 | [diff] [blame] | 643 | |
Akash Goel | 61a563a | 2014-03-25 18:01:50 +0530 | [diff] [blame] | 644 | /* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */ |
Tvrtko Ursulin | ac657f6 | 2016-05-10 10:57:08 +0100 | [diff] [blame] | 645 | if (IS_GEN(dev_priv, 4, 6)) |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 646 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH)); |
Chris Wilson | 1c8c38c | 2013-01-20 16:11:20 +0000 | [diff] [blame] | 647 | |
| 648 | /* We need to disable the AsyncFlip performance optimisations in order |
| 649 | * to use MI_WAIT_FOR_EVENT within the CS. It should already be |
| 650 | * programmed to '1' on all products. |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 651 | * |
Ville Syrjälä | 2441f87 | 2015-06-02 15:37:37 +0300 | [diff] [blame] | 652 | * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv |
Chris Wilson | 1c8c38c | 2013-01-20 16:11:20 +0000 | [diff] [blame] | 653 | */ |
Tvrtko Ursulin | ac657f6 | 2016-05-10 10:57:08 +0100 | [diff] [blame] | 654 | if (IS_GEN(dev_priv, 6, 7)) |
Chris Wilson | 1c8c38c | 2013-01-20 16:11:20 +0000 | [diff] [blame] | 655 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(ASYNC_FLIP_PERF_DISABLE)); |
| 656 | |
Chris Wilson | f05bb0c | 2013-01-20 16:33:32 +0000 | [diff] [blame] | 657 | /* Required for the hardware to program scanline values for waiting */ |
Akash Goel | 01fa030 | 2014-03-24 23:00:04 +0530 | [diff] [blame] | 658 | /* WaEnableFlushTlbInvalidationMode:snb */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 659 | if (IS_GEN6(dev_priv)) |
Chris Wilson | f05bb0c | 2013-01-20 16:33:32 +0000 | [diff] [blame] | 660 | I915_WRITE(GFX_MODE, |
Chris Wilson | aa83e30 | 2014-03-21 17:18:54 +0000 | [diff] [blame] | 661 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT)); |
Chris Wilson | f05bb0c | 2013-01-20 16:33:32 +0000 | [diff] [blame] | 662 | |
Akash Goel | 01fa030 | 2014-03-24 23:00:04 +0530 | [diff] [blame] | 663 | /* WaBCSVCSTlbInvalidationMode:ivb,vlv,hsw */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 664 | if (IS_GEN7(dev_priv)) |
Chris Wilson | 1c8c38c | 2013-01-20 16:11:20 +0000 | [diff] [blame] | 665 | I915_WRITE(GFX_MODE_GEN7, |
Akash Goel | 01fa030 | 2014-03-24 23:00:04 +0530 | [diff] [blame] | 666 | _MASKED_BIT_ENABLE(GFX_TLB_INVALIDATE_EXPLICIT) | |
Chris Wilson | 1c8c38c | 2013-01-20 16:11:20 +0000 | [diff] [blame] | 667 | _MASKED_BIT_ENABLE(GFX_REPLAY_MODE)); |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 668 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 669 | if (IS_GEN6(dev_priv)) { |
Kenneth Graunke | 3a69ddd | 2012-04-27 12:44:41 -0700 | [diff] [blame] | 670 | /* From the Sandybridge PRM, volume 1 part 3, page 24: |
| 671 | * "If this bit is set, STCunit will have LRA as replacement |
| 672 | * policy. [...] This bit must be reset. LRA replacement |
| 673 | * policy is not supported." |
| 674 | */ |
| 675 | I915_WRITE(CACHE_MODE_0, |
Daniel Vetter | 5e13a0c | 2012-05-08 13:39:59 +0200 | [diff] [blame] | 676 | _MASKED_BIT_DISABLE(CM0_STC_EVICT_DISABLE_LRA_SNB)); |
Ben Widawsky | 84f9f93 | 2011-12-12 19:21:58 -0800 | [diff] [blame] | 677 | } |
| 678 | |
Tvrtko Ursulin | ac657f6 | 2016-05-10 10:57:08 +0100 | [diff] [blame] | 679 | if (IS_GEN(dev_priv, 6, 7)) |
Daniel Vetter | 6b26c86 | 2012-04-24 14:04:12 +0200 | [diff] [blame] | 680 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_FORCE_ORDERING)); |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 681 | |
Ville Syrjälä | 035ea40 | 2016-07-12 19:24:47 +0300 | [diff] [blame] | 682 | if (INTEL_INFO(dev_priv)->gen >= 6) |
| 683 | I915_WRITE_IMR(engine, ~engine->irq_keep_mask); |
Ben Widawsky | 15b9f80 | 2012-05-25 16:56:23 -0700 | [diff] [blame] | 684 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 685 | return init_workarounds_ring(engine); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 686 | } |
| 687 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 688 | static void render_ring_cleanup(struct intel_engine_cs *engine) |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 689 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 690 | struct drm_i915_private *dev_priv = engine->i915; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 691 | |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 692 | i915_vma_unpin_and_release(&dev_priv->semaphore); |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 693 | } |
| 694 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 695 | static u32 *gen8_rcs_signal(struct drm_i915_gem_request *req, u32 *cs) |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 696 | { |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 697 | struct drm_i915_private *dev_priv = req->i915; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 698 | struct intel_engine_cs *waiter; |
Dave Gordon | c3232b1 | 2016-03-23 18:19:53 +0000 | [diff] [blame] | 699 | enum intel_engine_id id; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 700 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 701 | for_each_engine(waiter, dev_priv, id) { |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 702 | u64 gtt_offset = req->engine->semaphore.signal_ggtt[id]; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 703 | if (gtt_offset == MI_SEMAPHORE_SYNC_INVALID) |
| 704 | continue; |
| 705 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 706 | *cs++ = GFX_OP_PIPE_CONTROL(6); |
| 707 | *cs++ = PIPE_CONTROL_GLOBAL_GTT_IVB | PIPE_CONTROL_QW_WRITE | |
| 708 | PIPE_CONTROL_CS_STALL; |
| 709 | *cs++ = lower_32_bits(gtt_offset); |
| 710 | *cs++ = upper_32_bits(gtt_offset); |
| 711 | *cs++ = req->global_seqno; |
| 712 | *cs++ = 0; |
| 713 | *cs++ = MI_SEMAPHORE_SIGNAL | |
| 714 | MI_SEMAPHORE_TARGET(waiter->hw_id); |
| 715 | *cs++ = 0; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 718 | return cs; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 719 | } |
| 720 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 721 | static u32 *gen8_xcs_signal(struct drm_i915_gem_request *req, u32 *cs) |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 722 | { |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 723 | struct drm_i915_private *dev_priv = req->i915; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 724 | struct intel_engine_cs *waiter; |
Dave Gordon | c3232b1 | 2016-03-23 18:19:53 +0000 | [diff] [blame] | 725 | enum intel_engine_id id; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 726 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 727 | for_each_engine(waiter, dev_priv, id) { |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 728 | u64 gtt_offset = req->engine->semaphore.signal_ggtt[id]; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 729 | if (gtt_offset == MI_SEMAPHORE_SYNC_INVALID) |
| 730 | continue; |
| 731 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 732 | *cs++ = (MI_FLUSH_DW + 1) | MI_FLUSH_DW_OP_STOREDW; |
| 733 | *cs++ = lower_32_bits(gtt_offset) | MI_FLUSH_DW_USE_GTT; |
| 734 | *cs++ = upper_32_bits(gtt_offset); |
| 735 | *cs++ = req->global_seqno; |
| 736 | *cs++ = MI_SEMAPHORE_SIGNAL | |
| 737 | MI_SEMAPHORE_TARGET(waiter->hw_id); |
| 738 | *cs++ = 0; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 739 | } |
| 740 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 741 | return cs; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 742 | } |
| 743 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 744 | static u32 *gen6_signal(struct drm_i915_gem_request *req, u32 *cs) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 745 | { |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 746 | struct drm_i915_private *dev_priv = req->i915; |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 747 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 748 | enum intel_engine_id id; |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 749 | int num_rings = 0; |
Ben Widawsky | 024a43e | 2014-04-29 14:52:30 -0700 | [diff] [blame] | 750 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 751 | for_each_engine(engine, dev_priv, id) { |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 752 | i915_reg_t mbox_reg; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 753 | |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 754 | if (!(BIT(engine->hw_id) & GEN6_SEMAPHORES_MASK)) |
| 755 | continue; |
| 756 | |
| 757 | mbox_reg = req->engine->semaphore.mbox.signal[engine->hw_id]; |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 758 | if (i915_mmio_reg_valid(mbox_reg)) { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 759 | *cs++ = MI_LOAD_REGISTER_IMM(1); |
| 760 | *cs++ = i915_mmio_reg_offset(mbox_reg); |
| 761 | *cs++ = req->global_seqno; |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 762 | num_rings++; |
Ben Widawsky | 78325f2 | 2014-04-29 14:52:29 -0700 | [diff] [blame] | 763 | } |
| 764 | } |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 765 | if (num_rings & 1) |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 766 | *cs++ = MI_NOOP; |
Ben Widawsky | 024a43e | 2014-04-29 14:52:30 -0700 | [diff] [blame] | 767 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 768 | return cs; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 771 | static void i9xx_submit_request(struct drm_i915_gem_request *request) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 772 | { |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 773 | struct drm_i915_private *dev_priv = request->i915; |
| 774 | |
Chris Wilson | d55ac5b | 2016-11-14 20:40:59 +0000 | [diff] [blame] | 775 | i915_gem_request_submit(request); |
| 776 | |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 777 | assert_ring_tail_valid(request->ring, request->tail); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 778 | I915_WRITE_TAIL(request->engine, request->tail); |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 781 | static void i9xx_emit_breadcrumb(struct drm_i915_gem_request *req, u32 *cs) |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 782 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 783 | *cs++ = MI_STORE_DWORD_INDEX; |
| 784 | *cs++ = I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT; |
| 785 | *cs++ = req->global_seqno; |
| 786 | *cs++ = MI_USER_INTERRUPT; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 787 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 788 | req->tail = intel_ring_offset(req, cs); |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 789 | assert_ring_tail_valid(req->ring, req->tail); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 792 | static const int i9xx_emit_breadcrumb_sz = 4; |
| 793 | |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 794 | /** |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 795 | * gen6_sema_emit_breadcrumb - Update the semaphore mailbox registers |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 796 | * |
| 797 | * @request - request to write to the ring |
| 798 | * |
| 799 | * Update the mailbox registers in the *other* rings with the current seqno. |
| 800 | * This acts like a signal in the canonical semaphore. |
| 801 | */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 802 | static void gen6_sema_emit_breadcrumb(struct drm_i915_gem_request *req, u32 *cs) |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 803 | { |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 804 | return i9xx_emit_breadcrumb(req, |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 805 | req->engine->semaphore.signal(req, cs)); |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 806 | } |
| 807 | |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 808 | static void gen8_render_emit_breadcrumb(struct drm_i915_gem_request *req, |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 809 | u32 *cs) |
Chris Wilson | a58c01a | 2016-04-29 13:18:21 +0100 | [diff] [blame] | 810 | { |
| 811 | struct intel_engine_cs *engine = req->engine; |
Chris Wilson | a58c01a | 2016-04-29 13:18:21 +0100 | [diff] [blame] | 812 | |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 813 | if (engine->semaphore.signal) |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 814 | cs = engine->semaphore.signal(req, cs); |
Chris Wilson | 9242f97 | 2016-08-02 22:50:33 +0100 | [diff] [blame] | 815 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 816 | *cs++ = GFX_OP_PIPE_CONTROL(6); |
| 817 | *cs++ = PIPE_CONTROL_GLOBAL_GTT_IVB | PIPE_CONTROL_CS_STALL | |
| 818 | PIPE_CONTROL_QW_WRITE; |
| 819 | *cs++ = intel_hws_seqno_address(engine); |
| 820 | *cs++ = 0; |
| 821 | *cs++ = req->global_seqno; |
Chris Wilson | a58c01a | 2016-04-29 13:18:21 +0100 | [diff] [blame] | 822 | /* We're thrashing one dword of HWS. */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 823 | *cs++ = 0; |
| 824 | *cs++ = MI_USER_INTERRUPT; |
| 825 | *cs++ = MI_NOOP; |
Chris Wilson | c5efa1a | 2016-08-02 22:50:29 +0100 | [diff] [blame] | 826 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 827 | req->tail = intel_ring_offset(req, cs); |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 828 | assert_ring_tail_valid(req->ring, req->tail); |
Chris Wilson | a58c01a | 2016-04-29 13:18:21 +0100 | [diff] [blame] | 829 | } |
| 830 | |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 831 | static const int gen8_render_emit_breadcrumb_sz = 8; |
| 832 | |
Ben Widawsky | c8c99b0 | 2011-09-14 20:32:47 -0700 | [diff] [blame] | 833 | /** |
| 834 | * intel_ring_sync - sync the waiter to the signaller on seqno |
| 835 | * |
| 836 | * @waiter - ring that is waiting |
| 837 | * @signaller - ring which has, or will signal |
| 838 | * @seqno - seqno which the waiter will block on |
| 839 | */ |
Ben Widawsky | 5ee426c | 2014-06-30 09:53:38 -0700 | [diff] [blame] | 840 | |
| 841 | static int |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 842 | gen8_ring_sync_to(struct drm_i915_gem_request *req, |
| 843 | struct drm_i915_gem_request *signal) |
Ben Widawsky | 5ee426c | 2014-06-30 09:53:38 -0700 | [diff] [blame] | 844 | { |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 845 | struct drm_i915_private *dev_priv = req->i915; |
| 846 | u64 offset = GEN8_WAIT_OFFSET(req->engine, signal->engine->id); |
Chris Wilson | 6ef48d7 | 2016-04-29 13:18:25 +0100 | [diff] [blame] | 847 | struct i915_hw_ppgtt *ppgtt; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 848 | u32 *cs; |
Ben Widawsky | 5ee426c | 2014-06-30 09:53:38 -0700 | [diff] [blame] | 849 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 850 | cs = intel_ring_begin(req, 4); |
| 851 | if (IS_ERR(cs)) |
| 852 | return PTR_ERR(cs); |
Ben Widawsky | 5ee426c | 2014-06-30 09:53:38 -0700 | [diff] [blame] | 853 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 854 | *cs++ = MI_SEMAPHORE_WAIT | MI_SEMAPHORE_GLOBAL_GTT | |
| 855 | MI_SEMAPHORE_SAD_GTE_SDD; |
| 856 | *cs++ = signal->global_seqno; |
| 857 | *cs++ = lower_32_bits(offset); |
| 858 | *cs++ = upper_32_bits(offset); |
| 859 | intel_ring_advance(req, cs); |
Chris Wilson | 6ef48d7 | 2016-04-29 13:18:25 +0100 | [diff] [blame] | 860 | |
| 861 | /* When the !RCS engines idle waiting upon a semaphore, they lose their |
| 862 | * pagetables and we must reload them before executing the batch. |
| 863 | * We do this on the i915_switch_context() following the wait and |
| 864 | * before the dispatch. |
| 865 | */ |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 866 | ppgtt = req->ctx->ppgtt; |
| 867 | if (ppgtt && req->engine->id != RCS) |
| 868 | ppgtt->pd_dirty_rings |= intel_engine_flag(req->engine); |
Ben Widawsky | 5ee426c | 2014-06-30 09:53:38 -0700 | [diff] [blame] | 869 | return 0; |
| 870 | } |
| 871 | |
Ben Widawsky | c8c99b0 | 2011-09-14 20:32:47 -0700 | [diff] [blame] | 872 | static int |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 873 | gen6_ring_sync_to(struct drm_i915_gem_request *req, |
| 874 | struct drm_i915_gem_request *signal) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 875 | { |
Ben Widawsky | c8c99b0 | 2011-09-14 20:32:47 -0700 | [diff] [blame] | 876 | u32 dw1 = MI_SEMAPHORE_MBOX | |
| 877 | MI_SEMAPHORE_COMPARE | |
| 878 | MI_SEMAPHORE_REGISTER; |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 879 | u32 wait_mbox = signal->engine->semaphore.mbox.wait[req->engine->hw_id]; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 880 | u32 *cs; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 881 | |
Chris Wilson | ddf07be | 2016-08-02 22:50:39 +0100 | [diff] [blame] | 882 | WARN_ON(wait_mbox == MI_SEMAPHORE_SYNC_INVALID); |
| 883 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 884 | cs = intel_ring_begin(req, 4); |
| 885 | if (IS_ERR(cs)) |
| 886 | return PTR_ERR(cs); |
Chris Wilson | ddf07be | 2016-08-02 22:50:39 +0100 | [diff] [blame] | 887 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 888 | *cs++ = dw1 | wait_mbox; |
Ben Widawsky | 1500f7e | 2012-04-11 11:18:21 -0700 | [diff] [blame] | 889 | /* Throughout all of the GEM code, seqno passed implies our current |
| 890 | * seqno is >= the last seqno executed. However for hardware the |
| 891 | * comparison is strictly greater than. |
| 892 | */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 893 | *cs++ = signal->global_seqno - 1; |
| 894 | *cs++ = 0; |
| 895 | *cs++ = MI_NOOP; |
| 896 | intel_ring_advance(req, cs); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 897 | |
| 898 | return 0; |
| 899 | } |
| 900 | |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 901 | static void |
Dave Gordon | 38a0f2d | 2016-07-20 18:16:06 +0100 | [diff] [blame] | 902 | gen5_seqno_barrier(struct intel_engine_cs *engine) |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 903 | { |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 904 | /* MI_STORE are internally buffered by the GPU and not flushed |
| 905 | * either by MI_FLUSH or SyncFlush or any other combination of |
| 906 | * MI commands. |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 907 | * |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 908 | * "Only the submission of the store operation is guaranteed. |
| 909 | * The write result will be complete (coherent) some time later |
| 910 | * (this is practically a finite period but there is no guaranteed |
| 911 | * latency)." |
| 912 | * |
| 913 | * Empirically, we observe that we need a delay of at least 75us to |
| 914 | * be sure that the seqno write is visible by the CPU. |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 915 | */ |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 916 | usleep_range(125, 250); |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Chris Wilson | c04e0f3 | 2016-04-09 10:57:54 +0100 | [diff] [blame] | 919 | static void |
| 920 | gen6_seqno_barrier(struct intel_engine_cs *engine) |
Daniel Vetter | 4cd53c0 | 2012-12-14 16:01:25 +0100 | [diff] [blame] | 921 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 922 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | bcbdb6d | 2016-04-27 09:02:01 +0100 | [diff] [blame] | 923 | |
Daniel Vetter | 4cd53c0 | 2012-12-14 16:01:25 +0100 | [diff] [blame] | 924 | /* Workaround to force correct ordering between irq and seqno writes on |
| 925 | * 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] | 926 | * ACTHD) before reading the status page. |
| 927 | * |
| 928 | * Note that this effectively stalls the read by the time it takes to |
| 929 | * do a memory transaction, which more or less ensures that the write |
| 930 | * from the GPU has sufficient time to invalidate the CPU cacheline. |
| 931 | * Alternatively we could delay the interrupt from the CS ring to give |
| 932 | * the write time to land, but that would incur a delay after every |
| 933 | * batch i.e. much more frequent than a delay when waiting for the |
| 934 | * interrupt (with the same net latency). |
Chris Wilson | bcbdb6d | 2016-04-27 09:02:01 +0100 | [diff] [blame] | 935 | * |
| 936 | * Also note that to prevent whole machine hangs on gen7, we have to |
| 937 | * take the spinlock to guard against concurrent cacheline access. |
Chris Wilson | 9b9ed30 | 2016-04-09 10:57:53 +0100 | [diff] [blame] | 938 | */ |
Chris Wilson | bcbdb6d | 2016-04-27 09:02:01 +0100 | [diff] [blame] | 939 | spin_lock_irq(&dev_priv->uncore.lock); |
Chris Wilson | c04e0f3 | 2016-04-09 10:57:54 +0100 | [diff] [blame] | 940 | POSTING_READ_FW(RING_ACTHD(engine->mmio_base)); |
Chris Wilson | bcbdb6d | 2016-04-27 09:02:01 +0100 | [diff] [blame] | 941 | spin_unlock_irq(&dev_priv->uncore.lock); |
Daniel Vetter | 4cd53c0 | 2012-12-14 16:01:25 +0100 | [diff] [blame] | 942 | } |
| 943 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 944 | static void |
| 945 | gen5_irq_enable(struct intel_engine_cs *engine) |
Daniel Vetter | e48d863 | 2012-04-11 22:12:54 +0200 | [diff] [blame] | 946 | { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 947 | gen5_enable_gt_irq(engine->i915, engine->irq_enable_mask); |
Daniel Vetter | e48d863 | 2012-04-11 22:12:54 +0200 | [diff] [blame] | 948 | } |
| 949 | |
| 950 | static void |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 951 | gen5_irq_disable(struct intel_engine_cs *engine) |
Daniel Vetter | e48d863 | 2012-04-11 22:12:54 +0200 | [diff] [blame] | 952 | { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 953 | gen5_disable_gt_irq(engine->i915, engine->irq_enable_mask); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 956 | static void |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 957 | i9xx_irq_enable(struct intel_engine_cs *engine) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 958 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 959 | struct drm_i915_private *dev_priv = engine->i915; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 960 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 961 | dev_priv->irq_mask &= ~engine->irq_enable_mask; |
| 962 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 963 | POSTING_READ_FW(RING_IMR(engine->mmio_base)); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 964 | } |
| 965 | |
| 966 | static void |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 967 | i9xx_irq_disable(struct intel_engine_cs *engine) |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 968 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 969 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 970 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 971 | dev_priv->irq_mask |= engine->irq_enable_mask; |
| 972 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 973 | } |
| 974 | |
| 975 | static void |
| 976 | i8xx_irq_enable(struct intel_engine_cs *engine) |
| 977 | { |
| 978 | struct drm_i915_private *dev_priv = engine->i915; |
| 979 | |
| 980 | dev_priv->irq_mask &= ~engine->irq_enable_mask; |
| 981 | I915_WRITE16(IMR, dev_priv->irq_mask); |
| 982 | POSTING_READ16(RING_IMR(engine->mmio_base)); |
| 983 | } |
| 984 | |
| 985 | static void |
| 986 | i8xx_irq_disable(struct intel_engine_cs *engine) |
| 987 | { |
| 988 | struct drm_i915_private *dev_priv = engine->i915; |
| 989 | |
| 990 | dev_priv->irq_mask |= engine->irq_enable_mask; |
| 991 | I915_WRITE16(IMR, dev_priv->irq_mask); |
Chris Wilson | c2798b1 | 2012-04-22 21:13:57 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 994 | static int |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 995 | bsd_ring_flush(struct drm_i915_gem_request *req, u32 mode) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 996 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 997 | u32 *cs; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 998 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 999 | cs = intel_ring_begin(req, 2); |
| 1000 | if (IS_ERR(cs)) |
| 1001 | return PTR_ERR(cs); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1002 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1003 | *cs++ = MI_FLUSH; |
| 1004 | *cs++ = MI_NOOP; |
| 1005 | intel_ring_advance(req, cs); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1006 | return 0; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1009 | static void |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1010 | gen6_irq_enable(struct intel_engine_cs *engine) |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1011 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1012 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1013 | |
Chris Wilson | 61ff75a | 2016-07-01 17:23:28 +0100 | [diff] [blame] | 1014 | I915_WRITE_IMR(engine, |
| 1015 | ~(engine->irq_enable_mask | |
| 1016 | engine->irq_keep_mask)); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1017 | gen5_enable_gt_irq(dev_priv, engine->irq_enable_mask); |
Ben Widawsky | a19d293 | 2013-05-28 19:22:30 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | static void |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1021 | gen6_irq_disable(struct intel_engine_cs *engine) |
Ben Widawsky | a19d293 | 2013-05-28 19:22:30 -0700 | [diff] [blame] | 1022 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1023 | struct drm_i915_private *dev_priv = engine->i915; |
Ben Widawsky | a19d293 | 2013-05-28 19:22:30 -0700 | [diff] [blame] | 1024 | |
Chris Wilson | 61ff75a | 2016-07-01 17:23:28 +0100 | [diff] [blame] | 1025 | I915_WRITE_IMR(engine, ~engine->irq_keep_mask); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1026 | gen5_disable_gt_irq(dev_priv, engine->irq_enable_mask); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1027 | } |
| 1028 | |
| 1029 | static void |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1030 | hsw_vebox_irq_enable(struct intel_engine_cs *engine) |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1031 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1032 | struct drm_i915_private *dev_priv = engine->i915; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1033 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1034 | I915_WRITE_IMR(engine, ~engine->irq_enable_mask); |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 1035 | gen6_unmask_pm_irq(dev_priv, engine->irq_enable_mask); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | static void |
| 1039 | hsw_vebox_irq_disable(struct intel_engine_cs *engine) |
| 1040 | { |
| 1041 | struct drm_i915_private *dev_priv = engine->i915; |
| 1042 | |
| 1043 | I915_WRITE_IMR(engine, ~0); |
Akash Goel | f4e9af4 | 2016-10-12 21:54:30 +0530 | [diff] [blame] | 1044 | gen6_mask_pm_irq(dev_priv, engine->irq_enable_mask); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | static void |
| 1048 | gen8_irq_enable(struct intel_engine_cs *engine) |
| 1049 | { |
| 1050 | struct drm_i915_private *dev_priv = engine->i915; |
| 1051 | |
Chris Wilson | 61ff75a | 2016-07-01 17:23:28 +0100 | [diff] [blame] | 1052 | I915_WRITE_IMR(engine, |
| 1053 | ~(engine->irq_enable_mask | |
| 1054 | engine->irq_keep_mask)); |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1055 | POSTING_READ_FW(RING_IMR(engine->mmio_base)); |
| 1056 | } |
| 1057 | |
| 1058 | static void |
| 1059 | gen8_irq_disable(struct intel_engine_cs *engine) |
| 1060 | { |
| 1061 | struct drm_i915_private *dev_priv = engine->i915; |
| 1062 | |
Chris Wilson | 61ff75a | 2016-07-01 17:23:28 +0100 | [diff] [blame] | 1063 | I915_WRITE_IMR(engine, ~engine->irq_keep_mask); |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1066 | static int |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1067 | i965_emit_bb_start(struct drm_i915_gem_request *req, |
| 1068 | u64 offset, u32 length, |
| 1069 | unsigned int dispatch_flags) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1070 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1071 | u32 *cs; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1072 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1073 | cs = intel_ring_begin(req, 2); |
| 1074 | if (IS_ERR(cs)) |
| 1075 | return PTR_ERR(cs); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1076 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1077 | *cs++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT | (dispatch_flags & |
| 1078 | I915_DISPATCH_SECURE ? 0 : MI_BATCH_NON_SECURE_I965); |
| 1079 | *cs++ = offset; |
| 1080 | intel_ring_advance(req, cs); |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1081 | |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1082 | return 0; |
| 1083 | } |
| 1084 | |
Daniel Vetter | b45305f | 2012-12-17 16:21:27 +0100 | [diff] [blame] | 1085 | /* Just userspace ABI convention to limit the wa batch bo to a resonable size */ |
| 1086 | #define I830_BATCH_LIMIT (256*1024) |
Chris Wilson | c4d69da | 2014-09-08 14:25:41 +0100 | [diff] [blame] | 1087 | #define I830_TLB_ENTRIES (2) |
| 1088 | #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] | 1089 | static int |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1090 | i830_emit_bb_start(struct drm_i915_gem_request *req, |
| 1091 | u64 offset, u32 len, |
| 1092 | unsigned int dispatch_flags) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1093 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1094 | u32 *cs, cs_offset = i915_ggtt_offset(req->engine->scratch); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1095 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1096 | cs = intel_ring_begin(req, 6); |
| 1097 | if (IS_ERR(cs)) |
| 1098 | return PTR_ERR(cs); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1099 | |
Chris Wilson | c4d69da | 2014-09-08 14:25:41 +0100 | [diff] [blame] | 1100 | /* Evict the invalid PTE TLBs */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1101 | *cs++ = COLOR_BLT_CMD | BLT_WRITE_RGBA; |
| 1102 | *cs++ = BLT_DEPTH_32 | BLT_ROP_COLOR_COPY | 4096; |
| 1103 | *cs++ = I830_TLB_ENTRIES << 16 | 4; /* load each page */ |
| 1104 | *cs++ = cs_offset; |
| 1105 | *cs++ = 0xdeadbeef; |
| 1106 | *cs++ = MI_NOOP; |
| 1107 | intel_ring_advance(req, cs); |
Daniel Vetter | b45305f | 2012-12-17 16:21:27 +0100 | [diff] [blame] | 1108 | |
John Harrison | 8e004ef | 2015-02-13 11:48:10 +0000 | [diff] [blame] | 1109 | if ((dispatch_flags & I915_DISPATCH_PINNED) == 0) { |
Daniel Vetter | b45305f | 2012-12-17 16:21:27 +0100 | [diff] [blame] | 1110 | if (len > I830_BATCH_LIMIT) |
| 1111 | return -ENOSPC; |
| 1112 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1113 | cs = intel_ring_begin(req, 6 + 2); |
| 1114 | if (IS_ERR(cs)) |
| 1115 | return PTR_ERR(cs); |
Chris Wilson | c4d69da | 2014-09-08 14:25:41 +0100 | [diff] [blame] | 1116 | |
| 1117 | /* Blit the batch (which has now all relocs applied) to the |
| 1118 | * stable batch scratch bo area (so that the CS never |
| 1119 | * stumbles over its tlb invalidation bug) ... |
| 1120 | */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1121 | *cs++ = SRC_COPY_BLT_CMD | BLT_WRITE_RGBA; |
| 1122 | *cs++ = BLT_DEPTH_32 | BLT_ROP_SRC_COPY | 4096; |
| 1123 | *cs++ = DIV_ROUND_UP(len, 4096) << 16 | 4096; |
| 1124 | *cs++ = cs_offset; |
| 1125 | *cs++ = 4096; |
| 1126 | *cs++ = offset; |
Chris Wilson | c4d69da | 2014-09-08 14:25:41 +0100 | [diff] [blame] | 1127 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1128 | *cs++ = MI_FLUSH; |
| 1129 | *cs++ = MI_NOOP; |
| 1130 | intel_ring_advance(req, cs); |
Daniel Vetter | b45305f | 2012-12-17 16:21:27 +0100 | [diff] [blame] | 1131 | |
| 1132 | /* ... and execute it. */ |
Chris Wilson | c4d69da | 2014-09-08 14:25:41 +0100 | [diff] [blame] | 1133 | offset = cs_offset; |
Daniel Vetter | b45305f | 2012-12-17 16:21:27 +0100 | [diff] [blame] | 1134 | } |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1135 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1136 | cs = intel_ring_begin(req, 2); |
| 1137 | if (IS_ERR(cs)) |
| 1138 | return PTR_ERR(cs); |
Chris Wilson | c4d69da | 2014-09-08 14:25:41 +0100 | [diff] [blame] | 1139 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1140 | *cs++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT; |
| 1141 | *cs++ = offset | (dispatch_flags & I915_DISPATCH_SECURE ? 0 : |
| 1142 | MI_BATCH_NON_SECURE); |
| 1143 | intel_ring_advance(req, cs); |
Chris Wilson | c4d69da | 2014-09-08 14:25:41 +0100 | [diff] [blame] | 1144 | |
Daniel Vetter | fb3256d | 2012-04-11 22:12:56 +0200 | [diff] [blame] | 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | static int |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1149 | i915_emit_bb_start(struct drm_i915_gem_request *req, |
| 1150 | u64 offset, u32 len, |
| 1151 | unsigned int dispatch_flags) |
Daniel Vetter | fb3256d | 2012-04-11 22:12:56 +0200 | [diff] [blame] | 1152 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1153 | u32 *cs; |
Daniel Vetter | fb3256d | 2012-04-11 22:12:56 +0200 | [diff] [blame] | 1154 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1155 | cs = intel_ring_begin(req, 2); |
| 1156 | if (IS_ERR(cs)) |
| 1157 | return PTR_ERR(cs); |
Daniel Vetter | fb3256d | 2012-04-11 22:12:56 +0200 | [diff] [blame] | 1158 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1159 | *cs++ = MI_BATCH_BUFFER_START | MI_BATCH_GTT; |
| 1160 | *cs++ = offset | (dispatch_flags & I915_DISPATCH_SECURE ? 0 : |
| 1161 | MI_BATCH_NON_SECURE); |
| 1162 | intel_ring_advance(req, cs); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1163 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1164 | return 0; |
| 1165 | } |
| 1166 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1167 | static void cleanup_phys_status_page(struct intel_engine_cs *engine) |
Ville Syrjälä | 7d3fdff | 2016-01-11 20:48:32 +0200 | [diff] [blame] | 1168 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1169 | struct drm_i915_private *dev_priv = engine->i915; |
Ville Syrjälä | 7d3fdff | 2016-01-11 20:48:32 +0200 | [diff] [blame] | 1170 | |
| 1171 | if (!dev_priv->status_page_dmah) |
| 1172 | return; |
| 1173 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1174 | drm_pci_free(&dev_priv->drm, dev_priv->status_page_dmah); |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1175 | engine->status_page.page_addr = NULL; |
Ville Syrjälä | 7d3fdff | 2016-01-11 20:48:32 +0200 | [diff] [blame] | 1176 | } |
| 1177 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1178 | static void cleanup_status_page(struct intel_engine_cs *engine) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1179 | { |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1180 | struct i915_vma *vma; |
Chris Wilson | f8a7fde | 2016-10-28 13:58:29 +0100 | [diff] [blame] | 1181 | struct drm_i915_gem_object *obj; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1182 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1183 | vma = fetch_and_zero(&engine->status_page.vma); |
| 1184 | if (!vma) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1185 | return; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1186 | |
Chris Wilson | f8a7fde | 2016-10-28 13:58:29 +0100 | [diff] [blame] | 1187 | obj = vma->obj; |
| 1188 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1189 | i915_vma_unpin(vma); |
Chris Wilson | f8a7fde | 2016-10-28 13:58:29 +0100 | [diff] [blame] | 1190 | i915_vma_close(vma); |
| 1191 | |
| 1192 | i915_gem_object_unpin_map(obj); |
| 1193 | __i915_gem_object_release_unless_active(obj); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1196 | static int init_status_page(struct intel_engine_cs *engine) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1197 | { |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1198 | struct drm_i915_gem_object *obj; |
| 1199 | struct i915_vma *vma; |
| 1200 | unsigned int flags; |
Chris Wilson | 920cf41 | 2016-10-28 13:58:30 +0100 | [diff] [blame] | 1201 | void *vaddr; |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1202 | int ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1203 | |
Chris Wilson | f51455d | 2017-01-10 14:47:34 +0000 | [diff] [blame] | 1204 | obj = i915_gem_object_create_internal(engine->i915, PAGE_SIZE); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1205 | if (IS_ERR(obj)) { |
| 1206 | DRM_ERROR("Failed to allocate status page\n"); |
| 1207 | return PTR_ERR(obj); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1208 | } |
Chris Wilson | e4ffd17 | 2011-04-04 09:44:39 +0100 | [diff] [blame] | 1209 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1210 | ret = i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); |
| 1211 | if (ret) |
| 1212 | goto err; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1213 | |
Chris Wilson | a01cb37 | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 1214 | vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1215 | if (IS_ERR(vma)) { |
| 1216 | ret = PTR_ERR(vma); |
| 1217 | goto err; |
| 1218 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1219 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1220 | flags = PIN_GLOBAL; |
| 1221 | if (!HAS_LLC(engine->i915)) |
| 1222 | /* On g33, we cannot place HWS above 256MiB, so |
| 1223 | * restrict its pinning to the low mappable arena. |
| 1224 | * Though this restriction is not documented for |
| 1225 | * gen4, gen5, or byt, they also behave similarly |
| 1226 | * and hang if the HWS is placed at the top of the |
| 1227 | * GTT. To generalise, it appears that all !llc |
| 1228 | * platforms have issues with us placing the HWS |
| 1229 | * above the mappable region (even though we never |
| 1230 | * actualy map it). |
| 1231 | */ |
| 1232 | flags |= PIN_MAPPABLE; |
| 1233 | ret = i915_vma_pin(vma, 0, 4096, flags); |
| 1234 | if (ret) |
| 1235 | goto err; |
| 1236 | |
Chris Wilson | 920cf41 | 2016-10-28 13:58:30 +0100 | [diff] [blame] | 1237 | vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB); |
| 1238 | if (IS_ERR(vaddr)) { |
| 1239 | ret = PTR_ERR(vaddr); |
| 1240 | goto err_unpin; |
| 1241 | } |
| 1242 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1243 | engine->status_page.vma = vma; |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1244 | engine->status_page.ggtt_offset = i915_ggtt_offset(vma); |
Chris Wilson | f51455d | 2017-01-10 14:47:34 +0000 | [diff] [blame] | 1245 | engine->status_page.page_addr = memset(vaddr, 0, PAGE_SIZE); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1246 | |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1247 | DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", |
| 1248 | engine->name, i915_ggtt_offset(vma)); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1249 | return 0; |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1250 | |
Chris Wilson | 920cf41 | 2016-10-28 13:58:30 +0100 | [diff] [blame] | 1251 | err_unpin: |
| 1252 | i915_vma_unpin(vma); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1253 | err: |
| 1254 | i915_gem_object_put(obj); |
| 1255 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1256 | } |
| 1257 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1258 | static int init_phys_status_page(struct intel_engine_cs *engine) |
Chris Wilson | 6b8294a | 2012-11-16 11:43:20 +0000 | [diff] [blame] | 1259 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1260 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 6b8294a | 2012-11-16 11:43:20 +0000 | [diff] [blame] | 1261 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1262 | dev_priv->status_page_dmah = |
| 1263 | drm_pci_alloc(&dev_priv->drm, PAGE_SIZE, PAGE_SIZE); |
| 1264 | if (!dev_priv->status_page_dmah) |
| 1265 | return -ENOMEM; |
Chris Wilson | 6b8294a | 2012-11-16 11:43:20 +0000 | [diff] [blame] | 1266 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1267 | engine->status_page.page_addr = dev_priv->status_page_dmah->vaddr; |
| 1268 | memset(engine->status_page.page_addr, 0, PAGE_SIZE); |
Chris Wilson | 6b8294a | 2012-11-16 11:43:20 +0000 | [diff] [blame] | 1269 | |
| 1270 | return 0; |
| 1271 | } |
| 1272 | |
Daniele Ceraolo Spurio | d3ef1af | 2016-12-23 15:56:21 -0800 | [diff] [blame] | 1273 | int intel_ring_pin(struct intel_ring *ring, unsigned int offset_bias) |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1274 | { |
Daniele Ceraolo Spurio | d3ef1af | 2016-12-23 15:56:21 -0800 | [diff] [blame] | 1275 | unsigned int flags; |
Chris Wilson | 9d80841 | 2016-08-18 17:16:56 +0100 | [diff] [blame] | 1276 | enum i915_map_type map; |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1277 | struct i915_vma *vma = ring->vma; |
Dave Gordon | 8305216 | 2016-04-12 14:46:16 +0100 | [diff] [blame] | 1278 | void *addr; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1279 | int ret; |
| 1280 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1281 | GEM_BUG_ON(ring->vaddr); |
| 1282 | |
Chris Wilson | 9d80841 | 2016-08-18 17:16:56 +0100 | [diff] [blame] | 1283 | map = HAS_LLC(ring->engine->i915) ? I915_MAP_WB : I915_MAP_WC; |
| 1284 | |
Daniele Ceraolo Spurio | d3ef1af | 2016-12-23 15:56:21 -0800 | [diff] [blame] | 1285 | flags = PIN_GLOBAL; |
| 1286 | if (offset_bias) |
| 1287 | flags |= PIN_OFFSET_BIAS | offset_bias; |
Chris Wilson | 9d80841 | 2016-08-18 17:16:56 +0100 | [diff] [blame] | 1288 | if (vma->obj->stolen) |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1289 | flags |= PIN_MAPPABLE; |
| 1290 | |
| 1291 | if (!(vma->flags & I915_VMA_GLOBAL_BIND)) { |
Chris Wilson | 9d80841 | 2016-08-18 17:16:56 +0100 | [diff] [blame] | 1292 | if (flags & PIN_MAPPABLE || map == I915_MAP_WC) |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1293 | ret = i915_gem_object_set_to_gtt_domain(vma->obj, true); |
| 1294 | else |
| 1295 | ret = i915_gem_object_set_to_cpu_domain(vma->obj, true); |
| 1296 | if (unlikely(ret)) |
Chris Wilson | def0c5f | 2015-10-08 13:39:54 +0100 | [diff] [blame] | 1297 | return ret; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1300 | ret = i915_vma_pin(vma, 0, PAGE_SIZE, flags); |
| 1301 | if (unlikely(ret)) |
| 1302 | return ret; |
| 1303 | |
Chris Wilson | 9d80841 | 2016-08-18 17:16:56 +0100 | [diff] [blame] | 1304 | if (i915_vma_is_map_and_fenceable(vma)) |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1305 | addr = (void __force *)i915_vma_pin_iomap(vma); |
| 1306 | else |
Chris Wilson | 9d80841 | 2016-08-18 17:16:56 +0100 | [diff] [blame] | 1307 | addr = i915_gem_object_pin_map(vma->obj, map); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1308 | if (IS_ERR(addr)) |
| 1309 | goto err; |
| 1310 | |
Chris Wilson | 32c04f1 | 2016-08-02 22:50:22 +0100 | [diff] [blame] | 1311 | ring->vaddr = addr; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1312 | return 0; |
Chris Wilson | d2cad53 | 2016-04-08 12:11:10 +0100 | [diff] [blame] | 1313 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1314 | err: |
| 1315 | i915_vma_unpin(vma); |
| 1316 | return PTR_ERR(addr); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Chris Wilson | aad29fb | 2016-08-02 22:50:23 +0100 | [diff] [blame] | 1319 | void intel_ring_unpin(struct intel_ring *ring) |
| 1320 | { |
| 1321 | GEM_BUG_ON(!ring->vma); |
| 1322 | GEM_BUG_ON(!ring->vaddr); |
| 1323 | |
Chris Wilson | 9d80841 | 2016-08-18 17:16:56 +0100 | [diff] [blame] | 1324 | if (i915_vma_is_map_and_fenceable(ring->vma)) |
Chris Wilson | aad29fb | 2016-08-02 22:50:23 +0100 | [diff] [blame] | 1325 | i915_vma_unpin_iomap(ring->vma); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1326 | else |
| 1327 | i915_gem_object_unpin_map(ring->vma->obj); |
Chris Wilson | aad29fb | 2016-08-02 22:50:23 +0100 | [diff] [blame] | 1328 | ring->vaddr = NULL; |
| 1329 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1330 | i915_vma_unpin(ring->vma); |
Chris Wilson | aad29fb | 2016-08-02 22:50:23 +0100 | [diff] [blame] | 1331 | } |
| 1332 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1333 | static struct i915_vma * |
| 1334 | intel_ring_create_vma(struct drm_i915_private *dev_priv, int size) |
Oscar Mateo | 2919d29 | 2014-07-03 16:28:02 +0100 | [diff] [blame] | 1335 | { |
Chris Wilson | e3efda4 | 2014-04-09 09:19:41 +0100 | [diff] [blame] | 1336 | struct drm_i915_gem_object *obj; |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1337 | struct i915_vma *vma; |
Chris Wilson | e3efda4 | 2014-04-09 09:19:41 +0100 | [diff] [blame] | 1338 | |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 1339 | obj = i915_gem_object_create_stolen(dev_priv, size); |
Chris Wilson | c58b735 | 2016-08-18 17:16:57 +0100 | [diff] [blame] | 1340 | if (!obj) |
Tvrtko Ursulin | 12d79d7 | 2016-12-01 14:16:37 +0000 | [diff] [blame] | 1341 | obj = i915_gem_object_create(dev_priv, size); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1342 | if (IS_ERR(obj)) |
| 1343 | return ERR_CAST(obj); |
Chris Wilson | e3efda4 | 2014-04-09 09:19:41 +0100 | [diff] [blame] | 1344 | |
Akash Goel | 24f3a8c | 2014-06-17 10:59:42 +0530 | [diff] [blame] | 1345 | /* mark ring buffers as read-only from GPU side by default */ |
| 1346 | obj->gt_ro = 1; |
| 1347 | |
Chris Wilson | a01cb37 | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 1348 | vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1349 | if (IS_ERR(vma)) |
| 1350 | goto err; |
Chris Wilson | e3efda4 | 2014-04-09 09:19:41 +0100 | [diff] [blame] | 1351 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1352 | return vma; |
| 1353 | |
| 1354 | err: |
| 1355 | i915_gem_object_put(obj); |
| 1356 | return vma; |
Chris Wilson | e3efda4 | 2014-04-09 09:19:41 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1359 | struct intel_ring * |
| 1360 | intel_engine_create_ring(struct intel_engine_cs *engine, int size) |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1361 | { |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1362 | struct intel_ring *ring; |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1363 | struct i915_vma *vma; |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1364 | |
Chris Wilson | 8f94201 | 2016-08-02 22:50:30 +0100 | [diff] [blame] | 1365 | GEM_BUG_ON(!is_power_of_2(size)); |
Chris Wilson | 62ae14b | 2016-10-04 21:11:25 +0100 | [diff] [blame] | 1366 | GEM_BUG_ON(RING_CTL_SIZE(size) & ~RING_NR_PAGES); |
Chris Wilson | 8f94201 | 2016-08-02 22:50:30 +0100 | [diff] [blame] | 1367 | |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1368 | ring = kzalloc(sizeof(*ring), GFP_KERNEL); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1369 | if (!ring) |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1370 | return ERR_PTR(-ENOMEM); |
| 1371 | |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 1372 | ring->engine = engine; |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1373 | |
Chris Wilson | 675d9ad | 2016-08-04 07:52:36 +0100 | [diff] [blame] | 1374 | INIT_LIST_HEAD(&ring->request_list); |
| 1375 | |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1376 | ring->size = size; |
| 1377 | /* Workaround an erratum on the i830 which causes a hang if |
| 1378 | * the TAIL pointer points to within the last 2 cachelines |
| 1379 | * of the buffer. |
| 1380 | */ |
| 1381 | ring->effective_size = size; |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 1382 | if (IS_I830(engine->i915) || IS_I845G(engine->i915)) |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1383 | ring->effective_size -= 2 * CACHELINE_BYTES; |
| 1384 | |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1385 | intel_ring_update_space(ring); |
| 1386 | |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1387 | vma = intel_ring_create_vma(engine->i915, size); |
| 1388 | if (IS_ERR(vma)) { |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1389 | kfree(ring); |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1390 | return ERR_CAST(vma); |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1391 | } |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1392 | ring->vma = vma; |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1393 | |
| 1394 | return ring; |
| 1395 | } |
| 1396 | |
| 1397 | void |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1398 | intel_ring_free(struct intel_ring *ring) |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1399 | { |
Chris Wilson | f8a7fde | 2016-10-28 13:58:29 +0100 | [diff] [blame] | 1400 | struct drm_i915_gem_object *obj = ring->vma->obj; |
| 1401 | |
| 1402 | i915_vma_close(ring->vma); |
| 1403 | __i915_gem_object_release_unless_active(obj); |
| 1404 | |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1405 | kfree(ring); |
| 1406 | } |
| 1407 | |
Chris Wilson | 72b72ae | 2017-02-10 10:14:22 +0000 | [diff] [blame] | 1408 | static int context_pin(struct i915_gem_context *ctx) |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1409 | { |
| 1410 | struct i915_vma *vma = ctx->engine[RCS].state; |
| 1411 | int ret; |
| 1412 | |
| 1413 | /* Clear this page out of any CPU caches for coherent swap-in/out. |
| 1414 | * We only want to do this on the first bind so that we do not stall |
| 1415 | * on an active context (which by nature is already on the GPU). |
| 1416 | */ |
| 1417 | if (!(vma->flags & I915_VMA_GLOBAL_BIND)) { |
| 1418 | ret = i915_gem_object_set_to_gtt_domain(vma->obj, false); |
| 1419 | if (ret) |
| 1420 | return ret; |
| 1421 | } |
| 1422 | |
Chris Wilson | afeddf5 | 2017-02-27 13:59:13 +0000 | [diff] [blame] | 1423 | return i915_vma_pin(vma, 0, I915_GTT_MIN_ALIGNMENT, |
| 1424 | PIN_GLOBAL | PIN_HIGH); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | static int intel_ring_context_pin(struct intel_engine_cs *engine, |
| 1428 | struct i915_gem_context *ctx) |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1429 | { |
| 1430 | struct intel_context *ce = &ctx->engine[engine->id]; |
| 1431 | int ret; |
| 1432 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1433 | lockdep_assert_held(&ctx->i915->drm.struct_mutex); |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1434 | |
| 1435 | if (ce->pin_count++) |
| 1436 | return 0; |
Chris Wilson | a533b4b | 2017-03-16 17:16:28 +0000 | [diff] [blame] | 1437 | GEM_BUG_ON(!ce->pin_count); /* no overflow please! */ |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1438 | |
| 1439 | if (ce->state) { |
Chris Wilson | 72b72ae | 2017-02-10 10:14:22 +0000 | [diff] [blame] | 1440 | ret = context_pin(ctx); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1441 | if (ret) |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1442 | goto error; |
Chris Wilson | 5d4bac5 | 2017-03-22 20:59:30 +0000 | [diff] [blame] | 1443 | |
| 1444 | ce->state->obj->mm.dirty = true; |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
Chris Wilson | c7c3c07 | 2016-06-24 14:55:54 +0100 | [diff] [blame] | 1447 | /* The kernel context is only used as a placeholder for flushing the |
| 1448 | * active context. It is never used for submitting user rendering and |
| 1449 | * as such never requires the golden render context, and so we can skip |
| 1450 | * emitting it when we switch to the kernel context. This is required |
| 1451 | * as during eviction we cannot allocate and pin the renderstate in |
| 1452 | * order to initialise the context. |
| 1453 | */ |
Chris Wilson | 984ff29f | 2017-01-06 15:20:13 +0000 | [diff] [blame] | 1454 | if (i915_gem_context_is_kernel(ctx)) |
Chris Wilson | c7c3c07 | 2016-06-24 14:55:54 +0100 | [diff] [blame] | 1455 | ce->initialised = true; |
| 1456 | |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 1457 | i915_gem_context_get(ctx); |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1458 | return 0; |
| 1459 | |
| 1460 | error: |
| 1461 | ce->pin_count = 0; |
| 1462 | return ret; |
| 1463 | } |
| 1464 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1465 | static void intel_ring_context_unpin(struct intel_engine_cs *engine, |
| 1466 | struct i915_gem_context *ctx) |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1467 | { |
| 1468 | struct intel_context *ce = &ctx->engine[engine->id]; |
| 1469 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1470 | lockdep_assert_held(&ctx->i915->drm.struct_mutex); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1471 | GEM_BUG_ON(ce->pin_count == 0); |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1472 | |
| 1473 | if (--ce->pin_count) |
| 1474 | return; |
| 1475 | |
| 1476 | if (ce->state) |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 1477 | i915_vma_unpin(ce->state); |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1478 | |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 1479 | i915_gem_context_put(ctx); |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1480 | } |
| 1481 | |
Tvrtko Ursulin | acd2784 | 2016-07-13 16:03:39 +0100 | [diff] [blame] | 1482 | static int intel_init_ring_buffer(struct intel_engine_cs *engine) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1483 | { |
Tvrtko Ursulin | acd2784 | 2016-07-13 16:03:39 +0100 | [diff] [blame] | 1484 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 32c04f1 | 2016-08-02 22:50:22 +0100 | [diff] [blame] | 1485 | struct intel_ring *ring; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 1486 | int ret; |
| 1487 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1488 | WARN_ON(engine->buffer); |
Daniel Vetter | bfc882b | 2014-11-20 00:33:08 +0100 | [diff] [blame] | 1489 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 1490 | intel_engine_setup_common(engine); |
| 1491 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 1492 | ret = intel_engine_init_common(engine); |
Chris Wilson | 688e6c7 | 2016-07-01 17:23:15 +0100 | [diff] [blame] | 1493 | if (ret) |
| 1494 | goto error; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1495 | |
Chris Wilson | 32c04f1 | 2016-08-02 22:50:22 +0100 | [diff] [blame] | 1496 | ring = intel_engine_create_ring(engine, 32 * PAGE_SIZE); |
| 1497 | if (IS_ERR(ring)) { |
| 1498 | ret = PTR_ERR(ring); |
Dave Gordon | b0366a5 | 2015-12-08 15:02:36 +0000 | [diff] [blame] | 1499 | goto error; |
| 1500 | } |
Chris Wilson | 01101fa | 2015-09-03 13:01:39 +0100 | [diff] [blame] | 1501 | |
Carlos Santa | 3177659 | 2016-08-17 12:30:56 -0700 | [diff] [blame] | 1502 | if (HWS_NEEDS_PHYSICAL(dev_priv)) { |
| 1503 | WARN_ON(engine->id != RCS); |
| 1504 | ret = init_phys_status_page(engine); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1505 | if (ret) |
Oscar Mateo | 8ee1497 | 2014-05-22 14:13:34 +0100 | [diff] [blame] | 1506 | goto error; |
Chris Wilson | 6b8294a | 2012-11-16 11:43:20 +0000 | [diff] [blame] | 1507 | } else { |
Carlos Santa | 3177659 | 2016-08-17 12:30:56 -0700 | [diff] [blame] | 1508 | ret = init_status_page(engine); |
Chris Wilson | 6b8294a | 2012-11-16 11:43:20 +0000 | [diff] [blame] | 1509 | if (ret) |
Oscar Mateo | 8ee1497 | 2014-05-22 14:13:34 +0100 | [diff] [blame] | 1510 | goto error; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1511 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1512 | |
Daniele Ceraolo Spurio | d3ef1af | 2016-12-23 15:56:21 -0800 | [diff] [blame] | 1513 | /* Ring wraparound at offset 0 sometimes hangs. No idea why. */ |
Chris Wilson | f51455d | 2017-01-10 14:47:34 +0000 | [diff] [blame] | 1514 | ret = intel_ring_pin(ring, I915_GTT_PAGE_SIZE); |
Daniel Vetter | bfc882b | 2014-11-20 00:33:08 +0100 | [diff] [blame] | 1515 | if (ret) { |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1516 | intel_ring_free(ring); |
Daniel Vetter | bfc882b | 2014-11-20 00:33:08 +0100 | [diff] [blame] | 1517 | goto error; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1518 | } |
Chris Wilson | 57e8853 | 2016-08-15 10:48:57 +0100 | [diff] [blame] | 1519 | engine->buffer = ring; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1520 | |
Oscar Mateo | 8ee1497 | 2014-05-22 14:13:34 +0100 | [diff] [blame] | 1521 | return 0; |
| 1522 | |
| 1523 | error: |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1524 | intel_engine_cleanup(engine); |
Oscar Mateo | 8ee1497 | 2014-05-22 14:13:34 +0100 | [diff] [blame] | 1525 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1528 | void intel_engine_cleanup(struct intel_engine_cs *engine) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1529 | { |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 1530 | struct drm_i915_private *dev_priv; |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 1531 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1532 | dev_priv = engine->i915; |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 1533 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1534 | if (engine->buffer) { |
Chris Wilson | 21a2c58 | 2016-08-15 10:49:11 +0100 | [diff] [blame] | 1535 | WARN_ON(INTEL_GEN(dev_priv) > 2 && |
| 1536 | (I915_READ_MODE(engine) & MODE_IDLE) == 0); |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 1537 | |
Chris Wilson | aad29fb | 2016-08-02 22:50:23 +0100 | [diff] [blame] | 1538 | intel_ring_unpin(engine->buffer); |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1539 | intel_ring_free(engine->buffer); |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1540 | engine->buffer = NULL; |
Dave Gordon | b0366a5 | 2015-12-08 15:02:36 +0000 | [diff] [blame] | 1541 | } |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1542 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1543 | if (engine->cleanup) |
| 1544 | engine->cleanup(engine); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1545 | |
Carlos Santa | 3177659 | 2016-08-17 12:30:56 -0700 | [diff] [blame] | 1546 | if (HWS_NEEDS_PHYSICAL(dev_priv)) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1547 | WARN_ON(engine->id != RCS); |
| 1548 | cleanup_phys_status_page(engine); |
Carlos Santa | 3177659 | 2016-08-17 12:30:56 -0700 | [diff] [blame] | 1549 | } else { |
| 1550 | cleanup_status_page(engine); |
Ville Syrjälä | 7d3fdff | 2016-01-11 20:48:32 +0200 | [diff] [blame] | 1551 | } |
Brad Volkin | 44e895a | 2014-05-10 14:10:43 -0700 | [diff] [blame] | 1552 | |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 1553 | intel_engine_cleanup_common(engine); |
Chris Wilson | 0cb26a8 | 2016-06-24 14:55:53 +0100 | [diff] [blame] | 1554 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1555 | engine->i915 = NULL; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1556 | dev_priv->engine[engine->id] = NULL; |
| 1557 | kfree(engine); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1560 | void intel_legacy_submission_resume(struct drm_i915_private *dev_priv) |
| 1561 | { |
| 1562 | struct intel_engine_cs *engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1563 | enum intel_engine_id id; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1564 | |
Chris Wilson | fe085f1 | 2017-03-21 10:25:52 +0000 | [diff] [blame] | 1565 | for_each_engine(engine, dev_priv, id) |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1566 | engine->buffer->head = engine->buffer->tail; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
Chris Wilson | f73e739 | 2016-12-18 15:37:24 +0000 | [diff] [blame] | 1569 | static int ring_request_alloc(struct drm_i915_gem_request *request) |
Chris Wilson | 9d773091 | 2012-11-27 16:22:52 +0000 | [diff] [blame] | 1570 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1571 | u32 *cs; |
Chris Wilson | 6310346 | 2016-04-28 09:56:49 +0100 | [diff] [blame] | 1572 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1573 | GEM_BUG_ON(!request->ctx->engine[request->engine->id].pin_count); |
| 1574 | |
Chris Wilson | 6310346 | 2016-04-28 09:56:49 +0100 | [diff] [blame] | 1575 | /* Flush enough space to reduce the likelihood of waiting after |
| 1576 | * we start building the request - in which case we will just |
| 1577 | * have to repeat work. |
| 1578 | */ |
Chris Wilson | a044246 | 2016-04-29 09:07:05 +0100 | [diff] [blame] | 1579 | request->reserved_space += LEGACY_REQUEST_SIZE; |
Chris Wilson | 6310346 | 2016-04-28 09:56:49 +0100 | [diff] [blame] | 1580 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1581 | GEM_BUG_ON(!request->engine->buffer); |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1582 | request->ring = request->engine->buffer; |
Chris Wilson | 6310346 | 2016-04-28 09:56:49 +0100 | [diff] [blame] | 1583 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1584 | cs = intel_ring_begin(request, 0); |
| 1585 | if (IS_ERR(cs)) |
| 1586 | return PTR_ERR(cs); |
Chris Wilson | 6310346 | 2016-04-28 09:56:49 +0100 | [diff] [blame] | 1587 | |
Chris Wilson | a044246 | 2016-04-29 09:07:05 +0100 | [diff] [blame] | 1588 | request->reserved_space -= LEGACY_REQUEST_SIZE; |
Chris Wilson | 6310346 | 2016-04-28 09:56:49 +0100 | [diff] [blame] | 1589 | return 0; |
Chris Wilson | 9d773091 | 2012-11-27 16:22:52 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1592 | 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] | 1593 | { |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1594 | struct intel_ring *ring = req->ring; |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1595 | struct drm_i915_gem_request *target; |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 1596 | long timeout; |
| 1597 | |
| 1598 | lockdep_assert_held(&req->i915->drm.struct_mutex); |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1599 | |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1600 | intel_ring_update_space(ring); |
| 1601 | if (ring->space >= bytes) |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1602 | return 0; |
| 1603 | |
| 1604 | /* |
| 1605 | * Space is reserved in the ringbuffer for finalising the request, |
| 1606 | * as that cannot be allowed to fail. During request finalisation, |
| 1607 | * reserved_space is set to 0 to stop the overallocation and the |
| 1608 | * assumption is that then we never need to wait (which has the |
| 1609 | * risk of failing with EINTR). |
| 1610 | * |
| 1611 | * See also i915_gem_request_alloc() and i915_add_request(). |
| 1612 | */ |
Chris Wilson | 0251a96 | 2016-04-28 09:56:47 +0100 | [diff] [blame] | 1613 | GEM_BUG_ON(!req->reserved_space); |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1614 | |
Chris Wilson | 675d9ad | 2016-08-04 07:52:36 +0100 | [diff] [blame] | 1615 | list_for_each_entry(target, &ring->request_list, ring_link) { |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1616 | unsigned space; |
| 1617 | |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1618 | /* Would completion of this request free enough space? */ |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1619 | space = __intel_ring_space(target->postfix, ring->tail, |
| 1620 | ring->size); |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1621 | if (space >= bytes) |
| 1622 | break; |
| 1623 | } |
| 1624 | |
Chris Wilson | 675d9ad | 2016-08-04 07:52:36 +0100 | [diff] [blame] | 1625 | if (WARN_ON(&target->ring_link == &ring->request_list)) |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1626 | return -ENOSPC; |
| 1627 | |
Chris Wilson | e95433c | 2016-10-28 13:58:27 +0100 | [diff] [blame] | 1628 | timeout = i915_wait_request(target, |
| 1629 | I915_WAIT_INTERRUPTIBLE | I915_WAIT_LOCKED, |
| 1630 | MAX_SCHEDULE_TIMEOUT); |
| 1631 | if (timeout < 0) |
| 1632 | return timeout; |
Chris Wilson | 7da844c | 2016-08-04 07:52:38 +0100 | [diff] [blame] | 1633 | |
Chris Wilson | 7da844c | 2016-08-04 07:52:38 +0100 | [diff] [blame] | 1634 | i915_gem_request_retire_upto(target); |
| 1635 | |
| 1636 | intel_ring_update_space(ring); |
| 1637 | GEM_BUG_ON(ring->space < bytes); |
| 1638 | return 0; |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1639 | } |
| 1640 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1641 | u32 *intel_ring_begin(struct drm_i915_gem_request *req, int num_dwords) |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1642 | { |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 1643 | struct intel_ring *ring = req->ring; |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1644 | int remain_actual = ring->size - ring->tail; |
| 1645 | int remain_usable = ring->effective_size - ring->tail; |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1646 | int bytes = num_dwords * sizeof(u32); |
| 1647 | int total_bytes, wait_bytes; |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 1648 | bool need_wrap = false; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1649 | u32 *cs; |
Mika Kuoppala | cbcc80d | 2012-12-04 15:12:03 +0200 | [diff] [blame] | 1650 | |
Chris Wilson | 0251a96 | 2016-04-28 09:56:47 +0100 | [diff] [blame] | 1651 | total_bytes = bytes + req->reserved_space; |
John Harrison | 29b1b41 | 2015-06-18 13:10:09 +0100 | [diff] [blame] | 1652 | |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 1653 | if (unlikely(bytes > remain_usable)) { |
| 1654 | /* |
| 1655 | * Not enough space for the basic request. So need to flush |
| 1656 | * out the remainder and then wait for base + reserved. |
| 1657 | */ |
| 1658 | wait_bytes = remain_actual + total_bytes; |
| 1659 | need_wrap = true; |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1660 | } else if (unlikely(total_bytes > remain_usable)) { |
| 1661 | /* |
| 1662 | * The base request will fit but the reserved space |
| 1663 | * falls off the end. So we don't need an immediate wrap |
| 1664 | * and only need to effectively wait for the reserved |
| 1665 | * size space from the start of ringbuffer. |
| 1666 | */ |
Chris Wilson | 0251a96 | 2016-04-28 09:56:47 +0100 | [diff] [blame] | 1667 | wait_bytes = remain_actual + req->reserved_space; |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 1668 | } else { |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1669 | /* No wrapping required, just waiting. */ |
| 1670 | wait_bytes = total_bytes; |
Mika Kuoppala | cbcc80d | 2012-12-04 15:12:03 +0200 | [diff] [blame] | 1671 | } |
| 1672 | |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1673 | if (wait_bytes > ring->space) { |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1674 | int ret = wait_for_space(req, wait_bytes); |
Mika Kuoppala | cbcc80d | 2012-12-04 15:12:03 +0200 | [diff] [blame] | 1675 | if (unlikely(ret)) |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1676 | return ERR_PTR(ret); |
Mika Kuoppala | cbcc80d | 2012-12-04 15:12:03 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1679 | if (unlikely(need_wrap)) { |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1680 | GEM_BUG_ON(remain_actual > ring->space); |
| 1681 | GEM_BUG_ON(ring->tail + remain_actual > ring->size); |
Mika Kuoppala | cbcc80d | 2012-12-04 15:12:03 +0200 | [diff] [blame] | 1682 | |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1683 | /* Fill the tail with MI_NOOP */ |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1684 | memset(ring->vaddr + ring->tail, 0, remain_actual); |
| 1685 | ring->tail = 0; |
| 1686 | ring->space -= remain_actual; |
Chris Wilson | 987046a | 2016-04-28 09:56:46 +0100 | [diff] [blame] | 1687 | } |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1688 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1689 | GEM_BUG_ON(ring->tail > ring->size - bytes); |
| 1690 | cs = ring->vaddr + ring->tail; |
| 1691 | ring->tail += bytes; |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1692 | ring->space -= bytes; |
| 1693 | GEM_BUG_ON(ring->space < 0); |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1694 | |
| 1695 | return cs; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1696 | } |
| 1697 | |
Ville Syrjälä | 753b1ad | 2014-02-11 19:52:05 +0200 | [diff] [blame] | 1698 | /* Align the ring tail to a cacheline boundary */ |
John Harrison | bba09b1 | 2015-05-29 17:44:06 +0100 | [diff] [blame] | 1699 | int intel_ring_cacheline_align(struct drm_i915_gem_request *req) |
Ville Syrjälä | 753b1ad | 2014-02-11 19:52:05 +0200 | [diff] [blame] | 1700 | { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 1701 | int num_dwords = |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1702 | (req->ring->tail & (CACHELINE_BYTES - 1)) / sizeof(uint32_t); |
| 1703 | u32 *cs; |
Ville Syrjälä | 753b1ad | 2014-02-11 19:52:05 +0200 | [diff] [blame] | 1704 | |
| 1705 | if (num_dwords == 0) |
| 1706 | return 0; |
| 1707 | |
Chris Wilson | 18393f6 | 2014-04-09 09:19:40 +0100 | [diff] [blame] | 1708 | num_dwords = CACHELINE_BYTES / sizeof(uint32_t) - num_dwords; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1709 | cs = intel_ring_begin(req, num_dwords); |
| 1710 | if (IS_ERR(cs)) |
| 1711 | return PTR_ERR(cs); |
Ville Syrjälä | 753b1ad | 2014-02-11 19:52:05 +0200 | [diff] [blame] | 1712 | |
| 1713 | while (num_dwords--) |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1714 | *cs++ = MI_NOOP; |
Ville Syrjälä | 753b1ad | 2014-02-11 19:52:05 +0200 | [diff] [blame] | 1715 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1716 | intel_ring_advance(req, cs); |
Ville Syrjälä | 753b1ad | 2014-02-11 19:52:05 +0200 | [diff] [blame] | 1717 | |
| 1718 | return 0; |
| 1719 | } |
| 1720 | |
Chris Wilson | c5efa1a | 2016-08-02 22:50:29 +0100 | [diff] [blame] | 1721 | static void gen6_bsd_submit_request(struct drm_i915_gem_request *request) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1722 | { |
Chris Wilson | c5efa1a | 2016-08-02 22:50:29 +0100 | [diff] [blame] | 1723 | struct drm_i915_private *dev_priv = request->i915; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1724 | |
Chris Wilson | 76f8421 | 2016-06-30 15:33:45 +0100 | [diff] [blame] | 1725 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
| 1726 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1727 | /* Every tail move must follow the sequence below */ |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1728 | |
Chris Wilson | 12f5581 | 2012-07-05 17:14:01 +0100 | [diff] [blame] | 1729 | /* Disable notification that the ring is IDLE. The GT |
| 1730 | * will then assume that it is busy and bring it out of rc6. |
| 1731 | */ |
Chris Wilson | 76f8421 | 2016-06-30 15:33:45 +0100 | [diff] [blame] | 1732 | I915_WRITE_FW(GEN6_BSD_SLEEP_PSMI_CONTROL, |
| 1733 | _MASKED_BIT_ENABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
Chris Wilson | 12f5581 | 2012-07-05 17:14:01 +0100 | [diff] [blame] | 1734 | |
| 1735 | /* Clear the context id. Here be magic! */ |
Chris Wilson | 76f8421 | 2016-06-30 15:33:45 +0100 | [diff] [blame] | 1736 | I915_WRITE64_FW(GEN6_BSD_RNCID, 0x0); |
Chris Wilson | 12f5581 | 2012-07-05 17:14:01 +0100 | [diff] [blame] | 1737 | |
| 1738 | /* 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] | 1739 | if (intel_wait_for_register_fw(dev_priv, |
| 1740 | GEN6_BSD_SLEEP_PSMI_CONTROL, |
| 1741 | GEN6_BSD_SLEEP_INDICATOR, |
| 1742 | 0, |
| 1743 | 50)) |
Chris Wilson | 12f5581 | 2012-07-05 17:14:01 +0100 | [diff] [blame] | 1744 | 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] | 1745 | |
Chris Wilson | 12f5581 | 2012-07-05 17:14:01 +0100 | [diff] [blame] | 1746 | /* Now that the ring is fully powered up, update the tail */ |
Chris Wilson | b0411e7 | 2016-08-02 22:50:34 +0100 | [diff] [blame] | 1747 | i9xx_submit_request(request); |
Chris Wilson | 12f5581 | 2012-07-05 17:14:01 +0100 | [diff] [blame] | 1748 | |
| 1749 | /* Let the ring send IDLE messages to the GT again, |
| 1750 | * and so let it sleep to conserve power when idle. |
| 1751 | */ |
Chris Wilson | 76f8421 | 2016-06-30 15:33:45 +0100 | [diff] [blame] | 1752 | I915_WRITE_FW(GEN6_BSD_SLEEP_PSMI_CONTROL, |
| 1753 | _MASKED_BIT_DISABLE(GEN6_BSD_SLEEP_MSG_DISABLE)); |
| 1754 | |
| 1755 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1756 | } |
| 1757 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1758 | 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] | 1759 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1760 | u32 cmd, *cs; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1761 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1762 | cs = intel_ring_begin(req, 4); |
| 1763 | if (IS_ERR(cs)) |
| 1764 | return PTR_ERR(cs); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1765 | |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1766 | cmd = MI_FLUSH_DW; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1767 | if (INTEL_GEN(req->i915) >= 8) |
Ben Widawsky | 075b3bb | 2013-11-02 21:07:13 -0700 | [diff] [blame] | 1768 | cmd += 1; |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1769 | |
| 1770 | /* We always require a command barrier so that subsequent |
| 1771 | * commands, such as breadcrumb interrupts, are strictly ordered |
| 1772 | * wrt the contents of the write cache being flushed to memory |
| 1773 | * (and thus being coherent from the CPU). |
| 1774 | */ |
| 1775 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; |
| 1776 | |
Jesse Barnes | 9a28977 | 2012-10-26 09:42:42 -0700 | [diff] [blame] | 1777 | /* |
| 1778 | * Bspec vol 1c.5 - video engine command streamer: |
| 1779 | * "If ENABLED, all TLBs will be invalidated once the flush |
| 1780 | * operation is complete. This bit is only valid when the |
| 1781 | * Post-Sync Operation field is a value of 1h or 3h." |
| 1782 | */ |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1783 | if (mode & EMIT_INVALIDATE) |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1784 | cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD; |
| 1785 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1786 | *cs++ = cmd; |
| 1787 | *cs++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1788 | if (INTEL_GEN(req->i915) >= 8) { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1789 | *cs++ = 0; /* upper addr */ |
| 1790 | *cs++ = 0; /* value */ |
Ben Widawsky | 075b3bb | 2013-11-02 21:07:13 -0700 | [diff] [blame] | 1791 | } else { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1792 | *cs++ = 0; |
| 1793 | *cs++ = MI_NOOP; |
Ben Widawsky | 075b3bb | 2013-11-02 21:07:13 -0700 | [diff] [blame] | 1794 | } |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1795 | intel_ring_advance(req, cs); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1796 | return 0; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | static int |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1800 | gen8_emit_bb_start(struct drm_i915_gem_request *req, |
| 1801 | u64 offset, u32 len, |
| 1802 | unsigned int dispatch_flags) |
Ben Widawsky | 1c7a062 | 2013-11-02 21:07:12 -0700 | [diff] [blame] | 1803 | { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 1804 | bool ppgtt = USES_PPGTT(req->i915) && |
John Harrison | 8e004ef | 2015-02-13 11:48:10 +0000 | [diff] [blame] | 1805 | !(dispatch_flags & I915_DISPATCH_SECURE); |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1806 | u32 *cs; |
Ben Widawsky | 1c7a062 | 2013-11-02 21:07:12 -0700 | [diff] [blame] | 1807 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1808 | cs = intel_ring_begin(req, 4); |
| 1809 | if (IS_ERR(cs)) |
| 1810 | return PTR_ERR(cs); |
Ben Widawsky | 1c7a062 | 2013-11-02 21:07:12 -0700 | [diff] [blame] | 1811 | |
| 1812 | /* FIXME(BDW): Address space and security selectors. */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1813 | *cs++ = MI_BATCH_BUFFER_START_GEN8 | (ppgtt << 8) | (dispatch_flags & |
| 1814 | I915_DISPATCH_RS ? MI_BATCH_RESOURCE_STREAMER : 0); |
| 1815 | *cs++ = lower_32_bits(offset); |
| 1816 | *cs++ = upper_32_bits(offset); |
| 1817 | *cs++ = MI_NOOP; |
| 1818 | intel_ring_advance(req, cs); |
Ben Widawsky | 1c7a062 | 2013-11-02 21:07:12 -0700 | [diff] [blame] | 1819 | |
| 1820 | return 0; |
| 1821 | } |
| 1822 | |
| 1823 | static int |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1824 | hsw_emit_bb_start(struct drm_i915_gem_request *req, |
| 1825 | u64 offset, u32 len, |
| 1826 | unsigned int dispatch_flags) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1827 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1828 | u32 *cs; |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 1829 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1830 | cs = intel_ring_begin(req, 2); |
| 1831 | if (IS_ERR(cs)) |
| 1832 | return PTR_ERR(cs); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1833 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1834 | *cs++ = MI_BATCH_BUFFER_START | (dispatch_flags & I915_DISPATCH_SECURE ? |
| 1835 | 0 : MI_BATCH_PPGTT_HSW | MI_BATCH_NON_SECURE_HSW) | |
| 1836 | (dispatch_flags & I915_DISPATCH_RS ? |
| 1837 | MI_BATCH_RESOURCE_STREAMER : 0); |
Chris Wilson | d7d4eed | 2012-10-17 12:09:54 +0100 | [diff] [blame] | 1838 | /* bit0-7 is the length on GEN6+ */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1839 | *cs++ = offset; |
| 1840 | intel_ring_advance(req, cs); |
Chris Wilson | d7d4eed | 2012-10-17 12:09:54 +0100 | [diff] [blame] | 1841 | |
| 1842 | return 0; |
| 1843 | } |
| 1844 | |
| 1845 | static int |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1846 | gen6_emit_bb_start(struct drm_i915_gem_request *req, |
| 1847 | u64 offset, u32 len, |
| 1848 | unsigned int dispatch_flags) |
Chris Wilson | d7d4eed | 2012-10-17 12:09:54 +0100 | [diff] [blame] | 1849 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1850 | u32 *cs; |
Chris Wilson | d7d4eed | 2012-10-17 12:09:54 +0100 | [diff] [blame] | 1851 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1852 | cs = intel_ring_begin(req, 2); |
| 1853 | if (IS_ERR(cs)) |
| 1854 | return PTR_ERR(cs); |
Chris Wilson | d7d4eed | 2012-10-17 12:09:54 +0100 | [diff] [blame] | 1855 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1856 | *cs++ = MI_BATCH_BUFFER_START | (dispatch_flags & I915_DISPATCH_SECURE ? |
| 1857 | 0 : MI_BATCH_NON_SECURE_I965); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1858 | /* bit0-7 is the length on GEN6+ */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1859 | *cs++ = offset; |
| 1860 | intel_ring_advance(req, cs); |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 1861 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1862 | return 0; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1863 | } |
| 1864 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1865 | /* Blitter support (SandyBridge+) */ |
| 1866 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1867 | 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] | 1868 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1869 | u32 cmd, *cs; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1870 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1871 | cs = intel_ring_begin(req, 4); |
| 1872 | if (IS_ERR(cs)) |
| 1873 | return PTR_ERR(cs); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1874 | |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1875 | cmd = MI_FLUSH_DW; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1876 | if (INTEL_GEN(req->i915) >= 8) |
Ben Widawsky | 075b3bb | 2013-11-02 21:07:13 -0700 | [diff] [blame] | 1877 | cmd += 1; |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1878 | |
| 1879 | /* We always require a command barrier so that subsequent |
| 1880 | * commands, such as breadcrumb interrupts, are strictly ordered |
| 1881 | * wrt the contents of the write cache being flushed to memory |
| 1882 | * (and thus being coherent from the CPU). |
| 1883 | */ |
| 1884 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; |
| 1885 | |
Jesse Barnes | 9a28977 | 2012-10-26 09:42:42 -0700 | [diff] [blame] | 1886 | /* |
| 1887 | * Bspec vol 1c.3 - blitter engine command streamer: |
| 1888 | * "If ENABLED, all TLBs will be invalidated once the flush |
| 1889 | * operation is complete. This bit is only valid when the |
| 1890 | * Post-Sync Operation field is a value of 1h or 3h." |
| 1891 | */ |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1892 | if (mode & EMIT_INVALIDATE) |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1893 | cmd |= MI_INVALIDATE_TLB; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1894 | *cs++ = cmd; |
| 1895 | *cs++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1896 | if (INTEL_GEN(req->i915) >= 8) { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1897 | *cs++ = 0; /* upper addr */ |
| 1898 | *cs++ = 0; /* value */ |
Ben Widawsky | 075b3bb | 2013-11-02 21:07:13 -0700 | [diff] [blame] | 1899 | } else { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1900 | *cs++ = 0; |
| 1901 | *cs++ = MI_NOOP; |
Ben Widawsky | 075b3bb | 2013-11-02 21:07:13 -0700 | [diff] [blame] | 1902 | } |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1903 | intel_ring_advance(req, cs); |
Rodrigo Vivi | fd3da6c | 2013-06-06 16:58:16 -0300 | [diff] [blame] | 1904 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1905 | return 0; |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1906 | } |
| 1907 | |
Tvrtko Ursulin | d9a6461 | 2016-06-29 16:09:27 +0100 | [diff] [blame] | 1908 | static void intel_ring_init_semaphores(struct drm_i915_private *dev_priv, |
| 1909 | struct intel_engine_cs *engine) |
| 1910 | { |
Tvrtko Ursulin | db3d401 | 2016-06-29 16:09:28 +0100 | [diff] [blame] | 1911 | struct drm_i915_gem_object *obj; |
Tvrtko Ursulin | 1b9e665 | 2016-06-29 16:09:29 +0100 | [diff] [blame] | 1912 | int ret, i; |
Tvrtko Ursulin | db3d401 | 2016-06-29 16:09:28 +0100 | [diff] [blame] | 1913 | |
Chris Wilson | 39df919 | 2016-07-20 13:31:57 +0100 | [diff] [blame] | 1914 | if (!i915.semaphores) |
Tvrtko Ursulin | db3d401 | 2016-06-29 16:09:28 +0100 | [diff] [blame] | 1915 | return; |
| 1916 | |
Chris Wilson | 51d545d | 2016-08-15 10:49:02 +0100 | [diff] [blame] | 1917 | if (INTEL_GEN(dev_priv) >= 8 && !dev_priv->semaphore) { |
| 1918 | struct i915_vma *vma; |
| 1919 | |
Chris Wilson | f51455d | 2017-01-10 14:47:34 +0000 | [diff] [blame] | 1920 | obj = i915_gem_object_create(dev_priv, PAGE_SIZE); |
Chris Wilson | 51d545d | 2016-08-15 10:49:02 +0100 | [diff] [blame] | 1921 | if (IS_ERR(obj)) |
| 1922 | goto err; |
| 1923 | |
Chris Wilson | a01cb37 | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 1924 | vma = i915_vma_instance(obj, &dev_priv->ggtt.base, NULL); |
Chris Wilson | 51d545d | 2016-08-15 10:49:02 +0100 | [diff] [blame] | 1925 | if (IS_ERR(vma)) |
| 1926 | goto err_obj; |
| 1927 | |
| 1928 | ret = i915_gem_object_set_to_gtt_domain(obj, false); |
| 1929 | if (ret) |
| 1930 | goto err_obj; |
| 1931 | |
| 1932 | ret = i915_vma_pin(vma, 0, 0, PIN_GLOBAL | PIN_HIGH); |
| 1933 | if (ret) |
| 1934 | goto err_obj; |
| 1935 | |
| 1936 | dev_priv->semaphore = vma; |
Tvrtko Ursulin | db3d401 | 2016-06-29 16:09:28 +0100 | [diff] [blame] | 1937 | } |
| 1938 | |
Tvrtko Ursulin | d9a6461 | 2016-06-29 16:09:27 +0100 | [diff] [blame] | 1939 | if (INTEL_GEN(dev_priv) >= 8) { |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1940 | u32 offset = i915_ggtt_offset(dev_priv->semaphore); |
Tvrtko Ursulin | 1b9e665 | 2016-06-29 16:09:29 +0100 | [diff] [blame] | 1941 | |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 1942 | engine->semaphore.sync_to = gen8_ring_sync_to; |
Tvrtko Ursulin | d9a6461 | 2016-06-29 16:09:27 +0100 | [diff] [blame] | 1943 | engine->semaphore.signal = gen8_xcs_signal; |
Tvrtko Ursulin | 1b9e665 | 2016-06-29 16:09:29 +0100 | [diff] [blame] | 1944 | |
| 1945 | for (i = 0; i < I915_NUM_ENGINES; i++) { |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1946 | u32 ring_offset; |
Tvrtko Ursulin | 1b9e665 | 2016-06-29 16:09:29 +0100 | [diff] [blame] | 1947 | |
| 1948 | if (i != engine->id) |
| 1949 | ring_offset = offset + GEN8_SEMAPHORE_OFFSET(engine->id, i); |
| 1950 | else |
| 1951 | ring_offset = MI_SEMAPHORE_SYNC_INVALID; |
| 1952 | |
| 1953 | engine->semaphore.signal_ggtt[i] = ring_offset; |
| 1954 | } |
Tvrtko Ursulin | d9a6461 | 2016-06-29 16:09:27 +0100 | [diff] [blame] | 1955 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Chris Wilson | ad7bdb2 | 2016-08-02 22:50:40 +0100 | [diff] [blame] | 1956 | engine->semaphore.sync_to = gen6_ring_sync_to; |
Tvrtko Ursulin | d9a6461 | 2016-06-29 16:09:27 +0100 | [diff] [blame] | 1957 | engine->semaphore.signal = gen6_signal; |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 1958 | |
| 1959 | /* |
| 1960 | * The current semaphore is only applied on pre-gen8 |
| 1961 | * platform. And there is no VCS2 ring on the pre-gen8 |
| 1962 | * platform. So the semaphore between RCS and VCS2 is |
| 1963 | * initialized as INVALID. Gen8 will initialize the |
| 1964 | * sema between VCS2 and RCS later. |
| 1965 | */ |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 1966 | for (i = 0; i < GEN6_NUM_SEMAPHORES; i++) { |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 1967 | static const struct { |
| 1968 | u32 wait_mbox; |
| 1969 | i915_reg_t mbox_reg; |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 1970 | } sem_data[GEN6_NUM_SEMAPHORES][GEN6_NUM_SEMAPHORES] = { |
| 1971 | [RCS_HW] = { |
| 1972 | [VCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_RV, .mbox_reg = GEN6_VRSYNC }, |
| 1973 | [BCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_RB, .mbox_reg = GEN6_BRSYNC }, |
| 1974 | [VECS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_RVE, .mbox_reg = GEN6_VERSYNC }, |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 1975 | }, |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 1976 | [VCS_HW] = { |
| 1977 | [RCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VR, .mbox_reg = GEN6_RVSYNC }, |
| 1978 | [BCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VB, .mbox_reg = GEN6_BVSYNC }, |
| 1979 | [VECS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VVE, .mbox_reg = GEN6_VEVSYNC }, |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 1980 | }, |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 1981 | [BCS_HW] = { |
| 1982 | [RCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_BR, .mbox_reg = GEN6_RBSYNC }, |
| 1983 | [VCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_BV, .mbox_reg = GEN6_VBSYNC }, |
| 1984 | [VECS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_BVE, .mbox_reg = GEN6_VEBSYNC }, |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 1985 | }, |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 1986 | [VECS_HW] = { |
| 1987 | [RCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VER, .mbox_reg = GEN6_RVESYNC }, |
| 1988 | [VCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VEV, .mbox_reg = GEN6_VVESYNC }, |
| 1989 | [BCS_HW] = { .wait_mbox = MI_SEMAPHORE_SYNC_VEB, .mbox_reg = GEN6_BVESYNC }, |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 1990 | }, |
| 1991 | }; |
| 1992 | u32 wait_mbox; |
| 1993 | i915_reg_t mbox_reg; |
| 1994 | |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 1995 | if (i == engine->hw_id) { |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 1996 | wait_mbox = MI_SEMAPHORE_SYNC_INVALID; |
| 1997 | mbox_reg = GEN6_NOSYNC; |
| 1998 | } else { |
Tvrtko Ursulin | 318f89c | 2016-08-16 17:04:21 +0100 | [diff] [blame] | 1999 | wait_mbox = sem_data[engine->hw_id][i].wait_mbox; |
| 2000 | mbox_reg = sem_data[engine->hw_id][i].mbox_reg; |
Tvrtko Ursulin | 4b8e38a | 2016-06-29 16:09:31 +0100 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | engine->semaphore.mbox.wait[i] = wait_mbox; |
| 2004 | engine->semaphore.mbox.signal[i] = mbox_reg; |
| 2005 | } |
Tvrtko Ursulin | d9a6461 | 2016-06-29 16:09:27 +0100 | [diff] [blame] | 2006 | } |
Chris Wilson | 51d545d | 2016-08-15 10:49:02 +0100 | [diff] [blame] | 2007 | |
| 2008 | return; |
| 2009 | |
| 2010 | err_obj: |
| 2011 | i915_gem_object_put(obj); |
| 2012 | err: |
| 2013 | DRM_DEBUG_DRIVER("Failed to allocate space for semaphores, disabling\n"); |
| 2014 | i915.semaphores = 0; |
Tvrtko Ursulin | d9a6461 | 2016-06-29 16:09:27 +0100 | [diff] [blame] | 2015 | } |
| 2016 | |
Chris Wilson | ed00307 | 2016-07-01 09:18:13 +0100 | [diff] [blame] | 2017 | static void intel_ring_init_irq(struct drm_i915_private *dev_priv, |
| 2018 | struct intel_engine_cs *engine) |
| 2019 | { |
Tvrtko Ursulin | c78d606 | 2016-07-13 16:03:38 +0100 | [diff] [blame] | 2020 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT << engine->irq_shift; |
| 2021 | |
Chris Wilson | ed00307 | 2016-07-01 09:18:13 +0100 | [diff] [blame] | 2022 | if (INTEL_GEN(dev_priv) >= 8) { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2023 | engine->irq_enable = gen8_irq_enable; |
| 2024 | engine->irq_disable = gen8_irq_disable; |
Chris Wilson | ed00307 | 2016-07-01 09:18:13 +0100 | [diff] [blame] | 2025 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
| 2026 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2027 | engine->irq_enable = gen6_irq_enable; |
| 2028 | engine->irq_disable = gen6_irq_disable; |
Chris Wilson | ed00307 | 2016-07-01 09:18:13 +0100 | [diff] [blame] | 2029 | engine->irq_seqno_barrier = gen6_seqno_barrier; |
| 2030 | } else if (INTEL_GEN(dev_priv) >= 5) { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2031 | engine->irq_enable = gen5_irq_enable; |
| 2032 | engine->irq_disable = gen5_irq_disable; |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 2033 | engine->irq_seqno_barrier = gen5_seqno_barrier; |
Chris Wilson | ed00307 | 2016-07-01 09:18:13 +0100 | [diff] [blame] | 2034 | } else if (INTEL_GEN(dev_priv) >= 3) { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2035 | engine->irq_enable = i9xx_irq_enable; |
| 2036 | engine->irq_disable = i9xx_irq_disable; |
Chris Wilson | ed00307 | 2016-07-01 09:18:13 +0100 | [diff] [blame] | 2037 | } else { |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2038 | engine->irq_enable = i8xx_irq_enable; |
| 2039 | engine->irq_disable = i8xx_irq_disable; |
Chris Wilson | ed00307 | 2016-07-01 09:18:13 +0100 | [diff] [blame] | 2040 | } |
| 2041 | } |
| 2042 | |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 2043 | static void i9xx_set_default_submission(struct intel_engine_cs *engine) |
| 2044 | { |
| 2045 | engine->submit_request = i9xx_submit_request; |
| 2046 | } |
| 2047 | |
| 2048 | static void gen6_bsd_set_default_submission(struct intel_engine_cs *engine) |
| 2049 | { |
| 2050 | engine->submit_request = gen6_bsd_submit_request; |
| 2051 | } |
| 2052 | |
Tvrtko Ursulin | 06a2fe2 | 2016-06-29 16:09:20 +0100 | [diff] [blame] | 2053 | static void intel_ring_default_vfuncs(struct drm_i915_private *dev_priv, |
| 2054 | struct intel_engine_cs *engine) |
| 2055 | { |
Chris Wilson | 618e4ca | 2016-08-02 22:50:35 +0100 | [diff] [blame] | 2056 | intel_ring_init_irq(dev_priv, engine); |
| 2057 | intel_ring_init_semaphores(dev_priv, engine); |
| 2058 | |
Tvrtko Ursulin | 1d8a133 | 2016-06-29 16:09:25 +0100 | [diff] [blame] | 2059 | engine->init_hw = init_ring_common; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 2060 | engine->reset_hw = reset_ring_common; |
Tvrtko Ursulin | 7445a2a | 2016-06-29 16:09:21 +0100 | [diff] [blame] | 2061 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 2062 | engine->context_pin = intel_ring_context_pin; |
| 2063 | engine->context_unpin = intel_ring_context_unpin; |
| 2064 | |
Chris Wilson | f73e739 | 2016-12-18 15:37:24 +0000 | [diff] [blame] | 2065 | engine->request_alloc = ring_request_alloc; |
| 2066 | |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 2067 | engine->emit_breadcrumb = i9xx_emit_breadcrumb; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2068 | engine->emit_breadcrumb_sz = i9xx_emit_breadcrumb_sz; |
| 2069 | if (i915.semaphores) { |
| 2070 | int num_rings; |
| 2071 | |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 2072 | engine->emit_breadcrumb = gen6_sema_emit_breadcrumb; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2073 | |
| 2074 | num_rings = hweight32(INTEL_INFO(dev_priv)->ring_mask) - 1; |
| 2075 | if (INTEL_GEN(dev_priv) >= 8) { |
| 2076 | engine->emit_breadcrumb_sz += num_rings * 6; |
| 2077 | } else { |
| 2078 | engine->emit_breadcrumb_sz += num_rings * 3; |
| 2079 | if (num_rings & 1) |
| 2080 | engine->emit_breadcrumb_sz++; |
| 2081 | } |
| 2082 | } |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 2083 | |
| 2084 | engine->set_default_submission = i9xx_set_default_submission; |
Chris Wilson | 6f7bef7 | 2016-07-01 09:18:12 +0100 | [diff] [blame] | 2085 | |
| 2086 | if (INTEL_GEN(dev_priv) >= 8) |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 2087 | engine->emit_bb_start = gen8_emit_bb_start; |
Chris Wilson | 6f7bef7 | 2016-07-01 09:18:12 +0100 | [diff] [blame] | 2088 | else if (INTEL_GEN(dev_priv) >= 6) |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 2089 | engine->emit_bb_start = gen6_emit_bb_start; |
Chris Wilson | 6f7bef7 | 2016-07-01 09:18:12 +0100 | [diff] [blame] | 2090 | else if (INTEL_GEN(dev_priv) >= 4) |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 2091 | engine->emit_bb_start = i965_emit_bb_start; |
Jani Nikula | 2a307c2 | 2016-11-30 17:43:04 +0200 | [diff] [blame] | 2092 | else if (IS_I830(dev_priv) || IS_I845G(dev_priv)) |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 2093 | engine->emit_bb_start = i830_emit_bb_start; |
Chris Wilson | 6f7bef7 | 2016-07-01 09:18:12 +0100 | [diff] [blame] | 2094 | else |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 2095 | engine->emit_bb_start = i915_emit_bb_start; |
Tvrtko Ursulin | 06a2fe2 | 2016-06-29 16:09:20 +0100 | [diff] [blame] | 2096 | } |
| 2097 | |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2098 | int intel_init_render_ring_buffer(struct intel_engine_cs *engine) |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 2099 | { |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2100 | struct drm_i915_private *dev_priv = engine->i915; |
Ben Widawsky | 3e78998 | 2014-06-30 09:53:37 -0700 | [diff] [blame] | 2101 | int ret; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 2102 | |
Tvrtko Ursulin | 06a2fe2 | 2016-06-29 16:09:20 +0100 | [diff] [blame] | 2103 | intel_ring_default_vfuncs(dev_priv, engine); |
| 2104 | |
Chris Wilson | 61ff75a | 2016-07-01 17:23:28 +0100 | [diff] [blame] | 2105 | if (HAS_L3_DPF(dev_priv)) |
| 2106 | engine->irq_keep_mask = GT_RENDER_L3_PARITY_ERROR_INTERRUPT; |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 2107 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2108 | if (INTEL_GEN(dev_priv) >= 8) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2109 | engine->init_context = intel_rcs_ctx_init; |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 2110 | engine->emit_breadcrumb = gen8_render_emit_breadcrumb; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2111 | engine->emit_breadcrumb_sz = gen8_render_emit_breadcrumb_sz; |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2112 | engine->emit_flush = gen8_render_ring_flush; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2113 | if (i915.semaphores) { |
| 2114 | int num_rings; |
| 2115 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2116 | engine->semaphore.signal = gen8_rcs_signal; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2117 | |
| 2118 | num_rings = |
| 2119 | hweight32(INTEL_INFO(dev_priv)->ring_mask) - 1; |
Chris Wilson | 6f9b850 | 2017-03-24 15:17:24 +0000 | [diff] [blame] | 2120 | engine->emit_breadcrumb_sz += num_rings * 8; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2121 | } |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2122 | } else if (INTEL_GEN(dev_priv) >= 6) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2123 | engine->init_context = intel_rcs_ctx_init; |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2124 | engine->emit_flush = gen7_render_ring_flush; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2125 | if (IS_GEN6(dev_priv)) |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2126 | engine->emit_flush = gen6_render_ring_flush; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2127 | } else if (IS_GEN5(dev_priv)) { |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2128 | engine->emit_flush = gen4_render_ring_flush; |
Daniel Vetter | 59465b5 | 2012-04-11 22:12:48 +0200 | [diff] [blame] | 2129 | } else { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2130 | if (INTEL_GEN(dev_priv) < 4) |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2131 | engine->emit_flush = gen2_render_ring_flush; |
Chris Wilson | 46f0f8d | 2012-04-18 11:12:11 +0100 | [diff] [blame] | 2132 | else |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2133 | engine->emit_flush = gen4_render_ring_flush; |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2134 | engine->irq_enable_mask = I915_USER_INTERRUPT; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 2135 | } |
Ben Widawsky | 707d9cf | 2014-06-30 09:53:36 -0700 | [diff] [blame] | 2136 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2137 | if (IS_HASWELL(dev_priv)) |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 2138 | engine->emit_bb_start = hsw_emit_bb_start; |
Chris Wilson | 6f7bef7 | 2016-07-01 09:18:12 +0100 | [diff] [blame] | 2139 | |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2140 | engine->init_hw = init_render_ring; |
| 2141 | engine->cleanup = render_ring_cleanup; |
Daniel Vetter | 59465b5 | 2012-04-11 22:12:48 +0200 | [diff] [blame] | 2142 | |
Tvrtko Ursulin | acd2784 | 2016-07-13 16:03:39 +0100 | [diff] [blame] | 2143 | ret = intel_init_ring_buffer(engine); |
Daniel Vetter | 99be1df | 2014-11-20 00:33:06 +0100 | [diff] [blame] | 2144 | if (ret) |
| 2145 | return ret; |
| 2146 | |
Chris Wilson | f8973c2 | 2016-07-01 17:23:21 +0100 | [diff] [blame] | 2147 | if (INTEL_GEN(dev_priv) >= 6) { |
Chris Wilson | f51455d | 2017-01-10 14:47:34 +0000 | [diff] [blame] | 2148 | ret = intel_engine_create_scratch(engine, PAGE_SIZE); |
Chris Wilson | 7d5ea80 | 2016-07-01 17:23:20 +0100 | [diff] [blame] | 2149 | if (ret) |
| 2150 | return ret; |
| 2151 | } else if (HAS_BROKEN_CS_TLB(dev_priv)) { |
Chris Wilson | 56c0f1a | 2016-08-15 10:48:58 +0100 | [diff] [blame] | 2152 | ret = intel_engine_create_scratch(engine, I830_WA_SIZE); |
Daniel Vetter | 99be1df | 2014-11-20 00:33:06 +0100 | [diff] [blame] | 2153 | if (ret) |
| 2154 | return ret; |
| 2155 | } |
| 2156 | |
| 2157 | return 0; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 2158 | } |
| 2159 | |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2160 | int intel_init_bsd_ring_buffer(struct intel_engine_cs *engine) |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 2161 | { |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2162 | struct drm_i915_private *dev_priv = engine->i915; |
Daniel Vetter | 58fa383 | 2012-04-11 22:12:49 +0200 | [diff] [blame] | 2163 | |
Tvrtko Ursulin | 06a2fe2 | 2016-06-29 16:09:20 +0100 | [diff] [blame] | 2164 | intel_ring_default_vfuncs(dev_priv, engine); |
| 2165 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2166 | if (INTEL_GEN(dev_priv) >= 6) { |
Daniel Vetter | 0fd2c20 | 2012-04-11 22:12:55 +0200 | [diff] [blame] | 2167 | /* gen6 bsd needs a special wa for tail updates */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2168 | if (IS_GEN6(dev_priv)) |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 2169 | engine->set_default_submission = gen6_bsd_set_default_submission; |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2170 | engine->emit_flush = gen6_bsd_ring_flush; |
Tvrtko Ursulin | c78d606 | 2016-07-13 16:03:38 +0100 | [diff] [blame] | 2171 | if (INTEL_GEN(dev_priv) < 8) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2172 | engine->irq_enable_mask = GT_BSD_USER_INTERRUPT; |
Daniel Vetter | 58fa383 | 2012-04-11 22:12:49 +0200 | [diff] [blame] | 2173 | } else { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2174 | engine->mmio_base = BSD_RING_BASE; |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2175 | engine->emit_flush = bsd_ring_flush; |
Tvrtko Ursulin | 8d22891 | 2016-06-29 16:09:32 +0100 | [diff] [blame] | 2176 | if (IS_GEN5(dev_priv)) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2177 | engine->irq_enable_mask = ILK_BSD_USER_INTERRUPT; |
Tvrtko Ursulin | 8d22891 | 2016-06-29 16:09:32 +0100 | [diff] [blame] | 2178 | else |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2179 | engine->irq_enable_mask = I915_BSD_USER_INTERRUPT; |
Daniel Vetter | 58fa383 | 2012-04-11 22:12:49 +0200 | [diff] [blame] | 2180 | } |
Daniel Vetter | 58fa383 | 2012-04-11 22:12:49 +0200 | [diff] [blame] | 2181 | |
Tvrtko Ursulin | acd2784 | 2016-07-13 16:03:39 +0100 | [diff] [blame] | 2182 | return intel_init_ring_buffer(engine); |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 2183 | } |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 2184 | |
Zhao Yakui | 845f74a | 2014-04-17 10:37:37 +0800 | [diff] [blame] | 2185 | /** |
Damien Lespiau | 6265992 | 2015-01-29 14:13:40 +0000 | [diff] [blame] | 2186 | * Initialize the second BSD ring (eg. Broadwell GT3, Skylake GT3) |
Zhao Yakui | 845f74a | 2014-04-17 10:37:37 +0800 | [diff] [blame] | 2187 | */ |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2188 | int intel_init_bsd2_ring_buffer(struct intel_engine_cs *engine) |
Zhao Yakui | 845f74a | 2014-04-17 10:37:37 +0800 | [diff] [blame] | 2189 | { |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2190 | struct drm_i915_private *dev_priv = engine->i915; |
Tvrtko Ursulin | 06a2fe2 | 2016-06-29 16:09:20 +0100 | [diff] [blame] | 2191 | |
| 2192 | intel_ring_default_vfuncs(dev_priv, engine); |
| 2193 | |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2194 | engine->emit_flush = gen6_bsd_ring_flush; |
Zhao Yakui | 845f74a | 2014-04-17 10:37:37 +0800 | [diff] [blame] | 2195 | |
Tvrtko Ursulin | acd2784 | 2016-07-13 16:03:39 +0100 | [diff] [blame] | 2196 | return intel_init_ring_buffer(engine); |
Zhao Yakui | 845f74a | 2014-04-17 10:37:37 +0800 | [diff] [blame] | 2197 | } |
| 2198 | |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2199 | int intel_init_blt_ring_buffer(struct intel_engine_cs *engine) |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 2200 | { |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2201 | struct drm_i915_private *dev_priv = engine->i915; |
Tvrtko Ursulin | 06a2fe2 | 2016-06-29 16:09:20 +0100 | [diff] [blame] | 2202 | |
| 2203 | intel_ring_default_vfuncs(dev_priv, engine); |
| 2204 | |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2205 | engine->emit_flush = gen6_ring_flush; |
Tvrtko Ursulin | c78d606 | 2016-07-13 16:03:38 +0100 | [diff] [blame] | 2206 | if (INTEL_GEN(dev_priv) < 8) |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2207 | engine->irq_enable_mask = GT_BLT_USER_INTERRUPT; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 2208 | |
Tvrtko Ursulin | acd2784 | 2016-07-13 16:03:39 +0100 | [diff] [blame] | 2209 | return intel_init_ring_buffer(engine); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 2210 | } |
Chris Wilson | a7b9761 | 2012-07-20 12:41:08 +0100 | [diff] [blame] | 2211 | |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2212 | int intel_init_vebox_ring_buffer(struct intel_engine_cs *engine) |
Ben Widawsky | 9a8a221 | 2013-05-28 19:22:23 -0700 | [diff] [blame] | 2213 | { |
Tvrtko Ursulin | 8b3e2d3 | 2016-07-13 16:03:37 +0100 | [diff] [blame] | 2214 | struct drm_i915_private *dev_priv = engine->i915; |
Tvrtko Ursulin | 06a2fe2 | 2016-06-29 16:09:20 +0100 | [diff] [blame] | 2215 | |
| 2216 | intel_ring_default_vfuncs(dev_priv, engine); |
| 2217 | |
Chris Wilson | c7fe7d2 | 2016-08-02 22:50:24 +0100 | [diff] [blame] | 2218 | engine->emit_flush = gen6_ring_flush; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2219 | |
Tvrtko Ursulin | c78d606 | 2016-07-13 16:03:38 +0100 | [diff] [blame] | 2220 | if (INTEL_GEN(dev_priv) < 8) { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2221 | engine->irq_enable_mask = PM_VEBOX_USER_INTERRUPT; |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 2222 | engine->irq_enable = hsw_vebox_irq_enable; |
| 2223 | engine->irq_disable = hsw_vebox_irq_disable; |
Ben Widawsky | abd58f0 | 2013-11-02 21:07:09 -0700 | [diff] [blame] | 2224 | } |
Ben Widawsky | 9a8a221 | 2013-05-28 19:22:23 -0700 | [diff] [blame] | 2225 | |
Tvrtko Ursulin | acd2784 | 2016-07-13 16:03:39 +0100 | [diff] [blame] | 2226 | return intel_init_ring_buffer(engine); |
Ben Widawsky | 9a8a221 | 2013-05-28 19:22:23 -0700 | [diff] [blame] | 2227 | } |