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;
160 * A reference to the CRTC commit object that is kept for use by
161 * drm_atomic_helper_wait_for_flip_done() after
162 * drm_atomic_helper_commit_hw_done() is called. This ensures that a
163 * concurrent commit won't free a commit object that is still in use.
165 struct drm_crtc_commit *commit;
167 s32 __user *out_fence_ptr;
168 u64 last_vblank_count;
171 struct __drm_connnectors_state {
172 struct drm_connector *ptr;
173 struct drm_connector_state *state, *old_state, *new_state;
177 * User-provided pointer which the kernel uses to return a sync_file
178 * file descriptor. Used by writeback connectors to signal completion of
181 s32 __user *out_fence_ptr;
184 struct drm_private_obj;
185 struct drm_private_state;
188 * struct drm_private_state_funcs - atomic state functions for private objects
190 * These hooks are used by atomic helpers to create, swap and destroy states of
191 * private objects. The structure itself is used as a vtable to identify the
192 * associated private object type. Each private object type that needs to be
193 * added to the atomic states is expected to have an implementation of these
194 * hooks and pass a pointer to it's drm_private_state_funcs struct to
195 * drm_atomic_get_private_obj_state().
197 struct drm_private_state_funcs {
199 * @atomic_duplicate_state:
201 * Duplicate the current state of the private object and return it. It
202 * is an error to call this before obj->state has been initialized.
206 * Duplicated atomic state or NULL when obj->state is not
207 * initialized or allocation failed.
209 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
212 * @atomic_destroy_state:
214 * Frees the private object state created with @atomic_duplicate_state.
216 void (*atomic_destroy_state)(struct drm_private_obj *obj,
217 struct drm_private_state *state);
221 * struct drm_private_obj - base struct for driver private atomic object
223 * A driver private object is initialized by calling
224 * drm_atomic_private_obj_init() and cleaned up by calling
225 * drm_atomic_private_obj_fini().
227 * Currently only tracks the state update functions and the opaque driver
228 * private state itself, but in the future might also track which
229 * &drm_modeset_lock is required to duplicate and update this object's state.
231 struct drm_private_obj {
233 * @state: Current atomic state for this driver private object.
235 struct drm_private_state *state;
240 * Functions to manipulate the state of this driver private object, see
241 * &drm_private_state_funcs.
243 const struct drm_private_state_funcs *funcs;
247 * struct drm_private_state - base struct for driver private object state
248 * @state: backpointer to global drm_atomic_state
250 * Currently only contains a backpointer to the overall atomic update, but in
251 * the future also might hold synchronization information similar to e.g.
254 struct drm_private_state {
255 struct drm_atomic_state *state;
258 struct __drm_private_objs_state {
259 struct drm_private_obj *ptr;
260 struct drm_private_state *state, *old_state, *new_state;
264 * struct drm_atomic_state - the global state object for atomic updates
265 * @ref: count of all references to this state (will not be freed until zero)
266 * @dev: parent DRM device
267 * @allow_modeset: allow full modeset
268 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
269 * @async_update: hint for asynchronous plane update
270 * @planes: pointer to array of structures with per-plane data
271 * @crtcs: pointer to array of CRTC pointers
272 * @num_connector: size of the @connectors and @connector_states arrays
273 * @connectors: pointer to array of structures with per-connector data
274 * @num_private_objs: size of the @private_objs array
275 * @private_objs: pointer to array of private object pointers
276 * @acquire_ctx: acquire context for this atomic modeset state update
278 * States are added to an atomic update by calling drm_atomic_get_crtc_state(),
279 * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for
280 * private state structures, drm_atomic_get_private_obj_state().
282 struct drm_atomic_state {
285 struct drm_device *dev;
286 bool allow_modeset : 1;
287 bool legacy_cursor_update : 1;
288 bool async_update : 1;
289 struct __drm_planes_state *planes;
290 struct __drm_crtcs_state *crtcs;
292 struct __drm_connnectors_state *connectors;
293 int num_private_objs;
294 struct __drm_private_objs_state *private_objs;
296 struct drm_modeset_acquire_ctx *acquire_ctx;
301 * Used for signaling unbound planes/connectors.
302 * When a connector or plane is not bound to any CRTC, it's still important
303 * to preserve linearity to prevent the atomic states from being freed to early.
305 * This commit (if set) is not bound to any crtc, but will be completed when
306 * drm_atomic_helper_commit_hw_done() is called.
308 struct drm_crtc_commit *fake_commit;
313 * Work item which can be used by the driver or helpers to execute the
314 * commit without blocking.
316 struct work_struct commit_work;
319 void __drm_crtc_commit_free(struct kref *kref);
322 * drm_crtc_commit_get - acquire a reference to the CRTC commit
323 * @commit: CRTC commit
325 * Increases the reference of @commit.
328 * The pointer to @commit, with reference increased.
330 static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
332 kref_get(&commit->ref);
337 * drm_crtc_commit_put - release a reference to the CRTC commmit
338 * @commit: CRTC commit
340 * This releases a reference to @commit which is freed after removing the
341 * final reference. No locking required and callable from any context.
343 static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
345 kref_put(&commit->ref, __drm_crtc_commit_free);
348 struct drm_atomic_state * __must_check
349 drm_atomic_state_alloc(struct drm_device *dev);
350 void drm_atomic_state_clear(struct drm_atomic_state *state);
353 * drm_atomic_state_get - acquire a reference to the atomic state
354 * @state: The atomic state
356 * Returns a new reference to the @state
358 static inline struct drm_atomic_state *
359 drm_atomic_state_get(struct drm_atomic_state *state)
361 kref_get(&state->ref);
365 void __drm_atomic_state_free(struct kref *ref);
368 * drm_atomic_state_put - release a reference to the atomic state
369 * @state: The atomic state
371 * This releases a reference to @state which is freed after removing the
372 * final reference. No locking required and callable from any context.
374 static inline void drm_atomic_state_put(struct drm_atomic_state *state)
376 kref_put(&state->ref, __drm_atomic_state_free);
380 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
381 void drm_atomic_state_default_clear(struct drm_atomic_state *state);
382 void drm_atomic_state_default_release(struct drm_atomic_state *state);
384 struct drm_crtc_state * __must_check
385 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
386 struct drm_crtc *crtc);
387 int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
388 struct drm_crtc_state *state, struct drm_property *property,
390 struct drm_plane_state * __must_check
391 drm_atomic_get_plane_state(struct drm_atomic_state *state,
392 struct drm_plane *plane);
393 struct drm_connector_state * __must_check
394 drm_atomic_get_connector_state(struct drm_atomic_state *state,
395 struct drm_connector *connector);
397 void drm_atomic_private_obj_init(struct drm_private_obj *obj,
398 struct drm_private_state *state,
399 const struct drm_private_state_funcs *funcs);
400 void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
402 struct drm_private_state * __must_check
403 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
404 struct drm_private_obj *obj);
407 * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
408 * @state: global atomic state object
409 * @crtc: crtc to grab
411 * This function returns the crtc state for the given crtc, or NULL
412 * if the crtc is not part of the global atomic state.
414 * This function is deprecated, @drm_atomic_get_old_crtc_state or
415 * @drm_atomic_get_new_crtc_state should be used instead.
417 static inline struct drm_crtc_state *
418 drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
419 struct drm_crtc *crtc)
421 return state->crtcs[drm_crtc_index(crtc)].state;
425 * drm_atomic_get_old_crtc_state - get old crtc state, if it exists
426 * @state: global atomic state object
427 * @crtc: crtc to grab
429 * This function returns the old crtc state for the given crtc, or
430 * NULL if the crtc is not part of the global atomic state.
432 static inline struct drm_crtc_state *
433 drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
434 struct drm_crtc *crtc)
436 return state->crtcs[drm_crtc_index(crtc)].old_state;
439 * drm_atomic_get_new_crtc_state - get new crtc state, if it exists
440 * @state: global atomic state object
441 * @crtc: crtc to grab
443 * This function returns the new crtc state for the given crtc, or
444 * NULL if the crtc is not part of the global atomic state.
446 static inline struct drm_crtc_state *
447 drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
448 struct drm_crtc *crtc)
450 return state->crtcs[drm_crtc_index(crtc)].new_state;
454 * drm_atomic_get_existing_plane_state - get plane state, if it exists
455 * @state: global atomic state object
456 * @plane: plane to grab
458 * This function returns the plane state for the given plane, or NULL
459 * if the plane is not part of the global atomic state.
461 * This function is deprecated, @drm_atomic_get_old_plane_state or
462 * @drm_atomic_get_new_plane_state should be used instead.
464 static inline struct drm_plane_state *
465 drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
466 struct drm_plane *plane)
468 return state->planes[drm_plane_index(plane)].state;
472 * drm_atomic_get_old_plane_state - get plane state, if it exists
473 * @state: global atomic state object
474 * @plane: plane to grab
476 * This function returns the old plane state for the given plane, or
477 * NULL if the plane is not part of the global atomic state.
479 static inline struct drm_plane_state *
480 drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
481 struct drm_plane *plane)
483 return state->planes[drm_plane_index(plane)].old_state;
487 * drm_atomic_get_new_plane_state - get plane state, if it exists
488 * @state: global atomic state object
489 * @plane: plane to grab
491 * This function returns the new plane state for the given plane, or
492 * NULL if the plane is not part of the global atomic state.
494 static inline struct drm_plane_state *
495 drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
496 struct drm_plane *plane)
498 return state->planes[drm_plane_index(plane)].new_state;
502 * drm_atomic_get_existing_connector_state - get connector state, if it exists
503 * @state: global atomic state object
504 * @connector: connector to grab
506 * This function returns the connector state for the given connector,
507 * or NULL if the connector is not part of the global atomic state.
509 * This function is deprecated, @drm_atomic_get_old_connector_state or
510 * @drm_atomic_get_new_connector_state should be used instead.
512 static inline struct drm_connector_state *
513 drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
514 struct drm_connector *connector)
516 int index = drm_connector_index(connector);
518 if (index >= state->num_connector)
521 return state->connectors[index].state;
525 * drm_atomic_get_old_connector_state - get connector state, if it exists
526 * @state: global atomic state object
527 * @connector: connector to grab
529 * This function returns the old connector state for the given connector,
530 * or NULL if the connector is not part of the global atomic state.
532 static inline struct drm_connector_state *
533 drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
534 struct drm_connector *connector)
536 int index = drm_connector_index(connector);
538 if (index >= state->num_connector)
541 return state->connectors[index].old_state;
545 * drm_atomic_get_new_connector_state - get connector state, if it exists
546 * @state: global atomic state object
547 * @connector: connector to grab
549 * This function returns the new connector state for the given connector,
550 * or NULL if the connector is not part of the global atomic state.
552 static inline struct drm_connector_state *
553 drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
554 struct drm_connector *connector)
556 int index = drm_connector_index(connector);
558 if (index >= state->num_connector)
561 return state->connectors[index].new_state;
565 * __drm_atomic_get_current_plane_state - get current plane state
566 * @state: global atomic state object
567 * @plane: plane to grab
569 * This function returns the plane state for the given plane, either from
570 * @state, or if the plane isn't part of the atomic state update, from @plane.
571 * This is useful in atomic check callbacks, when drivers need to peek at, but
572 * not change, state of other planes, since it avoids threading an error code
573 * back up the call chain.
577 * Note that this function is in general unsafe since it doesn't check for the
578 * required locking for access state structures. Drivers must ensure that it is
579 * safe to access the returned state structure through other means. One common
580 * example is when planes are fixed to a single CRTC, and the driver knows that
581 * the CRTC lock is held already. In that case holding the CRTC lock gives a
582 * read-lock on all planes connected to that CRTC. But if planes can be
583 * reassigned things get more tricky. In that case it's better to use
584 * drm_atomic_get_plane_state and wire up full error handling.
588 * Read-only pointer to the current plane state.
590 static inline const struct drm_plane_state *
591 __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
592 struct drm_plane *plane)
594 if (state->planes[drm_plane_index(plane)].state)
595 return state->planes[drm_plane_index(plane)].state;
601 drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
602 const struct drm_display_mode *mode);
604 drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
605 struct drm_property_blob *blob);
607 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
608 struct drm_crtc *crtc);
609 void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
610 struct drm_framebuffer *fb);
611 void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
612 struct dma_fence *fence);
614 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
615 struct drm_crtc *crtc);
616 int drm_atomic_set_writeback_fb_for_connector(
617 struct drm_connector_state *conn_state,
618 struct drm_framebuffer *fb);
620 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
621 struct drm_crtc *crtc);
623 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
624 struct drm_crtc *crtc);
626 int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
627 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
628 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
630 void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
633 * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
634 * @__state: &struct drm_atomic_state pointer
635 * @connector: &struct drm_connector iteration cursor
636 * @old_connector_state: &struct drm_connector_state iteration cursor for the
638 * @new_connector_state: &struct drm_connector_state iteration cursor for the
640 * @__i: int iteration cursor, for macro-internal use
642 * This iterates over all connectors in an atomic update, tracking both old and
643 * new state. This is useful in places where the state delta needs to be
644 * considered, for example in atomic check functions.
646 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
648 (__i) < (__state)->num_connector; \
650 for_each_if ((__state)->connectors[__i].ptr && \
651 ((connector) = (__state)->connectors[__i].ptr, \
652 (old_connector_state) = (__state)->connectors[__i].old_state, \
653 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
656 * for_each_old_connector_in_state - iterate over all connectors in an atomic update
657 * @__state: &struct drm_atomic_state pointer
658 * @connector: &struct drm_connector iteration cursor
659 * @old_connector_state: &struct drm_connector_state iteration cursor for the
661 * @__i: int iteration cursor, for macro-internal use
663 * This iterates over all connectors in an atomic update, tracking only the old
664 * state. This is useful in disable functions, where we need the old state the
665 * hardware is still in.
667 #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
669 (__i) < (__state)->num_connector; \
671 for_each_if ((__state)->connectors[__i].ptr && \
672 ((connector) = (__state)->connectors[__i].ptr, \
673 (old_connector_state) = (__state)->connectors[__i].old_state, 1))
676 * for_each_new_connector_in_state - iterate over all connectors in an atomic update
677 * @__state: &struct drm_atomic_state pointer
678 * @connector: &struct drm_connector iteration cursor
679 * @new_connector_state: &struct drm_connector_state iteration cursor for the
681 * @__i: int iteration cursor, for macro-internal use
683 * This iterates over all connectors in an atomic update, tracking only the new
684 * state. This is useful in enable functions, where we need the new state the
685 * hardware should be in when the atomic commit operation has completed.
687 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
689 (__i) < (__state)->num_connector; \
691 for_each_if ((__state)->connectors[__i].ptr && \
692 ((connector) = (__state)->connectors[__i].ptr, \
693 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
696 * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
697 * @__state: &struct drm_atomic_state pointer
698 * @crtc: &struct drm_crtc iteration cursor
699 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
700 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
701 * @__i: int iteration cursor, for macro-internal use
703 * This iterates over all CRTCs in an atomic update, tracking both old and
704 * new state. This is useful in places where the state delta needs to be
705 * considered, for example in atomic check functions.
707 #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
709 (__i) < (__state)->dev->mode_config.num_crtc; \
711 for_each_if ((__state)->crtcs[__i].ptr && \
712 ((crtc) = (__state)->crtcs[__i].ptr, \
713 (old_crtc_state) = (__state)->crtcs[__i].old_state, \
714 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
717 * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
718 * @__state: &struct drm_atomic_state pointer
719 * @crtc: &struct drm_crtc iteration cursor
720 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
721 * @__i: int iteration cursor, for macro-internal use
723 * This iterates over all CRTCs in an atomic update, tracking only the old
724 * state. This is useful in disable functions, where we need the old state the
725 * hardware is still in.
727 #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
729 (__i) < (__state)->dev->mode_config.num_crtc; \
731 for_each_if ((__state)->crtcs[__i].ptr && \
732 ((crtc) = (__state)->crtcs[__i].ptr, \
733 (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
736 * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
737 * @__state: &struct drm_atomic_state pointer
738 * @crtc: &struct drm_crtc iteration cursor
739 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
740 * @__i: int iteration cursor, for macro-internal use
742 * This iterates over all CRTCs in an atomic update, tracking only the new
743 * state. This is useful in enable functions, where we need the new state the
744 * hardware should be in when the atomic commit operation has completed.
746 #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
748 (__i) < (__state)->dev->mode_config.num_crtc; \
750 for_each_if ((__state)->crtcs[__i].ptr && \
751 ((crtc) = (__state)->crtcs[__i].ptr, \
752 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
755 * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
756 * @__state: &struct drm_atomic_state pointer
757 * @plane: &struct drm_plane iteration cursor
758 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
759 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
760 * @__i: int iteration cursor, for macro-internal use
762 * This iterates over all planes in an atomic update, tracking both old and
763 * new state. This is useful in places where the state delta needs to be
764 * considered, for example in atomic check functions.
766 #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
768 (__i) < (__state)->dev->mode_config.num_total_plane; \
770 for_each_if ((__state)->planes[__i].ptr && \
771 ((plane) = (__state)->planes[__i].ptr, \
772 (old_plane_state) = (__state)->planes[__i].old_state,\
773 (new_plane_state) = (__state)->planes[__i].new_state, 1))
776 * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic
777 * update in reverse order
778 * @__state: &struct drm_atomic_state pointer
779 * @plane: &struct drm_plane iteration cursor
780 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
781 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
782 * @__i: int iteration cursor, for macro-internal use
784 * This iterates over all planes in an atomic update in reverse order,
785 * tracking both old and new state. This is useful in places where the
786 * state delta needs to be considered, for example in atomic check functions.
788 #define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \
789 for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
792 for_each_if ((__state)->planes[__i].ptr && \
793 ((plane) = (__state)->planes[__i].ptr, \
794 (old_plane_state) = (__state)->planes[__i].old_state,\
795 (new_plane_state) = (__state)->planes[__i].new_state, 1))
798 * for_each_old_plane_in_state - iterate over all planes in an atomic update
799 * @__state: &struct drm_atomic_state pointer
800 * @plane: &struct drm_plane iteration cursor
801 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
802 * @__i: int iteration cursor, for macro-internal use
804 * This iterates over all planes in an atomic update, tracking only the old
805 * state. This is useful in disable functions, where we need the old state the
806 * hardware is still in.
808 #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
810 (__i) < (__state)->dev->mode_config.num_total_plane; \
812 for_each_if ((__state)->planes[__i].ptr && \
813 ((plane) = (__state)->planes[__i].ptr, \
814 (old_plane_state) = (__state)->planes[__i].old_state, 1))
816 * for_each_new_plane_in_state - iterate over all planes in an atomic update
817 * @__state: &struct drm_atomic_state pointer
818 * @plane: &struct drm_plane iteration cursor
819 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
820 * @__i: int iteration cursor, for macro-internal use
822 * This iterates over all planes in an atomic update, tracking only the new
823 * state. This is useful in enable functions, where we need the new state the
824 * hardware should be in when the atomic commit operation has completed.
826 #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
828 (__i) < (__state)->dev->mode_config.num_total_plane; \
830 for_each_if ((__state)->planes[__i].ptr && \
831 ((plane) = (__state)->planes[__i].ptr, \
832 (new_plane_state) = (__state)->planes[__i].new_state, 1))
835 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
836 * @__state: &struct drm_atomic_state pointer
837 * @obj: &struct drm_private_obj iteration cursor
838 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
839 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
840 * @__i: int iteration cursor, for macro-internal use
842 * This iterates over all private objects in an atomic update, tracking both
843 * old and new state. This is useful in places where the state delta needs
844 * to be considered, for example in atomic check functions.
846 #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
848 (__i) < (__state)->num_private_objs && \
849 ((obj) = (__state)->private_objs[__i].ptr, \
850 (old_obj_state) = (__state)->private_objs[__i].old_state, \
851 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
855 * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
856 * @__state: &struct drm_atomic_state pointer
857 * @obj: &struct drm_private_obj iteration cursor
858 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
859 * @__i: int iteration cursor, for macro-internal use
861 * This iterates over all private objects in an atomic update, tracking only
862 * the old state. This is useful in disable functions, where we need the old
863 * state the hardware is still in.
865 #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
867 (__i) < (__state)->num_private_objs && \
868 ((obj) = (__state)->private_objs[__i].ptr, \
869 (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
873 * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
874 * @__state: &struct drm_atomic_state pointer
875 * @obj: &struct drm_private_obj iteration cursor
876 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
877 * @__i: int iteration cursor, for macro-internal use
879 * This iterates over all private objects in an atomic update, tracking only
880 * the new state. This is useful in enable functions, where we need the new state the
881 * hardware should be in when the atomic commit operation has completed.
883 #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
885 (__i) < (__state)->num_private_objs && \
886 ((obj) = (__state)->private_objs[__i].ptr, \
887 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
891 * drm_atomic_crtc_needs_modeset - compute combined modeset need
892 * @state: &drm_crtc_state for the CRTC
894 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
895 * whether the state CRTC changed enough to need a full modeset cycle:
896 * mode_changed, active_changed and connectors_changed. This helper simply
897 * combines these three to compute the overall need for a modeset for @state.
899 * The atomic helper code sets these booleans, but drivers can and should
900 * change them appropriately to accurately represent whether a modeset is
901 * really needed. In general, drivers should avoid full modesets whenever
904 * For example if the CRTC mode has changed, and the hardware is able to enact
905 * the requested mode change without going through a full modeset, the driver
906 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
910 drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
912 return state->mode_changed || state->active_changed ||
913 state->connectors_changed;
916 #endif /* DRM_ATOMIC_H_ */