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