drm_atomic_helper.h 11.1 KB
Newer Older
D
Daniel Vetter 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
/*
 * Copyright (C) 2014 Red Hat
 * Copyright (C) 2014 Intel Corp.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 * Rob Clark <robdclark@gmail.com>
 * Daniel Vetter <daniel.vetter@ffwll.ch>
 */

#ifndef DRM_ATOMIC_HELPER_H_
#define DRM_ATOMIC_HELPER_H_

31
#include <drm/drm_crtc.h>
32 33
#include <drm/drm_modeset_helper_vtables.h>
#include <drm/drm_modeset_helper.h>
34

35
struct drm_atomic_state;
36 37
struct drm_private_obj;
struct drm_private_state;
38

39 40 41 42
int drm_atomic_helper_check_modeset(struct drm_device *dev,
				struct drm_atomic_state *state);
int drm_atomic_helper_check_planes(struct drm_device *dev,
			       struct drm_atomic_state *state);
D
Daniel Vetter 已提交
43 44
int drm_atomic_helper_check(struct drm_device *dev,
			    struct drm_atomic_state *state);
45
void drm_atomic_helper_commit_tail(struct drm_atomic_state *state);
46 47
int drm_atomic_helper_commit(struct drm_device *dev,
			     struct drm_atomic_state *state,
48
			     bool nonblock);
49 50 51 52
int drm_atomic_helper_async_check(struct drm_device *dev,
				  struct drm_atomic_state *state);
void drm_atomic_helper_async_commit(struct drm_device *dev,
				    struct drm_atomic_state *state);
53

54 55 56
int drm_atomic_helper_wait_for_fences(struct drm_device *dev,
					struct drm_atomic_state *state,
					bool pre_swap);
57

58 59 60
void drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
					struct drm_atomic_state *old_state);

61 62 63
void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
					  struct drm_atomic_state *old_state);

64 65 66 67
void
drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev,
					      struct drm_atomic_state *old_state);

68 69 70
void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev,
					       struct drm_atomic_state *state);
void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
71
					  struct drm_atomic_state *old_state);
D
Daniel Vetter 已提交
72 73 74

int drm_atomic_helper_prepare_planes(struct drm_device *dev,
				     struct drm_atomic_state *state);
75 76 77 78

#define DRM_PLANE_COMMIT_ACTIVE_ONLY			BIT(0)
#define DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET	BIT(1)

D
Daniel Vetter 已提交
79
void drm_atomic_helper_commit_planes(struct drm_device *dev,
80
				     struct drm_atomic_state *state,
81
				     uint32_t flags);
D
Daniel Vetter 已提交
82 83
void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
				      struct drm_atomic_state *old_state);
84
void drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state);
85 86 87
void
drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state,
					 bool atomic);
D
Daniel Vetter 已提交
88

89
int drm_atomic_helper_swap_state(struct drm_atomic_state *state, bool stall);
D
Daniel Vetter 已提交
90

91 92 93 94 95 96 97
/* nonblocking commit helpers */
int drm_atomic_helper_setup_commit(struct drm_atomic_state *state,
				   bool nonblock);
void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *state);
void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *state);
void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *state);

98 99 100 101 102 103 104
/* implementations for legacy interfaces */
int drm_atomic_helper_update_plane(struct drm_plane *plane,
				   struct drm_crtc *crtc,
				   struct drm_framebuffer *fb,
				   int crtc_x, int crtc_y,
				   unsigned int crtc_w, unsigned int crtc_h,
				   uint32_t src_x, uint32_t src_y,
105 106
				   uint32_t src_w, uint32_t src_h,
				   struct drm_modeset_acquire_ctx *ctx);
107 108
int drm_atomic_helper_disable_plane(struct drm_plane *plane,
				    struct drm_modeset_acquire_ctx *ctx);
109 110
int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
		struct drm_plane_state *plane_state);
111 112
int drm_atomic_helper_set_config(struct drm_mode_set *set,
				 struct drm_modeset_acquire_ctx *ctx);
113 114
int __drm_atomic_helper_set_config(struct drm_mode_set *set,
		struct drm_atomic_state *state);
115

116 117
int drm_atomic_helper_disable_all(struct drm_device *dev,
				  struct drm_modeset_acquire_ctx *ctx);
118
void drm_atomic_helper_shutdown(struct drm_device *dev);
119
struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev);
120 121
int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
					      struct drm_modeset_acquire_ctx *ctx);
122 123 124
int drm_atomic_helper_resume(struct drm_device *dev,
			     struct drm_atomic_state *state);

125 126 127 128 129 130 131 132 133
int drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
					struct drm_property *property,
					uint64_t val);
int drm_atomic_helper_plane_set_property(struct drm_plane *plane,
					struct drm_property *property,
					uint64_t val);
int drm_atomic_helper_connector_set_property(struct drm_connector *connector,
					struct drm_property *property,
					uint64_t val);
134 135 136
int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
				struct drm_framebuffer *fb,
				struct drm_pending_vblank_event *event,
137 138
				uint32_t flags,
				struct drm_modeset_acquire_ctx *ctx);
