drm_gem_atomic_helper.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. #ifndef __DRM_GEM_ATOMIC_HELPER_H__
  3. #define __DRM_GEM_ATOMIC_HELPER_H__
  4. #include <linux/iosys-map.h>
  5. #include <drm/drm_format_helper.h>
  6. #include <drm/drm_fourcc.h>
  7. #include <drm/drm_plane.h>
  8. struct drm_simple_display_pipe;
  9. /*
  10. * Plane Helpers
  11. */
  12. int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state);
  13. /*
  14. * Helpers for planes with shadow buffers
  15. */
  16. /**
  17. * DRM_SHADOW_PLANE_MAX_WIDTH - Maximum width of a plane's shadow buffer in pixels
  18. *
  19. * For drivers with shadow planes, the maximum width of the framebuffer is
  20. * usually independent from hardware limitations. Drivers can initialize struct
  21. * drm_mode_config.max_width from DRM_SHADOW_PLANE_MAX_WIDTH.
  22. */
  23. #define DRM_SHADOW_PLANE_MAX_WIDTH (4096u)
  24. /**
  25. * DRM_SHADOW_PLANE_MAX_HEIGHT - Maximum height of a plane's shadow buffer in scanlines
  26. *
  27. * For drivers with shadow planes, the maximum height of the framebuffer is
  28. * usually independent from hardware limitations. Drivers can initialize struct
  29. * drm_mode_config.max_height from DRM_SHADOW_PLANE_MAX_HEIGHT.
  30. */
  31. #define DRM_SHADOW_PLANE_MAX_HEIGHT (4096u)
  32. /**
  33. * struct drm_shadow_plane_state - plane state for planes with shadow buffers
  34. *
  35. * For planes that use a shadow buffer, struct drm_shadow_plane_state
  36. * provides the regular plane state plus mappings of the shadow buffer
  37. * into kernel address space.
  38. */
  39. struct drm_shadow_plane_state {
  40. /** @base: plane state */
  41. struct drm_plane_state base;
  42. /**
  43. * @fmtcnv_state: Format-conversion state
  44. *
  45. * Per-plane state for format conversion.
  46. * Flags for copying shadow buffers into backend storage. Also holds
  47. * temporary storage for format conversion.
  48. */
  49. struct drm_format_conv_state fmtcnv_state;
  50. /* Transitional state - do not export or duplicate */
  51. /**
  52. * @map: Mappings of the plane's framebuffer BOs in to kernel address space
  53. *
  54. * The memory mappings stored in map should be established in the plane's
  55. * prepare_fb callback and removed in the cleanup_fb callback.
  56. */
  57. struct iosys_map map[DRM_FORMAT_MAX_PLANES];
  58. /**
  59. * @data: Address of each framebuffer BO's data
  60. *
  61. * The address of the data stored in each mapping. This is different
  62. * for framebuffers with non-zero offset fields.
  63. */
  64. struct iosys_map data[DRM_FORMAT_MAX_PLANES];
  65. };
  66. /**
  67. * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
  68. * @state: the plane state
  69. */
  70. static inline struct drm_shadow_plane_state *
  71. to_drm_shadow_plane_state(struct drm_plane_state *state)
  72. {
  73. return container_of(state, struct drm_shadow_plane_state, base);
  74. }
  75. void __drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane,
  76. struct drm_shadow_plane_state *new_shadow_plane_state);
  77. void __drm_gem_destroy_shadow_plane_state(struct drm_shadow_plane_state *shadow_plane_state);
  78. void __drm_gem_reset_shadow_plane(struct drm_plane *plane,
  79. struct drm_shadow_plane_state *shadow_plane_state);
  80. void drm_gem_reset_shadow_plane(struct drm_plane *plane);
  81. struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
  82. void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
  83. struct drm_plane_state *plane_state);
  84. /**
  85. * DRM_GEM_SHADOW_PLANE_FUNCS -
  86. * Initializes struct drm_plane_funcs for shadow-buffered planes
  87. *
  88. * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
  89. * macro initializes struct drm_plane_funcs to use the rsp helper functions.
  90. */
  91. #define DRM_GEM_SHADOW_PLANE_FUNCS \
  92. .reset = drm_gem_reset_shadow_plane, \
  93. .atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
  94. .atomic_destroy_state = drm_gem_destroy_shadow_plane_state
  95. int drm_gem_begin_shadow_fb_access(struct drm_plane *plane, struct drm_plane_state *plane_state);
  96. void drm_gem_end_shadow_fb_access(struct drm_plane *plane, struct drm_plane_state *plane_state);
  97. /**
  98. * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
  99. * Initializes struct drm_plane_helper_funcs for shadow-buffered planes
  100. *
  101. * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
  102. * macro initializes struct drm_plane_helper_funcs to use the rsp helper
  103. * functions.
  104. */
  105. #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
  106. .begin_fb_access = drm_gem_begin_shadow_fb_access, \
  107. .end_fb_access = drm_gem_end_shadow_fb_access
  108. int drm_gem_simple_kms_begin_shadow_fb_access(struct drm_simple_display_pipe *pipe,
  109. struct drm_plane_state *plane_state);
  110. void drm_gem_simple_kms_end_shadow_fb_access(struct drm_simple_display_pipe *pipe,
  111. struct drm_plane_state *plane_state);
  112. void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
  113. struct drm_plane_state *
  114. drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
  115. void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
  116. struct drm_plane_state *plane_state);
  117. /**
  118. * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
  119. * Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
  120. *
  121. * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
  122. * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
  123. * functions.
  124. */
  125. #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
  126. .begin_fb_access = drm_gem_simple_kms_begin_shadow_fb_access, \
  127. .end_fb_access = drm_gem_simple_kms_end_shadow_fb_access, \
  128. .reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
  129. .duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
  130. .destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
  131. #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */