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