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