arm64: dts: marvell: mcbin: enable uart headers
[linux-2.6-block.git] / include / drm / drm_atomic.h
CommitLineData
cc4ceb48
DV
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
37cc0148
TR
31#include <drm/drm_crtc.h>
32
43968d7b
DV
33/**
34 * struct drm_crtc_commit - track modeset commits on a CRTC
35 *
36 * This structure is used to track pending modeset changes and atomic commit on
37 * a per-CRTC basis. Since updating the list should never block this structure
38 * is reference counted to allow waiters to safely wait on an event to complete,
39 * without holding any locks.
40 *
41 * It has 3 different events in total to allow a fine-grained synchronization
42 * between outstanding updates::
43 *
44 * atomic commit thread hardware
45 *
46 * write new state into hardware ----> ...
47 * signal hw_done
48 * switch to new state on next
49 * ... v/hblank
50 *
51 * wait for buffers to show up ...
52 *
53 * ... send completion irq
54 * irq handler signals flip_done
55 * cleanup old buffers
56 *
57 * signal cleanup_done
58 *
59 * wait for flip_done <----
60 * clean up atomic state
61 *
62 * The important bit to know is that cleanup_done is the terminal event, but the
63 * ordering between flip_done and hw_done is entirely up to the specific driver
64 * and modeset state change.
65 *
66 * For an implementation of how to use this look at
67 * drm_atomic_helper_setup_commit() from the atomic helper library.
68 */
69struct drm_crtc_commit {
70 /**
71 * @crtc:
72 *
73 * DRM CRTC for this commit.
74 */
75 struct drm_crtc *crtc;
76
77 /**
78 * @ref:
79 *
80 * Reference count for this structure. Needed to allow blocking on
81 * completions without the risk of the completion disappearing
82 * meanwhile.
83 */
84 struct kref ref;
85
86 /**
87 * @flip_done:
88 *
89 * Will be signaled when the hardware has flipped to the new set of
90 * buffers. Signals at the same time as when the drm event for this
91 * commit is sent to userspace, or when an out-fence is singalled. Note
92 * that for most hardware, in most cases this happens after @hw_done is
93 * signalled.
94 */
95 struct completion flip_done;
96
97 /**
98 * @hw_done:
99 *
100 * Will be signalled when all hw register changes for this commit have
101 * been written out. Especially when disabling a pipe this can be much
102 * later than than @flip_done, since that can signal already when the
103 * screen goes black, whereas to fully shut down a pipe more register
104 * I/O is required.
105 *
106 * Note that this does not need to include separately reference-counted
107 * resources like backing storage buffer pinning, or runtime pm
108 * management.
109 */
110 struct completion hw_done;
111
112 /**
113 * @cleanup_done:
114 *
115 * Will be signalled after old buffers have been cleaned up by calling
116 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
117 * a vblank wait completed it might be a bit later. This completion is
118 * useful to throttle updates and avoid hardware updates getting ahead
119 * of the buffer cleanup too much.
120 */
121 struct completion cleanup_done;
122
123 /**
124 * @commit_entry:
125 *
d574528a
DV
126 * Entry on the per-CRTC &drm_crtc.commit_list. Protected by
127 * $drm_crtc.commit_lock.
43968d7b
DV
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
139struct __drm_planes_state {
140 struct drm_plane *ptr;
581e49fe 141 struct drm_plane_state *state, *old_state, *new_state;
43968d7b
DV
142};
143
144struct __drm_crtcs_state {
145 struct drm_crtc *ptr;
581e49fe 146 struct drm_crtc_state *state, *old_state, *new_state;
7e9081c5 147 s32 __user *out_fence_ptr;
bdc57146 148 unsigned last_vblank_count;
43968d7b
DV
149};
150
151struct __drm_connnectors_state {
152 struct drm_connector *ptr;
581e49fe 153 struct drm_connector_state *state, *old_state, *new_state;
43968d7b
DV
154};
155
a4370c77
VS
156struct drm_private_obj;
157struct drm_private_state;
158
b430c27a
PD
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 */
169struct drm_private_state_funcs {
170 /**
a4370c77 171 * @atomic_duplicate_state:
b430c27a
PD
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 */
a4370c77 181 struct drm_private_state *(*atomic_duplicate_state)(struct drm_private_obj *obj);
b430c27a
PD
182
183 /**
a4370c77 184 * @atomic_destroy_state:
b430c27a 185 *
a4370c77 186 * Frees the private object state created with @atomic_duplicate_state.
b430c27a 187 */
a4370c77
VS
188 void (*atomic_destroy_state)(struct drm_private_obj *obj,
189 struct drm_private_state *state);
190};
b430c27a 191
da6c0596
DV
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 */
a4370c77 203struct drm_private_obj {
da6c0596
DV
204 /**
205 * @state: Current atomic state for this driver private object.
206 */
a4370c77
VS
207 struct drm_private_state *state;
208
da6c0596
DV
209 /**
210 * @funcs:
211 *
212 * Functions to manipulate the state of this driver private object, see
213 * &drm_private_state_funcs.
214 */
a4370c77
VS
215 const struct drm_private_state_funcs *funcs;
216};
217
da6c0596
DV
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 */
a4370c77
VS
226struct drm_private_state {
227 struct drm_atomic_state *state;
b430c27a
PD
228};
229
230struct __drm_private_objs_state {
a4370c77
VS
231 struct drm_private_obj *ptr;
232 struct drm_private_state *state, *old_state, *new_state;
b430c27a
PD
233};
234
43968d7b
DV
235/**
236 * struct drm_atomic_state - the global state object for atomic updates
0853695c 237 * @ref: count of all references to this state (will not be freed until zero)
43968d7b
DV
238 * @dev: parent DRM device
239 * @allow_modeset: allow full modeset
240 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
fef9df8b 241 * @async_update: hint for asynchronous plane update
43968d7b
DV
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
b430c27a
PD
246 * @num_private_objs: size of the @private_objs array
247 * @private_objs: pointer to array of private object pointers
43968d7b 248 * @acquire_ctx: acquire context for this atomic modeset state update
5fca5ece
DV
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().
43968d7b
DV
253 */
254struct drm_atomic_state {
0853695c
CW
255 struct kref ref;
256
43968d7b
DV
257 struct drm_device *dev;
258 bool allow_modeset : 1;
259 bool legacy_cursor_update : 1;
fef9df8b 260 bool async_update : 1;
43968d7b
DV
261 struct __drm_planes_state *planes;
262 struct __drm_crtcs_state *crtcs;
263 int num_connector;
264 struct __drm_connnectors_state *connectors;
b430c27a
PD
265 int num_private_objs;
266 struct __drm_private_objs_state *private_objs;
43968d7b
DV
267
268 struct drm_modeset_acquire_ctx *acquire_ctx;
269
21a01abb
ML
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
43968d7b
DV
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
b3ba3f6f
DV
291void __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.
f46640b9
ML
298 *
299 * Returns:
300 * The pointer to @commit, with reference increased.
b3ba3f6f 301 */
f46640b9 302static inline struct drm_crtc_commit *drm_crtc_commit_get(struct drm_crtc_commit *commit)
3b24f7d6
DV
303{
304 kref_get(&commit->ref);
f46640b9 305 return commit;
3b24f7d6
DV
306}
307
b3ba3f6f
DV
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 */
315static inline void drm_crtc_commit_put(struct drm_crtc_commit *commit)
316{
317 kref_put(&commit->ref, __drm_crtc_commit_free);
318}
319
cc4ceb48
DV
320struct drm_atomic_state * __must_check
321drm_atomic_state_alloc(struct drm_device *dev);
322void drm_atomic_state_clear(struct drm_atomic_state *state);
0853695c
CW
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 */
330static inline struct drm_atomic_state *
331drm_atomic_state_get(struct drm_atomic_state *state)
332{
333 kref_get(&state->ref);
334 return state;
335}
336
337void __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 */
346static inline void drm_atomic_state_put(struct drm_atomic_state *state)
347{
348 kref_put(&state->ref, __drm_atomic_state_free);
349}
036ef573
ML
350
351int __must_check
352drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state);
353void drm_atomic_state_default_clear(struct drm_atomic_state *state);
354void drm_atomic_state_default_release(struct drm_atomic_state *state);
cc4ceb48
DV
355
356struct drm_crtc_state * __must_check
357drm_atomic_get_crtc_state(struct drm_atomic_state *state,
358 struct drm_crtc *crtc);
40ecc694
RC
359int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
360 struct drm_crtc_state *state, struct drm_property *property,
361 uint64_t val);
cc4ceb48
DV
362struct drm_plane_state * __must_check
363drm_atomic_get_plane_state(struct drm_atomic_state *state,
364 struct drm_plane *plane);
365struct drm_connector_state * __must_check
366drm_atomic_get_connector_state(struct drm_atomic_state *state,
367 struct drm_connector *connector);
88a48e29 368
a4370c77
VS
369void drm_atomic_private_obj_init(struct drm_private_obj *obj,
370 struct drm_private_state *state,
371 const struct drm_private_state_funcs *funcs);
372void drm_atomic_private_obj_fini(struct drm_private_obj *obj);
373
374struct drm_private_state * __must_check
b430c27a 375drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
a4370c77 376 struct drm_private_obj *obj);
b430c27a 377
1b26a5e1
ML
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.
2107777c
ML
385 *
386 * This function is deprecated, @drm_atomic_get_old_crtc_state or
387 * @drm_atomic_get_new_crtc_state should be used instead.
1b26a5e1
ML
388 */
389static inline struct drm_crtc_state *
390drm_atomic_get_existing_crtc_state(struct drm_atomic_state *state,
391 struct drm_crtc *crtc)
392{
5d943aa6 393 return state->crtcs[drm_crtc_index(crtc)].state;
1b26a5e1
ML
394}
395
2107777c
ML
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 */
404static inline struct drm_crtc_state *
405drm_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 */
418static inline struct drm_crtc_state *
419drm_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
1b26a5e1
ML
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.
2107777c
ML
432 *
433 * This function is deprecated, @drm_atomic_get_old_plane_state or
434 * @drm_atomic_get_new_plane_state should be used instead.
1b26a5e1
ML
435 */
436static inline struct drm_plane_state *
437drm_atomic_get_existing_plane_state(struct drm_atomic_state *state,
438 struct drm_plane *plane)
439{
b8b5342b 440 return state->planes[drm_plane_index(plane)].state;
1b26a5e1
ML
441}
442
2107777c
ML
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 */
451static inline struct drm_plane_state *
452drm_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 */
466static inline struct drm_plane_state *
467drm_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
1b26a5e1
ML
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.
2107777c
ML
480 *
481 * This function is deprecated, @drm_atomic_get_old_connector_state or
482 * @drm_atomic_get_new_connector_state should be used instead.
1b26a5e1
ML
483 */
484static inline struct drm_connector_state *
485drm_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
63e83c1d 493 return state->connectors[index].state;
1b26a5e1
ML
494}
495
2107777c
ML
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 */
504static inline struct drm_connector_state *
505drm_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 */
524static inline struct drm_connector_state *
525drm_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
2f196b7c
DV
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
60c9e190 551 * safe to access the returned state structure through other means. One common
2f196b7c 552 * example is when planes are fixed to a single CRTC, and the driver knows that
60c9e190 553 * the CRTC lock is held already. In that case holding the CRTC lock gives a
2f196b7c
DV
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 */
562static inline const struct drm_plane_state *
563__drm_atomic_get_current_plane_state(struct drm_atomic_state *state,
564 struct drm_plane *plane)
565{
b8b5342b
DV
566 if (state->planes[drm_plane_index(plane)].state)
567 return state->planes[drm_plane_index(plane)].state;
2f196b7c
DV
568
569 return plane->state;
570}
571
819364da
DS
572int __must_check
573drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
91110a4b 574 const struct drm_display_mode *mode);
cc4ceb48 575int __must_check
955f3c33
DS
576drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
577 struct drm_property_blob *blob);
578int __must_check
07cc0ef6
DV
579drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
580 struct drm_crtc *crtc);
321ebf04
DV
581void drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
582 struct drm_framebuffer *fb);
13b55664
GP
583void drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
584 struct dma_fence *fence);
cc4ceb48
DV
585int __must_check
586drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
587 struct drm_crtc *crtc);
588int __must_check
589drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
590 struct drm_crtc *crtc);
e01e9f75
ML
591int __must_check
592drm_atomic_add_affected_planes(struct drm_atomic_state *state,
593 struct drm_crtc *crtc);
594
0f45c26f
ML
595void
596drm_atomic_clean_old_fb(struct drm_device *dev, unsigned plane_mask, int ret);
597
cc4ceb48
DV
598int __must_check drm_atomic_check_only(struct drm_atomic_state *state);
599int __must_check drm_atomic_commit(struct drm_atomic_state *state);
b837ba0a 600int __must_check drm_atomic_nonblocking_commit(struct drm_atomic_state *state);
cc4ceb48 601
6559c901
RC
602void drm_state_dump(struct drm_device *dev, struct drm_printer *p);
603
f9a76955
DV
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 */
581e49fe
ML
618#define for_each_oldnew_connector_in_state(__state, connector, old_connector_state, new_connector_state, __i) \
619 for ((__i) = 0; \
331494eb
ML
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))
581e49fe 626
f9a76955
DV
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 */
581e49fe
ML
639#define for_each_old_connector_in_state(__state, connector, old_connector_state, __i) \
640 for ((__i) = 0; \
331494eb
ML
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))
581e49fe 646
f9a76955
DV
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 */
581e49fe
ML
659#define for_each_new_connector_in_state(__state, connector, new_connector_state, __i) \
660 for ((__i) = 0; \
331494eb
ML
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))
581e49fe 666
f9a76955
DV
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 */
581e49fe
ML
679#define for_each_oldnew_crtc_in_state(__state, crtc, old_crtc_state, new_crtc_state, __i) \
680 for ((__i) = 0; \
331494eb 681 (__i) < (__state)->dev->mode_config.num_crtc; \
581e49fe 682 (__i)++) \
331494eb
ML
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))
581e49fe 687
f9a76955
DV
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 */
581e49fe
ML
699#define for_each_old_crtc_in_state(__state, crtc, old_crtc_state, __i) \
700 for ((__i) = 0; \
331494eb 701 (__i) < (__state)->dev->mode_config.num_crtc; \
581e49fe 702 (__i)++) \
331494eb
ML
703 for_each_if ((__state)->crtcs[__i].ptr && \
704 ((crtc) = (__state)->crtcs[__i].ptr, \
705 (old_crtc_state) = (__state)->crtcs[__i].old_state, 1))
581e49fe 706
f9a76955
DV
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 */
581e49fe
ML
718#define for_each_new_crtc_in_state(__state, crtc, new_crtc_state, __i) \
719 for ((__i) = 0; \
331494eb 720 (__i) < (__state)->dev->mode_config.num_crtc; \
581e49fe 721 (__i)++) \
331494eb
ML
722 for_each_if ((__state)->crtcs[__i].ptr && \
723 ((crtc) = (__state)->crtcs[__i].ptr, \
724 (new_crtc_state) = (__state)->crtcs[__i].new_state, 1))
581e49fe 725
f9a76955
DV
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 */
581e49fe
ML
738#define for_each_oldnew_plane_in_state(__state, plane, old_plane_state, new_plane_state, __i) \
739 for ((__i) = 0; \
331494eb 740 (__i) < (__state)->dev->mode_config.num_total_plane; \
581e49fe 741 (__i)++) \
331494eb
ML
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))
581e49fe 746
f9a76955
DV
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 */
581e49fe
ML
758#define for_each_old_plane_in_state(__state, plane, old_plane_state, __i) \
759 for ((__i) = 0; \
331494eb 760 (__i) < (__state)->dev->mode_config.num_total_plane; \
581e49fe 761 (__i)++) \
331494eb
ML
762 for_each_if ((__state)->planes[__i].ptr && \
763 ((plane) = (__state)->planes[__i].ptr, \
764 (old_plane_state) = (__state)->planes[__i].old_state, 1))
f9a76955
DV
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 */
581e49fe
ML
776#define for_each_new_plane_in_state(__state, plane, new_plane_state, __i) \
777 for ((__i) = 0; \
331494eb 778 (__i) < (__state)->dev->mode_config.num_total_plane; \
581e49fe 779 (__i)++) \
331494eb
ML
780 for_each_if ((__state)->planes[__i].ptr && \
781 ((plane) = (__state)->planes[__i].ptr, \
782 (new_plane_state) = (__state)->planes[__i].new_state, 1))
581e49fe 783
b430c27a 784/**
a4370c77 785 * for_each_oldnew_private_obj_in_state - iterate over all private objects in an atomic update
b430c27a 786 * @__state: &struct drm_atomic_state pointer
a4370c77
VS
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
b430c27a 790 * @__i: int iteration cursor, for macro-internal use
b430c27a 791 *
a4370c77
VS
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.
b430c27a 795 */
a4370c77
VS
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); \
f0d2e86c 802 (__i)++)
a4370c77
VS
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); \
f0d2e86c 820 (__i)++)
b430c27a
PD
821
822/**
a4370c77 823 * for_each_new_private_obj_in_state - iterate over all private objects in an atomic update
b430c27a 824 * @__state: &struct drm_atomic_state pointer
a4370c77
VS
825 * @obj: &struct drm_private_obj iteration cursor
826 * @new_obj_state: &struct drm_private_state iteration cursor for the new state
b430c27a 827 * @__i: int iteration cursor, for macro-internal use
b430c27a 828 *
a4370c77
VS
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.
b430c27a 832 */
a4370c77
VS
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); \
f0d2e86c 838 (__i)++)
b430c27a 839
081e9c0f
DV
840/**
841 * drm_atomic_crtc_needs_modeset - compute combined modeset need
842 * @state: &drm_crtc_state for the CRTC
843 *
ea0dd85a 844 * To give drivers flexibility &struct drm_crtc_state has 3 booleans to track
081e9c0f 845 * whether the state CRTC changed enough to need a full modeset cycle:
96bf51df 846 * mode_changed, active_changed and connectors_changed. This helper simply
081e9c0f 847 * combines these three to compute the overall need for a modeset for @state.
d807ed1c
BS
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
d574528a
DV
856 * should clear mode_changed in its &drm_mode_config_funcs.atomic_check
857 * implementation.
081e9c0f 858 */
2465ff62 859static inline bool
79b95552 860drm_atomic_crtc_needs_modeset(const struct drm_crtc_state *state)
2465ff62 861{
fc596660
ML
862 return state->mode_changed || state->active_changed ||
863 state->connectors_changed;
2465ff62
DV
864}
865
cc4ceb48 866#endif /* DRM_ATOMIC_H_ */