Skip to contentSkip to conversation

drm/vc4: add PM suspend/resume support

PATCH In review Stefan Wahren 2 participants 7 messages Oct 3, 2024 – Oct 9, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v4 cover drm/vc4: add PM suspend/resume support

This series implement the initial S2Idle support for VC4, which was a long time on my TODO list [1]. These patches were part of a bigger series [2], but after discovering a critical USB issue [3], i decided to split these changes out. There are no dependencies to the rest of the patches.

Changes in V4:
- fix compile warnings for VC4 & V3D patches

[1] - https://github.com/lategoodbye/rpi-zero/issues/9
[2] - https://lore.kernel.org/linux-arm-kernel/[email protected]/
[3] - https://lore.kernel.org/linux-usb/[email protected]/T/

Stefan Wahren (2):
drm/vc4: hdmi: add PM suspend/resume support
drm/vc4: v3d: add PM suspend/resume support

 drivers/gpu/drm/vc4/vc4_hdmi.c | 32 ++++++++++++++++++++++++++++----
 drivers/gpu/drm/vc4/vc4_v3d.c  |  7 +++----
 2 files changed, 31 insertions(+), 8 deletions(-)

--
2.34.1

#1 lore raw

PATCH v4 1/2 drm/vc4: hdmi: add PM suspend/resume support

Add suspend/resume support for the VC4 HDMI component in order to handle suspend to idle properly. Since the HDMI power domain is powered down during suspend, this makes connector status polling pointless.

---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)
drivers/gpu/drm/vc4/vc4_hdmi.c +28 -4
index 62b82b1eeb36..5e5d1c609858 100644
@@ -3117,6 +3117,31 @@ static int vc5_hdmi_init_resources(struct drm_device *drm,
 	return 0;
 }
 
+static int vc4_hdmi_suspend(struct device *dev)
+{
+	struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
+	struct drm_device *drm = vc4_hdmi->connector.dev;
+
+	if (drm && drm->mode_config.poll_enabled)
+		drm_kms_helper_poll_disable(drm);
+
+	return pm_runtime_force_suspend(dev);
+}
+
+static int vc4_hdmi_resume(struct device *dev)
+{
+	struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
+	struct drm_device *drm = vc4_hdmi->connector.dev;
+	int ret;
+
+	ret = pm_runtime_force_resume(dev);
+
+	if (drm && drm->mode_config.poll_enabled)
+		drm_kms_helper_poll_enable(drm);
+
+	return ret;
+}
+
 static int vc4_hdmi_runtime_suspend(struct device *dev)
 {
 	struct vc4_hdmi *vc4_hdmi = dev_get_drvdata(dev);
@@ -3415,9 +3440,8 @@ static const struct of_device_id vc4_hdmi_dt_match[] = {
 };
 
 static const struct dev_pm_ops vc4_hdmi_pm_ops = {
-	SET_RUNTIME_PM_OPS(vc4_hdmi_runtime_suspend,
-			   vc4_hdmi_runtime_resume,
-			   NULL)
+	RUNTIME_PM_OPS(vc4_hdmi_runtime_suspend, vc4_hdmi_runtime_resume, NULL)
+	SYSTEM_SLEEP_PM_OPS(vc4_hdmi_suspend, vc4_hdmi_resume)
 };
 
 struct platform_driver vc4_hdmi_driver = {
@@ -3426,6 +3450,6 @@ struct platform_driver vc4_hdmi_driver = {
 	.driver = {
 		.name = "vc4_hdmi",
 		.of_match_table = vc4_hdmi_dt_match,
-		.pm = &vc4_hdmi_pm_ops,
+		.pm = pm_ptr(&vc4_hdmi_pm_ops),
 	},
 };

--
2.34.1

#2 lore raw

PATCH v4 2/2 drm/vc4: v3d: add PM suspend/resume support

In reply to Stefan Wahren

Add suspend/resume support for the VC4 V3D component in order to handle suspend to idle properly.

---
 drivers/gpu/drm/vc4/vc4_v3d.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/vc4/vc4_v3d.c +3 -4
index 2423826c89eb..8057b06c1f16 100644
@@ -368,7 +368,6 @@ void vc4_v3d_bin_bo_put(struct vc4_dev *vc4)
 	mutex_unlock(&vc4->bin_bo_lock);
 }
 
-#ifdef CONFIG_PM
 static int vc4_v3d_runtime_suspend(struct device *dev)
 {
 	struct vc4_v3d *v3d = dev_get_drvdata(dev);
@@ -397,7 +396,6 @@ static int vc4_v3d_runtime_resume(struct device *dev)
 
 	return 0;
 }
-#endif
 
 int vc4_v3d_debugfs_init(struct drm_minor *minor)
 {
@@ -507,7 +505,8 @@ static void vc4_v3d_unbind(struct device *dev, struct device *master,
 }
 
 static const struct dev_pm_ops vc4_v3d_pm_ops = {
-	SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume, NULL)
+	RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume, NULL)
+	SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
 };
 
 static const struct component_ops vc4_v3d_ops = {
@@ -538,6 +537,6 @@ struct platform_driver vc4_v3d_driver = {
 	.driver = {
 		.name = "vc4_v3d",
 		.of_match_table = vc4_v3d_dt_match,
-		.pm = &vc4_v3d_pm_ops,
+		.pm = pm_ptr(&vc4_v3d_pm_ops),
 	},
 };

--
2.34.1

reviewer
#3 lore raw

Re: [PATCH V4 2/2] drm/vc4: v3d: add PM suspend/resume support

Hi Stefan,

Quoted 29 lines · Stefan Wahren

Add suspend/resume support for the VC4 V3D component in order to handle suspend to idle properly.

---
  drivers/gpu/drm/vc4/vc4_v3d.c | 7 +++----
  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/vc4/vc4_v3d.c +0 -2
index 2423826c89eb..8057b06c1f16 100644
@@ -368,7 +368,6 @@ void vc4_v3d_bin_bo_put(struct vc4_dev *vc4)
  	mutex_unlock(&vc4->bin_bo_lock);
  }
 
