2 * Copyright (C) 2014 Red Hat
3 * Copyright (C) 2014 Intel Corp.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
24 * Rob Clark <robdclark@gmail.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
31 #include <drm/drm_crtc.h>
34 * struct drm_crtc_commit - track modeset commits on a CRTC
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.
41 * It has 3 different events in total to allow a fine-grained synchronization
42 * between outstanding updates::
44 * atomic commit thread hardware
46 * write new state into hardware ----> ...
48 * switch to new state on next
51 * wait for buffers to show up ...
53 * ... send completion irq
54 * irq handler signals flip_done
59 * wait for flip_done <----
60 * clean up atomic state
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.
66 * For an implementation of how to use this look at
67 * drm_atomic_helper_setup_commit() from the atomic helper library.
69 struct drm_crtc_commit {
73 * DRM CRTC for this commit.
75 struct drm_crtc *crtc;
80 * Reference count for this structure. Needed to allow blocking on
81 * completions without the risk of the completion disappearing
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
95 struct completion flip_done;
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
106 * Note that this does not need to include separately reference-counted
107 * resources like backing storage buffer pinning, or runtime pm
110 struct completion hw_done;
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.
121 struct completion cleanup_done;
126 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
127 * $drm_crtc.commit_lock.
129 struct list_head commit_entry;
134 * &drm_pending_vblank_event pointer to clean up private events.
136 struct drm_pending_vblank_event *event;
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.
145 bool abort_completion;
148 struct __drm_planes_state {
149 struct drm_plane *ptr;
150 struct drm_plane_state *state, *old_state, *new_state;
153 struct __drm_crtcs_state {
154 struct drm_crtc *ptr;
155 struct drm_crtc_state *state, *old_state, *new_state;
156 s32 __user *out_fence_ptr;
157 u64 last_vblank_count;
160 struct __drm_connnectors_state {
161 struct drm_connector *ptr;
162 struct drm_connector_state *state, *old_state, *new_state;
166 * User-provided pointer which the kernel uses to return a sync_file
167 * file descriptor. Used by writeback connectors to signal completion of
170 s32 __user *out_fence_ptr;
173 struct drm_private_obj;
174 struct drm_private_state;
177 * struct drm_private_state_funcs - atomic state functions for private objects
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().
186 struct drm_private_state_funcs {
188 * @atomic_duplicate_state:
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.
195 * Duplicated atomic state or NULL when obj->state is not
196 * initialized or allocation failed.
198 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
201 * @atomic_destroy_state:
203 * Frees the private object state created with @atomic_duplicate_state.
205 void (*atomic_destroy_state)(struct drm_private_obj *obj,
206 struct drm_private_state *state);
210 * struct drm_private_obj - base struct for driver private atomic object
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().
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.
220 struct drm_private_obj {
222 * @state: Current atomic state for this driver private object.
224 struct drm_private_state *state;
229 * Functions to manipulate the state of this driver private object, see
230 * &drm_private_state_funcs.
232 const struct drm_private_state_funcs *funcs;
236 * struct drm_private_state - base struct for driver private object state
237 * @state: backpointer to global drm_atomic_state
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.
243 struct drm_private_state {
244 struct drm_atomic_state *state;
247 struct __drm_private_objs_state {
248 struct drm_private_obj *ptr;
249 struct drm_private_state *state, *old_state, *new_state;
253 * struct drm_atomic_state - the global state object for atomic updates
254 * @ref: count of all references to this state (will not be freed until zero)
255 * @dev: parent DRM device
256 * @allow_modeset: allow full modeset
257 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
258 * @async_update: hint for asynchronous plane update
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
263 * @num_private_objs: size of the @private_objs array
264 * @private_objs: pointer to array of private object pointers
265 * @acquire_ctx: acquire context for this atomic modeset state update
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().
271 struct drm_atomic_state {
274 struct drm_device *dev;
275 bool allow_modeset : 1;
276 bool legacy_cursor_update : 1;
277 bool async_update : 1;
278 struct __drm_planes_state *planes;
279 struct __drm_crtcs_state *crtcs;
281 struct __drm_connnectors_state *connectors;
282 int num_private_objs;
283 struct __drm_private_objs_state *private_objs;
285 struct drm_modeset_acquire_ctx *acquire_ctx;
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.
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.
297 struct drm_crtc_commit *fake_commit;
302 * Work item which can be used by the driver or helpers to execute the
303 * commit without blocking.
305 struct work_struct commit_work;
308 void __drm_crtc_commit_free(struct kref *kref);
311 * drm_crtc_commit_get - acquire a reference to the CRTC commit
312 * @commit: CRTC commit
314 * Increases the reference of @commit.
317 * The pointer to @commit, with reference increased.
319 static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
321 kref_get(&commit->ref);
326 * drm_crtc_commit_put - release a reference to the CRTC commmit
327 * @commit: CRTC commit
329 * This releases a reference to @commit which is freed after removing the
330 * final reference. No locking required and callable from any context.
332 static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
334 kref_put(&commit->ref, __drm_crtc_commit_free);
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);
342 * drm_atomic_state_get - acquire a reference to the atomic state
343 * @state: The atomic state
345 * Returns a new reference to the @state
347 static inline struct drm_atomic_state *
348 drm_atomic_state_get(struct drm_atomic_state *state)
350 kref_get(&state->ref);
354 void __drm_atomic_state_free(struct kref *ref);
357 * drm_atomic_state_put - release a reference to the atomic state
358 * @state: The atomic state
360 * This releases a reference to @state which is freed after removing the
361 * final reference. No locking required and callable from any context.
363 static inline void drm_atomic_state_put(struct drm_atomic_state *state)
365 kref_put(&state->ref, __drm_atomic_state_free);
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);
373 struct drm_crtc_state * __must_check
374 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
375 struct drm_crtc *crtc);
376 int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
377 struct drm_crtc_state *state, struct drm_property *property,
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);
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);
391 struct drm_private_state * __must_check
392 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
393 struct drm_private_obj *obj);
396 * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
397 * @state: global atomic state object
398 * @crtc: crtc to grab
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.
403 * This function is deprecated, @drm_atomic_get_old_crtc_state or
404 * @drm_atomic_get_new_crtc_state should be used instead.
406 static inline struct drm_crtc_state *
407 drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
408 struct drm_crtc *crtc)
410 return state->crtcs[drm_crtc_index(crtc)].state;
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
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.
421 static inline struct drm_crtc_state *
422 drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
423 struct drm_crtc *crtc)
425 return state->crtcs[drm_crtc_index(crtc)].old_state;
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
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.
435 static inline struct drm_crtc_state *
436 drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
437 struct drm_crtc *crtc)
439 return state->crtcs[drm_crtc_index(crtc)].new_state;
443 * drm_atomic_get_existing_plane_state - get plane state, if it exists
444 * @state: global atomic state object
445 * @plane: plane to grab
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.
450 * This function is deprecated, @drm_atomic_get_old_plane_state or
451 * @drm_atomic_get_new_plane_state should be used instead.
453 static inline struct drm_plane_state *
454 drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
455 struct drm_plane *plane)
457 return state->planes[drm_plane_index(plane)].state;
461 * drm_atomic_get_old_plane_state - get plane state, if it exists
462 * @state: global atomic state object
463 * @plane: plane to grab
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.
468 static inline struct drm_plane_state *
469 drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
470 struct drm_plane *plane)
472 return state->planes[drm_plane_index(plane)].old_state;
476 * drm_atomic_get_new_plane_state - get plane state, if it exists
477 * @state: global atomic state object
478 * @plane: plane to grab
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.
483 static inline struct drm_plane_state *
484 drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
485 struct drm_plane *plane)
487 return state->planes[drm_plane_index(plane)].new_state;
491 * drm_atomic_get_existing_connector_state - get connector state, if it exists
492 * @state: global atomic state object
493 * @connector: connector to grab
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.
498 * This function is deprecated, @drm_atomic_get_old_connector_state or
499 * @drm_atomic_get_new_connector_state should be used instead.
501 static inline struct drm_connector_state *
502 drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
503 struct drm_connector *connector)
505 int index = drm_connector_index(connector);
507 if (index >= state->num_connector)
510 return state->connectors[index].state;
514 * drm_atomic_get_old_connector_state - get connector state, if it exists
515 * @state: global atomic state object
516 * @connector: connector to grab
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.
521 static inline struct drm_connector_state *
522 drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
523 struct drm_connector *connector)
525 int index = drm_connector_index(connector);
527 if (index >= state->num_connector)
530 return state->connectors[index].old_state;
534 * drm_atomic_get_new_connector_state - get connector state, if it exists
535 * @state: global atomic state object
536 * @connector: connector to grab
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.
541 static inline struct drm_connector_state *
542 drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
543 struct drm_connector *connector)
545 int index = drm_connector_index(connector);
547 if (index >= state->num_connector)
550 return state->connectors[index].new_state;
554 * __drm_atomic_get_current_plane_state - get current plane state
555 * @state: global atomic state object
556 * @plane: plane to grab
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.
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
568 * safe to access the returned state structure through other means. One common
569 * example is when planes are fixed to a single CRTC, and the driver knows that
570 * the CRTC lock is held already. In that case holding the CRTC lock gives a
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.
577 * Read-only pointer to the current plane state.
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)
583 if (state->planes[drm_plane_index(plane)].state)
584 return state->planes[drm_plane_index(plane)].state;
590 drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
591 const struct drm_display_mode *mode);
593 drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
594 struct drm_property_blob *blob);
596 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
597 struct drm_crtc *crtc);
598 void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
599 struct drm_framebuffer *fb);
600 void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
601 struct dma_fence *fence);
603 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
604 struct drm_crtc *crtc);
605 int drm_atomic_set_writeback_fb_for_connector(
606 struct drm_connector_state *conn_state,
607 struct drm_framebuffer *fb);
609 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
610 struct drm_crtc *crtc);
612 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
613 struct drm_crtc *crtc);
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);
617 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
619 void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
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
627 * @new_connector_state: &struct drm_connector_state iteration cursor for the
629 * @__i: int iteration cursor, for macro-internal use
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.
635 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
637 (__i) < (__state)->num_connector; \
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))
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
650 * @__i: int iteration cursor, for macro-internal use
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.
656 #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
658 (__i) < (__state)->num_connector; \
660 for_each_if ((__state)->connectors[__i].ptr && \
661 ((connector) = (__state)->connectors[__i].ptr, \
662 (old_connector_state) = (__state)->connectors[__i].old_state, 1))
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
670 * @__i: int iteration cursor, for macro-internal use
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.
676 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
678 (__i) < (__state)->num_connector; \
680 for_each_if ((__state)->connectors[__i].ptr && \
681 ((connector) = (__state)->connectors[__i].ptr, \
682 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
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
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.
696 #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
698 (__i) < (__state)->dev->mode_config.num_crtc; \
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))
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
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.
716 #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
718 (__i) < (__state)->dev->mode_config.num_crtc; \
720 for_each_if ((__state)->crtcs[__i].ptr && \
721 ((crtc) = (__state)->crtcs[__i].ptr, \
722 (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
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
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.
735 #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
737 (__i) < (__state)->dev->mode_config.num_crtc; \
739 for_each_if ((__state)->crtcs[__i].ptr && \
740 ((crtc) = (__state)->crtcs[__i].ptr, \
741 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
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
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.
755 #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
757 (__i) < (__state)->dev->mode_config.num_total_plane; \
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))
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
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.
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); \
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))
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
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.
797 #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
799 (__i) < (__state)->dev->mode_config.num_total_plane; \
801 for_each_if ((__state)->planes[__i].ptr && \
802 ((plane) = (__state)->planes[__i].ptr, \
803 (old_plane_state) = (__state)->planes[__i].old_state, 1))
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
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.
815 #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
817 (__i) < (__state)->dev->mode_config.num_total_plane; \
819 for_each_if ((__state)->planes[__i].ptr && \
820 ((plane) = (__state)->planes[__i].ptr, \
821 (new_plane_state) = (__state)->planes[__i].new_state, 1))
824 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
825 * @__state: &struct drm_atomic_state pointer
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
829 * @__i: int iteration cursor, for macro-internal use
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.
835 #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
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); \
844 * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
845 * @__state: &struct drm_atomic_state pointer
846 * @obj: &struct drm_private_obj iteration cursor
847 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
848 * @__i: int iteration cursor, for macro-internal use
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.
854 #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
856 (__i) < (__state)->num_private_objs && \
857 ((obj) = (__state)->private_objs[__i].ptr, \
858 (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
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
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.
872 #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
874 (__i) < (__state)->num_private_objs && \
875 ((obj) = (__state)->private_objs[__i].ptr, \
876 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
880 * drm_atomic_crtc_needs_modeset - compute combined modeset need
881 * @state: &drm_crtc_state for the CRTC
883 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
884 * whether the state CRTC changed enough to need a full modeset cycle:
885 * mode_changed, active_changed and connectors_changed. This helper simply
886 * combines these three to compute the overall need for a modeset for @state.
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
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
895 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
899 drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
901 return state->mode_changed || state->active_changed ||
902 state->connectors_changed;
905 #endif /* DRM_ATOMIC_H_ */