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