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