drm_gem_atomic_helper.h 5.3 KB

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