drm_simple_kms_helper.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2016 Noralf Trønnes
  4. */
  5. #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H
  6. #define __LINUX_DRM_SIMPLE_KMS_HELPER_H
  7. #include <drm/drm_crtc.h>
  8. #include <drm/drm_encoder.h>
  9. #include <drm/drm_plane.h>
  10. struct drm_simple_display_pipe;
  11. /**
  12. * struct drm_simple_display_pipe_funcs - helper operations for a simple
  13. * display pipeline
  14. */
  15. struct drm_simple_display_pipe_funcs {
  16. /**
  17. * @mode_valid:
  18. *
  19. * This callback is used to check if a specific mode is valid in the
  20. * crtc used in this simple display pipe. This should be implemented
  21. * if the display pipe has some sort of restriction in the modes
  22. * it can display. For example, a given display pipe may be responsible
  23. * to set a clock value. If the clock can not produce all the values
  24. * for the available modes then this callback can be used to restrict
  25. * the number of modes to only the ones that can be displayed. Another
  26. * reason can be bandwidth mitigation: the memory port on the display
  27. * controller can have bandwidth limitations not allowing pixel data
  28. * to be fetched at any rate.
  29. *
  30. * This hook is used by the probe helpers to filter the mode list in
  31. * drm_helper_probe_single_connector_modes(), and it is used by the
  32. * atomic helpers to validate modes supplied by userspace in
  33. * drm_atomic_helper_check_modeset().
  34. *
  35. * This function is optional.
  36. *
  37. * NOTE:
  38. *
  39. * Since this function is both called from the check phase of an atomic
  40. * commit, and the mode validation in the probe paths it is not allowed
  41. * to look at anything else but the passed-in mode, and validate it
  42. * against configuration-invariant hardware constraints.
  43. *
  44. * RETURNS:
  45. *
  46. * drm_mode_status Enum
  47. */
  48. enum drm_mode_status (*mode_valid)(struct drm_simple_display_pipe *pipe,
  49. const struct drm_display_mode *mode);
  50. /**
  51. * @enable:
  52. *
  53. * This function should be used to enable the pipeline.
  54. * It is called when the underlying crtc is enabled.
  55. * This hook is optional.
  56. */
  57. void (*enable)(struct drm_simple_display_pipe *pipe,
  58. struct drm_crtc_state *crtc_state,
  59. struct drm_plane_state *plane_state);
  60. /**
  61. * @disable:
  62. *
  63. * This function should be used to disable the pipeline.
  64. * It is called when the underlying crtc is disabled.
  65. * This hook is optional.
  66. */
  67. void (*disable)(struct drm_simple_display_pipe *pipe);
  68. /**
  69. * @check:
  70. *
  71. * This function is called in the check phase of an atomic update,
  72. * specifically when the underlying plane is checked.
  73. * The simple display pipeline helpers already check that the plane is
  74. * not scaled, fills the entire visible area and is always enabled
  75. * when the crtc is also enabled.
  76. * This hook is optional.
  77. *
  78. * RETURNS:
  79. *
  80. * 0 on success, -EINVAL if the state or the transition can't be
  81. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  82. * attempt to obtain another state object ran into a &drm_modeset_lock
  83. * deadlock.
  84. */
  85. int (*check)(struct drm_simple_display_pipe *pipe,
  86. struct drm_plane_state *plane_state,
  87. struct drm_crtc_state *crtc_state);
  88. /**
  89. * @update:
  90. *
  91. * This function is called when the underlying plane state is updated.
  92. * This hook is optional.
  93. *
  94. * This is the function drivers should submit the
  95. * &drm_pending_vblank_event from. Using either
  96. * drm_crtc_arm_vblank_event(), when the driver supports vblank
  97. * interrupt handling, or drm_crtc_send_vblank_event() for more
  98. * complex case. In case the hardware lacks vblank support entirely,
  99. * drivers can set &struct drm_crtc_state.no_vblank in
  100. * &struct drm_simple_display_pipe_funcs.check and let DRM's
  101. * atomic helper fake a vblank event.
  102. */
  103. void (*update)(struct drm_simple_display_pipe *pipe,
  104. struct drm_plane_state *old_plane_state);
  105. /**
  106. * @prepare_fb:
  107. *
  108. * Optional, called by &drm_plane_helper_funcs.prepare_fb. Please read
  109. * the documentation for the &drm_plane_helper_funcs.prepare_fb hook for
  110. * more details.
  111. *
  112. * For GEM drivers who neither have a @prepare_fb nor @cleanup_fb hook
  113. * set drm_gem_simple_display_pipe_prepare_fb() is called automatically
  114. * to implement this. Other drivers which need additional plane
  115. * processing can call drm_gem_simple_display_pipe_prepare_fb() from
  116. * their @prepare_fb hook.
  117. */
  118. int (*prepare_fb)(struct drm_simple_display_pipe *pipe,
  119. struct drm_plane_state *plane_state);
  120. /**
  121. * @cleanup_fb:
  122. *
  123. * Optional, called by &drm_plane_helper_funcs.cleanup_fb. Please read
  124. * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for
  125. * more details.
  126. */
  127. void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,
  128. struct drm_plane_state *plane_state);
  129. /**
  130. * @enable_vblank:
  131. *
  132. * Optional, called by &drm_crtc_funcs.enable_vblank. Please read
  133. * the documentation for the &drm_crtc_funcs.enable_vblank hook for
  134. * more details.
  135. */
  136. int (*enable_vblank)(struct drm_simple_display_pipe *pipe);
  137. /**
  138. * @disable_vblank:
  139. *
  140. * Optional, called by &drm_crtc_funcs.disable_vblank. Please read
  141. * the documentation for the &drm_crtc_funcs.disable_vblank hook for
  142. * more details.
  143. */
  144. void (*disable_vblank)(struct drm_simple_display_pipe *pipe);
  145. /**
  146. * @reset_crtc:
  147. *
  148. * Optional, called by &drm_crtc_funcs.reset. Please read the
  149. * documentation for the &drm_crtc_funcs.reset hook for more details.
  150. */
  151. void (*reset_crtc)(struct drm_simple_display_pipe *pipe);
  152. /**
  153. * @duplicate_crtc_state:
  154. *
  155. * Optional, called by &drm_crtc_funcs.atomic_duplicate_state. Please
  156. * read the documentation for the &drm_crtc_funcs.atomic_duplicate_state
  157. * hook for more details.
  158. */
  159. struct drm_crtc_state * (*duplicate_crtc_state)(struct drm_simple_display_pipe *pipe);
  160. /**
  161. * @destroy_crtc_state:
  162. *
  163. * Optional, called by &drm_crtc_funcs.atomic_destroy_state. Please
  164. * read the documentation for the &drm_crtc_funcs.atomic_destroy_state
  165. * hook for more details.
  166. */
  167. void (*destroy_crtc_state)(struct drm_simple_display_pipe *pipe,
  168. struct drm_crtc_state *crtc_state);
  169. /**
  170. * @reset_plane:
  171. *
  172. * Optional, called by &drm_plane_funcs.reset. Please read the
  173. * documentation for the &drm_plane_funcs.reset hook for more details.
  174. */
  175. void (*reset_plane)(struct drm_simple_display_pipe *pipe);
  176. /**
  177. * @duplicate_plane_state:
  178. *
  179. * Optional, called by &drm_plane_funcs.atomic_duplicate_state. Please
  180. * read the documentation for the &drm_plane_funcs.atomic_duplicate_state
  181. * hook for more details.
  182. */
  183. struct drm_plane_state * (*duplicate_plane_state)(struct drm_simple_display_pipe *pipe);
  184. /**
  185. * @destroy_plane_state:
  186. *
  187. * Optional, called by &drm_plane_funcs.atomic_destroy_state. Please
  188. * read the documentation for the &drm_plane_funcs.atomic_destroy_state
  189. * hook for more details.
  190. */
  191. void (*destroy_plane_state)(struct drm_simple_display_pipe *pipe,
  192. struct drm_plane_state *plane_state);
  193. };
  194. /**
  195. * struct drm_simple_display_pipe - simple display pipeline
  196. * @crtc: CRTC control structure
  197. * @plane: Plane control structure
  198. * @encoder: Encoder control structure
  199. * @connector: Connector control structure
  200. * @funcs: Pipeline control functions (optional)
  201. *
  202. * Simple display pipeline with plane, crtc and encoder collapsed into one
  203. * entity. It should be initialized by calling drm_simple_display_pipe_init().
  204. */
  205. struct drm_simple_display_pipe {
  206. struct drm_crtc crtc;
  207. struct drm_plane plane;
  208. struct drm_encoder encoder;
  209. struct drm_connector *connector;
  210. const struct drm_simple_display_pipe_funcs *funcs;
  211. };
  212. int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
  213. struct drm_bridge *bridge);
  214. int drm_simple_display_pipe_init(struct drm_device *dev,
  215. struct drm_simple_display_pipe *pipe,
  216. const struct drm_simple_display_pipe_funcs *funcs,
  217. const uint32_t *formats, unsigned int format_count,
  218. const uint64_t *format_modifiers,
  219. struct drm_connector *connector);
  220. int drm_simple_encoder_init(struct drm_device *dev,
  221. struct drm_encoder *encoder,
  222. int encoder_type);
  223. void *__drmm_simple_encoder_alloc(struct drm_device *dev, size_t size,
  224. size_t offset, int encoder_type);
  225. /**
  226. * drmm_simple_encoder_alloc - Allocate and initialize an encoder with basic
  227. * functionality.
  228. * @dev: drm device
  229. * @type: the type of the struct which contains struct &drm_encoder
  230. * @member: the name of the &drm_encoder within @type.
  231. * @encoder_type: user visible type of the encoder
  232. *
  233. * Allocates and initializes an encoder that has no further functionality.
  234. * Settings for possible CRTC and clones are left to their initial values.
  235. * Cleanup is automatically handled through registering drm_encoder_cleanup()
  236. * with drmm_add_action().
  237. *
  238. * Returns:
  239. * Pointer to new encoder, or ERR_PTR on failure.
  240. */
  241. #define drmm_simple_encoder_alloc(dev, type, member, encoder_type) \
  242. ((type *)__drmm_simple_encoder_alloc(dev, sizeof(type), \
  243. offsetof(type, member), \
  244. encoder_type))
  245. #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */