staticvoid mmio_debug_suspend(struct intel_uncore *uncore)
{ if (!uncore->debug) return;
spin_lock(&uncore->debug->lock);
/* Save and disable mmio debugging for the user bypass */ if (!uncore->debug->suspend_count++) {
uncore->debug->saved_mmio_check = uncore->debug->unclaimed_mmio_check;
uncore->debug->unclaimed_mmio_check = 0;
}
staticinlinevoid
fw_domain_reset(conststruct intel_uncore_forcewake_domain *d)
{ /* * We don't really know if the powerwell for the forcewake domain we are * trying to reset here does exist at this point (engines could be fused * off in ICL+), so no waiting for acks
*/ /* WaRsClearFWBitsAtReset */ if (GRAPHICS_VER(d->uncore->i915) >= 12)
fw_clear(d, 0xefff); else
fw_clear(d, 0xffff);
}
/* * There is a possibility of driver's wake request colliding * with hardware's own wake requests and that can cause * hardware to not deliver the driver's ack message. * * Use a fallback bit toggle to kick the gpu state machine * in the hope that the original ack will be delivered along with * the fallback ack. * * This workaround is described in HSDES #1604254524 and it's known as: * WaRsForcewakeAddDelayForAck:skl,bxt,kbl,glk,cfl,cnl,icl * although the name is a bit misleading.
*/
pass = 1; do {
wait_ack_clear(d, FORCEWAKE_KERNEL_FALLBACK);
fw_set(d, FORCEWAKE_KERNEL_FALLBACK); /* Give gt some time to relax before the polling frenzy */
udelay(10 * pass);
wait_ack_set(d, FORCEWAKE_KERNEL_FALLBACK);
ack_detected = (fw_ack(d) & ack_bit) == value;
fw_clear(d, FORCEWAKE_KERNEL_FALLBACK);
} while (!ack_detected && pass++ < 10);
drm_dbg(&d->uncore->i915->drm, "%s had to use fallback to %s ack, 0x%x (passes %u)\n",
intel_uncore_forcewake_domain_to_str(d->id),
type == ACK_SET ? "set" : "clear",
fw_ack(d),
pass);
return ack_detected ? 0 : -ETIMEDOUT;
}
staticinlinevoid
fw_domain_wait_ack_clear_fallback(conststruct intel_uncore_forcewake_domain *d)
{ if (likely(!wait_ack_clear(d, FORCEWAKE_KERNEL))) return;
if (fw_domain_wait_ack_with_fallback(d, ACK_CLEAR))
fw_domain_wait_ack_clear(d);
}
val = __raw_uncore_read32(uncore, GEN6_GT_THREAD_STATUS_REG);
val &= GEN6_GT_THREAD_STATUS_CORE_MASK;
return val;
}
staticvoid __gen6_gt_wait_for_thread_c0(struct intel_uncore *uncore)
{ /* * w/a for a sporadic read returning 0 by waiting for the GT * thread to wake up.
*/
drm_WARN_ONCE(&uncore->i915->drm,
wait_for_atomic_us(gt_thread_status(uncore) == 0, 5000), "GT thread status wait timed out\n");
}
/* On VLV, FIFO will be shared by both SW and HW.
* So, we need to read the FREE_ENTRIES everytime */ if (IS_VALLEYVIEW(uncore->i915))
n = fifo_free_entries(uncore); else
n = uncore->fifo_count;
if (xchg(&domain->active, false)) return HRTIMER_RESTART;
spin_lock_irqsave(&uncore->lock, irqflags);
uncore->fw_domains_timer &= ~domain->mask;
GEM_BUG_ON(!domain->wake_count); if (--domain->wake_count == 0)
fw_domains_put(uncore, domain->mask);
spin_unlock_irqrestore(&uncore->lock, irqflags);
return HRTIMER_NORESTART;
}
/* Note callers must have acquired the PUNIT->PMIC bus, before calling this. */ staticunsignedint
intel_uncore_forcewake_reset(struct intel_uncore *uncore)
{ unsignedlong irqflags; struct intel_uncore_forcewake_domain *domain; int retry_count = 100; enum forcewake_domains fw, active_domains;
iosf_mbi_assert_punit_acquired();
/* Hold uncore.lock across reset to prevent any register access * with forcewake not set correctly. Wait until all pending * timers are run before holding.
*/ while (1) { unsignedint tmp;
dbg = __raw_uncore_read32(uncore, FPGA_DBG); if (likely(!(dbg & FPGA_DBG_RM_NOCLAIM))) returnfalse;
/* * Bugs in PCI programming (or failing hardware) can occasionally cause * us to lose access to the MMIO BAR. When this happens, register * reads will come back with 0xFFFFFFFF for every register and things * go bad very quickly. Let's try to detect that special case and at * least try to print a more informative message about what has * happened. * * During normal operation the FPGA_DBG register has several unused * bits that will always read back as 0's so we can use them as canaries * to recognize when MMIO accesses are just busted.
*/ if (unlikely(dbg == ~0))
drm_err(&uncore->i915->drm, "Lost access to MMIO BAR; all registers now read back as 0xFFFFFFFF!\n");
if (fw_domains)
fw_domains_get(uncore, fw_domains);
}
/** * intel_uncore_forcewake_get - grab forcewake domain references * @uncore: the intel_uncore structure * @fw_domains: forcewake domains to get reference on * * This function can be used get GT's forcewake domain references. * Normal register access will handle the forcewake domains automatically. * However if some sequence requires the GT to not power down a particular * forcewake domains this function should be called at the beginning of the * sequence. And subsequently the reference should be dropped by symmetric * call to intel_unforce_forcewake_put(). Usually caller wants all the domains * to be kept awake so the @fw_domains would be then FORCEWAKE_ALL.
*/ void intel_uncore_forcewake_get(struct intel_uncore *uncore, enum forcewake_domains fw_domains)
{ unsignedlong irqflags;
/** * intel_uncore_forcewake_user_get - claim forcewake on behalf of userspace * @uncore: the intel_uncore structure * * This function is a wrapper around intel_uncore_forcewake_get() to acquire * the GT powerwell and in the process disable our debugging for the * duration of userspace's bypass.
*/ void intel_uncore_forcewake_user_get(struct intel_uncore *uncore)
{
spin_lock_irq(&uncore->lock); if (!uncore->user_forcewake_count++) {
intel_uncore_forcewake_get__locked(uncore, FORCEWAKE_ALL);
mmio_debug_suspend(uncore);
}
spin_unlock_irq(&uncore->lock);
}
/** * intel_uncore_forcewake_user_put - release forcewake on behalf of userspace * @uncore: the intel_uncore structure * * This function complements intel_uncore_forcewake_user_get() and releases * the GT powerwell taken on behalf of the userspace bypass.
*/ void intel_uncore_forcewake_user_put(struct intel_uncore *uncore)
{
spin_lock_irq(&uncore->lock); if (!--uncore->user_forcewake_count) {
mmio_debug_resume(uncore);
intel_uncore_forcewake_put__locked(uncore, FORCEWAKE_ALL);
}
spin_unlock_irq(&uncore->lock);
}
/** * intel_uncore_forcewake_get__locked - grab forcewake domain references * @uncore: the intel_uncore structure * @fw_domains: forcewake domains to get reference on * * See intel_uncore_forcewake_get(). This variant places the onus * on the caller to explicitly handle the dev_priv->uncore.lock spinlock.
*/ void intel_uncore_forcewake_get__locked(struct intel_uncore *uncore, enum forcewake_domains fw_domains)
{
lockdep_assert_held(&uncore->lock);
/** * intel_uncore_forcewake_put__locked - release forcewake domain references * @uncore: the intel_uncore structure * @fw_domains: forcewake domains to put references * * See intel_uncore_forcewake_put(). This variant places the onus * on the caller to explicitly handle the dev_priv->uncore.lock spinlock.
*/ void intel_uncore_forcewake_put__locked(struct intel_uncore *uncore, enum forcewake_domains fw_domains)
{
lockdep_assert_held(&uncore->lock);
void assert_forcewakes_inactive(struct intel_uncore *uncore)
{ if (!uncore->fw_get_funcs) return;
drm_WARN(&uncore->i915->drm, uncore->fw_domains_active, "Expected all fw_domains to be inactive, but %08x are still on\n",
uncore->fw_domains_active);
}
if (!IS_ENABLED(CONFIG_DRM_I915_DEBUG_RUNTIME_PM)) return;
if (!uncore->fw_get_funcs) return;
spin_lock_irq(&uncore->lock);
assert_rpm_wakelock_held(uncore->rpm);
fw_domains &= uncore->fw_domains;
drm_WARN(&uncore->i915->drm, fw_domains & ~uncore->fw_domains_active, "Expected %08x fw_domains to be active, but %08x are off\n",
fw_domains, fw_domains & ~uncore->fw_domains_active);
/* * Check that the caller has an explicit wakeref and we don't mistake * it for the auto wakeref.
*/
for_each_fw_domain_masked(domain, fw_domains, uncore, tmp) { unsignedint actual = READ_ONCE(domain->wake_count); unsignedint expect = 1;
if (uncore->fw_domains_timer & domain->mask)
expect++; /* pending automatic release */
if (drm_WARN(&uncore->i915->drm, actual < expect, "Expected domain %d to be held awake by caller, count=%d\n",
domain->id, actual)) break;
}
spin_unlock_irq(&uncore->lock);
}
/* * We give fast paths for the really cool registers. The second range includes * media domains (and the GSC starting from Xe_LPM+)
*/ #define NEEDS_FORCE_WAKE(reg) ({ \
u32 __reg = (reg); \
__reg < 0x40000 || __reg >= 0x116000; \
})
/* * The list of FW domains depends on the SKU in gen11+ so we * can't determine it statically. We use FORCEWAKE_ALL and * translate it here to the list of available domains.
*/ if (entry->domains == FORCEWAKE_ALL) return uncore->fw_domains;
/* * Shadowed register tables describe special register ranges that i915 is * allowed to write to without acquiring forcewake. If these registers' power * wells are down, the hardware will save values written by i915 to a shadow * copy and automatically transfer them into the real register the next time * the power well is woken up. Shadowing only applies to writes; forcewake * must still be acquired when reading from registers in these ranges. * * The documentation for shadowed registers is somewhat spotty on older * platforms. However missing registers from these lists is non-fatal; it just * means we'll wake up the hardware for some register accesses where we didn't * really need to. * * The ranges listed in these tables must be sorted by offset. * * When adding new tables here, please also add them to * intel_shadow_table_check() in selftests/intel_uncore.c so that they will be * scanned for obvious mistakes or typos by the selftests.
*/
/* * All platforms' forcewake tables below must be sorted by offset ranges. * Furthermore, new forcewake tables added should be "watertight" and have * no gaps between ranges. * * When there are multiple consecutive ranges listed in the bspec with * the same forcewake domain, it is customary to combine them into a single * row in the tables below to keep the tables small and lookups fast. * Likewise, reserved/unused ranges may be combined with the preceding and/or * following ranges since the driver will never be making MMIO accesses in * those ranges. * * For example, if the bspec were to list: * * ... * 0x1000 - 0x1fff: GT * 0x2000 - 0x2cff: GT * 0x2d00 - 0x2fff: unused/reserved * 0x3000 - 0xffff: GT * ... * * these could all be represented by a single line in the code: * * GEN_FW_RANGE(0x1000, 0xffff, FORCEWAKE_GT) * * When adding new forcewake tables here, please also add them to * intel_uncore_mock_selftests in selftests/intel_uncore.c so that they will be * scanned for obvious mistakes or typos by the selftests.
*/
/* * Note that the register ranges here are the final offsets after * translation of the GSI block to the 0x380000 offset. * * NOTE: There are a couple MCR ranges near the bottom of this table * that need to power up either VD0 or VD2 depending on which replicated * instance of the register we're trying to access. Our forcewake logic * at the moment doesn't have a good way to take steering into consideration, * and the driver doesn't even access any registers in those ranges today, * so for now we just mark those ranges as FORCEWAKE_ALL. That will ensure * proper operation if we do start using the ranges in the future, and we * can determine at that time whether it's worth adding extra complexity to * the forcewake handling to take steering into consideration.
*/ staticconststruct intel_forcewake_range __xelpmp_fw_ranges[] = {
GEN_FW_RANGE(0x0, 0x115fff, 0), /* render GT range */
GEN_FW_RANGE(0x116000, 0x11ffff, FORCEWAKE_GSC), /* 0x116000 - 0x117fff: gsc 0x118000 - 0x119fff: reserved 0x11a000 - 0x11efff: gsc
0x11f000 - 0x11ffff: reserved */
GEN_FW_RANGE(0x120000, 0x1bffff, 0), /* non-GT range */
GEN_FW_RANGE(0x1c0000, 0x1c7fff, FORCEWAKE_MEDIA_VDBOX0), /* 0x1c0000 - 0x1c3dff: VD0 0x1c3e00 - 0x1c3eff: reserved 0x1c3f00 - 0x1c3fff: VD0
0x1c4000 - 0x1c7fff: reserved */
GEN_FW_RANGE(0x1c8000, 0x1cbfff, FORCEWAKE_MEDIA_VEBOX0), /* 0x1c8000 - 0x1ca0ff: VE0
0x1ca100 - 0x1cbfff: reserved */
GEN_FW_RANGE(0x1cc000, 0x1cffff, FORCEWAKE_MEDIA_VDBOX0), /* 0x1cc000 - 0x1cdfff: VD0
0x1ce000 - 0x1cffff: reserved */
GEN_FW_RANGE(0x1d0000, 0x1d7fff, FORCEWAKE_MEDIA_VDBOX2), /* 0x1d0000 - 0x1d3dff: VD2 0x1d3e00 - 0x1d3eff: reserved
0x1d4000 - 0x1d7fff: VD2 */
GEN_FW_RANGE(0x1d8000, 0x1da0ff, FORCEWAKE_MEDIA_VEBOX1),
GEN_FW_RANGE(0x1da100, 0x380aff, 0), /* 0x1da100 - 0x23ffff: reserved 0x240000 - 0x37ffff: non-GT range
0x380000 - 0x380aff: reserved */
GEN_FW_RANGE(0x380b00, 0x380bff, FORCEWAKE_GT),
GEN_FW_RANGE(0x380c00, 0x380fff, 0),
GEN_FW_RANGE(0x381000, 0x38817f, FORCEWAKE_GT), /* 0x381000 - 0x381fff: gt 0x382000 - 0x383fff: reserved 0x384000 - 0x384aff: gt 0x384b00 - 0x3851ff: reserved 0x385200 - 0x3871ff: gt 0x387200 - 0x387fff: reserved 0x388000 - 0x38813f: gt
0x388140 - 0x38817f: reserved */
GEN_FW_RANGE(0x388180, 0x3882ff, 0), /* 0x388180 - 0x3881ff: always on
0x388200 - 0x3882ff: reserved */
GEN_FW_RANGE(0x388300, 0x38955f, FORCEWAKE_GT), /* 0x388300 - 0x38887f: gt 0x388880 - 0x388fff: reserved 0x389000 - 0x38947f: gt
0x389480 - 0x38955f: reserved */
GEN_FW_RANGE(0x389560, 0x389fff, 0), /* 0x389560 - 0x3895ff: always on
0x389600 - 0x389fff: reserved */
GEN_FW_RANGE(0x38a000, 0x38cfff, FORCEWAKE_GT), /* 0x38a000 - 0x38afff: gt 0x38b000 - 0x38bfff: reserved
0x38c000 - 0x38cfff: gt */
GEN_FW_RANGE(0x38d000, 0x38d11f, 0),
GEN_FW_RANGE(0x38d120, 0x391fff, FORCEWAKE_GT), /* 0x38d120 - 0x38dfff: gt 0x38e000 - 0x38efff: reserved 0x38f000 - 0x38ffff: gt
0x389000 - 0x391fff: reserved */
GEN_FW_RANGE(0x392000, 0x392fff, 0), /* 0x392000 - 0x3927ff: always on
0x392800 - 0x292fff: reserved */
GEN_FW_RANGE(0x393000, 0x3931ff, FORCEWAKE_GT),
GEN_FW_RANGE(0x393200, 0x39323f, FORCEWAKE_ALL), /* instance-based, see note above */
GEN_FW_RANGE(0x393240, 0x3933ff, FORCEWAKE_GT),
GEN_FW_RANGE(0x393400, 0x3934ff, FORCEWAKE_ALL), /* instance-based, see note above */
GEN_FW_RANGE(0x393500, 0x393c7f, 0), /* 0x393500 - 0x393bff: reserved
0x393c00 - 0x393c7f: always on */
GEN_FW_RANGE(0x393c80, 0x393dff, FORCEWAKE_GT),
};
staticvoid
ilk_dummy_write(struct intel_uncore *uncore)
{ /* WaIssueDummyWriteToWakeupFromRC6:ilk Issue a dummy write to wake up * the chip from rc6 before touching it for real. MI_MODE is masked,
* hence harmless to write 0 into. */
__raw_uncore_write32(uncore, RING_MI_MODE(RENDER_RING_BASE), 0);
}
staticvoid
__unclaimed_reg_debug(struct intel_uncore *uncore, const i915_reg_t reg, constbool read)
{ if (drm_WARN(&uncore->i915->drm,
check_for_unclaimed_mmio(uncore), "Unclaimed %s register 0x%x\n",
read ? "read from" : "write to",
i915_mmio_reg_offset(reg))) /* Only report the first N failures */
uncore->i915->params.mmio_debug--;
}
if (RCS_MASK(uncore->gt) || CCS_MASK(uncore->gt))
fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
FORCEWAKE_RENDER_GEN9,
FORCEWAKE_ACK_RENDER_GEN9);
for (i = 0; i < I915_MAX_VCS; i++) { if (!__HAS_ENGINE(emask, _VCS(i))) continue;
fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA_VDBOX0 + i,
FORCEWAKE_MEDIA_VDBOX_GEN11(i),
FORCEWAKE_ACK_MEDIA_VDBOX_GEN11(i));
} for (i = 0; i < I915_MAX_VECS; i++) { if (!__HAS_ENGINE(emask, _VECS(i))) continue;
fw_domain_init(uncore, FW_DOMAIN_ID_MEDIA_VEBOX0 + i,
FORCEWAKE_MEDIA_VEBOX_GEN11(i),
FORCEWAKE_ACK_MEDIA_VEBOX_GEN11(i));
}
/* IVB configs may use multi-threaded forcewake */
/* A small trick here - if the bios hasn't configured * MT forcewake, and if the device is in RC6, then * force_wake_mt_get will not wake the device and the * ECOBUS read will return zero. Which will be * (correctly) interpreted by the test below as MT * forcewake being disabled.
*/
uncore->fw_get_funcs = &uncore_get_thread_status;
/* We need to init first for ECOBUS access and then * determine later if we want to reinit, in case of MT access is * not working. In this stage we don't know which flavour this * ivb is, so it is better to reset also the gen6 fw registers * before the ecobus check.
*/
if (!(ecobus & FORCEWAKE_MT_ENABLE)) {
drm_info(&i915->drm, "No MT forcewake available on Ivybridge, this can result in issues\n");
drm_info(&i915->drm, "when using vblank-synced partial screen updates.\n");
fw_domain_fini(uncore, FW_DOMAIN_ID_RENDER);
fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
FORCEWAKE, FORCEWAKE_ACK);
}
} elseif (GRAPHICS_VER(i915) == 6) {
uncore->fw_get_funcs = &uncore_get_thread_status;
fw_domain_init(uncore, FW_DOMAIN_ID_RENDER,
FORCEWAKE, FORCEWAKE_ACK);
}
#undef fw_domain_init
/* All future platforms are expected to require complex power gating */
drm_WARN_ON(&i915->drm, !ret && uncore->fw_domains == 0);
out: if (ret)
intel_uncore_fw_domains_fini(uncore);
switch (action) { case MBI_PMIC_BUS_ACCESS_BEGIN: /* * forcewake all now to make sure that we don't need to do a * forcewake later which on systems where this notifier gets * called requires the punit to access to the shared pmic i2c * bus, which will be busy after this notification, leading to: * "render: timed out waiting for forcewake ack request." * errors. * * The notifier is unregistered during intel_runtime_suspend(), * so it's ok to access the HW here without holding a RPM * wake reference -> disable wakeref asserts for the time of * the access.
*/
disable_rpm_wakeref_asserts(uncore->rpm);
intel_uncore_forcewake_get(uncore, FORCEWAKE_ALL);
enable_rpm_wakeref_asserts(uncore->rpm); break; case MBI_PMIC_BUS_ACCESS_END:
intel_uncore_forcewake_put(uncore, FORCEWAKE_ALL); break;
}
int intel_uncore_setup_mmio(struct intel_uncore *uncore, phys_addr_t phys_addr)
{ struct drm_i915_private *i915 = uncore->i915; int mmio_size;
/* * Before gen4, the registers and the GTT are behind different BARs. * However, from gen4 onwards, the registers and the GTT are shared * in the same BAR, so we want to restrict this ioremap from * clobbering the GTT which we want ioremap_wc instead. Fortunately, * the register BAR remains the same size for all the earlier * generations up to Ironlake. * For dgfx chips register range is expanded to 4MB, and this larger * range is also used for integrated gpus beginning with Meteor Lake.
*/ if (IS_DGFX(i915) || GRAPHICS_VER_FULL(i915) >= IP_VER(12, 70))
mmio_size = 4 * 1024 * 1024; elseif (GRAPHICS_VER(i915) >= 5)
mmio_size = 2 * 1024 * 1024; else
mmio_size = 512 * 1024;
uncore->regs = ioremap(phys_addr, mmio_size); if (uncore->regs == NULL) {
drm_err(&i915->drm, "failed to map registers\n"); return -EIO;
}
/* * Sanitycheck that MMIO access to the device is working properly. If * the CPU is unable to communicate with a PCI device, BAR reads will * return 0xFFFFFFFF. Let's make sure the device isn't in this state * before we start trying to access registers. * * We use the primary GT's forcewake register as our guinea pig since * it's been around since HSW and it's a masked register so the upper * 16 bits can never read back as 1's if device access is operating * properly. * * If MMIO isn't working, we'll wait up to 2 seconds to see if it * recovers, then give up.
*/ #define COND (__raw_uncore_read32(uncore, FORCEWAKE_MT) != ~0) if (wait_for(COND, 2000) == -ETIMEDOUT) {
drm_err(&i915->drm, "Device is non-operational; MMIO access returns 0xFFFFFFFF!\n"); return -EIO;
}
return 0;
}
int intel_uncore_init_mmio(struct intel_uncore *uncore)
{ struct drm_i915_private *i915 = uncore->i915; int ret;
ret = sanity_check_mmio_access(uncore); if (ret) return ret;
/* * The boot firmware initializes local memory and assesses its health. * If memory training fails, the punit will have been instructed to * keep the GT powered down; we won't be able to communicate with it * and we should not continue with driver initialization.
*/ if (IS_DGFX(i915) &&
!(__raw_uncore_read32(uncore, GU_CNTL) & LMEM_INIT)) {
drm_err(&i915->drm, "LMEM not initialized by firmware\n"); return -ENODEV;
}
if (GRAPHICS_VER(i915) > 5 && !intel_vgpu_active(i915))
uncore->flags |= UNCORE_HAS_FORCEWAKE;
if (!intel_uncore_has_forcewake(uncore)) {
uncore_raw_init(uncore);
} else {
ret = uncore_forcewake_init(uncore); if (ret) return ret;
}
/* make sure fw funcs are set if and only if we have fw*/
GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->fw_get_funcs);
GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->funcs.read_fw_domains);
GEM_BUG_ON(intel_uncore_has_forcewake(uncore) != !!uncore->funcs.write_fw_domains);
if (HAS_FPGA_DBG_UNCLAIMED(i915))
uncore->flags |= UNCORE_HAS_FPGA_DBG_UNCLAIMED;
if (IS_VALLEYVIEW(i915) || IS_CHERRYVIEW(i915))
uncore->flags |= UNCORE_HAS_DBG_UNCLAIMED;
if (IS_GRAPHICS_VER(i915, 6, 7))
uncore->flags |= UNCORE_HAS_FIFO;
/* clear out unclaimed reg detection bit */ if (intel_uncore_unclaimed_mmio(uncore))
drm_dbg(&i915->drm, "unclaimed mmio detected on uncore init, clearing\n");
return 0;
}
/* * We might have detected that some engines are fused off after we initialized * the forcewake domains. Prune them, to make sure they only reference existing * engines.
*/ void intel_uncore_prune_engine_fw_domains(struct intel_uncore *uncore, struct intel_gt *gt)
{ enum forcewake_domains fw_domains = uncore->fw_domains; enum forcewake_domain_id domain_id; int i;
if (!intel_uncore_has_forcewake(uncore) || GRAPHICS_VER(uncore->i915) < 11) return;
for (i = 0; i < I915_MAX_VCS; i++) {
domain_id = FW_DOMAIN_ID_MEDIA_VDBOX0 + i;
if (HAS_ENGINE(gt, _VCS(i))) continue;
/* * Starting with XeHP, the power well for an even-numbered * VDBOX is also used for shared units within the * media slice such as SFC. So even if the engine * itself is fused off, we still need to initialize * the forcewake domain if any of the other engines * in the same media slice are present.
*/ if (GRAPHICS_VER_FULL(uncore->i915) >= IP_VER(12, 55) && i % 2 == 0) { if ((i + 1 < I915_MAX_VCS) && HAS_ENGINE(gt, _VCS(i + 1))) continue;
if (HAS_ENGINE(gt, _VECS(i / 2))) continue;
}
if (fw_domains & BIT(domain_id))
fw_domain_fini(uncore, domain_id);
}
for (i = 0; i < I915_MAX_VECS; i++) {
domain_id = FW_DOMAIN_ID_MEDIA_VEBOX0 + i;
if (HAS_ENGINE(gt, _VECS(i))) continue;
if (fw_domains & BIT(domain_id))
fw_domain_fini(uncore, domain_id);
}
if ((fw_domains & BIT(FW_DOMAIN_ID_GSC)) && !HAS_ENGINE(gt, GSC0))
fw_domain_fini(uncore, FW_DOMAIN_ID_GSC);
}
/* * The driver-initiated FLR is the highest level of reset that we can trigger * from within the driver. It is different from the PCI FLR in that it doesn't * fully reset the SGUnit and doesn't modify the PCI config space and therefore * it doesn't require a re-enumeration of the PCI BARs. However, the * driver-initiated FLR does still cause a reset of both GT and display and a * memory wipe of local and stolen memory, so recovery would require a full HW * re-init and saving/restoring (or re-populating) the wiped memory. Since we * perform the FLR as the very last action before releasing access to the HW * during the driver release flow, we don't attempt recovery at all, because * if/when a new instance of i915 is bound to the device it will do a full * re-init anyway.
*/ staticvoid driver_initiated_flr(struct intel_uncore *uncore)
{ struct drm_i915_private *i915 = uncore->i915; unsignedint flr_timeout_ms; int ret;
drm_dbg(&i915->drm, "Triggering Driver-FLR\n");
/* * The specification recommends a 3 seconds FLR reset timeout. To be * cautious, we will extend this to 9 seconds, three times the specified * timeout.
*/
flr_timeout_ms = 9000;
/* * Make sure any pending FLR requests have cleared by waiting for the * FLR trigger bit to go to zero. Also clear GU_DEBUG's DRIVERFLR_STATUS * to make sure it's not still set from a prior attempt (it's a write to * clear bit). * Note that we should never be in a situation where a previous attempt * is still pending (unless the HW is totally dead), but better to be * safe in case something unexpected happens
*/
ret = intel_wait_for_register_fw(uncore, GU_CNTL, DRIVERFLR, 0, flr_timeout_ms, NULL); if (ret) {
drm_err(&i915->drm, "Failed to wait for Driver-FLR bit to clear! %d\n",
ret); return;
}
intel_uncore_write_fw(uncore, GU_DEBUG, DRIVERFLR_STATUS);
/* Trigger the actual Driver-FLR */
intel_uncore_rmw_fw(uncore, GU_CNTL, 0, DRIVERFLR);
/* Wait for hardware teardown to complete */
ret = intel_wait_for_register_fw(uncore, GU_CNTL,
DRIVERFLR, 0,
flr_timeout_ms, NULL); if (ret) {
drm_err(&i915->drm, "Driver-FLR-teardown wait completion failed! %d\n", ret); return;
}
/* Wait for hardware/firmware re-init to complete */
ret = intel_wait_for_register_fw(uncore, GU_DEBUG,
DRIVERFLR_STATUS, DRIVERFLR_STATUS,
flr_timeout_ms, NULL); if (ret) {
drm_err(&i915->drm, "Driver-FLR-reinit wait completion failed! %d\n", ret); return;
}
/* Clear sticky completion status */
intel_uncore_write_fw(uncore, GU_DEBUG, DRIVERFLR_STATUS);
}
/* Called via drm-managed action */ void intel_uncore_fini_mmio(struct drm_device *dev, void *data)
{ struct intel_uncore *uncore = data;
if (intel_uncore_has_forcewake(uncore)) {
iosf_mbi_punit_acquire();
iosf_mbi_unregister_pmic_bus_access_notifier_unlocked(
&uncore->pmic_bus_access_nb);
intel_uncore_forcewake_reset(uncore);
intel_uncore_fw_domains_fini(uncore);
iosf_mbi_punit_release();
}
if (intel_uncore_needs_flr_on_fini(uncore))
driver_initiated_flr(uncore);
}
/** * __intel_wait_for_register_fw - wait until register matches expected state * @uncore: the struct intel_uncore * @reg: the register to read * @mask: mask to apply to register value * @value: expected value * @fast_timeout_us: fast timeout in microsecond for atomic/tight wait * @slow_timeout_ms: slow timeout in millisecond * @out_value: optional placeholder to hold registry value * * This routine waits until the target register @reg contains the expected * @value after applying the @mask, i.e. it waits until :: * * (intel_uncore_read_fw(uncore, reg) & mask) == value * * Otherwise, the wait will timeout after @slow_timeout_ms milliseconds. * For atomic context @slow_timeout_ms must be zero and @fast_timeout_us * must be not larger than 20,0000 microseconds. * * Note that this routine assumes the caller holds forcewake asserted, it is * not suitable for very long waits. See intel_wait_for_register() if you * wish to wait without holding forcewake for the duration (i.e. you expect * the wait to be slow). * * Return: 0 if the register matches the desired condition, or -ETIMEDOUT.
*/ int __intel_wait_for_register_fw(struct intel_uncore *uncore,
i915_reg_t reg,
u32 mask,
u32 value, unsignedint fast_timeout_us, unsignedint slow_timeout_ms,
u32 *out_value)
{
u32 reg_value = 0; #define done (((reg_value = intel_uncore_read_fw(uncore, reg)) & mask) == value) int ret;
/* Catch any overuse of this function */
might_sleep_if(slow_timeout_ms);
GEM_BUG_ON(fast_timeout_us > 20000);
GEM_BUG_ON(!fast_timeout_us && !slow_timeout_ms);
ret = -ETIMEDOUT; if (fast_timeout_us && fast_timeout_us <= 20000)
ret = _wait_for_atomic(done, fast_timeout_us, 0); if (ret && slow_timeout_ms)
ret = wait_for(done, slow_timeout_ms);
if (out_value)
*out_value = reg_value;
return ret; #undef done
}
/** * __intel_wait_for_register - wait until register matches expected state * @uncore: the struct intel_uncore * @reg: the register to read * @mask: mask to apply to register value * @value: expected value * @fast_timeout_us: fast timeout in microsecond for atomic/tight wait * @slow_timeout_ms: slow timeout in millisecond * @out_value: optional placeholder to hold registry value * * This routine waits until the target register @reg contains the expected * @value after applying the @mask, i.e. it waits until :: * * (intel_uncore_read(uncore, reg) & mask) == value * * Otherwise, the wait will timeout after @timeout_ms milliseconds. * * Return: 0 if the register matches the desired condition, or -ETIMEDOUT.
*/ int __intel_wait_for_register(struct intel_uncore *uncore,
i915_reg_t reg,
u32 mask,
u32 value, unsignedint fast_timeout_us, unsignedint slow_timeout_ms,
u32 *out_value)
{ unsigned fw =
intel_uncore_forcewake_for_reg(uncore, reg, FW_REG_READ);
u32 reg_value; int ret;
spin_lock_irq(&uncore->debug->lock);
ret = check_for_unclaimed_mmio(uncore);
spin_unlock_irq(&uncore->debug->lock);
return ret;
}
bool
intel_uncore_arm_unclaimed_mmio_detection(struct intel_uncore *uncore)
{ bool ret = false;
if (drm_WARN_ON(&uncore->i915->drm, !uncore->debug)) returnfalse;
spin_lock_irq(&uncore->debug->lock);
if (unlikely(uncore->debug->unclaimed_mmio_check <= 0)) goto out;
if (unlikely(check_for_unclaimed_mmio(uncore))) { if (!uncore->i915->params.mmio_debug) {
drm_dbg(&uncore->i915->drm, "Unclaimed register detected, " "enabling oneshot unclaimed register reporting. " "Please use i915.mmio_debug=N for more information.\n");
uncore->i915->params.mmio_debug++;
}
uncore->debug->unclaimed_mmio_check--;
ret = true;
}
out:
spin_unlock_irq(&uncore->debug->lock);
return ret;
}
/** * intel_uncore_forcewake_for_reg - which forcewake domains are needed to access * a register * @uncore: pointer to struct intel_uncore * @reg: register in question * @op: operation bitmask of FW_REG_READ and/or FW_REG_WRITE * * Returns a set of forcewake domains required to be taken with for example * intel_uncore_forcewake_get for the specified register to be accessible in the * specified mode (read, write or read/write) with raw mmio accessors. * * NOTE: On Gen6 and Gen7 write forcewake domain (FORCEWAKE_RENDER) requires the * callers to do FIFO management on their own or risk losing writes.
*/ enum forcewake_domains
intel_uncore_forcewake_for_reg(struct intel_uncore *uncore,
i915_reg_t reg, unsignedint op)
{ enum forcewake_domains fw_domains = 0;
drm_WARN_ON(&uncore->i915->drm, !op);
if (!intel_uncore_has_forcewake(uncore)) return 0;
if (op & FW_REG_READ)
fw_domains = uncore->funcs.read_fw_domains(uncore, reg);
if (op & FW_REG_WRITE)
fw_domains |= uncore->funcs.write_fw_domains(uncore, reg);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.