2 * Copyright © 2016 Intel Corporation
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:
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
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
25 #include <drm/drm_print.h>
27 #include "gem/i915_gem_context.h"
31 #include "intel_engine.h"
32 #include "intel_engine_pm.h"
33 #include "intel_context.h"
34 #include "intel_lrc.h"
35 #include "intel_reset.h"
37 /* Haswell does have the CXT_SIZE register however it does not appear to be
38 * valid. Now, docs explain in dwords what is in the context object. The full
39 * size is 70720 bytes, however, the power context and execlist context will
40 * never be saved (power context is stored elsewhere, and execlists don't work
41 * on HSW) - so the final size, including the extra state required for the
42 * Resource Streamer, is 66944 bytes, which rounds to 17 pages.
44 #define HSW_CXT_TOTAL_SIZE (17 * PAGE_SIZE)
46 #define DEFAULT_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)
47 #define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE)
48 #define GEN9_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)
49 #define GEN10_LR_CONTEXT_RENDER_SIZE (18 * PAGE_SIZE)
50 #define GEN11_LR_CONTEXT_RENDER_SIZE (14 * PAGE_SIZE)
52 #define GEN8_LR_CONTEXT_OTHER_SIZE ( 2 * PAGE_SIZE)
54 struct engine_class_info {
59 static const struct engine_class_info intel_engine_classes[] = {
62 .uabi_class = I915_ENGINE_CLASS_RENDER,
64 [COPY_ENGINE_CLASS] = {
66 .uabi_class = I915_ENGINE_CLASS_COPY,
68 [VIDEO_DECODE_CLASS] = {
70 .uabi_class = I915_ENGINE_CLASS_VIDEO,
72 [VIDEO_ENHANCEMENT_CLASS] = {
74 .uabi_class = I915_ENGINE_CLASS_VIDEO_ENHANCE,
78 #define MAX_MMIO_BASES 3
83 /* mmio bases table *must* be sorted in reverse gen order */
84 struct engine_mmio_base {
87 } mmio_bases[MAX_MMIO_BASES];
90 static const struct engine_info intel_engines[] = {
93 .class = RENDER_CLASS,
96 { .gen = 1, .base = RENDER_RING_BASE }
101 .class = COPY_ENGINE_CLASS,
104 { .gen = 6, .base = BLT_RING_BASE }
109 .class = VIDEO_DECODE_CLASS,
112 { .gen = 11, .base = GEN11_BSD_RING_BASE },
113 { .gen = 6, .base = GEN6_BSD_RING_BASE },
114 { .gen = 4, .base = BSD_RING_BASE }
119 .class = VIDEO_DECODE_CLASS,
122 { .gen = 11, .base = GEN11_BSD2_RING_BASE },
123 { .gen = 8, .base = GEN8_BSD2_RING_BASE }
128 .class = VIDEO_DECODE_CLASS,
131 { .gen = 11, .base = GEN11_BSD3_RING_BASE }
136 .class = VIDEO_DECODE_CLASS,
139 { .gen = 11, .base = GEN11_BSD4_RING_BASE }
144 .class = VIDEO_ENHANCEMENT_CLASS,
147 { .gen = 11, .base = GEN11_VEBOX_RING_BASE },
148 { .gen = 7, .base = VEBOX_RING_BASE }
153 .class = VIDEO_ENHANCEMENT_CLASS,
156 { .gen = 11, .base = GEN11_VEBOX2_RING_BASE }
162 * intel_engine_context_size() - return the size of the context for an engine
163 * @dev_priv: i915 device private
164 * @class: engine class
166 * Each engine class may require a different amount of space for a context
169 * Return: size (in bytes) of an engine class specific context image
171 * Note: this size includes the HWSP, which is part of the context image
172 * in LRC mode, but does not include the "shared data page" used with
173 * GuC submission. The caller should account for this if using the GuC.
175 u32 intel_engine_context_size(struct drm_i915_private *dev_priv, u8 class)
179 BUILD_BUG_ON(I915_GTT_PAGE_SIZE != PAGE_SIZE);
183 switch (INTEL_GEN(dev_priv)) {
185 MISSING_CASE(INTEL_GEN(dev_priv));
186 return DEFAULT_LR_CONTEXT_RENDER_SIZE;
188 return GEN11_LR_CONTEXT_RENDER_SIZE;
190 return GEN10_LR_CONTEXT_RENDER_SIZE;
192 return GEN9_LR_CONTEXT_RENDER_SIZE;
194 return GEN8_LR_CONTEXT_RENDER_SIZE;
196 if (IS_HASWELL(dev_priv))
197 return HSW_CXT_TOTAL_SIZE;
199 cxt_size = I915_READ(GEN7_CXT_SIZE);
200 return round_up(GEN7_CXT_TOTAL_SIZE(cxt_size) * 64,
203 cxt_size = I915_READ(CXT_SIZE);
204 return round_up(GEN6_CXT_TOTAL_SIZE(cxt_size) * 64,
209 * There is a discrepancy here between the size reported
210 * by the register and the size of the context layout
211 * in the docs. Both are described as authorative!
213 * The discrepancy is on the order of a few cachelines,
214 * but the total is under one page (4k), which is our
215 * minimum allocation anyway so it should all come
218 cxt_size = I915_READ(CXT_SIZE) + 1;
219 DRM_DEBUG_DRIVER("gen%d CXT_SIZE = %d bytes [0x%08x]\n",
223 return round_up(cxt_size * 64, PAGE_SIZE);
226 /* For the special day when i810 gets merged. */
234 case VIDEO_DECODE_CLASS:
235 case VIDEO_ENHANCEMENT_CLASS:
236 case COPY_ENGINE_CLASS:
237 if (INTEL_GEN(dev_priv) < 8)
239 return GEN8_LR_CONTEXT_OTHER_SIZE;
243 static u32 __engine_mmio_base(struct drm_i915_private *i915,
244 const struct engine_mmio_base *bases)
248 for (i = 0; i < MAX_MMIO_BASES; i++)
249 if (INTEL_GEN(i915) >= bases[i].gen)
252 GEM_BUG_ON(i == MAX_MMIO_BASES);
253 GEM_BUG_ON(!bases[i].base);
255 return bases[i].base;
258 static void __sprint_engine_name(char *name, const struct engine_info *info)
260 WARN_ON(snprintf(name, INTEL_ENGINE_CS_MAX_NAME, "%s%u",
261 intel_engine_classes[info->class].name,
262 info->instance) >= INTEL_ENGINE_CS_MAX_NAME);
265 void intel_engine_set_hwsp_writemask(struct intel_engine_cs *engine, u32 mask)
268 * Though they added more rings on g4x/ilk, they did not add
269 * per-engine HWSTAM until gen6.
271 if (INTEL_GEN(engine->i915) < 6 && engine->class != RENDER_CLASS)
274 if (INTEL_GEN(engine->i915) >= 3)
275 ENGINE_WRITE(engine, RING_HWSTAM, mask);
277 ENGINE_WRITE16(engine, RING_HWSTAM, mask);
280 static void intel_engine_sanitize_mmio(struct intel_engine_cs *engine)
282 /* Mask off all writes into the unknown HWSP */
283 intel_engine_set_hwsp_writemask(engine, ~0u);
287 intel_engine_setup(struct drm_i915_private *dev_priv,
288 enum intel_engine_id id)
290 const struct engine_info *info = &intel_engines[id];
291 struct intel_engine_cs *engine;
293 GEM_BUG_ON(info->class >= ARRAY_SIZE(intel_engine_classes));
295 BUILD_BUG_ON(MAX_ENGINE_CLASS >= BIT(GEN11_ENGINE_CLASS_WIDTH));
296 BUILD_BUG_ON(MAX_ENGINE_INSTANCE >= BIT(GEN11_ENGINE_INSTANCE_WIDTH));
298 if (GEM_DEBUG_WARN_ON(info->class > MAX_ENGINE_CLASS))
301 if (GEM_DEBUG_WARN_ON(info->instance > MAX_ENGINE_INSTANCE))
304 if (GEM_DEBUG_WARN_ON(dev_priv->engine_class[info->class][info->instance]))
307 GEM_BUG_ON(dev_priv->engine[id]);
308 engine = kzalloc(sizeof(*engine), GFP_KERNEL);
312 BUILD_BUG_ON(BITS_PER_TYPE(engine->mask) < I915_NUM_ENGINES);
315 engine->mask = BIT(id);
316 engine->i915 = dev_priv;
317 engine->uncore = &dev_priv->uncore;
318 __sprint_engine_name(engine->name, info);
319 engine->hw_id = engine->guc_id = info->hw_id;
320 engine->mmio_base = __engine_mmio_base(dev_priv, info->mmio_bases);
321 engine->class = info->class;
322 engine->instance = info->instance;
325 * To be overridden by the backend on setup. However to facilitate
326 * cleanup on error during setup, we always provide the destroy vfunc.
328 engine->destroy = (typeof(engine->destroy))kfree;
330 engine->uabi_class = intel_engine_classes[info->class].uabi_class;
332 engine->context_size = intel_engine_context_size(dev_priv,
334 if (WARN_ON(engine->context_size > BIT(20)))
335 engine->context_size = 0;
336 if (engine->context_size)
337 DRIVER_CAPS(dev_priv)->has_logical_contexts = true;
339 /* Nothing to do here, execute in order of dependencies */
340 engine->schedule = NULL;
342 seqlock_init(&engine->stats.lock);
344 ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier);
346 /* Scrub mmio state on takeover */
347 intel_engine_sanitize_mmio(engine);
349 dev_priv->engine_class[info->class][info->instance] = engine;
350 dev_priv->engine[id] = engine;
354 static void __setup_engine_capabilities(struct intel_engine_cs *engine)
356 struct drm_i915_private *i915 = engine->i915;
358 if (engine->class == VIDEO_DECODE_CLASS) {
360 * HEVC support is present on first engine instance
361 * before Gen11 and on all instances afterwards.
363 if (INTEL_GEN(i915) >= 11 ||
364 (INTEL_GEN(i915) >= 9 && engine->instance == 0))
365 engine->uabi_capabilities |=
366 I915_VIDEO_CLASS_CAPABILITY_HEVC;
369 * SFC block is present only on even logical engine
372 if ((INTEL_GEN(i915) >= 11 &&
373 RUNTIME_INFO(i915)->vdbox_sfc_access & engine->mask) ||
374 (INTEL_GEN(i915) >= 9 && engine->instance == 0))
375 engine->uabi_capabilities |=
376 I915_VIDEO_AND_ENHANCE_CLASS_CAPABILITY_SFC;
377 } else if (engine->class == VIDEO_ENHANCEMENT_CLASS) {
378 if (INTEL_GEN(i915) >= 9)
379 engine->uabi_capabilities |=
380 I915_VIDEO_AND_ENHANCE_CLASS_CAPABILITY_SFC;
384 static void intel_setup_engine_capabilities(struct drm_i915_private *i915)
386 struct intel_engine_cs *engine;
387 enum intel_engine_id id;
389 for_each_engine(engine, i915, id)
390 __setup_engine_capabilities(engine);
394 * intel_engines_cleanup() - free the resources allocated for Command Streamers
395 * @i915: the i915 devic
397 void intel_engines_cleanup(struct drm_i915_private *i915)
399 struct intel_engine_cs *engine;
400 enum intel_engine_id id;
402 for_each_engine(engine, i915, id) {
403 engine->destroy(engine);
404 i915->engine[id] = NULL;
409 * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers
410 * @i915: the i915 device
412 * Return: non-zero if the initialization failed.
414 int intel_engines_init_mmio(struct drm_i915_private *i915)
416 struct intel_device_info *device_info = mkwrite_device_info(i915);
417 const unsigned int engine_mask = INTEL_INFO(i915)->engine_mask;
418 unsigned int mask = 0;
422 WARN_ON(engine_mask == 0);
423 WARN_ON(engine_mask &
424 GENMASK(BITS_PER_TYPE(mask) - 1, I915_NUM_ENGINES));
426 if (i915_inject_load_failure())
429 for (i = 0; i < ARRAY_SIZE(intel_engines); i++) {
430 if (!HAS_ENGINE(i915, i))
433 err = intel_engine_setup(i915, i);
441 * Catch failures to update intel_engines table when the new engines
442 * are added to the driver by a warning and disabling the forgotten
445 if (WARN_ON(mask != engine_mask))
446 device_info->engine_mask = mask;
448 /* We always presume we have at least RCS available for later probing */
449 if (WARN_ON(!HAS_ENGINE(i915, RCS0))) {
454 RUNTIME_INFO(i915)->num_engines = hweight32(mask);
456 i915_check_and_clear_faults(i915);
458 intel_setup_engine_capabilities(i915);
463 intel_engines_cleanup(i915);
468 * intel_engines_init() - init the Engine Command Streamers
469 * @i915: i915 device private
471 * Return: non-zero if the initialization failed.
473 int intel_engines_init(struct drm_i915_private *i915)
475 int (*init)(struct intel_engine_cs *engine);
476 struct intel_engine_cs *engine;
477 enum intel_engine_id id;
480 if (HAS_EXECLISTS(i915))
481 init = intel_execlists_submission_init;
483 init = intel_ring_submission_init;
485 for_each_engine(engine, i915, id) {
494 intel_engines_cleanup(i915);
498 static void intel_engine_init_batch_pool(struct intel_engine_cs *engine)
500 i915_gem_batch_pool_init(&engine->batch_pool, engine);
503 void intel_engine_init_execlists(struct intel_engine_cs *engine)
505 struct intel_engine_execlists * const execlists = &engine->execlists;
507 execlists->port_mask = 1;
508 GEM_BUG_ON(!is_power_of_2(execlists_num_ports(execlists)));
509 GEM_BUG_ON(execlists_num_ports(execlists) > EXECLIST_MAX_PORTS);
511 execlists->queue_priority_hint = INT_MIN;
512 execlists->queue = RB_ROOT_CACHED;
515 static void cleanup_status_page(struct intel_engine_cs *engine)
517 struct i915_vma *vma;
519 /* Prevent writes into HWSP after returning the page to the system */
520 intel_engine_set_hwsp_writemask(engine, ~0u);
522 vma = fetch_and_zero(&engine->status_page.vma);
526 if (!HWS_NEEDS_PHYSICAL(engine->i915))
529 i915_gem_object_unpin_map(vma->obj);
530 i915_gem_object_put(vma->obj);
533 static int pin_ggtt_status_page(struct intel_engine_cs *engine,
534 struct i915_vma *vma)
539 if (!HAS_LLC(engine->i915))
541 * On g33, we cannot place HWS above 256MiB, so
542 * restrict its pinning to the low mappable arena.
543 * Though this restriction is not documented for
544 * gen4, gen5, or byt, they also behave similarly
545 * and hang if the HWS is placed at the top of the
546 * GTT. To generalise, it appears that all !llc
547 * platforms have issues with us placing the HWS
548 * above the mappable region (even though we never
551 flags |= PIN_MAPPABLE;
555 return i915_vma_pin(vma, 0, 0, flags);
558 static int init_status_page(struct intel_engine_cs *engine)
560 struct drm_i915_gem_object *obj;
561 struct i915_vma *vma;
566 * Though the HWS register does support 36bit addresses, historically
567 * we have had hangs and corruption reported due to wild writes if
568 * the HWS is placed above 4G. We only allow objects to be allocated
569 * in GFP_DMA32 for i965, and no earlier physical address users had
570 * access to more than 4G.
572 obj = i915_gem_object_create_internal(engine->i915, PAGE_SIZE);
574 DRM_ERROR("Failed to allocate status page\n");
578 i915_gem_object_set_cache_coherency(obj, I915_CACHE_LLC);
580 vma = i915_vma_instance(obj, &engine->i915->ggtt.vm, NULL);
586 vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB);
588 ret = PTR_ERR(vaddr);
592 engine->status_page.addr = memset(vaddr, 0, PAGE_SIZE);
593 engine->status_page.vma = vma;
595 if (!HWS_NEEDS_PHYSICAL(engine->i915)) {
596 ret = pin_ggtt_status_page(engine, vma);
604 i915_gem_object_unpin_map(obj);
606 i915_gem_object_put(obj);
610 static int intel_engine_setup_common(struct intel_engine_cs *engine)
614 init_llist_head(&engine->barrier_tasks);
616 err = init_status_page(engine);
620 intel_engine_init_active(engine, ENGINE_PHYSICAL);
621 intel_engine_init_breadcrumbs(engine);
622 intel_engine_init_execlists(engine);
623 intel_engine_init_hangcheck(engine);
624 intel_engine_init_batch_pool(engine);
625 intel_engine_init_cmd_parser(engine);
626 intel_engine_init__pm(engine);
628 /* Use the whole device by default */
630 intel_sseu_from_device_info(&RUNTIME_INFO(engine->i915)->sseu);
636 * intel_engines_setup- setup engine state not requiring hw access
637 * @i915: Device to setup.
639 * Initializes engine structure members shared between legacy and execlists
640 * submission modes which do not require hardware access.
642 * Typically done early in the submission mode specific engine setup stage.
644 int intel_engines_setup(struct drm_i915_private *i915)
646 int (*setup)(struct intel_engine_cs *engine);
647 struct intel_engine_cs *engine;
648 enum intel_engine_id id;
651 if (HAS_EXECLISTS(i915))
652 setup = intel_execlists_submission_setup;
654 setup = intel_ring_submission_setup;
656 for_each_engine(engine, i915, id) {
657 err = intel_engine_setup_common(engine);
665 /* We expect the backend to take control over its state */
666 GEM_BUG_ON(engine->destroy == (typeof(engine->destroy))kfree);
668 GEM_BUG_ON(!engine->cops);
674 intel_engines_cleanup(i915);
678 void intel_engines_set_scheduler_caps(struct drm_i915_private *i915)
680 static const struct {
684 #define MAP(x, y) { ilog2(I915_ENGINE_HAS_##x), ilog2(I915_SCHEDULER_CAP_##y) }
685 MAP(PREEMPTION, PREEMPTION),
686 MAP(SEMAPHORES, SEMAPHORES),
689 struct intel_engine_cs *engine;
690 enum intel_engine_id id;
691 u32 enabled, disabled;
695 for_each_engine(engine, i915, id) { /* all engines must agree! */
698 if (engine->schedule)
699 enabled |= (I915_SCHEDULER_CAP_ENABLED |
700 I915_SCHEDULER_CAP_PRIORITY);
702 disabled |= (I915_SCHEDULER_CAP_ENABLED |
703 I915_SCHEDULER_CAP_PRIORITY);
705 for (i = 0; i < ARRAY_SIZE(map); i++) {
706 if (engine->flags & BIT(map[i].engine))
707 enabled |= BIT(map[i].sched);
709 disabled |= BIT(map[i].sched);
713 i915->caps.scheduler = enabled & ~disabled;
714 if (!(i915->caps.scheduler & I915_SCHEDULER_CAP_ENABLED))
715 i915->caps.scheduler = 0;
718 struct measure_breadcrumb {
719 struct i915_request rq;
720 struct i915_timeline timeline;
721 struct intel_ring ring;
725 static int measure_breadcrumb_dw(struct intel_engine_cs *engine)
727 struct measure_breadcrumb *frame;
730 GEM_BUG_ON(!engine->i915->gt.scratch);
732 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
736 if (i915_timeline_init(engine->i915,
738 engine->status_page.vma))
741 INIT_LIST_HEAD(&frame->ring.request_list);
742 frame->ring.timeline = &frame->timeline;
743 frame->ring.vaddr = frame->cs;
744 frame->ring.size = sizeof(frame->cs);
745 frame->ring.effective_size = frame->ring.size;
746 intel_ring_update_space(&frame->ring);
748 frame->rq.i915 = engine->i915;
749 frame->rq.engine = engine;
750 frame->rq.ring = &frame->ring;
751 frame->rq.timeline = &frame->timeline;
753 dw = i915_timeline_pin(&frame->timeline);
757 dw = engine->emit_fini_breadcrumb(&frame->rq, frame->cs) - frame->cs;
758 GEM_BUG_ON(dw & 1); /* RING_TAIL must be qword aligned */
760 i915_timeline_unpin(&frame->timeline);
763 i915_timeline_fini(&frame->timeline);
769 static int pin_context(struct i915_gem_context *ctx,
770 struct intel_engine_cs *engine,
771 struct intel_context **out)
773 struct intel_context *ce;
776 ce = i915_gem_context_get_engine(ctx, engine->id);
780 err = intel_context_pin(ce);
781 intel_context_put(ce);
790 intel_engine_init_active(struct intel_engine_cs *engine, unsigned int subclass)
792 INIT_LIST_HEAD(&engine->active.requests);
794 spin_lock_init(&engine->active.lock);
795 lockdep_set_subclass(&engine->active.lock, subclass);
798 * Due to an interesting quirk in lockdep's internal debug tracking,
799 * after setting a subclass we must ensure the lock is used. Otherwise,
800 * nr_unused_locks is incremented once too often.
802 #ifdef CONFIG_DEBUG_LOCK_ALLOC
804 lock_map_acquire(&engine->active.lock.dep_map);
805 lock_map_release(&engine->active.lock.dep_map);
811 * intel_engines_init_common - initialize cengine state which might require hw access
812 * @engine: Engine to initialize.
814 * Initializes @engine@ structure members shared between legacy and execlists
815 * submission modes which do require hardware access.
817 * Typcally done at later stages of submission mode specific engine setup.
819 * Returns zero on success or an error code on failure.
821 int intel_engine_init_common(struct intel_engine_cs *engine)
823 struct drm_i915_private *i915 = engine->i915;
826 /* We may need to do things with the shrinker which
827 * require us to immediately switch back to the default
828 * context. This can cause a problem as pinning the
829 * default context also requires GTT space which may not
830 * be available. To avoid this we always pin the default
833 ret = pin_context(i915->kernel_context, engine,
834 &engine->kernel_context);
839 * Similarly the preempt context must always be available so that
840 * we can interrupt the engine at any time. However, as preemption
841 * is optional, we allow it to fail.
843 if (i915->preempt_context)
844 pin_context(i915->preempt_context, engine,
845 &engine->preempt_context);
847 ret = measure_breadcrumb_dw(engine);
851 engine->emit_fini_breadcrumb_dw = ret;
853 engine->set_default_submission(engine);
858 if (engine->preempt_context)
859 intel_context_unpin(engine->preempt_context);
860 intel_context_unpin(engine->kernel_context);
865 * intel_engines_cleanup_common - cleans up the engine state created by
866 * the common initiailizers.
867 * @engine: Engine to cleanup.
869 * This cleans up everything created by the common helpers.
871 void intel_engine_cleanup_common(struct intel_engine_cs *engine)
873 GEM_BUG_ON(!list_empty(&engine->active.requests));
875 cleanup_status_page(engine);
877 intel_engine_fini_breadcrumbs(engine);
878 intel_engine_cleanup_cmd_parser(engine);
879 i915_gem_batch_pool_fini(&engine->batch_pool);
881 if (engine->default_state)
882 i915_gem_object_put(engine->default_state);
884 if (engine->preempt_context)
885 intel_context_unpin(engine->preempt_context);
886 intel_context_unpin(engine->kernel_context);
887 GEM_BUG_ON(!llist_empty(&engine->barrier_tasks));
889 intel_wa_list_free(&engine->ctx_wa_list);
890 intel_wa_list_free(&engine->wa_list);
891 intel_wa_list_free(&engine->whitelist);
894 u64 intel_engine_get_active_head(const struct intel_engine_cs *engine)
896 struct drm_i915_private *i915 = engine->i915;
900 if (INTEL_GEN(i915) >= 8)
901 acthd = ENGINE_READ64(engine, RING_ACTHD, RING_ACTHD_UDW);
902 else if (INTEL_GEN(i915) >= 4)
903 acthd = ENGINE_READ(engine, RING_ACTHD);
905 acthd = ENGINE_READ(engine, ACTHD);
910 u64 intel_engine_get_last_batch_head(const struct intel_engine_cs *engine)
914 if (INTEL_GEN(engine->i915) >= 8)
915 bbaddr = ENGINE_READ64(engine, RING_BBADDR, RING_BBADDR_UDW);
917 bbaddr = ENGINE_READ(engine, RING_BBADDR);
922 int intel_engine_stop_cs(struct intel_engine_cs *engine)
924 struct intel_uncore *uncore = engine->uncore;
925 const u32 base = engine->mmio_base;
926 const i915_reg_t mode = RING_MI_MODE(base);
929 if (INTEL_GEN(engine->i915) < 3)
932 GEM_TRACE("%s\n", engine->name);
934 intel_uncore_write_fw(uncore, mode, _MASKED_BIT_ENABLE(STOP_RING));
937 if (__intel_wait_for_register_fw(uncore,
938 mode, MODE_IDLE, MODE_IDLE,
941 GEM_TRACE("%s: timed out on STOP_RING -> IDLE\n", engine->name);
945 /* A final mmio read to let GPU writes be hopefully flushed to memory */
946 intel_uncore_posting_read_fw(uncore, mode);
951 void intel_engine_cancel_stop_cs(struct intel_engine_cs *engine)
953 GEM_TRACE("%s\n", engine->name);
955 ENGINE_WRITE_FW(engine, RING_MI_MODE, _MASKED_BIT_DISABLE(STOP_RING));
958 const char *i915_cache_level_str(struct drm_i915_private *i915, int type)
961 case I915_CACHE_NONE: return " uncached";
962 case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped";
963 case I915_CACHE_L3_LLC: return " L3+LLC";
964 case I915_CACHE_WT: return " WT";
969 u32 intel_calculate_mcr_s_ss_select(struct drm_i915_private *dev_priv)
971 const struct sseu_dev_info *sseu = &RUNTIME_INFO(dev_priv)->sseu;
972 unsigned int slice = fls(sseu->slice_mask) - 1;
973 unsigned int subslice;
976 GEM_BUG_ON(slice >= ARRAY_SIZE(sseu->subslice_mask));
977 subslice = fls(sseu->subslice_mask[slice]);
978 GEM_BUG_ON(!subslice);
981 if (IS_GEN(dev_priv, 10))
982 mcr_s_ss_select = GEN8_MCR_SLICE(slice) |
983 GEN8_MCR_SUBSLICE(subslice);
984 else if (INTEL_GEN(dev_priv) >= 11)
985 mcr_s_ss_select = GEN11_MCR_SLICE(slice) |
986 GEN11_MCR_SUBSLICE(subslice);
990 return mcr_s_ss_select;
994 read_subslice_reg(struct intel_engine_cs *engine, int slice, int subslice,
997 struct drm_i915_private *i915 = engine->i915;
998 struct intel_uncore *uncore = engine->uncore;
999 u32 mcr_slice_subslice_mask;
1000 u32 mcr_slice_subslice_select;
1001 u32 default_mcr_s_ss_select;
1004 enum forcewake_domains fw_domains;
1006 if (INTEL_GEN(i915) >= 11) {
1007 mcr_slice_subslice_mask = GEN11_MCR_SLICE_MASK |
1008 GEN11_MCR_SUBSLICE_MASK;
1009 mcr_slice_subslice_select = GEN11_MCR_SLICE(slice) |
1010 GEN11_MCR_SUBSLICE(subslice);
1012 mcr_slice_subslice_mask = GEN8_MCR_SLICE_MASK |
1013 GEN8_MCR_SUBSLICE_MASK;
1014 mcr_slice_subslice_select = GEN8_MCR_SLICE(slice) |
1015 GEN8_MCR_SUBSLICE(subslice);
1018 default_mcr_s_ss_select = intel_calculate_mcr_s_ss_select(i915);
1020 fw_domains = intel_uncore_forcewake_for_reg(uncore, reg,
1022 fw_domains |= intel_uncore_forcewake_for_reg(uncore,
1024 FW_REG_READ | FW_REG_WRITE);
1026 spin_lock_irq(&uncore->lock);
1027 intel_uncore_forcewake_get__locked(uncore, fw_domains);
1029 mcr = intel_uncore_read_fw(uncore, GEN8_MCR_SELECTOR);
1031 WARN_ON_ONCE((mcr & mcr_slice_subslice_mask) !=
1032 default_mcr_s_ss_select);
1034 mcr &= ~mcr_slice_subslice_mask;
1035 mcr |= mcr_slice_subslice_select;
1036 intel_uncore_write_fw(uncore, GEN8_MCR_SELECTOR, mcr);
1038 ret = intel_uncore_read_fw(uncore, reg);
1040 mcr &= ~mcr_slice_subslice_mask;
1041 mcr |= default_mcr_s_ss_select;
1043 intel_uncore_write_fw(uncore, GEN8_MCR_SELECTOR, mcr);
1045 intel_uncore_forcewake_put__locked(uncore, fw_domains);
1046 spin_unlock_irq(&uncore->lock);
1051 /* NB: please notice the memset */
1052 void intel_engine_get_instdone(struct intel_engine_cs *engine,
1053 struct intel_instdone *instdone)
1055 struct drm_i915_private *i915 = engine->i915;
1056 struct intel_uncore *uncore = engine->uncore;
1057 u32 mmio_base = engine->mmio_base;
1061 memset(instdone, 0, sizeof(*instdone));
1063 switch (INTEL_GEN(i915)) {
1065 instdone->instdone =
1066 intel_uncore_read(uncore, RING_INSTDONE(mmio_base));
1068 if (engine->id != RCS0)
1071 instdone->slice_common =
1072 intel_uncore_read(uncore, GEN7_SC_INSTDONE);
1073 for_each_instdone_slice_subslice(i915, slice, subslice) {
1074 instdone->sampler[slice][subslice] =
1075 read_subslice_reg(engine, slice, subslice,
1076 GEN7_SAMPLER_INSTDONE);
1077 instdone->row[slice][subslice] =
1078 read_subslice_reg(engine, slice, subslice,
1083 instdone->instdone =
1084 intel_uncore_read(uncore, RING_INSTDONE(mmio_base));
1086 if (engine->id != RCS0)
1089 instdone->slice_common =
1090 intel_uncore_read(uncore, GEN7_SC_INSTDONE);
1091 instdone->sampler[0][0] =
1092 intel_uncore_read(uncore, GEN7_SAMPLER_INSTDONE);
1093 instdone->row[0][0] =
1094 intel_uncore_read(uncore, GEN7_ROW_INSTDONE);
1100 instdone->instdone =
1101 intel_uncore_read(uncore, RING_INSTDONE(mmio_base));
1102 if (engine->id == RCS0)
1103 /* HACK: Using the wrong struct member */
1104 instdone->slice_common =
1105 intel_uncore_read(uncore, GEN4_INSTDONE1);
1109 instdone->instdone = intel_uncore_read(uncore, GEN2_INSTDONE);
1114 static bool ring_is_idle(struct intel_engine_cs *engine)
1116 struct drm_i915_private *dev_priv = engine->i915;
1117 intel_wakeref_t wakeref;
1120 if (I915_SELFTEST_ONLY(!engine->mmio_base))
1123 /* If the whole device is asleep, the engine must be idle */
1124 wakeref = intel_runtime_pm_get_if_in_use(&dev_priv->runtime_pm);
1128 /* First check that no commands are left in the ring */
1129 if ((ENGINE_READ(engine, RING_HEAD) & HEAD_ADDR) !=
1130 (ENGINE_READ(engine, RING_TAIL) & TAIL_ADDR))
1133 /* No bit for gen2, so assume the CS parser is idle */
1134 if (INTEL_GEN(dev_priv) > 2 &&
1135 !(ENGINE_READ(engine, RING_MI_MODE) & MODE_IDLE))
1138 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
1144 * intel_engine_is_idle() - Report if the engine has finished process all work
1145 * @engine: the intel_engine_cs
1147 * Return true if there are no requests pending, nothing left to be submitted
1148 * to hardware, and that the engine is idle.
1150 bool intel_engine_is_idle(struct intel_engine_cs *engine)
1152 /* More white lies, if wedged, hw state is inconsistent */
1153 if (i915_reset_failed(engine->i915))
1156 if (!intel_wakeref_active(&engine->wakeref))
1159 /* Waiting to drain ELSP? */
1160 if (READ_ONCE(engine->execlists.active)) {
1161 struct tasklet_struct *t = &engine->execlists.tasklet;
1163 synchronize_hardirq(engine->i915->drm.irq);
1166 if (tasklet_trylock(t)) {
1167 /* Must wait for any GPU reset in progress. */
1168 if (__tasklet_is_enabled(t))
1174 /* Otherwise flush the tasklet if it was on another cpu */
1175 tasklet_unlock_wait(t);
1177 if (READ_ONCE(engine->execlists.active))
1181 /* ELSP is empty, but there are ready requests? E.g. after reset */
1182 if (!RB_EMPTY_ROOT(&engine->execlists.queue.rb_root))
1186 return ring_is_idle(engine);
1189 bool intel_engines_are_idle(struct drm_i915_private *i915)
1191 struct intel_engine_cs *engine;
1192 enum intel_engine_id id;
1195 * If the driver is wedged, HW state may be very inconsistent and
1196 * report that it is still busy, even though we have stopped using it.
1198 if (i915_reset_failed(i915))
1201 /* Already parked (and passed an idleness test); must still be idle */
1202 if (!READ_ONCE(i915->gt.awake))
1205 for_each_engine(engine, i915, id) {
1206 if (!intel_engine_is_idle(engine))
1213 void intel_engines_reset_default_submission(struct drm_i915_private *i915)
1215 struct intel_engine_cs *engine;
1216 enum intel_engine_id id;
1218 for_each_engine(engine, i915, id)
1219 engine->set_default_submission(engine);
1222 bool intel_engine_can_store_dword(struct intel_engine_cs *engine)
1224 switch (INTEL_GEN(engine->i915)) {
1226 return false; /* uses physical not virtual addresses */
1228 /* maybe only uses physical not virtual addresses */
1229 return !(IS_I915G(engine->i915) || IS_I915GM(engine->i915));
1231 return engine->class != VIDEO_DECODE_CLASS; /* b0rked */
1237 unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915)
1239 struct intel_engine_cs *engine;
1240 enum intel_engine_id id;
1244 for_each_engine(engine, i915, id)
1245 if (engine->default_state)
1246 which |= BIT(engine->uabi_class);
1251 static int print_sched_attr(struct drm_i915_private *i915,
1252 const struct i915_sched_attr *attr,
1253 char *buf, int x, int len)
1255 if (attr->priority == I915_PRIORITY_INVALID)
1258 x += snprintf(buf + x, len - x,
1259 " prio=%d", attr->priority);
1264 static void print_request(struct drm_printer *m,
1265 struct i915_request *rq,
1268 const char *name = rq->fence.ops->get_timeline_name(&rq->fence);
1272 x = print_sched_attr(rq->i915, &rq->sched.attr, buf, x, sizeof(buf));
1274 drm_printf(m, "%s %llx:%llx%s%s %s @ %dms: %s\n",
1276 rq->fence.context, rq->fence.seqno,
1277 i915_request_completed(rq) ? "!" :
1278 i915_request_started(rq) ? "*" :
1280 test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
1281 &rq->fence.flags) ? "+" :
1282 test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
1283 &rq->fence.flags) ? "-" :
1286 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
1290 static void hexdump(struct drm_printer *m, const void *buf, size_t len)
1292 const size_t rowsize = 8 * sizeof(u32);
1293 const void *prev = NULL;
1297 for (pos = 0; pos < len; pos += rowsize) {
1300 if (prev && !memcmp(prev, buf + pos, rowsize)) {
1302 drm_printf(m, "*\n");
1308 WARN_ON_ONCE(hex_dump_to_buffer(buf + pos, len - pos,
1309 rowsize, sizeof(u32),
1311 false) >= sizeof(line));
1312 drm_printf(m, "[%04zx] %s\n", pos, line);
1319 static void intel_engine_print_registers(struct intel_engine_cs *engine,
1320 struct drm_printer *m)
1322 struct drm_i915_private *dev_priv = engine->i915;
1323 const struct intel_engine_execlists * const execlists =
1325 unsigned long flags;
1328 if (engine->id == RCS0 && IS_GEN_RANGE(dev_priv, 4, 7))
1329 drm_printf(m, "\tCCID: 0x%08x\n", ENGINE_READ(engine, CCID));
1330 drm_printf(m, "\tRING_START: 0x%08x\n",
1331 ENGINE_READ(engine, RING_START));
1332 drm_printf(m, "\tRING_HEAD: 0x%08x\n",
1333 ENGINE_READ(engine, RING_HEAD) & HEAD_ADDR);
1334 drm_printf(m, "\tRING_TAIL: 0x%08x\n",
1335 ENGINE_READ(engine, RING_TAIL) & TAIL_ADDR);
1336 drm_printf(m, "\tRING_CTL: 0x%08x%s\n",
1337 ENGINE_READ(engine, RING_CTL),
1338 ENGINE_READ(engine, RING_CTL) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? " [waiting]" : "");
1339 if (INTEL_GEN(engine->i915) > 2) {
1340 drm_printf(m, "\tRING_MODE: 0x%08x%s\n",
1341 ENGINE_READ(engine, RING_MI_MODE),
1342 ENGINE_READ(engine, RING_MI_MODE) & (MODE_IDLE) ? " [idle]" : "");
1345 if (INTEL_GEN(dev_priv) >= 6) {
1346 drm_printf(m, "\tRING_IMR: %08x\n",
1347 ENGINE_READ(engine, RING_IMR));
1350 addr = intel_engine_get_active_head(engine);
1351 drm_printf(m, "\tACTHD: 0x%08x_%08x\n",
1352 upper_32_bits(addr), lower_32_bits(addr));
1353 addr = intel_engine_get_last_batch_head(engine);
1354 drm_printf(m, "\tBBADDR: 0x%08x_%08x\n",
1355 upper_32_bits(addr), lower_32_bits(addr));
1356 if (INTEL_GEN(dev_priv) >= 8)
1357 addr = ENGINE_READ64(engine, RING_DMA_FADD, RING_DMA_FADD_UDW);
1358 else if (INTEL_GEN(dev_priv) >= 4)
1359 addr = ENGINE_READ(engine, RING_DMA_FADD);
1361 addr = ENGINE_READ(engine, DMA_FADD_I8XX);
1362 drm_printf(m, "\tDMA_FADDR: 0x%08x_%08x\n",
1363 upper_32_bits(addr), lower_32_bits(addr));
1364 if (INTEL_GEN(dev_priv) >= 4) {
1365 drm_printf(m, "\tIPEIR: 0x%08x\n",
1366 ENGINE_READ(engine, RING_IPEIR));
1367 drm_printf(m, "\tIPEHR: 0x%08x\n",
1368 ENGINE_READ(engine, RING_IPEHR));
1370 drm_printf(m, "\tIPEIR: 0x%08x\n", ENGINE_READ(engine, IPEIR));
1371 drm_printf(m, "\tIPEHR: 0x%08x\n", ENGINE_READ(engine, IPEHR));
1374 if (HAS_EXECLISTS(dev_priv)) {
1376 &engine->status_page.addr[I915_HWS_CSB_BUF0_INDEX];
1377 const u8 num_entries = execlists->csb_size;
1381 drm_printf(m, "\tExeclist status: 0x%08x %08x, entries %u\n",
1382 ENGINE_READ(engine, RING_EXECLIST_STATUS_LO),
1383 ENGINE_READ(engine, RING_EXECLIST_STATUS_HI),
1386 read = execlists->csb_head;
1387 write = READ_ONCE(*execlists->csb_write);
1389 drm_printf(m, "\tExeclist CSB read %d, write %d, tasklet queued? %s (%s)\n",
1391 yesno(test_bit(TASKLET_STATE_SCHED,
1392 &engine->execlists.tasklet.state)),
1393 enableddisabled(!atomic_read(&engine->execlists.tasklet.count)));
1394 if (read >= num_entries)
1396 if (write >= num_entries)
1399 write += num_entries;
1400 while (read < write) {
1401 idx = ++read % num_entries;
1402 drm_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
1403 idx, hws[idx * 2], hws[idx * 2 + 1]);
1406 spin_lock_irqsave(&engine->active.lock, flags);
1407 for (idx = 0; idx < execlists_num_ports(execlists); idx++) {
1408 struct i915_request *rq;
1412 rq = port_unpack(&execlists->port[idx], &count);
1414 drm_printf(m, "\t\tELSP[%d] idle\n", idx);
1415 } else if (!i915_request_signaled(rq)) {
1416 snprintf(hdr, sizeof(hdr),
1417 "\t\tELSP[%d] count=%d, ring:{start:%08x, hwsp:%08x, seqno:%08x}, rq: ",
1419 i915_ggtt_offset(rq->ring->vma),
1420 rq->timeline->hwsp_offset,
1422 print_request(m, rq, hdr);
1424 print_request(m, rq, "\t\tELSP[%d] rq: ");
1427 drm_printf(m, "\t\tHW active? 0x%x\n", execlists->active);
1428 spin_unlock_irqrestore(&engine->active.lock, flags);
1429 } else if (INTEL_GEN(dev_priv) > 6) {
1430 drm_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
1431 ENGINE_READ(engine, RING_PP_DIR_BASE));
1432 drm_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
1433 ENGINE_READ(engine, RING_PP_DIR_BASE_READ));
1434 drm_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
1435 ENGINE_READ(engine, RING_PP_DIR_DCLV));
1439 static void print_request_ring(struct drm_printer *m, struct i915_request *rq)
1445 "[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]:\n",
1446 rq->head, rq->postfix, rq->tail,
1447 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
1448 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
1450 size = rq->tail - rq->head;
1451 if (rq->tail < rq->head)
1452 size += rq->ring->size;
1454 ring = kmalloc(size, GFP_ATOMIC);
1456 const void *vaddr = rq->ring->vaddr;
1457 unsigned int head = rq->head;
1458 unsigned int len = 0;
1460 if (rq->tail < head) {
1461 len = rq->ring->size - head;
1462 memcpy(ring, vaddr + head, len);
1465 memcpy(ring + len, vaddr + head, size - len);
1467 hexdump(m, ring, size);
1472 void intel_engine_dump(struct intel_engine_cs *engine,
1473 struct drm_printer *m,
1474 const char *header, ...)
1476 struct i915_gpu_error * const error = &engine->i915->gpu_error;
1477 struct i915_request *rq;
1478 intel_wakeref_t wakeref;
1479 unsigned long flags;
1484 va_start(ap, header);
1485 drm_vprintf(m, header, &ap);
1489 if (i915_reset_failed(engine->i915))
1490 drm_printf(m, "*** WEDGED ***\n");
1492 drm_printf(m, "\tAwake? %d\n", atomic_read(&engine->wakeref.count));
1493 drm_printf(m, "\tHangcheck: %d ms ago\n",
1494 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
1495 drm_printf(m, "\tReset count: %d (global %d)\n",
1496 i915_reset_engine_count(error, engine),
1497 i915_reset_count(error));
1499 drm_printf(m, "\tRequests:\n");
1501 spin_lock_irqsave(&engine->active.lock, flags);
1502 rq = intel_engine_find_active_request(engine);
1504 print_request(m, rq, "\t\tactive ");
1506 drm_printf(m, "\t\tring->start: 0x%08x\n",
1507 i915_ggtt_offset(rq->ring->vma));
1508 drm_printf(m, "\t\tring->head: 0x%08x\n",
1510 drm_printf(m, "\t\tring->tail: 0x%08x\n",
1512 drm_printf(m, "\t\tring->emit: 0x%08x\n",
1514 drm_printf(m, "\t\tring->space: 0x%08x\n",
1516 drm_printf(m, "\t\tring->hwsp: 0x%08x\n",
1517 rq->timeline->hwsp_offset);
1519 print_request_ring(m, rq);
1521 spin_unlock_irqrestore(&engine->active.lock, flags);
1523 wakeref = intel_runtime_pm_get_if_in_use(&engine->i915->runtime_pm);
1525 intel_engine_print_registers(engine, m);
1526 intel_runtime_pm_put(&engine->i915->runtime_pm, wakeref);
1528 drm_printf(m, "\tDevice is asleep; skipping register dump\n");
1531 intel_execlists_show_requests(engine, m, print_request, 8);
1533 drm_printf(m, "HWSP:\n");
1534 hexdump(m, engine->status_page.addr, PAGE_SIZE);
1536 drm_printf(m, "Idle? %s\n", yesno(intel_engine_is_idle(engine)));
1538 intel_engine_print_breadcrumbs(engine, m);
1541 static u8 user_class_map[] = {
1542 [I915_ENGINE_CLASS_RENDER] = RENDER_CLASS,
1543 [I915_ENGINE_CLASS_COPY] = COPY_ENGINE_CLASS,
1544 [I915_ENGINE_CLASS_VIDEO] = VIDEO_DECODE_CLASS,
1545 [I915_ENGINE_CLASS_VIDEO_ENHANCE] = VIDEO_ENHANCEMENT_CLASS,
1548 struct intel_engine_cs *
1549 intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance)
1551 if (class >= ARRAY_SIZE(user_class_map))
1554 class = user_class_map[class];
1556 GEM_BUG_ON(class > MAX_ENGINE_CLASS);
1558 if (instance > MAX_ENGINE_INSTANCE)
1561 return i915->engine_class[class][instance];
1565 * intel_enable_engine_stats() - Enable engine busy tracking on engine
1566 * @engine: engine to enable stats collection
1568 * Start collecting the engine busyness data for @engine.
1570 * Returns 0 on success or a negative error code.
1572 int intel_enable_engine_stats(struct intel_engine_cs *engine)
1574 struct intel_engine_execlists *execlists = &engine->execlists;
1575 unsigned long flags;
1578 if (!intel_engine_supports_stats(engine))
1581 spin_lock_irqsave(&engine->active.lock, flags);
1582 write_seqlock(&engine->stats.lock);
1584 if (unlikely(engine->stats.enabled == ~0)) {
1589 if (engine->stats.enabled++ == 0) {
1590 const struct execlist_port *port = execlists->port;
1591 unsigned int num_ports = execlists_num_ports(execlists);
1593 engine->stats.enabled_at = ktime_get();
1595 /* XXX submission method oblivious? */
1596 while (num_ports-- && port_isset(port)) {
1597 engine->stats.active++;
1601 if (engine->stats.active)
1602 engine->stats.start = engine->stats.enabled_at;
1606 write_sequnlock(&engine->stats.lock);
1607 spin_unlock_irqrestore(&engine->active.lock, flags);
1612 static ktime_t __intel_engine_get_busy_time(struct intel_engine_cs *engine)
1614 ktime_t total = engine->stats.total;
1617 * If the engine is executing something at the moment
1618 * add it to the total.
1620 if (engine->stats.active)
1621 total = ktime_add(total,
1622 ktime_sub(ktime_get(), engine->stats.start));
1628 * intel_engine_get_busy_time() - Return current accumulated engine busyness
1629 * @engine: engine to report on
1631 * Returns accumulated time @engine was busy since engine stats were enabled.
1633 ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine)
1639 seq = read_seqbegin(&engine->stats.lock);
1640 total = __intel_engine_get_busy_time(engine);
1641 } while (read_seqretry(&engine->stats.lock, seq));
1647 * intel_disable_engine_stats() - Disable engine busy tracking on engine
1648 * @engine: engine to disable stats collection
1650 * Stops collecting the engine busyness data for @engine.
1652 void intel_disable_engine_stats(struct intel_engine_cs *engine)
1654 unsigned long flags;
1656 if (!intel_engine_supports_stats(engine))
1659 write_seqlock_irqsave(&engine->stats.lock, flags);
1660 WARN_ON_ONCE(engine->stats.enabled == 0);
1661 if (--engine->stats.enabled == 0) {
1662 engine->stats.total = __intel_engine_get_busy_time(engine);
1663 engine->stats.active = 0;
1665 write_sequnlock_irqrestore(&engine->stats.lock, flags);
1668 static bool match_ring(struct i915_request *rq)
1670 u32 ring = ENGINE_READ(rq->engine, RING_START);
1672 return ring == i915_ggtt_offset(rq->ring->vma);
1675 struct i915_request *
1676 intel_engine_find_active_request(struct intel_engine_cs *engine)
1678 struct i915_request *request, *active = NULL;
1681 * We are called by the error capture, reset and to dump engine
1682 * state at random points in time. In particular, note that neither is
1683 * crucially ordered with an interrupt. After a hang, the GPU is dead
1684 * and we assume that no more writes can happen (we waited long enough
1685 * for all writes that were in transaction to be flushed) - adding an
1686 * extra delay for a recent interrupt is pointless. Hence, we do
1687 * not need an engine->irq_seqno_barrier() before the seqno reads.
1688 * At all other times, we must assume the GPU is still running, but
1689 * we only care about the snapshot of this moment.
1691 lockdep_assert_held(&engine->active.lock);
1692 list_for_each_entry(request, &engine->active.requests, sched.link) {
1693 if (i915_request_completed(request))
1696 if (!i915_request_started(request))
1699 /* More than one preemptible request may match! */
1700 if (!match_ring(request))
1710 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
1711 #include "selftest_engine_cs.c"