1 // SPDX-License-Identifier: MIT
3 * Copyright © 2019 Intel Corporation
6 #include <drm/drm_managed.h>
7 #include <drm/intel-gtt.h>
9 #include "gem/i915_gem_internal.h"
10 #include "gem/i915_gem_lmem.h"
11 #include "pxp/intel_pxp.h"
14 #include "intel_context.h"
15 #include "intel_engine_regs.h"
16 #include "intel_ggtt_gmch.h"
18 #include "intel_gt_buffer_pool.h"
19 #include "intel_gt_clock_utils.h"
20 #include "intel_gt_debugfs.h"
21 #include "intel_gt_mcr.h"
22 #include "intel_gt_pm.h"
23 #include "intel_gt_regs.h"
24 #include "intel_gt_requests.h"
25 #include "intel_migrate.h"
26 #include "intel_mocs.h"
28 #include "intel_rc6.h"
29 #include "intel_renderstate.h"
30 #include "intel_rps.h"
31 #include "intel_gt_sysfs.h"
32 #include "intel_uncore.h"
33 #include "shmem_utils.h"
35 static void __intel_gt_init_early(struct intel_gt *gt)
37 spin_lock_init(>->irq_lock);
39 mutex_init(>->tlb_invalidate_lock);
41 INIT_LIST_HEAD(>->closed_vma);
42 spin_lock_init(>->closed_lock);
44 init_llist_head(>->watchdog.list);
45 INIT_WORK(>->watchdog.work, intel_gt_watchdog_work);
47 intel_gt_init_buffer_pool(gt);
48 intel_gt_init_reset(gt);
49 intel_gt_init_requests(gt);
50 intel_gt_init_timelines(gt);
51 intel_gt_pm_init_early(gt);
53 intel_uc_init_early(>->uc);
54 intel_rps_init_early(>->rps);
57 /* Preliminary initialization of Tile 0 */
58 void intel_root_gt_init_early(struct drm_i915_private *i915)
60 struct intel_gt *gt = to_gt(i915);
63 gt->uncore = &i915->uncore;
65 __intel_gt_init_early(gt);
68 static int intel_gt_probe_lmem(struct intel_gt *gt)
70 struct drm_i915_private *i915 = gt->i915;
71 unsigned int instance = gt->info.id;
72 int id = INTEL_REGION_LMEM_0 + instance;
73 struct intel_memory_region *mem;
76 mem = intel_gt_setup_lmem(gt);
83 "Failed to setup region(%d) type=%d\n",
84 err, INTEL_MEMORY_LOCAL);
89 mem->instance = instance;
91 intel_memory_region_set_name(mem, "local%u", mem->instance);
93 GEM_BUG_ON(!HAS_REGION(i915, id));
94 GEM_BUG_ON(i915->mm.regions[id]);
95 i915->mm.regions[id] = mem;
100 int intel_gt_assign_ggtt(struct intel_gt *gt)
102 gt->ggtt = drmm_kzalloc(>->i915->drm, sizeof(*gt->ggtt), GFP_KERNEL);
104 return gt->ggtt ? 0 : -ENOMEM;
107 int intel_gt_init_mmio(struct intel_gt *gt)
109 intel_gt_init_clock_frequency(gt);
111 intel_uc_init_mmio(>->uc);
112 intel_sseu_info_init(gt);
113 intel_gt_mcr_init(gt);
115 return intel_engines_init_mmio(gt);
118 static void init_unused_ring(struct intel_gt *gt, u32 base)
120 struct intel_uncore *uncore = gt->uncore;
122 intel_uncore_write(uncore, RING_CTL(base), 0);
123 intel_uncore_write(uncore, RING_HEAD(base), 0);
124 intel_uncore_write(uncore, RING_TAIL(base), 0);
125 intel_uncore_write(uncore, RING_START(base), 0);
128 static void init_unused_rings(struct intel_gt *gt)
130 struct drm_i915_private *i915 = gt->i915;
133 init_unused_ring(gt, PRB1_BASE);
134 init_unused_ring(gt, SRB0_BASE);
135 init_unused_ring(gt, SRB1_BASE);
136 init_unused_ring(gt, SRB2_BASE);
137 init_unused_ring(gt, SRB3_BASE);
138 } else if (GRAPHICS_VER(i915) == 2) {
139 init_unused_ring(gt, SRB0_BASE);
140 init_unused_ring(gt, SRB1_BASE);
141 } else if (GRAPHICS_VER(i915) == 3) {
142 init_unused_ring(gt, PRB1_BASE);
143 init_unused_ring(gt, PRB2_BASE);
147 int intel_gt_init_hw(struct intel_gt *gt)
149 struct drm_i915_private *i915 = gt->i915;
150 struct intel_uncore *uncore = gt->uncore;
153 gt->last_init_time = ktime_get();
155 /* Double layer security blanket, see i915_gem_init() */
156 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
158 if (HAS_EDRAM(i915) && GRAPHICS_VER(i915) < 9)
159 intel_uncore_rmw(uncore, HSW_IDICR, 0, IDIHASHMSK(0xf));
161 if (IS_HASWELL(i915))
162 intel_uncore_write(uncore,
163 HSW_MI_PREDICATE_RESULT_2,
165 LOWER_SLICE_ENABLED : LOWER_SLICE_DISABLED);
167 /* Apply the GT workarounds... */
168 intel_gt_apply_workarounds(gt);
169 /* ...and determine whether they are sticking. */
170 intel_gt_verify_workarounds(gt, "init");
172 intel_gt_init_swizzling(gt);
175 * At least 830 can leave some of the unused rings
176 * "active" (ie. head != tail) after resume which
177 * will prevent c3 entry. Makes sure all unused rings
180 init_unused_rings(gt);
182 ret = i915_ppgtt_init_hw(gt);
184 DRM_ERROR("Enabling PPGTT failed (%d)\n", ret);
188 /* We can't enable contexts until all firmware is loaded */
189 ret = intel_uc_init_hw(>->uc);
191 i915_probe_error(i915, "Enabling uc failed (%d)\n", ret);
198 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL);
202 static void rmw_set(struct intel_uncore *uncore, i915_reg_t reg, u32 set)
204 intel_uncore_rmw(uncore, reg, 0, set);
207 static void rmw_clear(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
209 intel_uncore_rmw(uncore, reg, clr, 0);
212 static void clear_register(struct intel_uncore *uncore, i915_reg_t reg)
214 intel_uncore_rmw(uncore, reg, 0, 0);
217 static void gen6_clear_engine_error_register(struct intel_engine_cs *engine)
219 GEN6_RING_FAULT_REG_RMW(engine, RING_FAULT_VALID, 0);
220 GEN6_RING_FAULT_REG_POSTING_READ(engine);
224 intel_gt_clear_error_registers(struct intel_gt *gt,
225 intel_engine_mask_t engine_mask)
227 struct drm_i915_private *i915 = gt->i915;
228 struct intel_uncore *uncore = gt->uncore;
231 if (GRAPHICS_VER(i915) != 2)
232 clear_register(uncore, PGTBL_ER);
234 if (GRAPHICS_VER(i915) < 4)
235 clear_register(uncore, IPEIR(RENDER_RING_BASE));
237 clear_register(uncore, IPEIR_I965);
239 clear_register(uncore, EIR);
240 eir = intel_uncore_read(uncore, EIR);
243 * some errors might have become stuck,
246 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
247 rmw_set(uncore, EMR, eir);
248 intel_uncore_write(uncore, GEN2_IIR,
249 I915_MASTER_ERROR_INTERRUPT);
252 if (GRAPHICS_VER(i915) >= 12) {
253 rmw_clear(uncore, GEN12_RING_FAULT_REG, RING_FAULT_VALID);
254 intel_uncore_posting_read(uncore, GEN12_RING_FAULT_REG);
255 } else if (GRAPHICS_VER(i915) >= 8) {
256 rmw_clear(uncore, GEN8_RING_FAULT_REG, RING_FAULT_VALID);
257 intel_uncore_posting_read(uncore, GEN8_RING_FAULT_REG);
258 } else if (GRAPHICS_VER(i915) >= 6) {
259 struct intel_engine_cs *engine;
260 enum intel_engine_id id;
262 for_each_engine_masked(engine, gt, engine_mask, id)
263 gen6_clear_engine_error_register(engine);
267 static void gen6_check_faults(struct intel_gt *gt)
269 struct intel_engine_cs *engine;
270 enum intel_engine_id id;
273 for_each_engine(engine, gt, id) {
274 fault = GEN6_RING_FAULT_REG_READ(engine);
275 if (fault & RING_FAULT_VALID) {
276 drm_dbg(&engine->i915->drm, "Unexpected fault\n"
278 "\tAddress space: %s\n"
282 fault & RING_FAULT_GTTSEL_MASK ?
284 RING_FAULT_SRCID(fault),
285 RING_FAULT_FAULT_TYPE(fault));
290 static void gen8_check_faults(struct intel_gt *gt)
292 struct intel_uncore *uncore = gt->uncore;
293 i915_reg_t fault_reg, fault_data0_reg, fault_data1_reg;
296 if (GRAPHICS_VER(gt->i915) >= 12) {
297 fault_reg = GEN12_RING_FAULT_REG;
298 fault_data0_reg = GEN12_FAULT_TLB_DATA0;
299 fault_data1_reg = GEN12_FAULT_TLB_DATA1;
301 fault_reg = GEN8_RING_FAULT_REG;
302 fault_data0_reg = GEN8_FAULT_TLB_DATA0;
303 fault_data1_reg = GEN8_FAULT_TLB_DATA1;
306 fault = intel_uncore_read(uncore, fault_reg);
307 if (fault & RING_FAULT_VALID) {
308 u32 fault_data0, fault_data1;
311 fault_data0 = intel_uncore_read(uncore, fault_data0_reg);
312 fault_data1 = intel_uncore_read(uncore, fault_data1_reg);
314 fault_addr = ((u64)(fault_data1 & FAULT_VA_HIGH_BITS) << 44) |
315 ((u64)fault_data0 << 12);
317 drm_dbg(&uncore->i915->drm, "Unexpected fault\n"
318 "\tAddr: 0x%08x_%08x\n"
319 "\tAddress space: %s\n"
323 upper_32_bits(fault_addr), lower_32_bits(fault_addr),
324 fault_data1 & FAULT_GTT_SEL ? "GGTT" : "PPGTT",
325 GEN8_RING_FAULT_ENGINE_ID(fault),
326 RING_FAULT_SRCID(fault),
327 RING_FAULT_FAULT_TYPE(fault));
331 void intel_gt_check_and_clear_faults(struct intel_gt *gt)
333 struct drm_i915_private *i915 = gt->i915;
335 /* From GEN8 onwards we only have one 'All Engine Fault Register' */
336 if (GRAPHICS_VER(i915) >= 8)
337 gen8_check_faults(gt);
338 else if (GRAPHICS_VER(i915) >= 6)
339 gen6_check_faults(gt);
343 intel_gt_clear_error_registers(gt, ALL_ENGINES);
346 void intel_gt_flush_ggtt_writes(struct intel_gt *gt)
348 struct intel_uncore *uncore = gt->uncore;
349 intel_wakeref_t wakeref;
352 * No actual flushing is required for the GTT write domain for reads
353 * from the GTT domain. Writes to it "immediately" go to main memory
354 * as far as we know, so there's no chipset flush. It also doesn't
355 * land in the GPU render cache.
357 * However, we do have to enforce the order so that all writes through
358 * the GTT land before any writes to the device, such as updates to
361 * We also have to wait a bit for the writes to land from the GTT.
362 * An uncached read (i.e. mmio) seems to be ideal for the round-trip
363 * timing. This issue has only been observed when switching quickly
364 * between GTT writes and CPU reads from inside the kernel on recent hw,
365 * and it appears to only affect discrete GTT blocks (i.e. on LLC
366 * system agents we cannot reproduce this behaviour, until Cannonlake
372 if (INTEL_INFO(gt->i915)->has_coherent_ggtt)
375 intel_gt_chipset_flush(gt);
377 with_intel_runtime_pm_if_in_use(uncore->rpm, wakeref) {
380 spin_lock_irqsave(&uncore->lock, flags);
381 intel_uncore_posting_read_fw(uncore,
382 RING_HEAD(RENDER_RING_BASE));
383 spin_unlock_irqrestore(&uncore->lock, flags);
387 void intel_gt_chipset_flush(struct intel_gt *gt)
390 if (GRAPHICS_VER(gt->i915) < 6)
391 intel_ggtt_gmch_flush();
394 void intel_gt_driver_register(struct intel_gt *gt)
396 intel_gsc_init(>->gsc, gt->i915);
398 intel_rps_driver_register(>->rps);
400 intel_gt_debugfs_register(gt);
401 intel_gt_sysfs_register(gt);
404 static int intel_gt_init_scratch(struct intel_gt *gt, unsigned int size)
406 struct drm_i915_private *i915 = gt->i915;
407 struct drm_i915_gem_object *obj;
408 struct i915_vma *vma;
411 obj = i915_gem_object_create_lmem(i915, size,
412 I915_BO_ALLOC_VOLATILE |
413 I915_BO_ALLOC_GPU_ONLY);
415 obj = i915_gem_object_create_stolen(i915, size);
417 obj = i915_gem_object_create_internal(i915, size);
419 drm_err(&i915->drm, "Failed to allocate scratch page\n");
423 vma = i915_vma_instance(obj, >->ggtt->vm, NULL);
429 ret = i915_ggtt_pin(vma, NULL, 0, PIN_HIGH);
433 gt->scratch = i915_vma_make_unshrinkable(vma);
438 i915_gem_object_put(obj);
442 static void intel_gt_fini_scratch(struct intel_gt *gt)
444 i915_vma_unpin_and_release(>->scratch, 0);
447 static struct i915_address_space *kernel_vm(struct intel_gt *gt)
449 if (INTEL_PPGTT(gt->i915) > INTEL_PPGTT_ALIASING)
450 return &i915_ppgtt_create(gt, I915_BO_ALLOC_PM_EARLY)->vm;
452 return i915_vm_get(>->ggtt->vm);
455 static int __engines_record_defaults(struct intel_gt *gt)
457 struct i915_request *requests[I915_NUM_ENGINES] = {};
458 struct intel_engine_cs *engine;
459 enum intel_engine_id id;
463 * As we reset the gpu during very early sanitisation, the current
464 * register state on the GPU should reflect its defaults values.
465 * We load a context onto the hw (with restore-inhibit), then switch
466 * over to a second context to save that default register state. We
467 * can then prime every new context with that state so they all start
468 * from the same default HW values.
471 for_each_engine(engine, gt, id) {
472 struct intel_renderstate so;
473 struct intel_context *ce;
474 struct i915_request *rq;
476 /* We must be able to switch to something! */
477 GEM_BUG_ON(!engine->kernel_context);
479 ce = intel_context_create(engine);
485 err = intel_renderstate_init(&so, ce);
489 rq = i915_request_create(ce);
495 err = intel_engine_emit_ctx_wa(rq);
499 err = intel_renderstate_emit(&so, rq);
504 requests[id] = i915_request_get(rq);
505 i915_request_add(rq);
507 intel_renderstate_fini(&so, ce);
510 intel_context_put(ce);
515 /* Flush the default context image to memory, and enable powersaving. */
516 if (intel_gt_wait_for_idle(gt, I915_GEM_IDLE_TIMEOUT) == -ETIME) {
521 for (id = 0; id < ARRAY_SIZE(requests); id++) {
522 struct i915_request *rq;
529 if (rq->fence.error) {
534 GEM_BUG_ON(!test_bit(CONTEXT_ALLOC_BIT, &rq->context->flags));
535 if (!rq->context->state)
538 /* Keep a copy of the state's backing pages; free the obj */
539 state = shmem_create_from_object(rq->context->state->obj);
541 err = PTR_ERR(state);
544 rq->engine->default_state = state;
549 * If we have to abandon now, we expect the engines to be idle
550 * and ready to be torn-down. The quickest way we can accomplish
551 * this is by declaring ourselves wedged.
554 intel_gt_set_wedged(gt);
556 for (id = 0; id < ARRAY_SIZE(requests); id++) {
557 struct intel_context *ce;
558 struct i915_request *rq;
565 i915_request_put(rq);
566 intel_context_put(ce);
571 static int __engines_verify_workarounds(struct intel_gt *gt)
573 struct intel_engine_cs *engine;
574 enum intel_engine_id id;
577 if (!IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
580 for_each_engine(engine, gt, id) {
581 if (intel_engine_verify_workarounds(engine, "load"))
585 /* Flush and restore the kernel context for safety */
586 if (intel_gt_wait_for_idle(gt, I915_GEM_IDLE_TIMEOUT) == -ETIME)
592 static void __intel_gt_disable(struct intel_gt *gt)
594 intel_gt_set_wedged_on_fini(gt);
596 intel_gt_suspend_prepare(gt);
597 intel_gt_suspend_late(gt);
599 GEM_BUG_ON(intel_gt_pm_is_awake(gt));
602 int intel_gt_wait_for_idle(struct intel_gt *gt, long timeout)
604 long remaining_timeout;
606 /* If the device is asleep, we have no requests outstanding */
607 if (!intel_gt_pm_is_awake(gt))
610 while ((timeout = intel_gt_retire_requests_timeout(gt, timeout,
611 &remaining_timeout)) > 0) {
613 if (signal_pending(current))
617 return timeout ? timeout : intel_uc_wait_for_idle(>->uc,
621 int intel_gt_init(struct intel_gt *gt)
625 err = i915_inject_probe_error(gt->i915, -ENODEV);
629 intel_gt_init_workarounds(gt);
632 * This is just a security blanket to placate dragons.
633 * On some systems, we very sporadically observe that the first TLBs
634 * used by the CS may be stale, despite us poking the TLB reset. If
635 * we hold the forcewake during initialisation these problems
636 * just magically go away.
638 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL);
640 err = intel_gt_init_scratch(gt,
641 GRAPHICS_VER(gt->i915) == 2 ? SZ_256K : SZ_4K);
645 intel_gt_pm_init(gt);
647 gt->vm = kernel_vm(gt);
653 intel_set_mocs_index(gt);
655 err = intel_engines_init(gt);
659 err = intel_uc_init(>->uc);
663 err = intel_gt_resume(gt);
667 err = intel_gt_init_hwconfig(gt);
669 drm_err(>->i915->drm, "Failed to retrieve hwconfig table: %pe\n",
672 err = __engines_record_defaults(gt);
676 err = __engines_verify_workarounds(gt);
680 intel_uc_init_late(>->uc);
682 err = i915_inject_probe_error(gt->i915, -EIO);
686 intel_migrate_init(>->migrate, gt);
688 intel_pxp_init(>->pxp);
692 __intel_gt_disable(gt);
693 intel_uc_fini_hw(>->uc);
695 intel_uc_fini(>->uc);
697 intel_engines_release(gt);
698 i915_vm_put(fetch_and_zero(>->vm));
700 intel_gt_pm_fini(gt);
701 intel_gt_fini_scratch(gt);
704 intel_gt_set_wedged_on_init(gt);
705 intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL);
709 void intel_gt_driver_remove(struct intel_gt *gt)
711 __intel_gt_disable(gt);
713 intel_migrate_fini(>->migrate);
714 intel_uc_driver_remove(>->uc);
716 intel_engines_release(gt);
718 intel_gt_flush_buffer_pool(gt);
721 void intel_gt_driver_unregister(struct intel_gt *gt)
723 intel_wakeref_t wakeref;
725 intel_gt_sysfs_unregister(gt);
726 intel_rps_driver_unregister(>->rps);
727 intel_gsc_fini(>->gsc);
729 intel_pxp_fini(>->pxp);
732 * Upon unregistering the device to prevent any new users, cancel
733 * all in-flight requests so that we can quickly unbind the active
736 intel_gt_set_wedged_on_fini(gt);
738 /* Scrub all HW state upon release */
739 with_intel_runtime_pm(gt->uncore->rpm, wakeref)
740 __intel_gt_reset(gt, ALL_ENGINES);
743 void intel_gt_driver_release(struct intel_gt *gt)
745 struct i915_address_space *vm;
747 vm = fetch_and_zero(>->vm);
748 if (vm) /* FIXME being called twice on error paths :( */
751 intel_wa_list_free(>->wa_list);
752 intel_gt_pm_fini(gt);
753 intel_gt_fini_scratch(gt);
754 intel_gt_fini_buffer_pool(gt);
755 intel_gt_fini_hwconfig(gt);
758 void intel_gt_driver_late_release_all(struct drm_i915_private *i915)
763 /* We need to wait for inflight RCU frees to release their grip */
766 for_each_gt(gt, i915, id) {
767 intel_uc_driver_late_release(>->uc);
768 intel_gt_fini_requests(gt);
769 intel_gt_fini_reset(gt);
770 intel_gt_fini_timelines(gt);
771 intel_engines_free(gt);
775 static int intel_gt_tile_setup(struct intel_gt *gt, phys_addr_t phys_addr)
779 if (!gt_is_root(gt)) {
780 struct intel_uncore_mmio_debug *mmio_debug;
781 struct intel_uncore *uncore;
783 uncore = kzalloc(sizeof(*uncore), GFP_KERNEL);
787 mmio_debug = kzalloc(sizeof(*mmio_debug), GFP_KERNEL);
794 gt->uncore->debug = mmio_debug;
796 __intel_gt_init_early(gt);
799 intel_uncore_init_early(gt->uncore, gt);
801 ret = intel_uncore_setup_mmio(gt->uncore, phys_addr);
805 gt->phys_addr = phys_addr;
811 intel_gt_tile_cleanup(struct intel_gt *gt)
813 intel_uncore_cleanup_mmio(gt->uncore);
815 if (!gt_is_root(gt)) {
816 kfree(gt->uncore->debug);
822 int intel_gt_probe_all(struct drm_i915_private *i915)
824 struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
825 struct intel_gt *gt = &i915->gt0;
826 phys_addr_t phys_addr;
827 unsigned int mmio_bar;
830 mmio_bar = GRAPHICS_VER(i915) == 2 ? 1 : 0;
831 phys_addr = pci_resource_start(pdev, mmio_bar);
834 * We always have at least one primary GT on any device
835 * and it has been already initialized early during probe
836 * in i915_driver_probe()
838 ret = intel_gt_tile_setup(gt, phys_addr);
844 /* TODO: add more tiles */
848 int intel_gt_tiles_init(struct drm_i915_private *i915)
854 for_each_gt(gt, i915, id) {
855 ret = intel_gt_probe_lmem(gt);
863 void intel_gt_release_all(struct drm_i915_private *i915)
868 for_each_gt(gt, i915, id) {
869 intel_gt_tile_cleanup(gt);
874 void intel_gt_info_print(const struct intel_gt_info *info,
875 struct drm_printer *p)
877 drm_printf(p, "available engines: %x\n", info->engine_mask);
879 intel_sseu_dump(&info->sseu, p);
887 static struct reg_and_bit
888 get_reg_and_bit(const struct intel_engine_cs *engine, const bool gen8,
889 const i915_reg_t *regs, const unsigned int num)
891 const unsigned int class = engine->class;
892 struct reg_and_bit rb = { };
894 if (drm_WARN_ON_ONCE(&engine->i915->drm,
895 class >= num || !regs[class].reg))
898 rb.reg = regs[class];
899 if (gen8 && class == VIDEO_DECODE_CLASS)
900 rb.reg.reg += 4 * engine->instance; /* GEN8_M2TCR */
902 rb.bit = engine->instance;
904 rb.bit = BIT(rb.bit);
909 void intel_gt_invalidate_tlbs(struct intel_gt *gt)
911 static const i915_reg_t gen8_regs[] = {
912 [RENDER_CLASS] = GEN8_RTCR,
913 [VIDEO_DECODE_CLASS] = GEN8_M1TCR, /* , GEN8_M2TCR */
914 [VIDEO_ENHANCEMENT_CLASS] = GEN8_VTCR,
915 [COPY_ENGINE_CLASS] = GEN8_BTCR,
917 static const i915_reg_t gen12_regs[] = {
918 [RENDER_CLASS] = GEN12_GFX_TLB_INV_CR,
919 [VIDEO_DECODE_CLASS] = GEN12_VD_TLB_INV_CR,
920 [VIDEO_ENHANCEMENT_CLASS] = GEN12_VE_TLB_INV_CR,
921 [COPY_ENGINE_CLASS] = GEN12_BLT_TLB_INV_CR,
922 [COMPUTE_CLASS] = GEN12_COMPCTX_TLB_INV_CR,
924 struct drm_i915_private *i915 = gt->i915;
925 struct intel_uncore *uncore = gt->uncore;
926 struct intel_engine_cs *engine;
927 enum intel_engine_id id;
928 const i915_reg_t *regs;
929 unsigned int num = 0;
931 if (I915_SELFTEST_ONLY(gt->awake == -ENODEV))
934 if (GRAPHICS_VER(i915) == 12) {
936 num = ARRAY_SIZE(gen12_regs);
937 } else if (GRAPHICS_VER(i915) >= 8 && GRAPHICS_VER(i915) <= 11) {
939 num = ARRAY_SIZE(gen8_regs);
940 } else if (GRAPHICS_VER(i915) < 8) {
944 if (drm_WARN_ONCE(&i915->drm, !num,
945 "Platform does not implement TLB invalidation!"))
950 assert_rpm_wakelock_held(&i915->runtime_pm);
952 mutex_lock(>->tlb_invalidate_lock);
953 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
955 spin_lock_irq(&uncore->lock); /* serialise invalidate with GT reset */
957 for_each_engine(engine, gt, id) {
958 struct reg_and_bit rb;
960 rb = get_reg_and_bit(engine, regs == gen8_regs, regs, num);
961 if (!i915_mmio_reg_offset(rb.reg))
964 intel_uncore_write_fw(uncore, rb.reg, rb.bit);
967 spin_unlock_irq(&uncore->lock);
969 for_each_engine(engine, gt, id) {
971 * HW architecture suggest typical invalidation time at 40us,
972 * with pessimistic cases up to 100us and a recommendation to
973 * cap at 1ms. We go a bit higher just in case.
975 const unsigned int timeout_us = 100;
976 const unsigned int timeout_ms = 4;
977 struct reg_and_bit rb;
979 rb = get_reg_and_bit(engine, regs == gen8_regs, regs, num);
980 if (!i915_mmio_reg_offset(rb.reg))
983 if (__intel_wait_for_register_fw(uncore,
985 timeout_us, timeout_ms,
987 drm_err_ratelimited(>->i915->drm,
988 "%s TLB invalidation did not complete in %ums!\n",
989 engine->name, timeout_ms);
993 * Use delayed put since a) we mostly expect a flurry of TLB
994 * invalidations so it is good to avoid paying the forcewake cost and
995 * b) it works around a bug in Icelake which cannot cope with too rapid
998 intel_uncore_forcewake_put_delayed(uncore, FORCEWAKE_ALL);
999 mutex_unlock(>->tlb_invalidate_lock);