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