Oscar Mateo | b20385f | 2014-07-24 17:04:10 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2014 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 | * Ben Widawsky <ben@bwidawsk.net> |
| 25 | * Michel Thierry <michel.thierry@intel.com> |
| 26 | * Thomas Daniel <thomas.daniel@intel.com> |
| 27 | * Oscar Mateo <oscar.mateo@intel.com> |
| 28 | * |
| 29 | */ |
| 30 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 31 | /** |
| 32 | * DOC: Logical Rings, Logical Ring Contexts and Execlists |
| 33 | * |
| 34 | * Motivation: |
Oscar Mateo | b20385f | 2014-07-24 17:04:10 +0100 | [diff] [blame] | 35 | * GEN8 brings an expansion of the HW contexts: "Logical Ring Contexts". |
| 36 | * These expanded contexts enable a number of new abilities, especially |
| 37 | * "Execlists" (also implemented in this file). |
| 38 | * |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 39 | * One of the main differences with the legacy HW contexts is that logical |
| 40 | * ring contexts incorporate many more things to the context's state, like |
| 41 | * PDPs or ringbuffer control registers: |
| 42 | * |
| 43 | * The reason why PDPs are included in the context is straightforward: as |
| 44 | * PPGTTs (per-process GTTs) are actually per-context, having the PDPs |
| 45 | * contained there mean you don't need to do a ppgtt->switch_mm yourself, |
| 46 | * instead, the GPU will do it for you on the context switch. |
| 47 | * |
| 48 | * But, what about the ringbuffer control registers (head, tail, etc..)? |
| 49 | * shouldn't we just need a set of those per engine command streamer? This is |
| 50 | * where the name "Logical Rings" starts to make sense: by virtualizing the |
| 51 | * rings, the engine cs shifts to a new "ring buffer" with every context |
| 52 | * switch. When you want to submit a workload to the GPU you: A) choose your |
| 53 | * context, B) find its appropriate virtualized ring, C) write commands to it |
| 54 | * and then, finally, D) tell the GPU to switch to that context. |
| 55 | * |
| 56 | * Instead of the legacy MI_SET_CONTEXT, the way you tell the GPU to switch |
| 57 | * to a contexts is via a context execution list, ergo "Execlists". |
| 58 | * |
| 59 | * LRC implementation: |
| 60 | * Regarding the creation of contexts, we have: |
| 61 | * |
| 62 | * - One global default context. |
| 63 | * - One local default context for each opened fd. |
| 64 | * - One local extra context for each context create ioctl call. |
| 65 | * |
| 66 | * Now that ringbuffers belong per-context (and not per-engine, like before) |
| 67 | * and that contexts are uniquely tied to a given engine (and not reusable, |
| 68 | * like before) we need: |
| 69 | * |
| 70 | * - One ringbuffer per-engine inside each context. |
| 71 | * - One backing object per-engine inside each context. |
| 72 | * |
| 73 | * The global default context starts its life with these new objects fully |
| 74 | * allocated and populated. The local default context for each opened fd is |
| 75 | * more complex, because we don't know at creation time which engine is going |
| 76 | * to use them. To handle this, we have implemented a deferred creation of LR |
| 77 | * contexts: |
| 78 | * |
| 79 | * The local context starts its life as a hollow or blank holder, that only |
| 80 | * gets populated for a given engine once we receive an execbuffer. If later |
| 81 | * on we receive another execbuffer ioctl for the same context but a different |
| 82 | * engine, we allocate/populate a new ringbuffer and context backing object and |
| 83 | * so on. |
| 84 | * |
| 85 | * Finally, regarding local contexts created using the ioctl call: as they are |
| 86 | * only allowed with the render ring, we can allocate & populate them right |
| 87 | * away (no need to defer anything, at least for now). |
| 88 | * |
| 89 | * Execlists implementation: |
Oscar Mateo | b20385f | 2014-07-24 17:04:10 +0100 | [diff] [blame] | 90 | * Execlists are the new method by which, on gen8+ hardware, workloads are |
| 91 | * submitted for execution (as opposed to the legacy, ringbuffer-based, method). |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 92 | * This method works as follows: |
| 93 | * |
| 94 | * When a request is committed, its commands (the BB start and any leading or |
| 95 | * trailing commands, like the seqno breadcrumbs) are placed in the ringbuffer |
| 96 | * for the appropriate context. The tail pointer in the hardware context is not |
| 97 | * updated at this time, but instead, kept by the driver in the ringbuffer |
| 98 | * structure. A structure representing this request is added to a request queue |
| 99 | * for the appropriate engine: this structure contains a copy of the context's |
| 100 | * tail after the request was written to the ring buffer and a pointer to the |
| 101 | * context itself. |
| 102 | * |
| 103 | * If the engine's request queue was empty before the request was added, the |
| 104 | * queue is processed immediately. Otherwise the queue will be processed during |
| 105 | * a context switch interrupt. In any case, elements on the queue will get sent |
| 106 | * (in pairs) to the GPU's ExecLists Submit Port (ELSP, for short) with a |
| 107 | * globally unique 20-bits submission ID. |
| 108 | * |
| 109 | * When execution of a request completes, the GPU updates the context status |
| 110 | * buffer with a context complete event and generates a context switch interrupt. |
| 111 | * During the interrupt handling, the driver examines the events in the buffer: |
| 112 | * for each context complete event, if the announced ID matches that on the head |
| 113 | * of the request queue, then that request is retired and removed from the queue. |
| 114 | * |
| 115 | * After processing, if any requests were retired and the queue is not empty |
| 116 | * then a new execution list can be submitted. The two requests at the front of |
| 117 | * the queue are next to be submitted but since a context may not occur twice in |
| 118 | * an execution list, if subsequent requests have the same ID as the first then |
| 119 | * the two requests must be combined. This is done simply by discarding requests |
| 120 | * at the head of the queue until either only one requests is left (in which case |
| 121 | * we use a NULL second context) or the first two requests have unique IDs. |
| 122 | * |
| 123 | * By always executing the first two requests in the queue the driver ensures |
| 124 | * that the GPU is kept as busy as possible. In the case where a single context |
| 125 | * completes but a second context is still executing, the request for this second |
| 126 | * context will be at the head of the queue when we remove the first one. This |
| 127 | * request will then be resubmitted along with a new request for a different context, |
| 128 | * which will cause the hardware to continue executing the second request and queue |
| 129 | * the new request (the GPU detects the condition of a context getting preempted |
| 130 | * with the same context and optimizes the context switch flow by not doing |
| 131 | * preemption, but just sampling the new tail pointer). |
| 132 | * |
Oscar Mateo | b20385f | 2014-07-24 17:04:10 +0100 | [diff] [blame] | 133 | */ |
Tvrtko Ursulin | 27af5ee | 2016-04-04 12:11:56 +0100 | [diff] [blame] | 134 | #include <linux/interrupt.h> |
Oscar Mateo | b20385f | 2014-07-24 17:04:10 +0100 | [diff] [blame] | 135 | |
| 136 | #include <drm/drmP.h> |
| 137 | #include <drm/i915_drm.h> |
| 138 | #include "i915_drv.h" |
Peter Antoine | 3bbaba0 | 2015-07-10 20:13:11 +0300 | [diff] [blame] | 139 | #include "intel_mocs.h" |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 140 | |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 141 | #define RING_EXECLIST_QFULL (1 << 0x2) |
| 142 | #define RING_EXECLIST1_VALID (1 << 0x3) |
| 143 | #define RING_EXECLIST0_VALID (1 << 0x4) |
| 144 | #define RING_EXECLIST_ACTIVE_STATUS (3 << 0xE) |
| 145 | #define RING_EXECLIST1_ACTIVE (1 << 0x11) |
| 146 | #define RING_EXECLIST0_ACTIVE (1 << 0x12) |
| 147 | |
| 148 | #define GEN8_CTX_STATUS_IDLE_ACTIVE (1 << 0) |
| 149 | #define GEN8_CTX_STATUS_PREEMPTED (1 << 1) |
| 150 | #define GEN8_CTX_STATUS_ELEMENT_SWITCH (1 << 2) |
| 151 | #define GEN8_CTX_STATUS_ACTIVE_IDLE (1 << 3) |
| 152 | #define GEN8_CTX_STATUS_COMPLETE (1 << 4) |
| 153 | #define GEN8_CTX_STATUS_LITE_RESTORE (1 << 15) |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 154 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 155 | #define GEN8_CTX_STATUS_COMPLETED_MASK \ |
| 156 | (GEN8_CTX_STATUS_ACTIVE_IDLE | \ |
| 157 | GEN8_CTX_STATUS_PREEMPTED | \ |
| 158 | GEN8_CTX_STATUS_ELEMENT_SWITCH) |
| 159 | |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 160 | #define CTX_LRI_HEADER_0 0x01 |
| 161 | #define CTX_CONTEXT_CONTROL 0x02 |
| 162 | #define CTX_RING_HEAD 0x04 |
| 163 | #define CTX_RING_TAIL 0x06 |
| 164 | #define CTX_RING_BUFFER_START 0x08 |
| 165 | #define CTX_RING_BUFFER_CONTROL 0x0a |
| 166 | #define CTX_BB_HEAD_U 0x0c |
| 167 | #define CTX_BB_HEAD_L 0x0e |
| 168 | #define CTX_BB_STATE 0x10 |
| 169 | #define CTX_SECOND_BB_HEAD_U 0x12 |
| 170 | #define CTX_SECOND_BB_HEAD_L 0x14 |
| 171 | #define CTX_SECOND_BB_STATE 0x16 |
| 172 | #define CTX_BB_PER_CTX_PTR 0x18 |
| 173 | #define CTX_RCS_INDIRECT_CTX 0x1a |
| 174 | #define CTX_RCS_INDIRECT_CTX_OFFSET 0x1c |
| 175 | #define CTX_LRI_HEADER_1 0x21 |
| 176 | #define CTX_CTX_TIMESTAMP 0x22 |
| 177 | #define CTX_PDP3_UDW 0x24 |
| 178 | #define CTX_PDP3_LDW 0x26 |
| 179 | #define CTX_PDP2_UDW 0x28 |
| 180 | #define CTX_PDP2_LDW 0x2a |
| 181 | #define CTX_PDP1_UDW 0x2c |
| 182 | #define CTX_PDP1_LDW 0x2e |
| 183 | #define CTX_PDP0_UDW 0x30 |
| 184 | #define CTX_PDP0_LDW 0x32 |
| 185 | #define CTX_LRI_HEADER_2 0x41 |
| 186 | #define CTX_R_PWR_CLK_STATE 0x42 |
| 187 | #define CTX_GPGPU_CSR_BASE_ADDRESS 0x44 |
| 188 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 189 | #define CTX_REG(reg_state, pos, reg, val) do { \ |
Ville Syrjälä | f0f59a0 | 2015-11-18 15:33:26 +0200 | [diff] [blame] | 190 | (reg_state)[(pos)+0] = i915_mmio_reg_offset(reg); \ |
Ville Syrjälä | 0d925ea | 2015-11-04 23:20:11 +0200 | [diff] [blame] | 191 | (reg_state)[(pos)+1] = (val); \ |
| 192 | } while (0) |
| 193 | |
| 194 | #define ASSIGN_CTX_PDP(ppgtt, reg_state, n) do { \ |
Mika Kuoppala | d852c7b | 2015-06-25 18:35:06 +0300 | [diff] [blame] | 195 | const u64 _addr = i915_page_dir_dma_addr((ppgtt), (n)); \ |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 196 | reg_state[CTX_PDP ## n ## _UDW+1] = upper_32_bits(_addr); \ |
| 197 | reg_state[CTX_PDP ## n ## _LDW+1] = lower_32_bits(_addr); \ |
Ville Syrjälä | 9244a81 | 2015-11-04 23:20:09 +0200 | [diff] [blame] | 198 | } while (0) |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 199 | |
Ville Syrjälä | 9244a81 | 2015-11-04 23:20:09 +0200 | [diff] [blame] | 200 | #define ASSIGN_CTX_PML4(ppgtt, reg_state) do { \ |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 201 | reg_state[CTX_PDP0_UDW + 1] = upper_32_bits(px_dma(&ppgtt->pml4)); \ |
| 202 | reg_state[CTX_PDP0_LDW + 1] = lower_32_bits(px_dma(&ppgtt->pml4)); \ |
Ville Syrjälä | 9244a81 | 2015-11-04 23:20:09 +0200 | [diff] [blame] | 203 | } while (0) |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 204 | |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 205 | #define GEN8_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT 0x17 |
| 206 | #define GEN9_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT 0x26 |
Michel Thierry | 7bd0a2c | 2017-06-06 13:30:38 -0700 | [diff] [blame] | 207 | #define GEN10_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT 0x19 |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 208 | |
Chris Wilson | 0e93cdd | 2016-04-29 09:07:06 +0100 | [diff] [blame] | 209 | /* Typical size of the average request (2 pipecontrols and a MI_BB) */ |
| 210 | #define EXECLISTS_REQUEST_SIZE 64 /* bytes */ |
| 211 | |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 212 | #define WA_TAIL_DWORDS 2 |
| 213 | |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 214 | static int execlists_context_deferred_alloc(struct i915_gem_context *ctx, |
Chris Wilson | 978f1e0 | 2016-04-28 09:56:54 +0100 | [diff] [blame] | 215 | struct intel_engine_cs *engine); |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 216 | static void execlists_init_reg_state(u32 *reg_state, |
| 217 | struct i915_gem_context *ctx, |
| 218 | struct intel_engine_cs *engine, |
| 219 | struct intel_ring *ring); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 220 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 221 | /** |
| 222 | * intel_sanitize_enable_execlists() - sanitize i915.enable_execlists |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 223 | * @dev_priv: i915 device private |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 224 | * @enable_execlists: value of i915.enable_execlists module parameter. |
| 225 | * |
| 226 | * Only certain platforms support Execlists (the prerequisites being |
Thomas Daniel | 27401d1 | 2014-12-11 12:48:35 +0000 | [diff] [blame] | 227 | * support for Logical Ring Contexts and Aliasing PPGTT or better). |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 228 | * |
| 229 | * Return: 1 if Execlists is supported and has to be enabled. |
| 230 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 231 | int intel_sanitize_enable_execlists(struct drm_i915_private *dev_priv, int enable_execlists) |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 232 | { |
Zhiyuan Lv | a0bd6c3 | 2015-08-28 15:41:16 +0800 | [diff] [blame] | 233 | /* On platforms with execlist available, vGPU will only |
| 234 | * support execlist mode, no ring buffer mode. |
| 235 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 236 | if (HAS_LOGICAL_RING_CONTEXTS(dev_priv) && intel_vgpu_active(dev_priv)) |
Zhiyuan Lv | a0bd6c3 | 2015-08-28 15:41:16 +0800 | [diff] [blame] | 237 | return 1; |
| 238 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 239 | if (INTEL_GEN(dev_priv) >= 9) |
Damien Lespiau | 70ee45e | 2014-11-14 15:05:59 +0000 | [diff] [blame] | 240 | return 1; |
| 241 | |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 242 | if (enable_execlists == 0) |
| 243 | return 0; |
| 244 | |
Daniel Vetter | 5a21b66 | 2016-05-24 17:13:53 +0200 | [diff] [blame] | 245 | if (HAS_LOGICAL_RING_CONTEXTS(dev_priv) && |
| 246 | USES_PPGTT(dev_priv) && |
| 247 | i915.use_mmio_flip >= 0) |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 248 | return 1; |
| 249 | |
| 250 | return 0; |
| 251 | } |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 252 | |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 253 | /** |
| 254 | * intel_lr_context_descriptor_update() - calculate & cache the descriptor |
| 255 | * descriptor for a pinned context |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 256 | * @ctx: Context to work on |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 257 | * @engine: Engine the descriptor will be used with |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 258 | * |
| 259 | * The context descriptor encodes various attributes of a context, |
| 260 | * including its GTT address and some flags. Because it's fairly |
| 261 | * expensive to calculate, we'll just do it once and cache the result, |
| 262 | * which remains valid until the context is unpinned. |
| 263 | * |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 264 | * This is what a descriptor looks like, from LSB to MSB:: |
| 265 | * |
Mika Kuoppala | 2355cf0 | 2017-01-27 15:03:09 +0200 | [diff] [blame] | 266 | * bits 0-11: flags, GEN8_CTX_* (cached in ctx->desc_template) |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 267 | * bits 12-31: LRCA, GTT address of (the HWSP of) this context |
| 268 | * bits 32-52: ctx ID, a globally unique tag |
| 269 | * bits 53-54: mbz, reserved for use by hardware |
| 270 | * bits 55-63: group ID, currently unused and set to 0 |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 271 | */ |
| 272 | static void |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 273 | intel_lr_context_descriptor_update(struct i915_gem_context *ctx, |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 274 | struct intel_engine_cs *engine) |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 275 | { |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 276 | struct intel_context *ce = &ctx->engine[engine->id]; |
Chris Wilson | 7069b14 | 2016-04-28 09:56:52 +0100 | [diff] [blame] | 277 | u64 desc; |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 278 | |
Chris Wilson | 7069b14 | 2016-04-28 09:56:52 +0100 | [diff] [blame] | 279 | BUILD_BUG_ON(MAX_CONTEXT_HW_ID > (1<<GEN8_CTX_ID_WIDTH)); |
| 280 | |
Mika Kuoppala | 2355cf0 | 2017-01-27 15:03:09 +0200 | [diff] [blame] | 281 | desc = ctx->desc_template; /* bits 0-11 */ |
Michel Thierry | 0b29c75 | 2017-09-13 09:56:00 +0100 | [diff] [blame] | 282 | desc |= i915_ggtt_offset(ce->state) + LRC_HEADER_PAGES * PAGE_SIZE; |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 283 | /* bits 12-31 */ |
Chris Wilson | 7069b14 | 2016-04-28 09:56:52 +0100 | [diff] [blame] | 284 | desc |= (u64)ctx->hw_id << GEN8_CTX_ID_SHIFT; /* bits 32-52 */ |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 285 | |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 286 | ce->lrc_desc = desc; |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 289 | static inline void |
| 290 | execlists_context_status_change(struct drm_i915_gem_request *rq, |
| 291 | unsigned long status) |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 292 | { |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 293 | /* |
| 294 | * Only used when GVT-g is enabled now. When GVT-g is disabled, |
| 295 | * The compiler should eliminate this function as dead-code. |
| 296 | */ |
| 297 | if (!IS_ENABLED(CONFIG_DRM_I915_GVT)) |
| 298 | return; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 299 | |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 300 | atomic_notifier_call_chain(&rq->engine->context_status_notifier, |
| 301 | status, rq); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 302 | } |
| 303 | |
Tvrtko Ursulin | c6a2ac7 | 2016-02-26 16:58:32 +0000 | [diff] [blame] | 304 | static void |
| 305 | execlists_update_context_pdps(struct i915_hw_ppgtt *ppgtt, u32 *reg_state) |
| 306 | { |
| 307 | ASSIGN_CTX_PDP(ppgtt, reg_state, 3); |
| 308 | ASSIGN_CTX_PDP(ppgtt, reg_state, 2); |
| 309 | ASSIGN_CTX_PDP(ppgtt, reg_state, 1); |
| 310 | ASSIGN_CTX_PDP(ppgtt, reg_state, 0); |
| 311 | } |
| 312 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 313 | static u64 execlists_update_context(struct drm_i915_gem_request *rq) |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 314 | { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 315 | struct intel_context *ce = &rq->ctx->engine[rq->engine->id]; |
Zhi Wang | 04da811 | 2017-02-06 18:37:16 +0800 | [diff] [blame] | 316 | struct i915_hw_ppgtt *ppgtt = |
| 317 | rq->ctx->ppgtt ?: rq->i915->mm.aliasing_ppgtt; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 318 | u32 *reg_state = ce->lrc_reg_state; |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 319 | |
Chris Wilson | e6ba999 | 2017-04-25 14:00:49 +0100 | [diff] [blame] | 320 | reg_state[CTX_RING_TAIL+1] = intel_ring_set_tail(rq->ring, rq->tail); |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 321 | |
Tvrtko Ursulin | c6a2ac7 | 2016-02-26 16:58:32 +0000 | [diff] [blame] | 322 | /* True 32b PPGTT with dynamic page allocation: update PDP |
| 323 | * registers and point the unallocated PDPs to scratch page. |
| 324 | * PML4 is allocated during ppgtt init, so this is not needed |
| 325 | * in 48-bit mode. |
| 326 | */ |
Chris Wilson | 949e8ab | 2017-02-09 14:40:36 +0000 | [diff] [blame] | 327 | if (ppgtt && !i915_vm_is_48bit(&ppgtt->base)) |
Tvrtko Ursulin | c6a2ac7 | 2016-02-26 16:58:32 +0000 | [diff] [blame] | 328 | execlists_update_context_pdps(ppgtt, reg_state); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 329 | |
| 330 | return ce->lrc_desc; |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 333 | static void execlists_submit_ports(struct intel_engine_cs *engine) |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 334 | { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 335 | struct execlist_port *port = engine->execlist_port; |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 336 | u32 __iomem *elsp = |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 337 | engine->i915->regs + i915_mmio_reg_offset(RING_ELSP(engine)); |
| 338 | unsigned int n; |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 339 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 340 | for (n = ARRAY_SIZE(engine->execlist_port); n--; ) { |
| 341 | struct drm_i915_gem_request *rq; |
| 342 | unsigned int count; |
| 343 | u64 desc; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 344 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 345 | rq = port_unpack(&port[n], &count); |
| 346 | if (rq) { |
| 347 | GEM_BUG_ON(count > !n); |
| 348 | if (!count++) |
| 349 | execlists_context_status_change(rq, INTEL_CONTEXT_SCHEDULE_IN); |
| 350 | port_set(&port[n], port_pack(rq, count)); |
| 351 | desc = execlists_update_context(rq); |
| 352 | GEM_DEBUG_EXEC(port[n].context_id = upper_32_bits(desc)); |
| 353 | } else { |
| 354 | GEM_BUG_ON(!n); |
| 355 | desc = 0; |
| 356 | } |
| 357 | |
| 358 | writel(upper_32_bits(desc), elsp); |
| 359 | writel(lower_32_bits(desc), elsp); |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 360 | } |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 361 | } |
| 362 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 363 | static bool ctx_single_port_submission(const struct i915_gem_context *ctx) |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 364 | { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 365 | return (IS_ENABLED(CONFIG_DRM_I915_GVT) && |
Chris Wilson | 6095868 | 2016-12-31 11:20:11 +0000 | [diff] [blame] | 366 | i915_gem_context_force_single_submission(ctx)); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 367 | } |
| 368 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 369 | static bool can_merge_ctx(const struct i915_gem_context *prev, |
| 370 | const struct i915_gem_context *next) |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 371 | { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 372 | if (prev != next) |
| 373 | return false; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 374 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 375 | if (ctx_single_port_submission(prev)) |
| 376 | return false; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 377 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 378 | return true; |
| 379 | } |
Peter Antoine | 779949f | 2015-05-11 16:03:27 +0100 | [diff] [blame] | 380 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 381 | static void port_assign(struct execlist_port *port, |
| 382 | struct drm_i915_gem_request *rq) |
| 383 | { |
| 384 | GEM_BUG_ON(rq == port_request(port)); |
| 385 | |
| 386 | if (port_isset(port)) |
| 387 | i915_gem_request_put(port_request(port)); |
| 388 | |
| 389 | port_set(port, port_pack(i915_gem_request_get(rq), port_count(port))); |
| 390 | } |
| 391 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 392 | static void execlists_dequeue(struct intel_engine_cs *engine) |
| 393 | { |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 394 | struct drm_i915_gem_request *last; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 395 | struct execlist_port *port = engine->execlist_port; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 396 | struct rb_node *rb; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 397 | bool submit = false; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 398 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 399 | last = port_request(port); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 400 | if (last) |
| 401 | /* WaIdleLiteRestore:bdw,skl |
| 402 | * Apply the wa NOOPs to prevent ring:HEAD == req:TAIL |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 403 | * as we resubmit the request. See gen8_emit_breadcrumb() |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 404 | * for where we prepare the padding after the end of the |
| 405 | * request. |
Michel Thierry | 53292cd | 2015-04-15 18:11:33 +0100 | [diff] [blame] | 406 | */ |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 407 | last->tail = last->wa_tail; |
| 408 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 409 | GEM_BUG_ON(port_isset(&port[1])); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 410 | |
| 411 | /* Hardware submission is through 2 ports. Conceptually each port |
| 412 | * has a (RING_START, RING_HEAD, RING_TAIL) tuple. RING_START is |
| 413 | * static for a context, and unique to each, so we only execute |
| 414 | * requests belonging to a single context from each ring. RING_HEAD |
| 415 | * is maintained by the CS in the context image, it marks the place |
| 416 | * where it got up to last time, and through RING_TAIL we tell the CS |
| 417 | * where we want to execute up to this time. |
| 418 | * |
| 419 | * In this list the requests are in order of execution. Consecutive |
| 420 | * requests from the same context are adjacent in the ringbuffer. We |
| 421 | * can combine these requests into a single RING_TAIL update: |
| 422 | * |
| 423 | * RING_HEAD...req1...req2 |
| 424 | * ^- RING_TAIL |
| 425 | * since to execute req2 the CS must first execute req1. |
| 426 | * |
| 427 | * Our goal then is to point each port to the end of a consecutive |
| 428 | * sequence of requests as being the most optimal (fewest wake ups |
| 429 | * and context switches) submission. |
| 430 | */ |
| 431 | |
Tvrtko Ursulin | 9f7886d | 2017-03-21 10:55:11 +0000 | [diff] [blame] | 432 | spin_lock_irq(&engine->timeline->lock); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 433 | rb = engine->execlist_first; |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 434 | GEM_BUG_ON(rb_first(&engine->execlist_queue) != rb); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 435 | while (rb) { |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 436 | struct i915_priolist *p = rb_entry(rb, typeof(*p), node); |
| 437 | struct drm_i915_gem_request *rq, *rn; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 438 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 439 | list_for_each_entry_safe(rq, rn, &p->requests, priotree.link) { |
| 440 | /* |
| 441 | * Can we combine this request with the current port? |
| 442 | * It has to be the same context/ringbuffer and not |
| 443 | * have any exceptions (e.g. GVT saying never to |
| 444 | * combine contexts). |
| 445 | * |
| 446 | * If we can combine the requests, we can execute both |
| 447 | * by updating the RING_TAIL to point to the end of the |
| 448 | * second request, and so we never need to tell the |
| 449 | * hardware about the first. |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 450 | */ |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 451 | if (last && !can_merge_ctx(rq->ctx, last->ctx)) { |
| 452 | /* |
| 453 | * If we are on the second port and cannot |
| 454 | * combine this request with the last, then we |
| 455 | * are done. |
| 456 | */ |
| 457 | if (port != engine->execlist_port) { |
| 458 | __list_del_many(&p->requests, |
| 459 | &rq->priotree.link); |
| 460 | goto done; |
| 461 | } |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 462 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 463 | /* |
| 464 | * If GVT overrides us we only ever submit |
| 465 | * port[0], leaving port[1] empty. Note that we |
| 466 | * also have to be careful that we don't queue |
| 467 | * the same context (even though a different |
| 468 | * request) to the second port. |
| 469 | */ |
| 470 | if (ctx_single_port_submission(last->ctx) || |
| 471 | ctx_single_port_submission(rq->ctx)) { |
| 472 | __list_del_many(&p->requests, |
| 473 | &rq->priotree.link); |
| 474 | goto done; |
| 475 | } |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 476 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 477 | GEM_BUG_ON(last->ctx == rq->ctx); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 478 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 479 | if (submit) |
| 480 | port_assign(port, last); |
| 481 | port++; |
| 482 | } |
| 483 | |
| 484 | INIT_LIST_HEAD(&rq->priotree.link); |
| 485 | rq->priotree.priority = INT_MAX; |
| 486 | |
| 487 | __i915_gem_request_submit(rq); |
| 488 | trace_i915_gem_request_in(rq, port_index(port, engine)); |
| 489 | last = rq; |
| 490 | submit = true; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 491 | } |
Chris Wilson | d55ac5b | 2016-11-14 20:40:59 +0000 | [diff] [blame] | 492 | |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 493 | rb = rb_next(rb); |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 494 | rb_erase(&p->node, &engine->execlist_queue); |
| 495 | INIT_LIST_HEAD(&p->requests); |
| 496 | if (p->priority != I915_PRIORITY_NORMAL) |
Chris Wilson | c5cf9a9 | 2017-05-17 13:10:04 +0100 | [diff] [blame] | 497 | kmem_cache_free(engine->i915->priorities, p); |
Michel Thierry | 53292cd | 2015-04-15 18:11:33 +0100 | [diff] [blame] | 498 | } |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 499 | done: |
| 500 | engine->execlist_first = rb; |
| 501 | if (submit) |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 502 | port_assign(port, last); |
Tvrtko Ursulin | 9f7886d | 2017-03-21 10:55:11 +0000 | [diff] [blame] | 503 | spin_unlock_irq(&engine->timeline->lock); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 504 | |
| 505 | if (submit) |
| 506 | execlists_submit_ports(engine); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 507 | } |
| 508 | |
Chris Wilson | 816ee79 | 2017-01-24 11:00:03 +0000 | [diff] [blame] | 509 | static bool execlists_elsp_ready(const struct intel_engine_cs *engine) |
Ben Widawsky | 91a4103 | 2016-01-05 10:30:07 -0800 | [diff] [blame] | 510 | { |
Chris Wilson | 816ee79 | 2017-01-24 11:00:03 +0000 | [diff] [blame] | 511 | const struct execlist_port *port = engine->execlist_port; |
Ben Widawsky | 91a4103 | 2016-01-05 10:30:07 -0800 | [diff] [blame] | 512 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 513 | return port_count(&port[0]) + port_count(&port[1]) < 2; |
Ben Widawsky | 91a4103 | 2016-01-05 10:30:07 -0800 | [diff] [blame] | 514 | } |
| 515 | |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 516 | /* |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 517 | * Check the unread Context Status Buffers and manage the submission of new |
| 518 | * contexts to the ELSP accordingly. |
| 519 | */ |
Tvrtko Ursulin | 27af5ee | 2016-04-04 12:11:56 +0100 | [diff] [blame] | 520 | static void intel_lrc_irq_handler(unsigned long data) |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 521 | { |
Tvrtko Ursulin | 27af5ee | 2016-04-04 12:11:56 +0100 | [diff] [blame] | 522 | struct intel_engine_cs *engine = (struct intel_engine_cs *)data; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 523 | struct execlist_port *port = engine->execlist_port; |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 524 | struct drm_i915_private *dev_priv = engine->i915; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 525 | |
Chris Wilson | 4892126 | 2017-04-11 18:58:50 +0100 | [diff] [blame] | 526 | /* We can skip acquiring intel_runtime_pm_get() here as it was taken |
| 527 | * on our behalf by the request (see i915_gem_mark_busy()) and it will |
| 528 | * not be relinquished until the device is idle (see |
| 529 | * i915_gem_idle_work_handler()). As a precaution, we make sure |
| 530 | * that all ELSP are drained i.e. we have processed the CSB, |
| 531 | * before allowing ourselves to idle and calling intel_runtime_pm_put(). |
| 532 | */ |
| 533 | GEM_BUG_ON(!dev_priv->gt.awake); |
| 534 | |
Tvrtko Ursulin | 3756685 | 2016-04-12 14:37:31 +0100 | [diff] [blame] | 535 | intel_uncore_forcewake_get(dev_priv, engine->fw_domains); |
Tvrtko Ursulin | c6a2ac7 | 2016-02-26 16:58:32 +0000 | [diff] [blame] | 536 | |
Chris Wilson | 899f620 | 2017-03-21 11:33:20 +0000 | [diff] [blame] | 537 | /* Prefer doing test_and_clear_bit() as a two stage operation to avoid |
| 538 | * imposing the cost of a locked atomic transaction when submitting a |
| 539 | * new request (outside of the context-switch interrupt). |
| 540 | */ |
| 541 | while (test_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted)) { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 542 | u32 __iomem *csb_mmio = |
| 543 | dev_priv->regs + i915_mmio_reg_offset(RING_CONTEXT_STATUS_PTR(engine)); |
| 544 | u32 __iomem *buf = |
| 545 | dev_priv->regs + i915_mmio_reg_offset(RING_CONTEXT_STATUS_BUF_LO(engine, 0)); |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 546 | unsigned int head, tail; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 547 | |
Chris Wilson | 2e70b8c | 2017-03-23 13:48:03 +0000 | [diff] [blame] | 548 | /* The write will be ordered by the uncached read (itself |
| 549 | * a memory barrier), so we do not need another in the form |
| 550 | * of a locked instruction. The race between the interrupt |
| 551 | * handler and the split test/clear is harmless as we order |
| 552 | * our clear before the CSB read. If the interrupt arrived |
| 553 | * first between the test and the clear, we read the updated |
| 554 | * CSB and clear the bit. If the interrupt arrives as we read |
| 555 | * the CSB or later (i.e. after we had cleared the bit) the bit |
| 556 | * is set and we do a new loop. |
| 557 | */ |
| 558 | __clear_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted); |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 559 | head = readl(csb_mmio); |
| 560 | tail = GEN8_CSB_WRITE_PTR(head); |
| 561 | head = GEN8_CSB_READ_PTR(head); |
| 562 | while (head != tail) { |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 563 | struct drm_i915_gem_request *rq; |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 564 | unsigned int status; |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 565 | unsigned int count; |
Chris Wilson | a37951a | 2017-01-24 11:00:06 +0000 | [diff] [blame] | 566 | |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 567 | if (++head == GEN8_CSB_ENTRIES) |
| 568 | head = 0; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 569 | |
Chris Wilson | 2ffe80a | 2017-02-06 17:05:02 +0000 | [diff] [blame] | 570 | /* We are flying near dragons again. |
| 571 | * |
| 572 | * We hold a reference to the request in execlist_port[] |
| 573 | * but no more than that. We are operating in softirq |
| 574 | * context and so cannot hold any mutex or sleep. That |
| 575 | * prevents us stopping the requests we are processing |
| 576 | * in port[] from being retired simultaneously (the |
| 577 | * breadcrumb will be complete before we see the |
| 578 | * context-switch). As we only hold the reference to the |
| 579 | * request, any pointer chasing underneath the request |
| 580 | * is subject to a potential use-after-free. Thus we |
| 581 | * store all of the bookkeeping within port[] as |
| 582 | * required, and avoid using unguarded pointers beneath |
| 583 | * request itself. The same applies to the atomic |
| 584 | * status notifier. |
| 585 | */ |
| 586 | |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 587 | status = readl(buf + 2 * head); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 588 | if (!(status & GEN8_CTX_STATUS_COMPLETED_MASK)) |
| 589 | continue; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 590 | |
Chris Wilson | 86aa7e7 | 2017-01-23 11:31:32 +0000 | [diff] [blame] | 591 | /* Check the context/desc id for this event matches */ |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 592 | GEM_DEBUG_BUG_ON(readl(buf + 2 * head + 1) != |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 593 | port->context_id); |
Chris Wilson | 86aa7e7 | 2017-01-23 11:31:32 +0000 | [diff] [blame] | 594 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 595 | rq = port_unpack(port, &count); |
| 596 | GEM_BUG_ON(count == 0); |
| 597 | if (--count == 0) { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 598 | GEM_BUG_ON(status & GEN8_CTX_STATUS_PREEMPTED); |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 599 | GEM_BUG_ON(!i915_gem_request_completed(rq)); |
| 600 | execlists_context_status_change(rq, INTEL_CONTEXT_SCHEDULE_OUT); |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 601 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 602 | trace_i915_gem_request_out(rq); |
| 603 | i915_gem_request_put(rq); |
| 604 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 605 | port[0] = port[1]; |
| 606 | memset(&port[1], 0, sizeof(port[1])); |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 607 | } else { |
| 608 | port_set(port, port_pack(rq, count)); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 609 | } |
Tvrtko Ursulin | c6a2ac7 | 2016-02-26 16:58:32 +0000 | [diff] [blame] | 610 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 611 | /* After the final element, the hw should be idle */ |
| 612 | GEM_BUG_ON(port_count(port) == 0 && |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 613 | !(status & GEN8_CTX_STATUS_ACTIVE_IDLE)); |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 614 | } |
Tvrtko Ursulin | 26720ab | 2016-03-17 12:59:46 +0000 | [diff] [blame] | 615 | |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 616 | writel(_MASKED_FIELD(GEN8_CSB_READ_PTR_MASK, head << 8), |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 617 | csb_mmio); |
Tvrtko Ursulin | 26720ab | 2016-03-17 12:59:46 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 620 | if (execlists_elsp_ready(engine)) |
| 621 | execlists_dequeue(engine); |
Tvrtko Ursulin | 26720ab | 2016-03-17 12:59:46 +0000 | [diff] [blame] | 622 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 623 | intel_uncore_forcewake_put(dev_priv, engine->fw_domains); |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 624 | } |
| 625 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 626 | static bool |
| 627 | insert_request(struct intel_engine_cs *engine, |
| 628 | struct i915_priotree *pt, |
| 629 | int prio) |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 630 | { |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 631 | struct i915_priolist *p; |
| 632 | struct rb_node **parent, *rb; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 633 | bool first = true; |
| 634 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 635 | if (unlikely(engine->no_priolist)) |
| 636 | prio = I915_PRIORITY_NORMAL; |
| 637 | |
| 638 | find_priolist: |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 639 | /* most positive priority is scheduled first, equal priorities fifo */ |
| 640 | rb = NULL; |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 641 | parent = &engine->execlist_queue.rb_node; |
| 642 | while (*parent) { |
| 643 | rb = *parent; |
| 644 | p = rb_entry(rb, typeof(*p), node); |
| 645 | if (prio > p->priority) { |
| 646 | parent = &rb->rb_left; |
| 647 | } else if (prio < p->priority) { |
| 648 | parent = &rb->rb_right; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 649 | first = false; |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 650 | } else { |
| 651 | list_add_tail(&pt->link, &p->requests); |
| 652 | return false; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 653 | } |
| 654 | } |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 655 | |
| 656 | if (prio == I915_PRIORITY_NORMAL) { |
| 657 | p = &engine->default_priolist; |
| 658 | } else { |
Chris Wilson | c5cf9a9 | 2017-05-17 13:10:04 +0100 | [diff] [blame] | 659 | p = kmem_cache_alloc(engine->i915->priorities, GFP_ATOMIC); |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 660 | /* Convert an allocation failure to a priority bump */ |
| 661 | if (unlikely(!p)) { |
| 662 | prio = I915_PRIORITY_NORMAL; /* recurses just once */ |
| 663 | |
| 664 | /* To maintain ordering with all rendering, after an |
| 665 | * allocation failure we have to disable all scheduling. |
| 666 | * Requests will then be executed in fifo, and schedule |
| 667 | * will ensure that dependencies are emitted in fifo. |
| 668 | * There will be still some reordering with existing |
| 669 | * requests, so if userspace lied about their |
| 670 | * dependencies that reordering may be visible. |
| 671 | */ |
| 672 | engine->no_priolist = true; |
| 673 | goto find_priolist; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | p->priority = prio; |
| 678 | rb_link_node(&p->node, rb, parent); |
| 679 | rb_insert_color(&p->node, &engine->execlist_queue); |
| 680 | |
| 681 | INIT_LIST_HEAD(&p->requests); |
| 682 | list_add_tail(&pt->link, &p->requests); |
| 683 | |
| 684 | if (first) |
| 685 | engine->execlist_first = &p->node; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 686 | |
| 687 | return first; |
| 688 | } |
| 689 | |
Chris Wilson | f4ea6bd | 2016-08-02 22:50:32 +0100 | [diff] [blame] | 690 | static void execlists_submit_request(struct drm_i915_gem_request *request) |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 691 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 692 | struct intel_engine_cs *engine = request->engine; |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 693 | unsigned long flags; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 694 | |
Chris Wilson | 663f71e | 2016-11-14 20:41:00 +0000 | [diff] [blame] | 695 | /* Will be called from irq-context when using foreign fences. */ |
| 696 | spin_lock_irqsave(&engine->timeline->lock, flags); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 697 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 698 | if (insert_request(engine, |
| 699 | &request->priotree, |
| 700 | request->priotree.priority)) { |
Chris Wilson | 48ea255 | 2017-01-24 11:00:08 +0000 | [diff] [blame] | 701 | if (execlists_elsp_ready(engine)) |
Chris Wilson | 3833281 | 2017-01-24 11:00:07 +0000 | [diff] [blame] | 702 | tasklet_hi_schedule(&engine->irq_tasklet); |
| 703 | } |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 704 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 705 | GEM_BUG_ON(!engine->execlist_first); |
| 706 | GEM_BUG_ON(list_empty(&request->priotree.link)); |
| 707 | |
Chris Wilson | 663f71e | 2016-11-14 20:41:00 +0000 | [diff] [blame] | 708 | spin_unlock_irqrestore(&engine->timeline->lock, flags); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 709 | } |
| 710 | |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 711 | static struct intel_engine_cs * |
| 712 | pt_lock_engine(struct i915_priotree *pt, struct intel_engine_cs *locked) |
| 713 | { |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 714 | struct intel_engine_cs *engine = |
| 715 | container_of(pt, struct drm_i915_gem_request, priotree)->engine; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 716 | |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 717 | GEM_BUG_ON(!locked); |
| 718 | |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 719 | if (engine != locked) { |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 720 | spin_unlock(&locked->timeline->lock); |
| 721 | spin_lock(&engine->timeline->lock); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | return engine; |
| 725 | } |
| 726 | |
| 727 | static void execlists_schedule(struct drm_i915_gem_request *request, int prio) |
| 728 | { |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 729 | struct intel_engine_cs *engine; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 730 | struct i915_dependency *dep, *p; |
| 731 | struct i915_dependency stack; |
| 732 | LIST_HEAD(dfs); |
| 733 | |
| 734 | if (prio <= READ_ONCE(request->priotree.priority)) |
| 735 | return; |
| 736 | |
Chris Wilson | 70cd147 | 2016-11-28 14:36:49 +0000 | [diff] [blame] | 737 | /* Need BKL in order to use the temporary link inside i915_dependency */ |
| 738 | lockdep_assert_held(&request->i915->drm.struct_mutex); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 739 | |
| 740 | stack.signaler = &request->priotree; |
| 741 | list_add(&stack.dfs_link, &dfs); |
| 742 | |
| 743 | /* Recursively bump all dependent priorities to match the new request. |
| 744 | * |
| 745 | * A naive approach would be to use recursion: |
| 746 | * static void update_priorities(struct i915_priotree *pt, prio) { |
| 747 | * list_for_each_entry(dep, &pt->signalers_list, signal_link) |
| 748 | * update_priorities(dep->signal, prio) |
| 749 | * insert_request(pt); |
| 750 | * } |
| 751 | * but that may have unlimited recursion depth and so runs a very |
| 752 | * real risk of overunning the kernel stack. Instead, we build |
| 753 | * a flat list of all dependencies starting with the current request. |
| 754 | * As we walk the list of dependencies, we add all of its dependencies |
| 755 | * to the end of the list (this may include an already visited |
| 756 | * request) and continue to walk onwards onto the new dependencies. The |
| 757 | * end result is a topological list of requests in reverse order, the |
| 758 | * last element in the list is the request we must execute first. |
| 759 | */ |
| 760 | list_for_each_entry_safe(dep, p, &dfs, dfs_link) { |
| 761 | struct i915_priotree *pt = dep->signaler; |
| 762 | |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 763 | /* Within an engine, there can be no cycle, but we may |
| 764 | * refer to the same dependency chain multiple times |
| 765 | * (redundant dependencies are not eliminated) and across |
| 766 | * engines. |
| 767 | */ |
| 768 | list_for_each_entry(p, &pt->signalers_list, signal_link) { |
| 769 | GEM_BUG_ON(p->signaler->priority < pt->priority); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 770 | if (prio > READ_ONCE(p->signaler->priority)) |
| 771 | list_move_tail(&p->dfs_link, &dfs); |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 772 | } |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 773 | |
Chris Wilson | 0798cff | 2016-12-05 14:29:41 +0000 | [diff] [blame] | 774 | list_safe_reset_next(dep, p, dfs_link); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 775 | } |
| 776 | |
Chris Wilson | 349bdb6 | 2017-05-17 13:10:05 +0100 | [diff] [blame] | 777 | /* If we didn't need to bump any existing priorities, and we haven't |
| 778 | * yet submitted this request (i.e. there is no potential race with |
| 779 | * execlists_submit_request()), we can set our own priority and skip |
| 780 | * acquiring the engine locks. |
| 781 | */ |
| 782 | if (request->priotree.priority == INT_MIN) { |
| 783 | GEM_BUG_ON(!list_empty(&request->priotree.link)); |
| 784 | request->priotree.priority = prio; |
| 785 | if (stack.dfs_link.next == stack.dfs_link.prev) |
| 786 | return; |
| 787 | __list_del_entry(&stack.dfs_link); |
| 788 | } |
| 789 | |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 790 | engine = request->engine; |
| 791 | spin_lock_irq(&engine->timeline->lock); |
| 792 | |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 793 | /* Fifo and depth-first replacement ensure our deps execute before us */ |
| 794 | list_for_each_entry_safe_reverse(dep, p, &dfs, dfs_link) { |
| 795 | struct i915_priotree *pt = dep->signaler; |
| 796 | |
| 797 | INIT_LIST_HEAD(&dep->dfs_link); |
| 798 | |
| 799 | engine = pt_lock_engine(pt, engine); |
| 800 | |
| 801 | if (prio <= pt->priority) |
| 802 | continue; |
| 803 | |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 804 | pt->priority = prio; |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 805 | if (!list_empty(&pt->link)) { |
| 806 | __list_del_entry(&pt->link); |
| 807 | insert_request(engine, pt, prio); |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 808 | } |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 809 | } |
| 810 | |
Chris Wilson | a79a524 | 2017-03-27 21:21:43 +0100 | [diff] [blame] | 811 | spin_unlock_irq(&engine->timeline->lock); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 812 | |
| 813 | /* XXX Do we need to preempt to make room for us and our deps? */ |
| 814 | } |
| 815 | |
Chris Wilson | 266a240 | 2017-05-04 10:33:08 +0100 | [diff] [blame] | 816 | static struct intel_ring * |
| 817 | execlists_context_pin(struct intel_engine_cs *engine, |
| 818 | struct i915_gem_context *ctx) |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 819 | { |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 820 | struct intel_context *ce = &ctx->engine[engine->id]; |
Chris Wilson | 2947e40 | 2016-12-18 15:37:23 +0000 | [diff] [blame] | 821 | unsigned int flags; |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 822 | void *vaddr; |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 823 | int ret; |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 824 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 825 | lockdep_assert_held(&ctx->i915->drm.struct_mutex); |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 826 | |
Chris Wilson | 266a240 | 2017-05-04 10:33:08 +0100 | [diff] [blame] | 827 | if (likely(ce->pin_count++)) |
| 828 | goto out; |
Chris Wilson | a533b4b | 2017-03-16 17:16:28 +0000 | [diff] [blame] | 829 | GEM_BUG_ON(!ce->pin_count); /* no overflow please! */ |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 830 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 831 | if (!ce->state) { |
| 832 | ret = execlists_context_deferred_alloc(ctx, engine); |
| 833 | if (ret) |
| 834 | goto err; |
| 835 | } |
Chris Wilson | 56f6e0a | 2017-01-05 15:30:20 +0000 | [diff] [blame] | 836 | GEM_BUG_ON(!ce->state); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 837 | |
Chris Wilson | 72b72ae | 2017-02-10 10:14:22 +0000 | [diff] [blame] | 838 | flags = PIN_GLOBAL | PIN_HIGH; |
Daniele Ceraolo Spurio | feef2a7 | 2016-12-23 15:56:22 -0800 | [diff] [blame] | 839 | if (ctx->ggtt_offset_bias) |
| 840 | flags |= PIN_OFFSET_BIAS | ctx->ggtt_offset_bias; |
Chris Wilson | 2947e40 | 2016-12-18 15:37:23 +0000 | [diff] [blame] | 841 | |
| 842 | ret = i915_vma_pin(ce->state, 0, GEN8_LR_CONTEXT_ALIGN, flags); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 843 | if (ret) |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 844 | goto err; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 845 | |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 846 | vaddr = i915_gem_object_pin_map(ce->state->obj, I915_MAP_WB); |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 847 | if (IS_ERR(vaddr)) { |
| 848 | ret = PTR_ERR(vaddr); |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 849 | goto unpin_vma; |
Tvrtko Ursulin | 82352e9 | 2016-01-15 17:12:45 +0000 | [diff] [blame] | 850 | } |
| 851 | |
Chris Wilson | d822bb1 | 2017-04-03 12:34:25 +0100 | [diff] [blame] | 852 | ret = intel_ring_pin(ce->ring, ctx->i915, ctx->ggtt_offset_bias); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 853 | if (ret) |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 854 | goto unpin_map; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 855 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 856 | intel_lr_context_descriptor_update(ctx, engine); |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 857 | |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 858 | ce->lrc_reg_state = vaddr + LRC_STATE_PN * PAGE_SIZE; |
| 859 | ce->lrc_reg_state[CTX_RING_BUFFER_START+1] = |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 860 | i915_ggtt_offset(ce->ring->vma); |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 861 | |
Chris Wilson | a4f5ea6 | 2016-10-28 13:58:35 +0100 | [diff] [blame] | 862 | ce->state->obj->mm.dirty = true; |
Daniel Vetter | e93c28f | 2015-09-02 14:33:42 +0200 | [diff] [blame] | 863 | |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 864 | i915_gem_context_get(ctx); |
Chris Wilson | 266a240 | 2017-05-04 10:33:08 +0100 | [diff] [blame] | 865 | out: |
| 866 | return ce->ring; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 867 | |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 868 | unpin_map: |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 869 | i915_gem_object_unpin_map(ce->state->obj); |
| 870 | unpin_vma: |
| 871 | __i915_vma_unpin(ce->state); |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 872 | err: |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 873 | ce->pin_count = 0; |
Chris Wilson | 266a240 | 2017-05-04 10:33:08 +0100 | [diff] [blame] | 874 | return ERR_PTR(ret); |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 875 | } |
| 876 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 877 | static void execlists_context_unpin(struct intel_engine_cs *engine, |
| 878 | struct i915_gem_context *ctx) |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 879 | { |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 880 | struct intel_context *ce = &ctx->engine[engine->id]; |
Daniel Vetter | af3302b | 2015-12-04 17:27:15 +0100 | [diff] [blame] | 881 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 882 | lockdep_assert_held(&ctx->i915->drm.struct_mutex); |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 883 | GEM_BUG_ON(ce->pin_count == 0); |
Tvrtko Ursulin | 321fe30 | 2016-01-28 10:29:55 +0000 | [diff] [blame] | 884 | |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 885 | if (--ce->pin_count) |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 886 | return; |
| 887 | |
Chris Wilson | aad29fb | 2016-08-02 22:50:23 +0100 | [diff] [blame] | 888 | intel_ring_unpin(ce->ring); |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 889 | |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 890 | i915_gem_object_unpin_map(ce->state->obj); |
| 891 | i915_vma_unpin(ce->state); |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 892 | |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 893 | i915_gem_context_put(ctx); |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Chris Wilson | f73e739 | 2016-12-18 15:37:24 +0000 | [diff] [blame] | 896 | static int execlists_request_alloc(struct drm_i915_gem_request *request) |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 897 | { |
| 898 | struct intel_engine_cs *engine = request->engine; |
| 899 | struct intel_context *ce = &request->ctx->engine[engine->id]; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 900 | u32 *cs; |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 901 | int ret; |
| 902 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 903 | GEM_BUG_ON(!ce->pin_count); |
| 904 | |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 905 | /* Flush enough space to reduce the likelihood of waiting after |
| 906 | * we start building the request - in which case we will just |
| 907 | * have to repeat work. |
| 908 | */ |
| 909 | request->reserved_space += EXECLISTS_REQUEST_SIZE; |
| 910 | |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 911 | if (i915.enable_guc_submission) { |
| 912 | /* |
| 913 | * Check that the GuC has space for the request before |
| 914 | * going any further, as the i915_add_request() call |
| 915 | * later on mustn't fail ... |
| 916 | */ |
| 917 | ret = i915_guc_wq_reserve(request); |
| 918 | if (ret) |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 919 | goto err; |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 922 | cs = intel_ring_begin(request, 0); |
| 923 | if (IS_ERR(cs)) { |
| 924 | ret = PTR_ERR(cs); |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 925 | goto err_unreserve; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 926 | } |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 927 | |
| 928 | if (!ce->initialised) { |
| 929 | ret = engine->init_context(request); |
| 930 | if (ret) |
| 931 | goto err_unreserve; |
| 932 | |
| 933 | ce->initialised = true; |
| 934 | } |
| 935 | |
| 936 | /* Note that after this point, we have committed to using |
| 937 | * this request as it is being used to both track the |
| 938 | * state of engine initialisation and liveness of the |
| 939 | * golden renderstate above. Think twice before you try |
| 940 | * to cancel/unwind this request now. |
| 941 | */ |
| 942 | |
| 943 | request->reserved_space -= EXECLISTS_REQUEST_SIZE; |
| 944 | return 0; |
| 945 | |
| 946 | err_unreserve: |
| 947 | if (i915.enable_guc_submission) |
| 948 | i915_guc_wq_unreserve(request); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 949 | err: |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 950 | return ret; |
| 951 | } |
| 952 | |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 953 | /* |
| 954 | * In this WA we need to set GEN8_L3SQCREG4[21:21] and reset it after |
| 955 | * PIPE_CONTROL instruction. This is required for the flush to happen correctly |
| 956 | * but there is a slight complication as this is applied in WA batch where the |
| 957 | * values are only initialized once so we cannot take register value at the |
| 958 | * beginning and reuse it further; hence we save its value to memory, upload a |
| 959 | * constant value with bit21 set and then we restore it back with the saved value. |
| 960 | * To simplify the WA, a constant value is formed by using the default value |
| 961 | * of this register. This shouldn't be a problem because we are only modifying |
| 962 | * it for a short period and this batch in non-premptible. We can ofcourse |
| 963 | * use additional instructions that read the actual value of the register |
| 964 | * at that time and set our bit of interest but it makes the WA complicated. |
| 965 | * |
| 966 | * This WA is also required for Gen9 so extracting as a function avoids |
| 967 | * code duplication. |
| 968 | */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 969 | static u32 * |
| 970 | gen8_emit_flush_coherentl3_wa(struct intel_engine_cs *engine, u32 *batch) |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 971 | { |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 972 | *batch++ = MI_STORE_REGISTER_MEM_GEN8 | MI_SRM_LRM_GLOBAL_GTT; |
| 973 | *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4); |
| 974 | *batch++ = i915_ggtt_offset(engine->scratch) + 256; |
| 975 | *batch++ = 0; |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 976 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 977 | *batch++ = MI_LOAD_REGISTER_IMM(1); |
| 978 | *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4); |
| 979 | *batch++ = 0x40400000 | GEN8_LQSC_FLUSH_COHERENT_LINES; |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 980 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 981 | batch = gen8_emit_pipe_control(batch, |
| 982 | PIPE_CONTROL_CS_STALL | |
| 983 | PIPE_CONTROL_DC_FLUSH_ENABLE, |
| 984 | 0); |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 985 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 986 | *batch++ = MI_LOAD_REGISTER_MEM_GEN8 | MI_SRM_LRM_GLOBAL_GTT; |
| 987 | *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4); |
| 988 | *batch++ = i915_ggtt_offset(engine->scratch) + 256; |
| 989 | *batch++ = 0; |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 990 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 991 | return batch; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 992 | } |
| 993 | |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 994 | /* |
| 995 | * Typically we only have one indirect_ctx and per_ctx batch buffer which are |
| 996 | * initialized at the beginning and shared across all contexts but this field |
| 997 | * helps us to have multiple batches at different offsets and select them based |
| 998 | * on a criteria. At the moment this batch always start at the beginning of the page |
| 999 | * and at this point we don't have multiple wa_ctx batch buffers. |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1000 | * |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 1001 | * The number of WA applied are not known at the beginning; we use this field |
| 1002 | * to return the no of DWORDS written. |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1003 | * |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 1004 | * It is to be noted that this batch does not contain MI_BATCH_BUFFER_END |
| 1005 | * so it adds NOOPs as padding to make it cacheline aligned. |
| 1006 | * MI_BATCH_BUFFER_END will be added to perctx batch and both of them together |
| 1007 | * makes a complete batch buffer. |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1008 | */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1009 | static u32 *gen8_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1010 | { |
Arun Siluvery | 7ad00d1 | 2015-06-19 18:37:12 +0100 | [diff] [blame] | 1011 | /* WaDisableCtxRestoreArbitration:bdw,chv */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1012 | *batch++ = MI_ARB_ON_OFF | MI_ARB_DISABLE; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1013 | |
Arun Siluvery | c82435b | 2015-06-19 18:37:13 +0100 | [diff] [blame] | 1014 | /* WaFlushCoherentL3CacheLinesAtContextSwitch:bdw */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1015 | if (IS_BROADWELL(engine->i915)) |
| 1016 | batch = gen8_emit_flush_coherentl3_wa(engine, batch); |
Arun Siluvery | c82435b | 2015-06-19 18:37:13 +0100 | [diff] [blame] | 1017 | |
Arun Siluvery | 0160f05 | 2015-06-23 15:46:57 +0100 | [diff] [blame] | 1018 | /* WaClearSlmSpaceAtContextSwitch:bdw,chv */ |
| 1019 | /* Actual scratch location is at 128 bytes offset */ |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1020 | batch = gen8_emit_pipe_control(batch, |
| 1021 | PIPE_CONTROL_FLUSH_L3 | |
| 1022 | PIPE_CONTROL_GLOBAL_GTT_IVB | |
| 1023 | PIPE_CONTROL_CS_STALL | |
| 1024 | PIPE_CONTROL_QW_WRITE, |
| 1025 | i915_ggtt_offset(engine->scratch) + |
| 1026 | 2 * CACHELINE_BYTES); |
Arun Siluvery | 0160f05 | 2015-06-23 15:46:57 +0100 | [diff] [blame] | 1027 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1028 | /* Pad to end of cacheline */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1029 | while ((unsigned long)batch % CACHELINE_BYTES) |
| 1030 | *batch++ = MI_NOOP; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1031 | |
| 1032 | /* |
| 1033 | * MI_BATCH_BUFFER_END is not required in Indirect ctx BB because |
| 1034 | * execution depends on the length specified in terms of cache lines |
| 1035 | * in the register CTX_RCS_INDIRECT_CTX |
| 1036 | */ |
| 1037 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1038 | return batch; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1039 | } |
| 1040 | |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 1041 | /* |
| 1042 | * This batch is started immediately after indirect_ctx batch. Since we ensure |
| 1043 | * that indirect_ctx ends on a cacheline this batch is aligned automatically. |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1044 | * |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 1045 | * The number of DWORDS written are returned using this field. |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1046 | * |
| 1047 | * This batch is terminated with MI_BATCH_BUFFER_END and so we need not add padding |
| 1048 | * to align it with cacheline as padding after MI_BATCH_BUFFER_END is redundant. |
| 1049 | */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1050 | static u32 *gen8_init_perctx_bb(struct intel_engine_cs *engine, u32 *batch) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1051 | { |
Arun Siluvery | 7ad00d1 | 2015-06-19 18:37:12 +0100 | [diff] [blame] | 1052 | /* WaDisableCtxRestoreArbitration:bdw,chv */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1053 | *batch++ = MI_ARB_ON_OFF | MI_ARB_ENABLE; |
| 1054 | *batch++ = MI_BATCH_BUFFER_END; |
Arun Siluvery | 7ad00d1 | 2015-06-19 18:37:12 +0100 | [diff] [blame] | 1055 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1056 | return batch; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1057 | } |
| 1058 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1059 | static u32 *gen9_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch) |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1060 | { |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 1061 | /* WaFlushCoherentL3CacheLinesAtContextSwitch:skl,bxt,glk */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1062 | batch = gen8_emit_flush_coherentl3_wa(engine, batch); |
Arun Siluvery | a4106a7 | 2015-07-14 15:01:29 +0100 | [diff] [blame] | 1063 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 1064 | /* WaDisableGatherAtSetShaderCommonSlice:skl,bxt,kbl,glk */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1065 | *batch++ = MI_LOAD_REGISTER_IMM(1); |
| 1066 | *batch++ = i915_mmio_reg_offset(COMMON_SLICE_CHICKEN2); |
| 1067 | *batch++ = _MASKED_BIT_DISABLE( |
| 1068 | GEN9_DISABLE_GATHER_AT_SET_SHADER_COMMON_SLICE); |
| 1069 | *batch++ = MI_NOOP; |
Mika Kuoppala | 873e817 | 2016-07-20 14:26:13 +0300 | [diff] [blame] | 1070 | |
Mika Kuoppala | 066d462 | 2016-06-07 17:19:15 +0300 | [diff] [blame] | 1071 | /* WaClearSlmSpaceAtContextSwitch:kbl */ |
| 1072 | /* Actual scratch location is at 128 bytes offset */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1073 | if (IS_KBL_REVID(engine->i915, 0, KBL_REVID_A0)) { |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1074 | batch = gen8_emit_pipe_control(batch, |
| 1075 | PIPE_CONTROL_FLUSH_L3 | |
| 1076 | PIPE_CONTROL_GLOBAL_GTT_IVB | |
| 1077 | PIPE_CONTROL_CS_STALL | |
| 1078 | PIPE_CONTROL_QW_WRITE, |
| 1079 | i915_ggtt_offset(engine->scratch) |
| 1080 | + 2 * CACHELINE_BYTES); |
Mika Kuoppala | 066d462 | 2016-06-07 17:19:15 +0300 | [diff] [blame] | 1081 | } |
Tim Gore | 3485d99 | 2016-07-05 10:01:30 +0100 | [diff] [blame] | 1082 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 1083 | /* WaMediaPoolStateCmdInWABB:bxt,glk */ |
Tim Gore | 3485d99 | 2016-07-05 10:01:30 +0100 | [diff] [blame] | 1084 | if (HAS_POOLED_EU(engine->i915)) { |
| 1085 | /* |
| 1086 | * EU pool configuration is setup along with golden context |
| 1087 | * during context initialization. This value depends on |
| 1088 | * device type (2x6 or 3x6) and needs to be updated based |
| 1089 | * on which subslice is disabled especially for 2x6 |
| 1090 | * devices, however it is safe to load default |
| 1091 | * configuration of 3x6 device instead of masking off |
| 1092 | * corresponding bits because HW ignores bits of a disabled |
| 1093 | * subslice and drops down to appropriate config. Please |
| 1094 | * see render_state_setup() in i915_gem_render_state.c for |
| 1095 | * possible configurations, to avoid duplication they are |
| 1096 | * not shown here again. |
| 1097 | */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1098 | *batch++ = GEN9_MEDIA_POOL_STATE; |
| 1099 | *batch++ = GEN9_MEDIA_POOL_ENABLE; |
| 1100 | *batch++ = 0x00777000; |
| 1101 | *batch++ = 0; |
| 1102 | *batch++ = 0; |
| 1103 | *batch++ = 0; |
Tim Gore | 3485d99 | 2016-07-05 10:01:30 +0100 | [diff] [blame] | 1104 | } |
| 1105 | |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1106 | /* Pad to end of cacheline */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1107 | while ((unsigned long)batch % CACHELINE_BYTES) |
| 1108 | *batch++ = MI_NOOP; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1109 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1110 | return batch; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1111 | } |
| 1112 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1113 | static u32 *gen9_init_perctx_bb(struct intel_engine_cs *engine, u32 *batch) |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1114 | { |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1115 | *batch++ = MI_BATCH_BUFFER_END; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1116 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1117 | return batch; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1118 | } |
| 1119 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1120 | #define CTX_WA_BB_OBJ_SIZE (PAGE_SIZE) |
| 1121 | |
| 1122 | static int lrc_setup_wa_ctx(struct intel_engine_cs *engine) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1123 | { |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1124 | struct drm_i915_gem_object *obj; |
| 1125 | struct i915_vma *vma; |
| 1126 | int err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1127 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1128 | obj = i915_gem_object_create(engine->i915, CTX_WA_BB_OBJ_SIZE); |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1129 | if (IS_ERR(obj)) |
| 1130 | return PTR_ERR(obj); |
| 1131 | |
Chris Wilson | a01cb37a | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 1132 | vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL); |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1133 | if (IS_ERR(vma)) { |
| 1134 | err = PTR_ERR(vma); |
| 1135 | goto err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1136 | } |
| 1137 | |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1138 | err = i915_vma_pin(vma, 0, PAGE_SIZE, PIN_GLOBAL | PIN_HIGH); |
| 1139 | if (err) |
| 1140 | goto err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1141 | |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1142 | engine->wa_ctx.vma = vma; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1143 | return 0; |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1144 | |
| 1145 | err: |
| 1146 | i915_gem_object_put(obj); |
| 1147 | return err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1148 | } |
| 1149 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1150 | static void lrc_destroy_wa_ctx(struct intel_engine_cs *engine) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1151 | { |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 1152 | i915_vma_unpin_and_release(&engine->wa_ctx.vma); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1153 | } |
| 1154 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1155 | typedef u32 *(*wa_bb_func_t)(struct intel_engine_cs *engine, u32 *batch); |
| 1156 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1157 | static int intel_init_workaround_bb(struct intel_engine_cs *engine) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1158 | { |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1159 | struct i915_ctx_workarounds *wa_ctx = &engine->wa_ctx; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1160 | struct i915_wa_ctx_bb *wa_bb[2] = { &wa_ctx->indirect_ctx, |
| 1161 | &wa_ctx->per_ctx }; |
| 1162 | wa_bb_func_t wa_bb_fn[2]; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1163 | struct page *page; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1164 | void *batch, *batch_ptr; |
| 1165 | unsigned int i; |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1166 | int ret; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1167 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1168 | if (WARN_ON(engine->id != RCS || !engine->scratch)) |
| 1169 | return -EINVAL; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1170 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1171 | switch (INTEL_GEN(engine->i915)) { |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1172 | case 10: |
| 1173 | return 0; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1174 | case 9: |
| 1175 | wa_bb_fn[0] = gen9_init_indirectctx_bb; |
| 1176 | wa_bb_fn[1] = gen9_init_perctx_bb; |
| 1177 | break; |
| 1178 | case 8: |
| 1179 | wa_bb_fn[0] = gen8_init_indirectctx_bb; |
| 1180 | wa_bb_fn[1] = gen8_init_perctx_bb; |
| 1181 | break; |
| 1182 | default: |
| 1183 | MISSING_CASE(INTEL_GEN(engine->i915)); |
Arun Siluvery | 5e60d79 | 2015-06-23 15:50:44 +0100 | [diff] [blame] | 1184 | return 0; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1185 | } |
Arun Siluvery | 5e60d79 | 2015-06-23 15:50:44 +0100 | [diff] [blame] | 1186 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1187 | ret = lrc_setup_wa_ctx(engine); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1188 | if (ret) { |
| 1189 | DRM_DEBUG_DRIVER("Failed to setup context WA page: %d\n", ret); |
| 1190 | return ret; |
| 1191 | } |
| 1192 | |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1193 | page = i915_gem_object_get_dirty_page(wa_ctx->vma->obj, 0); |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1194 | batch = batch_ptr = kmap_atomic(page); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1195 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1196 | /* |
| 1197 | * Emit the two workaround batch buffers, recording the offset from the |
| 1198 | * start of the workaround batch buffer object for each and their |
| 1199 | * respective sizes. |
| 1200 | */ |
| 1201 | for (i = 0; i < ARRAY_SIZE(wa_bb_fn); i++) { |
| 1202 | wa_bb[i]->offset = batch_ptr - batch; |
| 1203 | if (WARN_ON(!IS_ALIGNED(wa_bb[i]->offset, CACHELINE_BYTES))) { |
| 1204 | ret = -EINVAL; |
| 1205 | break; |
| 1206 | } |
| 1207 | batch_ptr = wa_bb_fn[i](engine, batch_ptr); |
| 1208 | wa_bb[i]->size = batch_ptr - (batch + wa_bb[i]->offset); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1209 | } |
| 1210 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1211 | BUG_ON(batch_ptr - batch > CTX_WA_BB_OBJ_SIZE); |
| 1212 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1213 | kunmap_atomic(batch); |
| 1214 | if (ret) |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1215 | lrc_destroy_wa_ctx(engine); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1216 | |
| 1217 | return ret; |
| 1218 | } |
| 1219 | |
Chris Wilson | 64f09f0 | 2017-08-07 13:19:19 +0100 | [diff] [blame] | 1220 | static u8 gtiir[] = { |
| 1221 | [RCS] = 0, |
| 1222 | [BCS] = 0, |
| 1223 | [VCS] = 1, |
| 1224 | [VCS2] = 1, |
| 1225 | [VECS] = 3, |
| 1226 | }; |
| 1227 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1228 | static int gen8_init_common_ring(struct intel_engine_cs *engine) |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1229 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1230 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 6b764a5 | 2017-04-25 11:38:35 +0100 | [diff] [blame] | 1231 | struct execlist_port *port = engine->execlist_port; |
| 1232 | unsigned int n; |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 1233 | bool submit; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1234 | int ret; |
| 1235 | |
| 1236 | ret = intel_mocs_init_engine(engine); |
| 1237 | if (ret) |
| 1238 | return ret; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1239 | |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 1240 | intel_engine_reset_breadcrumbs(engine); |
Chris Wilson | f3b8f91 | 2017-01-05 15:30:21 +0000 | [diff] [blame] | 1241 | intel_engine_init_hangcheck(engine); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1242 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1243 | I915_WRITE(RING_HWSTAM(engine->mmio_base), 0xffffffff); |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1244 | I915_WRITE(RING_MODE_GEN7(engine), |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1245 | _MASKED_BIT_ENABLE(GFX_RUN_LIST_ENABLE)); |
Chris Wilson | f3b8f91 | 2017-01-05 15:30:21 +0000 | [diff] [blame] | 1246 | I915_WRITE(RING_HWS_PGA(engine->mmio_base), |
| 1247 | engine->status_page.ggtt_offset); |
| 1248 | POSTING_READ(RING_HWS_PGA(engine->mmio_base)); |
Michel Thierry | dfc53c5 | 2015-09-28 13:25:12 +0100 | [diff] [blame] | 1249 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1250 | DRM_DEBUG_DRIVER("Execlists enabled for %s\n", engine->name); |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1251 | |
Chris Wilson | 64f09f0 | 2017-08-07 13:19:19 +0100 | [diff] [blame] | 1252 | GEM_BUG_ON(engine->id >= ARRAY_SIZE(gtiir)); |
| 1253 | |
| 1254 | /* |
| 1255 | * Clear any pending interrupt state. |
| 1256 | * |
| 1257 | * We do it twice out of paranoia that some of the IIR are double |
| 1258 | * buffered, and if we only reset it once there may still be |
| 1259 | * an interrupt pending. |
| 1260 | */ |
| 1261 | I915_WRITE(GEN8_GT_IIR(gtiir[engine->id]), |
| 1262 | GT_CONTEXT_SWITCH_INTERRUPT << engine->irq_shift); |
| 1263 | I915_WRITE(GEN8_GT_IIR(gtiir[engine->id]), |
| 1264 | GT_CONTEXT_SWITCH_INTERRUPT << engine->irq_shift); |
Chris Wilson | f747026 | 2017-01-24 15:20:21 +0000 | [diff] [blame] | 1265 | clear_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted); |
Chris Wilson | 6b764a5 | 2017-04-25 11:38:35 +0100 | [diff] [blame] | 1266 | |
Chris Wilson | 64f09f0 | 2017-08-07 13:19:19 +0100 | [diff] [blame] | 1267 | /* After a GPU reset, we may have requests to replay */ |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 1268 | submit = false; |
Chris Wilson | 6b764a5 | 2017-04-25 11:38:35 +0100 | [diff] [blame] | 1269 | for (n = 0; n < ARRAY_SIZE(engine->execlist_port); n++) { |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 1270 | if (!port_isset(&port[n])) |
Chris Wilson | 6b764a5 | 2017-04-25 11:38:35 +0100 | [diff] [blame] | 1271 | break; |
| 1272 | |
| 1273 | DRM_DEBUG_DRIVER("Restarting %s:%d from 0x%x\n", |
| 1274 | engine->name, n, |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 1275 | port_request(&port[n])->global_seqno); |
Chris Wilson | 6b764a5 | 2017-04-25 11:38:35 +0100 | [diff] [blame] | 1276 | |
| 1277 | /* Discard the current inflight count */ |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 1278 | port_set(&port[n], port_request(&port[n])); |
| 1279 | submit = true; |
Chris Wilson | c87d50c | 2016-10-04 21:11:27 +0100 | [diff] [blame] | 1280 | } |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1281 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 1282 | if (submit && !i915.enable_guc_submission) |
Chris Wilson | 6b764a5 | 2017-04-25 11:38:35 +0100 | [diff] [blame] | 1283 | execlists_submit_ports(engine); |
| 1284 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1285 | return 0; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1286 | } |
| 1287 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1288 | static int gen8_init_render_ring(struct intel_engine_cs *engine) |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1289 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1290 | struct drm_i915_private *dev_priv = engine->i915; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1291 | int ret; |
| 1292 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1293 | ret = gen8_init_common_ring(engine); |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1294 | if (ret) |
| 1295 | return ret; |
| 1296 | |
| 1297 | /* We need to disable the AsyncFlip performance optimisations in order |
| 1298 | * to use MI_WAIT_FOR_EVENT within the CS. It should already be |
| 1299 | * programmed to '1' on all products. |
| 1300 | * |
| 1301 | * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv,bdw,chv |
| 1302 | */ |
| 1303 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(ASYNC_FLIP_PERF_DISABLE)); |
| 1304 | |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1305 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_FORCE_ORDERING)); |
| 1306 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1307 | return init_workarounds_ring(engine); |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1308 | } |
| 1309 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1310 | static int gen9_init_render_ring(struct intel_engine_cs *engine) |
Damien Lespiau | 82ef822 | 2015-02-09 19:33:08 +0000 | [diff] [blame] | 1311 | { |
| 1312 | int ret; |
| 1313 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1314 | ret = gen8_init_common_ring(engine); |
Damien Lespiau | 82ef822 | 2015-02-09 19:33:08 +0000 | [diff] [blame] | 1315 | if (ret) |
| 1316 | return ret; |
| 1317 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1318 | return init_workarounds_ring(engine); |
Damien Lespiau | 82ef822 | 2015-02-09 19:33:08 +0000 | [diff] [blame] | 1319 | } |
| 1320 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1321 | static void reset_common_ring(struct intel_engine_cs *engine, |
| 1322 | struct drm_i915_gem_request *request) |
| 1323 | { |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1324 | struct execlist_port *port = engine->execlist_port; |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 1325 | struct intel_context *ce; |
Chris Wilson | cdb6ded | 2017-07-21 13:32:22 +0100 | [diff] [blame] | 1326 | unsigned int n; |
| 1327 | |
| 1328 | /* |
| 1329 | * Catch up with any missed context-switch interrupts. |
| 1330 | * |
| 1331 | * Ideally we would just read the remaining CSB entries now that we |
| 1332 | * know the gpu is idle. However, the CSB registers are sometimes^W |
| 1333 | * often trashed across a GPU reset! Instead we have to rely on |
| 1334 | * guessing the missed context-switch events by looking at what |
| 1335 | * requests were completed. |
| 1336 | */ |
| 1337 | if (!request) { |
| 1338 | for (n = 0; n < ARRAY_SIZE(engine->execlist_port); n++) |
| 1339 | i915_gem_request_put(port_request(&port[n])); |
| 1340 | memset(engine->execlist_port, 0, sizeof(engine->execlist_port)); |
| 1341 | return; |
| 1342 | } |
| 1343 | |
| 1344 | if (request->ctx != port_request(port)->ctx) { |
| 1345 | i915_gem_request_put(port_request(port)); |
| 1346 | port[0] = port[1]; |
| 1347 | memset(&port[1], 0, sizeof(port[1])); |
| 1348 | } |
| 1349 | |
| 1350 | GEM_BUG_ON(request->ctx != port_request(port)->ctx); |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 1351 | |
| 1352 | /* If the request was innocent, we leave the request in the ELSP |
| 1353 | * and will try to replay it on restarting. The context image may |
| 1354 | * have been corrupted by the reset, in which case we may have |
| 1355 | * to service a new GPU hang, but more likely we can continue on |
| 1356 | * without impact. |
| 1357 | * |
| 1358 | * If the request was guilty, we presume the context is corrupt |
| 1359 | * and have to at least restore the RING register in the context |
| 1360 | * image back to the expected values to skip over the guilty request. |
| 1361 | */ |
Chris Wilson | cdb6ded | 2017-07-21 13:32:22 +0100 | [diff] [blame] | 1362 | if (request->fence.error != -EIO) |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 1363 | return; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1364 | |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1365 | /* We want a simple context + ring to execute the breadcrumb update. |
| 1366 | * We cannot rely on the context being intact across the GPU hang, |
| 1367 | * so clear it and rebuild just what we need for the breadcrumb. |
| 1368 | * All pending requests for this context will be zapped, and any |
| 1369 | * future request will be after userspace has had the opportunity |
| 1370 | * to recreate its own state. |
| 1371 | */ |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 1372 | ce = &request->ctx->engine[engine->id]; |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1373 | execlists_init_reg_state(ce->lrc_reg_state, |
| 1374 | request->ctx, engine, ce->ring); |
| 1375 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1376 | /* Move the RING_HEAD onto the breadcrumb, past the hanging batch */ |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1377 | ce->lrc_reg_state[CTX_RING_BUFFER_START+1] = |
| 1378 | i915_ggtt_offset(ce->ring->vma); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1379 | ce->lrc_reg_state[CTX_RING_HEAD+1] = request->postfix; |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1380 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1381 | request->ring->head = request->postfix; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1382 | intel_ring_update_space(request->ring); |
| 1383 | |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1384 | /* Reset WaIdleLiteRestore:bdw,skl as well */ |
Chris Wilson | 450362d | 2017-03-27 14:00:07 +0100 | [diff] [blame] | 1385 | request->tail = |
| 1386 | intel_ring_wrap(request->ring, |
| 1387 | request->wa_tail - WA_TAIL_DWORDS*sizeof(u32)); |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 1388 | assert_ring_tail_valid(request->ring, request->tail); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1389 | } |
| 1390 | |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1391 | static int intel_logical_ring_emit_pdps(struct drm_i915_gem_request *req) |
| 1392 | { |
| 1393 | struct i915_hw_ppgtt *ppgtt = req->ctx->ppgtt; |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 1394 | struct intel_engine_cs *engine = req->engine; |
Mika Kuoppala | e716776 | 2017-02-28 17:28:10 +0200 | [diff] [blame] | 1395 | const int num_lri_cmds = GEN8_3LVL_PDPES * 2; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1396 | u32 *cs; |
| 1397 | int i; |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1398 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1399 | cs = intel_ring_begin(req, num_lri_cmds * 2 + 2); |
| 1400 | if (IS_ERR(cs)) |
| 1401 | return PTR_ERR(cs); |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1402 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1403 | *cs++ = MI_LOAD_REGISTER_IMM(num_lri_cmds); |
Mika Kuoppala | e716776 | 2017-02-28 17:28:10 +0200 | [diff] [blame] | 1404 | for (i = GEN8_3LVL_PDPES - 1; i >= 0; i--) { |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1405 | const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i); |
| 1406 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1407 | *cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_UDW(engine, i)); |
| 1408 | *cs++ = upper_32_bits(pd_daddr); |
| 1409 | *cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_LDW(engine, i)); |
| 1410 | *cs++ = lower_32_bits(pd_daddr); |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1411 | } |
| 1412 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1413 | *cs++ = MI_NOOP; |
| 1414 | intel_ring_advance(req, cs); |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1415 | |
| 1416 | return 0; |
| 1417 | } |
| 1418 | |
John Harrison | be795fc | 2015-05-29 17:44:03 +0100 | [diff] [blame] | 1419 | static int gen8_emit_bb_start(struct drm_i915_gem_request *req, |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1420 | u64 offset, u32 len, |
Mika Kuoppala | 54af56d | 2017-02-28 17:28:08 +0200 | [diff] [blame] | 1421 | const unsigned int flags) |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1422 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1423 | u32 *cs; |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1424 | int ret; |
| 1425 | |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1426 | /* Don't rely in hw updating PDPs, specially in lite-restore. |
| 1427 | * Ideally, we should set Force PD Restore in ctx descriptor, |
| 1428 | * but we can't. Force Restore would be a second option, but |
| 1429 | * it is unsafe in case of lite-restore (because the ctx is |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 1430 | * not idle). PML4 is allocated during ppgtt init so this is |
| 1431 | * not needed in 48-bit.*/ |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1432 | if (req->ctx->ppgtt && |
Mika Kuoppala | 54af56d | 2017-02-28 17:28:08 +0200 | [diff] [blame] | 1433 | (intel_engine_flag(req->engine) & req->ctx->ppgtt->pd_dirty_rings) && |
| 1434 | !i915_vm_is_48bit(&req->ctx->ppgtt->base) && |
| 1435 | !intel_vgpu_active(req->i915)) { |
| 1436 | ret = intel_logical_ring_emit_pdps(req); |
| 1437 | if (ret) |
| 1438 | return ret; |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1439 | |
Tvrtko Ursulin | 666796d | 2016-03-16 11:00:39 +0000 | [diff] [blame] | 1440 | req->ctx->ppgtt->pd_dirty_rings &= ~intel_engine_flag(req->engine); |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1443 | cs = intel_ring_begin(req, 4); |
| 1444 | if (IS_ERR(cs)) |
| 1445 | return PTR_ERR(cs); |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1446 | |
| 1447 | /* FIXME(BDW): Address space and security selectors. */ |
Mika Kuoppala | 54af56d | 2017-02-28 17:28:08 +0200 | [diff] [blame] | 1448 | *cs++ = MI_BATCH_BUFFER_START_GEN8 | |
| 1449 | (flags & I915_DISPATCH_SECURE ? 0 : BIT(8)) | |
| 1450 | (flags & I915_DISPATCH_RS ? MI_BATCH_RESOURCE_STREAMER : 0); |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1451 | *cs++ = lower_32_bits(offset); |
| 1452 | *cs++ = upper_32_bits(offset); |
| 1453 | *cs++ = MI_NOOP; |
| 1454 | intel_ring_advance(req, cs); |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1455 | |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1459 | static void gen8_logical_ring_enable_irq(struct intel_engine_cs *engine) |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1460 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1461 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1462 | I915_WRITE_IMR(engine, |
| 1463 | ~(engine->irq_enable_mask | engine->irq_keep_mask)); |
| 1464 | POSTING_READ_FW(RING_IMR(engine->mmio_base)); |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1465 | } |
| 1466 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1467 | static void gen8_logical_ring_disable_irq(struct intel_engine_cs *engine) |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1468 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1469 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1470 | I915_WRITE_IMR(engine, ~engine->irq_keep_mask); |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1473 | static int gen8_emit_flush(struct drm_i915_gem_request *request, u32 mode) |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1474 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1475 | u32 cmd, *cs; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1476 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1477 | cs = intel_ring_begin(request, 4); |
| 1478 | if (IS_ERR(cs)) |
| 1479 | return PTR_ERR(cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1480 | |
| 1481 | cmd = MI_FLUSH_DW + 1; |
| 1482 | |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1483 | /* We always require a command barrier so that subsequent |
| 1484 | * commands, such as breadcrumb interrupts, are strictly ordered |
| 1485 | * wrt the contents of the write cache being flushed to memory |
| 1486 | * (and thus being coherent from the CPU). |
| 1487 | */ |
| 1488 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; |
| 1489 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1490 | if (mode & EMIT_INVALIDATE) { |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1491 | cmd |= MI_INVALIDATE_TLB; |
Chris Wilson | 1dae2df | 2016-08-02 22:50:19 +0100 | [diff] [blame] | 1492 | if (request->engine->id == VCS) |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1493 | cmd |= MI_INVALIDATE_BSD; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1496 | *cs++ = cmd; |
| 1497 | *cs++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT; |
| 1498 | *cs++ = 0; /* upper addr */ |
| 1499 | *cs++ = 0; /* value */ |
| 1500 | intel_ring_advance(request, cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1501 | |
| 1502 | return 0; |
| 1503 | } |
| 1504 | |
John Harrison | 7deb4d3 | 2015-05-29 17:43:59 +0100 | [diff] [blame] | 1505 | static int gen8_emit_flush_render(struct drm_i915_gem_request *request, |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1506 | u32 mode) |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1507 | { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 1508 | struct intel_engine_cs *engine = request->engine; |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1509 | u32 scratch_addr = |
| 1510 | i915_ggtt_offset(engine->scratch) + 2 * CACHELINE_BYTES; |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1511 | bool vf_flush_wa = false, dc_flush_wa = false; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1512 | u32 *cs, flags = 0; |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1513 | int len; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1514 | |
| 1515 | flags |= PIPE_CONTROL_CS_STALL; |
| 1516 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1517 | if (mode & EMIT_FLUSH) { |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1518 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; |
| 1519 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
Francisco Jerez | 965fd60 | 2016-01-13 18:59:39 -0800 | [diff] [blame] | 1520 | flags |= PIPE_CONTROL_DC_FLUSH_ENABLE; |
Chris Wilson | 40a2448 | 2015-08-21 16:08:41 +0100 | [diff] [blame] | 1521 | flags |= PIPE_CONTROL_FLUSH_ENABLE; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1522 | } |
| 1523 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1524 | if (mode & EMIT_INVALIDATE) { |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1525 | flags |= PIPE_CONTROL_TLB_INVALIDATE; |
| 1526 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; |
| 1527 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 1528 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 1529 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; |
| 1530 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; |
| 1531 | flags |= PIPE_CONTROL_QW_WRITE; |
| 1532 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1533 | |
Ben Widawsky | 1a5a9ce | 2015-12-17 09:49:57 -0800 | [diff] [blame] | 1534 | /* |
| 1535 | * On GEN9: before VF_CACHE_INVALIDATE we need to emit a NULL |
| 1536 | * pipe control. |
| 1537 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1538 | if (IS_GEN9(request->i915)) |
Ben Widawsky | 1a5a9ce | 2015-12-17 09:49:57 -0800 | [diff] [blame] | 1539 | vf_flush_wa = true; |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1540 | |
| 1541 | /* WaForGAMHang:kbl */ |
| 1542 | if (IS_KBL_REVID(request->i915, 0, KBL_REVID_B0)) |
| 1543 | dc_flush_wa = true; |
Ben Widawsky | 1a5a9ce | 2015-12-17 09:49:57 -0800 | [diff] [blame] | 1544 | } |
Imre Deak | 9647ff3 | 2015-01-25 13:27:11 -0800 | [diff] [blame] | 1545 | |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1546 | len = 6; |
| 1547 | |
| 1548 | if (vf_flush_wa) |
| 1549 | len += 6; |
| 1550 | |
| 1551 | if (dc_flush_wa) |
| 1552 | len += 12; |
| 1553 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1554 | cs = intel_ring_begin(request, len); |
| 1555 | if (IS_ERR(cs)) |
| 1556 | return PTR_ERR(cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1557 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1558 | if (vf_flush_wa) |
| 1559 | cs = gen8_emit_pipe_control(cs, 0, 0); |
Imre Deak | 9647ff3 | 2015-01-25 13:27:11 -0800 | [diff] [blame] | 1560 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1561 | if (dc_flush_wa) |
| 1562 | cs = gen8_emit_pipe_control(cs, PIPE_CONTROL_DC_FLUSH_ENABLE, |
| 1563 | 0); |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1564 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1565 | cs = gen8_emit_pipe_control(cs, flags, scratch_addr); |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1566 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1567 | if (dc_flush_wa) |
| 1568 | cs = gen8_emit_pipe_control(cs, PIPE_CONTROL_CS_STALL, 0); |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1569 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1570 | intel_ring_advance(request, cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1571 | |
| 1572 | return 0; |
| 1573 | } |
| 1574 | |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 1575 | /* |
| 1576 | * Reserve space for 2 NOOPs at the end of each request to be |
| 1577 | * used as a workaround for not being allowed to do lite |
| 1578 | * restore with HEAD==TAIL (WaIdleLiteRestore). |
| 1579 | */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1580 | static void gen8_emit_wa_tail(struct drm_i915_gem_request *request, u32 *cs) |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1581 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1582 | *cs++ = MI_NOOP; |
| 1583 | *cs++ = MI_NOOP; |
| 1584 | request->wa_tail = intel_ring_offset(request, cs); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 1585 | } |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1586 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1587 | static void gen8_emit_breadcrumb(struct drm_i915_gem_request *request, u32 *cs) |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 1588 | { |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 1589 | /* w/a: bit 5 needs to be zero for MI_FLUSH_DW address. */ |
| 1590 | BUILD_BUG_ON(I915_GEM_HWS_INDEX_ADDR & (1 << 5)); |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1591 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1592 | *cs++ = (MI_FLUSH_DW + 1) | MI_FLUSH_DW_OP_STOREDW; |
| 1593 | *cs++ = intel_hws_seqno_address(request->engine) | MI_FLUSH_DW_USE_GTT; |
| 1594 | *cs++ = 0; |
| 1595 | *cs++ = request->global_seqno; |
| 1596 | *cs++ = MI_USER_INTERRUPT; |
| 1597 | *cs++ = MI_NOOP; |
| 1598 | request->tail = intel_ring_offset(request, cs); |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 1599 | assert_ring_tail_valid(request->ring, request->tail); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 1600 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1601 | gen8_emit_wa_tail(request, cs); |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 1602 | } |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1603 | |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 1604 | static const int gen8_emit_breadcrumb_sz = 6 + WA_TAIL_DWORDS; |
| 1605 | |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 1606 | static void gen8_emit_breadcrumb_render(struct drm_i915_gem_request *request, |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1607 | u32 *cs) |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 1608 | { |
Michał Winiarski | ce81a65 | 2016-04-12 15:51:55 +0200 | [diff] [blame] | 1609 | /* We're using qword write, seqno should be aligned to 8 bytes. */ |
| 1610 | BUILD_BUG_ON(I915_GEM_HWS_INDEX & 1); |
| 1611 | |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 1612 | /* w/a for post sync ops following a GPGPU operation we |
| 1613 | * need a prior CS_STALL, which is emitted by the flush |
| 1614 | * following the batch. |
Michel Thierry | 53292cd | 2015-04-15 18:11:33 +0100 | [diff] [blame] | 1615 | */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1616 | *cs++ = GFX_OP_PIPE_CONTROL(6); |
| 1617 | *cs++ = PIPE_CONTROL_GLOBAL_GTT_IVB | PIPE_CONTROL_CS_STALL | |
| 1618 | PIPE_CONTROL_QW_WRITE; |
| 1619 | *cs++ = intel_hws_seqno_address(request->engine); |
| 1620 | *cs++ = 0; |
| 1621 | *cs++ = request->global_seqno; |
Michał Winiarski | ce81a65 | 2016-04-12 15:51:55 +0200 | [diff] [blame] | 1622 | /* We're thrashing one dword of HWS. */ |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1623 | *cs++ = 0; |
| 1624 | *cs++ = MI_USER_INTERRUPT; |
| 1625 | *cs++ = MI_NOOP; |
| 1626 | request->tail = intel_ring_offset(request, cs); |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 1627 | assert_ring_tail_valid(request->ring, request->tail); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 1628 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1629 | gen8_emit_wa_tail(request, cs); |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 1632 | static const int gen8_emit_breadcrumb_render_sz = 8 + WA_TAIL_DWORDS; |
| 1633 | |
John Harrison | 8753181 | 2015-05-29 17:43:44 +0100 | [diff] [blame] | 1634 | static int gen8_init_rcs_context(struct drm_i915_gem_request *req) |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 1635 | { |
| 1636 | int ret; |
| 1637 | |
Tvrtko Ursulin | 4ac9659 | 2017-02-14 15:00:17 +0000 | [diff] [blame] | 1638 | ret = intel_ring_workarounds_emit(req); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 1639 | if (ret) |
| 1640 | return ret; |
| 1641 | |
Peter Antoine | 3bbaba0 | 2015-07-10 20:13:11 +0300 | [diff] [blame] | 1642 | ret = intel_rcs_context_init_mocs(req); |
| 1643 | /* |
| 1644 | * Failing to program the MOCS is non-fatal.The system will not |
| 1645 | * run at peak performance. So generate an error and carry on. |
| 1646 | */ |
| 1647 | if (ret) |
| 1648 | DRM_ERROR("MOCS failed to program: expect performance issues.\n"); |
| 1649 | |
Chris Wilson | 4e50f08 | 2016-10-28 13:58:31 +0100 | [diff] [blame] | 1650 | return i915_gem_render_state_emit(req); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 1651 | } |
| 1652 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 1653 | /** |
| 1654 | * intel_logical_ring_cleanup() - deallocate the Engine Command Streamer |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 1655 | * @engine: Engine Command Streamer. |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 1656 | */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1657 | void intel_logical_ring_cleanup(struct intel_engine_cs *engine) |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1658 | { |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 1659 | struct drm_i915_private *dev_priv; |
Oscar Mateo | 9832b9d | 2014-07-24 17:04:30 +0100 | [diff] [blame] | 1660 | |
Tvrtko Ursulin | 27af5ee | 2016-04-04 12:11:56 +0100 | [diff] [blame] | 1661 | /* |
| 1662 | * Tasklet cannot be active at this point due intel_mark_active/idle |
| 1663 | * so this is just for documentation. |
| 1664 | */ |
| 1665 | if (WARN_ON(test_bit(TASKLET_STATE_SCHED, &engine->irq_tasklet.state))) |
| 1666 | tasklet_kill(&engine->irq_tasklet); |
| 1667 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1668 | dev_priv = engine->i915; |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 1669 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1670 | if (engine->buffer) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1671 | WARN_ON((I915_READ_MODE(engine) & MODE_IDLE) == 0); |
Dave Gordon | b0366a5 | 2015-12-08 15:02:36 +0000 | [diff] [blame] | 1672 | } |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1673 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1674 | if (engine->cleanup) |
| 1675 | engine->cleanup(engine); |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1676 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1677 | intel_engine_cleanup_common(engine); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1678 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1679 | lrc_destroy_wa_ctx(engine); |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1680 | engine->i915 = NULL; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 1681 | dev_priv->engine[engine->id] = NULL; |
| 1682 | kfree(engine); |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1683 | } |
| 1684 | |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 1685 | static void execlists_set_default_submission(struct intel_engine_cs *engine) |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1686 | { |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 1687 | engine->submit_request = execlists_submit_request; |
| 1688 | engine->schedule = execlists_schedule; |
Chris Wilson | c9203e8 | 2017-03-18 10:28:59 +0000 | [diff] [blame] | 1689 | engine->irq_tasklet.func = intel_lrc_irq_handler; |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1690 | } |
| 1691 | |
Tvrtko Ursulin | c9cacf9 | 2016-01-12 17:32:34 +0000 | [diff] [blame] | 1692 | static void |
Chris Wilson | e1382ef | 2016-05-06 15:40:20 +0100 | [diff] [blame] | 1693 | logical_ring_default_vfuncs(struct intel_engine_cs *engine) |
Tvrtko Ursulin | c9cacf9 | 2016-01-12 17:32:34 +0000 | [diff] [blame] | 1694 | { |
| 1695 | /* Default vfuncs which can be overriden by each engine. */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1696 | engine->init_hw = gen8_init_common_ring; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1697 | engine->reset_hw = reset_common_ring; |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1698 | |
| 1699 | engine->context_pin = execlists_context_pin; |
| 1700 | engine->context_unpin = execlists_context_unpin; |
| 1701 | |
Chris Wilson | f73e739 | 2016-12-18 15:37:24 +0000 | [diff] [blame] | 1702 | engine->request_alloc = execlists_request_alloc; |
| 1703 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1704 | engine->emit_flush = gen8_emit_flush; |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 1705 | engine->emit_breadcrumb = gen8_emit_breadcrumb; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 1706 | engine->emit_breadcrumb_sz = gen8_emit_breadcrumb_sz; |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 1707 | |
| 1708 | engine->set_default_submission = execlists_set_default_submission; |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 1709 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1710 | engine->irq_enable = gen8_logical_ring_enable_irq; |
| 1711 | engine->irq_disable = gen8_logical_ring_disable_irq; |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1712 | engine->emit_bb_start = gen8_emit_bb_start; |
Tvrtko Ursulin | c9cacf9 | 2016-01-12 17:32:34 +0000 | [diff] [blame] | 1713 | } |
| 1714 | |
Tvrtko Ursulin | d9f3af9 | 2016-01-12 17:32:35 +0000 | [diff] [blame] | 1715 | static inline void |
Dave Gordon | c2c7f24 | 2016-07-13 16:03:35 +0100 | [diff] [blame] | 1716 | logical_ring_default_irqs(struct intel_engine_cs *engine) |
Tvrtko Ursulin | d9f3af9 | 2016-01-12 17:32:35 +0000 | [diff] [blame] | 1717 | { |
Dave Gordon | c2c7f24 | 2016-07-13 16:03:35 +0100 | [diff] [blame] | 1718 | unsigned shift = engine->irq_shift; |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1719 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT << shift; |
| 1720 | engine->irq_keep_mask = GT_CONTEXT_SWITCH_INTERRUPT << shift; |
Tvrtko Ursulin | d9f3af9 | 2016-01-12 17:32:35 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 1723 | static void |
| 1724 | logical_ring_setup(struct intel_engine_cs *engine) |
| 1725 | { |
| 1726 | struct drm_i915_private *dev_priv = engine->i915; |
| 1727 | enum forcewake_domains fw_domains; |
| 1728 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 1729 | intel_engine_setup_common(engine); |
| 1730 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 1731 | /* Intentionally left blank. */ |
| 1732 | engine->buffer = NULL; |
| 1733 | |
| 1734 | fw_domains = intel_uncore_forcewake_for_reg(dev_priv, |
| 1735 | RING_ELSP(engine), |
| 1736 | FW_REG_WRITE); |
| 1737 | |
| 1738 | fw_domains |= intel_uncore_forcewake_for_reg(dev_priv, |
| 1739 | RING_CONTEXT_STATUS_PTR(engine), |
| 1740 | FW_REG_READ | FW_REG_WRITE); |
| 1741 | |
| 1742 | fw_domains |= intel_uncore_forcewake_for_reg(dev_priv, |
| 1743 | RING_CONTEXT_STATUS_BUF_BASE(engine), |
| 1744 | FW_REG_READ); |
| 1745 | |
| 1746 | engine->fw_domains = fw_domains; |
| 1747 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 1748 | tasklet_init(&engine->irq_tasklet, |
| 1749 | intel_lrc_irq_handler, (unsigned long)engine); |
| 1750 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 1751 | logical_ring_default_vfuncs(engine); |
| 1752 | logical_ring_default_irqs(engine); |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 1753 | } |
| 1754 | |
Daniele Ceraolo Spurio | 486e93f | 2017-09-13 09:56:02 +0100 | [diff] [blame^] | 1755 | static int logical_ring_init(struct intel_engine_cs *engine) |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1756 | { |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1757 | int ret; |
| 1758 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 1759 | ret = intel_engine_init_common(engine); |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1760 | if (ret) |
| 1761 | goto error; |
| 1762 | |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1763 | return 0; |
| 1764 | |
| 1765 | error: |
| 1766 | intel_logical_ring_cleanup(engine); |
| 1767 | return ret; |
| 1768 | } |
| 1769 | |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 1770 | int logical_render_ring_init(struct intel_engine_cs *engine) |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1771 | { |
| 1772 | struct drm_i915_private *dev_priv = engine->i915; |
| 1773 | int ret; |
| 1774 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 1775 | logical_ring_setup(engine); |
| 1776 | |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1777 | if (HAS_L3_DPF(dev_priv)) |
| 1778 | engine->irq_keep_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; |
| 1779 | |
| 1780 | /* Override some for render ring. */ |
| 1781 | if (INTEL_GEN(dev_priv) >= 9) |
| 1782 | engine->init_hw = gen9_init_render_ring; |
| 1783 | else |
| 1784 | engine->init_hw = gen8_init_render_ring; |
| 1785 | engine->init_context = gen8_init_rcs_context; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1786 | engine->emit_flush = gen8_emit_flush_render; |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 1787 | engine->emit_breadcrumb = gen8_emit_breadcrumb_render; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 1788 | engine->emit_breadcrumb_sz = gen8_emit_breadcrumb_render_sz; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1789 | |
Chris Wilson | f51455d | 2017-01-10 14:47:34 +0000 | [diff] [blame] | 1790 | ret = intel_engine_create_scratch(engine, PAGE_SIZE); |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1791 | if (ret) |
| 1792 | return ret; |
| 1793 | |
| 1794 | ret = intel_init_workaround_bb(engine); |
| 1795 | if (ret) { |
| 1796 | /* |
| 1797 | * We continue even if we fail to initialize WA batch |
| 1798 | * because we only expect rare glitches but nothing |
| 1799 | * critical to prevent us from using GPU |
| 1800 | */ |
| 1801 | DRM_ERROR("WA batch buffer initialization failed: %d\n", |
| 1802 | ret); |
| 1803 | } |
| 1804 | |
Tvrtko Ursulin | d038fc7 | 2016-12-16 13:18:42 +0000 | [diff] [blame] | 1805 | return logical_ring_init(engine); |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 1806 | } |
| 1807 | |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 1808 | int logical_xcs_ring_init(struct intel_engine_cs *engine) |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 1809 | { |
| 1810 | logical_ring_setup(engine); |
| 1811 | |
| 1812 | return logical_ring_init(engine); |
| 1813 | } |
| 1814 | |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1815 | static u32 |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1816 | make_rpcs(struct drm_i915_private *dev_priv) |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1817 | { |
| 1818 | u32 rpcs = 0; |
| 1819 | |
| 1820 | /* |
| 1821 | * No explicit RPCS request is needed to ensure full |
| 1822 | * slice/subslice/EU enablement prior to Gen9. |
| 1823 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1824 | if (INTEL_GEN(dev_priv) < 9) |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1825 | return 0; |
| 1826 | |
| 1827 | /* |
| 1828 | * Starting in Gen9, render power gating can leave |
| 1829 | * slice/subslice/EU in a partially enabled state. We |
| 1830 | * must make an explicit request through RPCS for full |
| 1831 | * enablement. |
| 1832 | */ |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 1833 | if (INTEL_INFO(dev_priv)->sseu.has_slice_pg) { |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1834 | rpcs |= GEN8_RPCS_S_CNT_ENABLE; |
Imre Deak | f08a0c9 | 2016-08-31 19:13:04 +0300 | [diff] [blame] | 1835 | rpcs |= hweight8(INTEL_INFO(dev_priv)->sseu.slice_mask) << |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1836 | GEN8_RPCS_S_CNT_SHIFT; |
| 1837 | rpcs |= GEN8_RPCS_ENABLE; |
| 1838 | } |
| 1839 | |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 1840 | if (INTEL_INFO(dev_priv)->sseu.has_subslice_pg) { |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1841 | rpcs |= GEN8_RPCS_SS_CNT_ENABLE; |
Imre Deak | 57ec171 | 2016-08-31 19:13:05 +0300 | [diff] [blame] | 1842 | rpcs |= hweight8(INTEL_INFO(dev_priv)->sseu.subslice_mask) << |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1843 | GEN8_RPCS_SS_CNT_SHIFT; |
| 1844 | rpcs |= GEN8_RPCS_ENABLE; |
| 1845 | } |
| 1846 | |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 1847 | if (INTEL_INFO(dev_priv)->sseu.has_eu_pg) { |
| 1848 | rpcs |= INTEL_INFO(dev_priv)->sseu.eu_per_subslice << |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1849 | GEN8_RPCS_EU_MIN_SHIFT; |
Imre Deak | 43b6799 | 2016-08-31 19:13:02 +0300 | [diff] [blame] | 1850 | rpcs |= INTEL_INFO(dev_priv)->sseu.eu_per_subslice << |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1851 | GEN8_RPCS_EU_MAX_SHIFT; |
| 1852 | rpcs |= GEN8_RPCS_ENABLE; |
| 1853 | } |
| 1854 | |
| 1855 | return rpcs; |
| 1856 | } |
| 1857 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1858 | static u32 intel_lr_indirect_ctx_offset(struct intel_engine_cs *engine) |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 1859 | { |
| 1860 | u32 indirect_ctx_offset; |
| 1861 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1862 | switch (INTEL_GEN(engine->i915)) { |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 1863 | default: |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1864 | MISSING_CASE(INTEL_GEN(engine->i915)); |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 1865 | /* fall through */ |
Michel Thierry | 7bd0a2c | 2017-06-06 13:30:38 -0700 | [diff] [blame] | 1866 | case 10: |
| 1867 | indirect_ctx_offset = |
| 1868 | GEN10_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; |
| 1869 | break; |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 1870 | case 9: |
| 1871 | indirect_ctx_offset = |
| 1872 | GEN9_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; |
| 1873 | break; |
| 1874 | case 8: |
| 1875 | indirect_ctx_offset = |
| 1876 | GEN8_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; |
| 1877 | break; |
| 1878 | } |
| 1879 | |
| 1880 | return indirect_ctx_offset; |
| 1881 | } |
| 1882 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1883 | static void execlists_init_reg_state(u32 *regs, |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1884 | struct i915_gem_context *ctx, |
| 1885 | struct intel_engine_cs *engine, |
| 1886 | struct intel_ring *ring) |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 1887 | { |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1888 | struct drm_i915_private *dev_priv = engine->i915; |
| 1889 | struct i915_hw_ppgtt *ppgtt = ctx->ppgtt ?: dev_priv->mm.aliasing_ppgtt; |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1890 | u32 base = engine->mmio_base; |
| 1891 | bool rcs = engine->id == RCS; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 1892 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1893 | /* A context is actually a big batch buffer with several |
| 1894 | * MI_LOAD_REGISTER_IMM commands followed by (reg, value) pairs. The |
| 1895 | * values we are setting here are only for the first context restore: |
| 1896 | * on a subsequent save, the GPU will recreate this batchbuffer with new |
| 1897 | * values (including all the missing MI_LOAD_REGISTER_IMM commands that |
| 1898 | * we are not initializing here). |
| 1899 | */ |
| 1900 | regs[CTX_LRI_HEADER_0] = MI_LOAD_REGISTER_IMM(rcs ? 14 : 11) | |
| 1901 | MI_LRI_FORCE_POSTED; |
| 1902 | |
| 1903 | CTX_REG(regs, CTX_CONTEXT_CONTROL, RING_CONTEXT_CONTROL(engine), |
| 1904 | _MASKED_BIT_ENABLE(CTX_CTRL_INHIBIT_SYN_CTX_SWITCH | |
| 1905 | CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT | |
| 1906 | (HAS_RESOURCE_STREAMER(dev_priv) ? |
| 1907 | CTX_CTRL_RS_CTX_ENABLE : 0))); |
| 1908 | CTX_REG(regs, CTX_RING_HEAD, RING_HEAD(base), 0); |
| 1909 | CTX_REG(regs, CTX_RING_TAIL, RING_TAIL(base), 0); |
| 1910 | CTX_REG(regs, CTX_RING_BUFFER_START, RING_START(base), 0); |
| 1911 | CTX_REG(regs, CTX_RING_BUFFER_CONTROL, RING_CTL(base), |
| 1912 | RING_CTL_SIZE(ring->size) | RING_VALID); |
| 1913 | CTX_REG(regs, CTX_BB_HEAD_U, RING_BBADDR_UDW(base), 0); |
| 1914 | CTX_REG(regs, CTX_BB_HEAD_L, RING_BBADDR(base), 0); |
| 1915 | CTX_REG(regs, CTX_BB_STATE, RING_BBSTATE(base), RING_BB_PPGTT); |
| 1916 | CTX_REG(regs, CTX_SECOND_BB_HEAD_U, RING_SBBADDR_UDW(base), 0); |
| 1917 | CTX_REG(regs, CTX_SECOND_BB_HEAD_L, RING_SBBADDR(base), 0); |
| 1918 | CTX_REG(regs, CTX_SECOND_BB_STATE, RING_SBBSTATE(base), 0); |
| 1919 | if (rcs) { |
| 1920 | CTX_REG(regs, CTX_BB_PER_CTX_PTR, RING_BB_PER_CTX_PTR(base), 0); |
| 1921 | CTX_REG(regs, CTX_RCS_INDIRECT_CTX, RING_INDIRECT_CTX(base), 0); |
| 1922 | CTX_REG(regs, CTX_RCS_INDIRECT_CTX_OFFSET, |
| 1923 | RING_INDIRECT_CTX_OFFSET(base), 0); |
| 1924 | |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1925 | if (engine->wa_ctx.vma) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1926 | struct i915_ctx_workarounds *wa_ctx = &engine->wa_ctx; |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1927 | u32 ggtt_offset = i915_ggtt_offset(wa_ctx->vma); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1928 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1929 | regs[CTX_RCS_INDIRECT_CTX + 1] = |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1930 | (ggtt_offset + wa_ctx->indirect_ctx.offset) | |
| 1931 | (wa_ctx->indirect_ctx.size / CACHELINE_BYTES); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1932 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1933 | regs[CTX_RCS_INDIRECT_CTX_OFFSET + 1] = |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1934 | intel_lr_indirect_ctx_offset(engine) << 6; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1935 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1936 | regs[CTX_BB_PER_CTX_PTR + 1] = |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1937 | (ggtt_offset + wa_ctx->per_ctx.offset) | 0x01; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1938 | } |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 1939 | } |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1940 | |
| 1941 | regs[CTX_LRI_HEADER_1] = MI_LOAD_REGISTER_IMM(9) | MI_LRI_FORCE_POSTED; |
| 1942 | |
| 1943 | CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0); |
Ville Syrjälä | 0d925ea | 2015-11-04 23:20:11 +0200 | [diff] [blame] | 1944 | /* PDP values well be assigned later if needed */ |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1945 | CTX_REG(regs, CTX_PDP3_UDW, GEN8_RING_PDP_UDW(engine, 3), 0); |
| 1946 | CTX_REG(regs, CTX_PDP3_LDW, GEN8_RING_PDP_LDW(engine, 3), 0); |
| 1947 | CTX_REG(regs, CTX_PDP2_UDW, GEN8_RING_PDP_UDW(engine, 2), 0); |
| 1948 | CTX_REG(regs, CTX_PDP2_LDW, GEN8_RING_PDP_LDW(engine, 2), 0); |
| 1949 | CTX_REG(regs, CTX_PDP1_UDW, GEN8_RING_PDP_UDW(engine, 1), 0); |
| 1950 | CTX_REG(regs, CTX_PDP1_LDW, GEN8_RING_PDP_LDW(engine, 1), 0); |
| 1951 | CTX_REG(regs, CTX_PDP0_UDW, GEN8_RING_PDP_UDW(engine, 0), 0); |
| 1952 | CTX_REG(regs, CTX_PDP0_LDW, GEN8_RING_PDP_LDW(engine, 0), 0); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 1953 | |
Chris Wilson | 949e8ab | 2017-02-09 14:40:36 +0000 | [diff] [blame] | 1954 | if (ppgtt && i915_vm_is_48bit(&ppgtt->base)) { |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 1955 | /* 64b PPGTT (48bit canonical) |
| 1956 | * PDP0_DESCRIPTOR contains the base address to PML4 and |
| 1957 | * other PDP Descriptors are ignored. |
| 1958 | */ |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1959 | ASSIGN_CTX_PML4(ppgtt, regs); |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 1962 | if (rcs) { |
| 1963 | regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1); |
| 1964 | CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, |
| 1965 | make_rpcs(dev_priv)); |
Robert Bragg | 19f81df | 2017-06-13 12:23:03 +0100 | [diff] [blame] | 1966 | |
| 1967 | i915_oa_init_reg_state(engine, ctx, regs); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 1968 | } |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static int |
| 1972 | populate_lr_context(struct i915_gem_context *ctx, |
| 1973 | struct drm_i915_gem_object *ctx_obj, |
| 1974 | struct intel_engine_cs *engine, |
| 1975 | struct intel_ring *ring) |
| 1976 | { |
| 1977 | void *vaddr; |
| 1978 | int ret; |
| 1979 | |
| 1980 | ret = i915_gem_object_set_to_cpu_domain(ctx_obj, true); |
| 1981 | if (ret) { |
| 1982 | DRM_DEBUG_DRIVER("Could not set to CPU domain\n"); |
| 1983 | return ret; |
| 1984 | } |
| 1985 | |
| 1986 | vaddr = i915_gem_object_pin_map(ctx_obj, I915_MAP_WB); |
| 1987 | if (IS_ERR(vaddr)) { |
| 1988 | ret = PTR_ERR(vaddr); |
| 1989 | DRM_DEBUG_DRIVER("Could not map object pages! (%d)\n", ret); |
| 1990 | return ret; |
| 1991 | } |
Chris Wilson | a4f5ea6 | 2016-10-28 13:58:35 +0100 | [diff] [blame] | 1992 | ctx_obj->mm.dirty = true; |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1993 | |
| 1994 | /* The second page of the context object contains some fields which must |
| 1995 | * be set up prior to the first execution. */ |
| 1996 | |
| 1997 | execlists_init_reg_state(vaddr + LRC_STATE_PN * PAGE_SIZE, |
| 1998 | ctx, engine, ring); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 1999 | |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 2000 | i915_gem_object_unpin_map(ctx_obj); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2001 | |
| 2002 | return 0; |
| 2003 | } |
| 2004 | |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 2005 | static int execlists_context_deferred_alloc(struct i915_gem_context *ctx, |
Chris Wilson | 978f1e0 | 2016-04-28 09:56:54 +0100 | [diff] [blame] | 2006 | struct intel_engine_cs *engine) |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2007 | { |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2008 | struct drm_i915_gem_object *ctx_obj; |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 2009 | struct intel_context *ce = &ctx->engine[engine->id]; |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 2010 | struct i915_vma *vma; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2011 | uint32_t context_size; |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 2012 | struct intel_ring *ring; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2013 | int ret; |
| 2014 | |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 2015 | WARN_ON(ce->state); |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2016 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 2017 | context_size = round_up(engine->context_size, I915_GTT_PAGE_SIZE); |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2018 | |
Michel Thierry | 0b29c75 | 2017-09-13 09:56:00 +0100 | [diff] [blame] | 2019 | /* |
| 2020 | * Before the actual start of the context image, we insert a few pages |
| 2021 | * for our own use and for sharing with the GuC. |
| 2022 | */ |
| 2023 | context_size += LRC_HEADER_PAGES * PAGE_SIZE; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 2024 | |
Tvrtko Ursulin | 12d79d7 | 2016-12-01 14:16:37 +0000 | [diff] [blame] | 2025 | ctx_obj = i915_gem_object_create(ctx->i915, context_size); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 2026 | if (IS_ERR(ctx_obj)) { |
Dan Carpenter | 3126a66 | 2015-04-30 17:30:50 +0300 | [diff] [blame] | 2027 | DRM_DEBUG_DRIVER("Alloc LRC backing obj failed.\n"); |
Chris Wilson | fe3db79 | 2016-04-25 13:32:13 +0100 | [diff] [blame] | 2028 | return PTR_ERR(ctx_obj); |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2029 | } |
| 2030 | |
Chris Wilson | a01cb37a | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 2031 | vma = i915_vma_instance(ctx_obj, &ctx->i915->ggtt.base, NULL); |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 2032 | if (IS_ERR(vma)) { |
| 2033 | ret = PTR_ERR(vma); |
| 2034 | goto error_deref_obj; |
| 2035 | } |
| 2036 | |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 2037 | ring = intel_engine_create_ring(engine, ctx->ring_size); |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2038 | if (IS_ERR(ring)) { |
| 2039 | ret = PTR_ERR(ring); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 2040 | goto error_deref_obj; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2041 | } |
| 2042 | |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2043 | ret = populate_lr_context(ctx, ctx_obj, engine, ring); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2044 | if (ret) { |
| 2045 | DRM_DEBUG_DRIVER("Failed to populate LRC: %d\n", ret); |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2046 | goto error_ring_free; |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2047 | } |
| 2048 | |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2049 | ce->ring = ring; |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 2050 | ce->state = vma; |
Chuanxiao Dong | 0d402a2 | 2017-05-11 18:07:42 +0800 | [diff] [blame] | 2051 | ce->initialised |= engine->init_context == NULL; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2052 | |
| 2053 | return 0; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2054 | |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2055 | error_ring_free: |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 2056 | intel_ring_free(ring); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 2057 | error_deref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2058 | i915_gem_object_put(ctx_obj); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2059 | return ret; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2060 | } |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2061 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 2062 | void intel_lr_context_resume(struct drm_i915_private *dev_priv) |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2063 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2064 | struct intel_engine_cs *engine; |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2065 | struct i915_gem_context *ctx; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2066 | enum intel_engine_id id; |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2067 | |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2068 | /* Because we emit WA_TAIL_DWORDS there may be a disparity |
| 2069 | * between our bookkeeping in ce->ring->head and ce->ring->tail and |
| 2070 | * that stored in context. As we only write new commands from |
| 2071 | * ce->ring->tail onwards, everything before that is junk. If the GPU |
| 2072 | * starts reading from its RING_HEAD from the context, it may try to |
| 2073 | * execute that junk and die. |
| 2074 | * |
| 2075 | * So to avoid that we reset the context images upon resume. For |
| 2076 | * simplicity, we just zero everything out. |
| 2077 | */ |
Chris Wilson | 829a0af | 2017-06-20 12:05:45 +0100 | [diff] [blame] | 2078 | list_for_each_entry(ctx, &dev_priv->contexts.list, link) { |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2079 | for_each_engine(engine, dev_priv, id) { |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2080 | struct intel_context *ce = &ctx->engine[engine->id]; |
| 2081 | u32 *reg; |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2082 | |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2083 | if (!ce->state) |
| 2084 | continue; |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2085 | |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2086 | reg = i915_gem_object_pin_map(ce->state->obj, |
| 2087 | I915_MAP_WB); |
| 2088 | if (WARN_ON(IS_ERR(reg))) |
| 2089 | continue; |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 2090 | |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2091 | reg += LRC_STATE_PN * PAGE_SIZE / sizeof(*reg); |
| 2092 | reg[CTX_RING_HEAD+1] = 0; |
| 2093 | reg[CTX_RING_TAIL+1] = 0; |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2094 | |
Chris Wilson | a4f5ea6 | 2016-10-28 13:58:35 +0100 | [diff] [blame] | 2095 | ce->state->obj->mm.dirty = true; |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2096 | i915_gem_object_unpin_map(ce->state->obj); |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2097 | |
Chris Wilson | e6ba999 | 2017-04-25 14:00:49 +0100 | [diff] [blame] | 2098 | intel_ring_reset(ce->ring, 0); |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2099 | } |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2100 | } |
| 2101 | } |