1 // SPDX-License-Identifier: MIT
3 * Copyright © 2014 Intel Corporation
6 #include "gem/i915_gem_lmem.h"
8 #include "gen8_engine_cs.h"
10 #include "i915_perf.h"
12 #include "intel_context.h"
13 #include "intel_engine.h"
14 #include "intel_engine_regs.h"
15 #include "intel_gpu_commands.h"
17 #include "intel_gt_regs.h"
18 #include "intel_lrc.h"
19 #include "intel_lrc_reg.h"
20 #include "intel_ring.h"
21 #include "shmem_utils.h"
24 * The per-platform tables are u8-encoded in @data. Decode @data and set the
25 * addresses' offset and commands in @regs. The following encoding is used
26 * for each byte. There are 2 steps: decoding commands and decoding addresses.
29 * [7]: create NOPs - number of NOPs are set in lower bits
30 * [6]: When creating MI_LOAD_REGISTER_IMM command, allow to set
32 * [5:0]: Number of NOPs or registers to set values to in case of
33 * MI_LOAD_REGISTER_IMM
35 * Addresses: these are decoded after a MI_LOAD_REGISTER_IMM command by "count"
36 * number of registers. They are set by using the REG/REG16 macros: the former
37 * is used for offsets smaller than 0x200 while the latter is for values bigger
38 * than that. Those macros already set all the bits documented below correctly:
40 * [7]: When a register offset needs more than 6 bits, use additional bytes, to
41 * follow, for the lower bits
42 * [6:0]: Register offset, without considering the engine base.
44 * This function only tweaks the commands and register offsets. Values are not
47 static void set_offsets(u32 *regs,
49 const struct intel_engine_cs *engine,
51 #define NOP(x) (BIT(7) | (x))
52 #define LRI(count, flags) ((flags) << 6 | (count) | BUILD_BUG_ON_ZERO(count >= BIT(6)))
54 #define REG(x) (((x) >> 2) | BUILD_BUG_ON_ZERO(x >= 0x200))
56 (((x) >> 9) | BIT(7) | BUILD_BUG_ON_ZERO(x >= 0x10000)), \
60 const u32 base = engine->mmio_base;
65 if (*data & BIT(7)) { /* skip */
66 count = *data++ & ~BIT(7);
75 *regs = MI_LOAD_REGISTER_IMM(count);
77 *regs |= MI_LRI_FORCE_POSTED;
78 if (GRAPHICS_VER(engine->i915) >= 11)
79 *regs |= MI_LRI_LRM_CS_MMIO;
90 offset |= v & ~BIT(7);
93 regs[0] = base + (offset << 2);
99 /* Close the batch; used mainly by live_lrc_layout() */
100 *regs = MI_BATCH_BUFFER_END;
101 if (GRAPHICS_VER(engine->i915) >= 11)
106 static const u8 gen8_xcs_offsets[] = {
141 static const u8 gen9_xcs_offsets[] = {
225 static const u8 gen12_xcs_offsets[] = {
257 static const u8 dg2_xcs_offsets[] = {
291 static const u8 gen8_rcs_offsets[] = {
328 static const u8 gen9_rcs_offsets[] = {
412 static const u8 gen11_rcs_offsets[] = {
453 static const u8 gen12_rcs_offsets[] = {
549 static const u8 xehp_rcs_offsets[] = {
590 static const u8 dg2_rcs_offsets[] = {
633 static const u8 mtl_rcs_offsets[] = {
682 static const u8 *reg_offsets(const struct intel_engine_cs *engine)
685 * The gen12+ lists only have the registers we program in the basic
686 * default state. We rely on the context image using relative
687 * addressing to automatic fixup the register state between the
688 * physical engines for virtual engine.
690 GEM_BUG_ON(GRAPHICS_VER(engine->i915) >= 12 &&
691 !intel_engine_has_relative_mmio(engine));
693 if (engine->flags & I915_ENGINE_HAS_RCS_REG_STATE) {
694 if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 70))
695 return mtl_rcs_offsets;
696 else if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 55))
697 return dg2_rcs_offsets;
698 else if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 50))
699 return xehp_rcs_offsets;
700 else if (GRAPHICS_VER(engine->i915) >= 12)
701 return gen12_rcs_offsets;
702 else if (GRAPHICS_VER(engine->i915) >= 11)
703 return gen11_rcs_offsets;
704 else if (GRAPHICS_VER(engine->i915) >= 9)
705 return gen9_rcs_offsets;
707 return gen8_rcs_offsets;
709 if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 55))
710 return dg2_xcs_offsets;
711 else if (GRAPHICS_VER(engine->i915) >= 12)
712 return gen12_xcs_offsets;
713 else if (GRAPHICS_VER(engine->i915) >= 9)
714 return gen9_xcs_offsets;
716 return gen8_xcs_offsets;
720 static int lrc_ring_mi_mode(const struct intel_engine_cs *engine)
722 if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 50))
724 else if (GRAPHICS_VER(engine->i915) >= 12)
726 else if (GRAPHICS_VER(engine->i915) >= 9)
728 else if (engine->class == RENDER_CLASS)
734 static int lrc_ring_bb_offset(const struct intel_engine_cs *engine)
736 if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 50))
738 else if (GRAPHICS_VER(engine->i915) >= 12)
740 else if (GRAPHICS_VER(engine->i915) >= 9)
742 else if (GRAPHICS_VER(engine->i915) >= 8 &&
743 engine->class == RENDER_CLASS)
749 static int lrc_ring_gpr0(const struct intel_engine_cs *engine)
751 if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 50))
753 else if (GRAPHICS_VER(engine->i915) >= 12)
755 else if (GRAPHICS_VER(engine->i915) >= 9)
757 else if (engine->class == RENDER_CLASS)
763 static int lrc_ring_wa_bb_per_ctx(const struct intel_engine_cs *engine)
765 if (GRAPHICS_VER(engine->i915) >= 12)
767 else if (GRAPHICS_VER(engine->i915) >= 9 || engine->class == RENDER_CLASS)
773 static int lrc_ring_indirect_ptr(const struct intel_engine_cs *engine)
777 x = lrc_ring_wa_bb_per_ctx(engine);
784 static int lrc_ring_indirect_offset(const struct intel_engine_cs *engine)
788 x = lrc_ring_indirect_ptr(engine);
795 static int lrc_ring_cmd_buf_cctl(const struct intel_engine_cs *engine)
798 if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 50))
800 * Note that the CSFE context has a dummy slot for CMD_BUF_CCTL
801 * simply to match the RCS context image layout.
804 else if (engine->class != RENDER_CLASS)
806 else if (GRAPHICS_VER(engine->i915) >= 12)
808 else if (GRAPHICS_VER(engine->i915) >= 11)
815 lrc_ring_indirect_offset_default(const struct intel_engine_cs *engine)
817 if (GRAPHICS_VER(engine->i915) >= 12)
818 return GEN12_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT;
819 else if (GRAPHICS_VER(engine->i915) >= 11)
820 return GEN11_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT;
821 else if (GRAPHICS_VER(engine->i915) >= 9)
822 return GEN9_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT;
823 else if (GRAPHICS_VER(engine->i915) >= 8)
824 return GEN8_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT;
826 GEM_BUG_ON(GRAPHICS_VER(engine->i915) < 8);
832 lrc_setup_bb_per_ctx(u32 *regs,
833 const struct intel_engine_cs *engine,
834 u32 ctx_bb_ggtt_addr)
836 GEM_BUG_ON(lrc_ring_wa_bb_per_ctx(engine) == -1);
837 regs[lrc_ring_wa_bb_per_ctx(engine) + 1] =
844 lrc_setup_indirect_ctx(u32 *regs,
845 const struct intel_engine_cs *engine,
846 u32 ctx_bb_ggtt_addr,
850 GEM_BUG_ON(!IS_ALIGNED(size, CACHELINE_BYTES));
851 GEM_BUG_ON(lrc_ring_indirect_ptr(engine) == -1);
852 regs[lrc_ring_indirect_ptr(engine) + 1] =
853 ctx_bb_ggtt_addr | (size / CACHELINE_BYTES);
855 GEM_BUG_ON(lrc_ring_indirect_offset(engine) == -1);
856 regs[lrc_ring_indirect_offset(engine) + 1] =
857 lrc_ring_indirect_offset_default(engine) << 6;
860 static bool ctx_needs_runalone(const struct intel_context *ce)
862 struct i915_gem_context *gem_ctx;
863 bool ctx_is_protected = false;
866 * On MTL and newer platforms, protected contexts require setting
867 * the LRC run-alone bit or else the encryption will not happen.
869 if (GRAPHICS_VER_FULL(ce->engine->i915) >= IP_VER(12, 70) &&
870 (ce->engine->class == COMPUTE_CLASS || ce->engine->class == RENDER_CLASS)) {
872 gem_ctx = rcu_dereference(ce->gem_context);
874 ctx_is_protected = gem_ctx->uses_protected_content;
878 return ctx_is_protected;
881 static void init_common_regs(u32 * const regs,
882 const struct intel_context *ce,
883 const struct intel_engine_cs *engine,
889 ctl = _MASKED_BIT_ENABLE(CTX_CTRL_INHIBIT_SYN_CTX_SWITCH);
890 ctl |= _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT);
892 ctl |= CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT;
893 if (GRAPHICS_VER(engine->i915) < 11)
894 ctl |= _MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT |
895 CTX_CTRL_RS_CTX_ENABLE);
896 if (ctx_needs_runalone(ce))
897 ctl |= _MASKED_BIT_ENABLE(GEN12_CTX_CTRL_RUNALONE_MODE);
898 regs[CTX_CONTEXT_CONTROL] = ctl;
900 regs[CTX_TIMESTAMP] = ce->stats.runtime.last;
902 loc = lrc_ring_bb_offset(engine);
907 static void init_wa_bb_regs(u32 * const regs,
908 const struct intel_engine_cs *engine)
910 const struct i915_ctx_workarounds * const wa_ctx = &engine->wa_ctx;
912 if (wa_ctx->per_ctx.size) {
913 const u32 ggtt_offset = i915_ggtt_offset(wa_ctx->vma);
915 GEM_BUG_ON(lrc_ring_wa_bb_per_ctx(engine) == -1);
916 regs[lrc_ring_wa_bb_per_ctx(engine) + 1] =
917 (ggtt_offset + wa_ctx->per_ctx.offset) | 0x01;
920 if (wa_ctx->indirect_ctx.size) {
921 lrc_setup_indirect_ctx(regs, engine,
922 i915_ggtt_offset(wa_ctx->vma) +
923 wa_ctx->indirect_ctx.offset,
924 wa_ctx->indirect_ctx.size);
928 static void init_ppgtt_regs(u32 *regs, const struct i915_ppgtt *ppgtt)
930 if (i915_vm_is_4lvl(&ppgtt->vm)) {
931 /* 64b PPGTT (48bit canonical)
932 * PDP0_DESCRIPTOR contains the base address to PML4 and
933 * other PDP Descriptors are ignored.
935 ASSIGN_CTX_PML4(ppgtt, regs);
937 ASSIGN_CTX_PDP(ppgtt, regs, 3);
938 ASSIGN_CTX_PDP(ppgtt, regs, 2);
939 ASSIGN_CTX_PDP(ppgtt, regs, 1);
940 ASSIGN_CTX_PDP(ppgtt, regs, 0);
944 static struct i915_ppgtt *vm_alias(struct i915_address_space *vm)
946 if (i915_is_ggtt(vm))
947 return i915_vm_to_ggtt(vm)->alias;
949 return i915_vm_to_ppgtt(vm);
952 static void __reset_stop_ring(u32 *regs, const struct intel_engine_cs *engine)
956 x = lrc_ring_mi_mode(engine);
958 regs[x + 1] &= ~STOP_RING;
959 regs[x + 1] |= STOP_RING << 16;
963 static void __lrc_init_regs(u32 *regs,
964 const struct intel_context *ce,
965 const struct intel_engine_cs *engine,
969 * A context is actually a big batch buffer with several
970 * MI_LOAD_REGISTER_IMM commands followed by (reg, value) pairs. The
971 * values we are setting here are only for the first context restore:
972 * on a subsequent save, the GPU will recreate this batchbuffer with new
973 * values (including all the missing MI_LOAD_REGISTER_IMM commands that
974 * we are not initializing here).
976 * Must keep consistent with virtual_update_register_offsets().
980 memset(regs, 0, PAGE_SIZE);
982 set_offsets(regs, reg_offsets(engine), engine, inhibit);
984 init_common_regs(regs, ce, engine, inhibit);
985 init_ppgtt_regs(regs, vm_alias(ce->vm));
987 init_wa_bb_regs(regs, engine);
989 __reset_stop_ring(regs, engine);
992 void lrc_init_regs(const struct intel_context *ce,
993 const struct intel_engine_cs *engine,
996 __lrc_init_regs(ce->lrc_reg_state, ce, engine, inhibit);
999 void lrc_reset_regs(const struct intel_context *ce,
1000 const struct intel_engine_cs *engine)
1002 __reset_stop_ring(ce->lrc_reg_state, engine);
1006 set_redzone(void *vaddr, const struct intel_engine_cs *engine)
1008 if (!IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
1011 vaddr += engine->context_size;
1013 memset(vaddr, CONTEXT_REDZONE, I915_GTT_PAGE_SIZE);
1017 check_redzone(const void *vaddr, const struct intel_engine_cs *engine)
1019 if (!IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
1022 vaddr += engine->context_size;
1024 if (memchr_inv(vaddr, CONTEXT_REDZONE, I915_GTT_PAGE_SIZE))
1025 drm_err_once(&engine->i915->drm,
1026 "%s context redzone overwritten!\n",
1030 static u32 context_wa_bb_offset(const struct intel_context *ce)
1032 return PAGE_SIZE * ce->wa_bb_page;
1036 * per_ctx below determines which WABB section is used.
1037 * When true, the function returns the location of the
1038 * PER_CTX_BB. When false, the function returns the
1039 * location of the INDIRECT_CTX.
1041 static u32 *context_wabb(const struct intel_context *ce, bool per_ctx)
1045 GEM_BUG_ON(!ce->wa_bb_page);
1047 ptr = ce->lrc_reg_state;
1048 ptr -= LRC_STATE_OFFSET; /* back to start of context image */
1049 ptr += context_wa_bb_offset(ce);
1050 ptr += per_ctx ? PAGE_SIZE : 0;
1055 void lrc_init_state(struct intel_context *ce,
1056 struct intel_engine_cs *engine,
1059 bool inhibit = true;
1061 set_redzone(state, engine);
1063 if (engine->default_state) {
1064 shmem_read(engine->default_state, 0,
1065 state, engine->context_size);
1066 __set_bit(CONTEXT_VALID_BIT, &ce->flags);
1070 /* Clear the ppHWSP (inc. per-context counters) */
1071 memset(state, 0, PAGE_SIZE);
1073 /* Clear the indirect wa and storage */
1075 memset(state + context_wa_bb_offset(ce), 0, PAGE_SIZE);
1078 * The second page of the context object contains some registers which
1079 * must be set up prior to the first execution.
1081 __lrc_init_regs(state + LRC_STATE_OFFSET, ce, engine, inhibit);
1084 u32 lrc_indirect_bb(const struct intel_context *ce)
1086 return i915_ggtt_offset(ce->state) + context_wa_bb_offset(ce);
1089 static u32 *setup_predicate_disable_wa(const struct intel_context *ce, u32 *cs)
1091 /* If predication is active, this will be noop'ed */
1092 *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT | (4 - 2);
1093 *cs++ = lrc_indirect_bb(ce) + DG2_PREDICATE_RESULT_WA;
1095 *cs++ = 0; /* No predication */
1097 /* predicated end, only terminates if SET_PREDICATE_RESULT:0 is clear */
1098 *cs++ = MI_BATCH_BUFFER_END | BIT(15);
1099 *cs++ = MI_SET_PREDICATE | MI_SET_PREDICATE_DISABLE;
1101 /* Instructions are no longer predicated (disabled), we can proceed */
1102 *cs++ = MI_STORE_DWORD_IMM_GEN4 | MI_USE_GGTT | (4 - 2);
1103 *cs++ = lrc_indirect_bb(ce) + DG2_PREDICATE_RESULT_WA;
1105 *cs++ = 1; /* enable predication before the next BB */
1107 *cs++ = MI_BATCH_BUFFER_END;
1108 GEM_BUG_ON(offset_in_page(cs) > DG2_PREDICATE_RESULT_WA);
1113 static struct i915_vma *
1114 __lrc_alloc_state(struct intel_context *ce, struct intel_engine_cs *engine)
1116 struct drm_i915_gem_object *obj;
1117 struct i915_vma *vma;
1120 context_size = round_up(engine->context_size, I915_GTT_PAGE_SIZE);
1122 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
1123 context_size += I915_GTT_PAGE_SIZE; /* for redzone */
1125 if (GRAPHICS_VER(engine->i915) >= 12) {
1126 ce->wa_bb_page = context_size / PAGE_SIZE;
1127 /* INDIRECT_CTX and PER_CTX_BB need separate pages. */
1128 context_size += PAGE_SIZE * 2;
1131 if (intel_context_is_parent(ce) && intel_engine_uses_guc(engine)) {
1132 ce->parallel.guc.parent_page = context_size / PAGE_SIZE;
1133 context_size += PARENT_SCRATCH_SIZE;
1136 obj = i915_gem_object_create_lmem(engine->i915, context_size,
1137 I915_BO_ALLOC_PM_VOLATILE);
1139 obj = i915_gem_object_create_shmem(engine->i915, context_size);
1141 return ERR_CAST(obj);
1144 * Wa_22016122933: For Media version 13.0, all Media GT shared
1145 * memory needs to be mapped as WC on CPU side and UC (PAT
1146 * index 2) on GPU side.
1148 if (intel_gt_needs_wa_22016122933(engine->gt))
1149 i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
1152 vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
1154 i915_gem_object_put(obj);
1161 static struct intel_timeline *
1162 pinned_timeline(struct intel_context *ce, struct intel_engine_cs *engine)
1164 struct intel_timeline *tl = fetch_and_zero(&ce->timeline);
1166 return intel_timeline_create_from_engine(engine, page_unmask_bits(tl));
1169 int lrc_alloc(struct intel_context *ce, struct intel_engine_cs *engine)
1171 struct intel_ring *ring;
1172 struct i915_vma *vma;
1175 GEM_BUG_ON(ce->state);
1177 vma = __lrc_alloc_state(ce, engine);
1179 return PTR_ERR(vma);
1181 ring = intel_engine_create_ring(engine, ce->ring_size);
1183 err = PTR_ERR(ring);
1187 if (!page_mask_bits(ce->timeline)) {
1188 struct intel_timeline *tl;
1191 * Use the static global HWSP for the kernel context, and
1192 * a dynamically allocated cacheline for everyone else.
1194 if (unlikely(ce->timeline))
1195 tl = pinned_timeline(ce, engine);
1197 tl = intel_timeline_create(engine->gt);
1212 intel_ring_put(ring);
1218 void lrc_reset(struct intel_context *ce)
1220 GEM_BUG_ON(!intel_context_is_pinned(ce));
1222 intel_ring_reset(ce->ring, ce->ring->emit);
1224 /* Scrub away the garbage */
1225 lrc_init_regs(ce, ce->engine, true);
1226 ce->lrc.lrca = lrc_update_regs(ce, ce->engine, ce->ring->tail);
1230 lrc_pre_pin(struct intel_context *ce,
1231 struct intel_engine_cs *engine,
1232 struct i915_gem_ww_ctx *ww,
1235 GEM_BUG_ON(!ce->state);
1236 GEM_BUG_ON(!i915_vma_is_pinned(ce->state));
1238 *vaddr = i915_gem_object_pin_map(ce->state->obj,
1239 intel_gt_coherent_map_type(ce->engine->gt,
1244 return PTR_ERR_OR_ZERO(*vaddr);
1248 lrc_pin(struct intel_context *ce,
1249 struct intel_engine_cs *engine,
1252 ce->lrc_reg_state = vaddr + LRC_STATE_OFFSET;
1254 if (!__test_and_set_bit(CONTEXT_INIT_BIT, &ce->flags))
1255 lrc_init_state(ce, engine, vaddr);
1257 ce->lrc.lrca = lrc_update_regs(ce, engine, ce->ring->tail);
1261 void lrc_unpin(struct intel_context *ce)
1263 if (unlikely(ce->parallel.last_rq)) {
1264 i915_request_put(ce->parallel.last_rq);
1265 ce->parallel.last_rq = NULL;
1267 check_redzone((void *)ce->lrc_reg_state - LRC_STATE_OFFSET,
1271 void lrc_post_unpin(struct intel_context *ce)
1273 i915_gem_object_unpin_map(ce->state->obj);
1276 void lrc_fini(struct intel_context *ce)
1281 intel_ring_put(fetch_and_zero(&ce->ring));
1282 i915_vma_put(fetch_and_zero(&ce->state));
1285 void lrc_destroy(struct kref *kref)
1287 struct intel_context *ce = container_of(kref, typeof(*ce), ref);
1289 GEM_BUG_ON(!i915_active_is_idle(&ce->active));
1290 GEM_BUG_ON(intel_context_is_pinned(ce));
1294 intel_context_fini(ce);
1295 intel_context_free(ce);
1299 gen12_emit_timestamp_wa(const struct intel_context *ce, u32 *cs)
1301 *cs++ = MI_LOAD_REGISTER_MEM_GEN8 |
1302 MI_SRM_LRM_GLOBAL_GTT |
1304 *cs++ = i915_mmio_reg_offset(GEN8_RING_CS_GPR(0, 0));
1305 *cs++ = i915_ggtt_offset(ce->state) + LRC_STATE_OFFSET +
1306 CTX_TIMESTAMP * sizeof(u32);
1309 *cs++ = MI_LOAD_REGISTER_REG |
1310 MI_LRR_SOURCE_CS_MMIO |
1312 *cs++ = i915_mmio_reg_offset(GEN8_RING_CS_GPR(0, 0));
1313 *cs++ = i915_mmio_reg_offset(RING_CTX_TIMESTAMP(0));
1315 *cs++ = MI_LOAD_REGISTER_REG |
1316 MI_LRR_SOURCE_CS_MMIO |
1318 *cs++ = i915_mmio_reg_offset(GEN8_RING_CS_GPR(0, 0));
1319 *cs++ = i915_mmio_reg_offset(RING_CTX_TIMESTAMP(0));
1325 gen12_emit_restore_scratch(const struct intel_context *ce, u32 *cs)
1327 GEM_BUG_ON(lrc_ring_gpr0(ce->engine) == -1);
1329 *cs++ = MI_LOAD_REGISTER_MEM_GEN8 |
1330 MI_SRM_LRM_GLOBAL_GTT |
1332 *cs++ = i915_mmio_reg_offset(GEN8_RING_CS_GPR(0, 0));
1333 *cs++ = i915_ggtt_offset(ce->state) + LRC_STATE_OFFSET +
1334 (lrc_ring_gpr0(ce->engine) + 1) * sizeof(u32);
1341 gen12_emit_cmd_buf_wa(const struct intel_context *ce, u32 *cs)
1343 GEM_BUG_ON(lrc_ring_cmd_buf_cctl(ce->engine) == -1);
1345 *cs++ = MI_LOAD_REGISTER_MEM_GEN8 |
1346 MI_SRM_LRM_GLOBAL_GTT |
1348 *cs++ = i915_mmio_reg_offset(GEN8_RING_CS_GPR(0, 0));
1349 *cs++ = i915_ggtt_offset(ce->state) + LRC_STATE_OFFSET +
1350 (lrc_ring_cmd_buf_cctl(ce->engine) + 1) * sizeof(u32);
1353 *cs++ = MI_LOAD_REGISTER_REG |
1354 MI_LRR_SOURCE_CS_MMIO |
1356 *cs++ = i915_mmio_reg_offset(GEN8_RING_CS_GPR(0, 0));
1357 *cs++ = i915_mmio_reg_offset(RING_CMD_BUF_CCTL(0));
1363 * The bspec's tuning guide asks us to program a vertical watermark value of
1364 * 0x3FF. However this register is not saved/restored properly by the
1365 * hardware, so we're required to apply the desired value via INDIRECT_CTX
1366 * batch buffer to ensure the value takes effect properly. All other bits
1367 * in this register should remain at 0 (the hardware default).
1370 dg2_emit_draw_watermark_setting(u32 *cs)
1372 *cs++ = MI_LOAD_REGISTER_IMM(1);
1373 *cs++ = i915_mmio_reg_offset(DRAW_WATERMARK);
1374 *cs++ = REG_FIELD_PREP(VERT_WM_VAL, 0x3FF);
1380 gen12_invalidate_state_cache(u32 *cs)
1382 *cs++ = MI_LOAD_REGISTER_IMM(1);
1383 *cs++ = i915_mmio_reg_offset(GEN12_CS_DEBUG_MODE2);
1384 *cs++ = _MASKED_BIT_ENABLE(INSTRUCTION_STATE_CACHE_INVALIDATE);
1389 gen12_emit_indirect_ctx_rcs(const struct intel_context *ce, u32 *cs)
1391 cs = gen12_emit_timestamp_wa(ce, cs);
1392 cs = gen12_emit_cmd_buf_wa(ce, cs);
1393 cs = gen12_emit_restore_scratch(ce, cs);
1395 /* Wa_16013000631:dg2 */
1396 if (IS_DG2_G11(ce->engine->i915))
1397 cs = gen8_emit_pipe_control(cs, PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE, 0);
1399 cs = gen12_emit_aux_table_inv(ce->engine, cs);
1401 /* Wa_18022495364 */
1402 if (IS_GFX_GT_IP_RANGE(ce->engine->gt, IP_VER(12, 0), IP_VER(12, 10)))
1403 cs = gen12_invalidate_state_cache(cs);
1405 /* Wa_16014892111 */
1406 if (IS_GFX_GT_IP_STEP(ce->engine->gt, IP_VER(12, 70), STEP_A0, STEP_B0) ||
1407 IS_GFX_GT_IP_STEP(ce->engine->gt, IP_VER(12, 71), STEP_A0, STEP_B0) ||
1408 IS_DG2(ce->engine->i915))
1409 cs = dg2_emit_draw_watermark_setting(cs);
1415 gen12_emit_indirect_ctx_xcs(const struct intel_context *ce, u32 *cs)
1417 cs = gen12_emit_timestamp_wa(ce, cs);
1418 cs = gen12_emit_restore_scratch(ce, cs);
1420 /* Wa_16013000631:dg2 */
1421 if (IS_DG2_G11(ce->engine->i915))
1422 if (ce->engine->class == COMPUTE_CLASS)
1423 cs = gen8_emit_pipe_control(cs,
1424 PIPE_CONTROL_INSTRUCTION_CACHE_INVALIDATE,
1427 return gen12_emit_aux_table_inv(ce->engine, cs);
1430 static u32 *xehp_emit_fastcolor_blt_wabb(const struct intel_context *ce, u32 *cs)
1432 struct intel_gt *gt = ce->engine->gt;
1433 int mocs = gt->mocs.uc_index << 1;
1436 * Wa_16018031267 / Wa_16018063123 requires that SW forces the
1437 * main copy engine arbitration into round robin mode. We
1438 * additionally need to submit the following WABB blt command
1439 * to produce 4 subblits with each subblit generating 0 byte
1440 * write requests as WABB:
1444 * BG1 -> 0000003F (Dest pitch)
1445 * BG2 -> 00000000 (X1, Y1) = (0, 0)
1446 * BG3 -> 00040001 (X2, Y2) = (1, 4)
1449 * BG6-12 -> 00000000
1450 * BG13 -> 20004004 (Surf. Width= 2,Surf. Height = 5 )
1451 * BG14 -> 00000010 (Qpitch = 4)
1454 *cs++ = XY_FAST_COLOR_BLT_CMD | (16 - 2);
1455 *cs++ = FIELD_PREP(XY_FAST_COLOR_BLT_MOCS_MASK, mocs) | 0x3f;
1457 *cs++ = 4 << 16 | 1;
1458 *cs++ = lower_32_bits(i915_vma_offset(ce->vm->rsvd.vma));
1459 *cs++ = upper_32_bits(i915_vma_offset(ce->vm->rsvd.vma));
1475 xehp_emit_per_ctx_bb(const struct intel_context *ce, u32 *cs)
1477 /* Wa_16018031267, Wa_16018063123 */
1478 if (NEEDS_FASTCOLOR_BLT_WABB(ce->engine))
1479 cs = xehp_emit_fastcolor_blt_wabb(ce, cs);
1485 setup_per_ctx_bb(const struct intel_context *ce,
1486 const struct intel_engine_cs *engine,
1487 u32 *(*emit)(const struct intel_context *, u32 *))
1489 /* Place PER_CTX_BB on next page after INDIRECT_CTX */
1490 u32 * const start = context_wabb(ce, true);
1493 cs = emit(ce, start);
1495 /* PER_CTX_BB must manually terminate */
1496 *cs++ = MI_BATCH_BUFFER_END;
1498 GEM_BUG_ON(cs - start > I915_GTT_PAGE_SIZE / sizeof(*cs));
1499 lrc_setup_bb_per_ctx(ce->lrc_reg_state, engine,
1500 lrc_indirect_bb(ce) + PAGE_SIZE);
1504 setup_indirect_ctx_bb(const struct intel_context *ce,
1505 const struct intel_engine_cs *engine,
1506 u32 *(*emit)(const struct intel_context *, u32 *))
1508 u32 * const start = context_wabb(ce, false);
1511 cs = emit(ce, start);
1512 GEM_BUG_ON(cs - start > I915_GTT_PAGE_SIZE / sizeof(*cs));
1513 while ((unsigned long)cs % CACHELINE_BYTES)
1516 GEM_BUG_ON(cs - start > DG2_PREDICATE_RESULT_BB / sizeof(*start));
1517 setup_predicate_disable_wa(ce, start + DG2_PREDICATE_RESULT_BB / sizeof(*start));
1519 lrc_setup_indirect_ctx(ce->lrc_reg_state, engine,
1520 lrc_indirect_bb(ce),
1521 (cs - start) * sizeof(*cs));
1525 * The context descriptor encodes various attributes of a context,
1526 * including its GTT address and some flags. Because it's fairly
1527 * expensive to calculate, we'll just do it once and cache the result,
1528 * which remains valid until the context is unpinned.
1530 * This is what a descriptor looks like, from LSB to MSB::
1532 * bits 0-11: flags, GEN8_CTX_* (cached in ctx->desc_template)
1533 * bits 12-31: LRCA, GTT address of (the HWSP of) this context
1534 * bits 32-52: ctx ID, a globally unique tag (highest bit used by GuC)
1535 * bits 53-54: mbz, reserved for use by hardware
1536 * bits 55-63: group ID, currently unused and set to 0
1538 * Starting from Gen11, the upper dword of the descriptor has a new format:
1540 * bits 32-36: reserved
1541 * bits 37-47: SW context ID
1542 * bits 48:53: engine instance
1543 * bit 54: mbz, reserved for use by hardware
1544 * bits 55-60: SW counter
1545 * bits 61-63: engine class
1547 * On Xe_HP, the upper dword of the descriptor has a new format:
1549 * bits 32-37: virtual function number
1550 * bit 38: mbz, reserved for use by hardware
1551 * bits 39-54: SW context ID
1552 * bits 55-57: reserved
1553 * bits 58-63: SW counter
1555 * engine info, SW context ID and SW counter need to form a unique number
1556 * (Context ID) per lrc.
1558 static u32 lrc_descriptor(const struct intel_context *ce)
1562 desc = INTEL_LEGACY_32B_CONTEXT;
1563 if (i915_vm_is_4lvl(ce->vm))
1564 desc = INTEL_LEGACY_64B_CONTEXT;
1565 desc <<= GEN8_CTX_ADDRESSING_MODE_SHIFT;
1567 desc |= GEN8_CTX_VALID | GEN8_CTX_PRIVILEGE;
1568 if (GRAPHICS_VER(ce->vm->i915) == 8)
1569 desc |= GEN8_CTX_L3LLC_COHERENT;
1571 return i915_ggtt_offset(ce->state) | desc;
1574 u32 lrc_update_regs(const struct intel_context *ce,
1575 const struct intel_engine_cs *engine,
1578 struct intel_ring *ring = ce->ring;
1579 u32 *regs = ce->lrc_reg_state;
1581 GEM_BUG_ON(!intel_ring_offset_valid(ring, head));
1582 GEM_BUG_ON(!intel_ring_offset_valid(ring, ring->tail));
1584 regs[CTX_RING_START] = i915_ggtt_offset(ring->vma);
1585 regs[CTX_RING_HEAD] = head;
1586 regs[CTX_RING_TAIL] = ring->tail;
1587 regs[CTX_RING_CTL] = RING_CTL_SIZE(ring->size) | RING_VALID;
1590 if (engine->class == RENDER_CLASS) {
1591 regs[CTX_R_PWR_CLK_STATE] =
1592 intel_sseu_make_rpcs(engine->gt, &ce->sseu);
1594 i915_oa_init_reg_state(ce, engine);
1597 if (ce->wa_bb_page) {
1598 u32 *(*fn)(const struct intel_context *ce, u32 *cs);
1600 fn = gen12_emit_indirect_ctx_xcs;
1601 if (ce->engine->class == RENDER_CLASS)
1602 fn = gen12_emit_indirect_ctx_rcs;
1604 /* Mutually exclusive wrt to global indirect bb */
1605 GEM_BUG_ON(engine->wa_ctx.indirect_ctx.size);
1606 setup_indirect_ctx_bb(ce, engine, fn);
1607 setup_per_ctx_bb(ce, engine, xehp_emit_per_ctx_bb);
1610 return lrc_descriptor(ce) | CTX_DESC_FORCE_RESTORE;
1613 void lrc_update_offsets(struct intel_context *ce,
1614 struct intel_engine_cs *engine)
1616 set_offsets(ce->lrc_reg_state, reg_offsets(engine), engine, false);
1619 void lrc_check_regs(const struct intel_context *ce,
1620 const struct intel_engine_cs *engine,
1623 const struct intel_ring *ring = ce->ring;
1624 u32 *regs = ce->lrc_reg_state;
1628 if (regs[CTX_RING_START] != i915_ggtt_offset(ring->vma)) {
1629 pr_err("%s: context submitted with incorrect RING_START [%08x], expected %08x\n",
1631 regs[CTX_RING_START],
1632 i915_ggtt_offset(ring->vma));
1633 regs[CTX_RING_START] = i915_ggtt_offset(ring->vma);
1637 if ((regs[CTX_RING_CTL] & ~(RING_WAIT | RING_WAIT_SEMAPHORE)) !=
1638 (RING_CTL_SIZE(ring->size) | RING_VALID)) {
1639 pr_err("%s: context submitted with incorrect RING_CTL [%08x], expected %08x\n",
1642 (u32)(RING_CTL_SIZE(ring->size) | RING_VALID));
1643 regs[CTX_RING_CTL] = RING_CTL_SIZE(ring->size) | RING_VALID;
1647 x = lrc_ring_mi_mode(engine);
1648 if (x != -1 && regs[x + 1] & (regs[x + 1] >> 16) & STOP_RING) {
1649 pr_err("%s: context submitted with STOP_RING [%08x] in RING_MI_MODE\n",
1650 engine->name, regs[x + 1]);
1651 regs[x + 1] &= ~STOP_RING;
1652 regs[x + 1] |= STOP_RING << 16;
1656 WARN_ONCE(!valid, "Invalid lrc state found %s submission\n", when);
1660 * In this WA we need to set GEN8_L3SQCREG4[21:21] and reset it after
1661 * PIPE_CONTROL instruction. This is required for the flush to happen correctly
1662 * but there is a slight complication as this is applied in WA batch where the
1663 * values are only initialized once so we cannot take register value at the
1664 * beginning and reuse it further; hence we save its value to memory, upload a
1665 * constant value with bit21 set and then we restore it back with the saved value.
1666 * To simplify the WA, a constant value is formed by using the default value
1667 * of this register. This shouldn't be a problem because we are only modifying
1668 * it for a short period and this batch in non-premptible. We can ofcourse
1669 * use additional instructions that read the actual value of the register
1670 * at that time and set our bit of interest but it makes the WA complicated.
1672 * This WA is also required for Gen9 so extracting as a function avoids
1676 gen8_emit_flush_coherentl3_wa(struct intel_engine_cs *engine, u32 *batch)
1678 /* NB no one else is allowed to scribble over scratch + 256! */
1679 *batch++ = MI_STORE_REGISTER_MEM_GEN8 | MI_SRM_LRM_GLOBAL_GTT;
1680 *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4);
1681 *batch++ = intel_gt_scratch_offset(engine->gt,
1682 INTEL_GT_SCRATCH_FIELD_COHERENTL3_WA);
1685 *batch++ = MI_LOAD_REGISTER_IMM(1);
1686 *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4);
1687 *batch++ = 0x40400000 | GEN8_LQSC_FLUSH_COHERENT_LINES;
1689 batch = gen8_emit_pipe_control(batch,
1690 PIPE_CONTROL_CS_STALL |
1691 PIPE_CONTROL_DC_FLUSH_ENABLE,
1694 *batch++ = MI_LOAD_REGISTER_MEM_GEN8 | MI_SRM_LRM_GLOBAL_GTT;
1695 *batch++ = i915_mmio_reg_offset(GEN8_L3SQCREG4);
1696 *batch++ = intel_gt_scratch_offset(engine->gt,
1697 INTEL_GT_SCRATCH_FIELD_COHERENTL3_WA);
1704 * Typically we only have one indirect_ctx and per_ctx batch buffer which are
1705 * initialized at the beginning and shared across all contexts but this field
1706 * helps us to have multiple batches at different offsets and select them based
1707 * on a criteria. At the moment this batch always start at the beginning of the page
1708 * and at this point we don't have multiple wa_ctx batch buffers.
1710 * The number of WA applied are not known at the beginning; we use this field
1711 * to return the no of DWORDS written.
1713 * It is to be noted that this batch does not contain MI_BATCH_BUFFER_END
1714 * so it adds NOOPs as padding to make it cacheline aligned.
1715 * MI_BATCH_BUFFER_END will be added to perctx batch and both of them together
1716 * makes a complete batch buffer.
1718 static u32 *gen8_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch)
1720 /* WaDisableCtxRestoreArbitration:bdw,chv */
1721 *batch++ = MI_ARB_ON_OFF | MI_ARB_DISABLE;
1723 /* WaFlushCoherentL3CacheLinesAtContextSwitch:bdw */
1724 if (IS_BROADWELL(engine->i915))
1725 batch = gen8_emit_flush_coherentl3_wa(engine, batch);
1727 /* WaClearSlmSpaceAtContextSwitch:bdw,chv */
1728 /* Actual scratch location is at 128 bytes offset */
1729 batch = gen8_emit_pipe_control(batch,
1730 PIPE_CONTROL_FLUSH_L3 |
1731 PIPE_CONTROL_STORE_DATA_INDEX |
1732 PIPE_CONTROL_CS_STALL |
1733 PIPE_CONTROL_QW_WRITE,
1734 LRC_PPHWSP_SCRATCH_ADDR);
1736 *batch++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
1738 /* Pad to end of cacheline */
1739 while ((unsigned long)batch % CACHELINE_BYTES)
1743 * MI_BATCH_BUFFER_END is not required in Indirect ctx BB because
1744 * execution depends on the length specified in terms of cache lines
1745 * in the register CTX_RCS_INDIRECT_CTX
1756 static u32 *emit_lri(u32 *batch, const struct lri *lri, unsigned int count)
1758 GEM_BUG_ON(!count || count > 63);
1760 *batch++ = MI_LOAD_REGISTER_IMM(count);
1762 *batch++ = i915_mmio_reg_offset(lri->reg);
1763 *batch++ = lri->value;
1764 } while (lri++, --count);
1770 static u32 *gen9_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch)
1772 static const struct lri lri[] = {
1773 /* WaDisableGatherAtSetShaderCommonSlice:skl,bxt,kbl,glk */
1775 COMMON_SLICE_CHICKEN2,
1776 __MASKED_FIELD(GEN9_DISABLE_GATHER_AT_SET_SHADER_COMMON_SLICE,
1783 __MASKED_FIELD(FF_SLICE_CHICKEN_CL_PROVOKING_VERTEX_FIX,
1784 FF_SLICE_CHICKEN_CL_PROVOKING_VERTEX_FIX),
1790 __MASKED_FIELD(_3D_CHICKEN_SF_PROVOKING_VERTEX_FIX,
1791 _3D_CHICKEN_SF_PROVOKING_VERTEX_FIX),
1795 *batch++ = MI_ARB_ON_OFF | MI_ARB_DISABLE;
1797 /* WaFlushCoherentL3CacheLinesAtContextSwitch:skl,bxt,glk */
1798 batch = gen8_emit_flush_coherentl3_wa(engine, batch);
1800 /* WaClearSlmSpaceAtContextSwitch:skl,bxt,kbl,glk,cfl */
1801 batch = gen8_emit_pipe_control(batch,
1802 PIPE_CONTROL_FLUSH_L3 |
1803 PIPE_CONTROL_STORE_DATA_INDEX |
1804 PIPE_CONTROL_CS_STALL |
1805 PIPE_CONTROL_QW_WRITE,
1806 LRC_PPHWSP_SCRATCH_ADDR);
1808 batch = emit_lri(batch, lri, ARRAY_SIZE(lri));
1810 /* WaMediaPoolStateCmdInWABB:bxt,glk */
1811 if (HAS_POOLED_EU(engine->i915)) {
1813 * EU pool configuration is setup along with golden context
1814 * during context initialization. This value depends on
1815 * device type (2x6 or 3x6) and needs to be updated based
1816 * on which subslice is disabled especially for 2x6
1817 * devices, however it is safe to load default
1818 * configuration of 3x6 device instead of masking off
1819 * corresponding bits because HW ignores bits of a disabled
1820 * subslice and drops down to appropriate config. Please
1821 * see render_state_setup() in i915_gem_render_state.c for
1822 * possible configurations, to avoid duplication they are
1823 * not shown here again.
1825 *batch++ = GEN9_MEDIA_POOL_STATE;
1826 *batch++ = GEN9_MEDIA_POOL_ENABLE;
1827 *batch++ = 0x00777000;
1833 *batch++ = MI_ARB_ON_OFF | MI_ARB_ENABLE;
1835 /* Pad to end of cacheline */
1836 while ((unsigned long)batch % CACHELINE_BYTES)
1842 #define CTX_WA_BB_SIZE (PAGE_SIZE)
1844 static int lrc_create_wa_ctx(struct intel_engine_cs *engine)
1846 struct drm_i915_gem_object *obj;
1847 struct i915_vma *vma;
1850 obj = i915_gem_object_create_shmem(engine->i915, CTX_WA_BB_SIZE);
1852 return PTR_ERR(obj);
1854 vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
1860 engine->wa_ctx.vma = vma;
1864 i915_gem_object_put(obj);
1868 void lrc_fini_wa_ctx(struct intel_engine_cs *engine)
1870 i915_vma_unpin_and_release(&engine->wa_ctx.vma, 0);
1873 typedef u32 *(*wa_bb_func_t)(struct intel_engine_cs *engine, u32 *batch);
1875 void lrc_init_wa_ctx(struct intel_engine_cs *engine)
1877 struct i915_ctx_workarounds *wa_ctx = &engine->wa_ctx;
1878 struct i915_wa_ctx_bb *wa_bb[] = {
1879 &wa_ctx->indirect_ctx, &wa_ctx->per_ctx
1881 wa_bb_func_t wa_bb_fn[ARRAY_SIZE(wa_bb)];
1882 struct i915_gem_ww_ctx ww;
1883 void *batch, *batch_ptr;
1887 if (GRAPHICS_VER(engine->i915) >= 11 ||
1888 !(engine->flags & I915_ENGINE_HAS_RCS_REG_STATE))
1891 if (GRAPHICS_VER(engine->i915) == 9) {
1892 wa_bb_fn[0] = gen9_init_indirectctx_bb;
1894 } else if (GRAPHICS_VER(engine->i915) == 8) {
1895 wa_bb_fn[0] = gen8_init_indirectctx_bb;
1899 err = lrc_create_wa_ctx(engine);
1902 * We continue even if we fail to initialize WA batch
1903 * because we only expect rare glitches but nothing
1904 * critical to prevent us from using GPU
1906 drm_err(&engine->i915->drm,
1907 "Ignoring context switch w/a allocation error:%d\n",
1912 if (!engine->wa_ctx.vma)
1915 i915_gem_ww_ctx_init(&ww, true);
1917 err = i915_gem_object_lock(wa_ctx->vma->obj, &ww);
1919 err = i915_ggtt_pin(wa_ctx->vma, &ww, 0, PIN_HIGH);
1923 batch = i915_gem_object_pin_map(wa_ctx->vma->obj, I915_MAP_WB);
1924 if (IS_ERR(batch)) {
1925 err = PTR_ERR(batch);
1930 * Emit the two workaround batch buffers, recording the offset from the
1931 * start of the workaround batch buffer object for each and their
1935 for (i = 0; i < ARRAY_SIZE(wa_bb_fn); i++) {
1936 wa_bb[i]->offset = batch_ptr - batch;
1937 if (GEM_DEBUG_WARN_ON(!IS_ALIGNED(wa_bb[i]->offset,
1938 CACHELINE_BYTES))) {
1943 batch_ptr = wa_bb_fn[i](engine, batch_ptr);
1944 wa_bb[i]->size = batch_ptr - (batch + wa_bb[i]->offset);
1946 GEM_BUG_ON(batch_ptr - batch > CTX_WA_BB_SIZE);
1948 __i915_gem_object_flush_map(wa_ctx->vma->obj, 0, batch_ptr - batch);
1949 __i915_gem_object_release_map(wa_ctx->vma->obj);
1951 /* Verify that we can handle failure to setup the wa_ctx */
1953 err = i915_inject_probe_error(engine->i915, -ENODEV);
1957 i915_vma_unpin(wa_ctx->vma);
1959 if (err == -EDEADLK) {
1960 err = i915_gem_ww_ctx_backoff(&ww);
1964 i915_gem_ww_ctx_fini(&ww);
1967 i915_vma_put(engine->wa_ctx.vma);
1969 /* Clear all flags to prevent further use */
1970 memset(wa_ctx, 0, sizeof(*wa_ctx));
1974 static void st_runtime_underflow(struct intel_context_stats *stats, s32 dt)
1976 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
1977 stats->runtime.num_underflow++;
1978 stats->runtime.max_underflow =
1979 max_t(u32, stats->runtime.max_underflow, -dt);
1983 static u32 lrc_get_runtime(const struct intel_context *ce)
1986 * We can use either ppHWSP[16] which is recorded before the context
1987 * switch (and so excludes the cost of context switches) or use the
1988 * value from the context image itself, which is saved/restored earlier
1989 * and so includes the cost of the save.
1991 return READ_ONCE(ce->lrc_reg_state[CTX_TIMESTAMP]);
1994 void lrc_update_runtime(struct intel_context *ce)
1996 struct intel_context_stats *stats = &ce->stats;
2000 old = stats->runtime.last;
2001 stats->runtime.last = lrc_get_runtime(ce);
2002 dt = stats->runtime.last - old;
2006 if (unlikely(dt < 0)) {
2007 CE_TRACE(ce, "runtime underflow: last=%u, new=%u, delta=%d\n",
2008 old, stats->runtime.last, dt);
2009 st_runtime_underflow(stats, dt);
2013 ewma_runtime_add(&stats->runtime.avg, dt);
2014 stats->runtime.total += dt;
2017 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
2018 #include "selftest_lrc.c"