From patchwork Mon Sep 18 10:11:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: sagar.a.kamble@intel.com X-Patchwork-Id: 9956275 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4059A601E9 for ; Mon, 18 Sep 2017 10:08:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F95F288D2 for ; Mon, 18 Sep 2017 10:08:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 248AF28B2F; Mon, 18 Sep 2017 10:08:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 690472841D for ; Mon, 18 Sep 2017 10:08:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 742796E315; Mon, 18 Sep 2017 10:08:20 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 14FE26E305 for ; Mon, 18 Sep 2017 10:08:14 +0000 (UTC) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP; 18 Sep 2017 03:08:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.42,412,1500966000"; d="scan'208";a="901282331" Received: from sakamble-desktop.iind.intel.com ([10.223.26.118]) by FMSMGA003.fm.intel.com with ESMTP; 18 Sep 2017 03:08:12 -0700 From: Sagar Arun Kamble To: intel-gfx@lists.freedesktop.org Date: Mon, 18 Sep 2017 15:41:27 +0530 Message-Id: <1505729491-26148-4-git-send-email-sagar.a.kamble@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505729491-26148-1-git-send-email-sagar.a.kamble@intel.com> References: <1505729491-26148-1-git-send-email-sagar.a.kamble@intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH 4/8] drm/i915/guc: Fix GuC interaction in reset/suspend scenarios X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP Pass intel_guc to intel_guc_suspend/resume instead of drm_i915_private. guc_ggtt_invalidate/guc_interrupts should be disabled towards end of reset/suspend post GuC suspension as these are setup back again during recovery/resume. Prepared helpers intel_guc_pause and intel_guc_unpause that will do teardown/bringup of this setup along with suspension/resumption of GuC if loaded. These helpers can then be used along the system or runtime suspend/resume paths as applicable. Currently post system resume, since GuC is loaded completely system_resume function for GuC is doing nothing. We rely on the setup happening in intel_uc_init_hw path. During runtime_suspend we will call intel_guc_pause helper. Another helper added is intel_guc_reset_prepare, this will make sure that disabling of ggtt_invalidate and GuC interrupts happens prior to reset and updates the firmware load status to PENDING. v2: Updated commit message. Added note about skipped call to intel_guc_system_resume. guc_enable/disable_communication was moved to earlier patch so corresponding rebase. (Michal Wajdeczko) v3: Introduction of intel_uc_runtime/system_suspend/resume. Updated changes for enable/disable_communication. v4: Squashed change to update parameters of intel_guc_suspend/resume from earlier patch. v5: Rebase as intel_guc.h is removed. Updated intel_uc_runtime_resume and intel_uc_system_resume as guc_enable_communication should happen prior to resuming the uc. Thanks to trybot for catching this. (Sagar) Cc: Michal Wajdeczko Cc: MichaƂ Winiarski Signed-off-by: Sagar Arun Kamble --- drivers/gpu/drm/i915/i915_drv.c | 15 +++- drivers/gpu/drm/i915/i915_gem.c | 4 +- drivers/gpu/drm/i915/i915_guc_submission.c | 52 ------------ drivers/gpu/drm/i915/intel_guc.c | 129 +++++++++++++++++++++++++++++ drivers/gpu/drm/i915/intel_uc.c | 53 ++++++++++++ drivers/gpu/drm/i915/intel_uc.h | 12 ++- 6 files changed, 206 insertions(+), 59 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c index 5c111ea..f41f0e0 100644 --- a/drivers/gpu/drm/i915/i915_drv.c +++ b/drivers/gpu/drm/i915/i915_drv.c @@ -1684,6 +1684,11 @@ static int i915_drm_resume(struct drm_device *dev) drm_mode_config_reset(dev); + /* + * NB: Full gem reinitialization is being done during i915_drm_resume, + * hence intel_guc_system_resume will be of no use. If full + * reinitialization is avoided, need to call intel_guc_system_resume. + */ mutex_lock(&dev->struct_mutex); if (i915_gem_init_hw(dev_priv)) { DRM_ERROR("failed to re-initialize GPU, declaring wedged!\n"); @@ -1691,8 +1696,6 @@ static int i915_drm_resume(struct drm_device *dev) } mutex_unlock(&dev->struct_mutex); - intel_guc_resume(dev_priv); - intel_modeset_init_hw(dev); spin_lock_irq(&dev_priv->irq_lock); @@ -2493,7 +2496,7 @@ static int intel_runtime_suspend(struct device *kdev) */ i915_gem_runtime_suspend(dev_priv); - intel_guc_suspend(dev_priv); + intel_uc_runtime_suspend(dev_priv); intel_runtime_pm_disable_interrupts(dev_priv); @@ -2578,7 +2581,11 @@ static int intel_runtime_resume(struct device *kdev) if (intel_uncore_unclaimed_mmio(dev_priv)) DRM_DEBUG_DRIVER("Unclaimed access during suspend, bios?\n"); - intel_guc_resume(dev_priv); + ret = intel_uc_runtime_resume(dev_priv); + if (ret) { + DRM_ERROR("uc runtime resume failed (%d)\n", ret); + return ret; + } if (IS_GEN9_LP(dev_priv)) { bxt_disable_dc9(dev_priv); diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index 3250dfa..ae97a6f 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -2847,6 +2847,8 @@ int i915_gem_reset_prepare(struct drm_i915_private *dev_priv) i915_gem_revoke_fences(dev_priv); + intel_uc_reset_prepare(dev_priv); + return err; } @@ -4575,7 +4577,7 @@ int i915_gem_suspend(struct drm_i915_private *dev_priv) i915_gem_contexts_lost(dev_priv); mutex_unlock(&dev->struct_mutex); - intel_guc_suspend(dev_priv); + intel_uc_system_suspend(dev_priv); cancel_delayed_work_sync(&dev_priv->gpu_error.hangcheck_work); cancel_delayed_work_sync(&dev_priv->gt.retire_work); diff --git a/drivers/gpu/drm/i915/i915_guc_submission.c b/drivers/gpu/drm/i915/i915_guc_submission.c index 3f9d227..f527963 100644 --- a/drivers/gpu/drm/i915/i915_guc_submission.c +++ b/drivers/gpu/drm/i915/i915_guc_submission.c @@ -1205,55 +1205,3 @@ void i915_guc_submission_disable(struct drm_i915_private *dev_priv) guc_client_free(guc->execbuf_client); guc->execbuf_client = NULL; } - -/** - * intel_guc_suspend() - notify GuC entering suspend state - * @dev_priv: i915 device private - */ -int intel_guc_suspend(struct drm_i915_private *dev_priv) -{ - struct intel_guc *guc = &dev_priv->guc; - struct i915_gem_context *ctx; - u32 data[3]; - - if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) - return 0; - - gen9_disable_guc_interrupts(dev_priv); - - ctx = dev_priv->kernel_context; - - data[0] = INTEL_GUC_ACTION_ENTER_S_STATE; - /* any value greater than GUC_POWER_D0 */ - data[1] = GUC_POWER_D1; - /* first page is shared data with GuC */ - data[2] = guc_ggtt_offset(ctx->engine[RCS].state) + LRC_GUCSHR_PN * PAGE_SIZE; - - return intel_guc_send(guc, data, ARRAY_SIZE(data)); -} - -/** - * intel_guc_resume() - notify GuC resuming from suspend state - * @dev_priv: i915 device private - */ -int intel_guc_resume(struct drm_i915_private *dev_priv) -{ - struct intel_guc *guc = &dev_priv->guc; - struct i915_gem_context *ctx; - u32 data[3]; - - if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) - return 0; - - if (i915.guc_log_level >= 0) - gen9_enable_guc_interrupts(dev_priv); - - ctx = dev_priv->kernel_context; - - data[0] = INTEL_GUC_ACTION_EXIT_S_STATE; - data[1] = GUC_POWER_D0; - /* first page is shared data with GuC */ - data[2] = guc_ggtt_offset(ctx->engine[RCS].state) + LRC_GUCSHR_PN * PAGE_SIZE; - - return intel_guc_send(guc, data, ARRAY_SIZE(data)); -} diff --git a/drivers/gpu/drm/i915/intel_guc.c b/drivers/gpu/drm/i915/intel_guc.c index d8b3559..792a302 100644 --- a/drivers/gpu/drm/i915/intel_guc.c +++ b/drivers/gpu/drm/i915/intel_guc.c @@ -144,3 +144,132 @@ int intel_guc_sample_forcewake(struct intel_guc *guc) return intel_guc_send(guc, action, ARRAY_SIZE(action)); } + +/** + * intel_guc_suspend() - notify GuC entering suspend state + */ +static int intel_guc_suspend(struct intel_guc *guc) +{ + struct drm_i915_private *dev_priv = guc_to_i915(guc); + struct i915_gem_context *ctx; + u32 data[3]; + + if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) + return 0; + + ctx = dev_priv->kernel_context; + + data[0] = INTEL_GUC_ACTION_ENTER_S_STATE; + /* any value greater than GUC_POWER_D0 */ + data[1] = GUC_POWER_D1; + /* first page is shared data with GuC */ + data[2] = guc_ggtt_offset(ctx->engine[RCS].state); + + return intel_guc_send(guc, data, ARRAY_SIZE(data)); +} + +/** + * intel_guc_resume() - notify GuC resuming from suspend state + */ +static int intel_guc_resume(struct intel_guc *guc) +{ + struct drm_i915_private *dev_priv = guc_to_i915(guc); + struct i915_gem_context *ctx; + u32 data[3]; + + if (guc->fw.load_status != INTEL_UC_FIRMWARE_SUCCESS) + return 0; + + ctx = dev_priv->kernel_context; + + data[0] = INTEL_GUC_ACTION_EXIT_S_STATE; + data[1] = GUC_POWER_D0; + /* first page is shared data with GuC */ + data[2] = guc_ggtt_offset(ctx->engine[RCS].state); + + return intel_guc_send(guc, data, ARRAY_SIZE(data)); +} + +static void intel_guc_sanitize(struct intel_guc *guc) +{ + struct drm_i915_private *dev_priv = guc_to_i915(guc); + + i915_ggtt_disable_guc(dev_priv); + gen9_disable_guc_interrupts(dev_priv); +} + +void intel_guc_reset_prepare(struct intel_guc *guc) +{ + if (!i915.enable_guc_loading) + return; + + intel_guc_sanitize(guc); + guc->fw.load_status = INTEL_UC_FIRMWARE_PENDING; +} + +static int intel_guc_pause(struct intel_guc *guc) +{ + int ret = 0; + + ret = intel_guc_suspend(guc); + intel_guc_sanitize(guc); + + return ret; +} + +static int intel_guc_unpause(struct intel_guc *guc) +{ + struct drm_i915_private *dev_priv = guc_to_i915(guc); + int ret = 0; + + if (i915.guc_log_level >= 0) + gen9_enable_guc_interrupts(dev_priv); + i915_ggtt_enable_guc(dev_priv); + ret = intel_guc_resume(guc); + + return ret; +} + +int intel_guc_runtime_suspend(struct intel_guc *guc) +{ + if (!i915.enable_guc_loading) + return 0; + + return intel_guc_pause(guc); +} + +int intel_guc_runtime_resume(struct intel_guc *guc) +{ + if (!i915.enable_guc_loading) + return 0; + + return intel_guc_unpause(guc); +} + +int intel_guc_system_suspend(struct intel_guc *guc) +{ + int ret = 0; + + if (!i915.enable_guc_loading) + return ret; + + ret = intel_guc_pause(guc); + guc->fw.load_status = INTEL_UC_FIRMWARE_PENDING; + + return ret; +} + +int intel_guc_system_resume(struct intel_guc *guc) +{ + int ret = 0; + + if (!i915.enable_guc_loading) + return ret; + + /* + * Placeholder for GuC resume from system suspend/freeze states. + * Currently full reinitialization of GEM and GuC happens along + * these paths, Hence this function is doing nothing. + */ + return ret; +} diff --git a/drivers/gpu/drm/i915/intel_uc.c b/drivers/gpu/drm/i915/intel_uc.c index f7c5112..aa1310b 100644 --- a/drivers/gpu/drm/i915/intel_uc.c +++ b/drivers/gpu/drm/i915/intel_uc.c @@ -419,3 +419,56 @@ void intel_uc_fini_hw(struct drm_i915_private *dev_priv) i915_ggtt_disable_guc(dev_priv); } + +void intel_uc_reset_prepare(struct drm_i915_private *dev_priv) +{ + intel_guc_reset_prepare(&dev_priv->guc); + guc_disable_communication(&dev_priv->guc); +} + +void intel_uc_runtime_suspend(struct drm_i915_private *dev_priv) +{ + intel_guc_runtime_suspend(&dev_priv->guc); + guc_disable_communication(&dev_priv->guc); +} + +int intel_uc_runtime_resume(struct drm_i915_private *dev_priv) +{ + int ret; + + ret = guc_enable_communication(&dev_priv->guc); + if (ret) { + DRM_ERROR("GuC communication enable failed\n"); + return ret; + } + ret = intel_guc_runtime_resume(&dev_priv->guc); + if (ret) { + DRM_ERROR("GuC resume failed\n"); + return ret; + } + return 0; +} + +void intel_uc_system_suspend(struct drm_i915_private *dev_priv) +{ + intel_guc_system_suspend(&dev_priv->guc); + guc_disable_communication(&dev_priv->guc); +} + +int intel_uc_system_resume(struct drm_i915_private *dev_priv) +{ + int ret; + + ret = guc_enable_communication(&dev_priv->guc); + if (ret) { + DRM_ERROR("GuC communication enable failed\n"); + return ret; + } + ret = intel_guc_system_resume(&dev_priv->guc); + if (ret) { + DRM_ERROR("GuC resume failed\n"); + return ret; + } + return 0; + +} diff --git a/drivers/gpu/drm/i915/intel_uc.h b/drivers/gpu/drm/i915/intel_uc.h index fea206b..5077619 100644 --- a/drivers/gpu/drm/i915/intel_uc.h +++ b/drivers/gpu/drm/i915/intel_uc.h @@ -208,6 +208,11 @@ struct intel_huc { void intel_uc_fini_fw(struct drm_i915_private *dev_priv); int intel_uc_init_hw(struct drm_i915_private *dev_priv); void intel_uc_fini_hw(struct drm_i915_private *dev_priv); +void intel_uc_reset_prepare(struct drm_i915_private *dev_priv); +void intel_uc_runtime_suspend(struct drm_i915_private *dev_priv); +int intel_uc_runtime_resume(struct drm_i915_private *dev_priv); +void intel_uc_system_suspend(struct drm_i915_private *dev_priv); +int intel_uc_system_resume(struct drm_i915_private *dev_priv); static inline int intel_guc_send(struct intel_guc *guc, const u32 *action, u32 len) { @@ -225,12 +230,15 @@ static inline void intel_guc_notify(struct intel_guc *guc) void intel_guc_init_send_regs(struct intel_guc *guc); int intel_guc_send_mmio(struct intel_guc *guc, const u32 *action, u32 len); int intel_guc_sample_forcewake(struct intel_guc *guc); +void intel_guc_reset_prepare(struct intel_guc *guc); +int intel_guc_runtime_suspend(struct intel_guc *guc); +int intel_guc_runtime_resume(struct intel_guc *guc); +int intel_guc_system_suspend(struct intel_guc *guc); +int intel_guc_system_resume(struct intel_guc *guc); /* intel_guc_loader.c */ int intel_guc_select_fw(struct intel_guc *guc); int intel_guc_init_hw(struct intel_guc *guc); -int intel_guc_suspend(struct drm_i915_private *dev_priv); -int intel_guc_resume(struct drm_i915_private *dev_priv); u32 intel_guc_wopcm_size(struct drm_i915_private *dev_priv); /* i915_guc_submission.c */