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;
973 u32 slice = fls(sseu->slice_mask);
974 u32 subslice = fls(sseu->subslice_mask[slice]);
976 if (IS_GEN(dev_priv, 10))
977 mcr_s_ss_select = GEN8_MCR_SLICE(slice) |
978 GEN8_MCR_SUBSLICE(subslice);
979 else if (INTEL_GEN(dev_priv) >= 11)
980 mcr_s_ss_select = GEN11_MCR_SLICE(slice) |
981 GEN11_MCR_SUBSLICE(subslice);
985 return mcr_s_ss_select;
989 read_subslice_reg(struct intel_engine_cs *engine, int slice, int subslice,
992 struct drm_i915_private *i915 = engine->i915;
993 struct intel_uncore *uncore = engine->uncore;
994 u32 mcr_slice_subslice_mask;
995 u32 mcr_slice_subslice_select;
996 u32 default_mcr_s_ss_select;
999 enum forcewake_domains fw_domains;
1001 if (INTEL_GEN(i915) >= 11) {
1002 mcr_slice_subslice_mask = GEN11_MCR_SLICE_MASK |
1003 GEN11_MCR_SUBSLICE_MASK;
1004 mcr_slice_subslice_select = GEN11_MCR_SLICE(slice) |
1005 GEN11_MCR_SUBSLICE(subslice);
1007 mcr_slice_subslice_mask = GEN8_MCR_SLICE_MASK |
1008 GEN8_MCR_SUBSLICE_MASK;
1009 mcr_slice_subslice_select = GEN8_MCR_SLICE(slice) |
1010 GEN8_MCR_SUBSLICE(subslice);
1013 default_mcr_s_ss_select = intel_calculate_mcr_s_ss_select(i915);
1015 fw_domains = intel_uncore_forcewake_for_reg(uncore, reg,
1017 fw_domains |= intel_uncore_forcewake_for_reg(uncore,
1019 FW_REG_READ | FW_REG_WRITE);
1021 spin_lock_irq(&uncore->lock);
1022 intel_uncore_forcewake_get__locked(uncore, fw_domains);
1024 mcr = intel_uncore_read_fw(uncore, GEN8_MCR_SELECTOR);
1026 WARN_ON_ONCE((mcr & mcr_slice_subslice_mask) !=
1027 default_mcr_s_ss_select);
1029 mcr &= ~mcr_slice_subslice_mask;
1030 mcr |= mcr_slice_subslice_select;
1031 intel_uncore_write_fw(uncore, GEN8_MCR_SELECTOR, mcr);
1033 ret = intel_uncore_read_fw(uncore, reg);
1035 mcr &= ~mcr_slice_subslice_mask;
1036 mcr |= default_mcr_s_ss_select;
1038 intel_uncore_write_fw(uncore, GEN8_MCR_SELECTOR, mcr);
1040 intel_uncore_forcewake_put__locked(uncore, fw_domains);
1041 spin_unlock_irq(&uncore->lock);
1046 /* NB: please notice the memset */
1047 void intel_engine_get_instdone(struct intel_engine_cs *engine,
1048 struct intel_instdone *instdone)
1050 struct drm_i915_private *i915 = engine->i915;
1051 struct intel_uncore *uncore = engine->uncore;
1052 u32 mmio_base = engine->mmio_base;
1056 memset(instdone, 0, sizeof(*instdone));
1058 switch (INTEL_GEN(i915)) {
1060 instdone->instdone =
1061 intel_uncore_read(uncore, RING_INSTDONE(mmio_base));
1063 if (engine->id != RCS0)
1066 instdone->slice_common =
1067 intel_uncore_read(uncore, GEN7_SC_INSTDONE);
1068 for_each_instdone_slice_subslice(i915, slice, subslice) {
1069 instdone->sampler[slice][subslice] =
1070 read_subslice_reg(engine, slice, subslice,
1071 GEN7_SAMPLER_INSTDONE);
1072 instdone->row[slice][subslice] =
1073 read_subslice_reg(engine, slice, subslice,
1078 instdone->instdone =
1079 intel_uncore_read(uncore, RING_INSTDONE(mmio_base));
1081 if (engine->id != RCS0)
1084 instdone->slice_common =
1085 intel_uncore_read(uncore, GEN7_SC_INSTDONE);
1086 instdone->sampler[0][0] =
1087 intel_uncore_read(uncore, GEN7_SAMPLER_INSTDONE);
1088 instdone->row[0][0] =
1089 intel_uncore_read(uncore, GEN7_ROW_INSTDONE);
1095 instdone->instdone =
1096 intel_uncore_read(uncore, RING_INSTDONE(mmio_base));
1097 if (engine->id == RCS0)
1098 /* HACK: Using the wrong struct member */
1099 instdone->slice_common =
1100 intel_uncore_read(uncore, GEN4_INSTDONE1);
1104 instdone->instdone = intel_uncore_read(uncore, GEN2_INSTDONE);
1109 static bool ring_is_idle(struct intel_engine_cs *engine)
1111 struct drm_i915_private *dev_priv = engine->i915;
1112 intel_wakeref_t wakeref;
1115 if (I915_SELFTEST_ONLY(!engine->mmio_base))
1118 /* If the whole device is asleep, the engine must be idle */
1119 wakeref = intel_runtime_pm_get_if_in_use(&dev_priv->runtime_pm);
1123 /* First check that no commands are left in the ring */
1124 if ((ENGINE_READ(engine, RING_HEAD) & HEAD_ADDR) !=
1125 (ENGINE_READ(engine, RING_TAIL) & TAIL_ADDR))
1128 /* No bit for gen2, so assume the CS parser is idle */
1129 if (INTEL_GEN(dev_priv) > 2 &&
1130 !(ENGINE_READ(engine, RING_MI_MODE) & MODE_IDLE))
1133 intel_runtime_pm_put(&dev_priv->runtime_pm, wakeref);
1139 * intel_engine_is_idle() - Report if the engine has finished process all work
1140 * @engine: the intel_engine_cs
1142 * Return true if there are no requests pending, nothing left to be submitted
1143 * to hardware, and that the engine is idle.
1145 bool intel_engine_is_idle(struct intel_engine_cs *engine)
1147 /* More white lies, if wedged, hw state is inconsistent */
1148 if (i915_reset_failed(engine->i915))
1151 if (!intel_wakeref_active(&engine->wakeref))
1154 /* Waiting to drain ELSP? */
1155 if (READ_ONCE(engine->execlists.active)) {
1156 struct tasklet_struct *t = &engine->execlists.tasklet;
1158 synchronize_hardirq(engine->i915->drm.irq);
1161 if (tasklet_trylock(t)) {
1162 /* Must wait for any GPU reset in progress. */
1163 if (__tasklet_is_enabled(t))
1169 /* Otherwise flush the tasklet if it was on another cpu */
1170 tasklet_unlock_wait(t);
1172 if (READ_ONCE(engine->execlists.active))
1176 /* ELSP is empty, but there are ready requests? E.g. after reset */
1177 if (!RB_EMPTY_ROOT(&engine->execlists.queue.rb_root))
1181 return ring_is_idle(engine);
1184 bool intel_engines_are_idle(struct drm_i915_private *i915)
1186 struct intel_engine_cs *engine;
1187 enum intel_engine_id id;
1190 * If the driver is wedged, HW state may be very inconsistent and
1191 * report that it is still busy, even though we have stopped using it.
1193 if (i915_reset_failed(i915))
1196 /* Already parked (and passed an idleness test); must still be idle */
1197 if (!READ_ONCE(i915->gt.awake))
1200 for_each_engine(engine, i915, id) {
1201 if (!intel_engine_is_idle(engine))
1208 void intel_engines_reset_default_submission(struct drm_i915_private *i915)
1210 struct intel_engine_cs *engine;
1211 enum intel_engine_id id;
1213 for_each_engine(engine, i915, id)
1214 engine->set_default_submission(engine);
1217 bool intel_engine_can_store_dword(struct intel_engine_cs *engine)
1219 switch (INTEL_GEN(engine->i915)) {
1221 return false; /* uses physical not virtual addresses */
1223 /* maybe only uses physical not virtual addresses */
1224 return !(IS_I915G(engine->i915) || IS_I915GM(engine->i915));
1226 return engine->class != VIDEO_DECODE_CLASS; /* b0rked */
1232 unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915)
1234 struct intel_engine_cs *engine;
1235 enum intel_engine_id id;
1239 for_each_engine(engine, i915, id)
1240 if (engine->default_state)
1241 which |= BIT(engine->uabi_class);
1246 static int print_sched_attr(struct drm_i915_private *i915,
1247 const struct i915_sched_attr *attr,
1248 char *buf, int x, int len)
1250 if (attr->priority == I915_PRIORITY_INVALID)
1253 x += snprintf(buf + x, len - x,
1254 " prio=%d", attr->priority);
1259 static void print_request(struct drm_printer *m,
1260 struct i915_request *rq,
1263 const char *name = rq->fence.ops->get_timeline_name(&rq->fence);
1267 x = print_sched_attr(rq->i915, &rq->sched.attr, buf, x, sizeof(buf));
1269 drm_printf(m, "%s %llx:%llx%s%s %s @ %dms: %s\n",
1271 rq->fence.context, rq->fence.seqno,
1272 i915_request_completed(rq) ? "!" :
1273 i915_request_started(rq) ? "*" :
1275 test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
1276 &rq->fence.flags) ? "+" :
1277 test_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
1278 &rq->fence.flags) ? "-" :
1281 jiffies_to_msecs(jiffies - rq->emitted_jiffies),
1285 static void hexdump(struct drm_printer *m, const void *buf, size_t len)
1287 const size_t rowsize = 8 * sizeof(u32);
1288 const void *prev = NULL;
1292 for (pos = 0; pos < len; pos += rowsize) {
1295 if (prev && !memcmp(prev, buf + pos, rowsize)) {
1297 drm_printf(m, "*\n");
1303 WARN_ON_ONCE(hex_dump_to_buffer(buf + pos, len - pos,
1304 rowsize, sizeof(u32),
1306 false) >= sizeof(line));
1307 drm_printf(m, "[%04zx] %s\n", pos, line);
1314 static void intel_engine_print_registers(struct intel_engine_cs *engine,
1315 struct drm_printer *m)
1317 struct drm_i915_private *dev_priv = engine->i915;
1318 const struct intel_engine_execlists * const execlists =
1320 unsigned long flags;
1323 if (engine->id == RCS0 && IS_GEN_RANGE(dev_priv, 4, 7))
1324 drm_printf(m, "\tCCID: 0x%08x\n", ENGINE_READ(engine, CCID));
1325 drm_printf(m, "\tRING_START: 0x%08x\n",
1326 ENGINE_READ(engine, RING_START));
1327 drm_printf(m, "\tRING_HEAD: 0x%08x\n",
1328 ENGINE_READ(engine, RING_HEAD) & HEAD_ADDR);
1329 drm_printf(m, "\tRING_TAIL: 0x%08x\n",
1330 ENGINE_READ(engine, RING_TAIL) & TAIL_ADDR);
1331 drm_printf(m, "\tRING_CTL: 0x%08x%s\n",
1332 ENGINE_READ(engine, RING_CTL),
1333 ENGINE_READ(engine, RING_CTL) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? " [waiting]" : "");
1334 if (INTEL_GEN(engine->i915) > 2) {
1335 drm_printf(m, "\tRING_MODE: 0x%08x%s\n",
1336 ENGINE_READ(engine, RING_MI_MODE),
1337 ENGINE_READ(engine, RING_MI_MODE) & (MODE_IDLE) ? " [idle]" : "");
1340 if (INTEL_GEN(dev_priv) >= 6) {
1341 drm_printf(m, "\tRING_IMR: %08x\n",
1342 ENGINE_READ(engine, RING_IMR));
1345 addr = intel_engine_get_active_head(engine);
1346 drm_printf(m, "\tACTHD: 0x%08x_%08x\n",
1347 upper_32_bits(addr), lower_32_bits(addr));
1348 addr = intel_engine_get_last_batch_head(engine);
1349 drm_printf(m, "\tBBADDR: 0x%08x_%08x\n",
1350 upper_32_bits(addr), lower_32_bits(addr));
1351 if (INTEL_GEN(dev_priv) >= 8)
1352 addr = ENGINE_READ64(engine, RING_DMA_FADD, RING_DMA_FADD_UDW);
1353 else if (INTEL_GEN(dev_priv) >= 4)
1354 addr = ENGINE_READ(engine, RING_DMA_FADD);
1356 addr = ENGINE_READ(engine, DMA_FADD_I8XX);
1357 drm_printf(m, "\tDMA_FADDR: 0x%08x_%08x\n",
1358 upper_32_bits(addr), lower_32_bits(addr));
1359 if (INTEL_GEN(dev_priv) >= 4) {
1360 drm_printf(m, "\tIPEIR: 0x%08x\n",
1361 ENGINE_READ(engine, RING_IPEIR));
1362 drm_printf(m, "\tIPEHR: 0x%08x\n",
1363 ENGINE_READ(engine, RING_IPEHR));
1365 drm_printf(m, "\tIPEIR: 0x%08x\n", ENGINE_READ(engine, IPEIR));
1366 drm_printf(m, "\tIPEHR: 0x%08x\n", ENGINE_READ(engine, IPEHR));
1369 if (HAS_EXECLISTS(dev_priv)) {
1371 &engine->status_page.addr[I915_HWS_CSB_BUF0_INDEX];
1372 const u8 num_entries = execlists->csb_size;
1376 drm_printf(m, "\tExeclist status: 0x%08x %08x, entries %u\n",
1377 ENGINE_READ(engine, RING_EXECLIST_STATUS_LO),
1378 ENGINE_READ(engine, RING_EXECLIST_STATUS_HI),
1381 read = execlists->csb_head;
1382 write = READ_ONCE(*execlists->csb_write);
1384 drm_printf(m, "\tExeclist CSB read %d, write %d, tasklet queued? %s (%s)\n",
1386 yesno(test_bit(TASKLET_STATE_SCHED,
1387 &engine->execlists.tasklet.state)),
1388 enableddisabled(!atomic_read(&engine->execlists.tasklet.count)));
1389 if (read >= num_entries)
1391 if (write >= num_entries)
1394 write += num_entries;
1395 while (read < write) {
1396 idx = ++read % num_entries;
1397 drm_printf(m, "\tExeclist CSB[%d]: 0x%08x, context: %d\n",
1398 idx, hws[idx * 2], hws[idx * 2 + 1]);
1401 spin_lock_irqsave(&engine->active.lock, flags);
1402 for (idx = 0; idx < execlists_num_ports(execlists); idx++) {
1403 struct i915_request *rq;
1407 rq = port_unpack(&execlists->port[idx], &count);
1409 drm_printf(m, "\t\tELSP[%d] idle\n", idx);
1410 } else if (!i915_request_signaled(rq)) {
1411 snprintf(hdr, sizeof(hdr),
1412 "\t\tELSP[%d] count=%d, ring:{start:%08x, hwsp:%08x, seqno:%08x}, rq: ",
1414 i915_ggtt_offset(rq->ring->vma),
1415 rq->timeline->hwsp_offset,
1417 print_request(m, rq, hdr);
1419 print_request(m, rq, "\t\tELSP[%d] rq: ");
1422 drm_printf(m, "\t\tHW active? 0x%x\n", execlists->active);
1423 spin_unlock_irqrestore(&engine->active.lock, flags);
1424 } else if (INTEL_GEN(dev_priv) > 6) {
1425 drm_printf(m, "\tPP_DIR_BASE: 0x%08x\n",
1426 ENGINE_READ(engine, RING_PP_DIR_BASE));
1427 drm_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n",
1428 ENGINE_READ(engine, RING_PP_DIR_BASE_READ));
1429 drm_printf(m, "\tPP_DIR_DCLV: 0x%08x\n",
1430 ENGINE_READ(engine, RING_PP_DIR_DCLV));
1434 static void print_request_ring(struct drm_printer *m, struct i915_request *rq)
1440 "[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]:\n",
1441 rq->head, rq->postfix, rq->tail,
1442 rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u,
1443 rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u);
1445 size = rq->tail - rq->head;
1446 if (rq->tail < rq->head)
1447 size += rq->ring->size;
1449 ring = kmalloc(size, GFP_ATOMIC);
1451 const void *vaddr = rq->ring->vaddr;
1452 unsigned int head = rq->head;
1453 unsigned int len = 0;
1455 if (rq->tail < head) {
1456 len = rq->ring->size - head;
1457 memcpy(ring, vaddr + head, len);
1460 memcpy(ring + len, vaddr + head, size - len);
1462 hexdump(m, ring, size);
1467 void intel_engine_dump(struct intel_engine_cs *engine,
1468 struct drm_printer *m,
1469 const char *header, ...)
1471 struct i915_gpu_error * const error = &engine->i915->gpu_error;
1472 struct i915_request *rq;
1473 intel_wakeref_t wakeref;
1478 va_start(ap, header);
1479 drm_vprintf(m, header, &ap);
1483 if (i915_reset_failed(engine->i915))
1484 drm_printf(m, "*** WEDGED ***\n");
1486 drm_printf(m, "\tAwake? %d\n", atomic_read(&engine->wakeref.count));
1487 drm_printf(m, "\tHangcheck: %d ms ago\n",
1488 jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp));
1489 drm_printf(m, "\tReset count: %d (global %d)\n",
1490 i915_reset_engine_count(error, engine),
1491 i915_reset_count(error));
1495 drm_printf(m, "\tRequests:\n");
1497 rq = intel_engine_find_active_request(engine);
1499 print_request(m, rq, "\t\tactive ");
1501 drm_printf(m, "\t\tring->start: 0x%08x\n",
1502 i915_ggtt_offset(rq->ring->vma));
1503 drm_printf(m, "\t\tring->head: 0x%08x\n",
1505 drm_printf(m, "\t\tring->tail: 0x%08x\n",
1507 drm_printf(m, "\t\tring->emit: 0x%08x\n",
1509 drm_printf(m, "\t\tring->space: 0x%08x\n",
1511 drm_printf(m, "\t\tring->hwsp: 0x%08x\n",
1512 rq->timeline->hwsp_offset);
1514 print_request_ring(m, rq);
1519 wakeref = intel_runtime_pm_get_if_in_use(&engine->i915->runtime_pm);
1521 intel_engine_print_registers(engine, m);
1522 intel_runtime_pm_put(&engine->i915->runtime_pm, wakeref);
1524 drm_printf(m, "\tDevice is asleep; skipping register dump\n");
1527 intel_execlists_show_requests(engine, m, print_request, 8);
1529 drm_printf(m, "HWSP:\n");
1530 hexdump(m, engine->status_page.addr, PAGE_SIZE);
1532 drm_printf(m, "Idle? %s\n", yesno(intel_engine_is_idle(engine)));
1534 intel_engine_print_breadcrumbs(engine, m);
1537 static u8 user_class_map[] = {
1538 [I915_ENGINE_CLASS_RENDER] = RENDER_CLASS,
1539 [I915_ENGINE_CLASS_COPY] = COPY_ENGINE_CLASS,
1540 [I915_ENGINE_CLASS_VIDEO] = VIDEO_DECODE_CLASS,
1541 [I915_ENGINE_CLASS_VIDEO_ENHANCE] = VIDEO_ENHANCEMENT_CLASS,
1544 struct intel_engine_cs *
1545 intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance)
1547 if (class >= ARRAY_SIZE(user_class_map))
1550 class = user_class_map[class];
1552 GEM_BUG_ON(class > MAX_ENGINE_CLASS);
1554 if (instance > MAX_ENGINE_INSTANCE)
1557 return i915->engine_class[class][instance];
1561 * intel_enable_engine_stats() - Enable engine busy tracking on engine
1562 * @engine: engine to enable stats collection
1564 * Start collecting the engine busyness data for @engine.
1566 * Returns 0 on success or a negative error code.
1568 int intel_enable_engine_stats(struct intel_engine_cs *engine)
1570 struct intel_engine_execlists *execlists = &engine->execlists;
1571 unsigned long flags;
1574 if (!intel_engine_supports_stats(engine))
1577 spin_lock_irqsave(&engine->active.lock, flags);
1578 write_seqlock(&engine->stats.lock);
1580 if (unlikely(engine->stats.enabled == ~0)) {
1585 if (engine->stats.enabled++ == 0) {
1586 const struct execlist_port *port = execlists->port;
1587 unsigned int num_ports = execlists_num_ports(execlists);
1589 engine->stats.enabled_at = ktime_get();
1591 /* XXX submission method oblivious? */
1592 while (num_ports-- && port_isset(port)) {
1593 engine->stats.active++;
1597 if (engine->stats.active)
1598 engine->stats.start = engine->stats.enabled_at;
1602 write_sequnlock(&engine->stats.lock);
1603 spin_unlock_irqrestore(&engine->active.lock, flags);
1608 static ktime_t __intel_engine_get_busy_time(struct intel_engine_cs *engine)
1610 ktime_t total = engine->stats.total;
1613 * If the engine is executing something at the moment
1614 * add it to the total.
1616 if (engine->stats.active)
1617 total = ktime_add(total,
1618 ktime_sub(ktime_get(), engine->stats.start));
1624 * intel_engine_get_busy_time() - Return current accumulated engine busyness
1625 * @engine: engine to report on
1627 * Returns accumulated time @engine was busy since engine stats were enabled.
1629 ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine)
1635 seq = read_seqbegin(&engine->stats.lock);
1636 total = __intel_engine_get_busy_time(engine);
1637 } while (read_seqretry(&engine->stats.lock, seq));
1643 * intel_disable_engine_stats() - Disable engine busy tracking on engine
1644 * @engine: engine to disable stats collection
1646 * Stops collecting the engine busyness data for @engine.
1648 void intel_disable_engine_stats(struct intel_engine_cs *engine)
1650 unsigned long flags;
1652 if (!intel_engine_supports_stats(engine))
1655 write_seqlock_irqsave(&engine->stats.lock, flags);
1656 WARN_ON_ONCE(engine->stats.enabled == 0);
1657 if (--engine->stats.enabled == 0) {
1658 engine->stats.total = __intel_engine_get_busy_time(engine);
1659 engine->stats.active = 0;
1661 write_sequnlock_irqrestore(&engine->stats.lock, flags);
1664 static bool match_ring(struct i915_request *rq)
1666 u32 ring = ENGINE_READ(rq->engine, RING_START);
1668 return ring == i915_ggtt_offset(rq->ring->vma);
1671 struct i915_request *
1672 intel_engine_find_active_request(struct intel_engine_cs *engine)
1674 struct i915_request *request, *active = NULL;
1675 unsigned long flags;
1678 * We are called by the error capture, reset and to dump engine
1679 * state at random points in time. In particular, note that neither is
1680 * crucially ordered with an interrupt. After a hang, the GPU is dead
1681 * and we assume that no more writes can happen (we waited long enough
1682 * for all writes that were in transaction to be flushed) - adding an
1683 * extra delay for a recent interrupt is pointless. Hence, we do
1684 * not need an engine->irq_seqno_barrier() before the seqno reads.
1685 * At all other times, we must assume the GPU is still running, but
1686 * we only care about the snapshot of this moment.
1688 spin_lock_irqsave(&engine->active.lock, flags);
1689 list_for_each_entry(request, &engine->active.requests, sched.link) {
1690 if (i915_request_completed(request))
1693 if (!i915_request_started(request))
1696 /* More than one preemptible request may match! */
1697 if (!match_ring(request))
1703 spin_unlock_irqrestore(&engine->active.lock, flags);
1708 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
1709 #include "selftest_engine_cs.c"