selftest --r live shows failure in suspend tests when RPM wakelock is not acquired during suspend. This changes addresses below error : <4> [154.177535] RPM wakelock ref not held during HW access <4> [154.177575] WARNING: CPU: 4 PID: 5772 at drivers/gpu/drm/i915/intel_runtime_pm.h:113 fwtable_write32+0x240/0x320 [i915] <4> [154.177974] Modules linked in: i915(+) vgem drm_shmem_helper fuse snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_codec_generic ledtrig_audio mei_hdcp mei_pxp x86_pkg_temp_thermal coretemp crct10dif_pclmul crc32_pclmul ghash_clmulni_intel snd_intel_dspcfg snd_hda_codec snd_hwdep igc snd_hda_core ttm mei_me ptp snd_pcm prime_numbers mei i2c_i801 pps_core i2c_smbus intel_lpss_pci btusb btrtl btbcm btintel bluetooth ecdh_generic ecc [last unloaded: i915] <4> [154.178143] CPU: 4 PID: 5772 Comm: i915_selftest Tainted: G U 5.15.0-rc6-CI-Patchwork_21432+ #1 <4> [154.178154] Hardware name: ASUS System Product Name/TUF GAMING Z590-PLUS WIFI, BIOS 0811 04/06/2021 <4> [154.178160] RIP: 0010:fwtable_write32+0x240/0x320 [i915] <4> [154.178604] Code: 15 7b e1 0f 0b e9 34 fe ff ff 80 3d a9 89 31 00 00 0f 85 31 fe ff ff 48 c7 c7 88 9e 4f a0 c6 05 95 89 31 00 01 e8 c0 15 7b e1 <0f> 0b e9 17 fe ff ff 8b 05 0f 83 58 e2 85 c0 0f 85 8d 00 00 00 48 <4> [154.178614] RSP: 0018:ffffc900016279f0 EFLAGS: 00010286 <4> [154.178626] RAX: 0000000000000000 RBX: ffff888204fe0ee0 RCX: 0000000000000001 <4> [154.178634] RDX: 0000000080000001 RSI: ffffffff823142b5 RDI: 00000000ffffffff <4> [154.178641] RBP: 00000000000320f0 R08: 0000000000000000 R09: c0000000ffffcd5a <4> [154.178647] R10: 00000000000f8c90 R11: ffffc90001627808 R12: 0000000000000000 <4> [154.178654] R13: 0000000040000000 R14: ffffffffa04d12e0 R15: 0000000000000000 <4> [154.178660] FS: 00007f7390aa4c00(0000) GS:ffff88844f000000(0000) knlGS:0000000000000000 <4> [154.178669] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 <4> [154.178675] CR2: 000055bc40595028 CR3: 0000000204474005 CR4: 0000000000770ee0 <4> [154.178682] PKRU: 55555554 <4> [154.178687] Call Trace: <4> [154.178706] intel_pxp_fini_hw+0x23/0x30 [i915] <4> [154.179284] intel_pxp_suspend+0x1f/0x30 [i915] <4> [154.179807] live_gt_resume+0x5b/0x90 [i915] Changes since V2 : - Remove boolean in intel_pxp_runtime_preapre for non-pxp configs. Solves build error Changes since V2 : - Open-code intel_pxp_runtime_suspend - Daniele - Remove boolean in intel_pxp_runtime_preapre - Daniele Changes since V1 : - split the HW access parts in gt_suspend_late - Daniele - Remove default PXP configs Signed-off-by: Tejas Upadhyay <tejaskumarx.surendrakumar.upadhyay@intel.com> Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Fixes: 0cfab4cb3c4e ("drm/i915/pxp: Enable PXP power management") Signed-off-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20211117060321.3729343-1-tejaskumarx.surendrakumar.upadhyay@intel.com
409 lines
9.2 KiB
C
409 lines
9.2 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2019 Intel Corporation
|
|
*/
|
|
|
|
#include <linux/suspend.h>
|
|
|
|
#include "i915_drv.h"
|
|
#include "i915_params.h"
|
|
#include "intel_context.h"
|
|
#include "intel_engine_pm.h"
|
|
#include "intel_gt.h"
|
|
#include "intel_gt_clock_utils.h"
|
|
#include "intel_gt_pm.h"
|
|
#include "intel_gt_requests.h"
|
|
#include "intel_llc.h"
|
|
#include "intel_pm.h"
|
|
#include "intel_rc6.h"
|
|
#include "intel_rps.h"
|
|
#include "intel_wakeref.h"
|
|
#include "pxp/intel_pxp_pm.h"
|
|
|
|
#define I915_GT_SUSPEND_IDLE_TIMEOUT (HZ / 2)
|
|
|
|
static void user_forcewake(struct intel_gt *gt, bool suspend)
|
|
{
|
|
int count = atomic_read(>->user_wakeref);
|
|
|
|
/* Inside suspend/resume so single threaded, no races to worry about. */
|
|
if (likely(!count))
|
|
return;
|
|
|
|
intel_gt_pm_get(gt);
|
|
if (suspend) {
|
|
GEM_BUG_ON(count > atomic_read(>->wakeref.count));
|
|
atomic_sub(count, >->wakeref.count);
|
|
} else {
|
|
atomic_add(count, >->wakeref.count);
|
|
}
|
|
intel_gt_pm_put(gt);
|
|
}
|
|
|
|
static void runtime_begin(struct intel_gt *gt)
|
|
{
|
|
local_irq_disable();
|
|
write_seqcount_begin(>->stats.lock);
|
|
gt->stats.start = ktime_get();
|
|
gt->stats.active = true;
|
|
write_seqcount_end(>->stats.lock);
|
|
local_irq_enable();
|
|
}
|
|
|
|
static void runtime_end(struct intel_gt *gt)
|
|
{
|
|
local_irq_disable();
|
|
write_seqcount_begin(>->stats.lock);
|
|
gt->stats.active = false;
|
|
gt->stats.total =
|
|
ktime_add(gt->stats.total,
|
|
ktime_sub(ktime_get(), gt->stats.start));
|
|
write_seqcount_end(>->stats.lock);
|
|
local_irq_enable();
|
|
}
|
|
|
|
static int __gt_unpark(struct intel_wakeref *wf)
|
|
{
|
|
struct intel_gt *gt = container_of(wf, typeof(*gt), wakeref);
|
|
struct drm_i915_private *i915 = gt->i915;
|
|
|
|
GT_TRACE(gt, "\n");
|
|
|
|
/*
|
|
* It seems that the DMC likes to transition between the DC states a lot
|
|
* when there are no connected displays (no active power domains) during
|
|
* command submission.
|
|
*
|
|
* This activity has negative impact on the performance of the chip with
|
|
* huge latencies observed in the interrupt handler and elsewhere.
|
|
*
|
|
* Work around it by grabbing a GT IRQ power domain whilst there is any
|
|
* GT activity, preventing any DC state transitions.
|
|
*/
|
|
gt->awake = intel_display_power_get(i915, POWER_DOMAIN_GT_IRQ);
|
|
GEM_BUG_ON(!gt->awake);
|
|
|
|
intel_rc6_unpark(>->rc6);
|
|
intel_rps_unpark(>->rps);
|
|
i915_pmu_gt_unparked(i915);
|
|
intel_guc_busyness_unpark(gt);
|
|
|
|
intel_gt_unpark_requests(gt);
|
|
runtime_begin(gt);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __gt_park(struct intel_wakeref *wf)
|
|
{
|
|
struct intel_gt *gt = container_of(wf, typeof(*gt), wakeref);
|
|
intel_wakeref_t wakeref = fetch_and_zero(>->awake);
|
|
struct drm_i915_private *i915 = gt->i915;
|
|
|
|
GT_TRACE(gt, "\n");
|
|
|
|
runtime_end(gt);
|
|
intel_gt_park_requests(gt);
|
|
|
|
intel_guc_busyness_park(gt);
|
|
i915_vma_parked(gt);
|
|
i915_pmu_gt_parked(i915);
|
|
intel_rps_park(>->rps);
|
|
intel_rc6_park(>->rc6);
|
|
|
|
/* Everything switched off, flush any residual interrupt just in case */
|
|
intel_synchronize_irq(i915);
|
|
|
|
/* Defer dropping the display power well for 100ms, it's slow! */
|
|
GEM_BUG_ON(!wakeref);
|
|
intel_display_power_put_async(i915, POWER_DOMAIN_GT_IRQ, wakeref);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct intel_wakeref_ops wf_ops = {
|
|
.get = __gt_unpark,
|
|
.put = __gt_park,
|
|
};
|
|
|
|
void intel_gt_pm_init_early(struct intel_gt *gt)
|
|
{
|
|
intel_wakeref_init(>->wakeref, gt->uncore->rpm, &wf_ops);
|
|
seqcount_mutex_init(>->stats.lock, >->wakeref.mutex);
|
|
}
|
|
|
|
void intel_gt_pm_init(struct intel_gt *gt)
|
|
{
|
|
/*
|
|
* Enabling power-management should be "self-healing". If we cannot
|
|
* enable a feature, simply leave it disabled with a notice to the
|
|
* user.
|
|
*/
|
|
intel_rc6_init(>->rc6);
|
|
intel_rps_init(>->rps);
|
|
}
|
|
|
|
static bool reset_engines(struct intel_gt *gt)
|
|
{
|
|
if (INTEL_INFO(gt->i915)->gpu_reset_clobbers_display)
|
|
return false;
|
|
|
|
return __intel_gt_reset(gt, ALL_ENGINES) == 0;
|
|
}
|
|
|
|
static void gt_sanitize(struct intel_gt *gt, bool force)
|
|
{
|
|
struct intel_engine_cs *engine;
|
|
enum intel_engine_id id;
|
|
intel_wakeref_t wakeref;
|
|
|
|
GT_TRACE(gt, "force:%s", yesno(force));
|
|
|
|
/* Use a raw wakeref to avoid calling intel_display_power_get early */
|
|
wakeref = intel_runtime_pm_get(gt->uncore->rpm);
|
|
intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL);
|
|
|
|
intel_gt_check_clock_frequency(gt);
|
|
|
|
/*
|
|
* As we have just resumed the machine and woken the device up from
|
|
* deep PCI sleep (presumably D3_cold), assume the HW has been reset
|
|
* back to defaults, recovering from whatever wedged state we left it
|
|
* in and so worth trying to use the device once more.
|
|
*/
|
|
if (intel_gt_is_wedged(gt))
|
|
intel_gt_unset_wedged(gt);
|
|
|
|
for_each_engine(engine, gt, id)
|
|
if (engine->reset.prepare)
|
|
engine->reset.prepare(engine);
|
|
|
|
intel_uc_reset_prepare(>->uc);
|
|
|
|
for_each_engine(engine, gt, id)
|
|
if (engine->sanitize)
|
|
engine->sanitize(engine);
|
|
|
|
if (reset_engines(gt) || force) {
|
|
for_each_engine(engine, gt, id)
|
|
__intel_engine_reset(engine, false);
|
|
}
|
|
|
|
intel_uc_reset(>->uc, false);
|
|
|
|
for_each_engine(engine, gt, id)
|
|
if (engine->reset.finish)
|
|
engine->reset.finish(engine);
|
|
|
|
intel_rps_sanitize(>->rps);
|
|
|
|
intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL);
|
|
intel_runtime_pm_put(gt->uncore->rpm, wakeref);
|
|
}
|
|
|
|
void intel_gt_pm_fini(struct intel_gt *gt)
|
|
{
|
|
intel_rc6_fini(>->rc6);
|
|
}
|
|
|
|
int intel_gt_resume(struct intel_gt *gt)
|
|
{
|
|
struct intel_engine_cs *engine;
|
|
enum intel_engine_id id;
|
|
int err;
|
|
|
|
err = intel_gt_has_unrecoverable_error(gt);
|
|
if (err)
|
|
return err;
|
|
|
|
GT_TRACE(gt, "\n");
|
|
|
|
/*
|
|
* After resume, we may need to poke into the pinned kernel
|
|
* contexts to paper over any damage caused by the sudden suspend.
|
|
* Only the kernel contexts should remain pinned over suspend,
|
|
* allowing us to fixup the user contexts on their first pin.
|
|
*/
|
|
gt_sanitize(gt, true);
|
|
|
|
intel_gt_pm_get(gt);
|
|
|
|
intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL);
|
|
intel_rc6_sanitize(>->rc6);
|
|
if (intel_gt_is_wedged(gt)) {
|
|
err = -EIO;
|
|
goto out_fw;
|
|
}
|
|
|
|
/* Only when the HW is re-initialised, can we replay the requests */
|
|
err = intel_gt_init_hw(gt);
|
|
if (err) {
|
|
i915_probe_error(gt->i915,
|
|
"Failed to initialize GPU, declaring it wedged!\n");
|
|
goto err_wedged;
|
|
}
|
|
|
|
intel_uc_reset_finish(>->uc);
|
|
|
|
intel_rps_enable(>->rps);
|
|
intel_llc_enable(>->llc);
|
|
|
|
for_each_engine(engine, gt, id) {
|
|
intel_engine_pm_get(engine);
|
|
|
|
engine->serial++; /* kernel context lost */
|
|
err = intel_engine_resume(engine);
|
|
|
|
intel_engine_pm_put(engine);
|
|
if (err) {
|
|
drm_err(>->i915->drm,
|
|
"Failed to restart %s (%d)\n",
|
|
engine->name, err);
|
|
goto err_wedged;
|
|
}
|
|
}
|
|
|
|
intel_rc6_enable(>->rc6);
|
|
|
|
intel_uc_resume(>->uc);
|
|
|
|
intel_pxp_resume(>->pxp);
|
|
|
|
user_forcewake(gt, false);
|
|
|
|
out_fw:
|
|
intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL);
|
|
intel_gt_pm_put(gt);
|
|
return err;
|
|
|
|
err_wedged:
|
|
intel_gt_set_wedged(gt);
|
|
goto out_fw;
|
|
}
|
|
|
|
static void wait_for_suspend(struct intel_gt *gt)
|
|
{
|
|
if (!intel_gt_pm_is_awake(gt))
|
|
return;
|
|
|
|
if (intel_gt_wait_for_idle(gt, I915_GT_SUSPEND_IDLE_TIMEOUT) == -ETIME) {
|
|
/*
|
|
* Forcibly cancel outstanding work and leave
|
|
* the gpu quiet.
|
|
*/
|
|
intel_gt_set_wedged(gt);
|
|
intel_gt_retire_requests(gt);
|
|
}
|
|
|
|
intel_gt_pm_wait_for_idle(gt);
|
|
}
|
|
|
|
void intel_gt_suspend_prepare(struct intel_gt *gt)
|
|
{
|
|
user_forcewake(gt, true);
|
|
wait_for_suspend(gt);
|
|
|
|
intel_pxp_suspend_prepare(>->pxp);
|
|
}
|
|
|
|
static suspend_state_t pm_suspend_target(void)
|
|
{
|
|
#if IS_ENABLED(CONFIG_SUSPEND) && IS_ENABLED(CONFIG_PM_SLEEP)
|
|
return pm_suspend_target_state;
|
|
#else
|
|
return PM_SUSPEND_TO_IDLE;
|
|
#endif
|
|
}
|
|
|
|
void intel_gt_suspend_late(struct intel_gt *gt)
|
|
{
|
|
intel_wakeref_t wakeref;
|
|
|
|
/* We expect to be idle already; but also want to be independent */
|
|
wait_for_suspend(gt);
|
|
|
|
if (is_mock_gt(gt))
|
|
return;
|
|
|
|
GEM_BUG_ON(gt->awake);
|
|
|
|
intel_uc_suspend(>->uc);
|
|
intel_pxp_suspend(>->pxp);
|
|
|
|
/*
|
|
* On disabling the device, we want to turn off HW access to memory
|
|
* that we no longer own.
|
|
*
|
|
* However, not all suspend-states disable the device. S0 (s2idle)
|
|
* is effectively runtime-suspend, the device is left powered on
|
|
* but needs to be put into a low power state. We need to keep
|
|
* powermanagement enabled, but we also retain system state and so
|
|
* it remains safe to keep on using our allocated memory.
|
|
*/
|
|
if (pm_suspend_target() == PM_SUSPEND_TO_IDLE)
|
|
return;
|
|
|
|
with_intel_runtime_pm(gt->uncore->rpm, wakeref) {
|
|
intel_rps_disable(>->rps);
|
|
intel_rc6_disable(>->rc6);
|
|
intel_llc_disable(>->llc);
|
|
}
|
|
|
|
gt_sanitize(gt, false);
|
|
|
|
GT_TRACE(gt, "\n");
|
|
}
|
|
|
|
void intel_gt_runtime_suspend(struct intel_gt *gt)
|
|
{
|
|
intel_pxp_runtime_suspend(>->pxp);
|
|
intel_uc_runtime_suspend(>->uc);
|
|
|
|
GT_TRACE(gt, "\n");
|
|
}
|
|
|
|
int intel_gt_runtime_resume(struct intel_gt *gt)
|
|
{
|
|
int ret;
|
|
|
|
GT_TRACE(gt, "\n");
|
|
intel_gt_init_swizzling(gt);
|
|
intel_ggtt_restore_fences(gt->ggtt);
|
|
|
|
ret = intel_uc_runtime_resume(>->uc);
|
|
if (ret)
|
|
return ret;
|
|
|
|
intel_pxp_runtime_resume(>->pxp);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static ktime_t __intel_gt_get_awake_time(const struct intel_gt *gt)
|
|
{
|
|
ktime_t total = gt->stats.total;
|
|
|
|
if (gt->stats.active)
|
|
total = ktime_add(total,
|
|
ktime_sub(ktime_get(), gt->stats.start));
|
|
|
|
return total;
|
|
}
|
|
|
|
ktime_t intel_gt_get_awake_time(const struct intel_gt *gt)
|
|
{
|
|
unsigned int seq;
|
|
ktime_t total;
|
|
|
|
do {
|
|
seq = read_seqcount_begin(>->stats.lock);
|
|
total = __intel_gt_get_awake_time(gt);
|
|
} while (read_seqcount_retry(>->stats.lock, seq));
|
|
|
|
return total;
|
|
}
|
|
|
|
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
|
|
#include "selftest_gt_pm.c"
|
|
#endif
|