]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/drm/drm_atomic.h
x86/apic/msi: Plug non-maskable MSI affinity race
[mirror_ubuntu-bionic-kernel.git] / include / drm / drm_atomic.h
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 */
69 struct 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
148 struct __drm_planes_state {
149 struct drm_plane *ptr;
150 struct drm_plane_state *state, *old_state, *new_state;
151 };
152
153 struct __drm_crtcs_state {
154 struct drm_crtc *ptr;
155 struct drm_crtc_state *state, *old_state, *new_state;
156
157 /**
158 * @commit:
159 *
160 * A reference to the CRTC commit object that is kept for use by
161 * drm_atomic_helper_wait_for_flip_done() after
162 * drm_atomic_helper_commit_hw_done() is called. This ensures that a
163 * concurrent commit won't free a commit object that is still in use.
164 */
165 struct drm_crtc_commit *commit;
166
167 s32 __user *out_fence_ptr;
168 unsigned last_vblank_count;
169 };
170
171 struct __drm_connnectors_state {
172 struct drm_connector *ptr;
173 struct drm_connector_state *state, *old_state, *new_state;
174 };
175
176 struct drm_private_obj;
177 struct drm_private_state;
178
179 /**
180 * struct drm_private_state_funcs - atomic state functions for private objects
181 *
182 * These hooks are used by atomic helpers to create, swap and destroy states of
183 * private objects. The structure itself is used as a vtable to identify the
184 * associated private object type. Each private object type that needs to be
185 * added to the atomic states is expected to have an implementation of these
186 * hooks and pass a pointer to it's drm_private_state_funcs struct to
187 * drm_atomic_get_private_obj_state().
188 */
189 struct drm_private_state_funcs {
190 /**
191 * @atomic_duplicate_state:
192 *
193 * Duplicate the current state of the private object and return it. It
194 * is an error to call this before obj->state has been initialized.
195 *
196 * RETURNS:
197 *
198 * Duplicated atomic state or NULL when obj->state is not
199 * initialized or allocation failed.
200 */
201 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
202
203 /**
204 * @atomic_destroy_state:
205 *
206 * Frees the private object state created with @atomic_duplicate_state.
207 */
208 void (*atomic_destroy_state)(struct drm_private_obj *obj,
209 struct drm_private_state *state);
210 };
211
212 struct drm_private_obj {
213 struct drm_private_state *state;
214
215 const struct drm_private_state_funcs *funcs;
216 };
217
218 struct drm_private_state {
219 struct drm_atomic_state *state;
220 };
221
222 struct __drm_private_objs_state {
223 struct drm_private_obj *ptr;
224 struct drm_private_state *state, *old_state, *new_state;
225 };
226
227 /**
228 * struct drm_atomic_state - the global state object for atomic updates
229 * @ref: count of all references to this state (will not be freed until zero)
230 * @dev: parent DRM device
231 * @allow_modeset: allow full modeset
232 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
233 * @async_update: hint for asynchronous plane update
234 * @planes: pointer to array of structures with per-plane data
235 * @crtcs: pointer to array of CRTC pointers
236 * @num_connector: size of the @connectors and @connector_states arrays
237 * @connectors: pointer to array of structures with per-connector data
238 * @num_private_objs: size of the @private_objs array
239 * @private_objs: pointer to array of private object pointers
240 * @acquire_ctx: acquire context for this atomic modeset state update
241 */
242 struct drm_atomic_state {
243 struct kref ref;
244
245 struct drm_device *dev;
246 bool allow_modeset : 1;
247 bool legacy_cursor_update : 1;
248 bool async_update : 1;
249 struct __drm_planes_state *planes;
250 struct __drm_crtcs_state *crtcs;
251 int num_connector;
252 struct __drm_connnectors_state *connectors;
253 int num_private_objs;
254 struct __drm_private_objs_state *private_objs;
255
256 struct drm_modeset_acquire_ctx *acquire_ctx;
257
258 /**
259 * @fake_commit:
260 *
261 * Used for signaling unbound planes/connectors.
262 * When a connector or plane is not bound to any CRTC, it's still important
263 * to preserve linearity to prevent the atomic states from being freed to early.
264 *
265 * This commit (if set) is not bound to any crtc, but will be completed when
266 * drm_atomic_helper_commit_hw_done() is called.
267 */
268 struct drm_crtc_commit *fake_commit;
269
270 /**
271 * @commit_work:
272 *
273 * Work item which can be used by the driver or helpers to execute the
274 * commit without blocking.
275 */
276 struct work_struct commit_work;
277 };
278
279 void __drm_crtc_commit_free(struct kref *kref);
280
281 /**
282 * drm_crtc_commit_get - acquire a reference to the CRTC commit
283 * @commit: CRTC commit
284 *
285 * Increases the reference of @commit.
286 *
287 * Returns:
288 * The pointer to @commit, with reference increased.
289 */
290 static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
291 {
292 kref_get(&commit->ref);
293 return commit;
294 }
295
296 /**
297 * drm_crtc_commit_put - release a reference to the CRTC commmit
298 * @commit: CRTC commit
299 *
300 * This releases a reference to @commit which is freed after removing the
301 * final reference. No locking required and callable from any context.
302 */
303 static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
304 {
305 kref_put(&commit->ref, __drm_crtc_commit_free);
306 }
307
308 struct drm_atomic_state * __must_check
309 drm_atomic_state_alloc(struct drm_device *dev);
310 void drm_atomic_state_clear(struct drm_atomic_state *state);
311
312 /**
313 * drm_atomic_state_get - acquire a reference to the atomic state
314 * @state: The atomic state
315 *
316 * Returns a new reference to the @state
317 */
318 static inline struct drm_atomic_state *
319 drm_atomic_state_get(struct drm_atomic_state *state)
320 {
321 kref_get(&state->ref);
322 return state;
323 }
324
325 void __drm_atomic_state_free(struct kref *ref);
326
327 /**
328 * drm_atomic_state_put - release a reference to the atomic state
329 * @state: The atomic state
330 *
331 * This releases a reference to @state which is freed after removing the
332 * final reference. No locking required and callable from any context.
333 */
334 static inline void drm_atomic_state_put(struct drm_atomic_state *state)
335 {
336 kref_put(&state->ref, __drm_atomic_state_free);
337 }
338
339 int __must_check
340 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
341 void drm_atomic_state_default_clear(struct drm_atomic_state *state);
342 void drm_atomic_state_default_release(struct drm_atomic_state *state);
343
344 struct drm_crtc_state * __must_check
345 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
346 struct drm_crtc *crtc);
347 int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
348 struct drm_crtc_state *state, struct drm_property *property,
349 uint64_t val);
350 struct drm_plane_state * __must_check
351 drm_atomic_get_plane_state(struct drm_atomic_state *state,
352 struct drm_plane *plane);
353 struct drm_connector_state * __must_check
354 drm_atomic_get_connector_state(struct drm_atomic_state *state,
355 struct drm_connector *connector);
356
357 void drm_atomic_private_obj_init(struct drm_private_obj *obj,
358 struct drm_private_state *state,
359 const struct drm_private_state_funcs *funcs);
360 void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
361
362 struct drm_private_state * __must_check
363 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
364 struct drm_private_obj *obj);
365
366 /**
367 * drm_atomic_get_existing_crtc_state - get crtc state, if it exists
368 * @state: global atomic state object
369 * @crtc: crtc to grab
370 *
371 * This function returns the crtc state for the given crtc, or NULL
372 * if the crtc is not part of the global atomic state.
373 *
374 * This function is deprecated, @drm_atomic_get_old_crtc_state or
375 * @drm_atomic_get_new_crtc_state should be used instead.
376 */
377 static inline struct drm_crtc_state *
378 drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
379 struct drm_crtc *crtc)
380 {
381 return state->crtcs[drm_crtc_index(crtc)].state;
382 }
383
384 /**
385 * drm_atomic_get_old_crtc_state - get old crtc state, if it exists
386 * @state: global atomic state object
387 * @crtc: crtc to grab
388 *
389 * This function returns the old crtc state for the given crtc, or
390 * NULL if the crtc is not part of the global atomic state.
391 */
392 static inline struct drm_crtc_state *
393 drm_atomic_get_old_crtc_state(struct drm_atomic_state *state,
394 struct drm_crtc *crtc)
395 {
396 return state->crtcs[drm_crtc_index(crtc)].old_state;
397 }
398 /**
399 * drm_atomic_get_new_crtc_state - get new crtc state, if it exists
400 * @state: global atomic state object
401 * @crtc: crtc to grab
402 *
403 * This function returns the new crtc state for the given crtc, or
404 * NULL if the crtc is not part of the global atomic state.
405 */
406 static inline struct drm_crtc_state *
407 drm_atomic_get_new_crtc_state(struct drm_atomic_state *state,
408 struct drm_crtc *crtc)
409 {
410 return state->crtcs[drm_crtc_index(crtc)].new_state;
411 }
412
413 /**
414 * drm_atomic_get_existing_plane_state - get plane state, if it exists
415 * @state: global atomic state object
416 * @plane: plane to grab
417 *
418 * This function returns the plane state for the given plane, or NULL
419 * if the plane is not part of the global atomic state.
420 *
421 * This function is deprecated, @drm_atomic_get_old_plane_state or
422 * @drm_atomic_get_new_plane_state should be used instead.
423 */
424 static inline struct drm_plane_state *
425 drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
426 struct drm_plane *plane)
427 {
428 return state->planes[drm_plane_index(plane)].state;
429 }
430
431 /**
432 * drm_atomic_get_old_plane_state - get plane state, if it exists
433 * @state: global atomic state object
434 * @plane: plane to grab
435 *
436 * This function returns the old plane state for the given plane, or
437 * NULL if the plane is not part of the global atomic state.
438 */
439 static inline struct drm_plane_state *
440 drm_atomic_get_old_plane_state(struct drm_atomic_state *state,
441 struct drm_plane *plane)
442 {
443 return state->planes[drm_plane_index(plane)].old_state;
444 }
445
446 /**
447 * drm_atomic_get_new_plane_state - get plane state, if it exists
448 * @state: global atomic state object
449 * @plane: plane to grab
450 *
451 * This function returns the new plane state for the given plane, or
452 * NULL if the plane is not part of the global atomic state.
453 */
454 static inline struct drm_plane_state *
455 drm_atomic_get_new_plane_state(struct drm_atomic_state *state,
456 struct drm_plane *plane)
457 {
458 return state->planes[drm_plane_index(plane)].new_state;
459 }
460
461 /**
462 * drm_atomic_get_existing_connector_state - get connector state, if it exists
463 * @state: global atomic state object
464 * @connector: connector to grab
465 *
466 * This function returns the connector state for the given connector,
467 * or NULL if the connector is not part of the global atomic state.
468 *
469 * This function is deprecated, @drm_atomic_get_old_connector_state or
470 * @drm_atomic_get_new_connector_state should be used instead.
471 */
472 static inline struct drm_connector_state *
473 drm_atomic_get_existing_connector_state(struct drm_atomic_state *state,
474 struct drm_connector *connector)
475 {
476 int index = drm_connector_index(connector);
477
478 if (index >= state->num_connector)
479 return NULL;
480
481 return state->connectors[index].state;
482 }
483
484 /**
485 * drm_atomic_get_old_connector_state - get connector state, if it exists
486 * @state: global atomic state object
487 * @connector: connector to grab
488 *
489 * This function returns the old connector state for the given connector,
490 * or NULL if the connector is not part of the global atomic state.
491 */
492 static inline struct drm_connector_state *
493 drm_atomic_get_old_connector_state(struct drm_atomic_state *state,
494 struct drm_connector *connector)
495 {
496 int index = drm_connector_index(connector);
497
498 if (index >= state->num_connector)
499 return NULL;
500
501 return state->connectors[index].old_state;
502 }
503
504 /**
505 * drm_atomic_get_new_connector_state - get connector state, if it exists
506 * @state: global atomic state object
507 * @connector: connector to grab
508 *
509 * This function returns the new connector state for the given connector,
510 * or NULL if the connector is not part of the global atomic state.
511 */
512 static inline struct drm_connector_state *
513 drm_atomic_get_new_connector_state(struct drm_atomic_state *state,
514 struct drm_connector *connector)
515 {
516 int index = drm_connector_index(connector);
517
518 if (index >= state->num_connector)
519 return NULL;
520
521 return state->connectors[index].new_state;
522 }
523
524 /**
525 * __drm_atomic_get_current_plane_state - get current plane state
526 * @state: global atomic state object
527 * @plane: plane to grab
528 *
529 * This function returns the plane state for the given plane, either from
530 * @state, or if the plane isn't part of the atomic state update, from @plane.
531 * This is useful in atomic check callbacks, when drivers need to peek at, but
532 * not change, state of other planes, since it avoids threading an error code
533 * back up the call chain.
534 *
535 * WARNING:
536 *
537 * Note that this function is in general unsafe since it doesn't check for the
538 * required locking for access state structures. Drivers must ensure that it is
539 * safe to access the returned state structure through other means. One common
540 * example is when planes are fixed to a single CRTC, and the driver knows that
541 * the CRTC lock is held already. In that case holding the CRTC lock gives a
542 * read-lock on all planes connected to that CRTC. But if planes can be
543 * reassigned things get more tricky. In that case it's better to use
544 * drm_atomic_get_plane_state and wire up full error handling.
545 *
546 * Returns:
547 *
548 * Read-only pointer to the current plane state.
549 */
550 static inline const struct drm_plane_state *
551 __drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
552 struct drm_plane *plane)
553 {
554 if (state->planes[drm_plane_index(plane)].state)
555 return state->planes[drm_plane_index(plane)].state;
556
557 return plane->state;
558 }
559
560 int __must_check
561 drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
562 const struct drm_display_mode *mode);
563 int __must_check
564 drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
565 struct drm_property_blob *blob);
566 int __must_check
567 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
568 struct drm_crtc *crtc);
569 void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
570 struct drm_framebuffer *fb);
571 void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
572 struct dma_fence *fence);
573 int __must_check
574 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
575 struct drm_crtc *crtc);
576 int __must_check
577 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
578 struct drm_crtc *crtc);
579 int __must_check
580 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
581 struct drm_crtc *crtc);
582
583 void
584 drm_atomic_clean_old_fb(struct drm_device *dev, unsigned plane_mask, int ret);
585
586 int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
587 int __must_check drm_atomic_commit(struct drm_atomic_state *state);
588 int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
589
590 void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
591
592 /**
593 * for_each_oldnew_connector_in_state - iterate over all connectors in an atomic update
594 * @__state: &struct drm_atomic_state pointer
595 * @connector: &struct drm_connector iteration cursor
596 * @old_connector_state: &struct drm_connector_state iteration cursor for the
597 * old state
598 * @new_connector_state: &struct drm_connector_state iteration cursor for the
599 * new state
600 * @__i: int iteration cursor, for macro-internal use
601 *
602 * This iterates over all connectors in an atomic update, tracking both old and
603 * new state. This is useful in places where the state delta needs to be
604 * considered, for example in atomic check functions.
605 */
606 #define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
607 for ((__i) = 0; \
608 (__i) < (__state)->num_connector; \
609 (__i)++) \
610 for_each_if ((__state)->connectors[__i].ptr && \
611 ((connector) = (__state)->connectors[__i].ptr, \
612 (old_connector_state) = (__state)->connectors[__i].old_state, \
613 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
614
615 /**
616 * for_each_old_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 * @old_connector_state: &struct drm_connector_state iteration cursor for the
620 * old state
621 * @__i: int iteration cursor, for macro-internal use
622 *
623 * This iterates over all connectors in an atomic update, tracking only the old
624 * state. This is useful in disable functions, where we need the old state the
625 * hardware is still in.
626 */
627 #define for_each_old_connector_in_state(__state, connector, old_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 (old_connector_state) = (__state)->connectors[__i].old_state, 1))
634
635 /**
636 * for_each_new_connector_in_state - iterate over all connectors in an atomic update
637 * @__state: &struct drm_atomic_state pointer
638 * @connector: &struct drm_connector iteration cursor
639 * @new_connector_state: &struct drm_connector_state iteration cursor for the
640 * new state
641 * @__i: int iteration cursor, for macro-internal use
642 *
643 * This iterates over all connectors in an atomic update, tracking only the new
644 * state. This is useful in enable functions, where we need the new state the
645 * hardware should be in when the atomic commit operation has completed.
646 */
647 #define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
648 for ((__i) = 0; \
649 (__i) < (__state)->num_connector; \
650 (__i)++) \
651 for_each_if ((__state)->connectors[__i].ptr && \
652 ((connector) = (__state)->connectors[__i].ptr, \
653 (new_connector_state) = (__state)->connectors[__i].new_state, 1))
654
655 /**
656 * for_each_oldnew_crtc_in_state - iterate over all CRTCs in an atomic update
657 * @__state: &struct drm_atomic_state pointer
658 * @crtc: &struct drm_crtc iteration cursor
659 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
660 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
661 * @__i: int iteration cursor, for macro-internal use
662 *
663 * This iterates over all CRTCs in an atomic update, tracking both old and
664 * new state. This is useful in places where the state delta needs to be
665 * considered, for example in atomic check functions.
666 */
667 #define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_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, \
674 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
675
676 /**
677 * for_each_old_crtc_in_state - iterate over all CRTCs in an atomic update
678 * @__state: &struct drm_atomic_state pointer
679 * @crtc: &struct drm_crtc iteration cursor
680 * @old_crtc_state: &struct drm_crtc_state iteration cursor for the old state
681 * @__i: int iteration cursor, for macro-internal use
682 *
683 * This iterates over all CRTCs in an atomic update, tracking only the old
684 * state. This is useful in disable functions, where we need the old state the
685 * hardware is still in.
686 */
687 #define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
688 for ((__i) = 0; \
689 (__i) < (__state)->dev->mode_config.num_crtc; \
690 (__i)++) \
691 for_each_if ((__state)->crtcs[__i].ptr && \
692 ((crtc) = (__state)->crtcs[__i].ptr, \
693 (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
694
695 /**
696 * for_each_new_crtc_in_state - iterate over all CRTCs in an atomic update
697 * @__state: &struct drm_atomic_state pointer
698 * @crtc: &struct drm_crtc iteration cursor
699 * @new_crtc_state: &struct drm_crtc_state iteration cursor for the new state
700 * @__i: int iteration cursor, for macro-internal use
701 *
702 * This iterates over all CRTCs in an atomic update, tracking only the new
703 * state. This is useful in enable functions, where we need the new state the
704 * hardware should be in when the atomic commit operation has completed.
705 */
706 #define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
707 for ((__i) = 0; \
708 (__i) < (__state)->dev->mode_config.num_crtc; \
709 (__i)++) \
710 for_each_if ((__state)->crtcs[__i].ptr && \
711 ((crtc) = (__state)->crtcs[__i].ptr, \
712 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
713
714 /**
715 * for_each_oldnew_plane_in_state - iterate over all planes in an atomic update
716 * @__state: &struct drm_atomic_state pointer
717 * @plane: &struct drm_plane iteration cursor
718 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
719 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
720 * @__i: int iteration cursor, for macro-internal use
721 *
722 * This iterates over all planes in an atomic update, tracking both old and
723 * new state. This is useful in places where the state delta needs to be
724 * considered, for example in atomic check functions.
725 */
726 #define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_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,\
733 (new_plane_state) = (__state)->planes[__i].new_state, 1))
734
735 /**
736 * for_each_old_plane_in_state - iterate over all planes in an atomic update
737 * @__state: &struct drm_atomic_state pointer
738 * @plane: &struct drm_plane iteration cursor
739 * @old_plane_state: &struct drm_plane_state iteration cursor for the old state
740 * @__i: int iteration cursor, for macro-internal use
741 *
742 * This iterates over all planes in an atomic update, tracking only the old
743 * state. This is useful in disable functions, where we need the old state the
744 * hardware is still in.
745 */
746 #define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
747 for ((__i) = 0; \
748 (__i) < (__state)->dev->mode_config.num_total_plane; \
749 (__i)++) \
750 for_each_if ((__state)->planes[__i].ptr && \
751 ((plane) = (__state)->planes[__i].ptr, \
752 (old_plane_state) = (__state)->planes[__i].old_state, 1))
753 /**
754 * for_each_new_plane_in_state - iterate over all planes in an atomic update
755 * @__state: &struct drm_atomic_state pointer
756 * @plane: &struct drm_plane iteration cursor
757 * @new_plane_state: &struct drm_plane_state iteration cursor for the new state
758 * @__i: int iteration cursor, for macro-internal use
759 *
760 * This iterates over all planes in an atomic update, tracking only the new
761 * state. This is useful in enable functions, where we need the new state the
762 * hardware should be in when the atomic commit operation has completed.
763 */
764 #define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
765 for ((__i) = 0; \
766 (__i) < (__state)->dev->mode_config.num_total_plane; \
767 (__i)++) \
768 for_each_if ((__state)->planes[__i].ptr && \
769 ((plane) = (__state)->planes[__i].ptr, \
770 (new_plane_state) = (__state)->planes[__i].new_state, 1))
771
772 /**
773 * for_each_oldnew_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 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
778 * @__i: int iteration cursor, for macro-internal use
779 *
780 * This iterates over all private objects in an atomic update, tracking both
781 * old and new state. This is useful in places where the state delta needs
782 * to be considered, for example in atomic check functions.
783 */
784 #define for_each_oldnew_private_obj_in_state(__state, obj, old_obj_state, new_obj_state, __i) \
785 for ((__i) = 0; \
786 (__i) < (__state)->num_private_objs && \
787 ((obj) = (__state)->private_objs[__i].ptr, \
788 (old_obj_state) = (__state)->private_objs[__i].old_state, \
789 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
790 (__i)++)
791
792 /**
793 * for_each_old_private_obj_in_state - iterate over all private objects in an atomic update
794 * @__state: &struct drm_atomic_state pointer
795 * @obj: &struct drm_private_obj iteration cursor
796 * @old_obj_state: &struct drm_private_state iteration cursor for the old state
797 * @__i: int iteration cursor, for macro-internal use
798 *
799 * This iterates over all private objects in an atomic update, tracking only
800 * the old state. This is useful in disable functions, where we need the old
801 * state the hardware is still in.
802 */
803 #define for_each_old_private_obj_in_state(__state, obj, old_obj_state, __i) \
804 for ((__i) = 0; \
805 (__i) < (__state)->num_private_objs && \
806 ((obj) = (__state)->private_objs[__i].ptr, \
807 (old_obj_state) = (__state)->private_objs[__i].old_state, 1); \
808 (__i)++)
809
810 /**
811 * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
812 * @__state: &struct drm_atomic_state pointer
813 * @obj: &struct drm_private_obj iteration cursor
814 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
815 * @__i: int iteration cursor, for macro-internal use
816 *
817 * This iterates over all private objects in an atomic update, tracking only
818 * the new state. This is useful in enable functions, where we need the new state the
819 * hardware should be in when the atomic commit operation has completed.
820 */
821 #define for_each_new_private_obj_in_state(__state, obj, new_obj_state, __i) \
822 for ((__i) = 0; \
823 (__i) < (__state)->num_private_objs && \
824 ((obj) = (__state)->private_objs[__i].ptr, \
825 (new_obj_state) = (__state)->private_objs[__i].new_state, 1); \
826 (__i)++)
827
828 /**
829 * drm_atomic_crtc_needs_modeset - compute combined modeset need
830 * @state: &drm_crtc_state for the CRTC
831 *
832 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
833 * whether the state CRTC changed enough to need a full modeset cycle:
834 * mode_changed, active_changed and connectors_changed. This helper simply
835 * combines these three to compute the overall need for a modeset for @state.
836 *
837 * The atomic helper code sets these booleans, but drivers can and should
838 * change them appropriately to accurately represent whether a modeset is
839 * really needed. In general, drivers should avoid full modesets whenever
840 * possible.
841 *
842 * For example if the CRTC mode has changed, and the hardware is able to enact
843 * the requested mode change without going through a full modeset, the driver
844 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
845 * implementation.
846 */
847 static inline bool
848 drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
849 {
850 return state->mode_changed || state->active_changed ||
851 state->connectors_changed;
852 }
853
854 #endif /* DRM_ATOMIC_H_ */