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>
28 #include "intel_ringbuffer.h"
29 #include "intel_lrc.h"
31 /* Haswell does have the CXT_SIZE register however it does not appear to be
32 * valid. Now, docs explain in dwords what is in the context object. The full
33 * size is 70720 bytes, however, the power context and execlist context will
34 * never be saved (power context is stored elsewhere, and execlists don't work
35 * on HSW) - so the final size, including the extra state required for the
36 * Resource Streamer, is 66944 bytes, which rounds to 17 pages.
38 #define HSW_CXT_TOTAL_SIZE (17 * PAGE_SIZE)
40 #define DEFAULT_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)
41 #define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE)
42 #define GEN9_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE)
43 #define GEN10_LR_CONTEXT_RENDER_SIZE (18 * PAGE_SIZE)
44 #define GEN11_LR_CONTEXT_RENDER_SIZE (14 * PAGE_SIZE)
46 #define GEN8_LR_CONTEXT_OTHER_SIZE ( 2 * PAGE_SIZE)
48 struct engine_class_info
{
50 int (*init_legacy
)(struct intel_engine_cs
*engine
);
51 int (*init_execlists
)(struct intel_engine_cs
*engine
);
56 static const struct engine_class_info intel_engine_classes
[] = {
59 .init_execlists
= logical_render_ring_init
,
60 .init_legacy
= intel_init_render_ring_buffer
,
61 .uabi_class
= I915_ENGINE_CLASS_RENDER
,
63 [COPY_ENGINE_CLASS
] = {
65 .init_execlists
= logical_xcs_ring_init
,
66 .init_legacy
= intel_init_blt_ring_buffer
,
67 .uabi_class
= I915_ENGINE_CLASS_COPY
,
69 [VIDEO_DECODE_CLASS
] = {
71 .init_execlists
= logical_xcs_ring_init
,
72 .init_legacy
= intel_init_bsd_ring_buffer
,
73 .uabi_class
= I915_ENGINE_CLASS_VIDEO
,
75 [VIDEO_ENHANCEMENT_CLASS
] = {
77 .init_execlists
= logical_xcs_ring_init
,
78 .init_legacy
= intel_init_vebox_ring_buffer
,
79 .uabi_class
= I915_ENGINE_CLASS_VIDEO_ENHANCE
,
83 #define MAX_MMIO_BASES 3
89 /* mmio bases table *must* be sorted in reverse gen order */
90 struct engine_mmio_base
{
93 } mmio_bases
[MAX_MMIO_BASES
];
96 static const struct engine_info intel_engines
[] = {
99 .uabi_id
= I915_EXEC_RENDER
,
100 .class = RENDER_CLASS
,
103 { .gen
= 1, .base
= RENDER_RING_BASE
}
108 .uabi_id
= I915_EXEC_BLT
,
109 .class = COPY_ENGINE_CLASS
,
112 { .gen
= 6, .base
= BLT_RING_BASE
}
117 .uabi_id
= I915_EXEC_BSD
,
118 .class = VIDEO_DECODE_CLASS
,
121 { .gen
= 11, .base
= GEN11_BSD_RING_BASE
},
122 { .gen
= 6, .base
= GEN6_BSD_RING_BASE
},
123 { .gen
= 4, .base
= BSD_RING_BASE
}
128 .uabi_id
= I915_EXEC_BSD
,
129 .class = VIDEO_DECODE_CLASS
,
132 { .gen
= 11, .base
= GEN11_BSD2_RING_BASE
},
133 { .gen
= 8, .base
= GEN8_BSD2_RING_BASE
}
138 .uabi_id
= I915_EXEC_BSD
,
139 .class = VIDEO_DECODE_CLASS
,
142 { .gen
= 11, .base
= GEN11_BSD3_RING_BASE
}
147 .uabi_id
= I915_EXEC_BSD
,
148 .class = VIDEO_DECODE_CLASS
,
151 { .gen
= 11, .base
= GEN11_BSD4_RING_BASE
}
156 .uabi_id
= I915_EXEC_VEBOX
,
157 .class = VIDEO_ENHANCEMENT_CLASS
,
160 { .gen
= 11, .base
= GEN11_VEBOX_RING_BASE
},
161 { .gen
= 7, .base
= VEBOX_RING_BASE
}
166 .uabi_id
= I915_EXEC_VEBOX
,
167 .class = VIDEO_ENHANCEMENT_CLASS
,
170 { .gen
= 11, .base
= GEN11_VEBOX2_RING_BASE
}
176 * ___intel_engine_context_size() - return the size of the context for an engine
177 * @dev_priv: i915 device private
178 * @class: engine class
180 * Each engine class may require a different amount of space for a context
183 * Return: size (in bytes) of an engine class specific context image
185 * Note: this size includes the HWSP, which is part of the context image
186 * in LRC mode, but does not include the "shared data page" used with
187 * GuC submission. The caller should account for this if using the GuC.
190 __intel_engine_context_size(struct drm_i915_private
*dev_priv
, u8
class)
194 BUILD_BUG_ON(I915_GTT_PAGE_SIZE
!= PAGE_SIZE
);
198 switch (INTEL_GEN(dev_priv
)) {
200 MISSING_CASE(INTEL_GEN(dev_priv
));
201 return DEFAULT_LR_CONTEXT_RENDER_SIZE
;
203 return GEN11_LR_CONTEXT_RENDER_SIZE
;
205 return GEN10_LR_CONTEXT_RENDER_SIZE
;
207 return GEN9_LR_CONTEXT_RENDER_SIZE
;
209 return GEN8_LR_CONTEXT_RENDER_SIZE
;
211 if (IS_HASWELL(dev_priv
))
212 return HSW_CXT_TOTAL_SIZE
;
214 cxt_size
= I915_READ(GEN7_CXT_SIZE
);
215 return round_up(GEN7_CXT_TOTAL_SIZE(cxt_size
) * 64,
218 cxt_size
= I915_READ(CXT_SIZE
);
219 return round_up(GEN6_CXT_TOTAL_SIZE(cxt_size
) * 64,
225 /* For the special day when i810 gets merged. */
233 case VIDEO_DECODE_CLASS
:
234 case VIDEO_ENHANCEMENT_CLASS
:
235 case COPY_ENGINE_CLASS
:
236 if (INTEL_GEN(dev_priv
) < 8)
238 return GEN8_LR_CONTEXT_OTHER_SIZE
;
242 static u32
__engine_mmio_base(struct drm_i915_private
*i915
,
243 const struct engine_mmio_base
*bases
)
247 for (i
= 0; i
< MAX_MMIO_BASES
; i
++)
248 if (INTEL_GEN(i915
) >= bases
[i
].gen
)
251 GEM_BUG_ON(i
== MAX_MMIO_BASES
);
252 GEM_BUG_ON(!bases
[i
].base
);
254 return bases
[i
].base
;
257 static void __sprint_engine_name(char *name
, const struct engine_info
*info
)
259 WARN_ON(snprintf(name
, INTEL_ENGINE_CS_MAX_NAME
, "%s%u",
260 intel_engine_classes
[info
->class].name
,
261 info
->instance
) >= INTEL_ENGINE_CS_MAX_NAME
);
265 intel_engine_setup(struct drm_i915_private
*dev_priv
,
266 enum intel_engine_id id
)
268 const struct engine_info
*info
= &intel_engines
[id
];
269 struct intel_engine_cs
*engine
;
271 GEM_BUG_ON(info
->class >= ARRAY_SIZE(intel_engine_classes
));
273 BUILD_BUG_ON(MAX_ENGINE_CLASS
>= BIT(GEN11_ENGINE_CLASS_WIDTH
));
274 BUILD_BUG_ON(MAX_ENGINE_INSTANCE
>= BIT(GEN11_ENGINE_INSTANCE_WIDTH
));
276 if (GEM_WARN_ON(info
->class > MAX_ENGINE_CLASS
))
279 if (GEM_WARN_ON(info
->instance
> MAX_ENGINE_INSTANCE
))
282 if (GEM_WARN_ON(dev_priv
->engine_class
[info
->class][info
->instance
]))
285 GEM_BUG_ON(dev_priv
->engine
[id
]);
286 engine
= kzalloc(sizeof(*engine
), GFP_KERNEL
);
291 engine
->i915
= dev_priv
;
292 __sprint_engine_name(engine
->name
, info
);
293 engine
->hw_id
= engine
->guc_id
= info
->hw_id
;
294 engine
->mmio_base
= __engine_mmio_base(dev_priv
, info
->mmio_bases
);
295 engine
->class = info
->class;
296 engine
->instance
= info
->instance
;
298 engine
->uabi_id
= info
->uabi_id
;
299 engine
->uabi_class
= intel_engine_classes
[info
->class].uabi_class
;
301 engine
->context_size
= __intel_engine_context_size(dev_priv
,
303 if (WARN_ON(engine
->context_size
> BIT(20)))
304 engine
->context_size
= 0;
305 if (engine
->context_size
)
306 DRIVER_CAPS(dev_priv
)->has_logical_contexts
= true;
308 /* Nothing to do here, execute in order of dependencies */
309 engine
->schedule
= NULL
;
311 seqlock_init(&engine
->stats
.lock
);
313 ATOMIC_INIT_NOTIFIER_HEAD(&engine
->context_status_notifier
);
315 dev_priv
->engine_class
[info
->class][info
->instance
] = engine
;
316 dev_priv
->engine
[id
] = engine
;
321 * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers
322 * @dev_priv: i915 device private
324 * Return: non-zero if the initialization failed.
326 int intel_engines_init_mmio(struct drm_i915_private
*dev_priv
)
328 struct intel_device_info
*device_info
= mkwrite_device_info(dev_priv
);
329 const unsigned int ring_mask
= INTEL_INFO(dev_priv
)->ring_mask
;
330 struct intel_engine_cs
*engine
;
331 enum intel_engine_id id
;
332 unsigned int mask
= 0;
336 WARN_ON(ring_mask
== 0);
338 GENMASK(sizeof(mask
) * BITS_PER_BYTE
- 1, I915_NUM_ENGINES
));
340 for (i
= 0; i
< ARRAY_SIZE(intel_engines
); i
++) {
341 if (!HAS_ENGINE(dev_priv
, i
))
344 err
= intel_engine_setup(dev_priv
, i
);
348 mask
|= ENGINE_MASK(i
);
352 * Catch failures to update intel_engines table when the new engines
353 * are added to the driver by a warning and disabling the forgotten
356 if (WARN_ON(mask
!= ring_mask
))
357 device_info
->ring_mask
= mask
;
359 /* We always presume we have at least RCS available for later probing */
360 if (WARN_ON(!HAS_ENGINE(dev_priv
, RCS
))) {
365 device_info
->num_rings
= hweight32(mask
);
367 i915_check_and_clear_faults(dev_priv
);
372 for_each_engine(engine
, dev_priv
, id
)
378 * intel_engines_init() - init the Engine Command Streamers
379 * @dev_priv: i915 device private
381 * Return: non-zero if the initialization failed.
383 int intel_engines_init(struct drm_i915_private
*dev_priv
)
385 struct intel_engine_cs
*engine
;
386 enum intel_engine_id id
, err_id
;
389 for_each_engine(engine
, dev_priv
, id
) {
390 const struct engine_class_info
*class_info
=
391 &intel_engine_classes
[engine
->class];
392 int (*init
)(struct intel_engine_cs
*engine
);
394 if (HAS_EXECLISTS(dev_priv
))
395 init
= class_info
->init_execlists
;
397 init
= class_info
->init_legacy
;
402 if (GEM_WARN_ON(!init
))
409 GEM_BUG_ON(!engine
->submit_request
);
415 for_each_engine(engine
, dev_priv
, id
) {
418 dev_priv
->engine
[id
] = NULL
;
420 dev_priv
->gt
.cleanup_engine(engine
);
426 void intel_engine_init_global_seqno(struct intel_engine_cs
*engine
, u32 seqno
)
428 struct drm_i915_private
*dev_priv
= engine
->i915
;
430 /* Our semaphore implementation is strictly monotonic (i.e. we proceed
431 * so long as the semaphore value in the register/page is greater
432 * than the sync value), so whenever we reset the seqno,
433 * so long as we reset the tracking semaphore value to 0, it will
434 * always be before the next request's seqno. If we don't reset
435 * the semaphore value, then when the seqno moves backwards all
436 * future waits will complete instantly (causing rendering corruption).
438 if (IS_GEN6(dev_priv
) || IS_GEN7(dev_priv
)) {
439 I915_WRITE(RING_SYNC_0(engine
->mmio_base
), 0);
440 I915_WRITE(RING_SYNC_1(engine
->mmio_base
), 0);
441 if (HAS_VEBOX(dev_priv
))
442 I915_WRITE(RING_SYNC_2(engine
->mmio_base
), 0);
445 intel_write_status_page(engine
, I915_GEM_HWS_INDEX
, seqno
);
446 clear_bit(ENGINE_IRQ_BREADCRUMB
, &engine
->irq_posted
);
448 /* After manually advancing the seqno, fake the interrupt in case
449 * there are any waiters for that seqno.
451 intel_engine_wakeup(engine
);
453 GEM_BUG_ON(intel_engine_get_seqno(engine
) != seqno
);
456 static void intel_engine_init_batch_pool(struct intel_engine_cs
*engine
)
458 i915_gem_batch_pool_init(&engine
->batch_pool
, engine
);
461 static void intel_engine_init_execlist(struct intel_engine_cs
*engine
)
463 struct intel_engine_execlists
* const execlists
= &engine
->execlists
;
465 execlists
->port_mask
= 1;
466 BUILD_BUG_ON_NOT_POWER_OF_2(execlists_num_ports(execlists
));
467 GEM_BUG_ON(execlists_num_ports(execlists
) > EXECLIST_MAX_PORTS
);
469 execlists
->queue_priority
= INT_MIN
;
470 execlists
->queue
= RB_ROOT_CACHED
;
474 * intel_engines_setup_common - setup engine state not requiring hw access
475 * @engine: Engine to setup.
477 * Initializes @engine@ structure members shared between legacy and execlists
478 * submission modes which do not require hardware access.
480 * Typically done early in the submission mode specific engine setup stage.
482 void intel_engine_setup_common(struct intel_engine_cs
*engine
)
484 i915_timeline_init(engine
->i915
, &engine
->timeline
, engine
->name
);
485 lockdep_set_subclass(&engine
->timeline
.lock
, TIMELINE_ENGINE
);
487 intel_engine_init_execlist(engine
);
488 intel_engine_init_hangcheck(engine
);
489 intel_engine_init_batch_pool(engine
);
490 intel_engine_init_cmd_parser(engine
);
493 int intel_engine_create_scratch(struct intel_engine_cs
*engine
,
496 struct drm_i915_gem_object
*obj
;
497 struct i915_vma
*vma
;
500 WARN_ON(engine
->scratch
);
502 obj
= i915_gem_object_create_stolen(engine
->i915
, size
);
504 obj
= i915_gem_object_create_internal(engine
->i915
, size
);
506 DRM_ERROR("Failed to allocate scratch page\n");
510 vma
= i915_vma_instance(obj
, &engine
->i915
->ggtt
.vm
, NULL
);
516 ret
= i915_vma_pin(vma
, 0, 4096, PIN_GLOBAL
| PIN_HIGH
);
520 engine
->scratch
= vma
;
524 i915_gem_object_put(obj
);
528 void intel_engine_cleanup_scratch(struct intel_engine_cs
*engine
)
530 i915_vma_unpin_and_release(&engine
->scratch
);
533 static void cleanup_phys_status_page(struct intel_engine_cs
*engine
)
535 struct drm_i915_private
*dev_priv
= engine
->i915
;
537 if (!dev_priv
->status_page_dmah
)
540 drm_pci_free(&dev_priv
->drm
, dev_priv
->status_page_dmah
);
541 engine
->status_page
.page_addr
= NULL
;
544 static void cleanup_status_page(struct intel_engine_cs
*engine
)
546 struct i915_vma
*vma
;
547 struct drm_i915_gem_object
*obj
;
549 vma
= fetch_and_zero(&engine
->status_page
.vma
);
558 i915_gem_object_unpin_map(obj
);
559 __i915_gem_object_release_unless_active(obj
);
562 static int init_status_page(struct intel_engine_cs
*engine
)
564 struct drm_i915_gem_object
*obj
;
565 struct i915_vma
*vma
;
570 obj
= i915_gem_object_create_internal(engine
->i915
, PAGE_SIZE
);
572 DRM_ERROR("Failed to allocate status page\n");
576 ret
= i915_gem_object_set_cache_level(obj
, I915_CACHE_LLC
);
580 vma
= i915_vma_instance(obj
, &engine
->i915
->ggtt
.vm
, NULL
);
587 if (!HAS_LLC(engine
->i915
))
588 /* On g33, we cannot place HWS above 256MiB, so
589 * restrict its pinning to the low mappable arena.
590 * Though this restriction is not documented for
591 * gen4, gen5, or byt, they also behave similarly
592 * and hang if the HWS is placed at the top of the
593 * GTT. To generalise, it appears that all !llc
594 * platforms have issues with us placing the HWS
595 * above the mappable region (even though we never
598 flags
|= PIN_MAPPABLE
;
601 ret
= i915_vma_pin(vma
, 0, 4096, flags
);
605 vaddr
= i915_gem_object_pin_map(obj
, I915_MAP_WB
);
607 ret
= PTR_ERR(vaddr
);
611 engine
->status_page
.vma
= vma
;
612 engine
->status_page
.ggtt_offset
= i915_ggtt_offset(vma
);
613 engine
->status_page
.page_addr
= memset(vaddr
, 0, PAGE_SIZE
);
619 i915_gem_object_put(obj
);
623 static int init_phys_status_page(struct intel_engine_cs
*engine
)
625 struct drm_i915_private
*dev_priv
= engine
->i915
;
627 GEM_BUG_ON(engine
->id
!= RCS
);
629 dev_priv
->status_page_dmah
=
630 drm_pci_alloc(&dev_priv
->drm
, PAGE_SIZE
, PAGE_SIZE
);
631 if (!dev_priv
->status_page_dmah
)
634 engine
->status_page
.page_addr
= dev_priv
->status_page_dmah
->vaddr
;
635 memset(engine
->status_page
.page_addr
, 0, PAGE_SIZE
);
640 static void __intel_context_unpin(struct i915_gem_context
*ctx
,
641 struct intel_engine_cs
*engine
)
643 intel_context_unpin(to_intel_context(ctx
, engine
));
647 * intel_engines_init_common - initialize cengine state which might require hw access
648 * @engine: Engine to initialize.
650 * Initializes @engine@ structure members shared between legacy and execlists
651 * submission modes which do require hardware access.
653 * Typcally done at later stages of submission mode specific engine setup.
655 * Returns zero on success or an error code on failure.
657 int intel_engine_init_common(struct intel_engine_cs
*engine
)
659 struct drm_i915_private
*i915
= engine
->i915
;
660 struct intel_context
*ce
;
663 engine
->set_default_submission(engine
);
665 /* We may need to do things with the shrinker which
666 * require us to immediately switch back to the default
667 * context. This can cause a problem as pinning the
668 * default context also requires GTT space which may not
669 * be available. To avoid this we always pin the default
672 ce
= intel_context_pin(i915
->kernel_context
, engine
);
677 * Similarly the preempt context must always be available so that
678 * we can interrupt the engine at any time.
680 if (i915
->preempt_context
) {
681 ce
= intel_context_pin(i915
->preempt_context
, engine
);
684 goto err_unpin_kernel
;
688 ret
= intel_engine_init_breadcrumbs(engine
);
690 goto err_unpin_preempt
;
692 if (HWS_NEEDS_PHYSICAL(i915
))
693 ret
= init_phys_status_page(engine
);
695 ret
= init_status_page(engine
);
697 goto err_breadcrumbs
;
702 intel_engine_fini_breadcrumbs(engine
);
704 if (i915
->preempt_context
)
705 __intel_context_unpin(i915
->preempt_context
, engine
);
708 __intel_context_unpin(i915
->kernel_context
, engine
);
713 * intel_engines_cleanup_common - cleans up the engine state created by
714 * the common initiailizers.
715 * @engine: Engine to cleanup.
717 * This cleans up everything created by the common helpers.
719 void intel_engine_cleanup_common(struct intel_engine_cs
*engine
)
721 struct drm_i915_private
*i915
= engine
->i915
;
723 intel_engine_cleanup_scratch(engine
);
725 if (HWS_NEEDS_PHYSICAL(engine
->i915
))
726 cleanup_phys_status_page(engine
);
728 cleanup_status_page(engine
);
730 intel_engine_fini_breadcrumbs(engine
);
731 intel_engine_cleanup_cmd_parser(engine
);
732 i915_gem_batch_pool_fini(&engine
->batch_pool
);
734 if (engine
->default_state
)
735 i915_gem_object_put(engine
->default_state
);
737 if (i915
->preempt_context
)
738 __intel_context_unpin(i915
->preempt_context
, engine
);
739 __intel_context_unpin(i915
->kernel_context
, engine
);
741 i915_timeline_fini(&engine
->timeline
);
744 u64
intel_engine_get_active_head(const struct intel_engine_cs
*engine
)
746 struct drm_i915_private
*dev_priv
= engine
->i915
;
749 if (INTEL_GEN(dev_priv
) >= 8)
750 acthd
= I915_READ64_2x32(RING_ACTHD(engine
->mmio_base
),
751 RING_ACTHD_UDW(engine
->mmio_base
));
752 else if (INTEL_GEN(dev_priv
) >= 4)
753 acthd
= I915_READ(RING_ACTHD(engine
->mmio_base
));
755 acthd
= I915_READ(ACTHD
);
760 u64
intel_engine_get_last_batch_head(const struct intel_engine_cs
*engine
)
762 struct drm_i915_private
*dev_priv
= engine
->i915
;
765 if (INTEL_GEN(dev_priv
) >= 8)
766 bbaddr
= I915_READ64_2x32(RING_BBADDR(engine
->mmio_base
),
767 RING_BBADDR_UDW(engine
->mmio_base
));
769 bbaddr
= I915_READ(RING_BBADDR(engine
->mmio_base
));
774 int intel_engine_stop_cs(struct intel_engine_cs
*engine
)
776 struct drm_i915_private
*dev_priv
= engine
->i915
;
777 const u32 base
= engine
->mmio_base
;
778 const i915_reg_t mode
= RING_MI_MODE(base
);
781 if (INTEL_GEN(dev_priv
) < 3)
784 GEM_TRACE("%s\n", engine
->name
);
786 I915_WRITE_FW(mode
, _MASKED_BIT_ENABLE(STOP_RING
));
789 if (__intel_wait_for_register_fw(dev_priv
,
790 mode
, MODE_IDLE
, MODE_IDLE
,
793 GEM_TRACE("%s: timed out on STOP_RING -> IDLE\n", engine
->name
);
797 /* A final mmio read to let GPU writes be hopefully flushed to memory */
798 POSTING_READ_FW(mode
);
803 const char *i915_cache_level_str(struct drm_i915_private
*i915
, int type
)
806 case I915_CACHE_NONE
: return " uncached";
807 case I915_CACHE_LLC
: return HAS_LLC(i915
) ? " LLC" : " snooped";
808 case I915_CACHE_L3_LLC
: return " L3+LLC";
809 case I915_CACHE_WT
: return " WT";
814 u32
intel_calculate_mcr_s_ss_select(struct drm_i915_private
*dev_priv
)
816 const struct sseu_dev_info
*sseu
= &(INTEL_INFO(dev_priv
)->sseu
);
818 u32 slice
= fls(sseu
->slice_mask
);
819 u32 subslice
= fls(sseu
->subslice_mask
[slice
]);
821 if (INTEL_GEN(dev_priv
) == 10)
822 mcr_s_ss_select
= GEN8_MCR_SLICE(slice
) |
823 GEN8_MCR_SUBSLICE(subslice
);
824 else if (INTEL_GEN(dev_priv
) >= 11)
825 mcr_s_ss_select
= GEN11_MCR_SLICE(slice
) |
826 GEN11_MCR_SUBSLICE(subslice
);
830 return mcr_s_ss_select
;
833 static inline uint32_t
834 read_subslice_reg(struct drm_i915_private
*dev_priv
, int slice
,
835 int subslice
, i915_reg_t reg
)
837 uint32_t mcr_slice_subslice_mask
;
838 uint32_t mcr_slice_subslice_select
;
839 uint32_t default_mcr_s_ss_select
;
842 enum forcewake_domains fw_domains
;
844 if (INTEL_GEN(dev_priv
) >= 11) {
845 mcr_slice_subslice_mask
= GEN11_MCR_SLICE_MASK
|
846 GEN11_MCR_SUBSLICE_MASK
;
847 mcr_slice_subslice_select
= GEN11_MCR_SLICE(slice
) |
848 GEN11_MCR_SUBSLICE(subslice
);
850 mcr_slice_subslice_mask
= GEN8_MCR_SLICE_MASK
|
851 GEN8_MCR_SUBSLICE_MASK
;
852 mcr_slice_subslice_select
= GEN8_MCR_SLICE(slice
) |
853 GEN8_MCR_SUBSLICE(subslice
);
856 default_mcr_s_ss_select
= intel_calculate_mcr_s_ss_select(dev_priv
);
858 fw_domains
= intel_uncore_forcewake_for_reg(dev_priv
, reg
,
860 fw_domains
|= intel_uncore_forcewake_for_reg(dev_priv
,
862 FW_REG_READ
| FW_REG_WRITE
);
864 spin_lock_irq(&dev_priv
->uncore
.lock
);
865 intel_uncore_forcewake_get__locked(dev_priv
, fw_domains
);
867 mcr
= I915_READ_FW(GEN8_MCR_SELECTOR
);
869 WARN_ON_ONCE((mcr
& mcr_slice_subslice_mask
) !=
870 default_mcr_s_ss_select
);
872 mcr
&= ~mcr_slice_subslice_mask
;
873 mcr
|= mcr_slice_subslice_select
;
874 I915_WRITE_FW(GEN8_MCR_SELECTOR
, mcr
);
876 ret
= I915_READ_FW(reg
);
878 mcr
&= ~mcr_slice_subslice_mask
;
879 mcr
|= default_mcr_s_ss_select
;
881 I915_WRITE_FW(GEN8_MCR_SELECTOR
, mcr
);
883 intel_uncore_forcewake_put__locked(dev_priv
, fw_domains
);
884 spin_unlock_irq(&dev_priv
->uncore
.lock
);
889 /* NB: please notice the memset */
890 void intel_engine_get_instdone(struct intel_engine_cs
*engine
,
891 struct intel_instdone
*instdone
)
893 struct drm_i915_private
*dev_priv
= engine
->i915
;
894 u32 mmio_base
= engine
->mmio_base
;
898 memset(instdone
, 0, sizeof(*instdone
));
900 switch (INTEL_GEN(dev_priv
)) {
902 instdone
->instdone
= I915_READ(RING_INSTDONE(mmio_base
));
904 if (engine
->id
!= RCS
)
907 instdone
->slice_common
= I915_READ(GEN7_SC_INSTDONE
);
908 for_each_instdone_slice_subslice(dev_priv
, slice
, subslice
) {
909 instdone
->sampler
[slice
][subslice
] =
910 read_subslice_reg(dev_priv
, slice
, subslice
,
911 GEN7_SAMPLER_INSTDONE
);
912 instdone
->row
[slice
][subslice
] =
913 read_subslice_reg(dev_priv
, slice
, subslice
,
918 instdone
->instdone
= I915_READ(RING_INSTDONE(mmio_base
));
920 if (engine
->id
!= RCS
)
923 instdone
->slice_common
= I915_READ(GEN7_SC_INSTDONE
);
924 instdone
->sampler
[0][0] = I915_READ(GEN7_SAMPLER_INSTDONE
);
925 instdone
->row
[0][0] = I915_READ(GEN7_ROW_INSTDONE
);
931 instdone
->instdone
= I915_READ(RING_INSTDONE(mmio_base
));
933 if (engine
->id
== RCS
)
934 /* HACK: Using the wrong struct member */
935 instdone
->slice_common
= I915_READ(GEN4_INSTDONE1
);
939 instdone
->instdone
= I915_READ(GEN2_INSTDONE
);
944 static bool ring_is_idle(struct intel_engine_cs
*engine
)
946 struct drm_i915_private
*dev_priv
= engine
->i915
;
949 /* If the whole device is asleep, the engine must be idle */
950 if (!intel_runtime_pm_get_if_in_use(dev_priv
))
953 /* First check that no commands are left in the ring */
954 if ((I915_READ_HEAD(engine
) & HEAD_ADDR
) !=
955 (I915_READ_TAIL(engine
) & TAIL_ADDR
))
958 /* No bit for gen2, so assume the CS parser is idle */
959 if (INTEL_GEN(dev_priv
) > 2 && !(I915_READ_MODE(engine
) & MODE_IDLE
))
962 intel_runtime_pm_put(dev_priv
);
968 * intel_engine_is_idle() - Report if the engine has finished process all work
969 * @engine: the intel_engine_cs
971 * Return true if there are no requests pending, nothing left to be submitted
972 * to hardware, and that the engine is idle.
974 bool intel_engine_is_idle(struct intel_engine_cs
*engine
)
976 struct drm_i915_private
*dev_priv
= engine
->i915
;
978 /* More white lies, if wedged, hw state is inconsistent */
979 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
982 /* Any inflight/incomplete requests? */
983 if (!i915_seqno_passed(intel_engine_get_seqno(engine
),
984 intel_engine_last_submit(engine
)))
987 if (I915_SELFTEST_ONLY(engine
->breadcrumbs
.mock
))
990 /* Waiting to drain ELSP? */
991 if (READ_ONCE(engine
->execlists
.active
)) {
992 struct tasklet_struct
*t
= &engine
->execlists
.tasklet
;
995 if (tasklet_trylock(t
)) {
996 /* Must wait for any GPU reset in progress. */
997 if (__tasklet_is_enabled(t
))
1003 if (READ_ONCE(engine
->execlists
.active
))
1007 /* ELSP is empty, but there are ready requests? E.g. after reset */
1008 if (!RB_EMPTY_ROOT(&engine
->execlists
.queue
.rb_root
))
1012 if (!ring_is_idle(engine
))
1018 bool intel_engines_are_idle(struct drm_i915_private
*dev_priv
)
1020 struct intel_engine_cs
*engine
;
1021 enum intel_engine_id id
;
1024 * If the driver is wedged, HW state may be very inconsistent and
1025 * report that it is still busy, even though we have stopped using it.
1027 if (i915_terminally_wedged(&dev_priv
->gpu_error
))
1030 for_each_engine(engine
, dev_priv
, id
) {
1031 if (!intel_engine_is_idle(engine
))
1039 * intel_engine_has_kernel_context:
1040 * @engine: the engine
1042 * Returns true if the last context to be executed on this engine, or has been
1043 * executed if the engine is already idle, is the kernel context
1044 * (#i915.kernel_context).
1046 bool intel_engine_has_kernel_context(const struct intel_engine_cs
*engine
)
1048 const struct intel_context
*kernel_context
=
1049 to_intel_context(engine
->i915
->kernel_context
, engine
);
1050 struct i915_request
*rq
;
1052 lockdep_assert_held(&engine
->i915
->drm
.struct_mutex
);
1055 * Check the last context seen by the engine. If active, it will be
1056 * the last request that remains in the timeline. When idle, it is
1057 * the last executed context as tracked by retirement.
1059 rq
= __i915_gem_active_peek(&engine
->timeline
.last_request
);
1061 return rq
->hw_context
== kernel_context
;
1063 return engine
->last_retired_context
== kernel_context
;
1066 void intel_engines_reset_default_submission(struct drm_i915_private
*i915
)
1068 struct intel_engine_cs
*engine
;
1069 enum intel_engine_id id
;
1071 for_each_engine(engine
, i915
, id
)
1072 engine
->set_default_submission(engine
);
1076 * intel_engines_sanitize: called after the GPU has lost power
1077 * @i915: the i915 device
1079 * Anytime we reset the GPU, either with an explicit GPU reset or through a
1080 * PCI power cycle, the GPU loses state and we must reset our state tracking
1081 * to match. Note that calling intel_engines_sanitize() if the GPU has not
1082 * been reset results in much confusion!
1084 void intel_engines_sanitize(struct drm_i915_private
*i915
)
1086 struct intel_engine_cs
*engine
;
1087 enum intel_engine_id id
;
1091 for_each_engine(engine
, i915
, id
) {
1092 if (engine
->reset
.reset
)
1093 engine
->reset
.reset(engine
, NULL
);
1098 * intel_engines_park: called when the GT is transitioning from busy->idle
1099 * @i915: the i915 device
1101 * The GT is now idle and about to go to sleep (maybe never to wake again?).
1102 * Time for us to tidy and put away our toys (release resources back to the
1105 void intel_engines_park(struct drm_i915_private
*i915
)
1107 struct intel_engine_cs
*engine
;
1108 enum intel_engine_id id
;
1110 for_each_engine(engine
, i915
, id
) {
1111 /* Flush the residual irq tasklets first. */
1112 intel_engine_disarm_breadcrumbs(engine
);
1113 tasklet_kill(&engine
->execlists
.tasklet
);
1116 * We are committed now to parking the engines, make sure there
1117 * will be no more interrupts arriving later and the engines
1120 if (wait_for(intel_engine_is_idle(engine
), 10)) {
1121 struct drm_printer p
= drm_debug_printer(__func__
);
1123 dev_err(i915
->drm
.dev
,
1124 "%s is not idle before parking\n",
1126 intel_engine_dump(engine
, &p
, NULL
);
1129 /* Must be reset upon idling, or we may miss the busy wakeup. */
1130 GEM_BUG_ON(engine
->execlists
.queue_priority
!= INT_MIN
);
1133 engine
->park(engine
);
1135 if (engine
->pinned_default_state
) {
1136 i915_gem_object_unpin_map(engine
->default_state
);
1137 engine
->pinned_default_state
= NULL
;
1140 i915_gem_batch_pool_fini(&engine
->batch_pool
);
1141 engine
->execlists
.no_priolist
= false;
1146 * intel_engines_unpark: called when the GT is transitioning from idle->busy
1147 * @i915: the i915 device
1149 * The GT was idle and now about to fire up with some new user requests.
1151 void intel_engines_unpark(struct drm_i915_private
*i915
)
1153 struct intel_engine_cs
*engine
;
1154 enum intel_engine_id id
;
1156 for_each_engine(engine
, i915
, id
) {
1159 /* Pin the default state for fast resets from atomic context. */
1161 if (engine
->default_state
)
1162 map
= i915_gem_object_pin_map(engine
->default_state
,
1164 if (!IS_ERR_OR_NULL(map
))
1165 engine
->pinned_default_state
= map
;
1168 engine
->unpark(engine
);
1170 intel_engine_init_hangcheck(engine
);
1175 * intel_engine_lost_context: called when the GPU is reset into unknown state
1176 * @engine: the engine
1178 * We have either reset the GPU or otherwise about to lose state tracking of
1179 * the current GPU logical state (e.g. suspend). On next use, it is therefore
1180 * imperative that we make no presumptions about the current state and load
1183 void intel_engine_lost_context(struct intel_engine_cs
*engine
)
1185 struct intel_context
*ce
;
1187 lockdep_assert_held(&engine
->i915
->drm
.struct_mutex
);
1189 ce
= fetch_and_zero(&engine
->last_retired_context
);
1191 intel_context_unpin(ce
);
1194 bool intel_engine_can_store_dword(struct intel_engine_cs
*engine
)
1196 switch (INTEL_GEN(engine
->i915
)) {
1198 return false; /* uses physical not virtual addresses */
1200 /* maybe only uses physical not virtual addresses */
1201 return !(IS_I915G(engine
->i915
) || IS_I915GM(engine
->i915
));
1203 return engine
->class != VIDEO_DECODE_CLASS
; /* b0rked */
1209 unsigned int intel_engines_has_context_isolation(struct drm_i915_private
*i915
)
1211 struct intel_engine_cs
*engine
;
1212 enum intel_engine_id id
;
1216 for_each_engine(engine
, i915
, id
)
1217 if (engine
->default_state
)
1218 which
|= BIT(engine
->uabi_class
);
1223 static int print_sched_attr(struct drm_i915_private
*i915
,
1224 const struct i915_sched_attr
*attr
,
1225 char *buf
, int x
, int len
)
1227 if (attr
->priority
== I915_PRIORITY_INVALID
)
1230 x
+= snprintf(buf
+ x
, len
- x
,
1231 " prio=%d", attr
->priority
);
1236 static void print_request(struct drm_printer
*m
,
1237 struct i915_request
*rq
,
1240 const char *name
= rq
->fence
.ops
->get_timeline_name(&rq
->fence
);
1244 x
= print_sched_attr(rq
->i915
, &rq
->sched
.attr
, buf
, x
, sizeof(buf
));
1246 drm_printf(m
, "%s%x%s [%llx:%x]%s @ %dms: %s\n",
1249 i915_request_completed(rq
) ? "!" : "",
1250 rq
->fence
.context
, rq
->fence
.seqno
,
1252 jiffies_to_msecs(jiffies
- rq
->emitted_jiffies
),
1256 static void hexdump(struct drm_printer
*m
, const void *buf
, size_t len
)
1258 const size_t rowsize
= 8 * sizeof(u32
);
1259 const void *prev
= NULL
;
1263 for (pos
= 0; pos
< len
; pos
+= rowsize
) {
1266 if (prev
&& !memcmp(prev
, buf
+ pos
, rowsize
)) {
1268 drm_printf(m
, "*\n");
1274 WARN_ON_ONCE(hex_dump_to_buffer(buf
+ pos
, len
- pos
,
1275 rowsize
, sizeof(u32
),
1277 false) >= sizeof(line
));
1278 drm_printf(m
, "[%04zx] %s\n", pos
, line
);
1285 static void intel_engine_print_registers(const struct intel_engine_cs
*engine
,
1286 struct drm_printer
*m
)
1288 struct drm_i915_private
*dev_priv
= engine
->i915
;
1289 const struct intel_engine_execlists
* const execlists
=
1293 if (engine
->id
== RCS
&& IS_GEN(dev_priv
, 4, 7))
1294 drm_printf(m
, "\tCCID: 0x%08x\n", I915_READ(CCID
));
1295 drm_printf(m
, "\tRING_START: 0x%08x\n",
1296 I915_READ(RING_START(engine
->mmio_base
)));
1297 drm_printf(m
, "\tRING_HEAD: 0x%08x\n",
1298 I915_READ(RING_HEAD(engine
->mmio_base
)) & HEAD_ADDR
);
1299 drm_printf(m
, "\tRING_TAIL: 0x%08x\n",
1300 I915_READ(RING_TAIL(engine
->mmio_base
)) & TAIL_ADDR
);
1301 drm_printf(m
, "\tRING_CTL: 0x%08x%s\n",
1302 I915_READ(RING_CTL(engine
->mmio_base
)),
1303 I915_READ(RING_CTL(engine
->mmio_base
)) & (RING_WAIT
| RING_WAIT_SEMAPHORE
) ? " [waiting]" : "");
1304 if (INTEL_GEN(engine
->i915
) > 2) {
1305 drm_printf(m
, "\tRING_MODE: 0x%08x%s\n",
1306 I915_READ(RING_MI_MODE(engine
->mmio_base
)),
1307 I915_READ(RING_MI_MODE(engine
->mmio_base
)) & (MODE_IDLE
) ? " [idle]" : "");
1310 if (INTEL_GEN(dev_priv
) >= 6) {
1311 drm_printf(m
, "\tRING_IMR: %08x\n", I915_READ_IMR(engine
));
1314 if (HAS_LEGACY_SEMAPHORES(dev_priv
)) {
1315 drm_printf(m
, "\tSYNC_0: 0x%08x\n",
1316 I915_READ(RING_SYNC_0(engine
->mmio_base
)));
1317 drm_printf(m
, "\tSYNC_1: 0x%08x\n",
1318 I915_READ(RING_SYNC_1(engine
->mmio_base
)));
1319 if (HAS_VEBOX(dev_priv
))
1320 drm_printf(m
, "\tSYNC_2: 0x%08x\n",
1321 I915_READ(RING_SYNC_2(engine
->mmio_base
)));
1324 addr
= intel_engine_get_active_head(engine
);
1325 drm_printf(m
, "\tACTHD: 0x%08x_%08x\n",
1326 upper_32_bits(addr
), lower_32_bits(addr
));
1327 addr
= intel_engine_get_last_batch_head(engine
);
1328 drm_printf(m
, "\tBBADDR: 0x%08x_%08x\n",
1329 upper_32_bits(addr
), lower_32_bits(addr
));
1330 if (INTEL_GEN(dev_priv
) >= 8)
1331 addr
= I915_READ64_2x32(RING_DMA_FADD(engine
->mmio_base
),
1332 RING_DMA_FADD_UDW(engine
->mmio_base
));
1333 else if (INTEL_GEN(dev_priv
) >= 4)
1334 addr
= I915_READ(RING_DMA_FADD(engine
->mmio_base
));
1336 addr
= I915_READ(DMA_FADD_I8XX
);
1337 drm_printf(m
, "\tDMA_FADDR: 0x%08x_%08x\n",
1338 upper_32_bits(addr
), lower_32_bits(addr
));
1339 if (INTEL_GEN(dev_priv
) >= 4) {
1340 drm_printf(m
, "\tIPEIR: 0x%08x\n",
1341 I915_READ(RING_IPEIR(engine
->mmio_base
)));
1342 drm_printf(m
, "\tIPEHR: 0x%08x\n",
1343 I915_READ(RING_IPEHR(engine
->mmio_base
)));
1345 drm_printf(m
, "\tIPEIR: 0x%08x\n", I915_READ(IPEIR
));
1346 drm_printf(m
, "\tIPEHR: 0x%08x\n", I915_READ(IPEHR
));
1349 if (HAS_EXECLISTS(dev_priv
)) {
1350 const u32
*hws
= &engine
->status_page
.page_addr
[I915_HWS_CSB_BUF0_INDEX
];
1351 u32 ptr
, read
, write
;
1354 drm_printf(m
, "\tExeclist status: 0x%08x %08x\n",
1355 I915_READ(RING_EXECLIST_STATUS_LO(engine
)),
1356 I915_READ(RING_EXECLIST_STATUS_HI(engine
)));
1358 ptr
= I915_READ(RING_CONTEXT_STATUS_PTR(engine
));
1359 read
= GEN8_CSB_READ_PTR(ptr
);
1360 write
= GEN8_CSB_WRITE_PTR(ptr
);
1361 drm_printf(m
, "\tExeclist CSB read %d [%d cached], write %d [%d from hws], tasklet queued? %s (%s)\n",
1362 read
, execlists
->csb_head
,
1364 intel_read_status_page(engine
, intel_hws_csb_write_index(engine
->i915
)),
1365 yesno(test_bit(TASKLET_STATE_SCHED
,
1366 &engine
->execlists
.tasklet
.state
)),
1367 enableddisabled(!atomic_read(&engine
->execlists
.tasklet
.count
)));
1368 if (read
>= GEN8_CSB_ENTRIES
)
1370 if (write
>= GEN8_CSB_ENTRIES
)
1373 write
+= GEN8_CSB_ENTRIES
;
1374 while (read
< write
) {
1375 idx
= ++read
% GEN8_CSB_ENTRIES
;
1376 drm_printf(m
, "\tExeclist CSB[%d]: 0x%08x [0x%08x in hwsp], context: %d [%d in hwsp]\n",
1378 I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine
, idx
)),
1380 I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine
, idx
)),
1385 for (idx
= 0; idx
< execlists_num_ports(execlists
); idx
++) {
1386 struct i915_request
*rq
;
1389 rq
= port_unpack(&execlists
->port
[idx
], &count
);
1393 snprintf(hdr
, sizeof(hdr
),
1394 "\t\tELSP[%d] count=%d, ring->start=%08x, rq: ",
1396 i915_ggtt_offset(rq
->ring
->vma
));
1397 print_request(m
, rq
, hdr
);
1399 drm_printf(m
, "\t\tELSP[%d] idle\n", idx
);
1402 drm_printf(m
, "\t\tHW active? 0x%x\n", execlists
->active
);
1404 } else if (INTEL_GEN(dev_priv
) > 6) {
1405 drm_printf(m
, "\tPP_DIR_BASE: 0x%08x\n",
1406 I915_READ(RING_PP_DIR_BASE(engine
)));
1407 drm_printf(m
, "\tPP_DIR_BASE_READ: 0x%08x\n",
1408 I915_READ(RING_PP_DIR_BASE_READ(engine
)));
1409 drm_printf(m
, "\tPP_DIR_DCLV: 0x%08x\n",
1410 I915_READ(RING_PP_DIR_DCLV(engine
)));
1414 static void print_request_ring(struct drm_printer
*m
, struct i915_request
*rq
)
1420 "[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]:\n",
1421 rq
->head
, rq
->postfix
, rq
->tail
,
1422 rq
->batch
? upper_32_bits(rq
->batch
->node
.start
) : ~0u,
1423 rq
->batch
? lower_32_bits(rq
->batch
->node
.start
) : ~0u);
1425 size
= rq
->tail
- rq
->head
;
1426 if (rq
->tail
< rq
->head
)
1427 size
+= rq
->ring
->size
;
1429 ring
= kmalloc(size
, GFP_ATOMIC
);
1431 const void *vaddr
= rq
->ring
->vaddr
;
1432 unsigned int head
= rq
->head
;
1433 unsigned int len
= 0;
1435 if (rq
->tail
< head
) {
1436 len
= rq
->ring
->size
- head
;
1437 memcpy(ring
, vaddr
+ head
, len
);
1440 memcpy(ring
+ len
, vaddr
+ head
, size
- len
);
1442 hexdump(m
, ring
, size
);
1447 void intel_engine_dump(struct intel_engine_cs
*engine
,
1448 struct drm_printer
*m
,
1449 const char *header
, ...)
1451 const int MAX_REQUESTS_TO_SHOW
= 8;
1452 struct intel_breadcrumbs
* const b
= &engine
->breadcrumbs
;
1453 const struct intel_engine_execlists
* const execlists
= &engine
->execlists
;
1454 struct i915_gpu_error
* const error
= &engine
->i915
->gpu_error
;
1455 struct i915_request
*rq
, *last
;
1456 unsigned long flags
;
1463 va_start(ap
, header
);
1464 drm_vprintf(m
, header
, &ap
);
1468 if (i915_terminally_wedged(&engine
->i915
->gpu_error
))
1469 drm_printf(m
, "*** WEDGED ***\n");
1471 drm_printf(m
, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms]\n",
1472 intel_engine_get_seqno(engine
),
1473 intel_engine_last_submit(engine
),
1474 engine
->hangcheck
.seqno
,
1475 jiffies_to_msecs(jiffies
- engine
->hangcheck
.action_timestamp
));
1476 drm_printf(m
, "\tReset count: %d (global %d)\n",
1477 i915_reset_engine_count(error
, engine
),
1478 i915_reset_count(error
));
1482 drm_printf(m
, "\tRequests:\n");
1484 rq
= list_first_entry(&engine
->timeline
.requests
,
1485 struct i915_request
, link
);
1486 if (&rq
->link
!= &engine
->timeline
.requests
)
1487 print_request(m
, rq
, "\t\tfirst ");
1489 rq
= list_last_entry(&engine
->timeline
.requests
,
1490 struct i915_request
, link
);
1491 if (&rq
->link
!= &engine
->timeline
.requests
)
1492 print_request(m
, rq
, "\t\tlast ");
1494 rq
= i915_gem_find_active_request(engine
);
1496 print_request(m
, rq
, "\t\tactive ");
1498 drm_printf(m
, "\t\tring->start: 0x%08x\n",
1499 i915_ggtt_offset(rq
->ring
->vma
));
1500 drm_printf(m
, "\t\tring->head: 0x%08x\n",
1502 drm_printf(m
, "\t\tring->tail: 0x%08x\n",
1504 drm_printf(m
, "\t\tring->emit: 0x%08x\n",
1506 drm_printf(m
, "\t\tring->space: 0x%08x\n",
1509 print_request_ring(m
, rq
);
1514 if (intel_runtime_pm_get_if_in_use(engine
->i915
)) {
1515 intel_engine_print_registers(engine
, m
);
1516 intel_runtime_pm_put(engine
->i915
);
1518 drm_printf(m
, "\tDevice is asleep; skipping register dump\n");
1521 local_irq_save(flags
);
1522 spin_lock(&engine
->timeline
.lock
);
1526 list_for_each_entry(rq
, &engine
->timeline
.requests
, link
) {
1527 if (count
++ < MAX_REQUESTS_TO_SHOW
- 1)
1528 print_request(m
, rq
, "\t\tE ");
1533 if (count
> MAX_REQUESTS_TO_SHOW
) {
1535 "\t\t...skipping %d executing requests...\n",
1536 count
- MAX_REQUESTS_TO_SHOW
);
1538 print_request(m
, last
, "\t\tE ");
1543 drm_printf(m
, "\t\tQueue priority: %d\n", execlists
->queue_priority
);
1544 for (rb
= rb_first_cached(&execlists
->queue
); rb
; rb
= rb_next(rb
)) {
1545 struct i915_priolist
*p
=
1546 rb_entry(rb
, typeof(*p
), node
);
1548 list_for_each_entry(rq
, &p
->requests
, sched
.link
) {
1549 if (count
++ < MAX_REQUESTS_TO_SHOW
- 1)
1550 print_request(m
, rq
, "\t\tQ ");
1556 if (count
> MAX_REQUESTS_TO_SHOW
) {
1558 "\t\t...skipping %d queued requests...\n",
1559 count
- MAX_REQUESTS_TO_SHOW
);
1561 print_request(m
, last
, "\t\tQ ");
1564 spin_unlock(&engine
->timeline
.lock
);
1566 spin_lock(&b
->rb_lock
);
1567 for (rb
= rb_first(&b
->waiters
); rb
; rb
= rb_next(rb
)) {
1568 struct intel_wait
*w
= rb_entry(rb
, typeof(*w
), node
);
1570 drm_printf(m
, "\t%s [%d] waiting for %x\n",
1571 w
->tsk
->comm
, w
->tsk
->pid
, w
->seqno
);
1573 spin_unlock(&b
->rb_lock
);
1574 local_irq_restore(flags
);
1576 drm_printf(m
, "IRQ? 0x%lx (breadcrumbs? %s)\n",
1578 yesno(test_bit(ENGINE_IRQ_BREADCRUMB
,
1579 &engine
->irq_posted
)));
1581 drm_printf(m
, "HWSP:\n");
1582 hexdump(m
, engine
->status_page
.page_addr
, PAGE_SIZE
);
1584 drm_printf(m
, "Idle? %s\n", yesno(intel_engine_is_idle(engine
)));
1587 static u8 user_class_map
[] = {
1588 [I915_ENGINE_CLASS_RENDER
] = RENDER_CLASS
,
1589 [I915_ENGINE_CLASS_COPY
] = COPY_ENGINE_CLASS
,
1590 [I915_ENGINE_CLASS_VIDEO
] = VIDEO_DECODE_CLASS
,
1591 [I915_ENGINE_CLASS_VIDEO_ENHANCE
] = VIDEO_ENHANCEMENT_CLASS
,
1594 struct intel_engine_cs
*
1595 intel_engine_lookup_user(struct drm_i915_private
*i915
, u8
class, u8 instance
)
1597 if (class >= ARRAY_SIZE(user_class_map
))
1600 class = user_class_map
[class];
1602 GEM_BUG_ON(class > MAX_ENGINE_CLASS
);
1604 if (instance
> MAX_ENGINE_INSTANCE
)
1607 return i915
->engine_class
[class][instance
];
1611 * intel_enable_engine_stats() - Enable engine busy tracking on engine
1612 * @engine: engine to enable stats collection
1614 * Start collecting the engine busyness data for @engine.
1616 * Returns 0 on success or a negative error code.
1618 int intel_enable_engine_stats(struct intel_engine_cs
*engine
)
1620 struct intel_engine_execlists
*execlists
= &engine
->execlists
;
1621 unsigned long flags
;
1624 if (!intel_engine_supports_stats(engine
))
1627 spin_lock_irqsave(&engine
->timeline
.lock
, flags
);
1628 write_seqlock(&engine
->stats
.lock
);
1630 if (unlikely(engine
->stats
.enabled
== ~0)) {
1635 if (engine
->stats
.enabled
++ == 0) {
1636 const struct execlist_port
*port
= execlists
->port
;
1637 unsigned int num_ports
= execlists_num_ports(execlists
);
1639 engine
->stats
.enabled_at
= ktime_get();
1641 /* XXX submission method oblivious? */
1642 while (num_ports
-- && port_isset(port
)) {
1643 engine
->stats
.active
++;
1647 if (engine
->stats
.active
)
1648 engine
->stats
.start
= engine
->stats
.enabled_at
;
1652 write_sequnlock(&engine
->stats
.lock
);
1653 spin_unlock_irqrestore(&engine
->timeline
.lock
, flags
);
1658 static ktime_t
__intel_engine_get_busy_time(struct intel_engine_cs
*engine
)
1660 ktime_t total
= engine
->stats
.total
;
1663 * If the engine is executing something at the moment
1664 * add it to the total.
1666 if (engine
->stats
.active
)
1667 total
= ktime_add(total
,
1668 ktime_sub(ktime_get(), engine
->stats
.start
));
1674 * intel_engine_get_busy_time() - Return current accumulated engine busyness
1675 * @engine: engine to report on
1677 * Returns accumulated time @engine was busy since engine stats were enabled.
1679 ktime_t
intel_engine_get_busy_time(struct intel_engine_cs
*engine
)
1685 seq
= read_seqbegin(&engine
->stats
.lock
);
1686 total
= __intel_engine_get_busy_time(engine
);
1687 } while (read_seqretry(&engine
->stats
.lock
, seq
));
1693 * intel_disable_engine_stats() - Disable engine busy tracking on engine
1694 * @engine: engine to disable stats collection
1696 * Stops collecting the engine busyness data for @engine.
1698 void intel_disable_engine_stats(struct intel_engine_cs
*engine
)
1700 unsigned long flags
;
1702 if (!intel_engine_supports_stats(engine
))
1705 write_seqlock_irqsave(&engine
->stats
.lock
, flags
);
1706 WARN_ON_ONCE(engine
->stats
.enabled
== 0);
1707 if (--engine
->stats
.enabled
== 0) {
1708 engine
->stats
.total
= __intel_engine_get_busy_time(engine
);
1709 engine
->stats
.active
= 0;
1711 write_sequnlock_irqrestore(&engine
->stats
.lock
, flags
);
1714 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
1715 #include "selftests/mock_engine.c"
1716 #include "selftests/intel_engine_cs.c"