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