-#ifdef CONFIG_PM
  static int vc4_v3d_runtime_suspend(struct device *dev)
  {
  	struct vc4_v3d *v3d = dev_get_drvdata(dev);
@@ -397,7 +396,6 @@ static int vc4_v3d_runtime_resume(struct device *dev)
 
  	return 0;
  }
-#endif
 
  int vc4_v3d_debugfs_init(struct drm_minor *minor)
  {

drivers/gpu/drm/vc4/vc4_v3d.c static void vc4_v3d_unbind(struct device *dev, struct device *master, · line 509

Quoted 6 lines
drivers/gpu/drm/vc4/vc4_v3d.c +2 -1
@@ -507,7 +505,8 @@ static void vc4_v3d_unbind(struct device *dev, struct device *master,
  }
 
  static const struct dev_pm_ops vc4_v3d_pm_ops = {
-	SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume, NULL)
+	RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume, NULL)
+	SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)

I have a question: How can we guarantee that no jobs are running when the system is forced to suspend?

Best Regards,
- Maíra

Quoted 14 lines
drivers/gpu/drm/vc4/vc4_v3d.c +1 -2
  };
 
  static const struct component_ops vc4_v3d_ops = {
@@ -538,6 +537,6 @@ struct platform_driver vc4_v3d_driver = {
  	.driver = {
  		.name = "vc4_v3d",
  		.of_match_table = vc4_v3d_dt_match,
-		.pm = &vc4_v3d_pm_ops,
+		.pm = pm_ptr(&vc4_v3d_pm_ops),
  	},
  };
--

2.34.1

#4 lore raw

Re: [PATCH V4 2/2] drm/vc4: v3d: add PM suspend/resume support

Hi Maíra,

Am 08.10.24 um 15:49 schrieb Maíra Canal:

Quoted 37 lines

Hi Stefan,

Quoted 34 lines · Stefan Wahren

Add suspend/resume support for the VC4 V3D component in order to handle suspend to idle properly.

---
  drivers/gpu/drm/vc4/vc4_v3d.c | 7 +++----

  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/vc4/vc4_v3d.c +0 -2
index 2423826c89eb..8057b06c1f16 100644
@@ -368,7 +368,6 @@ void vc4_v3d_bin_bo_put(struct vc4_dev *vc4)
       mutex_unlock(&vc4->bin_bo_lock);
   }
 
-#ifdef CONFIG_PM
   static int vc4_v3d_runtime_suspend(struct device *dev)
   {
       struct vc4_v3d *v3d = dev_get_drvdata(dev);
@@ -397,7 +396,6 @@ static int vc4_v3d_runtime_resume(struct device
 *dev)
 
       return 0;
   }
