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