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