-#endif
 
   int vc4_v3d_debugfs_init(struct drm_minor *minor)

  {

drivers/gpu/drm/vc4/vc4_v3d.c +0 -0
@@ -507,7 +505,8 @@ static void vc4_v3d_unbind(struct device *dev,
 struct device *master,
   }
 
Quoted 10 lines
Quoted 7 lines
drivers/gpu/drm/vc4/vc4_v3d.c +2 -1
   static const struct dev_pm_ops vc4_v3d_pm_ops = {
-    SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend,
 vc4_v3d_runtime_resume, NULL)
+    RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume,
 NULL)
+    SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,

pm_runtime_force_resume)

I have a question: How can we guarantee that no jobs are running when the system is forced to suspend?

Not sure what do you mean with job. userspace task or v3d job within the driver?

Do you have something specific in mind.

Why is there a difference between runtime pm and system pm?

I must confess that i didn't test a system sleep while running a v3d application.

Best regards
Stefan

Quoted 18 lines

Best Regards,
- Maíra

Quoted 14 lines

  };

  static const struct component_ops vc4_v3d_ops = {

drivers/gpu/drm/vc4/vc4_v3d.c +1 -2
@@ -538,6 +537,6 @@ struct platform_driver vc4_v3d_driver = {
       .driver = {
           .name = "vc4_v3d",
           .of_match_table = vc4_v3d_dt_match,
-        .pm = &vc4_v3d_pm_ops,
+        .pm = pm_ptr(&vc4_v3d_pm_ops),
       },
   };
--

2.34.1

reviewer
#5 lore raw

Re: [PATCH V4 2/2] drm/vc4: v3d: add PM suspend/resume support

Hi Stefan,

Quoted 50 lines · Stefan Wahren

Hi Maíra,

Am 08.10.24 um 15:49 schrieb Maíra Canal:

Quoted 37 lines

Hi Stefan,

Quoted 34 lines · Stefan Wahren

Add suspend/resume support for the VC4 V3D component in order to handle suspend to idle properly.

---
  drivers/gpu/drm/vc4/vc4_v3d.c | 7 +++----

  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/vc4/vc4_v3d.c +0 -2
index 2423826c89eb..8057b06c1f16 100644
@@ -368,7 +368,6 @@ void vc4_v3d_bin_bo_put(struct vc4_dev *vc4)
       mutex_unlock(&vc4->bin_bo_lock);
   }
 
-#ifdef CONFIG_PM
   static int vc4_v3d_runtime_suspend(struct device *dev)
   {
       struct vc4_v3d *v3d = dev_get_drvdata(dev);
@@ -397,7 +396,6 @@ static int vc4_v3d_runtime_resume(struct device
 *dev)
 
       return 0;
   }
-#endif
 
   int vc4_v3d_debugfs_init(struct drm_minor *minor)

  {

drivers/gpu/drm/vc4/vc4_v3d.c +0 -0
@@ -507,7 +505,8 @@ static void vc4_v3d_unbind(struct device *dev,
 struct device *master,
   }
 
Quoted 10 lines
Quoted 7 lines
drivers/gpu/drm/vc4/vc4_v3d.c +2 -1
   static const struct dev_pm_ops vc4_v3d_pm_ops = {
-    SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend,
 vc4_v3d_runtime_resume, NULL)
+    RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume,
 NULL)
+    SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,

pm_runtime_force_resume)

I have a question: How can we guarantee that no jobs are running when the system is forced to suspend?

Quoted 2 lines

Not sure what do you mean with job. userspace task or v3d job within the driver?

I mean a V3D job. See, when we submit a CL to the GPU, we only know when it's done through a IRQ. I'm thinking in the case where:

1. We submitted a CL to the GPU
2. We suspend but the job wasn't ended yet

What happens to this job? Is the GPU going to be in a unstable state when we resume?

Quoted 5 lines

Do you have something specific in mind.

Why is there a difference between runtime pm and system pm?

As far as I can see, for system PM, we need at least to suspend V3D in a stable state, without any jobs running and with IRQs disabled.

Best Regards,
- Maíra

Quoted 24 lines

I must confess that i didn't test a system sleep while running a v3d application.

Best regards
Stefan

