From patchwork Tue Mar 11 19:56:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 14012654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 174C3C282EC for ; Tue, 11 Mar 2025 19:56:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8887610E1B9; Tue, 11 Mar 2025 19:56:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="nW5UGi+B"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id 961FE10E1B9 for ; Tue, 11 Mar 2025 19:56:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741722990; x=1773258990; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uHrI6YEWgQ4aWaf9f79q2MiD8kxneVhidZILtrsXBoQ=; b=nW5UGi+BfW+/nehOvtnF1VJGkB72ZALl5vrrr94zaTQRarM+Su7DB18X 07dEUV9qRMeVA2vt0YaF8ybfppcFSR0qISdRSG0M0wuCC12uS4CH+Bm8d 3kbk6SvhvtQEswvcR3EHxRRuoehcNG8jb0IBfevvQ1MVjP/hGji4QjcFD feze5LgkSlrbmtThf6byMgHCQo++8/V6/UlaAf4znJcfOXrj9caIw+2KX jLDFEiTUR24H9hJrnVZ+N86SM+qnY3/sPsmQ/n+GurUOz2u5RU1KeYkSR UcYt86hY9RDeA5iTwJ2bW1QM9xgybWDMe5E+KF7rkj0eVNe9ioUmdn9UO A==; X-CSE-ConnectionGUID: /irdYRsRSsGH0t/lZbEtrw== X-CSE-MsgGUID: EVA0Qu7eRdWaSU9sJIiFkQ== X-IronPort-AV: E=McAfee;i="6700,10204,11370"; a="60183851" X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="60183851" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2025 12:56:30 -0700 X-CSE-ConnectionGUID: +ee3yOddSC++kENEFR+e2g== X-CSE-MsgGUID: Eahs+5kGRzORzKjDWKelVA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="125617190" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orviesa005.jf.intel.com with SMTP; 11 Mar 2025 12:56:26 -0700 Received: by stinkbox (sSMTP sendmail emulation); Tue, 11 Mar 2025 21:56:27 +0200 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Cc: Rodrigo Vivi Subject: [PATCH v2 1/6] drm/i915/pm: Simplify pm hook documentation Date: Tue, 11 Mar 2025 21:56:19 +0200 Message-ID: <20250311195624.22420-2-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250311195624.22420-1-ville.syrjala@linux.intel.com> References: <20250311195624.22420-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" From: Ville Syrjälä Stop spelling out each variant of the hook ("" vs. "_late" vs. "_early") and just say eg. "@thaw*" to indicate all of them. Avoids having to update the docs whenever we start/stop using one of the variants. Reviewed-by: Rodrigo Vivi Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/i915/i915_driver.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index ce3cc93ea211..be232caef9df 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1664,18 +1664,18 @@ const struct dev_pm_ops i915_pm_ops = { /* * S4 event handlers - * @freeze, @freeze_late : called (1) before creating the - * hibernation image [PMSG_FREEZE] and - * (2) after rebooting, before restoring - * the image [PMSG_QUIESCE] - * @thaw, @thaw_early : called (1) after creating the hibernation - * image, before writing it [PMSG_THAW] - * and (2) after failing to create or - * restore the image [PMSG_RECOVER] - * @poweroff, @poweroff_late: called after writing the hibernation - * image, before rebooting [PMSG_HIBERNATE] - * @restore, @restore_early : called after rebooting and restoring the - * hibernation image [PMSG_RESTORE] + * @freeze* : called (1) before creating the + * hibernation image [PMSG_FREEZE] and + * (2) after rebooting, before restoring + * the image [PMSG_QUIESCE] + * @thaw* : called (1) after creating the hibernation + * image, before writing it [PMSG_THAW] + * and (2) after failing to create or + * restore the image [PMSG_RECOVER] + * @poweroff* : called after writing the hibernation + * image, before rebooting [PMSG_HIBERNATE] + * @restore* : called after rebooting and restoring the + * hibernation image [PMSG_RESTORE] */ .freeze = i915_pm_freeze, .freeze_late = i915_pm_freeze_late, From patchwork Tue Mar 11 19:56:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 14012655 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1252FC282EC for ; Tue, 11 Mar 2025 19:56:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 937D710E658; Tue, 11 Mar 2025 19:56:34 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="Xyf8NN/F"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE33810E658 for ; Tue, 11 Mar 2025 19:56:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741722993; x=1773258993; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WVxReDaIh2Ofs7OIhU0ypvXOBMDjIR8LI0is+TMiaCI=; b=Xyf8NN/FiP7MszqBantvYNkT3r5yiwqXZDQbl4gzPIRifTkkPU1WFqXX 2wIexZP7CxWHrEcLUOIoiLBltNAOuJRcBIis1EguCh68WAOlPQ47LsKfK Zu4HmBHljKusbQKaB2TdS15kPaj9wmHnaWPfdOfAWUGkpbqqMpPJs8cgT /7R8RyFQfnAnSAf4+7PfllRo2YkeoUoJcANzuI1PFAnkSgeSTpwjPIRL7 D1Vl9FEpjpdlaQ13m4lyH0PxMaGyApNYJKBY2m62BzfzteW2lbYySwE0j Ec+MI3Oe05RZzN4t+Em3nGIl9vOuO5Rcvd8cF5nU0Iyj76LMgnpi3A2c/ A==; X-CSE-ConnectionGUID: XHj6wG0jT4CpH7osCP9zNw== X-CSE-MsgGUID: x7pq1warS4amkHMtFPXMRw== X-IronPort-AV: E=McAfee;i="6700,10204,11370"; a="60183855" X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="60183855" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2025 12:56:33 -0700 X-CSE-ConnectionGUID: YEwnLSCTSY2DwGfYs6Dugw== X-CSE-MsgGUID: gHC4L+YvTzSA4IHq6q9JkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="125617210" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orviesa005.jf.intel.com with SMTP; 11 Mar 2025 12:56:29 -0700 Received: by stinkbox (sSMTP sendmail emulation); Tue, 11 Mar 2025 21:56:30 +0200 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Cc: Rodrigo Vivi Subject: [PATCH v2 2/6] drm/i915/pm: Hoist pci_save_state()+pci_set_power_state() to the end of pm _late() hook Date: Tue, 11 Mar 2025 21:56:20 +0200 Message-ID: <20250311195624.22420-3-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250311195624.22420-1-ville.syrjala@linux.intel.com> References: <20250311195624.22420-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" From: Ville Syrjälä drivers/pci does the pci_save_state()+pci_set_power_state() from the _noirq() pm hooks. Move our manual calls (needed for the hibernate vs. D3 workaround with buggy BIOSes) towards that same point. We currently have no _noirq() hooks, so end of _late() hooks is the best we can do right now. Cc: Rodrigo Vivi Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/i915/i915_driver.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index be232caef9df..e06f2956382c 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1045,7 +1045,6 @@ static int i915_drm_suspend(struct drm_device *dev) { struct drm_i915_private *dev_priv = to_i915(dev); struct intel_display *display = &dev_priv->display; - struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); pci_power_t opregion_target_state; disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); @@ -1059,8 +1058,6 @@ static int i915_drm_suspend(struct drm_device *dev) intel_display_driver_disable_user_access(display); } - pci_save_state(pdev); - intel_display_driver_suspend(display); intel_irq_suspend(dev_priv); @@ -1117,10 +1114,16 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) drm_err(&dev_priv->drm, "Suspend complete failed: %d\n", ret); intel_display_power_resume_early(display); - goto out; + goto fail; } + enable_rpm_wakeref_asserts(rpm); + + if (!dev_priv->uncore.user_forcewake_count) + intel_runtime_pm_driver_release(rpm); + pci_disable_device(pdev); + /* * During hibernation on some platforms the BIOS may try to access * the device even though it's already in D3 and hang the machine. So @@ -1132,11 +1135,17 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) * Lenovo Thinkpad X301, X61s, X60, T60, X41 * Fujitsu FSC S7110 * Acer Aspire 1830T + * + * pci_save_state() prevents drivers/pci from + * automagically putting the device into D3. */ + pci_save_state(pdev); if (!(hibernation && GRAPHICS_VER(dev_priv) < 6)) pci_set_power_state(pdev, PCI_D3hot); -out: + return 0; + +fail: enable_rpm_wakeref_asserts(rpm); if (!dev_priv->uncore.user_forcewake_count) intel_runtime_pm_driver_release(rpm); From patchwork Tue Mar 11 19:56:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 14012656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EE4B1C282EC for ; Tue, 11 Mar 2025 19:56:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 76B5710E674; Tue, 11 Mar 2025 19:56:37 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="JnqDQdVl"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id E517410E674 for ; Tue, 11 Mar 2025 19:56:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741722997; x=1773258997; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=LFYV2y/FsXxKCK5k99PiIl+3Wk5WTBGIw27Fqd8QZW0=; b=JnqDQdVlE0tdSy0NWeMy0zW+I2KBxiXPo2SuAam++L74UTT7o/oMdt8V yseo3EBiw2cNl6nER5W7fBNKRlAdlVhhzC8hY3rXBthjj7XQFzqQ8XWV6 106NNXWvmVMcObl8KRrZJePvyLuDIInKBJRcErJx3zZ0MoxMFJQeu7tSf 7bVpT64CcSiarZyRXuiLfoG18beh7G/bhBYICHuChMQ0Yoq1BkIts8bPq bXFdbMUkqkfM7RFvwjHUgEQ7xycOaCwcbmSmux2FhDercrBux323a4eDS MV489A5cFZ1OqM2LVxv3Xo3cfGkxcEACYITLiam5z1xwHVeZaVPgD4prN g==; X-CSE-ConnectionGUID: LpwbNWsQRoWWrTkO/2We9w== X-CSE-MsgGUID: /GxLJu9tSgOOwuDuq2uo8A== X-IronPort-AV: E=McAfee;i="6700,10204,11370"; a="60183857" X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="60183857" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2025 12:56:36 -0700 X-CSE-ConnectionGUID: W3qg50nERwaMMF6OMdpmsQ== X-CSE-MsgGUID: JuYqYSj3S+qyCa7YYzsCQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="125617223" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orviesa005.jf.intel.com with SMTP; 11 Mar 2025 12:56:32 -0700 Received: by stinkbox (sSMTP sendmail emulation); Tue, 11 Mar 2025 21:56:33 +0200 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Cc: Rodrigo Vivi Subject: [PATCH v2 3/6] drm/i915/pm: Move the hibernate+D3 quirk stuff into noirq() pm hooks Date: Tue, 11 Mar 2025 21:56:21 +0200 Message-ID: <20250311195624.22420-4-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250311195624.22420-1-ville.syrjala@linux.intel.com> References: <20250311195624.22420-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" From: Ville Syrjälä If the driver doesn't call pci_save_state() drivers/pci will normally save+power manage the device from the _noirq() pm hooks. We can't let that happen as some old BIOSes fail to hibernate when the device is in D3. However, we can get very close to the standard behaviour by doing our explicit pci_save_state() and pci_set_power_state() stuff from driver provided _noirq() hooks. This results in a change of behaviour where we no longer go into D3 at the end of freeze_late, so when it comes time to thaw() we'll already be in D0, and thus we can drop the explicit pci_set_power_state(D0) call. Presumably switcheroo suspend will want to go into D3 so call the _noirq() stuff from the switcheroo suspend hook, and since we dropped the pci_set_power_state(D0) from resume_early() we'll need to add one back into the switcheroo resume hook. Cc: Rodrigo Vivi Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/i915/i915_driver.c | 76 ++++++++++++++++++++---------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index e06f2956382c..995205e24ebf 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1124,6 +1124,21 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) pci_disable_device(pdev); + return 0; + +fail: + enable_rpm_wakeref_asserts(rpm); + if (!dev_priv->uncore.user_forcewake_count) + intel_runtime_pm_driver_release(rpm); + + return ret; +} + +static int i915_drm_suspend_noirq(struct drm_device *dev, bool hibernation) +{ + struct drm_i915_private *dev_priv = to_i915(dev); + struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); + /* * During hibernation on some platforms the BIOS may try to access * the device even though it's already in D3 and hang the machine. So @@ -1144,13 +1159,6 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) pci_set_power_state(pdev, PCI_D3hot); return 0; - -fail: - enable_rpm_wakeref_asserts(rpm); - if (!dev_priv->uncore.user_forcewake_count) - intel_runtime_pm_driver_release(rpm); - - return ret; } int i915_driver_suspend_switcheroo(struct drm_i915_private *i915, @@ -1169,7 +1177,15 @@ int i915_driver_suspend_switcheroo(struct drm_i915_private *i915, if (error) return error; - return i915_drm_suspend_late(&i915->drm, false); + error = i915_drm_suspend_late(&i915->drm, false); + if (error) + return error; + + error = i915_drm_suspend_noirq(&i915->drm, false); + if (error) + return error; + + return 0; } static int i915_drm_resume(struct drm_device *dev) @@ -1277,23 +1293,6 @@ static int i915_drm_resume_early(struct drm_device *dev) * similar so that power domains can be employed. */ - /* - * Note that we need to set the power state explicitly, since we - * powered off the device during freeze and the PCI core won't power - * it back up for us during thaw. Powering off the device during - * freeze is not a hard requirement though, and during the - * suspend/resume phases the PCI core makes sure we get here with the - * device powered on. So in case we change our freeze logic and keep - * the device powered we can also remove the following set power state - * call. - */ - ret = pci_set_power_state(pdev, PCI_D0); - if (ret) { - drm_err(&dev_priv->drm, - "failed to set PCI D0 power state (%d)\n", ret); - return ret; - } - /* * Note that pci_enable_device() first enables any parent bridge * device and only then sets the power state for this device. The @@ -1331,11 +1330,16 @@ static int i915_drm_resume_early(struct drm_device *dev) int i915_driver_resume_switcheroo(struct drm_i915_private *i915) { + struct pci_dev *pdev = to_pci_dev(i915->drm.dev); int ret; if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) return 0; + ret = pci_set_power_state(pdev, PCI_D0); + if (ret) + return ret; + ret = i915_drm_resume_early(&i915->drm); if (ret) return ret; @@ -1392,6 +1396,16 @@ static int i915_pm_suspend_late(struct device *kdev) return i915_drm_suspend_late(&i915->drm, false); } +static int i915_pm_suspend_noirq(struct device *kdev) +{ + struct drm_i915_private *i915 = kdev_to_i915(kdev); + + if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) + return 0; + + return i915_drm_suspend_noirq(&i915->drm, false); +} + static int i915_pm_poweroff_late(struct device *kdev) { struct drm_i915_private *i915 = kdev_to_i915(kdev); @@ -1402,6 +1416,16 @@ static int i915_pm_poweroff_late(struct device *kdev) return i915_drm_suspend_late(&i915->drm, true); } +static int i915_pm_poweroff_noirq(struct device *kdev) +{ + struct drm_i915_private *i915 = kdev_to_i915(kdev); + + if (i915->drm.switch_power_state == DRM_SWITCH_POWER_OFF) + return 0; + + return i915_drm_suspend_noirq(&i915->drm, true); +} + static int i915_pm_resume_early(struct device *kdev) { struct drm_i915_private *i915 = kdev_to_i915(kdev); @@ -1667,6 +1691,7 @@ const struct dev_pm_ops i915_pm_ops = { .prepare = i915_pm_prepare, .suspend = i915_pm_suspend, .suspend_late = i915_pm_suspend_late, + .suspend_noirq = i915_pm_suspend_noirq, .resume_early = i915_pm_resume_early, .resume = i915_pm_resume, .complete = i915_pm_complete, @@ -1692,6 +1717,7 @@ const struct dev_pm_ops i915_pm_ops = { .thaw = i915_pm_thaw, .poweroff = i915_pm_suspend, .poweroff_late = i915_pm_poweroff_late, + .poweroff_noirq = i915_pm_poweroff_noirq, .restore_early = i915_pm_restore_early, .restore = i915_pm_restore, From patchwork Tue Mar 11 19:56:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 14012657 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D6185C282EC for ; Tue, 11 Mar 2025 19:56:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6071110E67B; Tue, 11 Mar 2025 19:56:41 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="XFV6lt+k"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0803C10E685 for ; Tue, 11 Mar 2025 19:56:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741723000; x=1773259000; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lCkGaChBWAS+HeQ8oV2kMXWKEoka5XdT3ILfEAMiBVA=; b=XFV6lt+kpsjKRXuPCQPNkfVKFvlRJaRCScVkRpMywvL2ce5TFgX4u+9P 7RrdeHOCj6nyJneKT6+fJfmkjiTL8nPMALBE+FuZhWGikdPtu6Dl3v97p ajP2UV637s1YivZZMNS+6srADbrhe6sGg9UFHCuJsCvHc7gWHvl3DJLCX FCi477wmhvvq0FJbJk6tEnHMYBBmgGE4iYWddzFGrD1qM/xyTix69s8Ag RLAjpCqRVQKlKBNg/+U/NkCIRdwk+yb30FGCfp+8hTVPbPExVICuXh5gU TRJjZroTNy67wK1wDzJi764fFfE7T/Rl4cBydUnaD3p8oYJFM0uW5IOeM g==; X-CSE-ConnectionGUID: QBYNPaofRIqJqOtLwGfI/A== X-CSE-MsgGUID: XfGYHZ5BSTifJVgFXnSIZQ== X-IronPort-AV: E=McAfee;i="6700,10204,11370"; a="60183858" X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="60183858" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2025 12:56:40 -0700 X-CSE-ConnectionGUID: MEuXUNy6QYWLdH5q6S2wMg== X-CSE-MsgGUID: ter+6boqQKyuxtAoyxhHZQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="125617231" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orviesa005.jf.intel.com with SMTP; 11 Mar 2025 12:56:36 -0700 Received: by stinkbox (sSMTP sendmail emulation); Tue, 11 Mar 2025 21:56:37 +0200 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Cc: Rodrigo Vivi Subject: [PATCH v2 4/6] drm/i915/pm: Do pci_restore_state() in switcheroo resume hook Date: Tue, 11 Mar 2025 21:56:22 +0200 Message-ID: <20250311195624.22420-5-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250311195624.22420-1-ville.syrjala@linux.intel.com> References: <20250311195624.22420-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" From: Ville Syrjälä Since this switcheroo garbage bypasses all the core pm we have to manually manage the pci state. To that end add the missing pci_restore_state() to the switcheroo resume hook. We already have the pci_save_state() counterpart on the suspend side. Arguably none of this code should exist in the driver in the first place, and instead the entire switcheroo mechanism should be rewritten and properly integrated into core pm code... Cc: Rodrigo Vivi Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/i915/i915_driver.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index 995205e24ebf..a199e21c7bb4 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1340,6 +1340,8 @@ int i915_driver_resume_switcheroo(struct drm_i915_private *i915) if (ret) return ret; + pci_restore_state(pdev); + ret = i915_drm_resume_early(&i915->drm); if (ret) return ret; From patchwork Tue Mar 11 19:56:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 14012658 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 70678C28B2F for ; Tue, 11 Mar 2025 19:56:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0AAD010E689; Tue, 11 Mar 2025 19:56:44 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="P9S1Qe30"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id D0EC410E680 for ; Tue, 11 Mar 2025 19:56:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741723002; x=1773259002; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=IcUOV48Y5TJIZtwyMwfTMidOHxmBb0v5Wg2LPstZPgo=; b=P9S1Qe30kvz7J9HDVcRNMY6nFmmIoKMs+MV5DK7/Xw6oDfCLSzDKQBef 8Lxt9KU5AzY6jnQ4cxhQdYq78dxLnDpJFgYr6/pmum5I02ejLUtA9/BXQ dVY5SG0ZGAnZ562BShF7o8SxX+ozkadKfv+W1IwecZFUGi092ApnldR6i xK2skghwBTvfyFqg3qUAGOxIhnv2Qch+p1s+vNhUmjNVXGYHfYoPxFr+l sdqcP910G5JkPDfnI+EKpfBxeY0lrWF4AvFWpVxYbSfPXol70QXRVj28E f3GJ6JBDFIywpY6tWVHZ/FE8MjP3mNjsGxRShLyAgFHEvCTMzERd5wssT w==; X-CSE-ConnectionGUID: 7QBUm+E3TxCTJJvqtan5cQ== X-CSE-MsgGUID: tjegkNACSRypOvCW9n7KPA== X-IronPort-AV: E=McAfee;i="6700,10204,11370"; a="60183859" X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="60183859" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2025 12:56:42 -0700 X-CSE-ConnectionGUID: vwBl3tjWTH+TribYKlpYoA== X-CSE-MsgGUID: mkxtI/RfRVOIPAj8ZXM21g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="125617233" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orviesa005.jf.intel.com with SMTP; 11 Mar 2025 12:56:39 -0700 Received: by stinkbox (sSMTP sendmail emulation); Tue, 11 Mar 2025 21:56:40 +0200 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Subject: [PATCH v2 5/6] drm/i915/pm: Allow drivers/pci to manage our pci state normally Date: Tue, 11 Mar 2025 21:56:23 +0200 Message-ID: <20250311195624.22420-6-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250311195624.22420-1-ville.syrjala@linux.intel.com> References: <20250311195624.22420-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" From: Ville Syrjälä Stop doing the pci_save_state(), except when we need to prevent D3 due to BIOS bugs, so that the code in drivers/pci is allowed to manage the state of the PCI device. Less chance something getting left by the wayside by i915 if/when the things change in drivers/pci. Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/i915/i915_driver.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index a199e21c7bb4..503f1b6b694f 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1154,9 +1154,8 @@ static int i915_drm_suspend_noirq(struct drm_device *dev, bool hibernation) * pci_save_state() prevents drivers/pci from * automagically putting the device into D3. */ - pci_save_state(pdev); - if (!(hibernation && GRAPHICS_VER(dev_priv) < 6)) - pci_set_power_state(pdev, PCI_D3hot); + if (hibernation && GRAPHICS_VER(dev_priv) < 6) + pci_save_state(pdev); return 0; } @@ -1164,6 +1163,7 @@ static int i915_drm_suspend_noirq(struct drm_device *dev, bool hibernation) int i915_driver_suspend_switcheroo(struct drm_i915_private *i915, pm_message_t state) { + struct pci_dev *pdev = to_pci_dev(i915->drm.dev); int error; if (drm_WARN_ON_ONCE(&i915->drm, state.event != PM_EVENT_SUSPEND && @@ -1181,9 +1181,8 @@ int i915_driver_suspend_switcheroo(struct drm_i915_private *i915, if (error) return error; - error = i915_drm_suspend_noirq(&i915->drm, false); - if (error) - return error; + pci_save_state(pdev); + pci_set_power_state(pdev, PCI_D3hot); return 0; } From patchwork Tue Mar 11 19:56:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= X-Patchwork-Id: 14012659 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 57902C28B2F for ; Tue, 11 Mar 2025 19:56:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E37A410E685; Tue, 11 Mar 2025 19:56:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="eviU4Yx1"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) by gabe.freedesktop.org (Postfix) with ESMTPS id C818910E68A for ; Tue, 11 Mar 2025 19:56:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1741723005; x=1773259005; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=c4+uLCSLc4uQGMCvSJcOIGDNIl72PD2sr6Io9Q9nt1U=; b=eviU4Yx1117cLqTdBX14GNCw8Cw/oG9dzZHTNwZqHG+CxeFvM4BkE0Nr NNWl5cXlwrf5YCsQ9l6SubERQ38g5HIaSJUcUgwTFN9h9SIdrje9pHmYL qCzppFu9Hv4TUVCpf7RutG0nJWCKKQxVKgHUoHlms5hWX7X1j01He3jkV 09s6r0IyQVpQK0vxlV1+6lwk+ZUxeLgsroCMEHCeEigKH2E0n8KBbp8FJ aQlQ5b31+YNdn1ZKd2Ce+tcA9nQikA7/ko/JLl0WMYWP5OY3DGKOKUwil VgFqilLm3DJk6LISeStUbv4ljnm1eNPgX2Mjrv/DC0llDU6Lx+UPjSoCf w==; X-CSE-ConnectionGUID: mISIaLs2SR2Wxq0c7qSxTg== X-CSE-MsgGUID: KlEzTmpJRRKzP80dB32iLQ== X-IronPort-AV: E=McAfee;i="6700,10204,11370"; a="60183863" X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="60183863" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Mar 2025 12:56:45 -0700 X-CSE-ConnectionGUID: tsRvBLvlQWehXQ0o6AUjmA== X-CSE-MsgGUID: jXJuk7/TQVWuMbUmXauR1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.14,239,1736841600"; d="scan'208";a="125617238" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by orviesa005.jf.intel.com with SMTP; 11 Mar 2025 12:56:42 -0700 Received: by stinkbox (sSMTP sendmail emulation); Tue, 11 Mar 2025 21:56:43 +0200 From: Ville Syrjala To: intel-gfx@lists.freedesktop.org Subject: [PATCH v2 6/6] drm/i915/pm: Drop redundant pci stuff from suspend/resume paths Date: Tue, 11 Mar 2025 21:56:24 +0200 Message-ID: <20250311195624.22420-7-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.3 In-Reply-To: <20250311195624.22420-1-ville.syrjala@linux.intel.com> References: <20250311195624.22420-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 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" From: Ville Syrjälä I don't think there should be any need for us to call any of pci_enable_device(), pci_disable_device() or pci_set_master() from the suspend/resume paths. The config space save/restore should take care of all of this. Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/i915/i915_driver.c | 31 ------------------------------ 1 file changed, 31 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_driver.c b/drivers/gpu/drm/i915/i915_driver.c index 503f1b6b694f..d3d1b2d082dd 100644 --- a/drivers/gpu/drm/i915/i915_driver.c +++ b/drivers/gpu/drm/i915/i915_driver.c @@ -1092,7 +1092,6 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) { struct drm_i915_private *dev_priv = to_i915(dev); struct intel_display *display = &dev_priv->display; - struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); struct intel_runtime_pm *rpm = &dev_priv->runtime_pm; struct intel_gt *gt; int ret, i; @@ -1113,21 +1112,10 @@ static int i915_drm_suspend_late(struct drm_device *dev, bool hibernation) if (ret) { drm_err(&dev_priv->drm, "Suspend complete failed: %d\n", ret); intel_display_power_resume_early(display); - - goto fail; } enable_rpm_wakeref_asserts(rpm); - if (!dev_priv->uncore.user_forcewake_count) - intel_runtime_pm_driver_release(rpm); - - pci_disable_device(pdev); - - return 0; - -fail: - enable_rpm_wakeref_asserts(rpm); if (!dev_priv->uncore.user_forcewake_count) intel_runtime_pm_driver_release(rpm); @@ -1278,7 +1266,6 @@ static int i915_drm_resume_early(struct drm_device *dev) { struct drm_i915_private *dev_priv = to_i915(dev); struct intel_display *display = &dev_priv->display; - struct pci_dev *pdev = to_pci_dev(dev_priv->drm.dev); struct intel_gt *gt; int ret, i; @@ -1292,24 +1279,6 @@ static int i915_drm_resume_early(struct drm_device *dev) * similar so that power domains can be employed. */ - /* - * Note that pci_enable_device() first enables any parent bridge - * device and only then sets the power state for this device. The - * bridge enabling is a nop though, since bridge devices are resumed - * first. The order of enabling power and enabling the device is - * imposed by the PCI core as described above, so here we preserve the - * same order for the freeze/thaw phases. - * - * TODO: eventually we should remove pci_disable_device() / - * pci_enable_enable_device() from suspend/resume. Due to how they - * depend on the device enable refcount we can't anyway depend on them - * disabling/enabling the device. - */ - if (pci_enable_device(pdev)) - return -EIO; - - pci_set_master(pdev); - disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); ret = vlv_resume_prepare(dev_priv, false);