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