Quoted 18 lines

Best Regards,
- Maíra

Quoted 14 lines

  };

  static const struct component_ops vc4_v3d_ops = {

drivers/gpu/drm/vc4/vc4_v3d.c +1 -1
@@ -538,6 +537,6 @@ struct platform_driver vc4_v3d_driver = {
       .driver = {
           .name = "vc4_v3d",
           .of_match_table = vc4_v3d_dt_match,
-        .pm = &vc4_v3d_pm_ops,
+        .pm = pm_ptr(&vc4_v3d_pm_ops),
       },
   };
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH V4 2/2] drm/vc4: v3d: add PM suspend/resume support

Hi Maíra,

Am 09.10.24 um 14:16 schrieb Maíra Canal:

Quoted 53 lines

Hi Stefan,

Quoted 50 lines · Stefan Wahren

Hi Maíra,

Am 08.10.24 um 15:49 schrieb Maíra Canal:

Quoted 47 lines

Hi Stefan,

Quoted 40 lines · Stefan Wahren

Add suspend/resume support for the VC4 V3D component in order to handle suspend to idle properly.

---
  drivers/gpu/drm/vc4/vc4_v3d.c | 7 +++----

  1 file changed, 3 insertions(+), 4 deletions(-)
drivers/gpu/drm/vc4/vc4_v3d.c +0 -2
index 2423826c89eb..8057b06c1f16 100644
@@ -368,7 +368,6 @@ void vc4_v3d_bin_bo_put(struct vc4_dev *vc4)
       mutex_unlock(&vc4->bin_bo_lock);
   }
 
-#ifdef CONFIG_PM
   static int vc4_v3d_runtime_suspend(struct device *dev)
   {
       struct vc4_v3d *v3d = dev_get_drvdata(dev);
@@ -397,7 +396,6 @@ static int vc4_v3d_runtime_resume(struct device
 *dev)
 
       return 0;
   }
-#endif
 
   int vc4_v3d_debugfs_init(struct drm_minor *minor)

  {

drivers/gpu/drm/vc4/vc4_v3d.c +2 -1
@@ -507,7 +505,8 @@ static void vc4_v3d_unbind(struct device *dev,
 struct device *master,
   }
 
   static const struct dev_pm_ops vc4_v3d_pm_ops = {
-    SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend,
 vc4_v3d_runtime_resume, NULL)
+    RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume,
 NULL)
+    SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
Quoted 1 line

pm_runtime_force_resume)

I have a question: How can we guarantee that no jobs are running when the system is forced to suspend?

Quoted 8 lines
Quoted 2 lines

Not sure what do you mean with job. userspace task or v3d job within the driver?

I mean a V3D job. See, when we submit a CL to the GPU, we only know when it's done through a IRQ. I'm thinking in the case where:

1. We submitted a CL to the GPU
2. We suspend but the job wasn't ended yet

okay, now i understand. I was under the naive impression that everything is handled in the ARM cores. Sorry, i don't really have a deeper understanding of the V3D stuff.

Quoted 3 lines

What happens to this job? Is the GPU going to be in a unstable state when we resume?

I don't know what happens to the GPU, but during suspend most of the IRQs would be disabled so the ARM core(s) won't serve the interrupt handler.

At least i need some guidance here, how to prevent sending new jobs to the GPU. I assume such a logic must be already part of the driver removal.

Best regards

Quoted 36 lines
Quoted 6 lines

Do you have something specific in mind.

Why is there a difference between runtime pm and system pm?

As far as I can see, for system PM, we need at least to suspend V3D in a stable state, without any jobs running and with IRQs disabled.

Best Regards,
- Maíra

Quoted 24 lines

I must confess that i didn't test a system sleep while running a v3d application.

Best regards
Stefan

Quoted 18 lines

Best Regards,
- Maíra

Quoted 14 lines

  };

  static const struct component_ops vc4_v3d_ops = {

drivers/gpu/drm/vc4/vc4_v3d.c +1 -2
@@ -538,6 +537,6 @@ struct platform_driver vc4_v3d_driver = {
       .driver = {
           .name = "vc4_v3d",
           .of_match_table = vc4_v3d_dt_match,
-        .pm = &vc4_v3d_pm_ops,
+        .pm = pm_ptr(&vc4_v3d_pm_ops),
       },
   };
--

2.34.1