Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 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 <[email protected]> |
| 25 | * Daniel Vetter <[email protected]> |
| 26 | */ |
| 27 | |
| 28 | #ifndef DRM_ATOMIC_H_ |
| 29 | #define DRM_ATOMIC_H_ |
| 30 | |
Thierry Reding | 37cc014 | 2014-11-25 12:09:48 +0100 | [diff] [blame] | 31 | #include <drm/drm_crtc.h> |
| 32 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 33 | /** |
| 34 | * struct drm_crtc_commit - track modeset commits on a CRTC |
| 35 | * |
| 36 | * This structure is used to track pending modeset changes and atomic commit on |
| 37 | * a per-CRTC basis. Since updating the list should never block this structure |
| 38 | * is reference counted to allow waiters to safely wait on an event to complete, |
| 39 | * without holding any locks. |
| 40 | * |
| 41 | * It has 3 different events in total to allow a fine-grained synchronization |
| 42 | * between outstanding updates:: |
| 43 | * |
| 44 | * atomic commit thread hardware |
| 45 | * |
| 46 | * write new state into hardware ----> ... |
| 47 | * signal hw_done |
| 48 | * switch to new state on next |
| 49 | * ... v/hblank |
| 50 | * |
| 51 | * wait for buffers to show up ... |
| 52 | * |
| 53 | * ... send completion irq |
| 54 | * irq handler signals flip_done |
| 55 | * cleanup old buffers |
| 56 | * |
| 57 | * signal cleanup_done |
| 58 | * |
| 59 | * wait for flip_done <---- |
| 60 | * clean up atomic state |
| 61 | * |
| 62 | * The important bit to know is that cleanup_done is the terminal event, but the |
| 63 | * ordering between flip_done and hw_done is entirely up to the specific driver |
| 64 | * and modeset state change. |
| 65 | * |
| 66 | * For an implementation of how to use this look at |
| 67 | * drm_atomic_helper_setup_commit() from the atomic helper library. |
| 68 | */ |
| 69 | struct drm_crtc_commit { |
| 70 | /** |
| 71 | * @crtc: |
| 72 | * |
| 73 | * DRM CRTC for this commit. |
| 74 | */ |
| 75 | struct drm_crtc *crtc; |
| 76 | |
| 77 | /** |
| 78 | * @ref: |
| 79 | * |
| 80 | * Reference count for this structure. Needed to allow blocking on |
| 81 | * completions without the risk of the completion disappearing |
| 82 | * meanwhile. |
| 83 | */ |
| 84 | struct kref ref; |
| 85 | |
| 86 | /** |
| 87 | * @flip_done: |
| 88 | * |
| 89 | * Will be signaled when the hardware has flipped to the new set of |
| 90 | * buffers. Signals at the same time as when the drm event for this |
| 91 | * commit is sent to userspace, or when an out-fence is singalled. Note |
| 92 | * that for most hardware, in most cases this happens after @hw_done is |
| 93 | * signalled. |
| 94 | */ |
| 95 | struct completion flip_done; |
| 96 | |
| 97 | /** |
| 98 | * @hw_done: |
| 99 | * |
| 100 | * Will be signalled when all hw register changes for this commit have |
| 101 | * been written out. Especially when disabling a pipe this can be much |
| 102 | * later than than @flip_done, since that can signal already when the |
| 103 | * screen goes black, whereas to fully shut down a pipe more register |
| 104 | * I/O is required. |
| 105 | * |
| 106 | * Note that this does not need to include separately reference-counted |
| 107 | * resources like backing storage buffer pinning, or runtime pm |
| 108 | * management. |
| 109 | */ |
| 110 | struct completion hw_done; |
| 111 | |
| 112 | /** |
| 113 | * @cleanup_done: |
| 114 | * |
| 115 | * Will be signalled after old buffers have been cleaned up by calling |
| 116 | * drm_atomic_helper_cleanup_planes(). Since this can only happen after |
| 117 | * a vblank wait completed it might be a bit later. This completion is |
| 118 | * useful to throttle updates and avoid hardware updates getting ahead |
| 119 | * of the buffer cleanup too much. |
| 120 | */ |
| 121 | struct completion cleanup_done; |
| 122 | |
| 123 | /** |
| 124 | * @commit_entry: |
| 125 | * |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 126 | * Entry on the per-CRTC &drm_crtc.commit_list. Protected by |
| 127 | * $drm_crtc.commit_lock. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 128 | */ |
| 129 | struct list_head commit_entry; |
| 130 | |
| 131 | /** |
| 132 | * @event: |
| 133 | * |
| 134 | * &drm_pending_vblank_event pointer to clean up private events. |
| 135 | */ |
| 136 | struct drm_pending_vblank_event *event; |
Leo (Sunpeng) Li | 1c6ceee | 2018-01-17 12:51:08 +0100 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * @abort_completion: |
| 140 | * |
| 141 | * A flag that's set after drm_atomic_helper_setup_commit takes a second |
| 142 | * reference for the completion of $drm_crtc_state.event. It's used by |
| 143 | * the free code to remove the second reference if commit fails. |
| 144 | */ |
| 145 | bool abort_completion; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | struct __drm_planes_state { |
| 149 | struct drm_plane *ptr; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 150 | struct drm_plane_state *state, *old_state, *new_state; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 151 | }; |
| 152 | |
| 153 | struct __drm_crtcs_state { |
| 154 | struct drm_crtc *ptr; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 155 | struct drm_crtc_state *state, *old_state, *new_state; |
Gustavo Padovan | 7e9081c | 2017-01-13 12:22:09 -0200 | [diff] [blame] | 156 | s32 __user *out_fence_ptr; |
Dhinakaran Pandiyan | f4c0468 | 2018-02-02 21:12:59 -0800 | [diff] [blame] | 157 | u64 last_vblank_count; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | struct __drm_connnectors_state { |
| 161 | struct drm_connector *ptr; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 162 | struct drm_connector_state *state, *old_state, *new_state; |
Brian Starkey | b13cc8d | 2017-03-29 17:42:33 +0100 | [diff] [blame^] | 163 | /** |
| 164 | * @out_fence_ptr: |
| 165 | * |
| 166 | * User-provided pointer which the kernel uses to return a sync_file |
| 167 | * file descriptor. Used by writeback connectors to signal completion of |
| 168 | * the writeback. |
| 169 | */ |
| 170 | s32 __user *out_fence_ptr; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 171 | }; |
| 172 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 173 | struct drm_private_obj; |
| 174 | struct drm_private_state; |
| 175 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 176 | /** |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 177 | * struct drm_private_state_funcs - atomic state functions for private objects |
| 178 | * |
| 179 | * These hooks are used by atomic helpers to create, swap and destroy states of |
| 180 | * private objects. The structure itself is used as a vtable to identify the |
| 181 | * associated private object type. Each private object type that needs to be |
| 182 | * added to the atomic states is expected to have an implementation of these |
| 183 | * hooks and pass a pointer to it's drm_private_state_funcs struct to |
| 184 | * drm_atomic_get_private_obj_state(). |
| 185 | */ |
| 186 | struct drm_private_state_funcs { |
| 187 | /** |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 188 | * @atomic_duplicate_state: |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 189 | * |
| 190 | * Duplicate the current state of the private object and return it. It |
| 191 | * is an error to call this before obj->state has been initialized. |
| 192 | * |
| 193 | * RETURNS: |
| 194 | * |
| 195 | * Duplicated atomic state or NULL when obj->state is not |
| 196 | * initialized or allocation failed. |
| 197 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 198 | struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj); |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 199 | |
| 200 | /** |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 201 | * @atomic_destroy_state: |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 202 | * |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 203 | * Frees the private object state created with @atomic_duplicate_state. |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 204 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 205 | void (*atomic_destroy_state)(struct drm_private_obj *obj, |
| 206 | struct drm_private_state *state); |
| 207 | }; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 208 | |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 209 | /** |
| 210 | * struct drm_private_obj - base struct for driver private atomic object |
| 211 | * |
| 212 | * A driver private object is initialized by calling |
| 213 | * drm_atomic_private_obj_init() and cleaned up by calling |
| 214 | * drm_atomic_private_obj_fini(). |
| 215 | * |
| 216 | * Currently only tracks the state update functions and the opaque driver |
| 217 | * private state itself, but in the future might also track which |
| 218 | * &drm_modeset_lock is required to duplicate and update this object's state. |
| 219 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 220 | struct drm_private_obj { |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 221 | /** |
| 222 | * @state: Current atomic state for this driver private object. |
| 223 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 224 | struct drm_private_state *state; |
| 225 | |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 226 | /** |
| 227 | * @funcs: |
| 228 | * |
| 229 | * Functions to manipulate the state of this driver private object, see |
| 230 | * &drm_private_state_funcs. |
| 231 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 232 | const struct drm_private_state_funcs *funcs; |
| 233 | }; |
| 234 | |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 235 | /** |
| 236 | * struct drm_private_state - base struct for driver private object state |
| 237 | * @state: backpointer to global drm_atomic_state |
| 238 | * |
| 239 | * Currently only contains a backpointer to the overall atomic update, but in |
| 240 | * the future also might hold synchronization information similar to e.g. |
| 241 | * &drm_crtc.commit. |
| 242 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 243 | struct drm_private_state { |
| 244 | struct drm_atomic_state *state; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 245 | }; |
| 246 | |
| 247 | struct __drm_private_objs_state { |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 248 | struct drm_private_obj *ptr; |
| 249 | struct drm_private_state *state, *old_state, *new_state; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 250 | }; |
| 251 | |
| 252 | /** |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 253 | * struct drm_atomic_state - the global state object for atomic updates |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 254 | * @ref: count of all references to this state (will not be freed until zero) |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 255 | * @dev: parent DRM device |
| 256 | * @allow_modeset: allow full modeset |
| 257 | * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 258 | * @async_update: hint for asynchronous plane update |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 259 | * @planes: pointer to array of structures with per-plane data |
| 260 | * @crtcs: pointer to array of CRTC pointers |
| 261 | * @num_connector: size of the @connectors and @connector_states arrays |
| 262 | * @connectors: pointer to array of structures with per-connector data |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 263 | * @num_private_objs: size of the @private_objs array |
| 264 | * @private_objs: pointer to array of private object pointers |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 265 | * @acquire_ctx: acquire context for this atomic modeset state update |
Daniel Vetter | 5fca5ec | 2017-12-14 21:30:54 +0100 | [diff] [blame] | 266 | * |
| 267 | * States are added to an atomic update by calling drm_atomic_get_crtc_state(), |
| 268 | * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for |
| 269 | * private state structures, drm_atomic_get_private_obj_state(). |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 270 | */ |
| 271 | struct drm_atomic_state { |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 272 | struct kref ref; |
| 273 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 274 | struct drm_device *dev; |
| 275 | bool allow_modeset : 1; |
| 276 | bool legacy_cursor_update : 1; |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 277 | bool async_update : 1; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 278 | struct __drm_planes_state *planes; |
| 279 | struct __drm_crtcs_state *crtcs; |
| 280 | int num_connector; |
| 281 | struct __drm_connnectors_state *connectors; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 282 | int num_private_objs; |
| 283 | struct __drm_private_objs_state *private_objs; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 284 | |
| 285 | struct drm_modeset_acquire_ctx *acquire_ctx; |
| 286 | |
| 287 | /** |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 288 | * @fake_commit: |
| 289 | * |
| 290 | * Used for signaling unbound planes/connectors. |
| 291 | * When a connector or plane is not bound to any CRTC, it's still important |
| 292 | * to preserve linearity to prevent the atomic states from being freed to early. |
| 293 | * |
| 294 | * This commit (if set) is not bound to any crtc, but will be completed when |
| 295 | * drm_atomic_helper_commit_hw_done() is called. |
| 296 | */ |
| 297 | struct drm_crtc_commit *fake_commit; |
| 298 | |
| 299 | /** |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 300 | * @commit_work: |
| 301 | * |
| 302 | * Work item which can be used by the driver or helpers to execute the |
| 303 | * commit without blocking. |
| 304 | */ |
| 305 | struct work_struct commit_work; |
| 306 | }; |
| 307 | |
Daniel Vetter | b3ba3f6f | 2016-12-21 14:03:35 +0100 | [diff] [blame] | 308 | void __drm_crtc_commit_free(struct kref *kref); |
| 309 | |
| 310 | /** |
| 311 | * drm_crtc_commit_get - acquire a reference to the CRTC commit |
| 312 | * @commit: CRTC commit |
| 313 | * |
| 314 | * Increases the reference of @commit. |
Maarten Lankhorst | f46640b | 2017-09-04 12:48:36 +0200 | [diff] [blame] | 315 | * |
| 316 | * Returns: |
| 317 | * The pointer to @commit, with reference increased. |
Daniel Vetter | b3ba3f6f | 2016-12-21 14:03:35 +0100 | [diff] [blame] | 318 | */ |
Maarten Lankhorst | f46640b | 2017-09-04 12:48:36 +0200 | [diff] [blame] | 319 | static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit) |
Daniel Vetter | 3b24f7d | 2016-06-08 14:19:00 +0200 | [diff] [blame] | 320 | { |
| 321 | kref_get(&commit->ref); |
Maarten Lankhorst | f46640b | 2017-09-04 12:48:36 +0200 | [diff] [blame] | 322 | return commit; |
Daniel Vetter | 3b24f7d | 2016-06-08 14:19:00 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Daniel Vetter | b3ba3f6f | 2016-12-21 14:03:35 +0100 | [diff] [blame] | 325 | /** |
| 326 | * drm_crtc_commit_put - release a reference to the CRTC commmit |
| 327 | * @commit: CRTC commit |
| 328 | * |
| 329 | * This releases a reference to @commit which is freed after removing the |
| 330 | * final reference. No locking required and callable from any context. |
| 331 | */ |
| 332 | static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit) |
| 333 | { |
| 334 | kref_put(&commit->ref, __drm_crtc_commit_free); |
| 335 | } |
| 336 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 337 | struct drm_atomic_state * __must_check |
| 338 | drm_atomic_state_alloc(struct drm_device *dev); |
| 339 | void drm_atomic_state_clear(struct drm_atomic_state *state); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 340 | |
| 341 | /** |
| 342 | * drm_atomic_state_get - acquire a reference to the atomic state |
| 343 | * @state: The atomic state |
| 344 | * |
| 345 | * Returns a new reference to the @state |
| 346 | */ |
| 347 | static inline struct drm_atomic_state * |
| 348 | drm_atomic_state_get(struct drm_atomic_state *state) |
| 349 | { |
| 350 | kref_get(&state->ref); |
| 351 | return state; |
| 352 | } |
| 353 | |
| 354 | void __drm_atomic_state_free(struct kref *ref); |
| 355 | |
| 356 | /** |
| 357 | * drm_atomic_state_put - release a reference to the atomic state |
| 358 | * @state: The atomic state |
| 359 | * |
| 360 | * This releases a reference to @state which is freed after removing the |
| 361 | * final reference. No locking required and callable from any context. |
| 362 | */ |
| 363 | static inline void drm_atomic_state_put(struct drm_atomic_state *state) |
| 364 | { |
| 365 | kref_put(&state->ref, __drm_atomic_state_free); |
| 366 | } |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 367 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 368 | int __must_check |
| 369 | drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state); |
| 370 | void drm_atomic_state_default_clear(struct drm_atomic_state *state); |
| 371 | void drm_atomic_state_default_release(struct drm_atomic_state *state); |
| 372 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 373 | struct drm_crtc_state * __must_check |
| 374 | drm_atomic_get_crtc_state(struct drm_atomic_state *state, |
| 375 | struct drm_crtc *crtc); |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 376 | int drm_atomic_crtc_set_property(struct drm_crtc *crtc, |
| 377 | struct drm_crtc_state *state, struct drm_property *property, |
| 378 | uint64_t val); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 379 | struct drm_plane_state * __must_check |
| 380 | drm_atomic_get_plane_state(struct drm_atomic_state *state, |
| 381 | struct drm_plane *plane); |
| 382 | struct drm_connector_state * __must_check |
| 383 | drm_atomic_get_connector_state(struct drm_atomic_state *state, |
| 384 | struct drm_connector *connector); |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 385 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 386 | void drm_atomic_private_obj_init(struct drm_private_obj *obj, |
| 387 | struct drm_private_state *state, |
| 388 | const struct drm_private_state_funcs *funcs); |
| 389 | void drm_atomic_private_obj_fini(struct drm_private_obj *obj); |
| 390 | |
| 391 | struct drm_private_state * __must_check |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 392 | drm_atomic_get_private_obj_state(struct drm_atomic_state *state, |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 393 | struct drm_private_obj *obj); |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 394 | |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 395 | /** |
| 396 | * drm_atomic_get_existing_crtc_state - get crtc state, if it exists |
| 397 | * @state: global atomic state object |
| 398 | * @crtc: crtc to grab |
| 399 | * |
| 400 | * This function returns the crtc state for the given crtc, or NULL |
| 401 | * if the crtc is not part of the global atomic state. |
Maarten Lankhorst | 2107777 | 2017-02-16 15:47:08 +0100 | [diff] [blame] | 402 | * |
| 403 | * This function is deprecated, @drm_atomic_get_old_crtc_state or |
| 404 | * @drm_atomic_get_new_crtc_state should be used instead. |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 405 | */ |
| 406 | static inline struct drm_crtc_state * |
| 407 | drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state, |
| 408 | struct drm_crtc *crtc) |
| 409 | { |
Daniel Vetter | 5d943aa6 | 2016-06-02 00:06:34 +0200 | [diff] [blame] | 410 | return state->crtcs[drm_crtc_index(crtc)].state; |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /** |
Maarten Lankhorst | 2107777 | 2017-02-16 15:47:08 +0100 | [diff] [blame] | 414 | * drm_atomic_get_old_crtc_state - get old crtc state, if it exists |
| 415 | * @state: global atomic state object |
| 416 | * @crtc: crtc to grab |
| 417 | * |
| 418 | * This function returns the old crtc state for the given crtc, or |
| 419 | * NULL if the crtc is not part of the global atomic state. |
| 420 | */ |
| 421 | static inline struct drm_crtc_state * |
| 422 | drm_atomic_get_old_crtc_state(struct drm_atomic_state *state, |
| 423 | struct drm_crtc *crtc) |
| 424 | { |
| 425 | return state->crtcs[drm_crtc_index(crtc)].old_state; |
| 426 | } |
| 427 | /** |
| 428 | * drm_atomic_get_new_crtc_state - get new crtc state, if it exists |
| 429 | * @state: global atomic state object |
| 430 | * @crtc: crtc to grab |
| 431 | * |
| 432 | * This function returns the new crtc state for the given crtc, or |
| 433 | * NULL if the crtc is not part of the global atomic state. |
| 434 | */ |
| 435 | static inline struct drm_crtc_state * |
| 436 | drm_atomic_get_new_crtc_state(struct drm_atomic_state *state, |
| 437 | struct drm_crtc *crtc) |
| 438 | { |
| 439 | return state->crtcs[drm_crtc_index(crtc)].new_state; |
| 440 | } |
| 441 | |
| 442 | /** |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 443 | * drm_atomic_get_existing_plane_state - get plane state, if it exists |
| 444 | * @state: global atomic state object |
| 445 | * @plane: plane to grab |
| 446 | * |
| 447 | * This function returns the plane state for the given plane, or NULL |
| 448 | * if the plane is not part of the global atomic state. |
Maarten Lankhorst | 2107777 | 2017-02-16 15:47:08 +0100 | [diff] [blame] | 449 | * |
| 450 | * This function is deprecated, @drm_atomic_get_old_plane_state or |
| 451 | * @drm_atomic_get_new_plane_state should be used instead. |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 452 | */ |
| 453 | static inline struct drm_plane_state * |
| 454 | drm_atomic_get_existing_plane_state(struct drm_atomic_state *state, |
| 455 | struct drm_plane *plane) |
| 456 | { |
Daniel Vetter | b8b5342 | 2016-06-02 00:06:33 +0200 | [diff] [blame] | 457 | return state->planes[drm_plane_index(plane)].state; |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /** |
Maarten Lankhorst | 2107777 | 2017-02-16 15:47:08 +0100 | [diff] [blame] | 461 | * drm_atomic_get_old_plane_state - get plane state, if it exists |
| 462 | * @state: global atomic state object |
| 463 | * @plane: plane to grab |
| 464 | * |
| 465 | * This function returns the old plane state for the given plane, or |
| 466 | * NULL if the plane is not part of the global atomic state. |
| 467 | */ |
| 468 | static inline struct drm_plane_state * |
| 469 | drm_atomic_get_old_plane_state(struct drm_atomic_state *state, |
| 470 | struct drm_plane *plane) |
| 471 | { |
| 472 | return state->planes[drm_plane_index(plane)].old_state; |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * drm_atomic_get_new_plane_state - get plane state, if it exists |
| 477 | * @state: global atomic state object |
| 478 | * @plane: plane to grab |
| 479 | * |
| 480 | * This function returns the new plane state for the given plane, or |
| 481 | * NULL if the plane is not part of the global atomic state. |
| 482 | */ |
| 483 | static inline struct drm_plane_state * |
| 484 | drm_atomic_get_new_plane_state(struct drm_atomic_state *state, |
| 485 | struct drm_plane *plane) |
| 486 | { |
| 487 | return state->planes[drm_plane_index(plane)].new_state; |
| 488 | } |
| 489 | |
| 490 | /** |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 491 | * drm_atomic_get_existing_connector_state - get connector state, if it exists |
| 492 | * @state: global atomic state object |
| 493 | * @connector: connector to grab |
| 494 | * |
| 495 | * This function returns the connector state for the given connector, |
| 496 | * or NULL if the connector is not part of the global atomic state. |
Maarten Lankhorst | 2107777 | 2017-02-16 15:47:08 +0100 | [diff] [blame] | 497 | * |
| 498 | * This function is deprecated, @drm_atomic_get_old_connector_state or |
| 499 | * @drm_atomic_get_new_connector_state should be used instead. |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 500 | */ |
| 501 | static inline struct drm_connector_state * |
| 502 | drm_atomic_get_existing_connector_state(struct drm_atomic_state *state, |
| 503 | struct drm_connector *connector) |
| 504 | { |
| 505 | int index = drm_connector_index(connector); |
| 506 | |
| 507 | if (index >= state->num_connector) |
| 508 | return NULL; |
| 509 | |
Daniel Vetter | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 510 | return state->connectors[index].state; |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 511 | } |
| 512 | |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 513 | /** |
Maarten Lankhorst | 2107777 | 2017-02-16 15:47:08 +0100 | [diff] [blame] | 514 | * drm_atomic_get_old_connector_state - get connector state, if it exists |
| 515 | * @state: global atomic state object |
| 516 | * @connector: connector to grab |
| 517 | * |
| 518 | * This function returns the old connector state for the given connector, |
| 519 | * or NULL if the connector is not part of the global atomic state. |
| 520 | */ |
| 521 | static inline struct drm_connector_state * |
| 522 | drm_atomic_get_old_connector_state(struct drm_atomic_state *state, |
| 523 | struct drm_connector *connector) |
| 524 | { |
| 525 | int index = drm_connector_index(connector); |
| 526 | |
| 527 | if (index >= state->num_connector) |
| 528 | return NULL; |
| 529 | |
| 530 | return state->connectors[index].old_state; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * drm_atomic_get_new_connector_state - get connector state, if it exists |
| 535 | * @state: global atomic state object |
| 536 | * @connector: connector to grab |
| 537 | * |
| 538 | * This function returns the new connector state for the given connector, |
| 539 | * or NULL if the connector is not part of the global atomic state. |
| 540 | */ |
| 541 | static inline struct drm_connector_state * |
| 542 | drm_atomic_get_new_connector_state(struct drm_atomic_state *state, |
| 543 | struct drm_connector *connector) |
| 544 | { |
| 545 | int index = drm_connector_index(connector); |
| 546 | |
| 547 | if (index >= state->num_connector) |
| 548 | return NULL; |
| 549 | |
| 550 | return state->connectors[index].new_state; |
| 551 | } |
| 552 | |
| 553 | /** |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 554 | * __drm_atomic_get_current_plane_state - get current plane state |
| 555 | * @state: global atomic state object |
| 556 | * @plane: plane to grab |
| 557 | * |
| 558 | * This function returns the plane state for the given plane, either from |
| 559 | * @state, or if the plane isn't part of the atomic state update, from @plane. |
| 560 | * This is useful in atomic check callbacks, when drivers need to peek at, but |
| 561 | * not change, state of other planes, since it avoids threading an error code |
| 562 | * back up the call chain. |
| 563 | * |
| 564 | * WARNING: |
| 565 | * |
| 566 | * Note that this function is in general unsafe since it doesn't check for the |
| 567 | * required locking for access state structures. Drivers must ensure that it is |
Daniel Vetter | 60c9e190 | 2016-06-02 17:39:14 +0200 | [diff] [blame] | 568 | * safe to access the returned state structure through other means. One common |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 569 | * example is when planes are fixed to a single CRTC, and the driver knows that |
Daniel Vetter | 60c9e190 | 2016-06-02 17:39:14 +0200 | [diff] [blame] | 570 | * the CRTC lock is held already. In that case holding the CRTC lock gives a |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 571 | * read-lock on all planes connected to that CRTC. But if planes can be |
| 572 | * reassigned things get more tricky. In that case it's better to use |
| 573 | * drm_atomic_get_plane_state and wire up full error handling. |
| 574 | * |
| 575 | * Returns: |
| 576 | * |
| 577 | * Read-only pointer to the current plane state. |
| 578 | */ |
| 579 | static inline const struct drm_plane_state * |
| 580 | __drm_atomic_get_current_plane_state(struct drm_atomic_state *state, |
| 581 | struct drm_plane *plane) |
| 582 | { |
Daniel Vetter | b8b5342 | 2016-06-02 00:06:33 +0200 | [diff] [blame] | 583 | if (state->planes[drm_plane_index(plane)].state) |
| 584 | return state->planes[drm_plane_index(plane)].state; |
Daniel Vetter | 2f196b7 | 2016-06-02 16:21:44 +0200 | [diff] [blame] | 585 | |
| 586 | return plane->state; |
| 587 | } |
| 588 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 589 | int __must_check |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 590 | drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, |
Ville Syrjälä | 91110a4 | 2017-05-18 22:38:36 +0300 | [diff] [blame] | 591 | const struct drm_display_mode *mode); |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 592 | int __must_check |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 593 | drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, |
| 594 | struct drm_property_blob *blob); |
| 595 | int __must_check |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 596 | drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state, |
| 597 | struct drm_crtc *crtc); |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 598 | void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state, |
| 599 | struct drm_framebuffer *fb); |
Gustavo Padovan | 13b5566 | 2016-11-07 19:03:30 +0900 | [diff] [blame] | 600 | void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state, |
| 601 | struct dma_fence *fence); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 602 | int __must_check |
| 603 | drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state, |
| 604 | struct drm_crtc *crtc); |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 605 | int drm_atomic_set_writeback_fb_for_connector( |
| 606 | struct drm_connector_state *conn_state, |
| 607 | struct drm_framebuffer *fb); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 608 | int __must_check |
| 609 | drm_atomic_add_affected_connectors(struct drm_atomic_state *state, |
| 610 | struct drm_crtc *crtc); |
Maarten Lankhorst | e01e9f7 | 2015-05-19 16:41:02 +0200 | [diff] [blame] | 611 | int __must_check |
| 612 | drm_atomic_add_affected_planes(struct drm_atomic_state *state, |
| 613 | struct drm_crtc *crtc); |
| 614 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 615 | int __must_check drm_atomic_check_only(struct drm_atomic_state *state); |
| 616 | int __must_check drm_atomic_commit(struct drm_atomic_state *state); |
Maarten Lankhorst | b837ba0 | 2016-04-26 16:11:35 +0200 | [diff] [blame] | 617 | int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 618 | |
Rob Clark | 6559c90 | 2016-11-05 11:08:10 -0400 | [diff] [blame] | 619 | void drm_state_dump(struct drm_device *dev, struct drm_printer *p); |
| 620 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 621 | /** |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 622 | * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update |
| 623 | * @__state: &struct drm_atomic_state pointer |
| 624 | * @connector: &struct drm_connector iteration cursor |
| 625 | * @old_connector_state: &struct drm_connector_state iteration cursor for the |
| 626 | * old state |
| 627 | * @new_connector_state: &struct drm_connector_state iteration cursor for the |
| 628 | * new state |
| 629 | * @__i: int iteration cursor, for macro-internal use |
| 630 | * |
| 631 | * This iterates over all connectors in an atomic update, tracking both old and |
| 632 | * new state. This is useful in places where the state delta needs to be |
| 633 | * considered, for example in atomic check functions. |
| 634 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 635 | #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \ |
| 636 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 637 | (__i) < (__state)->num_connector; \ |
| 638 | (__i)++) \ |
| 639 | for_each_if ((__state)->connectors[__i].ptr && \ |
| 640 | ((connector) = (__state)->connectors[__i].ptr, \ |
| 641 | (old_connector_state) = (__state)->connectors[__i].old_state, \ |
| 642 | (new_connector_state) = (__state)->connectors[__i].new_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 643 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 644 | /** |
| 645 | * for_each_old_connector_in_state - iterate over all connectors in an atomic update |
| 646 | * @__state: &struct drm_atomic_state pointer |
| 647 | * @connector: &struct drm_connector iteration cursor |
| 648 | * @old_connector_state: &struct drm_connector_state iteration cursor for the |
| 649 | * old state |
| 650 | * @__i: int iteration cursor, for macro-internal use |
| 651 | * |
| 652 | * This iterates over all connectors in an atomic update, tracking only the old |
| 653 | * state. This is useful in disable functions, where we need the old state the |
| 654 | * hardware is still in. |
| 655 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 656 | #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \ |
| 657 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 658 | (__i) < (__state)->num_connector; \ |
| 659 | (__i)++) \ |
| 660 | for_each_if ((__state)->connectors[__i].ptr && \ |
| 661 | ((connector) = (__state)->connectors[__i].ptr, \ |
| 662 | (old_connector_state) = (__state)->connectors[__i].old_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 663 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 664 | /** |
| 665 | * for_each_new_connector_in_state - iterate over all connectors in an atomic update |
| 666 | * @__state: &struct drm_atomic_state pointer |
| 667 | * @connector: &struct drm_connector iteration cursor |
| 668 | * @new_connector_state: &struct drm_connector_state iteration cursor for the |
| 669 | * new state |
| 670 | * @__i: int iteration cursor, for macro-internal use |
| 671 | * |
| 672 | * This iterates over all connectors in an atomic update, tracking only the new |
| 673 | * state. This is useful in enable functions, where we need the new state the |
| 674 | * hardware should be in when the atomic commit operation has completed. |
| 675 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 676 | #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \ |
| 677 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 678 | (__i) < (__state)->num_connector; \ |
| 679 | (__i)++) \ |
| 680 | for_each_if ((__state)->connectors[__i].ptr && \ |
| 681 | ((connector) = (__state)->connectors[__i].ptr, \ |
| 682 | (new_connector_state) = (__state)->connectors[__i].new_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 683 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 684 | /** |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 685 | * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update |
| 686 | * @__state: &struct drm_atomic_state pointer |
| 687 | * @crtc: &struct drm_crtc iteration cursor |
| 688 | * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state |
| 689 | * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state |
| 690 | * @__i: int iteration cursor, for macro-internal use |
| 691 | * |
| 692 | * This iterates over all CRTCs in an atomic update, tracking both old and |
| 693 | * new state. This is useful in places where the state delta needs to be |
| 694 | * considered, for example in atomic check functions. |
| 695 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 696 | #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \ |
| 697 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 698 | (__i) < (__state)->dev->mode_config.num_crtc; \ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 699 | (__i)++) \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 700 | for_each_if ((__state)->crtcs[__i].ptr && \ |
| 701 | ((crtc) = (__state)->crtcs[__i].ptr, \ |
| 702 | (old_crtc_state) = (__state)->crtcs[__i].old_state, \ |
| 703 | (new_crtc_state) = (__state)->crtcs[__i].new_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 704 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 705 | /** |
| 706 | * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update |
| 707 | * @__state: &struct drm_atomic_state pointer |
| 708 | * @crtc: &struct drm_crtc iteration cursor |
| 709 | * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state |
| 710 | * @__i: int iteration cursor, for macro-internal use |
| 711 | * |
| 712 | * This iterates over all CRTCs in an atomic update, tracking only the old |
| 713 | * state. This is useful in disable functions, where we need the old state the |
| 714 | * hardware is still in. |
| 715 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 716 | #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \ |
| 717 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 718 | (__i) < (__state)->dev->mode_config.num_crtc; \ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 719 | (__i)++) \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 720 | for_each_if ((__state)->crtcs[__i].ptr && \ |
| 721 | ((crtc) = (__state)->crtcs[__i].ptr, \ |
| 722 | (old_crtc_state) = (__state)->crtcs[__i].old_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 723 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 724 | /** |
| 725 | * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update |
| 726 | * @__state: &struct drm_atomic_state pointer |
| 727 | * @crtc: &struct drm_crtc iteration cursor |
| 728 | * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state |
| 729 | * @__i: int iteration cursor, for macro-internal use |
| 730 | * |
| 731 | * This iterates over all CRTCs in an atomic update, tracking only the new |
| 732 | * state. This is useful in enable functions, where we need the new state the |
| 733 | * hardware should be in when the atomic commit operation has completed. |
| 734 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 735 | #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \ |
| 736 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 737 | (__i) < (__state)->dev->mode_config.num_crtc; \ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 738 | (__i)++) \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 739 | for_each_if ((__state)->crtcs[__i].ptr && \ |
| 740 | ((crtc) = (__state)->crtcs[__i].ptr, \ |
| 741 | (new_crtc_state) = (__state)->crtcs[__i].new_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 742 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 743 | /** |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 744 | * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update |
| 745 | * @__state: &struct drm_atomic_state pointer |
| 746 | * @plane: &struct drm_plane iteration cursor |
| 747 | * @old_plane_state: &struct drm_plane_state iteration cursor for the old state |
| 748 | * @new_plane_state: &struct drm_plane_state iteration cursor for the new state |
| 749 | * @__i: int iteration cursor, for macro-internal use |
| 750 | * |
| 751 | * This iterates over all planes in an atomic update, tracking both old and |
| 752 | * new state. This is useful in places where the state delta needs to be |
| 753 | * considered, for example in atomic check functions. |
| 754 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 755 | #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \ |
| 756 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 757 | (__i) < (__state)->dev->mode_config.num_total_plane; \ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 758 | (__i)++) \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 759 | for_each_if ((__state)->planes[__i].ptr && \ |
| 760 | ((plane) = (__state)->planes[__i].ptr, \ |
| 761 | (old_plane_state) = (__state)->planes[__i].old_state,\ |
| 762 | (new_plane_state) = (__state)->planes[__i].new_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 763 | |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 764 | /** |
Shirish S | 55de292 | 2018-03-07 08:40:03 +0530 | [diff] [blame] | 765 | * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic |
| 766 | * update in reverse order |
| 767 | * @__state: &struct drm_atomic_state pointer |
| 768 | * @plane: &struct drm_plane iteration cursor |
| 769 | * @old_plane_state: &struct drm_plane_state iteration cursor for the old state |
| 770 | * @new_plane_state: &struct drm_plane_state iteration cursor for the new state |
| 771 | * @__i: int iteration cursor, for macro-internal use |
| 772 | * |
| 773 | * This iterates over all planes in an atomic update in reverse order, |
| 774 | * tracking both old and new state. This is useful in places where the |
| 775 | * state delta needs to be considered, for example in atomic check functions. |
| 776 | */ |
| 777 | #define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \ |
| 778 | for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \ |
| 779 | (__i) >= 0; \ |
| 780 | (__i)--) \ |
| 781 | for_each_if ((__state)->planes[__i].ptr && \ |
| 782 | ((plane) = (__state)->planes[__i].ptr, \ |
| 783 | (old_plane_state) = (__state)->planes[__i].old_state,\ |
| 784 | (new_plane_state) = (__state)->planes[__i].new_state, 1)) |
| 785 | |
| 786 | /** |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 787 | * for_each_old_plane_in_state - iterate over all planes in an atomic update |
| 788 | * @__state: &struct drm_atomic_state pointer |
| 789 | * @plane: &struct drm_plane iteration cursor |
| 790 | * @old_plane_state: &struct drm_plane_state iteration cursor for the old state |
| 791 | * @__i: int iteration cursor, for macro-internal use |
| 792 | * |
| 793 | * This iterates over all planes in an atomic update, tracking only the old |
| 794 | * state. This is useful in disable functions, where we need the old state the |
| 795 | * hardware is still in. |
| 796 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 797 | #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \ |
| 798 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 799 | (__i) < (__state)->dev->mode_config.num_total_plane; \ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 800 | (__i)++) \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 801 | for_each_if ((__state)->planes[__i].ptr && \ |
| 802 | ((plane) = (__state)->planes[__i].ptr, \ |
| 803 | (old_plane_state) = (__state)->planes[__i].old_state, 1)) |
Daniel Vetter | f9a7695 | 2017-03-28 17:53:49 +0200 | [diff] [blame] | 804 | /** |
| 805 | * for_each_new_plane_in_state - iterate over all planes in an atomic update |
| 806 | * @__state: &struct drm_atomic_state pointer |
| 807 | * @plane: &struct drm_plane iteration cursor |
| 808 | * @new_plane_state: &struct drm_plane_state iteration cursor for the new state |
| 809 | * @__i: int iteration cursor, for macro-internal use |
| 810 | * |
| 811 | * This iterates over all planes in an atomic update, tracking only the new |
| 812 | * state. This is useful in enable functions, where we need the new state the |
| 813 | * hardware should be in when the atomic commit operation has completed. |
| 814 | */ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 815 | #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \ |
| 816 | for ((__i) = 0; \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 817 | (__i) < (__state)->dev->mode_config.num_total_plane; \ |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 818 | (__i)++) \ |
Maarten Lankhorst | 331494e | 2017-09-27 10:35:32 +0200 | [diff] [blame] | 819 | for_each_if ((__state)->planes[__i].ptr && \ |
| 820 | ((plane) = (__state)->planes[__i].ptr, \ |
| 821 | (new_plane_state) = (__state)->planes[__i].new_state, 1)) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 822 | |
Daniel Vetter | 081e9c0 | 2016-06-08 14:18:59 +0200 | [diff] [blame] | 823 | /** |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 824 | * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 825 | * @__state: &struct drm_atomic_state pointer |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 826 | * @obj: &struct drm_private_obj iteration cursor |
| 827 | * @old_obj_state: &struct drm_private_state iteration cursor for the old state |
| 828 | * @new_obj_state: &struct drm_private_state iteration cursor for the new state |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 829 | * @__i: int iteration cursor, for macro-internal use |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 830 | * |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 831 | * This iterates over all private objects in an atomic update, tracking both |
| 832 | * old and new state. This is useful in places where the state delta needs |
| 833 | * to be considered, for example in atomic check functions. |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 834 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 835 | #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \ |
| 836 | for ((__i) = 0; \ |
| 837 | (__i) < (__state)->num_private_objs && \ |
| 838 | ((obj) = (__state)->private_objs[__i].ptr, \ |
| 839 | (old_obj_state) = (__state)->private_objs[__i].old_state, \ |
| 840 | (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \ |
Maarten Lankhorst | f0d2e86 | 2017-09-27 10:35:31 +0200 | [diff] [blame] | 841 | (__i)++) |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 842 | |
| 843 | /** |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 844 | * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 845 | * @__state: &struct drm_atomic_state pointer |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 846 | * @obj: &struct drm_private_obj iteration cursor |
| 847 | * @old_obj_state: &struct drm_private_state iteration cursor for the old state |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 848 | * @__i: int iteration cursor, for macro-internal use |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 849 | * |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 850 | * This iterates over all private objects in an atomic update, tracking only |
| 851 | * the old state. This is useful in disable functions, where we need the old |
| 852 | * state the hardware is still in. |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 853 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 854 | #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \ |
| 855 | for ((__i) = 0; \ |
| 856 | (__i) < (__state)->num_private_objs && \ |
| 857 | ((obj) = (__state)->private_objs[__i].ptr, \ |
| 858 | (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \ |
Maarten Lankhorst | f0d2e86 | 2017-09-27 10:35:31 +0200 | [diff] [blame] | 859 | (__i)++) |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 860 | |
| 861 | /** |
| 862 | * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update |
| 863 | * @__state: &struct drm_atomic_state pointer |
| 864 | * @obj: &struct drm_private_obj iteration cursor |
| 865 | * @new_obj_state: &struct drm_private_state iteration cursor for the new state |
| 866 | * @__i: int iteration cursor, for macro-internal use |
| 867 | * |
| 868 | * This iterates over all private objects in an atomic update, tracking only |
| 869 | * the new state. This is useful in enable functions, where we need the new state the |
| 870 | * hardware should be in when the atomic commit operation has completed. |
| 871 | */ |
| 872 | #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \ |
| 873 | for ((__i) = 0; \ |
| 874 | (__i) < (__state)->num_private_objs && \ |
| 875 | ((obj) = (__state)->private_objs[__i].ptr, \ |
| 876 | (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \ |
Maarten Lankhorst | f0d2e86 | 2017-09-27 10:35:31 +0200 | [diff] [blame] | 877 | (__i)++) |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 878 | |
| 879 | /** |
Daniel Vetter | 081e9c0 | 2016-06-08 14:18:59 +0200 | [diff] [blame] | 880 | * drm_atomic_crtc_needs_modeset - compute combined modeset need |
| 881 | * @state: &drm_crtc_state for the CRTC |
| 882 | * |
Daniel Vetter | ea0dd85 | 2016-12-29 21:48:26 +0100 | [diff] [blame] | 883 | * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track |
Daniel Vetter | 081e9c0 | 2016-06-08 14:18:59 +0200 | [diff] [blame] | 884 | * whether the state CRTC changed enough to need a full modeset cycle: |
Thierry Reding | 96bf51d | 2017-07-31 11:13:43 +0200 | [diff] [blame] | 885 | * mode_changed, active_changed and connectors_changed. This helper simply |
Daniel Vetter | 081e9c0 | 2016-06-08 14:18:59 +0200 | [diff] [blame] | 886 | * combines these three to compute the overall need for a modeset for @state. |
Brian Starkey | d807ed1 | 2016-10-13 10:47:08 +0100 | [diff] [blame] | 887 | * |
| 888 | * The atomic helper code sets these booleans, but drivers can and should |
| 889 | * change them appropriately to accurately represent whether a modeset is |
| 890 | * really needed. In general, drivers should avoid full modesets whenever |
| 891 | * possible. |
| 892 | * |
| 893 | * For example if the CRTC mode has changed, and the hardware is able to enact |
| 894 | * the requested mode change without going through a full modeset, the driver |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 895 | * should clear mode_changed in its &drm_mode_config_funcs.atomic_check |
| 896 | * implementation. |
Daniel Vetter | 081e9c0 | 2016-06-08 14:18:59 +0200 | [diff] [blame] | 897 | */ |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 898 | static inline bool |
Ville Syrjälä | 79b9555 | 2016-11-24 19:47:02 +0200 | [diff] [blame] | 899 | drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state) |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 900 | { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 901 | return state->mode_changed || state->active_changed || |
| 902 | state->connectors_changed; |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 903 | } |
| 904 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 905 | #endif /* DRM_ATOMIC_H_ */ |