drm_atomic_helper.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 <robdclark@gmail.com>
  25. * Daniel Vetter <daniel.vetter@ffwll.ch>
  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 drm_atomic_helper_check_wb_connector_state(struct drm_connector *connector,
  48. struct drm_atomic_state *state);
  49. int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
  50. const struct drm_crtc_state *crtc_state,
  51. int min_scale,
  52. int max_scale,
  53. bool can_position,
  54. bool can_update_disabled);
  55. int drm_atomic_helper_check_planes(struct drm_device *dev,
  56. struct drm_atomic_state *state);
  57. int drm_atomic_helper_check_crtc_primary_plane(struct drm_crtc_state *crtc_state);
  58. void drm_atomic_helper_commit_encoder_bridge_disable(struct drm_device *dev,
  59. struct drm_atomic_state *state);
  60. void drm_atomic_helper_commit_crtc_disable(struct drm_device *dev,
  61. struct drm_atomic_state *state);
  62. void drm_atomic_helper_commit_encoder_bridge_post_disable(struct drm_device *dev,
  63. struct drm_atomic_state *state);
  64. int drm_atomic_helper_check(struct drm_device *dev,
  65. struct drm_atomic_state *state);
  66. void drm_atomic_helper_commit_tail(struct drm_atomic_state *state);
  67. void drm_atomic_helper_commit_tail_rpm(struct drm_atomic_state *state);
  68. int drm_atomic_helper_commit(struct drm_device *dev,
  69. struct drm_atomic_state *state,
  70. bool nonblock);
  71. int drm_atomic_helper_async_check(struct drm_device *dev,
  72. struct drm_atomic_state *state);
  73. void drm_atomic_helper_async_commit(struct drm_device *dev,
  74. struct drm_atomic_state *state);
  75. int drm_atomic_helper_wait_for_fences(struct drm_device *dev,
  76. struct drm_atomic_state *state,
  77. bool pre_swap);
  78. void drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
  79. struct drm_atomic_state *old_state);
  80. void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
  81. struct drm_atomic_state *old_state);
  82. void
  83. drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev,
  84. struct drm_atomic_state *old_state);
  85. void
  86. drm_atomic_helper_calc_timestamping_constants(struct drm_atomic_state *state);
  87. void drm_atomic_helper_commit_crtc_set_mode(struct drm_device *dev,
  88. struct drm_atomic_state *state);
  89. void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev,
  90. struct drm_atomic_state *state);
  91. void drm_atomic_helper_commit_writebacks(struct drm_device *dev,
  92. struct drm_atomic_state *state);
  93. void drm_atomic_helper_commit_encoder_bridge_pre_enable(struct drm_device *dev,
  94. struct drm_atomic_state *state);
  95. void drm_atomic_helper_commit_crtc_enable(struct drm_device *dev,
  96. struct drm_atomic_state *state);
  97. void drm_atomic_helper_commit_encoder_bridge_enable(struct drm_device *dev,
  98. struct drm_atomic_state *state);
  99. void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
  100. struct drm_atomic_state *old_state);
  101. int drm_atomic_helper_prepare_planes(struct drm_device *dev,
  102. struct drm_atomic_state *state);
  103. void drm_atomic_helper_unprepare_planes(struct drm_device *dev,
  104. struct drm_atomic_state *state);
  105. #define DRM_PLANE_COMMIT_ACTIVE_ONLY BIT(0)
  106. #define DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET BIT(1)
  107. void drm_atomic_helper_commit_planes(struct drm_device *dev,
  108. struct drm_atomic_state *state,
  109. uint32_t flags);
  110. void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
  111. struct drm_atomic_state *old_state);
  112. void drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state);
  113. void
  114. drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state,
  115. bool atomic);
  116. int __must_check drm_atomic_helper_swap_state(struct drm_atomic_state *state,
  117. bool stall);
  118. /* nonblocking commit helpers */
  119. int drm_atomic_helper_setup_commit(struct drm_atomic_state *state,
  120. bool nonblock);
  121. void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *state);
  122. void drm_atomic_helper_fake_vblank(struct drm_atomic_state *state);
  123. void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *state);
  124. void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *state);
  125. /* implementations for legacy interfaces */
  126. int drm_atomic_helper_update_plane(struct drm_plane *plane,
  127. struct drm_crtc *crtc,
  128. struct drm_framebuffer *fb,
  129. int crtc_x, int crtc_y,
  130. unsigned int crtc_w, unsigned int crtc_h,
  131. uint32_t src_x, uint32_t src_y,
  132. uint32_t src_w, uint32_t src_h,
  133. struct drm_modeset_acquire_ctx *ctx);
  134. int drm_atomic_helper_disable_plane(struct drm_plane *plane,
  135. struct drm_modeset_acquire_ctx *ctx);
  136. int drm_atomic_helper_set_config(struct drm_mode_set *set,
  137. struct drm_modeset_acquire_ctx *ctx);
  138. int drm_atomic_helper_disable_all(struct drm_device *dev,
  139. struct drm_modeset_acquire_ctx *ctx);
  140. int drm_atomic_helper_reset_crtc(struct drm_crtc *crtc,
  141. struct drm_modeset_acquire_ctx *ctx);
  142. void drm_atomic_helper_shutdown(struct drm_device *dev);
  143. struct drm_atomic_state *
  144. drm_atomic_helper_duplicate_state(struct drm_device *dev,
  145. struct drm_modeset_acquire_ctx *ctx);
  146. struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev);
  147. int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
  148. struct drm_modeset_acquire_ctx *ctx);
  149. int drm_atomic_helper_resume(struct drm_device *dev,
  150. struct drm_atomic_state *state);
  151. int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
  152. struct drm_framebuffer *fb,
  153. struct drm_pending_vblank_event *event,
  154. uint32_t flags,
  155. struct drm_modeset_acquire_ctx *ctx);
  156. int drm_atomic_helper_page_flip_target(
  157. struct drm_crtc *crtc,
  158. struct drm_framebuffer *fb,
  159. struct drm_pending_vblank_event *event,
  160. uint32_t flags,
  161. uint32_t target,
  162. struct drm_modeset_acquire_ctx *ctx);
  163. /**
  164. * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
  165. * @plane: the loop cursor
  166. * @crtc: the CRTC whose planes are iterated
  167. *
  168. * This iterates over the current state, useful (for example) when applying
  169. * atomic state after it has been checked and swapped. To iterate over the
  170. * planes which *will* be attached (more useful in code called from
  171. * &drm_mode_config_funcs.atomic_check) see
  172. * drm_atomic_crtc_state_for_each_plane().
  173. */
  174. #define drm_atomic_crtc_for_each_plane(plane, crtc) \
  175. drm_for_each_plane_mask(plane, (crtc)->dev, (crtc)->state->plane_mask)
  176. /**
  177. * drm_atomic_crtc_state_for_each_plane - iterate over attached planes in new state
  178. * @plane: the loop cursor
  179. * @crtc_state: the incoming CRTC state
  180. *
  181. * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
  182. * attached if the specified state is applied. Useful during for example
  183. * in code called from &drm_mode_config_funcs.atomic_check operations, to
  184. * validate the incoming state.
  185. */
  186. #define drm_atomic_crtc_state_for_each_plane(plane, crtc_state) \
  187. drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask)
  188. /**
  189. * drm_atomic_crtc_state_for_each_plane_state - iterate over attached planes in new state
  190. * @plane: the loop cursor
  191. * @plane_state: loop cursor for the plane's state, must be const
  192. * @crtc_state: the incoming CRTC state
  193. *
  194. * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
  195. * attached if the specified state is applied. Useful during for example
  196. * in code called from &drm_mode_config_funcs.atomic_check operations, to
  197. * validate the incoming state.
  198. *
  199. * Compared to just drm_atomic_crtc_state_for_each_plane() this also fills in a
  200. * const plane_state. This is useful when a driver just wants to peek at other
  201. * active planes on this CRTC, but does not need to change it.
  202. */
  203. #define drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) \
  204. drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) \
  205. for_each_if ((plane_state = \
  206. __drm_atomic_get_current_plane_state((crtc_state)->state, \
  207. plane)))
  208. /**
  209. * drm_atomic_plane_enabling - check whether a plane is being enabled
  210. * @old_plane_state: old atomic plane state
  211. * @new_plane_state: new atomic plane state
  212. *
  213. * Checks the atomic state of a plane to determine whether it's being enabled
  214. * or not. This also WARNs if it detects an invalid state (both CRTC and FB
  215. * need to either both be NULL or both be non-NULL).
  216. *
  217. * RETURNS:
  218. * True if the plane is being enabled, false otherwise.
  219. */
  220. static inline bool drm_atomic_plane_enabling(struct drm_plane_state *old_plane_state,
  221. struct drm_plane_state *new_plane_state)
  222. {
  223. /*
  224. * When enabling a plane, CRTC and FB should always be set together.
  225. * Anything else should be considered a bug in the atomic core, so we
  226. * gently warn about it.
  227. */
  228. WARN_ON((!new_plane_state->crtc && new_plane_state->fb) ||
  229. (new_plane_state->crtc && !new_plane_state->fb));
  230. return !old_plane_state->crtc && new_plane_state->crtc;
  231. }
  232. /**
  233. * drm_atomic_plane_disabling - check whether a plane is being disabled
  234. * @old_plane_state: old atomic plane state
  235. * @new_plane_state: new atomic plane state
  236. *
  237. * Checks the atomic state of a plane to determine whether it's being disabled
  238. * or not. This also WARNs if it detects an invalid state (both CRTC and FB
  239. * need to either both be NULL or both be non-NULL).
  240. *
  241. * RETURNS:
  242. * True if the plane is being disabled, false otherwise.
  243. */
  244. static inline bool
  245. drm_atomic_plane_disabling(struct drm_plane_state *old_plane_state,
  246. struct drm_plane_state *new_plane_state)
  247. {
  248. /*
  249. * When disabling a plane, CRTC and FB should always be NULL together.
  250. * Anything else should be considered a bug in the atomic core, so we
  251. * gently warn about it.
  252. */
  253. WARN_ON((new_plane_state->crtc == NULL && new_plane_state->fb != NULL) ||
  254. (new_plane_state->crtc != NULL && new_plane_state->fb == NULL));
  255. return old_plane_state->crtc && !new_plane_state->crtc;
  256. }
  257. u32 *
  258. drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
  259. struct drm_bridge_state *bridge_state,
  260. struct drm_crtc_state *crtc_state,
  261. struct drm_connector_state *conn_state,
  262. u32 output_fmt,
  263. unsigned int *num_input_fmts);
  264. #endif /* DRM_ATOMIC_HELPER_H_ */