[PATCH v6 09/12] drm/xe/pm: Refactor PM Sleep Ops

Badal Nilawar
2026-01-13T16:32:39Z

Refactor PM Sleep OPS to indicate xe_pm_suspend/resume is called
during hibernation (S4) or suspend (S3/S2idle).

Signed-off-by: Badal Nilawar <badal.nilawar@intel.com>
---
drivers/gpu/drm/xe/xe_pci.c | 64 +++++++++++++++++++++++++++++++++++--
drivers/gpu/drm/xe/xe_pm.c | 10 +++---
drivers/gpu/drm/xe/xe_pm.h | 4 +--
3 files changed, 69 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
index e1de6b337f1f..f1ec6aa26faa 100644
--- a/drivers/gpu/drm/xe/xe_pci.c
+++ b/drivers/gpu/drm/xe/xe_pci.c
@@ -1135,7 +1135,7 @@ static int xe_pci_suspend(struct device *dev)
if (xe_survivability_mode_is_boot_enabled(xe))
return -EBUSY;

- err = xe_pm_suspend(xe);
+ err = xe_pm_suspend(xe, false);
if (err)
return err;

@@ -1173,13 +1173,66 @@ static int xe_pci_resume(struct device *dev)

pci_set_master(pdev);

- err = xe_pm_resume(pdev_to_xe_device(pdev));
+ err = xe_pm_resume(pdev_to_xe_device(pdev), false);
if (err)
return err;

return 0;
}

+static int xe_pci_freeze(struct device *dev)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ struct xe_device *xe = pdev_to_xe_device(pdev);
+ int err;
+
+ if (xe_survivability_mode_is_boot_enabled(xe))
+ return -EBUSY;
+
+ err = xe_pm_suspend(xe, true);
+ if (err)
+ return err;
+
+ /*
+ * Enabling D3Cold is needed for S2Idle/S0ix.
+ * It is save to allow here since xe_pm_suspend has evicted
+ * the local memory and the direct complete optimization is disabled.
+ */
+ d3cold_toggle(pdev, D3COLD_ENABLE);
+
+ pci_save_state(pdev);
+ pci_disable_device(pdev);
+ pci_set_power_state(pdev, PCI_D3cold);
+
+ return 0;
+}
+
+static int xe_pci_thaw(struct device *dev)
+{
+ struct pci_dev *pdev = to_pci_dev(dev);
+ int err;
+
+ /* Give back the D3Cold decision to the runtime P M*/
+ d3cold_toggle(pdev, D3COLD_DISABLE);
+
+ err = pci_set_power_state(pdev, PCI_D0);
+ if (err)
+ return err;
+
+ pci_restore_state(pdev);
+
+ err = pci_enable_device(pdev);
+ if (err)
+ return err;
+
+ pci_set_master(pdev);
+
+ err = xe_pm_resume(pdev_to_xe_device(pdev), true);
+ if (err)
+ return err;
+
+ return 0;
+}
static int xe_pci_runtime_suspend(struct device *dev)
{
struct pci_dev *pdev = to_pci_dev(dev);
@@ -1248,7 +1301,12 @@ static int xe_pci_runtime_idle(struct device *dev)
}

static const struct dev_pm_ops xe_pm_ops = {
- SET_SYSTEM_SLEEP_PM_OPS(xe_pci_suspend, xe_pci_resume)
+ .suspend = xe_pci_suspend,
+ .resume = xe_pci_resume,
+ .freeze = xe_pci_freeze,
+ .thaw = xe_pci_thaw,
+ .poweroff = xe_pci_freeze,
+ .restore = xe_pci_thaw,
SET_RUNTIME_PM_OPS(xe_pci_runtime_suspend, xe_pci_runtime_resume, xe_pci_runtime_idle)
};
#endif
diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c
index 1a1edbfcf240..2cbcb9de7586 100644
--- a/drivers/gpu/drm/xe/xe_pm.c
+++ b/drivers/gpu/drm/xe/xe_pm.c
@@ -178,16 +178,17 @@ static void xe_pm_suspend_prepare(struct xe_device *xe)
/**
* xe_pm_suspend - Helper for System suspend, i.e. S0->S3 / S0->S2idle
* @xe: xe device instance
+ * @hibernation: whether the suspend is for hibernation
*
* Return: 0 on success
*/
-int xe_pm_suspend(struct xe_device *xe)
+int xe_pm_suspend(struct xe_device *xe, bool hibernation)
{
struct xe_gt *gt;
u8 id;
int err;

- drm_dbg(&xe->drm, "Suspending device\n");
+ drm_dbg(&xe->drm, "Suspending device for %s\n", hibernation ? "hibernation" : "S3/S2idle");
xe_pm_block_begin_signalling();
trace_xe_pm_suspend(xe, __builtin_return_address(0));

@@ -238,10 +239,11 @@ int xe_pm_suspend(struct xe_device *xe)
/**
* xe_pm_resume - Helper for System resume S3->S0 / S2idle->S0
* @xe: xe device instance
+ * @hibernation: whether the resume is from hibernation
*
* Return: 0 on success
*/
-int xe_pm_resume(struct xe_device *xe)
+int xe_pm_resume(struct xe_device *xe, bool hibernation)
{
struct xe_tile *tile;
struct xe_gt *gt;
@@ -249,7 +251,7 @@ int xe_pm_resume(struct xe_device *xe)
int err;

xe_pm_block_begin_signalling();
- drm_dbg(&xe->drm, "Resuming device\n");
+ drm_dbg(&xe->drm, "Resuming device from %s\n", hibernation ? "hibernation" : "S3/S2idle");
trace_xe_pm_resume(xe, __builtin_return_address(0));

for_each_gt(gt, xe, id)
diff --git a/drivers/gpu/drm/xe/xe_pm.h b/drivers/gpu/drm/xe/xe_pm.h
index cd7b4a9b2c05..973475f2f7dd 100644
--- a/drivers/gpu/drm/xe/xe_pm.h
+++ b/drivers/gpu/drm/xe/xe_pm.h
@@ -19,8 +19,8 @@ enum xe_d3_state {
XE_D3COLD_OFF,
};

-int xe_pm_suspend(struct xe_device *xe);
-int xe_pm_resume(struct xe_device *xe);
+int xe_pm_suspend(struct xe_device *xe, bool hibernation);
+int xe_pm_resume(struct xe_device *xe, bool hibernation);

int xe_pm_init_early(struct xe_device *xe);
int xe_pm_init(struct xe_device *xe);
--
2.52.0