139 140 141 142 143
int drm_atomic_helper_page_flip_target(
				struct drm_crtc *crtc,
				struct drm_framebuffer *fb,
				struct drm_pending_vblank_event *event,
				uint32_t flags,
144 145
				uint32_t target,
				struct drm_modeset_acquire_ctx *ctx);
146 147
int drm_atomic_helper_connector_dpms(struct drm_connector *connector,
				     int mode);
148 149
struct drm_encoder *
drm_atomic_helper_best_encoder(struct drm_connector *connector);
150

151 152
/* default implementations for state handling */
void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc);
153 154
void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
					      struct drm_crtc_state *state);
155 156
struct drm_crtc_state *
drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc);
157
void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state);
158 159 160 161
void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
					  struct drm_crtc_state *state);

void drm_atomic_helper_plane_reset(struct drm_plane *plane);
162 163
void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
					       struct drm_plane_state *state);
164 165
struct drm_plane_state *
drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane);
166
void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state);
167 168 169
void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
					  struct drm_plane_state *state);

170 171
void __drm_atomic_helper_connector_reset(struct drm_connector *connector,
					 struct drm_connector_state *conn_state);
172
void drm_atomic_helper_connector_reset(struct drm_connector *connector);
173 174 175
void
__drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
					   struct drm_connector_state *state);
176 177
struct drm_connector_state *
drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);
178 179 180
struct drm_atomic_state *
drm_atomic_helper_duplicate_state(struct drm_device *dev,
				  struct drm_modeset_acquire_ctx *ctx);
181
void
182
__drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state);
183 184
void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
					  struct drm_connector_state *state);
185 186
int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc,
				       u16 *red, u16 *green, u16 *blue,
187 188
				       uint32_t size,
				       struct drm_modeset_acquire_ctx *ctx);
189 190
void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
						     struct drm_private_state *state);
191

R
Rob Clark 已提交
192 193 194 195 196 197 198
/**
 * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
 * @plane: the loop cursor
 * @crtc:  the crtc whose planes are iterated
 *
 * This iterates over the current state, useful (for example) when applying
 * atomic state after it has been checked and swapped.  To iterate over the
199 200
 * planes which *will* be attached (more useful in code called from
 * &drm_mode_config_funcs.atomic_check) see
201
 * drm_atomic_crtc_state_for_each_plane().
R
Rob Clark 已提交
202 203 204 205 206 207 208 209 210 211
 */
#define drm_atomic_crtc_for_each_plane(plane, crtc) \
	drm_for_each_plane_mask(plane, (crtc)->dev, (crtc)->state->plane_mask)

/**
 * drm_crtc_atomic_state_for_each_plane - iterate over attached planes in new state
 * @plane: the loop cursor
 * @crtc_state: the incoming crtc-state
 *
 * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
212 213 214
 * attached if the specified state is applied.  Useful during for example
 * in code called from &drm_mode_config_funcs.atomic_check operations, to
 * validate the incoming state.
R
Rob Clark 已提交
215 216 217
 */
#define drm_atomic_crtc_state_for_each_plane(plane, crtc_state) \
	drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask)
218

219 220 221 222 223 224 225
/**
 * drm_crtc_atomic_state_for_each_plane_state - iterate over attached planes in new state
 * @plane: the loop cursor
 * @plane_state: loop cursor for the plane's state, must be const
 * @crtc_state: the incoming crtc-state
 *
 * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
226 227 228
 * attached if the specified state is applied.  Useful during for example
 * in code called from &drm_mode_config_funcs.atomic_check operations, to
 * validate the incoming state.
229 230 231 232 233 234 235 236 237 238 239
 *
 * Compared to just drm_atomic_crtc_state_for_each_plane() this also fills in a
 * const plane_state. This is useful when a driver just wants to peek at other
 * active planes on this crtc, but does not need to change it.
 */
#define drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) \
	drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) \
		for_each_if ((plane_state = \
			      __drm_atomic_get_current_plane_state((crtc_state)->state, \
								   plane)))

240
/**
241
 * drm_atomic_plane_disabling - check whether a plane is being disabled
242 243
 * @old_plane_state: old atomic plane state
 * @new_plane_state: new atomic plane state
244 245 246 247 248 249 250 251 252
 *
 * Checks the atomic state of a plane to determine whether it's being disabled
 * or not. This also WARNs if it detects an invalid state (both CRTC and FB
 * need to either both be NULL or both be non-NULL).
 *
 * RETURNS:
 * True if the plane is being disabled, false otherwise.
 */
static inline bool
253 254
drm_atomic_plane_disabling(struct drm_plane_state *old_plane_state,
			   struct drm_plane_state *new_plane_state)
255 256 257 258 259 260
{
	/*
	 * When disabling a plane, CRTC and FB should always be NULL together.
	 * Anything else should be considered a bug in the atomic core, so we
	 * gently warn about it.
	 */
261 262
	WARN_ON((new_plane_state->crtc == NULL && new_plane_state->fb != NULL) ||
		(new_plane_state->crtc != NULL && new_plane_state->fb == NULL));
263

264
	return old_plane_state->crtc && !new_plane_state->crtc;
265 266
}

D
Daniel Vetter 已提交
267
#endif /* DRM_ATOMIC_HELPER_H_ */