2 * Copyright (C) 2014 Red Hat
3 * Copyright (C) 2014 Intel Corp.
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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.
24 * Rob Clark <robdclark@gmail.com>
25 * Daniel Vetter <daniel.vetter@ffwll.ch>
29 #include <drm/drm_atomic.h>
30 #include <drm/drm_plane_helper.h>
31 #include <drm/drm_crtc_helper.h>
32 #include <drm/drm_atomic_helper.h>
33 #include <linux/dma-fence.h>
35 #include "drm_crtc_helper_internal.h"
36 #include "drm_crtc_internal.h"
41 * This helper library provides implementations of check and commit functions on
42 * top of the CRTC modeset helper callbacks and the plane helper callbacks. It
43 * also provides convenience implementations for the atomic state handling
44 * callbacks for drivers which don't need to subclass the drm core structures to
45 * add their own additional internal state.
47 * This library also provides default implementations for the check callback in
48 * drm_atomic_helper_check() and for the commit callback with
49 * drm_atomic_helper_commit(). But the individual stages and callbacks are
50 * exposed to allow drivers to mix and match and e.g. use the plane helpers only
51 * together with a driver private modeset implementation.
53 * This library also provides implementations for all the legacy driver
54 * interfaces on top of the atomic interface. See drm_atomic_helper_set_config(),
55 * drm_atomic_helper_disable_plane(), drm_atomic_helper_disable_plane() and the
56 * various functions to implement set_property callbacks. New drivers must not
57 * implement these functions themselves but must use the provided helpers.
59 * The atomic helper uses the same function table structures as all other
60 * modesetting helpers. See the documentation for &struct drm_crtc_helper_funcs,
61 * struct &drm_encoder_helper_funcs and &struct drm_connector_helper_funcs. It
62 * also shares the &struct drm_plane_helper_funcs function table with the plane
66 drm_atomic_helper_plane_changed(struct drm_atomic_state
*state
,
67 struct drm_plane_state
*old_plane_state
,
68 struct drm_plane_state
*plane_state
,
69 struct drm_plane
*plane
)
71 struct drm_crtc_state
*crtc_state
;
73 if (old_plane_state
->crtc
) {
74 crtc_state
= drm_atomic_get_new_crtc_state(state
,
75 old_plane_state
->crtc
);
77 if (WARN_ON(!crtc_state
))
80 crtc_state
->planes_changed
= true;
83 if (plane_state
->crtc
) {
84 crtc_state
= drm_atomic_get_new_crtc_state(state
, plane_state
->crtc
);
86 if (WARN_ON(!crtc_state
))
89 crtc_state
->planes_changed
= true;
93 static int handle_conflicting_encoders(struct drm_atomic_state
*state
,
94 bool disable_conflicting_encoders
)
96 struct drm_connector_state
*new_conn_state
;
97 struct drm_connector
*connector
;
98 struct drm_connector_list_iter conn_iter
;
99 struct drm_encoder
*encoder
;
100 unsigned encoder_mask
= 0;
104 * First loop, find all newly assigned encoders from the connectors
105 * part of the state. If the same encoder is assigned to multiple
106 * connectors bail out.
108 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
109 const struct drm_connector_helper_funcs
*funcs
= connector
->helper_private
;
110 struct drm_encoder
*new_encoder
;
112 if (!new_conn_state
->crtc
)
115 if (funcs
->atomic_best_encoder
)
116 new_encoder
= funcs
->atomic_best_encoder(connector
, new_conn_state
);
117 else if (funcs
->best_encoder
)
118 new_encoder
= funcs
->best_encoder(connector
);
120 new_encoder
= drm_atomic_helper_best_encoder(connector
);
123 if (encoder_mask
& (1 << drm_encoder_index(new_encoder
))) {
124 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n",
125 new_encoder
->base
.id
, new_encoder
->name
,
126 connector
->base
.id
, connector
->name
);
131 encoder_mask
|= 1 << drm_encoder_index(new_encoder
);
139 * Second loop, iterate over all connectors not part of the state.
141 * If a conflicting encoder is found and disable_conflicting_encoders
142 * is not set, an error is returned. Userspace can provide a solution
143 * through the atomic ioctl.
145 * If the flag is set conflicting connectors are removed from the crtc
146 * and the crtc is disabled if no encoder is left. This preserves
147 * compatibility with the legacy set_config behavior.
149 drm_connector_list_iter_begin(state
->dev
, &conn_iter
);
150 drm_for_each_connector_iter(connector
, &conn_iter
) {
151 struct drm_crtc_state
*crtc_state
;
153 if (drm_atomic_get_new_connector_state(state
, connector
))
156 encoder
= connector
->state
->best_encoder
;
157 if (!encoder
|| !(encoder_mask
& (1 << drm_encoder_index(encoder
))))
160 if (!disable_conflicting_encoders
) {
161 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s] by [CONNECTOR:%d:%s]\n",
162 encoder
->base
.id
, encoder
->name
,
163 connector
->state
->crtc
->base
.id
,
164 connector
->state
->crtc
->name
,
165 connector
->base
.id
, connector
->name
);
170 new_conn_state
= drm_atomic_get_connector_state(state
, connector
);
171 if (IS_ERR(new_conn_state
)) {
172 ret
= PTR_ERR(new_conn_state
);
176 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s], disabling [CONNECTOR:%d:%s]\n",
177 encoder
->base
.id
, encoder
->name
,
178 new_conn_state
->crtc
->base
.id
, new_conn_state
->crtc
->name
,
179 connector
->base
.id
, connector
->name
);
181 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_conn_state
->crtc
);
183 ret
= drm_atomic_set_crtc_for_connector(new_conn_state
, NULL
);
187 if (!crtc_state
->connector_mask
) {
188 ret
= drm_atomic_set_mode_prop_for_crtc(crtc_state
,
193 crtc_state
->active
= false;
197 drm_connector_list_iter_end(&conn_iter
);
203 set_best_encoder(struct drm_atomic_state
*state
,
204 struct drm_connector_state
*conn_state
,
205 struct drm_encoder
*encoder
)
207 struct drm_crtc_state
*crtc_state
;
208 struct drm_crtc
*crtc
;
210 if (conn_state
->best_encoder
) {
211 /* Unset the encoder_mask in the old crtc state. */
212 crtc
= conn_state
->connector
->state
->crtc
;
214 /* A NULL crtc is an error here because we should have
215 * duplicated a NULL best_encoder when crtc was NULL.
216 * As an exception restoring duplicated atomic state
217 * during resume is allowed, so don't warn when
218 * best_encoder is equal to encoder we intend to set.
220 WARN_ON(!crtc
&& encoder
!= conn_state
->best_encoder
);
222 crtc_state
= drm_atomic_get_new_crtc_state(state
, crtc
);
224 crtc_state
->encoder_mask
&=
225 ~(1 << drm_encoder_index(conn_state
->best_encoder
));
230 crtc
= conn_state
->crtc
;
233 crtc_state
= drm_atomic_get_new_crtc_state(state
, crtc
);
235 crtc_state
->encoder_mask
|=
236 1 << drm_encoder_index(encoder
);
240 conn_state
->best_encoder
= encoder
;
244 steal_encoder(struct drm_atomic_state
*state
,
245 struct drm_encoder
*encoder
)
247 struct drm_crtc_state
*crtc_state
;
248 struct drm_connector
*connector
;
249 struct drm_connector_state
*old_connector_state
, *new_connector_state
;
252 for_each_oldnew_connector_in_state(state
, connector
, old_connector_state
, new_connector_state
, i
) {
253 struct drm_crtc
*encoder_crtc
;
255 if (new_connector_state
->best_encoder
!= encoder
)
258 encoder_crtc
= old_connector_state
->crtc
;
260 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s], stealing it\n",
261 encoder
->base
.id
, encoder
->name
,
262 encoder_crtc
->base
.id
, encoder_crtc
->name
);
264 set_best_encoder(state
, new_connector_state
, NULL
);
266 crtc_state
= drm_atomic_get_new_crtc_state(state
, encoder_crtc
);
267 crtc_state
->connectors_changed
= true;
274 update_connector_routing(struct drm_atomic_state
*state
,
275 struct drm_connector
*connector
,
276 struct drm_connector_state
*old_connector_state
,
277 struct drm_connector_state
*new_connector_state
)
279 const struct drm_connector_helper_funcs
*funcs
;
280 struct drm_encoder
*new_encoder
;
281 struct drm_crtc_state
*crtc_state
;
283 DRM_DEBUG_ATOMIC("Updating routing for [CONNECTOR:%d:%s]\n",
287 if (old_connector_state
->crtc
!= new_connector_state
->crtc
) {
288 if (old_connector_state
->crtc
) {
289 crtc_state
= drm_atomic_get_new_crtc_state(state
, old_connector_state
->crtc
);
290 crtc_state
->connectors_changed
= true;
293 if (new_connector_state
->crtc
) {
294 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_connector_state
->crtc
);
295 crtc_state
->connectors_changed
= true;
299 if (!new_connector_state
->crtc
) {
300 DRM_DEBUG_ATOMIC("Disabling [CONNECTOR:%d:%s]\n",
304 set_best_encoder(state
, new_connector_state
, NULL
);
309 funcs
= connector
->helper_private
;
311 if (funcs
->atomic_best_encoder
)
312 new_encoder
= funcs
->atomic_best_encoder(connector
,
313 new_connector_state
);
314 else if (funcs
->best_encoder
)
315 new_encoder
= funcs
->best_encoder(connector
);
317 new_encoder
= drm_atomic_helper_best_encoder(connector
);
320 DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n",
326 if (!drm_encoder_crtc_ok(new_encoder
, new_connector_state
->crtc
)) {
327 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] incompatible with [CRTC:%d:%s]\n",
328 new_encoder
->base
.id
,
330 new_connector_state
->crtc
->base
.id
,
331 new_connector_state
->crtc
->name
);
335 if (new_encoder
== new_connector_state
->best_encoder
) {
336 set_best_encoder(state
, new_connector_state
, new_encoder
);
338 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d:%s]\n",
341 new_encoder
->base
.id
,
343 new_connector_state
->crtc
->base
.id
,
344 new_connector_state
->crtc
->name
);
349 steal_encoder(state
, new_encoder
);
351 set_best_encoder(state
, new_connector_state
, new_encoder
);
353 crtc_state
= drm_atomic_get_new_crtc_state(state
, new_connector_state
->crtc
);
354 crtc_state
->connectors_changed
= true;
356 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d:%s]\n",
359 new_encoder
->base
.id
,
361 new_connector_state
->crtc
->base
.id
,
362 new_connector_state
->crtc
->name
);
368 mode_fixup(struct drm_atomic_state
*state
)
370 struct drm_crtc
*crtc
;
371 struct drm_crtc_state
*new_crtc_state
;
372 struct drm_connector
*connector
;
373 struct drm_connector_state
*new_conn_state
;
377 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
378 if (!new_crtc_state
->mode_changed
&&
379 !new_crtc_state
->connectors_changed
)
382 drm_mode_copy(&new_crtc_state
->adjusted_mode
, &new_crtc_state
->mode
);
385 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
386 const struct drm_encoder_helper_funcs
*funcs
;
387 struct drm_encoder
*encoder
;
389 WARN_ON(!!new_conn_state
->best_encoder
!= !!new_conn_state
->crtc
);
391 if (!new_conn_state
->crtc
|| !new_conn_state
->best_encoder
)
395 drm_atomic_get_new_crtc_state(state
, new_conn_state
->crtc
);
398 * Each encoder has at most one connector (since we always steal
399 * it away), so we won't call ->mode_fixup twice.
401 encoder
= new_conn_state
->best_encoder
;
402 funcs
= encoder
->helper_private
;
404 ret
= drm_bridge_mode_fixup(encoder
->bridge
, &new_crtc_state
->mode
,
405 &new_crtc_state
->adjusted_mode
);
407 DRM_DEBUG_ATOMIC("Bridge fixup failed\n");
411 if (funcs
&& funcs
->atomic_check
) {
412 ret
= funcs
->atomic_check(encoder
, new_crtc_state
,
415 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] check failed\n",
416 encoder
->base
.id
, encoder
->name
);
419 } else if (funcs
&& funcs
->mode_fixup
) {
420 ret
= funcs
->mode_fixup(encoder
, &new_crtc_state
->mode
,
421 &new_crtc_state
->adjusted_mode
);
423 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] fixup failed\n",
424 encoder
->base
.id
, encoder
->name
);
430 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
431 const struct drm_crtc_helper_funcs
*funcs
;
433 if (!new_crtc_state
->enable
)
436 if (!new_crtc_state
->mode_changed
&&
437 !new_crtc_state
->connectors_changed
)
440 funcs
= crtc
->helper_private
;
441 if (!funcs
->mode_fixup
)
444 ret
= funcs
->mode_fixup(crtc
, &new_crtc_state
->mode
,
445 &new_crtc_state
->adjusted_mode
);
447 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] fixup failed\n",
448 crtc
->base
.id
, crtc
->name
);
456 static enum drm_mode_status
mode_valid_path(struct drm_connector
*connector
,
457 struct drm_encoder
*encoder
,
458 struct drm_crtc
*crtc
,
459 struct drm_display_mode
*mode
)
461 enum drm_mode_status ret
;
463 ret
= drm_encoder_mode_valid(encoder
, mode
);
464 if (ret
!= MODE_OK
) {
465 DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] mode_valid() failed\n",
466 encoder
->base
.id
, encoder
->name
);
470 ret
= drm_bridge_mode_valid(encoder
->bridge
, mode
);
471 if (ret
!= MODE_OK
) {
472 DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n");
476 ret
= drm_crtc_mode_valid(crtc
, mode
);
477 if (ret
!= MODE_OK
) {
478 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode_valid() failed\n",
479 crtc
->base
.id
, crtc
->name
);
487 mode_valid(struct drm_atomic_state
*state
)
489 struct drm_connector_state
*conn_state
;
490 struct drm_connector
*connector
;
493 for_each_new_connector_in_state(state
, connector
, conn_state
, i
) {
494 struct drm_encoder
*encoder
= conn_state
->best_encoder
;
495 struct drm_crtc
*crtc
= conn_state
->crtc
;
496 struct drm_crtc_state
*crtc_state
;
497 enum drm_mode_status mode_status
;
498 struct drm_display_mode
*mode
;
500 if (!crtc
|| !encoder
)
503 crtc_state
= drm_atomic_get_new_crtc_state(state
, crtc
);
506 if (!crtc_state
->mode_changed
&& !crtc_state
->connectors_changed
)
509 mode
= &crtc_state
->mode
;
511 mode_status
= mode_valid_path(connector
, encoder
, crtc
, mode
);
512 if (mode_status
!= MODE_OK
)
520 * drm_atomic_helper_check_modeset - validate state object for modeset changes
522 * @state: the driver state object
524 * Check the state object to see if the requested state is physically possible.
525 * This does all the crtc and connector related computations for an atomic
526 * update and adds any additional connectors needed for full modesets. It calls
527 * the various per-object callbacks in the follow order:
529 * 1. &drm_connector_helper_funcs.atomic_best_encoder for determining the new encoder.
530 * 2. &drm_connector_helper_funcs.atomic_check to validate the connector state.
531 * 3. If it's determined a modeset is needed then all connectors on the affected crtc
532 * crtc are added and &drm_connector_helper_funcs.atomic_check is run on them.
533 * 4. &drm_encoder_helper_funcs.mode_valid, &drm_bridge_funcs.mode_valid and
534 * &drm_crtc_helper_funcs.mode_valid are called on the affected components.
535 * 5. &drm_bridge_funcs.mode_fixup is called on all encoder bridges.
536 * 6. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state.
537 * This function is only called when the encoder will be part of a configured crtc,
538 * it must not be used for implementing connector property validation.
539 * If this function is NULL, &drm_atomic_encoder_helper_funcs.mode_fixup is called
541 * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints.
543 * &drm_crtc_state.mode_changed is set when the input mode is changed.
544 * &drm_crtc_state.connectors_changed is set when a connector is added or
545 * removed from the crtc. &drm_crtc_state.active_changed is set when
546 * &drm_crtc_state.active changes, which is used for DPMS.
547 * See also: drm_atomic_crtc_needs_modeset()
551 * Drivers which set &drm_crtc_state.mode_changed (e.g. in their
552 * &drm_plane_helper_funcs.atomic_check hooks if a plane update can't be done
553 * without a full modeset) _must_ call this function afterwards after that
554 * change. It is permitted to call this function multiple times for the same
555 * update, e.g. when the &drm_crtc_helper_funcs.atomic_check functions depend
556 * upon the adjusted dotclock for fifo space allocation and watermark
560 * Zero for success or -errno
563 drm_atomic_helper_check_modeset(struct drm_device
*dev
,
564 struct drm_atomic_state
*state
)
566 struct drm_crtc
*crtc
;
567 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
568 struct drm_connector
*connector
;
569 struct drm_connector_state
*old_connector_state
, *new_connector_state
;
571 unsigned connectors_mask
= 0;
573 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
574 bool has_connectors
=
575 !!new_crtc_state
->connector_mask
;
577 if (!drm_mode_equal(&old_crtc_state
->mode
, &new_crtc_state
->mode
)) {
578 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode changed\n",
579 crtc
->base
.id
, crtc
->name
);
580 new_crtc_state
->mode_changed
= true;
583 if (old_crtc_state
->enable
!= new_crtc_state
->enable
) {
584 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enable changed\n",
585 crtc
->base
.id
, crtc
->name
);
588 * For clarity this assignment is done here, but
589 * enable == 0 is only true when there are no
590 * connectors and a NULL mode.
592 * The other way around is true as well. enable != 0
593 * iff connectors are attached and a mode is set.
595 new_crtc_state
->mode_changed
= true;
596 new_crtc_state
->connectors_changed
= true;
599 if (old_crtc_state
->active
!= new_crtc_state
->active
) {
600 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active changed\n",
601 crtc
->base
.id
, crtc
->name
);
602 new_crtc_state
->active_changed
= true;
605 if (new_crtc_state
->enable
!= has_connectors
) {
606 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled/connectors mismatch\n",
607 crtc
->base
.id
, crtc
->name
);
613 ret
= handle_conflicting_encoders(state
, false);
617 for_each_oldnew_connector_in_state(state
, connector
, old_connector_state
, new_connector_state
, i
) {
618 const struct drm_connector_helper_funcs
*funcs
= connector
->helper_private
;
621 * This only sets crtc->connectors_changed for routing changes,
622 * drivers must set crtc->connectors_changed themselves when
623 * connector properties need to be updated.
625 ret
= update_connector_routing(state
, connector
,
627 new_connector_state
);
630 if (old_connector_state
->crtc
) {
631 new_crtc_state
= drm_atomic_get_new_crtc_state(state
,
632 old_connector_state
->crtc
);
633 if (old_connector_state
->link_status
!=
634 new_connector_state
->link_status
)
635 new_crtc_state
->connectors_changed
= true;
638 if (funcs
->atomic_check
)
639 ret
= funcs
->atomic_check(connector
, new_connector_state
);
643 connectors_mask
+= BIT(i
);
647 * After all the routing has been prepared we need to add in any
648 * connector which is itself unchanged, but who's crtc changes it's
649 * configuration. This must be done before calling mode_fixup in case a
650 * crtc only changed its mode but has the same set of connectors.
652 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
653 if (!drm_atomic_crtc_needs_modeset(new_crtc_state
))
656 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] needs all connectors, enable: %c, active: %c\n",
657 crtc
->base
.id
, crtc
->name
,
658 new_crtc_state
->enable
? 'y' : 'n',
659 new_crtc_state
->active
? 'y' : 'n');
661 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
665 ret
= drm_atomic_add_affected_planes(state
, crtc
);
671 * Iterate over all connectors again, to make sure atomic_check()
672 * has been called on them when a modeset is forced.
674 for_each_oldnew_connector_in_state(state
, connector
, old_connector_state
, new_connector_state
, i
) {
675 const struct drm_connector_helper_funcs
*funcs
= connector
->helper_private
;
677 if (connectors_mask
& BIT(i
))
680 if (funcs
->atomic_check
)
681 ret
= funcs
->atomic_check(connector
, new_connector_state
);
686 ret
= mode_valid(state
);
690 return mode_fixup(state
);
692 EXPORT_SYMBOL(drm_atomic_helper_check_modeset
);
695 * drm_atomic_helper_check_planes - validate state object for planes changes
697 * @state: the driver state object
699 * Check the state object to see if the requested state is physically possible.
700 * This does all the plane update related checks using by calling into the
701 * &drm_crtc_helper_funcs.atomic_check and &drm_plane_helper_funcs.atomic_check
702 * hooks provided by the driver.
704 * It also sets &drm_crtc_state.planes_changed to indicate that a crtc has
708 * Zero for success or -errno
711 drm_atomic_helper_check_planes(struct drm_device
*dev
,
712 struct drm_atomic_state
*state
)
714 struct drm_crtc
*crtc
;
715 struct drm_crtc_state
*new_crtc_state
;
716 struct drm_plane
*plane
;
717 struct drm_plane_state
*new_plane_state
, *old_plane_state
;
720 for_each_oldnew_plane_in_state(state
, plane
, old_plane_state
, new_plane_state
, i
) {
721 const struct drm_plane_helper_funcs
*funcs
;
723 funcs
= plane
->helper_private
;
725 drm_atomic_helper_plane_changed(state
, old_plane_state
, new_plane_state
, plane
);
727 if (!funcs
|| !funcs
->atomic_check
)
730 ret
= funcs
->atomic_check(plane
, new_plane_state
);
732 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic driver check failed\n",
733 plane
->base
.id
, plane
->name
);
738 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
739 const struct drm_crtc_helper_funcs
*funcs
;
741 funcs
= crtc
->helper_private
;
743 if (!funcs
|| !funcs
->atomic_check
)
746 ret
= funcs
->atomic_check(crtc
, new_crtc_state
);
748 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n",
749 crtc
->base
.id
, crtc
->name
);
756 EXPORT_SYMBOL(drm_atomic_helper_check_planes
);
759 * drm_atomic_helper_check - validate state object
761 * @state: the driver state object
763 * Check the state object to see if the requested state is physically possible.
764 * Only crtcs and planes have check callbacks, so for any additional (global)
765 * checking that a driver needs it can simply wrap that around this function.
766 * Drivers without such needs can directly use this as their
767 * &drm_mode_config_funcs.atomic_check callback.
769 * This just wraps the two parts of the state checking for planes and modeset
770 * state in the default order: First it calls drm_atomic_helper_check_modeset()
771 * and then drm_atomic_helper_check_planes(). The assumption is that the
772 * @drm_plane_helper_funcs.atomic_check and @drm_crtc_helper_funcs.atomic_check
773 * functions depend upon an updated adjusted_mode.clock to e.g. properly compute
777 * Zero for success or -errno
779 int drm_atomic_helper_check(struct drm_device
*dev
,
780 struct drm_atomic_state
*state
)
784 ret
= drm_atomic_helper_check_modeset(dev
, state
);
788 ret
= drm_atomic_helper_check_planes(dev
, state
);
794 EXPORT_SYMBOL(drm_atomic_helper_check
);
797 disable_outputs(struct drm_device
*dev
, struct drm_atomic_state
*old_state
)
799 struct drm_connector
*connector
;
800 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
801 struct drm_crtc
*crtc
;
802 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
805 for_each_oldnew_connector_in_state(old_state
, connector
, old_conn_state
, new_conn_state
, i
) {
806 const struct drm_encoder_helper_funcs
*funcs
;
807 struct drm_encoder
*encoder
;
809 /* Shut down everything that's in the changeset and currently
810 * still on. So need to check the old, saved state. */
811 if (!old_conn_state
->crtc
)
814 old_crtc_state
= drm_atomic_get_old_crtc_state(old_state
, old_conn_state
->crtc
);
816 if (!old_crtc_state
->active
||
817 !drm_atomic_crtc_needs_modeset(old_conn_state
->crtc
->state
))
820 encoder
= old_conn_state
->best_encoder
;
822 /* We shouldn't get this far if we didn't previously have
823 * an encoder.. but WARN_ON() rather than explode.
825 if (WARN_ON(!encoder
))
828 funcs
= encoder
->helper_private
;
830 DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n",
831 encoder
->base
.id
, encoder
->name
);
834 * Each encoder has at most one connector (since we always steal
835 * it away), so we won't call disable hooks twice.
837 drm_bridge_disable(encoder
->bridge
);
839 /* Right function depends upon target state. */
841 if (new_conn_state
->crtc
&& funcs
->prepare
)
842 funcs
->prepare(encoder
);
843 else if (funcs
->disable
)
844 funcs
->disable(encoder
);
845 else if (funcs
->dpms
)
846 funcs
->dpms(encoder
, DRM_MODE_DPMS_OFF
);
849 drm_bridge_post_disable(encoder
->bridge
);
852 for_each_oldnew_crtc_in_state(old_state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
853 const struct drm_crtc_helper_funcs
*funcs
;
855 /* Shut down everything that needs a full modeset. */
856 if (!drm_atomic_crtc_needs_modeset(new_crtc_state
))
859 if (!old_crtc_state
->active
)
862 funcs
= crtc
->helper_private
;
864 DRM_DEBUG_ATOMIC("disabling [CRTC:%d:%s]\n",
865 crtc
->base
.id
, crtc
->name
);
868 /* Right function depends upon target state. */
869 if (new_crtc_state
->enable
&& funcs
->prepare
)
870 funcs
->prepare(crtc
);
871 else if (funcs
->atomic_disable
)
872 funcs
->atomic_disable(crtc
, old_crtc_state
);
873 else if (funcs
->disable
)
874 funcs
->disable(crtc
);
876 funcs
->dpms(crtc
, DRM_MODE_DPMS_OFF
);
881 * drm_atomic_helper_update_legacy_modeset_state - update legacy modeset state
883 * @old_state: atomic state object with old state structures
885 * This function updates all the various legacy modeset state pointers in
886 * connectors, encoders and crtcs. It also updates the timestamping constants
887 * used for precise vblank timestamps by calling
888 * drm_calc_timestamping_constants().
890 * Drivers can use this for building their own atomic commit if they don't have
891 * a pure helper-based modeset implementation.
894 drm_atomic_helper_update_legacy_modeset_state(struct drm_device
*dev
,
895 struct drm_atomic_state
*old_state
)
897 struct drm_connector
*connector
;
898 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
899 struct drm_crtc
*crtc
;
900 struct drm_crtc_state
*new_crtc_state
;
903 /* clear out existing links and update dpms */
904 for_each_oldnew_connector_in_state(old_state
, connector
, old_conn_state
, new_conn_state
, i
) {
905 if (connector
->encoder
) {
906 WARN_ON(!connector
->encoder
->crtc
);
908 connector
->encoder
->crtc
= NULL
;
909 connector
->encoder
= NULL
;
912 crtc
= new_conn_state
->crtc
;
913 if ((!crtc
&& old_conn_state
->crtc
) ||
914 (crtc
&& drm_atomic_crtc_needs_modeset(crtc
->state
))) {
915 struct drm_property
*dpms_prop
=
916 dev
->mode_config
.dpms_property
;
917 int mode
= DRM_MODE_DPMS_OFF
;
919 if (crtc
&& crtc
->state
->active
)
920 mode
= DRM_MODE_DPMS_ON
;
922 connector
->dpms
= mode
;
923 drm_object_property_set_value(&connector
->base
,
929 for_each_new_connector_in_state(old_state
, connector
, new_conn_state
, i
) {
930 if (!new_conn_state
->crtc
)
933 if (WARN_ON(!new_conn_state
->best_encoder
))
936 connector
->encoder
= new_conn_state
->best_encoder
;
937 connector
->encoder
->crtc
= new_conn_state
->crtc
;
940 /* set legacy state in the crtc structure */
941 for_each_new_crtc_in_state(old_state
, crtc
, new_crtc_state
, i
) {
942 struct drm_plane
*primary
= crtc
->primary
;
943 struct drm_plane_state
*new_plane_state
;
945 crtc
->mode
= new_crtc_state
->mode
;
946 crtc
->enabled
= new_crtc_state
->enable
;
949 drm_atomic_get_new_plane_state(old_state
, primary
);
951 if (new_plane_state
&& new_plane_state
->crtc
== crtc
) {
952 crtc
->x
= new_plane_state
->src_x
>> 16;
953 crtc
->y
= new_plane_state
->src_y
>> 16;
956 if (new_crtc_state
->enable
)
957 drm_calc_timestamping_constants(crtc
,
958 &new_crtc_state
->adjusted_mode
);
961 EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state
);
964 crtc_set_mode(struct drm_device
*dev
, struct drm_atomic_state
*old_state
)
966 struct drm_crtc
*crtc
;
967 struct drm_crtc_state
*new_crtc_state
;
968 struct drm_connector
*connector
;
969 struct drm_connector_state
*new_conn_state
;
972 for_each_new_crtc_in_state(old_state
, crtc
, new_crtc_state
, i
) {
973 const struct drm_crtc_helper_funcs
*funcs
;
975 if (!new_crtc_state
->mode_changed
)
978 funcs
= crtc
->helper_private
;
980 if (new_crtc_state
->enable
&& funcs
->mode_set_nofb
) {
981 DRM_DEBUG_ATOMIC("modeset on [CRTC:%d:%s]\n",
982 crtc
->base
.id
, crtc
->name
);
984 funcs
->mode_set_nofb(crtc
);
988 for_each_new_connector_in_state(old_state
, connector
, new_conn_state
, i
) {
989 const struct drm_encoder_helper_funcs
*funcs
;
990 struct drm_encoder
*encoder
;
991 struct drm_display_mode
*mode
, *adjusted_mode
;
993 if (!new_conn_state
->best_encoder
)
996 encoder
= new_conn_state
->best_encoder
;
997 funcs
= encoder
->helper_private
;
998 new_crtc_state
= new_conn_state
->crtc
->state
;
999 mode
= &new_crtc_state
->mode
;
1000 adjusted_mode
= &new_crtc_state
->adjusted_mode
;
1002 if (!new_crtc_state
->mode_changed
)
1005 DRM_DEBUG_ATOMIC("modeset on [ENCODER:%d:%s]\n",
1006 encoder
->base
.id
, encoder
->name
);
1009 * Each encoder has at most one connector (since we always steal
1010 * it away), so we won't call mode_set hooks twice.
1012 if (funcs
&& funcs
->atomic_mode_set
) {
1013 funcs
->atomic_mode_set(encoder
, new_crtc_state
,
1015 } else if (funcs
&& funcs
->mode_set
) {
1016 funcs
->mode_set(encoder
, mode
, adjusted_mode
);
1019 drm_bridge_mode_set(encoder
->bridge
, mode
, adjusted_mode
);
1024 * drm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs
1026 * @old_state: atomic state object with old state structures
1028 * This function shuts down all the outputs that need to be shut down and
1029 * prepares them (if required) with the new mode.
1031 * For compatibility with legacy crtc helpers this should be called before
1032 * drm_atomic_helper_commit_planes(), which is what the default commit function
1033 * does. But drivers with different needs can group the modeset commits together
1034 * and do the plane commits at the end. This is useful for drivers doing runtime
1035 * PM since planes updates then only happen when the CRTC is actually enabled.
1037 void drm_atomic_helper_commit_modeset_disables(struct drm_device
*dev
,
1038 struct drm_atomic_state
*old_state
)
1040 disable_outputs(dev
, old_state
);
1042 drm_atomic_helper_update_legacy_modeset_state(dev
, old_state
);
1044 crtc_set_mode(dev
, old_state
);
1046 EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables
);
1049 * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs
1051 * @old_state: atomic state object with old state structures
1053 * This function enables all the outputs with the new configuration which had to
1054 * be turned off for the update.
1056 * For compatibility with legacy crtc helpers this should be called after
1057 * drm_atomic_helper_commit_planes(), which is what the default commit function
1058 * does. But drivers with different needs can group the modeset commits together
1059 * and do the plane commits at the end. This is useful for drivers doing runtime
1060 * PM since planes updates then only happen when the CRTC is actually enabled.
1062 void drm_atomic_helper_commit_modeset_enables(struct drm_device
*dev
,
1063 struct drm_atomic_state
*old_state
)
1065 struct drm_crtc
*crtc
;
1066 struct drm_crtc_state
*new_crtc_state
;
1067 struct drm_connector
*connector
;
1068 struct drm_connector_state
*new_conn_state
;
1071 for_each_new_crtc_in_state(old_state
, crtc
, new_crtc_state
, i
) {
1072 const struct drm_crtc_helper_funcs
*funcs
;
1074 /* Need to filter out CRTCs where only planes change. */
1075 if (!drm_atomic_crtc_needs_modeset(new_crtc_state
))
1078 if (!new_crtc_state
->active
)
1081 funcs
= crtc
->helper_private
;
1083 if (new_crtc_state
->enable
) {
1084 DRM_DEBUG_ATOMIC("enabling [CRTC:%d:%s]\n",
1085 crtc
->base
.id
, crtc
->name
);
1088 funcs
->enable(crtc
);
1090 funcs
->commit(crtc
);
1094 for_each_new_connector_in_state(old_state
, connector
, new_conn_state
, i
) {
1095 const struct drm_encoder_helper_funcs
*funcs
;
1096 struct drm_encoder
*encoder
;
1098 if (!new_conn_state
->best_encoder
)
1101 if (!new_conn_state
->crtc
->state
->active
||
1102 !drm_atomic_crtc_needs_modeset(new_conn_state
->crtc
->state
))
1105 encoder
= new_conn_state
->best_encoder
;
1106 funcs
= encoder
->helper_private
;
1108 DRM_DEBUG_ATOMIC("enabling [ENCODER:%d:%s]\n",
1109 encoder
->base
.id
, encoder
->name
);
1112 * Each encoder has at most one connector (since we always steal
1113 * it away), so we won't call enable hooks twice.
1115 drm_bridge_pre_enable(encoder
->bridge
);
1119 funcs
->enable(encoder
);
1120 else if (funcs
->commit
)
1121 funcs
->commit(encoder
);
1124 drm_bridge_enable(encoder
->bridge
);
1127 EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables
);
1130 * drm_atomic_helper_wait_for_fences - wait for fences stashed in plane state
1132 * @state: atomic state object with old state structures
1133 * @pre_swap: If true, do an interruptible wait, and @state is the new state.
1134 * Otherwise @state is the old state.
1136 * For implicit sync, driver should fish the exclusive fence out from the
1137 * incoming fb's and stash it in the drm_plane_state. This is called after
1138 * drm_atomic_helper_swap_state() so it uses the current plane state (and
1139 * just uses the atomic state to find the changed planes)
1141 * Note that @pre_swap is needed since the point where we block for fences moves
1142 * around depending upon whether an atomic commit is blocking or
1143 * non-blocking. For non-blocking commit all waiting needs to happen after
1144 * drm_atomic_helper_swap_state() is called, but for blocking commits we want
1145 * to wait **before** we do anything that can't be easily rolled back. That is
1146 * before we call drm_atomic_helper_swap_state().
1148 * Returns zero if success or < 0 if dma_fence_wait() fails.
1150 int drm_atomic_helper_wait_for_fences(struct drm_device
*dev
,
1151 struct drm_atomic_state
*state
,
1154 struct drm_plane
*plane
;
1155 struct drm_plane_state
*new_plane_state
;
1158 for_each_new_plane_in_state(state
, plane
, new_plane_state
, i
) {
1159 if (!new_plane_state
->fence
)
1162 WARN_ON(!new_plane_state
->fb
);
1165 * If waiting for fences pre-swap (ie: nonblock), userspace can
1166 * still interrupt the operation. Instead of blocking until the
1167 * timer expires, make the wait interruptible.
1169 ret
= dma_fence_wait(new_plane_state
->fence
, pre_swap
);
1173 dma_fence_put(new_plane_state
->fence
);
1174 new_plane_state
->fence
= NULL
;
1179 EXPORT_SYMBOL(drm_atomic_helper_wait_for_fences
);
1182 * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs
1184 * @old_state: atomic state object with old state structures
1186 * Helper to, after atomic commit, wait for vblanks on all effected
1187 * crtcs (ie. before cleaning up old framebuffers using
1188 * drm_atomic_helper_cleanup_planes()). It will only wait on CRTCs where the
1189 * framebuffers have actually changed to optimize for the legacy cursor and
1190 * plane update use-case.
1192 * Drivers using the nonblocking commit tracking support initialized by calling
1193 * drm_atomic_helper_setup_commit() should look at
1194 * drm_atomic_helper_wait_for_flip_done() as an alternative.
1197 drm_atomic_helper_wait_for_vblanks(struct drm_device
*dev
,
1198 struct drm_atomic_state
*old_state
)
1200 struct drm_crtc
*crtc
;
1201 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
1203 unsigned crtc_mask
= 0;
1206 * Legacy cursor ioctls are completely unsynced, and userspace
1207 * relies on that (by doing tons of cursor updates).
1209 if (old_state
->legacy_cursor_update
)
1212 for_each_oldnew_crtc_in_state(old_state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
1213 if (!new_crtc_state
->active
|| !new_crtc_state
->planes_changed
)
1216 ret
= drm_crtc_vblank_get(crtc
);
1220 crtc_mask
|= drm_crtc_mask(crtc
);
1221 old_state
->crtcs
[i
].last_vblank_count
= drm_crtc_vblank_count(crtc
);
1224 for_each_old_crtc_in_state(old_state
, crtc
, old_crtc_state
, i
) {
1225 if (!(crtc_mask
& drm_crtc_mask(crtc
)))
1228 ret
= wait_event_timeout(dev
->vblank
[i
].queue
,
1229 old_state
->crtcs
[i
].last_vblank_count
!=
1230 drm_crtc_vblank_count(crtc
),
1231 msecs_to_jiffies(50));
1233 WARN(!ret
, "[CRTC:%d:%s] vblank wait timed out\n",
1234 crtc
->base
.id
, crtc
->name
);
1236 drm_crtc_vblank_put(crtc
);
1239 EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks
);
1242 * drm_atomic_helper_wait_for_flip_done - wait for all page flips to be done
1244 * @old_state: atomic state object with old state structures
1246 * Helper to, after atomic commit, wait for page flips on all effected
1247 * crtcs (ie. before cleaning up old framebuffers using
1248 * drm_atomic_helper_cleanup_planes()). Compared to
1249 * drm_atomic_helper_wait_for_vblanks() this waits for the completion of on all
1250 * CRTCs, assuming that cursors-only updates are signalling their completion
1251 * immediately (or using a different path).
1253 * This requires that drivers use the nonblocking commit tracking support
1254 * initialized using drm_atomic_helper_setup_commit().
1256 void drm_atomic_helper_wait_for_flip_done(struct drm_device
*dev
,
1257 struct drm_atomic_state
*old_state
)
1259 struct drm_crtc_state
*crtc_state
;
1260 struct drm_crtc
*crtc
;
1263 for_each_crtc_in_state(old_state
, crtc
, crtc_state
, i
) {
1264 struct drm_crtc_commit
*commit
= old_state
->crtcs
[i
].commit
;
1270 ret
= wait_for_completion_timeout(&commit
->flip_done
, 10 * HZ
);
1272 DRM_ERROR("[CRTC:%d:%s] flip_done timed out\n",
1273 crtc
->base
.id
, crtc
->name
);
1276 EXPORT_SYMBOL(drm_atomic_helper_wait_for_flip_done
);
1279 * drm_atomic_helper_commit_tail - commit atomic update to hardware
1280 * @old_state: atomic state object with old state structures
1282 * This is the default implementation for the
1283 * &drm_mode_config_helper_funcs.atomic_commit_tail hook.
1285 * Note that the default ordering of how the various stages are called is to
1286 * match the legacy modeset helper library closest. One peculiarity of that is
1287 * that it doesn't mesh well with runtime PM at all.
1289 * For drivers supporting runtime PM the recommended sequence is instead ::
1291 * drm_atomic_helper_commit_modeset_disables(dev, old_state);
1293 * drm_atomic_helper_commit_modeset_enables(dev, old_state);
1295 * drm_atomic_helper_commit_planes(dev, old_state,
1296 * DRM_PLANE_COMMIT_ACTIVE_ONLY);
1298 * for committing the atomic update to hardware. See the kerneldoc entries for
1299 * these three functions for more details.
1301 void drm_atomic_helper_commit_tail(struct drm_atomic_state
*old_state
)
1303 struct drm_device
*dev
= old_state
->dev
;
1305 drm_atomic_helper_commit_modeset_disables(dev
, old_state
);
1307 drm_atomic_helper_commit_planes(dev
, old_state
, 0);
1309 drm_atomic_helper_commit_modeset_enables(dev
, old_state
);
1311 drm_atomic_helper_commit_hw_done(old_state
);
1313 drm_atomic_helper_wait_for_vblanks(dev
, old_state
);
1315 drm_atomic_helper_cleanup_planes(dev
, old_state
);
1317 EXPORT_SYMBOL(drm_atomic_helper_commit_tail
);
1319 static void commit_tail(struct drm_atomic_state
*old_state
)
1321 struct drm_device
*dev
= old_state
->dev
;
1322 const struct drm_mode_config_helper_funcs
*funcs
;
1324 funcs
= dev
->mode_config
.helper_private
;
1326 drm_atomic_helper_wait_for_fences(dev
, old_state
, false);
1328 drm_atomic_helper_wait_for_dependencies(old_state
);
1330 if (funcs
&& funcs
->atomic_commit_tail
)
1331 funcs
->atomic_commit_tail(old_state
);
1333 drm_atomic_helper_commit_tail(old_state
);
1335 drm_atomic_helper_commit_cleanup_done(old_state
);
1337 drm_atomic_state_put(old_state
);
1340 static void commit_work(struct work_struct
*work
)
1342 struct drm_atomic_state
*state
= container_of(work
,
1343 struct drm_atomic_state
,
1349 * drm_atomic_helper_commit - commit validated state object
1351 * @state: the driver state object
1352 * @nonblock: whether nonblocking behavior is requested.
1354 * This function commits a with drm_atomic_helper_check() pre-validated state
1355 * object. This can still fail when e.g. the framebuffer reservation fails. This
1356 * function implements nonblocking commits, using
1357 * drm_atomic_helper_setup_commit() and related functions.
1359 * Committing the actual hardware state is done through the
1360 * &drm_mode_config_helper_funcs.atomic_commit_tail callback, or it's default
1361 * implementation drm_atomic_helper_commit_tail().
1364 * Zero for success or -errno.
1366 int drm_atomic_helper_commit(struct drm_device
*dev
,
1367 struct drm_atomic_state
*state
,
1372 ret
= drm_atomic_helper_setup_commit(state
, nonblock
);
1376 INIT_WORK(&state
->commit_work
, commit_work
);
1378 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
1383 ret
= drm_atomic_helper_wait_for_fences(dev
, state
, true);
1385 drm_atomic_helper_cleanup_planes(dev
, state
);
1391 * This is the point of no return - everything below never fails except
1392 * when the hw goes bonghits. Which means we can commit the new state on
1393 * the software side now.
1396 drm_atomic_helper_swap_state(state
, true);
1399 * Everything below can be run asynchronously without the need to grab
1400 * any modeset locks at all under one condition: It must be guaranteed
1401 * that the asynchronous work has either been cancelled (if the driver
1402 * supports it, which at least requires that the framebuffers get
1403 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
1404 * before the new state gets committed on the software side with
1405 * drm_atomic_helper_swap_state().
1407 * This scheme allows new atomic state updates to be prepared and
1408 * checked in parallel to the asynchronous completion of the previous
1409 * update. Which is important since compositors need to figure out the
1410 * composition of the next frame right after having submitted the
1413 * NOTE: Commit work has multiple phases, first hardware commit, then
1414 * cleanup. We want them to overlap, hence need system_unbound_wq to
1415 * make sure work items don't artifically stall on each another.
1418 drm_atomic_state_get(state
);
1420 queue_work(system_unbound_wq
, &state
->commit_work
);
1426 EXPORT_SYMBOL(drm_atomic_helper_commit
);
1429 * DOC: implementing nonblocking commit
1431 * Nonblocking atomic commits have to be implemented in the following sequence:
1433 * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function
1434 * which commit needs to call which can fail, so we want to run it first and
1437 * 2. Synchronize with any outstanding nonblocking commit worker threads which
1438 * might be affected the new state update. This can be done by either cancelling
1439 * or flushing the work items, depending upon whether the driver can deal with
1440 * cancelled updates. Note that it is important to ensure that the framebuffer
1441 * cleanup is still done when cancelling.
1443 * Asynchronous workers need to have sufficient parallelism to be able to run
1444 * different atomic commits on different CRTCs in parallel. The simplest way to
1445 * achive this is by running them on the &system_unbound_wq work queue. Note
1446 * that drivers are not required to split up atomic commits and run an
1447 * individual commit in parallel - userspace is supposed to do that if it cares.
1448 * But it might be beneficial to do that for modesets, since those necessarily
1449 * must be done as one global operation, and enabling or disabling a CRTC can
1450 * take a long time. But even that is not required.
1452 * 3. The software state is updated synchronously with
1453 * drm_atomic_helper_swap_state(). Doing this under the protection of all modeset
1454 * locks means concurrent callers never see inconsistent state. And doing this
1455 * while it's guaranteed that no relevant nonblocking worker runs means that
1456 * nonblocking workers do not need grab any locks. Actually they must not grab
1457 * locks, for otherwise the work flushing will deadlock.
1459 * 4. Schedule a work item to do all subsequent steps, using the split-out
1460 * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
1461 * then cleaning up the framebuffers after the old framebuffer is no longer
1464 * The above scheme is implemented in the atomic helper libraries in
1465 * drm_atomic_helper_commit() using a bunch of helper functions. See
1466 * drm_atomic_helper_setup_commit() for a starting point.
1469 static int stall_checks(struct drm_crtc
*crtc
, bool nonblock
)
1471 struct drm_crtc_commit
*commit
, *stall_commit
= NULL
;
1472 bool completed
= true;
1476 spin_lock(&crtc
->commit_lock
);
1478 list_for_each_entry(commit
, &crtc
->commit_list
, commit_entry
) {
1480 completed
= try_wait_for_completion(&commit
->flip_done
);
1481 /* Userspace is not allowed to get ahead of the previous
1482 * commit with nonblocking ones. */
1483 if (!completed
&& nonblock
) {
1484 spin_unlock(&crtc
->commit_lock
);
1487 } else if (i
== 1) {
1488 stall_commit
= commit
;
1489 drm_crtc_commit_get(stall_commit
);
1495 spin_unlock(&crtc
->commit_lock
);
1500 /* We don't want to let commits get ahead of cleanup work too much,
1501 * stalling on 2nd previous commit means triple-buffer won't ever stall.
1503 ret
= wait_for_completion_interruptible_timeout(&stall_commit
->cleanup_done
,
1506 DRM_ERROR("[CRTC:%d:%s] cleanup_done timed out\n",
1507 crtc
->base
.id
, crtc
->name
);
1509 drm_crtc_commit_put(stall_commit
);
1511 return ret
< 0 ? ret
: 0;
1514 static void release_crtc_commit(struct completion
*completion
)
1516 struct drm_crtc_commit
*commit
= container_of(completion
,
1520 drm_crtc_commit_put(commit
);
1524 * drm_atomic_helper_setup_commit - setup possibly nonblocking commit
1525 * @state: new modeset state to be committed
1526 * @nonblock: whether nonblocking behavior is requested.
1528 * This function prepares @state to be used by the atomic helper's support for
1529 * nonblocking commits. Drivers using the nonblocking commit infrastructure
1530 * should always call this function from their
1531 * &drm_mode_config_funcs.atomic_commit hook.
1533 * To be able to use this support drivers need to use a few more helper
1534 * functions. drm_atomic_helper_wait_for_dependencies() must be called before
1535 * actually committing the hardware state, and for nonblocking commits this call
1536 * must be placed in the async worker. See also drm_atomic_helper_swap_state()
1537 * and it's stall parameter, for when a driver's commit hooks look at the
1538 * &drm_crtc.state, &drm_plane.state or &drm_connector.state pointer directly.
1540 * Completion of the hardware commit step must be signalled using
1541 * drm_atomic_helper_commit_hw_done(). After this step the driver is not allowed
1542 * to read or change any permanent software or hardware modeset state. The only
1543 * exception is state protected by other means than &drm_modeset_lock locks.
1544 * Only the free standing @state with pointers to the old state structures can
1545 * be inspected, e.g. to clean up old buffers using
1546 * drm_atomic_helper_cleanup_planes().
1548 * At the very end, before cleaning up @state drivers must call
1549 * drm_atomic_helper_commit_cleanup_done().
1551 * This is all implemented by in drm_atomic_helper_commit(), giving drivers a
1552 * complete and esay-to-use default implementation of the atomic_commit() hook.
1554 * The tracking of asynchronously executed and still pending commits is done
1555 * using the core structure &drm_crtc_commit.
1557 * By default there's no need to clean up resources allocated by this function
1558 * explicitly: drm_atomic_state_default_clear() will take care of that
1563 * 0 on success. -EBUSY when userspace schedules nonblocking commits too fast,
1564 * -ENOMEM on allocation failures and -EINTR when a signal is pending.
1566 int drm_atomic_helper_setup_commit(struct drm_atomic_state
*state
,
1569 struct drm_crtc
*crtc
;
1570 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
1571 struct drm_crtc_commit
*commit
;
1574 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
1575 commit
= kzalloc(sizeof(*commit
), GFP_KERNEL
);
1579 init_completion(&commit
->flip_done
);
1580 init_completion(&commit
->hw_done
);
1581 init_completion(&commit
->cleanup_done
);
1582 INIT_LIST_HEAD(&commit
->commit_entry
);
1583 kref_init(&commit
->ref
);
1584 commit
->crtc
= crtc
;
1586 state
->crtcs
[i
].commit
= commit
;
1588 ret
= stall_checks(crtc
, nonblock
);
1592 /* Drivers only send out events when at least either current or
1593 * new CRTC state is active. Complete right away if everything
1595 if (!old_crtc_state
->active
&& !new_crtc_state
->active
) {
1596 complete_all(&commit
->flip_done
);
1600 /* Legacy cursor updates are fully unsynced. */
1601 if (state
->legacy_cursor_update
) {
1602 complete_all(&commit
->flip_done
);
1606 if (!new_crtc_state
->event
) {
1607 commit
->event
= kzalloc(sizeof(*commit
->event
),
1612 new_crtc_state
->event
= commit
->event
;
1615 new_crtc_state
->event
->base
.completion
= &commit
->flip_done
;
1616 new_crtc_state
->event
->base
.completion_release
= release_crtc_commit
;
1617 drm_crtc_commit_get(commit
);
1622 EXPORT_SYMBOL(drm_atomic_helper_setup_commit
);
1625 static struct drm_crtc_commit
*preceeding_commit(struct drm_crtc
*crtc
)
1627 struct drm_crtc_commit
*commit
;
1630 list_for_each_entry(commit
, &crtc
->commit_list
, commit_entry
) {
1631 /* skip the first entry, that's the current commit */
1641 * drm_atomic_helper_wait_for_dependencies - wait for required preceeding commits
1642 * @old_state: atomic state object with old state structures
1644 * This function waits for all preceeding commits that touch the same CRTC as
1645 * @old_state to both be committed to the hardware (as signalled by
1646 * drm_atomic_helper_commit_hw_done) and executed by the hardware (as signalled
1647 * by calling drm_crtc_vblank_send_event() on the &drm_crtc_state.event).
1649 * This is part of the atomic helper support for nonblocking commits, see
1650 * drm_atomic_helper_setup_commit() for an overview.
1652 void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state
*old_state
)
1654 struct drm_crtc
*crtc
;
1655 struct drm_crtc_state
*new_crtc_state
;
1656 struct drm_crtc_commit
*commit
;
1660 for_each_new_crtc_in_state(old_state
, crtc
, new_crtc_state
, i
) {
1661 spin_lock(&crtc
->commit_lock
);
1662 commit
= preceeding_commit(crtc
);
1664 drm_crtc_commit_get(commit
);
1665 spin_unlock(&crtc
->commit_lock
);
1670 ret
= wait_for_completion_timeout(&commit
->hw_done
,
1673 DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n",
1674 crtc
->base
.id
, crtc
->name
);
1676 /* Currently no support for overwriting flips, hence
1677 * stall for previous one to execute completely. */
1678 ret
= wait_for_completion_timeout(&commit
->flip_done
,
1681 DRM_ERROR("[CRTC:%d:%s] flip_done timed out\n",
1682 crtc
->base
.id
, crtc
->name
);
1684 drm_crtc_commit_put(commit
);
1687 EXPORT_SYMBOL(drm_atomic_helper_wait_for_dependencies
);
1690 * drm_atomic_helper_commit_hw_done - setup possible nonblocking commit
1691 * @old_state: atomic state object with old state structures
1693 * This function is used to signal completion of the hardware commit step. After
1694 * this step the driver is not allowed to read or change any permanent software
1695 * or hardware modeset state. The only exception is state protected by other
1696 * means than &drm_modeset_lock locks.
1698 * Drivers should try to postpone any expensive or delayed cleanup work after
1699 * this function is called.
1701 * This is part of the atomic helper support for nonblocking commits, see
1702 * drm_atomic_helper_setup_commit() for an overview.
1704 void drm_atomic_helper_commit_hw_done(struct drm_atomic_state
*old_state
)
1706 struct drm_crtc
*crtc
;
1707 struct drm_crtc_state
*new_crtc_state
;
1708 struct drm_crtc_commit
*commit
;
1711 for_each_new_crtc_in_state(old_state
, crtc
, new_crtc_state
, i
) {
1712 commit
= old_state
->crtcs
[i
].commit
;
1716 /* backend must have consumed any event by now */
1717 WARN_ON(new_crtc_state
->event
);
1718 spin_lock(&crtc
->commit_lock
);
1719 complete_all(&commit
->hw_done
);
1720 spin_unlock(&crtc
->commit_lock
);
1723 EXPORT_SYMBOL(drm_atomic_helper_commit_hw_done
);
1726 * drm_atomic_helper_commit_cleanup_done - signal completion of commit
1727 * @old_state: atomic state object with old state structures
1729 * This signals completion of the atomic update @old_state, including any
1730 * cleanup work. If used, it must be called right before calling
1731 * drm_atomic_state_put().
1733 * This is part of the atomic helper support for nonblocking commits, see
1734 * drm_atomic_helper_setup_commit() for an overview.
1736 void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state
*old_state
)
1738 struct drm_crtc
*crtc
;
1739 struct drm_crtc_state
*new_crtc_state
;
1740 struct drm_crtc_commit
*commit
;
1744 for_each_new_crtc_in_state(old_state
, crtc
, new_crtc_state
, i
) {
1745 commit
= old_state
->crtcs
[i
].commit
;
1746 if (WARN_ON(!commit
))
1749 spin_lock(&crtc
->commit_lock
);
1750 complete_all(&commit
->cleanup_done
);
1751 WARN_ON(!try_wait_for_completion(&commit
->hw_done
));
1753 /* commit_list borrows our reference, need to remove before we
1754 * clean up our drm_atomic_state. But only after it actually
1755 * completed, otherwise subsequent commits won't stall properly. */
1756 if (try_wait_for_completion(&commit
->flip_done
))
1759 spin_unlock(&crtc
->commit_lock
);
1761 /* We must wait for the vblank event to signal our completion
1762 * before releasing our reference, since the vblank work does
1763 * not hold a reference of its own. */
1764 ret
= wait_for_completion_timeout(&commit
->flip_done
,
1767 DRM_ERROR("[CRTC:%d:%s] flip_done timed out\n",
1768 crtc
->base
.id
, crtc
->name
);
1770 spin_lock(&crtc
->commit_lock
);
1772 list_del(&commit
->commit_entry
);
1773 spin_unlock(&crtc
->commit_lock
);
1776 EXPORT_SYMBOL(drm_atomic_helper_commit_cleanup_done
);
1779 * drm_atomic_helper_prepare_planes - prepare plane resources before commit
1781 * @state: atomic state object with new state structures
1783 * This function prepares plane state, specifically framebuffers, for the new
1784 * configuration, by calling &drm_plane_helper_funcs.prepare_fb. If any failure
1785 * is encountered this function will call &drm_plane_helper_funcs.cleanup_fb on
1786 * any already successfully prepared framebuffer.
1789 * 0 on success, negative error code on failure.
1791 int drm_atomic_helper_prepare_planes(struct drm_device
*dev
,
1792 struct drm_atomic_state
*state
)
1794 struct drm_plane
*plane
;
1795 struct drm_plane_state
*new_plane_state
;
1798 for_each_new_plane_in_state(state
, plane
, new_plane_state
, i
) {
1799 const struct drm_plane_helper_funcs
*funcs
;
1801 funcs
= plane
->helper_private
;
1803 if (funcs
->prepare_fb
) {
1804 ret
= funcs
->prepare_fb(plane
, new_plane_state
);
1813 for_each_new_plane_in_state(state
, plane
, new_plane_state
, j
) {
1814 const struct drm_plane_helper_funcs
*funcs
;
1819 funcs
= plane
->helper_private
;
1821 if (funcs
->cleanup_fb
)
1822 funcs
->cleanup_fb(plane
, new_plane_state
);
1827 EXPORT_SYMBOL(drm_atomic_helper_prepare_planes
);
1829 static bool plane_crtc_active(const struct drm_plane_state
*state
)
1831 return state
->crtc
&& state
->crtc
->state
->active
;
1835 * drm_atomic_helper_commit_planes - commit plane state
1837 * @old_state: atomic state object with old state structures
1838 * @flags: flags for committing plane state
1840 * This function commits the new plane state using the plane and atomic helper
1841 * functions for planes and crtcs. It assumes that the atomic state has already
1842 * been pushed into the relevant object state pointers, since this step can no
1845 * It still requires the global state object @old_state to know which planes and
1846 * crtcs need to be updated though.
1848 * Note that this function does all plane updates across all CRTCs in one step.
1849 * If the hardware can't support this approach look at
1850 * drm_atomic_helper_commit_planes_on_crtc() instead.
1852 * Plane parameters can be updated by applications while the associated CRTC is
1853 * disabled. The DRM/KMS core will store the parameters in the plane state,
1854 * which will be available to the driver when the CRTC is turned on. As a result
1855 * most drivers don't need to be immediately notified of plane updates for a
1858 * Unless otherwise needed, drivers are advised to set the ACTIVE_ONLY flag in
1859 * @flags in order not to receive plane update notifications related to a
1860 * disabled CRTC. This avoids the need to manually ignore plane updates in
1861 * driver code when the driver and/or hardware can't or just don't need to deal
1862 * with updates on disabled CRTCs, for example when supporting runtime PM.
1864 * Drivers may set the NO_DISABLE_AFTER_MODESET flag in @flags if the relevant
1865 * display controllers require to disable a CRTC's planes when the CRTC is
1866 * disabled. This function would skip the &drm_plane_helper_funcs.atomic_disable
1867 * call for a plane if the CRTC of the old plane state needs a modesetting
1868 * operation. Of course, the drivers need to disable the planes in their CRTC
1869 * disable callbacks since no one else would do that.
1871 * The drm_atomic_helper_commit() default implementation doesn't set the
1872 * ACTIVE_ONLY flag to most closely match the behaviour of the legacy helpers.
1873 * This should not be copied blindly by drivers.
1875 void drm_atomic_helper_commit_planes(struct drm_device
*dev
,
1876 struct drm_atomic_state
*old_state
,
1879 struct drm_crtc
*crtc
;
1880 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
1881 struct drm_plane
*plane
;
1882 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
1884 bool active_only
= flags
& DRM_PLANE_COMMIT_ACTIVE_ONLY
;
1885 bool no_disable
= flags
& DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET
;
1887 for_each_oldnew_crtc_in_state(old_state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
1888 const struct drm_crtc_helper_funcs
*funcs
;
1890 funcs
= crtc
->helper_private
;
1892 if (!funcs
|| !funcs
->atomic_begin
)
1895 if (active_only
&& !new_crtc_state
->active
)
1898 funcs
->atomic_begin(crtc
, old_crtc_state
);
1901 for_each_oldnew_plane_in_state(old_state
, plane
, old_plane_state
, new_plane_state
, i
) {
1902 const struct drm_plane_helper_funcs
*funcs
;
1905 funcs
= plane
->helper_private
;
1910 disabling
= drm_atomic_plane_disabling(old_plane_state
,
1915 * Skip planes related to inactive CRTCs. If the plane
1916 * is enabled use the state of the current CRTC. If the
1917 * plane is being disabled use the state of the old
1918 * CRTC to avoid skipping planes being disabled on an
1921 if (!disabling
&& !plane_crtc_active(new_plane_state
))
1923 if (disabling
&& !plane_crtc_active(old_plane_state
))
1928 * Special-case disabling the plane if drivers support it.
1930 if (disabling
&& funcs
->atomic_disable
) {
1931 struct drm_crtc_state
*crtc_state
;
1933 crtc_state
= old_plane_state
->crtc
->state
;
1935 if (drm_atomic_crtc_needs_modeset(crtc_state
) &&
1939 funcs
->atomic_disable(plane
, old_plane_state
);
1940 } else if (new_plane_state
->crtc
|| disabling
) {
1941 funcs
->atomic_update(plane
, old_plane_state
);
1945 for_each_oldnew_crtc_in_state(old_state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
1946 const struct drm_crtc_helper_funcs
*funcs
;
1948 funcs
= crtc
->helper_private
;
1950 if (!funcs
|| !funcs
->atomic_flush
)
1953 if (active_only
&& !new_crtc_state
->active
)
1956 funcs
->atomic_flush(crtc
, old_crtc_state
);
1959 EXPORT_SYMBOL(drm_atomic_helper_commit_planes
);
1962 * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc
1963 * @old_crtc_state: atomic state object with the old crtc state
1965 * This function commits the new plane state using the plane and atomic helper
1966 * functions for planes on the specific crtc. It assumes that the atomic state
1967 * has already been pushed into the relevant object state pointers, since this
1968 * step can no longer fail.
1970 * This function is useful when plane updates should be done crtc-by-crtc
1971 * instead of one global step like drm_atomic_helper_commit_planes() does.
1973 * This function can only be savely used when planes are not allowed to move
1974 * between different CRTCs because this function doesn't handle inter-CRTC
1975 * depencies. Callers need to ensure that either no such depencies exist,
1976 * resolve them through ordering of commit calls or through some other means.
1979 drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state
*old_crtc_state
)
1981 const struct drm_crtc_helper_funcs
*crtc_funcs
;
1982 struct drm_crtc
*crtc
= old_crtc_state
->crtc
;
1983 struct drm_atomic_state
*old_state
= old_crtc_state
->state
;
1984 struct drm_plane
*plane
;
1985 unsigned plane_mask
;
1987 plane_mask
= old_crtc_state
->plane_mask
;
1988 plane_mask
|= crtc
->state
->plane_mask
;
1990 crtc_funcs
= crtc
->helper_private
;
1991 if (crtc_funcs
&& crtc_funcs
->atomic_begin
)
1992 crtc_funcs
->atomic_begin(crtc
, old_crtc_state
);
1994 drm_for_each_plane_mask(plane
, crtc
->dev
, plane_mask
) {
1995 struct drm_plane_state
*old_plane_state
=
1996 drm_atomic_get_old_plane_state(old_state
, plane
);
1997 const struct drm_plane_helper_funcs
*plane_funcs
;
1999 plane_funcs
= plane
->helper_private
;
2001 if (!old_plane_state
|| !plane_funcs
)
2004 WARN_ON(plane
->state
->crtc
&& plane
->state
->crtc
!= crtc
);
2006 if (drm_atomic_plane_disabling(old_plane_state
, plane
->state
) &&
2007 plane_funcs
->atomic_disable
)
2008 plane_funcs
->atomic_disable(plane
, old_plane_state
);
2009 else if (plane
->state
->crtc
||
2010 drm_atomic_plane_disabling(old_plane_state
, plane
->state
))
2011 plane_funcs
->atomic_update(plane
, old_plane_state
);
2014 if (crtc_funcs
&& crtc_funcs
->atomic_flush
)
2015 crtc_funcs
->atomic_flush(crtc
, old_crtc_state
);
2017 EXPORT_SYMBOL(drm_atomic_helper_commit_planes_on_crtc
);
2020 * drm_atomic_helper_disable_planes_on_crtc - helper to disable CRTC's planes
2021 * @old_crtc_state: atomic state object with the old CRTC state
2022 * @atomic: if set, synchronize with CRTC's atomic_begin/flush hooks
2024 * Disables all planes associated with the given CRTC. This can be
2025 * used for instance in the CRTC helper atomic_disable callback to disable
2028 * If the atomic-parameter is set the function calls the CRTC's
2029 * atomic_begin hook before and atomic_flush hook after disabling the
2032 * It is a bug to call this function without having implemented the
2033 * &drm_plane_helper_funcs.atomic_disable plane hook.
2036 drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state
*old_crtc_state
,
2039 struct drm_crtc
*crtc
= old_crtc_state
->crtc
;
2040 const struct drm_crtc_helper_funcs
*crtc_funcs
=
2041 crtc
->helper_private
;
2042 struct drm_plane
*plane
;
2044 if (atomic
&& crtc_funcs
&& crtc_funcs
->atomic_begin
)
2045 crtc_funcs
->atomic_begin(crtc
, NULL
);
2047 drm_atomic_crtc_state_for_each_plane(plane
, old_crtc_state
) {
2048 const struct drm_plane_helper_funcs
*plane_funcs
=
2049 plane
->helper_private
;
2054 WARN_ON(!plane_funcs
->atomic_disable
);
2055 if (plane_funcs
->atomic_disable
)
2056 plane_funcs
->atomic_disable(plane
, NULL
);
2059 if (atomic
&& crtc_funcs
&& crtc_funcs
->atomic_flush
)
2060 crtc_funcs
->atomic_flush(crtc
, NULL
);
2062 EXPORT_SYMBOL(drm_atomic_helper_disable_planes_on_crtc
);
2065 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit
2067 * @old_state: atomic state object with old state structures
2069 * This function cleans up plane state, specifically framebuffers, from the old
2070 * configuration. Hence the old configuration must be perserved in @old_state to
2071 * be able to call this function.
2073 * This function must also be called on the new state when the atomic update
2074 * fails at any point after calling drm_atomic_helper_prepare_planes().
2076 void drm_atomic_helper_cleanup_planes(struct drm_device
*dev
,
2077 struct drm_atomic_state
*old_state
)
2079 struct drm_plane
*plane
;
2080 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
2083 for_each_oldnew_plane_in_state(old_state
, plane
, old_plane_state
, new_plane_state
, i
) {
2084 const struct drm_plane_helper_funcs
*funcs
;
2085 struct drm_plane_state
*plane_state
;
2088 * This might be called before swapping when commit is aborted,
2089 * in which case we have to cleanup the new state.
2091 if (old_plane_state
== plane
->state
)
2092 plane_state
= new_plane_state
;
2094 plane_state
= old_plane_state
;
2096 funcs
= plane
->helper_private
;
2098 if (funcs
->cleanup_fb
)
2099 funcs
->cleanup_fb(plane
, plane_state
);
2102 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes
);
2105 * drm_atomic_helper_swap_state - store atomic state into current sw state
2106 * @state: atomic state
2107 * @stall: stall for proceeding commits
2109 * This function stores the atomic state into the current state pointers in all
2110 * driver objects. It should be called after all failing steps have been done
2111 * and succeeded, but before the actual hardware state is committed.
2113 * For cleanup and error recovery the current state for all changed objects will
2114 * be swaped into @state.
2116 * With that sequence it fits perfectly into the plane prepare/cleanup sequence:
2118 * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state.
2120 * 2. Do any other steps that might fail.
2122 * 3. Put the staged state into the current state pointers with this function.
2124 * 4. Actually commit the hardware state.
2126 * 5. Call drm_atomic_helper_cleanup_planes() with @state, which since step 3
2127 * contains the old state. Also do any other cleanup required with that state.
2129 * @stall must be set when nonblocking commits for this driver directly access
2130 * the &drm_plane.state, &drm_crtc.state or &drm_connector.state pointer. With
2131 * the current atomic helpers this is almost always the case, since the helpers
2132 * don't pass the right state structures to the callbacks.
2134 void drm_atomic_helper_swap_state(struct drm_atomic_state
*state
,
2139 struct drm_connector
*connector
;
2140 struct drm_connector_state
*old_conn_state
, *new_conn_state
;
2141 struct drm_crtc
*crtc
;
2142 struct drm_crtc_state
*old_crtc_state
, *new_crtc_state
;
2143 struct drm_plane
*plane
;
2144 struct drm_plane_state
*old_plane_state
, *new_plane_state
;
2145 struct drm_crtc_commit
*commit
;
2146 void *obj
, *obj_state
;
2147 const struct drm_private_state_funcs
*funcs
;
2150 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
2151 spin_lock(&crtc
->commit_lock
);
2152 commit
= list_first_entry_or_null(&crtc
->commit_list
,
2153 struct drm_crtc_commit
, commit_entry
);
2155 drm_crtc_commit_get(commit
);
2156 spin_unlock(&crtc
->commit_lock
);
2161 ret
= wait_for_completion_timeout(&commit
->hw_done
,
2164 DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n",
2165 crtc
->base
.id
, crtc
->name
);
2166 drm_crtc_commit_put(commit
);
2170 for_each_oldnew_connector_in_state(state
, connector
, old_conn_state
, new_conn_state
, i
) {
2171 WARN_ON(connector
->state
!= old_conn_state
);
2173 old_conn_state
->state
= state
;
2174 new_conn_state
->state
= NULL
;
2176 state
->connectors
[i
].state
= old_conn_state
;
2177 connector
->state
= new_conn_state
;
2180 for_each_oldnew_crtc_in_state(state
, crtc
, old_crtc_state
, new_crtc_state
, i
) {
2181 WARN_ON(crtc
->state
!= old_crtc_state
);
2183 old_crtc_state
->state
= state
;
2184 new_crtc_state
->state
= NULL
;
2186 state
->crtcs
[i
].state
= old_crtc_state
;
2187 crtc
->state
= new_crtc_state
;
2189 if (state
->crtcs
[i
].commit
) {
2190 spin_lock(&crtc
->commit_lock
);
2191 list_add(&state
->crtcs
[i
].commit
->commit_entry
,
2192 &crtc
->commit_list
);
2193 spin_unlock(&crtc
->commit_lock
);
2195 state
->crtcs
[i
].commit
->event
= NULL
;
2199 for_each_oldnew_plane_in_state(state
, plane
, old_plane_state
, new_plane_state
, i
) {
2200 WARN_ON(plane
->state
!= old_plane_state
);
2202 old_plane_state
->state
= state
;
2203 new_plane_state
->state
= NULL
;
2205 state
->planes
[i
].state
= old_plane_state
;
2206 plane
->state
= new_plane_state
;
2209 __for_each_private_obj(state
, obj
, obj_state
, i
, funcs
)
2210 funcs
->swap_state(obj
, &state
->private_objs
[i
].obj_state
);
2212 EXPORT_SYMBOL(drm_atomic_helper_swap_state
);
2215 * drm_atomic_helper_update_plane - Helper for primary plane update using atomic
2216 * @plane: plane object to update
2217 * @crtc: owning CRTC of owning plane
2218 * @fb: framebuffer to flip onto plane
2219 * @crtc_x: x offset of primary plane on crtc
2220 * @crtc_y: y offset of primary plane on crtc
2221 * @crtc_w: width of primary plane rectangle on crtc
2222 * @crtc_h: height of primary plane rectangle on crtc
2223 * @src_x: x offset of @fb for panning
2224 * @src_y: y offset of @fb for panning
2225 * @src_w: width of source rectangle in @fb
2226 * @src_h: height of source rectangle in @fb
2227 * @ctx: lock acquire context
2229 * Provides a default plane update handler using the atomic driver interface.
2232 * Zero on success, error code on failure
2234 int drm_atomic_helper_update_plane(struct drm_plane
*plane
,
2235 struct drm_crtc
*crtc
,
2236 struct drm_framebuffer
*fb
,
2237 int crtc_x
, int crtc_y
,
2238 unsigned int crtc_w
, unsigned int crtc_h
,
2239 uint32_t src_x
, uint32_t src_y
,
2240 uint32_t src_w
, uint32_t src_h
,
2241 struct drm_modeset_acquire_ctx
*ctx
)
2243 struct drm_atomic_state
*state
;
2244 struct drm_plane_state
*plane_state
;
2247 state
= drm_atomic_state_alloc(plane
->dev
);
2251 state
->acquire_ctx
= ctx
;
2252 plane_state
= drm_atomic_get_plane_state(state
, plane
);
2253 if (IS_ERR(plane_state
)) {
2254 ret
= PTR_ERR(plane_state
);
2258 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
2261 drm_atomic_set_fb_for_plane(plane_state
, fb
);
2262 plane_state
->crtc_x
= crtc_x
;
2263 plane_state
->crtc_y
= crtc_y
;
2264 plane_state
->crtc_w
= crtc_w
;
2265 plane_state
->crtc_h
= crtc_h
;
2266 plane_state
->src_x
= src_x
;
2267 plane_state
->src_y
= src_y
;
2268 plane_state
->src_w
= src_w
;
2269 plane_state
->src_h
= src_h
;
2271 if (plane
== crtc
->cursor
)
2272 state
->legacy_cursor_update
= true;
2274 ret
= drm_atomic_commit(state
);
2276 drm_atomic_state_put(state
);
2279 EXPORT_SYMBOL(drm_atomic_helper_update_plane
);
2282 * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic
2283 * @plane: plane to disable
2284 * @ctx: lock acquire context
2286 * Provides a default plane disable handler using the atomic driver interface.
2289 * Zero on success, error code on failure
2291 int drm_atomic_helper_disable_plane(struct drm_plane
*plane
,
2292 struct drm_modeset_acquire_ctx
*ctx
)
2294 struct drm_atomic_state
*state
;
2295 struct drm_plane_state
*plane_state
;
2298 state
= drm_atomic_state_alloc(plane
->dev
);
2302 state
->acquire_ctx
= ctx
;
2303 plane_state
= drm_atomic_get_plane_state(state
, plane
);
2304 if (IS_ERR(plane_state
)) {
2305 ret
= PTR_ERR(plane_state
);
2309 if (plane_state
->crtc
&& (plane
== plane
->crtc
->cursor
))
2310 plane_state
->state
->legacy_cursor_update
= true;
2312 ret
= __drm_atomic_helper_disable_plane(plane
, plane_state
);
2316 ret
= drm_atomic_commit(state
);
2318 drm_atomic_state_put(state
);
2321 EXPORT_SYMBOL(drm_atomic_helper_disable_plane
);
2323 /* just used from fb-helper and atomic-helper: */
2324 int __drm_atomic_helper_disable_plane(struct drm_plane
*plane
,
2325 struct drm_plane_state
*plane_state
)
2329 ret
= drm_atomic_set_crtc_for_plane(plane_state
, NULL
);
2333 drm_atomic_set_fb_for_plane(plane_state
, NULL
);
2334 plane_state
->crtc_x
= 0;
2335 plane_state
->crtc_y
= 0;
2336 plane_state
->crtc_w
= 0;
2337 plane_state
->crtc_h
= 0;
2338 plane_state
->src_x
= 0;
2339 plane_state
->src_y
= 0;
2340 plane_state
->src_w
= 0;
2341 plane_state
->src_h
= 0;
2346 static int update_output_state(struct drm_atomic_state
*state
,
2347 struct drm_mode_set
*set
)
2349 struct drm_device
*dev
= set
->crtc
->dev
;
2350 struct drm_crtc
*crtc
;
2351 struct drm_crtc_state
*new_crtc_state
;
2352 struct drm_connector
*connector
;
2353 struct drm_connector_state
*new_conn_state
;
2356 ret
= drm_modeset_lock(&dev
->mode_config
.connection_mutex
,
2357 state
->acquire_ctx
);
2361 /* First disable all connectors on the target crtc. */
2362 ret
= drm_atomic_add_affected_connectors(state
, set
->crtc
);
2366 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
) {
2367 if (new_conn_state
->crtc
== set
->crtc
) {
2368 ret
= drm_atomic_set_crtc_for_connector(new_conn_state
,
2373 /* Make sure legacy setCrtc always re-trains */
2374 new_conn_state
->link_status
= DRM_LINK_STATUS_GOOD
;
2378 /* Then set all connectors from set->connectors on the target crtc */
2379 for (i
= 0; i
< set
->num_connectors
; i
++) {
2380 new_conn_state
= drm_atomic_get_connector_state(state
,
2381 set
->connectors
[i
]);
2382 if (IS_ERR(new_conn_state
))
2383 return PTR_ERR(new_conn_state
);
2385 ret
= drm_atomic_set_crtc_for_connector(new_conn_state
,
2391 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
) {
2392 /* Don't update ->enable for the CRTC in the set_config request,
2393 * since a mismatch would indicate a bug in the upper layers.
2394 * The actual modeset code later on will catch any
2395 * inconsistencies here. */
2396 if (crtc
== set
->crtc
)
2399 if (!new_crtc_state
->connector_mask
) {
2400 ret
= drm_atomic_set_mode_prop_for_crtc(new_crtc_state
,
2405 new_crtc_state
->active
= false;
2413 * drm_atomic_helper_set_config - set a new config from userspace
2414 * @set: mode set configuration
2415 * @ctx: lock acquisition context
2417 * Provides a default crtc set_config handler using the atomic driver interface.
2419 * NOTE: For backwards compatibility with old userspace this automatically
2420 * resets the "link-status" property to GOOD, to force any link
2421 * re-training. The SETCRTC ioctl does not define whether an update does
2422 * need a full modeset or just a plane update, hence we're allowed to do
2423 * that. See also drm_mode_connector_set_link_status_property().
2426 * Returns 0 on success, negative errno numbers on failure.
2428 int drm_atomic_helper_set_config(struct drm_mode_set
*set
,
2429 struct drm_modeset_acquire_ctx
*ctx
)
2431 struct drm_atomic_state
*state
;
2432 struct drm_crtc
*crtc
= set
->crtc
;
2435 state
= drm_atomic_state_alloc(crtc
->dev
);
2439 state
->acquire_ctx
= ctx
;
2440 ret
= __drm_atomic_helper_set_config(set
, state
);
2444 ret
= handle_conflicting_encoders(state
, true);
2448 ret
= drm_atomic_commit(state
);
2451 drm_atomic_state_put(state
);
2454 EXPORT_SYMBOL(drm_atomic_helper_set_config
);
2456 /* just used from fb-helper and atomic-helper: */
2457 int __drm_atomic_helper_set_config(struct drm_mode_set
*set
,
2458 struct drm_atomic_state
*state
)
2460 struct drm_crtc_state
*crtc_state
;
2461 struct drm_plane_state
*primary_state
;
2462 struct drm_crtc
*crtc
= set
->crtc
;
2463 int hdisplay
, vdisplay
;
2466 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
2467 if (IS_ERR(crtc_state
))
2468 return PTR_ERR(crtc_state
);
2470 primary_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
2471 if (IS_ERR(primary_state
))
2472 return PTR_ERR(primary_state
);
2476 WARN_ON(set
->num_connectors
);
2478 ret
= drm_atomic_set_mode_for_crtc(crtc_state
, NULL
);
2482 crtc_state
->active
= false;
2484 ret
= drm_atomic_set_crtc_for_plane(primary_state
, NULL
);
2488 drm_atomic_set_fb_for_plane(primary_state
, NULL
);
2494 WARN_ON(!set
->num_connectors
);
2496 ret
= drm_atomic_set_mode_for_crtc(crtc_state
, set
->mode
);
2500 crtc_state
->active
= true;
2502 ret
= drm_atomic_set_crtc_for_plane(primary_state
, crtc
);
2506 drm_mode_get_hv_timing(set
->mode
, &hdisplay
, &vdisplay
);
2508 drm_atomic_set_fb_for_plane(primary_state
, set
->fb
);
2509 primary_state
->crtc_x
= 0;
2510 primary_state
->crtc_y
= 0;
2511 primary_state
->crtc_w
= hdisplay
;
2512 primary_state
->crtc_h
= vdisplay
;
2513 primary_state
->src_x
= set
->x
<< 16;
2514 primary_state
->src_y
= set
->y
<< 16;
2515 if (drm_rotation_90_or_270(primary_state
->rotation
)) {
2516 primary_state
->src_w
= vdisplay
<< 16;
2517 primary_state
->src_h
= hdisplay
<< 16;
2519 primary_state
->src_w
= hdisplay
<< 16;
2520 primary_state
->src_h
= vdisplay
<< 16;
2524 ret
= update_output_state(state
, set
);
2532 * drm_atomic_helper_disable_all - disable all currently active outputs
2534 * @ctx: lock acquisition context
2536 * Loops through all connectors, finding those that aren't turned off and then
2537 * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
2538 * that they are connected to.
2540 * This is used for example in suspend/resume to disable all currently active
2541 * functions when suspending. If you just want to shut down everything at e.g.
2542 * driver unload, look at drm_atomic_helper_shutdown().
2544 * Note that if callers haven't already acquired all modeset locks this might
2545 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
2548 * 0 on success or a negative error code on failure.
2551 * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and
2552 * drm_atomic_helper_shutdown().
2554 int drm_atomic_helper_disable_all(struct drm_device
*dev
,
2555 struct drm_modeset_acquire_ctx
*ctx
)
2557 struct drm_atomic_state
*state
;
2558 struct drm_connector_state
*conn_state
;
2559 struct drm_connector
*conn
;
2560 struct drm_plane_state
*plane_state
;
2561 struct drm_plane
*plane
;
2562 struct drm_crtc_state
*crtc_state
;
2563 struct drm_crtc
*crtc
;
2566 state
= drm_atomic_state_alloc(dev
);
2570 state
->acquire_ctx
= ctx
;
2572 drm_for_each_crtc(crtc
, dev
) {
2573 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
2574 if (IS_ERR(crtc_state
)) {
2575 ret
= PTR_ERR(crtc_state
);
2579 crtc_state
->active
= false;
2581 ret
= drm_atomic_set_mode_prop_for_crtc(crtc_state
, NULL
);
2585 ret
= drm_atomic_add_affected_planes(state
, crtc
);
2589 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
2594 for_each_connector_in_state(state
, conn
, conn_state
, i
) {
2595 ret
= drm_atomic_set_crtc_for_connector(conn_state
, NULL
);
2600 for_each_plane_in_state(state
, plane
, plane_state
, i
) {
2601 ret
= drm_atomic_set_crtc_for_plane(plane_state
, NULL
);
2605 drm_atomic_set_fb_for_plane(plane_state
, NULL
);
2608 ret
= drm_atomic_commit(state
);
2610 drm_atomic_state_put(state
);
2614 EXPORT_SYMBOL(drm_atomic_helper_disable_all
);
2617 * drm_atomic_helper_shutdown - shutdown all CRTC
2620 * This shuts down all CRTC, which is useful for driver unloading. Shutdown on
2621 * suspend should instead be handled with drm_atomic_helper_suspend(), since
2622 * that also takes a snapshot of the modeset state to be restored on resume.
2624 * This is just a convenience wrapper around drm_atomic_helper_disable_all(),
2625 * and it is the atomic version of drm_crtc_force_disable_all().
2627 void drm_atomic_helper_shutdown(struct drm_device
*dev
)
2629 struct drm_modeset_acquire_ctx ctx
;
2632 drm_modeset_acquire_init(&ctx
, 0);
2634 ret
= drm_modeset_lock_all_ctx(dev
, &ctx
);
2636 ret
= drm_atomic_helper_disable_all(dev
, &ctx
);
2638 if (ret
!= -EDEADLK
)
2641 drm_modeset_backoff(&ctx
);
2645 DRM_ERROR("Disabling all crtc's during unload failed with %i\n", ret
);
2647 drm_modeset_drop_locks(&ctx
);
2648 drm_modeset_acquire_fini(&ctx
);
2650 EXPORT_SYMBOL(drm_atomic_helper_shutdown
);
2653 * drm_atomic_helper_suspend - subsystem-level suspend helper
2656 * Duplicates the current atomic state, disables all active outputs and then
2657 * returns a pointer to the original atomic state to the caller. Drivers can
2658 * pass this pointer to the drm_atomic_helper_resume() helper upon resume to
2659 * restore the output configuration that was active at the time the system
2662 * Note that it is potentially unsafe to use this. The atomic state object
2663 * returned by this function is assumed to be persistent. Drivers must ensure
2664 * that this holds true. Before calling this function, drivers must make sure
2665 * to suspend fbdev emulation so that nothing can be using the device.
2668 * A pointer to a copy of the state before suspend on success or an ERR_PTR()-
2669 * encoded error code on failure. Drivers should store the returned atomic
2670 * state object and pass it to the drm_atomic_helper_resume() helper upon
2674 * drm_atomic_helper_duplicate_state(), drm_atomic_helper_disable_all(),
2675 * drm_atomic_helper_resume(), drm_atomic_helper_commit_duplicated_state()
2677 struct drm_atomic_state
*drm_atomic_helper_suspend(struct drm_device
*dev
)
2679 struct drm_modeset_acquire_ctx ctx
;
2680 struct drm_atomic_state
*state
;
2683 drm_modeset_acquire_init(&ctx
, 0);
2686 err
= drm_modeset_lock_all_ctx(dev
, &ctx
);
2688 state
= ERR_PTR(err
);
2692 state
= drm_atomic_helper_duplicate_state(dev
, &ctx
);
2696 err
= drm_atomic_helper_disable_all(dev
, &ctx
);
2698 drm_atomic_state_put(state
);
2699 state
= ERR_PTR(err
);
2704 if (PTR_ERR(state
) == -EDEADLK
) {
2705 drm_modeset_backoff(&ctx
);
2709 drm_modeset_drop_locks(&ctx
);
2710 drm_modeset_acquire_fini(&ctx
);
2713 EXPORT_SYMBOL(drm_atomic_helper_suspend
);
2716 * drm_atomic_helper_commit_duplicated_state - commit duplicated state
2717 * @state: duplicated atomic state to commit
2718 * @ctx: pointer to acquire_ctx to use for commit.
2720 * The state returned by drm_atomic_helper_duplicate_state() and
2721 * drm_atomic_helper_suspend() is partially invalid, and needs to
2722 * be fixed up before commit.
2725 * 0 on success or a negative error code on failure.
2728 * drm_atomic_helper_suspend()
2730 int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state
*state
,
2731 struct drm_modeset_acquire_ctx
*ctx
)
2734 struct drm_plane
*plane
;
2735 struct drm_plane_state
*new_plane_state
;
2736 struct drm_connector
*connector
;
2737 struct drm_connector_state
*new_conn_state
;
2738 struct drm_crtc
*crtc
;
2739 struct drm_crtc_state
*new_crtc_state
;
2741 state
->acquire_ctx
= ctx
;
2743 for_each_new_plane_in_state(state
, plane
, new_plane_state
, i
)
2744 state
->planes
[i
].old_state
= plane
->state
;
2746 for_each_new_crtc_in_state(state
, crtc
, new_crtc_state
, i
)
2747 state
->crtcs
[i
].old_state
= crtc
->state
;
2749 for_each_new_connector_in_state(state
, connector
, new_conn_state
, i
)
2750 state
->connectors
[i
].old_state
= connector
->state
;
2752 return drm_atomic_commit(state
);
2754 EXPORT_SYMBOL(drm_atomic_helper_commit_duplicated_state
);
2757 * drm_atomic_helper_resume - subsystem-level resume helper
2759 * @state: atomic state to resume to
2761 * Calls drm_mode_config_reset() to synchronize hardware and software states,
2762 * grabs all modeset locks and commits the atomic state object. This can be
2763 * used in conjunction with the drm_atomic_helper_suspend() helper to
2764 * implement suspend/resume for drivers that support atomic mode-setting.
2767 * 0 on success or a negative error code on failure.
2770 * drm_atomic_helper_suspend()
2772 int drm_atomic_helper_resume(struct drm_device
*dev
,
2773 struct drm_atomic_state
*state
)
2775 struct drm_modeset_acquire_ctx ctx
;
2778 drm_mode_config_reset(dev
);
2780 drm_modeset_acquire_init(&ctx
, 0);
2782 err
= drm_atomic_helper_commit_duplicated_state(state
, &ctx
);
2783 if (err
!= -EDEADLK
)
2786 drm_modeset_backoff(&ctx
);
2789 drm_modeset_drop_locks(&ctx
);
2790 drm_modeset_acquire_fini(&ctx
);
2794 EXPORT_SYMBOL(drm_atomic_helper_resume
);
2797 * drm_atomic_helper_crtc_set_property - helper for crtc properties
2799 * @property: DRM property
2800 * @val: value of property
2802 * Provides a default crtc set_property handler using the atomic driver
2806 * Zero on success, error code on failure
2809 drm_atomic_helper_crtc_set_property(struct drm_crtc
*crtc
,
2810 struct drm_property
*property
,
2813 struct drm_atomic_state
*state
;
2814 struct drm_crtc_state
*crtc_state
;
2817 state
= drm_atomic_state_alloc(crtc
->dev
);
2821 /* ->set_property is always called with all locks held. */
2822 state
->acquire_ctx
= crtc
->dev
->mode_config
.acquire_ctx
;
2824 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
2825 if (IS_ERR(crtc_state
)) {
2826 ret
= PTR_ERR(crtc_state
);
2830 ret
= drm_atomic_crtc_set_property(crtc
, crtc_state
,
2835 ret
= drm_atomic_commit(state
);
2837 if (ret
== -EDEADLK
)
2840 drm_atomic_state_put(state
);
2844 drm_atomic_state_clear(state
);
2845 drm_atomic_legacy_backoff(state
);
2849 EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property
);
2852 * drm_atomic_helper_plane_set_property - helper for plane properties
2854 * @property: DRM property
2855 * @val: value of property
2857 * Provides a default plane set_property handler using the atomic driver
2861 * Zero on success, error code on failure
2864 drm_atomic_helper_plane_set_property(struct drm_plane
*plane
,
2865 struct drm_property
*property
,
2868 struct drm_atomic_state
*state
;
2869 struct drm_plane_state
*plane_state
;
2872 state
= drm_atomic_state_alloc(plane
->dev
);
2876 /* ->set_property is always called with all locks held. */
2877 state
->acquire_ctx
= plane
->dev
->mode_config
.acquire_ctx
;
2879 plane_state
= drm_atomic_get_plane_state(state
, plane
);
2880 if (IS_ERR(plane_state
)) {
2881 ret
= PTR_ERR(plane_state
);
2885 ret
= drm_atomic_plane_set_property(plane
, plane_state
,
2890 ret
= drm_atomic_commit(state
);
2892 if (ret
== -EDEADLK
)
2895 drm_atomic_state_put(state
);
2899 drm_atomic_state_clear(state
);
2900 drm_atomic_legacy_backoff(state
);
2904 EXPORT_SYMBOL(drm_atomic_helper_plane_set_property
);
2907 * drm_atomic_helper_connector_set_property - helper for connector properties
2908 * @connector: DRM connector
2909 * @property: DRM property
2910 * @val: value of property
2912 * Provides a default connector set_property handler using the atomic driver
2916 * Zero on success, error code on failure
2919 drm_atomic_helper_connector_set_property(struct drm_connector
*connector
,
2920 struct drm_property
*property
,
2923 struct drm_atomic_state
*state
;
2924 struct drm_connector_state
*connector_state
;
2927 state
= drm_atomic_state_alloc(connector
->dev
);
2931 /* ->set_property is always called with all locks held. */
2932 state
->acquire_ctx
= connector
->dev
->mode_config
.acquire_ctx
;
2934 connector_state
= drm_atomic_get_connector_state(state
, connector
);
2935 if (IS_ERR(connector_state
)) {
2936 ret
= PTR_ERR(connector_state
);
2940 ret
= drm_atomic_connector_set_property(connector
, connector_state
,
2945 ret
= drm_atomic_commit(state
);
2947 if (ret
== -EDEADLK
)
2950 drm_atomic_state_put(state
);
2954 drm_atomic_state_clear(state
);
2955 drm_atomic_legacy_backoff(state
);
2959 EXPORT_SYMBOL(drm_atomic_helper_connector_set_property
);
2961 static int page_flip_common(
2962 struct drm_atomic_state
*state
,
2963 struct drm_crtc
*crtc
,
2964 struct drm_framebuffer
*fb
,
2965 struct drm_pending_vblank_event
*event
,
2968 struct drm_plane
*plane
= crtc
->primary
;
2969 struct drm_plane_state
*plane_state
;
2970 struct drm_crtc_state
*crtc_state
;
2973 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
2974 if (IS_ERR(crtc_state
))
2975 return PTR_ERR(crtc_state
);
2977 crtc_state
->event
= event
;
2978 crtc_state
->pageflip_flags
= flags
;
2980 plane_state
= drm_atomic_get_plane_state(state
, plane
);
2981 if (IS_ERR(plane_state
))
2982 return PTR_ERR(plane_state
);
2984 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
2987 drm_atomic_set_fb_for_plane(plane_state
, fb
);
2989 /* Make sure we don't accidentally do a full modeset. */
2990 state
->allow_modeset
= false;
2991 if (!crtc_state
->active
) {
2992 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled, rejecting legacy flip\n",
2993 crtc
->base
.id
, crtc
->name
);
3001 * drm_atomic_helper_page_flip - execute a legacy page flip
3003 * @fb: DRM framebuffer
3004 * @event: optional DRM event to signal upon completion
3005 * @flags: flip flags for non-vblank sync'ed updates
3006 * @ctx: lock acquisition context
3008 * Provides a default &drm_crtc_funcs.page_flip implementation
3009 * using the atomic driver interface.
3012 * Returns 0 on success, negative errno numbers on failure.
3015 * drm_atomic_helper_page_flip_target()
3017 int drm_atomic_helper_page_flip(struct drm_crtc
*crtc
,
3018 struct drm_framebuffer
*fb
,
3019 struct drm_pending_vblank_event
*event
,
3021 struct drm_modeset_acquire_ctx
*ctx
)
3023 struct drm_plane
*plane
= crtc
->primary
;
3024 struct drm_atomic_state
*state
;
3027 state
= drm_atomic_state_alloc(plane
->dev
);
3031 state
->acquire_ctx
= ctx
;
3033 ret
= page_flip_common(state
, crtc
, fb
, event
, flags
);
3037 ret
= drm_atomic_nonblocking_commit(state
);
3039 drm_atomic_state_put(state
);
3042 EXPORT_SYMBOL(drm_atomic_helper_page_flip
);
3045 * drm_atomic_helper_page_flip_target - do page flip on target vblank period.
3047 * @fb: DRM framebuffer
3048 * @event: optional DRM event to signal upon completion
3049 * @flags: flip flags for non-vblank sync'ed updates
3050 * @target: specifying the target vblank period when the flip to take effect
3051 * @ctx: lock acquisition context
3053 * Provides a default &drm_crtc_funcs.page_flip_target implementation.
3054 * Similar to drm_atomic_helper_page_flip() with extra parameter to specify
3055 * target vblank period to flip.
3058 * Returns 0 on success, negative errno numbers on failure.
3060 int drm_atomic_helper_page_flip_target(
3061 struct drm_crtc
*crtc
,
3062 struct drm_framebuffer
*fb
,
3063 struct drm_pending_vblank_event
*event
,
3066 struct drm_modeset_acquire_ctx
*ctx
)
3068 struct drm_plane
*plane
= crtc
->primary
;
3069 struct drm_atomic_state
*state
;
3070 struct drm_crtc_state
*crtc_state
;
3073 state
= drm_atomic_state_alloc(plane
->dev
);
3077 state
->acquire_ctx
= ctx
;
3079 ret
= page_flip_common(state
, crtc
, fb
, event
, flags
);
3083 crtc_state
= drm_atomic_get_new_crtc_state(state
, crtc
);
3084 if (WARN_ON(!crtc_state
)) {
3088 crtc_state
->target_vblank
= target
;
3090 ret
= drm_atomic_nonblocking_commit(state
);
3092 drm_atomic_state_put(state
);
3095 EXPORT_SYMBOL(drm_atomic_helper_page_flip_target
);
3098 * drm_atomic_helper_connector_dpms() - connector dpms helper implementation
3099 * @connector: affected connector
3102 * This is the main helper function provided by the atomic helper framework for
3103 * implementing the legacy DPMS connector interface. It computes the new desired
3104 * &drm_crtc_state.active state for the corresponding CRTC (if the connector is
3105 * enabled) and updates it.
3108 * Returns 0 on success, negative errno numbers on failure.
3110 int drm_atomic_helper_connector_dpms(struct drm_connector
*connector
,
3113 struct drm_mode_config
*config
= &connector
->dev
->mode_config
;
3114 struct drm_atomic_state
*state
;
3115 struct drm_crtc_state
*crtc_state
;
3116 struct drm_crtc
*crtc
;
3117 struct drm_connector
*tmp_connector
;
3118 struct drm_connector_list_iter conn_iter
;
3120 bool active
= false;
3121 int old_mode
= connector
->dpms
;
3123 if (mode
!= DRM_MODE_DPMS_ON
)
3124 mode
= DRM_MODE_DPMS_OFF
;
3126 connector
->dpms
= mode
;
3127 crtc
= connector
->state
->crtc
;
3132 state
= drm_atomic_state_alloc(connector
->dev
);
3136 state
->acquire_ctx
= crtc
->dev
->mode_config
.acquire_ctx
;
3138 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
3139 if (IS_ERR(crtc_state
)) {
3140 ret
= PTR_ERR(crtc_state
);
3144 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
3146 drm_connector_list_iter_begin(connector
->dev
, &conn_iter
);
3147 drm_for_each_connector_iter(tmp_connector
, &conn_iter
) {
3148 if (tmp_connector
->state
->crtc
!= crtc
)
3151 if (tmp_connector
->dpms
== DRM_MODE_DPMS_ON
) {
3156 drm_connector_list_iter_end(&conn_iter
);
3157 crtc_state
->active
= active
;
3159 ret
= drm_atomic_commit(state
);
3161 if (ret
== -EDEADLK
)
3164 connector
->dpms
= old_mode
;
3165 drm_atomic_state_put(state
);
3169 drm_atomic_state_clear(state
);
3170 drm_atomic_legacy_backoff(state
);
3174 EXPORT_SYMBOL(drm_atomic_helper_connector_dpms
);
3177 * drm_atomic_helper_best_encoder - Helper for
3178 * &drm_connector_helper_funcs.best_encoder callback
3179 * @connector: Connector control structure
3181 * This is a &drm_connector_helper_funcs.best_encoder callback helper for
3182 * connectors that support exactly 1 encoder, statically determined at driver
3185 struct drm_encoder
*
3186 drm_atomic_helper_best_encoder(struct drm_connector
*connector
)
3188 WARN_ON(connector
->encoder_ids
[1]);
3189 return drm_encoder_find(connector
->dev
, connector
->encoder_ids
[0]);
3191 EXPORT_SYMBOL(drm_atomic_helper_best_encoder
);
3194 * DOC: atomic state reset and initialization
3196 * Both the drm core and the atomic helpers assume that there is always the full
3197 * and correct atomic software state for all connectors, CRTCs and planes
3198 * available. Which is a bit a problem on driver load and also after system
3199 * suspend. One way to solve this is to have a hardware state read-out
3200 * infrastructure which reconstructs the full software state (e.g. the i915
3203 * The simpler solution is to just reset the software state to everything off,
3204 * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
3205 * the atomic helpers provide default reset implementations for all hooks.
3207 * On the upside the precise state tracking of atomic simplifies system suspend
3208 * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe
3209 * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume().
3210 * For other drivers the building blocks are split out, see the documentation
3211 * for these functions.
3215 * drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs
3218 * Resets the atomic state for @crtc by freeing the state pointer (which might
3219 * be NULL, e.g. at driver load time) and allocating a new empty state object.
3221 void drm_atomic_helper_crtc_reset(struct drm_crtc
*crtc
)
3224 __drm_atomic_helper_crtc_destroy_state(crtc
->state
);
3227 crtc
->state
= kzalloc(sizeof(*crtc
->state
), GFP_KERNEL
);
3230 crtc
->state
->crtc
= crtc
;
3232 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset
);
3235 * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state
3236 * @crtc: CRTC object
3237 * @state: atomic CRTC state
3239 * Copies atomic state from a CRTC's current state and resets inferred values.
3240 * This is useful for drivers that subclass the CRTC state.
3242 void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc
*crtc
,
3243 struct drm_crtc_state
*state
)
3245 memcpy(state
, crtc
->state
, sizeof(*state
));
3247 if (state
->mode_blob
)
3248 drm_property_blob_get(state
->mode_blob
);
3249 if (state
->degamma_lut
)
3250 drm_property_blob_get(state
->degamma_lut
);
3252 drm_property_blob_get(state
->ctm
);
3253 if (state
->gamma_lut
)
3254 drm_property_blob_get(state
->gamma_lut
);
3255 state
->mode_changed
= false;
3256 state
->active_changed
= false;
3257 state
->planes_changed
= false;
3258 state
->connectors_changed
= false;
3259 state
->color_mgmt_changed
= false;
3260 state
->zpos_changed
= false;
3261 state
->event
= NULL
;
3262 state
->pageflip_flags
= 0;
3264 EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state
);
3267 * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
3270 * Default CRTC state duplicate hook for drivers which don't have their own
3271 * subclassed CRTC state structure.
3273 struct drm_crtc_state
*
3274 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc
*crtc
)
3276 struct drm_crtc_state
*state
;
3278 if (WARN_ON(!crtc
->state
))
3281 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
3283 __drm_atomic_helper_crtc_duplicate_state(crtc
, state
);
3287 EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state
);
3290 * __drm_atomic_helper_crtc_destroy_state - release CRTC state
3291 * @state: CRTC state object to release
3293 * Releases all resources stored in the CRTC state without actually freeing
3294 * the memory of the CRTC state. This is useful for drivers that subclass the
3297 void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state
*state
)
3299 drm_property_blob_put(state
->mode_blob
);
3300 drm_property_blob_put(state
->degamma_lut
);
3301 drm_property_blob_put(state
->ctm
);
3302 drm_property_blob_put(state
->gamma_lut
);
3304 EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state
);
3307 * drm_atomic_helper_crtc_destroy_state - default state destroy hook
3309 * @state: CRTC state object to release
3311 * Default CRTC state destroy hook for drivers which don't have their own
3312 * subclassed CRTC state structure.
3314 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc
*crtc
,
3315 struct drm_crtc_state
*state
)
3317 __drm_atomic_helper_crtc_destroy_state(state
);
3320 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state
);
3323 * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes
3326 * Resets the atomic state for @plane by freeing the state pointer (which might
3327 * be NULL, e.g. at driver load time) and allocating a new empty state object.
3329 void drm_atomic_helper_plane_reset(struct drm_plane
*plane
)
3332 __drm_atomic_helper_plane_destroy_state(plane
->state
);
3334 kfree(plane
->state
);
3335 plane
->state
= kzalloc(sizeof(*plane
->state
), GFP_KERNEL
);
3338 plane
->state
->plane
= plane
;
3339 plane
->state
->rotation
= DRM_MODE_ROTATE_0
;
3342 EXPORT_SYMBOL(drm_atomic_helper_plane_reset
);
3345 * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
3346 * @plane: plane object
3347 * @state: atomic plane state
3349 * Copies atomic state from a plane's current state. This is useful for
3350 * drivers that subclass the plane state.
3352 void __drm_atomic_helper_plane_duplicate_state(struct drm_plane
*plane
,
3353 struct drm_plane_state
*state
)
3355 memcpy(state
, plane
->state
, sizeof(*state
));
3358 drm_framebuffer_get(state
->fb
);
3360 state
->fence
= NULL
;
3362 EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state
);
3365 * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
3368 * Default plane state duplicate hook for drivers which don't have their own
3369 * subclassed plane state structure.
3371 struct drm_plane_state
*
3372 drm_atomic_helper_plane_duplicate_state(struct drm_plane
*plane
)
3374 struct drm_plane_state
*state
;
3376 if (WARN_ON(!plane
->state
))
3379 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
3381 __drm_atomic_helper_plane_duplicate_state(plane
, state
);
3385 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state
);
3388 * __drm_atomic_helper_plane_destroy_state - release plane state
3389 * @state: plane state object to release
3391 * Releases all resources stored in the plane state without actually freeing
3392 * the memory of the plane state. This is useful for drivers that subclass the
3395 void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state
*state
)
3398 drm_framebuffer_put(state
->fb
);
3401 dma_fence_put(state
->fence
);
3403 EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state
);
3406 * drm_atomic_helper_plane_destroy_state - default state destroy hook
3408 * @state: plane state object to release
3410 * Default plane state destroy hook for drivers which don't have their own
3411 * subclassed plane state structure.
3413 void drm_atomic_helper_plane_destroy_state(struct drm_plane
*plane
,
3414 struct drm_plane_state
*state
)
3416 __drm_atomic_helper_plane_destroy_state(state
);
3419 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state
);
3422 * __drm_atomic_helper_connector_reset - reset state on connector
3423 * @connector: drm connector
3424 * @conn_state: connector state to assign
3426 * Initializes the newly allocated @conn_state and assigns it to
3427 * the &drm_conector->state pointer of @connector, usually required when
3428 * initializing the drivers or when called from the &drm_connector_funcs.reset
3431 * This is useful for drivers that subclass the connector state.
3434 __drm_atomic_helper_connector_reset(struct drm_connector
*connector
,
3435 struct drm_connector_state
*conn_state
)
3438 conn_state
->connector
= connector
;
3440 connector
->state
= conn_state
;
3442 EXPORT_SYMBOL(__drm_atomic_helper_connector_reset
);
3445 * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors
3446 * @connector: drm connector
3448 * Resets the atomic state for @connector by freeing the state pointer (which
3449 * might be NULL, e.g. at driver load time) and allocating a new empty state
3452 void drm_atomic_helper_connector_reset(struct drm_connector
*connector
)
3454 struct drm_connector_state
*conn_state
=
3455 kzalloc(sizeof(*conn_state
), GFP_KERNEL
);
3457 if (connector
->state
)
3458 __drm_atomic_helper_connector_destroy_state(connector
->state
);
3460 kfree(connector
->state
);
3461 __drm_atomic_helper_connector_reset(connector
, conn_state
);
3463 EXPORT_SYMBOL(drm_atomic_helper_connector_reset
);
3466 * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state
3467 * @connector: connector object
3468 * @state: atomic connector state
3470 * Copies atomic state from a connector's current state. This is useful for
3471 * drivers that subclass the connector state.
3474 __drm_atomic_helper_connector_duplicate_state(struct drm_connector
*connector
,
3475 struct drm_connector_state
*state
)
3477 memcpy(state
, connector
->state
, sizeof(*state
));
3479 drm_connector_get(connector
);
3481 EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state
);
3484 * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
3485 * @connector: drm connector
3487 * Default connector state duplicate hook for drivers which don't have their own
3488 * subclassed connector state structure.
3490 struct drm_connector_state
*
3491 drm_atomic_helper_connector_duplicate_state(struct drm_connector
*connector
)
3493 struct drm_connector_state
*state
;
3495 if (WARN_ON(!connector
->state
))
3498 state
= kmalloc(sizeof(*state
), GFP_KERNEL
);
3500 __drm_atomic_helper_connector_duplicate_state(connector
, state
);
3504 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state
);
3507 * drm_atomic_helper_duplicate_state - duplicate an atomic state object
3509 * @ctx: lock acquisition context
3511 * Makes a copy of the current atomic state by looping over all objects and
3512 * duplicating their respective states. This is used for example by suspend/
3513 * resume support code to save the state prior to suspend such that it can
3514 * be restored upon resume.
3516 * Note that this treats atomic state as persistent between save and restore.
3517 * Drivers must make sure that this is possible and won't result in confusion
3518 * or erroneous behaviour.
3520 * Note that if callers haven't already acquired all modeset locks this might
3521 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3524 * A pointer to the copy of the atomic state object on success or an
3525 * ERR_PTR()-encoded error code on failure.
3528 * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
3530 struct drm_atomic_state
*
3531 drm_atomic_helper_duplicate_state(struct drm_device
*dev
,
3532 struct drm_modeset_acquire_ctx
*ctx
)
3534 struct drm_atomic_state
*state
;
3535 struct drm_connector
*conn
;
3536 struct drm_connector_list_iter conn_iter
;
3537 struct drm_plane
*plane
;
3538 struct drm_crtc
*crtc
;
3541 state
= drm_atomic_state_alloc(dev
);
3543 return ERR_PTR(-ENOMEM
);
3545 state
->acquire_ctx
= ctx
;
3547 drm_for_each_crtc(crtc
, dev
) {
3548 struct drm_crtc_state
*crtc_state
;
3550 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
3551 if (IS_ERR(crtc_state
)) {
3552 err
= PTR_ERR(crtc_state
);
3557 drm_for_each_plane(plane
, dev
) {
3558 struct drm_plane_state
*plane_state
;
3560 plane_state
= drm_atomic_get_plane_state(state
, plane
);
3561 if (IS_ERR(plane_state
)) {
3562 err
= PTR_ERR(plane_state
);
3567 drm_connector_list_iter_begin(dev
, &conn_iter
);
3568 drm_for_each_connector_iter(conn
, &conn_iter
) {
3569 struct drm_connector_state
*conn_state
;
3571 conn_state
= drm_atomic_get_connector_state(state
, conn
);
3572 if (IS_ERR(conn_state
)) {
3573 err
= PTR_ERR(conn_state
);
3574 drm_connector_list_iter_end(&conn_iter
);
3578 drm_connector_list_iter_end(&conn_iter
);
3580 /* clear the acquire context so that it isn't accidentally reused */
3581 state
->acquire_ctx
= NULL
;
3585 drm_atomic_state_put(state
);
3586 state
= ERR_PTR(err
);
3591 EXPORT_SYMBOL(drm_atomic_helper_duplicate_state
);
3594 * __drm_atomic_helper_connector_destroy_state - release connector state
3595 * @state: connector state object to release
3597 * Releases all resources stored in the connector state without actually
3598 * freeing the memory of the connector state. This is useful for drivers that
3599 * subclass the connector state.
3602 __drm_atomic_helper_connector_destroy_state(struct drm_connector_state
*state
)
3605 drm_connector_put(state
->connector
);
3607 EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state
);
3610 * drm_atomic_helper_connector_destroy_state - default state destroy hook
3611 * @connector: drm connector
3612 * @state: connector state object to release
3614 * Default connector state destroy hook for drivers which don't have their own
3615 * subclassed connector state structure.
3617 void drm_atomic_helper_connector_destroy_state(struct drm_connector
*connector
,
3618 struct drm_connector_state
*state
)
3620 __drm_atomic_helper_connector_destroy_state(state
);
3623 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state
);
3626 * drm_atomic_helper_legacy_gamma_set - set the legacy gamma correction table
3627 * @crtc: CRTC object
3628 * @red: red correction table
3629 * @green: green correction table
3630 * @blue: green correction table
3631 * @size: size of the tables
3632 * @ctx: lock acquire context
3634 * Implements support for legacy gamma correction table for drivers
3635 * that support color management through the DEGAMMA_LUT/GAMMA_LUT
3636 * properties. See drm_crtc_enable_color_mgmt() and the containing chapter for
3637 * how the atomic color management and gamma tables work.
3639 int drm_atomic_helper_legacy_gamma_set(struct drm_crtc
*crtc
,
3640 u16
*red
, u16
*green
, u16
*blue
,
3642 struct drm_modeset_acquire_ctx
*ctx
)
3644 struct drm_device
*dev
= crtc
->dev
;
3645 struct drm_mode_config
*config
= &dev
->mode_config
;
3646 struct drm_atomic_state
*state
;
3647 struct drm_crtc_state
*crtc_state
;
3648 struct drm_property_blob
*blob
= NULL
;
3649 struct drm_color_lut
*blob_data
;
3652 state
= drm_atomic_state_alloc(crtc
->dev
);
3656 blob
= drm_property_create_blob(dev
,
3657 sizeof(struct drm_color_lut
) * size
,
3660 ret
= PTR_ERR(blob
);
3665 /* Prepare GAMMA_LUT with the legacy values. */
3666 blob_data
= (struct drm_color_lut
*) blob
->data
;
3667 for (i
= 0; i
< size
; i
++) {
3668 blob_data
[i
].red
= red
[i
];
3669 blob_data
[i
].green
= green
[i
];
3670 blob_data
[i
].blue
= blue
[i
];
3673 state
->acquire_ctx
= ctx
;
3674 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
3675 if (IS_ERR(crtc_state
)) {
3676 ret
= PTR_ERR(crtc_state
);
3680 /* Reset DEGAMMA_LUT and CTM properties. */
3681 ret
= drm_atomic_crtc_set_property(crtc
, crtc_state
,
3682 config
->degamma_lut_property
, 0);
3686 ret
= drm_atomic_crtc_set_property(crtc
, crtc_state
,
3687 config
->ctm_property
, 0);
3691 ret
= drm_atomic_crtc_set_property(crtc
, crtc_state
,
3692 config
->gamma_lut_property
, blob
->base
.id
);
3696 ret
= drm_atomic_commit(state
);
3699 drm_atomic_state_put(state
);
3700 drm_property_blob_put(blob
);
3703 EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set
);