Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux/fpc-iii.git] / include / drm / drm_atomic.h
blob5afd6e364fb6774b846134e05a1e33b010672cc1
1 /*
2 * Copyright (C) 2014 Red Hat
3 * Copyright (C) 2014 Intel Corp.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
23 * Authors:
24 * Rob Clark <robdclark@gmail.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
28 #ifndef DRM_ATOMIC_H_
29 #define DRM_ATOMIC_H_
31 #include <drm/drm_crtc.h>
33 /**
34 * struct drm_crtc_commit - track modeset commits on a CRTC
36 * This structure is used to track pending modeset changes and atomic commit on
37 * a per-CRTC basis. Since updating the list should never block this structure
38 * is reference counted to allow waiters to safely wait on an event to complete,
39 * without holding any locks.
41 * It has 3 different events in total to allow a fine-grained synchronization
42 * between outstanding updates::
44 * atomic commit thread hardware
46 * write new state into hardware ----> ...
47 * signal hw_done
48 * switch to new state on next
49 * ... v/hblank
51 * wait for buffers to show up ...
53 * ... send completion irq
54 * irq handler signals flip_done
55 * cleanup old buffers
57 * signal cleanup_done
59 * wait for flip_done <----
60 * clean up atomic state
62 * The important bit to know is that cleanup_done is the terminal event, but the
63 * ordering between flip_done and hw_done is entirely up to the specific driver
64 * and modeset state change.
66 * For an implementation of how to use this look at
67 * drm_atomic_helper_setup_commit() from the atomic helper library.
69 struct drm_crtc_commit {
70 /**
71 * @crtc:
73 * DRM CRTC for this commit.
75 struct drm_crtc *crtc;
77 /**
78 * @ref:
80 * Reference count for this structure. Needed to allow blocking on
81 * completions without the risk of the completion disappearing
82 * meanwhile.
84 struct kref ref;
86 /**
87 * @flip_done:
89 * Will be signaled when the hardware has flipped to the new set of
90 * buffers. Signals at the same time as when the drm event for this
91 * commit is sent to userspace, or when an out-fence is singalled. Note
92 * that for most hardware, in most cases this happens after @hw_done is
93 * signalled.
95 struct completion flip_done;
97 /**
98 * @hw_done:
100 * Will be signalled when all hw register changes for this commit have
101 * been written out. Especially when disabling a pipe this can be much
102 * later than than @flip_done, since that can signal already when the
103 * screen goes black, whereas to fully shut down a pipe more register
104 * I/O is required.
106 * Note that this does not need to include separately reference-counted
107 * resources like backing storage buffer pinning, or runtime pm
108 * management.
110 struct completion hw_done;
113 * @cleanup_done:
115 * Will be signalled after old buffers have been cleaned up by calling
116 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
117 * a vblank wait completed it might be a bit later. This completion is
118 * useful to throttle updates and avoid hardware updates getting ahead
119 * of the buffer cleanup too much.
121 struct completion cleanup_done;
124 * @commit_entry:
126 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
127 * $drm_crtc.commit_lock.
129 struct list_head commit_entry;
132 * @event:
134 * &drm_pending_vblank_event pointer to clean up private events.
136 struct drm_pending_vblank_event *event;
139 struct __drm_planes_state {
140 struct drm_plane *ptr;
141 struct drm_plane_state *state, *old_state, *new_state;
144 struct __drm_crtcs_state {
145 struct drm_crtc *ptr;
146 struct drm_crtc_state *state, *old_state, *new_state;
147 s32 __user *out_fence_ptr;
148 unsigned last_vblank_count;
151 struct __drm_connnectors_state {
152 struct drm_connector *ptr;
153 struct drm_connector_state *state, *old_state, *new_state;
156 struct drm_private_obj;
157 struct drm_private_state;
160 * struct drm_private_state_funcs - atomic state functions for private objects
162 * These hooks are used by atomic helpers to create, swap and destroy states of
163 * private objects. The structure itself is used as a vtable to identify the
164 * associated private object type. Each private object type that needs to be
165 * added to the atomic states is expected to have an implementation of these
166 * hooks and pass a pointer to it's drm_private_state_funcs struct to
167 * drm_atomic_get_private_obj_state().
169 struct drm_private_state_funcs {
171 * @atomic_duplicate_state:
173 * Duplicate the current state of the private object and return it. It
174 * is an error to call this before obj->state has been initialized.
176 * RETURNS:
178 * Duplicated atomic state or NULL when obj->state is not
179 * initialized or allocation failed.
181 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
184 * @atomic_destroy_state:
186 * Frees the private object state created with @atomic_duplicate_state.
188 void (*atomic_destroy_state)(struct drm_private_obj *obj,
189 struct drm_private_state *state);
192 struct drm_private_obj {
193 struct drm_private_state *state;
195 const struct drm_private_state_funcs *funcs;
198 struct drm_private_state {
199 struct drm_atomic_state *state;
202 struct __drm_private_objs_state {
203 struct drm_private_obj *ptr;
204 struct drm_private_state *state, *old_state, *new_state;
208 * struct drm_atomic_state - the global state object for atomic updates
209 * @ref: count of all references to this state (will not be freed until zero)
210 * @dev: parent DRM device
211 * @allow_modeset: allow full modeset
212 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
213 * @async_update: hint for asynchronous plane update
214 * @planes: pointer to array of structures with per-plane data
215 * @crtcs: pointer to array of CRTC pointers
216 * @num_connector: size of the @connectors and @connector_states arrays
217 * @connectors: pointer to array of structures with per-connector data
218 * @num_private_objs: size of the @private_objs array
219 * @private_objs: pointer to array of private object pointers
220 * @acquire_ctx: acquire context for this atomic modeset state update
222 struct drm_atomic_state {
223 struct kref ref;
225 struct drm_device *dev;
226 bool allow_modeset : 1;
227 bool legacy_cursor_update : 1;
228 bool async_update : 1;
229 struct __drm_planes_state *planes;
230 struct __drm_crtcs_state *crtcs;
231 int num_connector;
232 struct __drm_connnectors_state *connectors;
233 int num_private_objs;
234 struct __drm_private_objs_state *private_objs;
236 struct drm_modeset_acquire_ctx *acquire_ctx;
239 * @fake_commit:
241 * Used for signaling unbound planes/connectors.
242 * When a connector or plane is not bound to any CRTC, it's still important
243 * to preserve linearity to prevent the atomic states from being freed to early.
245 * This commit (if set) is not bound to any crtc, but will be completed when
246 * drm_atomic_helper_commit_hw_done() is called.
248 struct drm_crtc_commit *fake_commit;
251 * @commit_work:
253 * Work item which can be used by the driver or helpers to execute the
254 * commit without blocking.
256 struct work_struct commit_work;
259 void __drm_crtc_commit_free(struct kref *kref);
262 * drm_crtc_commit_get - acquire a reference to the CRTC commit
263 * @commit: CRTC commit
265 * Increases the reference of @commit.
267 * Returns:
268 * The pointer to @commit, with reference increased.
270 static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
272 kref_get(&commit->ref);
273 return commit;
277 * drm_crtc_commit_put - release a reference to the CRTC commmit
278 * @commit: CRTC commit
280 * This releases a reference to @commit which is freed after removing the
281 * final reference. No locking required and callable from any context.
283 static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
285 kref_put(&commit->ref, __drm_crtc_commit_free);
288 struct drm_atomic_state * __must_check
289 drm_atomic_state_alloc(struct drm_device *dev);
290 void drm_atomic_state_clear(struct drm_atomic_state *state);
293 * drm_atomic_state_get - acquire a reference to the atomic state
294 * @state: The atomic state
296 * Returns a new reference to the @state
298 static inline struct drm_atomic_state *
299 drm_atomic_state_get(struct drm_atomic_state *state)
301 kref_get(&state->ref);
302 return state;
305 void __drm_atomic_state_free(struct kref *ref);
308 * drm_atomic_state_put - release a reference to the atomic state
309 * @state: The atomic state
311 * This releases a reference to @state which is freed after removing the
312 * final reference. No locking required and callable from any context.
314 static inline void drm_atomic_state_put(struct drm_atomic_state *state)
316 kref_put(&state->ref, __drm_atomic_state_free);
319 int __must_check
320 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
321 void drm_atomic_state_default_clear(struct drm_atomic_state *state);
322 void drm_atomic_state_default_release(struct drm_atomic_state *state);
324 struct drm_crtc_state * __must_check
325 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
326 struct drm_crtc *crtc);
327 int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
328 struct drm_crtc_state *state, struct drm_property *property,
329 uint64_t val);
330 struct drm_plane_state * __must_check
331 drm_atomic_get_plane_state(struct drm_atomic_state *state,
332 struct drm_plane *plane);
333 struct drm_connector_state * __must_check
334 drm_atomic_get_connector_state(struct drm_atomic_state *state,
335 struct drm_connector *connector);
337 void drm_atomic_private_obj_init(struct drm_private_obj *obj,
338 struct drm_private_state *state,
339 const struct drm_private_state_funcs *funcs);
340 void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
342 struct drm_private_state * __must_check
343 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
344 struct drm_private_obj *obj);
347 * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
348 * @state: global atomic state object
349 * @crtc: crtc to grab
351 * This function returns the crtc state for the given crtc, or NULL
352 * if the crtc is not part of the global atomic state.
354 * This function is deprecated, @drm_atomic_get_old_crtc_state or
355 * @drm_atomic_get_new_crtc_state should be used instead.
357 static inline struct drm_crtc_state *
358 drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
359 struct drm_crtc *crtc)
361 return state->crtcs[drm_crtc_index(crtc)].state;
365 * drm_atomic_get_old_crtc_state - get old crtc state, if it exists
366 * @state: global atomic state object
367 * @crtc: crtc to grab
369 * This function returns the old crtc state for the given crtc, or
370 * NULL if the crtc is not part of the global atomic state.
372 static inline struct drm_crtc_state *
373 drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
374 struct drm_crtc *crtc)
376 return state->crtcs[drm_crtc_index(crtc)].old_state;
379 * drm_atomic_get_new_crtc_state - get new crtc state, if it exists
380 * @state: global atomic state object
381 * @crtc: crtc to grab
383 * This function returns the new crtc state for the given crtc, or
384 * NULL if the crtc is not part of the global atomic state.
386 static inline struct drm_crtc_state *
387 drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
388 struct drm_crtc *crtc)
390 return state->crtcs[drm_crtc_index(crtc)].new_state;
394 * drm_atomic_get_existing_plane_state - get plane state, if it exists
395 * @state: global atomic state object
396 * @plane: plane to grab
398 * This function returns the plane state for the given plane, or NULL
399 * if the plane is not part of the global atomic state.
401 * This function is deprecated, @drm_atomic_get_old_plane_state or
402 * @drm_atomic_get_new_plane_state should be used instead.
404 static inline struct drm_plane_state *
405 drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
406 struct drm_plane *plane)
408 return state->planes[drm_plane_index(plane)].state;
412 * drm_atomic_get_old_plane_state - get plane state, if it exists
413 * @state: global atomic state object
414 * @plane: plane to grab
416 * This function returns the old plane state for the given plane, or
417 * NULL if the plane is not part of the global atomic state.
419 static inline struct drm_plane_state *
420 drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
421 struct drm_plane *plane)
423 return state->planes[drm_plane_index(plane)].old_state;
427 * drm_atomic_get_new_plane_state - get plane state, if it exists
428 * @state: global atomic state object
429 * @plane: plane to grab
431 * This function returns the new plane state for the given plane, or
432 * NULL if the plane is not part of the global atomic state.
434 static inline struct drm_plane_state *
435 drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
436 struct drm_plane *plane)
438 return state->planes[drm_plane_index(plane)].new_state;
442 * drm_atomic_get_existing_connector_state - get connector state, if it exists
443 * @state: global atomic state object
444 * @connector: connector to grab
446 * This function returns the connector state for the given connector,
447 * or NULL if the connector is not part of the global atomic state.
449 * This function is deprecated, @drm_atomic_get_old_connector_state or
450 * @drm_atomic_get_new_connector_state should be used instead.
452 static inline struct drm_connector_state *
453 drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
454 struct drm_connector *connector)
456 int index = drm_connector_index(connector);
458 if (index >= state->num_connector)
459 return NULL;
461 return state->connectors[index].state;
465 * drm_atomic_get_old_connector_state - get connector state, if it exists
466 * @state: global atomic state object
467 * @connector: connector to grab
469 * This function returns the old connector state for the given connector,
470 * or NULL if the connector is not part of the global atomic state.
472 static inline struct drm_connector_state *
473 drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
474 struct drm_connector *connector)
476 int index = drm_connector_index(connector);
478 if (index >= state->num_connector)
479 return NULL;
481 return state->connectors[index].old_state;
485 * drm_atomic_get_new_connector_state - get connector state, if it exists
486 * @state: global atomic state object
487 * @connector: connector to grab
489 * This function returns the new connector state for the given connector,
490 * or NULL if the connector is not part of the global atomic state.
492 static inline struct drm_connector_state *
493 drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
494 struct drm_connector *connector)
496 int index = drm_connector_index(connector);
498 if (index >= state->num_connector)
499 return NULL;
501 return state->connectors[index].new_state;
505 * __drm_atomic_get_current_plane_state - get current plane state
506 * @state: global atomic state object
507 * @plane: plane to grab
509 * This function returns the plane state for the given plane, either from
510 * @state, or if the plane isn't part of the atomic state update, from @plane.
511 * This is useful in atomic check callbacks, when drivers need to peek at, but
512 * not change, state of other planes, since it avoids threading an error code
513 * back up the call chain.
515 * WARNING:
517 * Note that this function is in general unsafe since it doesn't check for the
518 * required locking for access state structures. Drivers must ensure that it is
519 * safe to access the returned state structure through other means. One common
520 * example is when planes are fixed to a single CRTC, and the driver knows that
521 * the CRTC lock is held already. In that case holding the CRTC lock gives a
522 * read-lock on all planes connected to that CRTC. But if planes can be
523 * reassigned things get more tricky. In that case it's better to use
524 * drm_atomic_get_plane_state and wire up full error handling.
526 * Returns:
528 * Read-only pointer to the current plane state.
530 static inline const struct drm_plane_state *
531 __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
532 struct drm_plane *plane)
534 if (state->planes[drm_plane_index(plane)].state)
535 return state->planes[drm_plane_index(plane)].state;
537 return plane->state;
540 int __must_check
541 drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
542 const struct drm_display_mode *mode);
543 int __must_check
544 drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
545 struct drm_property_blob *blob);
546 int __must_check
547 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
548 struct drm_crtc *crtc);
549 void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
550 struct drm_framebuffer *fb);
551 void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
552 struct dma_fence *fence);
553 int __must_check
554 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
555 struct drm_crtc *crtc);
556 int __must_check
557 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
558 struct drm_crtc *crtc);
559 int __must_check
560 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
561 struct drm_crtc *crtc);
563 void
564 drm_atomic_clean_old_fb(struct drm_device *dev, unsigned plane_mask, int ret);
566 int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
567 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
568 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
570 void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
573 * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
574 * @__state: &struct drm_atomic_state pointer
575 * @connector: &struct drm_connector iteration cursor
576 * @old_connector_state: &struct drm_connector_state iteration cursor for the
577 * old state
578 * @new_connector_state: &struct drm_connector_state iteration cursor for the
579 * new state
580 * @__i: int iteration cursor, for macro-internal use
582 * This iterates over all connectors in an atomic update, tracking both old and
583 * new state. This is useful in places where the state delta needs to be
584 * considered, for example in atomic check functions.
586 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
587 for ((__i) = 0; \
588 (__i) < (__state)->num_connector; \
589 (__i)++) \
590 for_each_if ((__state)->connectors[__i].ptr && \
591 ((connector) = (__state)->connectors[__i].ptr, \
592 (old_connector_state) = (__state)->connectors[__i].old_state, \
593 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
596 * for_each_old_connector_in_state - iterate over all connectors in an atomic update
597 * @__state: &struct drm_atomic_state pointer
598 * @connector: &struct drm_connector iteration cursor
599 * @old_connector_state: &struct drm_connector_state iteration cursor for the
600 * old state
601 * @__i: int iteration cursor, for macro-internal use
603 * This iterates over all connectors in an atomic update, tracking only the old
604 * state. This is useful in disable functions, where we need the old state the
605 * hardware is still in.
607 #define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
608 for ((__i) = 0; \
609 (__i) < (__state)->num_connector; \
610 (__i)++) \
611 for_each_if ((__state)->connectors[__i].ptr && \
612 ((connector) = (__state)->connectors[__i].ptr, \
613 (old_connector_state) = (__state)->connectors[__i].old_state, 1))
616 * for_each_new_connector_in_state - iterate over all connectors in an atomic update
617 * @__state: &struct drm_atomic_state pointer
618 * @connector: &struct drm_connector iteration cursor
619 * @new_connector_state: &struct drm_connector_state iteration cursor for the
620 * new state
621 * @__i: int iteration cursor, for macro-internal use
623 * This iterates over all connectors in an atomic update, tracking only the new
624 * state. This is useful in enable functions, where we need the new state the
625 * hardware should be in when the atomic commit operation has completed.
627 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
628 for ((__i) = 0; \
629 (__i) < (__state)->num_connector; \
630 (__i)++) \
631 for_each_if ((__state)->connectors[__i].ptr && \
632 ((connector) = (__state)->connectors[__i].ptr, \
633 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
636 * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
637 * @__state: &struct drm_atomic_state pointer
638 * @crtc: &struct drm_crtc iteration cursor
639 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
640 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
641 * @__i: int iteration cursor, for macro-internal use
643 * This iterates over all CRTCs in an atomic update, tracking both old and
644 * new state. This is useful in places where the state delta needs to be
645 * considered, for example in atomic check functions.
647 #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
648 for ((__i) = 0; \
649 (__i) < (__state)->dev->mode_config.num_crtc; \
650 (__i)++) \
651 for_each_if ((__state)->crtcs[__i].ptr && \
652 ((crtc) = (__state)->crtcs[__i].ptr, \
653 (old_crtc_state) = (__state)->crtcs[__i].old_state, \
654 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
657 * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
658 * @__state: &struct drm_atomic_state pointer
659 * @crtc: &struct drm_crtc iteration cursor
660 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
661 * @__i: int iteration cursor, for macro-internal use
663 * This iterates over all CRTCs in an atomic update, tracking only the old
664 * state. This is useful in disable functions, where we need the old state the
665 * hardware is still in.
667 #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
668 for ((__i) = 0; \
669 (__i) < (__state)->dev->mode_config.num_crtc; \
670 (__i)++) \
671 for_each_if ((__state)->crtcs[__i].ptr && \
672 ((crtc) = (__state)->crtcs[__i].ptr, \
673 (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
676 * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
677 * @__state: &struct drm_atomic_state pointer
678 * @crtc: &struct drm_crtc iteration cursor
679 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
680 * @__i: int iteration cursor, for macro-internal use
682 * This iterates over all CRTCs in an atomic update, tracking only the new
683 * state. This is useful in enable functions, where we need the new state the
684 * hardware should be in when the atomic commit operation has completed.
686 #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
687 for ((__i) = 0; \
688 (__i) < (__state)->dev->mode_config.num_crtc; \
689 (__i)++) \
690 for_each_if ((__state)->crtcs[__i].ptr && \
691 ((crtc) = (__state)->crtcs[__i].ptr, \
692 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
695 * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
696 * @__state: &struct drm_atomic_state pointer
697 * @plane: &struct drm_plane iteration cursor
698 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
699 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
700 * @__i: int iteration cursor, for macro-internal use
702 * This iterates over all planes in an atomic update, tracking both old and
703 * new state. This is useful in places where the state delta needs to be
704 * considered, for example in atomic check functions.
706 #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
707 for ((__i) = 0; \
708 (__i) < (__state)->dev->mode_config.num_total_plane; \
709 (__i)++) \
710 for_each_if ((__state)->planes[__i].ptr && \
711 ((plane) = (__state)->planes[__i].ptr, \
712 (old_plane_state) = (__state)->planes[__i].old_state,\
713 (new_plane_state) = (__state)->planes[__i].new_state, 1))
716 * for_each_old_plane_in_state - iterate over all planes in an atomic update
717 * @__state: &struct drm_atomic_state pointer
718 * @plane: &struct drm_plane iteration cursor
719 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
720 * @__i: int iteration cursor, for macro-internal use
722 * This iterates over all planes in an atomic update, tracking only the old
723 * state. This is useful in disable functions, where we need the old state the
724 * hardware is still in.
726 #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
727 for ((__i) = 0; \
728 (__i) < (__state)->dev->mode_config.num_total_plane; \
729 (__i)++) \
730 for_each_if ((__state)->planes[__i].ptr && \
731 ((plane) = (__state)->planes[__i].ptr, \
732 (old_plane_state) = (__state)->planes[__i].old_state, 1))
734 * for_each_new_plane_in_state - iterate over all planes in an atomic update
735 * @__state: &struct drm_atomic_state pointer
736 * @plane: &struct drm_plane iteration cursor
737 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
738 * @__i: int iteration cursor, for macro-internal use
740 * This iterates over all planes in an atomic update, tracking only the new
741 * state. This is useful in enable functions, where we need the new state the
742 * hardware should be in when the atomic commit operation has completed.
744 #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
745 for ((__i) = 0; \
746 (__i) < (__state)->dev->mode_config.num_total_plane; \
747 (__i)++) \
748 for_each_if ((__state)->planes[__i].ptr && \
749 ((plane) = (__state)->planes[__i].ptr, \
750 (new_plane_state) = (__state)->planes[__i].new_state, 1))
753 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
754 * @__state: &struct drm_atomic_state pointer
755 * @obj: &struct drm_private_obj iteration cursor
756 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
757 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
758 * @__i: int iteration cursor, for macro-internal use
760 * This iterates over all private objects in an atomic update, tracking both
761 * old and new state. This is useful in places where the state delta needs
762 * to be considered, for example in atomic check functions.
764 #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
765 for ((__i) = 0; \
766 (__i) < (__state)->num_private_objs && \
767 ((obj) = (__state)->private_objs[__i].ptr, \
768 (old_obj_state) = (__state)->private_objs[__i].old_state, \
769 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
770 (__i)++)
773 * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
774 * @__state: &struct drm_atomic_state pointer
775 * @obj: &struct drm_private_obj iteration cursor
776 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
777 * @__i: int iteration cursor, for macro-internal use
779 * This iterates over all private objects in an atomic update, tracking only
780 * the old state. This is useful in disable functions, where we need the old
781 * state the hardware is still in.
783 #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
784 for ((__i) = 0; \
785 (__i) < (__state)->num_private_objs && \
786 ((obj) = (__state)->private_objs[__i].ptr, \
787 (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
788 (__i)++)
791 * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
792 * @__state: &struct drm_atomic_state pointer
793 * @obj: &struct drm_private_obj iteration cursor
794 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
795 * @__i: int iteration cursor, for macro-internal use
797 * This iterates over all private objects in an atomic update, tracking only
798 * the new state. This is useful in enable functions, where we need the new state the
799 * hardware should be in when the atomic commit operation has completed.
801 #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
802 for ((__i) = 0; \
803 (__i) < (__state)->num_private_objs && \
804 ((obj) = (__state)->private_objs[__i].ptr, \
805 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
806 (__i)++)
809 * drm_atomic_crtc_needs_modeset - compute combined modeset need
810 * @state: &drm_crtc_state for the CRTC
812 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
813 * whether the state CRTC changed enough to need a full modeset cycle:
814 * mode_changed, active_changed and connectors_changed. This helper simply
815 * combines these three to compute the overall need for a modeset for @state.
817 * The atomic helper code sets these booleans, but drivers can and should
818 * change them appropriately to accurately represent whether a modeset is
819 * really needed. In general, drivers should avoid full modesets whenever
820 * possible.
822 * For example if the CRTC mode has changed, and the hardware is able to enact
823 * the requested mode change without going through a full modeset, the driver
824 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
825 * implementation.
827 static inline bool
828 drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
830 return state->mode_changed || state->active_changed ||
831 state->connectors_changed;
834 #endif /* DRM_ATOMIC_H_ */