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_fourcc.h>
9 #include <drm/drm_plane.h>
11 struct drm_simple_display_pipe;
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);
22 * Helpers for planes with shadow buffers
26 * struct drm_shadow_plane_state - plane state for planes with shadow buffers
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.
32 struct drm_shadow_plane_state {
33 /** @base: plane state */
34 struct drm_plane_state base;
36 /* Transitional state - do not export or duplicate */
39 * @map: Mappings of the plane's framebuffer BOs in to kernel address space
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.
44 struct dma_buf_map map[DRM_FORMAT_MAX_PLANES];
47 * @data: Address of each framebuffer BO's data
49 * The address of the data stored in each mapping. This is different
50 * for framebuffers with non-zero offset fields.
52 struct dma_buf_map data[DRM_FORMAT_MAX_PLANES];
56 * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
57 * @state: the plane state
59 static inline struct drm_shadow_plane_state *
60 to_drm_shadow_plane_state(struct drm_plane_state *state)
62 return container_of(state, struct drm_shadow_plane_state, base);
65 void __drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane,
66 struct drm_shadow_plane_state *new_shadow_plane_state);
67 void __drm_gem_destroy_shadow_plane_state(struct drm_shadow_plane_state *shadow_plane_state);
68 void __drm_gem_reset_shadow_plane(struct drm_plane *plane,
69 struct drm_shadow_plane_state *shadow_plane_state);
71 void drm_gem_reset_shadow_plane(struct drm_plane *plane);
72 struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
73 void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
74 struct drm_plane_state *plane_state);
77 * DRM_GEM_SHADOW_PLANE_FUNCS -
78 * Initializes struct drm_plane_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_funcs to use the rsp helper functions.
83 #define DRM_GEM_SHADOW_PLANE_FUNCS \
84 .reset = drm_gem_reset_shadow_plane, \
85 .atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
86 .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);
92 * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
93 * Initializes struct drm_plane_helper_funcs for shadow-buffered planes
95 * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
96 * macro initializes struct drm_plane_helper_funcs to use the rsp helper
99 #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
100 .prepare_fb = drm_gem_prepare_shadow_fb, \
101 .cleanup_fb = drm_gem_cleanup_shadow_fb
103 int drm_gem_simple_kms_prepare_shadow_fb(struct drm_simple_display_pipe *pipe,
104 struct drm_plane_state *plane_state);
105 void drm_gem_simple_kms_cleanup_shadow_fb(struct drm_simple_display_pipe *pipe,
106 struct drm_plane_state *plane_state);
107 void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
108 struct drm_plane_state *
109 drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
110 void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
111 struct drm_plane_state *plane_state);
114 * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
115 * Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
117 * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
118 * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
121 #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
122 .prepare_fb = drm_gem_simple_kms_prepare_shadow_fb, \
123 .cleanup_fb = drm_gem_simple_kms_cleanup_shadow_fb, \
124 .reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
125 .duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
126 .destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
128 #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */