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