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