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 | |
Oscar Mateo | b20385f | 2014-07-24 17:04:10 +0100 | [diff] [blame] | 136 | #include <drm/i915_drm.h> |
| 137 | #include "i915_drv.h" |
Chris Wilson | 7c2fa7f | 2017-11-10 14:26:34 +0000 | [diff] [blame] | 138 | #include "i915_gem_render_state.h" |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 139 | #include "i915_vgpu.h" |
Michel Thierry | 578f1ac | 2018-01-23 16:43:49 -0800 | [diff] [blame] | 140 | #include "intel_lrc_reg.h" |
Peter Antoine | 3bbaba0 | 2015-07-10 20:13:11 +0300 | [diff] [blame] | 141 | #include "intel_mocs.h" |
Oscar Mateo | 7d3c425 | 2018-04-10 09:12:46 -0700 | [diff] [blame] | 142 | #include "intel_workarounds.h" |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 143 | |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 144 | #define RING_EXECLIST_QFULL (1 << 0x2) |
| 145 | #define RING_EXECLIST1_VALID (1 << 0x3) |
| 146 | #define RING_EXECLIST0_VALID (1 << 0x4) |
| 147 | #define RING_EXECLIST_ACTIVE_STATUS (3 << 0xE) |
| 148 | #define RING_EXECLIST1_ACTIVE (1 << 0x11) |
| 149 | #define RING_EXECLIST0_ACTIVE (1 << 0x12) |
| 150 | |
| 151 | #define GEN8_CTX_STATUS_IDLE_ACTIVE (1 << 0) |
| 152 | #define GEN8_CTX_STATUS_PREEMPTED (1 << 1) |
| 153 | #define GEN8_CTX_STATUS_ELEMENT_SWITCH (1 << 2) |
| 154 | #define GEN8_CTX_STATUS_ACTIVE_IDLE (1 << 3) |
| 155 | #define GEN8_CTX_STATUS_COMPLETE (1 << 4) |
| 156 | #define GEN8_CTX_STATUS_LITE_RESTORE (1 << 15) |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 157 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 158 | #define GEN8_CTX_STATUS_COMPLETED_MASK \ |
Chris Wilson | d8747af | 2017-11-20 12:34:56 +0000 | [diff] [blame] | 159 | (GEN8_CTX_STATUS_COMPLETE | GEN8_CTX_STATUS_PREEMPTED) |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 160 | |
Chris Wilson | 0e93cdd | 2016-04-29 09:07:06 +0100 | [diff] [blame] | 161 | /* Typical size of the average request (2 pipecontrols and a MI_BB) */ |
| 162 | #define EXECLISTS_REQUEST_SIZE 64 /* bytes */ |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 163 | #define WA_TAIL_DWORDS 2 |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 164 | #define WA_TAIL_BYTES (sizeof(u32) * WA_TAIL_DWORDS) |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 165 | |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 166 | static int execlists_context_deferred_alloc(struct i915_gem_context *ctx, |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 167 | struct intel_engine_cs *engine, |
| 168 | struct intel_context *ce); |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 169 | static void execlists_init_reg_state(u32 *reg_state, |
| 170 | struct i915_gem_context *ctx, |
| 171 | struct intel_engine_cs *engine, |
| 172 | struct intel_ring *ring); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 173 | |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 174 | static inline struct i915_priolist *to_priolist(struct rb_node *rb) |
| 175 | { |
| 176 | return rb_entry(rb, struct i915_priolist, node); |
| 177 | } |
| 178 | |
| 179 | static inline int rq_prio(const struct i915_request *rq) |
| 180 | { |
Chris Wilson | b7268c5 | 2018-04-18 19:40:52 +0100 | [diff] [blame] | 181 | return rq->sched.attr.priority; |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static inline bool need_preempt(const struct intel_engine_cs *engine, |
| 185 | const struct i915_request *last, |
| 186 | int prio) |
| 187 | { |
Chris Wilson | 2a694fe | 2018-04-03 19:35:37 +0100 | [diff] [blame] | 188 | return (intel_engine_has_preemption(engine) && |
Chris Wilson | c5ce3b8 | 2018-05-01 13:21:31 +0100 | [diff] [blame] | 189 | __execlists_need_preempt(prio, rq_prio(last)) && |
| 190 | !i915_request_completed(last)); |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 193 | /* |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 194 | * The context descriptor encodes various attributes of a context, |
| 195 | * including its GTT address and some flags. Because it's fairly |
| 196 | * expensive to calculate, we'll just do it once and cache the result, |
| 197 | * which remains valid until the context is unpinned. |
| 198 | * |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 199 | * This is what a descriptor looks like, from LSB to MSB:: |
| 200 | * |
Mika Kuoppala | 2355cf0 | 2017-01-27 15:03:09 +0200 | [diff] [blame] | 201 | * bits 0-11: flags, GEN8_CTX_* (cached in ctx->desc_template) |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 202 | * bits 12-31: LRCA, GTT address of (the HWSP of) this context |
Lionel Landwerlin | 218b500 | 2018-06-02 12:29:45 +0100 | [diff] [blame] | 203 | * bits 32-52: ctx ID, a globally unique tag (highest bit used by GuC) |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 204 | * bits 53-54: mbz, reserved for use by hardware |
| 205 | * bits 55-63: group ID, currently unused and set to 0 |
Daniele Ceraolo Spurio | ac52da6 | 2018-03-02 18:14:58 +0200 | [diff] [blame] | 206 | * |
| 207 | * Starting from Gen11, the upper dword of the descriptor has a new format: |
| 208 | * |
| 209 | * bits 32-36: reserved |
| 210 | * bits 37-47: SW context ID |
| 211 | * bits 48:53: engine instance |
| 212 | * bit 54: mbz, reserved for use by hardware |
| 213 | * bits 55-60: SW counter |
| 214 | * bits 61-63: engine class |
| 215 | * |
| 216 | * engine info, SW context ID and SW counter need to form a unique number |
| 217 | * (Context ID) per lrc. |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 218 | */ |
| 219 | static void |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 220 | intel_lr_context_descriptor_update(struct i915_gem_context *ctx, |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 221 | struct intel_engine_cs *engine, |
| 222 | struct intel_context *ce) |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 223 | { |
Chris Wilson | 7069b14 | 2016-04-28 09:56:52 +0100 | [diff] [blame] | 224 | u64 desc; |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 225 | |
Daniele Ceraolo Spurio | ac52da6 | 2018-03-02 18:14:58 +0200 | [diff] [blame] | 226 | BUILD_BUG_ON(MAX_CONTEXT_HW_ID > (BIT(GEN8_CTX_ID_WIDTH))); |
| 227 | BUILD_BUG_ON(GEN11_MAX_CONTEXT_HW_ID > (BIT(GEN11_SW_CTX_ID_WIDTH))); |
Chris Wilson | 7069b14 | 2016-04-28 09:56:52 +0100 | [diff] [blame] | 228 | |
Mika Kuoppala | 2355cf0 | 2017-01-27 15:03:09 +0200 | [diff] [blame] | 229 | desc = ctx->desc_template; /* bits 0-11 */ |
Daniele Ceraolo Spurio | ac52da6 | 2018-03-02 18:14:58 +0200 | [diff] [blame] | 230 | GEM_BUG_ON(desc & GENMASK_ULL(63, 12)); |
| 231 | |
Michel Thierry | 0b29c75 | 2017-09-13 09:56:00 +0100 | [diff] [blame] | 232 | desc |= i915_ggtt_offset(ce->state) + LRC_HEADER_PAGES * PAGE_SIZE; |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 233 | /* bits 12-31 */ |
Daniele Ceraolo Spurio | ac52da6 | 2018-03-02 18:14:58 +0200 | [diff] [blame] | 234 | GEM_BUG_ON(desc & GENMASK_ULL(63, 32)); |
| 235 | |
Lionel Landwerlin | 61d5676 | 2018-06-02 12:29:46 +0100 | [diff] [blame] | 236 | /* |
| 237 | * The following 32bits are copied into the OA reports (dword 2). |
| 238 | * Consider updating oa_get_render_ctx_id in i915_perf.c when changing |
| 239 | * anything below. |
| 240 | */ |
Daniele Ceraolo Spurio | ac52da6 | 2018-03-02 18:14:58 +0200 | [diff] [blame] | 241 | if (INTEL_GEN(ctx->i915) >= 11) { |
| 242 | GEM_BUG_ON(ctx->hw_id >= BIT(GEN11_SW_CTX_ID_WIDTH)); |
| 243 | desc |= (u64)ctx->hw_id << GEN11_SW_CTX_ID_SHIFT; |
| 244 | /* bits 37-47 */ |
| 245 | |
| 246 | desc |= (u64)engine->instance << GEN11_ENGINE_INSTANCE_SHIFT; |
| 247 | /* bits 48-53 */ |
| 248 | |
| 249 | /* TODO: decide what to do with SW counter (bits 55-60) */ |
| 250 | |
| 251 | desc |= (u64)engine->class << GEN11_ENGINE_CLASS_SHIFT; |
| 252 | /* bits 61-63 */ |
| 253 | } else { |
| 254 | GEM_BUG_ON(ctx->hw_id >= BIT(GEN8_CTX_ID_WIDTH)); |
| 255 | desc |= (u64)ctx->hw_id << GEN8_CTX_ID_SHIFT; /* bits 32-52 */ |
| 256 | } |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 257 | |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 258 | ce->lrc_desc = desc; |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 261 | static void unwind_wa_tail(struct i915_request *rq) |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 262 | { |
| 263 | rq->tail = intel_ring_wrap(rq->ring, rq->wa_tail - WA_TAIL_BYTES); |
| 264 | assert_ring_tail_valid(rq->ring, rq->tail); |
| 265 | } |
| 266 | |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 267 | static void __unwind_incomplete_requests(struct intel_engine_cs *engine) |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 268 | { |
Chris Wilson | b16c765 | 2018-10-01 15:47:53 +0100 | [diff] [blame] | 269 | struct i915_request *rq, *rn, *active = NULL; |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 270 | struct list_head *uninitialized_var(pl); |
Chris Wilson | b16c765 | 2018-10-01 15:47:53 +0100 | [diff] [blame] | 271 | int prio = I915_PRIORITY_INVALID | I915_PRIORITY_NEWCLIENT; |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 272 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 273 | lockdep_assert_held(&engine->timeline.lock); |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 274 | |
| 275 | list_for_each_entry_safe_reverse(rq, rn, |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 276 | &engine->timeline.requests, |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 277 | link) { |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 278 | if (i915_request_completed(rq)) |
Chris Wilson | b16c765 | 2018-10-01 15:47:53 +0100 | [diff] [blame] | 279 | break; |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 280 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 281 | __i915_request_unsubmit(rq); |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 282 | unwind_wa_tail(rq); |
| 283 | |
Chris Wilson | bc2477f | 2018-10-03 12:09:41 +0100 | [diff] [blame] | 284 | GEM_BUG_ON(rq->hw_context->active); |
| 285 | |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 286 | GEM_BUG_ON(rq_prio(rq) == I915_PRIORITY_INVALID); |
Chris Wilson | b16c765 | 2018-10-01 15:47:53 +0100 | [diff] [blame] | 287 | if (rq_prio(rq) != prio) { |
| 288 | prio = rq_prio(rq); |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 289 | pl = i915_sched_lookup_priolist(engine, prio); |
Michał Winiarski | 097a948 | 2017-09-28 20:39:01 +0100 | [diff] [blame] | 290 | } |
Chris Wilson | 8db05f5 | 2018-09-19 20:55:16 +0100 | [diff] [blame] | 291 | GEM_BUG_ON(RB_EMPTY_ROOT(&engine->execlists.queue.rb_root)); |
Michał Winiarski | 097a948 | 2017-09-28 20:39:01 +0100 | [diff] [blame] | 292 | |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 293 | list_add(&rq->sched.link, pl); |
Chris Wilson | b16c765 | 2018-10-01 15:47:53 +0100 | [diff] [blame] | 294 | |
| 295 | active = rq; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * The active request is now effectively the start of a new client |
| 300 | * stream, so give it the equivalent small priority bump to prevent |
| 301 | * it being gazumped a second time by another peer. |
| 302 | */ |
| 303 | if (!(prio & I915_PRIORITY_NEWCLIENT)) { |
| 304 | prio |= I915_PRIORITY_NEWCLIENT; |
| 305 | list_move_tail(&active->sched.link, |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 306 | i915_sched_lookup_priolist(engine, prio)); |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 307 | } |
| 308 | } |
| 309 | |
Michał Winiarski | c41937fd | 2017-10-26 15:35:58 +0200 | [diff] [blame] | 310 | void |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 311 | execlists_unwind_incomplete_requests(struct intel_engine_execlists *execlists) |
| 312 | { |
| 313 | struct intel_engine_cs *engine = |
| 314 | container_of(execlists, typeof(*engine), execlists); |
Chris Wilson | 4413c47 | 2018-05-08 22:03:17 +0100 | [diff] [blame] | 315 | |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 316 | __unwind_incomplete_requests(engine); |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 317 | } |
| 318 | |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 319 | static inline void |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 320 | execlists_context_status_change(struct i915_request *rq, unsigned long status) |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 321 | { |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 322 | /* |
| 323 | * Only used when GVT-g is enabled now. When GVT-g is disabled, |
| 324 | * The compiler should eliminate this function as dead-code. |
| 325 | */ |
| 326 | if (!IS_ENABLED(CONFIG_DRM_I915_GVT)) |
| 327 | return; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 328 | |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 329 | atomic_notifier_call_chain(&rq->engine->context_status_notifier, |
| 330 | status, rq); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Chris Wilson | f260520 | 2018-03-31 14:06:26 +0100 | [diff] [blame] | 333 | inline void |
| 334 | execlists_user_begin(struct intel_engine_execlists *execlists, |
| 335 | const struct execlist_port *port) |
| 336 | { |
| 337 | execlists_set_active_once(execlists, EXECLISTS_ACTIVE_USER); |
| 338 | } |
| 339 | |
| 340 | inline void |
| 341 | execlists_user_end(struct intel_engine_execlists *execlists) |
| 342 | { |
| 343 | execlists_clear_active(execlists, EXECLISTS_ACTIVE_USER); |
| 344 | } |
| 345 | |
Tvrtko Ursulin | 73fd9d3 | 2017-11-21 18:18:47 +0000 | [diff] [blame] | 346 | static inline void |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 347 | execlists_context_schedule_in(struct i915_request *rq) |
Tvrtko Ursulin | 73fd9d3 | 2017-11-21 18:18:47 +0000 | [diff] [blame] | 348 | { |
Chris Wilson | bc2477f | 2018-10-03 12:09:41 +0100 | [diff] [blame] | 349 | GEM_BUG_ON(rq->hw_context->active); |
| 350 | |
Tvrtko Ursulin | 73fd9d3 | 2017-11-21 18:18:47 +0000 | [diff] [blame] | 351 | execlists_context_status_change(rq, INTEL_CONTEXT_SCHEDULE_IN); |
Tvrtko Ursulin | 30e17b7 | 2017-11-21 18:18:48 +0000 | [diff] [blame] | 352 | intel_engine_context_in(rq->engine); |
Chris Wilson | bc2477f | 2018-10-03 12:09:41 +0100 | [diff] [blame] | 353 | rq->hw_context->active = rq->engine; |
Tvrtko Ursulin | 73fd9d3 | 2017-11-21 18:18:47 +0000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | static inline void |
Chris Wilson | b9b7742 | 2018-05-03 00:02:02 +0100 | [diff] [blame] | 357 | execlists_context_schedule_out(struct i915_request *rq, unsigned long status) |
Tvrtko Ursulin | 73fd9d3 | 2017-11-21 18:18:47 +0000 | [diff] [blame] | 358 | { |
Chris Wilson | bc2477f | 2018-10-03 12:09:41 +0100 | [diff] [blame] | 359 | rq->hw_context->active = NULL; |
Tvrtko Ursulin | 30e17b7 | 2017-11-21 18:18:48 +0000 | [diff] [blame] | 360 | intel_engine_context_out(rq->engine); |
Chris Wilson | b9b7742 | 2018-05-03 00:02:02 +0100 | [diff] [blame] | 361 | execlists_context_status_change(rq, status); |
| 362 | trace_i915_request_out(rq); |
Tvrtko Ursulin | 73fd9d3 | 2017-11-21 18:18:47 +0000 | [diff] [blame] | 363 | } |
| 364 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 365 | static u64 execlists_update_context(struct i915_request *rq) |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 366 | { |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 367 | struct intel_context *ce = rq->hw_context; |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 368 | |
Chris Wilson | e889426 | 2018-12-07 09:02:13 +0000 | [diff] [blame] | 369 | ce->lrc_reg_state[CTX_RING_TAIL + 1] = |
| 370 | intel_ring_set_tail(rq->ring, rq->tail); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 371 | |
Chris Wilson | 987abd5 | 2018-11-08 08:17:38 +0000 | [diff] [blame] | 372 | /* |
| 373 | * Make sure the context image is complete before we submit it to HW. |
| 374 | * |
| 375 | * Ostensibly, writes (including the WCB) should be flushed prior to |
| 376 | * an uncached write such as our mmio register access, the empirical |
| 377 | * evidence (esp. on Braswell) suggests that the WC write into memory |
| 378 | * may not be visible to the HW prior to the completion of the UC |
| 379 | * register write and that we may begin execution from the context |
| 380 | * before its image is complete leading to invalid PD chasing. |
Chris Wilson | 490b8c6 | 2018-12-06 08:44:31 +0000 | [diff] [blame] | 381 | * |
| 382 | * Furthermore, Braswell, at least, wants a full mb to be sure that |
| 383 | * the writes are coherent in memory (visible to the GPU) prior to |
| 384 | * execution, and not just visible to other CPUs (as is the result of |
| 385 | * wmb). |
Chris Wilson | 987abd5 | 2018-11-08 08:17:38 +0000 | [diff] [blame] | 386 | */ |
Chris Wilson | 490b8c6 | 2018-12-06 08:44:31 +0000 | [diff] [blame] | 387 | mb(); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 388 | return ce->lrc_desc; |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 389 | } |
| 390 | |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 391 | static inline void write_desc(struct intel_engine_execlists *execlists, u64 desc, u32 port) |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 392 | { |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 393 | if (execlists->ctrl_reg) { |
| 394 | writel(lower_32_bits(desc), execlists->submit_reg + port * 2); |
| 395 | writel(upper_32_bits(desc), execlists->submit_reg + port * 2 + 1); |
| 396 | } else { |
| 397 | writel(upper_32_bits(desc), execlists->submit_reg); |
| 398 | writel(lower_32_bits(desc), execlists->submit_reg); |
| 399 | } |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 402 | static void execlists_submit_ports(struct intel_engine_cs *engine) |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 403 | { |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 404 | struct intel_engine_execlists *execlists = &engine->execlists; |
| 405 | struct execlist_port *port = execlists->port; |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 406 | unsigned int n; |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 407 | |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 408 | /* |
Chris Wilson | d78d334 | 2018-07-19 08:50:29 +0100 | [diff] [blame] | 409 | * We can skip acquiring intel_runtime_pm_get() here as it was taken |
| 410 | * on our behalf by the request (see i915_gem_mark_busy()) and it will |
| 411 | * not be relinquished until the device is idle (see |
| 412 | * i915_gem_idle_work_handler()). As a precaution, we make sure |
| 413 | * that all ELSP are drained i.e. we have processed the CSB, |
| 414 | * before allowing ourselves to idle and calling intel_runtime_pm_put(). |
| 415 | */ |
| 416 | GEM_BUG_ON(!engine->i915->gt.awake); |
| 417 | |
| 418 | /* |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 419 | * ELSQ note: the submit queue is not cleared after being submitted |
| 420 | * to the HW so we need to make sure we always clean it up. This is |
| 421 | * currently ensured by the fact that we always write the same number |
| 422 | * of elsq entries, keep this in mind before changing the loop below. |
| 423 | */ |
| 424 | for (n = execlists_num_ports(execlists); n--; ) { |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 425 | struct i915_request *rq; |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 426 | unsigned int count; |
| 427 | u64 desc; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 428 | |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 429 | rq = port_unpack(&port[n], &count); |
| 430 | if (rq) { |
| 431 | GEM_BUG_ON(count > !n); |
| 432 | if (!count++) |
Tvrtko Ursulin | 73fd9d3 | 2017-11-21 18:18:47 +0000 | [diff] [blame] | 433 | execlists_context_schedule_in(rq); |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 434 | port_set(&port[n], port_pack(rq, count)); |
| 435 | desc = execlists_update_context(rq); |
| 436 | GEM_DEBUG_EXEC(port[n].context_id = upper_32_bits(desc)); |
Chris Wilson | bccd3b8 | 2017-11-09 14:30:19 +0000 | [diff] [blame] | 437 | |
Tvrtko Ursulin | 0c5c7df | 2018-04-06 13:35:14 +0100 | [diff] [blame] | 438 | GEM_TRACE("%s in[%d]: ctx=%d.%d, global=%d (fence %llx:%d) (current %d), prio=%d\n", |
Chris Wilson | bccd3b8 | 2017-11-09 14:30:19 +0000 | [diff] [blame] | 439 | engine->name, n, |
Chris Wilson | 16c8619 | 2017-12-19 22:09:16 +0000 | [diff] [blame] | 440 | port[n].context_id, count, |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 441 | rq->global_seqno, |
Tvrtko Ursulin | 0c5c7df | 2018-04-06 13:35:14 +0100 | [diff] [blame] | 442 | rq->fence.context, rq->fence.seqno, |
Chris Wilson | e770276 | 2018-03-27 22:01:57 +0100 | [diff] [blame] | 443 | intel_engine_get_seqno(engine), |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 444 | rq_prio(rq)); |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 445 | } else { |
| 446 | GEM_BUG_ON(!n); |
| 447 | desc = 0; |
| 448 | } |
| 449 | |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 450 | write_desc(execlists, desc, n); |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 451 | } |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 452 | |
| 453 | /* we need to manually load the submit queue */ |
| 454 | if (execlists->ctrl_reg) |
| 455 | writel(EL_CTRL_LOAD, execlists->ctrl_reg); |
| 456 | |
| 457 | execlists_clear_active(execlists, EXECLISTS_ACTIVE_HWACK); |
Chris Wilson | bbd6c47 | 2016-09-09 14:11:45 +0100 | [diff] [blame] | 458 | } |
| 459 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 460 | static bool ctx_single_port_submission(const struct intel_context *ce) |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 461 | { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 462 | return (IS_ENABLED(CONFIG_DRM_I915_GVT) && |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 463 | i915_gem_context_force_single_submission(ce->gem_context)); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 464 | } |
| 465 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 466 | static bool can_merge_ctx(const struct intel_context *prev, |
| 467 | const struct intel_context *next) |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 468 | { |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 469 | if (prev != next) |
| 470 | return false; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 471 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 472 | if (ctx_single_port_submission(prev)) |
| 473 | return false; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 474 | |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 475 | return true; |
| 476 | } |
Peter Antoine | 779949f | 2015-05-11 16:03:27 +0100 | [diff] [blame] | 477 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 478 | static void port_assign(struct execlist_port *port, struct i915_request *rq) |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 479 | { |
| 480 | GEM_BUG_ON(rq == port_request(port)); |
| 481 | |
| 482 | if (port_isset(port)) |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 483 | i915_request_put(port_request(port)); |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 484 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 485 | port_set(port, port_pack(i915_request_get(rq), port_count(port))); |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 486 | } |
| 487 | |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 488 | static void inject_preempt_context(struct intel_engine_cs *engine) |
| 489 | { |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 490 | struct intel_engine_execlists *execlists = &engine->execlists; |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 491 | struct intel_context *ce = |
Chris Wilson | ab82a06 | 2018-04-30 14:15:01 +0100 | [diff] [blame] | 492 | to_intel_context(engine->i915->preempt_context, engine); |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 493 | unsigned int n; |
| 494 | |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 495 | GEM_BUG_ON(execlists->preempt_complete_status != |
Chris Wilson | d637637 | 2018-02-07 21:05:44 +0000 | [diff] [blame] | 496 | upper_32_bits(ce->lrc_desc)); |
Chris Wilson | 09b1a4e | 2018-01-25 11:24:42 +0000 | [diff] [blame] | 497 | |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 498 | /* |
| 499 | * Switch to our empty preempt context so |
| 500 | * the state of the GPU is known (idle). |
| 501 | */ |
Chris Wilson | 16a8739 | 2017-12-20 09:06:26 +0000 | [diff] [blame] | 502 | GEM_TRACE("%s\n", engine->name); |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 503 | for (n = execlists_num_ports(execlists); --n; ) |
| 504 | write_desc(execlists, 0, n); |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 505 | |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 506 | write_desc(execlists, ce->lrc_desc, n); |
| 507 | |
| 508 | /* we need to manually load the submit queue */ |
| 509 | if (execlists->ctrl_reg) |
| 510 | writel(EL_CTRL_LOAD, execlists->ctrl_reg); |
| 511 | |
Chris Wilson | ef2fb72 | 2018-05-16 19:33:50 +0100 | [diff] [blame] | 512 | execlists_clear_active(execlists, EXECLISTS_ACTIVE_HWACK); |
| 513 | execlists_set_active(execlists, EXECLISTS_ACTIVE_PREEMPT); |
| 514 | } |
| 515 | |
| 516 | static void complete_preempt_context(struct intel_engine_execlists *execlists) |
| 517 | { |
| 518 | GEM_BUG_ON(!execlists_is_active(execlists, EXECLISTS_ACTIVE_PREEMPT)); |
| 519 | |
Chris Wilson | 0f6b79f | 2018-07-16 14:21:54 +0100 | [diff] [blame] | 520 | if (inject_preempt_hang(execlists)) |
| 521 | return; |
| 522 | |
Chris Wilson | ef2fb72 | 2018-05-16 19:33:50 +0100 | [diff] [blame] | 523 | execlists_cancel_port_requests(execlists); |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 524 | __unwind_incomplete_requests(container_of(execlists, |
| 525 | struct intel_engine_cs, |
| 526 | execlists)); |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 527 | } |
| 528 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 529 | static void execlists_dequeue(struct intel_engine_cs *engine) |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 530 | { |
Mika Kuoppala | 7a62cc6 | 2017-09-22 15:43:06 +0300 | [diff] [blame] | 531 | struct intel_engine_execlists * const execlists = &engine->execlists; |
| 532 | struct execlist_port *port = execlists->port; |
Mika Kuoppala | 76e7008 | 2017-09-22 15:43:07 +0300 | [diff] [blame] | 533 | const struct execlist_port * const last_port = |
| 534 | &execlists->port[execlists->port_mask]; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 535 | struct i915_request *last = port_request(port); |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 536 | struct rb_node *rb; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 537 | bool submit = false; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 538 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 539 | /* |
| 540 | * Hardware submission is through 2 ports. Conceptually each port |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 541 | * has a (RING_START, RING_HEAD, RING_TAIL) tuple. RING_START is |
| 542 | * static for a context, and unique to each, so we only execute |
| 543 | * requests belonging to a single context from each ring. RING_HEAD |
| 544 | * is maintained by the CS in the context image, it marks the place |
| 545 | * where it got up to last time, and through RING_TAIL we tell the CS |
| 546 | * where we want to execute up to this time. |
| 547 | * |
| 548 | * In this list the requests are in order of execution. Consecutive |
| 549 | * requests from the same context are adjacent in the ringbuffer. We |
| 550 | * can combine these requests into a single RING_TAIL update: |
| 551 | * |
| 552 | * RING_HEAD...req1...req2 |
| 553 | * ^- RING_TAIL |
| 554 | * since to execute req2 the CS must first execute req1. |
| 555 | * |
| 556 | * Our goal then is to point each port to the end of a consecutive |
| 557 | * sequence of requests as being the most optimal (fewest wake ups |
| 558 | * and context switches) submission. |
| 559 | */ |
| 560 | |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 561 | if (last) { |
| 562 | /* |
| 563 | * Don't resubmit or switch until all outstanding |
| 564 | * preemptions (lite-restore) are seen. Then we |
| 565 | * know the next preemption status we see corresponds |
| 566 | * to this ELSP update. |
| 567 | */ |
Chris Wilson | eed7ec5 | 2018-03-24 12:58:29 +0000 | [diff] [blame] | 568 | GEM_BUG_ON(!execlists_is_active(execlists, |
| 569 | EXECLISTS_ACTIVE_USER)); |
Michel Thierry | ba74cb1 | 2017-11-20 12:34:58 +0000 | [diff] [blame] | 570 | GEM_BUG_ON(!port_count(&port[0])); |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 571 | |
Michel Thierry | ba74cb1 | 2017-11-20 12:34:58 +0000 | [diff] [blame] | 572 | /* |
| 573 | * If we write to ELSP a second time before the HW has had |
| 574 | * a chance to respond to the previous write, we can confuse |
| 575 | * the HW and hit "undefined behaviour". After writing to ELSP, |
| 576 | * we must then wait until we see a context-switch event from |
| 577 | * the HW to indicate that it has had a chance to respond. |
| 578 | */ |
| 579 | if (!execlists_is_active(execlists, EXECLISTS_ACTIVE_HWACK)) |
Chris Wilson | 0b02bef | 2018-06-28 21:12:04 +0100 | [diff] [blame] | 580 | return; |
Michel Thierry | ba74cb1 | 2017-11-20 12:34:58 +0000 | [diff] [blame] | 581 | |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 582 | if (need_preempt(engine, last, execlists->queue_priority)) { |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 583 | inject_preempt_context(engine); |
Chris Wilson | 0b02bef | 2018-06-28 21:12:04 +0100 | [diff] [blame] | 584 | return; |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 585 | } |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 586 | |
| 587 | /* |
| 588 | * In theory, we could coalesce more requests onto |
| 589 | * the second port (the first port is active, with |
| 590 | * no preemptions pending). However, that means we |
| 591 | * then have to deal with the possible lite-restore |
| 592 | * of the second port (as we submit the ELSP, there |
| 593 | * may be a context-switch) but also we may complete |
| 594 | * the resubmission before the context-switch. Ergo, |
| 595 | * coalescing onto the second port will cause a |
| 596 | * preemption event, but we cannot predict whether |
| 597 | * that will affect port[0] or port[1]. |
| 598 | * |
| 599 | * If the second port is already active, we can wait |
| 600 | * until the next context-switch before contemplating |
| 601 | * new requests. The GPU will be busy and we should be |
| 602 | * able to resubmit the new ELSP before it idles, |
| 603 | * avoiding pipeline bubbles (momentary pauses where |
| 604 | * the driver is unable to keep up the supply of new |
| 605 | * work). However, we have to double check that the |
| 606 | * priorities of the ports haven't been switch. |
| 607 | */ |
| 608 | if (port_count(&port[1])) |
Chris Wilson | 0b02bef | 2018-06-28 21:12:04 +0100 | [diff] [blame] | 609 | return; |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 610 | |
| 611 | /* |
| 612 | * WaIdleLiteRestore:bdw,skl |
| 613 | * Apply the wa NOOPs to prevent |
| 614 | * ring:HEAD == rq:TAIL as we resubmit the |
| 615 | * request. See gen8_emit_breadcrumb() for |
| 616 | * where we prepare the padding after the |
| 617 | * end of the request. |
| 618 | */ |
| 619 | last->tail = last->wa_tail; |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 620 | } |
| 621 | |
Chris Wilson | 655250a | 2018-06-29 08:53:20 +0100 | [diff] [blame] | 622 | while ((rb = rb_first_cached(&execlists->queue))) { |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 623 | struct i915_priolist *p = to_priolist(rb); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 624 | struct i915_request *rq, *rn; |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 625 | int i; |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 626 | |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 627 | priolist_for_each_request_consume(rq, rn, p, i) { |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 628 | /* |
| 629 | * Can we combine this request with the current port? |
| 630 | * It has to be the same context/ringbuffer and not |
| 631 | * have any exceptions (e.g. GVT saying never to |
| 632 | * combine contexts). |
| 633 | * |
| 634 | * If we can combine the requests, we can execute both |
| 635 | * by updating the RING_TAIL to point to the end of the |
| 636 | * second request, and so we never need to tell the |
| 637 | * hardware about the first. |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 638 | */ |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 639 | if (last && |
| 640 | !can_merge_ctx(rq->hw_context, last->hw_context)) { |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 641 | /* |
| 642 | * If we are on the second port and cannot |
| 643 | * combine this request with the last, then we |
| 644 | * are done. |
| 645 | */ |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 646 | if (port == last_port) |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 647 | goto done; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 648 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 649 | /* |
| 650 | * If GVT overrides us we only ever submit |
| 651 | * port[0], leaving port[1] empty. Note that we |
| 652 | * also have to be careful that we don't queue |
| 653 | * the same context (even though a different |
| 654 | * request) to the second port. |
| 655 | */ |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 656 | if (ctx_single_port_submission(last->hw_context) || |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 657 | ctx_single_port_submission(rq->hw_context)) |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 658 | goto done; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 659 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 660 | GEM_BUG_ON(last->hw_context == rq->hw_context); |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 661 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 662 | if (submit) |
| 663 | port_assign(port, last); |
| 664 | port++; |
Mika Kuoppala | 7a62cc6 | 2017-09-22 15:43:06 +0300 | [diff] [blame] | 665 | |
| 666 | GEM_BUG_ON(port_isset(port)); |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 667 | } |
| 668 | |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 669 | list_del_init(&rq->sched.link); |
| 670 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 671 | __i915_request_submit(rq); |
| 672 | trace_i915_request_in(rq, port_index(port, execlists)); |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 673 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 674 | last = rq; |
| 675 | submit = true; |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 676 | } |
Chris Wilson | d55ac5b | 2016-11-14 20:40:59 +0000 | [diff] [blame] | 677 | |
Chris Wilson | 655250a | 2018-06-29 08:53:20 +0100 | [diff] [blame] | 678 | rb_erase_cached(&p->node, &execlists->queue); |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 679 | if (p->priority != I915_PRIORITY_NORMAL) |
Chris Wilson | c5cf9a9 | 2017-05-17 13:10:04 +0100 | [diff] [blame] | 680 | kmem_cache_free(engine->i915->priorities, p); |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 681 | } |
Chris Wilson | 15c83c4 | 2018-04-11 11:39:29 +0100 | [diff] [blame] | 682 | |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 683 | done: |
Chris Wilson | 15c83c4 | 2018-04-11 11:39:29 +0100 | [diff] [blame] | 684 | /* |
| 685 | * Here be a bit of magic! Or sleight-of-hand, whichever you prefer. |
| 686 | * |
| 687 | * We choose queue_priority such that if we add a request of greater |
| 688 | * priority than this, we kick the submission tasklet to decide on |
| 689 | * the right order of submitting the requests to hardware. We must |
| 690 | * also be prepared to reorder requests as they are in-flight on the |
| 691 | * HW. We derive the queue_priority then as the first "hole" in |
| 692 | * the HW submission ports and if there are no available slots, |
| 693 | * the priority of the lowest executing request, i.e. last. |
| 694 | * |
| 695 | * When we do receive a higher priority request ready to run from the |
| 696 | * user, see queue_request(), the queue_priority is bumped to that |
| 697 | * request triggering preemption on the next dequeue (or subsequent |
| 698 | * interrupt for secondary ports). |
| 699 | */ |
| 700 | execlists->queue_priority = |
| 701 | port != execlists->port ? rq_prio(last) : INT_MIN; |
| 702 | |
Chris Wilson | 0b02bef | 2018-06-28 21:12:04 +0100 | [diff] [blame] | 703 | if (submit) { |
Chris Wilson | 77f0d0e | 2017-05-17 13:10:00 +0100 | [diff] [blame] | 704 | port_assign(port, last); |
Chris Wilson | 0b02bef | 2018-06-28 21:12:04 +0100 | [diff] [blame] | 705 | execlists_submit_ports(engine); |
| 706 | } |
Chris Wilson | 339ccd3 | 2018-02-15 16:25:53 +0000 | [diff] [blame] | 707 | |
| 708 | /* We must always keep the beast fed if we have work piled up */ |
Chris Wilson | 655250a | 2018-06-29 08:53:20 +0100 | [diff] [blame] | 709 | GEM_BUG_ON(rb_first_cached(&execlists->queue) && |
| 710 | !port_isset(execlists->port)); |
Chris Wilson | 339ccd3 | 2018-02-15 16:25:53 +0000 | [diff] [blame] | 711 | |
Chris Wilson | 4413c47 | 2018-05-08 22:03:17 +0100 | [diff] [blame] | 712 | /* Re-evaluate the executing context setup after each preemptive kick */ |
| 713 | if (last) |
Chris Wilson | f260520 | 2018-03-31 14:06:26 +0100 | [diff] [blame] | 714 | execlists_user_begin(execlists, execlists->port); |
Chris Wilson | 4413c47 | 2018-05-08 22:03:17 +0100 | [diff] [blame] | 715 | |
Chris Wilson | 0b02bef | 2018-06-28 21:12:04 +0100 | [diff] [blame] | 716 | /* If the engine is now idle, so should be the flag; and vice versa. */ |
| 717 | GEM_BUG_ON(execlists_is_active(&engine->execlists, |
| 718 | EXECLISTS_ACTIVE_USER) == |
| 719 | !port_isset(engine->execlists.port)); |
Chris Wilson | 4413c47 | 2018-05-08 22:03:17 +0100 | [diff] [blame] | 720 | } |
| 721 | |
Michał Winiarski | c41937fd | 2017-10-26 15:35:58 +0200 | [diff] [blame] | 722 | void |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 723 | execlists_cancel_port_requests(struct intel_engine_execlists * const execlists) |
Mika Kuoppala | cf4591d | 2017-09-22 15:43:05 +0300 | [diff] [blame] | 724 | { |
Chris Wilson | 3f9e6cd | 2017-09-25 13:49:27 +0100 | [diff] [blame] | 725 | struct execlist_port *port = execlists->port; |
Mika Kuoppala | dc2279e | 2017-10-10 14:48:57 +0300 | [diff] [blame] | 726 | unsigned int num_ports = execlists_num_ports(execlists); |
Mika Kuoppala | cf4591d | 2017-09-22 15:43:05 +0300 | [diff] [blame] | 727 | |
Chris Wilson | 3f9e6cd | 2017-09-25 13:49:27 +0100 | [diff] [blame] | 728 | while (num_ports-- && port_isset(port)) { |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 729 | struct i915_request *rq = port_request(port); |
Chris Wilson | 7e44fc2 | 2017-09-26 11:17:19 +0100 | [diff] [blame] | 730 | |
Tvrtko Ursulin | 0c5c7df | 2018-04-06 13:35:14 +0100 | [diff] [blame] | 731 | GEM_TRACE("%s:port%u global=%d (fence %llx:%d), (current %d)\n", |
| 732 | rq->engine->name, |
| 733 | (unsigned int)(port - execlists->port), |
| 734 | rq->global_seqno, |
| 735 | rq->fence.context, rq->fence.seqno, |
| 736 | intel_engine_get_seqno(rq->engine)); |
| 737 | |
Chris Wilson | 4a118ec | 2017-10-23 22:32:36 +0100 | [diff] [blame] | 738 | GEM_BUG_ON(!execlists->active); |
Chris Wilson | b9b7742 | 2018-05-03 00:02:02 +0100 | [diff] [blame] | 739 | execlists_context_schedule_out(rq, |
| 740 | i915_request_completed(rq) ? |
| 741 | INTEL_CONTEXT_SCHEDULE_OUT : |
| 742 | INTEL_CONTEXT_SCHEDULE_PREEMPTED); |
Weinan Li | 702791f | 2018-03-06 10:15:57 +0800 | [diff] [blame] | 743 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 744 | i915_request_put(rq); |
Chris Wilson | 7e44fc2 | 2017-09-26 11:17:19 +0100 | [diff] [blame] | 745 | |
Chris Wilson | 3f9e6cd | 2017-09-25 13:49:27 +0100 | [diff] [blame] | 746 | memset(port, 0, sizeof(*port)); |
| 747 | port++; |
| 748 | } |
Chris Wilson | eed7ec5 | 2018-03-24 12:58:29 +0000 | [diff] [blame] | 749 | |
Chris Wilson | 0051163 | 2018-07-16 13:54:24 +0100 | [diff] [blame] | 750 | execlists_clear_all_active(execlists); |
Mika Kuoppala | cf4591d | 2017-09-22 15:43:05 +0300 | [diff] [blame] | 751 | } |
| 752 | |
Mika Kuoppala | d8f50531 | 2018-12-05 15:46:12 +0200 | [diff] [blame] | 753 | static inline void |
| 754 | invalidate_csb_entries(const u32 *first, const u32 *last) |
| 755 | { |
| 756 | clflush((void *)first); |
| 757 | clflush((void *)last); |
| 758 | } |
| 759 | |
Chris Wilson | f4b58f0 | 2018-06-28 21:12:08 +0100 | [diff] [blame] | 760 | static void reset_csb_pointers(struct intel_engine_execlists *execlists) |
| 761 | { |
Chris Wilson | 4659289 | 2018-11-30 12:59:54 +0000 | [diff] [blame] | 762 | const unsigned int reset_value = GEN8_CSB_ENTRIES - 1; |
| 763 | |
Chris Wilson | f4b58f0 | 2018-06-28 21:12:08 +0100 | [diff] [blame] | 764 | /* |
| 765 | * After a reset, the HW starts writing into CSB entry [0]. We |
| 766 | * therefore have to set our HEAD pointer back one entry so that |
| 767 | * the *first* entry we check is entry 0. To complicate this further, |
| 768 | * as we don't wait for the first interrupt after reset, we have to |
| 769 | * fake the HW write to point back to the last entry so that our |
| 770 | * inline comparison of our cached head position against the last HW |
| 771 | * write works even before the first interrupt. |
| 772 | */ |
Chris Wilson | 4659289 | 2018-11-30 12:59:54 +0000 | [diff] [blame] | 773 | execlists->csb_head = reset_value; |
| 774 | WRITE_ONCE(*execlists->csb_write, reset_value); |
Mika Kuoppala | d8f50531 | 2018-12-05 15:46:12 +0200 | [diff] [blame] | 775 | |
| 776 | invalidate_csb_entries(&execlists->csb_status[0], |
| 777 | &execlists->csb_status[GEN8_CSB_ENTRIES - 1]); |
Chris Wilson | f4b58f0 | 2018-06-28 21:12:08 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Chris Wilson | f1a498f | 2018-07-16 09:03:30 +0100 | [diff] [blame] | 780 | static void nop_submission_tasklet(unsigned long data) |
| 781 | { |
| 782 | /* The driver is wedged; don't process any more events. */ |
| 783 | } |
| 784 | |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 785 | static void execlists_cancel_requests(struct intel_engine_cs *engine) |
| 786 | { |
Mika Kuoppala | b620e87 | 2017-09-22 15:43:03 +0300 | [diff] [blame] | 787 | struct intel_engine_execlists * const execlists = &engine->execlists; |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 788 | struct i915_request *rq, *rn; |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 789 | struct rb_node *rb; |
| 790 | unsigned long flags; |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 791 | |
Tvrtko Ursulin | 0c5c7df | 2018-04-06 13:35:14 +0100 | [diff] [blame] | 792 | GEM_TRACE("%s current %d\n", |
| 793 | engine->name, intel_engine_get_seqno(engine)); |
Chris Wilson | 963ddd6 | 2018-03-02 11:33:24 +0000 | [diff] [blame] | 794 | |
Chris Wilson | a3e3883 | 2018-03-02 14:32:45 +0000 | [diff] [blame] | 795 | /* |
| 796 | * Before we call engine->cancel_requests(), we should have exclusive |
| 797 | * access to the submission state. This is arranged for us by the |
| 798 | * caller disabling the interrupt generation, the tasklet and other |
| 799 | * threads that may then access the same state, giving us a free hand |
| 800 | * to reset state. However, we still need to let lockdep be aware that |
| 801 | * we know this state may be accessed in hardirq context, so we |
| 802 | * disable the irq around this manipulation and we want to keep |
| 803 | * the spinlock focused on its duties and not accidentally conflate |
| 804 | * coverage to the submission's irq state. (Similarly, although we |
| 805 | * shouldn't need to disable irq around the manipulation of the |
| 806 | * submission's irq state, we also wish to remind ourselves that |
| 807 | * it is irq state.) |
| 808 | */ |
Chris Wilson | d8857d5 | 2018-06-28 21:12:05 +0100 | [diff] [blame] | 809 | spin_lock_irqsave(&engine->timeline.lock, flags); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 810 | |
| 811 | /* Cancel the requests on the HW and clear the ELSP tracker. */ |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 812 | execlists_cancel_port_requests(execlists); |
Chris Wilson | 0051163 | 2018-07-16 13:54:24 +0100 | [diff] [blame] | 813 | execlists_user_end(execlists); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 814 | |
| 815 | /* Mark all executing requests as skipped. */ |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 816 | list_for_each_entry(rq, &engine->timeline.requests, link) { |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 817 | GEM_BUG_ON(!rq->global_seqno); |
Chris Wilson | 3800960 | 2018-12-03 11:36:55 +0000 | [diff] [blame] | 818 | |
| 819 | if (test_bit(DMA_FENCE_FLAG_SIGNALED_BIT, &rq->fence.flags)) |
| 820 | continue; |
| 821 | |
| 822 | dma_fence_set_error(&rq->fence, -EIO); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | /* Flush the queued requests to the timeline list (for retiring). */ |
Chris Wilson | 655250a | 2018-06-29 08:53:20 +0100 | [diff] [blame] | 826 | while ((rb = rb_first_cached(&execlists->queue))) { |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 827 | struct i915_priolist *p = to_priolist(rb); |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 828 | int i; |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 829 | |
Chris Wilson | 85f5e1f | 2018-10-01 13:32:04 +0100 | [diff] [blame] | 830 | priolist_for_each_request_consume(rq, rn, p, i) { |
| 831 | list_del_init(&rq->sched.link); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 832 | |
| 833 | dma_fence_set_error(&rq->fence, -EIO); |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 834 | __i915_request_submit(rq); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 835 | } |
| 836 | |
Chris Wilson | 655250a | 2018-06-29 08:53:20 +0100 | [diff] [blame] | 837 | rb_erase_cached(&p->node, &execlists->queue); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 838 | if (p->priority != I915_PRIORITY_NORMAL) |
| 839 | kmem_cache_free(engine->i915->priorities, p); |
| 840 | } |
| 841 | |
Chris Wilson | 3800960 | 2018-12-03 11:36:55 +0000 | [diff] [blame] | 842 | intel_write_status_page(engine, |
| 843 | I915_GEM_HWS_INDEX, |
| 844 | intel_engine_last_submit(engine)); |
| 845 | |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 846 | /* Remaining _unready_ requests will be nop'ed when submitted */ |
| 847 | |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 848 | execlists->queue_priority = INT_MIN; |
Chris Wilson | 655250a | 2018-06-29 08:53:20 +0100 | [diff] [blame] | 849 | execlists->queue = RB_ROOT_CACHED; |
Chris Wilson | 3f9e6cd | 2017-09-25 13:49:27 +0100 | [diff] [blame] | 850 | GEM_BUG_ON(port_isset(execlists->port)); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 851 | |
Chris Wilson | f1a498f | 2018-07-16 09:03:30 +0100 | [diff] [blame] | 852 | GEM_BUG_ON(__tasklet_is_enabled(&execlists->tasklet)); |
| 853 | execlists->tasklet.func = nop_submission_tasklet; |
| 854 | |
Chris Wilson | d8857d5 | 2018-06-28 21:12:05 +0100 | [diff] [blame] | 855 | spin_unlock_irqrestore(&engine->timeline.lock, flags); |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 856 | } |
| 857 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 858 | static inline bool |
| 859 | reset_in_progress(const struct intel_engine_execlists *execlists) |
| 860 | { |
| 861 | return unlikely(!__tasklet_is_enabled(&execlists->tasklet)); |
| 862 | } |
| 863 | |
Chris Wilson | 73377db | 2018-05-16 19:33:53 +0100 | [diff] [blame] | 864 | static void process_csb(struct intel_engine_cs *engine) |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 865 | { |
Mika Kuoppala | b620e87 | 2017-09-22 15:43:03 +0300 | [diff] [blame] | 866 | struct intel_engine_execlists * const execlists = &engine->execlists; |
Chris Wilson | f260520 | 2018-03-31 14:06:26 +0100 | [diff] [blame] | 867 | struct execlist_port *port = execlists->port; |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 868 | const u32 * const buf = execlists->csb_status; |
| 869 | u8 head, tail; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 870 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 871 | /* |
| 872 | * Note that csb_write, csb_status may be either in HWSP or mmio. |
| 873 | * When reading from the csb_write mmio register, we have to be |
| 874 | * careful to only use the GEN8_CSB_WRITE_PTR portion, which is |
| 875 | * the low 4bits. As it happens we know the next 4bits are always |
| 876 | * zero and so we can simply masked off the low u8 of the register |
| 877 | * and treat it identically to reading from the HWSP (without having |
| 878 | * to use explicit shifting and masking, and probably bifurcating |
| 879 | * the code to handle the legacy mmio read). |
| 880 | */ |
| 881 | head = execlists->csb_head; |
| 882 | tail = READ_ONCE(*execlists->csb_write); |
| 883 | GEM_TRACE("%s cs-irq head=%d, tail=%d\n", engine->name, head, tail); |
| 884 | if (unlikely(head == tail)) |
| 885 | return; |
Chris Wilson | 9153e6b | 2018-03-21 09:10:27 +0000 | [diff] [blame] | 886 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 887 | /* |
| 888 | * Hopefully paired with a wmb() in HW! |
| 889 | * |
| 890 | * We must complete the read of the write pointer before any reads |
| 891 | * from the CSB, so that we do not see stale values. Without an rmb |
| 892 | * (lfence) the HW may speculatively perform the CSB[] reads *before* |
| 893 | * we perform the READ_ONCE(*csb_write). |
| 894 | */ |
| 895 | rmb(); |
Chris Wilson | bb5db7e | 2018-01-22 10:07:14 +0000 | [diff] [blame] | 896 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 897 | do { |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 898 | struct i915_request *rq; |
| 899 | unsigned int status; |
| 900 | unsigned int count; |
| 901 | |
| 902 | if (++head == GEN8_CSB_ENTRIES) |
| 903 | head = 0; |
| 904 | |
| 905 | /* |
| 906 | * We are flying near dragons again. |
| 907 | * |
| 908 | * We hold a reference to the request in execlist_port[] |
| 909 | * but no more than that. We are operating in softirq |
| 910 | * context and so cannot hold any mutex or sleep. That |
| 911 | * prevents us stopping the requests we are processing |
| 912 | * in port[] from being retired simultaneously (the |
| 913 | * breadcrumb will be complete before we see the |
| 914 | * context-switch). As we only hold the reference to the |
| 915 | * request, any pointer chasing underneath the request |
| 916 | * is subject to a potential use-after-free. Thus we |
| 917 | * store all of the bookkeeping within port[] as |
| 918 | * required, and avoid using unguarded pointers beneath |
| 919 | * request itself. The same applies to the atomic |
| 920 | * status notifier. |
| 921 | */ |
| 922 | |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 923 | GEM_TRACE("%s csb[%d]: status=0x%08x:0x%08x, active=0x%x\n", |
| 924 | engine->name, head, |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 925 | buf[2 * head + 0], buf[2 * head + 1], |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 926 | execlists->active); |
| 927 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 928 | status = buf[2 * head]; |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 929 | if (status & (GEN8_CTX_STATUS_IDLE_ACTIVE | |
| 930 | GEN8_CTX_STATUS_PREEMPTED)) |
| 931 | execlists_set_active(execlists, |
| 932 | EXECLISTS_ACTIVE_HWACK); |
| 933 | if (status & GEN8_CTX_STATUS_ACTIVE_IDLE) |
| 934 | execlists_clear_active(execlists, |
| 935 | EXECLISTS_ACTIVE_HWACK); |
| 936 | |
| 937 | if (!(status & GEN8_CTX_STATUS_COMPLETED_MASK)) |
| 938 | continue; |
| 939 | |
| 940 | /* We should never get a COMPLETED | IDLE_ACTIVE! */ |
| 941 | GEM_BUG_ON(status & GEN8_CTX_STATUS_IDLE_ACTIVE); |
| 942 | |
| 943 | if (status & GEN8_CTX_STATUS_COMPLETE && |
| 944 | buf[2*head + 1] == execlists->preempt_complete_status) { |
| 945 | GEM_TRACE("%s preempt-idle\n", engine->name); |
| 946 | complete_preempt_context(execlists); |
| 947 | continue; |
Chris Wilson | 767a983 | 2017-09-13 09:56:05 +0100 | [diff] [blame] | 948 | } |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 949 | |
| 950 | if (status & GEN8_CTX_STATUS_PREEMPTED && |
| 951 | execlists_is_active(execlists, |
| 952 | EXECLISTS_ACTIVE_PREEMPT)) |
| 953 | continue; |
| 954 | |
| 955 | GEM_BUG_ON(!execlists_is_active(execlists, |
| 956 | EXECLISTS_ACTIVE_USER)); |
| 957 | |
| 958 | rq = port_unpack(port, &count); |
| 959 | GEM_TRACE("%s out[0]: ctx=%d.%d, global=%d (fence %llx:%d) (current %d), prio=%d\n", |
Chris Wilson | bccd3b8 | 2017-11-09 14:30:19 +0000 | [diff] [blame] | 960 | engine->name, |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 961 | port->context_id, count, |
| 962 | rq ? rq->global_seqno : 0, |
| 963 | rq ? rq->fence.context : 0, |
| 964 | rq ? rq->fence.seqno : 0, |
| 965 | intel_engine_get_seqno(engine), |
| 966 | rq ? rq_prio(rq) : 0); |
Mika Kuoppala | b620e87 | 2017-09-22 15:43:03 +0300 | [diff] [blame] | 967 | |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 968 | /* Check the context/desc id for this event matches */ |
| 969 | GEM_DEBUG_BUG_ON(buf[2 * head + 1] != port->context_id); |
Chris Wilson | a37951a | 2017-01-24 11:00:06 +0000 | [diff] [blame] | 970 | |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 971 | GEM_BUG_ON(count == 0); |
| 972 | if (--count == 0) { |
| 973 | /* |
| 974 | * On the final event corresponding to the |
| 975 | * submission of this context, we expect either |
| 976 | * an element-switch event or a completion |
| 977 | * event (and on completion, the active-idle |
| 978 | * marker). No more preemptions, lite-restore |
| 979 | * or otherwise. |
| 980 | */ |
| 981 | GEM_BUG_ON(status & GEN8_CTX_STATUS_PREEMPTED); |
| 982 | GEM_BUG_ON(port_isset(&port[1]) && |
| 983 | !(status & GEN8_CTX_STATUS_ELEMENT_SWITCH)); |
| 984 | GEM_BUG_ON(!port_isset(&port[1]) && |
| 985 | !(status & GEN8_CTX_STATUS_ACTIVE_IDLE)); |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 986 | |
Chris Wilson | 73377db | 2018-05-16 19:33:53 +0100 | [diff] [blame] | 987 | /* |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 988 | * We rely on the hardware being strongly |
| 989 | * ordered, that the breadcrumb write is |
| 990 | * coherent (visible from the CPU) before the |
| 991 | * user interrupt and CSB is processed. |
Chris Wilson | 2ffe80a | 2017-02-06 17:05:02 +0000 | [diff] [blame] | 992 | */ |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 993 | GEM_BUG_ON(!i915_request_completed(rq)); |
Chris Wilson | 2ffe80a | 2017-02-06 17:05:02 +0000 | [diff] [blame] | 994 | |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 995 | execlists_context_schedule_out(rq, |
| 996 | INTEL_CONTEXT_SCHEDULE_OUT); |
| 997 | i915_request_put(rq); |
Michel Thierry | ba74cb1 | 2017-11-20 12:34:58 +0000 | [diff] [blame] | 998 | |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 999 | GEM_TRACE("%s completed ctx=%d\n", |
| 1000 | engine->name, port->context_id); |
Michel Thierry | ba74cb1 | 2017-11-20 12:34:58 +0000 | [diff] [blame] | 1001 | |
Chris Wilson | 8ea397f | 2018-06-28 21:12:06 +0100 | [diff] [blame] | 1002 | port = execlists_port_complete(execlists, port); |
| 1003 | if (port_isset(port)) |
| 1004 | execlists_user_begin(execlists, port); |
| 1005 | else |
| 1006 | execlists_user_end(execlists); |
| 1007 | } else { |
| 1008 | port_set(port, port_pack(rq, count)); |
Chris Wilson | 4af0d72 | 2017-03-25 20:10:53 +0000 | [diff] [blame] | 1009 | } |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 1010 | } while (head != tail); |
Tvrtko Ursulin | 26720ab | 2016-03-17 12:59:46 +0000 | [diff] [blame] | 1011 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 1012 | execlists->csb_head = head; |
Mika Kuoppala | d8f50531 | 2018-12-05 15:46:12 +0200 | [diff] [blame] | 1013 | |
| 1014 | /* |
| 1015 | * Gen11 has proven to fail wrt global observation point between |
| 1016 | * entry and tail update, failing on the ordering and thus |
| 1017 | * we see an old entry in the context status buffer. |
| 1018 | * |
| 1019 | * Forcibly evict out entries for the next gpu csb update, |
| 1020 | * to increase the odds that we get a fresh entries with non |
| 1021 | * working hardware. The cost for doing so comes out mostly with |
| 1022 | * the wash as hardware, working or not, will need to do the |
| 1023 | * invalidation before. |
| 1024 | */ |
| 1025 | invalidate_csb_entries(&buf[0], &buf[GEN8_CSB_ENTRIES - 1]); |
Chris Wilson | 73377db | 2018-05-16 19:33:53 +0100 | [diff] [blame] | 1026 | } |
| 1027 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1028 | static void __execlists_submission_tasklet(struct intel_engine_cs *const engine) |
Chris Wilson | 73377db | 2018-05-16 19:33:53 +0100 | [diff] [blame] | 1029 | { |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1030 | lockdep_assert_held(&engine->timeline.lock); |
Chris Wilson | 73377db | 2018-05-16 19:33:53 +0100 | [diff] [blame] | 1031 | |
Chris Wilson | fd8526e | 2018-06-28 21:12:10 +0100 | [diff] [blame] | 1032 | process_csb(engine); |
Chris Wilson | 73377db | 2018-05-16 19:33:53 +0100 | [diff] [blame] | 1033 | if (!execlists_is_active(&engine->execlists, EXECLISTS_ACTIVE_PREEMPT)) |
Chris Wilson | 70c2a24 | 2016-09-09 14:11:46 +0100 | [diff] [blame] | 1034 | execlists_dequeue(engine); |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 1035 | } |
| 1036 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1037 | /* |
| 1038 | * Check the unread Context Status Buffers and manage the submission of new |
| 1039 | * contexts to the ELSP accordingly. |
| 1040 | */ |
| 1041 | static void execlists_submission_tasklet(unsigned long data) |
| 1042 | { |
| 1043 | struct intel_engine_cs * const engine = (struct intel_engine_cs *)data; |
| 1044 | unsigned long flags; |
| 1045 | |
| 1046 | GEM_TRACE("%s awake?=%d, active=%x\n", |
| 1047 | engine->name, |
Chris Wilson | 8d761e7 | 2019-01-14 14:21:28 +0000 | [diff] [blame] | 1048 | !!engine->i915->gt.awake, |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1049 | engine->execlists.active); |
| 1050 | |
| 1051 | spin_lock_irqsave(&engine->timeline.lock, flags); |
Chris Wilson | d78d334 | 2018-07-19 08:50:29 +0100 | [diff] [blame] | 1052 | __execlists_submission_tasklet(engine); |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1053 | spin_unlock_irqrestore(&engine->timeline.lock, flags); |
| 1054 | } |
| 1055 | |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 1056 | static void queue_request(struct intel_engine_cs *engine, |
Chris Wilson | 0c7112a | 2018-04-18 19:40:51 +0100 | [diff] [blame] | 1057 | struct i915_sched_node *node, |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 1058 | int prio) |
Chris Wilson | 27606fd | 2017-09-16 21:44:13 +0100 | [diff] [blame] | 1059 | { |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 1060 | list_add_tail(&node->link, i915_sched_lookup_priolist(engine, prio)); |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | static void __submit_queue_imm(struct intel_engine_cs *engine) |
| 1064 | { |
| 1065 | struct intel_engine_execlists * const execlists = &engine->execlists; |
| 1066 | |
| 1067 | if (reset_in_progress(execlists)) |
| 1068 | return; /* defer until we restart the engine following reset */ |
| 1069 | |
| 1070 | if (execlists->tasklet.func == execlists_submission_tasklet) |
| 1071 | __execlists_submission_tasklet(engine); |
| 1072 | else |
| 1073 | tasklet_hi_schedule(&execlists->tasklet); |
Chris Wilson | ae2f5c0 | 2018-03-26 12:50:34 +0100 | [diff] [blame] | 1074 | } |
| 1075 | |
Chris Wilson | f6322ed | 2018-02-22 14:22:29 +0000 | [diff] [blame] | 1076 | static void submit_queue(struct intel_engine_cs *engine, int prio) |
| 1077 | { |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1078 | if (prio > engine->execlists.queue_priority) { |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 1079 | engine->execlists.queue_priority = prio; |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1080 | __submit_queue_imm(engine); |
| 1081 | } |
Chris Wilson | 27606fd | 2017-09-16 21:44:13 +0100 | [diff] [blame] | 1082 | } |
| 1083 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 1084 | static void execlists_submit_request(struct i915_request *request) |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 1085 | { |
Tvrtko Ursulin | 4a570db | 2016-03-16 11:00:38 +0000 | [diff] [blame] | 1086 | struct intel_engine_cs *engine = request->engine; |
Chris Wilson | 5590af3 | 2016-09-09 14:11:54 +0100 | [diff] [blame] | 1087 | unsigned long flags; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 1088 | |
Chris Wilson | 663f71e | 2016-11-14 20:41:00 +0000 | [diff] [blame] | 1089 | /* Will be called from irq-context when using foreign fences. */ |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 1090 | spin_lock_irqsave(&engine->timeline.lock, flags); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 1091 | |
Chris Wilson | 0c7112a | 2018-04-18 19:40:51 +0100 | [diff] [blame] | 1092 | queue_request(engine, &request->sched, rq_prio(request)); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 1093 | |
Chris Wilson | 655250a | 2018-06-29 08:53:20 +0100 | [diff] [blame] | 1094 | GEM_BUG_ON(RB_EMPTY_ROOT(&engine->execlists.queue.rb_root)); |
Chris Wilson | 0c7112a | 2018-04-18 19:40:51 +0100 | [diff] [blame] | 1095 | GEM_BUG_ON(list_empty(&request->sched.link)); |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 1096 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1097 | submit_queue(engine, rq_prio(request)); |
| 1098 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 1099 | spin_unlock_irqrestore(&engine->timeline.lock, flags); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 1100 | } |
| 1101 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1102 | static void execlists_context_destroy(struct intel_context *ce) |
| 1103 | { |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1104 | GEM_BUG_ON(ce->pin_count); |
| 1105 | |
Chris Wilson | dd12c6c | 2018-06-25 11:06:03 +0100 | [diff] [blame] | 1106 | if (!ce->state) |
| 1107 | return; |
| 1108 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1109 | intel_ring_free(ce->ring); |
Chris Wilson | efe79d4 | 2018-06-25 11:06:04 +0100 | [diff] [blame] | 1110 | |
| 1111 | GEM_BUG_ON(i915_gem_object_is_active(ce->state->obj)); |
| 1112 | i915_gem_object_put(ce->state->obj); |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
Chris Wilson | 867985d | 2018-05-17 22:26:33 +0100 | [diff] [blame] | 1115 | static void execlists_context_unpin(struct intel_context *ce) |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1116 | { |
Chris Wilson | bc2477f | 2018-10-03 12:09:41 +0100 | [diff] [blame] | 1117 | struct intel_engine_cs *engine; |
| 1118 | |
| 1119 | /* |
| 1120 | * The tasklet may still be using a pointer to our state, via an |
| 1121 | * old request. However, since we know we only unpin the context |
| 1122 | * on retirement of the following request, we know that the last |
| 1123 | * request referencing us will have had a completion CS interrupt. |
| 1124 | * If we see that it is still active, it means that the tasklet hasn't |
| 1125 | * had the chance to run yet; let it run before we teardown the |
| 1126 | * reference it may use. |
| 1127 | */ |
| 1128 | engine = READ_ONCE(ce->active); |
| 1129 | if (unlikely(engine)) { |
| 1130 | unsigned long flags; |
| 1131 | |
| 1132 | spin_lock_irqsave(&engine->timeline.lock, flags); |
| 1133 | process_csb(engine); |
| 1134 | spin_unlock_irqrestore(&engine->timeline.lock, flags); |
| 1135 | |
| 1136 | GEM_BUG_ON(READ_ONCE(ce->active)); |
| 1137 | } |
| 1138 | |
Chris Wilson | 288f1ce | 2018-09-04 16:31:17 +0100 | [diff] [blame] | 1139 | i915_gem_context_unpin_hw_id(ce->gem_context); |
| 1140 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1141 | intel_ring_unpin(ce->ring); |
| 1142 | |
| 1143 | ce->state->obj->pin_global--; |
| 1144 | i915_gem_object_unpin_map(ce->state->obj); |
| 1145 | i915_vma_unpin(ce->state); |
| 1146 | |
| 1147 | i915_gem_context_put(ce->gem_context); |
| 1148 | } |
| 1149 | |
Chris Wilson | f4e15af | 2017-11-10 14:26:32 +0000 | [diff] [blame] | 1150 | static int __context_pin(struct i915_gem_context *ctx, struct i915_vma *vma) |
| 1151 | { |
| 1152 | unsigned int flags; |
| 1153 | int err; |
| 1154 | |
| 1155 | /* |
| 1156 | * Clear this page out of any CPU caches for coherent swap-in/out. |
| 1157 | * We only want to do this on the first bind so that we do not stall |
| 1158 | * on an active context (which by nature is already on the GPU). |
| 1159 | */ |
| 1160 | if (!(vma->flags & I915_VMA_GLOBAL_BIND)) { |
Chris Wilson | 666424a | 2018-09-14 13:35:04 +0100 | [diff] [blame] | 1161 | err = i915_gem_object_set_to_wc_domain(vma->obj, true); |
Chris Wilson | f4e15af | 2017-11-10 14:26:32 +0000 | [diff] [blame] | 1162 | if (err) |
| 1163 | return err; |
| 1164 | } |
| 1165 | |
| 1166 | flags = PIN_GLOBAL | PIN_HIGH; |
Jakub Bartmiński | 496bcce | 2018-07-27 16:11:46 +0200 | [diff] [blame] | 1167 | flags |= PIN_OFFSET_BIAS | i915_ggtt_pin_bias(vma); |
Chris Wilson | f4e15af | 2017-11-10 14:26:32 +0000 | [diff] [blame] | 1168 | |
Chris Wilson | c00db49 | 2018-07-27 10:29:47 +0100 | [diff] [blame] | 1169 | return i915_vma_pin(vma, 0, 0, flags); |
Chris Wilson | f4e15af | 2017-11-10 14:26:32 +0000 | [diff] [blame] | 1170 | } |
| 1171 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1172 | static struct intel_context * |
| 1173 | __execlists_context_pin(struct intel_engine_cs *engine, |
| 1174 | struct i915_gem_context *ctx, |
| 1175 | struct intel_context *ce) |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1176 | { |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 1177 | void *vaddr; |
Tvrtko Ursulin | ca82580 | 2016-01-15 15:10:27 +0000 | [diff] [blame] | 1178 | int ret; |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1179 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1180 | ret = execlists_context_deferred_alloc(ctx, engine, ce); |
Chris Wilson | 1d2a19c | 2018-01-26 12:18:46 +0000 | [diff] [blame] | 1181 | if (ret) |
| 1182 | goto err; |
Chris Wilson | 56f6e0a | 2017-01-05 15:30:20 +0000 | [diff] [blame] | 1183 | GEM_BUG_ON(!ce->state); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1184 | |
Chris Wilson | f4e15af | 2017-11-10 14:26:32 +0000 | [diff] [blame] | 1185 | ret = __context_pin(ctx, ce->state); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 1186 | if (ret) |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 1187 | goto err; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1188 | |
Chris Wilson | 666424a | 2018-09-14 13:35:04 +0100 | [diff] [blame] | 1189 | vaddr = i915_gem_object_pin_map(ce->state->obj, |
| 1190 | i915_coherent_map_type(ctx->i915) | |
| 1191 | I915_MAP_OVERRIDE); |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 1192 | if (IS_ERR(vaddr)) { |
| 1193 | ret = PTR_ERR(vaddr); |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 1194 | goto unpin_vma; |
Tvrtko Ursulin | 82352e9 | 2016-01-15 17:12:45 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
Chris Wilson | 5503cb0 | 2018-07-27 16:55:01 +0100 | [diff] [blame] | 1197 | ret = intel_ring_pin(ce->ring); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 1198 | if (ret) |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 1199 | goto unpin_map; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 1200 | |
Chris Wilson | 288f1ce | 2018-09-04 16:31:17 +0100 | [diff] [blame] | 1201 | ret = i915_gem_context_pin_hw_id(ctx); |
| 1202 | if (ret) |
| 1203 | goto unpin_ring; |
| 1204 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1205 | intel_lr_context_descriptor_update(ctx, engine, ce); |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 1206 | |
Chris Wilson | dee60ca | 2018-09-14 13:35:02 +0100 | [diff] [blame] | 1207 | GEM_BUG_ON(!intel_ring_offset_valid(ce->ring, ce->ring->head)); |
| 1208 | |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1209 | ce->lrc_reg_state = vaddr + LRC_STATE_PN * PAGE_SIZE; |
| 1210 | ce->lrc_reg_state[CTX_RING_BUFFER_START+1] = |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1211 | i915_ggtt_offset(ce->ring->vma); |
Chris Wilson | dee60ca | 2018-09-14 13:35:02 +0100 | [diff] [blame] | 1212 | ce->lrc_reg_state[CTX_RING_HEAD + 1] = ce->ring->head; |
| 1213 | ce->lrc_reg_state[CTX_RING_TAIL + 1] = ce->ring->tail; |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1214 | |
Chris Wilson | 3d574a6 | 2017-10-13 21:26:16 +0100 | [diff] [blame] | 1215 | ce->state->obj->pin_global++; |
Chris Wilson | 9a6feaf | 2016-07-20 13:31:50 +0100 | [diff] [blame] | 1216 | i915_gem_context_get(ctx); |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1217 | return ce; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1218 | |
Chris Wilson | 288f1ce | 2018-09-04 16:31:17 +0100 | [diff] [blame] | 1219 | unpin_ring: |
| 1220 | intel_ring_unpin(ce->ring); |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 1221 | unpin_map: |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 1222 | i915_gem_object_unpin_map(ce->state->obj); |
| 1223 | unpin_vma: |
| 1224 | __i915_vma_unpin(ce->state); |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 1225 | err: |
Chris Wilson | 9021ad0 | 2016-05-24 14:53:37 +0100 | [diff] [blame] | 1226 | ce->pin_count = 0; |
Chris Wilson | 266a240 | 2017-05-04 10:33:08 +0100 | [diff] [blame] | 1227 | return ERR_PTR(ret); |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1230 | static const struct intel_context_ops execlists_context_ops = { |
| 1231 | .unpin = execlists_context_unpin, |
| 1232 | .destroy = execlists_context_destroy, |
| 1233 | }; |
| 1234 | |
| 1235 | static struct intel_context * |
| 1236 | execlists_context_pin(struct intel_engine_cs *engine, |
| 1237 | struct i915_gem_context *ctx) |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1238 | { |
Chris Wilson | ab82a06 | 2018-04-30 14:15:01 +0100 | [diff] [blame] | 1239 | struct intel_context *ce = to_intel_context(ctx, engine); |
Daniel Vetter | af3302b | 2015-12-04 17:27:15 +0100 | [diff] [blame] | 1240 | |
Chris Wilson | 91c8a32 | 2016-07-05 10:40:23 +0100 | [diff] [blame] | 1241 | lockdep_assert_held(&ctx->i915->drm.struct_mutex); |
Chris Wilson | 4bdafb9 | 2018-09-26 21:12:22 +0100 | [diff] [blame] | 1242 | GEM_BUG_ON(!ctx->ppgtt); |
Tvrtko Ursulin | 321fe30 | 2016-01-28 10:29:55 +0000 | [diff] [blame] | 1243 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1244 | if (likely(ce->pin_count++)) |
| 1245 | return ce; |
| 1246 | GEM_BUG_ON(!ce->pin_count); /* no overflow please! */ |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 1247 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1248 | ce->ops = &execlists_context_ops; |
Chris Wilson | 24f1d3c | 2016-04-28 09:56:53 +0100 | [diff] [blame] | 1249 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1250 | return __execlists_context_pin(engine, ctx, ce); |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Chris Wilson | e889426 | 2018-12-07 09:02:13 +0000 | [diff] [blame] | 1253 | static int emit_pdps(struct i915_request *rq) |
| 1254 | { |
| 1255 | const struct intel_engine_cs * const engine = rq->engine; |
| 1256 | struct i915_hw_ppgtt * const ppgtt = rq->gem_context->ppgtt; |
| 1257 | int err, i; |
| 1258 | u32 *cs; |
| 1259 | |
| 1260 | GEM_BUG_ON(intel_vgpu_active(rq->i915)); |
| 1261 | |
| 1262 | /* |
| 1263 | * Beware ye of the dragons, this sequence is magic! |
| 1264 | * |
| 1265 | * Small changes to this sequence can cause anything from |
| 1266 | * GPU hangs to forcewake errors and machine lockups! |
| 1267 | */ |
| 1268 | |
| 1269 | /* Flush any residual operations from the context load */ |
| 1270 | err = engine->emit_flush(rq, EMIT_FLUSH); |
| 1271 | if (err) |
| 1272 | return err; |
| 1273 | |
| 1274 | /* Magic required to prevent forcewake errors! */ |
| 1275 | err = engine->emit_flush(rq, EMIT_INVALIDATE); |
| 1276 | if (err) |
| 1277 | return err; |
| 1278 | |
| 1279 | cs = intel_ring_begin(rq, 4 * GEN8_3LVL_PDPES + 2); |
| 1280 | if (IS_ERR(cs)) |
| 1281 | return PTR_ERR(cs); |
| 1282 | |
| 1283 | /* Ensure the LRI have landed before we invalidate & continue */ |
| 1284 | *cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) | MI_LRI_FORCE_POSTED; |
| 1285 | for (i = GEN8_3LVL_PDPES; i--; ) { |
| 1286 | const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i); |
| 1287 | |
| 1288 | *cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_UDW(engine, i)); |
| 1289 | *cs++ = upper_32_bits(pd_daddr); |
| 1290 | *cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_LDW(engine, i)); |
| 1291 | *cs++ = lower_32_bits(pd_daddr); |
| 1292 | } |
| 1293 | *cs++ = MI_NOOP; |
| 1294 | |
| 1295 | intel_ring_advance(rq, cs); |
| 1296 | |
| 1297 | /* Be doubly sure the LRI have landed before proceeding */ |
| 1298 | err = engine->emit_flush(rq, EMIT_FLUSH); |
| 1299 | if (err) |
| 1300 | return err; |
| 1301 | |
| 1302 | /* Re-invalidate the TLB for luck */ |
| 1303 | return engine->emit_flush(rq, EMIT_INVALIDATE); |
| 1304 | } |
| 1305 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 1306 | static int execlists_request_alloc(struct i915_request *request) |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 1307 | { |
Chris Wilson | fd13821 | 2017-11-15 15:12:04 +0000 | [diff] [blame] | 1308 | int ret; |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 1309 | |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1310 | GEM_BUG_ON(!request->hw_context->pin_count); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 1311 | |
Chris Wilson | 5f5800a | 2018-12-07 09:02:11 +0000 | [diff] [blame] | 1312 | /* |
| 1313 | * Flush enough space to reduce the likelihood of waiting after |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 1314 | * we start building the request - in which case we will just |
| 1315 | * have to repeat work. |
| 1316 | */ |
| 1317 | request->reserved_space += EXECLISTS_REQUEST_SIZE; |
| 1318 | |
Chris Wilson | 5f5800a | 2018-12-07 09:02:11 +0000 | [diff] [blame] | 1319 | /* |
| 1320 | * Note that after this point, we have committed to using |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 1321 | * this request as it is being used to both track the |
| 1322 | * state of engine initialisation and liveness of the |
| 1323 | * golden renderstate above. Think twice before you try |
| 1324 | * to cancel/unwind this request now. |
| 1325 | */ |
| 1326 | |
Chris Wilson | e889426 | 2018-12-07 09:02:13 +0000 | [diff] [blame] | 1327 | /* Unconditionally invalidate GPU caches and TLBs. */ |
| 1328 | if (i915_vm_is_48bit(&request->gem_context->ppgtt->vm)) |
| 1329 | ret = request->engine->emit_flush(request, EMIT_INVALIDATE); |
| 1330 | else |
| 1331 | ret = emit_pdps(request); |
| 1332 | if (ret) |
| 1333 | return ret; |
| 1334 | |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 1335 | request->reserved_space -= EXECLISTS_REQUEST_SIZE; |
| 1336 | return 0; |
Chris Wilson | ef11c01 | 2016-12-18 15:37:19 +0000 | [diff] [blame] | 1337 | } |
| 1338 | |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 1339 | /* |
| 1340 | * In this WA we need to set GEN8_L3SQCREG4[21:21] and reset it after |
| 1341 | * PIPE_CONTROL instruction. This is required for the flush to happen correctly |
| 1342 | * but there is a slight complication as this is applied in WA batch where the |
| 1343 | * values are only initialized once so we cannot take register value at the |
| 1344 | * beginning and reuse it further; hence we save its value to memory, upload a |
| 1345 | * constant value with bit21 set and then we restore it back with the saved value. |
| 1346 | * To simplify the WA, a constant value is formed by using the default value |
| 1347 | * of this register. This shouldn't be a problem because we are only modifying |
| 1348 | * it for a short period and this batch in non-premptible. We can ofcourse |
| 1349 | * use additional instructions that read the actual value of the register |
| 1350 | * at that time and set our bit of interest but it makes the WA complicated. |
| 1351 | * |
| 1352 | * This WA is also required for Gen9 so extracting as a function avoids |
| 1353 | * code duplication. |
| 1354 | */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1355 | static u32 * |
| 1356 | gen8_emit_flush_coherentl3_wa(struct intel_engine_cs *engine, u32 *batch) |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 1357 | { |
Chris Wilson | 5179749 | 2018-12-04 14:15:16 +0000 | [diff] [blame] | 1358 | /* NB no one else is allowed to scribble over scratch + 256! */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1359 | *batch++ = MI_STORE_REGISTER_MEM_GEN8 | MI_SRM_LRM_GLOBAL_GTT; |
| 1360 | *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4); |
Chris Wilson | 5179749 | 2018-12-04 14:15:16 +0000 | [diff] [blame] | 1361 | *batch++ = i915_scratch_offset(engine->i915) + 256; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1362 | *batch++ = 0; |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 1363 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1364 | *batch++ = MI_LOAD_REGISTER_IMM(1); |
| 1365 | *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4); |
| 1366 | *batch++ = 0x40400000 | GEN8_LQSC_FLUSH_COHERENT_LINES; |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 1367 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1368 | batch = gen8_emit_pipe_control(batch, |
| 1369 | PIPE_CONTROL_CS_STALL | |
| 1370 | PIPE_CONTROL_DC_FLUSH_ENABLE, |
| 1371 | 0); |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 1372 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1373 | *batch++ = MI_LOAD_REGISTER_MEM_GEN8 | MI_SRM_LRM_GLOBAL_GTT; |
| 1374 | *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4); |
Chris Wilson | 5179749 | 2018-12-04 14:15:16 +0000 | [diff] [blame] | 1375 | *batch++ = i915_scratch_offset(engine->i915) + 256; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1376 | *batch++ = 0; |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame] | 1377 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1378 | return batch; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 1381 | /* |
| 1382 | * Typically we only have one indirect_ctx and per_ctx batch buffer which are |
| 1383 | * initialized at the beginning and shared across all contexts but this field |
| 1384 | * helps us to have multiple batches at different offsets and select them based |
| 1385 | * on a criteria. At the moment this batch always start at the beginning of the page |
| 1386 | * 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] | 1387 | * |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 1388 | * The number of WA applied are not known at the beginning; we use this field |
| 1389 | * to return the no of DWORDS written. |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1390 | * |
Daniel Vetter | 6e5248b | 2016-07-15 21:48:06 +0200 | [diff] [blame] | 1391 | * It is to be noted that this batch does not contain MI_BATCH_BUFFER_END |
| 1392 | * so it adds NOOPs as padding to make it cacheline aligned. |
| 1393 | * MI_BATCH_BUFFER_END will be added to perctx batch and both of them together |
| 1394 | * makes a complete batch buffer. |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1395 | */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1396 | 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] | 1397 | { |
Arun Siluvery | 7ad00d1 | 2015-06-19 18:37:12 +0100 | [diff] [blame] | 1398 | /* WaDisableCtxRestoreArbitration:bdw,chv */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1399 | *batch++ = MI_ARB_ON_OFF | MI_ARB_DISABLE; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1400 | |
Arun Siluvery | c82435b | 2015-06-19 18:37:13 +0100 | [diff] [blame] | 1401 | /* WaFlushCoherentL3CacheLinesAtContextSwitch:bdw */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1402 | if (IS_BROADWELL(engine->i915)) |
| 1403 | batch = gen8_emit_flush_coherentl3_wa(engine, batch); |
Arun Siluvery | c82435b | 2015-06-19 18:37:13 +0100 | [diff] [blame] | 1404 | |
Arun Siluvery | 0160f05 | 2015-06-23 15:46:57 +0100 | [diff] [blame] | 1405 | /* WaClearSlmSpaceAtContextSwitch:bdw,chv */ |
| 1406 | /* Actual scratch location is at 128 bytes offset */ |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1407 | batch = gen8_emit_pipe_control(batch, |
| 1408 | PIPE_CONTROL_FLUSH_L3 | |
| 1409 | PIPE_CONTROL_GLOBAL_GTT_IVB | |
| 1410 | PIPE_CONTROL_CS_STALL | |
| 1411 | PIPE_CONTROL_QW_WRITE, |
Chris Wilson | 5179749 | 2018-12-04 14:15:16 +0000 | [diff] [blame] | 1412 | i915_scratch_offset(engine->i915) + |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 1413 | 2 * CACHELINE_BYTES); |
Arun Siluvery | 0160f05 | 2015-06-23 15:46:57 +0100 | [diff] [blame] | 1414 | |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 1415 | *batch++ = MI_ARB_ON_OFF | MI_ARB_ENABLE; |
| 1416 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1417 | /* Pad to end of cacheline */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1418 | while ((unsigned long)batch % CACHELINE_BYTES) |
| 1419 | *batch++ = MI_NOOP; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1420 | |
| 1421 | /* |
| 1422 | * MI_BATCH_BUFFER_END is not required in Indirect ctx BB because |
| 1423 | * execution depends on the length specified in terms of cache lines |
| 1424 | * in the register CTX_RCS_INDIRECT_CTX |
| 1425 | */ |
| 1426 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1427 | return batch; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1428 | } |
| 1429 | |
Chris Wilson | 5ee4a7a | 2018-06-18 10:41:50 +0100 | [diff] [blame] | 1430 | struct lri { |
| 1431 | i915_reg_t reg; |
| 1432 | u32 value; |
| 1433 | }; |
| 1434 | |
| 1435 | static u32 *emit_lri(u32 *batch, const struct lri *lri, unsigned int count) |
| 1436 | { |
| 1437 | GEM_BUG_ON(!count || count > 63); |
| 1438 | |
| 1439 | *batch++ = MI_LOAD_REGISTER_IMM(count); |
| 1440 | do { |
| 1441 | *batch++ = i915_mmio_reg_offset(lri->reg); |
| 1442 | *batch++ = lri->value; |
| 1443 | } while (lri++, --count); |
| 1444 | *batch++ = MI_NOOP; |
| 1445 | |
| 1446 | return batch; |
| 1447 | } |
| 1448 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1449 | 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] | 1450 | { |
Chris Wilson | 5ee4a7a | 2018-06-18 10:41:50 +0100 | [diff] [blame] | 1451 | static const struct lri lri[] = { |
| 1452 | /* WaDisableGatherAtSetShaderCommonSlice:skl,bxt,kbl,glk */ |
| 1453 | { |
| 1454 | COMMON_SLICE_CHICKEN2, |
| 1455 | __MASKED_FIELD(GEN9_DISABLE_GATHER_AT_SET_SHADER_COMMON_SLICE, |
| 1456 | 0), |
| 1457 | }, |
| 1458 | |
| 1459 | /* BSpec: 11391 */ |
| 1460 | { |
| 1461 | FF_SLICE_CHICKEN, |
| 1462 | __MASKED_FIELD(FF_SLICE_CHICKEN_CL_PROVOKING_VERTEX_FIX, |
| 1463 | FF_SLICE_CHICKEN_CL_PROVOKING_VERTEX_FIX), |
| 1464 | }, |
| 1465 | |
| 1466 | /* BSpec: 11299 */ |
| 1467 | { |
| 1468 | _3D_CHICKEN3, |
| 1469 | __MASKED_FIELD(_3D_CHICKEN_SF_PROVOKING_VERTEX_FIX, |
| 1470 | _3D_CHICKEN_SF_PROVOKING_VERTEX_FIX), |
| 1471 | } |
| 1472 | }; |
| 1473 | |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 1474 | *batch++ = MI_ARB_ON_OFF | MI_ARB_DISABLE; |
| 1475 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 1476 | /* WaFlushCoherentL3CacheLinesAtContextSwitch:skl,bxt,glk */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1477 | batch = gen8_emit_flush_coherentl3_wa(engine, batch); |
Arun Siluvery | a4106a7 | 2015-07-14 15:01:29 +0100 | [diff] [blame] | 1478 | |
Chris Wilson | 5ee4a7a | 2018-06-18 10:41:50 +0100 | [diff] [blame] | 1479 | batch = emit_lri(batch, lri, ARRAY_SIZE(lri)); |
Mika Kuoppala | 873e817 | 2016-07-20 14:26:13 +0300 | [diff] [blame] | 1480 | |
Ander Conselvan de Oliveira | 9fb5026 | 2017-01-26 11:16:58 +0200 | [diff] [blame] | 1481 | /* WaMediaPoolStateCmdInWABB:bxt,glk */ |
Tim Gore | 3485d99 | 2016-07-05 10:01:30 +0100 | [diff] [blame] | 1482 | if (HAS_POOLED_EU(engine->i915)) { |
| 1483 | /* |
| 1484 | * EU pool configuration is setup along with golden context |
| 1485 | * during context initialization. This value depends on |
| 1486 | * device type (2x6 or 3x6) and needs to be updated based |
| 1487 | * on which subslice is disabled especially for 2x6 |
| 1488 | * devices, however it is safe to load default |
| 1489 | * configuration of 3x6 device instead of masking off |
| 1490 | * corresponding bits because HW ignores bits of a disabled |
| 1491 | * subslice and drops down to appropriate config. Please |
| 1492 | * see render_state_setup() in i915_gem_render_state.c for |
| 1493 | * possible configurations, to avoid duplication they are |
| 1494 | * not shown here again. |
| 1495 | */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1496 | *batch++ = GEN9_MEDIA_POOL_STATE; |
| 1497 | *batch++ = GEN9_MEDIA_POOL_ENABLE; |
| 1498 | *batch++ = 0x00777000; |
| 1499 | *batch++ = 0; |
| 1500 | *batch++ = 0; |
| 1501 | *batch++ = 0; |
Tim Gore | 3485d99 | 2016-07-05 10:01:30 +0100 | [diff] [blame] | 1502 | } |
| 1503 | |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 1504 | *batch++ = MI_ARB_ON_OFF | MI_ARB_ENABLE; |
| 1505 | |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1506 | /* Pad to end of cacheline */ |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1507 | while ((unsigned long)batch % CACHELINE_BYTES) |
| 1508 | *batch++ = MI_NOOP; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1509 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1510 | return batch; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1511 | } |
| 1512 | |
Rafael Antognolli | 4b6ce68 | 2018-02-05 15:33:30 -0800 | [diff] [blame] | 1513 | static u32 * |
| 1514 | gen10_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch) |
| 1515 | { |
| 1516 | int i; |
| 1517 | |
| 1518 | /* |
| 1519 | * WaPipeControlBefore3DStateSamplePattern: cnl |
| 1520 | * |
| 1521 | * Ensure the engine is idle prior to programming a |
| 1522 | * 3DSTATE_SAMPLE_PATTERN during a context restore. |
| 1523 | */ |
| 1524 | batch = gen8_emit_pipe_control(batch, |
| 1525 | PIPE_CONTROL_CS_STALL, |
| 1526 | 0); |
| 1527 | /* |
| 1528 | * WaPipeControlBefore3DStateSamplePattern says we need 4 dwords for |
| 1529 | * the PIPE_CONTROL followed by 12 dwords of 0x0, so 16 dwords in |
| 1530 | * total. However, a PIPE_CONTROL is 6 dwords long, not 4, which is |
| 1531 | * confusing. Since gen8_emit_pipe_control() already advances the |
| 1532 | * batch by 6 dwords, we advance the other 10 here, completing a |
| 1533 | * cacheline. It's not clear if the workaround requires this padding |
| 1534 | * before other commands, or if it's just the regular padding we would |
| 1535 | * already have for the workaround bb, so leave it here for now. |
| 1536 | */ |
| 1537 | for (i = 0; i < 10; i++) |
| 1538 | *batch++ = MI_NOOP; |
| 1539 | |
| 1540 | /* Pad to end of cacheline */ |
| 1541 | while ((unsigned long)batch % CACHELINE_BYTES) |
| 1542 | *batch++ = MI_NOOP; |
| 1543 | |
| 1544 | return batch; |
| 1545 | } |
| 1546 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1547 | #define CTX_WA_BB_OBJ_SIZE (PAGE_SIZE) |
| 1548 | |
| 1549 | static int lrc_setup_wa_ctx(struct intel_engine_cs *engine) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1550 | { |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1551 | struct drm_i915_gem_object *obj; |
| 1552 | struct i915_vma *vma; |
| 1553 | int err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1554 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1555 | obj = i915_gem_object_create(engine->i915, CTX_WA_BB_OBJ_SIZE); |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1556 | if (IS_ERR(obj)) |
| 1557 | return PTR_ERR(obj); |
| 1558 | |
Chris Wilson | 82ad644 | 2018-06-05 16:37:58 +0100 | [diff] [blame] | 1559 | vma = i915_vma_instance(obj, &engine->i915->ggtt.vm, NULL); |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1560 | if (IS_ERR(vma)) { |
| 1561 | err = PTR_ERR(vma); |
| 1562 | goto err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1563 | } |
| 1564 | |
Chris Wilson | 7a859c6 | 2018-07-27 10:18:55 +0100 | [diff] [blame] | 1565 | err = i915_vma_pin(vma, 0, 0, PIN_GLOBAL | PIN_HIGH); |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1566 | if (err) |
| 1567 | goto err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1568 | |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1569 | engine->wa_ctx.vma = vma; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1570 | return 0; |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1571 | |
| 1572 | err: |
| 1573 | i915_gem_object_put(obj); |
| 1574 | return err; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1575 | } |
| 1576 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1577 | static void lrc_destroy_wa_ctx(struct intel_engine_cs *engine) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1578 | { |
Chris Wilson | 6a2f59e | 2018-07-21 13:50:37 +0100 | [diff] [blame] | 1579 | i915_vma_unpin_and_release(&engine->wa_ctx.vma, 0); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1580 | } |
| 1581 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1582 | typedef u32 *(*wa_bb_func_t)(struct intel_engine_cs *engine, u32 *batch); |
| 1583 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 1584 | static int intel_init_workaround_bb(struct intel_engine_cs *engine) |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1585 | { |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1586 | struct i915_ctx_workarounds *wa_ctx = &engine->wa_ctx; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1587 | struct i915_wa_ctx_bb *wa_bb[2] = { &wa_ctx->indirect_ctx, |
| 1588 | &wa_ctx->per_ctx }; |
| 1589 | wa_bb_func_t wa_bb_fn[2]; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1590 | struct page *page; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1591 | void *batch, *batch_ptr; |
| 1592 | unsigned int i; |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1593 | int ret; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1594 | |
Tvrtko Ursulin | bbb8a9d | 2018-10-12 07:31:42 +0100 | [diff] [blame] | 1595 | if (GEM_DEBUG_WARN_ON(engine->id != RCS)) |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1596 | return -EINVAL; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1597 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1598 | switch (INTEL_GEN(engine->i915)) { |
Oscar Mateo | cc38cae | 2018-05-08 14:29:23 -0700 | [diff] [blame] | 1599 | case 11: |
| 1600 | return 0; |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1601 | case 10: |
Rafael Antognolli | 4b6ce68 | 2018-02-05 15:33:30 -0800 | [diff] [blame] | 1602 | wa_bb_fn[0] = gen10_init_indirectctx_bb; |
| 1603 | wa_bb_fn[1] = NULL; |
| 1604 | break; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1605 | case 9: |
| 1606 | wa_bb_fn[0] = gen9_init_indirectctx_bb; |
Chris Wilson | b8aa223 | 2017-09-21 14:54:44 +0100 | [diff] [blame] | 1607 | wa_bb_fn[1] = NULL; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1608 | break; |
| 1609 | case 8: |
| 1610 | wa_bb_fn[0] = gen8_init_indirectctx_bb; |
Chris Wilson | 3ad7b52 | 2017-10-03 21:34:49 +0100 | [diff] [blame] | 1611 | wa_bb_fn[1] = NULL; |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1612 | break; |
| 1613 | default: |
| 1614 | MISSING_CASE(INTEL_GEN(engine->i915)); |
Arun Siluvery | 5e60d79 | 2015-06-23 15:50:44 +0100 | [diff] [blame] | 1615 | return 0; |
Arun Siluvery | 0504cff | 2015-07-14 15:01:27 +0100 | [diff] [blame] | 1616 | } |
Arun Siluvery | 5e60d79 | 2015-06-23 15:50:44 +0100 | [diff] [blame] | 1617 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1618 | ret = lrc_setup_wa_ctx(engine); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1619 | if (ret) { |
| 1620 | DRM_DEBUG_DRIVER("Failed to setup context WA page: %d\n", ret); |
| 1621 | return ret; |
| 1622 | } |
| 1623 | |
Chris Wilson | 48bb74e | 2016-08-15 10:49:04 +0100 | [diff] [blame] | 1624 | page = i915_gem_object_get_dirty_page(wa_ctx->vma->obj, 0); |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1625 | batch = batch_ptr = kmap_atomic(page); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1626 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1627 | /* |
| 1628 | * Emit the two workaround batch buffers, recording the offset from the |
| 1629 | * start of the workaround batch buffer object for each and their |
| 1630 | * respective sizes. |
| 1631 | */ |
| 1632 | for (i = 0; i < ARRAY_SIZE(wa_bb_fn); i++) { |
| 1633 | wa_bb[i]->offset = batch_ptr - batch; |
Tvrtko Ursulin | bbb8a9d | 2018-10-12 07:31:42 +0100 | [diff] [blame] | 1634 | if (GEM_DEBUG_WARN_ON(!IS_ALIGNED(wa_bb[i]->offset, |
| 1635 | CACHELINE_BYTES))) { |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1636 | ret = -EINVAL; |
| 1637 | break; |
| 1638 | } |
Chris Wilson | 604a8f6 | 2017-09-21 14:54:43 +0100 | [diff] [blame] | 1639 | if (wa_bb_fn[i]) |
| 1640 | batch_ptr = wa_bb_fn[i](engine, batch_ptr); |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1641 | wa_bb[i]->size = batch_ptr - (batch + wa_bb[i]->offset); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1642 | } |
| 1643 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1644 | BUG_ON(batch_ptr - batch > CTX_WA_BB_OBJ_SIZE); |
| 1645 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1646 | kunmap_atomic(batch); |
| 1647 | if (ret) |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 1648 | lrc_destroy_wa_ctx(engine); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1649 | |
| 1650 | return ret; |
| 1651 | } |
| 1652 | |
Chris Wilson | f3c9d407 | 2018-01-02 15:12:34 +0000 | [diff] [blame] | 1653 | static void enable_execlists(struct intel_engine_cs *engine) |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1654 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1655 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | f3c9d407 | 2018-01-02 15:12:34 +0000 | [diff] [blame] | 1656 | |
Chris Wilson | 060f232 | 2018-12-18 10:27:12 +0000 | [diff] [blame] | 1657 | intel_engine_set_hwsp_writemask(engine, ~0u); /* HWSTAM */ |
Kelvin Gardiner | 225701f | 2018-01-30 11:49:17 -0200 | [diff] [blame] | 1658 | |
| 1659 | /* |
| 1660 | * Make sure we're not enabling the new 12-deep CSB |
| 1661 | * FIFO as that requires a slightly updated handling |
| 1662 | * in the ctx switch irq. Since we're currently only |
| 1663 | * using only 2 elements of the enhanced execlists the |
| 1664 | * deeper FIFO it's not needed and it's not worth adding |
| 1665 | * more statements to the irq handler to support it. |
| 1666 | */ |
| 1667 | if (INTEL_GEN(dev_priv) >= 11) |
| 1668 | I915_WRITE(RING_MODE_GEN7(engine), |
| 1669 | _MASKED_BIT_DISABLE(GEN11_GFX_DISABLE_LEGACY_MODE)); |
| 1670 | else |
| 1671 | I915_WRITE(RING_MODE_GEN7(engine), |
| 1672 | _MASKED_BIT_ENABLE(GFX_RUN_LIST_ENABLE)); |
| 1673 | |
Chris Wilson | 9a4dc80 | 2018-05-18 11:09:33 +0100 | [diff] [blame] | 1674 | I915_WRITE(RING_MI_MODE(engine->mmio_base), |
| 1675 | _MASKED_BIT_DISABLE(STOP_RING)); |
| 1676 | |
Chris Wilson | f3c9d407 | 2018-01-02 15:12:34 +0000 | [diff] [blame] | 1677 | I915_WRITE(RING_HWS_PGA(engine->mmio_base), |
| 1678 | engine->status_page.ggtt_offset); |
| 1679 | POSTING_READ(RING_HWS_PGA(engine->mmio_base)); |
| 1680 | } |
| 1681 | |
Chris Wilson | 9a4dc80 | 2018-05-18 11:09:33 +0100 | [diff] [blame] | 1682 | static bool unexpected_starting_state(struct intel_engine_cs *engine) |
| 1683 | { |
| 1684 | struct drm_i915_private *dev_priv = engine->i915; |
| 1685 | bool unexpected = false; |
| 1686 | |
| 1687 | if (I915_READ(RING_MI_MODE(engine->mmio_base)) & STOP_RING) { |
| 1688 | DRM_DEBUG_DRIVER("STOP_RING still set in RING_MI_MODE\n"); |
| 1689 | unexpected = true; |
| 1690 | } |
| 1691 | |
| 1692 | return unexpected; |
| 1693 | } |
| 1694 | |
Chris Wilson | f3c9d407 | 2018-01-02 15:12:34 +0000 | [diff] [blame] | 1695 | static int gen8_init_common_ring(struct intel_engine_cs *engine) |
| 1696 | { |
Tvrtko Ursulin | 4a15c75c | 2018-12-03 13:33:41 +0000 | [diff] [blame] | 1697 | intel_engine_apply_workarounds(engine); |
Chris Wilson | 5a688ee | 2018-12-06 18:07:13 +0000 | [diff] [blame] | 1698 | intel_engine_apply_whitelist(engine); |
Tvrtko Ursulin | 4a15c75c | 2018-12-03 13:33:41 +0000 | [diff] [blame] | 1699 | |
Chris Wilson | 805615d | 2018-08-15 19:42:51 +0100 | [diff] [blame] | 1700 | intel_mocs_init_engine(engine); |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1701 | |
Chris Wilson | ad07dfc | 2016-10-07 07:53:26 +0100 | [diff] [blame] | 1702 | intel_engine_reset_breadcrumbs(engine); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1703 | |
Chris Wilson | 9a4dc80 | 2018-05-18 11:09:33 +0100 | [diff] [blame] | 1704 | if (GEM_SHOW_DEBUG() && unexpected_starting_state(engine)) { |
| 1705 | struct drm_printer p = drm_debug_printer(__func__); |
| 1706 | |
| 1707 | intel_engine_dump(engine, &p, NULL); |
| 1708 | } |
| 1709 | |
Chris Wilson | f3c9d407 | 2018-01-02 15:12:34 +0000 | [diff] [blame] | 1710 | enable_execlists(engine); |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1711 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1712 | return 0; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1713 | } |
| 1714 | |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 1715 | static struct i915_request * |
| 1716 | execlists_reset_prepare(struct intel_engine_cs *engine) |
| 1717 | { |
| 1718 | struct intel_engine_execlists * const execlists = &engine->execlists; |
Chris Wilson | 6357293 | 2018-05-16 19:33:54 +0100 | [diff] [blame] | 1719 | struct i915_request *request, *active; |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1720 | unsigned long flags; |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 1721 | |
Chris Wilson | 66fc829 | 2018-08-15 14:58:27 +0100 | [diff] [blame] | 1722 | GEM_TRACE("%s: depth<-%d\n", engine->name, |
| 1723 | atomic_read(&execlists->tasklet.count)); |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 1724 | |
| 1725 | /* |
| 1726 | * Prevent request submission to the hardware until we have |
| 1727 | * completed the reset in i915_gem_reset_finish(). If a request |
| 1728 | * is completed by one engine, it may then queue a request |
| 1729 | * to a second via its execlists->tasklet *just* as we are |
| 1730 | * calling engine->init_hw() and also writing the ELSP. |
| 1731 | * Turning off the execlists->tasklet until the reset is over |
| 1732 | * prevents the race. |
| 1733 | */ |
| 1734 | __tasklet_disable_sync_once(&execlists->tasklet); |
| 1735 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1736 | spin_lock_irqsave(&engine->timeline.lock, flags); |
| 1737 | |
Chris Wilson | 6357293 | 2018-05-16 19:33:54 +0100 | [diff] [blame] | 1738 | /* |
| 1739 | * We want to flush the pending context switches, having disabled |
| 1740 | * the tasklet above, we can assume exclusive access to the execlists. |
| 1741 | * For this allows us to catch up with an inflight preemption event, |
| 1742 | * and avoid blaming an innocent request if the stall was due to the |
| 1743 | * preemption itself. |
| 1744 | */ |
Chris Wilson | fd8526e | 2018-06-28 21:12:10 +0100 | [diff] [blame] | 1745 | process_csb(engine); |
Chris Wilson | 6357293 | 2018-05-16 19:33:54 +0100 | [diff] [blame] | 1746 | |
| 1747 | /* |
| 1748 | * The last active request can then be no later than the last request |
| 1749 | * now in ELSP[0]. So search backwards from there, so that if the GPU |
| 1750 | * has advanced beyond the last CSB update, it will be pardoned. |
| 1751 | */ |
| 1752 | active = NULL; |
| 1753 | request = port_request(execlists->port); |
| 1754 | if (request) { |
Chris Wilson | 3f6e982 | 2018-05-16 19:33:55 +0100 | [diff] [blame] | 1755 | /* |
| 1756 | * Prevent the breadcrumb from advancing before we decide |
| 1757 | * which request is currently active. |
| 1758 | */ |
| 1759 | intel_engine_stop_cs(engine); |
| 1760 | |
Chris Wilson | 6357293 | 2018-05-16 19:33:54 +0100 | [diff] [blame] | 1761 | list_for_each_entry_from_reverse(request, |
| 1762 | &engine->timeline.requests, |
| 1763 | link) { |
| 1764 | if (__i915_request_completed(request, |
| 1765 | request->global_seqno)) |
| 1766 | break; |
| 1767 | |
| 1768 | active = request; |
| 1769 | } |
Chris Wilson | 6357293 | 2018-05-16 19:33:54 +0100 | [diff] [blame] | 1770 | } |
| 1771 | |
Chris Wilson | 9512f98 | 2018-06-28 21:12:11 +0100 | [diff] [blame] | 1772 | spin_unlock_irqrestore(&engine->timeline.lock, flags); |
| 1773 | |
Chris Wilson | 6357293 | 2018-05-16 19:33:54 +0100 | [diff] [blame] | 1774 | return active; |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | static void execlists_reset(struct intel_engine_cs *engine, |
| 1778 | struct i915_request *request) |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1779 | { |
Mika Kuoppala | b620e87 | 2017-09-22 15:43:03 +0300 | [diff] [blame] | 1780 | struct intel_engine_execlists * const execlists = &engine->execlists; |
Chris Wilson | 221ab9719 | 2017-09-16 21:44:14 +0100 | [diff] [blame] | 1781 | unsigned long flags; |
Chris Wilson | 5692251 | 2018-04-28 12:15:32 +0100 | [diff] [blame] | 1782 | u32 *regs; |
Chris Wilson | cdb6ded | 2017-07-21 13:32:22 +0100 | [diff] [blame] | 1783 | |
Tvrtko Ursulin | c5f6d57 | 2018-09-26 15:50:33 +0100 | [diff] [blame] | 1784 | GEM_TRACE("%s request global=%d, current=%d\n", |
Tvrtko Ursulin | 0c5c7df | 2018-04-06 13:35:14 +0100 | [diff] [blame] | 1785 | engine->name, request ? request->global_seqno : 0, |
| 1786 | intel_engine_get_seqno(engine)); |
Chris Wilson | 4223221 | 2018-01-02 15:12:32 +0000 | [diff] [blame] | 1787 | |
Chris Wilson | d8857d5 | 2018-06-28 21:12:05 +0100 | [diff] [blame] | 1788 | spin_lock_irqsave(&engine->timeline.lock, flags); |
Chris Wilson | 221ab9719 | 2017-09-16 21:44:14 +0100 | [diff] [blame] | 1789 | |
Chris Wilson | cdb6ded | 2017-07-21 13:32:22 +0100 | [diff] [blame] | 1790 | /* |
| 1791 | * Catch up with any missed context-switch interrupts. |
| 1792 | * |
| 1793 | * Ideally we would just read the remaining CSB entries now that we |
| 1794 | * know the gpu is idle. However, the CSB registers are sometimes^W |
| 1795 | * often trashed across a GPU reset! Instead we have to rely on |
| 1796 | * guessing the missed context-switch events by looking at what |
| 1797 | * requests were completed. |
| 1798 | */ |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 1799 | execlists_cancel_port_requests(execlists); |
Chris Wilson | 221ab9719 | 2017-09-16 21:44:14 +0100 | [diff] [blame] | 1800 | |
| 1801 | /* Push back any incomplete requests for replay after the reset. */ |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 1802 | __unwind_incomplete_requests(engine); |
Chris Wilson | cdb6ded | 2017-07-21 13:32:22 +0100 | [diff] [blame] | 1803 | |
Chris Wilson | c3160da | 2018-05-31 09:22:45 +0100 | [diff] [blame] | 1804 | /* Following the reset, we need to reload the CSB read/write pointers */ |
Chris Wilson | f4b58f0 | 2018-06-28 21:12:08 +0100 | [diff] [blame] | 1805 | reset_csb_pointers(&engine->execlists); |
Chris Wilson | c3160da | 2018-05-31 09:22:45 +0100 | [diff] [blame] | 1806 | |
Chris Wilson | d8857d5 | 2018-06-28 21:12:05 +0100 | [diff] [blame] | 1807 | spin_unlock_irqrestore(&engine->timeline.lock, flags); |
Chris Wilson | aebbc2d | 2018-03-02 13:12:46 +0000 | [diff] [blame] | 1808 | |
Chris Wilson | a3e3883 | 2018-03-02 14:32:45 +0000 | [diff] [blame] | 1809 | /* |
| 1810 | * If the request was innocent, we leave the request in the ELSP |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 1811 | * and will try to replay it on restarting. The context image may |
| 1812 | * have been corrupted by the reset, in which case we may have |
| 1813 | * to service a new GPU hang, but more likely we can continue on |
| 1814 | * without impact. |
| 1815 | * |
| 1816 | * If the request was guilty, we presume the context is corrupt |
| 1817 | * and have to at least restore the RING register in the context |
| 1818 | * image back to the expected values to skip over the guilty request. |
| 1819 | */ |
Chris Wilson | 221ab9719 | 2017-09-16 21:44:14 +0100 | [diff] [blame] | 1820 | if (!request || request->fence.error != -EIO) |
Chris Wilson | c0dcb20 | 2017-02-07 15:24:37 +0000 | [diff] [blame] | 1821 | return; |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1822 | |
Chris Wilson | a3e3883 | 2018-03-02 14:32:45 +0000 | [diff] [blame] | 1823 | /* |
| 1824 | * We want a simple context + ring to execute the breadcrumb update. |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1825 | * We cannot rely on the context being intact across the GPU hang, |
| 1826 | * so clear it and rebuild just what we need for the breadcrumb. |
| 1827 | * All pending requests for this context will be zapped, and any |
| 1828 | * future request will be after userspace has had the opportunity |
| 1829 | * to recreate its own state. |
| 1830 | */ |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 1831 | regs = request->hw_context->lrc_reg_state; |
Chris Wilson | fe0c493 | 2018-05-18 10:02:11 +0100 | [diff] [blame] | 1832 | if (engine->pinned_default_state) { |
| 1833 | memcpy(regs, /* skip restoring the vanilla PPHWSP */ |
| 1834 | engine->pinned_default_state + LRC_STATE_PN * PAGE_SIZE, |
| 1835 | engine->context_size - PAGE_SIZE); |
Chris Wilson | 5692251 | 2018-04-28 12:15:32 +0100 | [diff] [blame] | 1836 | } |
Chris Wilson | 4e0d64d | 2018-05-17 22:26:30 +0100 | [diff] [blame] | 1837 | execlists_init_reg_state(regs, |
| 1838 | request->gem_context, engine, request->ring); |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1839 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1840 | /* Move the RING_HEAD onto the breadcrumb, past the hanging batch */ |
Chris Wilson | 5692251 | 2018-04-28 12:15:32 +0100 | [diff] [blame] | 1841 | regs[CTX_RING_BUFFER_START + 1] = i915_ggtt_offset(request->ring->vma); |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1842 | |
Chris Wilson | 41d3768 | 2018-06-11 12:08:45 +0100 | [diff] [blame] | 1843 | request->ring->head = intel_ring_wrap(request->ring, request->postfix); |
| 1844 | regs[CTX_RING_HEAD + 1] = request->ring->head; |
| 1845 | |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1846 | intel_ring_update_space(request->ring); |
| 1847 | |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 1848 | /* Reset WaIdleLiteRestore:bdw,skl as well */ |
Chris Wilson | 7e4992a | 2017-09-28 20:38:59 +0100 | [diff] [blame] | 1849 | unwind_wa_tail(request); |
Chris Wilson | 821ed7d | 2016-09-09 14:11:53 +0100 | [diff] [blame] | 1850 | } |
| 1851 | |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 1852 | static void execlists_reset_finish(struct intel_engine_cs *engine) |
| 1853 | { |
Chris Wilson | 5db1d4e | 2018-06-04 08:34:40 +0100 | [diff] [blame] | 1854 | struct intel_engine_execlists * const execlists = &engine->execlists; |
| 1855 | |
Chris Wilson | fe25f30 | 2018-05-22 11:19:37 +0100 | [diff] [blame] | 1856 | /* |
Chris Wilson | 9e4fa01 | 2018-08-28 16:27:02 +0100 | [diff] [blame] | 1857 | * After a GPU reset, we may have requests to replay. Do so now while |
| 1858 | * we still have the forcewake to be sure that the GPU is not allowed |
| 1859 | * to sleep before we restart and reload a context. |
Chris Wilson | fe25f30 | 2018-05-22 11:19:37 +0100 | [diff] [blame] | 1860 | * |
Chris Wilson | fe25f30 | 2018-05-22 11:19:37 +0100 | [diff] [blame] | 1861 | */ |
Chris Wilson | 9e4fa01 | 2018-08-28 16:27:02 +0100 | [diff] [blame] | 1862 | if (!RB_EMPTY_ROOT(&execlists->queue.rb_root)) |
| 1863 | execlists->tasklet.func(execlists->tasklet.data); |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 1864 | |
Chris Wilson | 9e4fa01 | 2018-08-28 16:27:02 +0100 | [diff] [blame] | 1865 | tasklet_enable(&execlists->tasklet); |
Chris Wilson | 66fc829 | 2018-08-15 14:58:27 +0100 | [diff] [blame] | 1866 | GEM_TRACE("%s: depth->%d\n", engine->name, |
| 1867 | atomic_read(&execlists->tasklet.count)); |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 1868 | } |
| 1869 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 1870 | static int gen8_emit_bb_start(struct i915_request *rq, |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 1871 | u64 offset, u32 len, |
Mika Kuoppala | 54af56d | 2017-02-28 17:28:08 +0200 | [diff] [blame] | 1872 | const unsigned int flags) |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1873 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1874 | u32 *cs; |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1875 | |
Chris Wilson | 74f947412 | 2018-05-03 20:54:16 +0100 | [diff] [blame] | 1876 | cs = intel_ring_begin(rq, 6); |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1877 | if (IS_ERR(cs)) |
| 1878 | return PTR_ERR(cs); |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1879 | |
Chris Wilson | 279f5a0 | 2017-10-05 20:10:05 +0100 | [diff] [blame] | 1880 | /* |
| 1881 | * WaDisableCtxRestoreArbitration:bdw,chv |
| 1882 | * |
| 1883 | * We don't need to perform MI_ARB_ENABLE as often as we do (in |
| 1884 | * particular all the gen that do not need the w/a at all!), if we |
| 1885 | * took care to make sure that on every switch into this context |
| 1886 | * (both ordinary and for preemption) that arbitrartion was enabled |
| 1887 | * we would be fine. However, there doesn't seem to be a downside to |
| 1888 | * being paranoid and making sure it is set before each batch and |
| 1889 | * every context-switch. |
| 1890 | * |
| 1891 | * Note that if we fail to enable arbitration before the request |
| 1892 | * is complete, then we do not see the context-switch interrupt and |
| 1893 | * the engine hangs (with RING_HEAD == RING_TAIL). |
| 1894 | * |
| 1895 | * That satisfies both the GPGPU w/a and our heavy-handed paranoia. |
| 1896 | */ |
Chris Wilson | 3ad7b52 | 2017-10-03 21:34:49 +0100 | [diff] [blame] | 1897 | *cs++ = MI_ARB_ON_OFF | MI_ARB_ENABLE; |
| 1898 | |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1899 | /* FIXME(BDW): Address space and security selectors. */ |
Mika Kuoppala | 54af56d | 2017-02-28 17:28:08 +0200 | [diff] [blame] | 1900 | *cs++ = MI_BATCH_BUFFER_START_GEN8 | |
Lucas De Marchi | 08e3e21 | 2018-08-03 16:24:43 -0700 | [diff] [blame] | 1901 | (flags & I915_DISPATCH_SECURE ? 0 : BIT(8)); |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1902 | *cs++ = lower_32_bits(offset); |
| 1903 | *cs++ = upper_32_bits(offset); |
Chris Wilson | 74f947412 | 2018-05-03 20:54:16 +0100 | [diff] [blame] | 1904 | |
| 1905 | *cs++ = MI_ARB_ON_OFF | MI_ARB_DISABLE; |
| 1906 | *cs++ = MI_NOOP; |
Chris Wilson | e889426 | 2018-12-07 09:02:13 +0000 | [diff] [blame] | 1907 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 1908 | intel_ring_advance(rq, cs); |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1909 | |
| 1910 | return 0; |
| 1911 | } |
| 1912 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1913 | static void gen8_logical_ring_enable_irq(struct intel_engine_cs *engine) |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1914 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1915 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1916 | I915_WRITE_IMR(engine, |
| 1917 | ~(engine->irq_enable_mask | engine->irq_keep_mask)); |
| 1918 | POSTING_READ_FW(RING_IMR(engine->mmio_base)); |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1919 | } |
| 1920 | |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1921 | static void gen8_logical_ring_disable_irq(struct intel_engine_cs *engine) |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1922 | { |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 1923 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 31bb59c | 2016-07-01 17:23:27 +0100 | [diff] [blame] | 1924 | I915_WRITE_IMR(engine, ~engine->irq_keep_mask); |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1925 | } |
| 1926 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 1927 | static int gen8_emit_flush(struct i915_request *request, u32 mode) |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1928 | { |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1929 | u32 cmd, *cs; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1930 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1931 | cs = intel_ring_begin(request, 4); |
| 1932 | if (IS_ERR(cs)) |
| 1933 | return PTR_ERR(cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1934 | |
| 1935 | cmd = MI_FLUSH_DW + 1; |
| 1936 | |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1937 | /* We always require a command barrier so that subsequent |
| 1938 | * commands, such as breadcrumb interrupts, are strictly ordered |
| 1939 | * wrt the contents of the write cache being flushed to memory |
| 1940 | * (and thus being coherent from the CPU). |
| 1941 | */ |
| 1942 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; |
| 1943 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1944 | if (mode & EMIT_INVALIDATE) { |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1945 | cmd |= MI_INVALIDATE_TLB; |
Chris Wilson | 5fc2805 | 2018-11-08 14:00:39 +0000 | [diff] [blame] | 1946 | if (request->engine->class == VIDEO_DECODE_CLASS) |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1947 | cmd |= MI_INVALIDATE_BSD; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1948 | } |
| 1949 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1950 | *cs++ = cmd; |
| 1951 | *cs++ = I915_GEM_HWS_SCRATCH_ADDR | MI_FLUSH_DW_USE_GTT; |
| 1952 | *cs++ = 0; /* upper addr */ |
| 1953 | *cs++ = 0; /* value */ |
| 1954 | intel_ring_advance(request, cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1955 | |
| 1956 | return 0; |
| 1957 | } |
| 1958 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 1959 | static int gen8_emit_flush_render(struct i915_request *request, |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1960 | u32 mode) |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1961 | { |
Chris Wilson | b5321f3 | 2016-08-02 22:50:18 +0100 | [diff] [blame] | 1962 | struct intel_engine_cs *engine = request->engine; |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 1963 | u32 scratch_addr = |
Chris Wilson | 5179749 | 2018-12-04 14:15:16 +0000 | [diff] [blame] | 1964 | i915_scratch_offset(engine->i915) + 2 * CACHELINE_BYTES; |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1965 | bool vf_flush_wa = false, dc_flush_wa = false; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 1966 | u32 *cs, flags = 0; |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1967 | int len; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1968 | |
| 1969 | flags |= PIPE_CONTROL_CS_STALL; |
| 1970 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1971 | if (mode & EMIT_FLUSH) { |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1972 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; |
| 1973 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
Francisco Jerez | 965fd60 | 2016-01-13 18:59:39 -0800 | [diff] [blame] | 1974 | flags |= PIPE_CONTROL_DC_FLUSH_ENABLE; |
Chris Wilson | 40a2448 | 2015-08-21 16:08:41 +0100 | [diff] [blame] | 1975 | flags |= PIPE_CONTROL_FLUSH_ENABLE; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1976 | } |
| 1977 | |
Chris Wilson | 7c9cf4e | 2016-08-02 22:50:25 +0100 | [diff] [blame] | 1978 | if (mode & EMIT_INVALIDATE) { |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1979 | flags |= PIPE_CONTROL_TLB_INVALIDATE; |
| 1980 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; |
| 1981 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 1982 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 1983 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; |
| 1984 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; |
| 1985 | flags |= PIPE_CONTROL_QW_WRITE; |
| 1986 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1987 | |
Ben Widawsky | 1a5a9ce | 2015-12-17 09:49:57 -0800 | [diff] [blame] | 1988 | /* |
| 1989 | * On GEN9: before VF_CACHE_INVALIDATE we need to emit a NULL |
| 1990 | * pipe control. |
| 1991 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 1992 | if (IS_GEN(request->i915, 9)) |
Ben Widawsky | 1a5a9ce | 2015-12-17 09:49:57 -0800 | [diff] [blame] | 1993 | vf_flush_wa = true; |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 1994 | |
| 1995 | /* WaForGAMHang:kbl */ |
| 1996 | if (IS_KBL_REVID(request->i915, 0, KBL_REVID_B0)) |
| 1997 | dc_flush_wa = true; |
Ben Widawsky | 1a5a9ce | 2015-12-17 09:49:57 -0800 | [diff] [blame] | 1998 | } |
Imre Deak | 9647ff3 | 2015-01-25 13:27:11 -0800 | [diff] [blame] | 1999 | |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 2000 | len = 6; |
| 2001 | |
| 2002 | if (vf_flush_wa) |
| 2003 | len += 6; |
| 2004 | |
| 2005 | if (dc_flush_wa) |
| 2006 | len += 12; |
| 2007 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2008 | cs = intel_ring_begin(request, len); |
| 2009 | if (IS_ERR(cs)) |
| 2010 | return PTR_ERR(cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 2011 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 2012 | if (vf_flush_wa) |
| 2013 | cs = gen8_emit_pipe_control(cs, 0, 0); |
Imre Deak | 9647ff3 | 2015-01-25 13:27:11 -0800 | [diff] [blame] | 2014 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 2015 | if (dc_flush_wa) |
| 2016 | cs = gen8_emit_pipe_control(cs, PIPE_CONTROL_DC_FLUSH_ENABLE, |
| 2017 | 0); |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 2018 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 2019 | cs = gen8_emit_pipe_control(cs, flags, scratch_addr); |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 2020 | |
Tvrtko Ursulin | 9f235df | 2017-02-16 12:23:25 +0000 | [diff] [blame] | 2021 | if (dc_flush_wa) |
| 2022 | cs = gen8_emit_pipe_control(cs, PIPE_CONTROL_CS_STALL, 0); |
Mika Kuoppala | 0b2d093 | 2016-06-07 17:19:10 +0300 | [diff] [blame] | 2023 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2024 | intel_ring_advance(request, cs); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 2025 | |
| 2026 | return 0; |
| 2027 | } |
| 2028 | |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 2029 | /* |
| 2030 | * Reserve space for 2 NOOPs at the end of each request to be |
| 2031 | * used as a workaround for not being allowed to do lite |
| 2032 | * restore with HEAD==TAIL (WaIdleLiteRestore). |
| 2033 | */ |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 2034 | static void gen8_emit_wa_tail(struct i915_request *request, u32 *cs) |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 2035 | { |
Chris Wilson | beecec9 | 2017-10-03 21:34:52 +0100 | [diff] [blame] | 2036 | /* Ensure there's always at least one preemption point per-request. */ |
| 2037 | *cs++ = MI_ARB_CHECK; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2038 | *cs++ = MI_NOOP; |
| 2039 | request->wa_tail = intel_ring_offset(request, cs); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 2040 | } |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 2041 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 2042 | static void gen8_emit_breadcrumb(struct i915_request *request, u32 *cs) |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 2043 | { |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 2044 | /* w/a: bit 5 needs to be zero for MI_FLUSH_DW address. */ |
| 2045 | BUILD_BUG_ON(I915_GEM_HWS_INDEX_ADDR & (1 << 5)); |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 2046 | |
Michał Winiarski | df77cd8 | 2017-10-25 22:00:15 +0200 | [diff] [blame] | 2047 | cs = gen8_emit_ggtt_write(cs, request->global_seqno, |
| 2048 | intel_hws_seqno_address(request->engine)); |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2049 | *cs++ = MI_USER_INTERRUPT; |
Chris Wilson | 74f947412 | 2018-05-03 20:54:16 +0100 | [diff] [blame] | 2050 | *cs++ = MI_ARB_ON_OFF | MI_ARB_ENABLE; |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2051 | request->tail = intel_ring_offset(request, cs); |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 2052 | assert_ring_tail_valid(request->ring, request->tail); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 2053 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2054 | gen8_emit_wa_tail(request, cs); |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 2055 | } |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2056 | static const int gen8_emit_breadcrumb_sz = 6 + WA_TAIL_DWORDS; |
| 2057 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 2058 | static void gen8_emit_breadcrumb_rcs(struct i915_request *request, u32 *cs) |
Chris Wilson | 7c17d37 | 2016-01-20 15:43:35 +0200 | [diff] [blame] | 2059 | { |
Michał Winiarski | ce81a65 | 2016-04-12 15:51:55 +0200 | [diff] [blame] | 2060 | /* We're using qword write, seqno should be aligned to 8 bytes. */ |
| 2061 | BUILD_BUG_ON(I915_GEM_HWS_INDEX & 1); |
| 2062 | |
Chris Wilson | 6a62372 | 2018-12-28 15:31:13 +0000 | [diff] [blame] | 2063 | cs = gen8_emit_ggtt_write_rcs(cs, |
| 2064 | request->global_seqno, |
| 2065 | intel_hws_seqno_address(request->engine), |
| 2066 | PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH | |
| 2067 | PIPE_CONTROL_DEPTH_CACHE_FLUSH | |
| 2068 | PIPE_CONTROL_DC_FLUSH_ENABLE | |
| 2069 | PIPE_CONTROL_FLUSH_ENABLE | |
| 2070 | PIPE_CONTROL_CS_STALL); |
| 2071 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2072 | *cs++ = MI_USER_INTERRUPT; |
Chris Wilson | 74f947412 | 2018-05-03 20:54:16 +0100 | [diff] [blame] | 2073 | *cs++ = MI_ARB_ON_OFF | MI_ARB_ENABLE; |
Chris Wilson | 6a62372 | 2018-12-28 15:31:13 +0000 | [diff] [blame] | 2074 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2075 | request->tail = intel_ring_offset(request, cs); |
Chris Wilson | ed1501d | 2017-03-27 14:14:12 +0100 | [diff] [blame] | 2076 | assert_ring_tail_valid(request->ring, request->tail); |
Chris Wilson | caddfe7 | 2016-10-28 13:58:52 +0100 | [diff] [blame] | 2077 | |
Tvrtko Ursulin | 73dec95 | 2017-02-14 11:32:42 +0000 | [diff] [blame] | 2078 | gen8_emit_wa_tail(request, cs); |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 2079 | } |
Michał Winiarski | df77cd8 | 2017-10-25 22:00:15 +0200 | [diff] [blame] | 2080 | static const int gen8_emit_breadcrumb_rcs_sz = 8 + WA_TAIL_DWORDS; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2081 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 2082 | static int gen8_init_rcs_context(struct i915_request *rq) |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 2083 | { |
| 2084 | int ret; |
| 2085 | |
Tvrtko Ursulin | 452420d | 2018-12-03 13:33:57 +0000 | [diff] [blame] | 2086 | ret = intel_engine_emit_ctx_wa(rq); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 2087 | if (ret) |
| 2088 | return ret; |
| 2089 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 2090 | ret = intel_rcs_context_init_mocs(rq); |
Peter Antoine | 3bbaba0 | 2015-07-10 20:13:11 +0300 | [diff] [blame] | 2091 | /* |
| 2092 | * Failing to program the MOCS is non-fatal.The system will not |
| 2093 | * run at peak performance. So generate an error and carry on. |
| 2094 | */ |
| 2095 | if (ret) |
| 2096 | DRM_ERROR("MOCS failed to program: expect performance issues.\n"); |
| 2097 | |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 2098 | return i915_gem_render_state_emit(rq); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 2101 | /** |
| 2102 | * intel_logical_ring_cleanup() - deallocate the Engine Command Streamer |
Tvrtko Ursulin | 14bb2c1 | 2016-06-03 14:02:17 +0100 | [diff] [blame] | 2103 | * @engine: Engine Command Streamer. |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 2104 | */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2105 | void intel_logical_ring_cleanup(struct intel_engine_cs *engine) |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 2106 | { |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 2107 | struct drm_i915_private *dev_priv; |
Oscar Mateo | 9832b9d | 2014-07-24 17:04:30 +0100 | [diff] [blame] | 2108 | |
Tvrtko Ursulin | 27af5ee | 2016-04-04 12:11:56 +0100 | [diff] [blame] | 2109 | /* |
| 2110 | * Tasklet cannot be active at this point due intel_mark_active/idle |
| 2111 | * so this is just for documentation. |
| 2112 | */ |
Sagar Arun Kamble | c6dce8f | 2017-11-16 19:02:37 +0530 | [diff] [blame] | 2113 | if (WARN_ON(test_bit(TASKLET_STATE_SCHED, |
| 2114 | &engine->execlists.tasklet.state))) |
| 2115 | tasklet_kill(&engine->execlists.tasklet); |
Tvrtko Ursulin | 27af5ee | 2016-04-04 12:11:56 +0100 | [diff] [blame] | 2116 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2117 | dev_priv = engine->i915; |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 2118 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2119 | if (engine->buffer) { |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2120 | WARN_ON((I915_READ_MODE(engine) & MODE_IDLE) == 0); |
Dave Gordon | b0366a5 | 2015-12-08 15:02:36 +0000 | [diff] [blame] | 2121 | } |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 2122 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2123 | if (engine->cleanup) |
| 2124 | engine->cleanup(engine); |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 2125 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 2126 | intel_engine_cleanup_common(engine); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 2127 | |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 2128 | lrc_destroy_wa_ctx(engine); |
Chris Wilson | f3c9d407 | 2018-01-02 15:12:34 +0000 | [diff] [blame] | 2129 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2130 | engine->i915 = NULL; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2131 | dev_priv->engine[engine->id] = NULL; |
| 2132 | kfree(engine); |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 2133 | } |
| 2134 | |
Chris Wilson | 209b795 | 2018-07-17 21:29:32 +0100 | [diff] [blame] | 2135 | void intel_execlists_set_default_submission(struct intel_engine_cs *engine) |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 2136 | { |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 2137 | engine->submit_request = execlists_submit_request; |
Chris Wilson | 27a5f61 | 2017-09-15 18:31:00 +0100 | [diff] [blame] | 2138 | engine->cancel_requests = execlists_cancel_requests; |
Chris Wilson | e2f3496 | 2018-10-01 15:47:54 +0100 | [diff] [blame] | 2139 | engine->schedule = i915_schedule; |
Sagar Arun Kamble | c6dce8f | 2017-11-16 19:02:37 +0530 | [diff] [blame] | 2140 | engine->execlists.tasklet.func = execlists_submission_tasklet; |
Chris Wilson | aba5e27 | 2017-10-25 15:39:41 +0100 | [diff] [blame] | 2141 | |
Chris Wilson | 1329115 | 2018-05-16 19:33:52 +0100 | [diff] [blame] | 2142 | engine->reset.prepare = execlists_reset_prepare; |
| 2143 | |
Chris Wilson | aba5e27 | 2017-10-25 15:39:41 +0100 | [diff] [blame] | 2144 | engine->park = NULL; |
| 2145 | engine->unpark = NULL; |
Tvrtko Ursulin | cf669b4 | 2017-11-29 10:28:05 +0000 | [diff] [blame] | 2146 | |
| 2147 | engine->flags |= I915_ENGINE_SUPPORTS_STATS; |
Chris Wilson | 2a694fe | 2018-04-03 19:35:37 +0100 | [diff] [blame] | 2148 | if (engine->i915->preempt_context) |
| 2149 | engine->flags |= I915_ENGINE_HAS_PREEMPTION; |
Chris Wilson | 3fed180 | 2018-02-07 21:05:43 +0000 | [diff] [blame] | 2150 | |
| 2151 | engine->i915->caps.scheduler = |
| 2152 | I915_SCHEDULER_CAP_ENABLED | |
| 2153 | I915_SCHEDULER_CAP_PRIORITY; |
Chris Wilson | 2a694fe | 2018-04-03 19:35:37 +0100 | [diff] [blame] | 2154 | if (intel_engine_has_preemption(engine)) |
Chris Wilson | 3fed180 | 2018-02-07 21:05:43 +0000 | [diff] [blame] | 2155 | engine->i915->caps.scheduler |= I915_SCHEDULER_CAP_PREEMPTION; |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
Tvrtko Ursulin | c9cacf9 | 2016-01-12 17:32:34 +0000 | [diff] [blame] | 2158 | static void |
Chris Wilson | e1382ef | 2016-05-06 15:40:20 +0100 | [diff] [blame] | 2159 | logical_ring_default_vfuncs(struct intel_engine_cs *engine) |
Tvrtko Ursulin | c9cacf9 | 2016-01-12 17:32:34 +0000 | [diff] [blame] | 2160 | { |
| 2161 | /* Default vfuncs which can be overriden by each engine. */ |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2162 | engine->init_hw = gen8_init_common_ring; |
Chris Wilson | 5adfb77 | 2018-05-16 19:33:51 +0100 | [diff] [blame] | 2163 | |
| 2164 | engine->reset.prepare = execlists_reset_prepare; |
| 2165 | engine->reset.reset = execlists_reset; |
| 2166 | engine->reset.finish = execlists_reset_finish; |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 2167 | |
| 2168 | engine->context_pin = execlists_context_pin; |
Chris Wilson | f73e739 | 2016-12-18 15:37:24 +0000 | [diff] [blame] | 2169 | engine->request_alloc = execlists_request_alloc; |
| 2170 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2171 | engine->emit_flush = gen8_emit_flush; |
Chris Wilson | 9b81d55 | 2016-10-28 13:58:50 +0100 | [diff] [blame] | 2172 | engine->emit_breadcrumb = gen8_emit_breadcrumb; |
Chris Wilson | 98f29e8 | 2016-10-28 13:58:51 +0100 | [diff] [blame] | 2173 | engine->emit_breadcrumb_sz = gen8_emit_breadcrumb_sz; |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 2174 | |
Chris Wilson | 209b795 | 2018-07-17 21:29:32 +0100 | [diff] [blame] | 2175 | engine->set_default_submission = intel_execlists_set_default_submission; |
Chris Wilson | ddd66c5 | 2016-08-02 22:50:31 +0100 | [diff] [blame] | 2176 | |
Tvrtko Ursulin | d4ccceb | 2018-03-02 18:14:56 +0200 | [diff] [blame] | 2177 | if (INTEL_GEN(engine->i915) < 11) { |
| 2178 | engine->irq_enable = gen8_logical_ring_enable_irq; |
| 2179 | engine->irq_disable = gen8_logical_ring_disable_irq; |
| 2180 | } else { |
| 2181 | /* |
| 2182 | * TODO: On Gen11 interrupt masks need to be clear |
| 2183 | * to allow C6 entry. Keep interrupts enabled at |
| 2184 | * and take the hit of generating extra interrupts |
| 2185 | * until a more refined solution exists. |
| 2186 | */ |
| 2187 | } |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2188 | engine->emit_bb_start = gen8_emit_bb_start; |
Tvrtko Ursulin | c9cacf9 | 2016-01-12 17:32:34 +0000 | [diff] [blame] | 2189 | } |
| 2190 | |
Tvrtko Ursulin | d9f3af9 | 2016-01-12 17:32:35 +0000 | [diff] [blame] | 2191 | static inline void |
Dave Gordon | c2c7f24 | 2016-07-13 16:03:35 +0100 | [diff] [blame] | 2192 | logical_ring_default_irqs(struct intel_engine_cs *engine) |
Tvrtko Ursulin | d9f3af9 | 2016-01-12 17:32:35 +0000 | [diff] [blame] | 2193 | { |
Daniele Ceraolo Spurio | fa6f071 | 2018-03-14 11:26:53 -0700 | [diff] [blame] | 2194 | unsigned int shift = 0; |
| 2195 | |
| 2196 | if (INTEL_GEN(engine->i915) < 11) { |
| 2197 | const u8 irq_shifts[] = { |
| 2198 | [RCS] = GEN8_RCS_IRQ_SHIFT, |
| 2199 | [BCS] = GEN8_BCS_IRQ_SHIFT, |
| 2200 | [VCS] = GEN8_VCS1_IRQ_SHIFT, |
| 2201 | [VCS2] = GEN8_VCS2_IRQ_SHIFT, |
| 2202 | [VECS] = GEN8_VECS_IRQ_SHIFT, |
| 2203 | }; |
| 2204 | |
| 2205 | shift = irq_shifts[engine->id]; |
| 2206 | } |
| 2207 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2208 | engine->irq_enable_mask = GT_RENDER_USER_INTERRUPT << shift; |
| 2209 | engine->irq_keep_mask = GT_CONTEXT_SWITCH_INTERRUPT << shift; |
Tvrtko Ursulin | d9f3af9 | 2016-01-12 17:32:35 +0000 | [diff] [blame] | 2210 | } |
| 2211 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 2212 | static void |
| 2213 | logical_ring_setup(struct intel_engine_cs *engine) |
| 2214 | { |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 2215 | intel_engine_setup_common(engine); |
| 2216 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 2217 | /* Intentionally left blank. */ |
| 2218 | engine->buffer = NULL; |
| 2219 | |
Sagar Arun Kamble | c6dce8f | 2017-11-16 19:02:37 +0530 | [diff] [blame] | 2220 | tasklet_init(&engine->execlists.tasklet, |
| 2221 | execlists_submission_tasklet, (unsigned long)engine); |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 2222 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 2223 | logical_ring_default_vfuncs(engine); |
| 2224 | logical_ring_default_irqs(engine); |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 2225 | } |
| 2226 | |
Daniele Ceraolo Spurio | 486e93f | 2017-09-13 09:56:02 +0100 | [diff] [blame] | 2227 | static int logical_ring_init(struct intel_engine_cs *engine) |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2228 | { |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2229 | struct drm_i915_private *i915 = engine->i915; |
| 2230 | struct intel_engine_execlists * const execlists = &engine->execlists; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2231 | int ret; |
| 2232 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 2233 | ret = intel_engine_init_common(engine); |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2234 | if (ret) |
Chris Wilson | b2164e4 | 2018-09-20 20:59:48 +0100 | [diff] [blame] | 2235 | return ret; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2236 | |
Daniele Ceraolo Spurio | a60acb2 | 2019-01-09 17:32:32 -0800 | [diff] [blame] | 2237 | intel_engine_init_workarounds(engine); |
| 2238 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2239 | if (HAS_LOGICAL_RING_ELSQ(i915)) { |
| 2240 | execlists->submit_reg = i915->regs + |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 2241 | i915_mmio_reg_offset(RING_EXECLIST_SQ_CONTENTS(engine)); |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2242 | execlists->ctrl_reg = i915->regs + |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 2243 | i915_mmio_reg_offset(RING_EXECLIST_CONTROL(engine)); |
| 2244 | } else { |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2245 | execlists->submit_reg = i915->regs + |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 2246 | i915_mmio_reg_offset(RING_ELSP(engine)); |
| 2247 | } |
Chris Wilson | 693cfbf | 2018-01-02 15:12:33 +0000 | [diff] [blame] | 2248 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2249 | execlists->preempt_complete_status = ~0u; |
| 2250 | if (i915->preempt_context) { |
Chris Wilson | ab82a06 | 2018-04-30 14:15:01 +0100 | [diff] [blame] | 2251 | struct intel_context *ce = |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2252 | to_intel_context(i915->preempt_context, engine); |
Chris Wilson | ab82a06 | 2018-04-30 14:15:01 +0100 | [diff] [blame] | 2253 | |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2254 | execlists->preempt_complete_status = |
Chris Wilson | ab82a06 | 2018-04-30 14:15:01 +0100 | [diff] [blame] | 2255 | upper_32_bits(ce->lrc_desc); |
| 2256 | } |
Chris Wilson | d637637 | 2018-02-07 21:05:44 +0000 | [diff] [blame] | 2257 | |
Chris Wilson | 4659289 | 2018-11-30 12:59:54 +0000 | [diff] [blame] | 2258 | execlists->csb_status = |
| 2259 | &engine->status_page.page_addr[I915_HWS_CSB_BUF0_INDEX]; |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2260 | |
Chris Wilson | 4659289 | 2018-11-30 12:59:54 +0000 | [diff] [blame] | 2261 | execlists->csb_write = |
| 2262 | &engine->status_page.page_addr[intel_hws_csb_write_index(i915)]; |
Chris Wilson | bc4237e | 2018-06-28 21:12:07 +0100 | [diff] [blame] | 2263 | |
Chris Wilson | f4b58f0 | 2018-06-28 21:12:08 +0100 | [diff] [blame] | 2264 | reset_csb_pointers(execlists); |
Chris Wilson | c3160da | 2018-05-31 09:22:45 +0100 | [diff] [blame] | 2265 | |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2266 | return 0; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2267 | } |
| 2268 | |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 2269 | int logical_render_ring_init(struct intel_engine_cs *engine) |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2270 | { |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2271 | int ret; |
| 2272 | |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 2273 | logical_ring_setup(engine); |
| 2274 | |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2275 | /* Override some for render ring. */ |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2276 | engine->init_context = gen8_init_rcs_context; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2277 | engine->emit_flush = gen8_emit_flush_render; |
Michał Winiarski | df77cd8 | 2017-10-25 22:00:15 +0200 | [diff] [blame] | 2278 | engine->emit_breadcrumb = gen8_emit_breadcrumb_rcs; |
| 2279 | engine->emit_breadcrumb_sz = gen8_emit_breadcrumb_rcs_sz; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2280 | |
Chris Wilson | b2164e4 | 2018-09-20 20:59:48 +0100 | [diff] [blame] | 2281 | ret = logical_ring_init(engine); |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2282 | if (ret) |
| 2283 | return ret; |
| 2284 | |
| 2285 | ret = intel_init_workaround_bb(engine); |
| 2286 | if (ret) { |
| 2287 | /* |
| 2288 | * We continue even if we fail to initialize WA batch |
| 2289 | * because we only expect rare glitches but nothing |
| 2290 | * critical to prevent us from using GPU |
| 2291 | */ |
| 2292 | DRM_ERROR("WA batch buffer initialization failed: %d\n", |
| 2293 | ret); |
| 2294 | } |
| 2295 | |
Tvrtko Ursulin | 69bcdec | 2018-12-03 12:50:12 +0000 | [diff] [blame] | 2296 | intel_engine_init_whitelist(engine); |
Tvrtko Ursulin | 4a15c75c | 2018-12-03 13:33:41 +0000 | [diff] [blame] | 2297 | |
Chris Wilson | b2164e4 | 2018-09-20 20:59:48 +0100 | [diff] [blame] | 2298 | return 0; |
Tvrtko Ursulin | a19d6ff | 2016-06-23 14:52:41 +0100 | [diff] [blame] | 2299 | } |
| 2300 | |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 2301 | int logical_xcs_ring_init(struct intel_engine_cs *engine) |
Tvrtko Ursulin | bb45438 | 2016-07-13 16:03:36 +0100 | [diff] [blame] | 2302 | { |
| 2303 | logical_ring_setup(engine); |
| 2304 | |
| 2305 | return logical_ring_init(engine); |
| 2306 | } |
| 2307 | |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2308 | static u32 |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2309 | make_rpcs(struct drm_i915_private *dev_priv) |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2310 | { |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 2311 | bool subslice_pg = RUNTIME_INFO(dev_priv)->sseu.has_subslice_pg; |
| 2312 | u8 slices = hweight8(RUNTIME_INFO(dev_priv)->sseu.slice_mask); |
| 2313 | u8 subslices = hweight8(RUNTIME_INFO(dev_priv)->sseu.subslice_mask[0]); |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2314 | u32 rpcs = 0; |
| 2315 | |
| 2316 | /* |
| 2317 | * No explicit RPCS request is needed to ensure full |
| 2318 | * slice/subslice/EU enablement prior to Gen9. |
| 2319 | */ |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2320 | if (INTEL_GEN(dev_priv) < 9) |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2321 | return 0; |
| 2322 | |
| 2323 | /* |
Tvrtko Ursulin | b212f0a | 2018-09-03 12:30:07 +0100 | [diff] [blame] | 2324 | * Since the SScount bitfield in GEN8_R_PWR_CLK_STATE is only three bits |
| 2325 | * wide and Icelake has up to eight subslices, specfial programming is |
| 2326 | * needed in order to correctly enable all subslices. |
| 2327 | * |
| 2328 | * According to documentation software must consider the configuration |
| 2329 | * as 2x4x8 and hardware will translate this to 1x8x8. |
| 2330 | * |
| 2331 | * Furthemore, even though SScount is three bits, maximum documented |
| 2332 | * value for it is four. From this some rules/restrictions follow: |
| 2333 | * |
| 2334 | * 1. |
| 2335 | * If enabled subslice count is greater than four, two whole slices must |
| 2336 | * be enabled instead. |
| 2337 | * |
| 2338 | * 2. |
| 2339 | * When more than one slice is enabled, hardware ignores the subslice |
| 2340 | * count altogether. |
| 2341 | * |
| 2342 | * From these restrictions it follows that it is not possible to enable |
| 2343 | * a count of subslices between the SScount maximum of four restriction, |
| 2344 | * and the maximum available number on a particular SKU. Either all |
| 2345 | * subslices are enabled, or a count between one and four on the first |
| 2346 | * slice. |
| 2347 | */ |
Lucas De Marchi | cf819ef | 2018-12-12 10:10:43 -0800 | [diff] [blame] | 2348 | if (IS_GEN(dev_priv, 11) && slices == 1 && subslices >= 4) { |
Tvrtko Ursulin | b212f0a | 2018-09-03 12:30:07 +0100 | [diff] [blame] | 2349 | GEM_BUG_ON(subslices & 1); |
| 2350 | |
| 2351 | subslice_pg = false; |
| 2352 | slices *= 2; |
| 2353 | } |
| 2354 | |
| 2355 | /* |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2356 | * Starting in Gen9, render power gating can leave |
| 2357 | * slice/subslice/EU in a partially enabled state. We |
| 2358 | * must make an explicit request through RPCS for full |
| 2359 | * enablement. |
| 2360 | */ |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 2361 | if (RUNTIME_INFO(dev_priv)->sseu.has_slice_pg) { |
Tvrtko Ursulin | b212f0a | 2018-09-03 12:30:07 +0100 | [diff] [blame] | 2362 | u32 mask, val = slices; |
| 2363 | |
| 2364 | if (INTEL_GEN(dev_priv) >= 11) { |
| 2365 | mask = GEN11_RPCS_S_CNT_MASK; |
| 2366 | val <<= GEN11_RPCS_S_CNT_SHIFT; |
| 2367 | } else { |
| 2368 | mask = GEN8_RPCS_S_CNT_MASK; |
| 2369 | val <<= GEN8_RPCS_S_CNT_SHIFT; |
| 2370 | } |
| 2371 | |
| 2372 | GEM_BUG_ON(val & ~mask); |
| 2373 | val &= mask; |
| 2374 | |
| 2375 | rpcs |= GEN8_RPCS_ENABLE | GEN8_RPCS_S_CNT_ENABLE | val; |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2376 | } |
| 2377 | |
Tvrtko Ursulin | b212f0a | 2018-09-03 12:30:07 +0100 | [diff] [blame] | 2378 | if (subslice_pg) { |
| 2379 | u32 val = subslices; |
| 2380 | |
| 2381 | val <<= GEN8_RPCS_SS_CNT_SHIFT; |
| 2382 | |
| 2383 | GEM_BUG_ON(val & ~GEN8_RPCS_SS_CNT_MASK); |
| 2384 | val &= GEN8_RPCS_SS_CNT_MASK; |
| 2385 | |
| 2386 | rpcs |= GEN8_RPCS_ENABLE | GEN8_RPCS_SS_CNT_ENABLE | val; |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2387 | } |
| 2388 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 2389 | if (RUNTIME_INFO(dev_priv)->sseu.has_eu_pg) { |
Tvrtko Ursulin | b212f0a | 2018-09-03 12:30:07 +0100 | [diff] [blame] | 2390 | u32 val; |
| 2391 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 2392 | val = RUNTIME_INFO(dev_priv)->sseu.eu_per_subslice << |
Tvrtko Ursulin | b212f0a | 2018-09-03 12:30:07 +0100 | [diff] [blame] | 2393 | GEN8_RPCS_EU_MIN_SHIFT; |
| 2394 | GEM_BUG_ON(val & ~GEN8_RPCS_EU_MIN_MASK); |
| 2395 | val &= GEN8_RPCS_EU_MIN_MASK; |
| 2396 | |
| 2397 | rpcs |= val; |
| 2398 | |
Jani Nikula | 0258404 | 2018-12-31 16:56:41 +0200 | [diff] [blame] | 2399 | val = RUNTIME_INFO(dev_priv)->sseu.eu_per_subslice << |
Tvrtko Ursulin | b212f0a | 2018-09-03 12:30:07 +0100 | [diff] [blame] | 2400 | GEN8_RPCS_EU_MAX_SHIFT; |
| 2401 | GEM_BUG_ON(val & ~GEN8_RPCS_EU_MAX_MASK); |
| 2402 | val &= GEN8_RPCS_EU_MAX_MASK; |
| 2403 | |
| 2404 | rpcs |= val; |
| 2405 | |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2406 | rpcs |= GEN8_RPCS_ENABLE; |
| 2407 | } |
| 2408 | |
| 2409 | return rpcs; |
| 2410 | } |
| 2411 | |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2412 | static u32 intel_lr_indirect_ctx_offset(struct intel_engine_cs *engine) |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 2413 | { |
| 2414 | u32 indirect_ctx_offset; |
| 2415 | |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2416 | switch (INTEL_GEN(engine->i915)) { |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 2417 | default: |
Chris Wilson | c033666 | 2016-05-06 15:40:21 +0100 | [diff] [blame] | 2418 | MISSING_CASE(INTEL_GEN(engine->i915)); |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 2419 | /* fall through */ |
Michel Thierry | fd034c7 | 2018-03-02 18:15:00 +0200 | [diff] [blame] | 2420 | case 11: |
| 2421 | indirect_ctx_offset = |
| 2422 | GEN11_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; |
| 2423 | break; |
Michel Thierry | 7bd0a2c | 2017-06-06 13:30:38 -0700 | [diff] [blame] | 2424 | case 10: |
| 2425 | indirect_ctx_offset = |
| 2426 | GEN10_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; |
| 2427 | break; |
Michel Thierry | 7156291 | 2016-02-23 10:31:49 +0000 | [diff] [blame] | 2428 | case 9: |
| 2429 | indirect_ctx_offset = |
| 2430 | GEN9_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; |
| 2431 | break; |
| 2432 | case 8: |
| 2433 | indirect_ctx_offset = |
| 2434 | GEN8_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT; |
| 2435 | break; |
| 2436 | } |
| 2437 | |
| 2438 | return indirect_ctx_offset; |
| 2439 | } |
| 2440 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2441 | static void execlists_init_reg_state(u32 *regs, |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 2442 | struct i915_gem_context *ctx, |
| 2443 | struct intel_engine_cs *engine, |
| 2444 | struct intel_ring *ring) |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2445 | { |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 2446 | struct drm_i915_private *dev_priv = engine->i915; |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2447 | u32 base = engine->mmio_base; |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 2448 | bool rcs = engine->class == RENDER_CLASS; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2449 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2450 | /* A context is actually a big batch buffer with several |
| 2451 | * MI_LOAD_REGISTER_IMM commands followed by (reg, value) pairs. The |
| 2452 | * values we are setting here are only for the first context restore: |
| 2453 | * on a subsequent save, the GPU will recreate this batchbuffer with new |
| 2454 | * values (including all the missing MI_LOAD_REGISTER_IMM commands that |
| 2455 | * we are not initializing here). |
| 2456 | */ |
| 2457 | regs[CTX_LRI_HEADER_0] = MI_LOAD_REGISTER_IMM(rcs ? 14 : 11) | |
| 2458 | MI_LRI_FORCE_POSTED; |
| 2459 | |
| 2460 | CTX_REG(regs, CTX_CONTEXT_CONTROL, RING_CONTEXT_CONTROL(engine), |
Paulo Zanoni | ee43583 | 2018-08-09 16:58:52 -0700 | [diff] [blame] | 2461 | _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT) | |
Lucas De Marchi | 08e3e21 | 2018-08-03 16:24:43 -0700 | [diff] [blame] | 2462 | _MASKED_BIT_ENABLE(CTX_CTRL_INHIBIT_SYN_CTX_SWITCH)); |
Paulo Zanoni | ee43583 | 2018-08-09 16:58:52 -0700 | [diff] [blame] | 2463 | if (INTEL_GEN(dev_priv) < 11) { |
| 2464 | regs[CTX_CONTEXT_CONTROL + 1] |= |
| 2465 | _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT | |
| 2466 | CTX_CTRL_RS_CTX_ENABLE); |
| 2467 | } |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2468 | CTX_REG(regs, CTX_RING_HEAD, RING_HEAD(base), 0); |
| 2469 | CTX_REG(regs, CTX_RING_TAIL, RING_TAIL(base), 0); |
| 2470 | CTX_REG(regs, CTX_RING_BUFFER_START, RING_START(base), 0); |
| 2471 | CTX_REG(regs, CTX_RING_BUFFER_CONTROL, RING_CTL(base), |
| 2472 | RING_CTL_SIZE(ring->size) | RING_VALID); |
| 2473 | CTX_REG(regs, CTX_BB_HEAD_U, RING_BBADDR_UDW(base), 0); |
| 2474 | CTX_REG(regs, CTX_BB_HEAD_L, RING_BBADDR(base), 0); |
| 2475 | CTX_REG(regs, CTX_BB_STATE, RING_BBSTATE(base), RING_BB_PPGTT); |
| 2476 | CTX_REG(regs, CTX_SECOND_BB_HEAD_U, RING_SBBADDR_UDW(base), 0); |
| 2477 | CTX_REG(regs, CTX_SECOND_BB_HEAD_L, RING_SBBADDR(base), 0); |
| 2478 | CTX_REG(regs, CTX_SECOND_BB_STATE, RING_SBBSTATE(base), 0); |
| 2479 | if (rcs) { |
Chris Wilson | 604a8f6 | 2017-09-21 14:54:43 +0100 | [diff] [blame] | 2480 | struct i915_ctx_workarounds *wa_ctx = &engine->wa_ctx; |
| 2481 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2482 | CTX_REG(regs, CTX_RCS_INDIRECT_CTX, RING_INDIRECT_CTX(base), 0); |
| 2483 | CTX_REG(regs, CTX_RCS_INDIRECT_CTX_OFFSET, |
| 2484 | RING_INDIRECT_CTX_OFFSET(base), 0); |
Chris Wilson | 604a8f6 | 2017-09-21 14:54:43 +0100 | [diff] [blame] | 2485 | if (wa_ctx->indirect_ctx.size) { |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 2486 | u32 ggtt_offset = i915_ggtt_offset(wa_ctx->vma); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 2487 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2488 | regs[CTX_RCS_INDIRECT_CTX + 1] = |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 2489 | (ggtt_offset + wa_ctx->indirect_ctx.offset) | |
| 2490 | (wa_ctx->indirect_ctx.size / CACHELINE_BYTES); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 2491 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2492 | regs[CTX_RCS_INDIRECT_CTX_OFFSET + 1] = |
Tvrtko Ursulin | 0bc40be | 2016-03-16 11:00:37 +0000 | [diff] [blame] | 2493 | intel_lr_indirect_ctx_offset(engine) << 6; |
Chris Wilson | 604a8f6 | 2017-09-21 14:54:43 +0100 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | CTX_REG(regs, CTX_BB_PER_CTX_PTR, RING_BB_PER_CTX_PTR(base), 0); |
| 2497 | if (wa_ctx->per_ctx.size) { |
| 2498 | u32 ggtt_offset = i915_ggtt_offset(wa_ctx->vma); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 2499 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2500 | regs[CTX_BB_PER_CTX_PTR + 1] = |
Tvrtko Ursulin | 097d4f1 | 2017-02-17 07:58:59 +0000 | [diff] [blame] | 2501 | (ggtt_offset + wa_ctx->per_ctx.offset) | 0x01; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 2502 | } |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2503 | } |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2504 | |
| 2505 | regs[CTX_LRI_HEADER_1] = MI_LOAD_REGISTER_IMM(9) | MI_LRI_FORCE_POSTED; |
| 2506 | |
| 2507 | CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0); |
Ville Syrjälä | 0d925ea | 2015-11-04 23:20:11 +0200 | [diff] [blame] | 2508 | /* PDP values well be assigned later if needed */ |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2509 | CTX_REG(regs, CTX_PDP3_UDW, GEN8_RING_PDP_UDW(engine, 3), 0); |
| 2510 | CTX_REG(regs, CTX_PDP3_LDW, GEN8_RING_PDP_LDW(engine, 3), 0); |
| 2511 | CTX_REG(regs, CTX_PDP2_UDW, GEN8_RING_PDP_UDW(engine, 2), 0); |
| 2512 | CTX_REG(regs, CTX_PDP2_LDW, GEN8_RING_PDP_LDW(engine, 2), 0); |
| 2513 | CTX_REG(regs, CTX_PDP1_UDW, GEN8_RING_PDP_UDW(engine, 1), 0); |
| 2514 | CTX_REG(regs, CTX_PDP1_LDW, GEN8_RING_PDP_LDW(engine, 1), 0); |
| 2515 | CTX_REG(regs, CTX_PDP0_UDW, GEN8_RING_PDP_UDW(engine, 0), 0); |
| 2516 | 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] | 2517 | |
Chris Wilson | 4bdafb9 | 2018-09-26 21:12:22 +0100 | [diff] [blame] | 2518 | if (i915_vm_is_48bit(&ctx->ppgtt->vm)) { |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 2519 | /* 64b PPGTT (48bit canonical) |
| 2520 | * PDP0_DESCRIPTOR contains the base address to PML4 and |
| 2521 | * other PDP Descriptors are ignored. |
| 2522 | */ |
Chris Wilson | 4bdafb9 | 2018-09-26 21:12:22 +0100 | [diff] [blame] | 2523 | ASSIGN_CTX_PML4(ctx->ppgtt, regs); |
Chris Wilson | e889426 | 2018-12-07 09:02:13 +0000 | [diff] [blame] | 2524 | } else { |
| 2525 | ASSIGN_CTX_PDP(ctx->ppgtt, regs, 3); |
| 2526 | ASSIGN_CTX_PDP(ctx->ppgtt, regs, 2); |
| 2527 | ASSIGN_CTX_PDP(ctx->ppgtt, regs, 1); |
| 2528 | ASSIGN_CTX_PDP(ctx->ppgtt, regs, 0); |
Michel Thierry | 2dba323 | 2015-07-30 11:06:23 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
Tvrtko Ursulin | 56e51bf | 2017-02-21 09:58:39 +0000 | [diff] [blame] | 2531 | if (rcs) { |
| 2532 | regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1); |
| 2533 | CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, |
| 2534 | make_rpcs(dev_priv)); |
Robert Bragg | 19f81df | 2017-06-13 12:23:03 +0100 | [diff] [blame] | 2535 | |
| 2536 | i915_oa_init_reg_state(engine, ctx, regs); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2537 | } |
Chris Wilson | d0f5cc5 | 2018-07-30 17:43:25 +0100 | [diff] [blame] | 2538 | |
| 2539 | regs[CTX_END] = MI_BATCH_BUFFER_END; |
| 2540 | if (INTEL_GEN(dev_priv) >= 10) |
| 2541 | regs[CTX_END] |= BIT(0); |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | static int |
| 2545 | populate_lr_context(struct i915_gem_context *ctx, |
| 2546 | struct drm_i915_gem_object *ctx_obj, |
| 2547 | struct intel_engine_cs *engine, |
| 2548 | struct intel_ring *ring) |
| 2549 | { |
| 2550 | void *vaddr; |
Chris Wilson | d2b4b97 | 2017-11-10 14:26:33 +0000 | [diff] [blame] | 2551 | u32 *regs; |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 2552 | int ret; |
| 2553 | |
| 2554 | ret = i915_gem_object_set_to_cpu_domain(ctx_obj, true); |
| 2555 | if (ret) { |
| 2556 | DRM_DEBUG_DRIVER("Could not set to CPU domain\n"); |
| 2557 | return ret; |
| 2558 | } |
| 2559 | |
| 2560 | vaddr = i915_gem_object_pin_map(ctx_obj, I915_MAP_WB); |
| 2561 | if (IS_ERR(vaddr)) { |
| 2562 | ret = PTR_ERR(vaddr); |
| 2563 | DRM_DEBUG_DRIVER("Could not map object pages! (%d)\n", ret); |
| 2564 | return ret; |
| 2565 | } |
Chris Wilson | a4f5ea6 | 2016-10-28 13:58:35 +0100 | [diff] [blame] | 2566 | ctx_obj->mm.dirty = true; |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 2567 | |
Chris Wilson | d2b4b97 | 2017-11-10 14:26:33 +0000 | [diff] [blame] | 2568 | if (engine->default_state) { |
| 2569 | /* |
| 2570 | * We only want to copy over the template context state; |
| 2571 | * skipping over the headers reserved for GuC communication, |
| 2572 | * leaving those as zero. |
| 2573 | */ |
| 2574 | const unsigned long start = LRC_HEADER_PAGES * PAGE_SIZE; |
| 2575 | void *defaults; |
| 2576 | |
| 2577 | defaults = i915_gem_object_pin_map(engine->default_state, |
| 2578 | I915_MAP_WB); |
Matthew Auld | aaefa06 | 2018-03-01 11:46:39 +0000 | [diff] [blame] | 2579 | if (IS_ERR(defaults)) { |
| 2580 | ret = PTR_ERR(defaults); |
| 2581 | goto err_unpin_ctx; |
| 2582 | } |
Chris Wilson | d2b4b97 | 2017-11-10 14:26:33 +0000 | [diff] [blame] | 2583 | |
| 2584 | memcpy(vaddr + start, defaults + start, engine->context_size); |
| 2585 | i915_gem_object_unpin_map(engine->default_state); |
| 2586 | } |
| 2587 | |
Chris Wilson | a3aabe8 | 2016-10-04 21:11:26 +0100 | [diff] [blame] | 2588 | /* The second page of the context object contains some fields which must |
| 2589 | * be set up prior to the first execution. */ |
Chris Wilson | d2b4b97 | 2017-11-10 14:26:33 +0000 | [diff] [blame] | 2590 | regs = vaddr + LRC_STATE_PN * PAGE_SIZE; |
| 2591 | execlists_init_reg_state(regs, ctx, engine, ring); |
| 2592 | if (!engine->default_state) |
| 2593 | regs[CTX_CONTEXT_CONTROL + 1] |= |
| 2594 | _MASKED_BIT_ENABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT); |
Thomas Daniel | 05f0add | 2018-03-02 18:14:59 +0200 | [diff] [blame] | 2595 | if (ctx == ctx->i915->preempt_context && INTEL_GEN(engine->i915) < 11) |
Chris Wilson | 517aaff | 2018-01-23 21:04:12 +0000 | [diff] [blame] | 2596 | regs[CTX_CONTEXT_CONTROL + 1] |= |
| 2597 | _MASKED_BIT_ENABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT | |
| 2598 | CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2599 | |
Matthew Auld | aaefa06 | 2018-03-01 11:46:39 +0000 | [diff] [blame] | 2600 | err_unpin_ctx: |
Tvrtko Ursulin | 7d774ca | 2016-04-12 15:40:42 +0100 | [diff] [blame] | 2601 | i915_gem_object_unpin_map(ctx_obj); |
Matthew Auld | aaefa06 | 2018-03-01 11:46:39 +0000 | [diff] [blame] | 2602 | return ret; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2603 | } |
| 2604 | |
Chris Wilson | e2efd13 | 2016-05-24 14:53:34 +0100 | [diff] [blame] | 2605 | static int execlists_context_deferred_alloc(struct i915_gem_context *ctx, |
Chris Wilson | 1fc44d9 | 2018-05-17 22:26:32 +0100 | [diff] [blame] | 2606 | struct intel_engine_cs *engine, |
| 2607 | struct intel_context *ce) |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2608 | { |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2609 | struct drm_i915_gem_object *ctx_obj; |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 2610 | struct i915_vma *vma; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2611 | uint32_t context_size; |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 2612 | struct intel_ring *ring; |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 2613 | struct i915_timeline *timeline; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2614 | int ret; |
| 2615 | |
Chris Wilson | 1d2a19c | 2018-01-26 12:18:46 +0000 | [diff] [blame] | 2616 | if (ce->state) |
| 2617 | return 0; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2618 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 2619 | context_size = round_up(engine->context_size, I915_GTT_PAGE_SIZE); |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2620 | |
Michel Thierry | 0b29c75 | 2017-09-13 09:56:00 +0100 | [diff] [blame] | 2621 | /* |
| 2622 | * Before the actual start of the context image, we insert a few pages |
| 2623 | * for our own use and for sharing with the GuC. |
| 2624 | */ |
| 2625 | context_size += LRC_HEADER_PAGES * PAGE_SIZE; |
Alex Dai | d167519 | 2015-08-12 15:43:43 +0100 | [diff] [blame] | 2626 | |
Tvrtko Ursulin | 12d79d7 | 2016-12-01 14:16:37 +0000 | [diff] [blame] | 2627 | ctx_obj = i915_gem_object_create(ctx->i915, context_size); |
Chris Wilson | 467d357 | 2018-06-11 16:33:32 +0100 | [diff] [blame] | 2628 | if (IS_ERR(ctx_obj)) |
| 2629 | return PTR_ERR(ctx_obj); |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2630 | |
Chris Wilson | 82ad644 | 2018-06-05 16:37:58 +0100 | [diff] [blame] | 2631 | vma = i915_vma_instance(ctx_obj, &ctx->i915->ggtt.vm, NULL); |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 2632 | if (IS_ERR(vma)) { |
| 2633 | ret = PTR_ERR(vma); |
| 2634 | goto error_deref_obj; |
| 2635 | } |
| 2636 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 2637 | timeline = i915_timeline_create(ctx->i915, ctx->name); |
| 2638 | if (IS_ERR(timeline)) { |
| 2639 | ret = PTR_ERR(timeline); |
| 2640 | goto error_deref_obj; |
| 2641 | } |
| 2642 | |
| 2643 | ring = intel_engine_create_ring(engine, timeline, ctx->ring_size); |
| 2644 | i915_timeline_put(timeline); |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2645 | if (IS_ERR(ring)) { |
| 2646 | ret = PTR_ERR(ring); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 2647 | goto error_deref_obj; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2648 | } |
| 2649 | |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2650 | ret = populate_lr_context(ctx, ctx_obj, engine, ring); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2651 | if (ret) { |
| 2652 | DRM_DEBUG_DRIVER("Failed to populate LRC: %d\n", ret); |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2653 | goto error_ring_free; |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2654 | } |
| 2655 | |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2656 | ce->ring = ring; |
Chris Wilson | bf3783e | 2016-08-15 10:48:54 +0100 | [diff] [blame] | 2657 | ce->state = vma; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2658 | |
| 2659 | return 0; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2660 | |
Chris Wilson | dca33ec | 2016-08-02 22:50:20 +0100 | [diff] [blame] | 2661 | error_ring_free: |
Chris Wilson | 7e37f88 | 2016-08-02 22:50:21 +0100 | [diff] [blame] | 2662 | intel_ring_free(ring); |
Nick Hoath | e84fe80 | 2015-09-11 12:53:46 +0100 | [diff] [blame] | 2663 | error_deref_obj: |
Chris Wilson | f8c417c | 2016-07-20 13:31:53 +0100 | [diff] [blame] | 2664 | i915_gem_object_put(ctx_obj); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2665 | return ret; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2666 | } |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2667 | |
Chris Wilson | dee60ca | 2018-09-14 13:35:02 +0100 | [diff] [blame] | 2668 | void intel_lr_context_resume(struct drm_i915_private *i915) |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2669 | { |
Tvrtko Ursulin | e2f8039 | 2016-03-16 11:00:36 +0000 | [diff] [blame] | 2670 | struct intel_engine_cs *engine; |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2671 | struct i915_gem_context *ctx; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 2672 | enum intel_engine_id id; |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2673 | |
Chris Wilson | dee60ca | 2018-09-14 13:35:02 +0100 | [diff] [blame] | 2674 | /* |
| 2675 | * Because we emit WA_TAIL_DWORDS there may be a disparity |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2676 | * between our bookkeeping in ce->ring->head and ce->ring->tail and |
| 2677 | * that stored in context. As we only write new commands from |
| 2678 | * ce->ring->tail onwards, everything before that is junk. If the GPU |
| 2679 | * starts reading from its RING_HEAD from the context, it may try to |
| 2680 | * execute that junk and die. |
| 2681 | * |
| 2682 | * So to avoid that we reset the context images upon resume. For |
| 2683 | * simplicity, we just zero everything out. |
| 2684 | */ |
Chris Wilson | dee60ca | 2018-09-14 13:35:02 +0100 | [diff] [blame] | 2685 | list_for_each_entry(ctx, &i915->contexts.list, link) { |
| 2686 | for_each_engine(engine, i915, id) { |
Chris Wilson | ab82a06 | 2018-04-30 14:15:01 +0100 | [diff] [blame] | 2687 | struct intel_context *ce = |
| 2688 | to_intel_context(ctx, engine); |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2689 | |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2690 | if (!ce->state) |
| 2691 | continue; |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2692 | |
Chris Wilson | e6ba999 | 2017-04-25 14:00:49 +0100 | [diff] [blame] | 2693 | intel_ring_reset(ce->ring, 0); |
Chris Wilson | dee60ca | 2018-09-14 13:35:02 +0100 | [diff] [blame] | 2694 | |
| 2695 | if (ce->pin_count) { /* otherwise done in context_pin */ |
| 2696 | u32 *regs = ce->lrc_reg_state; |
| 2697 | |
| 2698 | regs[CTX_RING_HEAD + 1] = ce->ring->head; |
| 2699 | regs[CTX_RING_TAIL + 1] = ce->ring->tail; |
| 2700 | } |
Chris Wilson | bafb2f7 | 2016-09-21 14:51:08 +0100 | [diff] [blame] | 2701 | } |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2702 | } |
| 2703 | } |
Chris Wilson | 2c66555 | 2018-04-04 10:33:29 +0100 | [diff] [blame] | 2704 | |
Chris Wilson | 0212bde | 2019-01-15 21:29:48 +0000 | [diff] [blame^] | 2705 | void intel_execlists_show_requests(struct intel_engine_cs *engine, |
| 2706 | struct drm_printer *m, |
| 2707 | void (*show_request)(struct drm_printer *m, |
| 2708 | struct i915_request *rq, |
| 2709 | const char *prefix), |
| 2710 | unsigned int max) |
| 2711 | { |
| 2712 | const struct intel_engine_execlists *execlists = &engine->execlists; |
| 2713 | struct i915_request *rq, *last; |
| 2714 | unsigned long flags; |
| 2715 | unsigned int count; |
| 2716 | struct rb_node *rb; |
| 2717 | |
| 2718 | spin_lock_irqsave(&engine->timeline.lock, flags); |
| 2719 | |
| 2720 | last = NULL; |
| 2721 | count = 0; |
| 2722 | list_for_each_entry(rq, &engine->timeline.requests, link) { |
| 2723 | if (count++ < max - 1) |
| 2724 | show_request(m, rq, "\t\tE "); |
| 2725 | else |
| 2726 | last = rq; |
| 2727 | } |
| 2728 | if (last) { |
| 2729 | if (count > max) { |
| 2730 | drm_printf(m, |
| 2731 | "\t\t...skipping %d executing requests...\n", |
| 2732 | count - max); |
| 2733 | } |
| 2734 | show_request(m, last, "\t\tE "); |
| 2735 | } |
| 2736 | |
| 2737 | last = NULL; |
| 2738 | count = 0; |
| 2739 | drm_printf(m, "\t\tQueue priority: %d\n", execlists->queue_priority); |
| 2740 | for (rb = rb_first_cached(&execlists->queue); rb; rb = rb_next(rb)) { |
| 2741 | struct i915_priolist *p = rb_entry(rb, typeof(*p), node); |
| 2742 | int i; |
| 2743 | |
| 2744 | priolist_for_each_request(rq, p, i) { |
| 2745 | if (count++ < max - 1) |
| 2746 | show_request(m, rq, "\t\tQ "); |
| 2747 | else |
| 2748 | last = rq; |
| 2749 | } |
| 2750 | } |
| 2751 | if (last) { |
| 2752 | if (count > max) { |
| 2753 | drm_printf(m, |
| 2754 | "\t\t...skipping %d queued requests...\n", |
| 2755 | count - max); |
| 2756 | } |
| 2757 | show_request(m, last, "\t\tQ "); |
| 2758 | } |
| 2759 | |
| 2760 | spin_unlock_irqrestore(&engine->timeline.lock, flags); |
| 2761 | } |
| 2762 | |
Chris Wilson | 2c66555 | 2018-04-04 10:33:29 +0100 | [diff] [blame] | 2763 | #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) |
| 2764 | #include "selftests/intel_lrc.c" |
| 2765 | #endif |