1 // SPDX-License-Identifier: MIT
3 * Copyright © 2019 Intel Corporation
6 #include <drm/drm_managed.h>
7 #include <drm/intel-gtt.h>
9 #include "intel_gt_debugfs.h"
11 #include "gem/i915_gem_lmem.h"
13 #include "intel_context.h"
15 #include "intel_gt_buffer_pool.h"
16 #include "intel_gt_clock_utils.h"
17 #include "intel_gt_pm.h"
18 #include "intel_gt_requests.h"
19 #include "intel_migrate.h"
20 #include "intel_mocs.h"
22 #include "intel_rc6.h"
23 #include "intel_renderstate.h"
24 #include "intel_rps.h"
25 #include "intel_uncore.h"
26 #include "shmem_utils.h"
27 #include "pxp/intel_pxp.h"
29 void __intel_gt_init_early(struct intel_gt *gt, struct drm_i915_private *i915)
31 spin_lock_init(>->irq_lock);
33 mutex_init(>->tlb_invalidate_lock);
35 INIT_LIST_HEAD(>->closed_vma);
36 spin_lock_init(>->closed_lock);
38 init_llist_head(>->watchdog.list);
39 INIT_WORK(>->watchdog.work, intel_gt_watchdog_work);
41 intel_gt_init_buffer_pool(gt);
42 intel_gt_init_reset(gt);
43 intel_gt_init_requests(gt);
44 intel_gt_init_timelines(gt);
45 intel_gt_pm_init_early(gt);
47 intel_uc_init_early(>->uc);
48 intel_rps_init_early(>->rps);
51 void intel_gt_init_early(struct intel_gt *gt, struct drm_i915_private *i915)
54 gt->uncore = &i915->uncore;
57 int intel_gt_probe_lmem(struct intel_gt *gt)
59 struct drm_i915_private *i915 = gt->i915;
60 struct intel_memory_region *mem;
64 mem = intel_gt_setup_lmem(gt);
65 if (mem == ERR_PTR(-ENODEV))
66 mem = intel_gt_setup_fake_lmem(gt);
73 "Failed to setup region(%d) type=%d\n",
74 err, INTEL_MEMORY_LOCAL);
78 id = INTEL_REGION_LMEM;
82 intel_memory_region_set_name(mem, "local%u", mem->instance);
84 GEM_BUG_ON(!HAS_REGION(i915, id));
85 GEM_BUG_ON(i915->mm.regions[id]);
86 i915->mm.regions[id] = mem;
91 int intel_gt_assign_ggtt(struct intel_gt *gt)
93 gt->ggtt = drmm_kzalloc(>->i915->drm, sizeof(*gt->ggtt), GFP_KERNEL);
95 return gt->ggtt ? 0 : -ENOMEM;
98 static const struct intel_mmio_range icl_l3bank_steering_table[] = {
99 { 0x00B100, 0x00B3FF },
103 static const struct intel_mmio_range xehpsdv_mslice_steering_table[] = {
104 { 0x004000, 0x004AFF },
105 { 0x00C800, 0x00CFFF },
106 { 0x00DD00, 0x00DDFF },
107 { 0x00E900, 0x00FFFF }, /* 0xEA00 - OxEFFF is unused */
111 static const struct intel_mmio_range xehpsdv_lncf_steering_table[] = {
112 { 0x00B000, 0x00B0FF },
113 { 0x00D800, 0x00D8FF },
117 static const struct intel_mmio_range dg2_lncf_steering_table[] = {
118 { 0x00B000, 0x00B0FF },
119 { 0x00D880, 0x00D8FF },
123 static u16 slicemask(struct intel_gt *gt, int count)
125 u64 dss_mask = intel_sseu_get_subslices(>->info.sseu, 0);
127 return intel_slicemask_from_dssmask(dss_mask, count);
130 int intel_gt_init_mmio(struct intel_gt *gt)
132 struct drm_i915_private *i915 = gt->i915;
134 intel_gt_init_clock_frequency(gt);
136 intel_uc_init_mmio(>->uc);
137 intel_sseu_info_init(gt);
140 * An mslice is unavailable only if both the meml3 for the slice is
141 * disabled *and* all of the DSS in the slice (quadrant) are disabled.
143 if (HAS_MSLICES(i915))
144 gt->info.mslice_mask =
145 slicemask(gt, GEN_DSS_PER_MSLICE) |
146 (intel_uncore_read(gt->uncore, GEN10_MIRROR_FUSE3) &
147 GEN12_MEML3_EN_MASK);
150 gt->steering_table[MSLICE] = xehpsdv_mslice_steering_table;
151 gt->steering_table[LNCF] = dg2_lncf_steering_table;
152 } else if (IS_XEHPSDV(i915)) {
153 gt->steering_table[MSLICE] = xehpsdv_mslice_steering_table;
154 gt->steering_table[LNCF] = xehpsdv_lncf_steering_table;
155 } else if (GRAPHICS_VER(i915) >= 11 &&
156 GRAPHICS_VER_FULL(i915) < IP_VER(12, 50)) {
157 gt->steering_table[L3BANK] = icl_l3bank_steering_table;
158 gt->info.l3bank_mask =
159 ~intel_uncore_read(gt->uncore, GEN10_MIRROR_FUSE3) &
161 } else if (HAS_MSLICES(i915)) {
162 MISSING_CASE(INTEL_INFO(i915)->platform);
165 return intel_engines_init_mmio(gt);
168 static void init_unused_ring(struct intel_gt *gt, u32 base)
170 struct intel_uncore *uncore = gt->uncore;
172 intel_uncore_write(uncore, RING_CTL(base), 0);
173 intel_uncore_write(uncore, RING_HEAD(base), 0);
174 intel_uncore_write(uncore, RING_TAIL(base), 0);
175 intel_uncore_write(uncore, RING_START(base), 0);
178 static void init_unused_rings(struct intel_gt *gt)
180 struct drm_i915_private *i915 = gt->i915;
183 init_unused_ring(gt, PRB1_BASE);
184 init_unused_ring(gt, SRB0_BASE);
185 init_unused_ring(gt, SRB1_BASE);
186 init_unused_ring(gt, SRB2_BASE);
187 init_unused_ring(gt, SRB3_BASE);
188 } else if (GRAPHICS_VER(i915) == 2) {
189 init_unused_ring(gt, SRB0_BASE);
190 init_unused_ring(gt, SRB1_BASE);
191 } else if (GRAPHICS_VER(i915) == 3) {
192 init_unused_ring(gt, PRB1_BASE);
193 init_unused_ring(gt, PRB2_BASE);
197 int intel_gt_init_hw(struct intel_gt *gt)
199 struct drm_i915_private *i915 = gt->i915;
200 struct intel_uncore *uncore = gt->uncore;
203 gt->last_init_time = ktime_get();
205 /* Double layer security blanket, see i915_gem_init() */
206 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
208 if (HAS_EDRAM(i915) && GRAPHICS_VER(i915) < 9)
209 intel_uncore_rmw(uncore, HSW_IDICR, 0, IDIHASHMSK(0xf));
211 if (IS_HASWELL(i915))
212 intel_uncore_write(uncore,
213 MI_PREDICATE_RESULT_2,
215 LOWER_SLICE_ENABLED : LOWER_SLICE_DISABLED);
217 /* Apply the GT workarounds... */
218 intel_gt_apply_workarounds(gt);
219 /* ...and determine whether they are sticking. */
220 intel_gt_verify_workarounds(gt, "init");
222 intel_gt_init_swizzling(gt);
225 * At least 830 can leave some of the unused rings
226 * "active" (ie. head != tail) after resume which
227 * will prevent c3 entry. Makes sure all unused rings
230 init_unused_rings(gt);
232 ret = i915_ppgtt_init_hw(gt);
234 DRM_ERROR("Enabling PPGTT failed (%d)\n", ret);
238 /* We can't enable contexts until all firmware is loaded */
239 ret = intel_uc_init_hw(>->uc);
241 i915_probe_error(i915, "Enabling uc failed (%d)\n", ret);
248 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL);
252 static void rmw_set(struct intel_uncore *uncore, i915_reg_t reg, u32 set)
254 intel_uncore_rmw(uncore, reg, 0, set);
257 static void rmw_clear(struct intel_uncore *uncore, i915_reg_t reg, u32 clr)
259 intel_uncore_rmw(uncore, reg, clr, 0);
262 static void clear_register(struct intel_uncore *uncore, i915_reg_t reg)
264 intel_uncore_rmw(uncore, reg, 0, 0);
267 static void gen6_clear_engine_error_register(struct intel_engine_cs *engine)
269 GEN6_RING_FAULT_REG_RMW(engine, RING_FAULT_VALID, 0);
270 GEN6_RING_FAULT_REG_POSTING_READ(engine);
274 intel_gt_clear_error_registers(struct intel_gt *gt,
275 intel_engine_mask_t engine_mask)
277 struct drm_i915_private *i915 = gt->i915;
278 struct intel_uncore *uncore = gt->uncore;
281 if (GRAPHICS_VER(i915) != 2)
282 clear_register(uncore, PGTBL_ER);
284 if (GRAPHICS_VER(i915) < 4)
285 clear_register(uncore, IPEIR(RENDER_RING_BASE));
287 clear_register(uncore, IPEIR_I965);
289 clear_register(uncore, EIR);
290 eir = intel_uncore_read(uncore, EIR);
293 * some errors might have become stuck,
296 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
297 rmw_set(uncore, EMR, eir);
298 intel_uncore_write(uncore, GEN2_IIR,
299 I915_MASTER_ERROR_INTERRUPT);
302 if (GRAPHICS_VER(i915) >= 12) {
303 rmw_clear(uncore, GEN12_RING_FAULT_REG, RING_FAULT_VALID);
304 intel_uncore_posting_read(uncore, GEN12_RING_FAULT_REG);
305 } else if (GRAPHICS_VER(i915) >= 8) {
306 rmw_clear(uncore, GEN8_RING_FAULT_REG, RING_FAULT_VALID);
307 intel_uncore_posting_read(uncore, GEN8_RING_FAULT_REG);
308 } else if (GRAPHICS_VER(i915) >= 6) {
309 struct intel_engine_cs *engine;
310 enum intel_engine_id id;
312 for_each_engine_masked(engine, gt, engine_mask, id)
313 gen6_clear_engine_error_register(engine);
317 static void gen6_check_faults(struct intel_gt *gt)
319 struct intel_engine_cs *engine;
320 enum intel_engine_id id;
323 for_each_engine(engine, gt, id) {
324 fault = GEN6_RING_FAULT_REG_READ(engine);
325 if (fault & RING_FAULT_VALID) {
326 drm_dbg(&engine->i915->drm, "Unexpected fault\n"
328 "\tAddress space: %s\n"
332 fault & RING_FAULT_GTTSEL_MASK ?
334 RING_FAULT_SRCID(fault),
335 RING_FAULT_FAULT_TYPE(fault));
340 static void gen8_check_faults(struct intel_gt *gt)
342 struct intel_uncore *uncore = gt->uncore;
343 i915_reg_t fault_reg, fault_data0_reg, fault_data1_reg;
346 if (GRAPHICS_VER(gt->i915) >= 12) {
347 fault_reg = GEN12_RING_FAULT_REG;
348 fault_data0_reg = GEN12_FAULT_TLB_DATA0;
349 fault_data1_reg = GEN12_FAULT_TLB_DATA1;
351 fault_reg = GEN8_RING_FAULT_REG;
352 fault_data0_reg = GEN8_FAULT_TLB_DATA0;
353 fault_data1_reg = GEN8_FAULT_TLB_DATA1;
356 fault = intel_uncore_read(uncore, fault_reg);
357 if (fault & RING_FAULT_VALID) {
358 u32 fault_data0, fault_data1;
361 fault_data0 = intel_uncore_read(uncore, fault_data0_reg);
362 fault_data1 = intel_uncore_read(uncore, fault_data1_reg);
364 fault_addr = ((u64)(fault_data1 & FAULT_VA_HIGH_BITS) << 44) |
365 ((u64)fault_data0 << 12);
367 drm_dbg(&uncore->i915->drm, "Unexpected fault\n"
368 "\tAddr: 0x%08x_%08x\n"
369 "\tAddress space: %s\n"
373 upper_32_bits(fault_addr), lower_32_bits(fault_addr),
374 fault_data1 & FAULT_GTT_SEL ? "GGTT" : "PPGTT",
375 GEN8_RING_FAULT_ENGINE_ID(fault),
376 RING_FAULT_SRCID(fault),
377 RING_FAULT_FAULT_TYPE(fault));
381 void intel_gt_check_and_clear_faults(struct intel_gt *gt)
383 struct drm_i915_private *i915 = gt->i915;
385 /* From GEN8 onwards we only have one 'All Engine Fault Register' */
386 if (GRAPHICS_VER(i915) >= 8)
387 gen8_check_faults(gt);
388 else if (GRAPHICS_VER(i915) >= 6)
389 gen6_check_faults(gt);
393 intel_gt_clear_error_registers(gt, ALL_ENGINES);
396 void intel_gt_flush_ggtt_writes(struct intel_gt *gt)
398 struct intel_uncore *uncore = gt->uncore;
399 intel_wakeref_t wakeref;
402 * No actual flushing is required for the GTT write domain for reads
403 * from the GTT domain. Writes to it "immediately" go to main memory
404 * as far as we know, so there's no chipset flush. It also doesn't
405 * land in the GPU render cache.
407 * However, we do have to enforce the order so that all writes through
408 * the GTT land before any writes to the device, such as updates to
411 * We also have to wait a bit for the writes to land from the GTT.
412 * An uncached read (i.e. mmio) seems to be ideal for the round-trip
413 * timing. This issue has only been observed when switching quickly
414 * between GTT writes and CPU reads from inside the kernel on recent hw,
415 * and it appears to only affect discrete GTT blocks (i.e. on LLC
416 * system agents we cannot reproduce this behaviour, until Cannonlake
422 if (INTEL_INFO(gt->i915)->has_coherent_ggtt)
425 intel_gt_chipset_flush(gt);
427 with_intel_runtime_pm_if_in_use(uncore->rpm, wakeref) {
430 spin_lock_irqsave(&uncore->lock, flags);
431 intel_uncore_posting_read_fw(uncore,
432 RING_HEAD(RENDER_RING_BASE));
433 spin_unlock_irqrestore(&uncore->lock, flags);
437 void intel_gt_chipset_flush(struct intel_gt *gt)
440 if (GRAPHICS_VER(gt->i915) < 6)
441 intel_gtt_chipset_flush();
444 void intel_gt_driver_register(struct intel_gt *gt)
446 intel_rps_driver_register(>->rps);
448 intel_gt_debugfs_register(gt);
451 static int intel_gt_init_scratch(struct intel_gt *gt, unsigned int size)
453 struct drm_i915_private *i915 = gt->i915;
454 struct drm_i915_gem_object *obj;
455 struct i915_vma *vma;
458 obj = i915_gem_object_create_lmem(i915, size, I915_BO_ALLOC_VOLATILE);
460 obj = i915_gem_object_create_stolen(i915, size);
462 obj = i915_gem_object_create_internal(i915, size);
464 drm_err(&i915->drm, "Failed to allocate scratch page\n");
468 vma = i915_vma_instance(obj, >->ggtt->vm, NULL);
474 ret = i915_ggtt_pin(vma, NULL, 0, PIN_HIGH);
478 gt->scratch = i915_vma_make_unshrinkable(vma);
483 i915_gem_object_put(obj);
487 static void intel_gt_fini_scratch(struct intel_gt *gt)
489 i915_vma_unpin_and_release(>->scratch, 0);
492 static struct i915_address_space *kernel_vm(struct intel_gt *gt)
494 if (INTEL_PPGTT(gt->i915) > INTEL_PPGTT_ALIASING)
495 return &i915_ppgtt_create(gt, I915_BO_ALLOC_PM_EARLY)->vm;
497 return i915_vm_get(>->ggtt->vm);
500 static int __engines_record_defaults(struct intel_gt *gt)
502 struct i915_request *requests[I915_NUM_ENGINES] = {};
503 struct intel_engine_cs *engine;
504 enum intel_engine_id id;
508 * As we reset the gpu during very early sanitisation, the current
509 * register state on the GPU should reflect its defaults values.
510 * We load a context onto the hw (with restore-inhibit), then switch
511 * over to a second context to save that default register state. We
512 * can then prime every new context with that state so they all start
513 * from the same default HW values.
516 for_each_engine(engine, gt, id) {
517 struct intel_renderstate so;
518 struct intel_context *ce;
519 struct i915_request *rq;
521 /* We must be able to switch to something! */
522 GEM_BUG_ON(!engine->kernel_context);
524 ce = intel_context_create(engine);
530 err = intel_renderstate_init(&so, ce);
534 rq = i915_request_create(ce);
540 err = intel_engine_emit_ctx_wa(rq);
544 err = intel_renderstate_emit(&so, rq);
549 requests[id] = i915_request_get(rq);
550 i915_request_add(rq);
552 intel_renderstate_fini(&so, ce);
555 intel_context_put(ce);
560 /* Flush the default context image to memory, and enable powersaving. */
561 if (intel_gt_wait_for_idle(gt, I915_GEM_IDLE_TIMEOUT) == -ETIME) {
566 for (id = 0; id < ARRAY_SIZE(requests); id++) {
567 struct i915_request *rq;
574 if (rq->fence.error) {
579 GEM_BUG_ON(!test_bit(CONTEXT_ALLOC_BIT, &rq->context->flags));
580 if (!rq->context->state)
583 /* Keep a copy of the state's backing pages; free the obj */
584 state = shmem_create_from_object(rq->context->state->obj);
586 err = PTR_ERR(state);
589 rq->engine->default_state = state;
594 * If we have to abandon now, we expect the engines to be idle
595 * and ready to be torn-down. The quickest way we can accomplish
596 * this is by declaring ourselves wedged.
599 intel_gt_set_wedged(gt);
601 for (id = 0; id < ARRAY_SIZE(requests); id++) {
602 struct intel_context *ce;
603 struct i915_request *rq;
610 i915_request_put(rq);
611 intel_context_put(ce);
616 static int __engines_verify_workarounds(struct intel_gt *gt)
618 struct intel_engine_cs *engine;
619 enum intel_engine_id id;
622 if (!IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM))
625 for_each_engine(engine, gt, id) {
626 if (intel_engine_verify_workarounds(engine, "load"))
630 /* Flush and restore the kernel context for safety */
631 if (intel_gt_wait_for_idle(gt, I915_GEM_IDLE_TIMEOUT) == -ETIME)
637 static void __intel_gt_disable(struct intel_gt *gt)
639 intel_gt_set_wedged_on_fini(gt);
641 intel_gt_suspend_prepare(gt);
642 intel_gt_suspend_late(gt);
644 GEM_BUG_ON(intel_gt_pm_is_awake(gt));
647 int intel_gt_wait_for_idle(struct intel_gt *gt, long timeout)
649 long remaining_timeout;
651 /* If the device is asleep, we have no requests outstanding */
652 if (!intel_gt_pm_is_awake(gt))
655 while ((timeout = intel_gt_retire_requests_timeout(gt, timeout,
656 &remaining_timeout)) > 0) {
658 if (signal_pending(current))
662 return timeout ? timeout : intel_uc_wait_for_idle(>->uc,
666 int intel_gt_init(struct intel_gt *gt)
670 err = i915_inject_probe_error(gt->i915, -ENODEV);
674 intel_gt_init_workarounds(gt);
677 * This is just a security blanket to placate dragons.
678 * On some systems, we very sporadically observe that the first TLBs
679 * used by the CS may be stale, despite us poking the TLB reset. If
680 * we hold the forcewake during initialisation these problems
681 * just magically go away.
683 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL);
685 err = intel_gt_init_scratch(gt,
686 GRAPHICS_VER(gt->i915) == 2 ? SZ_256K : SZ_4K);
690 intel_gt_pm_init(gt);
692 gt->vm = kernel_vm(gt);
698 intel_set_mocs_index(gt);
700 err = intel_engines_init(gt);
704 err = intel_uc_init(>->uc);
708 err = intel_gt_resume(gt);
712 err = __engines_record_defaults(gt);
716 err = __engines_verify_workarounds(gt);
720 intel_uc_init_late(>->uc);
722 err = i915_inject_probe_error(gt->i915, -EIO);
726 intel_migrate_init(>->migrate, gt);
728 intel_pxp_init(>->pxp);
732 __intel_gt_disable(gt);
733 intel_uc_fini_hw(>->uc);
735 intel_uc_fini(>->uc);
737 intel_engines_release(gt);
738 i915_vm_put(fetch_and_zero(>->vm));
740 intel_gt_pm_fini(gt);
741 intel_gt_fini_scratch(gt);
744 intel_gt_set_wedged_on_init(gt);
745 intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL);
749 void intel_gt_driver_remove(struct intel_gt *gt)
751 __intel_gt_disable(gt);
753 intel_migrate_fini(>->migrate);
754 intel_uc_driver_remove(>->uc);
756 intel_engines_release(gt);
758 intel_gt_flush_buffer_pool(gt);
761 void intel_gt_driver_unregister(struct intel_gt *gt)
763 intel_wakeref_t wakeref;
765 intel_rps_driver_unregister(>->rps);
767 intel_pxp_fini(>->pxp);
770 * Upon unregistering the device to prevent any new users, cancel
771 * all in-flight requests so that we can quickly unbind the active
774 intel_gt_set_wedged_on_fini(gt);
776 /* Scrub all HW state upon release */
777 with_intel_runtime_pm(gt->uncore->rpm, wakeref)
778 __intel_gt_reset(gt, ALL_ENGINES);
781 void intel_gt_driver_release(struct intel_gt *gt)
783 struct i915_address_space *vm;
785 vm = fetch_and_zero(>->vm);
786 if (vm) /* FIXME being called twice on error paths :( */
789 intel_wa_list_free(>->wa_list);
790 intel_gt_pm_fini(gt);
791 intel_gt_fini_scratch(gt);
792 intel_gt_fini_buffer_pool(gt);
795 void intel_gt_driver_late_release(struct intel_gt *gt)
797 /* We need to wait for inflight RCU frees to release their grip */
800 intel_uc_driver_late_release(>->uc);
801 intel_gt_fini_requests(gt);
802 intel_gt_fini_reset(gt);
803 intel_gt_fini_timelines(gt);
804 intel_engines_free(gt);
808 * intel_gt_reg_needs_read_steering - determine whether a register read
809 * requires explicit steering
811 * @reg: the register to check steering requirements for
812 * @type: type of multicast steering to check
814 * Determines whether @reg needs explicit steering of a specific type for
817 * Returns false if @reg does not belong to a register range of the given
818 * steering type, or if the default (subslice-based) steering IDs are suitable
819 * for @type steering too.
821 static bool intel_gt_reg_needs_read_steering(struct intel_gt *gt,
823 enum intel_steering_type type)
825 const u32 offset = i915_mmio_reg_offset(reg);
826 const struct intel_mmio_range *entry;
828 if (likely(!intel_gt_needs_read_steering(gt, type)))
831 for (entry = gt->steering_table[type]; entry->end; entry++) {
832 if (offset >= entry->start && offset <= entry->end)
840 * intel_gt_get_valid_steering - determines valid IDs for a class of MCR steering
842 * @type: multicast register type
843 * @sliceid: Slice ID returned
844 * @subsliceid: Subslice ID returned
846 * Determines sliceid and subsliceid values that will steer reads
847 * of a specific multicast register class to a valid value.
849 static void intel_gt_get_valid_steering(struct intel_gt *gt,
850 enum intel_steering_type type,
851 u8 *sliceid, u8 *subsliceid)
855 GEM_DEBUG_WARN_ON(!gt->info.l3bank_mask); /* should be impossible! */
857 *sliceid = 0; /* unused */
858 *subsliceid = __ffs(gt->info.l3bank_mask);
861 GEM_DEBUG_WARN_ON(!gt->info.mslice_mask); /* should be impossible! */
863 *sliceid = __ffs(gt->info.mslice_mask);
864 *subsliceid = 0; /* unused */
867 GEM_DEBUG_WARN_ON(!gt->info.mslice_mask); /* should be impossible! */
870 * An LNCF is always present if its mslice is present, so we
871 * can safely just steer to LNCF 0 in all cases.
873 *sliceid = __ffs(gt->info.mslice_mask) << 1;
874 *subsliceid = 0; /* unused */
884 * intel_gt_read_register_fw - reads a GT register with support for multicast
886 * @reg: register to read
888 * This function will read a GT register. If the register is a multicast
889 * register, the read will be steered to a valid instance (i.e., one that
890 * isn't fused off or powered down by power gating).
892 * Returns the value from a valid instance of @reg.
894 u32 intel_gt_read_register_fw(struct intel_gt *gt, i915_reg_t reg)
897 u8 sliceid, subsliceid;
899 for (type = 0; type < NUM_STEERING_TYPES; type++) {
900 if (intel_gt_reg_needs_read_steering(gt, reg, type)) {
901 intel_gt_get_valid_steering(gt, type, &sliceid,
903 return intel_uncore_read_with_mcr_steering_fw(gt->uncore,
910 return intel_uncore_read_fw(gt->uncore, reg);
913 void intel_gt_info_print(const struct intel_gt_info *info,
914 struct drm_printer *p)
916 drm_printf(p, "available engines: %x\n", info->engine_mask);
918 intel_sseu_dump(&info->sseu, p);
926 static struct reg_and_bit
927 get_reg_and_bit(const struct intel_engine_cs *engine, const bool gen8,
928 const i915_reg_t *regs, const unsigned int num)
930 const unsigned int class = engine->class;
931 struct reg_and_bit rb = { };
933 if (drm_WARN_ON_ONCE(&engine->i915->drm,
934 class >= num || !regs[class].reg))
937 rb.reg = regs[class];
938 if (gen8 && class == VIDEO_DECODE_CLASS)
939 rb.reg.reg += 4 * engine->instance; /* GEN8_M2TCR */
941 rb.bit = engine->instance;
943 rb.bit = BIT(rb.bit);
948 void intel_gt_invalidate_tlbs(struct intel_gt *gt)
950 static const i915_reg_t gen8_regs[] = {
951 [RENDER_CLASS] = GEN8_RTCR,
952 [VIDEO_DECODE_CLASS] = GEN8_M1TCR, /* , GEN8_M2TCR */
953 [VIDEO_ENHANCEMENT_CLASS] = GEN8_VTCR,
954 [COPY_ENGINE_CLASS] = GEN8_BTCR,
956 static const i915_reg_t gen12_regs[] = {
957 [RENDER_CLASS] = GEN12_GFX_TLB_INV_CR,
958 [VIDEO_DECODE_CLASS] = GEN12_VD_TLB_INV_CR,
959 [VIDEO_ENHANCEMENT_CLASS] = GEN12_VE_TLB_INV_CR,
960 [COPY_ENGINE_CLASS] = GEN12_BLT_TLB_INV_CR,
962 struct drm_i915_private *i915 = gt->i915;
963 struct intel_uncore *uncore = gt->uncore;
964 struct intel_engine_cs *engine;
965 enum intel_engine_id id;
966 const i915_reg_t *regs;
967 unsigned int num = 0;
969 if (I915_SELFTEST_ONLY(gt->awake == -ENODEV))
972 if (GRAPHICS_VER(i915) == 12) {
974 num = ARRAY_SIZE(gen12_regs);
975 } else if (GRAPHICS_VER(i915) >= 8 && GRAPHICS_VER(i915) <= 11) {
977 num = ARRAY_SIZE(gen8_regs);
978 } else if (GRAPHICS_VER(i915) < 8) {
982 if (drm_WARN_ONCE(&i915->drm, !num,
983 "Platform does not implement TLB invalidation!"))
988 assert_rpm_wakelock_held(&i915->runtime_pm);
990 mutex_lock(>->tlb_invalidate_lock);
991 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
993 for_each_engine(engine, gt, id) {
995 * HW architecture suggest typical invalidation time at 40us,
996 * with pessimistic cases up to 100us and a recommendation to
997 * cap at 1ms. We go a bit higher just in case.
999 const unsigned int timeout_us = 100;
1000 const unsigned int timeout_ms = 4;
1001 struct reg_and_bit rb;
1003 rb = get_reg_and_bit(engine, regs == gen8_regs, regs, num);
1004 if (!i915_mmio_reg_offset(rb.reg))
1007 intel_uncore_write_fw(uncore, rb.reg, rb.bit);
1008 if (__intel_wait_for_register_fw(uncore,
1010 timeout_us, timeout_ms,
1012 drm_err_ratelimited(>->i915->drm,
1013 "%s TLB invalidation did not complete in %ums!\n",
1014 engine->name, timeout_ms);
1018 * Use delayed put since a) we mostly expect a flurry of TLB
1019 * invalidations so it is good to avoid paying the forcewake cost and
1020 * b) it works around a bug in Icelake which cannot cope with too rapid
1023 intel_uncore_forcewake_put_delayed(uncore, FORCEWAKE_ALL);
1024 mutex_unlock(>->tlb_invalidate_lock);