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/fence.h>
38 * This helper library provides implementations of check and commit functions on
39 * top of the CRTC modeset helper callbacks and the plane helper callbacks. It
40 * also provides convenience implementations for the atomic state handling
41 * callbacks for drivers which don't need to subclass the drm core structures to
42 * add their own additional internal state.
44 * This library also provides default implementations for the check callback in
45 * drm_atomic_helper_check and for the commit callback with
46 * drm_atomic_helper_commit. But the individual stages and callbacks are expose
47 * to allow drivers to mix and match and e.g. use the plane helpers only
48 * together with a driver private modeset implementation.
50 * This library also provides implementations for all the legacy driver
51 * interfaces on top of the atomic interface. See drm_atomic_helper_set_config,
52 * drm_atomic_helper_disable_plane, drm_atomic_helper_disable_plane and the
53 * various functions to implement set_property callbacks. New drivers must not
54 * implement these functions themselves but must use the provided helpers.
57 drm_atomic_helper_plane_changed(struct drm_atomic_state
*state
,
58 struct drm_plane_state
*plane_state
,
59 struct drm_plane
*plane
)
61 struct drm_crtc_state
*crtc_state
;
63 if (plane
->state
->crtc
) {
64 crtc_state
= state
->crtc_states
[drm_crtc_index(plane
->crtc
)];
66 if (WARN_ON(!crtc_state
))
69 crtc_state
->planes_changed
= true;
72 if (plane_state
->crtc
) {
74 state
->crtc_states
[drm_crtc_index(plane_state
->crtc
)];
76 if (WARN_ON(!crtc_state
))
79 crtc_state
->planes_changed
= true;
83 static struct drm_crtc
*
84 get_current_crtc_for_encoder(struct drm_device
*dev
,
85 struct drm_encoder
*encoder
)
87 struct drm_mode_config
*config
= &dev
->mode_config
;
88 struct drm_connector
*connector
;
90 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
92 list_for_each_entry(connector
, &config
->connector_list
, head
) {
93 if (connector
->state
->best_encoder
!= encoder
)
96 return connector
->state
->crtc
;
103 steal_encoder(struct drm_atomic_state
*state
,
104 struct drm_encoder
*encoder
,
105 struct drm_crtc
*encoder_crtc
)
107 struct drm_mode_config
*config
= &state
->dev
->mode_config
;
108 struct drm_crtc_state
*crtc_state
;
109 struct drm_connector
*connector
;
110 struct drm_connector_state
*connector_state
;
114 * We can only steal an encoder coming from a connector, which means we
115 * must already hold the connection_mutex.
117 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
119 DRM_DEBUG_KMS("[ENCODER:%d:%s] in use on [CRTC:%d], stealing it\n",
120 encoder
->base
.id
, encoder
->name
,
121 encoder_crtc
->base
.id
);
123 crtc_state
= drm_atomic_get_crtc_state(state
, encoder_crtc
);
124 if (IS_ERR(crtc_state
))
125 return PTR_ERR(crtc_state
);
127 crtc_state
->mode_changed
= true;
129 list_for_each_entry(connector
, &config
->connector_list
, head
) {
130 if (connector
->state
->best_encoder
!= encoder
)
133 DRM_DEBUG_KMS("Stealing encoder from [CONNECTOR:%d:%s]\n",
137 connector_state
= drm_atomic_get_connector_state(state
,
139 if (IS_ERR(connector_state
))
140 return PTR_ERR(connector_state
);
142 ret
= drm_atomic_set_crtc_for_connector(connector_state
, NULL
);
145 connector_state
->best_encoder
= NULL
;
152 update_connector_routing(struct drm_atomic_state
*state
, int conn_idx
)
154 struct drm_connector_helper_funcs
*funcs
;
155 struct drm_encoder
*new_encoder
;
156 struct drm_crtc
*encoder_crtc
;
157 struct drm_connector
*connector
;
158 struct drm_connector_state
*connector_state
;
159 struct drm_crtc_state
*crtc_state
;
162 connector
= state
->connectors
[conn_idx
];
163 connector_state
= state
->connector_states
[conn_idx
];
168 DRM_DEBUG_KMS("Updating routing for [CONNECTOR:%d:%s]\n",
172 if (connector
->state
->crtc
!= connector_state
->crtc
) {
173 if (connector
->state
->crtc
) {
174 idx
= drm_crtc_index(connector
->state
->crtc
);
176 crtc_state
= state
->crtc_states
[idx
];
177 crtc_state
->mode_changed
= true;
180 if (connector_state
->crtc
) {
181 idx
= drm_crtc_index(connector_state
->crtc
);
183 crtc_state
= state
->crtc_states
[idx
];
184 crtc_state
->mode_changed
= true;
188 if (!connector_state
->crtc
) {
189 DRM_DEBUG_KMS("Disabling [CONNECTOR:%d:%s]\n",
193 connector_state
->best_encoder
= NULL
;
198 funcs
= connector
->helper_private
;
199 new_encoder
= funcs
->best_encoder(connector
);
202 DRM_DEBUG_KMS("No suitable encoder found for [CONNECTOR:%d:%s]\n",
208 if (new_encoder
== connector_state
->best_encoder
) {
209 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d]\n",
212 new_encoder
->base
.id
,
214 connector_state
->crtc
->base
.id
);
219 encoder_crtc
= get_current_crtc_for_encoder(state
->dev
,
223 ret
= steal_encoder(state
, new_encoder
, encoder_crtc
);
225 DRM_DEBUG_KMS("Encoder stealing failed for [CONNECTOR:%d:%s]\n",
232 connector_state
->best_encoder
= new_encoder
;
233 idx
= drm_crtc_index(connector_state
->crtc
);
235 crtc_state
= state
->crtc_states
[idx
];
236 crtc_state
->mode_changed
= true;
238 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d]\n",
241 new_encoder
->base
.id
,
243 connector_state
->crtc
->base
.id
);
249 mode_fixup(struct drm_atomic_state
*state
)
251 int ncrtcs
= state
->dev
->mode_config
.num_crtc
;
252 int nconnectors
= state
->dev
->mode_config
.num_connector
;
253 struct drm_crtc_state
*crtc_state
;
254 struct drm_connector_state
*conn_state
;
258 for (i
= 0; i
< ncrtcs
; i
++) {
259 crtc_state
= state
->crtc_states
[i
];
261 if (!crtc_state
|| !crtc_state
->mode_changed
)
264 drm_mode_copy(&crtc_state
->adjusted_mode
, &crtc_state
->mode
);
267 for (i
= 0; i
< nconnectors
; i
++) {
268 struct drm_encoder_helper_funcs
*funcs
;
269 struct drm_encoder
*encoder
;
271 conn_state
= state
->connector_states
[i
];
276 WARN_ON(!!conn_state
->best_encoder
!= !!conn_state
->crtc
);
278 if (!conn_state
->crtc
|| !conn_state
->best_encoder
)
282 state
->crtc_states
[drm_crtc_index(conn_state
->crtc
)];
285 * Each encoder has at most one connector (since we always steal
286 * it away), so we won't call ->mode_fixup twice.
288 encoder
= conn_state
->best_encoder
;
289 funcs
= encoder
->helper_private
;
291 if (encoder
->bridge
&& encoder
->bridge
->funcs
->mode_fixup
) {
292 ret
= encoder
->bridge
->funcs
->mode_fixup(
293 encoder
->bridge
, &crtc_state
->mode
,
294 &crtc_state
->adjusted_mode
);
296 DRM_DEBUG_KMS("Bridge fixup failed\n");
302 ret
= funcs
->mode_fixup(encoder
, &crtc_state
->mode
,
303 &crtc_state
->adjusted_mode
);
305 DRM_DEBUG_KMS("[ENCODER:%d:%s] fixup failed\n",
306 encoder
->base
.id
, encoder
->name
);
311 for (i
= 0; i
< ncrtcs
; i
++) {
312 struct drm_crtc_helper_funcs
*funcs
;
313 struct drm_crtc
*crtc
;
315 crtc_state
= state
->crtc_states
[i
];
316 crtc
= state
->crtcs
[i
];
318 if (!crtc_state
|| !crtc_state
->mode_changed
)
321 funcs
= crtc
->helper_private
;
322 ret
= funcs
->mode_fixup(crtc
, &crtc_state
->mode
,
323 &crtc_state
->adjusted_mode
);
325 DRM_DEBUG_KMS("[CRTC:%d] fixup failed\n",
335 drm_atomic_helper_check_prepare(struct drm_device
*dev
,
336 struct drm_atomic_state
*state
)
338 int ncrtcs
= dev
->mode_config
.num_crtc
;
339 int nconnectors
= dev
->mode_config
.num_connector
;
340 struct drm_crtc
*crtc
;
341 struct drm_crtc_state
*crtc_state
;
344 for (i
= 0; i
< ncrtcs
; i
++) {
345 crtc
= state
->crtcs
[i
];
346 crtc_state
= state
->crtc_states
[i
];
351 if (!drm_mode_equal(&crtc
->state
->mode
, &crtc_state
->mode
)) {
352 DRM_DEBUG_KMS("[CRTC:%d] mode changed\n",
354 crtc_state
->mode_changed
= true;
357 if (crtc
->state
->enable
!= crtc_state
->enable
) {
358 DRM_DEBUG_KMS("[CRTC:%d] enable changed\n",
360 crtc_state
->mode_changed
= true;
364 for (i
= 0; i
< nconnectors
; i
++) {
366 * This only sets crtc->mode_changed for routing changes,
367 * drivers must set crtc->mode_changed themselves when connector
368 * properties need to be updated.
370 ret
= update_connector_routing(state
, i
);
376 * After all the routing has been prepared we need to add in any
377 * connector which is itself unchanged, but who's crtc changes it's
378 * configuration. This must be done before calling mode_fixup in case a
379 * crtc only changed its mode but has the same set of connectors.
381 for (i
= 0; i
< ncrtcs
; i
++) {
384 crtc
= state
->crtcs
[i
];
385 crtc_state
= state
->crtc_states
[i
];
387 if (!crtc
|| !crtc_state
->mode_changed
)
390 DRM_DEBUG_KMS("[CRTC:%d] needs full modeset, enable: %c\n",
392 crtc_state
->enable
? 'y' : 'n');
394 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
398 num_connectors
= drm_atomic_connectors_for_crtc(state
,
401 if (crtc_state
->enable
!= !!num_connectors
) {
402 DRM_DEBUG_KMS("[CRTC:%d] enabled/connectors mismatch\n",
409 return mode_fixup(state
);
413 * drm_atomic_helper_check - validate state object
415 * @state: the driver state object
417 * Check the state object to see if the requested state is physically possible.
418 * Only crtcs and planes have check callbacks, so for any additional (global)
419 * checking that a driver needs it can simply wrap that around this function.
420 * Drivers without such needs can directly use this as their ->atomic_check()
424 * Zero for success or -errno
426 int drm_atomic_helper_check(struct drm_device
*dev
,
427 struct drm_atomic_state
*state
)
429 int nplanes
= dev
->mode_config
.num_total_plane
;
430 int ncrtcs
= dev
->mode_config
.num_crtc
;
433 ret
= drm_atomic_helper_check_prepare(dev
, state
);
437 for (i
= 0; i
< nplanes
; i
++) {
438 struct drm_plane_helper_funcs
*funcs
;
439 struct drm_plane
*plane
= state
->planes
[i
];
440 struct drm_plane_state
*plane_state
= state
->plane_states
[i
];
445 funcs
= plane
->helper_private
;
447 drm_atomic_helper_plane_changed(state
, plane_state
, plane
);
449 if (!funcs
|| !funcs
->atomic_check
)
452 ret
= funcs
->atomic_check(plane
, plane_state
);
454 DRM_DEBUG_KMS("[PLANE:%d] atomic check failed\n",
460 for (i
= 0; i
< ncrtcs
; i
++) {
461 struct drm_crtc_helper_funcs
*funcs
;
462 struct drm_crtc
*crtc
= state
->crtcs
[i
];
467 funcs
= crtc
->helper_private
;
469 if (!funcs
|| !funcs
->atomic_check
)
472 ret
= funcs
->atomic_check(crtc
, state
->crtc_states
[i
]);
474 DRM_DEBUG_KMS("[CRTC:%d] atomic check failed\n",
482 EXPORT_SYMBOL(drm_atomic_helper_check
);
485 disable_outputs(struct drm_device
*dev
, struct drm_atomic_state
*old_state
)
487 int ncrtcs
= old_state
->dev
->mode_config
.num_crtc
;
488 int nconnectors
= old_state
->dev
->mode_config
.num_connector
;
491 for (i
= 0; i
< nconnectors
; i
++) {
492 struct drm_connector_state
*old_conn_state
;
493 struct drm_connector
*connector
;
494 struct drm_encoder_helper_funcs
*funcs
;
495 struct drm_encoder
*encoder
;
497 old_conn_state
= old_state
->connector_states
[i
];
498 connector
= old_state
->connectors
[i
];
500 /* Shut down everything that's in the changeset and currently
501 * still on. So need to check the old, saved state. */
502 if (!old_conn_state
|| !old_conn_state
->crtc
)
505 encoder
= connector
->state
->best_encoder
;
510 funcs
= encoder
->helper_private
;
513 * Each encoder has at most one connector (since we always steal
514 * it away), so we won't call call disable hooks twice.
517 encoder
->bridge
->funcs
->disable(encoder
->bridge
);
519 /* Right function depends upon target state. */
520 if (connector
->state
->crtc
)
521 funcs
->prepare(encoder
);
522 else if (funcs
->disable
)
523 funcs
->disable(encoder
);
525 funcs
->dpms(encoder
, DRM_MODE_DPMS_OFF
);
528 encoder
->bridge
->funcs
->post_disable(encoder
->bridge
);
531 for (i
= 0; i
< ncrtcs
; i
++) {
532 struct drm_crtc_helper_funcs
*funcs
;
533 struct drm_crtc
*crtc
;
535 crtc
= old_state
->crtcs
[i
];
537 /* Shut down everything that needs a full modeset. */
538 if (!crtc
|| !crtc
->state
->mode_changed
)
541 funcs
= crtc
->helper_private
;
543 /* Right function depends upon target state. */
544 if (crtc
->state
->enable
)
545 funcs
->prepare(crtc
);
546 else if (funcs
->disable
)
547 funcs
->disable(crtc
);
549 funcs
->dpms(crtc
, DRM_MODE_DPMS_OFF
);
554 set_routing_links(struct drm_device
*dev
, struct drm_atomic_state
*old_state
)
556 int nconnectors
= dev
->mode_config
.num_connector
;
557 int ncrtcs
= old_state
->dev
->mode_config
.num_crtc
;
560 /* clear out existing links */
561 for (i
= 0; i
< nconnectors
; i
++) {
562 struct drm_connector
*connector
;
564 connector
= old_state
->connectors
[i
];
566 if (!connector
|| !connector
->encoder
)
569 WARN_ON(!connector
->encoder
->crtc
);
571 connector
->encoder
->crtc
= NULL
;
572 connector
->encoder
= NULL
;
576 for (i
= 0; i
< nconnectors
; i
++) {
577 struct drm_connector
*connector
;
579 connector
= old_state
->connectors
[i
];
581 if (!connector
|| !connector
->state
->crtc
)
584 if (WARN_ON(!connector
->state
->best_encoder
))
587 connector
->encoder
= connector
->state
->best_encoder
;
588 connector
->encoder
->crtc
= connector
->state
->crtc
;
591 /* set legacy state in the crtc structure */
592 for (i
= 0; i
< ncrtcs
; i
++) {
593 struct drm_crtc
*crtc
;
595 crtc
= old_state
->crtcs
[i
];
600 crtc
->mode
= crtc
->state
->mode
;
601 crtc
->enabled
= crtc
->state
->enable
;
602 crtc
->x
= crtc
->primary
->state
->src_x
>> 16;
603 crtc
->y
= crtc
->primary
->state
->src_y
>> 16;
608 crtc_set_mode(struct drm_device
*dev
, struct drm_atomic_state
*old_state
)
610 int ncrtcs
= old_state
->dev
->mode_config
.num_crtc
;
611 int nconnectors
= old_state
->dev
->mode_config
.num_connector
;
614 for (i
= 0; i
< ncrtcs
; i
++) {
615 struct drm_crtc_helper_funcs
*funcs
;
616 struct drm_crtc
*crtc
;
618 crtc
= old_state
->crtcs
[i
];
620 if (!crtc
|| !crtc
->state
->mode_changed
)
623 funcs
= crtc
->helper_private
;
625 if (crtc
->state
->enable
)
626 funcs
->mode_set_nofb(crtc
);
629 for (i
= 0; i
< nconnectors
; i
++) {
630 struct drm_connector
*connector
;
631 struct drm_crtc_state
*new_crtc_state
;
632 struct drm_encoder_helper_funcs
*funcs
;
633 struct drm_encoder
*encoder
;
634 struct drm_display_mode
*mode
, *adjusted_mode
;
636 connector
= old_state
->connectors
[i
];
638 if (!connector
|| !connector
->state
->best_encoder
)
641 encoder
= connector
->state
->best_encoder
;
642 funcs
= encoder
->helper_private
;
643 new_crtc_state
= connector
->state
->crtc
->state
;
644 mode
= &new_crtc_state
->mode
;
645 adjusted_mode
= &new_crtc_state
->adjusted_mode
;
648 * Each encoder has at most one connector (since we always steal
649 * it away), so we won't call call mode_set hooks twice.
651 funcs
->mode_set(encoder
, mode
, adjusted_mode
);
653 if (encoder
->bridge
&& encoder
->bridge
->funcs
->mode_set
)
654 encoder
->bridge
->funcs
->mode_set(encoder
->bridge
,
655 mode
, adjusted_mode
);
660 * drm_atomic_helper_commit_pre_planes - modeset commit before plane updates
662 * @state: atomic state
664 * This function commits the modeset changes that need to be committed before
665 * updating planes. It shuts down all the outputs that need to be shut down and
666 * prepares them (if required) with the new mode.
668 void drm_atomic_helper_commit_pre_planes(struct drm_device
*dev
,
669 struct drm_atomic_state
*state
)
671 disable_outputs(dev
, state
);
672 set_routing_links(dev
, state
);
673 crtc_set_mode(dev
, state
);
675 EXPORT_SYMBOL(drm_atomic_helper_commit_pre_planes
);
678 * drm_atomic_helper_commit_post_planes - modeset commit after plane updates
680 * @old_state: atomic state object with old state structures
682 * This function commits the modeset changes that need to be committed after
683 * updating planes: It enables all the outputs with the new configuration which
684 * had to be turned off for the update.
686 void drm_atomic_helper_commit_post_planes(struct drm_device
*dev
,
687 struct drm_atomic_state
*old_state
)
689 int ncrtcs
= old_state
->dev
->mode_config
.num_crtc
;
690 int nconnectors
= old_state
->dev
->mode_config
.num_connector
;
693 for (i
= 0; i
< ncrtcs
; i
++) {
694 struct drm_crtc_helper_funcs
*funcs
;
695 struct drm_crtc
*crtc
;
697 crtc
= old_state
->crtcs
[i
];
699 /* Need to filter out CRTCs where only planes change. */
700 if (!crtc
|| !crtc
->state
->mode_changed
)
703 funcs
= crtc
->helper_private
;
705 if (crtc
->state
->enable
)
709 for (i
= 0; i
< nconnectors
; i
++) {
710 struct drm_connector
*connector
;
711 struct drm_encoder_helper_funcs
*funcs
;
712 struct drm_encoder
*encoder
;
714 connector
= old_state
->connectors
[i
];
716 if (!connector
|| !connector
->state
->best_encoder
)
719 encoder
= connector
->state
->best_encoder
;
720 funcs
= encoder
->helper_private
;
723 * Each encoder has at most one connector (since we always steal
724 * it away), so we won't call call enable hooks twice.
727 encoder
->bridge
->funcs
->pre_enable(encoder
->bridge
);
729 funcs
->commit(encoder
);
732 encoder
->bridge
->funcs
->enable(encoder
->bridge
);
735 EXPORT_SYMBOL(drm_atomic_helper_commit_post_planes
);
737 static void wait_for_fences(struct drm_device
*dev
,
738 struct drm_atomic_state
*state
)
740 int nplanes
= dev
->mode_config
.num_total_plane
;
743 for (i
= 0; i
< nplanes
; i
++) {
744 struct drm_plane
*plane
= state
->planes
[i
];
746 if (!plane
|| !plane
->state
->fence
)
749 WARN_ON(!plane
->state
->fb
);
751 fence_wait(plane
->state
->fence
, false);
752 fence_put(plane
->state
->fence
);
753 plane
->state
->fence
= NULL
;
758 wait_for_vblanks(struct drm_device
*dev
, struct drm_atomic_state
*old_state
)
760 struct drm_crtc
*crtc
;
761 struct drm_crtc_state
*old_crtc_state
;
762 int ncrtcs
= old_state
->dev
->mode_config
.num_crtc
;
765 for (i
= 0; i
< ncrtcs
; i
++) {
766 crtc
= old_state
->crtcs
[i
];
767 old_crtc_state
= old_state
->crtc_states
[i
];
772 /* No one cares about the old state, so abuse it for tracking
773 * and store whether we hold a vblank reference (and should do a
774 * vblank wait) in the ->enable boolean. */
775 old_crtc_state
->enable
= false;
777 if (!crtc
->state
->enable
)
780 ret
= drm_crtc_vblank_get(crtc
);
784 old_crtc_state
->enable
= true;
785 old_crtc_state
->last_vblank_count
= drm_vblank_count(dev
, i
);
788 for (i
= 0; i
< ncrtcs
; i
++) {
789 crtc
= old_state
->crtcs
[i
];
790 old_crtc_state
= old_state
->crtc_states
[i
];
792 if (!crtc
|| !old_crtc_state
->enable
)
795 ret
= wait_event_timeout(dev
->vblank
[i
].queue
,
796 old_crtc_state
->last_vblank_count
!=
797 drm_vblank_count(dev
, i
),
798 msecs_to_jiffies(50));
800 drm_crtc_vblank_put(crtc
);
805 * drm_atomic_helper_commit - commit validated state object
807 * @state: the driver state object
808 * @async: asynchronous commit
810 * This function commits a with drm_atomic_helper_check() pre-validated state
811 * object. This can still fail when e.g. the framebuffer reservation fails. For
812 * now this doesn't implement asynchronous commits.
815 * Zero for success or -errno.
817 int drm_atomic_helper_commit(struct drm_device
*dev
,
818 struct drm_atomic_state
*state
,
826 ret
= drm_atomic_helper_prepare_planes(dev
, state
);
831 * This is the point of no return - everything below never fails except
832 * when the hw goes bonghits. Which means we can commit the new state on
833 * the software side now.
836 drm_atomic_helper_swap_state(dev
, state
);
839 * Everything below can be run asynchronously without the need to grab
840 * any modeset locks at all under one conditions: It must be guaranteed
841 * that the asynchronous work has either been cancelled (if the driver
842 * supports it, which at least requires that the framebuffers get
843 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
844 * before the new state gets committed on the software side with
845 * drm_atomic_helper_swap_state().
847 * This scheme allows new atomic state updates to be prepared and
848 * checked in parallel to the asynchronous completion of the previous
849 * update. Which is important since compositors need to figure out the
850 * composition of the next frame right after having submitted the
854 wait_for_fences(dev
, state
);
856 drm_atomic_helper_commit_pre_planes(dev
, state
);
858 drm_atomic_helper_commit_planes(dev
, state
);
860 drm_atomic_helper_commit_post_planes(dev
, state
);
862 wait_for_vblanks(dev
, state
);
864 drm_atomic_helper_cleanup_planes(dev
, state
);
866 drm_atomic_state_free(state
);
870 EXPORT_SYMBOL(drm_atomic_helper_commit
);
873 * DOC: implementing async commit
875 * For now the atomic helpers don't support async commit directly. If there is
876 * real need it could be added though, using the dma-buf fence infrastructure
877 * for generic synchronization with outstanding rendering.
879 * For now drivers have to implement async commit themselves, with the following
880 * sequence being the recommended one:
882 * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function
883 * which commit needs to call which can fail, so we want to run it first and
886 * 2. Synchronize with any outstanding asynchronous commit worker threads which
887 * might be affected the new state update. This can be done by either cancelling
888 * or flushing the work items, depending upon whether the driver can deal with
889 * cancelled updates. Note that it is important to ensure that the framebuffer
890 * cleanup is still done when cancelling.
892 * For sufficient parallelism it is recommended to have a work item per crtc
893 * (for updates which don't touch global state) and a global one. Then we only
894 * need to synchronize with the crtc work items for changed crtcs and the global
895 * work item, which allows nice concurrent updates on disjoint sets of crtcs.
897 * 3. The software state is updated synchronously with
898 * drm_atomic_helper_swap_state. Doing this under the protection of all modeset
899 * locks means concurrent callers never see inconsistent state. And doing this
900 * while it's guaranteed that no relevant async worker runs means that async
901 * workers do not need grab any locks. Actually they must not grab locks, for
902 * otherwise the work flushing will deadlock.
904 * 4. Schedule a work item to do all subsequent steps, using the split-out
905 * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
906 * then cleaning up the framebuffers after the old framebuffer is no longer
911 * drm_atomic_helper_prepare_planes - prepare plane resources after commit
913 * @state: atomic state object with old state structures
915 * This function prepares plane state, specifically framebuffers, for the new
916 * configuration. If any failure is encountered this function will call
917 * ->cleanup_fb on any already successfully prepared framebuffer.
920 * 0 on success, negative error code on failure.
922 int drm_atomic_helper_prepare_planes(struct drm_device
*dev
,
923 struct drm_atomic_state
*state
)
925 int nplanes
= dev
->mode_config
.num_total_plane
;
928 for (i
= 0; i
< nplanes
; i
++) {
929 struct drm_plane_helper_funcs
*funcs
;
930 struct drm_plane
*plane
= state
->planes
[i
];
931 struct drm_framebuffer
*fb
;
936 funcs
= plane
->helper_private
;
938 fb
= state
->plane_states
[i
]->fb
;
940 if (fb
&& funcs
->prepare_fb
) {
941 ret
= funcs
->prepare_fb(plane
, fb
);
950 for (i
--; i
>= 0; i
--) {
951 struct drm_plane_helper_funcs
*funcs
;
952 struct drm_plane
*plane
= state
->planes
[i
];
953 struct drm_framebuffer
*fb
;
958 funcs
= plane
->helper_private
;
960 fb
= state
->plane_states
[i
]->fb
;
962 if (fb
&& funcs
->cleanup_fb
)
963 funcs
->cleanup_fb(plane
, fb
);
969 EXPORT_SYMBOL(drm_atomic_helper_prepare_planes
);
972 * drm_atomic_helper_commit_planes - commit plane state
974 * @state: atomic state
976 * This function commits the new plane state using the plane and atomic helper
977 * functions for planes and crtcs. It assumes that the atomic state has already
978 * been pushed into the relevant object state pointers, since this step can no
981 * It still requires the global state object @state to know which planes and
982 * crtcs need to be updated though.
984 void drm_atomic_helper_commit_planes(struct drm_device
*dev
,
985 struct drm_atomic_state
*state
)
987 int nplanes
= dev
->mode_config
.num_total_plane
;
988 int ncrtcs
= dev
->mode_config
.num_crtc
;
991 for (i
= 0; i
< ncrtcs
; i
++) {
992 struct drm_crtc_helper_funcs
*funcs
;
993 struct drm_crtc
*crtc
= state
->crtcs
[i
];
998 funcs
= crtc
->helper_private
;
1000 if (!funcs
|| !funcs
->atomic_begin
)
1003 funcs
->atomic_begin(crtc
);
1006 for (i
= 0; i
< nplanes
; i
++) {
1007 struct drm_plane_helper_funcs
*funcs
;
1008 struct drm_plane
*plane
= state
->planes
[i
];
1013 funcs
= plane
->helper_private
;
1015 if (!funcs
|| !funcs
->atomic_update
)
1018 funcs
->atomic_update(plane
);
1021 for (i
= 0; i
< ncrtcs
; i
++) {
1022 struct drm_crtc_helper_funcs
*funcs
;
1023 struct drm_crtc
*crtc
= state
->crtcs
[i
];
1028 funcs
= crtc
->helper_private
;
1030 if (!funcs
|| !funcs
->atomic_flush
)
1033 funcs
->atomic_flush(crtc
);
1036 EXPORT_SYMBOL(drm_atomic_helper_commit_planes
);
1039 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit
1041 * @old_state: atomic state object with old state structures
1043 * This function cleans up plane state, specifically framebuffers, from the old
1044 * configuration. Hence the old configuration must be perserved in @old_state to
1045 * be able to call this function.
1047 * This function must also be called on the new state when the atomic update
1048 * fails at any point after calling drm_atomic_helper_prepare_planes().
1050 void drm_atomic_helper_cleanup_planes(struct drm_device
*dev
,
1051 struct drm_atomic_state
*old_state
)
1053 int nplanes
= dev
->mode_config
.num_total_plane
;
1056 for (i
= 0; i
< nplanes
; i
++) {
1057 struct drm_plane_helper_funcs
*funcs
;
1058 struct drm_plane
*plane
= old_state
->planes
[i
];
1059 struct drm_framebuffer
*old_fb
;
1064 funcs
= plane
->helper_private
;
1066 old_fb
= old_state
->plane_states
[i
]->fb
;
1068 if (old_fb
&& funcs
->cleanup_fb
)
1069 funcs
->cleanup_fb(plane
, old_fb
);
1072 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes
);
1075 * drm_atomic_helper_swap_state - store atomic state into current sw state
1077 * @state: atomic state
1079 * This function stores the atomic state into the current state pointers in all
1080 * driver objects. It should be called after all failing steps have been done
1081 * and succeeded, but before the actual hardware state is committed.
1083 * For cleanup and error recovery the current state for all changed objects will
1084 * be swaped into @state.
1086 * With that sequence it fits perfectly into the plane prepare/cleanup sequence:
1088 * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state.
1090 * 2. Do any other steps that might fail.
1092 * 3. Put the staged state into the current state pointers with this function.
1094 * 4. Actually commit the hardware state.
1096 * 5. Call drm_atomic_helper_cleanup_planes with @state, which since step 3
1097 * contains the old state. Also do any other cleanup required with that state.
1099 void drm_atomic_helper_swap_state(struct drm_device
*dev
,
1100 struct drm_atomic_state
*state
)
1104 for (i
= 0; i
< dev
->mode_config
.num_connector
; i
++) {
1105 struct drm_connector
*connector
= state
->connectors
[i
];
1110 connector
->state
->state
= state
;
1111 swap(state
->connector_states
[i
], connector
->state
);
1112 connector
->state
->state
= NULL
;
1115 for (i
= 0; i
< dev
->mode_config
.num_crtc
; i
++) {
1116 struct drm_crtc
*crtc
= state
->crtcs
[i
];
1121 crtc
->state
->state
= state
;
1122 swap(state
->crtc_states
[i
], crtc
->state
);
1123 crtc
->state
->state
= NULL
;
1126 for (i
= 0; i
< dev
->mode_config
.num_total_plane
; i
++) {
1127 struct drm_plane
*plane
= state
->planes
[i
];
1132 plane
->state
->state
= state
;
1133 swap(state
->plane_states
[i
], plane
->state
);
1134 plane
->state
->state
= NULL
;
1137 EXPORT_SYMBOL(drm_atomic_helper_swap_state
);
1140 * drm_atomic_helper_update_plane - Helper for primary plane update using atomic
1141 * @plane: plane object to update
1142 * @crtc: owning CRTC of owning plane
1143 * @fb: framebuffer to flip onto plane
1144 * @crtc_x: x offset of primary plane on crtc
1145 * @crtc_y: y offset of primary plane on crtc
1146 * @crtc_w: width of primary plane rectangle on crtc
1147 * @crtc_h: height of primary plane rectangle on crtc
1148 * @src_x: x offset of @fb for panning
1149 * @src_y: y offset of @fb for panning
1150 * @src_w: width of source rectangle in @fb
1151 * @src_h: height of source rectangle in @fb
1153 * Provides a default plane update handler using the atomic driver interface.
1156 * Zero on success, error code on failure
1158 int drm_atomic_helper_update_plane(struct drm_plane
*plane
,
1159 struct drm_crtc
*crtc
,
1160 struct drm_framebuffer
*fb
,
1161 int crtc_x
, int crtc_y
,
1162 unsigned int crtc_w
, unsigned int crtc_h
,
1163 uint32_t src_x
, uint32_t src_y
,
1164 uint32_t src_w
, uint32_t src_h
)
1166 struct drm_atomic_state
*state
;
1167 struct drm_plane_state
*plane_state
;
1170 state
= drm_atomic_state_alloc(plane
->dev
);
1174 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
1176 plane_state
= drm_atomic_get_plane_state(state
, plane
);
1177 if (IS_ERR(plane_state
)) {
1178 ret
= PTR_ERR(plane_state
);
1182 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
1185 plane_state
->fb
= fb
;
1186 plane_state
->crtc_x
= crtc_x
;
1187 plane_state
->crtc_y
= crtc_y
;
1188 plane_state
->crtc_h
= crtc_h
;
1189 plane_state
->crtc_w
= crtc_w
;
1190 plane_state
->src_x
= src_x
;
1191 plane_state
->src_y
= src_y
;
1192 plane_state
->src_h
= src_h
;
1193 plane_state
->src_w
= src_w
;
1195 ret
= drm_atomic_commit(state
);
1199 /* Driver takes ownership of state on successful commit. */
1202 if (ret
== -EDEADLK
)
1205 drm_atomic_state_free(state
);
1209 drm_atomic_legacy_backoff(state
);
1210 drm_atomic_state_clear(state
);
1213 * Someone might have exchanged the framebuffer while we dropped locks
1214 * in the backoff code. We need to fix up the fb refcount tracking the
1217 plane
->old_fb
= plane
->fb
;
1221 EXPORT_SYMBOL(drm_atomic_helper_update_plane
);
1224 * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic
1225 * @plane: plane to disable
1227 * Provides a default plane disable handler using the atomic driver interface.
1230 * Zero on success, error code on failure
1232 int drm_atomic_helper_disable_plane(struct drm_plane
*plane
)
1234 struct drm_atomic_state
*state
;
1235 struct drm_plane_state
*plane_state
;
1238 state
= drm_atomic_state_alloc(plane
->dev
);
1242 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(plane
->crtc
);
1244 plane_state
= drm_atomic_get_plane_state(state
, plane
);
1245 if (IS_ERR(plane_state
)) {
1246 ret
= PTR_ERR(plane_state
);
1250 ret
= drm_atomic_set_crtc_for_plane(plane_state
, NULL
);
1253 plane_state
->fb
= NULL
;
1254 plane_state
->crtc_x
= 0;
1255 plane_state
->crtc_y
= 0;
1256 plane_state
->crtc_h
= 0;
1257 plane_state
->crtc_w
= 0;
1258 plane_state
->src_x
= 0;
1259 plane_state
->src_y
= 0;
1260 plane_state
->src_h
= 0;
1261 plane_state
->src_w
= 0;
1263 ret
= drm_atomic_commit(state
);
1267 /* Driver takes ownership of state on successful commit. */
1270 if (ret
== -EDEADLK
)
1273 drm_atomic_state_free(state
);
1277 drm_atomic_legacy_backoff(state
);
1278 drm_atomic_state_clear(state
);
1281 * Someone might have exchanged the framebuffer while we dropped locks
1282 * in the backoff code. We need to fix up the fb refcount tracking the
1285 plane
->old_fb
= plane
->fb
;
1289 EXPORT_SYMBOL(drm_atomic_helper_disable_plane
);
1291 static int update_output_state(struct drm_atomic_state
*state
,
1292 struct drm_mode_set
*set
)
1294 struct drm_device
*dev
= set
->crtc
->dev
;
1295 struct drm_connector_state
*conn_state
;
1296 int nconnectors
= state
->dev
->mode_config
.num_connector
;
1297 int ncrtcs
= state
->dev
->mode_config
.num_crtc
;
1300 ret
= drm_modeset_lock(&dev
->mode_config
.connection_mutex
,
1301 state
->acquire_ctx
);
1305 /* First grab all affected connector/crtc states. */
1306 for (i
= 0; i
< set
->num_connectors
; i
++) {
1307 conn_state
= drm_atomic_get_connector_state(state
,
1308 set
->connectors
[i
]);
1309 if (IS_ERR(conn_state
))
1310 return PTR_ERR(conn_state
);
1313 for (i
= 0; i
< ncrtcs
; i
++) {
1314 struct drm_crtc
*crtc
= state
->crtcs
[i
];
1319 ret
= drm_atomic_add_affected_connectors(state
, crtc
);
1324 /* Then recompute connector->crtc links and crtc enabling state. */
1325 for (i
= 0; i
< nconnectors
; i
++) {
1326 struct drm_connector
*connector
;
1328 connector
= state
->connectors
[i
];
1329 conn_state
= state
->connector_states
[i
];
1334 if (conn_state
->crtc
== set
->crtc
) {
1335 ret
= drm_atomic_set_crtc_for_connector(conn_state
,
1341 for (j
= 0; j
< set
->num_connectors
; j
++) {
1342 if (set
->connectors
[j
] == connector
) {
1343 ret
= drm_atomic_set_crtc_for_connector(conn_state
,
1352 for (i
= 0; i
< ncrtcs
; i
++) {
1353 struct drm_crtc
*crtc
= state
->crtcs
[i
];
1354 struct drm_crtc_state
*crtc_state
= state
->crtc_states
[i
];
1359 /* Don't update ->enable for the CRTC in the set_config request,
1360 * since a mismatch would indicate a bug in the upper layers.
1361 * The actual modeset code later on will catch any
1362 * inconsistencies here. */
1363 if (crtc
== set
->crtc
)
1366 crtc_state
->enable
=
1367 drm_atomic_connectors_for_crtc(state
, crtc
);
1374 * drm_atomic_helper_set_config - set a new config from userspace
1375 * @set: mode set configuration
1377 * Provides a default crtc set_config handler using the atomic driver interface.
1380 * Returns 0 on success, negative errno numbers on failure.
1382 int drm_atomic_helper_set_config(struct drm_mode_set
*set
)
1384 struct drm_atomic_state
*state
;
1385 struct drm_crtc
*crtc
= set
->crtc
;
1386 struct drm_crtc_state
*crtc_state
;
1387 struct drm_plane_state
*primary_state
;
1390 state
= drm_atomic_state_alloc(crtc
->dev
);
1394 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
1396 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
1397 if (IS_ERR(crtc_state
)) {
1398 ret
= PTR_ERR(crtc_state
);
1404 WARN_ON(set
->num_connectors
);
1406 crtc_state
->enable
= false;
1411 WARN_ON(!set
->num_connectors
);
1413 crtc_state
->enable
= true;
1414 drm_mode_copy(&crtc_state
->mode
, set
->mode
);
1416 primary_state
= drm_atomic_get_plane_state(state
, crtc
->primary
);
1417 if (IS_ERR(primary_state
)) {
1418 ret
= PTR_ERR(primary_state
);
1422 ret
= drm_atomic_set_crtc_for_plane(primary_state
, crtc
);
1425 primary_state
->fb
= set
->fb
;
1426 primary_state
->crtc_x
= 0;
1427 primary_state
->crtc_y
= 0;
1428 primary_state
->crtc_h
= set
->mode
->vdisplay
;
1429 primary_state
->crtc_w
= set
->mode
->hdisplay
;
1430 primary_state
->src_x
= set
->x
<< 16;
1431 primary_state
->src_y
= set
->y
<< 16;
1432 primary_state
->src_h
= set
->mode
->vdisplay
<< 16;
1433 primary_state
->src_w
= set
->mode
->hdisplay
<< 16;
1436 ret
= update_output_state(state
, set
);
1440 ret
= drm_atomic_commit(state
);
1444 /* Driver takes ownership of state on successful commit. */
1447 if (ret
== -EDEADLK
)
1450 drm_atomic_state_free(state
);
1454 drm_atomic_legacy_backoff(state
);
1455 drm_atomic_state_clear(state
);
1458 * Someone might have exchanged the framebuffer while we dropped locks
1459 * in the backoff code. We need to fix up the fb refcount tracking the
1462 crtc
->primary
->old_fb
= crtc
->primary
->fb
;
1466 EXPORT_SYMBOL(drm_atomic_helper_set_config
);
1469 * drm_atomic_helper_crtc_set_property - helper for crtc prorties
1471 * @property: DRM property
1472 * @val: value of property
1474 * Provides a default plane disablle handler using the atomic driver interface.
1477 * Zero on success, error code on failure
1480 drm_atomic_helper_crtc_set_property(struct drm_crtc
*crtc
,
1481 struct drm_property
*property
,
1484 struct drm_atomic_state
*state
;
1485 struct drm_crtc_state
*crtc_state
;
1488 state
= drm_atomic_state_alloc(crtc
->dev
);
1492 /* ->set_property is always called with all locks held. */
1493 state
->acquire_ctx
= crtc
->dev
->mode_config
.acquire_ctx
;
1495 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
1496 if (IS_ERR(crtc_state
)) {
1497 ret
= PTR_ERR(crtc_state
);
1501 ret
= crtc
->funcs
->atomic_set_property(crtc
, crtc_state
,
1506 ret
= drm_atomic_commit(state
);
1510 /* Driver takes ownership of state on successful commit. */
1513 if (ret
== -EDEADLK
)
1516 drm_atomic_state_free(state
);
1520 drm_atomic_legacy_backoff(state
);
1521 drm_atomic_state_clear(state
);
1525 EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property
);
1528 * drm_atomic_helper_plane_set_property - helper for plane prorties
1530 * @property: DRM property
1531 * @val: value of property
1533 * Provides a default plane disable handler using the atomic driver interface.
1536 * Zero on success, error code on failure
1539 drm_atomic_helper_plane_set_property(struct drm_plane
*plane
,
1540 struct drm_property
*property
,
1543 struct drm_atomic_state
*state
;
1544 struct drm_plane_state
*plane_state
;
1547 state
= drm_atomic_state_alloc(plane
->dev
);
1551 /* ->set_property is always called with all locks held. */
1552 state
->acquire_ctx
= plane
->dev
->mode_config
.acquire_ctx
;
1554 plane_state
= drm_atomic_get_plane_state(state
, plane
);
1555 if (IS_ERR(plane_state
)) {
1556 ret
= PTR_ERR(plane_state
);
1560 ret
= plane
->funcs
->atomic_set_property(plane
, plane_state
,
1565 ret
= drm_atomic_commit(state
);
1569 /* Driver takes ownership of state on successful commit. */
1572 if (ret
== -EDEADLK
)
1575 drm_atomic_state_free(state
);
1579 drm_atomic_legacy_backoff(state
);
1580 drm_atomic_state_clear(state
);
1584 EXPORT_SYMBOL(drm_atomic_helper_plane_set_property
);
1587 * drm_atomic_helper_connector_set_property - helper for connector prorties
1588 * @connector: DRM connector
1589 * @property: DRM property
1590 * @val: value of property
1592 * Provides a default plane disablle handler using the atomic driver interface.
1595 * Zero on success, error code on failure
1598 drm_atomic_helper_connector_set_property(struct drm_connector
*connector
,
1599 struct drm_property
*property
,
1602 struct drm_atomic_state
*state
;
1603 struct drm_connector_state
*connector_state
;
1606 state
= drm_atomic_state_alloc(connector
->dev
);
1610 /* ->set_property is always called with all locks held. */
1611 state
->acquire_ctx
= connector
->dev
->mode_config
.acquire_ctx
;
1613 connector_state
= drm_atomic_get_connector_state(state
, connector
);
1614 if (IS_ERR(connector_state
)) {
1615 ret
= PTR_ERR(connector_state
);
1619 ret
= connector
->funcs
->atomic_set_property(connector
, connector_state
,
1624 ret
= drm_atomic_commit(state
);
1628 /* Driver takes ownership of state on successful commit. */
1631 if (ret
== -EDEADLK
)
1634 drm_atomic_state_free(state
);
1638 drm_atomic_legacy_backoff(state
);
1639 drm_atomic_state_clear(state
);
1643 EXPORT_SYMBOL(drm_atomic_helper_connector_set_property
);
1646 * drm_atomic_helper_page_flip - execute a legacy page flip
1648 * @fb: DRM framebuffer
1649 * @event: optional DRM event to signal upon completion
1650 * @flags: flip flags for non-vblank sync'ed updates
1652 * Provides a default page flip implementation using the atomic driver interface.
1654 * Note that for now so called async page flips (i.e. updates which are not
1655 * synchronized to vblank) are not supported, since the atomic interfaces have
1656 * no provisions for this yet.
1659 * Returns 0 on success, negative errno numbers on failure.
1661 int drm_atomic_helper_page_flip(struct drm_crtc
*crtc
,
1662 struct drm_framebuffer
*fb
,
1663 struct drm_pending_vblank_event
*event
,
1666 struct drm_plane
*plane
= crtc
->primary
;
1667 struct drm_atomic_state
*state
;
1668 struct drm_plane_state
*plane_state
;
1669 struct drm_crtc_state
*crtc_state
;
1672 if (flags
& DRM_MODE_PAGE_FLIP_ASYNC
)
1675 state
= drm_atomic_state_alloc(plane
->dev
);
1679 state
->acquire_ctx
= drm_modeset_legacy_acquire_ctx(crtc
);
1681 crtc_state
= drm_atomic_get_crtc_state(state
, crtc
);
1682 if (IS_ERR(crtc_state
)) {
1683 ret
= PTR_ERR(crtc_state
);
1686 crtc_state
->event
= event
;
1688 plane_state
= drm_atomic_get_plane_state(state
, plane
);
1689 if (IS_ERR(plane_state
)) {
1690 ret
= PTR_ERR(plane_state
);
1694 ret
= drm_atomic_set_crtc_for_plane(plane_state
, crtc
);
1697 plane_state
->fb
= fb
;
1699 ret
= drm_atomic_async_commit(state
);
1703 /* TODO: ->page_flip is the only driver callback where the core
1704 * doesn't update plane->fb. For now patch it up here. */
1705 plane
->fb
= plane
->state
->fb
;
1707 /* Driver takes ownership of state on successful async commit. */
1710 if (ret
== -EDEADLK
)
1713 drm_atomic_state_free(state
);
1717 drm_atomic_legacy_backoff(state
);
1718 drm_atomic_state_clear(state
);
1721 * Someone might have exchanged the framebuffer while we dropped locks
1722 * in the backoff code. We need to fix up the fb refcount tracking the
1725 plane
->old_fb
= plane
->fb
;
1729 EXPORT_SYMBOL(drm_atomic_helper_page_flip
);
1732 * DOC: atomic state reset and initialization
1734 * Both the drm core and the atomic helpers assume that there is always the full
1735 * and correct atomic software state for all connectors, CRTCs and planes
1736 * available. Which is a bit a problem on driver load and also after system
1737 * suspend. One way to solve this is to have a hardware state read-out
1738 * infrastructure which reconstructs the full software state (e.g. the i915
1741 * The simpler solution is to just reset the software state to everything off,
1742 * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
1743 * the atomic helpers provide default reset implementations for all hooks.
1747 * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs
1750 * Resets the atomic state for @crtc by freeing the state pointer (which might
1751 * be NULL, e.g. at driver load time) and allocating a new empty state object.
1753 void drm_atomic_helper_crtc_reset(struct drm_crtc
*crtc
)
1756 crtc
->state
= kzalloc(sizeof(*crtc
->state
), GFP_KERNEL
);
1758 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset
);
1761 * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
1764 * Default CRTC state duplicate hook for drivers which don't have their own
1765 * subclassed CRTC state structure.
1767 struct drm_crtc_state
*
1768 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc
*crtc
)
1770 struct drm_crtc_state
*state
;
1772 if (WARN_ON(!crtc
->state
))
1775 state
= kmemdup(crtc
->state
, sizeof(*crtc
->state
), GFP_KERNEL
);
1778 state
->mode_changed
= false;
1779 state
->planes_changed
= false;
1780 state
->event
= NULL
;
1785 EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state
);
1788 * drm_atomic_helper_crtc_destroy_state - default state destroy hook
1790 * @state: CRTC state object to release
1792 * Default CRTC state destroy hook for drivers which don't have their own
1793 * subclassed CRTC state structure.
1795 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc
*crtc
,
1796 struct drm_crtc_state
*state
)
1800 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state
);
1803 * drm_atomic_helper_plane_reset - default ->reset hook for planes
1806 * Resets the atomic state for @plane by freeing the state pointer (which might
1807 * be NULL, e.g. at driver load time) and allocating a new empty state object.
1809 void drm_atomic_helper_plane_reset(struct drm_plane
*plane
)
1811 kfree(plane
->state
);
1812 plane
->state
= kzalloc(sizeof(*plane
->state
), GFP_KERNEL
);
1814 EXPORT_SYMBOL(drm_atomic_helper_plane_reset
);
1817 * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
1820 * Default plane state duplicate hook for drivers which don't have their own
1821 * subclassed plane state structure.
1823 struct drm_plane_state
*
1824 drm_atomic_helper_plane_duplicate_state(struct drm_plane
*plane
)
1826 if (WARN_ON(!plane
->state
))
1829 return kmemdup(plane
->state
, sizeof(*plane
->state
), GFP_KERNEL
);
1831 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state
);
1834 * drm_atomic_helper_plane_destroy_state - default state destroy hook
1836 * @state: plane state object to release
1838 * Default plane state destroy hook for drivers which don't have their own
1839 * subclassed plane state structure.
1841 void drm_atomic_helper_plane_destroy_state(struct drm_plane
*plane
,
1842 struct drm_plane_state
*state
)
1846 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state
);
1849 * drm_atomic_helper_connector_reset - default ->reset hook for connectors
1850 * @connector: drm connector
1852 * Resets the atomic state for @connector by freeing the state pointer (which
1853 * might be NULL, e.g. at driver load time) and allocating a new empty state
1856 void drm_atomic_helper_connector_reset(struct drm_connector
*connector
)
1858 kfree(connector
->state
);
1859 connector
->state
= kzalloc(sizeof(*connector
->state
), GFP_KERNEL
);
1861 EXPORT_SYMBOL(drm_atomic_helper_connector_reset
);
1864 * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
1865 * @connector: drm connector
1867 * Default connector state duplicate hook for drivers which don't have their own
1868 * subclassed connector state structure.
1870 struct drm_connector_state
*
1871 drm_atomic_helper_connector_duplicate_state(struct drm_connector
*connector
)
1873 if (WARN_ON(!connector
->state
))
1876 return kmemdup(connector
->state
, sizeof(*connector
->state
), GFP_KERNEL
);
1878 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state
);
1881 * drm_atomic_helper_connector_destroy_state - default state destroy hook
1882 * @connector: drm connector
1883 * @state: connector state object to release
1885 * Default connector state destroy hook for drivers which don't have their own
1886 * subclassed connector state structure.
1888 void drm_atomic_helper_connector_destroy_state(struct drm_connector
*connector
,
1889 struct drm_connector_state
*state
)
1893 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state
);