drm_simple_kms_helper.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * Copyright (C) 2016 Noralf Trønnes
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. */
  9. #ifndef __LINUX_DRM_SIMPLE_KMS_HELPER_H
  10. #define __LINUX_DRM_SIMPLE_KMS_HELPER_H
  11. #include <drm/drm_crtc.h>
  12. #include <drm/drm_encoder.h>
  13. #include <drm/drm_plane.h>
  14. struct drm_simple_display_pipe;
  15. /**
  16. * struct drm_simple_display_pipe_funcs - helper operations for a simple
  17. * display pipeline
  18. */
  19. struct drm_simple_display_pipe_funcs {
  20. /**
  21. * @mode_valid:
  22. *
  23. * This callback is used to check if a specific mode is valid in the
  24. * crtc used in this simple display pipe. This should be implemented
  25. * if the display pipe has some sort of restriction in the modes
  26. * it can display. For example, a given display pipe may be responsible
  27. * to set a clock value. If the clock can not produce all the values
  28. * for the available modes then this callback can be used to restrict
  29. * the number of modes to only the ones that can be displayed. Another
  30. * reason can be bandwidth mitigation: the memory port on the display
  31. * controller can have bandwidth limitations not allowing pixel data
  32. * to be fetched at any rate.
  33. *
  34. * This hook is used by the probe helpers to filter the mode list in
  35. * drm_helper_probe_single_connector_modes(), and it is used by the
  36. * atomic helpers to validate modes supplied by userspace in
  37. * drm_atomic_helper_check_modeset().
  38. *
  39. * This function is optional.
  40. *
  41. * NOTE:
  42. *
  43. * Since this function is both called from the check phase of an atomic
  44. * commit, and the mode validation in the probe paths it is not allowed
  45. * to look at anything else but the passed-in mode, and validate it
  46. * against configuration-invariant hardware constraints.
  47. *
  48. * RETURNS:
  49. *
  50. * drm_mode_status Enum
  51. */
  52. enum drm_mode_status (*mode_valid)(struct drm_crtc *crtc,
  53. const struct drm_display_mode *mode);
  54. /**
  55. * @enable:
  56. *
  57. * This function should be used to enable the pipeline.
  58. * It is called when the underlying crtc is enabled.
  59. * This hook is optional.
  60. */
  61. void (*enable)(struct drm_simple_display_pipe *pipe,
  62. struct drm_crtc_state *crtc_state,
  63. struct drm_plane_state *plane_state);
  64. /**
  65. * @disable:
  66. *
  67. * This function should be used to disable the pipeline.
  68. * It is called when the underlying crtc is disabled.
  69. * This hook is optional.
  70. */
  71. void (*disable)(struct drm_simple_display_pipe *pipe);
  72. /**
  73. * @check:
  74. *
  75. * This function is called in the check phase of an atomic update,
  76. * specifically when the underlying plane is checked.
  77. * The simple display pipeline helpers already check that the plane is
  78. * not scaled, fills the entire visible area and is always enabled
  79. * when the crtc is also enabled.
  80. * This hook is optional.
  81. *
  82. * RETURNS:
  83. *
  84. * 0 on success, -EINVAL if the state or the transition can't be
  85. * supported, -ENOMEM on memory allocation failure and -EDEADLK if an
  86. * attempt to obtain another state object ran into a &drm_modeset_lock
  87. * deadlock.
  88. */
  89. int (*check)(struct drm_simple_display_pipe *pipe,
  90. struct drm_plane_state *plane_state,
  91. struct drm_crtc_state *crtc_state);
  92. /**
  93. * @update:
  94. *
  95. * This function is called when the underlying plane state is updated.
  96. * This hook is optional.
  97. *
  98. * This is the function drivers should submit the
  99. * &drm_pending_vblank_event from. Using either
  100. * drm_crtc_arm_vblank_event(), when the driver supports vblank
  101. * interrupt handling, or drm_crtc_send_vblank_event() directly in case
  102. * the hardware lacks vblank support entirely.
  103. */
  104. void (*update)(struct drm_simple_display_pipe *pipe,
  105. struct drm_plane_state *old_plane_state);
  106. /**
  107. * @prepare_fb:
  108. *
  109. * Optional, called by &drm_plane_helper_funcs.prepare_fb. Please read
  110. * the documentation for the &drm_plane_helper_funcs.prepare_fb hook for
  111. * more details.
  112. *
  113. * Drivers which always have their buffers pinned should use
  114. * drm_gem_fb_simple_display_pipe_prepare_fb() for this hook.
  115. */
  116. int (*prepare_fb)(struct drm_simple_display_pipe *pipe,
  117. struct drm_plane_state *plane_state);
  118. /**
  119. * @cleanup_fb:
  120. *
  121. * Optional, called by &drm_plane_helper_funcs.cleanup_fb. Please read
  122. * the documentation for the &drm_plane_helper_funcs.cleanup_fb hook for
  123. * more details.
  124. */
  125. void (*cleanup_fb)(struct drm_simple_display_pipe *pipe,
  126. struct drm_plane_state *plane_state);
  127. /**
  128. * @enable_vblank:
  129. *
  130. * Optional, called by &drm_crtc_funcs.enable_vblank. Please read
  131. * the documentation for the &drm_crtc_funcs.enable_vblank hook for
  132. * more details.
  133. */
  134. int (*enable_vblank)(struct drm_simple_display_pipe *pipe);
  135. /**
  136. * @disable_vblank:
  137. *
  138. * Optional, called by &drm_crtc_funcs.disable_vblank. Please read
  139. * the documentation for the &drm_crtc_funcs.disable_vblank hook for
  140. * more details.
  141. */
  142. void (*disable_vblank)(struct drm_simple_display_pipe *pipe);
  143. };
  144. /**
  145. * struct drm_simple_display_pipe - simple display pipeline
  146. * @crtc: CRTC control structure
  147. * @plane: Plane control structure
  148. * @encoder: Encoder control structure
  149. * @connector: Connector control structure
  150. * @funcs: Pipeline control functions (optional)
  151. *
  152. * Simple display pipeline with plane, crtc and encoder collapsed into one
  153. * entity. It should be initialized by calling drm_simple_display_pipe_init().
  154. */
  155. struct drm_simple_display_pipe {
  156. struct drm_crtc crtc;
  157. struct drm_plane plane;
  158. struct drm_encoder encoder;
  159. struct drm_connector *connector;
  160. const struct drm_simple_display_pipe_funcs *funcs;
  161. };
  162. int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
  163. struct drm_bridge *bridge);
  164. int drm_simple_display_pipe_init(struct drm_device *dev,
  165. struct drm_simple_display_pipe *pipe,
  166. const struct drm_simple_display_pipe_funcs *funcs,
  167. const uint32_t *formats, unsigned int format_count,
  168. const uint64_t *format_modifiers,
  169. struct drm_connector *connector);
  170. #endif /* __LINUX_DRM_SIMPLE_KMS_HELPER_H */