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_plane.h> 9 10 struct drm_simple_display_pipe; 11 12 /* 13 * Helpers for planes with shadow buffers 14 */ 15 16 /** 17 * struct drm_shadow_plane_state - plane state for planes with shadow buffers 18 * 19 * For planes that use a shadow buffer, struct drm_shadow_plane_state 20 * provides the regular plane state plus mappings of the shadow buffer 21 * into kernel address space. 22 */ 23 struct drm_shadow_plane_state { 24 /** @base: plane state */ 25 struct drm_plane_state base; 26 27 /* Transitional state - do not export or duplicate */ 28 29 /** 30 * @map: Mappings of the plane's framebuffer BOs in to kernel address space 31 * 32 * The memory mappings stored in map should be established in the plane's 33 * prepare_fb callback and removed in the cleanup_fb callback. 34 */ 35 struct dma_buf_map map[4]; 36 }; 37 38 /** 39 * to_drm_shadow_plane_state - upcasts from struct drm_plane_state 40 * @state: the plane state 41 */ 42 static inline struct drm_shadow_plane_state * 43 to_drm_shadow_plane_state(struct drm_plane_state *state) 44 { 45 return container_of(state, struct drm_shadow_plane_state, base); 46 } 47 48 void drm_gem_reset_shadow_plane(struct drm_plane *plane); 49 struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane); 50 void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane, 51 struct drm_plane_state *plane_state); 52 53 /** 54 * DRM_GEM_SHADOW_PLANE_FUNCS - 55 * Initializes struct drm_plane_funcs for shadow-buffered planes 56 * 57 * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This 58 * macro initializes struct drm_plane_funcs to use the rsp helper functions. 59 */ 60 #define DRM_GEM_SHADOW_PLANE_FUNCS \ 61 .reset = drm_gem_reset_shadow_plane, \ 62 .atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \ 63 .atomic_destroy_state = drm_gem_destroy_shadow_plane_state 64 65 int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state); 66 void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state); 67 68 /** 69 * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS - 70 * Initializes struct drm_plane_helper_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_helper_funcs to use the rsp helper 74 * functions. 75 */ 76 #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \ 77 .prepare_fb = drm_gem_prepare_shadow_fb, \ 78 .cleanup_fb = drm_gem_cleanup_shadow_fb 79 80 int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe, 81 struct drm_plane_state *plane_state); 82 void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe, 83 struct drm_plane_state *plane_state); 84 void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe); 85 struct drm_plane_state * 86 drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe); 87 void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe, 88 struct drm_plane_state *plane_state); 89 90 /** 91 * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS - 92 * Initializes struct drm_simple_display_pipe_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_simple_display_pipe_funcs to use the rsp helper 96 * functions. 97 */ 98 #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \ 99 .prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \ 100 .cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \ 101 .reset_plane = drm_gem_simple_kms_reset_shadow_plane, \ 102 .duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \ 103 .destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state 104 105 #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */ 106