1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #ifndef __DRM_GEM_ATOMIC_HELPER_H__
4 #define __DRM_GEM_ATOMIC_HELPER_H__
6 #include <linux/dma-buf-map.h>
8 #include <drm/drm_plane.h>
10 struct drm_simple_display_pipe;
16 int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state);
17 int drm_gem_simple_display_pipe_prepare_fb(struct drm_simple_display_pipe *pipe,
18 struct drm_plane_state *plane_state);
21 * Helpers for planes with shadow buffers
25 * struct drm_shadow_plane_state - plane state for planes with shadow buffers
27 * For planes that use a shadow buffer, struct drm_shadow_plane_state
28 * provides the regular plane state plus mappings of the shadow buffer
29 * into kernel address space.
31 struct drm_shadow_plane_state {
32 /** @base: plane state */
33 struct drm_plane_state base;
35 /* Transitional state - do not export or duplicate */
38 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
40 * The memory mappings stored in map should be established in the plane's
41 * prepare_fb callback and removed in the cleanup_fb callback.
43 struct dma_buf_map map[4];
47 * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
48 * @state: the plane state
50 static inline struct drm_shadow_plane_state *
51 to_drm_shadow_plane_state(struct drm_plane_state *state)
53 return container_of(state, struct drm_shadow_plane_state, base);
56 void drm_gem_reset_shadow_plane(struct drm_plane *plane);
57 struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
58 void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
59 struct drm_plane_state *plane_state);
62 * DRM_GEM_SHADOW_PLANE_FUNCS -
63 * Initializes struct drm_plane_funcs for shadow-buffered planes
65 * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
66 * macro initializes struct drm_plane_funcs to use the rsp helper functions.
68 #define DRM_GEM_SHADOW_PLANE_FUNCS \
69 .reset = drm_gem_reset_shadow_plane, \
70 .atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
71 .atomic_destroy_state = drm_gem_destroy_shadow_plane_state
73 int drm_gem_prepare_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
74 void drm_gem_cleanup_shadow_fb(struct drm_plane *plane, struct drm_plane_state *plane_state);
77 * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
78 * Initializes struct drm_plane_helper_funcs for shadow-buffered planes
80 * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
81 * macro initializes struct drm_plane_helper_funcs to use the rsp helper
84 #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
85 .prepare_fb = drm_gem_prepare_shadow_fb, \
86 .cleanup_fb = drm_gem_cleanup_shadow_fb
88 int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,
89 struct drm_plane_state *plane_state);
90 void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe,
91 struct drm_plane_state *plane_state);
92 void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
93 struct drm_plane_state *
94 drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
95 void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
96 struct drm_plane_state *plane_state);
99 * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
100 * Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
102 * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
103 * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
106 #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
107 .prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \
108 .cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \
109 .reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
110 .duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
111 .destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
113 #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */