2 * Copyright © 2013 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
24 #include <drm/drm_managed.h>
25 #include <linux/pm_runtime.h>
27 #include "gt/intel_engine_regs.h"
28 #include "gt/intel_gt_regs.h"
31 #include "i915_iosf_mbi.h"
33 #include "i915_trace.h"
34 #include "i915_vgpu.h"
37 #define FORCEWAKE_ACK_TIMEOUT_MS 50
38 #define GT_FIFO_TIMEOUT_MS 10
40 #define __raw_posting_read(...) ((void)__raw_uncore_read32(__VA_ARGS__))
43 fw_domains_get(struct intel_uncore *uncore, enum forcewake_domains fw_domains)
45 uncore->fw_get_funcs->force_wake_get(uncore, fw_domains);
49 intel_uncore_mmio_debug_init_early(struct drm_i915_private *i915)
51 spin_lock_init(&i915->mmio_debug.lock);
52 i915->mmio_debug.unclaimed_mmio_check = 1;
54 i915->uncore.debug = &i915->mmio_debug;
57 static void mmio_debug_suspend(struct intel_uncore *uncore)
62 spin_lock(&uncore->debug->lock);
64 /* Save and disable mmio debugging for the user bypass */
65 if (!uncore->debug->suspend_count++) {
66 uncore->debug->saved_mmio_check = uncore->debug->unclaimed_mmio_check;
67 uncore->debug->unclaimed_mmio_check = 0;
70 spin_unlock(&uncore->debug->lock);
73 static bool check_for_unclaimed_mmio(struct intel_uncore *uncore);
75 static void mmio_debug_resume(struct intel_uncore *uncore)
80 spin_lock(&uncore->debug->lock);
82 if (!--uncore->debug->suspend_count)
83 uncore->debug->unclaimed_mmio_check = uncore->debug->saved_mmio_check;
85 if (check_for_unclaimed_mmio(uncore))
86 drm_info(&uncore->i915->drm,
87 "Invalid mmio detected during user access\n");
89 spin_unlock(&uncore->debug->lock);
92 static const char * const forcewake_domain_names[] = {
112 intel_uncore_forcewake_domain_to_str(const enum forcewake_domain_id id)
114 BUILD_BUG_ON(ARRAY_SIZE(forcewake_domain_names) != FW_DOMAIN_ID_COUNT);
116 if (id >= 0 && id < FW_DOMAIN_ID_COUNT)
117 return forcewake_domain_names[id];
124 #define fw_ack(d) readl((d)->reg_ack)
125 #define fw_set(d, val) writel(_MASKED_BIT_ENABLE((val)), (d)->reg_set)
126 #define fw_clear(d, val) writel(_MASKED_BIT_DISABLE((val)), (d)->reg_set)
129 fw_domain_reset(const struct intel_uncore_forcewake_domain *d)
132 * We don't really know if the powerwell for the forcewake domain we are
133 * trying to reset here does exist at this point (engines could be fused
134 * off in ICL+), so no waiting for acks
136 /* WaRsClearFWBitsAtReset */
137 if (GRAPHICS_VER(d->uncore->i915) >= 12)
144 fw_domain_arm_timer(struct intel_uncore_forcewake_domain *d)
146 GEM_BUG_ON(d->uncore->fw_domains_timer & d->mask);
147 d->uncore->fw_domains_timer |= d->mask;
149 hrtimer_start_range_ns(&d->timer,
156 __wait_for_ack(const struct intel_uncore_forcewake_domain *d,
160 return wait_for_atomic((fw_ack(d) & ack) == value,
161 FORCEWAKE_ACK_TIMEOUT_MS);
165 wait_ack_clear(const struct intel_uncore_forcewake_domain *d,
168 return __wait_for_ack(d, ack, 0);
172 wait_ack_set(const struct intel_uncore_forcewake_domain *d,
175 return __wait_for_ack(d, ack, ack);
179 fw_domain_wait_ack_clear(const struct intel_uncore_forcewake_domain *d)
181 if (wait_ack_clear(d, FORCEWAKE_KERNEL)) {
182 DRM_ERROR("%s: timed out waiting for forcewake ack to clear.\n",
183 intel_uncore_forcewake_domain_to_str(d->id));
184 add_taint_for_CI(d->uncore->i915, TAINT_WARN); /* CI now unreliable */
194 fw_domain_wait_ack_with_fallback(const struct intel_uncore_forcewake_domain *d,
195 const enum ack_type type)
197 const u32 ack_bit = FORCEWAKE_KERNEL;
198 const u32 value = type == ACK_SET ? ack_bit : 0;
203 * There is a possibility of driver's wake request colliding
204 * with hardware's own wake requests and that can cause
205 * hardware to not deliver the driver's ack message.
207 * Use a fallback bit toggle to kick the gpu state machine
208 * in the hope that the original ack will be delivered along with
211 * This workaround is described in HSDES #1604254524 and it's known as:
212 * WaRsForcewakeAddDelayForAck:skl,bxt,kbl,glk,cfl,cnl,icl
213 * although the name is a bit misleading.
218 wait_ack_clear(d, FORCEWAKE_KERNEL_FALLBACK);
220 fw_set(d, FORCEWAKE_KERNEL_FALLBACK);
221 /* Give gt some time to relax before the polling frenzy */
223 wait_ack_set(d, FORCEWAKE_KERNEL_FALLBACK);
225 ack_detected = (fw_ack(d) & ack_bit) == value;
227 fw_clear(d, FORCEWAKE_KERNEL_FALLBACK);
228 } while (!ack_detected && pass++ < 10);
230 DRM_DEBUG_DRIVER("%s had to use fallback to %s ack, 0x%x (passes %u)\n",
231 intel_uncore_forcewake_domain_to_str(d->id),
232 type == ACK_SET ? "set" : "clear",
236 return ack_detected ? 0 : -ETIMEDOUT;
240 fw_domain_wait_ack_clear_fallback(const struct intel_uncore_forcewake_domain *d)
242 if (likely(!wait_ack_clear(d, FORCEWAKE_KERNEL)))
245 if (fw_domain_wait_ack_with_fallback(d, ACK_CLEAR))
246 fw_domain_wait_ack_clear(d);
250 fw_domain_get(const struct intel_uncore_forcewake_domain *d)
252 fw_set(d, FORCEWAKE_KERNEL);
256 fw_domain_wait_ack_set(const struct intel_uncore_forcewake_domain *d)
258 if (wait_ack_set(d, FORCEWAKE_KERNEL)) {
259 DRM_ERROR("%s: timed out waiting for forcewake ack request.\n",
260 intel_uncore_forcewake_domain_to_str(d->id));
261 add_taint_for_CI(d->uncore->i915, TAINT_WARN); /* CI now unreliable */
266 fw_domain_wait_ack_set_fallback(const struct intel_uncore_forcewake_domain *d)
268 if (likely(!wait_ack_set(d, FORCEWAKE_KERNEL)))
271 if (fw_domain_wait_ack_with_fallback(d, ACK_SET))
272 fw_domain_wait_ack_set(d);
276 fw_domain_put(const struct intel_uncore_forcewake_domain *d)
278 fw_clear(d, FORCEWAKE_KERNEL);
282 fw_domains_get_normal(struct intel_uncore *uncore, enum forcewake_domains fw_domains)
284 struct intel_uncore_forcewake_domain *d;
287 GEM_BUG_ON(fw_domains & ~uncore->fw_domains);
289 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) {
290 fw_domain_wait_ack_clear(d);
294 for_each_fw_domain_masked(d, fw_domains, uncore, tmp)
295 fw_domain_wait_ack_set(d);
297 uncore->fw_domains_active |= fw_domains;
301 fw_domains_get_with_fallback(struct intel_uncore *uncore,
302 enum forcewake_domains fw_domains)
304 struct intel_uncore_forcewake_domain *d;
307 GEM_BUG_ON(fw_domains & ~uncore->fw_domains);
309 for_each_fw_domain_masked(d, fw_domains, uncore, tmp) {
310 fw_domain_wait_ack_clear_fallback(d);
314 for_each_fw_domain_masked(d, fw_domains, uncore, tmp)
315 fw_domain_wait_ack_set_fallback(d);
317 uncore->fw_domains_active |= fw_domains;
321 fw_domains_put(struct intel_uncore *uncore, enum forcewake_domains fw_domains)
323 struct intel_uncore_forcewake_domain *d;
326 GEM_BUG_ON(fw_domains & ~uncore->fw_domains);
328 for_each_fw_domain_masked(d, fw_domains, uncore, tmp)
331 uncore->fw_domains_active &= ~fw_domains;
335 fw_domains_reset(struct intel_uncore *uncore,
336 enum forcewake_domains fw_domains)
338 struct intel_uncore_forcewake_domain *d;
344 GEM_BUG_ON(fw_domains & ~uncore->fw_domains);
346 for_each_fw_domain_masked(d, fw_domains, uncore, tmp)
350 static inline u32 gt_thread_status(struct intel_uncore *uncore)
354 val = __raw_uncore_read32(uncore, GEN6_GT_THREAD_STATUS_REG);
355 val &= GEN6_GT_THREAD_STATUS_CORE_MASK;
360 static void __gen6_gt_wait_for_thread_c0(struct intel_uncore *uncore)
363 * w/a for a sporadic read returning 0 by waiting for the GT
366 drm_WARN_ONCE(&uncore->i915->drm,
367 wait_for_atomic_us(gt_thread_status(uncore) == 0, 5000),
368 "GT thread status wait timed out\n");
371 static void fw_domains_get_with_thread_status(struct intel_uncore *uncore,
372 enum forcewake_domains fw_domains)
374 fw_domains_get_normal(uncore, fw_domains);
376 /* WaRsForcewakeWaitTC0:snb,ivb,hsw,bdw,vlv */
377 __gen6_gt_wait_for_thread_c0(uncore);
380 static inline u32 fifo_free_entries(struct intel_uncore *uncore)
382 u32 count = __raw_uncore_read32(uncore, GTFIFOCTL);
384 return count & GT_FIFO_FREE_ENTRIES_MASK;
387 static void __gen6_gt_wait_for_fifo(struct intel_uncore *uncore)
391 /* On VLV, FIFO will be shared by both SW and HW.
392 * So, we need to read the FREE_ENTRIES everytime */
393 if (IS_VALLEYVIEW(uncore->i915))
394 n = fifo_free_entries(uncore);
396 n = uncore->fifo_count;
398 if (n <= GT_FIFO_NUM_RESERVED_ENTRIES) {
399 if (wait_for_atomic((n = fifo_free_entries(uncore)) >
400 GT_FIFO_NUM_RESERVED_ENTRIES,
401 GT_FIFO_TIMEOUT_MS)) {
402 drm_dbg(&uncore->i915->drm,
403 "GT_FIFO timeout, entries: %u\n", n);
408 uncore->fifo_count = n - 1;
411 static enum hrtimer_restart
412 intel_uncore_fw_release_timer(struct hrtimer *timer)
414 struct intel_uncore_forcewake_domain *domain =
415 container_of(timer, struct intel_uncore_forcewake_domain, timer);
416 struct intel_uncore *uncore = domain->uncore;
417 unsigned long irqflags;
419 assert_rpm_device_not_suspended(uncore->rpm);
421 if (xchg(&domain->active, false))
422 return HRTIMER_RESTART;
424 spin_lock_irqsave(&uncore->lock, irqflags);
426 uncore->fw_domains_timer &= ~domain->mask;
428 GEM_BUG_ON(!domain->wake_count);
429 if (--domain->wake_count == 0)
430 fw_domains_put(uncore, domain->mask);
432 spin_unlock_irqrestore(&uncore->lock, irqflags);
434 return HRTIMER_NORESTART;
437 /* Note callers must have acquired the PUNIT->PMIC bus, before calling this. */
439 intel_uncore_forcewake_reset(struct intel_uncore *uncore)
441 unsigned long irqflags;
442 struct intel_uncore_forcewake_domain *domain;
443 int retry_count = 100;
444 enum forcewake_domains fw, active_domains;
446 iosf_mbi_assert_punit_acquired();
448 /* Hold uncore.lock across reset to prevent any register access
449 * with forcewake not set correctly. Wait until all pending
450 * timers are run before holding.
457 for_each_fw_domain(domain, uncore, tmp) {
458 smp_store_mb(domain->active, false);
459 if (hrtimer_cancel(&domain->timer) == 0)
462 intel_uncore_fw_release_timer(&domain->timer);
465 spin_lock_irqsave(&uncore->lock, irqflags);
467 for_each_fw_domain(domain, uncore, tmp) {
468 if (hrtimer_active(&domain->timer))
469 active_domains |= domain->mask;
472 if (active_domains == 0)
475 if (--retry_count == 0) {
476 drm_err(&uncore->i915->drm, "Timed out waiting for forcewake timers to finish\n");
480 spin_unlock_irqrestore(&uncore->lock, irqflags);
484 drm_WARN_ON(&uncore->i915->drm, active_domains);
486 fw = uncore->fw_domains_active;
488 fw_domains_put(uncore, fw);
490 fw_domains_reset(uncore, uncore->fw_domains);
491 assert_forcewakes_inactive(uncore);
493 spin_unlock_irqrestore(&uncore->lock, irqflags);
495 return fw; /* track the lost user forcewake domains */
499 fpga_check_for_unclaimed_mmio(struct intel_uncore *uncore)
503 dbg = __raw_uncore_read32(uncore, FPGA_DBG);
504 if (likely(!(dbg & FPGA_DBG_RM_NOCLAIM)))
508 * Bugs in PCI programming (or failing hardware) can occasionally cause
509 * us to lose access to the MMIO BAR. When this happens, register
510 * reads will come back with 0xFFFFFFFF for every register and things
511 * go bad very quickly. Let's try to detect that special case and at
512 * least try to print a more informative message about what has
515 * During normal operation the FPGA_DBG register has several unused
516 * bits that will always read back as 0's so we can use them as canaries
517 * to recognize when MMIO accesses are just busted.
519 if (unlikely(dbg == ~0))
520 drm_err(&uncore->i915->drm,
521 "Lost access to MMIO BAR; all registers now read back as 0xFFFFFFFF!\n");
523 __raw_uncore_write32(uncore, FPGA_DBG, FPGA_DBG_RM_NOCLAIM);
529 vlv_check_for_unclaimed_mmio(struct intel_uncore *uncore)
533 cer = __raw_uncore_read32(uncore, CLAIM_ER);
534 if (likely(!(cer & (CLAIM_ER_OVERFLOW | CLAIM_ER_CTR_MASK))))
537 __raw_uncore_write32(uncore, CLAIM_ER, CLAIM_ER_CLR);
543 gen6_check_for_fifo_debug(struct intel_uncore *uncore)
547 fifodbg = __raw_uncore_read32(uncore, GTFIFODBG);
549 if (unlikely(fifodbg)) {
550 drm_dbg(&uncore->i915->drm, "GTFIFODBG = 0x08%x\n", fifodbg);
551 __raw_uncore_write32(uncore, GTFIFODBG, fifodbg);
558 check_for_unclaimed_mmio(struct intel_uncore *uncore)
562 lockdep_assert_held(&uncore->debug->lock);
564 if (uncore->debug->suspend_count)
567 if (intel_uncore_has_fpga_dbg_unclaimed(uncore))
568 ret |= fpga_check_for_unclaimed_mmio(uncore);
570 if (intel_uncore_has_dbg_unclaimed(uncore))
571 ret |= vlv_check_for_unclaimed_mmio(uncore);
573 if (intel_uncore_has_fifo(uncore))
574 ret |= gen6_check_for_fifo_debug(uncore);
579 static void forcewake_early_sanitize(struct intel_uncore *uncore,
580 unsigned int restore_forcewake)
582 GEM_BUG_ON(!intel_uncore_has_forcewake(uncore));
584 /* WaDisableShadowRegForCpd:chv */
585 if (IS_CHERRYVIEW(uncore->i915)) {
586 __raw_uncore_write32(uncore, GTFIFOCTL,
587 __raw_uncore_read32(uncore, GTFIFOCTL) |
588 GT_FIFO_CTL_BLOCK_ALL_POLICY_STALL |
589 GT_FIFO_CTL_RC6_POLICY_STALL);
592 iosf_mbi_punit_acquire();
593 intel_uncore_forcewake_reset(uncore);
594 if (restore_forcewake) {
595 spin_lock_irq(&uncore->lock);
596 fw_domains_get(uncore, restore_forcewake);
598 if (intel_uncore_has_fifo(uncore))
599 uncore->fifo_count = fifo_free_entries(uncore);
600 spin_unlock_irq(&uncore->lock);
602 iosf_mbi_punit_release();
605 void intel_uncore_suspend(struct intel_uncore *uncore)
607 if (!intel_uncore_has_forcewake(uncore))
610 iosf_mbi_punit_acquire();
611 iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(
612 &uncore->pmic_bus_access_nb);
613 uncore->fw_domains_saved = intel_uncore_forcewake_reset(uncore);
614 iosf_mbi_punit_release();
617 void intel_uncore_resume_early(struct intel_uncore *uncore)
619 unsigned int restore_forcewake;
621 if (intel_uncore_unclaimed_mmio(uncore))
622 drm_dbg(&uncore->i915->drm, "unclaimed mmio detected on resume, clearing\n");
624 if (!intel_uncore_has_forcewake(uncore))
627 restore_forcewake = fetch_and_zero(&uncore->fw_domains_saved);
628 forcewake_early_sanitize(uncore, restore_forcewake);
630 iosf_mbi_register_pmic_bus_access_notifier(&uncore->pmic_bus_access_nb);
633 void intel_uncore_runtime_resume(struct intel_uncore *uncore)
635 if (!intel_uncore_has_forcewake(uncore))
638 iosf_mbi_register_pmic_bus_access_notifier(&uncore->pmic_bus_access_nb);
641 static void __intel_uncore_forcewake_get(struct intel_uncore *uncore,
642 enum forcewake_domains fw_domains)
644 struct intel_uncore_forcewake_domain *domain;
647 fw_domains &= uncore->fw_domains;
649 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) {
650 if (domain->wake_count++) {
651 fw_domains &= ~domain->mask;
652 domain->active = true;
657 fw_domains_get(uncore, fw_domains);
661 * intel_uncore_forcewake_get - grab forcewake domain references
662 * @uncore: the intel_uncore structure
663 * @fw_domains: forcewake domains to get reference on
665 * This function can be used get GT's forcewake domain references.
666 * Normal register access will handle the forcewake domains automatically.
667 * However if some sequence requires the GT to not power down a particular
668 * forcewake domains this function should be called at the beginning of the
669 * sequence. And subsequently the reference should be dropped by symmetric
670 * call to intel_unforce_forcewake_put(). Usually caller wants all the domains
671 * to be kept awake so the @fw_domains would be then FORCEWAKE_ALL.
673 void intel_uncore_forcewake_get(struct intel_uncore *uncore,
674 enum forcewake_domains fw_domains)
676 unsigned long irqflags;
678 if (!uncore->fw_get_funcs)
681 assert_rpm_wakelock_held(uncore->rpm);
683 spin_lock_irqsave(&uncore->lock, irqflags);
684 __intel_uncore_forcewake_get(uncore, fw_domains);
685 spin_unlock_irqrestore(&uncore->lock, irqflags);
689 * intel_uncore_forcewake_user_get - claim forcewake on behalf of userspace
690 * @uncore: the intel_uncore structure
692 * This function is a wrapper around intel_uncore_forcewake_get() to acquire
693 * the GT powerwell and in the process disable our debugging for the
694 * duration of userspace's bypass.
696 void intel_uncore_forcewake_user_get(struct intel_uncore *uncore)
698 spin_lock_irq(&uncore->lock);
699 if (!uncore->user_forcewake_count++) {
700 intel_uncore_forcewake_get__locked(uncore, FORCEWAKE_ALL);
701 mmio_debug_suspend(uncore);
703 spin_unlock_irq(&uncore->lock);
707 * intel_uncore_forcewake_user_put - release forcewake on behalf of userspace
708 * @uncore: the intel_uncore structure
710 * This function complements intel_uncore_forcewake_user_get() and releases
711 * the GT powerwell taken on behalf of the userspace bypass.
713 void intel_uncore_forcewake_user_put(struct intel_uncore *uncore)
715 spin_lock_irq(&uncore->lock);
716 if (!--uncore->user_forcewake_count) {
717 mmio_debug_resume(uncore);
718 intel_uncore_forcewake_put__locked(uncore, FORCEWAKE_ALL);
720 spin_unlock_irq(&uncore->lock);
724 * intel_uncore_forcewake_get__locked - grab forcewake domain references
725 * @uncore: the intel_uncore structure
726 * @fw_domains: forcewake domains to get reference on
728 * See intel_uncore_forcewake_get(). This variant places the onus
729 * on the caller to explicitly handle the dev_priv->uncore.lock spinlock.
731 void intel_uncore_forcewake_get__locked(struct intel_uncore *uncore,
732 enum forcewake_domains fw_domains)
734 lockdep_assert_held(&uncore->lock);
736 if (!uncore->fw_get_funcs)
739 __intel_uncore_forcewake_get(uncore, fw_domains);
742 static void __intel_uncore_forcewake_put(struct intel_uncore *uncore,
743 enum forcewake_domains fw_domains,
746 struct intel_uncore_forcewake_domain *domain;
749 fw_domains &= uncore->fw_domains;
751 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) {
752 GEM_BUG_ON(!domain->wake_count);
754 if (--domain->wake_count) {
755 domain->active = true;
760 !(domain->uncore->fw_domains_timer & domain->mask))
761 fw_domain_arm_timer(domain);
763 fw_domains_put(uncore, domain->mask);
768 * intel_uncore_forcewake_put - release a forcewake domain reference
769 * @uncore: the intel_uncore structure
770 * @fw_domains: forcewake domains to put references
772 * This function drops the device-level forcewakes for specified
773 * domains obtained by intel_uncore_forcewake_get().
775 void intel_uncore_forcewake_put(struct intel_uncore *uncore,
776 enum forcewake_domains fw_domains)
778 unsigned long irqflags;
780 if (!uncore->fw_get_funcs)
783 spin_lock_irqsave(&uncore->lock, irqflags);
784 __intel_uncore_forcewake_put(uncore, fw_domains, false);
785 spin_unlock_irqrestore(&uncore->lock, irqflags);
788 void intel_uncore_forcewake_put_delayed(struct intel_uncore *uncore,
789 enum forcewake_domains fw_domains)
791 unsigned long irqflags;
793 if (!uncore->fw_get_funcs)
796 spin_lock_irqsave(&uncore->lock, irqflags);
797 __intel_uncore_forcewake_put(uncore, fw_domains, true);
798 spin_unlock_irqrestore(&uncore->lock, irqflags);
802 * intel_uncore_forcewake_flush - flush the delayed release
803 * @uncore: the intel_uncore structure
804 * @fw_domains: forcewake domains to flush
806 void intel_uncore_forcewake_flush(struct intel_uncore *uncore,
807 enum forcewake_domains fw_domains)
809 struct intel_uncore_forcewake_domain *domain;
812 if (!uncore->fw_get_funcs)
815 fw_domains &= uncore->fw_domains;
816 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) {
817 WRITE_ONCE(domain->active, false);
818 if (hrtimer_cancel(&domain->timer))
819 intel_uncore_fw_release_timer(&domain->timer);
824 * intel_uncore_forcewake_put__locked - grab forcewake domain references
825 * @uncore: the intel_uncore structure
826 * @fw_domains: forcewake domains to get reference on
828 * See intel_uncore_forcewake_put(). This variant places the onus
829 * on the caller to explicitly handle the dev_priv->uncore.lock spinlock.
831 void intel_uncore_forcewake_put__locked(struct intel_uncore *uncore,
832 enum forcewake_domains fw_domains)
834 lockdep_assert_held(&uncore->lock);
836 if (!uncore->fw_get_funcs)
839 __intel_uncore_forcewake_put(uncore, fw_domains, false);
842 void assert_forcewakes_inactive(struct intel_uncore *uncore)
844 if (!uncore->fw_get_funcs)
847 drm_WARN(&uncore->i915->drm, uncore->fw_domains_active,
848 "Expected all fw_domains to be inactive, but %08x are still on\n",
849 uncore->fw_domains_active);
852 void assert_forcewakes_active(struct intel_uncore *uncore,
853 enum forcewake_domains fw_domains)
855 struct intel_uncore_forcewake_domain *domain;
858 if (!IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM))
861 if (!uncore->fw_get_funcs)
864 spin_lock_irq(&uncore->lock);
866 assert_rpm_wakelock_held(uncore->rpm);
868 fw_domains &= uncore->fw_domains;
869 drm_WARN(&uncore->i915->drm, fw_domains & ~uncore->fw_domains_active,
870 "Expected %08x fw_domains to be active, but %08x are off\n",
871 fw_domains, fw_domains & ~uncore->fw_domains_active);
874 * Check that the caller has an explicit wakeref and we don't mistake
875 * it for the auto wakeref.
877 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) {
878 unsigned int actual = READ_ONCE(domain->wake_count);
879 unsigned int expect = 1;
881 if (uncore->fw_domains_timer & domain->mask)
882 expect++; /* pending automatic release */
884 if (drm_WARN(&uncore->i915->drm, actual < expect,
885 "Expected domain %d to be held awake by caller, count=%d\n",
890 spin_unlock_irq(&uncore->lock);
894 * We give fast paths for the really cool registers. The second range includes
895 * media domains (and the GSC starting from Xe_LPM+)
897 #define NEEDS_FORCE_WAKE(reg) ({ \
899 __reg < 0x40000 || __reg >= 0x116000; \
902 static int fw_range_cmp(u32 offset, const struct intel_forcewake_range *entry)
904 if (offset < entry->start)
906 else if (offset > entry->end)
912 /* Copied and "macroized" from lib/bsearch.c */
913 #define BSEARCH(key, base, num, cmp) ({ \
914 unsigned int start__ = 0, end__ = (num); \
915 typeof(base) result__ = NULL; \
916 while (start__ < end__) { \
917 unsigned int mid__ = start__ + (end__ - start__) / 2; \
918 int ret__ = (cmp)((key), (base) + mid__); \
921 } else if (ret__ > 0) { \
922 start__ = mid__ + 1; \
924 result__ = (base) + mid__; \
931 static enum forcewake_domains
932 find_fw_domain(struct intel_uncore *uncore, u32 offset)
934 const struct intel_forcewake_range *entry;
936 if (IS_GSI_REG(offset))
937 offset += uncore->gsi_offset;
939 entry = BSEARCH(offset,
940 uncore->fw_domains_table,
941 uncore->fw_domains_table_entries,
948 * The list of FW domains depends on the SKU in gen11+ so we
949 * can't determine it statically. We use FORCEWAKE_ALL and
950 * translate it here to the list of available domains.
952 if (entry->domains == FORCEWAKE_ALL)
953 return uncore->fw_domains;
955 drm_WARN(&uncore->i915->drm, entry->domains & ~uncore->fw_domains,
956 "Uninitialized forcewake domain(s) 0x%x accessed at 0x%x\n",
957 entry->domains & ~uncore->fw_domains, offset);
959 return entry->domains;
963 * Shadowed register tables describe special register ranges that i915 is
964 * allowed to write to without acquiring forcewake. If these registers' power
965 * wells are down, the hardware will save values written by i915 to a shadow
966 * copy and automatically transfer them into the real register the next time
967 * the power well is woken up. Shadowing only applies to writes; forcewake
968 * must still be acquired when reading from registers in these ranges.
970 * The documentation for shadowed registers is somewhat spotty on older
971 * platforms. However missing registers from these lists is non-fatal; it just
972 * means we'll wake up the hardware for some register accesses where we didn't
975 * The ranges listed in these tables must be sorted by offset.
977 * When adding new tables here, please also add them to
978 * intel_shadow_table_check() in selftests/intel_uncore.c so that they will be
979 * scanned for obvious mistakes or typos by the selftests.
982 static const struct i915_range gen8_shadowed_regs[] = {
983 { .start = 0x2030, .end = 0x2030 },
984 { .start = 0xA008, .end = 0xA00C },
985 { .start = 0x12030, .end = 0x12030 },
986 { .start = 0x1a030, .end = 0x1a030 },
987 { .start = 0x22030, .end = 0x22030 },
990 static const struct i915_range gen11_shadowed_regs[] = {
991 { .start = 0x2030, .end = 0x2030 },
992 { .start = 0x2550, .end = 0x2550 },
993 { .start = 0xA008, .end = 0xA00C },
994 { .start = 0x22030, .end = 0x22030 },
995 { .start = 0x22230, .end = 0x22230 },
996 { .start = 0x22510, .end = 0x22550 },
997 { .start = 0x1C0030, .end = 0x1C0030 },
998 { .start = 0x1C0230, .end = 0x1C0230 },
999 { .start = 0x1C0510, .end = 0x1C0550 },
1000 { .start = 0x1C4030, .end = 0x1C4030 },
1001 { .start = 0x1C4230, .end = 0x1C4230 },
1002 { .start = 0x1C4510, .end = 0x1C4550 },
1003 { .start = 0x1C8030, .end = 0x1C8030 },
1004 { .start = 0x1C8230, .end = 0x1C8230 },
1005 { .start = 0x1C8510, .end = 0x1C8550 },
1006 { .start = 0x1D0030, .end = 0x1D0030 },
1007 { .start = 0x1D0230, .end = 0x1D0230 },
1008 { .start = 0x1D0510, .end = 0x1D0550 },
1009 { .start = 0x1D4030, .end = 0x1D4030 },
1010 { .start = 0x1D4230, .end = 0x1D4230 },
1011 { .start = 0x1D4510, .end = 0x1D4550 },
1012 { .start = 0x1D8030, .end = 0x1D8030 },
1013 { .start = 0x1D8230, .end = 0x1D8230 },
1014 { .start = 0x1D8510, .end = 0x1D8550 },
1017 static const struct i915_range gen12_shadowed_regs[] = {
1018 { .start = 0x2030, .end = 0x2030 },
1019 { .start = 0x2510, .end = 0x2550 },
1020 { .start = 0xA008, .end = 0xA00C },
1021 { .start = 0xA188, .end = 0xA188 },
1022 { .start = 0xA278, .end = 0xA278 },
1023 { .start = 0xA540, .end = 0xA56C },
1024 { .start = 0xC4C8, .end = 0xC4C8 },
1025 { .start = 0xC4D4, .end = 0xC4D4 },
1026 { .start = 0xC600, .end = 0xC600 },
1027 { .start = 0x22030, .end = 0x22030 },
1028 { .start = 0x22510, .end = 0x22550 },
1029 { .start = 0x1C0030, .end = 0x1C0030 },
1030 { .start = 0x1C0510, .end = 0x1C0550 },
1031 { .start = 0x1C4030, .end = 0x1C4030 },
1032 { .start = 0x1C4510, .end = 0x1C4550 },
1033 { .start = 0x1C8030, .end = 0x1C8030 },
1034 { .start = 0x1C8510, .end = 0x1C8550 },
1035 { .start = 0x1D0030, .end = 0x1D0030 },
1036 { .start = 0x1D0510, .end = 0x1D0550 },
1037 { .start = 0x1D4030, .end = 0x1D4030 },
1038 { .start = 0x1D4510, .end = 0x1D4550 },
1039 { .start = 0x1D8030, .end = 0x1D8030 },
1040 { .start = 0x1D8510, .end = 0x1D8550 },
1043 * The rest of these ranges are specific to Xe_HP and beyond, but
1044 * are reserved/unused ranges on earlier gen12 platforms, so they can
1045 * be safely added to the gen12 table.
1047 { .start = 0x1E0030, .end = 0x1E0030 },
1048 { .start = 0x1E0510, .end = 0x1E0550 },
1049 { .start = 0x1E4030, .end = 0x1E4030 },
1050 { .start = 0x1E4510, .end = 0x1E4550 },
1051 { .start = 0x1E8030, .end = 0x1E8030 },
1052 { .start = 0x1E8510, .end = 0x1E8550 },
1053 { .start = 0x1F0030, .end = 0x1F0030 },
1054 { .start = 0x1F0510, .end = 0x1F0550 },
1055 { .start = 0x1F4030, .end = 0x1F4030 },
1056 { .start = 0x1F4510, .end = 0x1F4550 },
1057 { .start = 0x1F8030, .end = 0x1F8030 },
1058 { .start = 0x1F8510, .end = 0x1F8550 },
1061 static const struct i915_range dg2_shadowed_regs[] = {
1062 { .start = 0x2030, .end = 0x2030 },
1063 { .start = 0x2510, .end = 0x2550 },
1064 { .start = 0xA008, .end = 0xA00C },
1065 { .start = 0xA188, .end = 0xA188 },
1066 { .start = 0xA278, .end = 0xA278 },
1067 { .start = 0xA540, .end = 0xA56C },
1068 { .start = 0xC4C8, .end = 0xC4C8 },
1069 { .start = 0xC4E0, .end = 0xC4E0 },
1070 { .start = 0xC600, .end = 0xC600 },
1071 { .start = 0xC658, .end = 0xC658 },
1072 { .start = 0x22030, .end = 0x22030 },
1073 { .start = 0x22510, .end = 0x22550 },
1074 { .start = 0x1C0030, .end = 0x1C0030 },
1075 { .start = 0x1C0510, .end = 0x1C0550 },
1076 { .start = 0x1C4030, .end = 0x1C4030 },
1077 { .start = 0x1C4510, .end = 0x1C4550 },
1078 { .start = 0x1C8030, .end = 0x1C8030 },
1079 { .start = 0x1C8510, .end = 0x1C8550 },
1080 { .start = 0x1D0030, .end = 0x1D0030 },
1081 { .start = 0x1D0510, .end = 0x1D0550 },
1082 { .start = 0x1D4030, .end = 0x1D4030 },
1083 { .start = 0x1D4510, .end = 0x1D4550 },
1084 { .start = 0x1D8030, .end = 0x1D8030 },
1085 { .start = 0x1D8510, .end = 0x1D8550 },
1086 { .start = 0x1E0030, .end = 0x1E0030 },
1087 { .start = 0x1E0510, .end = 0x1E0550 },
1088 { .start = 0x1E4030, .end = 0x1E4030 },
1089 { .start = 0x1E4510, .end = 0x1E4550 },
1090 { .start = 0x1E8030, .end = 0x1E8030 },
1091 { .start = 0x1E8510, .end = 0x1E8550 },
1092 { .start = 0x1F0030, .end = 0x1F0030 },
1093 { .start = 0x1F0510, .end = 0x1F0550 },
1094 { .start = 0x1F4030, .end = 0x1F4030 },
1095 { .start = 0x1F4510, .end = 0x1F4550 },
1096 { .start = 0x1F8030, .end = 0x1F8030 },
1097 { .start = 0x1F8510, .end = 0x1F8550 },
1100 static const struct i915_range pvc_shadowed_regs[] = {
1101 { .start = 0x2030, .end = 0x2030 },
1102 { .start = 0x2510, .end = 0x2550 },
1103 { .start = 0xA008, .end = 0xA00C },
1104 { .start = 0xA188, .end = 0xA188 },
1105 { .start = 0xA278, .end = 0xA278 },
1106 { .start = 0xA540, .end = 0xA56C },
1107 { .start = 0xC4C8, .end = 0xC4C8 },
1108 { .start = 0xC4E0, .end = 0xC4E0 },
1109 { .start = 0xC600, .end = 0xC600 },
1110 { .start = 0xC658, .end = 0xC658 },
1111 { .start = 0x22030, .end = 0x22030 },
1112 { .start = 0x22510, .end = 0x22550 },
1113 { .start = 0x1C0030, .end = 0x1C0030 },
1114 { .start = 0x1C0510, .end = 0x1C0550 },
1115 { .start = 0x1C4030, .end = 0x1C4030 },
1116 { .start = 0x1C4510, .end = 0x1C4550 },
1117 { .start = 0x1C8030, .end = 0x1C8030 },
1118 { .start = 0x1C8510, .end = 0x1C8550 },
1119 { .start = 0x1D0030, .end = 0x1D0030 },
1120 { .start = 0x1D0510, .end = 0x1D0550 },
1121 { .start = 0x1D4030, .end = 0x1D4030 },
1122 { .start = 0x1D4510, .end = 0x1D4550 },
1123 { .start = 0x1D8030, .end = 0x1D8030 },
1124 { .start = 0x1D8510, .end = 0x1D8550 },
1125 { .start = 0x1E0030, .end = 0x1E0030 },
1126 { .start = 0x1E0510, .end = 0x1E0550 },
1127 { .start = 0x1E4030, .end = 0x1E4030 },
1128 { .start = 0x1E4510, .end = 0x1E4550 },
1129 { .start = 0x1E8030, .end = 0x1E8030 },
1130 { .start = 0x1E8510, .end = 0x1E8550 },
1131 { .start = 0x1F0030, .end = 0x1F0030 },
1132 { .start = 0x1F0510, .end = 0x1F0550 },
1133 { .start = 0x1F4030, .end = 0x1F4030 },
1134 { .start = 0x1F4510, .end = 0x1F4550 },
1135 { .start = 0x1F8030, .end = 0x1F8030 },
1136 { .start = 0x1F8510, .end = 0x1F8550 },
1139 static const struct i915_range mtl_shadowed_regs[] = {
1140 { .start = 0x2030, .end = 0x2030 },
1141 { .start = 0x2510, .end = 0x2550 },
1142 { .start = 0xA008, .end = 0xA00C },
1143 { .start = 0xA188, .end = 0xA188 },
1144 { .start = 0xA278, .end = 0xA278 },
1145 { .start = 0xA540, .end = 0xA56C },
1146 { .start = 0xC050, .end = 0xC050 },
1147 { .start = 0xC340, .end = 0xC340 },
1148 { .start = 0xC4C8, .end = 0xC4C8 },
1149 { .start = 0xC4E0, .end = 0xC4E0 },
1150 { .start = 0xC600, .end = 0xC600 },
1151 { .start = 0xC658, .end = 0xC658 },
1152 { .start = 0xCFD4, .end = 0xCFDC },
1153 { .start = 0x22030, .end = 0x22030 },
1154 { .start = 0x22510, .end = 0x22550 },
1157 static const struct i915_range xelpmp_shadowed_regs[] = {
1158 { .start = 0x1C0030, .end = 0x1C0030 },
1159 { .start = 0x1C0510, .end = 0x1C0550 },
1160 { .start = 0x1C8030, .end = 0x1C8030 },
1161 { .start = 0x1C8510, .end = 0x1C8550 },
1162 { .start = 0x1D0030, .end = 0x1D0030 },
1163 { .start = 0x1D0510, .end = 0x1D0550 },
1164 { .start = 0x38A008, .end = 0x38A00C },
1165 { .start = 0x38A188, .end = 0x38A188 },
1166 { .start = 0x38A278, .end = 0x38A278 },
1167 { .start = 0x38A540, .end = 0x38A56C },
1168 { .start = 0x38A618, .end = 0x38A618 },
1169 { .start = 0x38C050, .end = 0x38C050 },
1170 { .start = 0x38C340, .end = 0x38C340 },
1171 { .start = 0x38C4C8, .end = 0x38C4C8 },
1172 { .start = 0x38C4E0, .end = 0x38C4E4 },
1173 { .start = 0x38C600, .end = 0x38C600 },
1174 { .start = 0x38C658, .end = 0x38C658 },
1175 { .start = 0x38CFD4, .end = 0x38CFDC },
1178 static int mmio_range_cmp(u32 key, const struct i915_range *range)
1180 if (key < range->start)
1182 else if (key > range->end)
1188 static bool is_shadowed(struct intel_uncore *uncore, u32 offset)
1190 if (drm_WARN_ON(&uncore->i915->drm, !uncore->shadowed_reg_table))
1193 if (IS_GSI_REG(offset))
1194 offset += uncore->gsi_offset;
1196 return BSEARCH(offset,
1197 uncore->shadowed_reg_table,
1198 uncore->shadowed_reg_table_entries,
1202 static enum forcewake_domains
1203 gen6_reg_write_fw_domains(struct intel_uncore *uncore, i915_reg_t reg)
1205 return FORCEWAKE_RENDER;
1208 #define __fwtable_reg_read_fw_domains(uncore, offset) \
1210 enum forcewake_domains __fwd = 0; \
1211 if (NEEDS_FORCE_WAKE((offset))) \
1212 __fwd = find_fw_domain(uncore, offset); \
1216 #define __fwtable_reg_write_fw_domains(uncore, offset) \
1218 enum forcewake_domains __fwd = 0; \
1219 const u32 __offset = (offset); \
1220 if (NEEDS_FORCE_WAKE((__offset)) && !is_shadowed(uncore, __offset)) \
1221 __fwd = find_fw_domain(uncore, __offset); \
1225 #define GEN_FW_RANGE(s, e, d) \
1226 { .start = (s), .end = (e), .domains = (d) }
1229 * All platforms' forcewake tables below must be sorted by offset ranges.
1230 * Furthermore, new forcewake tables added should be "watertight" and have
1231 * no gaps between ranges.
1233 * When there are multiple consecutive ranges listed in the bspec with
1234 * the same forcewake domain, it is customary to combine them into a single
1235 * row in the tables below to keep the tables small and lookups fast.
1236 * Likewise, reserved/unused ranges may be combined with the preceding and/or
1237 * following ranges since the driver will never be making MMIO accesses in
1240 * For example, if the bspec were to list:
1243 * 0x1000 - 0x1fff: GT
1244 * 0x2000 - 0x2cff: GT
1245 * 0x2d00 - 0x2fff: unused/reserved
1246 * 0x3000 - 0xffff: GT
1249 * these could all be represented by a single line in the code:
1251 * GEN_FW_RANGE(0x1000, 0xffff, FORCEWAKE_GT)
1253 * When adding new forcewake tables here, please also add them to
1254 * intel_uncore_mock_selftests in selftests/intel_uncore.c so that they will be
1255 * scanned for obvious mistakes or typos by the selftests.
1258 static const struct intel_forcewake_range __gen6_fw_ranges[] = {
1259 GEN_FW_RANGE(0x0, 0x3ffff, FORCEWAKE_RENDER),
1262 static const struct intel_forcewake_range __vlv_fw_ranges[] = {
1263 GEN_FW_RANGE(0x2000, 0x3fff, FORCEWAKE_RENDER),
1264 GEN_FW_RANGE(0x5000, 0x7fff, FORCEWAKE_RENDER),
1265 GEN_FW_RANGE(0xb000, 0x11fff, FORCEWAKE_RENDER),
1266 GEN_FW_RANGE(0x12000, 0x13fff, FORCEWAKE_MEDIA),
1267 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_MEDIA),
1268 GEN_FW_RANGE(0x2e000, 0x2ffff, FORCEWAKE_RENDER),
1269 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_MEDIA),
1272 static const struct intel_forcewake_range __chv_fw_ranges[] = {
1273 GEN_FW_RANGE(0x2000, 0x3fff, FORCEWAKE_RENDER),
1274 GEN_FW_RANGE(0x4000, 0x4fff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA),
1275 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER),
1276 GEN_FW_RANGE(0x8000, 0x82ff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA),
1277 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER),
1278 GEN_FW_RANGE(0x8500, 0x85ff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA),
1279 GEN_FW_RANGE(0x8800, 0x88ff, FORCEWAKE_MEDIA),
1280 GEN_FW_RANGE(0x9000, 0xafff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA),
1281 GEN_FW_RANGE(0xb000, 0xb47f, FORCEWAKE_RENDER),
1282 GEN_FW_RANGE(0xd000, 0xd7ff, FORCEWAKE_MEDIA),
1283 GEN_FW_RANGE(0xe000, 0xe7ff, FORCEWAKE_RENDER),
1284 GEN_FW_RANGE(0xf000, 0xffff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA),
1285 GEN_FW_RANGE(0x12000, 0x13fff, FORCEWAKE_MEDIA),
1286 GEN_FW_RANGE(0x1a000, 0x1bfff, FORCEWAKE_MEDIA),
1287 GEN_FW_RANGE(0x1e800, 0x1e9ff, FORCEWAKE_MEDIA),
1288 GEN_FW_RANGE(0x30000, 0x37fff, FORCEWAKE_MEDIA),
1291 static const struct intel_forcewake_range __gen9_fw_ranges[] = {
1292 GEN_FW_RANGE(0x0, 0xaff, FORCEWAKE_GT),
1293 GEN_FW_RANGE(0xb00, 0x1fff, 0), /* uncore range */
1294 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER),
1295 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT),
1296 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER),
1297 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT),
1298 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER),
1299 GEN_FW_RANGE(0x8000, 0x812f, FORCEWAKE_GT),
1300 GEN_FW_RANGE(0x8130, 0x813f, FORCEWAKE_MEDIA),
1301 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER),
1302 GEN_FW_RANGE(0x8160, 0x82ff, FORCEWAKE_GT),
1303 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER),
1304 GEN_FW_RANGE(0x8500, 0x87ff, FORCEWAKE_GT),
1305 GEN_FW_RANGE(0x8800, 0x89ff, FORCEWAKE_MEDIA),
1306 GEN_FW_RANGE(0x8a00, 0x8bff, FORCEWAKE_GT),
1307 GEN_FW_RANGE(0x8c00, 0x8cff, FORCEWAKE_RENDER),
1308 GEN_FW_RANGE(0x8d00, 0x93ff, FORCEWAKE_GT),
1309 GEN_FW_RANGE(0x9400, 0x97ff, FORCEWAKE_RENDER | FORCEWAKE_MEDIA),
1310 GEN_FW_RANGE(0x9800, 0xafff, FORCEWAKE_GT),
1311 GEN_FW_RANGE(0xb000, 0xb47f, FORCEWAKE_RENDER),
1312 GEN_FW_RANGE(0xb480, 0xcfff, FORCEWAKE_GT),
1313 GEN_FW_RANGE(0xd000, 0xd7ff, FORCEWAKE_MEDIA),
1314 GEN_FW_RANGE(0xd800, 0xdfff, FORCEWAKE_GT),
1315 GEN_FW_RANGE(0xe000, 0xe8ff, FORCEWAKE_RENDER),
1316 GEN_FW_RANGE(0xe900, 0x11fff, FORCEWAKE_GT),
1317 GEN_FW_RANGE(0x12000, 0x13fff, FORCEWAKE_MEDIA),
1318 GEN_FW_RANGE(0x14000, 0x19fff, FORCEWAKE_GT),
1319 GEN_FW_RANGE(0x1a000, 0x1e9ff, FORCEWAKE_MEDIA),
1320 GEN_FW_RANGE(0x1ea00, 0x243ff, FORCEWAKE_GT),
1321 GEN_FW_RANGE(0x24400, 0x247ff, FORCEWAKE_RENDER),
1322 GEN_FW_RANGE(0x24800, 0x2ffff, FORCEWAKE_GT),
1323 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_MEDIA),
1326 static const struct intel_forcewake_range __gen11_fw_ranges[] = {
1327 GEN_FW_RANGE(0x0, 0x1fff, 0), /* uncore range */
1328 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER),
1329 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT),
1330 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER),
1331 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT),
1332 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER),
1333 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT),
1334 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER),
1335 GEN_FW_RANGE(0x8160, 0x82ff, FORCEWAKE_GT),
1336 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER),
1337 GEN_FW_RANGE(0x8500, 0x87ff, FORCEWAKE_GT),
1338 GEN_FW_RANGE(0x8800, 0x8bff, 0),
1339 GEN_FW_RANGE(0x8c00, 0x8cff, FORCEWAKE_RENDER),
1340 GEN_FW_RANGE(0x8d00, 0x94cf, FORCEWAKE_GT),
1341 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER),
1342 GEN_FW_RANGE(0x9560, 0x95ff, 0),
1343 GEN_FW_RANGE(0x9600, 0xafff, FORCEWAKE_GT),
1344 GEN_FW_RANGE(0xb000, 0xb47f, FORCEWAKE_RENDER),
1345 GEN_FW_RANGE(0xb480, 0xdeff, FORCEWAKE_GT),
1346 GEN_FW_RANGE(0xdf00, 0xe8ff, FORCEWAKE_RENDER),
1347 GEN_FW_RANGE(0xe900, 0x16dff, FORCEWAKE_GT),
1348 GEN_FW_RANGE(0x16e00, 0x19fff, FORCEWAKE_RENDER),
1349 GEN_FW_RANGE(0x1a000, 0x23fff, FORCEWAKE_GT),
1350 GEN_FW_RANGE(0x24000, 0x2407f, 0),
1351 GEN_FW_RANGE(0x24080, 0x2417f, FORCEWAKE_GT),
1352 GEN_FW_RANGE(0x24180, 0x242ff, FORCEWAKE_RENDER),
1353 GEN_FW_RANGE(0x24300, 0x243ff, FORCEWAKE_GT),
1354 GEN_FW_RANGE(0x24400, 0x24fff, FORCEWAKE_RENDER),
1355 GEN_FW_RANGE(0x25000, 0x3ffff, FORCEWAKE_GT),
1356 GEN_FW_RANGE(0x40000, 0x1bffff, 0),
1357 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0),
1358 GEN_FW_RANGE(0x1c4000, 0x1c7fff, 0),
1359 GEN_FW_RANGE(0x1c8000, 0x1cffff, FORCEWAKE_MEDIA_VEBOX0),
1360 GEN_FW_RANGE(0x1d0000, 0x1d3fff, FORCEWAKE_MEDIA_VDBOX2),
1361 GEN_FW_RANGE(0x1d4000, 0x1dbfff, 0)
1364 static const struct intel_forcewake_range __gen12_fw_ranges[] = {
1365 GEN_FW_RANGE(0x0, 0x1fff, 0), /*
1366 0x0 - 0xaff: reserved
1367 0xb00 - 0x1fff: always on */
1368 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER),
1369 GEN_FW_RANGE(0x2700, 0x27ff, FORCEWAKE_GT),
1370 GEN_FW_RANGE(0x2800, 0x2aff, FORCEWAKE_RENDER),
1371 GEN_FW_RANGE(0x2b00, 0x2fff, FORCEWAKE_GT),
1372 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER),
1373 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT), /*
1375 0x4900 - 0x51ff: reserved */
1376 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), /*
1377 0x5200 - 0x53ff: render
1378 0x5400 - 0x54ff: reserved
1379 0x5500 - 0x7fff: render */
1380 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT),
1381 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER),
1382 GEN_FW_RANGE(0x8160, 0x81ff, 0), /*
1383 0x8160 - 0x817f: reserved
1384 0x8180 - 0x81ff: always on */
1385 GEN_FW_RANGE(0x8200, 0x82ff, FORCEWAKE_GT),
1386 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER),
1387 GEN_FW_RANGE(0x8500, 0x94cf, FORCEWAKE_GT), /*
1389 0x8800 - 0x8fff: reserved
1391 0x9480 - 0x94cf: reserved */
1392 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER),
1393 GEN_FW_RANGE(0x9560, 0x97ff, 0), /*
1394 0x9560 - 0x95ff: always on
1395 0x9600 - 0x97ff: reserved */
1396 GEN_FW_RANGE(0x9800, 0xafff, FORCEWAKE_GT),
1397 GEN_FW_RANGE(0xb000, 0xb3ff, FORCEWAKE_RENDER),
1398 GEN_FW_RANGE(0xb400, 0xcfff, FORCEWAKE_GT), /*
1400 0xb480 - 0xbfff: reserved
1401 0xc000 - 0xcfff: gt */
1402 GEN_FW_RANGE(0xd000, 0xd7ff, 0),
1403 GEN_FW_RANGE(0xd800, 0xd8ff, FORCEWAKE_RENDER),
1404 GEN_FW_RANGE(0xd900, 0xdbff, FORCEWAKE_GT),
1405 GEN_FW_RANGE(0xdc00, 0xefff, FORCEWAKE_RENDER), /*
1406 0xdc00 - 0xddff: render
1407 0xde00 - 0xde7f: reserved
1408 0xde80 - 0xe8ff: render
1409 0xe900 - 0xefff: reserved */
1410 GEN_FW_RANGE(0xf000, 0x147ff, FORCEWAKE_GT), /*
1412 0x10000 - 0x147ff: reserved */
1413 GEN_FW_RANGE(0x14800, 0x1ffff, FORCEWAKE_RENDER), /*
1414 0x14800 - 0x14fff: render
1415 0x15000 - 0x16dff: reserved
1416 0x16e00 - 0x1bfff: render
1417 0x1c000 - 0x1ffff: reserved */
1418 GEN_FW_RANGE(0x20000, 0x20fff, FORCEWAKE_MEDIA_VDBOX0),
1419 GEN_FW_RANGE(0x21000, 0x21fff, FORCEWAKE_MEDIA_VDBOX2),
1420 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT),
1421 GEN_FW_RANGE(0x24000, 0x2417f, 0), /*
1422 0x24000 - 0x2407f: always on
1423 0x24080 - 0x2417f: reserved */
1424 GEN_FW_RANGE(0x24180, 0x249ff, FORCEWAKE_GT), /*
1425 0x24180 - 0x241ff: gt
1426 0x24200 - 0x249ff: reserved */
1427 GEN_FW_RANGE(0x24a00, 0x251ff, FORCEWAKE_RENDER), /*
1428 0x24a00 - 0x24a7f: render
1429 0x24a80 - 0x251ff: reserved */
1430 GEN_FW_RANGE(0x25200, 0x255ff, FORCEWAKE_GT), /*
1431 0x25200 - 0x252ff: gt
1432 0x25300 - 0x255ff: reserved */
1433 GEN_FW_RANGE(0x25600, 0x2567f, FORCEWAKE_MEDIA_VDBOX0),
1434 GEN_FW_RANGE(0x25680, 0x259ff, FORCEWAKE_MEDIA_VDBOX2), /*
1435 0x25680 - 0x256ff: VD2
1436 0x25700 - 0x259ff: reserved */
1437 GEN_FW_RANGE(0x25a00, 0x25a7f, FORCEWAKE_MEDIA_VDBOX0),
1438 GEN_FW_RANGE(0x25a80, 0x2ffff, FORCEWAKE_MEDIA_VDBOX2), /*
1439 0x25a80 - 0x25aff: VD2
1440 0x25b00 - 0x2ffff: reserved */
1441 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT),
1442 GEN_FW_RANGE(0x40000, 0x1bffff, 0),
1443 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0), /*
1444 0x1c0000 - 0x1c2bff: VD0
1445 0x1c2c00 - 0x1c2cff: reserved
1446 0x1c2d00 - 0x1c2dff: VD0
1447 0x1c2e00 - 0x1c3eff: reserved
1448 0x1c3f00 - 0x1c3fff: VD0 */
1449 GEN_FW_RANGE(0x1c4000, 0x1c7fff, 0),
1450 GEN_FW_RANGE(0x1c8000, 0x1cbfff, FORCEWAKE_MEDIA_VEBOX0), /*
1451 0x1c8000 - 0x1ca0ff: VE0
1452 0x1ca100 - 0x1cbeff: reserved
1453 0x1cbf00 - 0x1cbfff: VE0 */
1454 GEN_FW_RANGE(0x1cc000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX0), /*
1455 0x1cc000 - 0x1ccfff: VD0
1456 0x1cd000 - 0x1cffff: reserved */
1457 GEN_FW_RANGE(0x1d0000, 0x1d3fff, FORCEWAKE_MEDIA_VDBOX2), /*
1458 0x1d0000 - 0x1d2bff: VD2
1459 0x1d2c00 - 0x1d2cff: reserved
1460 0x1d2d00 - 0x1d2dff: VD2
1461 0x1d2e00 - 0x1d3eff: reserved
1462 0x1d3f00 - 0x1d3fff: VD2 */
1466 * Graphics IP version 12.55 brings a slight change to the 0xd800 range,
1467 * switching it from the GT domain to the render domain.
1469 #define XEHP_FWRANGES(FW_RANGE_D800) \
1470 GEN_FW_RANGE(0x0, 0x1fff, 0), /* \
1471 0x0 - 0xaff: reserved \
1472 0xb00 - 0x1fff: always on */ \
1473 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER), \
1474 GEN_FW_RANGE(0x2700, 0x4aff, FORCEWAKE_GT), \
1475 GEN_FW_RANGE(0x4b00, 0x51ff, 0), /* \
1476 0x4b00 - 0x4fff: reserved \
1477 0x5000 - 0x51ff: always on */ \
1478 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), \
1479 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT), \
1480 GEN_FW_RANGE(0x8140, 0x815f, FORCEWAKE_RENDER), \
1481 GEN_FW_RANGE(0x8160, 0x81ff, 0), /* \
1482 0x8160 - 0x817f: reserved \
1483 0x8180 - 0x81ff: always on */ \
1484 GEN_FW_RANGE(0x8200, 0x82ff, FORCEWAKE_GT), \
1485 GEN_FW_RANGE(0x8300, 0x84ff, FORCEWAKE_RENDER), \
1486 GEN_FW_RANGE(0x8500, 0x8cff, FORCEWAKE_GT), /* \
1487 0x8500 - 0x87ff: gt \
1488 0x8800 - 0x8c7f: reserved \
1489 0x8c80 - 0x8cff: gt (DG2 only) */ \
1490 GEN_FW_RANGE(0x8d00, 0x8fff, FORCEWAKE_RENDER), /* \
1491 0x8d00 - 0x8dff: render (DG2 only) \
1492 0x8e00 - 0x8fff: reserved */ \
1493 GEN_FW_RANGE(0x9000, 0x94cf, FORCEWAKE_GT), /* \
1494 0x9000 - 0x947f: gt \
1495 0x9480 - 0x94cf: reserved */ \
1496 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER), \
1497 GEN_FW_RANGE(0x9560, 0x967f, 0), /* \
1498 0x9560 - 0x95ff: always on \
1499 0x9600 - 0x967f: reserved */ \
1500 GEN_FW_RANGE(0x9680, 0x97ff, FORCEWAKE_RENDER), /* \
1501 0x9680 - 0x96ff: render (DG2 only) \
1502 0x9700 - 0x97ff: reserved */ \
1503 GEN_FW_RANGE(0x9800, 0xcfff, FORCEWAKE_GT), /* \
1504 0x9800 - 0xb4ff: gt \
1505 0xb500 - 0xbfff: reserved \
1506 0xc000 - 0xcfff: gt */ \
1507 GEN_FW_RANGE(0xd000, 0xd7ff, 0), \
1508 GEN_FW_RANGE(0xd800, 0xd87f, FW_RANGE_D800), \
1509 GEN_FW_RANGE(0xd880, 0xdbff, FORCEWAKE_GT), \
1510 GEN_FW_RANGE(0xdc00, 0xdcff, FORCEWAKE_RENDER), \
1511 GEN_FW_RANGE(0xdd00, 0xde7f, FORCEWAKE_GT), /* \
1512 0xdd00 - 0xddff: gt \
1513 0xde00 - 0xde7f: reserved */ \
1514 GEN_FW_RANGE(0xde80, 0xe8ff, FORCEWAKE_RENDER), /* \
1515 0xde80 - 0xdfff: render \
1516 0xe000 - 0xe0ff: reserved \
1517 0xe100 - 0xe8ff: render */ \
1518 GEN_FW_RANGE(0xe900, 0xffff, FORCEWAKE_GT), /* \
1519 0xe900 - 0xe9ff: gt \
1520 0xea00 - 0xefff: reserved \
1521 0xf000 - 0xffff: gt */ \
1522 GEN_FW_RANGE(0x10000, 0x12fff, 0), /* \
1523 0x10000 - 0x11fff: reserved \
1524 0x12000 - 0x127ff: always on \
1525 0x12800 - 0x12fff: reserved */ \
1526 GEN_FW_RANGE(0x13000, 0x131ff, FORCEWAKE_MEDIA_VDBOX0), /* DG2 only */ \
1527 GEN_FW_RANGE(0x13200, 0x13fff, FORCEWAKE_MEDIA_VDBOX2), /* \
1528 0x13200 - 0x133ff: VD2 (DG2 only) \
1529 0x13400 - 0x13fff: reserved */ \
1530 GEN_FW_RANGE(0x14000, 0x141ff, FORCEWAKE_MEDIA_VDBOX0), /* XEHPSDV only */ \
1531 GEN_FW_RANGE(0x14200, 0x143ff, FORCEWAKE_MEDIA_VDBOX2), /* XEHPSDV only */ \
1532 GEN_FW_RANGE(0x14400, 0x145ff, FORCEWAKE_MEDIA_VDBOX4), /* XEHPSDV only */ \
1533 GEN_FW_RANGE(0x14600, 0x147ff, FORCEWAKE_MEDIA_VDBOX6), /* XEHPSDV only */ \
1534 GEN_FW_RANGE(0x14800, 0x14fff, FORCEWAKE_RENDER), \
1535 GEN_FW_RANGE(0x15000, 0x16dff, FORCEWAKE_GT), /* \
1536 0x15000 - 0x15fff: gt (DG2 only) \
1537 0x16000 - 0x16dff: reserved */ \
1538 GEN_FW_RANGE(0x16e00, 0x1ffff, FORCEWAKE_RENDER), \
1539 GEN_FW_RANGE(0x20000, 0x21fff, FORCEWAKE_MEDIA_VDBOX0), /* \
1540 0x20000 - 0x20fff: VD0 (XEHPSDV only) \
1541 0x21000 - 0x21fff: reserved */ \
1542 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT), \
1543 GEN_FW_RANGE(0x24000, 0x2417f, 0), /* \
1544 0x24000 - 0x2407f: always on \
1545 0x24080 - 0x2417f: reserved */ \
1546 GEN_FW_RANGE(0x24180, 0x249ff, FORCEWAKE_GT), /* \
1547 0x24180 - 0x241ff: gt \
1548 0x24200 - 0x249ff: reserved */ \
1549 GEN_FW_RANGE(0x24a00, 0x251ff, FORCEWAKE_RENDER), /* \
1550 0x24a00 - 0x24a7f: render \
1551 0x24a80 - 0x251ff: reserved */ \
1552 GEN_FW_RANGE(0x25200, 0x25fff, FORCEWAKE_GT), /* \
1553 0x25200 - 0x252ff: gt \
1554 0x25300 - 0x25fff: reserved */ \
1555 GEN_FW_RANGE(0x26000, 0x2ffff, FORCEWAKE_RENDER), /* \
1556 0x26000 - 0x27fff: render \
1557 0x28000 - 0x29fff: reserved \
1558 0x2a000 - 0x2ffff: undocumented */ \
1559 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT), \
1560 GEN_FW_RANGE(0x40000, 0x1bffff, 0), \
1561 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0), /* \
1562 0x1c0000 - 0x1c2bff: VD0 \
1563 0x1c2c00 - 0x1c2cff: reserved \
1564 0x1c2d00 - 0x1c2dff: VD0 \
1565 0x1c2e00 - 0x1c3eff: VD0 (DG2 only) \
1566 0x1c3f00 - 0x1c3fff: VD0 */ \
1567 GEN_FW_RANGE(0x1c4000, 0x1c7fff, FORCEWAKE_MEDIA_VDBOX1), /* \
1568 0x1c4000 - 0x1c6bff: VD1 \
1569 0x1c6c00 - 0x1c6cff: reserved \
1570 0x1c6d00 - 0x1c6dff: VD1 \
1571 0x1c6e00 - 0x1c7fff: reserved */ \
1572 GEN_FW_RANGE(0x1c8000, 0x1cbfff, FORCEWAKE_MEDIA_VEBOX0), /* \
1573 0x1c8000 - 0x1ca0ff: VE0 \
1574 0x1ca100 - 0x1cbfff: reserved */ \
1575 GEN_FW_RANGE(0x1cc000, 0x1ccfff, FORCEWAKE_MEDIA_VDBOX0), \
1576 GEN_FW_RANGE(0x1cd000, 0x1cdfff, FORCEWAKE_MEDIA_VDBOX2), \
1577 GEN_FW_RANGE(0x1ce000, 0x1cefff, FORCEWAKE_MEDIA_VDBOX4), \
1578 GEN_FW_RANGE(0x1cf000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX6), \
1579 GEN_FW_RANGE(0x1d0000, 0x1d3fff, FORCEWAKE_MEDIA_VDBOX2), /* \
1580 0x1d0000 - 0x1d2bff: VD2 \
1581 0x1d2c00 - 0x1d2cff: reserved \
1582 0x1d2d00 - 0x1d2dff: VD2 \
1583 0x1d2e00 - 0x1d3dff: VD2 (DG2 only) \
1584 0x1d3e00 - 0x1d3eff: reserved \
1585 0x1d3f00 - 0x1d3fff: VD2 */ \
1586 GEN_FW_RANGE(0x1d4000, 0x1d7fff, FORCEWAKE_MEDIA_VDBOX3), /* \
1587 0x1d4000 - 0x1d6bff: VD3 \
1588 0x1d6c00 - 0x1d6cff: reserved \
1589 0x1d6d00 - 0x1d6dff: VD3 \
1590 0x1d6e00 - 0x1d7fff: reserved */ \
1591 GEN_FW_RANGE(0x1d8000, 0x1dffff, FORCEWAKE_MEDIA_VEBOX1), /* \
1592 0x1d8000 - 0x1da0ff: VE1 \
1593 0x1da100 - 0x1dffff: reserved */ \
1594 GEN_FW_RANGE(0x1e0000, 0x1e3fff, FORCEWAKE_MEDIA_VDBOX4), /* \
1595 0x1e0000 - 0x1e2bff: VD4 \
1596 0x1e2c00 - 0x1e2cff: reserved \
1597 0x1e2d00 - 0x1e2dff: VD4 \
1598 0x1e2e00 - 0x1e3eff: reserved \
1599 0x1e3f00 - 0x1e3fff: VD4 */ \
1600 GEN_FW_RANGE(0x1e4000, 0x1e7fff, FORCEWAKE_MEDIA_VDBOX5), /* \
1601 0x1e4000 - 0x1e6bff: VD5 \
1602 0x1e6c00 - 0x1e6cff: reserved \
1603 0x1e6d00 - 0x1e6dff: VD5 \
1604 0x1e6e00 - 0x1e7fff: reserved */ \
1605 GEN_FW_RANGE(0x1e8000, 0x1effff, FORCEWAKE_MEDIA_VEBOX2), /* \
1606 0x1e8000 - 0x1ea0ff: VE2 \
1607 0x1ea100 - 0x1effff: reserved */ \
1608 GEN_FW_RANGE(0x1f0000, 0x1f3fff, FORCEWAKE_MEDIA_VDBOX6), /* \
1609 0x1f0000 - 0x1f2bff: VD6 \
1610 0x1f2c00 - 0x1f2cff: reserved \
1611 0x1f2d00 - 0x1f2dff: VD6 \
1612 0x1f2e00 - 0x1f3eff: reserved \
1613 0x1f3f00 - 0x1f3fff: VD6 */ \
1614 GEN_FW_RANGE(0x1f4000, 0x1f7fff, FORCEWAKE_MEDIA_VDBOX7), /* \
1615 0x1f4000 - 0x1f6bff: VD7 \
1616 0x1f6c00 - 0x1f6cff: reserved \
1617 0x1f6d00 - 0x1f6dff: VD7 \
1618 0x1f6e00 - 0x1f7fff: reserved */ \
1619 GEN_FW_RANGE(0x1f8000, 0x1fa0ff, FORCEWAKE_MEDIA_VEBOX3),
1621 static const struct intel_forcewake_range __xehp_fw_ranges[] = {
1622 XEHP_FWRANGES(FORCEWAKE_GT)
1625 static const struct intel_forcewake_range __dg2_fw_ranges[] = {
1626 XEHP_FWRANGES(FORCEWAKE_RENDER)
1629 static const struct intel_forcewake_range __pvc_fw_ranges[] = {
1630 GEN_FW_RANGE(0x0, 0xaff, 0),
1631 GEN_FW_RANGE(0xb00, 0xbff, FORCEWAKE_GT),
1632 GEN_FW_RANGE(0xc00, 0xfff, 0),
1633 GEN_FW_RANGE(0x1000, 0x1fff, FORCEWAKE_GT),
1634 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER),
1635 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT),
1636 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER),
1637 GEN_FW_RANGE(0x4000, 0x813f, FORCEWAKE_GT), /*
1639 0x4b00 - 0x4fff: reserved
1641 0x5200 - 0x52ff: reserved
1643 0x5400 - 0x7fff: reserved
1644 0x8000 - 0x813f: gt */
1645 GEN_FW_RANGE(0x8140, 0x817f, FORCEWAKE_RENDER),
1646 GEN_FW_RANGE(0x8180, 0x81ff, 0),
1647 GEN_FW_RANGE(0x8200, 0x94cf, FORCEWAKE_GT), /*
1649 0x8300 - 0x84ff: reserved
1651 0x8880 - 0x8a7f: reserved
1653 0x8b00 - 0x8fff: reserved
1655 0x9480 - 0x94cf: reserved */
1656 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER),
1657 GEN_FW_RANGE(0x9560, 0x967f, 0), /*
1658 0x9560 - 0x95ff: always on
1659 0x9600 - 0x967f: reserved */
1660 GEN_FW_RANGE(0x9680, 0x97ff, FORCEWAKE_RENDER), /*
1661 0x9680 - 0x96ff: render
1662 0x9700 - 0x97ff: reserved */
1663 GEN_FW_RANGE(0x9800, 0xcfff, FORCEWAKE_GT), /*
1665 0xb500 - 0xbfff: reserved
1666 0xc000 - 0xcfff: gt */
1667 GEN_FW_RANGE(0xd000, 0xd3ff, 0),
1668 GEN_FW_RANGE(0xd400, 0xdbff, FORCEWAKE_GT),
1669 GEN_FW_RANGE(0xdc00, 0xdcff, FORCEWAKE_RENDER),
1670 GEN_FW_RANGE(0xdd00, 0xde7f, FORCEWAKE_GT), /*
1672 0xde00 - 0xde7f: reserved */
1673 GEN_FW_RANGE(0xde80, 0xe8ff, FORCEWAKE_RENDER), /*
1674 0xde80 - 0xdeff: render
1675 0xdf00 - 0xe1ff: reserved
1676 0xe200 - 0xe7ff: render
1677 0xe800 - 0xe8ff: reserved */
1678 GEN_FW_RANGE(0xe900, 0x11fff, FORCEWAKE_GT), /*
1680 0xea00 - 0xebff: reserved
1682 0x10000 - 0x11fff: reserved */
1683 GEN_FW_RANGE(0x12000, 0x12fff, 0), /*
1684 0x12000 - 0x127ff: always on
1685 0x12800 - 0x12fff: reserved */
1686 GEN_FW_RANGE(0x13000, 0x19fff, FORCEWAKE_GT), /*
1687 0x13000 - 0x135ff: gt
1688 0x13600 - 0x147ff: reserved
1689 0x14800 - 0x153ff: gt
1690 0x15400 - 0x19fff: reserved */
1691 GEN_FW_RANGE(0x1a000, 0x21fff, FORCEWAKE_RENDER), /*
1692 0x1a000 - 0x1ffff: render
1693 0x20000 - 0x21fff: reserved */
1694 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT),
1695 GEN_FW_RANGE(0x24000, 0x2417f, 0), /*
1696 24000 - 0x2407f: always on
1697 24080 - 0x2417f: reserved */
1698 GEN_FW_RANGE(0x24180, 0x25fff, FORCEWAKE_GT), /*
1699 0x24180 - 0x241ff: gt
1700 0x24200 - 0x251ff: reserved
1701 0x25200 - 0x252ff: gt
1702 0x25300 - 0x25fff: reserved */
1703 GEN_FW_RANGE(0x26000, 0x2ffff, FORCEWAKE_RENDER), /*
1704 0x26000 - 0x27fff: render
1705 0x28000 - 0x2ffff: reserved */
1706 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT),
1707 GEN_FW_RANGE(0x40000, 0x1bffff, 0),
1708 GEN_FW_RANGE(0x1c0000, 0x1c3fff, FORCEWAKE_MEDIA_VDBOX0), /*
1709 0x1c0000 - 0x1c2bff: VD0
1710 0x1c2c00 - 0x1c2cff: reserved
1711 0x1c2d00 - 0x1c2dff: VD0
1712 0x1c2e00 - 0x1c3eff: reserved
1713 0x1c3f00 - 0x1c3fff: VD0 */
1714 GEN_FW_RANGE(0x1c4000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX1), /*
1715 0x1c4000 - 0x1c6aff: VD1
1716 0x1c6b00 - 0x1c7eff: reserved
1717 0x1c7f00 - 0x1c7fff: VD1
1718 0x1c8000 - 0x1cffff: reserved */
1719 GEN_FW_RANGE(0x1d0000, 0x23ffff, FORCEWAKE_MEDIA_VDBOX2), /*
1720 0x1d0000 - 0x1d2aff: VD2
1721 0x1d2b00 - 0x1d3eff: reserved
1722 0x1d3f00 - 0x1d3fff: VD2
1723 0x1d4000 - 0x23ffff: reserved */
1724 GEN_FW_RANGE(0x240000, 0x3dffff, 0),
1725 GEN_FW_RANGE(0x3e0000, 0x3effff, FORCEWAKE_GT),
1728 static const struct intel_forcewake_range __mtl_fw_ranges[] = {
1729 GEN_FW_RANGE(0x0, 0xaff, 0),
1730 GEN_FW_RANGE(0xb00, 0xbff, FORCEWAKE_GT),
1731 GEN_FW_RANGE(0xc00, 0xfff, 0),
1732 GEN_FW_RANGE(0x1000, 0x1fff, FORCEWAKE_GT),
1733 GEN_FW_RANGE(0x2000, 0x26ff, FORCEWAKE_RENDER),
1734 GEN_FW_RANGE(0x2700, 0x2fff, FORCEWAKE_GT),
1735 GEN_FW_RANGE(0x3000, 0x3fff, FORCEWAKE_RENDER),
1736 GEN_FW_RANGE(0x4000, 0x51ff, FORCEWAKE_GT), /*
1737 0x4000 - 0x48ff: render
1738 0x4900 - 0x51ff: reserved */
1739 GEN_FW_RANGE(0x5200, 0x7fff, FORCEWAKE_RENDER), /*
1740 0x5200 - 0x53ff: render
1741 0x5400 - 0x54ff: reserved
1742 0x5500 - 0x7fff: render */
1743 GEN_FW_RANGE(0x8000, 0x813f, FORCEWAKE_GT),
1744 GEN_FW_RANGE(0x8140, 0x817f, FORCEWAKE_RENDER), /*
1745 0x8140 - 0x815f: render
1746 0x8160 - 0x817f: reserved */
1747 GEN_FW_RANGE(0x8180, 0x81ff, 0),
1748 GEN_FW_RANGE(0x8200, 0x94cf, FORCEWAKE_GT), /*
1750 0x8800 - 0x8dff: reserved
1752 0x8f80 - 0x8fff: reserved
1754 0x9480 - 0x94cf: reserved */
1755 GEN_FW_RANGE(0x94d0, 0x955f, FORCEWAKE_RENDER),
1756 GEN_FW_RANGE(0x9560, 0x967f, 0), /*
1757 0x9560 - 0x95ff: always on
1758 0x9600 - 0x967f: reserved */
1759 GEN_FW_RANGE(0x9680, 0x97ff, FORCEWAKE_RENDER), /*
1760 0x9680 - 0x96ff: render
1761 0x9700 - 0x97ff: reserved */
1762 GEN_FW_RANGE(0x9800, 0xcfff, FORCEWAKE_GT), /*
1764 0xb500 - 0xbfff: reserved
1765 0xc000 - 0xcfff: gt */
1766 GEN_FW_RANGE(0xd000, 0xd7ff, 0), /*
1767 0xd000 - 0xd3ff: always on
1768 0xd400 - 0xd7ff: reserved */
1769 GEN_FW_RANGE(0xd800, 0xd87f, FORCEWAKE_RENDER),
1770 GEN_FW_RANGE(0xd880, 0xdbff, FORCEWAKE_GT),
1771 GEN_FW_RANGE(0xdc00, 0xdcff, FORCEWAKE_RENDER),
1772 GEN_FW_RANGE(0xdd00, 0xde7f, FORCEWAKE_GT), /*
1774 0xde00 - 0xde7f: reserved */
1775 GEN_FW_RANGE(0xde80, 0xe8ff, FORCEWAKE_RENDER), /*
1776 0xde80 - 0xdfff: render
1777 0xe000 - 0xe0ff: reserved
1778 0xe100 - 0xe8ff: render */
1779 GEN_FW_RANGE(0xe900, 0xe9ff, FORCEWAKE_GT),
1780 GEN_FW_RANGE(0xea00, 0x147ff, 0), /*
1781 0xea00 - 0x11fff: reserved
1782 0x12000 - 0x127ff: always on
1783 0x12800 - 0x147ff: reserved */
1784 GEN_FW_RANGE(0x14800, 0x19fff, FORCEWAKE_GT), /*
1785 0x14800 - 0x153ff: gt
1786 0x15400 - 0x19fff: reserved */
1787 GEN_FW_RANGE(0x1a000, 0x21fff, FORCEWAKE_RENDER), /*
1788 0x1a000 - 0x1bfff: render
1789 0x1c000 - 0x21fff: reserved */
1790 GEN_FW_RANGE(0x22000, 0x23fff, FORCEWAKE_GT),
1791 GEN_FW_RANGE(0x24000, 0x2ffff, 0), /*
1792 0x24000 - 0x2407f: always on
1793 0x24080 - 0x2ffff: reserved */
1794 GEN_FW_RANGE(0x30000, 0x3ffff, FORCEWAKE_GT)
1798 * Note that the register ranges here are the final offsets after
1799 * translation of the GSI block to the 0x380000 offset.
1801 * NOTE: There are a couple MCR ranges near the bottom of this table
1802 * that need to power up either VD0 or VD2 depending on which replicated
1803 * instance of the register we're trying to access. Our forcewake logic
1804 * at the moment doesn't have a good way to take steering into consideration,
1805 * and the driver doesn't even access any registers in those ranges today,
1806 * so for now we just mark those ranges as FORCEWAKE_ALL. That will ensure
1807 * proper operation if we do start using the ranges in the future, and we
1808 * can determine at that time whether it's worth adding extra complexity to
1809 * the forcewake handling to take steering into consideration.
1811 static const struct intel_forcewake_range __xelpmp_fw_ranges[] = {
1812 GEN_FW_RANGE(0x0, 0x115fff, 0), /* render GT range */
1813 GEN_FW_RANGE(0x116000, 0x11ffff, FORCEWAKE_GSC), /*
1814 0x116000 - 0x117fff: gsc
1815 0x118000 - 0x119fff: reserved
1816 0x11a000 - 0x11efff: gsc
1817 0x11f000 - 0x11ffff: reserved */
1818 GEN_FW_RANGE(0x120000, 0x1bffff, 0), /* non-GT range */
1819 GEN_FW_RANGE(0x1c0000, 0x1c7fff, FORCEWAKE_MEDIA_VDBOX0), /*
1820 0x1c0000 - 0x1c3dff: VD0
1821 0x1c3e00 - 0x1c3eff: reserved
1822 0x1c3f00 - 0x1c3fff: VD0
1823 0x1c4000 - 0x1c7fff: reserved */
1824 GEN_FW_RANGE(0x1c8000, 0x1cbfff, FORCEWAKE_MEDIA_VEBOX0), /*
1825 0x1c8000 - 0x1ca0ff: VE0
1826 0x1ca100 - 0x1cbfff: reserved */
1827 GEN_FW_RANGE(0x1cc000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX0), /*
1828 0x1cc000 - 0x1cdfff: VD0
1829 0x1ce000 - 0x1cffff: reserved */
1830 GEN_FW_RANGE(0x1d0000, 0x1d7fff, FORCEWAKE_MEDIA_VDBOX2), /*
1831 0x1d0000 - 0x1d3dff: VD2
1832 0x1d3e00 - 0x1d3eff: reserved
1833 0x1d4000 - 0x1d7fff: VD2 */
1834 GEN_FW_RANGE(0x1d8000, 0x1da0ff, FORCEWAKE_MEDIA_VEBOX1),
1835 GEN_FW_RANGE(0x1da100, 0x380aff, 0), /*
1836 0x1da100 - 0x23ffff: reserved
1837 0x240000 - 0x37ffff: non-GT range
1838 0x380000 - 0x380aff: reserved */
1839 GEN_FW_RANGE(0x380b00, 0x380bff, FORCEWAKE_GT),
1840 GEN_FW_RANGE(0x380c00, 0x380fff, 0),
1841 GEN_FW_RANGE(0x381000, 0x38817f, FORCEWAKE_GT), /*
1842 0x381000 - 0x381fff: gt
1843 0x382000 - 0x383fff: reserved
1844 0x384000 - 0x384aff: gt
1845 0x384b00 - 0x3851ff: reserved
1846 0x385200 - 0x3871ff: gt
1847 0x387200 - 0x387fff: reserved
1848 0x388000 - 0x38813f: gt
1849 0x388140 - 0x38817f: reserved */
1850 GEN_FW_RANGE(0x388180, 0x3882ff, 0), /*
1851 0x388180 - 0x3881ff: always on
1852 0x388200 - 0x3882ff: reserved */
1853 GEN_FW_RANGE(0x388300, 0x38955f, FORCEWAKE_GT), /*
1854 0x388300 - 0x38887f: gt
1855 0x388880 - 0x388fff: reserved
1856 0x389000 - 0x38947f: gt
1857 0x389480 - 0x38955f: reserved */
1858 GEN_FW_RANGE(0x389560, 0x389fff, 0), /*
1859 0x389560 - 0x3895ff: always on
1860 0x389600 - 0x389fff: reserved */
1861 GEN_FW_RANGE(0x38a000, 0x38cfff, FORCEWAKE_GT), /*
1862 0x38a000 - 0x38afff: gt
1863 0x38b000 - 0x38bfff: reserved
1864 0x38c000 - 0x38cfff: gt */
1865 GEN_FW_RANGE(0x38d000, 0x38d11f, 0),
1866 GEN_FW_RANGE(0x38d120, 0x391fff, FORCEWAKE_GT), /*
1867 0x38d120 - 0x38dfff: gt
1868 0x38e000 - 0x38efff: reserved
1869 0x38f000 - 0x38ffff: gt
1870 0x389000 - 0x391fff: reserved */
1871 GEN_FW_RANGE(0x392000, 0x392fff, 0), /*
1872 0x392000 - 0x3927ff: always on
1873 0x392800 - 0x292fff: reserved */
1874 GEN_FW_RANGE(0x393000, 0x3931ff, FORCEWAKE_GT),
1875 GEN_FW_RANGE(0x393200, 0x39323f, FORCEWAKE_ALL), /* instance-based, see note above */
1876 GEN_FW_RANGE(0x393240, 0x3933ff, FORCEWAKE_GT),
1877 GEN_FW_RANGE(0x393400, 0x3934ff, FORCEWAKE_ALL), /* instance-based, see note above */
1878 GEN_FW_RANGE(0x393500, 0x393c7f, 0), /*
1879 0x393500 - 0x393bff: reserved
1880 0x393c00 - 0x393c7f: always on */
1881 GEN_FW_RANGE(0x393c80, 0x393dff, FORCEWAKE_GT),
1885 ilk_dummy_write(struct intel_uncore *uncore)
1887 /* WaIssueDummyWriteToWakeupFromRC6:ilk Issue a dummy write to wake up
1888 * the chip from rc6 before touching it for real. MI_MODE is masked,
1889 * hence harmless to write 0 into. */
1890 __raw_uncore_write32(uncore, RING_MI_MODE(RENDER_RING_BASE), 0);
1894 __unclaimed_reg_debug(struct intel_uncore *uncore,
1895 const i915_reg_t reg,
1898 if (drm_WARN(&uncore->i915->drm,
1899 check_for_unclaimed_mmio(uncore),
1900 "Unclaimed %s register 0x%x\n",
1901 read ? "read from" : "write to",
1902 i915_mmio_reg_offset(reg)))
1903 /* Only report the first N failures */
1904 uncore->i915->params.mmio_debug--;
1908 __unclaimed_previous_reg_debug(struct intel_uncore *uncore,
1909 const i915_reg_t reg,
1912 if (check_for_unclaimed_mmio(uncore))
1913 drm_dbg(&uncore->i915->drm,
1914 "Unclaimed access detected before %s register 0x%x\n",
1915 read ? "read from" : "write to",
1916 i915_mmio_reg_offset(reg));
1920 unclaimed_reg_debug(struct intel_uncore *uncore,
1921 const i915_reg_t reg,
1925 if (likely(!uncore->i915->params.mmio_debug) || !uncore->debug)
1928 /* interrupts are disabled and re-enabled around uncore->lock usage */
1929 lockdep_assert_held(&uncore->lock);
1932 spin_lock(&uncore->debug->lock);
1933 __unclaimed_previous_reg_debug(uncore, reg, read);
1935 __unclaimed_reg_debug(uncore, reg, read);
1936 spin_unlock(&uncore->debug->lock);
1940 #define __vgpu_read(x) \
1942 vgpu_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) { \
1943 u##x val = __raw_uncore_read##x(uncore, reg); \
1944 trace_i915_reg_rw(false, reg, val, sizeof(val), trace); \
1952 #define GEN2_READ_HEADER(x) \
1954 assert_rpm_wakelock_held(uncore->rpm);
1956 #define GEN2_READ_FOOTER \
1957 trace_i915_reg_rw(false, reg, val, sizeof(val), trace); \
1960 #define __gen2_read(x) \
1962 gen2_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) { \
1963 GEN2_READ_HEADER(x); \
1964 val = __raw_uncore_read##x(uncore, reg); \
1968 #define __gen5_read(x) \
1970 gen5_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) { \
1971 GEN2_READ_HEADER(x); \
1972 ilk_dummy_write(uncore); \
1973 val = __raw_uncore_read##x(uncore, reg); \
1989 #undef GEN2_READ_FOOTER
1990 #undef GEN2_READ_HEADER
1992 #define GEN6_READ_HEADER(x) \
1993 u32 offset = i915_mmio_reg_offset(reg); \
1994 unsigned long irqflags; \
1996 assert_rpm_wakelock_held(uncore->rpm); \
1997 spin_lock_irqsave(&uncore->lock, irqflags); \
1998 unclaimed_reg_debug(uncore, reg, true, true)
2000 #define GEN6_READ_FOOTER \
2001 unclaimed_reg_debug(uncore, reg, true, false); \
2002 spin_unlock_irqrestore(&uncore->lock, irqflags); \
2003 trace_i915_reg_rw(false, reg, val, sizeof(val), trace); \
2006 static noinline void ___force_wake_auto(struct intel_uncore *uncore,
2007 enum forcewake_domains fw_domains)
2009 struct intel_uncore_forcewake_domain *domain;
2012 GEM_BUG_ON(fw_domains & ~uncore->fw_domains);
2014 for_each_fw_domain_masked(domain, fw_domains, uncore, tmp)
2015 fw_domain_arm_timer(domain);
2017 fw_domains_get(uncore, fw_domains);
2020 static inline void __force_wake_auto(struct intel_uncore *uncore,
2021 enum forcewake_domains fw_domains)
2023 GEM_BUG_ON(!fw_domains);
2025 /* Turn on all requested but inactive supported forcewake domains. */
2026 fw_domains &= uncore->fw_domains;
2027 fw_domains &= ~uncore->fw_domains_active;
2030 ___force_wake_auto(uncore, fw_domains);
2033 #define __gen_fwtable_read(x) \
2035 fwtable_read##x(struct intel_uncore *uncore, i915_reg_t reg, bool trace) \
2037 enum forcewake_domains fw_engine; \
2038 GEN6_READ_HEADER(x); \
2039 fw_engine = __fwtable_reg_read_fw_domains(uncore, offset); \
2041 __force_wake_auto(uncore, fw_engine); \
2042 val = __raw_uncore_read##x(uncore, reg); \
2046 static enum forcewake_domains
2047 fwtable_reg_read_fw_domains(struct intel_uncore *uncore, i915_reg_t reg) {
2048 return __fwtable_reg_read_fw_domains(uncore, i915_mmio_reg_offset(reg));
2051 __gen_fwtable_read(8)
2052 __gen_fwtable_read(16)
2053 __gen_fwtable_read(32)
2054 __gen_fwtable_read(64)
2056 #undef __gen_fwtable_read
2057 #undef GEN6_READ_FOOTER
2058 #undef GEN6_READ_HEADER
2060 #define GEN2_WRITE_HEADER \
2061 trace_i915_reg_rw(true, reg, val, sizeof(val), trace); \
2062 assert_rpm_wakelock_held(uncore->rpm); \
2064 #define GEN2_WRITE_FOOTER
2066 #define __gen2_write(x) \
2068 gen2_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \
2069 GEN2_WRITE_HEADER; \
2070 __raw_uncore_write##x(uncore, reg, val); \
2071 GEN2_WRITE_FOOTER; \
2074 #define __gen5_write(x) \
2076 gen5_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \
2077 GEN2_WRITE_HEADER; \
2078 ilk_dummy_write(uncore); \
2079 __raw_uncore_write##x(uncore, reg, val); \
2080 GEN2_WRITE_FOOTER; \
2093 #undef GEN2_WRITE_FOOTER
2094 #undef GEN2_WRITE_HEADER
2096 #define GEN6_WRITE_HEADER \
2097 u32 offset = i915_mmio_reg_offset(reg); \
2098 unsigned long irqflags; \
2099 trace_i915_reg_rw(true, reg, val, sizeof(val), trace); \
2100 assert_rpm_wakelock_held(uncore->rpm); \
2101 spin_lock_irqsave(&uncore->lock, irqflags); \
2102 unclaimed_reg_debug(uncore, reg, false, true)
2104 #define GEN6_WRITE_FOOTER \
2105 unclaimed_reg_debug(uncore, reg, false, false); \
2106 spin_unlock_irqrestore(&uncore->lock, irqflags)
2108 #define __gen6_write(x) \
2110 gen6_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \
2111 GEN6_WRITE_HEADER; \
2112 if (NEEDS_FORCE_WAKE(offset)) \
2113 __gen6_gt_wait_for_fifo(uncore); \
2114 __raw_uncore_write##x(uncore, reg, val); \
2115 GEN6_WRITE_FOOTER; \
2121 #define __gen_fwtable_write(x) \
2123 fwtable_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \
2124 enum forcewake_domains fw_engine; \
2125 GEN6_WRITE_HEADER; \
2126 fw_engine = __fwtable_reg_write_fw_domains(uncore, offset); \
2128 __force_wake_auto(uncore, fw_engine); \
2129 __raw_uncore_write##x(uncore, reg, val); \
2130 GEN6_WRITE_FOOTER; \
2133 static enum forcewake_domains
2134 fwtable_reg_write_fw_domains(struct intel_uncore *uncore, i915_reg_t reg)
2136 return __fwtable_reg_write_fw_domains(uncore, i915_mmio_reg_offset(reg));
2139 __gen_fwtable_write(8)
2140 __gen_fwtable_write(16)
2141 __gen_fwtable_write(32)
2143 #undef __gen_fwtable_write
2144 #undef GEN6_WRITE_FOOTER
2145 #undef GEN6_WRITE_HEADER
2147 #define __vgpu_write(x) \
2149 vgpu_write##x(struct intel_uncore *uncore, i915_reg_t reg, u##x val, bool trace) { \
2150 trace_i915_reg_rw(true, reg, val, sizeof(val), trace); \
2151 __raw_uncore_write##x(uncore, reg, val); \
2157 #define ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, x) \
2159 (uncore)->funcs.mmio_writeb = x##_write8; \
2160 (uncore)->funcs.mmio_writew = x##_write16; \
2161 (uncore)->funcs.mmio_writel = x##_write32; \
2164 #define ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, x) \
2166 (uncore)->funcs.mmio_readb = x##_read8; \
2167 (uncore)->funcs.mmio_readw = x##_read16; \
2168 (uncore)->funcs.mmio_readl = x##_read32; \
2169 (uncore)->funcs.mmio_readq = x##_read64; \
2172 #define ASSIGN_WRITE_MMIO_VFUNCS(uncore, x) \
2174 ASSIGN_RAW_WRITE_MMIO_VFUNCS((uncore), x); \
2175 (uncore)->funcs.write_fw_domains = x##_reg_write_fw_domains; \
2178 #define ASSIGN_READ_MMIO_VFUNCS(uncore, x) \
2180 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, x); \
2181 (uncore)->funcs.read_fw_domains = x##_reg_read_fw_domains; \
2184 static int __fw_domain_init(struct intel_uncore *uncore,
2185 enum forcewake_domain_id domain_id,
2189 struct intel_uncore_forcewake_domain *d;
2191 GEM_BUG_ON(domain_id >= FW_DOMAIN_ID_COUNT);
2192 GEM_BUG_ON(uncore->fw_domain[domain_id]);
2194 if (i915_inject_probe_failure(uncore->i915))
2197 d = kzalloc(sizeof(*d), GFP_KERNEL);
2201 drm_WARN_ON(&uncore->i915->drm, !i915_mmio_reg_valid(reg_set));
2202 drm_WARN_ON(&uncore->i915->drm, !i915_mmio_reg_valid(reg_ack));
2206 d->reg_set = uncore->regs + i915_mmio_reg_offset(reg_set) + uncore->gsi_offset;
2207 d->reg_ack = uncore->regs + i915_mmio_reg_offset(reg_ack) + uncore->gsi_offset;
2211 BUILD_BUG_ON(FORCEWAKE_RENDER != (1 << FW_DOMAIN_ID_RENDER));
2212 BUILD_BUG_ON(FORCEWAKE_GT != (1 << FW_DOMAIN_ID_GT));
2213 BUILD_BUG_ON(FORCEWAKE_MEDIA != (1 << FW_DOMAIN_ID_MEDIA));
2214 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX0 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX0));
2215 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX1 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX1));
2216 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX2 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX2));
2217 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX3 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX3));
2218 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX4 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX4));
2219 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX5 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX5));
2220 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX6 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX6));
2221 BUILD_BUG_ON(FORCEWAKE_MEDIA_VDBOX7 != (1 << FW_DOMAIN_ID_MEDIA_VDBOX7));
2222 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX0 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX0));
2223 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX1 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX1));
2224 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX2 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX2));
2225 BUILD_BUG_ON(FORCEWAKE_MEDIA_VEBOX3 != (1 << FW_DOMAIN_ID_MEDIA_VEBOX3));
2226 BUILD_BUG_ON(FORCEWAKE_GSC != (1 << FW_DOMAIN_ID_GSC));
2228 d->mask = BIT(domain_id);
2230 hrtimer_init(&d->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
2231 d->timer.function = intel_uncore_fw_release_timer;
2233 uncore->fw_domains |= BIT(domain_id);
2237 uncore->fw_domain[domain_id] = d;
2242 static void fw_domain_fini(struct intel_uncore *uncore,
2243 enum forcewake_domain_id domain_id)
2245 struct intel_uncore_forcewake_domain *d;
2247 GEM_BUG_ON(domain_id >= FW_DOMAIN_ID_COUNT);
2249 d = fetch_and_zero(&uncore->fw_domain[domain_id]);
2253 uncore->fw_domains &= ~BIT(domain_id);
2254 drm_WARN_ON(&uncore->i915->drm, d->wake_count);
2255 drm_WARN_ON(&uncore->i915->drm, hrtimer_cancel(&d->timer));
2259 static void intel_uncore_fw_domains_fini(struct intel_uncore *uncore)
2261 struct intel_uncore_forcewake_domain *d;
2264 for_each_fw_domain(d, uncore, tmp)
2265 fw_domain_fini(uncore, d->id);
2268 static const struct intel_uncore_fw_get uncore_get_fallback = {
2269 .force_wake_get = fw_domains_get_with_fallback
2272 static const struct intel_uncore_fw_get uncore_get_normal = {
2273 .force_wake_get = fw_domains_get_normal,
2276 static const struct intel_uncore_fw_get uncore_get_thread_status = {
2277 .force_wake_get = fw_domains_get_with_thread_status
2280 static int intel_uncore_fw_domains_init(struct intel_uncore *uncore)
2282 struct drm_i915_private *i915 = uncore->i915;
2285 GEM_BUG_ON(!intel_uncore_has_forcewake(uncore));
2287 #define fw_domain_init(uncore__, id__, set__, ack__) \
2288 (ret ?: (ret = __fw_domain_init((uncore__), (id__), (set__), (ack__))))
2290 if (GRAPHICS_VER(i915) >= 11) {
2291 intel_engine_mask_t emask;
2294 /* we'll prune the domains of missing engines later */
2295 emask = uncore->gt->info.engine_mask;
2297 uncore->fw_get_funcs = &uncore_get_fallback;
2298 if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70))
2299 fw_domain_init(uncore, FW_DOMAIN_ID_GT,
2301 FORCEWAKE_ACK_GT_MTL);
2303 fw_domain_init(uncore, FW_DOMAIN_ID_GT,
2305 FORCEWAKE_ACK_GT_GEN9);
2307 if (RCS_MASK(uncore->gt) || CCS_MASK(uncore->gt))
2308 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
2309 FORCEWAKE_RENDER_GEN9,
2310 FORCEWAKE_ACK_RENDER_GEN9);
2312 for (i = 0; i < I915_MAX_VCS; i++) {
2313 if (!__HAS_ENGINE(emask, _VCS(i)))
2316 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA_VDBOX0 + i,
2317 FORCEWAKE_MEDIA_VDBOX_GEN11(i),
2318 FORCEWAKE_ACK_MEDIA_VDBOX_GEN11(i));
2320 for (i = 0; i < I915_MAX_VECS; i++) {
2321 if (!__HAS_ENGINE(emask, _VECS(i)))
2324 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA_VEBOX0 + i,
2325 FORCEWAKE_MEDIA_VEBOX_GEN11(i),
2326 FORCEWAKE_ACK_MEDIA_VEBOX_GEN11(i));
2329 if (uncore->gt->type == GT_MEDIA)
2330 fw_domain_init(uncore, FW_DOMAIN_ID_GSC,
2331 FORCEWAKE_REQ_GSC, FORCEWAKE_ACK_GSC);
2332 } else if (IS_GRAPHICS_VER(i915, 9, 10)) {
2333 uncore->fw_get_funcs = &uncore_get_fallback;
2334 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
2335 FORCEWAKE_RENDER_GEN9,
2336 FORCEWAKE_ACK_RENDER_GEN9);
2337 fw_domain_init(uncore, FW_DOMAIN_ID_GT,
2339 FORCEWAKE_ACK_GT_GEN9);
2340 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA,
2341 FORCEWAKE_MEDIA_GEN9, FORCEWAKE_ACK_MEDIA_GEN9);
2342 } else if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915)) {
2343 uncore->fw_get_funcs = &uncore_get_normal;
2344 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
2345 FORCEWAKE_VLV, FORCEWAKE_ACK_VLV);
2346 fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA,
2347 FORCEWAKE_MEDIA_VLV, FORCEWAKE_ACK_MEDIA_VLV);
2348 } else if (IS_HASWELL(i915) || IS_BROADWELL(i915)) {
2349 uncore->fw_get_funcs = &uncore_get_thread_status;
2350 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
2351 FORCEWAKE_MT, FORCEWAKE_ACK_HSW);
2352 } else if (IS_IVYBRIDGE(i915)) {
2355 /* IVB configs may use multi-threaded forcewake */
2357 /* A small trick here - if the bios hasn't configured
2358 * MT forcewake, and if the device is in RC6, then
2359 * force_wake_mt_get will not wake the device and the
2360 * ECOBUS read will return zero. Which will be
2361 * (correctly) interpreted by the test below as MT
2362 * forcewake being disabled.
2364 uncore->fw_get_funcs = &uncore_get_thread_status;
2366 /* We need to init first for ECOBUS access and then
2367 * determine later if we want to reinit, in case of MT access is
2368 * not working. In this stage we don't know which flavour this
2369 * ivb is, so it is better to reset also the gen6 fw registers
2370 * before the ecobus check.
2373 __raw_uncore_write32(uncore, FORCEWAKE, 0);
2374 __raw_posting_read(uncore, ECOBUS);
2376 ret = __fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
2377 FORCEWAKE_MT, FORCEWAKE_MT_ACK);
2381 spin_lock_irq(&uncore->lock);
2382 fw_domains_get_with_thread_status(uncore, FORCEWAKE_RENDER);
2383 ecobus = __raw_uncore_read32(uncore, ECOBUS);
2384 fw_domains_put(uncore, FORCEWAKE_RENDER);
2385 spin_unlock_irq(&uncore->lock);
2387 if (!(ecobus & FORCEWAKE_MT_ENABLE)) {
2388 drm_info(&i915->drm, "No MT forcewake available on Ivybridge, this can result in issues\n");
2389 drm_info(&i915->drm, "when using vblank-synced partial screen updates.\n");
2390 fw_domain_fini(uncore, FW_DOMAIN_ID_RENDER);
2391 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
2392 FORCEWAKE, FORCEWAKE_ACK);
2394 } else if (GRAPHICS_VER(i915) == 6) {
2395 uncore->fw_get_funcs = &uncore_get_thread_status;
2396 fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
2397 FORCEWAKE, FORCEWAKE_ACK);
2400 #undef fw_domain_init
2402 /* All future platforms are expected to require complex power gating */
2403 drm_WARN_ON(&i915->drm, !ret && uncore->fw_domains == 0);
2407 intel_uncore_fw_domains_fini(uncore);
2412 #define ASSIGN_FW_DOMAINS_TABLE(uncore, d) \
2414 (uncore)->fw_domains_table = \
2415 (struct intel_forcewake_range *)(d); \
2416 (uncore)->fw_domains_table_entries = ARRAY_SIZE((d)); \
2419 #define ASSIGN_SHADOW_TABLE(uncore, d) \
2421 (uncore)->shadowed_reg_table = d; \
2422 (uncore)->shadowed_reg_table_entries = ARRAY_SIZE((d)); \
2425 static int i915_pmic_bus_access_notifier(struct notifier_block *nb,
2426 unsigned long action, void *data)
2428 struct intel_uncore *uncore = container_of(nb,
2429 struct intel_uncore, pmic_bus_access_nb);
2432 case MBI_PMIC_BUS_ACCESS_BEGIN:
2434 * forcewake all now to make sure that we don't need to do a
2435 * forcewake later which on systems where this notifier gets
2436 * called requires the punit to access to the shared pmic i2c
2437 * bus, which will be busy after this notification, leading to:
2438 * "render: timed out waiting for forcewake ack request."
2441 * The notifier is unregistered during intel_runtime_suspend(),
2442 * so it's ok to access the HW here without holding a RPM
2443 * wake reference -> disable wakeref asserts for the time of
2446 disable_rpm_wakeref_asserts(uncore->rpm);
2447 intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
2448 enable_rpm_wakeref_asserts(uncore->rpm);
2450 case MBI_PMIC_BUS_ACCESS_END:
2451 intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL);
2458 static void uncore_unmap_mmio(struct drm_device *drm, void *regs)
2463 int intel_uncore_setup_mmio(struct intel_uncore *uncore, phys_addr_t phys_addr)
2465 struct drm_i915_private *i915 = uncore->i915;
2469 * Before gen4, the registers and the GTT are behind different BARs.
2470 * However, from gen4 onwards, the registers and the GTT are shared
2471 * in the same BAR, so we want to restrict this ioremap from
2472 * clobbering the GTT which we want ioremap_wc instead. Fortunately,
2473 * the register BAR remains the same size for all the earlier
2474 * generations up to Ironlake.
2475 * For dgfx chips register range is expanded to 4MB, and this larger
2476 * range is also used for integrated gpus beginning with Meteor Lake.
2478 if (IS_DGFX(i915) || GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70))
2479 mmio_size = 4 * 1024 * 1024;
2480 else if (GRAPHICS_VER(i915) >= 5)
2481 mmio_size = 2 * 1024 * 1024;
2483 mmio_size = 512 * 1024;
2485 uncore->regs = ioremap(phys_addr, mmio_size);
2486 if (uncore->regs == NULL) {
2487 drm_err(&i915->drm, "failed to map registers\n");
2491 return drmm_add_action_or_reset(&i915->drm, uncore_unmap_mmio, uncore->regs);
2494 void intel_uncore_init_early(struct intel_uncore *uncore,
2495 struct intel_gt *gt)
2497 spin_lock_init(&uncore->lock);
2498 uncore->i915 = gt->i915;
2500 uncore->rpm = >->i915->runtime_pm;
2503 static void uncore_raw_init(struct intel_uncore *uncore)
2505 GEM_BUG_ON(intel_uncore_has_forcewake(uncore));
2507 if (intel_vgpu_active(uncore->i915)) {
2508 ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, vgpu);
2509 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, vgpu);
2510 } else if (GRAPHICS_VER(uncore->i915) == 5) {
2511 ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, gen5);
2512 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, gen5);
2514 ASSIGN_RAW_WRITE_MMIO_VFUNCS(uncore, gen2);
2515 ASSIGN_RAW_READ_MMIO_VFUNCS(uncore, gen2);
2519 static int uncore_media_forcewake_init(struct intel_uncore *uncore)
2521 struct drm_i915_private *i915 = uncore->i915;
2523 if (MEDIA_VER(i915) >= 13) {
2524 ASSIGN_FW_DOMAINS_TABLE(uncore, __xelpmp_fw_ranges);
2525 ASSIGN_SHADOW_TABLE(uncore, xelpmp_shadowed_regs);
2526 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2528 MISSING_CASE(MEDIA_VER(i915));
2535 static int uncore_forcewake_init(struct intel_uncore *uncore)
2537 struct drm_i915_private *i915 = uncore->i915;
2540 GEM_BUG_ON(!intel_uncore_has_forcewake(uncore));
2542 ret = intel_uncore_fw_domains_init(uncore);
2545 forcewake_early_sanitize(uncore, 0);
2547 ASSIGN_READ_MMIO_VFUNCS(uncore, fwtable);
2549 if (uncore->gt->type == GT_MEDIA)
2550 return uncore_media_forcewake_init(uncore);
2552 if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70)) {
2553 ASSIGN_FW_DOMAINS_TABLE(uncore, __mtl_fw_ranges);
2554 ASSIGN_SHADOW_TABLE(uncore, mtl_shadowed_regs);
2555 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2556 } else if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 60)) {
2557 ASSIGN_FW_DOMAINS_TABLE(uncore, __pvc_fw_ranges);
2558 ASSIGN_SHADOW_TABLE(uncore, pvc_shadowed_regs);
2559 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2560 } else if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 55)) {
2561 ASSIGN_FW_DOMAINS_TABLE(uncore, __dg2_fw_ranges);
2562 ASSIGN_SHADOW_TABLE(uncore, dg2_shadowed_regs);
2563 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2564 } else if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 50)) {
2565 ASSIGN_FW_DOMAINS_TABLE(uncore, __xehp_fw_ranges);
2566 ASSIGN_SHADOW_TABLE(uncore, gen12_shadowed_regs);
2567 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2568 } else if (GRAPHICS_VER(i915) >= 12) {
2569 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen12_fw_ranges);
2570 ASSIGN_SHADOW_TABLE(uncore, gen12_shadowed_regs);
2571 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2572 } else if (GRAPHICS_VER(i915) == 11) {
2573 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen11_fw_ranges);
2574 ASSIGN_SHADOW_TABLE(uncore, gen11_shadowed_regs);
2575 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2576 } else if (IS_GRAPHICS_VER(i915, 9, 10)) {
2577 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen9_fw_ranges);
2578 ASSIGN_SHADOW_TABLE(uncore, gen8_shadowed_regs);
2579 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2580 } else if (IS_CHERRYVIEW(i915)) {
2581 ASSIGN_FW_DOMAINS_TABLE(uncore, __chv_fw_ranges);
2582 ASSIGN_SHADOW_TABLE(uncore, gen8_shadowed_regs);
2583 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2584 } else if (GRAPHICS_VER(i915) == 8) {
2585 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen6_fw_ranges);
2586 ASSIGN_SHADOW_TABLE(uncore, gen8_shadowed_regs);
2587 ASSIGN_WRITE_MMIO_VFUNCS(uncore, fwtable);
2588 } else if (IS_VALLEYVIEW(i915)) {
2589 ASSIGN_FW_DOMAINS_TABLE(uncore, __vlv_fw_ranges);
2590 ASSIGN_WRITE_MMIO_VFUNCS(uncore, gen6);
2591 } else if (IS_GRAPHICS_VER(i915, 6, 7)) {
2592 ASSIGN_FW_DOMAINS_TABLE(uncore, __gen6_fw_ranges);
2593 ASSIGN_WRITE_MMIO_VFUNCS(uncore, gen6);
2596 uncore->pmic_bus_access_nb.notifier_call = i915_pmic_bus_access_notifier;
2597 iosf_mbi_register_pmic_bus_access_notifier(&uncore->pmic_bus_access_nb);
2602 int intel_uncore_init_mmio(struct intel_uncore *uncore)
2604 struct drm_i915_private *i915 = uncore->i915;
2608 * The boot firmware initializes local memory and assesses its health.
2609 * If memory training fails, the punit will have been instructed to
2610 * keep the GT powered down; we won't be able to communicate with it
2611 * and we should not continue with driver initialization.
2613 if (IS_DGFX(i915) &&
2614 !(__raw_uncore_read32(uncore, GU_CNTL) & LMEM_INIT)) {
2615 drm_err(&i915->drm, "LMEM not initialized by firmware\n");
2619 if (GRAPHICS_VER(i915) > 5 && !intel_vgpu_active(i915))
2620 uncore->flags |= UNCORE_HAS_FORCEWAKE;
2622 if (!intel_uncore_has_forcewake(uncore)) {
2623 uncore_raw_init(uncore);
2625 ret = uncore_forcewake_init(uncore);
2630 /* make sure fw funcs are set if and only if we have fw*/
2631 GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->fw_get_funcs);
2632 GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->funcs.read_fw_domains);
2633 GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->funcs.write_fw_domains);
2635 if (HAS_FPGA_DBG_UNCLAIMED(i915))
2636 uncore->flags |= UNCORE_HAS_FPGA_DBG_UNCLAIMED;
2638 if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
2639 uncore->flags |= UNCORE_HAS_DBG_UNCLAIMED;
2641 if (IS_GRAPHICS_VER(i915, 6, 7))
2642 uncore->flags |= UNCORE_HAS_FIFO;
2644 /* clear out unclaimed reg detection bit */
2645 if (intel_uncore_unclaimed_mmio(uncore))
2646 drm_dbg(&i915->drm, "unclaimed mmio detected on uncore init, clearing\n");
2652 * We might have detected that some engines are fused off after we initialized
2653 * the forcewake domains. Prune them, to make sure they only reference existing
2656 void intel_uncore_prune_engine_fw_domains(struct intel_uncore *uncore,
2657 struct intel_gt *gt)
2659 enum forcewake_domains fw_domains = uncore->fw_domains;
2660 enum forcewake_domain_id domain_id;
2663 if (!intel_uncore_has_forcewake(uncore) || GRAPHICS_VER(uncore->i915) < 11)
2666 for (i = 0; i < I915_MAX_VCS; i++) {
2667 domain_id = FW_DOMAIN_ID_MEDIA_VDBOX0 + i;
2669 if (HAS_ENGINE(gt, _VCS(i)))
2673 * Starting with XeHP, the power well for an even-numbered
2674 * VDBOX is also used for shared units within the
2675 * media slice such as SFC. So even if the engine
2676 * itself is fused off, we still need to initialize
2677 * the forcewake domain if any of the other engines
2678 * in the same media slice are present.
2680 if (GRAPHICS_VER_FULL(uncore->i915) >= IP_VER(12, 50) && i % 2 == 0) {
2681 if ((i + 1 < I915_MAX_VCS) && HAS_ENGINE(gt, _VCS(i + 1)))
2684 if (HAS_ENGINE(gt, _VECS(i / 2)))
2688 if (fw_domains & BIT(domain_id))
2689 fw_domain_fini(uncore, domain_id);
2692 for (i = 0; i < I915_MAX_VECS; i++) {
2693 domain_id = FW_DOMAIN_ID_MEDIA_VEBOX0 + i;
2695 if (HAS_ENGINE(gt, _VECS(i)))
2698 if (fw_domains & BIT(domain_id))
2699 fw_domain_fini(uncore, domain_id);
2703 /* Called via drm-managed action */
2704 void intel_uncore_fini_mmio(struct drm_device *dev, void *data)
2706 struct intel_uncore *uncore = data;
2708 if (intel_uncore_has_forcewake(uncore)) {
2709 iosf_mbi_punit_acquire();
2710 iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(
2711 &uncore->pmic_bus_access_nb);
2712 intel_uncore_forcewake_reset(uncore);
2713 intel_uncore_fw_domains_fini(uncore);
2714 iosf_mbi_punit_release();
2719 * __intel_wait_for_register_fw - wait until register matches expected state
2720 * @uncore: the struct intel_uncore
2721 * @reg: the register to read
2722 * @mask: mask to apply to register value
2723 * @value: expected value
2724 * @fast_timeout_us: fast timeout in microsecond for atomic/tight wait
2725 * @slow_timeout_ms: slow timeout in millisecond
2726 * @out_value: optional placeholder to hold registry value
2728 * This routine waits until the target register @reg contains the expected
2729 * @value after applying the @mask, i.e. it waits until ::
2731 * (intel_uncore_read_fw(uncore, reg) & mask) == value
2733 * Otherwise, the wait will timeout after @slow_timeout_ms milliseconds.
2734 * For atomic context @slow_timeout_ms must be zero and @fast_timeout_us
2735 * must be not larger than 20,0000 microseconds.
2737 * Note that this routine assumes the caller holds forcewake asserted, it is
2738 * not suitable for very long waits. See intel_wait_for_register() if you
2739 * wish to wait without holding forcewake for the duration (i.e. you expect
2740 * the wait to be slow).
2742 * Return: 0 if the register matches the desired condition, or -ETIMEDOUT.
2744 int __intel_wait_for_register_fw(struct intel_uncore *uncore,
2748 unsigned int fast_timeout_us,
2749 unsigned int slow_timeout_ms,
2753 #define done (((reg_value = intel_uncore_read_fw(uncore, reg)) & mask) == value)
2756 /* Catch any overuse of this function */
2757 might_sleep_if(slow_timeout_ms);
2758 GEM_BUG_ON(fast_timeout_us > 20000);
2759 GEM_BUG_ON(!fast_timeout_us && !slow_timeout_ms);
2762 if (fast_timeout_us && fast_timeout_us <= 20000)
2763 ret = _wait_for_atomic(done, fast_timeout_us, 0);
2764 if (ret && slow_timeout_ms)
2765 ret = wait_for(done, slow_timeout_ms);
2768 *out_value = reg_value;
2775 * __intel_wait_for_register - wait until register matches expected state
2776 * @uncore: the struct intel_uncore
2777 * @reg: the register to read
2778 * @mask: mask to apply to register value
2779 * @value: expected value
2780 * @fast_timeout_us: fast timeout in microsecond for atomic/tight wait
2781 * @slow_timeout_ms: slow timeout in millisecond
2782 * @out_value: optional placeholder to hold registry value
2784 * This routine waits until the target register @reg contains the expected
2785 * @value after applying the @mask, i.e. it waits until ::
2787 * (intel_uncore_read(uncore, reg) & mask) == value
2789 * Otherwise, the wait will timeout after @timeout_ms milliseconds.
2791 * Return: 0 if the register matches the desired condition, or -ETIMEDOUT.
2793 int __intel_wait_for_register(struct intel_uncore *uncore,
2797 unsigned int fast_timeout_us,
2798 unsigned int slow_timeout_ms,
2802 intel_uncore_forcewake_for_reg(uncore, reg, FW_REG_READ);
2806 might_sleep_if(slow_timeout_ms);
2808 spin_lock_irq(&uncore->lock);
2809 intel_uncore_forcewake_get__locked(uncore, fw);
2811 ret = __intel_wait_for_register_fw(uncore,
2813 fast_timeout_us, 0, ®_value);
2815 intel_uncore_forcewake_put__locked(uncore, fw);
2816 spin_unlock_irq(&uncore->lock);
2818 if (ret && slow_timeout_ms)
2819 ret = __wait_for(reg_value = intel_uncore_read_notrace(uncore,
2821 (reg_value & mask) == value,
2822 slow_timeout_ms * 1000, 10, 1000);
2824 /* just trace the final value */
2825 trace_i915_reg_rw(false, reg, reg_value, sizeof(reg_value), true);
2828 *out_value = reg_value;
2833 bool intel_uncore_unclaimed_mmio(struct intel_uncore *uncore)
2840 spin_lock_irq(&uncore->debug->lock);
2841 ret = check_for_unclaimed_mmio(uncore);
2842 spin_unlock_irq(&uncore->debug->lock);
2848 intel_uncore_arm_unclaimed_mmio_detection(struct intel_uncore *uncore)
2852 if (drm_WARN_ON(&uncore->i915->drm, !uncore->debug))
2855 spin_lock_irq(&uncore->debug->lock);
2857 if (unlikely(uncore->debug->unclaimed_mmio_check <= 0))
2860 if (unlikely(check_for_unclaimed_mmio(uncore))) {
2861 if (!uncore->i915->params.mmio_debug) {
2862 drm_dbg(&uncore->i915->drm,
2863 "Unclaimed register detected, "
2864 "enabling oneshot unclaimed register reporting. "
2865 "Please use i915.mmio_debug=N for more information.\n");
2866 uncore->i915->params.mmio_debug++;
2868 uncore->debug->unclaimed_mmio_check--;
2873 spin_unlock_irq(&uncore->debug->lock);
2879 * intel_uncore_forcewake_for_reg - which forcewake domains are needed to access
2881 * @uncore: pointer to struct intel_uncore
2882 * @reg: register in question
2883 * @op: operation bitmask of FW_REG_READ and/or FW_REG_WRITE
2885 * Returns a set of forcewake domains required to be taken with for example
2886 * intel_uncore_forcewake_get for the specified register to be accessible in the
2887 * specified mode (read, write or read/write) with raw mmio accessors.
2889 * NOTE: On Gen6 and Gen7 write forcewake domain (FORCEWAKE_RENDER) requires the
2890 * callers to do FIFO management on their own or risk losing writes.
2892 enum forcewake_domains
2893 intel_uncore_forcewake_for_reg(struct intel_uncore *uncore,
2894 i915_reg_t reg, unsigned int op)
2896 enum forcewake_domains fw_domains = 0;
2898 drm_WARN_ON(&uncore->i915->drm, !op);
2900 if (!intel_uncore_has_forcewake(uncore))
2903 if (op & FW_REG_READ)
2904 fw_domains = uncore->funcs.read_fw_domains(uncore, reg);
2906 if (op & FW_REG_WRITE)
2907 fw_domains |= uncore->funcs.write_fw_domains(uncore, reg);
2909 drm_WARN_ON(&uncore->i915->drm, fw_domains & ~uncore->fw_domains);
2914 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
2915 #include "selftests/mock_uncore.c"
2916 #include "selftests/intel_uncore.c"