drm_simple_kms_helper.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. * Drivers which always have their buffers pinned should use
  113. * drm_gem_fb_simple_display_pipe_prepare_fb() for this hook.
  114. */
  115. int (*prepare_fb)(struct drm_simple_display_pipe *pipe,
  116. struct drm_plane_state *plane_state);
  117. /**
  118. * @cleanup_fb:
  119. *
  120. * Optional, called by &drm_plane_helper_funcs.cleanup_fb. Please read
  121. * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for
  122. * more details.
  123. */
  124. void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,
  125. struct drm_plane_state *plane_state);
  126. /**
  127. * @enable_vblank:
  128. *
  129. * Optional, called by &drm_crtc_funcs.enable_vblank. Please read
  130. * the documentation for the &drm_crtc_funcs.enable_vblank hook for
  131. * more details.
  132. */
  133. int (*enable_vblank)(struct drm_simple_display_pipe *pipe);
  134. /**
  135. * @disable_vblank:
  136. *
  137. * Optional, called by &drm_crtc_funcs.disable_vblank. Please read
  138. * the documentation for the &drm_crtc_funcs.disable_vblank hook for
  139. * more details.
  140. */
  141. void (*disable_vblank)(struct drm_simple_display_pipe *pipe);
  142. };
  143. /**
  144. * struct drm_simple_display_pipe - simple display pipeline
  145. * @crtc: CRTC control structure
  146. * @plane: Plane control structure
  147. * @encoder: Encoder control structure
  148. * @connector: Connector control structure
  149. * @funcs: Pipeline control functions (optional)
  150. *
  151. * Simple display pipeline with plane, crtc and encoder collapsed into one
  152. * entity. It should be initialized by calling drm_simple_display_pipe_init().
  153. */
  154. struct drm_simple_display_pipe {
  155. struct drm_crtc crtc;
  156. struct drm_plane plane;
  157. struct drm_encoder encoder;
  158. struct drm_connector *connector;
  159. const struct drm_simple_display_pipe_funcs *funcs;
  160. };
  161. int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
  162. struct drm_bridge *bridge);
  163. int drm_simple_display_pipe_init(struct drm_device *dev,
  164. struct drm_simple_display_pipe *pipe,
  165. const struct drm_simple_display_pipe_funcs *funcs,
  166. const uint32_t *formats, unsigned int format_count,
  167. const uint64_t *format_modifiers,
  168. struct drm_connector *connector);
  169. int drm_simple_encoder_init(struct drm_device *dev,
  170. struct drm_encoder *encoder,
  171. int encoder_type);
  172. #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */