drm_simple_kms_helper.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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_plane_helper_prepare_fb() is called automatically
  114. * to implement this. Other drivers which need additional plane
  115. * processing can call drm_gem_plane_helper_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. * @begin_fb_access:
  131. *
  132. * Optional, called by &drm_plane_helper_funcs.begin_fb_access. Please read
  133. * the documentation for the &drm_plane_helper_funcs.begin_fb_access hook for
  134. * more details.
  135. */
  136. int (*begin_fb_access)(struct drm_simple_display_pipe *pipe,
  137. struct drm_plane_state *new_plane_state);
  138. /**
  139. * @end_fb_access:
  140. *
  141. * Optional, called by &drm_plane_helper_funcs.end_fb_access. Please read
  142. * the documentation for the &drm_plane_helper_funcs.end_fb_access hook for
  143. * more details.
  144. */
  145. void (*end_fb_access)(struct drm_simple_display_pipe *pipe,
  146. struct drm_plane_state *plane_state);
  147. /**
  148. * @enable_vblank:
  149. *
  150. * Optional, called by &drm_crtc_funcs.enable_vblank. Please read
  151. * the documentation for the &drm_crtc_funcs.enable_vblank hook for
  152. * more details.
  153. */
  154. int (*enable_vblank)(struct drm_simple_display_pipe *pipe);
  155. /**
  156. * @disable_vblank:
  157. *
  158. * Optional, called by &drm_crtc_funcs.disable_vblank. Please read
  159. * the documentation for the &drm_crtc_funcs.disable_vblank hook for
  160. * more details.
  161. */
  162. void (*disable_vblank)(struct drm_simple_display_pipe *pipe);
  163. /**
  164. * @reset_crtc:
  165. *
  166. * Optional, called by &drm_crtc_funcs.reset. Please read the
  167. * documentation for the &drm_crtc_funcs.reset hook for more details.
  168. */
  169. void (*reset_crtc)(struct drm_simple_display_pipe *pipe);
  170. /**
  171. * @duplicate_crtc_state:
  172. *
  173. * Optional, called by &drm_crtc_funcs.atomic_duplicate_state. Please
  174. * read the documentation for the &drm_crtc_funcs.atomic_duplicate_state
  175. * hook for more details.
  176. */
  177. struct drm_crtc_state * (*duplicate_crtc_state)(struct drm_simple_display_pipe *pipe);
  178. /**
  179. * @destroy_crtc_state:
  180. *
  181. * Optional, called by &drm_crtc_funcs.atomic_destroy_state. Please
  182. * read the documentation for the &drm_crtc_funcs.atomic_destroy_state
  183. * hook for more details.
  184. */
  185. void (*destroy_crtc_state)(struct drm_simple_display_pipe *pipe,
  186. struct drm_crtc_state *crtc_state);
  187. /**
  188. * @reset_plane:
  189. *
  190. * Optional, called by &drm_plane_funcs.reset. Please read the
  191. * documentation for the &drm_plane_funcs.reset hook for more details.
  192. */
  193. void (*reset_plane)(struct drm_simple_display_pipe *pipe);
  194. /**
  195. * @duplicate_plane_state:
  196. *
  197. * Optional, called by &drm_plane_funcs.atomic_duplicate_state. Please
  198. * read the documentation for the &drm_plane_funcs.atomic_duplicate_state
  199. * hook for more details.
  200. */
  201. struct drm_plane_state * (*duplicate_plane_state)(struct drm_simple_display_pipe *pipe);
  202. /**
  203. * @destroy_plane_state:
  204. *
  205. * Optional, called by &drm_plane_funcs.atomic_destroy_state. Please
  206. * read the documentation for the &drm_plane_funcs.atomic_destroy_state
  207. * hook for more details.
  208. */
  209. void (*destroy_plane_state)(struct drm_simple_display_pipe *pipe,
  210. struct drm_plane_state *plane_state);
  211. };
  212. /**
  213. * struct drm_simple_display_pipe - simple display pipeline
  214. * @crtc: CRTC control structure
  215. * @plane: Plane control structure
  216. * @encoder: Encoder control structure
  217. * @connector: Connector control structure
  218. * @funcs: Pipeline control functions (optional)
  219. *
  220. * Simple display pipeline with plane, crtc and encoder collapsed into one
  221. * entity. It should be initialized by calling drm_simple_display_pipe_init().
  222. */
  223. struct drm_simple_display_pipe {
  224. struct drm_crtc crtc;
  225. struct drm_plane plane;
  226. struct drm_encoder encoder;
  227. struct drm_connector *connector;
  228. const struct drm_simple_display_pipe_funcs *funcs;
  229. };
  230. int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
  231. struct drm_bridge *bridge);
  232. int drm_simple_display_pipe_init(struct drm_device *dev,
  233. struct drm_simple_display_pipe *pipe,
  234. const struct drm_simple_display_pipe_funcs *funcs,
  235. const uint32_t *formats, unsigned int format_count,
  236. const uint64_t *format_modifiers,
  237. struct drm_connector *connector);
  238. int drm_simple_encoder_init(struct drm_device *dev,
  239. struct drm_encoder *encoder,
  240. int encoder_type);
  241. void *__drmm_simple_encoder_alloc(struct drm_device *dev, size_t size,
  242. size_t offset, int encoder_type);
  243. /**
  244. * drmm_simple_encoder_alloc - Allocate and initialize an encoder with basic
  245. * functionality.
  246. * @dev: drm device
  247. * @type: the type of the struct which contains struct &drm_encoder
  248. * @member: the name of the &drm_encoder within @type.
  249. * @encoder_type: user visible type of the encoder
  250. *
  251. * Allocates and initializes an encoder that has no further functionality.
  252. * Settings for possible CRTC and clones are left to their initial values.
  253. * Cleanup is automatically handled through registering drm_encoder_cleanup()
  254. * with drmm_add_action().
  255. *
  256. * Returns:
  257. * Pointer to new encoder, or ERR_PTR on failure.
  258. */
  259. #define drmm_simple_encoder_alloc(dev, type, member, encoder_type) \
  260. ((type *)__drmm_simple_encoder_alloc(dev, sizeof(type), \
  261. offsetof(type, member), \
  262. encoder_type))
  263. #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */