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