16dd7b6ceSThomas Zimmermann /* SPDX-License-Identifier: GPL-2.0-or-later */
26dd7b6ceSThomas Zimmermann
36dd7b6ceSThomas Zimmermann #ifndef __DRM_GEM_ATOMIC_HELPER_H__
46dd7b6ceSThomas Zimmermann #define __DRM_GEM_ATOMIC_HELPER_H__
56dd7b6ceSThomas Zimmermann
67938f421SLucas De Marchi #include <linux/iosys-map.h>
76dd7b6ceSThomas Zimmermann
8279cc2e9SThomas Zimmermann #include <drm/drm_fourcc.h>
96dd7b6ceSThomas Zimmermann #include <drm/drm_plane.h>
106dd7b6ceSThomas Zimmermann
116dd7b6ceSThomas Zimmermann struct drm_simple_display_pipe;
126dd7b6ceSThomas Zimmermann
136dd7b6ceSThomas Zimmermann /*
14820c1707SThomas Zimmermann * Plane Helpers
15820c1707SThomas Zimmermann */
16820c1707SThomas Zimmermann
17820c1707SThomas Zimmermann int drm_gem_plane_helper_prepare_fb(struct drm_plane *plane, struct drm_plane_state *state);
18820c1707SThomas Zimmermann
19820c1707SThomas Zimmermann /*
206dd7b6ceSThomas Zimmermann * Helpers for planes with shadow buffers
216dd7b6ceSThomas Zimmermann */
226dd7b6ceSThomas Zimmermann
236dd7b6ceSThomas Zimmermann /**
249239f3e1SThomas Zimmermann * DRM_SHADOW_PLANE_MAX_WIDTH - Maximum width of a plane's shadow buffer in pixels
259239f3e1SThomas Zimmermann *
269239f3e1SThomas Zimmermann * For drivers with shadow planes, the maximum width of the framebuffer is
279239f3e1SThomas Zimmermann * usually independent from hardware limitations. Drivers can initialize struct
289239f3e1SThomas Zimmermann * drm_mode_config.max_width from DRM_SHADOW_PLANE_MAX_WIDTH.
299239f3e1SThomas Zimmermann */
309239f3e1SThomas Zimmermann #define DRM_SHADOW_PLANE_MAX_WIDTH (4096u)
319239f3e1SThomas Zimmermann
329239f3e1SThomas Zimmermann /**
339239f3e1SThomas Zimmermann * DRM_SHADOW_PLANE_MAX_HEIGHT - Maximum height of a plane's shadow buffer in scanlines
349239f3e1SThomas Zimmermann *
359239f3e1SThomas Zimmermann * For drivers with shadow planes, the maximum height of the framebuffer is
369239f3e1SThomas Zimmermann * usually independent from hardware limitations. Drivers can initialize struct
379239f3e1SThomas Zimmermann * drm_mode_config.max_height from DRM_SHADOW_PLANE_MAX_HEIGHT.
389239f3e1SThomas Zimmermann */
399239f3e1SThomas Zimmermann #define DRM_SHADOW_PLANE_MAX_HEIGHT (4096u)
409239f3e1SThomas Zimmermann
419239f3e1SThomas Zimmermann /**
426dd7b6ceSThomas Zimmermann * struct drm_shadow_plane_state - plane state for planes with shadow buffers
436dd7b6ceSThomas Zimmermann *
446dd7b6ceSThomas Zimmermann * For planes that use a shadow buffer, struct drm_shadow_plane_state
456dd7b6ceSThomas Zimmermann * provides the regular plane state plus mappings of the shadow buffer
466dd7b6ceSThomas Zimmermann * into kernel address space.
476dd7b6ceSThomas Zimmermann */
486dd7b6ceSThomas Zimmermann struct drm_shadow_plane_state {
496dd7b6ceSThomas Zimmermann /** @base: plane state */
506dd7b6ceSThomas Zimmermann struct drm_plane_state base;
516dd7b6ceSThomas Zimmermann
526dd7b6ceSThomas Zimmermann /* Transitional state - do not export or duplicate */
536dd7b6ceSThomas Zimmermann
546dd7b6ceSThomas Zimmermann /**
556dd7b6ceSThomas Zimmermann * @map: Mappings of the plane's framebuffer BOs in to kernel address space
566dd7b6ceSThomas Zimmermann *
576dd7b6ceSThomas Zimmermann * The memory mappings stored in map should be established in the plane's
586dd7b6ceSThomas Zimmermann * prepare_fb callback and removed in the cleanup_fb callback.
596dd7b6ceSThomas Zimmermann */
607938f421SLucas De Marchi struct iosys_map map[DRM_FORMAT_MAX_PLANES];
6143b36232SThomas Zimmermann
6243b36232SThomas Zimmermann /**
6343b36232SThomas Zimmermann * @data: Address of each framebuffer BO's data
6443b36232SThomas Zimmermann *
6543b36232SThomas Zimmermann * The address of the data stored in each mapping. This is different
6643b36232SThomas Zimmermann * for framebuffers with non-zero offset fields.
6743b36232SThomas Zimmermann */
687938f421SLucas De Marchi struct iosys_map data[DRM_FORMAT_MAX_PLANES];
696dd7b6ceSThomas Zimmermann };
706dd7b6ceSThomas Zimmermann
716dd7b6ceSThomas Zimmermann /**
726dd7b6ceSThomas Zimmermann * to_drm_shadow_plane_state - upcasts from struct drm_plane_state
736dd7b6ceSThomas Zimmermann * @state: the plane state
746dd7b6ceSThomas Zimmermann */
756dd7b6ceSThomas Zimmermann static inline struct drm_shadow_plane_state *
to_drm_shadow_plane_state(struct drm_plane_state * state)766dd7b6ceSThomas Zimmermann to_drm_shadow_plane_state(struct drm_plane_state *state)
776dd7b6ceSThomas Zimmermann {
786dd7b6ceSThomas Zimmermann return container_of(state, struct drm_shadow_plane_state, base);
796dd7b6ceSThomas Zimmermann }
806dd7b6ceSThomas Zimmermann
81b7156502SThomas Zimmermann void __drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane,
82b7156502SThomas Zimmermann struct drm_shadow_plane_state *new_shadow_plane_state);
83b7156502SThomas Zimmermann void __drm_gem_destroy_shadow_plane_state(struct drm_shadow_plane_state *shadow_plane_state);
84b7156502SThomas Zimmermann void __drm_gem_reset_shadow_plane(struct drm_plane *plane,
85b7156502SThomas Zimmermann struct drm_shadow_plane_state *shadow_plane_state);
86b7156502SThomas Zimmermann
879dc9067dSThomas Zimmermann void drm_gem_reset_shadow_plane(struct drm_plane *plane);
889dc9067dSThomas Zimmermann struct drm_plane_state *drm_gem_duplicate_shadow_plane_state(struct drm_plane *plane);
899dc9067dSThomas Zimmermann void drm_gem_destroy_shadow_plane_state(struct drm_plane *plane,
909dc9067dSThomas Zimmermann struct drm_plane_state *plane_state);
919dc9067dSThomas Zimmermann
929dc9067dSThomas Zimmermann /**
939dc9067dSThomas Zimmermann * DRM_GEM_SHADOW_PLANE_FUNCS -
949dc9067dSThomas Zimmermann * Initializes struct drm_plane_funcs for shadow-buffered planes
959dc9067dSThomas Zimmermann *
969dc9067dSThomas Zimmermann * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
979dc9067dSThomas Zimmermann * macro initializes struct drm_plane_funcs to use the rsp helper functions.
989dc9067dSThomas Zimmermann */
999dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_FUNCS \
1009dc9067dSThomas Zimmermann .reset = drm_gem_reset_shadow_plane, \
1019dc9067dSThomas Zimmermann .atomic_duplicate_state = drm_gem_duplicate_shadow_plane_state, \
1029dc9067dSThomas Zimmermann .atomic_destroy_state = drm_gem_destroy_shadow_plane_state
1039dc9067dSThomas Zimmermann
104*359c6649SThomas Zimmermann int drm_gem_begin_shadow_fb_access(struct drm_plane *plane, struct drm_plane_state *plane_state);
105*359c6649SThomas Zimmermann void drm_gem_end_shadow_fb_access(struct drm_plane *plane, struct drm_plane_state *plane_state);
1069dc9067dSThomas Zimmermann
1079dc9067dSThomas Zimmermann /**
1089dc9067dSThomas Zimmermann * DRM_GEM_SHADOW_PLANE_HELPER_FUNCS -
1099dc9067dSThomas Zimmermann * Initializes struct drm_plane_helper_funcs for shadow-buffered planes
1109dc9067dSThomas Zimmermann *
1119dc9067dSThomas Zimmermann * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1129dc9067dSThomas Zimmermann * macro initializes struct drm_plane_helper_funcs to use the rsp helper
1139dc9067dSThomas Zimmermann * functions.
1149dc9067dSThomas Zimmermann */
1159dc9067dSThomas Zimmermann #define DRM_GEM_SHADOW_PLANE_HELPER_FUNCS \
116*359c6649SThomas Zimmermann .begin_fb_access = drm_gem_begin_shadow_fb_access, \
117*359c6649SThomas Zimmermann .end_fb_access = drm_gem_end_shadow_fb_access
1189dc9067dSThomas Zimmermann
119*359c6649SThomas Zimmermann int drm_gem_simple_kms_begin_shadow_fb_access(struct drm_simple_display_pipe *pipe,
1206dd7b6ceSThomas Zimmermann struct drm_plane_state *plane_state);
121*359c6649SThomas Zimmermann void drm_gem_simple_kms_end_shadow_fb_access(struct drm_simple_display_pipe *pipe,
1226dd7b6ceSThomas Zimmermann struct drm_plane_state *plane_state);
1236dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_reset_shadow_plane(struct drm_simple_display_pipe *pipe);
1246dd7b6ceSThomas Zimmermann struct drm_plane_state *
1256dd7b6ceSThomas Zimmermann drm_gem_simple_kms_duplicate_shadow_plane_state(struct drm_simple_display_pipe *pipe);
1266dd7b6ceSThomas Zimmermann void drm_gem_simple_kms_destroy_shadow_plane_state(struct drm_simple_display_pipe *pipe,
1276dd7b6ceSThomas Zimmermann struct drm_plane_state *plane_state);
1286dd7b6ceSThomas Zimmermann
1296dd7b6ceSThomas Zimmermann /**
1306dd7b6ceSThomas Zimmermann * DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS -
1316dd7b6ceSThomas Zimmermann * Initializes struct drm_simple_display_pipe_funcs for shadow-buffered planes
1326dd7b6ceSThomas Zimmermann *
1336dd7b6ceSThomas Zimmermann * Drivers may use GEM BOs as shadow buffers over the framebuffer memory. This
1346dd7b6ceSThomas Zimmermann * macro initializes struct drm_simple_display_pipe_funcs to use the rsp helper
1356dd7b6ceSThomas Zimmermann * functions.
1366dd7b6ceSThomas Zimmermann */
1376dd7b6ceSThomas Zimmermann #define DRM_GEM_SIMPLE_DISPLAY_PIPE_SHADOW_PLANE_FUNCS \
138*359c6649SThomas Zimmermann .begin_fb_access = drm_gem_simple_kms_begin_shadow_fb_access, \
139*359c6649SThomas Zimmermann .end_fb_access = drm_gem_simple_kms_end_shadow_fb_access, \
1406dd7b6ceSThomas Zimmermann .reset_plane = drm_gem_simple_kms_reset_shadow_plane, \
1416dd7b6ceSThomas Zimmermann .duplicate_plane_state = drm_gem_simple_kms_duplicate_shadow_plane_state, \
1426dd7b6ceSThomas Zimmermann .destroy_plane_state = drm_gem_simple_kms_destroy_shadow_plane_state
1436dd7b6ceSThomas Zimmermann
1446dd7b6ceSThomas Zimmermann #endif /* __DRM_GEM_ATOMIC_HELPER_H__ */
145