1 /* 2 * Copyright (C) 2014 Red Hat 3 * Copyright (C) 2014 Intel Corp. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included in 13 * all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 21 * OTHER DEALINGS IN THE SOFTWARE. 22 * 23 * Authors: 24 * Rob Clark <robdclark@gmail.com> 25 * Daniel Vetter <daniel.vetter@ffwll.ch> 26 */ 27 28 #ifndef DRM_ATOMIC_HELPER_H_ 29 #define DRM_ATOMIC_HELPER_H_ 30 31 #include <drm/drm_crtc.h> 32 #include <drm/drm_modeset_helper_vtables.h> 33 #include <drm/drm_modeset_helper.h> 34 #include <drm/drm_atomic_state_helper.h> 35 #include <drm/drm_util.h> 36 37 /* 38 * Drivers that don't allow primary plane scaling may pass this macro in place 39 * of the min/max scale parameters of the plane-state checker function. 40 * 41 * Due to src being in 16.16 fixed point and dest being in integer pixels, 42 * 1<<16 represents no scaling. 43 */ 44 #define DRM_PLANE_HELPER_NO_SCALING (1<<16) 45 46 struct drm_atomic_state; 47 struct drm_private_obj; 48 struct drm_private_state; 49 50 int drm_atomic_helper_check_modeset(struct drm_device *dev, 51 struct drm_atomic_state *state); 52 int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, 53 const struct drm_crtc_state *crtc_state, 54 int min_scale, 55 int max_scale, 56 bool can_position, 57 bool can_update_disabled); 58 int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state, 59 bool can_disable_primary_plane); 60 int drm_atomic_helper_check_planes(struct drm_device *dev, 61 struct drm_atomic_state *state); 62 int drm_atomic_helper_check(struct drm_device *dev, 63 struct drm_atomic_state *state); 64 void drm_atomic_helper_commit_tail(struct drm_atomic_state *state); 65 void drm_atomic_helper_commit_tail_rpm(struct drm_atomic_state *state); 66 int drm_atomic_helper_commit(struct drm_device *dev, 67 struct drm_atomic_state *state, 68 bool nonblock); 69 int drm_atomic_helper_async_check(struct drm_device *dev, 70 struct drm_atomic_state *state); 71 void drm_atomic_helper_async_commit(struct drm_device *dev, 72 struct drm_atomic_state *state); 73 74 int drm_atomic_helper_wait_for_fences(struct drm_device *dev, 75 struct drm_atomic_state *state, 76 bool pre_swap); 77 78 void drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, 79 struct drm_atomic_state *old_state); 80 81 void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev, 82 struct drm_atomic_state *old_state); 83 84 void 85 drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev, 86 struct drm_atomic_state *old_state); 87 88 void 89 drm_atomic_helper_calc_timestamping_constants(struct drm_atomic_state *state); 90 91 void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev, 92 struct drm_atomic_state *state); 93 void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, 94 struct drm_atomic_state *old_state); 95 96 int drm_atomic_helper_prepare_planes(struct drm_device *dev, 97 struct drm_atomic_state *state); 98 99 #define DRM_PLANE_COMMIT_ACTIVE_ONLY BIT(0) 100 #define DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET BIT(1) 101 102 void drm_atomic_helper_commit_planes(struct drm_device *dev, 103 struct drm_atomic_state *state, 104 uint32_t flags); 105 void drm_atomic_helper_cleanup_planes(struct drm_device *dev, 106 struct drm_atomic_state *old_state); 107 void drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state); 108 void 109 drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state, 110 bool atomic); 111 112 int __must_check drm_atomic_helper_swap_state(struct drm_atomic_state *state, 113 bool stall); 114 115 /* nonblocking commit helpers */ 116 int drm_atomic_helper_setup_commit(struct drm_atomic_state *state, 117 bool nonblock); 118 void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *state); 119 void drm_atomic_helper_fake_vblank(struct drm_atomic_state *state); 120 void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *state); 121 void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *state); 122 123 /* implementations for legacy interfaces */ 124 int drm_atomic_helper_update_plane(struct drm_plane *plane, 125 struct drm_crtc *crtc, 126 struct drm_framebuffer *fb, 127 int crtc_x, int crtc_y, 128 unsigned int crtc_w, unsigned int crtc_h, 129 uint32_t src_x, uint32_t src_y, 130 uint32_t src_w, uint32_t src_h, 131 struct drm_modeset_acquire_ctx *ctx); 132 int drm_atomic_helper_disable_plane(struct drm_plane *plane, 133 struct drm_modeset_acquire_ctx *ctx); 134 int drm_atomic_helper_set_config(struct drm_mode_set *set, 135 struct drm_modeset_acquire_ctx *ctx); 136 137 int drm_atomic_helper_disable_all(struct drm_device *dev, 138 struct drm_modeset_acquire_ctx *ctx); 139 void drm_atomic_helper_shutdown(struct drm_device *dev); 140 struct drm_atomic_state * 141 drm_atomic_helper_duplicate_state(struct drm_device *dev, 142 struct drm_modeset_acquire_ctx *ctx); 143 struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev); 144 int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state, 145 struct drm_modeset_acquire_ctx *ctx); 146 int drm_atomic_helper_resume(struct drm_device *dev, 147 struct drm_atomic_state *state); 148 149 int drm_atomic_helper_page_flip(struct drm_crtc *crtc, 150 struct drm_framebuffer *fb, 151 struct drm_pending_vblank_event *event, 152 uint32_t flags, 153 struct drm_modeset_acquire_ctx *ctx); 154 int drm_atomic_helper_page_flip_target( 155 struct drm_crtc *crtc, 156 struct drm_framebuffer *fb, 157 struct drm_pending_vblank_event *event, 158 uint32_t flags, 159 uint32_t target, 160 struct drm_modeset_acquire_ctx *ctx); 161 162 /** 163 * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC 164 * @plane: the loop cursor 165 * @crtc: the CRTC whose planes are iterated 166 * 167 * This iterates over the current state, useful (for example) when applying 168 * atomic state after it has been checked and swapped. To iterate over the 169 * planes which *will* be attached (more useful in code called from 170 * &drm_mode_config_funcs.atomic_check) see 171 * drm_atomic_crtc_state_for_each_plane(). 172 */ 173 #define drm_atomic_crtc_for_each_plane(plane, crtc) \ 174 drm_for_each_plane_mask(plane, (crtc)->dev, (crtc)->state->plane_mask) 175 176 /** 177 * drm_atomic_crtc_state_for_each_plane - iterate over attached planes in new state 178 * @plane: the loop cursor 179 * @crtc_state: the incoming CRTC state 180 * 181 * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be 182 * attached if the specified state is applied. Useful during for example 183 * in code called from &drm_mode_config_funcs.atomic_check operations, to 184 * validate the incoming state. 185 */ 186 #define drm_atomic_crtc_state_for_each_plane(plane, crtc_state) \ 187 drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) 188 189 /** 190 * drm_atomic_crtc_state_for_each_plane_state - iterate over attached planes in new state 191 * @plane: the loop cursor 192 * @plane_state: loop cursor for the plane's state, must be const 193 * @crtc_state: the incoming CRTC state 194 * 195 * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be 196 * attached if the specified state is applied. Useful during for example 197 * in code called from &drm_mode_config_funcs.atomic_check operations, to 198 * validate the incoming state. 199 * 200 * Compared to just drm_atomic_crtc_state_for_each_plane() this also fills in a 201 * const plane_state. This is useful when a driver just wants to peek at other 202 * active planes on this CRTC, but does not need to change it. 203 */ 204 #define drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) \ 205 drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) \ 206 for_each_if ((plane_state = \ 207 __drm_atomic_get_current_plane_state((crtc_state)->state, \ 208 plane))) 209 210 /** 211 * drm_atomic_plane_disabling - check whether a plane is being disabled 212 * @old_plane_state: old atomic plane state 213 * @new_plane_state: new atomic plane state 214 * 215 * Checks the atomic state of a plane to determine whether it's being disabled 216 * or not. This also WARNs if it detects an invalid state (both CRTC and FB 217 * need to either both be NULL or both be non-NULL). 218 * 219 * RETURNS: 220 * True if the plane is being disabled, false otherwise. 221 */ 222 static inline bool 223 drm_atomic_plane_disabling(struct drm_plane_state *old_plane_state, 224 struct drm_plane_state *new_plane_state) 225 { 226 /* 227 * When disabling a plane, CRTC and FB should always be NULL together. 228 * Anything else should be considered a bug in the atomic core, so we 229 * gently warn about it. 230 */ 231 WARN_ON((new_plane_state->crtc == NULL && new_plane_state->fb != NULL) || 232 (new_plane_state->crtc != NULL && new_plane_state->fb == NULL)); 233 234 return old_plane_state->crtc && !new_plane_state->crtc; 235 } 236 237 u32 * 238 drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge, 239 struct drm_bridge_state *bridge_state, 240 struct drm_crtc_state *crtc_state, 241 struct drm_connector_state *conn_state, 242 u32 output_fmt, 243 unsigned int *num_input_fmts); 244 245 #endif /* DRM_ATOMIC_HELPER_H_ */ 246