xref: /linux/include/drm/drm_atomic.h (revision 815e260a18a3af4dab59025ee99a7156c0e8b5e0)
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 <robdclark@gmail.com>
25  * Daniel Vetter <daniel.vetter@ffwll.ch>
26  */
27 
28 #ifndef DRM_ATOMIC_H_
29 #define DRM_ATOMIC_H_
30 
31 #include <drm/drm_crtc.h>
32 #include <drm/drm_util.h>
33 
34 /**
35  * struct drm_crtc_commit - track modeset commits on a CRTC
36  *
37  * This structure is used to track pending modeset changes and atomic commit on
38  * a per-CRTC basis. Since updating the list should never block, this structure
39  * is reference counted to allow waiters to safely wait on an event to complete,
40  * without holding any locks.
41  *
42  * It has 3 different events in total to allow a fine-grained synchronization
43  * between outstanding updates::
44  *
45  *	atomic commit thread			hardware
46  *
47  * 	write new state into hardware	---->	...
48  * 	signal hw_done
49  * 						switch to new state on next
50  * 	...					v/hblank
51  *
52  *	wait for buffers to show up		...
53  *
54  *	...					send completion irq
55  *						irq handler signals flip_done
56  *	cleanup old buffers
57  *
58  * 	signal cleanup_done
59  *
60  * 	wait for flip_done		<----
61  * 	clean up atomic state
62  *
63  * The important bit to know is that &cleanup_done is the terminal event, but the
64  * ordering between &flip_done and &hw_done is entirely up to the specific driver
65  * and modeset state change.
66  *
67  * For an implementation of how to use this look at
68  * drm_atomic_helper_setup_commit() from the atomic helper library.
69  *
70  * See also drm_crtc_commit_wait().
71  */
72 struct drm_crtc_commit {
73 	/**
74 	 * @crtc:
75 	 *
76 	 * DRM CRTC for this commit.
77 	 */
78 	struct drm_crtc *crtc;
79 
80 	/**
81 	 * @ref:
82 	 *
83 	 * Reference count for this structure. Needed to allow blocking on
84 	 * completions without the risk of the completion disappearing
85 	 * meanwhile.
86 	 */
87 	struct kref ref;
88 
89 	/**
90 	 * @flip_done:
91 	 *
92 	 * Will be signaled when the hardware has flipped to the new set of
93 	 * buffers. Signals at the same time as when the drm event for this
94 	 * commit is sent to userspace, or when an out-fence is singalled. Note
95 	 * that for most hardware, in most cases this happens after @hw_done is
96 	 * signalled.
97 	 *
98 	 * Completion of this stage is signalled implicitly by calling
99 	 * drm_crtc_send_vblank_event() on &drm_crtc_state.event.
100 	 */
101 	struct completion flip_done;
102 
103 	/**
104 	 * @hw_done:
105 	 *
106 	 * Will be signalled when all hw register changes for this commit have
107 	 * been written out. Especially when disabling a pipe this can be much
108 	 * later than @flip_done, since that can signal already when the
109 	 * screen goes black, whereas to fully shut down a pipe more register
110 	 * I/O is required.
111 	 *
112 	 * Note that this does not need to include separately reference-counted
113 	 * resources like backing storage buffer pinning, or runtime pm
114 	 * management.
115 	 *
116 	 * Drivers should call drm_atomic_helper_commit_hw_done() to signal
117 	 * completion of this stage.
118 	 */
119 	struct completion hw_done;
120 
121 	/**
122 	 * @cleanup_done:
123 	 *
124 	 * Will be signalled after old buffers have been cleaned up by calling
125 	 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
126 	 * a vblank wait completed it might be a bit later. This completion is
127 	 * useful to throttle updates and avoid hardware updates getting ahead
128 	 * of the buffer cleanup too much.
129 	 *
130 	 * Drivers should call drm_atomic_helper_commit_cleanup_done() to signal
131 	 * completion of this stage.
132 	 */
133 	struct completion cleanup_done;
134 
135 	/**
136 	 * @commit_entry:
137 	 *
138 	 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
139 	 * $drm_crtc.commit_lock.
140 	 */
141 	struct list_head commit_entry;
142 
143 	/**
144 	 * @event:
145 	 *
146 	 * &drm_pending_vblank_event pointer to clean up private events.
147 	 */
148 	struct drm_pending_vblank_event *event;
149 
150 	/**
151 	 * @abort_completion:
152 	 *
153 	 * A flag that's set after drm_atomic_helper_setup_commit() takes a
154 	 * second reference for the completion of $drm_crtc_state.event. It's
155 	 * used by the free code to remove the second reference if commit fails.
156 	 */
157 	bool abort_completion;
158 };
159 
160 struct __drm_planes_state {
161 	struct drm_plane *ptr;
162 
163 	/**
164 	 * @state_to_destroy:
165 	 *
166 	 * Used to track the @drm_plane_state we will need to free when
167 	 * tearing down the associated &drm_atomic_state in
168 	 * $drm_mode_config_funcs.atomic_state_clear or
169 	 * drm_atomic_state_default_clear().
170 	 *
171 	 * Before a commit, and the call to
172 	 * drm_atomic_helper_swap_state() in particular, it points to
173 	 * the same state than @new_state. After a commit, it points to
174 	 * the same state than @old_state.
175 	 */
176 	struct drm_plane_state *state_to_destroy;
177 
178 	struct drm_plane_state *old_state, *new_state;
179 };
180 
181 struct __drm_crtcs_state {
182 	struct drm_crtc *ptr;
183 
184 	/**
185 	 * @state_to_destroy:
186 	 *
187 	 * Used to track the @drm_crtc_state we will need to free when
188 	 * tearing down the associated &drm_atomic_state in
189 	 * $drm_mode_config_funcs.atomic_state_clear or
190 	 * drm_atomic_state_default_clear().
191 	 *
192 	 * Before a commit, and the call to
193 	 * drm_atomic_helper_swap_state() in particular, it points to
194 	 * the same state than @new_state. After a commit, it points to
195 	 * the same state than @old_state.
196 	 */
197 	struct drm_crtc_state *state_to_destroy;
198 
199 	struct drm_crtc_state *old_state, *new_state;
200 
201 	/**
202 	 * @commit:
203 	 *
204 	 * A reference to the CRTC commit object that is kept for use by
205 	 * drm_atomic_helper_wait_for_flip_done() after
206 	 * drm_atomic_helper_commit_hw_done() is called. This ensures that a
207 	 * concurrent commit won't free a commit object that is still in use.
208 	 */
209 	struct drm_crtc_commit *commit;
210 
211 	s32 __user *out_fence_ptr;
212 	u64 last_vblank_count;
213 };
214 
215 struct __drm_connnectors_state {
216 	struct drm_connector *ptr;
217 
218 	/**
219 	 * @state_to_destroy:
220 	 *
221 	 * Used to track the @drm_connector_state we will need to free
222 	 * when tearing down the associated &drm_atomic_state in
223 	 * $drm_mode_config_funcs.atomic_state_clear or
224 	 * drm_atomic_state_default_clear().
225 	 *
226 	 * Before a commit, and the call to
227 	 * drm_atomic_helper_swap_state() in particular, it points to
228 	 * the same state than @new_state. After a commit, it points to
229 	 * the same state than @old_state.
230 	 */
231 	struct drm_connector_state *state_to_destroy;
232 
233 	struct drm_connector_state *old_state, *new_state;
234 
235 	/**
236 	 * @out_fence_ptr:
237 	 *
238 	 * User-provided pointer which the kernel uses to return a sync_file
239 	 * file descriptor. Used by writeback connectors to signal completion of
240 	 * the writeback.
241 	 */
242 	s32 __user *out_fence_ptr;
243 };
244 
245 struct drm_private_obj;
246 struct drm_private_state;
247 
248 /**
249  * struct drm_private_state_funcs - atomic state functions for private objects
250  *
251  * These hooks are used by atomic helpers to create, swap and destroy states of
252  * private objects. The structure itself is used as a vtable to identify the
253  * associated private object type. Each private object type that needs to be
254  * added to the atomic states is expected to have an implementation of these
255  * hooks and pass a pointer to its drm_private_state_funcs struct to
256  * drm_atomic_get_private_obj_state().
257  */
258 struct drm_private_state_funcs {
259 	/**
260 	 * @atomic_duplicate_state:
261 	 *
262 	 * Duplicate the current state of the private object and return it. It
263 	 * is an error to call this before obj->state has been initialized.
264 	 *
265 	 * RETURNS:
266 	 *
267 	 * Duplicated atomic state or NULL when obj->state is not
268 	 * initialized or allocation failed.
269 	 */
270 	struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
271 
272 	/**
273 	 * @atomic_destroy_state:
274 	 *
275 	 * Frees the private object state created with @atomic_duplicate_state.
276 	 */
277 	void (*atomic_destroy_state)(struct drm_private_obj *obj,
278 				     struct drm_private_state *state);
279 
280 	/**
281 	 * @atomic_print_state:
282 	 *
283 	 * If driver subclasses &struct drm_private_state, it should implement
284 	 * this optional hook for printing additional driver specific state.
285 	 *
286 	 * Do not call this directly, use drm_atomic_private_obj_print_state()
287 	 * instead.
288 	 */
289 	void (*atomic_print_state)(struct drm_printer *p,
290 				   const struct drm_private_state *state);
291 };
292 
293 /**
294  * struct drm_private_obj - base struct for driver private atomic object
295  *
296  * A driver private object is initialized by calling
297  * drm_atomic_private_obj_init() and cleaned up by calling
298  * drm_atomic_private_obj_fini().
299  *
300  * Currently only tracks the state update functions and the opaque driver
301  * private state itself, but in the future might also track which
302  * &drm_modeset_lock is required to duplicate and update this object's state.
303  *
304  * All private objects must be initialized before the DRM device they are
305  * attached to is registered to the DRM subsystem (call to drm_dev_register())
306  * and should stay around until this DRM device is unregistered (call to
307  * drm_dev_unregister()). In other words, private objects lifetime is tied
308  * to the DRM device lifetime. This implies that:
309  *
310  * 1/ all calls to drm_atomic_private_obj_init() must be done before calling
311  *    drm_dev_register()
312  * 2/ all calls to drm_atomic_private_obj_fini() must be done after calling
313  *    drm_dev_unregister()
314  *
315  * If that private object is used to store a state shared by multiple
316  * CRTCs, proper care must be taken to ensure that non-blocking commits are
317  * properly ordered to avoid a use-after-free issue.
318  *
319  * Indeed, assuming a sequence of two non-blocking &drm_atomic_commit on two
320  * different &drm_crtc using different &drm_plane and &drm_connector, so with no
321  * resources shared, there's no guarantee on which commit is going to happen
322  * first. However, the second &drm_atomic_commit will consider the first
323  * &drm_private_obj its old state, and will be in charge of freeing it whenever
324  * the second &drm_atomic_commit is done.
325  *
326  * If the first &drm_atomic_commit happens after it, it will consider its
327  * &drm_private_obj the new state and will be likely to access it, resulting in
328  * an access to a freed memory region. Drivers should store (and get a reference
329  * to) the &drm_crtc_commit structure in our private state in
330  * &drm_mode_config_helper_funcs.atomic_commit_setup, and then wait for that
331  * commit to complete as the first step of
332  * &drm_mode_config_helper_funcs.atomic_commit_tail, similar to
333  * drm_atomic_helper_wait_for_dependencies().
334  */
335 struct drm_private_obj {
336 	/**
337 	 * @head: List entry used to attach a private object to a &drm_device
338 	 * (queued to &drm_mode_config.privobj_list).
339 	 */
340 	struct list_head head;
341 
342 	/**
343 	 * @lock: Modeset lock to protect the state object.
344 	 */
345 	struct drm_modeset_lock lock;
346 
347 	/**
348 	 * @state: Current atomic state for this driver private object.
349 	 */
350 	struct drm_private_state *state;
351 
352 	/**
353 	 * @funcs:
354 	 *
355 	 * Functions to manipulate the state of this driver private object, see
356 	 * &drm_private_state_funcs.
357 	 */
358 	const struct drm_private_state_funcs *funcs;
359 };
360 
361 /**
362  * drm_for_each_privobj() - private object iterator
363  *
364  * @privobj: pointer to the current private object. Updated after each
365  *	     iteration
366  * @dev: the DRM device we want get private objects from
367  *
368  * Allows one to iterate over all private objects attached to @dev
369  */
370 #define drm_for_each_privobj(privobj, dev) \
371 	list_for_each_entry(privobj, &(dev)->mode_config.privobj_list, head)
372 
373 /**
374  * struct drm_private_state - base struct for driver private object state
375  *
376  * Currently only contains a backpointer to the overall atomic update,
377  * and the relevant private object but in the future also might hold
378  * synchronization information similar to e.g. &drm_crtc.commit.
379  */
380 struct drm_private_state {
381 	/**
382 	 * @state: backpointer to global drm_atomic_state
383 	 */
384 	struct drm_atomic_state *state;
385 
386 	/**
387 	 * @obj: backpointer to the private object
388 	 */
389 	struct drm_private_obj *obj;
390 };
391 
392 struct __drm_private_objs_state {
393 	struct drm_private_obj *ptr;
394 
395 	/**
396 	 * @state_to_destroy:
397 	 *
398 	 * Used to track the @drm_private_state we will need to free
399 	 * when tearing down the associated &drm_atomic_state in
400 	 * $drm_mode_config_funcs.atomic_state_clear or
401 	 * drm_atomic_state_default_clear().
402 	 *
403 	 * Before a commit, and the call to
404 	 * drm_atomic_helper_swap_state() in particular, it points to
405 	 * the same state than @new_state. After a commit, it points to
406 	 * the same state than @old_state.
407 	 */
408 	struct drm_private_state *state_to_destroy;
409 
410 	struct drm_private_state *old_state, *new_state;
411 };
412 
413 /**
414  * struct drm_atomic_state - Atomic commit structure
415  *
416  * This structure is the kernel counterpart of @drm_mode_atomic and represents
417  * an atomic commit that transitions from an old to a new display state. It
418  * contains all the objects affected by the atomic commit and both the new
419  * state structures and pointers to the old state structures for
420  * these.
421  *
422  * States are added to an atomic update by calling drm_atomic_get_crtc_state(),
423  * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for
424  * private state structures, drm_atomic_get_private_obj_state().
425  *
426  * NOTE: struct drm_atomic_state first started as a single collection of
427  * entities state pointers (drm_plane_state, drm_crtc_state, etc.).
428  *
429  * At atomic_check time, you could get the state about to be committed
430  * from drm_atomic_state, and the one currently running from the
431  * entities state pointer (drm_crtc.state, for example). After the call
432  * to drm_atomic_helper_swap_state(), the entities state pointer would
433  * contain the state previously checked, and the drm_atomic_state
434  * structure the old state.
435  *
436  * Over time, and in order to avoid confusion, drm_atomic_state has
437  * grown to have both the old state (ie, the state we replace) and the
438  * new state (ie, the state we want to apply). Those names are stable
439  * during the commit process, which makes it easier to reason about.
440  *
441  * You can still find some traces of that evolution through some hooks
442  * or callbacks taking a drm_atomic_state parameter called names like
443  * "old_state". This doesn't necessarily mean that the previous
444  * drm_atomic_state is passed, but rather that this used to be the state
445  * collection we were replacing after drm_atomic_helper_swap_state(),
446  * but the variable name was never updated.
447  *
448  * Some atomic operations implementations followed a similar process. We
449  * first started to pass the entity state only. However, it was pretty
450  * cumbersome for drivers, and especially CRTCs, to retrieve the states
451  * of other components. Thus, we switched to passing the whole
452  * drm_atomic_state as a parameter to those operations. Similarly, the
453  * transition isn't complete yet, and one might still find atomic
454  * operations taking a drm_atomic_state pointer, or a component state
455  * pointer. The former is the preferred form.
456  */
457 struct drm_atomic_state {
458 	/**
459 	 * @ref:
460 	 *
461 	 * Count of all references to this update (will not be freed until zero).
462 	 */
463 	struct kref ref;
464 
465 	/**
466 	 * @dev: Parent DRM Device.
467 	 */
468 	struct drm_device *dev;
469 
470 	/**
471 	 * @allow_modeset:
472 	 *
473 	 * Allow full modeset. This is used by the ATOMIC IOCTL handler to
474 	 * implement the DRM_MODE_ATOMIC_ALLOW_MODESET flag. Drivers should
475 	 * generally not consult this flag, but instead look at the output of
476 	 * drm_atomic_crtc_needs_modeset(). The detailed rules are:
477 	 *
478 	 * - Drivers must not consult @allow_modeset in the atomic commit path.
479 	 *   Use drm_atomic_crtc_needs_modeset() instead.
480 	 *
481 	 * - Drivers must consult @allow_modeset before adding unrelated struct
482 	 *   drm_crtc_state to this commit by calling
483 	 *   drm_atomic_get_crtc_state(). See also the warning in the
484 	 *   documentation for that function.
485 	 *
486 	 * - Drivers must never change this flag, it is under the exclusive
487 	 *   control of userspace.
488 	 *
489 	 * - Drivers may consult @allow_modeset in the atomic check path, if
490 	 *   they have the choice between an optimal hardware configuration
491 	 *   which requires a modeset, and a less optimal configuration which
492 	 *   can be committed without a modeset. An example would be suboptimal
493 	 *   scanout FIFO allocation resulting in increased idle power
494 	 *   consumption. This allows userspace to avoid flickering and delays
495 	 *   for the normal composition loop at reasonable cost.
496 	 */
497 	bool allow_modeset : 1;
498 	/**
499 	 * @legacy_cursor_update:
500 	 *
501 	 * Hint to enforce legacy cursor IOCTL semantics.
502 	 *
503 	 * WARNING: This is thoroughly broken and pretty much impossible to
504 	 * implement correctly. Drivers must ignore this and should instead
505 	 * implement &drm_plane_helper_funcs.atomic_async_check and
506 	 * &drm_plane_helper_funcs.atomic_async_commit hooks. New users of this
507 	 * flag are not allowed.
508 	 */
509 	bool legacy_cursor_update : 1;
510 
511 	/**
512 	 * @async_update: hint for asynchronous plane update
513 	 */
514 	bool async_update : 1;
515 
516 	/**
517 	 * @duplicated:
518 	 *
519 	 * Indicates whether or not this atomic state was duplicated using
520 	 * drm_atomic_helper_duplicate_state(). Drivers and atomic helpers
521 	 * should use this to fixup normal  inconsistencies in duplicated
522 	 * states.
523 	 */
524 	bool duplicated : 1;
525 
526 	/**
527 	 * @checked:
528 	 *
529 	 * Indicates the state has been checked and thus must no longer
530 	 * be mutated. For internal use only, do not consult from drivers.
531 	 */
532 	bool checked : 1;
533 
534 	/**
535 	 * @planes:
536 	 *
537 	 * Pointer to array of @drm_plane and @drm_plane_state part of this
538 	 * update.
539 	 */
540 	struct __drm_planes_state *planes;
541 
542 	/**
543 	 * @crtcs:
544 	 *
545 	 * Pointer to array of @drm_crtc and @drm_crtc_state part of this
546 	 * update.
547 	 */
548 	struct __drm_crtcs_state *crtcs;
549 
550 	/**
551 	 * @num_connector: size of the @connectors array
552 	 */
553 	int num_connector;
554 
555 	/**
556 	 * @connectors:
557 	 *
558 	 * Pointer to array of @drm_connector and @drm_connector_state part of
559 	 * this update.
560 	 */
561 	struct __drm_connnectors_state *connectors;
562 
563 	/**
564 	 * @num_private_objs: size of the @private_objs array
565 	 */
566 	int num_private_objs;
567 
568 	/**
569 	 * @private_objs:
570 	 *
571 	 * Pointer to array of @drm_private_obj and @drm_private_obj_state part
572 	 * of this update.
573 	 */
574 	struct __drm_private_objs_state *private_objs;
575 
576 	/**
577 	 * @acquire_ctx: acquire context for this atomic modeset state update
578 	 */
579 	struct drm_modeset_acquire_ctx *acquire_ctx;
580 
581 	/**
582 	 * @fake_commit:
583 	 *
584 	 * Used for signaling unbound planes/connectors.
585 	 * When a connector or plane is not bound to any CRTC, it's still important
586 	 * to preserve linearity to prevent the atomic states from being freed too early.
587 	 *
588 	 * This commit (if set) is not bound to any CRTC, but will be completed when
589 	 * drm_atomic_helper_commit_hw_done() is called.
590 	 */
591 	struct drm_crtc_commit *fake_commit;
592 
593 	/**
594 	 * @commit_work:
595 	 *
596 	 * Work item which can be used by the driver or helpers to execute the
597 	 * commit without blocking.
598 	 */
599 	struct work_struct commit_work;
600 };
601 
602 void __drm_crtc_commit_free(struct kref *kref);
603 
604 /**
605  * drm_crtc_commit_get - acquire a reference to the CRTC commit
606  * @commit: CRTC commit
607  *
608  * Increases the reference of @commit.
609  *
610  * Returns:
611  * The pointer to @commit, with reference increased.
612  */
613 static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
614 {
615 	kref_get(&commit->ref);
616 	return commit;
617 }
618 
619 /**
620  * drm_crtc_commit_put - release a reference to the CRTC commmit
621  * @commit: CRTC commit
622  *
623  * This releases a reference to @commit which is freed after removing the
624  * final reference. No locking required and callable from any context.
625  */
626 static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
627 {
628 	kref_put(&commit->ref, __drm_crtc_commit_free);
629 }
630 
631 int drm_crtc_commit_wait(struct drm_crtc_commit *commit);
632 
633 struct drm_atomic_state * __must_check
634 drm_atomic_state_alloc(struct drm_device *dev);
635 void drm_atomic_state_clear(struct drm_atomic_state *state);
636 
637 /**
638  * drm_atomic_state_get - acquire a reference to the atomic state
639  * @state: The atomic state
640  *
641  * Returns a new reference to the @state
642  */
643 static inline struct drm_atomic_state *
644 drm_atomic_state_get(struct drm_atomic_state *state)
645 {
646 	kref_get(&state->ref);
647 	return state;
648 }
649 
650 void __drm_atomic_state_free(struct kref *ref);
651 
652 /**
653  * drm_atomic_state_put - release a reference to the atomic state
654  * @state: The atomic state
655  *
656  * This releases a reference to @state which is freed after removing the
657  * final reference. No locking required and callable from any context.
658  */
659 static inline void drm_atomic_state_put(struct drm_atomic_state *state)
660 {
661 	kref_put(&state->ref, __drm_atomic_state_free);
662 }
663 
664 int  __must_check
665 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
666 void drm_atomic_state_default_clear(struct drm_atomic_state *state);
667 void drm_atomic_state_default_release(struct drm_atomic_state *state);
668 
669 struct drm_crtc_state * __must_check
670 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
671 			  struct drm_crtc *crtc);
672 struct drm_plane_state * __must_check
673 drm_atomic_get_plane_state(struct drm_atomic_state *state,
674 			   struct drm_plane *plane);
675 struct drm_connector_state * __must_check
676 drm_atomic_get_connector_state(struct drm_atomic_state *state,
677 			       struct drm_connector *connector);
678 
679 void drm_atomic_private_obj_init(struct drm_device *dev,
680 				 struct drm_private_obj *obj,
681 				 struct drm_private_state *state,
682 				 const struct drm_private_state_funcs *funcs);
683 void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
684 
685 struct drm_private_state * __must_check
686 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
687 				 struct drm_private_obj *obj);
688 struct drm_private_state *
689 drm_atomic_get_old_private_obj_state(const struct drm_atomic_state *state,
690 				     struct drm_private_obj *obj);
691 struct drm_private_state *
692 drm_atomic_get_new_private_obj_state(const struct drm_atomic_state *state,
693 				     struct drm_private_obj *obj);
694 
695 struct drm_connector *
696 drm_atomic_get_old_connector_for_encoder(const struct drm_atomic_state *state,
697 					 struct drm_encoder *encoder);
698 struct drm_connector *
699 drm_atomic_get_new_connector_for_encoder(const struct drm_atomic_state *state,
700 					 struct drm_encoder *encoder);
701 struct drm_connector *
702 drm_atomic_get_connector_for_encoder(const struct drm_encoder *encoder,
703 				     struct drm_modeset_acquire_ctx *ctx);
704 
705 struct drm_crtc *
706 drm_atomic_get_old_crtc_for_encoder(struct drm_atomic_state *state,
707 					 struct drm_encoder *encoder);
708 struct drm_crtc *
709 drm_atomic_get_new_crtc_for_encoder(struct drm_atomic_state *state,
710 					 struct drm_encoder *encoder);
711 
712 /**
713  * drm_atomic_get_old_crtc_state - get old CRTC state, if it exists
714  * @state: global atomic state object
715  * @crtc: CRTC to grab
716  *
717  * This function returns the old CRTC state for the given CRTC, or
718  * NULL if the CRTC is not part of the global atomic state.
719  */
720 static inline struct drm_crtc_state *
721 drm_atomic_get_old_crtc_state(const struct drm_atomic_state *state,
722 			      struct drm_crtc *crtc)
723 {
724 	return state->crtcs[drm_crtc_index(crtc)].old_state;
725 }
726 /**
727  * drm_atomic_get_new_crtc_state - get new CRTC state, if it exists
728  * @state: global atomic state object
729  * @crtc: CRTC to grab
730  *
731  * This function returns the new CRTC state for the given CRTC, or
732  * NULL if the CRTC is not part of the global atomic state.
733  */
734 static inline struct drm_crtc_state *
735 drm_atomic_get_new_crtc_state(const struct drm_atomic_state *state,
736 			      struct drm_crtc *crtc)
737 {
738 	return state->crtcs[drm_crtc_index(crtc)].new_state;
739 }
740 
741 /**
742  * drm_atomic_get_old_plane_state - get plane state, if it exists
743  * @state: global atomic state object
744  * @plane: plane to grab
745  *
746  * This function returns the old plane state for the given plane, or
747  * NULL if the plane is not part of the global atomic state.
748  */
749 static inline struct drm_plane_state *
750 drm_atomic_get_old_plane_state(const struct drm_atomic_state *state,
751 			       struct drm_plane *plane)
752 {
753 	return state->planes[drm_plane_index(plane)].old_state;
754 }
755 
756 /**
757  * drm_atomic_get_new_plane_state - get plane state, if it exists
758  * @state: global atomic state object
759  * @plane: plane to grab
760  *
761  * This function returns the new plane state for the given plane, or
762  * NULL if the plane is not part of the global atomic state.
763  */
764 static inline struct drm_plane_state *
765 drm_atomic_get_new_plane_state(const struct drm_atomic_state *state,
766 			       struct drm_plane *plane)
767 {
768 	return state->planes[drm_plane_index(plane)].new_state;
769 }
770 
771 /**
772  * drm_atomic_get_old_connector_state - get connector state, if it exists
773  * @state: global atomic state object
774  * @connector: connector to grab
775  *
776  * This function returns the old connector state for the given connector,
777  * or NULL if the connector is not part of the global atomic state.
778  */
779 static inline struct drm_connector_state *
780 drm_atomic_get_old_connector_state(const struct drm_atomic_state *state,
781 				   struct drm_connector *connector)
782 {
783 	int index = drm_connector_index(connector);
784 
785 	if (index >= state->num_connector)
786 		return NULL;
787 
788 	return state->connectors[index].old_state;
789 }
790 
791 /**
792  * drm_atomic_get_new_connector_state - get connector state, if it exists
793  * @state: global atomic state object
794  * @connector: connector to grab
795  *
796  * This function returns the new connector state for the given connector,
797  * or NULL if the connector is not part of the global atomic state.
798  */
799 static inline struct drm_connector_state *
800 drm_atomic_get_new_connector_state(const struct drm_atomic_state *state,
801 				   struct drm_connector *connector)
802 {
803 	int index = drm_connector_index(connector);
804 
805 	if (index >= state->num_connector)
806 		return NULL;
807 
808 	return state->connectors[index].new_state;
809 }
810 
811 /**
812  * __drm_atomic_get_current_plane_state - get current plane state
813  * @state: global atomic state object
814  * @plane: plane to grab
815  *
816  * This function returns the plane state for the given plane, either the
817  * new plane state from @state, or if the plane isn't part of the atomic
818  * state update, from @plane. This is useful in atomic check callbacks,
819  * when drivers need to peek at, but not change, state of other planes,
820  * since it avoids threading an error code back up the call chain.
821  *
822  * WARNING:
823  *
824  * Note that this function is in general unsafe since it doesn't check for the
825  * required locking for access state structures. Drivers must ensure that it is
826  * safe to access the returned state structure through other means. One common
827  * example is when planes are fixed to a single CRTC, and the driver knows that
828  * the CRTC lock is held already. In that case holding the CRTC lock gives a
829  * read-lock on all planes connected to that CRTC. But if planes can be
830  * reassigned things get more tricky. In that case it's better to use
831  * drm_atomic_get_plane_state and wire up full error handling.
832  *
833  * Returns:
834  *
835  * Read-only pointer to the current plane state.
836  */
837 static inline const struct drm_plane_state *
838 __drm_atomic_get_current_plane_state(const struct drm_atomic_state *state,
839 				     struct drm_plane *plane)
840 {
841 	struct drm_plane_state *plane_state;
842 
843 	plane_state = drm_atomic_get_new_plane_state(state, plane);
844 	if (plane_state)
845 		return plane_state;
846 
847 	/*
848 	 * If the plane isn't part of the state, fallback to the currently active one.
849 	 */
850 	return plane->state;
851 }
852 
853 int __must_check
854 drm_atomic_add_encoder_bridges(struct drm_atomic_state *state,
855 			       struct drm_encoder *encoder);
856 int __must_check
857 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
858 				   struct drm_crtc *crtc);
859 int __must_check
860 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
861 			       struct drm_crtc *crtc);
862 
863 int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
864 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
865 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
866 
867 void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
868 
869 /**
870  * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
871  * @__state: &struct drm_atomic_state pointer
872  * @connector: &struct drm_connector iteration cursor
873  * @old_connector_state: &struct drm_connector_state iteration cursor for the
874  * 	old state
875  * @new_connector_state: &struct drm_connector_state iteration cursor for the
876  * 	new state
877  * @__i: int iteration cursor, for macro-internal use
878  *
879  * This iterates over all connectors in an atomic update, tracking both old and
880  * new state. This is useful in places where the state delta needs to be
881  * considered, for example in atomic check functions.
882  */
883 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
884 	for ((__i) = 0;								\
885 	     (__i) < (__state)->num_connector;					\
886 	     (__i)++)								\
887 		for_each_if ((__state)->connectors[__i].ptr &&			\
888 			     ((connector) = (__state)->connectors[__i].ptr,	\
889 			     (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
890 			     (old_connector_state) = (__state)->connectors[__i].old_state,	\
891 			     (new_connector_state) = (__state)->connectors[__i].new_state, 1))
892 
893 /**
894  * for_each_old_connector_in_state - iterate over all connectors in an atomic update
895  * @__state: &struct drm_atomic_state pointer
896  * @connector: &struct drm_connector iteration cursor
897  * @old_connector_state: &struct drm_connector_state iteration cursor for the
898  * 	old state
899  * @__i: int iteration cursor, for macro-internal use
900  *
901  * This iterates over all connectors in an atomic update, tracking only the old
902  * state. This is useful in disable functions, where we need the old state the
903  * hardware is still in.
904  */
905 #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
906 	for ((__i) = 0;								\
907 	     (__i) < (__state)->num_connector;					\
908 	     (__i)++)								\
909 		for_each_if ((__state)->connectors[__i].ptr &&			\
910 			     ((connector) = (__state)->connectors[__i].ptr,	\
911 			     (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
912 			     (old_connector_state) = (__state)->connectors[__i].old_state, 1))
913 
914 /**
915  * for_each_new_connector_in_state - iterate over all connectors in an atomic update
916  * @__state: &struct drm_atomic_state pointer
917  * @connector: &struct drm_connector iteration cursor
918  * @new_connector_state: &struct drm_connector_state iteration cursor for the
919  * 	new state
920  * @__i: int iteration cursor, for macro-internal use
921  *
922  * This iterates over all connectors in an atomic update, tracking only the new
923  * state. This is useful in enable functions, where we need the new state the
924  * hardware should be in when the atomic commit operation has completed.
925  */
926 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
927 	for ((__i) = 0;								\
928 	     (__i) < (__state)->num_connector;					\
929 	     (__i)++)								\
930 		for_each_if ((__state)->connectors[__i].ptr &&			\
931 			     ((connector) = (__state)->connectors[__i].ptr,	\
932 			     (void)(connector) /* Only to avoid unused-but-set-variable warning */, \
933 			     (new_connector_state) = (__state)->connectors[__i].new_state, \
934 			     (void)(new_connector_state) /* Only to avoid unused-but-set-variable warning */, 1))
935 
936 /**
937  * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
938  * @__state: &struct drm_atomic_state pointer
939  * @crtc: &struct drm_crtc iteration cursor
940  * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
941  * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
942  * @__i: int iteration cursor, for macro-internal use
943  *
944  * This iterates over all CRTCs in an atomic update, tracking both old and
945  * new state. This is useful in places where the state delta needs to be
946  * considered, for example in atomic check functions.
947  */
948 #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
949 	for ((__i) = 0;							\
950 	     (__i) < (__state)->dev->mode_config.num_crtc;		\
951 	     (__i)++)							\
952 		for_each_if ((__state)->crtcs[__i].ptr &&		\
953 			     ((crtc) = (__state)->crtcs[__i].ptr,	\
954 			      (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
955 			     (old_crtc_state) = (__state)->crtcs[__i].old_state, \
956 			     (void)(old_crtc_state) /* Only to avoid unused-but-set-variable warning */, \
957 			     (new_crtc_state) = (__state)->crtcs[__i].new_state, \
958 			     (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
959 
960 /**
961  * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
962  * @__state: &struct drm_atomic_state pointer
963  * @crtc: &struct drm_crtc iteration cursor
964  * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
965  * @__i: int iteration cursor, for macro-internal use
966  *
967  * This iterates over all CRTCs in an atomic update, tracking only the old
968  * state. This is useful in disable functions, where we need the old state the
969  * hardware is still in.
970  */
971 #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i)	\
972 	for ((__i) = 0;							\
973 	     (__i) < (__state)->dev->mode_config.num_crtc;		\
974 	     (__i)++)							\
975 		for_each_if ((__state)->crtcs[__i].ptr &&		\
976 			     ((crtc) = (__state)->crtcs[__i].ptr,	\
977 			     (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
978 			     (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
979 
980 /**
981  * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
982  * @__state: &struct drm_atomic_state pointer
983  * @crtc: &struct drm_crtc iteration cursor
984  * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
985  * @__i: int iteration cursor, for macro-internal use
986  *
987  * This iterates over all CRTCs in an atomic update, tracking only the new
988  * state. This is useful in enable functions, where we need the new state the
989  * hardware should be in when the atomic commit operation has completed.
990  */
991 #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i)	\
992 	for ((__i) = 0;							\
993 	     (__i) < (__state)->dev->mode_config.num_crtc;		\
994 	     (__i)++)							\
995 		for_each_if ((__state)->crtcs[__i].ptr &&		\
996 			     ((crtc) = (__state)->crtcs[__i].ptr,	\
997 			     (void)(crtc) /* Only to avoid unused-but-set-variable warning */, \
998 			     (new_crtc_state) = (__state)->crtcs[__i].new_state, \
999 			     (void)(new_crtc_state) /* Only to avoid unused-but-set-variable warning */, 1))
1000 
1001 /**
1002  * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
1003  * @__state: &struct drm_atomic_state pointer
1004  * @plane: &struct drm_plane iteration cursor
1005  * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
1006  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
1007  * @__i: int iteration cursor, for macro-internal use
1008  *
1009  * This iterates over all planes in an atomic update, tracking both old and
1010  * new state. This is useful in places where the state delta needs to be
1011  * considered, for example in atomic check functions.
1012  */
1013 #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
1014 	for ((__i) = 0;							\
1015 	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
1016 	     (__i)++)							\
1017 		for_each_if ((__state)->planes[__i].ptr &&		\
1018 			     ((plane) = (__state)->planes[__i].ptr,	\
1019 			      (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
1020 			      (old_plane_state) = (__state)->planes[__i].old_state,\
1021 			      (new_plane_state) = (__state)->planes[__i].new_state, 1))
1022 
1023 /**
1024  * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic
1025  * update in reverse order
1026  * @__state: &struct drm_atomic_state pointer
1027  * @plane: &struct drm_plane iteration cursor
1028  * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
1029  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
1030  * @__i: int iteration cursor, for macro-internal use
1031  *
1032  * This iterates over all planes in an atomic update in reverse order,
1033  * tracking both old and  new state. This is useful in places where the
1034  * state delta needs to be considered, for example in atomic check functions.
1035  */
1036 #define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \
1037 	for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1);	\
1038 	     (__i) >= 0;						\
1039 	     (__i)--)							\
1040 		for_each_if ((__state)->planes[__i].ptr &&		\
1041 			     ((plane) = (__state)->planes[__i].ptr,	\
1042 			      (old_plane_state) = (__state)->planes[__i].old_state,\
1043 			      (new_plane_state) = (__state)->planes[__i].new_state, 1))
1044 
1045 /**
1046  * for_each_new_plane_in_state_reverse - other than only tracking new state,
1047  * it's the same as for_each_oldnew_plane_in_state_reverse
1048  * @__state: &struct drm_atomic_state pointer
1049  * @plane: &struct drm_plane iteration cursor
1050  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
1051  * @__i: int iteration cursor, for macro-internal use
1052  */
1053 #define for_each_new_plane_in_state_reverse(__state, plane, new_plane_state, __i) \
1054 	for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1);	\
1055 	     (__i) >= 0;						\
1056 	     (__i)--)							\
1057 		for_each_if ((__state)->planes[__i].ptr &&		\
1058 			     ((plane) = (__state)->planes[__i].ptr,	\
1059 			      (new_plane_state) = (__state)->planes[__i].new_state, 1))
1060 
1061 /**
1062  * for_each_old_plane_in_state - iterate over all planes in an atomic update
1063  * @__state: &struct drm_atomic_state pointer
1064  * @plane: &struct drm_plane iteration cursor
1065  * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
1066  * @__i: int iteration cursor, for macro-internal use
1067  *
1068  * This iterates over all planes in an atomic update, tracking only the old
1069  * state. This is useful in disable functions, where we need the old state the
1070  * hardware is still in.
1071  */
1072 #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
1073 	for ((__i) = 0;							\
1074 	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
1075 	     (__i)++)							\
1076 		for_each_if ((__state)->planes[__i].ptr &&		\
1077 			     ((plane) = (__state)->planes[__i].ptr,	\
1078 			      (old_plane_state) = (__state)->planes[__i].old_state, 1))
1079 /**
1080  * for_each_new_plane_in_state - iterate over all planes in an atomic update
1081  * @__state: &struct drm_atomic_state pointer
1082  * @plane: &struct drm_plane iteration cursor
1083  * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
1084  * @__i: int iteration cursor, for macro-internal use
1085  *
1086  * This iterates over all planes in an atomic update, tracking only the new
1087  * state. This is useful in enable functions, where we need the new state the
1088  * hardware should be in when the atomic commit operation has completed.
1089  */
1090 #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
1091 	for ((__i) = 0;							\
1092 	     (__i) < (__state)->dev->mode_config.num_total_plane;	\
1093 	     (__i)++)							\
1094 		for_each_if ((__state)->planes[__i].ptr &&		\
1095 			     ((plane) = (__state)->planes[__i].ptr,	\
1096 			      (void)(plane) /* Only to avoid unused-but-set-variable warning */, \
1097 			      (new_plane_state) = (__state)->planes[__i].new_state, \
1098 			      (void)(new_plane_state) /* Only to avoid unused-but-set-variable warning */, 1))
1099 
1100 /**
1101  * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
1102  * @__state: &struct drm_atomic_state pointer
1103  * @obj: &struct drm_private_obj iteration cursor
1104  * @old_obj_state: &struct drm_private_state iteration cursor for the old state
1105  * @new_obj_state: &struct drm_private_state iteration cursor for the new state
1106  * @__i: int iteration cursor, for macro-internal use
1107  *
1108  * This iterates over all private objects in an atomic update, tracking both
1109  * old and new state. This is useful in places where the state delta needs
1110  * to be considered, for example in atomic check functions.
1111  */
1112 #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
1113 	for ((__i) = 0; \
1114 	     (__i) < (__state)->num_private_objs && \
1115 		     ((obj) = (__state)->private_objs[__i].ptr, \
1116 		      (old_obj_state) = (__state)->private_objs[__i].old_state,	\
1117 		      (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
1118 	     (__i)++)
1119 
1120 /**
1121  * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
1122  * @__state: &struct drm_atomic_state pointer
1123  * @obj: &struct drm_private_obj iteration cursor
1124  * @old_obj_state: &struct drm_private_state iteration cursor for the old state
1125  * @__i: int iteration cursor, for macro-internal use
1126  *
1127  * This iterates over all private objects in an atomic update, tracking only
1128  * the old state. This is useful in disable functions, where we need the old
1129  * state the hardware is still in.
1130  */
1131 #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
1132 	for ((__i) = 0; \
1133 	     (__i) < (__state)->num_private_objs && \
1134 		     ((obj) = (__state)->private_objs[__i].ptr, \
1135 		      (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
1136 	     (__i)++)
1137 
1138 /**
1139  * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
1140  * @__state: &struct drm_atomic_state pointer
1141  * @obj: &struct drm_private_obj iteration cursor
1142  * @new_obj_state: &struct drm_private_state iteration cursor for the new state
1143  * @__i: int iteration cursor, for macro-internal use
1144  *
1145  * This iterates over all private objects in an atomic update, tracking only
1146  * the new state. This is useful in enable functions, where we need the new state the
1147  * hardware should be in when the atomic commit operation has completed.
1148  */
1149 #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
1150 	for ((__i) = 0; \
1151 	     (__i) < (__state)->num_private_objs && \
1152 		     ((obj) = (__state)->private_objs[__i].ptr, \
1153 		      (void)(obj) /* Only to avoid unused-but-set-variable warning */, \
1154 		      (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
1155 	     (__i)++)
1156 
1157 /**
1158  * drm_atomic_crtc_needs_modeset - compute combined modeset need
1159  * @state: &drm_crtc_state for the CRTC
1160  *
1161  * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
1162  * whether the state CRTC changed enough to need a full modeset cycle:
1163  * mode_changed, active_changed and connectors_changed. This helper simply
1164  * combines these three to compute the overall need for a modeset for @state.
1165  *
1166  * The atomic helper code sets these booleans, but drivers can and should
1167  * change them appropriately to accurately represent whether a modeset is
1168  * really needed. In general, drivers should avoid full modesets whenever
1169  * possible.
1170  *
1171  * For example if the CRTC mode has changed, and the hardware is able to enact
1172  * the requested mode change without going through a full modeset, the driver
1173  * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
1174  * implementation.
1175  */
1176 static inline bool
1177 drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
1178 {
1179 	return state->mode_changed || state->active_changed ||
1180 	       state->connectors_changed;
1181 }
1182 
1183 /**
1184  * drm_atomic_crtc_effectively_active - compute whether CRTC is actually active
1185  * @state: &drm_crtc_state for the CRTC
1186  *
1187  * When in self refresh mode, the crtc_state->active value will be false, since
1188  * the CRTC is off. However in some cases we're interested in whether the CRTC
1189  * is active, or effectively active (ie: it's connected to an active display).
1190  * In these cases, use this function instead of just checking active.
1191  */
1192 static inline bool
1193 drm_atomic_crtc_effectively_active(const struct drm_crtc_state *state)
1194 {
1195 	return state->active || state->self_refresh_active;
1196 }
1197 
1198 /**
1199  * struct drm_bus_cfg - bus configuration
1200  *
1201  * This structure stores the configuration of a physical bus between two
1202  * components in an output pipeline, usually between two bridges, an encoder
1203  * and a bridge, or a bridge and a connector.
1204  *
1205  * The bus configuration is stored in &drm_bridge_state separately for the
1206  * input and output buses, as seen from the point of view of each bridge. The
1207  * bus configuration of a bridge output is usually identical to the
1208  * configuration of the next bridge's input, but may differ if the signals are
1209  * modified between the two bridges, for instance by an inverter on the board.
1210  * The input and output configurations of a bridge may differ if the bridge
1211  * modifies the signals internally, for instance by performing format
1212  * conversion, or modifying signals polarities.
1213  */
1214 struct drm_bus_cfg {
1215 	/**
1216 	 * @format: format used on this bus (one of the MEDIA_BUS_FMT_* format)
1217 	 *
1218 	 * This field should not be directly modified by drivers
1219 	 * (drm_atomic_bridge_chain_select_bus_fmts() takes care of the bus
1220 	 * format negotiation).
1221 	 */
1222 	u32 format;
1223 
1224 	/**
1225 	 * @flags: DRM_BUS_* flags used on this bus
1226 	 */
1227 	u32 flags;
1228 };
1229 
1230 /**
1231  * struct drm_bridge_state - Atomic bridge state object
1232  */
1233 struct drm_bridge_state {
1234 	/**
1235 	 * @base: inherit from &drm_private_state
1236 	 */
1237 	struct drm_private_state base;
1238 
1239 	/**
1240 	 * @bridge: the bridge this state refers to
1241 	 */
1242 	struct drm_bridge *bridge;
1243 
1244 	/**
1245 	 * @input_bus_cfg: input bus configuration
1246 	 */
1247 	struct drm_bus_cfg input_bus_cfg;
1248 
1249 	/**
1250 	 * @output_bus_cfg: output bus configuration
1251 	 */
1252 	struct drm_bus_cfg output_bus_cfg;
1253 };
1254 
1255 static inline struct drm_bridge_state *
1256 drm_priv_to_bridge_state(struct drm_private_state *priv)
1257 {
1258 	return container_of(priv, struct drm_bridge_state, base);
1259 }
1260 
1261 struct drm_bridge_state *
1262 drm_atomic_get_bridge_state(struct drm_atomic_state *state,
1263 			    struct drm_bridge *bridge);
1264 struct drm_bridge_state *
1265 drm_atomic_get_old_bridge_state(const struct drm_atomic_state *state,
1266 				struct drm_bridge *bridge);
1267 struct drm_bridge_state *
1268 drm_atomic_get_new_bridge_state(const struct drm_atomic_state *state,
1269 				struct drm_bridge *bridge);
1270 
1271 #endif /* DRM_ATOMIC_H_ */
1272