drm_atomic_helper.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Copyright (C) 2014 Red Hat
  3. * Copyright (C) 2014 Intel Corp.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  19. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  20. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  21. * OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Rob Clark <[email protected]>
  25. * Daniel Vetter <[email protected]>
  26. */
  27. #ifndef DRM_ATOMIC_HELPER_H_
  28. #define DRM_ATOMIC_HELPER_H_
  29. #include <drm/drm_crtc.h>
  30. #include <drm/drm_modeset_helper_vtables.h>
  31. #include <drm/drm_modeset_helper.h>
  32. #include <drm/drm_atomic_state_helper.h>
  33. #include <drm/drm_util.h>
  34. /*
  35. * Drivers that don't allow primary plane scaling may pass this macro in place
  36. * of the min/max scale parameters of the plane-state checker function.
  37. *
  38. * Due to src being in 16.16 fixed point and dest being in integer pixels,
  39. * 1<<16 represents no scaling.
  40. */
  41. #define DRM_PLANE_NO_SCALING (1<<16)
  42. struct drm_atomic_state;
  43. struct drm_private_obj;
  44. struct drm_private_state;
  45. int drm_atomic_helper_check_modeset(struct drm_device *dev,
  46. struct drm_atomic_state *state);
  47. int
  48. drm_atomic_helper_check_wb_encoder_state(struct drm_encoder *encoder,
  49. struct drm_connector_state *conn_state);
  50. int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
  51. const struct drm_crtc_state *crtc_state,
  52. int min_scale,
  53. int max_scale,
  54. bool can_position,
  55. bool can_update_disabled);
  56. int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
  57. bool can_disable_primary_plane);
  58. int drm_atomic_helper_check_planes(struct drm_device *dev,
  59. struct drm_atomic_state *state);
  60. int drm_atomic_helper_check(struct drm_device *dev,
  61. struct drm_atomic_state *state);
  62. void drm_atomic_helper_commit_tail(struct drm_atomic_state *state);
  63. void drm_atomic_helper_commit_tail_rpm(struct drm_atomic_state *state);
  64. int drm_atomic_helper_commit(struct drm_device *dev,
  65. struct drm_atomic_state *state,
  66. bool nonblock);
  67. int drm_atomic_helper_async_check(struct drm_device *dev,
  68. struct drm_atomic_state *state);
  69. void drm_atomic_helper_async_commit(struct drm_device *dev,
  70. struct drm_atomic_state *state);
  71. int drm_atomic_helper_wait_for_fences(struct drm_device *dev,
  72. struct drm_atomic_state *state,
  73. bool pre_swap);
  74. void drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
  75. struct drm_atomic_state *old_state);
  76. void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
  77. struct drm_atomic_state *old_state);
  78. void
  79. drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev,
  80. struct drm_atomic_state *old_state);
  81. void
  82. drm_atomic_helper_calc_timestamping_constants(struct drm_atomic_state *state);
  83. void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev,
  84. struct drm_atomic_state *state);
  85. void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
  86. struct drm_atomic_state *old_state);
  87. int drm_atomic_helper_prepare_planes(struct drm_device *dev,
  88. struct drm_atomic_state *state);
  89. #define DRM_PLANE_COMMIT_ACTIVE_ONLY BIT(0)
  90. #define DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET BIT(1)
  91. void drm_atomic_helper_commit_planes(struct drm_device *dev,
  92. struct drm_atomic_state *state,
  93. uint32_t flags);
  94. void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
  95. struct drm_atomic_state *old_state);
  96. void drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state);
  97. void
  98. drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state,
  99. bool atomic);
  100. int __must_check drm_atomic_helper_swap_state(struct drm_atomic_state *state,
  101. bool stall);
  102. /* nonblocking commit helpers */
  103. int drm_atomic_helper_setup_commit(struct drm_atomic_state *state,
  104. bool nonblock);
  105. void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *state);
  106. void drm_atomic_helper_fake_vblank(struct drm_atomic_state *state);
  107. void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *state);
  108. void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *state);
  109. /* implementations for legacy interfaces */
  110. int drm_atomic_helper_update_plane(struct drm_plane *plane,
  111. struct drm_crtc *crtc,
  112. struct drm_framebuffer *fb,
  113. int crtc_x, int crtc_y,
  114. unsigned int crtc_w, unsigned int crtc_h,
  115. uint32_t src_x, uint32_t src_y,
  116. uint32_t src_w, uint32_t src_h,
  117. struct drm_modeset_acquire_ctx *ctx);
  118. int drm_atomic_helper_disable_plane(struct drm_plane *plane,
  119. struct drm_modeset_acquire_ctx *ctx);
  120. int drm_atomic_helper_set_config(struct drm_mode_set *set,
  121. struct drm_modeset_acquire_ctx *ctx);
  122. int drm_atomic_helper_disable_all(struct drm_device *dev,
  123. struct drm_modeset_acquire_ctx *ctx);
  124. void drm_atomic_helper_shutdown(struct drm_device *dev);
  125. struct drm_atomic_state *
  126. drm_atomic_helper_duplicate_state(struct drm_device *dev,
  127. struct drm_modeset_acquire_ctx *ctx);
  128. struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev);
  129. int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
  130. struct drm_modeset_acquire_ctx *ctx);
  131. int drm_atomic_helper_resume(struct drm_device *dev,
  132. struct drm_atomic_state *state);
  133. int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
  134. struct drm_framebuffer *fb,
  135. struct drm_pending_vblank_event *event,
  136. uint32_t flags,
  137. struct drm_modeset_acquire_ctx *ctx);
  138. int drm_atomic_helper_page_flip_target(
  139. struct drm_crtc *crtc,
  140. struct drm_framebuffer *fb,
  141. struct drm_pending_vblank_event *event,
  142. uint32_t flags,
  143. uint32_t target,
  144. struct drm_modeset_acquire_ctx *ctx);
  145. /**
  146. * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
  147. * @plane: the loop cursor
  148. * @crtc: the CRTC whose planes are iterated
  149. *
  150. * This iterates over the current state, useful (for example) when applying
  151. * atomic state after it has been checked and swapped. To iterate over the
  152. * planes which *will* be attached (more useful in code called from
  153. * &drm_mode_config_funcs.atomic_check) see
  154. * drm_atomic_crtc_state_for_each_plane().
  155. */
  156. #define drm_atomic_crtc_for_each_plane(plane, crtc) \
  157. drm_for_each_plane_mask(plane, (crtc)->dev, (crtc)->state->plane_mask)
  158. /**
  159. * drm_atomic_crtc_state_for_each_plane - iterate over attached planes in new state
  160. * @plane: the loop cursor
  161. * @crtc_state: the incoming CRTC state
  162. *
  163. * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
  164. * attached if the specified state is applied. Useful during for example
  165. * in code called from &drm_mode_config_funcs.atomic_check operations, to
  166. * validate the incoming state.
  167. */
  168. #define drm_atomic_crtc_state_for_each_plane(plane, crtc_state) \
  169. drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask)
  170. /**
  171. * drm_atomic_crtc_state_for_each_plane_state - iterate over attached planes in new state
  172. * @plane: the loop cursor
  173. * @plane_state: loop cursor for the plane's state, must be const
  174. * @crtc_state: the incoming CRTC state
  175. *
  176. * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
  177. * attached if the specified state is applied. Useful during for example
  178. * in code called from &drm_mode_config_funcs.atomic_check operations, to
  179. * validate the incoming state.
  180. *
  181. * Compared to just drm_atomic_crtc_state_for_each_plane() this also fills in a
  182. * const plane_state. This is useful when a driver just wants to peek at other
  183. * active planes on this CRTC, but does not need to change it.
  184. */
  185. #define drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) \
  186. drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) \
  187. for_each_if ((plane_state = \
  188. __drm_atomic_get_current_plane_state((crtc_state)->state, \
  189. plane)))
  190. /**
  191. * drm_atomic_plane_disabling - check whether a plane is being disabled
  192. * @old_plane_state: old atomic plane state
  193. * @new_plane_state: new atomic plane state
  194. *
  195. * Checks the atomic state of a plane to determine whether it's being disabled
  196. * or not. This also WARNs if it detects an invalid state (both CRTC and FB
  197. * need to either both be NULL or both be non-NULL).
  198. *
  199. * RETURNS:
  200. * True if the plane is being disabled, false otherwise.
  201. */
  202. static inline bool
  203. drm_atomic_plane_disabling(struct drm_plane_state *old_plane_state,
  204. struct drm_plane_state *new_plane_state)
  205. {
  206. /*
  207. * When disabling a plane, CRTC and FB should always be NULL together.
  208. * Anything else should be considered a bug in the atomic core, so we
  209. * gently warn about it.
  210. */
  211. WARN_ON((new_plane_state->crtc == NULL && new_plane_state->fb != NULL) ||
  212. (new_plane_state->crtc != NULL && new_plane_state->fb == NULL));
  213. return old_plane_state->crtc && !new_plane_state->crtc;
  214. }
  215. u32 *
  216. drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
  217. struct drm_bridge_state *bridge_state,
  218. struct drm_crtc_state *crtc_state,
  219. struct drm_connector_state *conn_state,
  220. u32 output_fmt,
  221. unsigned int *num_input_fmts);
  222. #endif /* DRM_ATOMIC_HELPER_H_ */