0465-drm-vc4-Enable-runtime-PM.patch 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. From 70eecf52df7082d1b3bcc698de2de1b6ce31be08 Mon Sep 17 00:00:00 2001
  2. From: Eric Anholt <eric@anholt.net>
  3. Date: Fri, 5 Feb 2016 17:41:49 -0800
  4. Subject: [PATCH] drm/vc4: Enable runtime PM.
  5. This may actually get us a feature that the closed driver didn't have:
  6. turning off the GPU in between rendering jobs, while the V3D device is
  7. still opened by the client.
  8. There may be some tuning to be applied here to use autosuspend so that
  9. we don't bounce the device's power so much, but in steady-state
  10. GPU-bound rendering we keep the power on (since we keep multiple jobs
  11. outstanding) and even if we power cycle on every job we can still
  12. manage at least 680 fps.
  13. More importantly, though, runtime PM will allow us to power off the
  14. device to do a GPU reset.
  15. v2: Switch #ifdef to CONFIG_PM not CONFIG_PM_SLEEP (caught by kbuild
  16. test robot)
  17. Signed-off-by: Eric Anholt <eric@anholt.net>
  18. (cherry picked from commit 001bdb55d9eb72a9e2d5b623bacfc52da74ae03e)
  19. ---
  20. drivers/gpu/drm/vc4/vc4_drv.h | 1 +
  21. drivers/gpu/drm/vc4/vc4_gem.c | 10 ++++++++
  22. drivers/gpu/drm/vc4/vc4_v3d.c | 59 ++++++++++++++++++++++++++-----------------
  23. 3 files changed, 47 insertions(+), 23 deletions(-)
  24. --- a/drivers/gpu/drm/vc4/vc4_drv.h
  25. +++ b/drivers/gpu/drm/vc4/vc4_drv.h
  26. @@ -155,6 +155,7 @@ struct vc4_seqno_cb {
  27. };
  28. struct vc4_v3d {
  29. + struct vc4_dev *vc4;
  30. struct platform_device *pdev;
  31. void __iomem *regs;
  32. };
  33. --- a/drivers/gpu/drm/vc4/vc4_gem.c
  34. +++ b/drivers/gpu/drm/vc4/vc4_gem.c
  35. @@ -23,6 +23,7 @@
  36. #include <linux/module.h>
  37. #include <linux/platform_device.h>
  38. +#include <linux/pm_runtime.h>
  39. #include <linux/device.h>
  40. #include <linux/io.h>
  41. @@ -689,6 +690,7 @@ fail:
  42. static void
  43. vc4_complete_exec(struct drm_device *dev, struct vc4_exec_info *exec)
  44. {
  45. + struct vc4_dev *vc4 = to_vc4_dev(dev);
  46. unsigned i;
  47. /* Need the struct lock for drm_gem_object_unreference(). */
  48. @@ -707,6 +709,8 @@ vc4_complete_exec(struct drm_device *dev
  49. }
  50. mutex_unlock(&dev->struct_mutex);
  51. + pm_runtime_put(&vc4->v3d->pdev->dev);
  52. +
  53. kfree(exec);
  54. }
  55. @@ -860,6 +864,12 @@ vc4_submit_cl_ioctl(struct drm_device *d
  56. return -ENOMEM;
  57. }
  58. + ret = pm_runtime_get_sync(&vc4->v3d->pdev->dev);
  59. + if (ret < 0) {
  60. + kfree(exec);
  61. + return ret;
  62. + }
  63. +
  64. exec->args = args;
  65. INIT_LIST_HEAD(&exec->unref_list);
  66. --- a/drivers/gpu/drm/vc4/vc4_v3d.c
  67. +++ b/drivers/gpu/drm/vc4/vc4_v3d.c
  68. @@ -17,7 +17,7 @@
  69. */
  70. #include "linux/component.h"
  71. -#include "soc/bcm2835/raspberrypi-firmware.h"
  72. +#include "linux/pm_runtime.h"
  73. #include "vc4_drv.h"
  74. #include "vc4_regs.h"
  75. @@ -145,22 +145,6 @@ int vc4_v3d_debugfs_ident(struct seq_fil
  76. }
  77. #endif /* CONFIG_DEBUG_FS */
  78. -/*
  79. - * Asks the firmware to turn on power to the V3D engine.
  80. - *
  81. - * This may be doable with just the clocks interface, though this
  82. - * packet does some other register setup from the firmware, too.
  83. - */
  84. -int
  85. -vc4_v3d_set_power(struct vc4_dev *vc4, bool on)
  86. -{
  87. - u32 packet = on;
  88. -
  89. - return rpi_firmware_property(vc4->firmware,
  90. - RPI_FIRMWARE_SET_ENABLE_QPU,
  91. - &packet, sizeof(packet));
  92. -}
  93. -
  94. static void vc4_v3d_init_hw(struct drm_device *dev)
  95. {
  96. struct vc4_dev *vc4 = to_vc4_dev(dev);
  97. @@ -172,6 +156,29 @@ static void vc4_v3d_init_hw(struct drm_d
  98. V3D_WRITE(V3D_VPMBASE, 0);
  99. }
  100. +#ifdef CONFIG_PM
  101. +static int vc4_v3d_runtime_suspend(struct device *dev)
  102. +{
  103. + struct vc4_v3d *v3d = dev_get_drvdata(dev);
  104. + struct vc4_dev *vc4 = v3d->vc4;
  105. +
  106. + vc4_irq_uninstall(vc4->dev);
  107. +
  108. + return 0;
  109. +}
  110. +
  111. +static int vc4_v3d_runtime_resume(struct device *dev)
  112. +{
  113. + struct vc4_v3d *v3d = dev_get_drvdata(dev);
  114. + struct vc4_dev *vc4 = v3d->vc4;
  115. +
  116. + vc4_v3d_init_hw(vc4->dev);
  117. + vc4_irq_postinstall(vc4->dev);
  118. +
  119. + return 0;
  120. +}
  121. +#endif
  122. +
  123. static int vc4_v3d_bind(struct device *dev, struct device *master, void *data)
  124. {
  125. struct platform_device *pdev = to_platform_device(dev);
  126. @@ -184,6 +191,8 @@ static int vc4_v3d_bind(struct device *d
  127. if (!v3d)
  128. return -ENOMEM;
  129. + dev_set_drvdata(dev, v3d);
  130. +
  131. v3d->pdev = pdev;
  132. v3d->regs = vc4_ioremap_regs(pdev, 0);
  133. @@ -191,10 +200,7 @@ static int vc4_v3d_bind(struct device *d
  134. return PTR_ERR(v3d->regs);
  135. vc4->v3d = v3d;
  136. -
  137. - ret = vc4_v3d_set_power(vc4, true);
  138. - if (ret)
  139. - return ret;
  140. + v3d->vc4 = vc4;
  141. if (V3D_READ(V3D_IDENT0) != V3D_EXPECTED_IDENT0) {
  142. DRM_ERROR("V3D_IDENT0 read 0x%08x instead of 0x%08x\n",
  143. @@ -216,6 +222,8 @@ static int vc4_v3d_bind(struct device *d
  144. return ret;
  145. }
  146. + pm_runtime_enable(dev);
  147. +
  148. return 0;
  149. }
  150. @@ -225,6 +233,8 @@ static void vc4_v3d_unbind(struct device
  151. struct drm_device *drm = dev_get_drvdata(master);
  152. struct vc4_dev *vc4 = to_vc4_dev(drm);
  153. + pm_runtime_disable(dev);
  154. +
  155. drm_irq_uninstall(drm);
  156. /* Disable the binner's overflow memory address, so the next
  157. @@ -234,11 +244,13 @@ static void vc4_v3d_unbind(struct device
  158. V3D_WRITE(V3D_BPOA, 0);
  159. V3D_WRITE(V3D_BPOS, 0);
  160. - vc4_v3d_set_power(vc4, false);
  161. -
  162. vc4->v3d = NULL;
  163. }
  164. +static const struct dev_pm_ops vc4_v3d_pm_ops = {
  165. + SET_RUNTIME_PM_OPS(vc4_v3d_runtime_suspend, vc4_v3d_runtime_resume, NULL)
  166. +};
  167. +
  168. static const struct component_ops vc4_v3d_ops = {
  169. .bind = vc4_v3d_bind,
  170. .unbind = vc4_v3d_unbind,
  171. @@ -267,5 +279,6 @@ struct platform_driver vc4_v3d_driver =
  172. .driver = {
  173. .name = "vc4_v3d",
  174. .of_match_table = vc4_v3d_dt_match,
  175. + .pm = &vc4_v3d_pm_ops,
  176. },
  177. };