Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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
33/**
34 * struct drm_crtc_commit - track modeset commits on a CRTC
35 *
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.
40 *
41 * It has 3 different events in total to allow a fine-grained synchronization
42 * between outstanding updates::
43 *
44 * atomic commit thread hardware
45 *
46 * write new state into hardware ----> ...
47 * signal hw_done
48 * switch to new state on next
49 * ... v/hblank
50 *
51 * wait for buffers to show up ...
52 *
53 * ... send completion irq
54 * irq handler signals flip_done
55 * cleanup old buffers
56 *
57 * signal cleanup_done
58 *
59 * wait for flip_done <----
60 * clean up atomic state
61 *
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.
65 *
66 * For an implementation of how to use this look at
67 * drm_atomic_helper_setup_commit() from the atomic helper library.
68 */
69struct drm_crtc_commit {
70 /**
71 * @crtc:
72 *
73 * DRM CRTC for this commit.
74 */
75 struct drm_crtc *crtc;
76
77 /**
78 * @ref:
79 *
80 * Reference count for this structure. Needed to allow blocking on
81 * completions without the risk of the completion disappearing
82 * meanwhile.
83 */
84 struct kref ref;
85
86 /**
87 * @flip_done:
88 *
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.
94 */
95 struct completion flip_done;
96
97 /**
98 * @hw_done:
99 *
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.
105 *
106 * Note that this does not need to include separately reference-counted
107 * resources like backing storage buffer pinning, or runtime pm
108 * management.
109 */
110 struct completion hw_done;
111
112 /**
113 * @cleanup_done:
114 *
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.
120 */
121 struct completion cleanup_done;
122
123 /**
124 * @commit_entry:
125 *
126 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
127 * $drm_crtc.commit_lock.
128 */
129 struct list_head commit_entry;
130
131 /**
132 * @event:
133 *
134 * &drm_pending_vblank_event pointer to clean up private events.
135 */
136 struct drm_pending_vblank_event *event;
137
138 /**
139 * @abort_completion:
140 *
141 * A flag that's set after drm_atomic_helper_setup_commit takes a second
142 * reference for the completion of $drm_crtc_state.event. It's used by
143 * the free code to remove the second reference if commit fails.
144 */
145 bool abort_completion;
146};
147
148struct __drm_planes_state {
149 struct drm_plane *ptr;
150 struct drm_plane_state *state, *old_state, *new_state;
151};
152
153struct __drm_crtcs_state {
154 struct drm_crtc *ptr;
155 struct drm_crtc_state *state, *old_state, *new_state;
156 s32 __user *out_fence_ptr;
157 u64 last_vblank_count;
158};
159
160struct __drm_connnectors_state {
161 struct drm_connector *ptr;
162 struct drm_connector_state *state, *old_state, *new_state;
163 /**
164 * @out_fence_ptr:
165 *
166 * User-provided pointer which the kernel uses to return a sync_file
167 * file descriptor. Used by writeback connectors to signal completion of
168 * the writeback.
169 */
170 s32 __user *out_fence_ptr;
171};
172
173struct drm_private_obj;
174struct drm_private_state;
175
176/**
177 * struct drm_private_state_funcs - atomic state functions for private objects
178 *
179 * These hooks are used by atomic helpers to create, swap and destroy states of
180 * private objects. The structure itself is used as a vtable to identify the
181 * associated private object type. Each private object type that needs to be
182 * added to the atomic states is expected to have an implementation of these
183 * hooks and pass a pointer to it's drm_private_state_funcs struct to
184 * drm_atomic_get_private_obj_state().
185 */
186struct drm_private_state_funcs {
187 /**
188 * @atomic_duplicate_state:
189 *
190 * Duplicate the current state of the private object and return it. It
191 * is an error to call this before obj->state has been initialized.
192 *
193 * RETURNS:
194 *
195 * Duplicated atomic state or NULL when obj->state is not
196 * initialized or allocation failed.
197 */
198 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
199
200 /**
201 * @atomic_destroy_state:
202 *
203 * Frees the private object state created with @atomic_duplicate_state.
204 */
205 void (*atomic_destroy_state)(struct drm_private_obj *obj,
206 struct drm_private_state *state);
207};
208
209/**
210 * struct drm_private_obj - base struct for driver private atomic object
211 *
212 * A driver private object is initialized by calling
213 * drm_atomic_private_obj_init() and cleaned up by calling
214 * drm_atomic_private_obj_fini().
215 *
216 * Currently only tracks the state update functions and the opaque driver
217 * private state itself, but in the future might also track which
218 * &drm_modeset_lock is required to duplicate and update this object's state.
219 */
220struct drm_private_obj {
221 /**
222 * @state: Current atomic state for this driver private object.
223 */
224 struct drm_private_state *state;
225
226 /**
227 * @funcs:
228 *
229 * Functions to manipulate the state of this driver private object, see
230 * &drm_private_state_funcs.
231 */
232 const struct drm_private_state_funcs *funcs;
233};
234
235/**
236 * struct drm_private_state - base struct for driver private object state
237 * @state: backpointer to global drm_atomic_state
238 *
239 * Currently only contains a backpointer to the overall atomic update, but in
240 * the future also might hold synchronization information similar to e.g.
241 * &drm_crtc.commit.
242 */
243struct drm_private_state {
244 struct drm_atomic_state *state;
245};
246
247struct __drm_private_objs_state {
248 struct drm_private_obj *ptr;
249 struct drm_private_state *state, *old_state, *new_state;
250};
251
252/**
253 * struct drm_atomic_state - the global state object for atomic updates
254 * @ref: count of all references to this state (will not be freed until zero)
255 * @dev: parent DRM device
256 * @allow_modeset: allow full modeset
257 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
258 * @async_update: hint for asynchronous plane update
259 * @planes: pointer to array of structures with per-plane data
260 * @crtcs: pointer to array of CRTC pointers
261 * @num_connector: size of the @connectors and @connector_states arrays
262 * @connectors: pointer to array of structures with per-connector data
263 * @num_private_objs: size of the @private_objs array
264 * @private_objs: pointer to array of private object pointers
265 * @acquire_ctx: acquire context for this atomic modeset state update
266 *
267 * States are added to an atomic update by calling drm_atomic_get_crtc_state(),
268 * drm_atomic_get_plane_state(), drm_atomic_get_connector_state(), or for
269 * private state structures, drm_atomic_get_private_obj_state().
270 */
271struct drm_atomic_state {
272 struct kref ref;
273
274 struct drm_device *dev;
275 bool allow_modeset : 1;
276 bool legacy_cursor_update : 1;
277 bool async_update : 1;
278 struct __drm_planes_state *planes;
279 struct __drm_crtcs_state *crtcs;
280 int num_connector;
281 struct __drm_connnectors_state *connectors;
282 int num_private_objs;
283 struct __drm_private_objs_state *private_objs;
284
285 struct drm_modeset_acquire_ctx *acquire_ctx;
286
287 /**
288 * @fake_commit:
289 *
290 * Used for signaling unbound planes/connectors.
291 * When a connector or plane is not bound to any CRTC, it's still important
292 * to preserve linearity to prevent the atomic states from being freed to early.
293 *
294 * This commit (if set) is not bound to any crtc, but will be completed when
295 * drm_atomic_helper_commit_hw_done() is called.
296 */
297 struct drm_crtc_commit *fake_commit;
298
299 /**
300 * @commit_work:
301 *
302 * Work item which can be used by the driver or helpers to execute the
303 * commit without blocking.
304 */
305 struct work_struct commit_work;
306};
307
308void __drm_crtc_commit_free(struct kref *kref);
309
310/**
311 * drm_crtc_commit_get - acquire a reference to the CRTC commit
312 * @commit: CRTC commit
313 *
314 * Increases the reference of @commit.
315 *
316 * Returns:
317 * The pointer to @commit, with reference increased.
318 */
319static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
320{
321 kref_get(&commit->ref);
322 return commit;
323}
324
325/**
326 * drm_crtc_commit_put - release a reference to the CRTC commmit
327 * @commit: CRTC commit
328 *
329 * This releases a reference to @commit which is freed after removing the
330 * final reference. No locking required and callable from any context.
331 */
332static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
333{
334 kref_put(&commit->ref, __drm_crtc_commit_free);
335}
336
337struct drm_atomic_state * __must_check
338drm_atomic_state_alloc(struct drm_device *dev);
339void drm_atomic_state_clear(struct drm_atomic_state *state);
340
341/**
342 * drm_atomic_state_get - acquire a reference to the atomic state
343 * @state: The atomic state
344 *
345 * Returns a new reference to the @state
346 */
347static inline struct drm_atomic_state *
348drm_atomic_state_get(struct drm_atomic_state *state)
349{
350 kref_get(&state->ref);
351 return state;
352}
353
354void __drm_atomic_state_free(struct kref *ref);
355
356/**
357 * drm_atomic_state_put - release a reference to the atomic state
358 * @state: The atomic state
359 *
360 * This releases a reference to @state which is freed after removing the
361 * final reference. No locking required and callable from any context.
362 */
363static inline void drm_atomic_state_put(struct drm_atomic_state *state)
364{
365 kref_put(&state->ref, __drm_atomic_state_free);
366}
367
368int __must_check
369drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
370void drm_atomic_state_default_clear(struct drm_atomic_state *state);
371void drm_atomic_state_default_release(struct drm_atomic_state *state);
372
373struct drm_crtc_state * __must_check
374drm_atomic_get_crtc_state(struct drm_atomic_state *state,
375 struct drm_crtc *crtc);
376int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
377 struct drm_crtc_state *state, struct drm_property *property,
378 uint64_t val);
379struct drm_plane_state * __must_check
380drm_atomic_get_plane_state(struct drm_atomic_state *state,
381 struct drm_plane *plane);
382struct drm_connector_state * __must_check
383drm_atomic_get_connector_state(struct drm_atomic_state *state,
384 struct drm_connector *connector);
385
386void drm_atomic_private_obj_init(struct drm_private_obj *obj,
387 struct drm_private_state *state,
388 const struct drm_private_state_funcs *funcs);
389void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
390
391struct drm_private_state * __must_check
392drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
393 struct drm_private_obj *obj);
394
395/**
396 * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
397 * @state: global atomic state object
398 * @crtc: crtc to grab
399 *
400 * This function returns the crtc state for the given crtc, or NULL
401 * if the crtc is not part of the global atomic state.
402 *
403 * This function is deprecated, @drm_atomic_get_old_crtc_state or
404 * @drm_atomic_get_new_crtc_state should be used instead.
405 */
406static inline struct drm_crtc_state *
407drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
408 struct drm_crtc *crtc)
409{
410 return state->crtcs[drm_crtc_index(crtc)].state;
411}
412
413/**
414 * drm_atomic_get_old_crtc_state - get old crtc state, if it exists
415 * @state: global atomic state object
416 * @crtc: crtc to grab
417 *
418 * This function returns the old crtc state for the given crtc, or
419 * NULL if the crtc is not part of the global atomic state.
420 */
421static inline struct drm_crtc_state *
422drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
423 struct drm_crtc *crtc)
424{
425 return state->crtcs[drm_crtc_index(crtc)].old_state;
426}
427/**
428 * drm_atomic_get_new_crtc_state - get new crtc state, if it exists
429 * @state: global atomic state object
430 * @crtc: crtc to grab
431 *
432 * This function returns the new crtc state for the given crtc, or
433 * NULL if the crtc is not part of the global atomic state.
434 */
435static inline struct drm_crtc_state *
436drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
437 struct drm_crtc *crtc)
438{
439 return state->crtcs[drm_crtc_index(crtc)].new_state;
440}
441
442/**
443 * drm_atomic_get_existing_plane_state - get plane state, if it exists
444 * @state: global atomic state object
445 * @plane: plane to grab
446 *
447 * This function returns the plane state for the given plane, or NULL
448 * if the plane is not part of the global atomic state.
449 *
450 * This function is deprecated, @drm_atomic_get_old_plane_state or
451 * @drm_atomic_get_new_plane_state should be used instead.
452 */
453static inline struct drm_plane_state *
454drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
455 struct drm_plane *plane)
456{
457 return state->planes[drm_plane_index(plane)].state;
458}
459
460/**
461 * drm_atomic_get_old_plane_state - get plane state, if it exists
462 * @state: global atomic state object
463 * @plane: plane to grab
464 *
465 * This function returns the old plane state for the given plane, or
466 * NULL if the plane is not part of the global atomic state.
467 */
468static inline struct drm_plane_state *
469drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
470 struct drm_plane *plane)
471{
472 return state->planes[drm_plane_index(plane)].old_state;
473}
474
475/**
476 * drm_atomic_get_new_plane_state - get plane state, if it exists
477 * @state: global atomic state object
478 * @plane: plane to grab
479 *
480 * This function returns the new plane state for the given plane, or
481 * NULL if the plane is not part of the global atomic state.
482 */
483static inline struct drm_plane_state *
484drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
485 struct drm_plane *plane)
486{
487 return state->planes[drm_plane_index(plane)].new_state;
488}
489
490/**
491 * drm_atomic_get_existing_connector_state - get connector state, if it exists
492 * @state: global atomic state object
493 * @connector: connector to grab
494 *
495 * This function returns the connector state for the given connector,
496 * or NULL if the connector is not part of the global atomic state.
497 *
498 * This function is deprecated, @drm_atomic_get_old_connector_state or
499 * @drm_atomic_get_new_connector_state should be used instead.
500 */
501static inline struct drm_connector_state *
502drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
503 struct drm_connector *connector)
504{
505 int index = drm_connector_index(connector);
506
507 if (index >= state->num_connector)
508 return NULL;
509
510 return state->connectors[index].state;
511}
512
513/**
514 * drm_atomic_get_old_connector_state - get connector state, if it exists
515 * @state: global atomic state object
516 * @connector: connector to grab
517 *
518 * This function returns the old connector state for the given connector,
519 * or NULL if the connector is not part of the global atomic state.
520 */
521static inline struct drm_connector_state *
522drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
523 struct drm_connector *connector)
524{
525 int index = drm_connector_index(connector);
526
527 if (index >= state->num_connector)
528 return NULL;
529
530 return state->connectors[index].old_state;
531}
532
533/**
534 * drm_atomic_get_new_connector_state - get connector state, if it exists
535 * @state: global atomic state object
536 * @connector: connector to grab
537 *
538 * This function returns the new connector state for the given connector,
539 * or NULL if the connector is not part of the global atomic state.
540 */
541static inline struct drm_connector_state *
542drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
543 struct drm_connector *connector)
544{
545 int index = drm_connector_index(connector);
546
547 if (index >= state->num_connector)
548 return NULL;
549
550 return state->connectors[index].new_state;
551}
552
553/**
554 * __drm_atomic_get_current_plane_state - get current plane state
555 * @state: global atomic state object
556 * @plane: plane to grab
557 *
558 * This function returns the plane state for the given plane, either from
559 * @state, or if the plane isn't part of the atomic state update, from @plane.
560 * This is useful in atomic check callbacks, when drivers need to peek at, but
561 * not change, state of other planes, since it avoids threading an error code
562 * back up the call chain.
563 *
564 * WARNING:
565 *
566 * Note that this function is in general unsafe since it doesn't check for the
567 * required locking for access state structures. Drivers must ensure that it is
568 * safe to access the returned state structure through other means. One common
569 * example is when planes are fixed to a single CRTC, and the driver knows that
570 * the CRTC lock is held already. In that case holding the CRTC lock gives a
571 * read-lock on all planes connected to that CRTC. But if planes can be
572 * reassigned things get more tricky. In that case it's better to use
573 * drm_atomic_get_plane_state and wire up full error handling.
574 *
575 * Returns:
576 *
577 * Read-only pointer to the current plane state.
578 */
579static inline const struct drm_plane_state *
580__drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
581 struct drm_plane *plane)
582{
583 if (state->planes[drm_plane_index(plane)].state)
584 return state->planes[drm_plane_index(plane)].state;
585
586 return plane->state;
587}
588
589int __must_check
590drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
591 const struct drm_display_mode *mode);
592int __must_check
593drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
594 struct drm_property_blob *blob);
595int __must_check
596drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
597 struct drm_crtc *crtc);
598void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
599 struct drm_framebuffer *fb);
600void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
601 struct dma_fence *fence);
602int __must_check
603drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
604 struct drm_crtc *crtc);
605int drm_atomic_set_writeback_fb_for_connector(
606 struct drm_connector_state *conn_state,
607 struct drm_framebuffer *fb);
608int __must_check
609drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
610 struct drm_crtc *crtc);
611int __must_check
612drm_atomic_add_affected_planes(struct drm_atomic_state *state,
613 struct drm_crtc *crtc);
614
615int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
616int __must_check drm_atomic_commit(struct drm_atomic_state *state);
617int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
618
619void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
620
621/**
622 * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
623 * @__state: &struct drm_atomic_state pointer
624 * @connector: &struct drm_connector iteration cursor
625 * @old_connector_state: &struct drm_connector_state iteration cursor for the
626 * old state
627 * @new_connector_state: &struct drm_connector_state iteration cursor for the
628 * new state
629 * @__i: int iteration cursor, for macro-internal use
630 *
631 * This iterates over all connectors in an atomic update, tracking both old and
632 * new state. This is useful in places where the state delta needs to be
633 * considered, for example in atomic check functions.
634 */
635#define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
636 for ((__i) = 0; \
637 (__i) < (__state)->num_connector; \
638 (__i)++) \
639 for_each_if ((__state)->connectors[__i].ptr && \
640 ((connector) = (__state)->connectors[__i].ptr, \
641 (old_connector_state) = (__state)->connectors[__i].old_state, \
642 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
643
644/**
645 * for_each_old_connector_in_state - iterate over all connectors in an atomic update
646 * @__state: &struct drm_atomic_state pointer
647 * @connector: &struct drm_connector iteration cursor
648 * @old_connector_state: &struct drm_connector_state iteration cursor for the
649 * old state
650 * @__i: int iteration cursor, for macro-internal use
651 *
652 * This iterates over all connectors in an atomic update, tracking only the old
653 * state. This is useful in disable functions, where we need the old state the
654 * hardware is still in.
655 */
656#define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
657 for ((__i) = 0; \
658 (__i) < (__state)->num_connector; \
659 (__i)++) \
660 for_each_if ((__state)->connectors[__i].ptr && \
661 ((connector) = (__state)->connectors[__i].ptr, \
662 (old_connector_state) = (__state)->connectors[__i].old_state, 1))
663
664/**
665 * for_each_new_connector_in_state - iterate over all connectors in an atomic update
666 * @__state: &struct drm_atomic_state pointer
667 * @connector: &struct drm_connector iteration cursor
668 * @new_connector_state: &struct drm_connector_state iteration cursor for the
669 * new state
670 * @__i: int iteration cursor, for macro-internal use
671 *
672 * This iterates over all connectors in an atomic update, tracking only the new
673 * state. This is useful in enable functions, where we need the new state the
674 * hardware should be in when the atomic commit operation has completed.
675 */
676#define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
677 for ((__i) = 0; \
678 (__i) < (__state)->num_connector; \
679 (__i)++) \
680 for_each_if ((__state)->connectors[__i].ptr && \
681 ((connector) = (__state)->connectors[__i].ptr, \
682 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
683
684/**
685 * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
686 * @__state: &struct drm_atomic_state pointer
687 * @crtc: &struct drm_crtc iteration cursor
688 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
689 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
690 * @__i: int iteration cursor, for macro-internal use
691 *
692 * This iterates over all CRTCs in an atomic update, tracking both old and
693 * new state. This is useful in places where the state delta needs to be
694 * considered, for example in atomic check functions.
695 */
696#define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
697 for ((__i) = 0; \
698 (__i) < (__state)->dev->mode_config.num_crtc; \
699 (__i)++) \
700 for_each_if ((__state)->crtcs[__i].ptr && \
701 ((crtc) = (__state)->crtcs[__i].ptr, \
702 (old_crtc_state) = (__state)->crtcs[__i].old_state, \
703 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
704
705/**
706 * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
707 * @__state: &struct drm_atomic_state pointer
708 * @crtc: &struct drm_crtc iteration cursor
709 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
710 * @__i: int iteration cursor, for macro-internal use
711 *
712 * This iterates over all CRTCs in an atomic update, tracking only the old
713 * state. This is useful in disable functions, where we need the old state the
714 * hardware is still in.
715 */
716#define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
717 for ((__i) = 0; \
718 (__i) < (__state)->dev->mode_config.num_crtc; \
719 (__i)++) \
720 for_each_if ((__state)->crtcs[__i].ptr && \
721 ((crtc) = (__state)->crtcs[__i].ptr, \
722 (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
723
724/**
725 * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
726 * @__state: &struct drm_atomic_state pointer
727 * @crtc: &struct drm_crtc iteration cursor
728 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
729 * @__i: int iteration cursor, for macro-internal use
730 *
731 * This iterates over all CRTCs in an atomic update, tracking only the new
732 * state. This is useful in enable functions, where we need the new state the
733 * hardware should be in when the atomic commit operation has completed.
734 */
735#define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
736 for ((__i) = 0; \
737 (__i) < (__state)->dev->mode_config.num_crtc; \
738 (__i)++) \
739 for_each_if ((__state)->crtcs[__i].ptr && \
740 ((crtc) = (__state)->crtcs[__i].ptr, \
741 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
742
743/**
744 * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
745 * @__state: &struct drm_atomic_state pointer
746 * @plane: &struct drm_plane iteration cursor
747 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
748 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
749 * @__i: int iteration cursor, for macro-internal use
750 *
751 * This iterates over all planes in an atomic update, tracking both old and
752 * new state. This is useful in places where the state delta needs to be
753 * considered, for example in atomic check functions.
754 */
755#define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
756 for ((__i) = 0; \
757 (__i) < (__state)->dev->mode_config.num_total_plane; \
758 (__i)++) \
759 for_each_if ((__state)->planes[__i].ptr && \
760 ((plane) = (__state)->planes[__i].ptr, \
761 (old_plane_state) = (__state)->planes[__i].old_state,\
762 (new_plane_state) = (__state)->planes[__i].new_state, 1))
763
764/**
765 * for_each_oldnew_plane_in_state_reverse - iterate over all planes in an atomic
766 * update in reverse order
767 * @__state: &struct drm_atomic_state pointer
768 * @plane: &struct drm_plane iteration cursor
769 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
770 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
771 * @__i: int iteration cursor, for macro-internal use
772 *
773 * This iterates over all planes in an atomic update in reverse order,
774 * tracking both old and new state. This is useful in places where the
775 * state delta needs to be considered, for example in atomic check functions.
776 */
777#define for_each_oldnew_plane_in_state_reverse(__state, plane, old_plane_state, new_plane_state, __i) \
778 for ((__i) = ((__state)->dev->mode_config.num_total_plane - 1); \
779 (__i) >= 0; \
780 (__i)--) \
781 for_each_if ((__state)->planes[__i].ptr && \
782 ((plane) = (__state)->planes[__i].ptr, \
783 (old_plane_state) = (__state)->planes[__i].old_state,\
784 (new_plane_state) = (__state)->planes[__i].new_state, 1))
785
786/**
787 * for_each_old_plane_in_state - iterate over all planes in an atomic update
788 * @__state: &struct drm_atomic_state pointer
789 * @plane: &struct drm_plane iteration cursor
790 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
791 * @__i: int iteration cursor, for macro-internal use
792 *
793 * This iterates over all planes in an atomic update, tracking only the old
794 * state. This is useful in disable functions, where we need the old state the
795 * hardware is still in.
796 */
797#define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
798 for ((__i) = 0; \
799 (__i) < (__state)->dev->mode_config.num_total_plane; \
800 (__i)++) \
801 for_each_if ((__state)->planes[__i].ptr && \
802 ((plane) = (__state)->planes[__i].ptr, \
803 (old_plane_state) = (__state)->planes[__i].old_state, 1))
804/**
805 * for_each_new_plane_in_state - iterate over all planes in an atomic update
806 * @__state: &struct drm_atomic_state pointer
807 * @plane: &struct drm_plane iteration cursor
808 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
809 * @__i: int iteration cursor, for macro-internal use
810 *
811 * This iterates over all planes in an atomic update, tracking only the new
812 * state. This is useful in enable functions, where we need the new state the
813 * hardware should be in when the atomic commit operation has completed.
814 */
815#define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
816 for ((__i) = 0; \
817 (__i) < (__state)->dev->mode_config.num_total_plane; \
818 (__i)++) \
819 for_each_if ((__state)->planes[__i].ptr && \
820 ((plane) = (__state)->planes[__i].ptr, \
821 (new_plane_state) = (__state)->planes[__i].new_state, 1))
822
823/**
824 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
825 * @__state: &struct drm_atomic_state pointer
826 * @obj: &struct drm_private_obj iteration cursor
827 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
828 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
829 * @__i: int iteration cursor, for macro-internal use
830 *
831 * This iterates over all private objects in an atomic update, tracking both
832 * old and new state. This is useful in places where the state delta needs
833 * to be considered, for example in atomic check functions.
834 */
835#define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
836 for ((__i) = 0; \
837 (__i) < (__state)->num_private_objs && \
838 ((obj) = (__state)->private_objs[__i].ptr, \
839 (old_obj_state) = (__state)->private_objs[__i].old_state, \
840 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
841 (__i)++)
842
843/**
844 * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
845 * @__state: &struct drm_atomic_state pointer
846 * @obj: &struct drm_private_obj iteration cursor
847 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
848 * @__i: int iteration cursor, for macro-internal use
849 *
850 * This iterates over all private objects in an atomic update, tracking only
851 * the old state. This is useful in disable functions, where we need the old
852 * state the hardware is still in.
853 */
854#define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
855 for ((__i) = 0; \
856 (__i) < (__state)->num_private_objs && \
857 ((obj) = (__state)->private_objs[__i].ptr, \
858 (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
859 (__i)++)
860
861/**
862 * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
863 * @__state: &struct drm_atomic_state pointer
864 * @obj: &struct drm_private_obj iteration cursor
865 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
866 * @__i: int iteration cursor, for macro-internal use
867 *
868 * This iterates over all private objects in an atomic update, tracking only
869 * the new state. This is useful in enable functions, where we need the new state the
870 * hardware should be in when the atomic commit operation has completed.
871 */
872#define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
873 for ((__i) = 0; \
874 (__i) < (__state)->num_private_objs && \
875 ((obj) = (__state)->private_objs[__i].ptr, \
876 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
877 (__i)++)
878
879/**
880 * drm_atomic_crtc_needs_modeset - compute combined modeset need
881 * @state: &drm_crtc_state for the CRTC
882 *
883 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
884 * whether the state CRTC changed enough to need a full modeset cycle:
885 * mode_changed, active_changed and connectors_changed. This helper simply
886 * combines these three to compute the overall need for a modeset for @state.
887 *
888 * The atomic helper code sets these booleans, but drivers can and should
889 * change them appropriately to accurately represent whether a modeset is
890 * really needed. In general, drivers should avoid full modesets whenever
891 * possible.
892 *
893 * For example if the CRTC mode has changed, and the hardware is able to enact
894 * the requested mode change without going through a full modeset, the driver
895 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
896 * implementation.
897 */
898static inline bool
899drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
900{
901 return state->mode_changed || state->active_changed ||
902 state->connectors_changed;
903}
904
905#endif /* DRM_ATOMIC_H_ */