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 | */ |
| 134 | |
| 135 | #include <drm/drmP.h> |
| 136 | #include <drm/i915_drm.h> |
| 137 | #include "i915_drv.h" |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 138 | |
Michael H. Nguyen | 468c681 | 2014-11-13 17:51:49 +0000 | [diff] [blame] | 139 | #define GEN9_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE) |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 140 | #define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE) |
| 141 | #define GEN8_LR_CONTEXT_OTHER_SIZE (2 * PAGE_SIZE) |
| 142 | |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 143 | #define RING_EXECLIST_QFULL (1 << 0x2) |
| 144 | #define RING_EXECLIST1_VALID (1 << 0x3) |
| 145 | #define RING_EXECLIST0_VALID (1 << 0x4) |
| 146 | #define RING_EXECLIST_ACTIVE_STATUS (3 << 0xE) |
| 147 | #define RING_EXECLIST1_ACTIVE (1 << 0x11) |
| 148 | #define RING_EXECLIST0_ACTIVE (1 << 0x12) |
| 149 | |
| 150 | #define GEN8_CTX_STATUS_IDLE_ACTIVE (1 << 0) |
| 151 | #define GEN8_CTX_STATUS_PREEMPTED (1 << 1) |
| 152 | #define GEN8_CTX_STATUS_ELEMENT_SWITCH (1 << 2) |
| 153 | #define GEN8_CTX_STATUS_ACTIVE_IDLE (1 << 3) |
| 154 | #define GEN8_CTX_STATUS_COMPLETE (1 << 4) |
| 155 | #define GEN8_CTX_STATUS_LITE_RESTORE (1 << 15) |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 156 | |
| 157 | #define CTX_LRI_HEADER_0 0x01 |
| 158 | #define CTX_CONTEXT_CONTROL 0x02 |
| 159 | #define CTX_RING_HEAD 0x04 |
| 160 | #define CTX_RING_TAIL 0x06 |
| 161 | #define CTX_RING_BUFFER_START 0x08 |
| 162 | #define CTX_RING_BUFFER_CONTROL 0x0a |
| 163 | #define CTX_BB_HEAD_U 0x0c |
| 164 | #define CTX_BB_HEAD_L 0x0e |
| 165 | #define CTX_BB_STATE 0x10 |
| 166 | #define CTX_SECOND_BB_HEAD_U 0x12 |
| 167 | #define CTX_SECOND_BB_HEAD_L 0x14 |
| 168 | #define CTX_SECOND_BB_STATE 0x16 |
| 169 | #define CTX_BB_PER_CTX_PTR 0x18 |
| 170 | #define CTX_RCS_INDIRECT_CTX 0x1a |
| 171 | #define CTX_RCS_INDIRECT_CTX_OFFSET 0x1c |
| 172 | #define CTX_LRI_HEADER_1 0x21 |
| 173 | #define CTX_CTX_TIMESTAMP 0x22 |
| 174 | #define CTX_PDP3_UDW 0x24 |
| 175 | #define CTX_PDP3_LDW 0x26 |
| 176 | #define CTX_PDP2_UDW 0x28 |
| 177 | #define CTX_PDP2_LDW 0x2a |
| 178 | #define CTX_PDP1_UDW 0x2c |
| 179 | #define CTX_PDP1_LDW 0x2e |
| 180 | #define CTX_PDP0_UDW 0x30 |
| 181 | #define CTX_PDP0_LDW 0x32 |
| 182 | #define CTX_LRI_HEADER_2 0x41 |
| 183 | #define CTX_R_PWR_CLK_STATE 0x42 |
| 184 | #define CTX_GPGPU_CSR_BASE_ADDRESS 0x44 |
| 185 | |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 186 | #define GEN8_CTX_VALID (1<<0) |
| 187 | #define GEN8_CTX_FORCE_PD_RESTORE (1<<1) |
| 188 | #define GEN8_CTX_FORCE_RESTORE (1<<2) |
| 189 | #define GEN8_CTX_L3LLC_COHERENT (1<<5) |
| 190 | #define GEN8_CTX_PRIVILEGE (1<<8) |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 191 | |
| 192 | #define ASSIGN_CTX_PDP(ppgtt, reg_state, n) { \ |
Mika Kuoppala | d852c7b | 2015-06-25 18:35:06 +0300 | [diff] [blame] | 193 | const u64 _addr = i915_page_dir_dma_addr((ppgtt), (n)); \ |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 194 | reg_state[CTX_PDP ## n ## _UDW+1] = upper_32_bits(_addr); \ |
| 195 | reg_state[CTX_PDP ## n ## _LDW+1] = lower_32_bits(_addr); \ |
| 196 | } |
| 197 | |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 198 | enum { |
| 199 | ADVANCED_CONTEXT = 0, |
| 200 | LEGACY_CONTEXT, |
| 201 | ADVANCED_AD_CONTEXT, |
| 202 | LEGACY_64B_CONTEXT |
| 203 | }; |
| 204 | #define GEN8_CTX_MODE_SHIFT 3 |
| 205 | enum { |
| 206 | FAULT_AND_HANG = 0, |
| 207 | FAULT_AND_HALT, /* Debug only */ |
| 208 | FAULT_AND_STREAM, |
| 209 | FAULT_AND_CONTINUE /* Unsupported */ |
| 210 | }; |
| 211 | #define GEN8_CTX_ID_SHIFT 32 |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 212 | #define CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT 0x17 |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 213 | |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 214 | static int intel_lr_context_pin(struct intel_engine_cs *ring, |
| 215 | struct intel_context *ctx); |
| 216 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 217 | /** |
| 218 | * intel_sanitize_enable_execlists() - sanitize i915.enable_execlists |
| 219 | * @dev: DRM device. |
| 220 | * @enable_execlists: value of i915.enable_execlists module parameter. |
| 221 | * |
| 222 | * Only certain platforms support Execlists (the prerequisites being |
Thomas Daniel | 27401d1 | 2014-12-11 12:48:35 +0000 | [diff] [blame] | 223 | * support for Logical Ring Contexts and Aliasing PPGTT or better). |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 224 | * |
| 225 | * Return: 1 if Execlists is supported and has to be enabled. |
| 226 | */ |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 227 | int intel_sanitize_enable_execlists(struct drm_device *dev, int enable_execlists) |
| 228 | { |
Daniel Vetter | bd84b1e | 2014-08-11 15:57:57 +0200 | [diff] [blame] | 229 | WARN_ON(i915.enable_ppgtt == -1); |
| 230 | |
Damien Lespiau | 70ee45e | 2014-11-14 15:05:59 +0000 | [diff] [blame] | 231 | if (INTEL_INFO(dev)->gen >= 9) |
| 232 | return 1; |
| 233 | |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 234 | if (enable_execlists == 0) |
| 235 | return 0; |
| 236 | |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 237 | if (HAS_LOGICAL_RING_CONTEXTS(dev) && USES_PPGTT(dev) && |
| 238 | i915.use_mmio_flip >= 0) |
Oscar Mateo | 127f100 | 2014-07-24 17:04:11 +0100 | [diff] [blame] | 239 | return 1; |
| 240 | |
| 241 | return 0; |
| 242 | } |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 243 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 244 | /** |
| 245 | * intel_execlists_ctx_id() - get the Execlists Context ID |
| 246 | * @ctx_obj: Logical Ring Context backing object. |
| 247 | * |
| 248 | * Do not confuse with ctx->id! Unfortunately we have a name overload |
| 249 | * here: the old context ID we pass to userspace as a handler so that |
| 250 | * they can refer to a context, and the new context ID we pass to the |
| 251 | * ELSP so that the GPU can inform us of the context status via |
| 252 | * interrupts. |
| 253 | * |
| 254 | * Return: 20-bits globally unique context ID. |
| 255 | */ |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 256 | u32 intel_execlists_ctx_id(struct drm_i915_gem_object *ctx_obj) |
| 257 | { |
| 258 | u32 lrca = i915_gem_obj_ggtt_offset(ctx_obj); |
| 259 | |
| 260 | /* LRCA is required to be 4K aligned so the more significant 20 bits |
| 261 | * are globally unique */ |
| 262 | return lrca >> 12; |
| 263 | } |
| 264 | |
Nick Hoath | 203a571 | 2015-02-06 11:30:04 +0000 | [diff] [blame] | 265 | static uint64_t execlists_ctx_descriptor(struct intel_engine_cs *ring, |
| 266 | struct drm_i915_gem_object *ctx_obj) |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 267 | { |
Nick Hoath | 203a571 | 2015-02-06 11:30:04 +0000 | [diff] [blame] | 268 | struct drm_device *dev = ring->dev; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 269 | uint64_t desc; |
| 270 | uint64_t lrca = i915_gem_obj_ggtt_offset(ctx_obj); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 271 | |
| 272 | WARN_ON(lrca & 0xFFFFFFFF00000FFFULL); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 273 | |
| 274 | desc = GEN8_CTX_VALID; |
| 275 | desc |= LEGACY_CONTEXT << GEN8_CTX_MODE_SHIFT; |
Arun Siluvery | 51847fb | 2015-04-07 14:01:33 +0100 | [diff] [blame] | 276 | if (IS_GEN8(ctx_obj->base.dev)) |
| 277 | desc |= GEN8_CTX_L3LLC_COHERENT; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 278 | desc |= GEN8_CTX_PRIVILEGE; |
| 279 | desc |= lrca; |
| 280 | desc |= (u64)intel_execlists_ctx_id(ctx_obj) << GEN8_CTX_ID_SHIFT; |
| 281 | |
| 282 | /* TODO: WaDisableLiteRestore when we start using semaphore |
| 283 | * signalling between Command Streamers */ |
| 284 | /* desc |= GEN8_CTX_FORCE_RESTORE; */ |
| 285 | |
Nick Hoath | 203a571 | 2015-02-06 11:30:04 +0000 | [diff] [blame] | 286 | /* WaEnableForceRestoreInCtxtDescForVCS:skl */ |
| 287 | if (IS_GEN9(dev) && |
| 288 | INTEL_REVID(dev) <= SKL_REVID_B0 && |
| 289 | (ring->id == BCS || ring->id == VCS || |
| 290 | ring->id == VECS || ring->id == VCS2)) |
| 291 | desc |= GEN8_CTX_FORCE_RESTORE; |
| 292 | |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 293 | return desc; |
| 294 | } |
| 295 | |
| 296 | static void execlists_elsp_write(struct intel_engine_cs *ring, |
| 297 | struct drm_i915_gem_object *ctx_obj0, |
| 298 | struct drm_i915_gem_object *ctx_obj1) |
| 299 | { |
Tvrtko Ursulin | 6e7cc47 | 2014-11-13 17:51:51 +0000 | [diff] [blame] | 300 | struct drm_device *dev = ring->dev; |
| 301 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 302 | uint64_t temp = 0; |
| 303 | uint32_t desc[4]; |
| 304 | |
| 305 | /* XXX: You must always write both descriptors in the order below. */ |
| 306 | if (ctx_obj1) |
Nick Hoath | 203a571 | 2015-02-06 11:30:04 +0000 | [diff] [blame] | 307 | temp = execlists_ctx_descriptor(ring, ctx_obj1); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 308 | else |
| 309 | temp = 0; |
| 310 | desc[1] = (u32)(temp >> 32); |
| 311 | desc[0] = (u32)temp; |
| 312 | |
Nick Hoath | 203a571 | 2015-02-06 11:30:04 +0000 | [diff] [blame] | 313 | temp = execlists_ctx_descriptor(ring, ctx_obj0); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 314 | desc[3] = (u32)(temp >> 32); |
| 315 | desc[2] = (u32)temp; |
| 316 | |
Chris Wilson | a6111f7 | 2015-04-07 16:21:02 +0100 | [diff] [blame] | 317 | spin_lock(&dev_priv->uncore.lock); |
| 318 | intel_uncore_forcewake_get__locked(dev_priv, FORCEWAKE_ALL); |
| 319 | I915_WRITE_FW(RING_ELSP(ring), desc[1]); |
| 320 | I915_WRITE_FW(RING_ELSP(ring), desc[0]); |
| 321 | I915_WRITE_FW(RING_ELSP(ring), desc[3]); |
Chris Wilson | 6daccb0 | 2015-01-16 11:34:35 +0200 | [diff] [blame] | 322 | |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 323 | /* The context is automatically loaded after the following */ |
Chris Wilson | a6111f7 | 2015-04-07 16:21:02 +0100 | [diff] [blame] | 324 | I915_WRITE_FW(RING_ELSP(ring), desc[2]); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 325 | |
| 326 | /* ELSP is a wo register, so use another nearby reg for posting instead */ |
Chris Wilson | a6111f7 | 2015-04-07 16:21:02 +0100 | [diff] [blame] | 327 | POSTING_READ_FW(RING_EXECLIST_STATUS(ring)); |
| 328 | intel_uncore_forcewake_put__locked(dev_priv, FORCEWAKE_ALL); |
| 329 | spin_unlock(&dev_priv->uncore.lock); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 330 | } |
| 331 | |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 332 | static int execlists_update_context(struct drm_i915_gem_object *ctx_obj, |
| 333 | struct drm_i915_gem_object *ring_obj, |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 334 | struct i915_hw_ppgtt *ppgtt, |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 335 | u32 tail) |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 336 | { |
| 337 | struct page *page; |
| 338 | uint32_t *reg_state; |
| 339 | |
| 340 | page = i915_gem_object_get_page(ctx_obj, 1); |
| 341 | reg_state = kmap_atomic(page); |
| 342 | |
| 343 | reg_state[CTX_RING_TAIL+1] = tail; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 344 | reg_state[CTX_RING_BUFFER_START+1] = i915_gem_obj_ggtt_offset(ring_obj); |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 345 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 346 | /* True PPGTT with dynamic page allocation: update PDP registers and |
| 347 | * point the unallocated PDPs to the scratch page |
| 348 | */ |
| 349 | if (ppgtt) { |
| 350 | ASSIGN_CTX_PDP(ppgtt, reg_state, 3); |
| 351 | ASSIGN_CTX_PDP(ppgtt, reg_state, 2); |
| 352 | ASSIGN_CTX_PDP(ppgtt, reg_state, 1); |
| 353 | ASSIGN_CTX_PDP(ppgtt, reg_state, 0); |
| 354 | } |
| 355 | |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 356 | kunmap_atomic(reg_state); |
| 357 | |
| 358 | return 0; |
| 359 | } |
| 360 | |
Dave Gordon | cd0707c | 2014-10-30 15:41:56 +0000 | [diff] [blame] | 361 | static void execlists_submit_contexts(struct intel_engine_cs *ring, |
| 362 | struct intel_context *to0, u32 tail0, |
| 363 | struct intel_context *to1, u32 tail1) |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 364 | { |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 365 | struct drm_i915_gem_object *ctx_obj0 = to0->engine[ring->id].state; |
| 366 | struct intel_ringbuffer *ringbuf0 = to0->engine[ring->id].ringbuf; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 367 | struct drm_i915_gem_object *ctx_obj1 = NULL; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 368 | struct intel_ringbuffer *ringbuf1 = NULL; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 369 | |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 370 | BUG_ON(!ctx_obj0); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 371 | WARN_ON(!i915_gem_obj_is_pinned(ctx_obj0)); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 372 | WARN_ON(!i915_gem_obj_is_pinned(ringbuf0->obj)); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 373 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 374 | execlists_update_context(ctx_obj0, ringbuf0->obj, to0->ppgtt, tail0); |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 375 | |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 376 | if (to1) { |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 377 | ringbuf1 = to1->engine[ring->id].ringbuf; |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 378 | ctx_obj1 = to1->engine[ring->id].state; |
| 379 | BUG_ON(!ctx_obj1); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 380 | WARN_ON(!i915_gem_obj_is_pinned(ctx_obj1)); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 381 | WARN_ON(!i915_gem_obj_is_pinned(ringbuf1->obj)); |
Oscar Mateo | ae1250b | 2014-07-24 17:04:37 +0100 | [diff] [blame] | 382 | |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 383 | execlists_update_context(ctx_obj1, ringbuf1->obj, to1->ppgtt, tail1); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | execlists_elsp_write(ring, ctx_obj0, ctx_obj1); |
Ben Widawsky | 84b790f | 2014-07-24 17:04:36 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 389 | static void execlists_context_unqueue(struct intel_engine_cs *ring) |
| 390 | { |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 391 | struct drm_i915_gem_request *req0 = NULL, *req1 = NULL; |
| 392 | struct drm_i915_gem_request *cursor = NULL, *tmp = NULL; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 393 | |
| 394 | assert_spin_locked(&ring->execlist_lock); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 395 | |
Peter Antoine | 779949f | 2015-05-11 16:03:27 +0100 | [diff] [blame] | 396 | /* |
| 397 | * If irqs are not active generate a warning as batches that finish |
| 398 | * without the irqs may get lost and a GPU Hang may occur. |
| 399 | */ |
| 400 | WARN_ON(!intel_irqs_enabled(ring->dev->dev_private)); |
| 401 | |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 402 | if (list_empty(&ring->execlist_queue)) |
| 403 | return; |
| 404 | |
| 405 | /* Try to read in pairs */ |
| 406 | list_for_each_entry_safe(cursor, tmp, &ring->execlist_queue, |
| 407 | execlist_link) { |
| 408 | if (!req0) { |
| 409 | req0 = cursor; |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 410 | } else if (req0->ctx == cursor->ctx) { |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 411 | /* Same ctx: ignore first request, as second request |
| 412 | * will update tail past first request's workload */ |
Oscar Mateo | e1fee72 | 2014-07-24 17:04:40 +0100 | [diff] [blame] | 413 | cursor->elsp_submitted = req0->elsp_submitted; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 414 | list_del(&req0->execlist_link); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 415 | list_add_tail(&req0->execlist_link, |
| 416 | &ring->execlist_retired_req_list); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 417 | req0 = cursor; |
| 418 | } else { |
| 419 | req1 = cursor; |
| 420 | break; |
| 421 | } |
| 422 | } |
| 423 | |
Michel Thierry | 53292cd | 2015-04-15 18:11:33 +0100 | [diff] [blame] | 424 | if (IS_GEN8(ring->dev) || IS_GEN9(ring->dev)) { |
| 425 | /* |
| 426 | * WaIdleLiteRestore: make sure we never cause a lite |
| 427 | * restore with HEAD==TAIL |
| 428 | */ |
Michel Thierry | d63f820 | 2015-04-27 12:31:44 +0100 | [diff] [blame] | 429 | if (req0->elsp_submitted) { |
Michel Thierry | 53292cd | 2015-04-15 18:11:33 +0100 | [diff] [blame] | 430 | /* |
| 431 | * Apply the wa NOOPS to prevent ring:HEAD == req:TAIL |
| 432 | * as we resubmit the request. See gen8_emit_request() |
| 433 | * for where we prepare the padding after the end of the |
| 434 | * request. |
| 435 | */ |
| 436 | struct intel_ringbuffer *ringbuf; |
| 437 | |
| 438 | ringbuf = req0->ctx->engine[ring->id].ringbuf; |
| 439 | req0->tail += 8; |
| 440 | req0->tail &= ringbuf->size - 1; |
| 441 | } |
| 442 | } |
| 443 | |
Oscar Mateo | e1fee72 | 2014-07-24 17:04:40 +0100 | [diff] [blame] | 444 | WARN_ON(req1 && req1->elsp_submitted); |
| 445 | |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 446 | execlists_submit_contexts(ring, req0->ctx, req0->tail, |
| 447 | req1 ? req1->ctx : NULL, |
| 448 | req1 ? req1->tail : 0); |
Oscar Mateo | e1fee72 | 2014-07-24 17:04:40 +0100 | [diff] [blame] | 449 | |
| 450 | req0->elsp_submitted++; |
| 451 | if (req1) |
| 452 | req1->elsp_submitted++; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 453 | } |
| 454 | |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 455 | static bool execlists_check_remove_request(struct intel_engine_cs *ring, |
| 456 | u32 request_id) |
| 457 | { |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 458 | struct drm_i915_gem_request *head_req; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 459 | |
| 460 | assert_spin_locked(&ring->execlist_lock); |
| 461 | |
| 462 | head_req = list_first_entry_or_null(&ring->execlist_queue, |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 463 | struct drm_i915_gem_request, |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 464 | execlist_link); |
| 465 | |
| 466 | if (head_req != NULL) { |
| 467 | struct drm_i915_gem_object *ctx_obj = |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 468 | head_req->ctx->engine[ring->id].state; |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 469 | if (intel_execlists_ctx_id(ctx_obj) == request_id) { |
Oscar Mateo | e1fee72 | 2014-07-24 17:04:40 +0100 | [diff] [blame] | 470 | WARN(head_req->elsp_submitted == 0, |
| 471 | "Never submitted head request\n"); |
| 472 | |
| 473 | if (--head_req->elsp_submitted <= 0) { |
| 474 | list_del(&head_req->execlist_link); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 475 | list_add_tail(&head_req->execlist_link, |
| 476 | &ring->execlist_retired_req_list); |
Oscar Mateo | e1fee72 | 2014-07-24 17:04:40 +0100 | [diff] [blame] | 477 | return true; |
| 478 | } |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | |
| 482 | return false; |
| 483 | } |
| 484 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 485 | /** |
Daniel Vetter | 3f7531c | 2014-12-10 17:41:43 +0100 | [diff] [blame] | 486 | * intel_lrc_irq_handler() - handle Context Switch interrupts |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 487 | * @ring: Engine Command Streamer to handle. |
| 488 | * |
| 489 | * Check the unread Context Status Buffers and manage the submission of new |
| 490 | * contexts to the ELSP accordingly. |
| 491 | */ |
Daniel Vetter | 3f7531c | 2014-12-10 17:41:43 +0100 | [diff] [blame] | 492 | void intel_lrc_irq_handler(struct intel_engine_cs *ring) |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 493 | { |
| 494 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
| 495 | u32 status_pointer; |
| 496 | u8 read_pointer; |
| 497 | u8 write_pointer; |
| 498 | u32 status; |
| 499 | u32 status_id; |
| 500 | u32 submit_contexts = 0; |
| 501 | |
| 502 | status_pointer = I915_READ(RING_CONTEXT_STATUS_PTR(ring)); |
| 503 | |
| 504 | read_pointer = ring->next_context_status_buffer; |
| 505 | write_pointer = status_pointer & 0x07; |
| 506 | if (read_pointer > write_pointer) |
| 507 | write_pointer += 6; |
| 508 | |
| 509 | spin_lock(&ring->execlist_lock); |
| 510 | |
| 511 | while (read_pointer < write_pointer) { |
| 512 | read_pointer++; |
| 513 | status = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + |
| 514 | (read_pointer % 6) * 8); |
| 515 | status_id = I915_READ(RING_CONTEXT_STATUS_BUF(ring) + |
| 516 | (read_pointer % 6) * 8 + 4); |
| 517 | |
Oscar Mateo | e1fee72 | 2014-07-24 17:04:40 +0100 | [diff] [blame] | 518 | if (status & GEN8_CTX_STATUS_PREEMPTED) { |
| 519 | if (status & GEN8_CTX_STATUS_LITE_RESTORE) { |
| 520 | if (execlists_check_remove_request(ring, status_id)) |
| 521 | WARN(1, "Lite Restored request removed from queue\n"); |
| 522 | } else |
| 523 | WARN(1, "Preemption without Lite Restore\n"); |
| 524 | } |
| 525 | |
| 526 | if ((status & GEN8_CTX_STATUS_ACTIVE_IDLE) || |
| 527 | (status & GEN8_CTX_STATUS_ELEMENT_SWITCH)) { |
Thomas Daniel | e981e7b | 2014-07-24 17:04:39 +0100 | [diff] [blame] | 528 | if (execlists_check_remove_request(ring, status_id)) |
| 529 | submit_contexts++; |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (submit_contexts != 0) |
| 534 | execlists_context_unqueue(ring); |
| 535 | |
| 536 | spin_unlock(&ring->execlist_lock); |
| 537 | |
| 538 | WARN(submit_contexts > 2, "More than two context complete events?\n"); |
| 539 | ring->next_context_status_buffer = write_pointer % 6; |
| 540 | |
| 541 | I915_WRITE(RING_CONTEXT_STATUS_PTR(ring), |
| 542 | ((u32)ring->next_context_status_buffer & 0x07) << 8); |
| 543 | } |
| 544 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 545 | static int execlists_context_queue(struct drm_i915_gem_request *request) |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 546 | { |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 547 | struct intel_engine_cs *ring = request->ring; |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 548 | struct drm_i915_gem_request *cursor; |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 549 | int num_elements = 0; |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 550 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 551 | if (request->ctx != ring->default_context) |
| 552 | intel_lr_context_pin(ring, request->ctx); |
John Harrison | 9bb1af4 | 2015-05-29 17:44:13 +0100 | [diff] [blame] | 553 | |
| 554 | i915_gem_request_reference(request); |
| 555 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 556 | request->tail = request->ringbuf->tail; |
Nick Hoath | 2d12955 | 2015-01-15 13:10:36 +0000 | [diff] [blame] | 557 | |
Chris Wilson | b5eba37 | 2015-04-07 16:20:48 +0100 | [diff] [blame] | 558 | spin_lock_irq(&ring->execlist_lock); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 559 | |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 560 | list_for_each_entry(cursor, &ring->execlist_queue, execlist_link) |
| 561 | if (++num_elements > 2) |
| 562 | break; |
| 563 | |
| 564 | if (num_elements > 2) { |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 565 | struct drm_i915_gem_request *tail_req; |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 566 | |
| 567 | tail_req = list_last_entry(&ring->execlist_queue, |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 568 | struct drm_i915_gem_request, |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 569 | execlist_link); |
| 570 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 571 | if (request->ctx == tail_req->ctx) { |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 572 | WARN(tail_req->elsp_submitted != 0, |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 573 | "More than 2 already-submitted reqs queued\n"); |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 574 | list_del(&tail_req->execlist_link); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 575 | list_add_tail(&tail_req->execlist_link, |
| 576 | &ring->execlist_retired_req_list); |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 580 | list_add_tail(&request->execlist_link, &ring->execlist_queue); |
Oscar Mateo | f1ad5a1 | 2014-07-24 17:04:41 +0100 | [diff] [blame] | 581 | if (num_elements == 0) |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 582 | execlists_context_unqueue(ring); |
| 583 | |
Chris Wilson | b5eba37 | 2015-04-07 16:20:48 +0100 | [diff] [blame] | 584 | spin_unlock_irq(&ring->execlist_lock); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 585 | |
| 586 | return 0; |
| 587 | } |
| 588 | |
John Harrison | 2f20055 | 2015-05-29 17:43:53 +0100 | [diff] [blame] | 589 | static int logical_ring_invalidate_all_caches(struct drm_i915_gem_request *req) |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 590 | { |
John Harrison | 2f20055 | 2015-05-29 17:43:53 +0100 | [diff] [blame] | 591 | struct intel_engine_cs *ring = req->ring; |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 592 | uint32_t flush_domains; |
| 593 | int ret; |
| 594 | |
| 595 | flush_domains = 0; |
| 596 | if (ring->gpu_caches_dirty) |
| 597 | flush_domains = I915_GEM_GPU_DOMAINS; |
| 598 | |
John Harrison | 7deb4d3 | 2015-05-29 17:43:59 +0100 | [diff] [blame] | 599 | ret = ring->emit_flush(req, I915_GEM_GPU_DOMAINS, flush_domains); |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 600 | if (ret) |
| 601 | return ret; |
| 602 | |
| 603 | ring->gpu_caches_dirty = false; |
| 604 | return 0; |
| 605 | } |
| 606 | |
John Harrison | 535fbe8 | 2015-05-29 17:43:32 +0100 | [diff] [blame] | 607 | static int execlists_move_to_gpu(struct drm_i915_gem_request *req, |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 608 | struct list_head *vmas) |
| 609 | { |
John Harrison | 535fbe8 | 2015-05-29 17:43:32 +0100 | [diff] [blame] | 610 | const unsigned other_rings = ~intel_ring_flag(req->ring); |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 611 | struct i915_vma *vma; |
| 612 | uint32_t flush_domains = 0; |
| 613 | bool flush_chipset = false; |
| 614 | int ret; |
| 615 | |
| 616 | list_for_each_entry(vma, vmas, exec_list) { |
| 617 | struct drm_i915_gem_object *obj = vma->obj; |
| 618 | |
Chris Wilson | 03ade51 | 2015-04-27 13:41:18 +0100 | [diff] [blame] | 619 | if (obj->active & other_rings) { |
John Harrison | 91af127 | 2015-06-18 13:14:56 +0100 | [diff] [blame] | 620 | ret = i915_gem_object_sync(obj, req->ring, &req); |
Chris Wilson | 03ade51 | 2015-04-27 13:41:18 +0100 | [diff] [blame] | 621 | if (ret) |
| 622 | return ret; |
| 623 | } |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 624 | |
| 625 | if (obj->base.write_domain & I915_GEM_DOMAIN_CPU) |
| 626 | flush_chipset |= i915_gem_clflush_object(obj, false); |
| 627 | |
| 628 | flush_domains |= obj->base.write_domain; |
| 629 | } |
| 630 | |
| 631 | if (flush_domains & I915_GEM_DOMAIN_GTT) |
| 632 | wmb(); |
| 633 | |
| 634 | /* Unconditionally invalidate gpu caches and ensure that we do flush |
| 635 | * any residual writes from the previous batch. |
| 636 | */ |
John Harrison | 2f20055 | 2015-05-29 17:43:53 +0100 | [diff] [blame] | 637 | return logical_ring_invalidate_all_caches(req); |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 638 | } |
| 639 | |
John Harrison | 40e895c | 2015-05-29 17:43:26 +0100 | [diff] [blame] | 640 | int intel_logical_ring_alloc_request_extras(struct drm_i915_gem_request *request) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 641 | { |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 642 | int ret; |
| 643 | |
John Harrison | 40e895c | 2015-05-29 17:43:26 +0100 | [diff] [blame] | 644 | if (request->ctx != request->ring->default_context) { |
| 645 | ret = intel_lr_context_pin(request->ring, request->ctx); |
John Harrison | 6689cb2 | 2015-03-19 12:30:08 +0000 | [diff] [blame] | 646 | if (ret) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 647 | return ret; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 648 | } |
| 649 | |
John Harrison | 40e895c | 2015-05-29 17:43:26 +0100 | [diff] [blame] | 650 | request->ringbuf = request->ctx->engine[request->ring->id].ringbuf; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 651 | |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 652 | return 0; |
| 653 | } |
| 654 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 655 | static int logical_ring_wait_for_space(struct drm_i915_gem_request *req, |
Chris Wilson | 595e1ee | 2015-04-07 16:20:51 +0100 | [diff] [blame] | 656 | int bytes) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 657 | { |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 658 | struct intel_ringbuffer *ringbuf = req->ringbuf; |
| 659 | struct intel_engine_cs *ring = req->ring; |
| 660 | struct drm_i915_gem_request *target; |
Chris Wilson | b471618 | 2015-04-27 13:41:17 +0100 | [diff] [blame] | 661 | unsigned space; |
| 662 | int ret; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 663 | |
| 664 | if (intel_ring_space(ringbuf) >= bytes) |
| 665 | return 0; |
| 666 | |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 667 | /* The whole point of reserving space is to not wait! */ |
| 668 | WARN_ON(ringbuf->reserved_in_use); |
| 669 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 670 | list_for_each_entry(target, &ring->request_list, list) { |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 671 | /* |
| 672 | * The request queue is per-engine, so can contain requests |
| 673 | * from multiple ringbuffers. Here, we must ignore any that |
| 674 | * aren't from the ringbuffer we're considering. |
| 675 | */ |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 676 | if (target->ringbuf != ringbuf) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 677 | continue; |
| 678 | |
| 679 | /* Would completion of this request free enough space? */ |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 680 | space = __intel_ring_space(target->postfix, ringbuf->tail, |
Chris Wilson | b471618 | 2015-04-27 13:41:17 +0100 | [diff] [blame] | 681 | ringbuf->size); |
| 682 | if (space >= bytes) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 683 | break; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 684 | } |
| 685 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 686 | if (WARN_ON(&target->list == &ring->request_list)) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 687 | return -ENOSPC; |
| 688 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 689 | ret = i915_wait_request(target); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 690 | if (ret) |
| 691 | return ret; |
| 692 | |
Chris Wilson | b471618 | 2015-04-27 13:41:17 +0100 | [diff] [blame] | 693 | ringbuf->space = space; |
| 694 | return 0; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 695 | } |
| 696 | |
| 697 | /* |
| 698 | * intel_logical_ring_advance_and_submit() - advance the tail and submit the workload |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 699 | * @request: Request to advance the logical ringbuffer of. |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 700 | * |
| 701 | * The tail is updated in our logical ringbuffer struct, not in the actual context. What |
| 702 | * really happens during submission is that the context and current tail will be placed |
| 703 | * on a queue waiting for the ELSP to be ready to accept a new context submission. At that |
| 704 | * point, the tail *inside* the context is updated and the ELSP written to. |
| 705 | */ |
| 706 | static void |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 707 | intel_logical_ring_advance_and_submit(struct drm_i915_gem_request *request) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 708 | { |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 709 | struct intel_engine_cs *ring = request->ring; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 710 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 711 | intel_logical_ring_advance(request->ringbuf); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 712 | |
| 713 | if (intel_ring_stopped(ring)) |
| 714 | return; |
| 715 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 716 | execlists_context_queue(request); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 717 | } |
| 718 | |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 719 | static void __wrap_ring_buffer(struct intel_ringbuffer *ringbuf) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 720 | { |
| 721 | uint32_t __iomem *virt; |
| 722 | int rem = ringbuf->size - ringbuf->tail; |
| 723 | |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 724 | virt = ringbuf->virtual_start + ringbuf->tail; |
| 725 | rem /= 4; |
| 726 | while (rem--) |
| 727 | iowrite32(MI_NOOP, virt++); |
| 728 | |
| 729 | ringbuf->tail = 0; |
| 730 | intel_ring_update_space(ringbuf); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 731 | } |
| 732 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 733 | static int logical_ring_prepare(struct drm_i915_gem_request *req, int bytes) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 734 | { |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 735 | struct intel_ringbuffer *ringbuf = req->ringbuf; |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 736 | int remain_usable = ringbuf->effective_size - ringbuf->tail; |
| 737 | int remain_actual = ringbuf->size - ringbuf->tail; |
| 738 | int ret, total_bytes, wait_bytes = 0; |
| 739 | bool need_wrap = false; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 740 | |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 741 | if (ringbuf->reserved_in_use) |
| 742 | total_bytes = bytes; |
| 743 | else |
| 744 | total_bytes = bytes + ringbuf->reserved_size; |
John Harrison | 29b1b41 | 2015-06-18 13:10:09 +0100 | [diff] [blame] | 745 | |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 746 | if (unlikely(bytes > remain_usable)) { |
| 747 | /* |
| 748 | * Not enough space for the basic request. So need to flush |
| 749 | * out the remainder and then wait for base + reserved. |
| 750 | */ |
| 751 | wait_bytes = remain_actual + total_bytes; |
| 752 | need_wrap = true; |
| 753 | } else { |
| 754 | if (unlikely(total_bytes > remain_usable)) { |
| 755 | /* |
| 756 | * The base request will fit but the reserved space |
| 757 | * falls off the end. So only need to to wait for the |
| 758 | * reserved size after flushing out the remainder. |
| 759 | */ |
| 760 | wait_bytes = remain_actual + ringbuf->reserved_size; |
| 761 | need_wrap = true; |
| 762 | } else if (total_bytes > ringbuf->space) { |
| 763 | /* No wrapping required, just waiting. */ |
| 764 | wait_bytes = total_bytes; |
John Harrison | 29b1b41 | 2015-06-18 13:10:09 +0100 | [diff] [blame] | 765 | } |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 766 | } |
| 767 | |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 768 | if (wait_bytes) { |
| 769 | ret = logical_ring_wait_for_space(req, wait_bytes); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 770 | if (unlikely(ret)) |
| 771 | return ret; |
John Harrison | 79bbcc2 | 2015-06-30 12:40:55 +0100 | [diff] [blame] | 772 | |
| 773 | if (need_wrap) |
| 774 | __wrap_ring_buffer(ringbuf); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * intel_logical_ring_begin() - prepare the logical ringbuffer to accept some commands |
| 782 | * |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 783 | * @request: The request to start some new work for |
Arun Siluvery | 4d78c8d | 2015-06-23 15:50:43 +0100 | [diff] [blame] | 784 | * @ctx: Logical ring context whose ringbuffer is being prepared. |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 785 | * @num_dwords: number of DWORDs that we plan to write to the ringbuffer. |
| 786 | * |
| 787 | * The ringbuffer might not be ready to accept the commands right away (maybe it needs to |
| 788 | * be wrapped, or wait a bit for the tail to be updated). This function takes care of that |
| 789 | * and also preallocates a request (every workload submission is still mediated through |
| 790 | * requests, same as it did with legacy ringbuffer submission). |
| 791 | * |
| 792 | * Return: non-zero if the ringbuffer is not ready to be written to. |
| 793 | */ |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 794 | static int intel_logical_ring_begin(struct drm_i915_gem_request *req, |
| 795 | int num_dwords) |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 796 | { |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 797 | struct drm_i915_private *dev_priv; |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 798 | int ret; |
| 799 | |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 800 | WARN_ON(req == NULL); |
| 801 | dev_priv = req->ring->dev->dev_private; |
| 802 | |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 803 | ret = i915_gem_check_wedge(&dev_priv->gpu_error, |
| 804 | dev_priv->mm.interruptible); |
| 805 | if (ret) |
| 806 | return ret; |
| 807 | |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 808 | ret = logical_ring_prepare(req, num_dwords * sizeof(uint32_t)); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 809 | if (ret) |
| 810 | return ret; |
| 811 | |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 812 | req->ringbuf->space -= num_dwords * sizeof(uint32_t); |
John Harrison | bc0dce3 | 2015-03-19 12:30:07 +0000 | [diff] [blame] | 813 | return 0; |
| 814 | } |
| 815 | |
John Harrison | ccd98fe | 2015-05-29 17:44:09 +0100 | [diff] [blame] | 816 | int intel_logical_ring_reserve_space(struct drm_i915_gem_request *request) |
| 817 | { |
| 818 | /* |
| 819 | * The first call merely notes the reserve request and is common for |
| 820 | * all back ends. The subsequent localised _begin() call actually |
| 821 | * ensures that the reservation is available. Without the begin, if |
| 822 | * the request creator immediately submitted the request without |
| 823 | * adding any commands to it then there might not actually be |
| 824 | * sufficient room for the submission commands. |
| 825 | */ |
| 826 | intel_ring_reserved_space_reserve(request->ringbuf, MIN_SPACE_FOR_ADD_REQUEST); |
| 827 | |
| 828 | return intel_logical_ring_begin(request, 0); |
| 829 | } |
| 830 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 831 | /** |
| 832 | * execlists_submission() - submit a batchbuffer for execution, Execlists style |
| 833 | * @dev: DRM device. |
| 834 | * @file: DRM file. |
| 835 | * @ring: Engine Command Streamer to submit to. |
| 836 | * @ctx: Context to employ for this submission. |
| 837 | * @args: execbuffer call arguments. |
| 838 | * @vmas: list of vmas. |
| 839 | * @batch_obj: the batchbuffer to submit. |
| 840 | * @exec_start: batchbuffer start virtual address pointer. |
John Harrison | 8e004ef | 2015-02-13 11:48:10 +0000 | [diff] [blame] | 841 | * @dispatch_flags: translated execbuffer call flags. |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 842 | * |
| 843 | * This is the evil twin version of i915_gem_ringbuffer_submission. It abstracts |
| 844 | * away the submission details of the execbuffer ioctl call. |
| 845 | * |
| 846 | * Return: non-zero if the submission fails. |
| 847 | */ |
John Harrison | 5f19e2b | 2015-05-29 17:43:27 +0100 | [diff] [blame] | 848 | int intel_execlists_submission(struct i915_execbuffer_params *params, |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 849 | struct drm_i915_gem_execbuffer2 *args, |
John Harrison | 5f19e2b | 2015-05-29 17:43:27 +0100 | [diff] [blame] | 850 | struct list_head *vmas) |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 851 | { |
John Harrison | 5f19e2b | 2015-05-29 17:43:27 +0100 | [diff] [blame] | 852 | struct drm_device *dev = params->dev; |
| 853 | struct intel_engine_cs *ring = params->ring; |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 854 | struct drm_i915_private *dev_priv = dev->dev_private; |
John Harrison | 5f19e2b | 2015-05-29 17:43:27 +0100 | [diff] [blame] | 855 | struct intel_ringbuffer *ringbuf = params->ctx->engine[ring->id].ringbuf; |
| 856 | u64 exec_start; |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 857 | int instp_mode; |
| 858 | u32 instp_mask; |
| 859 | int ret; |
| 860 | |
| 861 | instp_mode = args->flags & I915_EXEC_CONSTANTS_MASK; |
| 862 | instp_mask = I915_EXEC_CONSTANTS_MASK; |
| 863 | switch (instp_mode) { |
| 864 | case I915_EXEC_CONSTANTS_REL_GENERAL: |
| 865 | case I915_EXEC_CONSTANTS_ABSOLUTE: |
| 866 | case I915_EXEC_CONSTANTS_REL_SURFACE: |
| 867 | if (instp_mode != 0 && ring != &dev_priv->ring[RCS]) { |
| 868 | DRM_DEBUG("non-0 rel constants mode on non-RCS\n"); |
| 869 | return -EINVAL; |
| 870 | } |
| 871 | |
| 872 | if (instp_mode != dev_priv->relative_constants_mode) { |
| 873 | if (instp_mode == I915_EXEC_CONSTANTS_REL_SURFACE) { |
| 874 | DRM_DEBUG("rel surface constants mode invalid on gen5+\n"); |
| 875 | return -EINVAL; |
| 876 | } |
| 877 | |
| 878 | /* The HW changed the meaning on this bit on gen6 */ |
| 879 | instp_mask &= ~I915_EXEC_CONSTANTS_REL_SURFACE; |
| 880 | } |
| 881 | break; |
| 882 | default: |
| 883 | DRM_DEBUG("execbuf with unknown constants: %d\n", instp_mode); |
| 884 | return -EINVAL; |
| 885 | } |
| 886 | |
| 887 | if (args->num_cliprects != 0) { |
| 888 | DRM_DEBUG("clip rectangles are only valid on pre-gen5\n"); |
| 889 | return -EINVAL; |
| 890 | } else { |
| 891 | if (args->DR4 == 0xffffffff) { |
| 892 | DRM_DEBUG("UXA submitting garbage DR4, fixing up\n"); |
| 893 | args->DR4 = 0; |
| 894 | } |
| 895 | |
| 896 | if (args->DR1 || args->DR4 || args->cliprects_ptr) { |
| 897 | DRM_DEBUG("0 cliprects but dirt in cliprects fields\n"); |
| 898 | return -EINVAL; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | if (args->flags & I915_EXEC_GEN7_SOL_RESET) { |
| 903 | DRM_DEBUG("sol reset is gen7 only\n"); |
| 904 | return -EINVAL; |
| 905 | } |
| 906 | |
John Harrison | 535fbe8 | 2015-05-29 17:43:32 +0100 | [diff] [blame] | 907 | ret = execlists_move_to_gpu(params->request, vmas); |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 908 | if (ret) |
| 909 | return ret; |
| 910 | |
| 911 | if (ring == &dev_priv->ring[RCS] && |
| 912 | instp_mode != dev_priv->relative_constants_mode) { |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 913 | ret = intel_logical_ring_begin(params->request, 4); |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 914 | if (ret) |
| 915 | return ret; |
| 916 | |
| 917 | intel_logical_ring_emit(ringbuf, MI_NOOP); |
| 918 | intel_logical_ring_emit(ringbuf, MI_LOAD_REGISTER_IMM(1)); |
| 919 | intel_logical_ring_emit(ringbuf, INSTPM); |
| 920 | intel_logical_ring_emit(ringbuf, instp_mask << 16 | instp_mode); |
| 921 | intel_logical_ring_advance(ringbuf); |
| 922 | |
| 923 | dev_priv->relative_constants_mode = instp_mode; |
| 924 | } |
| 925 | |
John Harrison | 5f19e2b | 2015-05-29 17:43:27 +0100 | [diff] [blame] | 926 | exec_start = params->batch_obj_vm_offset + |
| 927 | args->batch_start_offset; |
| 928 | |
John Harrison | be795fc | 2015-05-29 17:44:03 +0100 | [diff] [blame] | 929 | ret = ring->emit_bb_start(params->request, exec_start, params->dispatch_flags); |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 930 | if (ret) |
| 931 | return ret; |
| 932 | |
John Harrison | 95c2416 | 2015-05-29 17:43:31 +0100 | [diff] [blame] | 933 | trace_i915_gem_ring_dispatch(params->request, params->dispatch_flags); |
John Harrison | 5e4be7b | 2015-02-13 11:48:11 +0000 | [diff] [blame] | 934 | |
John Harrison | 8a8edb5 | 2015-05-29 17:43:33 +0100 | [diff] [blame] | 935 | i915_gem_execbuffer_move_to_active(vmas, params->request); |
John Harrison | adeca76 | 2015-05-29 17:43:28 +0100 | [diff] [blame] | 936 | i915_gem_execbuffer_retire_commands(params); |
Oscar Mateo | ba8b7cc | 2014-07-24 17:04:33 +0100 | [diff] [blame] | 937 | |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 938 | return 0; |
| 939 | } |
| 940 | |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 941 | void intel_execlists_retire_requests(struct intel_engine_cs *ring) |
| 942 | { |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 943 | struct drm_i915_gem_request *req, *tmp; |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 944 | struct list_head retired_list; |
| 945 | |
| 946 | WARN_ON(!mutex_is_locked(&ring->dev->struct_mutex)); |
| 947 | if (list_empty(&ring->execlist_retired_req_list)) |
| 948 | return; |
| 949 | |
| 950 | INIT_LIST_HEAD(&retired_list); |
Chris Wilson | b5eba37 | 2015-04-07 16:20:48 +0100 | [diff] [blame] | 951 | spin_lock_irq(&ring->execlist_lock); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 952 | list_replace_init(&ring->execlist_retired_req_list, &retired_list); |
Chris Wilson | b5eba37 | 2015-04-07 16:20:48 +0100 | [diff] [blame] | 953 | spin_unlock_irq(&ring->execlist_lock); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 954 | |
| 955 | list_for_each_entry_safe(req, tmp, &retired_list, execlist_link) { |
Nick Hoath | 6d3d827 | 2015-01-15 13:10:39 +0000 | [diff] [blame] | 956 | struct intel_context *ctx = req->ctx; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 957 | struct drm_i915_gem_object *ctx_obj = |
| 958 | ctx->engine[ring->id].state; |
| 959 | |
| 960 | if (ctx_obj && (ctx != ring->default_context)) |
| 961 | intel_lr_context_unpin(ring, ctx); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 962 | list_del(&req->execlist_link); |
Nick Hoath | f821079 | 2015-01-29 16:55:07 +0000 | [diff] [blame] | 963 | i915_gem_request_unreference(req); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 964 | } |
| 965 | } |
| 966 | |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 967 | void intel_logical_ring_stop(struct intel_engine_cs *ring) |
| 968 | { |
Oscar Mateo | 9832b9d | 2014-07-24 17:04:30 +0100 | [diff] [blame] | 969 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
| 970 | int ret; |
| 971 | |
| 972 | if (!intel_ring_initialized(ring)) |
| 973 | return; |
| 974 | |
| 975 | ret = intel_ring_idle(ring); |
| 976 | if (ret && !i915_reset_in_progress(&to_i915(ring->dev)->gpu_error)) |
| 977 | DRM_ERROR("failed to quiesce %s whilst cleaning up: %d\n", |
| 978 | ring->name, ret); |
| 979 | |
| 980 | /* TODO: Is this correct with Execlists enabled? */ |
| 981 | I915_WRITE_MODE(ring, _MASKED_BIT_ENABLE(STOP_RING)); |
| 982 | if (wait_for_atomic((I915_READ_MODE(ring) & MODE_IDLE) != 0, 1000)) { |
| 983 | DRM_ERROR("%s :timed out trying to stop ring\n", ring->name); |
| 984 | return; |
| 985 | } |
| 986 | I915_WRITE_MODE(ring, _MASKED_BIT_DISABLE(STOP_RING)); |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 987 | } |
| 988 | |
John Harrison | 4866d72 | 2015-05-29 17:43:55 +0100 | [diff] [blame] | 989 | int logical_ring_flush_all_caches(struct drm_i915_gem_request *req) |
Oscar Mateo | 48e29f5 | 2014-07-24 17:04:29 +0100 | [diff] [blame] | 990 | { |
John Harrison | 4866d72 | 2015-05-29 17:43:55 +0100 | [diff] [blame] | 991 | struct intel_engine_cs *ring = req->ring; |
Oscar Mateo | 48e29f5 | 2014-07-24 17:04:29 +0100 | [diff] [blame] | 992 | int ret; |
| 993 | |
| 994 | if (!ring->gpu_caches_dirty) |
| 995 | return 0; |
| 996 | |
John Harrison | 7deb4d3 | 2015-05-29 17:43:59 +0100 | [diff] [blame] | 997 | ret = ring->emit_flush(req, 0, I915_GEM_GPU_DOMAINS); |
Oscar Mateo | 48e29f5 | 2014-07-24 17:04:29 +0100 | [diff] [blame] | 998 | if (ret) |
| 999 | return ret; |
| 1000 | |
| 1001 | ring->gpu_caches_dirty = false; |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1005 | static int intel_lr_context_pin(struct intel_engine_cs *ring, |
| 1006 | struct intel_context *ctx) |
| 1007 | { |
| 1008 | struct drm_i915_gem_object *ctx_obj = ctx->engine[ring->id].state; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1009 | struct intel_ringbuffer *ringbuf = ctx->engine[ring->id].ringbuf; |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1010 | int ret = 0; |
| 1011 | |
| 1012 | WARN_ON(!mutex_is_locked(&ring->dev->struct_mutex)); |
Mika Kuoppala | a7cbede | 2015-01-13 11:32:25 +0200 | [diff] [blame] | 1013 | if (ctx->engine[ring->id].pin_count++ == 0) { |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1014 | ret = i915_gem_obj_ggtt_pin(ctx_obj, |
| 1015 | GEN8_LR_CONTEXT_ALIGN, 0); |
| 1016 | if (ret) |
Mika Kuoppala | a7cbede | 2015-01-13 11:32:25 +0200 | [diff] [blame] | 1017 | goto reset_pin_count; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1018 | |
| 1019 | ret = intel_pin_and_map_ringbuffer_obj(ring->dev, ringbuf); |
| 1020 | if (ret) |
| 1021 | goto unpin_ctx_obj; |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
| 1024 | return ret; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1025 | |
| 1026 | unpin_ctx_obj: |
| 1027 | i915_gem_object_ggtt_unpin(ctx_obj); |
Mika Kuoppala | a7cbede | 2015-01-13 11:32:25 +0200 | [diff] [blame] | 1028 | reset_pin_count: |
| 1029 | ctx->engine[ring->id].pin_count = 0; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1030 | |
| 1031 | return ret; |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | void intel_lr_context_unpin(struct intel_engine_cs *ring, |
| 1035 | struct intel_context *ctx) |
| 1036 | { |
| 1037 | struct drm_i915_gem_object *ctx_obj = ctx->engine[ring->id].state; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1038 | struct intel_ringbuffer *ringbuf = ctx->engine[ring->id].ringbuf; |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1039 | |
| 1040 | if (ctx_obj) { |
| 1041 | WARN_ON(!mutex_is_locked(&ring->dev->struct_mutex)); |
Mika Kuoppala | a7cbede | 2015-01-13 11:32:25 +0200 | [diff] [blame] | 1042 | if (--ctx->engine[ring->id].pin_count == 0) { |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1043 | intel_unpin_ringbuffer_obj(ringbuf); |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1044 | i915_gem_object_ggtt_unpin(ctx_obj); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 1045 | } |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 1046 | } |
| 1047 | } |
| 1048 | |
John Harrison | e2be4fa | 2015-05-29 17:43:54 +0100 | [diff] [blame] | 1049 | static int intel_logical_ring_workarounds_emit(struct drm_i915_gem_request *req) |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 1050 | { |
| 1051 | int ret, i; |
John Harrison | e2be4fa | 2015-05-29 17:43:54 +0100 | [diff] [blame] | 1052 | struct intel_engine_cs *ring = req->ring; |
| 1053 | struct intel_ringbuffer *ringbuf = req->ringbuf; |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 1054 | struct drm_device *dev = ring->dev; |
| 1055 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1056 | struct i915_workarounds *w = &dev_priv->workarounds; |
| 1057 | |
Michel Thierry | e6c1abb | 2014-11-26 14:21:02 +0000 | [diff] [blame] | 1058 | if (WARN_ON_ONCE(w->count == 0)) |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 1059 | return 0; |
| 1060 | |
| 1061 | ring->gpu_caches_dirty = true; |
John Harrison | 4866d72 | 2015-05-29 17:43:55 +0100 | [diff] [blame] | 1062 | ret = logical_ring_flush_all_caches(req); |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 1063 | if (ret) |
| 1064 | return ret; |
| 1065 | |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 1066 | ret = intel_logical_ring_begin(req, w->count * 2 + 2); |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 1067 | if (ret) |
| 1068 | return ret; |
| 1069 | |
| 1070 | intel_logical_ring_emit(ringbuf, MI_LOAD_REGISTER_IMM(w->count)); |
| 1071 | for (i = 0; i < w->count; i++) { |
| 1072 | intel_logical_ring_emit(ringbuf, w->reg[i].addr); |
| 1073 | intel_logical_ring_emit(ringbuf, w->reg[i].value); |
| 1074 | } |
| 1075 | intel_logical_ring_emit(ringbuf, MI_NOOP); |
| 1076 | |
| 1077 | intel_logical_ring_advance(ringbuf); |
| 1078 | |
| 1079 | ring->gpu_caches_dirty = true; |
John Harrison | 4866d72 | 2015-05-29 17:43:55 +0100 | [diff] [blame] | 1080 | ret = logical_ring_flush_all_caches(req); |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 1081 | if (ret) |
| 1082 | return ret; |
| 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1087 | #define wa_ctx_emit(batch, cmd) \ |
| 1088 | do { \ |
| 1089 | if (WARN_ON(index >= (PAGE_SIZE / sizeof(uint32_t)))) { \ |
| 1090 | return -ENOSPC; \ |
| 1091 | } \ |
| 1092 | batch[index++] = (cmd); \ |
| 1093 | } while (0) |
| 1094 | |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame^] | 1095 | |
| 1096 | /* |
| 1097 | * In this WA we need to set GEN8_L3SQCREG4[21:21] and reset it after |
| 1098 | * PIPE_CONTROL instruction. This is required for the flush to happen correctly |
| 1099 | * but there is a slight complication as this is applied in WA batch where the |
| 1100 | * values are only initialized once so we cannot take register value at the |
| 1101 | * beginning and reuse it further; hence we save its value to memory, upload a |
| 1102 | * constant value with bit21 set and then we restore it back with the saved value. |
| 1103 | * To simplify the WA, a constant value is formed by using the default value |
| 1104 | * of this register. This shouldn't be a problem because we are only modifying |
| 1105 | * it for a short period and this batch in non-premptible. We can ofcourse |
| 1106 | * use additional instructions that read the actual value of the register |
| 1107 | * at that time and set our bit of interest but it makes the WA complicated. |
| 1108 | * |
| 1109 | * This WA is also required for Gen9 so extracting as a function avoids |
| 1110 | * code duplication. |
| 1111 | */ |
| 1112 | static inline int gen8_emit_flush_coherentl3_wa(struct intel_engine_cs *ring, |
| 1113 | uint32_t *const batch, |
| 1114 | uint32_t index) |
| 1115 | { |
| 1116 | uint32_t l3sqc4_flush = (0x40400000 | GEN8_LQSC_FLUSH_COHERENT_LINES); |
| 1117 | |
| 1118 | wa_ctx_emit(batch, (MI_STORE_REGISTER_MEM_GEN8(1) | |
| 1119 | MI_SRM_LRM_GLOBAL_GTT)); |
| 1120 | wa_ctx_emit(batch, GEN8_L3SQCREG4); |
| 1121 | wa_ctx_emit(batch, ring->scratch.gtt_offset + 256); |
| 1122 | wa_ctx_emit(batch, 0); |
| 1123 | |
| 1124 | wa_ctx_emit(batch, MI_LOAD_REGISTER_IMM(1)); |
| 1125 | wa_ctx_emit(batch, GEN8_L3SQCREG4); |
| 1126 | wa_ctx_emit(batch, l3sqc4_flush); |
| 1127 | |
| 1128 | wa_ctx_emit(batch, GFX_OP_PIPE_CONTROL(6)); |
| 1129 | wa_ctx_emit(batch, (PIPE_CONTROL_CS_STALL | |
| 1130 | PIPE_CONTROL_DC_FLUSH_ENABLE)); |
| 1131 | wa_ctx_emit(batch, 0); |
| 1132 | wa_ctx_emit(batch, 0); |
| 1133 | wa_ctx_emit(batch, 0); |
| 1134 | wa_ctx_emit(batch, 0); |
| 1135 | |
| 1136 | wa_ctx_emit(batch, (MI_LOAD_REGISTER_MEM_GEN8(1) | |
| 1137 | MI_SRM_LRM_GLOBAL_GTT)); |
| 1138 | wa_ctx_emit(batch, GEN8_L3SQCREG4); |
| 1139 | wa_ctx_emit(batch, ring->scratch.gtt_offset + 256); |
| 1140 | wa_ctx_emit(batch, 0); |
| 1141 | |
| 1142 | return index; |
| 1143 | } |
| 1144 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1145 | static inline uint32_t wa_ctx_start(struct i915_wa_ctx_bb *wa_ctx, |
| 1146 | uint32_t offset, |
| 1147 | uint32_t start_alignment) |
| 1148 | { |
| 1149 | return wa_ctx->offset = ALIGN(offset, start_alignment); |
| 1150 | } |
| 1151 | |
| 1152 | static inline int wa_ctx_end(struct i915_wa_ctx_bb *wa_ctx, |
| 1153 | uint32_t offset, |
| 1154 | uint32_t size_alignment) |
| 1155 | { |
| 1156 | wa_ctx->size = offset - wa_ctx->offset; |
| 1157 | |
| 1158 | WARN(wa_ctx->size % size_alignment, |
| 1159 | "wa_ctx_bb failed sanity checks: size %d is not aligned to %d\n", |
| 1160 | wa_ctx->size, size_alignment); |
| 1161 | return 0; |
| 1162 | } |
| 1163 | |
| 1164 | /** |
| 1165 | * gen8_init_indirectctx_bb() - initialize indirect ctx batch with WA |
| 1166 | * |
| 1167 | * @ring: only applicable for RCS |
| 1168 | * @wa_ctx: structure representing wa_ctx |
| 1169 | * offset: specifies start of the batch, should be cache-aligned. This is updated |
| 1170 | * with the offset value received as input. |
| 1171 | * size: size of the batch in DWORDS but HW expects in terms of cachelines |
| 1172 | * @batch: page in which WA are loaded |
| 1173 | * @offset: This field specifies the start of the batch, it should be |
| 1174 | * cache-aligned otherwise it is adjusted accordingly. |
| 1175 | * Typically we only have one indirect_ctx and per_ctx batch buffer which are |
| 1176 | * initialized at the beginning and shared across all contexts but this field |
| 1177 | * helps us to have multiple batches at different offsets and select them based |
| 1178 | * on a criteria. At the moment this batch always start at the beginning of the page |
| 1179 | * and at this point we don't have multiple wa_ctx batch buffers. |
| 1180 | * |
| 1181 | * The number of WA applied are not known at the beginning; we use this field |
| 1182 | * to return the no of DWORDS written. |
Arun Siluvery | 4d78c8d | 2015-06-23 15:50:43 +0100 | [diff] [blame] | 1183 | * |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1184 | * It is to be noted that this batch does not contain MI_BATCH_BUFFER_END |
| 1185 | * so it adds NOOPs as padding to make it cacheline aligned. |
| 1186 | * MI_BATCH_BUFFER_END will be added to perctx batch and both of them together |
| 1187 | * makes a complete batch buffer. |
| 1188 | * |
| 1189 | * Return: non-zero if we exceed the PAGE_SIZE limit. |
| 1190 | */ |
| 1191 | |
| 1192 | static int gen8_init_indirectctx_bb(struct intel_engine_cs *ring, |
| 1193 | struct i915_wa_ctx_bb *wa_ctx, |
| 1194 | uint32_t *const batch, |
| 1195 | uint32_t *offset) |
| 1196 | { |
Arun Siluvery | 0160f05 | 2015-06-23 15:46:57 +0100 | [diff] [blame] | 1197 | uint32_t scratch_addr; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1198 | uint32_t index = wa_ctx_start(wa_ctx, *offset, CACHELINE_DWORDS); |
| 1199 | |
Arun Siluvery | 7ad00d1 | 2015-06-19 18:37:12 +0100 | [diff] [blame] | 1200 | /* WaDisableCtxRestoreArbitration:bdw,chv */ |
| 1201 | wa_ctx_emit(batch, MI_ARB_ON_OFF | MI_ARB_DISABLE); |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1202 | |
Arun Siluvery | c82435b | 2015-06-19 18:37:13 +0100 | [diff] [blame] | 1203 | /* WaFlushCoherentL3CacheLinesAtContextSwitch:bdw */ |
| 1204 | if (IS_BROADWELL(ring->dev)) { |
Arun Siluvery | 9e00084 | 2015-07-03 14:27:31 +0100 | [diff] [blame^] | 1205 | index = gen8_emit_flush_coherentl3_wa(ring, batch, index); |
| 1206 | if (index < 0) |
| 1207 | return index; |
Arun Siluvery | c82435b | 2015-06-19 18:37:13 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Arun Siluvery | 0160f05 | 2015-06-23 15:46:57 +0100 | [diff] [blame] | 1210 | /* WaClearSlmSpaceAtContextSwitch:bdw,chv */ |
| 1211 | /* Actual scratch location is at 128 bytes offset */ |
| 1212 | scratch_addr = ring->scratch.gtt_offset + 2*CACHELINE_BYTES; |
| 1213 | |
| 1214 | wa_ctx_emit(batch, GFX_OP_PIPE_CONTROL(6)); |
| 1215 | wa_ctx_emit(batch, (PIPE_CONTROL_FLUSH_L3 | |
| 1216 | PIPE_CONTROL_GLOBAL_GTT_IVB | |
| 1217 | PIPE_CONTROL_CS_STALL | |
| 1218 | PIPE_CONTROL_QW_WRITE)); |
| 1219 | wa_ctx_emit(batch, scratch_addr); |
| 1220 | wa_ctx_emit(batch, 0); |
| 1221 | wa_ctx_emit(batch, 0); |
| 1222 | wa_ctx_emit(batch, 0); |
| 1223 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1224 | /* Pad to end of cacheline */ |
| 1225 | while (index % CACHELINE_DWORDS) |
| 1226 | wa_ctx_emit(batch, MI_NOOP); |
| 1227 | |
| 1228 | /* |
| 1229 | * MI_BATCH_BUFFER_END is not required in Indirect ctx BB because |
| 1230 | * execution depends on the length specified in terms of cache lines |
| 1231 | * in the register CTX_RCS_INDIRECT_CTX |
| 1232 | */ |
| 1233 | |
| 1234 | return wa_ctx_end(wa_ctx, *offset = index, CACHELINE_DWORDS); |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * gen8_init_perctx_bb() - initialize per ctx batch with WA |
| 1239 | * |
| 1240 | * @ring: only applicable for RCS |
| 1241 | * @wa_ctx: structure representing wa_ctx |
| 1242 | * offset: specifies start of the batch, should be cache-aligned. |
| 1243 | * size: size of the batch in DWORDS but HW expects in terms of cachelines |
Arun Siluvery | 4d78c8d | 2015-06-23 15:50:43 +0100 | [diff] [blame] | 1244 | * @batch: page in which WA are loaded |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1245 | * @offset: This field specifies the start of this batch. |
| 1246 | * This batch is started immediately after indirect_ctx batch. Since we ensure |
| 1247 | * that indirect_ctx ends on a cacheline this batch is aligned automatically. |
| 1248 | * |
| 1249 | * The number of DWORDS written are returned using this field. |
| 1250 | * |
| 1251 | * This batch is terminated with MI_BATCH_BUFFER_END and so we need not add padding |
| 1252 | * to align it with cacheline as padding after MI_BATCH_BUFFER_END is redundant. |
| 1253 | */ |
| 1254 | static int gen8_init_perctx_bb(struct intel_engine_cs *ring, |
| 1255 | struct i915_wa_ctx_bb *wa_ctx, |
| 1256 | uint32_t *const batch, |
| 1257 | uint32_t *offset) |
| 1258 | { |
| 1259 | uint32_t index = wa_ctx_start(wa_ctx, *offset, CACHELINE_DWORDS); |
| 1260 | |
Arun Siluvery | 7ad00d1 | 2015-06-19 18:37:12 +0100 | [diff] [blame] | 1261 | /* WaDisableCtxRestoreArbitration:bdw,chv */ |
| 1262 | wa_ctx_emit(batch, MI_ARB_ON_OFF | MI_ARB_ENABLE); |
| 1263 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1264 | wa_ctx_emit(batch, MI_BATCH_BUFFER_END); |
| 1265 | |
| 1266 | return wa_ctx_end(wa_ctx, *offset = index, 1); |
| 1267 | } |
| 1268 | |
| 1269 | static int lrc_setup_wa_ctx_obj(struct intel_engine_cs *ring, u32 size) |
| 1270 | { |
| 1271 | int ret; |
| 1272 | |
| 1273 | ring->wa_ctx.obj = i915_gem_alloc_object(ring->dev, PAGE_ALIGN(size)); |
| 1274 | if (!ring->wa_ctx.obj) { |
| 1275 | DRM_DEBUG_DRIVER("alloc LRC WA ctx backing obj failed.\n"); |
| 1276 | return -ENOMEM; |
| 1277 | } |
| 1278 | |
| 1279 | ret = i915_gem_obj_ggtt_pin(ring->wa_ctx.obj, PAGE_SIZE, 0); |
| 1280 | if (ret) { |
| 1281 | DRM_DEBUG_DRIVER("pin LRC WA ctx backing obj failed: %d\n", |
| 1282 | ret); |
| 1283 | drm_gem_object_unreference(&ring->wa_ctx.obj->base); |
| 1284 | return ret; |
| 1285 | } |
| 1286 | |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | static void lrc_destroy_wa_ctx_obj(struct intel_engine_cs *ring) |
| 1291 | { |
| 1292 | if (ring->wa_ctx.obj) { |
| 1293 | i915_gem_object_ggtt_unpin(ring->wa_ctx.obj); |
| 1294 | drm_gem_object_unreference(&ring->wa_ctx.obj->base); |
| 1295 | ring->wa_ctx.obj = NULL; |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | static int intel_init_workaround_bb(struct intel_engine_cs *ring) |
| 1300 | { |
| 1301 | int ret; |
| 1302 | uint32_t *batch; |
| 1303 | uint32_t offset; |
| 1304 | struct page *page; |
| 1305 | struct i915_ctx_workarounds *wa_ctx = &ring->wa_ctx; |
| 1306 | |
| 1307 | WARN_ON(ring->id != RCS); |
| 1308 | |
Arun Siluvery | 5e60d79 | 2015-06-23 15:50:44 +0100 | [diff] [blame] | 1309 | /* update this when WA for higher Gen are added */ |
| 1310 | if (WARN(INTEL_INFO(ring->dev)->gen > 8, |
| 1311 | "WA batch buffer is not initialized for Gen%d\n", |
| 1312 | INTEL_INFO(ring->dev)->gen)) |
| 1313 | return 0; |
| 1314 | |
Arun Siluvery | c4db759 | 2015-06-19 18:37:11 +0100 | [diff] [blame] | 1315 | /* some WA perform writes to scratch page, ensure it is valid */ |
| 1316 | if (ring->scratch.obj == NULL) { |
| 1317 | DRM_ERROR("scratch page not allocated for %s\n", ring->name); |
| 1318 | return -EINVAL; |
| 1319 | } |
| 1320 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1321 | ret = lrc_setup_wa_ctx_obj(ring, PAGE_SIZE); |
| 1322 | if (ret) { |
| 1323 | DRM_DEBUG_DRIVER("Failed to setup context WA page: %d\n", ret); |
| 1324 | return ret; |
| 1325 | } |
| 1326 | |
| 1327 | page = i915_gem_object_get_page(wa_ctx->obj, 0); |
| 1328 | batch = kmap_atomic(page); |
| 1329 | offset = 0; |
| 1330 | |
| 1331 | if (INTEL_INFO(ring->dev)->gen == 8) { |
| 1332 | ret = gen8_init_indirectctx_bb(ring, |
| 1333 | &wa_ctx->indirect_ctx, |
| 1334 | batch, |
| 1335 | &offset); |
| 1336 | if (ret) |
| 1337 | goto out; |
| 1338 | |
| 1339 | ret = gen8_init_perctx_bb(ring, |
| 1340 | &wa_ctx->per_ctx, |
| 1341 | batch, |
| 1342 | &offset); |
| 1343 | if (ret) |
| 1344 | goto out; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | out: |
| 1348 | kunmap_atomic(batch); |
| 1349 | if (ret) |
| 1350 | lrc_destroy_wa_ctx_obj(ring); |
| 1351 | |
| 1352 | return ret; |
| 1353 | } |
| 1354 | |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1355 | static int gen8_init_common_ring(struct intel_engine_cs *ring) |
| 1356 | { |
| 1357 | struct drm_device *dev = ring->dev; |
| 1358 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1359 | |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1360 | I915_WRITE_IMR(ring, ~(ring->irq_enable_mask | ring->irq_keep_mask)); |
| 1361 | I915_WRITE(RING_HWSTAM(ring->mmio_base), 0xffffffff); |
| 1362 | |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1363 | I915_WRITE(RING_MODE_GEN7(ring), |
| 1364 | _MASKED_BIT_DISABLE(GFX_REPLAY_MODE) | |
| 1365 | _MASKED_BIT_ENABLE(GFX_RUN_LIST_ENABLE)); |
| 1366 | POSTING_READ(RING_MODE_GEN7(ring)); |
Thomas Daniel | c0a03a2 | 2015-01-09 11:09:37 +0000 | [diff] [blame] | 1367 | ring->next_context_status_buffer = 0; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1368 | DRM_DEBUG_DRIVER("Execlists enabled for %s\n", ring->name); |
| 1369 | |
| 1370 | memset(&ring->hangcheck, 0, sizeof(ring->hangcheck)); |
| 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | |
| 1375 | static int gen8_init_render_ring(struct intel_engine_cs *ring) |
| 1376 | { |
| 1377 | struct drm_device *dev = ring->dev; |
| 1378 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1379 | int ret; |
| 1380 | |
| 1381 | ret = gen8_init_common_ring(ring); |
| 1382 | if (ret) |
| 1383 | return ret; |
| 1384 | |
| 1385 | /* We need to disable the AsyncFlip performance optimisations in order |
| 1386 | * to use MI_WAIT_FOR_EVENT within the CS. It should already be |
| 1387 | * programmed to '1' on all products. |
| 1388 | * |
| 1389 | * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv,bdw,chv |
| 1390 | */ |
| 1391 | I915_WRITE(MI_MODE, _MASKED_BIT_ENABLE(ASYNC_FLIP_PERF_DISABLE)); |
| 1392 | |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1393 | I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_FORCE_ORDERING)); |
| 1394 | |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 1395 | return init_workarounds_ring(ring); |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Damien Lespiau | 82ef822 | 2015-02-09 19:33:08 +0000 | [diff] [blame] | 1398 | static int gen9_init_render_ring(struct intel_engine_cs *ring) |
| 1399 | { |
| 1400 | int ret; |
| 1401 | |
| 1402 | ret = gen8_init_common_ring(ring); |
| 1403 | if (ret) |
| 1404 | return ret; |
| 1405 | |
| 1406 | return init_workarounds_ring(ring); |
| 1407 | } |
| 1408 | |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1409 | static int intel_logical_ring_emit_pdps(struct drm_i915_gem_request *req) |
| 1410 | { |
| 1411 | struct i915_hw_ppgtt *ppgtt = req->ctx->ppgtt; |
| 1412 | struct intel_engine_cs *ring = req->ring; |
| 1413 | struct intel_ringbuffer *ringbuf = req->ringbuf; |
| 1414 | const int num_lri_cmds = GEN8_LEGACY_PDPES * 2; |
| 1415 | int i, ret; |
| 1416 | |
| 1417 | ret = intel_logical_ring_begin(req, num_lri_cmds * 2 + 2); |
| 1418 | if (ret) |
| 1419 | return ret; |
| 1420 | |
| 1421 | intel_logical_ring_emit(ringbuf, MI_LOAD_REGISTER_IMM(num_lri_cmds)); |
| 1422 | for (i = GEN8_LEGACY_PDPES - 1; i >= 0; i--) { |
| 1423 | const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i); |
| 1424 | |
| 1425 | intel_logical_ring_emit(ringbuf, GEN8_RING_PDP_UDW(ring, i)); |
| 1426 | intel_logical_ring_emit(ringbuf, upper_32_bits(pd_daddr)); |
| 1427 | intel_logical_ring_emit(ringbuf, GEN8_RING_PDP_LDW(ring, i)); |
| 1428 | intel_logical_ring_emit(ringbuf, lower_32_bits(pd_daddr)); |
| 1429 | } |
| 1430 | |
| 1431 | intel_logical_ring_emit(ringbuf, MI_NOOP); |
| 1432 | intel_logical_ring_advance(ringbuf); |
| 1433 | |
| 1434 | return 0; |
| 1435 | } |
| 1436 | |
John Harrison | be795fc | 2015-05-29 17:44:03 +0100 | [diff] [blame] | 1437 | static int gen8_emit_bb_start(struct drm_i915_gem_request *req, |
John Harrison | 8e004ef | 2015-02-13 11:48:10 +0000 | [diff] [blame] | 1438 | u64 offset, unsigned dispatch_flags) |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1439 | { |
John Harrison | be795fc | 2015-05-29 17:44:03 +0100 | [diff] [blame] | 1440 | struct intel_ringbuffer *ringbuf = req->ringbuf; |
John Harrison | 8e004ef | 2015-02-13 11:48:10 +0000 | [diff] [blame] | 1441 | bool ppgtt = !(dispatch_flags & I915_DISPATCH_SECURE); |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1442 | int ret; |
| 1443 | |
Michel Thierry | 7a01a0a | 2015-06-26 13:46:14 +0100 | [diff] [blame] | 1444 | /* Don't rely in hw updating PDPs, specially in lite-restore. |
| 1445 | * Ideally, we should set Force PD Restore in ctx descriptor, |
| 1446 | * but we can't. Force Restore would be a second option, but |
| 1447 | * it is unsafe in case of lite-restore (because the ctx is |
| 1448 | * not idle). */ |
| 1449 | if (req->ctx->ppgtt && |
| 1450 | (intel_ring_flag(req->ring) & req->ctx->ppgtt->pd_dirty_rings)) { |
| 1451 | ret = intel_logical_ring_emit_pdps(req); |
| 1452 | if (ret) |
| 1453 | return ret; |
| 1454 | |
| 1455 | req->ctx->ppgtt->pd_dirty_rings &= ~intel_ring_flag(req->ring); |
| 1456 | } |
| 1457 | |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 1458 | ret = intel_logical_ring_begin(req, 4); |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1459 | if (ret) |
| 1460 | return ret; |
| 1461 | |
| 1462 | /* FIXME(BDW): Address space and security selectors. */ |
Abdiel Janulgue | 6922528 | 2015-06-16 13:39:42 +0300 | [diff] [blame] | 1463 | intel_logical_ring_emit(ringbuf, MI_BATCH_BUFFER_START_GEN8 | |
| 1464 | (ppgtt<<8) | |
| 1465 | (dispatch_flags & I915_DISPATCH_RS ? |
| 1466 | MI_BATCH_RESOURCE_STREAMER : 0)); |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1467 | intel_logical_ring_emit(ringbuf, lower_32_bits(offset)); |
| 1468 | intel_logical_ring_emit(ringbuf, upper_32_bits(offset)); |
| 1469 | intel_logical_ring_emit(ringbuf, MI_NOOP); |
| 1470 | intel_logical_ring_advance(ringbuf); |
| 1471 | |
| 1472 | return 0; |
| 1473 | } |
| 1474 | |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1475 | static bool gen8_logical_ring_get_irq(struct intel_engine_cs *ring) |
| 1476 | { |
| 1477 | struct drm_device *dev = ring->dev; |
| 1478 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1479 | unsigned long flags; |
| 1480 | |
Daniel Vetter | 7cd512f | 2014-09-15 11:38:57 +0200 | [diff] [blame] | 1481 | if (WARN_ON(!intel_irqs_enabled(dev_priv))) |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1482 | return false; |
| 1483 | |
| 1484 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
| 1485 | if (ring->irq_refcount++ == 0) { |
| 1486 | I915_WRITE_IMR(ring, ~(ring->irq_enable_mask | ring->irq_keep_mask)); |
| 1487 | POSTING_READ(RING_IMR(ring->mmio_base)); |
| 1488 | } |
| 1489 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
| 1490 | |
| 1491 | return true; |
| 1492 | } |
| 1493 | |
| 1494 | static void gen8_logical_ring_put_irq(struct intel_engine_cs *ring) |
| 1495 | { |
| 1496 | struct drm_device *dev = ring->dev; |
| 1497 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1498 | unsigned long flags; |
| 1499 | |
| 1500 | spin_lock_irqsave(&dev_priv->irq_lock, flags); |
| 1501 | if (--ring->irq_refcount == 0) { |
| 1502 | I915_WRITE_IMR(ring, ~ring->irq_keep_mask); |
| 1503 | POSTING_READ(RING_IMR(ring->mmio_base)); |
| 1504 | } |
| 1505 | spin_unlock_irqrestore(&dev_priv->irq_lock, flags); |
| 1506 | } |
| 1507 | |
John Harrison | 7deb4d3 | 2015-05-29 17:43:59 +0100 | [diff] [blame] | 1508 | static int gen8_emit_flush(struct drm_i915_gem_request *request, |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1509 | u32 invalidate_domains, |
| 1510 | u32 unused) |
| 1511 | { |
John Harrison | 7deb4d3 | 2015-05-29 17:43:59 +0100 | [diff] [blame] | 1512 | struct intel_ringbuffer *ringbuf = request->ringbuf; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1513 | struct intel_engine_cs *ring = ringbuf->ring; |
| 1514 | struct drm_device *dev = ring->dev; |
| 1515 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1516 | uint32_t cmd; |
| 1517 | int ret; |
| 1518 | |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 1519 | ret = intel_logical_ring_begin(request, 4); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1520 | if (ret) |
| 1521 | return ret; |
| 1522 | |
| 1523 | cmd = MI_FLUSH_DW + 1; |
| 1524 | |
Chris Wilson | f0a1fb1 | 2015-01-22 13:42:00 +0000 | [diff] [blame] | 1525 | /* We always require a command barrier so that subsequent |
| 1526 | * commands, such as breadcrumb interrupts, are strictly ordered |
| 1527 | * wrt the contents of the write cache being flushed to memory |
| 1528 | * (and thus being coherent from the CPU). |
| 1529 | */ |
| 1530 | cmd |= MI_FLUSH_DW_STORE_INDEX | MI_FLUSH_DW_OP_STOREDW; |
| 1531 | |
| 1532 | if (invalidate_domains & I915_GEM_GPU_DOMAINS) { |
| 1533 | cmd |= MI_INVALIDATE_TLB; |
| 1534 | if (ring == &dev_priv->ring[VCS]) |
| 1535 | cmd |= MI_INVALIDATE_BSD; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | intel_logical_ring_emit(ringbuf, cmd); |
| 1539 | intel_logical_ring_emit(ringbuf, |
| 1540 | I915_GEM_HWS_SCRATCH_ADDR | |
| 1541 | MI_FLUSH_DW_USE_GTT); |
| 1542 | intel_logical_ring_emit(ringbuf, 0); /* upper addr */ |
| 1543 | intel_logical_ring_emit(ringbuf, 0); /* value */ |
| 1544 | intel_logical_ring_advance(ringbuf); |
| 1545 | |
| 1546 | return 0; |
| 1547 | } |
| 1548 | |
John Harrison | 7deb4d3 | 2015-05-29 17:43:59 +0100 | [diff] [blame] | 1549 | static int gen8_emit_flush_render(struct drm_i915_gem_request *request, |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1550 | u32 invalidate_domains, |
| 1551 | u32 flush_domains) |
| 1552 | { |
John Harrison | 7deb4d3 | 2015-05-29 17:43:59 +0100 | [diff] [blame] | 1553 | struct intel_ringbuffer *ringbuf = request->ringbuf; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1554 | struct intel_engine_cs *ring = ringbuf->ring; |
| 1555 | u32 scratch_addr = ring->scratch.gtt_offset + 2 * CACHELINE_BYTES; |
Imre Deak | 9647ff3 | 2015-01-25 13:27:11 -0800 | [diff] [blame] | 1556 | bool vf_flush_wa; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1557 | u32 flags = 0; |
| 1558 | int ret; |
| 1559 | |
| 1560 | flags |= PIPE_CONTROL_CS_STALL; |
| 1561 | |
| 1562 | if (flush_domains) { |
| 1563 | flags |= PIPE_CONTROL_RENDER_TARGET_CACHE_FLUSH; |
| 1564 | flags |= PIPE_CONTROL_DEPTH_CACHE_FLUSH; |
| 1565 | } |
| 1566 | |
| 1567 | if (invalidate_domains) { |
| 1568 | flags |= PIPE_CONTROL_TLB_INVALIDATE; |
| 1569 | flags |= PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE; |
| 1570 | flags |= PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE; |
| 1571 | flags |= PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 1572 | flags |= PIPE_CONTROL_CONST_CACHE_INVALIDATE; |
| 1573 | flags |= PIPE_CONTROL_STATE_CACHE_INVALIDATE; |
| 1574 | flags |= PIPE_CONTROL_QW_WRITE; |
| 1575 | flags |= PIPE_CONTROL_GLOBAL_GTT_IVB; |
| 1576 | } |
| 1577 | |
Imre Deak | 9647ff3 | 2015-01-25 13:27:11 -0800 | [diff] [blame] | 1578 | /* |
| 1579 | * On GEN9+ Before VF_CACHE_INVALIDATE we need to emit a NULL pipe |
| 1580 | * control. |
| 1581 | */ |
| 1582 | vf_flush_wa = INTEL_INFO(ring->dev)->gen >= 9 && |
| 1583 | flags & PIPE_CONTROL_VF_CACHE_INVALIDATE; |
| 1584 | |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 1585 | ret = intel_logical_ring_begin(request, vf_flush_wa ? 12 : 6); |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1586 | if (ret) |
| 1587 | return ret; |
| 1588 | |
Imre Deak | 9647ff3 | 2015-01-25 13:27:11 -0800 | [diff] [blame] | 1589 | if (vf_flush_wa) { |
| 1590 | intel_logical_ring_emit(ringbuf, GFX_OP_PIPE_CONTROL(6)); |
| 1591 | intel_logical_ring_emit(ringbuf, 0); |
| 1592 | intel_logical_ring_emit(ringbuf, 0); |
| 1593 | intel_logical_ring_emit(ringbuf, 0); |
| 1594 | intel_logical_ring_emit(ringbuf, 0); |
| 1595 | intel_logical_ring_emit(ringbuf, 0); |
| 1596 | } |
| 1597 | |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1598 | intel_logical_ring_emit(ringbuf, GFX_OP_PIPE_CONTROL(6)); |
| 1599 | intel_logical_ring_emit(ringbuf, flags); |
| 1600 | intel_logical_ring_emit(ringbuf, scratch_addr); |
| 1601 | intel_logical_ring_emit(ringbuf, 0); |
| 1602 | intel_logical_ring_emit(ringbuf, 0); |
| 1603 | intel_logical_ring_emit(ringbuf, 0); |
| 1604 | intel_logical_ring_advance(ringbuf); |
| 1605 | |
| 1606 | return 0; |
| 1607 | } |
| 1608 | |
Oscar Mateo | e94e37a | 2014-07-24 17:04:25 +0100 | [diff] [blame] | 1609 | static u32 gen8_get_seqno(struct intel_engine_cs *ring, bool lazy_coherency) |
| 1610 | { |
| 1611 | return intel_read_status_page(ring, I915_GEM_HWS_INDEX); |
| 1612 | } |
| 1613 | |
| 1614 | static void gen8_set_seqno(struct intel_engine_cs *ring, u32 seqno) |
| 1615 | { |
| 1616 | intel_write_status_page(ring, I915_GEM_HWS_INDEX, seqno); |
| 1617 | } |
| 1618 | |
John Harrison | c4e7663 | 2015-05-29 17:44:01 +0100 | [diff] [blame] | 1619 | static int gen8_emit_request(struct drm_i915_gem_request *request) |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1620 | { |
John Harrison | c4e7663 | 2015-05-29 17:44:01 +0100 | [diff] [blame] | 1621 | struct intel_ringbuffer *ringbuf = request->ringbuf; |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1622 | struct intel_engine_cs *ring = ringbuf->ring; |
| 1623 | u32 cmd; |
| 1624 | int ret; |
| 1625 | |
Michel Thierry | 53292cd | 2015-04-15 18:11:33 +0100 | [diff] [blame] | 1626 | /* |
| 1627 | * Reserve space for 2 NOOPs at the end of each request to be |
| 1628 | * used as a workaround for not being allowed to do lite |
| 1629 | * restore with HEAD==TAIL (WaIdleLiteRestore). |
| 1630 | */ |
John Harrison | 4d616a2 | 2015-05-29 17:44:08 +0100 | [diff] [blame] | 1631 | ret = intel_logical_ring_begin(request, 8); |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1632 | if (ret) |
| 1633 | return ret; |
| 1634 | |
Ville Syrjälä | 8edfbb8 | 2014-11-14 18:16:56 +0200 | [diff] [blame] | 1635 | cmd = MI_STORE_DWORD_IMM_GEN4; |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1636 | cmd |= MI_GLOBAL_GTT; |
| 1637 | |
| 1638 | intel_logical_ring_emit(ringbuf, cmd); |
| 1639 | intel_logical_ring_emit(ringbuf, |
| 1640 | (ring->status_page.gfx_addr + |
| 1641 | (I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT))); |
| 1642 | intel_logical_ring_emit(ringbuf, 0); |
John Harrison | c4e7663 | 2015-05-29 17:44:01 +0100 | [diff] [blame] | 1643 | intel_logical_ring_emit(ringbuf, i915_gem_request_get_seqno(request)); |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1644 | intel_logical_ring_emit(ringbuf, MI_USER_INTERRUPT); |
| 1645 | intel_logical_ring_emit(ringbuf, MI_NOOP); |
John Harrison | ae70797 | 2015-05-29 17:44:14 +0100 | [diff] [blame] | 1646 | intel_logical_ring_advance_and_submit(request); |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1647 | |
Michel Thierry | 53292cd | 2015-04-15 18:11:33 +0100 | [diff] [blame] | 1648 | /* |
| 1649 | * Here we add two extra NOOPs as padding to avoid |
| 1650 | * lite restore of a context with HEAD==TAIL. |
| 1651 | */ |
| 1652 | intel_logical_ring_emit(ringbuf, MI_NOOP); |
| 1653 | intel_logical_ring_emit(ringbuf, MI_NOOP); |
| 1654 | intel_logical_ring_advance(ringbuf); |
| 1655 | |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1656 | return 0; |
| 1657 | } |
| 1658 | |
John Harrison | be01363 | 2015-05-29 17:43:45 +0100 | [diff] [blame] | 1659 | static int intel_lr_context_render_state_init(struct drm_i915_gem_request *req) |
Damien Lespiau | cef437a | 2015-02-10 19:32:19 +0000 | [diff] [blame] | 1660 | { |
Damien Lespiau | cef437a | 2015-02-10 19:32:19 +0000 | [diff] [blame] | 1661 | struct render_state so; |
Damien Lespiau | cef437a | 2015-02-10 19:32:19 +0000 | [diff] [blame] | 1662 | int ret; |
| 1663 | |
John Harrison | be01363 | 2015-05-29 17:43:45 +0100 | [diff] [blame] | 1664 | ret = i915_gem_render_state_prepare(req->ring, &so); |
Damien Lespiau | cef437a | 2015-02-10 19:32:19 +0000 | [diff] [blame] | 1665 | if (ret) |
| 1666 | return ret; |
| 1667 | |
| 1668 | if (so.rodata == NULL) |
| 1669 | return 0; |
| 1670 | |
John Harrison | be795fc | 2015-05-29 17:44:03 +0100 | [diff] [blame] | 1671 | ret = req->ring->emit_bb_start(req, so.ggtt_offset, |
John Harrison | be01363 | 2015-05-29 17:43:45 +0100 | [diff] [blame] | 1672 | I915_DISPATCH_SECURE); |
Damien Lespiau | cef437a | 2015-02-10 19:32:19 +0000 | [diff] [blame] | 1673 | if (ret) |
| 1674 | goto out; |
| 1675 | |
John Harrison | b2af037 | 2015-05-29 17:43:50 +0100 | [diff] [blame] | 1676 | i915_vma_move_to_active(i915_gem_obj_to_ggtt(so.obj), req); |
Damien Lespiau | cef437a | 2015-02-10 19:32:19 +0000 | [diff] [blame] | 1677 | |
Damien Lespiau | cef437a | 2015-02-10 19:32:19 +0000 | [diff] [blame] | 1678 | out: |
| 1679 | i915_gem_render_state_fini(&so); |
| 1680 | return ret; |
| 1681 | } |
| 1682 | |
John Harrison | 8753181 | 2015-05-29 17:43:44 +0100 | [diff] [blame] | 1683 | static int gen8_init_rcs_context(struct drm_i915_gem_request *req) |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 1684 | { |
| 1685 | int ret; |
| 1686 | |
John Harrison | e2be4fa | 2015-05-29 17:43:54 +0100 | [diff] [blame] | 1687 | ret = intel_logical_ring_workarounds_emit(req); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 1688 | if (ret) |
| 1689 | return ret; |
| 1690 | |
John Harrison | be01363 | 2015-05-29 17:43:45 +0100 | [diff] [blame] | 1691 | return intel_lr_context_render_state_init(req); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 1692 | } |
| 1693 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 1694 | /** |
| 1695 | * intel_logical_ring_cleanup() - deallocate the Engine Command Streamer |
| 1696 | * |
| 1697 | * @ring: Engine Command Streamer. |
| 1698 | * |
| 1699 | */ |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1700 | void intel_logical_ring_cleanup(struct intel_engine_cs *ring) |
| 1701 | { |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 1702 | struct drm_i915_private *dev_priv; |
Oscar Mateo | 9832b9d | 2014-07-24 17:04:30 +0100 | [diff] [blame] | 1703 | |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1704 | if (!intel_ring_initialized(ring)) |
| 1705 | return; |
| 1706 | |
John Harrison | 6402c33 | 2014-10-31 12:00:26 +0000 | [diff] [blame] | 1707 | dev_priv = ring->dev->dev_private; |
| 1708 | |
Oscar Mateo | 9832b9d | 2014-07-24 17:04:30 +0100 | [diff] [blame] | 1709 | intel_logical_ring_stop(ring); |
| 1710 | WARN_ON((I915_READ_MODE(ring) & MODE_IDLE) == 0); |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1711 | |
| 1712 | if (ring->cleanup) |
| 1713 | ring->cleanup(ring); |
| 1714 | |
| 1715 | i915_cmd_parser_fini_ring(ring); |
Chris Wilson | 06fbca7 | 2015-04-07 16:20:36 +0100 | [diff] [blame] | 1716 | i915_gem_batch_pool_fini(&ring->batch_pool); |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1717 | |
| 1718 | if (ring->status_page.obj) { |
| 1719 | kunmap(sg_page(ring->status_page.obj->pages->sgl)); |
| 1720 | ring->status_page.obj = NULL; |
| 1721 | } |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1722 | |
| 1723 | lrc_destroy_wa_ctx_obj(ring); |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | static int logical_ring_init(struct drm_device *dev, struct intel_engine_cs *ring) |
| 1727 | { |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1728 | int ret; |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1729 | |
| 1730 | /* Intentionally left blank. */ |
| 1731 | ring->buffer = NULL; |
| 1732 | |
| 1733 | ring->dev = dev; |
| 1734 | INIT_LIST_HEAD(&ring->active_list); |
| 1735 | INIT_LIST_HEAD(&ring->request_list); |
Chris Wilson | 06fbca7 | 2015-04-07 16:20:36 +0100 | [diff] [blame] | 1736 | i915_gem_batch_pool_init(dev, &ring->batch_pool); |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1737 | init_waitqueue_head(&ring->irq_queue); |
| 1738 | |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 1739 | INIT_LIST_HEAD(&ring->execlist_queue); |
Thomas Daniel | c86ee3a9 | 2014-11-13 10:27:05 +0000 | [diff] [blame] | 1740 | INIT_LIST_HEAD(&ring->execlist_retired_req_list); |
Michel Thierry | acdd884 | 2014-07-24 17:04:38 +0100 | [diff] [blame] | 1741 | spin_lock_init(&ring->execlist_lock); |
| 1742 | |
Oscar Mateo | 48d8238 | 2014-07-24 17:04:23 +0100 | [diff] [blame] | 1743 | ret = i915_cmd_parser_init_ring(ring); |
| 1744 | if (ret) |
| 1745 | return ret; |
| 1746 | |
Oscar Mateo | 564ddb2 | 2014-08-21 11:40:54 +0100 | [diff] [blame] | 1747 | ret = intel_lr_context_deferred_create(ring->default_context, ring); |
| 1748 | |
| 1749 | return ret; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | static int logical_render_ring_init(struct drm_device *dev) |
| 1753 | { |
| 1754 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1755 | struct intel_engine_cs *ring = &dev_priv->ring[RCS]; |
Daniel Vetter | 99be1df | 2014-11-20 00:33:06 +0100 | [diff] [blame] | 1756 | int ret; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1757 | |
| 1758 | ring->name = "render ring"; |
| 1759 | ring->id = RCS; |
| 1760 | ring->mmio_base = RENDER_RING_BASE; |
| 1761 | ring->irq_enable_mask = |
| 1762 | GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1763 | ring->irq_keep_mask = |
| 1764 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT; |
| 1765 | if (HAS_L3_DPF(dev)) |
| 1766 | ring->irq_keep_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1767 | |
Damien Lespiau | 82ef822 | 2015-02-09 19:33:08 +0000 | [diff] [blame] | 1768 | if (INTEL_INFO(dev)->gen >= 9) |
| 1769 | ring->init_hw = gen9_init_render_ring; |
| 1770 | else |
| 1771 | ring->init_hw = gen8_init_render_ring; |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 1772 | ring->init_context = gen8_init_rcs_context; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1773 | ring->cleanup = intel_fini_pipe_control; |
Oscar Mateo | e94e37a | 2014-07-24 17:04:25 +0100 | [diff] [blame] | 1774 | ring->get_seqno = gen8_get_seqno; |
| 1775 | ring->set_seqno = gen8_set_seqno; |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1776 | ring->emit_request = gen8_emit_request; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1777 | ring->emit_flush = gen8_emit_flush_render; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1778 | ring->irq_get = gen8_logical_ring_get_irq; |
| 1779 | ring->irq_put = gen8_logical_ring_put_irq; |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1780 | ring->emit_bb_start = gen8_emit_bb_start; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1781 | |
Daniel Vetter | 99be1df | 2014-11-20 00:33:06 +0100 | [diff] [blame] | 1782 | ring->dev = dev; |
Arun Siluvery | c4db759 | 2015-06-19 18:37:11 +0100 | [diff] [blame] | 1783 | |
| 1784 | ret = intel_init_pipe_control(ring); |
Daniel Vetter | 99be1df | 2014-11-20 00:33:06 +0100 | [diff] [blame] | 1785 | if (ret) |
| 1786 | return ret; |
| 1787 | |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1788 | ret = intel_init_workaround_bb(ring); |
| 1789 | if (ret) { |
| 1790 | /* |
| 1791 | * We continue even if we fail to initialize WA batch |
| 1792 | * because we only expect rare glitches but nothing |
| 1793 | * critical to prevent us from using GPU |
| 1794 | */ |
| 1795 | DRM_ERROR("WA batch buffer initialization failed: %d\n", |
| 1796 | ret); |
| 1797 | } |
| 1798 | |
Arun Siluvery | c4db759 | 2015-06-19 18:37:11 +0100 | [diff] [blame] | 1799 | ret = logical_ring_init(dev, ring); |
| 1800 | if (ret) { |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1801 | lrc_destroy_wa_ctx_obj(ring); |
Arun Siluvery | c4db759 | 2015-06-19 18:37:11 +0100 | [diff] [blame] | 1802 | } |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 1803 | |
| 1804 | return ret; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | static int logical_bsd_ring_init(struct drm_device *dev) |
| 1808 | { |
| 1809 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1810 | struct intel_engine_cs *ring = &dev_priv->ring[VCS]; |
| 1811 | |
| 1812 | ring->name = "bsd ring"; |
| 1813 | ring->id = VCS; |
| 1814 | ring->mmio_base = GEN6_BSD_RING_BASE; |
| 1815 | ring->irq_enable_mask = |
| 1816 | GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1817 | ring->irq_keep_mask = |
| 1818 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1819 | |
Daniel Vetter | ecfe00d | 2014-11-20 00:33:04 +0100 | [diff] [blame] | 1820 | ring->init_hw = gen8_init_common_ring; |
Oscar Mateo | e94e37a | 2014-07-24 17:04:25 +0100 | [diff] [blame] | 1821 | ring->get_seqno = gen8_get_seqno; |
| 1822 | ring->set_seqno = gen8_set_seqno; |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1823 | ring->emit_request = gen8_emit_request; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1824 | ring->emit_flush = gen8_emit_flush; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1825 | ring->irq_get = gen8_logical_ring_get_irq; |
| 1826 | ring->irq_put = gen8_logical_ring_put_irq; |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1827 | ring->emit_bb_start = gen8_emit_bb_start; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1828 | |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1829 | return logical_ring_init(dev, ring); |
| 1830 | } |
| 1831 | |
| 1832 | static int logical_bsd2_ring_init(struct drm_device *dev) |
| 1833 | { |
| 1834 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1835 | struct intel_engine_cs *ring = &dev_priv->ring[VCS2]; |
| 1836 | |
| 1837 | ring->name = "bds2 ring"; |
| 1838 | ring->id = VCS2; |
| 1839 | ring->mmio_base = GEN8_BSD2_RING_BASE; |
| 1840 | ring->irq_enable_mask = |
| 1841 | GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1842 | ring->irq_keep_mask = |
| 1843 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1844 | |
Daniel Vetter | ecfe00d | 2014-11-20 00:33:04 +0100 | [diff] [blame] | 1845 | ring->init_hw = gen8_init_common_ring; |
Oscar Mateo | e94e37a | 2014-07-24 17:04:25 +0100 | [diff] [blame] | 1846 | ring->get_seqno = gen8_get_seqno; |
| 1847 | ring->set_seqno = gen8_set_seqno; |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1848 | ring->emit_request = gen8_emit_request; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1849 | ring->emit_flush = gen8_emit_flush; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1850 | ring->irq_get = gen8_logical_ring_get_irq; |
| 1851 | ring->irq_put = gen8_logical_ring_put_irq; |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1852 | ring->emit_bb_start = gen8_emit_bb_start; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1853 | |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1854 | return logical_ring_init(dev, ring); |
| 1855 | } |
| 1856 | |
| 1857 | static int logical_blt_ring_init(struct drm_device *dev) |
| 1858 | { |
| 1859 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1860 | struct intel_engine_cs *ring = &dev_priv->ring[BCS]; |
| 1861 | |
| 1862 | ring->name = "blitter ring"; |
| 1863 | ring->id = BCS; |
| 1864 | ring->mmio_base = BLT_RING_BASE; |
| 1865 | ring->irq_enable_mask = |
| 1866 | GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1867 | ring->irq_keep_mask = |
| 1868 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1869 | |
Daniel Vetter | ecfe00d | 2014-11-20 00:33:04 +0100 | [diff] [blame] | 1870 | ring->init_hw = gen8_init_common_ring; |
Oscar Mateo | e94e37a | 2014-07-24 17:04:25 +0100 | [diff] [blame] | 1871 | ring->get_seqno = gen8_get_seqno; |
| 1872 | ring->set_seqno = gen8_set_seqno; |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1873 | ring->emit_request = gen8_emit_request; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1874 | ring->emit_flush = gen8_emit_flush; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1875 | ring->irq_get = gen8_logical_ring_get_irq; |
| 1876 | ring->irq_put = gen8_logical_ring_put_irq; |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1877 | ring->emit_bb_start = gen8_emit_bb_start; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1878 | |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1879 | return logical_ring_init(dev, ring); |
| 1880 | } |
| 1881 | |
| 1882 | static int logical_vebox_ring_init(struct drm_device *dev) |
| 1883 | { |
| 1884 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1885 | struct intel_engine_cs *ring = &dev_priv->ring[VECS]; |
| 1886 | |
| 1887 | ring->name = "video enhancement ring"; |
| 1888 | ring->id = VECS; |
| 1889 | ring->mmio_base = VEBOX_RING_BASE; |
| 1890 | ring->irq_enable_mask = |
| 1891 | GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1892 | ring->irq_keep_mask = |
| 1893 | GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT; |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1894 | |
Daniel Vetter | ecfe00d | 2014-11-20 00:33:04 +0100 | [diff] [blame] | 1895 | ring->init_hw = gen8_init_common_ring; |
Oscar Mateo | e94e37a | 2014-07-24 17:04:25 +0100 | [diff] [blame] | 1896 | ring->get_seqno = gen8_get_seqno; |
| 1897 | ring->set_seqno = gen8_set_seqno; |
Oscar Mateo | 4da46e1 | 2014-07-24 17:04:27 +0100 | [diff] [blame] | 1898 | ring->emit_request = gen8_emit_request; |
Oscar Mateo | 4712274 | 2014-07-24 17:04:28 +0100 | [diff] [blame] | 1899 | ring->emit_flush = gen8_emit_flush; |
Oscar Mateo | 73d477f | 2014-07-24 17:04:31 +0100 | [diff] [blame] | 1900 | ring->irq_get = gen8_logical_ring_get_irq; |
| 1901 | ring->irq_put = gen8_logical_ring_put_irq; |
Oscar Mateo | 1564858 | 2014-07-24 17:04:32 +0100 | [diff] [blame] | 1902 | ring->emit_bb_start = gen8_emit_bb_start; |
Oscar Mateo | 9b1136d | 2014-07-24 17:04:24 +0100 | [diff] [blame] | 1903 | |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1904 | return logical_ring_init(dev, ring); |
| 1905 | } |
| 1906 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 1907 | /** |
| 1908 | * intel_logical_rings_init() - allocate, populate and init the Engine Command Streamers |
| 1909 | * @dev: DRM device. |
| 1910 | * |
| 1911 | * This function inits the engines for an Execlists submission style (the equivalent in the |
| 1912 | * legacy ringbuffer submission world would be i915_gem_init_rings). It does it only for |
| 1913 | * those engines that are present in the hardware. |
| 1914 | * |
| 1915 | * Return: non-zero if the initialization failed. |
| 1916 | */ |
Oscar Mateo | 454afeb | 2014-07-24 17:04:22 +0100 | [diff] [blame] | 1917 | int intel_logical_rings_init(struct drm_device *dev) |
| 1918 | { |
| 1919 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1920 | int ret; |
| 1921 | |
| 1922 | ret = logical_render_ring_init(dev); |
| 1923 | if (ret) |
| 1924 | return ret; |
| 1925 | |
| 1926 | if (HAS_BSD(dev)) { |
| 1927 | ret = logical_bsd_ring_init(dev); |
| 1928 | if (ret) |
| 1929 | goto cleanup_render_ring; |
| 1930 | } |
| 1931 | |
| 1932 | if (HAS_BLT(dev)) { |
| 1933 | ret = logical_blt_ring_init(dev); |
| 1934 | if (ret) |
| 1935 | goto cleanup_bsd_ring; |
| 1936 | } |
| 1937 | |
| 1938 | if (HAS_VEBOX(dev)) { |
| 1939 | ret = logical_vebox_ring_init(dev); |
| 1940 | if (ret) |
| 1941 | goto cleanup_blt_ring; |
| 1942 | } |
| 1943 | |
| 1944 | if (HAS_BSD2(dev)) { |
| 1945 | ret = logical_bsd2_ring_init(dev); |
| 1946 | if (ret) |
| 1947 | goto cleanup_vebox_ring; |
| 1948 | } |
| 1949 | |
| 1950 | ret = i915_gem_set_seqno(dev, ((u32)~0 - 0x1000)); |
| 1951 | if (ret) |
| 1952 | goto cleanup_bsd2_ring; |
| 1953 | |
| 1954 | return 0; |
| 1955 | |
| 1956 | cleanup_bsd2_ring: |
| 1957 | intel_logical_ring_cleanup(&dev_priv->ring[VCS2]); |
| 1958 | cleanup_vebox_ring: |
| 1959 | intel_logical_ring_cleanup(&dev_priv->ring[VECS]); |
| 1960 | cleanup_blt_ring: |
| 1961 | intel_logical_ring_cleanup(&dev_priv->ring[BCS]); |
| 1962 | cleanup_bsd_ring: |
| 1963 | intel_logical_ring_cleanup(&dev_priv->ring[VCS]); |
| 1964 | cleanup_render_ring: |
| 1965 | intel_logical_ring_cleanup(&dev_priv->ring[RCS]); |
| 1966 | |
| 1967 | return ret; |
| 1968 | } |
| 1969 | |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 1970 | static u32 |
| 1971 | make_rpcs(struct drm_device *dev) |
| 1972 | { |
| 1973 | u32 rpcs = 0; |
| 1974 | |
| 1975 | /* |
| 1976 | * No explicit RPCS request is needed to ensure full |
| 1977 | * slice/subslice/EU enablement prior to Gen9. |
| 1978 | */ |
| 1979 | if (INTEL_INFO(dev)->gen < 9) |
| 1980 | return 0; |
| 1981 | |
| 1982 | /* |
| 1983 | * Starting in Gen9, render power gating can leave |
| 1984 | * slice/subslice/EU in a partially enabled state. We |
| 1985 | * must make an explicit request through RPCS for full |
| 1986 | * enablement. |
| 1987 | */ |
| 1988 | if (INTEL_INFO(dev)->has_slice_pg) { |
| 1989 | rpcs |= GEN8_RPCS_S_CNT_ENABLE; |
| 1990 | rpcs |= INTEL_INFO(dev)->slice_total << |
| 1991 | GEN8_RPCS_S_CNT_SHIFT; |
| 1992 | rpcs |= GEN8_RPCS_ENABLE; |
| 1993 | } |
| 1994 | |
| 1995 | if (INTEL_INFO(dev)->has_subslice_pg) { |
| 1996 | rpcs |= GEN8_RPCS_SS_CNT_ENABLE; |
| 1997 | rpcs |= INTEL_INFO(dev)->subslice_per_slice << |
| 1998 | GEN8_RPCS_SS_CNT_SHIFT; |
| 1999 | rpcs |= GEN8_RPCS_ENABLE; |
| 2000 | } |
| 2001 | |
| 2002 | if (INTEL_INFO(dev)->has_eu_pg) { |
| 2003 | rpcs |= INTEL_INFO(dev)->eu_per_subslice << |
| 2004 | GEN8_RPCS_EU_MIN_SHIFT; |
| 2005 | rpcs |= INTEL_INFO(dev)->eu_per_subslice << |
| 2006 | GEN8_RPCS_EU_MAX_SHIFT; |
| 2007 | rpcs |= GEN8_RPCS_ENABLE; |
| 2008 | } |
| 2009 | |
| 2010 | return rpcs; |
| 2011 | } |
| 2012 | |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2013 | static int |
| 2014 | populate_lr_context(struct intel_context *ctx, struct drm_i915_gem_object *ctx_obj, |
| 2015 | struct intel_engine_cs *ring, struct intel_ringbuffer *ringbuf) |
| 2016 | { |
Thomas Daniel | 2d96553 | 2014-08-19 10:13:36 +0100 | [diff] [blame] | 2017 | struct drm_device *dev = ring->dev; |
| 2018 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | ae6c480 | 2014-08-06 15:04:53 +0200 | [diff] [blame] | 2019 | struct i915_hw_ppgtt *ppgtt = ctx->ppgtt; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2020 | struct page *page; |
| 2021 | uint32_t *reg_state; |
| 2022 | int ret; |
| 2023 | |
Thomas Daniel | 2d96553 | 2014-08-19 10:13:36 +0100 | [diff] [blame] | 2024 | if (!ppgtt) |
| 2025 | ppgtt = dev_priv->mm.aliasing_ppgtt; |
| 2026 | |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2027 | ret = i915_gem_object_set_to_cpu_domain(ctx_obj, true); |
| 2028 | if (ret) { |
| 2029 | DRM_DEBUG_DRIVER("Could not set to CPU domain\n"); |
| 2030 | return ret; |
| 2031 | } |
| 2032 | |
| 2033 | ret = i915_gem_object_get_pages(ctx_obj); |
| 2034 | if (ret) { |
| 2035 | DRM_DEBUG_DRIVER("Could not get object pages\n"); |
| 2036 | return ret; |
| 2037 | } |
| 2038 | |
| 2039 | i915_gem_object_pin_pages(ctx_obj); |
| 2040 | |
| 2041 | /* The second page of the context object contains some fields which must |
| 2042 | * be set up prior to the first execution. */ |
| 2043 | page = i915_gem_object_get_page(ctx_obj, 1); |
| 2044 | reg_state = kmap_atomic(page); |
| 2045 | |
| 2046 | /* A context is actually a big batch buffer with several MI_LOAD_REGISTER_IMM |
| 2047 | * commands followed by (reg, value) pairs. The values we are setting here are |
| 2048 | * only for the first context restore: on a subsequent save, the GPU will |
| 2049 | * recreate this batchbuffer with new values (including all the missing |
| 2050 | * MI_LOAD_REGISTER_IMM commands that we are not initializing here). */ |
| 2051 | if (ring->id == RCS) |
| 2052 | reg_state[CTX_LRI_HEADER_0] = MI_LOAD_REGISTER_IMM(14); |
| 2053 | else |
| 2054 | reg_state[CTX_LRI_HEADER_0] = MI_LOAD_REGISTER_IMM(11); |
| 2055 | reg_state[CTX_LRI_HEADER_0] |= MI_LRI_FORCE_POSTED; |
| 2056 | reg_state[CTX_CONTEXT_CONTROL] = RING_CONTEXT_CONTROL(ring); |
| 2057 | reg_state[CTX_CONTEXT_CONTROL+1] = |
Zhi Wang | 5baa22c5 | 2015-02-10 17:11:36 +0800 | [diff] [blame] | 2058 | _MASKED_BIT_ENABLE(CTX_CTRL_INHIBIT_SYN_CTX_SWITCH | |
Abdiel Janulgue | 6922528 | 2015-06-16 13:39:42 +0300 | [diff] [blame] | 2059 | CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT | |
| 2060 | CTX_CTRL_RS_CTX_ENABLE); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2061 | reg_state[CTX_RING_HEAD] = RING_HEAD(ring->mmio_base); |
| 2062 | reg_state[CTX_RING_HEAD+1] = 0; |
| 2063 | reg_state[CTX_RING_TAIL] = RING_TAIL(ring->mmio_base); |
| 2064 | reg_state[CTX_RING_TAIL+1] = 0; |
| 2065 | reg_state[CTX_RING_BUFFER_START] = RING_START(ring->mmio_base); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 2066 | /* Ring buffer start address is not known until the buffer is pinned. |
| 2067 | * It is written to the context image in execlists_update_context() |
| 2068 | */ |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2069 | reg_state[CTX_RING_BUFFER_CONTROL] = RING_CTL(ring->mmio_base); |
| 2070 | reg_state[CTX_RING_BUFFER_CONTROL+1] = |
| 2071 | ((ringbuf->size - PAGE_SIZE) & RING_NR_PAGES) | RING_VALID; |
| 2072 | reg_state[CTX_BB_HEAD_U] = ring->mmio_base + 0x168; |
| 2073 | reg_state[CTX_BB_HEAD_U+1] = 0; |
| 2074 | reg_state[CTX_BB_HEAD_L] = ring->mmio_base + 0x140; |
| 2075 | reg_state[CTX_BB_HEAD_L+1] = 0; |
| 2076 | reg_state[CTX_BB_STATE] = ring->mmio_base + 0x110; |
| 2077 | reg_state[CTX_BB_STATE+1] = (1<<5); |
| 2078 | reg_state[CTX_SECOND_BB_HEAD_U] = ring->mmio_base + 0x11c; |
| 2079 | reg_state[CTX_SECOND_BB_HEAD_U+1] = 0; |
| 2080 | reg_state[CTX_SECOND_BB_HEAD_L] = ring->mmio_base + 0x114; |
| 2081 | reg_state[CTX_SECOND_BB_HEAD_L+1] = 0; |
| 2082 | reg_state[CTX_SECOND_BB_STATE] = ring->mmio_base + 0x118; |
| 2083 | reg_state[CTX_SECOND_BB_STATE+1] = 0; |
| 2084 | if (ring->id == RCS) { |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2085 | reg_state[CTX_BB_PER_CTX_PTR] = ring->mmio_base + 0x1c0; |
| 2086 | reg_state[CTX_BB_PER_CTX_PTR+1] = 0; |
| 2087 | reg_state[CTX_RCS_INDIRECT_CTX] = ring->mmio_base + 0x1c4; |
| 2088 | reg_state[CTX_RCS_INDIRECT_CTX+1] = 0; |
| 2089 | reg_state[CTX_RCS_INDIRECT_CTX_OFFSET] = ring->mmio_base + 0x1c8; |
| 2090 | reg_state[CTX_RCS_INDIRECT_CTX_OFFSET+1] = 0; |
Arun Siluvery | 17ee950 | 2015-06-19 19:07:01 +0100 | [diff] [blame] | 2091 | if (ring->wa_ctx.obj) { |
| 2092 | struct i915_ctx_workarounds *wa_ctx = &ring->wa_ctx; |
| 2093 | uint32_t ggtt_offset = i915_gem_obj_ggtt_offset(wa_ctx->obj); |
| 2094 | |
| 2095 | reg_state[CTX_RCS_INDIRECT_CTX+1] = |
| 2096 | (ggtt_offset + wa_ctx->indirect_ctx.offset * sizeof(uint32_t)) | |
| 2097 | (wa_ctx->indirect_ctx.size / CACHELINE_DWORDS); |
| 2098 | |
| 2099 | reg_state[CTX_RCS_INDIRECT_CTX_OFFSET+1] = |
| 2100 | CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT << 6; |
| 2101 | |
| 2102 | reg_state[CTX_BB_PER_CTX_PTR+1] = |
| 2103 | (ggtt_offset + wa_ctx->per_ctx.offset * sizeof(uint32_t)) | |
| 2104 | 0x01; |
| 2105 | } |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2106 | } |
| 2107 | reg_state[CTX_LRI_HEADER_1] = MI_LOAD_REGISTER_IMM(9); |
| 2108 | reg_state[CTX_LRI_HEADER_1] |= MI_LRI_FORCE_POSTED; |
| 2109 | reg_state[CTX_CTX_TIMESTAMP] = ring->mmio_base + 0x3a8; |
| 2110 | reg_state[CTX_CTX_TIMESTAMP+1] = 0; |
| 2111 | reg_state[CTX_PDP3_UDW] = GEN8_RING_PDP_UDW(ring, 3); |
| 2112 | reg_state[CTX_PDP3_LDW] = GEN8_RING_PDP_LDW(ring, 3); |
| 2113 | reg_state[CTX_PDP2_UDW] = GEN8_RING_PDP_UDW(ring, 2); |
| 2114 | reg_state[CTX_PDP2_LDW] = GEN8_RING_PDP_LDW(ring, 2); |
| 2115 | reg_state[CTX_PDP1_UDW] = GEN8_RING_PDP_UDW(ring, 1); |
| 2116 | reg_state[CTX_PDP1_LDW] = GEN8_RING_PDP_LDW(ring, 1); |
| 2117 | reg_state[CTX_PDP0_UDW] = GEN8_RING_PDP_UDW(ring, 0); |
| 2118 | reg_state[CTX_PDP0_LDW] = GEN8_RING_PDP_LDW(ring, 0); |
Michel Thierry | d7b2633 | 2015-04-08 12:13:34 +0100 | [diff] [blame] | 2119 | |
| 2120 | /* With dynamic page allocation, PDPs may not be allocated at this point, |
| 2121 | * Point the unallocated PDPs to the scratch page |
Michel Thierry | e5815a2 | 2015-04-08 12:13:32 +0100 | [diff] [blame] | 2122 | */ |
| 2123 | ASSIGN_CTX_PDP(ppgtt, reg_state, 3); |
| 2124 | ASSIGN_CTX_PDP(ppgtt, reg_state, 2); |
| 2125 | ASSIGN_CTX_PDP(ppgtt, reg_state, 1); |
| 2126 | ASSIGN_CTX_PDP(ppgtt, reg_state, 0); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2127 | if (ring->id == RCS) { |
| 2128 | reg_state[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1); |
Jeff McGee | 0cea650 | 2015-02-13 10:27:56 -0600 | [diff] [blame] | 2129 | reg_state[CTX_R_PWR_CLK_STATE] = GEN8_R_PWR_CLK_STATE; |
| 2130 | reg_state[CTX_R_PWR_CLK_STATE+1] = make_rpcs(dev); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | kunmap_atomic(reg_state); |
| 2134 | |
| 2135 | ctx_obj->dirty = 1; |
| 2136 | set_page_dirty(page); |
| 2137 | i915_gem_object_unpin_pages(ctx_obj); |
| 2138 | |
| 2139 | return 0; |
| 2140 | } |
| 2141 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 2142 | /** |
| 2143 | * intel_lr_context_free() - free the LRC specific bits of a context |
| 2144 | * @ctx: the LR context to free. |
| 2145 | * |
| 2146 | * The real context freeing is done in i915_gem_context_free: this only |
| 2147 | * takes care of the bits that are LRC related: the per-engine backing |
| 2148 | * objects and the logical ringbuffer. |
| 2149 | */ |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2150 | void intel_lr_context_free(struct intel_context *ctx) |
| 2151 | { |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2152 | int i; |
| 2153 | |
| 2154 | for (i = 0; i < I915_NUM_RINGS; i++) { |
| 2155 | struct drm_i915_gem_object *ctx_obj = ctx->engine[i].state; |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2156 | |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2157 | if (ctx_obj) { |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 2158 | struct intel_ringbuffer *ringbuf = |
| 2159 | ctx->engine[i].ringbuf; |
| 2160 | struct intel_engine_cs *ring = ringbuf->ring; |
| 2161 | |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 2162 | if (ctx == ring->default_context) { |
| 2163 | intel_unpin_ringbuffer_obj(ringbuf); |
| 2164 | i915_gem_object_ggtt_unpin(ctx_obj); |
| 2165 | } |
Mika Kuoppala | a7cbede | 2015-01-13 11:32:25 +0200 | [diff] [blame] | 2166 | WARN_ON(ctx->engine[ring->id].pin_count); |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2167 | intel_destroy_ringbuffer_obj(ringbuf); |
| 2168 | kfree(ringbuf); |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2169 | drm_gem_object_unreference(&ctx_obj->base); |
| 2170 | } |
| 2171 | } |
| 2172 | } |
| 2173 | |
| 2174 | static uint32_t get_lr_context_size(struct intel_engine_cs *ring) |
| 2175 | { |
| 2176 | int ret = 0; |
| 2177 | |
Michael H. Nguyen | 468c681 | 2014-11-13 17:51:49 +0000 | [diff] [blame] | 2178 | WARN_ON(INTEL_INFO(ring->dev)->gen < 8); |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2179 | |
| 2180 | switch (ring->id) { |
| 2181 | case RCS: |
Michael H. Nguyen | 468c681 | 2014-11-13 17:51:49 +0000 | [diff] [blame] | 2182 | if (INTEL_INFO(ring->dev)->gen >= 9) |
| 2183 | ret = GEN9_LR_CONTEXT_RENDER_SIZE; |
| 2184 | else |
| 2185 | ret = GEN8_LR_CONTEXT_RENDER_SIZE; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2186 | break; |
| 2187 | case VCS: |
| 2188 | case BCS: |
| 2189 | case VECS: |
| 2190 | case VCS2: |
| 2191 | ret = GEN8_LR_CONTEXT_OTHER_SIZE; |
| 2192 | break; |
| 2193 | } |
| 2194 | |
| 2195 | return ret; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2196 | } |
| 2197 | |
Daniel Vetter | 70b0ea8 | 2014-11-18 09:09:32 +0100 | [diff] [blame] | 2198 | static void lrc_setup_hardware_status_page(struct intel_engine_cs *ring, |
Thomas Daniel | 1df06b7 | 2014-10-29 09:52:51 +0000 | [diff] [blame] | 2199 | struct drm_i915_gem_object *default_ctx_obj) |
| 2200 | { |
| 2201 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
| 2202 | |
| 2203 | /* The status page is offset 0 from the default context object |
| 2204 | * in LRC mode. */ |
| 2205 | ring->status_page.gfx_addr = i915_gem_obj_ggtt_offset(default_ctx_obj); |
| 2206 | ring->status_page.page_addr = |
| 2207 | kmap(sg_page(default_ctx_obj->pages->sgl)); |
Thomas Daniel | 1df06b7 | 2014-10-29 09:52:51 +0000 | [diff] [blame] | 2208 | ring->status_page.obj = default_ctx_obj; |
| 2209 | |
| 2210 | I915_WRITE(RING_HWS_PGA(ring->mmio_base), |
| 2211 | (u32)ring->status_page.gfx_addr); |
| 2212 | POSTING_READ(RING_HWS_PGA(ring->mmio_base)); |
Thomas Daniel | 1df06b7 | 2014-10-29 09:52:51 +0000 | [diff] [blame] | 2213 | } |
| 2214 | |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 2215 | /** |
| 2216 | * intel_lr_context_deferred_create() - create the LRC specific bits of a context |
| 2217 | * @ctx: LR context to create. |
| 2218 | * @ring: engine to be used with the context. |
| 2219 | * |
| 2220 | * This function can be called more than once, with different engines, if we plan |
| 2221 | * to use the context with them. The context backing objects and the ringbuffers |
| 2222 | * (specially the ringbuffer backing objects) suck a lot of memory up, and that's why |
| 2223 | * the creation is a deferred call: it's better to make sure first that we need to use |
| 2224 | * a given ring with the context. |
| 2225 | * |
Masanari Iida | 32197aa | 2014-10-20 23:53:13 +0900 | [diff] [blame] | 2226 | * Return: non-zero on error. |
Oscar Mateo | 73e4d07 | 2014-07-24 17:04:48 +0100 | [diff] [blame] | 2227 | */ |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2228 | int intel_lr_context_deferred_create(struct intel_context *ctx, |
| 2229 | struct intel_engine_cs *ring) |
| 2230 | { |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 2231 | const bool is_global_default_ctx = (ctx == ring->default_context); |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2232 | struct drm_device *dev = ring->dev; |
| 2233 | struct drm_i915_gem_object *ctx_obj; |
| 2234 | uint32_t context_size; |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2235 | struct intel_ringbuffer *ringbuf; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2236 | int ret; |
| 2237 | |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2238 | WARN_ON(ctx->legacy_hw_ctx.rcs_state != NULL); |
Daniel Vetter | bfc882b | 2014-11-20 00:33:08 +0100 | [diff] [blame] | 2239 | WARN_ON(ctx->engine[ring->id].state); |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2240 | |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2241 | context_size = round_up(get_lr_context_size(ring), 4096); |
| 2242 | |
Chris Wilson | 149c86e | 2015-04-07 16:21:11 +0100 | [diff] [blame] | 2243 | ctx_obj = i915_gem_alloc_object(dev, context_size); |
Dan Carpenter | 3126a66 | 2015-04-30 17:30:50 +0300 | [diff] [blame] | 2244 | if (!ctx_obj) { |
| 2245 | DRM_DEBUG_DRIVER("Alloc LRC backing obj failed.\n"); |
| 2246 | return -ENOMEM; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2247 | } |
| 2248 | |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 2249 | if (is_global_default_ctx) { |
| 2250 | ret = i915_gem_obj_ggtt_pin(ctx_obj, GEN8_LR_CONTEXT_ALIGN, 0); |
| 2251 | if (ret) { |
| 2252 | DRM_DEBUG_DRIVER("Pin LRC backing obj failed: %d\n", |
| 2253 | ret); |
| 2254 | drm_gem_object_unreference(&ctx_obj->base); |
| 2255 | return ret; |
| 2256 | } |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2257 | } |
| 2258 | |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2259 | ringbuf = kzalloc(sizeof(*ringbuf), GFP_KERNEL); |
| 2260 | if (!ringbuf) { |
| 2261 | DRM_DEBUG_DRIVER("Failed to allocate ringbuffer %s\n", |
| 2262 | ring->name); |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2263 | ret = -ENOMEM; |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 2264 | goto error_unpin_ctx; |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2265 | } |
| 2266 | |
Daniel Vetter | 0c7dd53 | 2014-08-11 16:17:44 +0200 | [diff] [blame] | 2267 | ringbuf->ring = ring; |
Oscar Mateo | 582d67f | 2014-07-24 17:04:16 +0100 | [diff] [blame] | 2268 | |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2269 | ringbuf->size = 32 * PAGE_SIZE; |
| 2270 | ringbuf->effective_size = ringbuf->size; |
| 2271 | ringbuf->head = 0; |
| 2272 | ringbuf->tail = 0; |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2273 | ringbuf->last_retired_head = -1; |
Dave Gordon | ebd0fd4 | 2014-11-27 11:22:49 +0000 | [diff] [blame] | 2274 | intel_ring_update_space(ringbuf); |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2275 | |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 2276 | if (ringbuf->obj == NULL) { |
| 2277 | ret = intel_alloc_ringbuffer_obj(dev, ringbuf); |
| 2278 | if (ret) { |
| 2279 | DRM_DEBUG_DRIVER( |
| 2280 | "Failed to allocate ringbuffer obj %s: %d\n", |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2281 | ring->name, ret); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 2282 | goto error_free_rbuf; |
| 2283 | } |
| 2284 | |
| 2285 | if (is_global_default_ctx) { |
| 2286 | ret = intel_pin_and_map_ringbuffer_obj(dev, ringbuf); |
| 2287 | if (ret) { |
| 2288 | DRM_ERROR( |
| 2289 | "Failed to pin and map ringbuffer %s: %d\n", |
| 2290 | ring->name, ret); |
| 2291 | goto error_destroy_rbuf; |
| 2292 | } |
| 2293 | } |
| 2294 | |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | ret = populate_lr_context(ctx, ctx_obj, ring, ringbuf); |
| 2298 | if (ret) { |
| 2299 | DRM_DEBUG_DRIVER("Failed to populate LRC: %d\n", ret); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2300 | goto error; |
Oscar Mateo | 84c2377 | 2014-07-24 17:04:15 +0100 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | ctx->engine[ring->id].ringbuf = ringbuf; |
Oscar Mateo | 8c857917 | 2014-07-24 17:04:14 +0100 | [diff] [blame] | 2304 | ctx->engine[ring->id].state = ctx_obj; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2305 | |
Daniel Vetter | 70b0ea8 | 2014-11-18 09:09:32 +0100 | [diff] [blame] | 2306 | if (ctx == ring->default_context) |
| 2307 | lrc_setup_hardware_status_page(ring, ctx_obj); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 2308 | else if (ring->id == RCS && !ctx->rcs_initialized) { |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 2309 | if (ring->init_context) { |
John Harrison | 76c3916 | 2015-05-29 17:43:43 +0100 | [diff] [blame] | 2310 | struct drm_i915_gem_request *req; |
| 2311 | |
| 2312 | ret = i915_gem_request_alloc(ring, ctx, &req); |
| 2313 | if (ret) |
| 2314 | return ret; |
| 2315 | |
John Harrison | 8753181 | 2015-05-29 17:43:44 +0100 | [diff] [blame] | 2316 | ret = ring->init_context(req); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 2317 | if (ret) { |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 2318 | DRM_ERROR("ring init context: %d\n", ret); |
John Harrison | 76c3916 | 2015-05-29 17:43:43 +0100 | [diff] [blame] | 2319 | i915_gem_request_cancel(req); |
Thomas Daniel | e7778be | 2014-12-02 12:50:48 +0000 | [diff] [blame] | 2320 | ctx->engine[ring->id].ringbuf = NULL; |
| 2321 | ctx->engine[ring->id].state = NULL; |
| 2322 | goto error; |
| 2323 | } |
John Harrison | 76c3916 | 2015-05-29 17:43:43 +0100 | [diff] [blame] | 2324 | |
John Harrison | 7528987 | 2015-05-29 17:43:49 +0100 | [diff] [blame] | 2325 | i915_add_request_no_flush(req); |
Michel Thierry | 771b9a5 | 2014-11-11 16:47:33 +0000 | [diff] [blame] | 2326 | } |
| 2327 | |
Oscar Mateo | 564ddb2 | 2014-08-21 11:40:54 +0100 | [diff] [blame] | 2328 | ctx->rcs_initialized = true; |
| 2329 | } |
| 2330 | |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2331 | return 0; |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2332 | |
| 2333 | error: |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 2334 | if (is_global_default_ctx) |
| 2335 | intel_unpin_ringbuffer_obj(ringbuf); |
| 2336 | error_destroy_rbuf: |
| 2337 | intel_destroy_ringbuffer_obj(ringbuf); |
| 2338 | error_free_rbuf: |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2339 | kfree(ringbuf); |
Thomas Daniel | 7ba717c | 2014-11-13 10:28:56 +0000 | [diff] [blame] | 2340 | error_unpin_ctx: |
Oscar Mateo | dcb4c12 | 2014-11-13 10:28:10 +0000 | [diff] [blame] | 2341 | if (is_global_default_ctx) |
| 2342 | i915_gem_object_ggtt_unpin(ctx_obj); |
Oscar Mateo | 8670d6f | 2014-07-24 17:04:17 +0100 | [diff] [blame] | 2343 | drm_gem_object_unreference(&ctx_obj->base); |
| 2344 | return ret; |
Oscar Mateo | ede7d42 | 2014-07-24 17:04:12 +0100 | [diff] [blame] | 2345 | } |
Thomas Daniel | 3e5b6f0 | 2015-02-16 16:12:53 +0000 | [diff] [blame] | 2346 | |
| 2347 | void intel_lr_context_reset(struct drm_device *dev, |
| 2348 | struct intel_context *ctx) |
| 2349 | { |
| 2350 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2351 | struct intel_engine_cs *ring; |
| 2352 | int i; |
| 2353 | |
| 2354 | for_each_ring(ring, dev_priv, i) { |
| 2355 | struct drm_i915_gem_object *ctx_obj = |
| 2356 | ctx->engine[ring->id].state; |
| 2357 | struct intel_ringbuffer *ringbuf = |
| 2358 | ctx->engine[ring->id].ringbuf; |
| 2359 | uint32_t *reg_state; |
| 2360 | struct page *page; |
| 2361 | |
| 2362 | if (!ctx_obj) |
| 2363 | continue; |
| 2364 | |
| 2365 | if (i915_gem_object_get_pages(ctx_obj)) { |
| 2366 | WARN(1, "Failed get_pages for context obj\n"); |
| 2367 | continue; |
| 2368 | } |
| 2369 | page = i915_gem_object_get_page(ctx_obj, 1); |
| 2370 | reg_state = kmap_atomic(page); |
| 2371 | |
| 2372 | reg_state[CTX_RING_HEAD+1] = 0; |
| 2373 | reg_state[CTX_RING_TAIL+1] = 0; |
| 2374 | |
| 2375 | kunmap_atomic(reg_state); |
| 2376 | |
| 2377 | ringbuf->head = 0; |
| 2378 | ringbuf->tail = 0; |
| 2379 | } |
| 2380 | } |