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