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