blob: 71eac571e141f569b691d0d2133add7e565d4a00 [file] [log] [blame]
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +01001/*
2 * Copyright © 2016 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 */
24
Chris Wilsonf636edb2017-10-09 12:02:57 +010025#include <drm/drm_print.h>
26
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +010027#include "i915_drv.h"
Weinan Li1fd51d92017-10-15 11:55:25 +080028#include "i915_vgpu.h"
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +010029#include "intel_ringbuffer.h"
30#include "intel_lrc.h"
31
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +030032/* Haswell does have the CXT_SIZE register however it does not appear to be
33 * valid. Now, docs explain in dwords what is in the context object. The full
34 * size is 70720 bytes, however, the power context and execlist context will
35 * never be saved (power context is stored elsewhere, and execlists don't work
36 * on HSW) - so the final size, including the extra state required for the
37 * Resource Streamer, is 66944 bytes, which rounds to 17 pages.
38 */
39#define HSW_CXT_TOTAL_SIZE (17 * PAGE_SIZE)
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +030040
Oscar Mateo7ab4adb2018-01-11 14:55:06 -080041#define DEFAULT_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +030042#define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE)
43#define GEN9_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)
Oscar Mateo3cf19342017-10-04 08:39:52 -070044#define GEN10_LR_CONTEXT_RENDER_SIZE (18 * PAGE_SIZE)
Tvrtko Ursulinb86aa442018-01-11 14:55:07 -080045#define GEN11_LR_CONTEXT_RENDER_SIZE (14 * PAGE_SIZE)
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +030046
47#define GEN8_LR_CONTEXT_OTHER_SIZE ( 2 * PAGE_SIZE)
48
Oscar Mateob8400f02017-04-10 07:34:32 -070049struct engine_class_info {
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +010050 const char *name;
Oscar Mateob8400f02017-04-10 07:34:32 -070051 int (*init_legacy)(struct intel_engine_cs *engine);
52 int (*init_execlists)(struct intel_engine_cs *engine);
Tvrtko Ursulin1803fcbc2017-11-10 14:26:27 +000053
54 u8 uabi_class;
Oscar Mateob8400f02017-04-10 07:34:32 -070055};
56
57static const struct engine_class_info intel_engine_classes[] = {
58 [RENDER_CLASS] = {
59 .name = "rcs",
60 .init_execlists = logical_render_ring_init,
61 .init_legacy = intel_init_render_ring_buffer,
Tvrtko Ursulin1803fcbc2017-11-10 14:26:27 +000062 .uabi_class = I915_ENGINE_CLASS_RENDER,
Oscar Mateob8400f02017-04-10 07:34:32 -070063 },
64 [COPY_ENGINE_CLASS] = {
65 .name = "bcs",
66 .init_execlists = logical_xcs_ring_init,
67 .init_legacy = intel_init_blt_ring_buffer,
Tvrtko Ursulin1803fcbc2017-11-10 14:26:27 +000068 .uabi_class = I915_ENGINE_CLASS_COPY,
Oscar Mateob8400f02017-04-10 07:34:32 -070069 },
70 [VIDEO_DECODE_CLASS] = {
71 .name = "vcs",
72 .init_execlists = logical_xcs_ring_init,
73 .init_legacy = intel_init_bsd_ring_buffer,
Tvrtko Ursulin1803fcbc2017-11-10 14:26:27 +000074 .uabi_class = I915_ENGINE_CLASS_VIDEO,
Oscar Mateob8400f02017-04-10 07:34:32 -070075 },
76 [VIDEO_ENHANCEMENT_CLASS] = {
77 .name = "vecs",
78 .init_execlists = logical_xcs_ring_init,
79 .init_legacy = intel_init_vebox_ring_buffer,
Tvrtko Ursulin1803fcbc2017-11-10 14:26:27 +000080 .uabi_class = I915_ENGINE_CLASS_VIDEO_ENHANCE,
Oscar Mateob8400f02017-04-10 07:34:32 -070081 },
82};
83
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -070084#define MAX_MMIO_BASES 3
Oscar Mateob8400f02017-04-10 07:34:32 -070085struct engine_info {
Michal Wajdeczko237ae7c2017-03-01 20:26:15 +000086 unsigned int hw_id;
Chris Wilson1d39f282017-04-11 13:43:06 +010087 unsigned int uabi_id;
Daniele Ceraolo Spurio09081802017-04-10 07:34:29 -070088 u8 class;
89 u8 instance;
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -070090 /* mmio bases table *must* be sorted in reverse gen order */
91 struct engine_mmio_base {
92 u32 gen : 8;
93 u32 base : 24;
94 } mmio_bases[MAX_MMIO_BASES];
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +010095 unsigned irq_shift;
Oscar Mateob8400f02017-04-10 07:34:32 -070096};
97
98static const struct engine_info intel_engines[] = {
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +010099 [RCS] = {
Tvrtko Ursulin5ec2cf72016-08-16 17:04:20 +0100100 .hw_id = RCS_HW,
Chris Wilson1d39f282017-04-11 13:43:06 +0100101 .uabi_id = I915_EXEC_RENDER,
Daniele Ceraolo Spurio09081802017-04-10 07:34:29 -0700102 .class = RENDER_CLASS,
103 .instance = 0,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700104 .mmio_bases = {
105 { .gen = 1, .base = RENDER_RING_BASE }
106 },
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100107 .irq_shift = GEN8_RCS_IRQ_SHIFT,
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100108 },
109 [BCS] = {
Tvrtko Ursulin5ec2cf72016-08-16 17:04:20 +0100110 .hw_id = BCS_HW,
Chris Wilson1d39f282017-04-11 13:43:06 +0100111 .uabi_id = I915_EXEC_BLT,
Daniele Ceraolo Spurio09081802017-04-10 07:34:29 -0700112 .class = COPY_ENGINE_CLASS,
113 .instance = 0,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700114 .mmio_bases = {
115 { .gen = 6, .base = BLT_RING_BASE }
116 },
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100117 .irq_shift = GEN8_BCS_IRQ_SHIFT,
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100118 },
119 [VCS] = {
Tvrtko Ursulin5ec2cf72016-08-16 17:04:20 +0100120 .hw_id = VCS_HW,
Chris Wilson1d39f282017-04-11 13:43:06 +0100121 .uabi_id = I915_EXEC_BSD,
Daniele Ceraolo Spurio09081802017-04-10 07:34:29 -0700122 .class = VIDEO_DECODE_CLASS,
123 .instance = 0,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700124 .mmio_bases = {
125 { .gen = 11, .base = GEN11_BSD_RING_BASE },
126 { .gen = 6, .base = GEN6_BSD_RING_BASE },
127 { .gen = 4, .base = BSD_RING_BASE }
128 },
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100129 .irq_shift = GEN8_VCS1_IRQ_SHIFT,
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100130 },
131 [VCS2] = {
Tvrtko Ursulin5ec2cf72016-08-16 17:04:20 +0100132 .hw_id = VCS2_HW,
Chris Wilson1d39f282017-04-11 13:43:06 +0100133 .uabi_id = I915_EXEC_BSD,
Daniele Ceraolo Spurio09081802017-04-10 07:34:29 -0700134 .class = VIDEO_DECODE_CLASS,
135 .instance = 1,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700136 .mmio_bases = {
137 { .gen = 11, .base = GEN11_BSD2_RING_BASE },
138 { .gen = 8, .base = GEN8_BSD2_RING_BASE }
139 },
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100140 .irq_shift = GEN8_VCS2_IRQ_SHIFT,
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100141 },
Oscar Mateo5f79e7c2018-03-02 18:14:57 +0200142 [VCS3] = {
143 .hw_id = VCS3_HW,
144 .uabi_id = I915_EXEC_BSD,
145 .class = VIDEO_DECODE_CLASS,
146 .instance = 2,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700147 .mmio_bases = {
148 { .gen = 11, .base = GEN11_BSD3_RING_BASE }
149 },
Oscar Mateo5f79e7c2018-03-02 18:14:57 +0200150 .irq_shift = 0, /* not used */
151 },
152 [VCS4] = {
153 .hw_id = VCS4_HW,
154 .uabi_id = I915_EXEC_BSD,
155 .class = VIDEO_DECODE_CLASS,
156 .instance = 3,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700157 .mmio_bases = {
158 { .gen = 11, .base = GEN11_BSD4_RING_BASE }
159 },
Oscar Mateo5f79e7c2018-03-02 18:14:57 +0200160 .irq_shift = 0, /* not used */
161 },
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100162 [VECS] = {
Tvrtko Ursulin5ec2cf72016-08-16 17:04:20 +0100163 .hw_id = VECS_HW,
Chris Wilson1d39f282017-04-11 13:43:06 +0100164 .uabi_id = I915_EXEC_VEBOX,
Daniele Ceraolo Spurio09081802017-04-10 07:34:29 -0700165 .class = VIDEO_ENHANCEMENT_CLASS,
166 .instance = 0,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700167 .mmio_bases = {
168 { .gen = 11, .base = GEN11_VEBOX_RING_BASE },
169 { .gen = 7, .base = VEBOX_RING_BASE }
170 },
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100171 .irq_shift = GEN8_VECS_IRQ_SHIFT,
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100172 },
Oscar Mateo5f79e7c2018-03-02 18:14:57 +0200173 [VECS2] = {
174 .hw_id = VECS2_HW,
175 .uabi_id = I915_EXEC_VEBOX,
176 .class = VIDEO_ENHANCEMENT_CLASS,
177 .instance = 1,
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700178 .mmio_bases = {
179 { .gen = 11, .base = GEN11_VEBOX2_RING_BASE }
180 },
Oscar Mateo5f79e7c2018-03-02 18:14:57 +0200181 .irq_shift = 0, /* not used */
182 },
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100183};
184
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300185/**
186 * ___intel_engine_context_size() - return the size of the context for an engine
187 * @dev_priv: i915 device private
188 * @class: engine class
189 *
190 * Each engine class may require a different amount of space for a context
191 * image.
192 *
193 * Return: size (in bytes) of an engine class specific context image
194 *
195 * Note: this size includes the HWSP, which is part of the context image
196 * in LRC mode, but does not include the "shared data page" used with
197 * GuC submission. The caller should account for this if using the GuC.
198 */
199static u32
200__intel_engine_context_size(struct drm_i915_private *dev_priv, u8 class)
201{
202 u32 cxt_size;
203
204 BUILD_BUG_ON(I915_GTT_PAGE_SIZE != PAGE_SIZE);
205
206 switch (class) {
207 case RENDER_CLASS:
208 switch (INTEL_GEN(dev_priv)) {
209 default:
210 MISSING_CASE(INTEL_GEN(dev_priv));
Oscar Mateo7ab4adb2018-01-11 14:55:06 -0800211 return DEFAULT_LR_CONTEXT_RENDER_SIZE;
Tvrtko Ursulinb86aa442018-01-11 14:55:07 -0800212 case 11:
213 return GEN11_LR_CONTEXT_RENDER_SIZE;
Rodrigo Vivif65f8412017-07-06 14:06:24 -0700214 case 10:
Oscar Mateo7fd0b1a2017-09-21 16:19:49 -0700215 return GEN10_LR_CONTEXT_RENDER_SIZE;
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300216 case 9:
217 return GEN9_LR_CONTEXT_RENDER_SIZE;
218 case 8:
Chris Wilsonfb5c5512017-11-20 20:55:00 +0000219 return GEN8_LR_CONTEXT_RENDER_SIZE;
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300220 case 7:
221 if (IS_HASWELL(dev_priv))
222 return HSW_CXT_TOTAL_SIZE;
223
224 cxt_size = I915_READ(GEN7_CXT_SIZE);
225 return round_up(GEN7_CXT_TOTAL_SIZE(cxt_size) * 64,
226 PAGE_SIZE);
227 case 6:
228 cxt_size = I915_READ(CXT_SIZE);
229 return round_up(GEN6_CXT_TOTAL_SIZE(cxt_size) * 64,
230 PAGE_SIZE);
231 case 5:
232 case 4:
233 case 3:
234 case 2:
235 /* For the special day when i810 gets merged. */
236 case 1:
237 return 0;
238 }
239 break;
240 default:
241 MISSING_CASE(class);
242 case VIDEO_DECODE_CLASS:
243 case VIDEO_ENHANCEMENT_CLASS:
244 case COPY_ENGINE_CLASS:
245 if (INTEL_GEN(dev_priv) < 8)
246 return 0;
247 return GEN8_LR_CONTEXT_OTHER_SIZE;
248 }
249}
250
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700251static u32 __engine_mmio_base(struct drm_i915_private *i915,
252 const struct engine_mmio_base *bases)
253{
254 int i;
255
256 for (i = 0; i < MAX_MMIO_BASES; i++)
257 if (INTEL_GEN(i915) >= bases[i].gen)
258 break;
259
260 GEM_BUG_ON(i == MAX_MMIO_BASES);
261 GEM_BUG_ON(!bases[i].base);
262
263 return bases[i].base;
264}
265
Akash Goel3b3f1652016-10-13 22:44:48 +0530266static int
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100267intel_engine_setup(struct drm_i915_private *dev_priv,
268 enum intel_engine_id id)
269{
270 const struct engine_info *info = &intel_engines[id];
Oscar Mateob8400f02017-04-10 07:34:32 -0700271 const struct engine_class_info *class_info;
Akash Goel3b3f1652016-10-13 22:44:48 +0530272 struct intel_engine_cs *engine;
273
Oscar Mateob8400f02017-04-10 07:34:32 -0700274 GEM_BUG_ON(info->class >= ARRAY_SIZE(intel_engine_classes));
275 class_info = &intel_engine_classes[info->class];
276
Daniele Ceraolo Spurioac52da62018-03-02 18:14:58 +0200277 BUILD_BUG_ON(MAX_ENGINE_CLASS >= BIT(GEN11_ENGINE_CLASS_WIDTH));
278 BUILD_BUG_ON(MAX_ENGINE_INSTANCE >= BIT(GEN11_ENGINE_INSTANCE_WIDTH));
279
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +0000280 if (GEM_WARN_ON(info->class > MAX_ENGINE_CLASS))
281 return -EINVAL;
282
283 if (GEM_WARN_ON(info->instance > MAX_ENGINE_INSTANCE))
284 return -EINVAL;
285
286 if (GEM_WARN_ON(dev_priv->engine_class[info->class][info->instance]))
287 return -EINVAL;
288
Akash Goel3b3f1652016-10-13 22:44:48 +0530289 GEM_BUG_ON(dev_priv->engine[id]);
290 engine = kzalloc(sizeof(*engine), GFP_KERNEL);
291 if (!engine)
292 return -ENOMEM;
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100293
294 engine->id = id;
295 engine->i915 = dev_priv;
Oscar Mateo6e516142017-04-10 07:34:31 -0700296 WARN_ON(snprintf(engine->name, sizeof(engine->name), "%s%u",
Oscar Mateob8400f02017-04-10 07:34:32 -0700297 class_info->name, info->instance) >=
298 sizeof(engine->name));
Tvrtko Ursulin5ec2cf72016-08-16 17:04:20 +0100299 engine->hw_id = engine->guc_id = info->hw_id;
Daniele Ceraolo Spurio80b216b2018-03-14 11:26:50 -0700300 engine->mmio_base = __engine_mmio_base(dev_priv, info->mmio_bases);
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100301 engine->irq_shift = info->irq_shift;
Daniele Ceraolo Spurio09081802017-04-10 07:34:29 -0700302 engine->class = info->class;
303 engine->instance = info->instance;
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100304
Tvrtko Ursulin1803fcbc2017-11-10 14:26:27 +0000305 engine->uabi_id = info->uabi_id;
306 engine->uabi_class = class_info->uabi_class;
307
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300308 engine->context_size = __intel_engine_context_size(dev_priv,
309 engine->class);
310 if (WARN_ON(engine->context_size > BIT(20)))
311 engine->context_size = 0;
312
Chris Wilson0de91362016-11-14 20:41:01 +0000313 /* Nothing to do here, execute in order of dependencies */
314 engine->schedule = NULL;
315
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +0000316 spin_lock_init(&engine->stats.lock);
317
Changbin Du3fc03062017-03-13 10:47:11 +0800318 ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier);
319
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +0000320 dev_priv->engine_class[info->class][info->instance] = engine;
Akash Goel3b3f1652016-10-13 22:44:48 +0530321 dev_priv->engine[id] = engine;
322 return 0;
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100323}
324
325/**
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300326 * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers
Tvrtko Ursulinbf9e8422016-12-01 14:16:38 +0000327 * @dev_priv: i915 device private
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100328 *
329 * Return: non-zero if the initialization failed.
330 */
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300331int intel_engines_init_mmio(struct drm_i915_private *dev_priv)
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100332{
Tvrtko Ursulinc1bb1142016-08-10 16:22:10 +0100333 struct intel_device_info *device_info = mkwrite_device_info(dev_priv);
Chris Wilson5f9be052017-04-11 17:56:58 +0100334 const unsigned int ring_mask = INTEL_INFO(dev_priv)->ring_mask;
Akash Goel3b3f1652016-10-13 22:44:48 +0530335 struct intel_engine_cs *engine;
336 enum intel_engine_id id;
Chris Wilson5f9be052017-04-11 17:56:58 +0100337 unsigned int mask = 0;
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100338 unsigned int i;
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000339 int err;
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100340
Tvrtko Ursulin70006ad2016-10-13 11:02:56 +0100341 WARN_ON(ring_mask == 0);
342 WARN_ON(ring_mask &
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100343 GENMASK(sizeof(mask) * BITS_PER_BYTE - 1, I915_NUM_ENGINES));
344
345 for (i = 0; i < ARRAY_SIZE(intel_engines); i++) {
346 if (!HAS_ENGINE(dev_priv, i))
347 continue;
348
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000349 err = intel_engine_setup(dev_priv, i);
350 if (err)
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100351 goto cleanup;
352
353 mask |= ENGINE_MASK(i);
354 }
355
356 /*
357 * Catch failures to update intel_engines table when the new engines
358 * are added to the driver by a warning and disabling the forgotten
359 * engines.
360 */
Tvrtko Ursulin70006ad2016-10-13 11:02:56 +0100361 if (WARN_ON(mask != ring_mask))
Tvrtko Ursulinc1bb1142016-08-10 16:22:10 +0100362 device_info->ring_mask = mask;
363
Chris Wilson5f9be052017-04-11 17:56:58 +0100364 /* We always presume we have at least RCS available for later probing */
365 if (WARN_ON(!HAS_ENGINE(dev_priv, RCS))) {
366 err = -ENODEV;
367 goto cleanup;
368 }
369
Tvrtko Ursulinc1bb1142016-08-10 16:22:10 +0100370 device_info->num_rings = hweight32(mask);
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100371
Michel Thierryce453b32017-11-10 16:44:47 -0800372 i915_check_and_clear_faults(dev_priv);
373
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100374 return 0;
375
376cleanup:
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000377 for_each_engine(engine, dev_priv, id)
378 kfree(engine);
379 return err;
380}
381
382/**
Joonas Lahtinen63ffbcd2017-04-28 10:53:36 +0300383 * intel_engines_init() - init the Engine Command Streamers
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000384 * @dev_priv: i915 device private
385 *
386 * Return: non-zero if the initialization failed.
387 */
388int intel_engines_init(struct drm_i915_private *dev_priv)
389{
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000390 struct intel_engine_cs *engine;
391 enum intel_engine_id id, err_id;
Tvrtko Ursulin33def1f2017-06-16 14:03:38 +0100392 int err;
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000393
Akash Goel3b3f1652016-10-13 22:44:48 +0530394 for_each_engine(engine, dev_priv, id) {
Oscar Mateob8400f02017-04-10 07:34:32 -0700395 const struct engine_class_info *class_info =
396 &intel_engine_classes[engine->class];
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000397 int (*init)(struct intel_engine_cs *engine);
398
Chris Wilsonfb5c5512017-11-20 20:55:00 +0000399 if (HAS_EXECLISTS(dev_priv))
Oscar Mateob8400f02017-04-10 07:34:32 -0700400 init = class_info->init_execlists;
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000401 else
Oscar Mateob8400f02017-04-10 07:34:32 -0700402 init = class_info->init_legacy;
Tvrtko Ursulin33def1f2017-06-16 14:03:38 +0100403
404 err = -EINVAL;
405 err_id = id;
406
407 if (GEM_WARN_ON(!init))
408 goto cleanup;
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000409
410 err = init(engine);
Tvrtko Ursulin33def1f2017-06-16 14:03:38 +0100411 if (err)
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000412 goto cleanup;
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000413
Chris Wilsonff44ad52017-03-16 17:13:03 +0000414 GEM_BUG_ON(!engine->submit_request);
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000415 }
416
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000417 return 0;
418
419cleanup:
420 for_each_engine(engine, dev_priv, id) {
Tvrtko Ursulin33def1f2017-06-16 14:03:38 +0100421 if (id >= err_id) {
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000422 kfree(engine);
Tvrtko Ursulin33def1f2017-06-16 14:03:38 +0100423 dev_priv->engine[id] = NULL;
424 } else {
Tvrtko Ursulin8ee7c6e2017-02-16 12:23:22 +0000425 dev_priv->gt.cleanup_engine(engine);
Tvrtko Ursulin33def1f2017-06-16 14:03:38 +0100426 }
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100427 }
Chris Wilsonbb8f0f52017-01-24 11:01:34 +0000428 return err;
Tvrtko Ursulin88d2ba22016-07-13 16:03:40 +0100429}
430
Chris Wilson73cb9702016-10-28 13:58:46 +0100431void intel_engine_init_global_seqno(struct intel_engine_cs *engine, u32 seqno)
Chris Wilson57f275a2016-08-15 10:49:00 +0100432{
433 struct drm_i915_private *dev_priv = engine->i915;
434
435 /* Our semaphore implementation is strictly monotonic (i.e. we proceed
436 * so long as the semaphore value in the register/page is greater
437 * than the sync value), so whenever we reset the seqno,
438 * so long as we reset the tracking semaphore value to 0, it will
439 * always be before the next request's seqno. If we don't reset
440 * the semaphore value, then when the seqno moves backwards all
441 * future waits will complete instantly (causing rendering corruption).
442 */
443 if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
444 I915_WRITE(RING_SYNC_0(engine->mmio_base), 0);
445 I915_WRITE(RING_SYNC_1(engine->mmio_base), 0);
446 if (HAS_VEBOX(dev_priv))
447 I915_WRITE(RING_SYNC_2(engine->mmio_base), 0);
448 }
Chris Wilson57f275a2016-08-15 10:49:00 +0100449
450 intel_write_status_page(engine, I915_GEM_HWS_INDEX, seqno);
Chris Wilson14a6bbf2017-03-14 11:14:52 +0000451 clear_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
Chris Wilson73cb9702016-10-28 13:58:46 +0100452
Chris Wilson57f275a2016-08-15 10:49:00 +0100453 /* After manually advancing the seqno, fake the interrupt in case
454 * there are any waiters for that seqno.
455 */
456 intel_engine_wakeup(engine);
Chris Wilson2ca9faa2017-04-05 16:30:54 +0100457
458 GEM_BUG_ON(intel_engine_get_seqno(engine) != seqno);
Chris Wilson57f275a2016-08-15 10:49:00 +0100459}
460
Chris Wilson73cb9702016-10-28 13:58:46 +0100461static void intel_engine_init_timeline(struct intel_engine_cs *engine)
Chris Wilsondcff85c2016-08-05 10:14:11 +0100462{
Chris Wilson73cb9702016-10-28 13:58:46 +0100463 engine->timeline = &engine->i915->gt.global_timeline.engine[engine->id];
Chris Wilsondcff85c2016-08-05 10:14:11 +0100464}
465
Michal Wajdeczkoc5781352018-03-08 09:50:35 +0000466static void intel_engine_init_batch_pool(struct intel_engine_cs *engine)
467{
468 i915_gem_batch_pool_init(&engine->batch_pool, engine);
469}
470
Mika Kuoppala19df9a52017-09-22 15:43:04 +0300471static bool csb_force_mmio(struct drm_i915_private *i915)
472{
Mika Kuoppala19df9a52017-09-22 15:43:04 +0300473 /*
474 * IOMMU adds unpredictable latency causing the CSB write (from the
475 * GPU into the HWSP) to only be visible some time after the interrupt
476 * (missed breadcrumb syndrome).
477 */
478 if (intel_vtd_active())
479 return true;
480
Weinan Li1fd51d92017-10-15 11:55:25 +0800481 /* Older GVT emulation depends upon intercepting CSB mmio */
482 if (intel_vgpu_active(i915) && !intel_vgpu_has_hwsp_emulation(i915))
483 return true;
484
Mika Kuoppala19df9a52017-09-22 15:43:04 +0300485 return false;
486}
487
488static void intel_engine_init_execlist(struct intel_engine_cs *engine)
489{
490 struct intel_engine_execlists * const execlists = &engine->execlists;
491
492 execlists->csb_use_mmio = csb_force_mmio(engine->i915);
493
Mika Kuoppala76e70082017-09-22 15:43:07 +0300494 execlists->port_mask = 1;
495 BUILD_BUG_ON_NOT_POWER_OF_2(execlists_num_ports(execlists));
496 GEM_BUG_ON(execlists_num_ports(execlists) > EXECLIST_MAX_PORTS);
497
Chris Wilsonf6322ed2018-02-22 14:22:29 +0000498 execlists->queue_priority = INT_MIN;
Mika Kuoppala19df9a52017-09-22 15:43:04 +0300499 execlists->queue = RB_ROOT;
500 execlists->first = NULL;
501}
502
Tvrtko Ursulin019bf272016-07-13 16:03:41 +0100503/**
504 * intel_engines_setup_common - setup engine state not requiring hw access
505 * @engine: Engine to setup.
506 *
507 * Initializes @engine@ structure members shared between legacy and execlists
508 * submission modes which do not require hardware access.
509 *
510 * Typically done early in the submission mode specific engine setup stage.
511 */
512void intel_engine_setup_common(struct intel_engine_cs *engine)
513{
Mika Kuoppala19df9a52017-09-22 15:43:04 +0300514 intel_engine_init_execlist(engine);
Chris Wilson73cb9702016-10-28 13:58:46 +0100515 intel_engine_init_timeline(engine);
Tvrtko Ursulin019bf272016-07-13 16:03:41 +0100516 intel_engine_init_hangcheck(engine);
Michal Wajdeczkoc5781352018-03-08 09:50:35 +0000517 intel_engine_init_batch_pool(engine);
Chris Wilson7756e452016-08-18 17:17:10 +0100518 intel_engine_init_cmd_parser(engine);
Tvrtko Ursulin019bf272016-07-13 16:03:41 +0100519}
520
Chris Wilsonadc320c2016-08-15 10:48:59 +0100521int intel_engine_create_scratch(struct intel_engine_cs *engine, int size)
522{
523 struct drm_i915_gem_object *obj;
524 struct i915_vma *vma;
525 int ret;
526
527 WARN_ON(engine->scratch);
528
Tvrtko Ursulin187685c2016-12-01 14:16:36 +0000529 obj = i915_gem_object_create_stolen(engine->i915, size);
Chris Wilsonadc320c2016-08-15 10:48:59 +0100530 if (!obj)
Chris Wilson920cf412016-10-28 13:58:30 +0100531 obj = i915_gem_object_create_internal(engine->i915, size);
Chris Wilsonadc320c2016-08-15 10:48:59 +0100532 if (IS_ERR(obj)) {
533 DRM_ERROR("Failed to allocate scratch page\n");
534 return PTR_ERR(obj);
535 }
536
Chris Wilsona01cb372017-01-16 15:21:30 +0000537 vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL);
Chris Wilsonadc320c2016-08-15 10:48:59 +0100538 if (IS_ERR(vma)) {
539 ret = PTR_ERR(vma);
540 goto err_unref;
541 }
542
543 ret = i915_vma_pin(vma, 0, 4096, PIN_GLOBAL | PIN_HIGH);
544 if (ret)
545 goto err_unref;
546
547 engine->scratch = vma;
Chris Wilsonbde13eb2016-08-15 10:49:07 +0100548 DRM_DEBUG_DRIVER("%s pipe control offset: 0x%08x\n",
549 engine->name, i915_ggtt_offset(vma));
Chris Wilsonadc320c2016-08-15 10:48:59 +0100550 return 0;
551
552err_unref:
553 i915_gem_object_put(obj);
554 return ret;
555}
556
557static void intel_engine_cleanup_scratch(struct intel_engine_cs *engine)
558{
Chris Wilson19880c42016-08-15 10:49:05 +0100559 i915_vma_unpin_and_release(&engine->scratch);
Chris Wilsonadc320c2016-08-15 10:48:59 +0100560}
561
Daniele Ceraolo Spurio486e93f2017-09-13 09:56:02 +0100562static void cleanup_phys_status_page(struct intel_engine_cs *engine)
563{
564 struct drm_i915_private *dev_priv = engine->i915;
565
566 if (!dev_priv->status_page_dmah)
567 return;
568
569 drm_pci_free(&dev_priv->drm, dev_priv->status_page_dmah);
570 engine->status_page.page_addr = NULL;
571}
572
573static void cleanup_status_page(struct intel_engine_cs *engine)
574{
575 struct i915_vma *vma;
576 struct drm_i915_gem_object *obj;
577
578 vma = fetch_and_zero(&engine->status_page.vma);
579 if (!vma)
580 return;
581
582 obj = vma->obj;
583
584 i915_vma_unpin(vma);
585 i915_vma_close(vma);
586
587 i915_gem_object_unpin_map(obj);
588 __i915_gem_object_release_unless_active(obj);
589}
590
591static int init_status_page(struct intel_engine_cs *engine)
592{
593 struct drm_i915_gem_object *obj;
594 struct i915_vma *vma;
595 unsigned int flags;
596 void *vaddr;
597 int ret;
598
599 obj = i915_gem_object_create_internal(engine->i915, PAGE_SIZE);
600 if (IS_ERR(obj)) {
601 DRM_ERROR("Failed to allocate status page\n");
602 return PTR_ERR(obj);
603 }
604
605 ret = i915_gem_object_set_cache_level(obj, I915_CACHE_LLC);
606 if (ret)
607 goto err;
608
609 vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL);
610 if (IS_ERR(vma)) {
611 ret = PTR_ERR(vma);
612 goto err;
613 }
614
615 flags = PIN_GLOBAL;
616 if (!HAS_LLC(engine->i915))
617 /* On g33, we cannot place HWS above 256MiB, so
618 * restrict its pinning to the low mappable arena.
619 * Though this restriction is not documented for
620 * gen4, gen5, or byt, they also behave similarly
621 * and hang if the HWS is placed at the top of the
622 * GTT. To generalise, it appears that all !llc
623 * platforms have issues with us placing the HWS
624 * above the mappable region (even though we never
625 * actually map it).
626 */
627 flags |= PIN_MAPPABLE;
Chris Wilson34a04e52017-09-13 09:56:03 +0100628 else
629 flags |= PIN_HIGH;
Daniele Ceraolo Spurio486e93f2017-09-13 09:56:02 +0100630 ret = i915_vma_pin(vma, 0, 4096, flags);
631 if (ret)
632 goto err;
633
634 vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
635 if (IS_ERR(vaddr)) {
636 ret = PTR_ERR(vaddr);
637 goto err_unpin;
638 }
639
640 engine->status_page.vma = vma;
641 engine->status_page.ggtt_offset = i915_ggtt_offset(vma);
642 engine->status_page.page_addr = memset(vaddr, 0, PAGE_SIZE);
643
644 DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n",
645 engine->name, i915_ggtt_offset(vma));
646 return 0;
647
648err_unpin:
649 i915_vma_unpin(vma);
650err:
651 i915_gem_object_put(obj);
652 return ret;
653}
654
655static int init_phys_status_page(struct intel_engine_cs *engine)
656{
657 struct drm_i915_private *dev_priv = engine->i915;
658
659 GEM_BUG_ON(engine->id != RCS);
660
661 dev_priv->status_page_dmah =
662 drm_pci_alloc(&dev_priv->drm, PAGE_SIZE, PAGE_SIZE);
663 if (!dev_priv->status_page_dmah)
664 return -ENOMEM;
665
666 engine->status_page.page_addr = dev_priv->status_page_dmah->vaddr;
667 memset(engine->status_page.page_addr, 0, PAGE_SIZE);
668
669 return 0;
670}
671
Tvrtko Ursulin019bf272016-07-13 16:03:41 +0100672/**
673 * intel_engines_init_common - initialize cengine state which might require hw access
674 * @engine: Engine to initialize.
675 *
676 * Initializes @engine@ structure members shared between legacy and execlists
677 * submission modes which do require hardware access.
678 *
679 * Typcally done at later stages of submission mode specific engine setup.
680 *
681 * Returns zero on success or an error code on failure.
682 */
683int intel_engine_init_common(struct intel_engine_cs *engine)
684{
Chris Wilson266a2402017-05-04 10:33:08 +0100685 struct intel_ring *ring;
Tvrtko Ursulin019bf272016-07-13 16:03:41 +0100686 int ret;
687
Chris Wilsonff44ad52017-03-16 17:13:03 +0000688 engine->set_default_submission(engine);
689
Chris Wilsone8a9c582016-12-18 15:37:20 +0000690 /* We may need to do things with the shrinker which
691 * require us to immediately switch back to the default
692 * context. This can cause a problem as pinning the
693 * default context also requires GTT space which may not
694 * be available. To avoid this we always pin the default
695 * context.
696 */
Chris Wilson266a2402017-05-04 10:33:08 +0100697 ring = engine->context_pin(engine, engine->i915->kernel_context);
698 if (IS_ERR(ring))
699 return PTR_ERR(ring);
Tvrtko Ursulin019bf272016-07-13 16:03:41 +0100700
Chris Wilsone7af3112017-10-03 21:34:48 +0100701 /*
702 * Similarly the preempt context must always be available so that
703 * we can interrupt the engine at any time.
704 */
Chris Wilsond6376372018-02-07 21:05:44 +0000705 if (engine->i915->preempt_context) {
Chris Wilsone7af3112017-10-03 21:34:48 +0100706 ring = engine->context_pin(engine,
707 engine->i915->preempt_context);
708 if (IS_ERR(ring)) {
709 ret = PTR_ERR(ring);
710 goto err_unpin_kernel;
711 }
712 }
713
Chris Wilsone8a9c582016-12-18 15:37:20 +0000714 ret = intel_engine_init_breadcrumbs(engine);
715 if (ret)
Chris Wilsone7af3112017-10-03 21:34:48 +0100716 goto err_unpin_preempt;
Chris Wilsone8a9c582016-12-18 15:37:20 +0000717
Daniele Ceraolo Spurio486e93f2017-09-13 09:56:02 +0100718 if (HWS_NEEDS_PHYSICAL(engine->i915))
719 ret = init_phys_status_page(engine);
720 else
721 ret = init_status_page(engine);
722 if (ret)
Chris Wilson7c2fa7f2017-11-10 14:26:34 +0000723 goto err_breadcrumbs;
Chris Wilson4e50f082016-10-28 13:58:31 +0100724
Chris Wilson7756e452016-08-18 17:17:10 +0100725 return 0;
Chris Wilsone8a9c582016-12-18 15:37:20 +0000726
Daniele Ceraolo Spurio486e93f2017-09-13 09:56:02 +0100727err_breadcrumbs:
728 intel_engine_fini_breadcrumbs(engine);
Chris Wilsone7af3112017-10-03 21:34:48 +0100729err_unpin_preempt:
Chris Wilsond6376372018-02-07 21:05:44 +0000730 if (engine->i915->preempt_context)
Chris Wilsone7af3112017-10-03 21:34:48 +0100731 engine->context_unpin(engine, engine->i915->preempt_context);
732err_unpin_kernel:
Chris Wilsone8a9c582016-12-18 15:37:20 +0000733 engine->context_unpin(engine, engine->i915->kernel_context);
734 return ret;
Tvrtko Ursulin019bf272016-07-13 16:03:41 +0100735}
Chris Wilson96a945a2016-08-03 13:19:16 +0100736
737/**
738 * intel_engines_cleanup_common - cleans up the engine state created by
739 * the common initiailizers.
740 * @engine: Engine to cleanup.
741 *
742 * This cleans up everything created by the common helpers.
743 */
744void intel_engine_cleanup_common(struct intel_engine_cs *engine)
745{
Chris Wilsonadc320c2016-08-15 10:48:59 +0100746 intel_engine_cleanup_scratch(engine);
747
Daniele Ceraolo Spurio486e93f2017-09-13 09:56:02 +0100748 if (HWS_NEEDS_PHYSICAL(engine->i915))
749 cleanup_phys_status_page(engine);
750 else
751 cleanup_status_page(engine);
752
Chris Wilson96a945a2016-08-03 13:19:16 +0100753 intel_engine_fini_breadcrumbs(engine);
Chris Wilson7756e452016-08-18 17:17:10 +0100754 intel_engine_cleanup_cmd_parser(engine);
Chris Wilson96a945a2016-08-03 13:19:16 +0100755 i915_gem_batch_pool_fini(&engine->batch_pool);
Chris Wilsone8a9c582016-12-18 15:37:20 +0000756
Chris Wilsond2b4b972017-11-10 14:26:33 +0000757 if (engine->default_state)
758 i915_gem_object_put(engine->default_state);
759
Chris Wilsond6376372018-02-07 21:05:44 +0000760 if (engine->i915->preempt_context)
Chris Wilsone7af3112017-10-03 21:34:48 +0100761 engine->context_unpin(engine, engine->i915->preempt_context);
Chris Wilsone8a9c582016-12-18 15:37:20 +0000762 engine->context_unpin(engine, engine->i915->kernel_context);
Chris Wilson96a945a2016-08-03 13:19:16 +0100763}
Chris Wilson1b365952016-10-04 21:11:31 +0100764
Chris Wilson3ceda3a2018-02-12 10:24:15 +0000765u64 intel_engine_get_active_head(const struct intel_engine_cs *engine)
Chris Wilson1b365952016-10-04 21:11:31 +0100766{
767 struct drm_i915_private *dev_priv = engine->i915;
768 u64 acthd;
769
770 if (INTEL_GEN(dev_priv) >= 8)
771 acthd = I915_READ64_2x32(RING_ACTHD(engine->mmio_base),
772 RING_ACTHD_UDW(engine->mmio_base));
773 else if (INTEL_GEN(dev_priv) >= 4)
774 acthd = I915_READ(RING_ACTHD(engine->mmio_base));
775 else
776 acthd = I915_READ(ACTHD);
777
778 return acthd;
779}
780
Chris Wilson3ceda3a2018-02-12 10:24:15 +0000781u64 intel_engine_get_last_batch_head(const struct intel_engine_cs *engine)
Chris Wilson1b365952016-10-04 21:11:31 +0100782{
783 struct drm_i915_private *dev_priv = engine->i915;
784 u64 bbaddr;
785
786 if (INTEL_GEN(dev_priv) >= 8)
787 bbaddr = I915_READ64_2x32(RING_BBADDR(engine->mmio_base),
788 RING_BBADDR_UDW(engine->mmio_base));
789 else
790 bbaddr = I915_READ(RING_BBADDR(engine->mmio_base));
791
792 return bbaddr;
793}
Chris Wilson0e704472016-10-12 10:05:17 +0100794
795const char *i915_cache_level_str(struct drm_i915_private *i915, int type)
796{
797 switch (type) {
798 case I915_CACHE_NONE: return " uncached";
799 case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped";
800 case I915_CACHE_L3_LLC: return " L3+LLC";
801 case I915_CACHE_WT: return " WT";
802 default: return "";
803 }
804}
805
806static inline uint32_t
807read_subslice_reg(struct drm_i915_private *dev_priv, int slice,
808 int subslice, i915_reg_t reg)
809{
810 uint32_t mcr;
811 uint32_t ret;
812 enum forcewake_domains fw_domains;
813
814 fw_domains = intel_uncore_forcewake_for_reg(dev_priv, reg,
815 FW_REG_READ);
816 fw_domains |= intel_uncore_forcewake_for_reg(dev_priv,
817 GEN8_MCR_SELECTOR,
818 FW_REG_READ | FW_REG_WRITE);
819
820 spin_lock_irq(&dev_priv->uncore.lock);
821 intel_uncore_forcewake_get__locked(dev_priv, fw_domains);
822
823 mcr = I915_READ_FW(GEN8_MCR_SELECTOR);
824 /*
825 * The HW expects the slice and sublice selectors to be reset to 0
826 * after reading out the registers.
827 */
828 WARN_ON_ONCE(mcr & (GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK));
829 mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK);
830 mcr |= GEN8_MCR_SLICE(slice) | GEN8_MCR_SUBSLICE(subslice);
831 I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr);
832
833 ret = I915_READ_FW(reg);
834
835 mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK);
836 I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr);
837
838 intel_uncore_forcewake_put__locked(dev_priv, fw_domains);
839 spin_unlock_irq(&dev_priv->uncore.lock);
840
841 return ret;
842}
843
844/* NB: please notice the memset */
845void intel_engine_get_instdone(struct intel_engine_cs *engine,
846 struct intel_instdone *instdone)
847{
848 struct drm_i915_private *dev_priv = engine->i915;
849 u32 mmio_base = engine->mmio_base;
850 int slice;
851 int subslice;
852
853 memset(instdone, 0, sizeof(*instdone));
854
855 switch (INTEL_GEN(dev_priv)) {
856 default:
857 instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
858
859 if (engine->id != RCS)
860 break;
861
862 instdone->slice_common = I915_READ(GEN7_SC_INSTDONE);
863 for_each_instdone_slice_subslice(dev_priv, slice, subslice) {
864 instdone->sampler[slice][subslice] =
865 read_subslice_reg(dev_priv, slice, subslice,
866 GEN7_SAMPLER_INSTDONE);
867 instdone->row[slice][subslice] =
868 read_subslice_reg(dev_priv, slice, subslice,
869 GEN7_ROW_INSTDONE);
870 }
871 break;
872 case 7:
873 instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
874
875 if (engine->id != RCS)
876 break;
877
878 instdone->slice_common = I915_READ(GEN7_SC_INSTDONE);
879 instdone->sampler[0][0] = I915_READ(GEN7_SAMPLER_INSTDONE);
880 instdone->row[0][0] = I915_READ(GEN7_ROW_INSTDONE);
881
882 break;
883 case 6:
884 case 5:
885 case 4:
886 instdone->instdone = I915_READ(RING_INSTDONE(mmio_base));
887
888 if (engine->id == RCS)
889 /* HACK: Using the wrong struct member */
890 instdone->slice_common = I915_READ(GEN4_INSTDONE1);
891 break;
892 case 3:
893 case 2:
894 instdone->instdone = I915_READ(GEN2_INSTDONE);
895 break;
896 }
897}
Chris Wilsonf97fbf92017-02-13 17:15:14 +0000898
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +0000899static int wa_add(struct drm_i915_private *dev_priv,
900 i915_reg_t addr,
901 const u32 mask, const u32 val)
902{
903 const u32 idx = dev_priv->workarounds.count;
904
905 if (WARN_ON(idx >= I915_MAX_WA_REGS))
906 return -ENOSPC;
907
908 dev_priv->workarounds.reg[idx].addr = addr;
909 dev_priv->workarounds.reg[idx].value = val;
910 dev_priv->workarounds.reg[idx].mask = mask;
911
912 dev_priv->workarounds.count++;
913
914 return 0;
915}
916
917#define WA_REG(addr, mask, val) do { \
918 const int r = wa_add(dev_priv, (addr), (mask), (val)); \
919 if (r) \
920 return r; \
921 } while (0)
922
923#define WA_SET_BIT_MASKED(addr, mask) \
924 WA_REG(addr, (mask), _MASKED_BIT_ENABLE(mask))
925
926#define WA_CLR_BIT_MASKED(addr, mask) \
927 WA_REG(addr, (mask), _MASKED_BIT_DISABLE(mask))
928
929#define WA_SET_FIELD_MASKED(addr, mask, value) \
930 WA_REG(addr, mask, _MASKED_FIELD(mask, value))
931
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +0000932static int wa_ring_whitelist_reg(struct intel_engine_cs *engine,
933 i915_reg_t reg)
934{
935 struct drm_i915_private *dev_priv = engine->i915;
936 struct i915_workarounds *wa = &dev_priv->workarounds;
937 const uint32_t index = wa->hw_whitelist_count[engine->id];
938
939 if (WARN_ON(index >= RING_MAX_NONPRIV_SLOTS))
940 return -EINVAL;
941
Oscar Mateo32ced392017-09-28 15:40:39 -0700942 I915_WRITE(RING_FORCE_TO_NONPRIV(engine->mmio_base, index),
943 i915_mmio_reg_offset(reg));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +0000944 wa->hw_whitelist_count[engine->id]++;
945
946 return 0;
947}
948
949static int gen8_init_workarounds(struct intel_engine_cs *engine)
950{
951 struct drm_i915_private *dev_priv = engine->i915;
952
953 WA_SET_BIT_MASKED(INSTPM, INSTPM_FORCE_ORDERING);
954
955 /* WaDisableAsyncFlipPerfMode:bdw,chv */
956 WA_SET_BIT_MASKED(MI_MODE, ASYNC_FLIP_PERF_DISABLE);
957
958 /* WaDisablePartialInstShootdown:bdw,chv */
959 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
960 PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
961
962 /* Use Force Non-Coherent whenever executing a 3D context. This is a
963 * workaround for for a possible hang in the unlikely event a TLB
964 * invalidation occurs during a PSD flush.
965 */
966 /* WaForceEnableNonCoherent:bdw,chv */
967 /* WaHdcDisableFetchWhenMasked:bdw,chv */
968 WA_SET_BIT_MASKED(HDC_CHICKEN0,
969 HDC_DONOT_FETCH_MEM_WHEN_MASKED |
970 HDC_FORCE_NON_COHERENT);
971
972 /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0:
973 * "The Hierarchical Z RAW Stall Optimization allows non-overlapping
974 * polygons in the same 8x4 pixel/sample area to be processed without
975 * stalling waiting for the earlier ones to write to Hierarchical Z
976 * buffer."
977 *
978 * This optimization is off by default for BDW and CHV; turn it on.
979 */
980 WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE);
981
982 /* Wa4x4STCOptimizationDisable:bdw,chv */
983 WA_SET_BIT_MASKED(CACHE_MODE_1, GEN8_4x4_STC_OPTIMIZATION_DISABLE);
984
985 /*
986 * BSpec recommends 8x4 when MSAA is used,
987 * however in practice 16x4 seems fastest.
988 *
989 * Note that PS/WM thread counts depend on the WIZ hashing
990 * disable bit, which we don't touch here, but it's good
991 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
992 */
993 WA_SET_FIELD_MASKED(GEN7_GT_MODE,
994 GEN6_WIZ_HASHING_MASK,
995 GEN6_WIZ_HASHING_16x4);
996
997 return 0;
998}
999
1000static int bdw_init_workarounds(struct intel_engine_cs *engine)
1001{
1002 struct drm_i915_private *dev_priv = engine->i915;
1003 int ret;
1004
1005 ret = gen8_init_workarounds(engine);
1006 if (ret)
1007 return ret;
1008
1009 /* WaDisableThreadStallDopClockGating:bdw (pre-production) */
1010 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
1011
1012 /* WaDisableDopClockGating:bdw
1013 *
1014 * Also see the related UCGTCL1 write in broadwell_init_clock_gating()
1015 * to disable EUTC clock gating.
1016 */
1017 WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2,
1018 DOP_CLOCK_GATING_DISABLE);
1019
1020 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
1021 GEN8_SAMPLER_POWER_BYPASS_DIS);
1022
1023 WA_SET_BIT_MASKED(HDC_CHICKEN0,
1024 /* WaForceContextSaveRestoreNonCoherent:bdw */
1025 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
1026 /* WaDisableFenceDestinationToSLM:bdw (pre-prod) */
1027 (IS_BDW_GT3(dev_priv) ? HDC_FENCE_DEST_SLM_DISABLE : 0));
1028
1029 return 0;
1030}
1031
1032static int chv_init_workarounds(struct intel_engine_cs *engine)
1033{
1034 struct drm_i915_private *dev_priv = engine->i915;
1035 int ret;
1036
1037 ret = gen8_init_workarounds(engine);
1038 if (ret)
1039 return ret;
1040
1041 /* WaDisableThreadStallDopClockGating:chv */
1042 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
1043
1044 /* Improve HiZ throughput on CHV. */
1045 WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X);
1046
1047 return 0;
1048}
1049
1050static int gen9_init_workarounds(struct intel_engine_cs *engine)
1051{
1052 struct drm_i915_private *dev_priv = engine->i915;
1053 int ret;
1054
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001055 /* WaConextSwitchWithConcurrentTLBInvalidate:skl,bxt,kbl,glk,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001056 I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, _MASKED_BIT_ENABLE(GEN9_PREEMPT_GPGPU_SYNC_SWITCH_DISABLE));
1057
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001058 /* WaEnableLbsSlaRetryTimerDecrement:skl,bxt,kbl,glk,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001059 I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) |
1060 GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE);
1061
Rodrigo Vivi98eed3d2017-06-19 14:21:47 -07001062 /* WaDisableKillLogic:bxt,skl,kbl */
1063 if (!IS_COFFEELAKE(dev_priv))
1064 I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) |
1065 ECOCHK_DIS_TLB);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001066
Ville Syrjälä93564042017-08-24 22:10:51 +03001067 if (HAS_LLC(dev_priv)) {
1068 /* WaCompressedResourceSamplerPbeMediaNewHashMode:skl,kbl
1069 *
1070 * Must match Display Engine. See
1071 * WaCompressedResourceDisplayNewHashMode.
1072 */
1073 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1074 GEN9_PBE_COMPRESSED_HASH_SELECTION);
1075 WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7,
1076 GEN9_SAMPLER_HASH_COMPRESSED_READ_ADDR);
Chris Wilson53221e12017-10-04 13:41:52 +01001077
1078 I915_WRITE(MMCD_MISC_CTRL,
1079 I915_READ(MMCD_MISC_CTRL) |
1080 MMCD_PCLA |
1081 MMCD_HOTSPOT_EN);
Ville Syrjälä93564042017-08-24 22:10:51 +03001082 }
1083
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001084 /* WaClearFlowControlGpgpuContextSave:skl,bxt,kbl,glk,cfl */
1085 /* WaDisablePartialInstShootdown:skl,bxt,kbl,glk,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001086 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
1087 FLOW_CONTROL_ENABLE |
1088 PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
1089
1090 /* Syncing dependencies between camera and graphics:skl,bxt,kbl */
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001091 if (!IS_COFFEELAKE(dev_priv))
1092 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
1093 GEN9_DISABLE_OCL_OOB_SUPPRESS_LOGIC);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001094
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001095 /* WaEnableYV12BugFixInHalfSliceChicken7:skl,bxt,kbl,glk,cfl */
1096 /* WaEnableSamplerGPGPUPreemptionSupport:skl,bxt,kbl,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001097 WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7,
Arkadiusz Hiler0b71cea2017-05-12 13:20:15 +02001098 GEN9_ENABLE_YV12_BUGFIX |
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001099 GEN9_ENABLE_GPGPU_PREEMPTION);
1100
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001101 /* Wa4x4STCOptimizationDisable:skl,bxt,kbl,glk,cfl */
1102 /* WaDisablePartialResolveInVc:skl,bxt,kbl,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001103 WA_SET_BIT_MASKED(CACHE_MODE_1, (GEN8_4x4_STC_OPTIMIZATION_DISABLE |
1104 GEN9_PARTIAL_RESOLVE_IN_VC_DISABLE));
1105
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001106 /* WaCcsTlbPrefetchDisable:skl,bxt,kbl,glk,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001107 WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5,
1108 GEN9_CCS_TLB_PREFETCH_ENABLE);
1109
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001110 /* WaForceContextSaveRestoreNonCoherent:skl,bxt,kbl,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001111 WA_SET_BIT_MASKED(HDC_CHICKEN0,
1112 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
1113 HDC_FORCE_CSR_NON_COHERENT_OVR_DISABLE);
1114
1115 /* WaForceEnableNonCoherent and WaDisableHDCInvalidation are
1116 * both tied to WaForceContextSaveRestoreNonCoherent
1117 * in some hsds for skl. We keep the tie for all gen9. The
1118 * documentation is a bit hazy and so we want to get common behaviour,
1119 * even though there is no clear evidence we would need both on kbl/bxt.
1120 * This area has been source of system hangs so we play it safe
1121 * and mimic the skl regardless of what bspec says.
1122 *
1123 * Use Force Non-Coherent whenever executing a 3D context. This
1124 * is a workaround for a possible hang in the unlikely event
1125 * a TLB invalidation occurs during a PSD flush.
1126 */
1127
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001128 /* WaForceEnableNonCoherent:skl,bxt,kbl,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001129 WA_SET_BIT_MASKED(HDC_CHICKEN0,
1130 HDC_FORCE_NON_COHERENT);
1131
Rodrigo Vivi98eed3d2017-06-19 14:21:47 -07001132 /* WaDisableHDCInvalidation:skl,bxt,kbl,cfl */
1133 I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) |
1134 BDW_DISABLE_HDC_INVALIDATION);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001135
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001136 /* WaDisableSamplerPowerBypassForSOPingPong:skl,bxt,kbl,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001137 if (IS_SKYLAKE(dev_priv) ||
1138 IS_KABYLAKE(dev_priv) ||
Chris Wilsonf3e2b2c2017-11-14 13:43:39 +00001139 IS_COFFEELAKE(dev_priv))
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001140 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
1141 GEN8_SAMPLER_POWER_BYPASS_DIS);
1142
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001143 /* WaDisableSTUnitPowerOptimization:skl,bxt,kbl,glk,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001144 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN2, GEN8_ST_PO_DISABLE);
1145
Valtteri Rantala74368302017-11-28 16:45:05 +02001146 /* WaProgramL3SqcReg1DefaultForPerf:bxt,glk */
1147 if (IS_GEN9_LP(dev_priv)) {
1148 u32 val = I915_READ(GEN8_L3SQCREG1);
1149
1150 val &= ~L3_PRIO_CREDITS_MASK;
1151 val |= L3_GENERAL_PRIO_CREDITS(62) | L3_HIGH_PRIO_CREDITS(2);
1152 I915_WRITE(GEN8_L3SQCREG1, val);
1153 }
1154
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001155 /* WaOCLCoherentLineFlush:skl,bxt,kbl,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001156 I915_WRITE(GEN8_L3SQCREG4, (I915_READ(GEN8_L3SQCREG4) |
1157 GEN8_LQSC_FLUSH_COHERENT_LINES));
1158
Michał Winiarski5152def2017-10-03 21:34:46 +01001159 /*
1160 * Supporting preemption with fine-granularity requires changes in the
1161 * batch buffer programming. Since we can't break old userspace, we
1162 * need to set our default preemption level to safe value. Userspace is
1163 * still able to use more fine-grained preemption levels, since in
1164 * WaEnablePreemptionGranularityControlByUMD we're whitelisting the
1165 * per-ctx register. As such, WaDisable{3D,GPGPU}MidCmdPreemption are
1166 * not real HW workarounds, but merely a way to start using preemption
1167 * while maintaining old contract with userspace.
1168 */
1169
1170 /* WaDisable3DMidCmdPreemption:skl,bxt,glk,cfl,[cnl] */
1171 WA_CLR_BIT_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_3D_OBJECT_LEVEL);
1172
1173 /* WaDisableGPGPUMidCmdPreemption:skl,bxt,blk,cfl,[cnl] */
1174 WA_SET_FIELD_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_GPGPU_LEVEL_MASK,
1175 GEN9_PREEMPT_GPGPU_COMMAND_LEVEL);
1176
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001177 /* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001178 ret = wa_ring_whitelist_reg(engine, GEN9_CTX_PREEMPT_REG);
1179 if (ret)
1180 return ret;
1181
Jeff McGee1e998342017-10-03 21:34:45 +01001182 /* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl,cfl,[cnl] */
1183 I915_WRITE(GEN7_FF_SLICE_CS_CHICKEN1,
1184 _MASKED_BIT_ENABLE(GEN9_FFSC_PERCTX_PREEMPT_CTRL));
1185 ret = wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001186 if (ret)
1187 return ret;
1188
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001189 /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk,cfl */
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001190 ret = wa_ring_whitelist_reg(engine, GEN8_HDC_CHICKEN1);
1191 if (ret)
1192 return ret;
1193
1194 return 0;
1195}
1196
1197static int skl_tune_iz_hashing(struct intel_engine_cs *engine)
1198{
1199 struct drm_i915_private *dev_priv = engine->i915;
1200 u8 vals[3] = { 0, 0, 0 };
1201 unsigned int i;
1202
1203 for (i = 0; i < 3; i++) {
1204 u8 ss;
1205
1206 /*
1207 * Only consider slices where one, and only one, subslice has 7
1208 * EUs
1209 */
1210 if (!is_power_of_2(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i]))
1211 continue;
1212
1213 /*
1214 * subslice_7eu[i] != 0 (because of the check above) and
1215 * ss_max == 4 (maximum number of subslices possible per slice)
1216 *
1217 * -> 0 <= ss <= 3;
1218 */
1219 ss = ffs(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i]) - 1;
1220 vals[i] = 3 - ss;
1221 }
1222
1223 if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0)
1224 return 0;
1225
1226 /* Tune IZ hashing. See intel_device_info_runtime_init() */
1227 WA_SET_FIELD_MASKED(GEN7_GT_MODE,
1228 GEN9_IZ_HASHING_MASK(2) |
1229 GEN9_IZ_HASHING_MASK(1) |
1230 GEN9_IZ_HASHING_MASK(0),
1231 GEN9_IZ_HASHING(2, vals[2]) |
1232 GEN9_IZ_HASHING(1, vals[1]) |
1233 GEN9_IZ_HASHING(0, vals[0]));
1234
1235 return 0;
1236}
1237
1238static int skl_init_workarounds(struct intel_engine_cs *engine)
1239{
1240 struct drm_i915_private *dev_priv = engine->i915;
1241 int ret;
1242
1243 ret = gen9_init_workarounds(engine);
1244 if (ret)
1245 return ret;
1246
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001247 /* WaEnableGapsTsvCreditFix:skl */
1248 I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) |
1249 GEN9_GAPS_TSV_CREDIT_DISABLE));
1250
1251 /* WaDisableGafsUnitClkGating:skl */
Oscar Mateo4827c542017-09-07 08:40:07 -07001252 I915_WRITE(GEN7_UCGCTL4, (I915_READ(GEN7_UCGCTL4) |
1253 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001254
1255 /* WaInPlaceDecompressionHang:skl */
1256 if (IS_SKL_REVID(dev_priv, SKL_REVID_H0, REVID_FOREVER))
Oscar Mateoefc886c2017-09-07 08:40:04 -07001257 I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA,
1258 (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) |
1259 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001260
1261 /* WaDisableLSQCROPERFforOCL:skl */
1262 ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
1263 if (ret)
1264 return ret;
1265
1266 return skl_tune_iz_hashing(engine);
1267}
1268
1269static int bxt_init_workarounds(struct intel_engine_cs *engine)
1270{
1271 struct drm_i915_private *dev_priv = engine->i915;
1272 int ret;
1273
1274 ret = gen9_init_workarounds(engine);
1275 if (ret)
1276 return ret;
1277
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001278 /* WaDisableThreadStallDopClockGating:bxt */
1279 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
1280 STALL_DOP_GATING_DISABLE);
1281
1282 /* WaDisablePooledEuLoadBalancingFix:bxt */
Chris Wilson70a84f32017-11-14 13:43:40 +00001283 I915_WRITE(FF_SLICE_CS_CHICKEN2,
1284 _MASKED_BIT_ENABLE(GEN9_POOLED_EU_LOAD_BALANCING_FIX_DISABLE));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001285
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001286 /* WaToEnableHwFixForPushConstHWBug:bxt */
Chris Wilson70a84f32017-11-14 13:43:40 +00001287 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1288 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001289
1290 /* WaInPlaceDecompressionHang:bxt */
Chris Wilson70a84f32017-11-14 13:43:40 +00001291 I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA,
1292 (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) |
1293 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001294
1295 return 0;
1296}
1297
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07001298static int cnl_init_workarounds(struct intel_engine_cs *engine)
1299{
1300 struct drm_i915_private *dev_priv = engine->i915;
1301 int ret;
1302
Oscar Mateo6cf20a02017-09-07 08:40:05 -07001303 /* WaDisableI2mCycleOnWRPort:cnl (pre-prod) */
Rodrigo Vivi86ebb012017-08-29 16:07:51 -07001304 if (IS_CNL_REVID(dev_priv, CNL_REVID_B0, CNL_REVID_B0))
Oscar Mateo6cf20a02017-09-07 08:40:05 -07001305 I915_WRITE(GAMT_CHKN_BIT_REG,
1306 (I915_READ(GAMT_CHKN_BIT_REG) |
1307 GAMT_CHKN_DISABLE_I2M_CYCLE_ON_WR_PORT));
Rodrigo Vivi86ebb012017-08-29 16:07:51 -07001308
Rodrigo Viviacfb5552017-08-23 13:35:04 -07001309 /* WaForceContextSaveRestoreNonCoherent:cnl */
1310 WA_SET_BIT_MASKED(CNL_HDC_CHICKEN0,
1311 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT);
1312
Rodrigo Viviaa9f4c42017-09-06 15:03:25 -07001313 /* WaThrottleEUPerfToAvoidTDBackPressure:cnl(pre-prod) */
1314 if (IS_CNL_REVID(dev_priv, CNL_REVID_B0, CNL_REVID_B0))
1315 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, THROTTLE_12_5);
1316
Rodrigo Vivie6d1a4f2017-08-15 16:16:49 -07001317 /* WaDisableReplayBufferBankArbitrationOptimization:cnl */
1318 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1319 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
1320
Rodrigo Vivid1d24752017-08-15 16:16:50 -07001321 /* WaDisableEnhancedSBEVertexCaching:cnl (pre-prod) */
1322 if (IS_CNL_REVID(dev_priv, 0, CNL_REVID_B0))
1323 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1324 GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE);
1325
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07001326 /* WaInPlaceDecompressionHang:cnl */
Oscar Mateoefc886c2017-09-07 08:40:04 -07001327 I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA,
1328 (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) |
1329 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS));
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07001330
Oscar Mateo2cbecff2017-08-23 12:56:31 -07001331 /* WaPushConstantDereferenceHoldDisable:cnl */
Oscar Mateob27f5902017-09-07 08:40:06 -07001332 WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2, PUSH_CONSTANT_DEREF_DISABLE);
Oscar Mateo2cbecff2017-08-23 12:56:31 -07001333
Rodrigo Vivi392572f2017-08-29 16:07:23 -07001334 /* FtrEnableFastAnisoL1BankingFix: cnl */
1335 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, CNL_FAST_ANISO_L1_BANKING_FIX);
1336
Michał Winiarski5152def2017-10-03 21:34:46 +01001337 /* WaDisable3DMidCmdPreemption:cnl */
1338 WA_CLR_BIT_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_3D_OBJECT_LEVEL);
1339
1340 /* WaDisableGPGPUMidCmdPreemption:cnl */
1341 WA_SET_FIELD_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_GPGPU_LEVEL_MASK,
1342 GEN9_PREEMPT_GPGPU_COMMAND_LEVEL);
1343
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07001344 /* WaEnablePreemptionGranularityControlByUMD:cnl */
Jeff McGee1e998342017-10-03 21:34:45 +01001345 I915_WRITE(GEN7_FF_SLICE_CS_CHICKEN1,
1346 _MASKED_BIT_ENABLE(GEN9_FFSC_PERCTX_PREEMPT_CTRL));
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07001347 ret= wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1);
1348 if (ret)
1349 return ret;
1350
Rafael Antognollia2b16582017-12-15 16:11:17 -08001351 /* WaDisableEarlyEOT:cnl */
1352 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, DISABLE_EARLY_EOT);
1353
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07001354 return 0;
1355}
1356
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001357static int kbl_init_workarounds(struct intel_engine_cs *engine)
1358{
1359 struct drm_i915_private *dev_priv = engine->i915;
1360 int ret;
1361
1362 ret = gen9_init_workarounds(engine);
1363 if (ret)
1364 return ret;
1365
1366 /* WaEnableGapsTsvCreditFix:kbl */
1367 I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) |
1368 GEN9_GAPS_TSV_CREDIT_DISABLE));
1369
1370 /* WaDisableDynamicCreditSharing:kbl */
1371 if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0))
Oscar Mateoc6ea497c2017-09-07 08:40:08 -07001372 I915_WRITE(GAMT_CHKN_BIT_REG,
1373 (I915_READ(GAMT_CHKN_BIT_REG) |
1374 GAMT_CHKN_DISABLE_DYNAMIC_CREDIT_SHARING));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001375
1376 /* WaDisableFenceDestinationToSLM:kbl (pre-prod) */
1377 if (IS_KBL_REVID(dev_priv, KBL_REVID_A0, KBL_REVID_A0))
1378 WA_SET_BIT_MASKED(HDC_CHICKEN0,
1379 HDC_FENCE_DEST_SLM_DISABLE);
1380
1381 /* WaToEnableHwFixForPushConstHWBug:kbl */
1382 if (IS_KBL_REVID(dev_priv, KBL_REVID_C0, REVID_FOREVER))
1383 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1384 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
1385
1386 /* WaDisableGafsUnitClkGating:kbl */
Oscar Mateo4827c542017-09-07 08:40:07 -07001387 I915_WRITE(GEN7_UCGCTL4, (I915_READ(GEN7_UCGCTL4) |
1388 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001389
1390 /* WaDisableSbeCacheDispatchPortSharing:kbl */
1391 WA_SET_BIT_MASKED(
1392 GEN7_HALF_SLICE_CHICKEN1,
1393 GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
1394
1395 /* WaInPlaceDecompressionHang:kbl */
Oscar Mateoefc886c2017-09-07 08:40:04 -07001396 I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA,
1397 (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) |
1398 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS));
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001399
1400 /* WaDisableLSQCROPERFforOCL:kbl */
1401 ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
1402 if (ret)
1403 return ret;
1404
1405 return 0;
1406}
1407
1408static int glk_init_workarounds(struct intel_engine_cs *engine)
1409{
1410 struct drm_i915_private *dev_priv = engine->i915;
1411 int ret;
1412
1413 ret = gen9_init_workarounds(engine);
1414 if (ret)
1415 return ret;
1416
Kenneth Graunkeab062632018-01-05 00:59:05 -08001417 /* WA #0862: Userspace has to set "Barrier Mode" to avoid hangs. */
1418 ret = wa_ring_whitelist_reg(engine, GEN9_SLICE_COMMON_ECO_CHICKEN1);
1419 if (ret)
1420 return ret;
1421
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001422 /* WaToEnableHwFixForPushConstHWBug:glk */
1423 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1424 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
1425
1426 return 0;
1427}
1428
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001429static int cfl_init_workarounds(struct intel_engine_cs *engine)
1430{
1431 struct drm_i915_private *dev_priv = engine->i915;
1432 int ret;
1433
1434 ret = gen9_init_workarounds(engine);
1435 if (ret)
1436 return ret;
1437
1438 /* WaEnableGapsTsvCreditFix:cfl */
1439 I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) |
1440 GEN9_GAPS_TSV_CREDIT_DISABLE));
1441
1442 /* WaToEnableHwFixForPushConstHWBug:cfl */
1443 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
1444 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
1445
1446 /* WaDisableGafsUnitClkGating:cfl */
Oscar Mateo4827c542017-09-07 08:40:07 -07001447 I915_WRITE(GEN7_UCGCTL4, (I915_READ(GEN7_UCGCTL4) |
1448 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE));
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001449
1450 /* WaDisableSbeCacheDispatchPortSharing:cfl */
1451 WA_SET_BIT_MASKED(
1452 GEN7_HALF_SLICE_CHICKEN1,
1453 GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
1454
1455 /* WaInPlaceDecompressionHang:cfl */
Oscar Mateoefc886c2017-09-07 08:40:04 -07001456 I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA,
1457 (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) |
1458 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS));
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001459
1460 return 0;
1461}
1462
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001463int init_workarounds_ring(struct intel_engine_cs *engine)
1464{
1465 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson02e012f2017-03-01 12:11:31 +00001466 int err;
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001467
Tvrtko Ursulinae504be2018-01-19 10:00:03 +00001468 if (GEM_WARN_ON(engine->id != RCS))
1469 return -EINVAL;
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001470
1471 dev_priv->workarounds.count = 0;
Chris Wilson02e012f2017-03-01 12:11:31 +00001472 dev_priv->workarounds.hw_whitelist_count[engine->id] = 0;
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001473
1474 if (IS_BROADWELL(dev_priv))
Chris Wilson02e012f2017-03-01 12:11:31 +00001475 err = bdw_init_workarounds(engine);
1476 else if (IS_CHERRYVIEW(dev_priv))
1477 err = chv_init_workarounds(engine);
1478 else if (IS_SKYLAKE(dev_priv))
1479 err = skl_init_workarounds(engine);
1480 else if (IS_BROXTON(dev_priv))
1481 err = bxt_init_workarounds(engine);
1482 else if (IS_KABYLAKE(dev_priv))
1483 err = kbl_init_workarounds(engine);
1484 else if (IS_GEMINILAKE(dev_priv))
1485 err = glk_init_workarounds(engine);
Rodrigo Vivi46c26662017-06-16 15:49:58 -07001486 else if (IS_COFFEELAKE(dev_priv))
1487 err = cfl_init_workarounds(engine);
Rodrigo Vivi90007bc2017-08-15 16:16:48 -07001488 else if (IS_CANNONLAKE(dev_priv))
1489 err = cnl_init_workarounds(engine);
Chris Wilson02e012f2017-03-01 12:11:31 +00001490 else
1491 err = 0;
1492 if (err)
1493 return err;
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001494
Chris Wilson02e012f2017-03-01 12:11:31 +00001495 DRM_DEBUG_DRIVER("%s: Number of context specific w/a: %d\n",
1496 engine->name, dev_priv->workarounds.count);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001497 return 0;
1498}
1499
Chris Wilsone61e0f52018-02-21 09:56:36 +00001500int intel_ring_workarounds_emit(struct i915_request *rq)
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001501{
Chris Wilsone61e0f52018-02-21 09:56:36 +00001502 struct i915_workarounds *w = &rq->i915->workarounds;
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001503 u32 *cs;
1504 int ret, i;
1505
1506 if (w->count == 0)
1507 return 0;
1508
Chris Wilsone61e0f52018-02-21 09:56:36 +00001509 ret = rq->engine->emit_flush(rq, EMIT_BARRIER);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001510 if (ret)
1511 return ret;
1512
Chris Wilsone61e0f52018-02-21 09:56:36 +00001513 cs = intel_ring_begin(rq, w->count * 2 + 2);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001514 if (IS_ERR(cs))
1515 return PTR_ERR(cs);
1516
1517 *cs++ = MI_LOAD_REGISTER_IMM(w->count);
1518 for (i = 0; i < w->count; i++) {
1519 *cs++ = i915_mmio_reg_offset(w->reg[i].addr);
1520 *cs++ = w->reg[i].value;
1521 }
1522 *cs++ = MI_NOOP;
1523
Chris Wilsone61e0f52018-02-21 09:56:36 +00001524 intel_ring_advance(rq, cs);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001525
Chris Wilsone61e0f52018-02-21 09:56:36 +00001526 ret = rq->engine->emit_flush(rq, EMIT_BARRIER);
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001527 if (ret)
1528 return ret;
1529
Tvrtko Ursulin133b4bd2017-02-16 12:23:23 +00001530 return 0;
1531}
1532
Chris Wilsona091d4e2017-05-30 13:13:33 +01001533static bool ring_is_idle(struct intel_engine_cs *engine)
1534{
1535 struct drm_i915_private *dev_priv = engine->i915;
1536 bool idle = true;
1537
Chris Wilson74d00d22018-02-12 09:39:28 +00001538 /* If the whole device is asleep, the engine must be idle */
1539 if (!intel_runtime_pm_get_if_in_use(dev_priv))
1540 return true;
Chris Wilsona091d4e2017-05-30 13:13:33 +01001541
Chris Wilsonaed2fc12017-05-30 13:13:34 +01001542 /* First check that no commands are left in the ring */
1543 if ((I915_READ_HEAD(engine) & HEAD_ADDR) !=
1544 (I915_READ_TAIL(engine) & TAIL_ADDR))
1545 idle = false;
1546
Chris Wilsona091d4e2017-05-30 13:13:33 +01001547 /* No bit for gen2, so assume the CS parser is idle */
1548 if (INTEL_GEN(dev_priv) > 2 && !(I915_READ_MODE(engine) & MODE_IDLE))
1549 idle = false;
1550
1551 intel_runtime_pm_put(dev_priv);
1552
1553 return idle;
1554}
1555
Chris Wilson54003672017-03-03 12:19:46 +00001556/**
1557 * intel_engine_is_idle() - Report if the engine has finished process all work
1558 * @engine: the intel_engine_cs
1559 *
1560 * Return true if there are no requests pending, nothing left to be submitted
1561 * to hardware, and that the engine is idle.
1562 */
1563bool intel_engine_is_idle(struct intel_engine_cs *engine)
1564{
1565 struct drm_i915_private *dev_priv = engine->i915;
1566
Chris Wilsona8e9a412017-04-11 20:00:42 +01001567 /* More white lies, if wedged, hw state is inconsistent */
1568 if (i915_terminally_wedged(&dev_priv->gpu_error))
1569 return true;
1570
Chris Wilson54003672017-03-03 12:19:46 +00001571 /* Any inflight/incomplete requests? */
1572 if (!i915_seqno_passed(intel_engine_get_seqno(engine),
1573 intel_engine_last_submit(engine)))
1574 return false;
1575
Chris Wilson8968a362017-04-12 00:44:26 +01001576 if (I915_SELFTEST_ONLY(engine->breadcrumbs.mock))
1577 return true;
1578
Chris Wilson4a118ec2017-10-23 22:32:36 +01001579 /* Waiting to drain ELSP? */
1580 if (READ_ONCE(engine->execlists.active))
Chris Wilson54003672017-03-03 12:19:46 +00001581 return false;
1582
Chris Wilsond6edb6e2017-07-21 13:32:24 +01001583 /* ELSP is empty, but there are ready requests? */
Mika Kuoppalab620e872017-09-22 15:43:03 +03001584 if (READ_ONCE(engine->execlists.first))
Chris Wilsond6edb6e2017-07-21 13:32:24 +01001585 return false;
1586
Chris Wilson54003672017-03-03 12:19:46 +00001587 /* Ring stopped? */
Chris Wilsona091d4e2017-05-30 13:13:33 +01001588 if (!ring_is_idle(engine))
Chris Wilson54003672017-03-03 12:19:46 +00001589 return false;
1590
1591 return true;
1592}
1593
Chris Wilson05425242017-03-03 12:19:47 +00001594bool intel_engines_are_idle(struct drm_i915_private *dev_priv)
1595{
1596 struct intel_engine_cs *engine;
1597 enum intel_engine_id id;
1598
Chris Wilsond7dc4132017-12-12 13:21:48 +00001599 /*
1600 * If the driver is wedged, HW state may be very inconsistent and
Chris Wilson8490ae202017-03-30 15:50:37 +01001601 * report that it is still busy, even though we have stopped using it.
1602 */
1603 if (i915_terminally_wedged(&dev_priv->gpu_error))
1604 return true;
1605
Chris Wilson05425242017-03-03 12:19:47 +00001606 for_each_engine(engine, dev_priv, id) {
1607 if (!intel_engine_is_idle(engine))
1608 return false;
1609 }
1610
1611 return true;
1612}
1613
Chris Wilsonae6c4572017-11-10 14:26:28 +00001614/**
1615 * intel_engine_has_kernel_context:
1616 * @engine: the engine
1617 *
1618 * Returns true if the last context to be executed on this engine, or has been
1619 * executed if the engine is already idle, is the kernel context
1620 * (#i915.kernel_context).
1621 */
Chris Wilson20ccd4d2017-10-24 23:08:55 +01001622bool intel_engine_has_kernel_context(const struct intel_engine_cs *engine)
1623{
Chris Wilsonae6c4572017-11-10 14:26:28 +00001624 const struct i915_gem_context * const kernel_context =
1625 engine->i915->kernel_context;
Chris Wilsone61e0f52018-02-21 09:56:36 +00001626 struct i915_request *rq;
Chris Wilsonae6c4572017-11-10 14:26:28 +00001627
1628 lockdep_assert_held(&engine->i915->drm.struct_mutex);
1629
1630 /*
1631 * Check the last context seen by the engine. If active, it will be
1632 * the last request that remains in the timeline. When idle, it is
1633 * the last executed context as tracked by retirement.
1634 */
1635 rq = __i915_gem_active_peek(&engine->timeline->last_request);
1636 if (rq)
1637 return rq->ctx == kernel_context;
1638 else
1639 return engine->last_retired_context == kernel_context;
Chris Wilson20ccd4d2017-10-24 23:08:55 +01001640}
1641
Chris Wilsonff44ad52017-03-16 17:13:03 +00001642void intel_engines_reset_default_submission(struct drm_i915_private *i915)
1643{
1644 struct intel_engine_cs *engine;
1645 enum intel_engine_id id;
1646
1647 for_each_engine(engine, i915, id)
1648 engine->set_default_submission(engine);
1649}
1650
Chris Wilsonaba5e272017-10-25 15:39:41 +01001651/**
1652 * intel_engines_park: called when the GT is transitioning from busy->idle
1653 * @i915: the i915 device
1654 *
1655 * The GT is now idle and about to go to sleep (maybe never to wake again?).
1656 * Time for us to tidy and put away our toys (release resources back to the
1657 * system).
1658 */
1659void intel_engines_park(struct drm_i915_private *i915)
Chris Wilson6c067572017-05-17 13:10:03 +01001660{
1661 struct intel_engine_cs *engine;
1662 enum intel_engine_id id;
1663
1664 for_each_engine(engine, i915, id) {
Chris Wilson820c5bb2017-11-01 20:21:49 +00001665 /* Flush the residual irq tasklets first. */
1666 intel_engine_disarm_breadcrumbs(engine);
Sagar Arun Kamblec6dce8f2017-11-16 19:02:37 +05301667 tasklet_kill(&engine->execlists.tasklet);
Chris Wilson820c5bb2017-11-01 20:21:49 +00001668
Chris Wilson32651242017-10-27 12:06:17 +01001669 /*
1670 * We are committed now to parking the engines, make sure there
1671 * will be no more interrupts arriving later and the engines
1672 * are truly idle.
1673 */
Chris Wilson30b29402017-11-10 11:25:50 +00001674 if (wait_for(intel_engine_is_idle(engine), 10)) {
Chris Wilson32651242017-10-27 12:06:17 +01001675 struct drm_printer p = drm_debug_printer(__func__);
1676
Chris Wilson30b29402017-11-10 11:25:50 +00001677 dev_err(i915->drm.dev,
1678 "%s is not idle before parking\n",
1679 engine->name);
Chris Wilson0db18b12017-12-08 01:23:00 +00001680 intel_engine_dump(engine, &p, NULL);
Chris Wilson32651242017-10-27 12:06:17 +01001681 }
1682
Chris Wilsonaba5e272017-10-25 15:39:41 +01001683 if (engine->park)
1684 engine->park(engine);
1685
Chris Wilsonaba5e272017-10-25 15:39:41 +01001686 i915_gem_batch_pool_fini(&engine->batch_pool);
Mika Kuoppalab620e872017-09-22 15:43:03 +03001687 engine->execlists.no_priolist = false;
Chris Wilson6c067572017-05-17 13:10:03 +01001688 }
1689}
1690
Chris Wilsonaba5e272017-10-25 15:39:41 +01001691/**
1692 * intel_engines_unpark: called when the GT is transitioning from idle->busy
1693 * @i915: the i915 device
1694 *
1695 * The GT was idle and now about to fire up with some new user requests.
1696 */
1697void intel_engines_unpark(struct drm_i915_private *i915)
1698{
1699 struct intel_engine_cs *engine;
1700 enum intel_engine_id id;
1701
1702 for_each_engine(engine, i915, id) {
1703 if (engine->unpark)
1704 engine->unpark(engine);
1705 }
1706}
1707
Chris Wilson90cad092017-09-06 16:28:59 +01001708bool intel_engine_can_store_dword(struct intel_engine_cs *engine)
1709{
1710 switch (INTEL_GEN(engine->i915)) {
1711 case 2:
1712 return false; /* uses physical not virtual addresses */
1713 case 3:
1714 /* maybe only uses physical not virtual addresses */
1715 return !(IS_I915G(engine->i915) || IS_I915GM(engine->i915));
1716 case 6:
1717 return engine->class != VIDEO_DECODE_CLASS; /* b0rked */
1718 default:
1719 return true;
1720 }
1721}
1722
Chris Wilsond2b4b972017-11-10 14:26:33 +00001723unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915)
1724{
1725 struct intel_engine_cs *engine;
1726 enum intel_engine_id id;
1727 unsigned int which;
1728
1729 which = 0;
1730 for_each_engine(engine, i915, id)
1731 if (engine->default_state)
1732 which |= BIT(engine->uabi_class);
1733
1734 return which;
1735}
1736
Chris Wilsonf636edb2017-10-09 12:02:57 +01001737static void print_request(struct drm_printer *m,
Chris Wilsone61e0f52018-02-21 09:56:36 +00001738 struct i915_request *rq,
Chris Wilsonf636edb2017-10-09 12:02:57 +01001739 const char *prefix)
1740{
Chris Wilsonab268152018-03-14 10:16:30 +00001741 const char *name = rq->fence.ops->get_timeline_name(&rq->fence);
1742
Chris Wilson367a35a2018-02-28 09:47:32 +00001743 drm_printf(m, "%s%x%s [%llx:%x] prio=%d @ %dms: %s\n", prefix,
Chris Wilsona27d5a42017-10-15 21:43:10 +01001744 rq->global_seqno,
Chris Wilsone61e0f52018-02-21 09:56:36 +00001745 i915_request_completed(rq) ? "!" : "",
Chris Wilson367a35a2018-02-28 09:47:32 +00001746 rq->fence.context, rq->fence.seqno,
Chris Wilsonf636edb2017-10-09 12:02:57 +01001747 rq->priotree.priority,
1748 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
Chris Wilsonab268152018-03-14 10:16:30 +00001749 name);
Chris Wilsonf636edb2017-10-09 12:02:57 +01001750}
1751
Chris Wilsonc1bf2722017-12-22 18:25:21 +00001752static void hexdump(struct drm_printer *m, const void *buf, size_t len)
1753{
1754 const size_t rowsize = 8 * sizeof(u32);
1755 const void *prev = NULL;
1756 bool skip = false;
1757 size_t pos;
1758
1759 for (pos = 0; pos < len; pos += rowsize) {
1760 char line[128];
1761
1762 if (prev && !memcmp(prev, buf + pos, rowsize)) {
1763 if (!skip) {
1764 drm_printf(m, "*\n");
1765 skip = true;
1766 }
1767 continue;
1768 }
1769
1770 WARN_ON_ONCE(hex_dump_to_buffer(buf + pos, len - pos,
1771 rowsize, sizeof(u32),
1772 line, sizeof(line),
1773 false) >= sizeof(line));
1774 drm_printf(m, "%08zx %s\n", pos, line);
1775
1776 prev = buf + pos;
1777 skip = false;
1778 }
1779}
1780
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001781static void intel_engine_print_registers(const struct intel_engine_cs *engine,
1782 struct drm_printer *m)
Chris Wilsonf636edb2017-10-09 12:02:57 +01001783{
Chris Wilsonf636edb2017-10-09 12:02:57 +01001784 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001785 const struct intel_engine_execlists * const execlists =
1786 &engine->execlists;
Chris Wilsonf636edb2017-10-09 12:02:57 +01001787 u64 addr;
1788
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001789 drm_printf(m, "\tRING_START: 0x%08x\n",
1790 I915_READ(RING_START(engine->mmio_base)));
1791 drm_printf(m, "\tRING_HEAD: 0x%08x\n",
1792 I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR);
1793 drm_printf(m, "\tRING_TAIL: 0x%08x\n",
1794 I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR);
Chris Wilson3c75de52017-10-26 12:50:48 +01001795 drm_printf(m, "\tRING_CTL: 0x%08x%s\n",
Chris Wilsonf636edb2017-10-09 12:02:57 +01001796 I915_READ(RING_CTL(engine->mmio_base)),
Chris Wilson3c75de52017-10-26 12:50:48 +01001797 I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? " [waiting]" : "");
1798 if (INTEL_GEN(engine->i915) > 2) {
1799 drm_printf(m, "\tRING_MODE: 0x%08x%s\n",
1800 I915_READ(RING_MI_MODE(engine->mmio_base)),
1801 I915_READ(RING_MI_MODE(engine->mmio_base)) & (MODE_IDLE) ? " [idle]" : "");
1802 }
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001803
1804 if (INTEL_GEN(dev_priv) >= 6) {
1805 drm_printf(m, "\tRING_IMR: %08x\n", I915_READ_IMR(engine));
1806 }
1807
Chris Wilson93c6e962017-11-20 20:55:04 +00001808 if (HAS_LEGACY_SEMAPHORES(dev_priv)) {
Chris Wilsonaf9ff6c2017-11-20 20:55:03 +00001809 drm_printf(m, "\tSYNC_0: 0x%08x\n",
1810 I915_READ(RING_SYNC_0(engine->mmio_base)));
1811 drm_printf(m, "\tSYNC_1: 0x%08x\n",
1812 I915_READ(RING_SYNC_1(engine->mmio_base)));
1813 if (HAS_VEBOX(dev_priv))
1814 drm_printf(m, "\tSYNC_2: 0x%08x\n",
1815 I915_READ(RING_SYNC_2(engine->mmio_base)));
1816 }
Chris Wilsonf636edb2017-10-09 12:02:57 +01001817
Chris Wilsonf636edb2017-10-09 12:02:57 +01001818 addr = intel_engine_get_active_head(engine);
1819 drm_printf(m, "\tACTHD: 0x%08x_%08x\n",
1820 upper_32_bits(addr), lower_32_bits(addr));
1821 addr = intel_engine_get_last_batch_head(engine);
1822 drm_printf(m, "\tBBADDR: 0x%08x_%08x\n",
1823 upper_32_bits(addr), lower_32_bits(addr));
Chris Wilsona0cf5792017-12-18 12:39:14 +00001824 if (INTEL_GEN(dev_priv) >= 8)
1825 addr = I915_READ64_2x32(RING_DMA_FADD(engine->mmio_base),
1826 RING_DMA_FADD_UDW(engine->mmio_base));
1827 else if (INTEL_GEN(dev_priv) >= 4)
1828 addr = I915_READ(RING_DMA_FADD(engine->mmio_base));
1829 else
1830 addr = I915_READ(DMA_FADD_I8XX);
1831 drm_printf(m, "\tDMA_FADDR: 0x%08x_%08x\n",
1832 upper_32_bits(addr), lower_32_bits(addr));
1833 if (INTEL_GEN(dev_priv) >= 4) {
1834 drm_printf(m, "\tIPEIR: 0x%08x\n",
1835 I915_READ(RING_IPEIR(engine->mmio_base)));
1836 drm_printf(m, "\tIPEHR: 0x%08x\n",
1837 I915_READ(RING_IPEHR(engine->mmio_base)));
1838 } else {
1839 drm_printf(m, "\tIPEIR: 0x%08x\n", I915_READ(IPEIR));
1840 drm_printf(m, "\tIPEHR: 0x%08x\n", I915_READ(IPEHR));
1841 }
Chris Wilsonf636edb2017-10-09 12:02:57 +01001842
Chris Wilsonfb5c5512017-11-20 20:55:00 +00001843 if (HAS_EXECLISTS(dev_priv)) {
Chris Wilsonf636edb2017-10-09 12:02:57 +01001844 const u32 *hws = &engine->status_page.page_addr[I915_HWS_CSB_BUF0_INDEX];
Chris Wilsonf636edb2017-10-09 12:02:57 +01001845 u32 ptr, read, write;
1846 unsigned int idx;
1847
1848 drm_printf(m, "\tExeclist status: 0x%08x %08x\n",
1849 I915_READ(RING_EXECLIST_STATUS_LO(engine)),
1850 I915_READ(RING_EXECLIST_STATUS_HI(engine)));
1851
1852 ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine));
1853 read = GEN8_CSB_READ_PTR(ptr);
1854 write = GEN8_CSB_WRITE_PTR(ptr);
1855 drm_printf(m, "\tExeclist CSB read %d [%d cached], write %d [%d from hws], interrupt posted? %s\n",
1856 read, execlists->csb_head,
1857 write,
1858 intel_read_status_page(engine, intel_hws_csb_write_index(engine->i915)),
1859 yesno(test_bit(ENGINE_IRQ_EXECLIST,
1860 &engine->irq_posted)));
1861 if (read >= GEN8_CSB_ENTRIES)
1862 read = 0;
1863 if (write >= GEN8_CSB_ENTRIES)
1864 write = 0;
1865 if (read > write)
1866 write += GEN8_CSB_ENTRIES;
1867 while (read < write) {
1868 idx = ++read % GEN8_CSB_ENTRIES;
1869 drm_printf(m, "\tExeclist CSB[%d]: 0x%08x [0x%08x in hwsp], context: %d [%d in hwsp]\n",
1870 idx,
1871 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)),
1872 hws[idx * 2],
1873 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)),
1874 hws[idx * 2 + 1]);
1875 }
1876
1877 rcu_read_lock();
1878 for (idx = 0; idx < execlists_num_ports(execlists); idx++) {
Chris Wilsone61e0f52018-02-21 09:56:36 +00001879 struct i915_request *rq;
Chris Wilsonf636edb2017-10-09 12:02:57 +01001880 unsigned int count;
1881
1882 rq = port_unpack(&execlists->port[idx], &count);
1883 if (rq) {
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001884 char hdr[80];
1885
Chris Wilsone8a70ca2017-12-08 01:22:59 +00001886 snprintf(hdr, sizeof(hdr),
1887 "\t\tELSP[%d] count=%d, rq: ",
1888 idx, count);
1889 print_request(m, rq, hdr);
Chris Wilsonf636edb2017-10-09 12:02:57 +01001890 } else {
Chris Wilsone8a70ca2017-12-08 01:22:59 +00001891 drm_printf(m, "\t\tELSP[%d] idle\n", idx);
Chris Wilsonf636edb2017-10-09 12:02:57 +01001892 }
1893 }
Chris Wilson4a118ec2017-10-23 22:32:36 +01001894 drm_printf(m, "\t\tHW active? 0x%x\n", execlists->active);
Chris Wilsonf636edb2017-10-09 12:02:57 +01001895 rcu_read_unlock();
Chris Wilsonf636edb2017-10-09 12:02:57 +01001896 } else if (INTEL_GEN(dev_priv) > 6) {
1897 drm_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
1898 I915_READ(RING_PP_DIR_BASE(engine)));
1899 drm_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
1900 I915_READ(RING_PP_DIR_BASE_READ(engine)));
1901 drm_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
1902 I915_READ(RING_PP_DIR_DCLV(engine)));
1903 }
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001904}
1905
1906void intel_engine_dump(struct intel_engine_cs *engine,
1907 struct drm_printer *m,
1908 const char *header, ...)
1909{
1910 struct intel_breadcrumbs * const b = &engine->breadcrumbs;
1911 const struct intel_engine_execlists * const execlists = &engine->execlists;
1912 struct i915_gpu_error * const error = &engine->i915->gpu_error;
Chris Wilsone61e0f52018-02-21 09:56:36 +00001913 struct i915_request *rq;
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001914 struct rb_node *rb;
1915
1916 if (header) {
1917 va_list ap;
1918
1919 va_start(ap, header);
1920 drm_vprintf(m, header, &ap);
1921 va_end(ap);
1922 }
1923
1924 if (i915_terminally_wedged(&engine->i915->gpu_error))
1925 drm_printf(m, "*** WEDGED ***\n");
1926
1927 drm_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n",
1928 intel_engine_get_seqno(engine),
1929 intel_engine_last_submit(engine),
1930 engine->hangcheck.seqno,
1931 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp),
1932 engine->timeline->inflight_seqnos);
1933 drm_printf(m, "\tReset count: %d (global %d)\n",
1934 i915_reset_engine_count(error, engine),
1935 i915_reset_count(error));
1936
1937 rcu_read_lock();
1938
1939 drm_printf(m, "\tRequests:\n");
1940
1941 rq = list_first_entry(&engine->timeline->requests,
Chris Wilsone61e0f52018-02-21 09:56:36 +00001942 struct i915_request, link);
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001943 if (&rq->link != &engine->timeline->requests)
1944 print_request(m, rq, "\t\tfirst ");
1945
1946 rq = list_last_entry(&engine->timeline->requests,
Chris Wilsone61e0f52018-02-21 09:56:36 +00001947 struct i915_request, link);
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001948 if (&rq->link != &engine->timeline->requests)
1949 print_request(m, rq, "\t\tlast ");
1950
1951 rq = i915_gem_find_active_request(engine);
1952 if (rq) {
1953 print_request(m, rq, "\t\tactive ");
1954 drm_printf(m,
1955 "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n",
1956 rq->head, rq->postfix, rq->tail,
1957 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
1958 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
Chris Wilsonef5032a2018-03-07 13:42:24 +00001959 drm_printf(m, "\t\tring->start: 0x%08x\n",
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001960 i915_ggtt_offset(rq->ring->vma));
Chris Wilsonef5032a2018-03-07 13:42:24 +00001961 drm_printf(m, "\t\tring->head: 0x%08x\n",
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001962 rq->ring->head);
Chris Wilsonef5032a2018-03-07 13:42:24 +00001963 drm_printf(m, "\t\tring->tail: 0x%08x\n",
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001964 rq->ring->tail);
Chris Wilsonef5032a2018-03-07 13:42:24 +00001965 drm_printf(m, "\t\tring->emit: 0x%08x\n",
1966 rq->ring->emit);
1967 drm_printf(m, "\t\tring->space: 0x%08x\n",
1968 rq->ring->space);
Chris Wilson3ceda3a2018-02-12 10:24:15 +00001969 }
1970
1971 rcu_read_unlock();
1972
1973 if (intel_runtime_pm_get_if_in_use(engine->i915)) {
1974 intel_engine_print_registers(engine, m);
1975 intel_runtime_pm_put(engine->i915);
1976 } else {
1977 drm_printf(m, "\tDevice is asleep; skipping register dump\n");
1978 }
Chris Wilsonf636edb2017-10-09 12:02:57 +01001979
Chris Wilsona27d5a42017-10-15 21:43:10 +01001980 spin_lock_irq(&engine->timeline->lock);
1981 list_for_each_entry(rq, &engine->timeline->requests, link)
1982 print_request(m, rq, "\t\tE ");
Chris Wilsonf6322ed2018-02-22 14:22:29 +00001983 drm_printf(m, "\t\tQueue priority: %d\n", execlists->queue_priority);
Chris Wilsona27d5a42017-10-15 21:43:10 +01001984 for (rb = execlists->first; rb; rb = rb_next(rb)) {
1985 struct i915_priolist *p =
1986 rb_entry(rb, typeof(*p), node);
1987
1988 list_for_each_entry(rq, &p->requests, priotree.link)
1989 print_request(m, rq, "\t\tQ ");
1990 }
1991 spin_unlock_irq(&engine->timeline->lock);
1992
Chris Wilsonf636edb2017-10-09 12:02:57 +01001993 spin_lock_irq(&b->rb_lock);
1994 for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
1995 struct intel_wait *w = rb_entry(rb, typeof(*w), node);
1996
1997 drm_printf(m, "\t%s [%d] waiting for %x\n",
1998 w->tsk->comm, w->tsk->pid, w->seqno);
1999 }
2000 spin_unlock_irq(&b->rb_lock);
2001
Chris Wilson832265d2017-12-08 01:23:01 +00002002 drm_printf(m, "IRQ? 0x%lx (breadcrumbs? %s) (execlists? %s)\n",
2003 engine->irq_posted,
2004 yesno(test_bit(ENGINE_IRQ_BREADCRUMB,
2005 &engine->irq_posted)),
2006 yesno(test_bit(ENGINE_IRQ_EXECLIST,
2007 &engine->irq_posted)));
Chris Wilsonc1bf2722017-12-22 18:25:21 +00002008
2009 drm_printf(m, "HWSP:\n");
2010 hexdump(m, engine->status_page.page_addr, PAGE_SIZE);
2011
Chris Wilsonc400cc22017-11-07 15:22:11 +00002012 drm_printf(m, "Idle? %s\n", yesno(intel_engine_is_idle(engine)));
Chris Wilsonf636edb2017-10-09 12:02:57 +01002013}
2014
Tvrtko Ursulinb46a33e2017-11-21 18:18:45 +00002015static u8 user_class_map[] = {
2016 [I915_ENGINE_CLASS_RENDER] = RENDER_CLASS,
2017 [I915_ENGINE_CLASS_COPY] = COPY_ENGINE_CLASS,
2018 [I915_ENGINE_CLASS_VIDEO] = VIDEO_DECODE_CLASS,
2019 [I915_ENGINE_CLASS_VIDEO_ENHANCE] = VIDEO_ENHANCEMENT_CLASS,
2020};
2021
2022struct intel_engine_cs *
2023intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance)
2024{
2025 if (class >= ARRAY_SIZE(user_class_map))
2026 return NULL;
2027
2028 class = user_class_map[class];
2029
2030 GEM_BUG_ON(class > MAX_ENGINE_CLASS);
2031
2032 if (instance > MAX_ENGINE_INSTANCE)
2033 return NULL;
2034
2035 return i915->engine_class[class][instance];
2036}
2037
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002038/**
2039 * intel_enable_engine_stats() - Enable engine busy tracking on engine
2040 * @engine: engine to enable stats collection
2041 *
2042 * Start collecting the engine busyness data for @engine.
2043 *
2044 * Returns 0 on success or a negative error code.
2045 */
2046int intel_enable_engine_stats(struct intel_engine_cs *engine)
2047{
Chris Wilson99e48bf2018-01-15 09:20:41 +00002048 struct intel_engine_execlists *execlists = &engine->execlists;
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002049 unsigned long flags;
Chris Wilson99e48bf2018-01-15 09:20:41 +00002050 int err = 0;
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002051
Tvrtko Ursulincf669b42017-11-29 10:28:05 +00002052 if (!intel_engine_supports_stats(engine))
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002053 return -ENODEV;
2054
Chris Wilson99e48bf2018-01-15 09:20:41 +00002055 tasklet_disable(&execlists->tasklet);
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002056 spin_lock_irqsave(&engine->stats.lock, flags);
Chris Wilson99e48bf2018-01-15 09:20:41 +00002057
2058 if (unlikely(engine->stats.enabled == ~0)) {
2059 err = -EBUSY;
2060 goto unlock;
2061 }
2062
Chris Wilson49007272018-01-11 07:30:31 +00002063 if (engine->stats.enabled++ == 0) {
Chris Wilson49007272018-01-11 07:30:31 +00002064 const struct execlist_port *port = execlists->port;
2065 unsigned int num_ports = execlists_num_ports(execlists);
2066
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002067 engine->stats.enabled_at = ktime_get();
Chris Wilson49007272018-01-11 07:30:31 +00002068
2069 /* XXX submission method oblivious? */
2070 while (num_ports-- && port_isset(port)) {
2071 engine->stats.active++;
2072 port++;
2073 }
2074
2075 if (engine->stats.active)
2076 engine->stats.start = engine->stats.enabled_at;
2077 }
Chris Wilson99e48bf2018-01-15 09:20:41 +00002078
2079unlock:
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002080 spin_unlock_irqrestore(&engine->stats.lock, flags);
Chris Wilson99e48bf2018-01-15 09:20:41 +00002081 tasklet_enable(&execlists->tasklet);
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002082
Chris Wilson99e48bf2018-01-15 09:20:41 +00002083 return err;
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002084}
2085
2086static ktime_t __intel_engine_get_busy_time(struct intel_engine_cs *engine)
2087{
2088 ktime_t total = engine->stats.total;
2089
2090 /*
2091 * If the engine is executing something at the moment
2092 * add it to the total.
2093 */
2094 if (engine->stats.active)
2095 total = ktime_add(total,
2096 ktime_sub(ktime_get(), engine->stats.start));
2097
2098 return total;
2099}
2100
2101/**
2102 * intel_engine_get_busy_time() - Return current accumulated engine busyness
2103 * @engine: engine to report on
2104 *
2105 * Returns accumulated time @engine was busy since engine stats were enabled.
2106 */
2107ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine)
2108{
2109 ktime_t total;
2110 unsigned long flags;
2111
2112 spin_lock_irqsave(&engine->stats.lock, flags);
2113 total = __intel_engine_get_busy_time(engine);
2114 spin_unlock_irqrestore(&engine->stats.lock, flags);
2115
2116 return total;
2117}
2118
2119/**
2120 * intel_disable_engine_stats() - Disable engine busy tracking on engine
2121 * @engine: engine to disable stats collection
2122 *
2123 * Stops collecting the engine busyness data for @engine.
2124 */
2125void intel_disable_engine_stats(struct intel_engine_cs *engine)
2126{
2127 unsigned long flags;
2128
Tvrtko Ursulincf669b42017-11-29 10:28:05 +00002129 if (!intel_engine_supports_stats(engine))
Tvrtko Ursulin30e17b72017-11-21 18:18:48 +00002130 return;
2131
2132 spin_lock_irqsave(&engine->stats.lock, flags);
2133 WARN_ON_ONCE(engine->stats.enabled == 0);
2134 if (--engine->stats.enabled == 0) {
2135 engine->stats.total = __intel_engine_get_busy_time(engine);
2136 engine->stats.active = 0;
2137 }
2138 spin_unlock_irqrestore(&engine->stats.lock, flags);
2139}
2140
Chris Wilsonf97fbf92017-02-13 17:15:14 +00002141#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
2142#include "selftests/mock_engine.c"
2143#endif