intel_frontbuffer.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright © 2014 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Daniel Vetter <daniel.vetter@ffwll.ch>
  25. */
  26. /**
  27. * DOC: frontbuffer tracking
  28. *
  29. * Many features require us to track changes to the currently active
  30. * frontbuffer, especially rendering targeted at the frontbuffer.
  31. *
  32. * To be able to do so GEM tracks frontbuffers using a bitmask for all possible
  33. * frontbuffer slots through i915_gem_track_fb(). The function in this file are
  34. * then called when the contents of the frontbuffer are invalidated, when
  35. * frontbuffer rendering has stopped again to flush out all the changes and when
  36. * the frontbuffer is exchanged with a flip. Subsystems interested in
  37. * frontbuffer changes (e.g. PSR, FBC, DRRS) should directly put their callbacks
  38. * into the relevant places and filter for the frontbuffer slots that they are
  39. * interested int.
  40. *
  41. * On a high level there are two types of powersaving features. The first one
  42. * work like a special cache (FBC and PSR) and are interested when they should
  43. * stop caching and when to restart caching. This is done by placing callbacks
  44. * into the invalidate and the flush functions: At invalidate the caching must
  45. * be stopped and at flush time it can be restarted. And maybe they need to know
  46. * when the frontbuffer changes (e.g. when the hw doesn't initiate an invalidate
  47. * and flush on its own) which can be achieved with placing callbacks into the
  48. * flip functions.
  49. *
  50. * The other type of display power saving feature only cares about busyness
  51. * (e.g. DRRS). In that case all three (invalidate, flush and flip) indicate
  52. * busyness. There is no direct way to detect idleness. Instead an idle timer
  53. * work delayed work should be started from the flush and flip functions and
  54. * cancelled as soon as busyness is detected.
  55. *
  56. * Note that there's also an older frontbuffer activity tracking scheme which
  57. * just tracks general activity. This is done by the various mark_busy and
  58. * mark_idle functions. For display power management features using these
  59. * functions is deprecated and should be avoided.
  60. */
  61. #include <drm/drmP.h>
  62. #include "intel_drv.h"
  63. #include "intel_frontbuffer.h"
  64. #include "i915_drv.h"
  65. void __intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  66. enum fb_op_origin origin,
  67. unsigned int frontbuffer_bits)
  68. {
  69. struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
  70. if (origin == ORIGIN_CS) {
  71. spin_lock(&dev_priv->fb_tracking.lock);
  72. dev_priv->fb_tracking.busy_bits |= frontbuffer_bits;
  73. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  74. spin_unlock(&dev_priv->fb_tracking.lock);
  75. }
  76. intel_psr_invalidate(dev_priv, frontbuffer_bits);
  77. intel_edp_drrs_invalidate(dev_priv, frontbuffer_bits);
  78. intel_fbc_invalidate(dev_priv, frontbuffer_bits, origin);
  79. }
  80. /**
  81. * intel_frontbuffer_flush - flush frontbuffer
  82. * @dev_priv: i915 device
  83. * @frontbuffer_bits: frontbuffer plane tracking bits
  84. * @origin: which operation caused the flush
  85. *
  86. * This function gets called every time rendering on the given planes has
  87. * completed and frontbuffer caching can be started again. Flushes will get
  88. * delayed if they're blocked by some outstanding asynchronous rendering.
  89. *
  90. * Can be called without any locks held.
  91. */
  92. static void intel_frontbuffer_flush(struct drm_i915_private *dev_priv,
  93. unsigned frontbuffer_bits,
  94. enum fb_op_origin origin)
  95. {
  96. /* Delay flushing when rings are still busy.*/
  97. spin_lock(&dev_priv->fb_tracking.lock);
  98. frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits;
  99. spin_unlock(&dev_priv->fb_tracking.lock);
  100. if (!frontbuffer_bits)
  101. return;
  102. intel_edp_drrs_flush(dev_priv, frontbuffer_bits);
  103. intel_psr_flush(dev_priv, frontbuffer_bits, origin);
  104. intel_fbc_flush(dev_priv, frontbuffer_bits, origin);
  105. }
  106. void __intel_fb_obj_flush(struct drm_i915_gem_object *obj,
  107. bool retire,
  108. enum fb_op_origin origin,
  109. unsigned int frontbuffer_bits)
  110. {
  111. struct drm_i915_private *dev_priv = to_i915(obj->base.dev);
  112. if (retire) {
  113. spin_lock(&dev_priv->fb_tracking.lock);
  114. /* Filter out new bits since rendering started. */
  115. frontbuffer_bits &= dev_priv->fb_tracking.busy_bits;
  116. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  117. spin_unlock(&dev_priv->fb_tracking.lock);
  118. }
  119. if (frontbuffer_bits)
  120. intel_frontbuffer_flush(dev_priv, frontbuffer_bits, origin);
  121. }
  122. /**
  123. * intel_frontbuffer_flip_prepare - prepare asynchronous frontbuffer flip
  124. * @dev_priv: i915 device
  125. * @frontbuffer_bits: frontbuffer plane tracking bits
  126. *
  127. * This function gets called after scheduling a flip on @obj. The actual
  128. * frontbuffer flushing will be delayed until completion is signalled with
  129. * intel_frontbuffer_flip_complete. If an invalidate happens in between this
  130. * flush will be cancelled.
  131. *
  132. * Can be called without any locks held.
  133. */
  134. void intel_frontbuffer_flip_prepare(struct drm_i915_private *dev_priv,
  135. unsigned frontbuffer_bits)
  136. {
  137. spin_lock(&dev_priv->fb_tracking.lock);
  138. dev_priv->fb_tracking.flip_bits |= frontbuffer_bits;
  139. /* Remove stale busy bits due to the old buffer. */
  140. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  141. spin_unlock(&dev_priv->fb_tracking.lock);
  142. intel_psr_single_frame_update(dev_priv, frontbuffer_bits);
  143. }
  144. /**
  145. * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flip
  146. * @dev_priv: i915 device
  147. * @frontbuffer_bits: frontbuffer plane tracking bits
  148. *
  149. * This function gets called after the flip has been latched and will complete
  150. * on the next vblank. It will execute the flush if it hasn't been cancelled yet.
  151. *
  152. * Can be called without any locks held.
  153. */
  154. void intel_frontbuffer_flip_complete(struct drm_i915_private *dev_priv,
  155. unsigned frontbuffer_bits)
  156. {
  157. spin_lock(&dev_priv->fb_tracking.lock);
  158. /* Mask any cancelled flips. */
  159. frontbuffer_bits &= dev_priv->fb_tracking.flip_bits;
  160. dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits;
  161. spin_unlock(&dev_priv->fb_tracking.lock);
  162. if (frontbuffer_bits)
  163. intel_frontbuffer_flush(dev_priv,
  164. frontbuffer_bits, ORIGIN_FLIP);
  165. }
  166. /**
  167. * intel_frontbuffer_flip - synchronous frontbuffer flip
  168. * @dev_priv: i915 device
  169. * @frontbuffer_bits: frontbuffer plane tracking bits
  170. *
  171. * This function gets called after scheduling a flip on @obj. This is for
  172. * synchronous plane updates which will happen on the next vblank and which will
  173. * not get delayed by pending gpu rendering.
  174. *
  175. * Can be called without any locks held.
  176. */
  177. void intel_frontbuffer_flip(struct drm_i915_private *dev_priv,
  178. unsigned frontbuffer_bits)
  179. {
  180. spin_lock(&dev_priv->fb_tracking.lock);
  181. /* Remove stale busy bits due to the old buffer. */
  182. dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits;
  183. spin_unlock(&dev_priv->fb_tracking.lock);
  184. intel_frontbuffer_flush(dev_priv, frontbuffer_bits, ORIGIN_FLIP);
  185. }