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 * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs
760 * @old_state: atomic state object with old state structures
762 * Helper to, after atomic commit, wait for vblanks on all effected
763 * crtcs (ie. before cleaning up old framebuffers using
764 * drm_atomic_helper_cleanup_planes())
767 drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
768 struct drm_atomic_state *old_state)
770 struct drm_crtc *crtc;
771 struct drm_crtc_state *old_crtc_state;
772 int ncrtcs = old_state->dev->mode_config.num_crtc;
775 for (i = 0; i < ncrtcs; i++) {
776 crtc = old_state->crtcs[i];
777 old_crtc_state = old_state->crtc_states[i];
782 /* No one cares about the old state, so abuse it for tracking
783 * and store whether we hold a vblank reference (and should do a
784 * vblank wait) in the ->enable boolean. */
785 old_crtc_state->enable = false;
787 if (!crtc->state->enable)
790 ret = drm_crtc_vblank_get(crtc);
794 old_crtc_state->enable = true;
795 old_crtc_state->last_vblank_count = drm_vblank_count(dev, i);
798 for (i = 0; i < ncrtcs; i++) {
799 crtc = old_state->crtcs[i];
800 old_crtc_state = old_state->crtc_states[i];
802 if (!crtc || !old_crtc_state->enable)
805 ret = wait_event_timeout(dev->vblank[i].queue,
806 old_crtc_state->last_vblank_count !=
807 drm_vblank_count(dev, i),
808 msecs_to_jiffies(50));
810 drm_crtc_vblank_put(crtc);
813 EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
816 * drm_atomic_helper_commit - commit validated state object
818 * @state: the driver state object
819 * @async: asynchronous commit
821 * This function commits a with drm_atomic_helper_check() pre-validated state
822 * object. This can still fail when e.g. the framebuffer reservation fails. For
823 * now this doesn't implement asynchronous commits.
826 * Zero for success or -errno.
828 int drm_atomic_helper_commit(struct drm_device *dev,
829 struct drm_atomic_state *state,
837 ret = drm_atomic_helper_prepare_planes(dev, state);
842 * This is the point of no return - everything below never fails except
843 * when the hw goes bonghits. Which means we can commit the new state on
844 * the software side now.
847 drm_atomic_helper_swap_state(dev, state);
850 * Everything below can be run asynchronously without the need to grab
851 * any modeset locks at all under one conditions: It must be guaranteed
852 * that the asynchronous work has either been cancelled (if the driver
853 * supports it, which at least requires that the framebuffers get
854 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
855 * before the new state gets committed on the software side with
856 * drm_atomic_helper_swap_state().
858 * This scheme allows new atomic state updates to be prepared and
859 * checked in parallel to the asynchronous completion of the previous
860 * update. Which is important since compositors need to figure out the
861 * composition of the next frame right after having submitted the
865 wait_for_fences(dev, state);
867 drm_atomic_helper_commit_pre_planes(dev, state);
869 drm_atomic_helper_commit_planes(dev, state);
871 drm_atomic_helper_commit_post_planes(dev, state);
873 drm_atomic_helper_wait_for_vblanks(dev, state);
875 drm_atomic_helper_cleanup_planes(dev, state);
877 drm_atomic_state_free(state);
881 EXPORT_SYMBOL(drm_atomic_helper_commit);
884 * DOC: implementing async commit
886 * For now the atomic helpers don't support async commit directly. If there is
887 * real need it could be added though, using the dma-buf fence infrastructure
888 * for generic synchronization with outstanding rendering.
890 * For now drivers have to implement async commit themselves, with the following
891 * sequence being the recommended one:
893 * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function
894 * which commit needs to call which can fail, so we want to run it first and
897 * 2. Synchronize with any outstanding asynchronous commit worker threads which
898 * might be affected the new state update. This can be done by either cancelling
899 * or flushing the work items, depending upon whether the driver can deal with
900 * cancelled updates. Note that it is important to ensure that the framebuffer
901 * cleanup is still done when cancelling.
903 * For sufficient parallelism it is recommended to have a work item per crtc
904 * (for updates which don't touch global state) and a global one. Then we only
905 * need to synchronize with the crtc work items for changed crtcs and the global
906 * work item, which allows nice concurrent updates on disjoint sets of crtcs.
908 * 3. The software state is updated synchronously with
909 * drm_atomic_helper_swap_state. Doing this under the protection of all modeset
910 * locks means concurrent callers never see inconsistent state. And doing this
911 * while it's guaranteed that no relevant async worker runs means that async
912 * workers do not need grab any locks. Actually they must not grab locks, for
913 * otherwise the work flushing will deadlock.
915 * 4. Schedule a work item to do all subsequent steps, using the split-out
916 * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
917 * then cleaning up the framebuffers after the old framebuffer is no longer
922 * drm_atomic_helper_prepare_planes - prepare plane resources after commit
924 * @state: atomic state object with old state structures
926 * This function prepares plane state, specifically framebuffers, for the new
927 * configuration. If any failure is encountered this function will call
928 * ->cleanup_fb on any already successfully prepared framebuffer.
931 * 0 on success, negative error code on failure.
933 int drm_atomic_helper_prepare_planes(struct drm_device *dev,
934 struct drm_atomic_state *state)
936 int nplanes = dev->mode_config.num_total_plane;
939 for (i = 0; i < nplanes; i++) {
940 struct drm_plane_helper_funcs *funcs;
941 struct drm_plane *plane = state->planes[i];
942 struct drm_framebuffer *fb;
947 funcs = plane->helper_private;
949 fb = state->plane_states[i]->fb;
951 if (fb && funcs->prepare_fb) {
952 ret = funcs->prepare_fb(plane, fb);
961 for (i--; i >= 0; i--) {
962 struct drm_plane_helper_funcs *funcs;
963 struct drm_plane *plane = state->planes[i];
964 struct drm_framebuffer *fb;
969 funcs = plane->helper_private;
971 fb = state->plane_states[i]->fb;
973 if (fb && funcs->cleanup_fb)
974 funcs->cleanup_fb(plane, fb);
980 EXPORT_SYMBOL(drm_atomic_helper_prepare_planes);
983 * drm_atomic_helper_commit_planes - commit plane state
985 * @state: atomic state
987 * This function commits the new plane state using the plane and atomic helper
988 * functions for planes and crtcs. It assumes that the atomic state has already
989 * been pushed into the relevant object state pointers, since this step can no
992 * It still requires the global state object @state to know which planes and
993 * crtcs need to be updated though.
995 void drm_atomic_helper_commit_planes(struct drm_device *dev,
996 struct drm_atomic_state *state)
998 int nplanes = dev->mode_config.num_total_plane;
999 int ncrtcs = dev->mode_config.num_crtc;
1002 for (i = 0; i < ncrtcs; i++) {
1003 struct drm_crtc_helper_funcs *funcs;
1004 struct drm_crtc *crtc = state->crtcs[i];
1009 funcs = crtc->helper_private;
1011 if (!funcs || !funcs->atomic_begin)
1014 funcs->atomic_begin(crtc);
1017 for (i = 0; i < nplanes; i++) {
1018 struct drm_plane_helper_funcs *funcs;
1019 struct drm_plane *plane = state->planes[i];
1024 funcs = plane->helper_private;
1026 if (!funcs || !funcs->atomic_update)
1029 funcs->atomic_update(plane);
1032 for (i = 0; i < ncrtcs; i++) {
1033 struct drm_crtc_helper_funcs *funcs;
1034 struct drm_crtc *crtc = state->crtcs[i];
1039 funcs = crtc->helper_private;
1041 if (!funcs || !funcs->atomic_flush)
1044 funcs->atomic_flush(crtc);
1047 EXPORT_SYMBOL(drm_atomic_helper_commit_planes);
1050 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit
1052 * @old_state: atomic state object with old state structures
1054 * This function cleans up plane state, specifically framebuffers, from the old
1055 * configuration. Hence the old configuration must be perserved in @old_state to
1056 * be able to call this function.
1058 * This function must also be called on the new state when the atomic update
1059 * fails at any point after calling drm_atomic_helper_prepare_planes().
1061 void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
1062 struct drm_atomic_state *old_state)
1064 int nplanes = dev->mode_config.num_total_plane;
1067 for (i = 0; i < nplanes; i++) {
1068 struct drm_plane_helper_funcs *funcs;
1069 struct drm_plane *plane = old_state->planes[i];
1070 struct drm_framebuffer *old_fb;
1075 funcs = plane->helper_private;
1077 old_fb = old_state->plane_states[i]->fb;
1079 if (old_fb && funcs->cleanup_fb)
1080 funcs->cleanup_fb(plane, old_fb);
1083 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
1086 * drm_atomic_helper_swap_state - store atomic state into current sw state
1088 * @state: atomic state
1090 * This function stores the atomic state into the current state pointers in all
1091 * driver objects. It should be called after all failing steps have been done
1092 * and succeeded, but before the actual hardware state is committed.
1094 * For cleanup and error recovery the current state for all changed objects will
1095 * be swaped into @state.
1097 * With that sequence it fits perfectly into the plane prepare/cleanup sequence:
1099 * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state.
1101 * 2. Do any other steps that might fail.
1103 * 3. Put the staged state into the current state pointers with this function.
1105 * 4. Actually commit the hardware state.
1107 * 5. Call drm_atomic_helper_cleanup_planes with @state, which since step 3
1108 * contains the old state. Also do any other cleanup required with that state.
1110 void drm_atomic_helper_swap_state(struct drm_device *dev,
1111 struct drm_atomic_state *state)
1115 for (i = 0; i < dev->mode_config.num_connector; i++) {
1116 struct drm_connector *connector = state->connectors[i];
1121 connector->state->state = state;
1122 swap(state->connector_states[i], connector->state);
1123 connector->state->state = NULL;
1126 for (i = 0; i < dev->mode_config.num_crtc; i++) {
1127 struct drm_crtc *crtc = state->crtcs[i];
1132 crtc->state->state = state;
1133 swap(state->crtc_states[i], crtc->state);
1134 crtc->state->state = NULL;
1137 for (i = 0; i < dev->mode_config.num_total_plane; i++) {
1138 struct drm_plane *plane = state->planes[i];
1143 plane->state->state = state;
1144 swap(state->plane_states[i], plane->state);
1145 plane->state->state = NULL;
1148 EXPORT_SYMBOL(drm_atomic_helper_swap_state);
1151 * drm_atomic_helper_update_plane - Helper for primary plane update using atomic
1152 * @plane: plane object to update
1153 * @crtc: owning CRTC of owning plane
1154 * @fb: framebuffer to flip onto plane
1155 * @crtc_x: x offset of primary plane on crtc
1156 * @crtc_y: y offset of primary plane on crtc
1157 * @crtc_w: width of primary plane rectangle on crtc
1158 * @crtc_h: height of primary plane rectangle on crtc
1159 * @src_x: x offset of @fb for panning
1160 * @src_y: y offset of @fb for panning
1161 * @src_w: width of source rectangle in @fb
1162 * @src_h: height of source rectangle in @fb
1164 * Provides a default plane update handler using the atomic driver interface.
1167 * Zero on success, error code on failure
1169 int drm_atomic_helper_update_plane(struct drm_plane *plane,
1170 struct drm_crtc *crtc,
1171 struct drm_framebuffer *fb,
1172 int crtc_x, int crtc_y,
1173 unsigned int crtc_w, unsigned int crtc_h,
1174 uint32_t src_x, uint32_t src_y,
1175 uint32_t src_w, uint32_t src_h)
1177 struct drm_atomic_state *state;
1178 struct drm_plane_state *plane_state;
1181 state = drm_atomic_state_alloc(plane->dev);
1185 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1187 plane_state = drm_atomic_get_plane_state(state, plane);
1188 if (IS_ERR(plane_state)) {
1189 ret = PTR_ERR(plane_state);
1193 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
1196 drm_atomic_set_fb_for_plane(plane_state, fb);
1197 plane_state->crtc_x = crtc_x;
1198 plane_state->crtc_y = crtc_y;
1199 plane_state->crtc_h = crtc_h;
1200 plane_state->crtc_w = crtc_w;
1201 plane_state->src_x = src_x;
1202 plane_state->src_y = src_y;
1203 plane_state->src_h = src_h;
1204 plane_state->src_w = src_w;
1206 ret = drm_atomic_commit(state);
1210 /* Driver takes ownership of state on successful commit. */
1213 if (ret == -EDEADLK)
1216 drm_atomic_state_free(state);
1220 drm_atomic_legacy_backoff(state);
1221 drm_atomic_state_clear(state);
1224 * Someone might have exchanged the framebuffer while we dropped locks
1225 * in the backoff code. We need to fix up the fb refcount tracking the
1228 plane->old_fb = plane->fb;
1232 EXPORT_SYMBOL(drm_atomic_helper_update_plane);
1235 * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic
1236 * @plane: plane to disable
1238 * Provides a default plane disable handler using the atomic driver interface.
1241 * Zero on success, error code on failure
1243 int drm_atomic_helper_disable_plane(struct drm_plane *plane)
1245 struct drm_atomic_state *state;
1246 struct drm_plane_state *plane_state;
1249 state = drm_atomic_state_alloc(plane->dev);
1253 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(plane->crtc);
1255 plane_state = drm_atomic_get_plane_state(state, plane);
1256 if (IS_ERR(plane_state)) {
1257 ret = PTR_ERR(plane_state);
1261 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
1264 drm_atomic_set_fb_for_plane(plane_state, NULL);
1265 plane_state->crtc_x = 0;
1266 plane_state->crtc_y = 0;
1267 plane_state->crtc_h = 0;
1268 plane_state->crtc_w = 0;
1269 plane_state->src_x = 0;
1270 plane_state->src_y = 0;
1271 plane_state->src_h = 0;
1272 plane_state->src_w = 0;
1274 ret = drm_atomic_commit(state);
1278 /* Driver takes ownership of state on successful commit. */
1281 if (ret == -EDEADLK)
1284 drm_atomic_state_free(state);
1288 drm_atomic_legacy_backoff(state);
1289 drm_atomic_state_clear(state);
1292 * Someone might have exchanged the framebuffer while we dropped locks
1293 * in the backoff code. We need to fix up the fb refcount tracking the
1296 plane->old_fb = plane->fb;
1300 EXPORT_SYMBOL(drm_atomic_helper_disable_plane);
1302 static int update_output_state(struct drm_atomic_state *state,
1303 struct drm_mode_set *set)
1305 struct drm_device *dev = set->crtc->dev;
1306 struct drm_connector_state *conn_state;
1307 int nconnectors = state->dev->mode_config.num_connector;
1308 int ncrtcs = state->dev->mode_config.num_crtc;
1311 ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
1312 state->acquire_ctx);
1316 /* First grab all affected connector/crtc states. */
1317 for (i = 0; i < set->num_connectors; i++) {
1318 conn_state = drm_atomic_get_connector_state(state,
1319 set->connectors[i]);
1320 if (IS_ERR(conn_state))
1321 return PTR_ERR(conn_state);
1324 for (i = 0; i < ncrtcs; i++) {
1325 struct drm_crtc *crtc = state->crtcs[i];
1330 ret = drm_atomic_add_affected_connectors(state, crtc);
1335 /* Then recompute connector->crtc links and crtc enabling state. */
1336 for (i = 0; i < nconnectors; i++) {
1337 struct drm_connector *connector;
1339 connector = state->connectors[i];
1340 conn_state = state->connector_states[i];
1345 if (conn_state->crtc == set->crtc) {
1346 ret = drm_atomic_set_crtc_for_connector(conn_state,
1352 for (j = 0; j < set->num_connectors; j++) {
1353 if (set->connectors[j] == connector) {
1354 ret = drm_atomic_set_crtc_for_connector(conn_state,
1363 for (i = 0; i < ncrtcs; i++) {
1364 struct drm_crtc *crtc = state->crtcs[i];
1365 struct drm_crtc_state *crtc_state = state->crtc_states[i];
1370 /* Don't update ->enable for the CRTC in the set_config request,
1371 * since a mismatch would indicate a bug in the upper layers.
1372 * The actual modeset code later on will catch any
1373 * inconsistencies here. */
1374 if (crtc == set->crtc)
1377 crtc_state->enable =
1378 drm_atomic_connectors_for_crtc(state, crtc);
1385 * drm_atomic_helper_set_config - set a new config from userspace
1386 * @set: mode set configuration
1388 * Provides a default crtc set_config handler using the atomic driver interface.
1391 * Returns 0 on success, negative errno numbers on failure.
1393 int drm_atomic_helper_set_config(struct drm_mode_set *set)
1395 struct drm_atomic_state *state;
1396 struct drm_crtc *crtc = set->crtc;
1397 struct drm_crtc_state *crtc_state;
1398 struct drm_plane_state *primary_state;
1401 state = drm_atomic_state_alloc(crtc->dev);
1405 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1407 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1408 if (IS_ERR(crtc_state)) {
1409 ret = PTR_ERR(crtc_state);
1415 WARN_ON(set->num_connectors);
1417 crtc_state->enable = false;
1422 WARN_ON(!set->num_connectors);
1424 crtc_state->enable = true;
1425 drm_mode_copy(&crtc_state->mode, set->mode);
1427 primary_state = drm_atomic_get_plane_state(state, crtc->primary);
1428 if (IS_ERR(primary_state)) {
1429 ret = PTR_ERR(primary_state);
1433 ret = drm_atomic_set_crtc_for_plane(primary_state, crtc);
1436 drm_atomic_set_fb_for_plane(primary_state, set->fb);
1437 primary_state->crtc_x = 0;
1438 primary_state->crtc_y = 0;
1439 primary_state->crtc_h = set->mode->vdisplay;
1440 primary_state->crtc_w = set->mode->hdisplay;
1441 primary_state->src_x = set->x << 16;
1442 primary_state->src_y = set->y << 16;
1443 primary_state->src_h = set->mode->vdisplay << 16;
1444 primary_state->src_w = set->mode->hdisplay << 16;
1447 ret = update_output_state(state, set);
1451 ret = drm_atomic_commit(state);
1455 /* Driver takes ownership of state on successful commit. */
1458 if (ret == -EDEADLK)
1461 drm_atomic_state_free(state);
1465 drm_atomic_legacy_backoff(state);
1466 drm_atomic_state_clear(state);
1469 * Someone might have exchanged the framebuffer while we dropped locks
1470 * in the backoff code. We need to fix up the fb refcount tracking the
1473 crtc->primary->old_fb = crtc->primary->fb;
1477 EXPORT_SYMBOL(drm_atomic_helper_set_config);
1480 * drm_atomic_helper_crtc_set_property - helper for crtc prorties
1482 * @property: DRM property
1483 * @val: value of property
1485 * Provides a default plane disablle handler using the atomic driver interface.
1488 * Zero on success, error code on failure
1491 drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
1492 struct drm_property *property,
1495 struct drm_atomic_state *state;
1496 struct drm_crtc_state *crtc_state;
1499 state = drm_atomic_state_alloc(crtc->dev);
1503 /* ->set_property is always called with all locks held. */
1504 state->acquire_ctx = crtc->dev->mode_config.acquire_ctx;
1506 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1507 if (IS_ERR(crtc_state)) {
1508 ret = PTR_ERR(crtc_state);
1512 ret = crtc->funcs->atomic_set_property(crtc, crtc_state,
1517 ret = drm_atomic_commit(state);
1521 /* Driver takes ownership of state on successful commit. */
1524 if (ret == -EDEADLK)
1527 drm_atomic_state_free(state);
1531 drm_atomic_legacy_backoff(state);
1532 drm_atomic_state_clear(state);
1536 EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property);
1539 * drm_atomic_helper_plane_set_property - helper for plane prorties
1541 * @property: DRM property
1542 * @val: value of property
1544 * Provides a default plane disable handler using the atomic driver interface.
1547 * Zero on success, error code on failure
1550 drm_atomic_helper_plane_set_property(struct drm_plane *plane,
1551 struct drm_property *property,
1554 struct drm_atomic_state *state;
1555 struct drm_plane_state *plane_state;
1558 state = drm_atomic_state_alloc(plane->dev);
1562 /* ->set_property is always called with all locks held. */
1563 state->acquire_ctx = plane->dev->mode_config.acquire_ctx;
1565 plane_state = drm_atomic_get_plane_state(state, plane);
1566 if (IS_ERR(plane_state)) {
1567 ret = PTR_ERR(plane_state);
1571 ret = plane->funcs->atomic_set_property(plane, plane_state,
1576 ret = drm_atomic_commit(state);
1580 /* Driver takes ownership of state on successful commit. */
1583 if (ret == -EDEADLK)
1586 drm_atomic_state_free(state);
1590 drm_atomic_legacy_backoff(state);
1591 drm_atomic_state_clear(state);
1595 EXPORT_SYMBOL(drm_atomic_helper_plane_set_property);
1598 * drm_atomic_helper_connector_set_property - helper for connector prorties
1599 * @connector: DRM connector
1600 * @property: DRM property
1601 * @val: value of property
1603 * Provides a default plane disablle handler using the atomic driver interface.
1606 * Zero on success, error code on failure
1609 drm_atomic_helper_connector_set_property(struct drm_connector *connector,
1610 struct drm_property *property,
1613 struct drm_atomic_state *state;
1614 struct drm_connector_state *connector_state;
1617 state = drm_atomic_state_alloc(connector->dev);
1621 /* ->set_property is always called with all locks held. */
1622 state->acquire_ctx = connector->dev->mode_config.acquire_ctx;
1624 connector_state = drm_atomic_get_connector_state(state, connector);
1625 if (IS_ERR(connector_state)) {
1626 ret = PTR_ERR(connector_state);
1630 ret = connector->funcs->atomic_set_property(connector, connector_state,
1635 ret = drm_atomic_commit(state);
1639 /* Driver takes ownership of state on successful commit. */
1642 if (ret == -EDEADLK)
1645 drm_atomic_state_free(state);
1649 drm_atomic_legacy_backoff(state);
1650 drm_atomic_state_clear(state);
1654 EXPORT_SYMBOL(drm_atomic_helper_connector_set_property);
1657 * drm_atomic_helper_page_flip - execute a legacy page flip
1659 * @fb: DRM framebuffer
1660 * @event: optional DRM event to signal upon completion
1661 * @flags: flip flags for non-vblank sync'ed updates
1663 * Provides a default page flip implementation using the atomic driver interface.
1665 * Note that for now so called async page flips (i.e. updates which are not
1666 * synchronized to vblank) are not supported, since the atomic interfaces have
1667 * no provisions for this yet.
1670 * Returns 0 on success, negative errno numbers on failure.
1672 int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
1673 struct drm_framebuffer *fb,
1674 struct drm_pending_vblank_event *event,
1677 struct drm_plane *plane = crtc->primary;
1678 struct drm_atomic_state *state;
1679 struct drm_plane_state *plane_state;
1680 struct drm_crtc_state *crtc_state;
1683 if (flags & DRM_MODE_PAGE_FLIP_ASYNC)
1686 state = drm_atomic_state_alloc(plane->dev);
1690 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1692 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1693 if (IS_ERR(crtc_state)) {
1694 ret = PTR_ERR(crtc_state);
1697 crtc_state->event = event;
1699 plane_state = drm_atomic_get_plane_state(state, plane);
1700 if (IS_ERR(plane_state)) {
1701 ret = PTR_ERR(plane_state);
1705 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
1708 drm_atomic_set_fb_for_plane(plane_state, fb);
1710 ret = drm_atomic_async_commit(state);
1714 /* TODO: ->page_flip is the only driver callback where the core
1715 * doesn't update plane->fb. For now patch it up here. */
1716 plane->fb = plane->state->fb;
1718 /* Driver takes ownership of state on successful async commit. */
1721 if (ret == -EDEADLK)
1724 drm_atomic_state_free(state);
1728 drm_atomic_legacy_backoff(state);
1729 drm_atomic_state_clear(state);
1732 * Someone might have exchanged the framebuffer while we dropped locks
1733 * in the backoff code. We need to fix up the fb refcount tracking the
1736 plane->old_fb = plane->fb;
1740 EXPORT_SYMBOL(drm_atomic_helper_page_flip);
1743 * DOC: atomic state reset and initialization
1745 * Both the drm core and the atomic helpers assume that there is always the full
1746 * and correct atomic software state for all connectors, CRTCs and planes
1747 * available. Which is a bit a problem on driver load and also after system
1748 * suspend. One way to solve this is to have a hardware state read-out
1749 * infrastructure which reconstructs the full software state (e.g. the i915
1752 * The simpler solution is to just reset the software state to everything off,
1753 * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
1754 * the atomic helpers provide default reset implementations for all hooks.
1758 * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs
1761 * Resets the atomic state for @crtc by freeing the state pointer (which might
1762 * be NULL, e.g. at driver load time) and allocating a new empty state object.
1764 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
1767 crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
1769 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
1772 * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
1775 * Default CRTC state duplicate hook for drivers which don't have their own
1776 * subclassed CRTC state structure.
1778 struct drm_crtc_state *
1779 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
1781 struct drm_crtc_state *state;
1783 if (WARN_ON(!crtc->state))
1786 state = kmemdup(crtc->state, sizeof(*crtc->state), GFP_KERNEL);
1789 state->mode_changed = false;
1790 state->planes_changed = false;
1791 state->event = NULL;
1796 EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
1799 * drm_atomic_helper_crtc_destroy_state - default state destroy hook
1801 * @state: CRTC state object to release
1803 * Default CRTC state destroy hook for drivers which don't have their own
1804 * subclassed CRTC state structure.
1806 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
1807 struct drm_crtc_state *state)
1811 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
1814 * drm_atomic_helper_plane_reset - default ->reset hook for planes
1817 * Resets the atomic state for @plane by freeing the state pointer (which might
1818 * be NULL, e.g. at driver load time) and allocating a new empty state object.
1820 void drm_atomic_helper_plane_reset(struct drm_plane *plane)
1822 if (plane->state && plane->state->fb)
1823 drm_framebuffer_unreference(plane->state->fb);
1825 kfree(plane->state);
1826 plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
1828 EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
1831 * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
1834 * Default plane state duplicate hook for drivers which don't have their own
1835 * subclassed plane state structure.
1837 struct drm_plane_state *
1838 drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
1840 struct drm_plane_state *state;
1842 if (WARN_ON(!plane->state))
1845 state = kmemdup(plane->state, sizeof(*plane->state), GFP_KERNEL);
1847 if (state && state->fb)
1848 drm_framebuffer_reference(state->fb);
1852 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
1855 * drm_atomic_helper_plane_destroy_state - default state destroy hook
1857 * @state: plane state object to release
1859 * Default plane state destroy hook for drivers which don't have their own
1860 * subclassed plane state structure.
1862 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
1863 struct drm_plane_state *state)
1866 drm_framebuffer_unreference(state->fb);
1870 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
1873 * drm_atomic_helper_connector_reset - default ->reset hook for connectors
1874 * @connector: drm connector
1876 * Resets the atomic state for @connector by freeing the state pointer (which
1877 * might be NULL, e.g. at driver load time) and allocating a new empty state
1880 void drm_atomic_helper_connector_reset(struct drm_connector *connector)
1882 kfree(connector->state);
1883 connector->state = kzalloc(sizeof(*connector->state), GFP_KERNEL);
1885 EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
1888 * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
1889 * @connector: drm connector
1891 * Default connector state duplicate hook for drivers which don't have their own
1892 * subclassed connector state structure.
1894 struct drm_connector_state *
1895 drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
1897 if (WARN_ON(!connector->state))
1900 return kmemdup(connector->state, sizeof(*connector->state), GFP_KERNEL);
1902 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
1905 * drm_atomic_helper_connector_destroy_state - default state destroy hook
1906 * @connector: drm connector
1907 * @state: connector state object to release
1909 * Default connector state destroy hook for drivers which don't have their own
1910 * subclassed connector state structure.
1912 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
1913 struct drm_connector_state *state)
1917 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);