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>
35 drm_atomic_helper_plane_changed(struct drm_atomic_state *state,
36 struct drm_plane_state *plane_state,
37 struct drm_plane *plane)
39 struct drm_crtc_state *crtc_state;
41 if (plane->state->crtc) {
42 crtc_state = state->crtc_states[drm_crtc_index(plane->crtc)];
44 if (WARN_ON(!crtc_state))
47 crtc_state->planes_changed = true;
50 if (plane_state->crtc) {
52 state->crtc_states[drm_crtc_index(plane_state->crtc)];
54 if (WARN_ON(!crtc_state))
57 crtc_state->planes_changed = true;
61 static struct drm_crtc *
62 get_current_crtc_for_encoder(struct drm_device *dev,
63 struct drm_encoder *encoder)
65 struct drm_mode_config *config = &dev->mode_config;
66 struct drm_connector *connector;
68 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
70 list_for_each_entry(connector, &config->connector_list, head) {
71 if (connector->state->best_encoder != encoder)
74 return connector->state->crtc;
81 steal_encoder(struct drm_atomic_state *state,
82 struct drm_encoder *encoder,
83 struct drm_crtc *encoder_crtc)
85 struct drm_mode_config *config = &state->dev->mode_config;
86 struct drm_crtc_state *crtc_state;
87 struct drm_connector *connector;
88 struct drm_connector_state *connector_state;
91 * We can only steal an encoder coming from a connector, which means we
92 * must already hold the connection_mutex.
94 WARN_ON(!drm_modeset_is_locked(&config->connection_mutex));
96 DRM_DEBUG_KMS("[ENCODER:%d:%s] in use on [CRTC:%d], stealing it\n",
97 encoder->base.id, encoder->name,
98 encoder_crtc->base.id);
100 crtc_state = drm_atomic_get_crtc_state(state, encoder_crtc);
101 if (IS_ERR(crtc_state))
102 return PTR_ERR(crtc_state);
104 crtc_state->mode_changed = true;
106 list_for_each_entry(connector, &config->connector_list, head) {
107 if (connector->state->best_encoder != encoder)
110 DRM_DEBUG_KMS("Stealing encoder from [CONNECTOR:%d:%s]\n",
114 connector_state = drm_atomic_get_connector_state(state,
116 if (IS_ERR(connector_state))
117 return PTR_ERR(connector_state);
119 connector_state->crtc = NULL;
120 connector_state->best_encoder = NULL;
127 update_connector_routing(struct drm_atomic_state *state, int conn_idx)
129 struct drm_connector_helper_funcs *funcs;
130 struct drm_encoder *new_encoder;
131 struct drm_crtc *encoder_crtc;
132 struct drm_connector *connector;
133 struct drm_connector_state *connector_state;
134 struct drm_crtc_state *crtc_state;
137 connector = state->connectors[conn_idx];
138 connector_state = state->connector_states[conn_idx];
143 DRM_DEBUG_KMS("Updating routing for [CONNECTOR:%d:%s]\n",
147 if (connector->state->crtc != connector_state->crtc) {
148 if (connector->state->crtc) {
149 idx = drm_crtc_index(connector->state->crtc);
151 crtc_state = state->crtc_states[idx];
152 crtc_state->mode_changed = true;
155 if (connector_state->crtc) {
156 idx = drm_crtc_index(connector_state->crtc);
158 crtc_state = state->crtc_states[idx];
159 crtc_state->mode_changed = true;
163 if (!connector_state->crtc) {
164 DRM_DEBUG_KMS("Disabling [CONNECTOR:%d:%s]\n",
168 connector_state->best_encoder = NULL;
173 funcs = connector->helper_private;
174 new_encoder = funcs->best_encoder(connector);
177 DRM_DEBUG_KMS("No suitable encoder found for [CONNECTOR:%d:%s]\n",
183 if (new_encoder == connector_state->best_encoder) {
184 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d]\n",
187 new_encoder->base.id,
189 connector_state->crtc->base.id);
194 encoder_crtc = get_current_crtc_for_encoder(state->dev,
198 ret = steal_encoder(state, new_encoder, encoder_crtc);
200 DRM_DEBUG_KMS("Encoder stealing failed for [CONNECTOR:%d:%s]\n",
207 connector_state->best_encoder = new_encoder;
208 idx = drm_crtc_index(connector_state->crtc);
210 crtc_state = state->crtc_states[idx];
211 crtc_state->mode_changed = true;
213 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d]\n",
216 new_encoder->base.id,
218 connector_state->crtc->base.id);
224 mode_fixup(struct drm_atomic_state *state)
226 int ncrtcs = state->dev->mode_config.num_crtc;
227 int nconnectors = state->dev->mode_config.num_connector;
228 struct drm_crtc_state *crtc_state;
229 struct drm_connector_state *conn_state;
233 for (i = 0; i < ncrtcs; i++) {
234 crtc_state = state->crtc_states[i];
236 if (!crtc_state || !crtc_state->mode_changed)
239 drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode);
242 for (i = 0; i < nconnectors; i++) {
243 struct drm_encoder_helper_funcs *funcs;
244 struct drm_encoder *encoder;
246 conn_state = state->connector_states[i];
251 WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc);
253 if (!conn_state->crtc || !conn_state->best_encoder)
257 state->crtc_states[drm_crtc_index(conn_state->crtc)];
260 * Each encoder has at most one connector (since we always steal
261 * it away), so we won't call ->mode_fixup twice.
263 encoder = conn_state->best_encoder;
264 funcs = encoder->helper_private;
266 if (encoder->bridge && encoder->bridge->funcs->mode_fixup) {
267 ret = encoder->bridge->funcs->mode_fixup(
268 encoder->bridge, &crtc_state->mode,
269 &crtc_state->adjusted_mode);
271 DRM_DEBUG_KMS("Bridge fixup failed\n");
277 ret = funcs->mode_fixup(encoder, &crtc_state->mode,
278 &crtc_state->adjusted_mode);
280 DRM_DEBUG_KMS("[ENCODER:%d:%s] fixup failed\n",
281 encoder->base.id, encoder->name);
286 for (i = 0; i < ncrtcs; i++) {
287 struct drm_crtc_helper_funcs *funcs;
288 struct drm_crtc *crtc;
290 crtc_state = state->crtc_states[i];
291 crtc = state->crtcs[i];
293 if (!crtc_state || !crtc_state->mode_changed)
296 funcs = crtc->helper_private;
297 ret = funcs->mode_fixup(crtc, &crtc_state->mode,
298 &crtc_state->adjusted_mode);
300 DRM_DEBUG_KMS("[CRTC:%d] fixup failed\n",
310 drm_atomic_helper_check_prepare(struct drm_device *dev,
311 struct drm_atomic_state *state)
313 int ncrtcs = dev->mode_config.num_crtc;
314 int nconnectors = dev->mode_config.num_connector;
315 struct drm_crtc *crtc;
316 struct drm_crtc_state *crtc_state;
319 for (i = 0; i < ncrtcs; i++) {
320 crtc = state->crtcs[i];
321 crtc_state = state->crtc_states[i];
326 if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) {
327 DRM_DEBUG_KMS("[CRTC:%d] mode changed\n",
329 crtc_state->mode_changed = true;
332 if (crtc->state->enable != crtc_state->enable) {
333 DRM_DEBUG_KMS("[CRTC:%d] enable changed\n",
335 crtc_state->mode_changed = true;
339 for (i = 0; i < nconnectors; i++) {
341 * This only sets crtc->mode_changed for routing changes,
342 * drivers must set crtc->mode_changed themselves when connector
343 * properties need to be updated.
345 ret = update_connector_routing(state, i);
351 * After all the routing has been prepared we need to add in any
352 * connector which is itself unchanged, but who's crtc changes it's
353 * configuration. This must be done before calling mode_fixup in case a
354 * crtc only changed its mode but has the same set of connectors.
356 for (i = 0; i < ncrtcs; i++) {
359 crtc = state->crtcs[i];
360 crtc_state = state->crtc_states[i];
362 if (!crtc || !crtc_state->mode_changed)
365 DRM_DEBUG_KMS("[CRTC:%d] needs full modeset, enable: %c\n",
367 crtc_state->enable ? 'y' : 'n');
369 ret = drm_atomic_add_affected_connectors(state, crtc);
373 num_connectors = drm_atomic_connectors_for_crtc(state,
376 if (crtc_state->enable != !!num_connectors) {
377 DRM_DEBUG_KMS("[CRTC:%d] enabled/connectors mismatch\n",
384 return mode_fixup(state);
388 * drm_atomic_helper_check - validate state object
390 * @state: the driver state object
392 * Check the state object to see if the requested state is physically possible.
393 * Only crtcs and planes have check callbacks, so for any additional (global)
394 * checking that a driver needs it can simply wrap that around this function.
395 * Drivers without such needs can directly use this as their ->atomic_check()
399 * Zero for success or -errno
401 int drm_atomic_helper_check(struct drm_device *dev,
402 struct drm_atomic_state *state)
404 int nplanes = dev->mode_config.num_total_plane;
405 int ncrtcs = dev->mode_config.num_crtc;
408 ret = drm_atomic_helper_check_prepare(dev, state);
412 for (i = 0; i < nplanes; i++) {
413 struct drm_plane_helper_funcs *funcs;
414 struct drm_plane *plane = state->planes[i];
415 struct drm_plane_state *plane_state = state->plane_states[i];
420 funcs = plane->helper_private;
422 drm_atomic_helper_plane_changed(state, plane_state, plane);
424 if (!funcs || !funcs->atomic_check)
427 ret = funcs->atomic_check(plane, plane_state);
429 DRM_DEBUG_KMS("[PLANE:%d] atomic check failed\n",
435 for (i = 0; i < ncrtcs; i++) {
436 struct drm_crtc_helper_funcs *funcs;
437 struct drm_crtc *crtc = state->crtcs[i];
442 funcs = crtc->helper_private;
444 if (!funcs || !funcs->atomic_check)
447 ret = funcs->atomic_check(crtc, state->crtc_states[i]);
449 DRM_DEBUG_KMS("[CRTC:%d] atomic check failed\n",
457 EXPORT_SYMBOL(drm_atomic_helper_check);
460 disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
462 int ncrtcs = old_state->dev->mode_config.num_crtc;
463 int nconnectors = old_state->dev->mode_config.num_connector;
466 for (i = 0; i < nconnectors; i++) {
467 struct drm_connector_state *old_conn_state;
468 struct drm_connector *connector;
469 struct drm_encoder_helper_funcs *funcs;
470 struct drm_encoder *encoder;
472 old_conn_state = old_state->connector_states[i];
473 connector = old_state->connectors[i];
475 /* Shut down everything that's in the changeset and currently
476 * still on. So need to check the old, saved state. */
477 if (!old_conn_state || !old_conn_state->crtc)
480 encoder = connector->state->best_encoder;
485 funcs = encoder->helper_private;
488 * Each encoder has at most one connector (since we always steal
489 * it away), so we won't call call disable hooks twice.
492 encoder->bridge->funcs->disable(encoder->bridge);
494 /* Right function depends upon target state. */
495 if (connector->state->crtc)
496 funcs->prepare(encoder);
497 else if (funcs->disable)
498 funcs->disable(encoder);
500 funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
503 encoder->bridge->funcs->post_disable(encoder->bridge);
506 for (i = 0; i < ncrtcs; i++) {
507 struct drm_crtc_helper_funcs *funcs;
508 struct drm_crtc *crtc;
510 crtc = old_state->crtcs[i];
512 /* Shut down everything that needs a full modeset. */
513 if (!crtc || !crtc->state->mode_changed)
516 funcs = crtc->helper_private;
518 /* Right function depends upon target state. */
519 if (crtc->state->enable)
520 funcs->prepare(crtc);
521 else if (funcs->disable)
522 funcs->disable(crtc);
524 funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
529 set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state)
531 int nconnectors = dev->mode_config.num_connector;
532 int ncrtcs = old_state->dev->mode_config.num_crtc;
535 /* clear out existing links */
536 for (i = 0; i < nconnectors; i++) {
537 struct drm_connector *connector;
539 connector = old_state->connectors[i];
541 if (!connector || !connector->encoder)
544 WARN_ON(!connector->encoder->crtc);
546 connector->encoder->crtc = NULL;
547 connector->encoder = NULL;
551 for (i = 0; i < nconnectors; i++) {
552 struct drm_connector *connector;
554 connector = old_state->connectors[i];
556 if (!connector || !connector->state->crtc)
559 if (WARN_ON(!connector->state->best_encoder))
562 connector->encoder = connector->state->best_encoder;
563 connector->encoder->crtc = connector->state->crtc;
566 /* set legacy state in the crtc structure */
567 for (i = 0; i < ncrtcs; i++) {
568 struct drm_crtc *crtc;
570 crtc = old_state->crtcs[i];
575 crtc->mode = crtc->state->mode;
576 crtc->enabled = crtc->state->enable;
577 crtc->x = crtc->primary->state->src_x >> 16;
578 crtc->y = crtc->primary->state->src_y >> 16;
583 crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
585 int ncrtcs = old_state->dev->mode_config.num_crtc;
586 int nconnectors = old_state->dev->mode_config.num_connector;
589 for (i = 0; i < ncrtcs; i++) {
590 struct drm_crtc_helper_funcs *funcs;
591 struct drm_crtc *crtc;
593 crtc = old_state->crtcs[i];
595 if (!crtc || !crtc->state->mode_changed)
598 funcs = crtc->helper_private;
600 if (crtc->state->enable)
601 funcs->mode_set_nofb(crtc);
604 for (i = 0; i < nconnectors; i++) {
605 struct drm_connector *connector;
606 struct drm_crtc_state *new_crtc_state;
607 struct drm_encoder_helper_funcs *funcs;
608 struct drm_encoder *encoder;
609 struct drm_display_mode *mode, *adjusted_mode;
611 connector = old_state->connectors[i];
613 if (!connector || !connector->state->best_encoder)
616 encoder = connector->state->best_encoder;
617 funcs = encoder->helper_private;
618 new_crtc_state = connector->state->crtc->state;
619 mode = &new_crtc_state->mode;
620 adjusted_mode = &new_crtc_state->adjusted_mode;
623 * Each encoder has at most one connector (since we always steal
624 * it away), so we won't call call mode_set hooks twice.
626 funcs->mode_set(encoder, mode, adjusted_mode);
628 if (encoder->bridge && encoder->bridge->funcs->mode_set)
629 encoder->bridge->funcs->mode_set(encoder->bridge,
630 mode, adjusted_mode);
635 * drm_atomic_helper_commit_pre_planes - modeset commit before plane updates
637 * @state: atomic state
639 * This function commits the modeset changes that need to be committed before
640 * updating planes. It shuts down all the outputs that need to be shut down and
641 * prepares them (if required) with the new mode.
643 void drm_atomic_helper_commit_pre_planes(struct drm_device *dev,
644 struct drm_atomic_state *state)
646 disable_outputs(dev, state);
647 set_routing_links(dev, state);
648 crtc_set_mode(dev, state);
650 EXPORT_SYMBOL(drm_atomic_helper_commit_pre_planes);
653 * drm_atomic_helper_commit_post_planes - modeset commit after plane updates
655 * @old_state: atomic state object with old state structures
657 * This function commits the modeset changes that need to be committed after
658 * updating planes: It enables all the outputs with the new configuration which
659 * had to be turned off for the update.
661 void drm_atomic_helper_commit_post_planes(struct drm_device *dev,
662 struct drm_atomic_state *old_state)
664 int ncrtcs = old_state->dev->mode_config.num_crtc;
665 int nconnectors = old_state->dev->mode_config.num_connector;
668 for (i = 0; i < ncrtcs; i++) {
669 struct drm_crtc_helper_funcs *funcs;
670 struct drm_crtc *crtc;
672 crtc = old_state->crtcs[i];
674 /* Need to filter out CRTCs where only planes change. */
675 if (!crtc || !crtc->state->mode_changed)
678 funcs = crtc->helper_private;
680 if (crtc->state->enable)
684 for (i = 0; i < nconnectors; i++) {
685 struct drm_connector *connector;
686 struct drm_encoder_helper_funcs *funcs;
687 struct drm_encoder *encoder;
689 connector = old_state->connectors[i];
691 if (!connector || !connector->state->best_encoder)
694 encoder = connector->state->best_encoder;
695 funcs = encoder->helper_private;
698 * Each encoder has at most one connector (since we always steal
699 * it away), so we won't call call enable hooks twice.
702 encoder->bridge->funcs->pre_enable(encoder->bridge);
704 funcs->commit(encoder);
707 encoder->bridge->funcs->enable(encoder->bridge);
710 EXPORT_SYMBOL(drm_atomic_helper_commit_post_planes);
713 wait_for_vblanks(struct drm_device *dev, struct drm_atomic_state *old_state)
715 struct drm_crtc *crtc;
716 struct drm_crtc_state *old_crtc_state;
717 int ncrtcs = old_state->dev->mode_config.num_crtc;
720 for (i = 0; i < ncrtcs; i++) {
721 crtc = old_state->crtcs[i];
722 old_crtc_state = old_state->crtc_states[i];
727 /* No one cares about the old state, so abuse it for tracking
728 * and store whether we hold a vblank reference (and should do a
729 * vblank wait) in the ->enable boolean. */
730 old_crtc_state->enable = false;
732 if (!crtc->state->enable)
735 ret = drm_crtc_vblank_get(crtc);
739 old_crtc_state->enable = true;
740 old_crtc_state->last_vblank_count = drm_vblank_count(dev, i);
743 for (i = 0; i < ncrtcs; i++) {
744 crtc = old_state->crtcs[i];
745 old_crtc_state = old_state->crtc_states[i];
747 if (!crtc || !old_crtc_state->enable)
750 ret = wait_event_timeout(dev->vblank[i].queue,
751 old_crtc_state->last_vblank_count !=
752 drm_vblank_count(dev, i),
753 msecs_to_jiffies(50));
755 drm_crtc_vblank_put(crtc);
760 * drm_atomic_helper_commit - commit validated state object
762 * @state: the driver state object
763 * @async: asynchronous commit
765 * This function commits a with drm_atomic_helper_check() pre-validated state
766 * object. This can still fail when e.g. the framebuffer reservation fails. For
767 * now this doesn't implement asynchronous commits.
770 * Zero for success or -errno.
772 int drm_atomic_helper_commit(struct drm_device *dev,
773 struct drm_atomic_state *state,
781 ret = drm_atomic_helper_prepare_planes(dev, state);
786 * This is the point of no return - everything below never fails except
787 * when the hw goes bonghits. Which means we can commit the new state on
788 * the software side now.
791 drm_atomic_helper_swap_state(dev, state);
794 * Everything below can be run asynchronously without the need to grab
795 * any modeset locks at all under one conditions: It must be guaranteed
796 * that the asynchronous work has either been cancelled (if the driver
797 * supports it, which at least requires that the framebuffers get
798 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
799 * before the new state gets committed on the software side with
800 * drm_atomic_helper_swap_state().
802 * This scheme allows new atomic state updates to be prepared and
803 * checked in parallel to the asynchronous completion of the previous
804 * update. Which is important since compositors need to figure out the
805 * composition of the next frame right after having submitted the
809 drm_atomic_helper_commit_pre_planes(dev, state);
811 drm_atomic_helper_commit_planes(dev, state);
813 drm_atomic_helper_commit_post_planes(dev, state);
815 wait_for_vblanks(dev, state);
817 drm_atomic_helper_cleanup_planes(dev, state);
819 drm_atomic_state_free(state);
823 EXPORT_SYMBOL(drm_atomic_helper_commit);
826 * drm_atomic_helper_prepare_planes - prepare plane resources after commit
828 * @state: atomic state object with old state structures
830 * This function prepares plane state, specifically framebuffers, for the new
831 * configuration. If any failure is encountered this function will call
832 * ->cleanup_fb on any already successfully prepared framebuffer.
835 * 0 on success, negative error code on failure.
837 int drm_atomic_helper_prepare_planes(struct drm_device *dev,
838 struct drm_atomic_state *state)
840 int nplanes = dev->mode_config.num_total_plane;
843 for (i = 0; i < nplanes; i++) {
844 struct drm_plane_helper_funcs *funcs;
845 struct drm_plane *plane = state->planes[i];
846 struct drm_framebuffer *fb;
851 funcs = plane->helper_private;
853 fb = state->plane_states[i]->fb;
855 if (fb && funcs->prepare_fb) {
856 ret = funcs->prepare_fb(plane, fb);
865 for (i--; i >= 0; i--) {
866 struct drm_plane_helper_funcs *funcs;
867 struct drm_plane *plane = state->planes[i];
868 struct drm_framebuffer *fb;
873 funcs = plane->helper_private;
875 fb = state->plane_states[i]->fb;
877 if (fb && funcs->cleanup_fb)
878 funcs->cleanup_fb(plane, fb);
884 EXPORT_SYMBOL(drm_atomic_helper_prepare_planes);
887 * drm_atomic_helper_commit_planes - commit plane state
889 * @state: atomic state
891 * This function commits the new plane state using the plane and atomic helper
892 * functions for planes and crtcs. It assumes that the atomic state has already
893 * been pushed into the relevant object state pointers, since this step can no
896 * It still requires the global state object @state to know which planes and
897 * crtcs need to be updated though.
899 void drm_atomic_helper_commit_planes(struct drm_device *dev,
900 struct drm_atomic_state *state)
902 int nplanes = dev->mode_config.num_total_plane;
903 int ncrtcs = dev->mode_config.num_crtc;
906 for (i = 0; i < ncrtcs; i++) {
907 struct drm_crtc_helper_funcs *funcs;
908 struct drm_crtc *crtc = state->crtcs[i];
913 funcs = crtc->helper_private;
915 if (!funcs || !funcs->atomic_begin)
918 funcs->atomic_begin(crtc);
921 for (i = 0; i < nplanes; i++) {
922 struct drm_plane_helper_funcs *funcs;
923 struct drm_plane *plane = state->planes[i];
928 funcs = plane->helper_private;
930 if (!funcs || !funcs->atomic_update)
933 funcs->atomic_update(plane);
936 for (i = 0; i < ncrtcs; i++) {
937 struct drm_crtc_helper_funcs *funcs;
938 struct drm_crtc *crtc = state->crtcs[i];
943 funcs = crtc->helper_private;
945 if (!funcs || !funcs->atomic_flush)
948 funcs->atomic_flush(crtc);
951 EXPORT_SYMBOL(drm_atomic_helper_commit_planes);
954 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit
956 * @old_state: atomic state object with old state structures
958 * This function cleans up plane state, specifically framebuffers, from the old
959 * configuration. Hence the old configuration must be perserved in @old_state to
960 * be able to call this function.
962 * This function must also be called on the new state when the atomic update
963 * fails at any point after calling drm_atomic_helper_prepare_planes().
965 void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
966 struct drm_atomic_state *old_state)
968 int nplanes = dev->mode_config.num_total_plane;
971 for (i = 0; i < nplanes; i++) {
972 struct drm_plane_helper_funcs *funcs;
973 struct drm_plane *plane = old_state->planes[i];
974 struct drm_framebuffer *old_fb;
979 funcs = plane->helper_private;
981 old_fb = old_state->plane_states[i]->fb;
983 if (old_fb && funcs->cleanup_fb)
984 funcs->cleanup_fb(plane, old_fb);
987 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
990 * drm_atomic_helper_swap_state - store atomic state into current sw state
992 * @state: atomic state
994 * This function stores the atomic state into the current state pointers in all
995 * driver objects. It should be called after all failing steps have been done
996 * and succeeded, but before the actual hardware state is committed.
998 * For cleanup and error recovery the current state for all changed objects will
999 * be swaped into @state.
1001 * With that sequence it fits perfectly into the plane prepare/cleanup sequence:
1003 * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state.
1005 * 2. Do any other steps that might fail.
1007 * 3. Put the staged state into the current state pointers with this function.
1009 * 4. Actually commit the hardware state.
1011 * 5. Call drm_atomic_helper_cleanup_planes with @state, which since step 3
1012 * contains the old state. Also do any other cleanup required with that state.
1014 void drm_atomic_helper_swap_state(struct drm_device *dev,
1015 struct drm_atomic_state *state)
1019 for (i = 0; i < dev->mode_config.num_connector; i++) {
1020 struct drm_connector *connector = state->connectors[i];
1025 connector->state->state = state;
1026 swap(state->connector_states[i], connector->state);
1027 connector->state->state = NULL;
1030 for (i = 0; i < dev->mode_config.num_crtc; i++) {
1031 struct drm_crtc *crtc = state->crtcs[i];
1036 crtc->state->state = state;
1037 swap(state->crtc_states[i], crtc->state);
1038 crtc->state->state = NULL;
1041 for (i = 0; i < dev->mode_config.num_total_plane; i++) {
1042 struct drm_plane *plane = state->planes[i];
1047 plane->state->state = state;
1048 swap(state->plane_states[i], plane->state);
1049 plane->state->state = NULL;
1052 EXPORT_SYMBOL(drm_atomic_helper_swap_state);