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 struct drm_crtc_state *crtc_state;
253 struct drm_connector_state *conn_state;
257 for (i = 0; i < ncrtcs; i++) {
258 crtc_state = state->crtc_states[i];
260 if (!crtc_state || !crtc_state->mode_changed)
263 drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode);
266 for (i = 0; i < state->num_connector; i++) {
267 struct drm_encoder_helper_funcs *funcs;
268 struct drm_encoder *encoder;
270 conn_state = state->connector_states[i];
275 WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc);
277 if (!conn_state->crtc || !conn_state->best_encoder)
281 state->crtc_states[drm_crtc_index(conn_state->crtc)];
284 * Each encoder has at most one connector (since we always steal
285 * it away), so we won't call ->mode_fixup twice.
287 encoder = conn_state->best_encoder;
288 funcs = encoder->helper_private;
290 if (encoder->bridge && encoder->bridge->funcs->mode_fixup) {
291 ret = encoder->bridge->funcs->mode_fixup(
292 encoder->bridge, &crtc_state->mode,
293 &crtc_state->adjusted_mode);
295 DRM_DEBUG_KMS("Bridge fixup failed\n");
301 ret = funcs->mode_fixup(encoder, &crtc_state->mode,
302 &crtc_state->adjusted_mode);
304 DRM_DEBUG_KMS("[ENCODER:%d:%s] fixup failed\n",
305 encoder->base.id, encoder->name);
310 for (i = 0; i < ncrtcs; i++) {
311 struct drm_crtc_helper_funcs *funcs;
312 struct drm_crtc *crtc;
314 crtc_state = state->crtc_states[i];
315 crtc = state->crtcs[i];
317 if (!crtc_state || !crtc_state->mode_changed)
320 funcs = crtc->helper_private;
321 ret = funcs->mode_fixup(crtc, &crtc_state->mode,
322 &crtc_state->adjusted_mode);
324 DRM_DEBUG_KMS("[CRTC:%d] fixup failed\n",
334 drm_atomic_helper_check_modeset(struct drm_device *dev,
335 struct drm_atomic_state *state)
337 int ncrtcs = dev->mode_config.num_crtc;
338 struct drm_crtc *crtc;
339 struct drm_crtc_state *crtc_state;
342 for (i = 0; i < ncrtcs; i++) {
343 crtc = state->crtcs[i];
344 crtc_state = state->crtc_states[i];
349 if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) {
350 DRM_DEBUG_KMS("[CRTC:%d] mode changed\n",
352 crtc_state->mode_changed = true;
355 if (crtc->state->enable != crtc_state->enable) {
356 DRM_DEBUG_KMS("[CRTC:%d] enable changed\n",
358 crtc_state->mode_changed = true;
362 for (i = 0; i < state->num_connector; i++) {
364 * This only sets crtc->mode_changed for routing changes,
365 * drivers must set crtc->mode_changed themselves when connector
366 * properties need to be updated.
368 ret = update_connector_routing(state, i);
374 * After all the routing has been prepared we need to add in any
375 * connector which is itself unchanged, but who's crtc changes it's
376 * configuration. This must be done before calling mode_fixup in case a
377 * crtc only changed its mode but has the same set of connectors.
379 for (i = 0; i < ncrtcs; i++) {
382 crtc = state->crtcs[i];
383 crtc_state = state->crtc_states[i];
385 if (!crtc || !crtc_state->mode_changed)
388 DRM_DEBUG_KMS("[CRTC:%d] needs full modeset, enable: %c\n",
390 crtc_state->enable ? 'y' : 'n');
392 ret = drm_atomic_add_affected_connectors(state, crtc);
396 num_connectors = drm_atomic_connectors_for_crtc(state,
399 if (crtc_state->enable != !!num_connectors) {
400 DRM_DEBUG_KMS("[CRTC:%d] enabled/connectors mismatch\n",
407 return mode_fixup(state);
411 * drm_atomic_helper_check - validate state object
413 * @state: the driver state object
415 * Check the state object to see if the requested state is physically possible.
416 * Only crtcs and planes have check callbacks, so for any additional (global)
417 * checking that a driver needs it can simply wrap that around this function.
418 * Drivers without such needs can directly use this as their ->atomic_check()
422 * Zero for success or -errno
424 int drm_atomic_helper_check(struct drm_device *dev,
425 struct drm_atomic_state *state)
427 int nplanes = dev->mode_config.num_total_plane;
428 int ncrtcs = dev->mode_config.num_crtc;
431 for (i = 0; i < nplanes; i++) {
432 struct drm_plane_helper_funcs *funcs;
433 struct drm_plane *plane = state->planes[i];
434 struct drm_plane_state *plane_state = state->plane_states[i];
439 funcs = plane->helper_private;
441 drm_atomic_helper_plane_changed(state, plane_state, plane);
443 if (!funcs || !funcs->atomic_check)
446 ret = funcs->atomic_check(plane, plane_state);
448 DRM_DEBUG_KMS("[PLANE:%d] atomic check failed\n",
454 for (i = 0; i < ncrtcs; i++) {
455 struct drm_crtc_helper_funcs *funcs;
456 struct drm_crtc *crtc = state->crtcs[i];
461 funcs = crtc->helper_private;
463 if (!funcs || !funcs->atomic_check)
466 ret = funcs->atomic_check(crtc, state->crtc_states[i]);
468 DRM_DEBUG_KMS("[CRTC:%d] atomic check failed\n",
474 ret = drm_atomic_helper_check_modeset(dev, state);
480 EXPORT_SYMBOL(drm_atomic_helper_check);
483 disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
485 int ncrtcs = old_state->dev->mode_config.num_crtc;
488 for (i = 0; i < old_state->num_connector; i++) {
489 struct drm_connector_state *old_conn_state;
490 struct drm_connector *connector;
491 struct drm_encoder_helper_funcs *funcs;
492 struct drm_encoder *encoder;
494 old_conn_state = old_state->connector_states[i];
495 connector = old_state->connectors[i];
497 /* Shut down everything that's in the changeset and currently
498 * still on. So need to check the old, saved state. */
499 if (!old_conn_state || !old_conn_state->crtc)
502 encoder = old_conn_state->best_encoder;
504 /* We shouldn't get this far if we didn't previously have
505 * an encoder.. but WARN_ON() rather than explode.
507 if (WARN_ON(!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 ncrtcs = old_state->dev->mode_config.num_crtc;
559 /* clear out existing links */
560 for (i = 0; i < old_state->num_connector; i++) {
561 struct drm_connector *connector;
563 connector = old_state->connectors[i];
565 if (!connector || !connector->encoder)
568 WARN_ON(!connector->encoder->crtc);
570 connector->encoder->crtc = NULL;
571 connector->encoder = NULL;
575 for (i = 0; i < old_state->num_connector; i++) {
576 struct drm_connector *connector;
578 connector = old_state->connectors[i];
580 if (!connector || !connector->state->crtc)
583 if (WARN_ON(!connector->state->best_encoder))
586 connector->encoder = connector->state->best_encoder;
587 connector->encoder->crtc = connector->state->crtc;
590 /* set legacy state in the crtc structure */
591 for (i = 0; i < ncrtcs; i++) {
592 struct drm_crtc *crtc;
594 crtc = old_state->crtcs[i];
599 crtc->mode = crtc->state->mode;
600 crtc->enabled = crtc->state->enable;
601 crtc->x = crtc->primary->state->src_x >> 16;
602 crtc->y = crtc->primary->state->src_y >> 16;
607 crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
609 int ncrtcs = old_state->dev->mode_config.num_crtc;
612 for (i = 0; i < ncrtcs; i++) {
613 struct drm_crtc_helper_funcs *funcs;
614 struct drm_crtc *crtc;
616 crtc = old_state->crtcs[i];
618 if (!crtc || !crtc->state->mode_changed)
621 funcs = crtc->helper_private;
623 if (crtc->state->enable)
624 funcs->mode_set_nofb(crtc);
627 for (i = 0; i < old_state->num_connector; i++) {
628 struct drm_connector *connector;
629 struct drm_crtc_state *new_crtc_state;
630 struct drm_encoder_helper_funcs *funcs;
631 struct drm_encoder *encoder;
632 struct drm_display_mode *mode, *adjusted_mode;
634 connector = old_state->connectors[i];
636 if (!connector || !connector->state->best_encoder)
639 encoder = connector->state->best_encoder;
640 funcs = encoder->helper_private;
641 new_crtc_state = connector->state->crtc->state;
642 mode = &new_crtc_state->mode;
643 adjusted_mode = &new_crtc_state->adjusted_mode;
646 * Each encoder has at most one connector (since we always steal
647 * it away), so we won't call call mode_set hooks twice.
649 funcs->mode_set(encoder, mode, adjusted_mode);
651 if (encoder->bridge && encoder->bridge->funcs->mode_set)
652 encoder->bridge->funcs->mode_set(encoder->bridge,
653 mode, adjusted_mode);
658 * drm_atomic_helper_commit_pre_planes - modeset commit before plane updates
660 * @state: atomic state
662 * This function commits the modeset changes that need to be committed before
663 * updating planes. It shuts down all the outputs that need to be shut down and
664 * prepares them (if required) with the new mode.
666 void drm_atomic_helper_commit_pre_planes(struct drm_device *dev,
667 struct drm_atomic_state *state)
669 disable_outputs(dev, state);
670 set_routing_links(dev, state);
671 crtc_set_mode(dev, state);
673 EXPORT_SYMBOL(drm_atomic_helper_commit_pre_planes);
676 * drm_atomic_helper_commit_post_planes - modeset commit after plane updates
678 * @old_state: atomic state object with old state structures
680 * This function commits the modeset changes that need to be committed after
681 * updating planes: It enables all the outputs with the new configuration which
682 * had to be turned off for the update.
684 void drm_atomic_helper_commit_post_planes(struct drm_device *dev,
685 struct drm_atomic_state *old_state)
687 int ncrtcs = old_state->dev->mode_config.num_crtc;
690 for (i = 0; i < ncrtcs; i++) {
691 struct drm_crtc_helper_funcs *funcs;
692 struct drm_crtc *crtc;
694 crtc = old_state->crtcs[i];
696 /* Need to filter out CRTCs where only planes change. */
697 if (!crtc || !crtc->state->mode_changed)
700 funcs = crtc->helper_private;
702 if (crtc->state->enable)
706 for (i = 0; i < old_state->num_connector; i++) {
707 struct drm_connector *connector;
708 struct drm_encoder_helper_funcs *funcs;
709 struct drm_encoder *encoder;
711 connector = old_state->connectors[i];
713 if (!connector || !connector->state->best_encoder)
716 encoder = connector->state->best_encoder;
717 funcs = encoder->helper_private;
720 * Each encoder has at most one connector (since we always steal
721 * it away), so we won't call call enable hooks twice.
724 encoder->bridge->funcs->pre_enable(encoder->bridge);
726 funcs->commit(encoder);
729 encoder->bridge->funcs->enable(encoder->bridge);
732 EXPORT_SYMBOL(drm_atomic_helper_commit_post_planes);
734 static void wait_for_fences(struct drm_device *dev,
735 struct drm_atomic_state *state)
737 int nplanes = dev->mode_config.num_total_plane;
740 for (i = 0; i < nplanes; i++) {
741 struct drm_plane *plane = state->planes[i];
743 if (!plane || !plane->state->fence)
746 WARN_ON(!plane->state->fb);
748 fence_wait(plane->state->fence, false);
749 fence_put(plane->state->fence);
750 plane->state->fence = NULL;
754 static bool framebuffer_changed(struct drm_device *dev,
755 struct drm_atomic_state *old_state,
756 struct drm_crtc *crtc)
758 struct drm_plane *plane;
759 struct drm_plane_state *old_plane_state;
760 int nplanes = old_state->dev->mode_config.num_total_plane;
763 for (i = 0; i < nplanes; i++) {
764 plane = old_state->planes[i];
765 old_plane_state = old_state->plane_states[i];
770 if (plane->state->crtc != crtc &&
771 old_plane_state->crtc != crtc)
774 if (plane->state->fb != old_plane_state->fb)
782 * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs
784 * @old_state: atomic state object with old state structures
786 * Helper to, after atomic commit, wait for vblanks on all effected
787 * crtcs (ie. before cleaning up old framebuffers using
788 * drm_atomic_helper_cleanup_planes()). It will only wait on crtcs where the
789 * framebuffers have actually changed to optimize for the legacy cursor and
790 * plane update use-case.
793 drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
794 struct drm_atomic_state *old_state)
796 struct drm_crtc *crtc;
797 struct drm_crtc_state *old_crtc_state;
798 int ncrtcs = old_state->dev->mode_config.num_crtc;
801 for (i = 0; i < ncrtcs; i++) {
802 crtc = old_state->crtcs[i];
803 old_crtc_state = old_state->crtc_states[i];
808 /* No one cares about the old state, so abuse it for tracking
809 * and store whether we hold a vblank reference (and should do a
810 * vblank wait) in the ->enable boolean. */
811 old_crtc_state->enable = false;
813 if (!crtc->state->enable)
816 if (!framebuffer_changed(dev, old_state, crtc))
819 ret = drm_crtc_vblank_get(crtc);
823 old_crtc_state->enable = true;
824 old_crtc_state->last_vblank_count = drm_vblank_count(dev, i);
827 for (i = 0; i < ncrtcs; i++) {
828 crtc = old_state->crtcs[i];
829 old_crtc_state = old_state->crtc_states[i];
831 if (!crtc || !old_crtc_state->enable)
834 ret = wait_event_timeout(dev->vblank[i].queue,
835 old_crtc_state->last_vblank_count !=
836 drm_vblank_count(dev, i),
837 msecs_to_jiffies(50));
839 drm_crtc_vblank_put(crtc);
842 EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks);
845 * drm_atomic_helper_commit - commit validated state object
847 * @state: the driver state object
848 * @async: asynchronous commit
850 * This function commits a with drm_atomic_helper_check() pre-validated state
851 * object. This can still fail when e.g. the framebuffer reservation fails. For
852 * now this doesn't implement asynchronous commits.
855 * Zero for success or -errno.
857 int drm_atomic_helper_commit(struct drm_device *dev,
858 struct drm_atomic_state *state,
866 ret = drm_atomic_helper_prepare_planes(dev, state);
871 * This is the point of no return - everything below never fails except
872 * when the hw goes bonghits. Which means we can commit the new state on
873 * the software side now.
876 drm_atomic_helper_swap_state(dev, state);
879 * Everything below can be run asynchronously without the need to grab
880 * any modeset locks at all under one conditions: It must be guaranteed
881 * that the asynchronous work has either been cancelled (if the driver
882 * supports it, which at least requires that the framebuffers get
883 * cleaned up with drm_atomic_helper_cleanup_planes()) or completed
884 * before the new state gets committed on the software side with
885 * drm_atomic_helper_swap_state().
887 * This scheme allows new atomic state updates to be prepared and
888 * checked in parallel to the asynchronous completion of the previous
889 * update. Which is important since compositors need to figure out the
890 * composition of the next frame right after having submitted the
894 wait_for_fences(dev, state);
896 drm_atomic_helper_commit_pre_planes(dev, state);
898 drm_atomic_helper_commit_planes(dev, state);
900 drm_atomic_helper_commit_post_planes(dev, state);
902 drm_atomic_helper_wait_for_vblanks(dev, state);
904 drm_atomic_helper_cleanup_planes(dev, state);
906 drm_atomic_state_free(state);
910 EXPORT_SYMBOL(drm_atomic_helper_commit);
913 * DOC: implementing async commit
915 * For now the atomic helpers don't support async commit directly. If there is
916 * real need it could be added though, using the dma-buf fence infrastructure
917 * for generic synchronization with outstanding rendering.
919 * For now drivers have to implement async commit themselves, with the following
920 * sequence being the recommended one:
922 * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function
923 * which commit needs to call which can fail, so we want to run it first and
926 * 2. Synchronize with any outstanding asynchronous commit worker threads which
927 * might be affected the new state update. This can be done by either cancelling
928 * or flushing the work items, depending upon whether the driver can deal with
929 * cancelled updates. Note that it is important to ensure that the framebuffer
930 * cleanup is still done when cancelling.
932 * For sufficient parallelism it is recommended to have a work item per crtc
933 * (for updates which don't touch global state) and a global one. Then we only
934 * need to synchronize with the crtc work items for changed crtcs and the global
935 * work item, which allows nice concurrent updates on disjoint sets of crtcs.
937 * 3. The software state is updated synchronously with
938 * drm_atomic_helper_swap_state. Doing this under the protection of all modeset
939 * locks means concurrent callers never see inconsistent state. And doing this
940 * while it's guaranteed that no relevant async worker runs means that async
941 * workers do not need grab any locks. Actually they must not grab locks, for
942 * otherwise the work flushing will deadlock.
944 * 4. Schedule a work item to do all subsequent steps, using the split-out
945 * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
946 * then cleaning up the framebuffers after the old framebuffer is no longer
951 * drm_atomic_helper_prepare_planes - prepare plane resources after commit
953 * @state: atomic state object with old state structures
955 * This function prepares plane state, specifically framebuffers, for the new
956 * configuration. If any failure is encountered this function will call
957 * ->cleanup_fb on any already successfully prepared framebuffer.
960 * 0 on success, negative error code on failure.
962 int drm_atomic_helper_prepare_planes(struct drm_device *dev,
963 struct drm_atomic_state *state)
965 int nplanes = dev->mode_config.num_total_plane;
968 for (i = 0; i < nplanes; i++) {
969 struct drm_plane_helper_funcs *funcs;
970 struct drm_plane *plane = state->planes[i];
971 struct drm_framebuffer *fb;
976 funcs = plane->helper_private;
978 fb = state->plane_states[i]->fb;
980 if (fb && funcs->prepare_fb) {
981 ret = funcs->prepare_fb(plane, fb);
990 for (i--; i >= 0; i--) {
991 struct drm_plane_helper_funcs *funcs;
992 struct drm_plane *plane = state->planes[i];
993 struct drm_framebuffer *fb;
998 funcs = plane->helper_private;
1000 fb = state->plane_states[i]->fb;
1002 if (fb && funcs->cleanup_fb)
1003 funcs->cleanup_fb(plane, fb);
1009 EXPORT_SYMBOL(drm_atomic_helper_prepare_planes);
1012 * drm_atomic_helper_commit_planes - commit plane state
1014 * @old_state: atomic state object with old state structures
1016 * This function commits the new plane state using the plane and atomic helper
1017 * functions for planes and crtcs. It assumes that the atomic state has already
1018 * been pushed into the relevant object state pointers, since this step can no
1021 * It still requires the global state object @old_state to know which planes and
1022 * crtcs need to be updated though.
1024 void drm_atomic_helper_commit_planes(struct drm_device *dev,
1025 struct drm_atomic_state *old_state)
1027 int nplanes = dev->mode_config.num_total_plane;
1028 int ncrtcs = dev->mode_config.num_crtc;
1031 for (i = 0; i < ncrtcs; i++) {
1032 struct drm_crtc_helper_funcs *funcs;
1033 struct drm_crtc *crtc = old_state->crtcs[i];
1038 funcs = crtc->helper_private;
1040 if (!funcs || !funcs->atomic_begin)
1043 funcs->atomic_begin(crtc);
1046 for (i = 0; i < nplanes; i++) {
1047 struct drm_plane_helper_funcs *funcs;
1048 struct drm_plane *plane = old_state->planes[i];
1053 funcs = plane->helper_private;
1055 if (!funcs || !funcs->atomic_update)
1058 funcs->atomic_update(plane);
1061 for (i = 0; i < ncrtcs; i++) {
1062 struct drm_crtc_helper_funcs *funcs;
1063 struct drm_crtc *crtc = old_state->crtcs[i];
1068 funcs = crtc->helper_private;
1070 if (!funcs || !funcs->atomic_flush)
1073 funcs->atomic_flush(crtc);
1076 EXPORT_SYMBOL(drm_atomic_helper_commit_planes);
1079 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit
1081 * @old_state: atomic state object with old state structures
1083 * This function cleans up plane state, specifically framebuffers, from the old
1084 * configuration. Hence the old configuration must be perserved in @old_state to
1085 * be able to call this function.
1087 * This function must also be called on the new state when the atomic update
1088 * fails at any point after calling drm_atomic_helper_prepare_planes().
1090 void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
1091 struct drm_atomic_state *old_state)
1093 int nplanes = dev->mode_config.num_total_plane;
1096 for (i = 0; i < nplanes; i++) {
1097 struct drm_plane_helper_funcs *funcs;
1098 struct drm_plane *plane = old_state->planes[i];
1099 struct drm_framebuffer *old_fb;
1104 funcs = plane->helper_private;
1106 old_fb = old_state->plane_states[i]->fb;
1108 if (old_fb && funcs->cleanup_fb)
1109 funcs->cleanup_fb(plane, old_fb);
1112 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
1115 * drm_atomic_helper_swap_state - store atomic state into current sw state
1117 * @state: atomic state
1119 * This function stores the atomic state into the current state pointers in all
1120 * driver objects. It should be called after all failing steps have been done
1121 * and succeeded, but before the actual hardware state is committed.
1123 * For cleanup and error recovery the current state for all changed objects will
1124 * be swaped into @state.
1126 * With that sequence it fits perfectly into the plane prepare/cleanup sequence:
1128 * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state.
1130 * 2. Do any other steps that might fail.
1132 * 3. Put the staged state into the current state pointers with this function.
1134 * 4. Actually commit the hardware state.
1136 * 5. Call drm_atomic_helper_cleanup_planes with @state, which since step 3
1137 * contains the old state. Also do any other cleanup required with that state.
1139 void drm_atomic_helper_swap_state(struct drm_device *dev,
1140 struct drm_atomic_state *state)
1144 for (i = 0; i < dev->mode_config.num_connector; i++) {
1145 struct drm_connector *connector = state->connectors[i];
1150 connector->state->state = state;
1151 swap(state->connector_states[i], connector->state);
1152 connector->state->state = NULL;
1155 for (i = 0; i < dev->mode_config.num_crtc; i++) {
1156 struct drm_crtc *crtc = state->crtcs[i];
1161 crtc->state->state = state;
1162 swap(state->crtc_states[i], crtc->state);
1163 crtc->state->state = NULL;
1166 for (i = 0; i < dev->mode_config.num_total_plane; i++) {
1167 struct drm_plane *plane = state->planes[i];
1172 plane->state->state = state;
1173 swap(state->plane_states[i], plane->state);
1174 plane->state->state = NULL;
1177 EXPORT_SYMBOL(drm_atomic_helper_swap_state);
1180 * drm_atomic_helper_update_plane - Helper for primary plane update using atomic
1181 * @plane: plane object to update
1182 * @crtc: owning CRTC of owning plane
1183 * @fb: framebuffer to flip onto plane
1184 * @crtc_x: x offset of primary plane on crtc
1185 * @crtc_y: y offset of primary plane on crtc
1186 * @crtc_w: width of primary plane rectangle on crtc
1187 * @crtc_h: height of primary plane rectangle on crtc
1188 * @src_x: x offset of @fb for panning
1189 * @src_y: y offset of @fb for panning
1190 * @src_w: width of source rectangle in @fb
1191 * @src_h: height of source rectangle in @fb
1193 * Provides a default plane update handler using the atomic driver interface.
1196 * Zero on success, error code on failure
1198 int drm_atomic_helper_update_plane(struct drm_plane *plane,
1199 struct drm_crtc *crtc,
1200 struct drm_framebuffer *fb,
1201 int crtc_x, int crtc_y,
1202 unsigned int crtc_w, unsigned int crtc_h,
1203 uint32_t src_x, uint32_t src_y,
1204 uint32_t src_w, uint32_t src_h)
1206 struct drm_atomic_state *state;
1207 struct drm_plane_state *plane_state;
1210 state = drm_atomic_state_alloc(plane->dev);
1214 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1216 plane_state = drm_atomic_get_plane_state(state, plane);
1217 if (IS_ERR(plane_state)) {
1218 ret = PTR_ERR(plane_state);
1222 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
1225 drm_atomic_set_fb_for_plane(plane_state, fb);
1226 plane_state->crtc_x = crtc_x;
1227 plane_state->crtc_y = crtc_y;
1228 plane_state->crtc_h = crtc_h;
1229 plane_state->crtc_w = crtc_w;
1230 plane_state->src_x = src_x;
1231 plane_state->src_y = src_y;
1232 plane_state->src_h = src_h;
1233 plane_state->src_w = src_w;
1235 ret = drm_atomic_commit(state);
1239 /* Driver takes ownership of state on successful commit. */
1242 if (ret == -EDEADLK)
1245 drm_atomic_state_free(state);
1249 drm_atomic_state_clear(state);
1250 drm_atomic_legacy_backoff(state);
1253 * Someone might have exchanged the framebuffer while we dropped locks
1254 * in the backoff code. We need to fix up the fb refcount tracking the
1257 plane->old_fb = plane->fb;
1261 EXPORT_SYMBOL(drm_atomic_helper_update_plane);
1264 * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic
1265 * @plane: plane to disable
1267 * Provides a default plane disable handler using the atomic driver interface.
1270 * Zero on success, error code on failure
1272 int drm_atomic_helper_disable_plane(struct drm_plane *plane)
1274 struct drm_atomic_state *state;
1275 struct drm_plane_state *plane_state;
1278 state = drm_atomic_state_alloc(plane->dev);
1282 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(plane->crtc);
1284 plane_state = drm_atomic_get_plane_state(state, plane);
1285 if (IS_ERR(plane_state)) {
1286 ret = PTR_ERR(plane_state);
1290 ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
1293 drm_atomic_set_fb_for_plane(plane_state, NULL);
1294 plane_state->crtc_x = 0;
1295 plane_state->crtc_y = 0;
1296 plane_state->crtc_h = 0;
1297 plane_state->crtc_w = 0;
1298 plane_state->src_x = 0;
1299 plane_state->src_y = 0;
1300 plane_state->src_h = 0;
1301 plane_state->src_w = 0;
1303 ret = drm_atomic_commit(state);
1307 /* Driver takes ownership of state on successful commit. */
1310 if (ret == -EDEADLK)
1313 drm_atomic_state_free(state);
1317 drm_atomic_state_clear(state);
1318 drm_atomic_legacy_backoff(state);
1321 * Someone might have exchanged the framebuffer while we dropped locks
1322 * in the backoff code. We need to fix up the fb refcount tracking the
1325 plane->old_fb = plane->fb;
1329 EXPORT_SYMBOL(drm_atomic_helper_disable_plane);
1331 static int update_output_state(struct drm_atomic_state *state,
1332 struct drm_mode_set *set)
1334 struct drm_device *dev = set->crtc->dev;
1335 struct drm_connector_state *conn_state;
1336 int ncrtcs = state->dev->mode_config.num_crtc;
1339 ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
1340 state->acquire_ctx);
1344 /* First grab all affected connector/crtc states. */
1345 for (i = 0; i < set->num_connectors; i++) {
1346 conn_state = drm_atomic_get_connector_state(state,
1347 set->connectors[i]);
1348 if (IS_ERR(conn_state))
1349 return PTR_ERR(conn_state);
1352 for (i = 0; i < ncrtcs; i++) {
1353 struct drm_crtc *crtc = state->crtcs[i];
1358 ret = drm_atomic_add_affected_connectors(state, crtc);
1363 /* Then recompute connector->crtc links and crtc enabling state. */
1364 for (i = 0; i < state->num_connector; i++) {
1365 struct drm_connector *connector;
1367 connector = state->connectors[i];
1368 conn_state = state->connector_states[i];
1373 if (conn_state->crtc == set->crtc) {
1374 ret = drm_atomic_set_crtc_for_connector(conn_state,
1380 for (j = 0; j < set->num_connectors; j++) {
1381 if (set->connectors[j] == connector) {
1382 ret = drm_atomic_set_crtc_for_connector(conn_state,
1391 for (i = 0; i < ncrtcs; i++) {
1392 struct drm_crtc *crtc = state->crtcs[i];
1393 struct drm_crtc_state *crtc_state = state->crtc_states[i];
1398 /* Don't update ->enable for the CRTC in the set_config request,
1399 * since a mismatch would indicate a bug in the upper layers.
1400 * The actual modeset code later on will catch any
1401 * inconsistencies here. */
1402 if (crtc == set->crtc)
1405 crtc_state->enable =
1406 drm_atomic_connectors_for_crtc(state, crtc);
1413 * drm_atomic_helper_set_config - set a new config from userspace
1414 * @set: mode set configuration
1416 * Provides a default crtc set_config handler using the atomic driver interface.
1419 * Returns 0 on success, negative errno numbers on failure.
1421 int drm_atomic_helper_set_config(struct drm_mode_set *set)
1423 struct drm_atomic_state *state;
1424 struct drm_crtc *crtc = set->crtc;
1425 struct drm_crtc_state *crtc_state;
1426 struct drm_plane_state *primary_state;
1429 state = drm_atomic_state_alloc(crtc->dev);
1433 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1435 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1436 if (IS_ERR(crtc_state)) {
1437 ret = PTR_ERR(crtc_state);
1443 WARN_ON(set->num_connectors);
1445 crtc_state->enable = false;
1450 WARN_ON(!set->num_connectors);
1452 crtc_state->enable = true;
1453 drm_mode_copy(&crtc_state->mode, set->mode);
1455 primary_state = drm_atomic_get_plane_state(state, crtc->primary);
1456 if (IS_ERR(primary_state)) {
1457 ret = PTR_ERR(primary_state);
1461 ret = drm_atomic_set_crtc_for_plane(primary_state, crtc);
1464 drm_atomic_set_fb_for_plane(primary_state, set->fb);
1465 primary_state->crtc_x = 0;
1466 primary_state->crtc_y = 0;
1467 primary_state->crtc_h = set->mode->vdisplay;
1468 primary_state->crtc_w = set->mode->hdisplay;
1469 primary_state->src_x = set->x << 16;
1470 primary_state->src_y = set->y << 16;
1471 primary_state->src_h = set->mode->vdisplay << 16;
1472 primary_state->src_w = set->mode->hdisplay << 16;
1475 ret = update_output_state(state, set);
1479 ret = drm_atomic_commit(state);
1483 /* Driver takes ownership of state on successful commit. */
1486 if (ret == -EDEADLK)
1489 drm_atomic_state_free(state);
1493 drm_atomic_state_clear(state);
1494 drm_atomic_legacy_backoff(state);
1497 * Someone might have exchanged the framebuffer while we dropped locks
1498 * in the backoff code. We need to fix up the fb refcount tracking the
1501 crtc->primary->old_fb = crtc->primary->fb;
1505 EXPORT_SYMBOL(drm_atomic_helper_set_config);
1508 * drm_atomic_helper_crtc_set_property - helper for crtc prorties
1510 * @property: DRM property
1511 * @val: value of property
1513 * Provides a default plane disablle handler using the atomic driver interface.
1516 * Zero on success, error code on failure
1519 drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
1520 struct drm_property *property,
1523 struct drm_atomic_state *state;
1524 struct drm_crtc_state *crtc_state;
1527 state = drm_atomic_state_alloc(crtc->dev);
1531 /* ->set_property is always called with all locks held. */
1532 state->acquire_ctx = crtc->dev->mode_config.acquire_ctx;
1534 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1535 if (IS_ERR(crtc_state)) {
1536 ret = PTR_ERR(crtc_state);
1540 ret = crtc->funcs->atomic_set_property(crtc, crtc_state,
1545 ret = drm_atomic_commit(state);
1549 /* Driver takes ownership of state on successful commit. */
1552 if (ret == -EDEADLK)
1555 drm_atomic_state_free(state);
1559 drm_atomic_state_clear(state);
1560 drm_atomic_legacy_backoff(state);
1564 EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property);
1567 * drm_atomic_helper_plane_set_property - helper for plane prorties
1569 * @property: DRM property
1570 * @val: value of property
1572 * Provides a default plane disable handler using the atomic driver interface.
1575 * Zero on success, error code on failure
1578 drm_atomic_helper_plane_set_property(struct drm_plane *plane,
1579 struct drm_property *property,
1582 struct drm_atomic_state *state;
1583 struct drm_plane_state *plane_state;
1586 state = drm_atomic_state_alloc(plane->dev);
1590 /* ->set_property is always called with all locks held. */
1591 state->acquire_ctx = plane->dev->mode_config.acquire_ctx;
1593 plane_state = drm_atomic_get_plane_state(state, plane);
1594 if (IS_ERR(plane_state)) {
1595 ret = PTR_ERR(plane_state);
1599 ret = plane->funcs->atomic_set_property(plane, plane_state,
1604 ret = drm_atomic_commit(state);
1608 /* Driver takes ownership of state on successful commit. */
1611 if (ret == -EDEADLK)
1614 drm_atomic_state_free(state);
1618 drm_atomic_state_clear(state);
1619 drm_atomic_legacy_backoff(state);
1623 EXPORT_SYMBOL(drm_atomic_helper_plane_set_property);
1626 * drm_atomic_helper_connector_set_property - helper for connector prorties
1627 * @connector: DRM connector
1628 * @property: DRM property
1629 * @val: value of property
1631 * Provides a default plane disablle handler using the atomic driver interface.
1634 * Zero on success, error code on failure
1637 drm_atomic_helper_connector_set_property(struct drm_connector *connector,
1638 struct drm_property *property,
1641 struct drm_atomic_state *state;
1642 struct drm_connector_state *connector_state;
1645 state = drm_atomic_state_alloc(connector->dev);
1649 /* ->set_property is always called with all locks held. */
1650 state->acquire_ctx = connector->dev->mode_config.acquire_ctx;
1652 connector_state = drm_atomic_get_connector_state(state, connector);
1653 if (IS_ERR(connector_state)) {
1654 ret = PTR_ERR(connector_state);
1658 ret = connector->funcs->atomic_set_property(connector, connector_state,
1663 ret = drm_atomic_commit(state);
1667 /* Driver takes ownership of state on successful commit. */
1670 if (ret == -EDEADLK)
1673 drm_atomic_state_free(state);
1677 drm_atomic_state_clear(state);
1678 drm_atomic_legacy_backoff(state);
1682 EXPORT_SYMBOL(drm_atomic_helper_connector_set_property);
1685 * drm_atomic_helper_page_flip - execute a legacy page flip
1687 * @fb: DRM framebuffer
1688 * @event: optional DRM event to signal upon completion
1689 * @flags: flip flags for non-vblank sync'ed updates
1691 * Provides a default page flip implementation using the atomic driver interface.
1693 * Note that for now so called async page flips (i.e. updates which are not
1694 * synchronized to vblank) are not supported, since the atomic interfaces have
1695 * no provisions for this yet.
1698 * Returns 0 on success, negative errno numbers on failure.
1700 int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
1701 struct drm_framebuffer *fb,
1702 struct drm_pending_vblank_event *event,
1705 struct drm_plane *plane = crtc->primary;
1706 struct drm_atomic_state *state;
1707 struct drm_plane_state *plane_state;
1708 struct drm_crtc_state *crtc_state;
1711 if (flags & DRM_MODE_PAGE_FLIP_ASYNC)
1714 state = drm_atomic_state_alloc(plane->dev);
1718 state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc);
1720 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1721 if (IS_ERR(crtc_state)) {
1722 ret = PTR_ERR(crtc_state);
1725 crtc_state->event = event;
1727 plane_state = drm_atomic_get_plane_state(state, plane);
1728 if (IS_ERR(plane_state)) {
1729 ret = PTR_ERR(plane_state);
1733 ret = drm_atomic_set_crtc_for_plane(plane_state, crtc);
1736 drm_atomic_set_fb_for_plane(plane_state, fb);
1738 ret = drm_atomic_async_commit(state);
1742 /* TODO: ->page_flip is the only driver callback where the core
1743 * doesn't update plane->fb. For now patch it up here. */
1744 plane->fb = plane->state->fb;
1746 /* Driver takes ownership of state on successful async commit. */
1749 if (ret == -EDEADLK)
1752 drm_atomic_state_free(state);
1756 drm_atomic_state_clear(state);
1757 drm_atomic_legacy_backoff(state);
1760 * Someone might have exchanged the framebuffer while we dropped locks
1761 * in the backoff code. We need to fix up the fb refcount tracking the
1764 plane->old_fb = plane->fb;
1768 EXPORT_SYMBOL(drm_atomic_helper_page_flip);
1771 * DOC: atomic state reset and initialization
1773 * Both the drm core and the atomic helpers assume that there is always the full
1774 * and correct atomic software state for all connectors, CRTCs and planes
1775 * available. Which is a bit a problem on driver load and also after system
1776 * suspend. One way to solve this is to have a hardware state read-out
1777 * infrastructure which reconstructs the full software state (e.g. the i915
1780 * The simpler solution is to just reset the software state to everything off,
1781 * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
1782 * the atomic helpers provide default reset implementations for all hooks.
1786 * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs
1789 * Resets the atomic state for @crtc by freeing the state pointer (which might
1790 * be NULL, e.g. at driver load time) and allocating a new empty state object.
1792 void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
1795 crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
1797 EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
1800 * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
1803 * Default CRTC state duplicate hook for drivers which don't have their own
1804 * subclassed CRTC state structure.
1806 struct drm_crtc_state *
1807 drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
1809 struct drm_crtc_state *state;
1811 if (WARN_ON(!crtc->state))
1814 state = kmemdup(crtc->state, sizeof(*crtc->state), GFP_KERNEL);
1817 state->mode_changed = false;
1818 state->planes_changed = false;
1819 state->event = NULL;
1824 EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
1827 * drm_atomic_helper_crtc_destroy_state - default state destroy hook
1829 * @state: CRTC state object to release
1831 * Default CRTC state destroy hook for drivers which don't have their own
1832 * subclassed CRTC state structure.
1834 void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
1835 struct drm_crtc_state *state)
1839 EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
1842 * drm_atomic_helper_plane_reset - default ->reset hook for planes
1845 * Resets the atomic state for @plane by freeing the state pointer (which might
1846 * be NULL, e.g. at driver load time) and allocating a new empty state object.
1848 void drm_atomic_helper_plane_reset(struct drm_plane *plane)
1850 if (plane->state && plane->state->fb)
1851 drm_framebuffer_unreference(plane->state->fb);
1853 kfree(plane->state);
1854 plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
1856 EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
1859 * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
1862 * Default plane state duplicate hook for drivers which don't have their own
1863 * subclassed plane state structure.
1865 struct drm_plane_state *
1866 drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
1868 struct drm_plane_state *state;
1870 if (WARN_ON(!plane->state))
1873 state = kmemdup(plane->state, sizeof(*plane->state), GFP_KERNEL);
1875 if (state && state->fb)
1876 drm_framebuffer_reference(state->fb);
1880 EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
1883 * drm_atomic_helper_plane_destroy_state - default state destroy hook
1885 * @state: plane state object to release
1887 * Default plane state destroy hook for drivers which don't have their own
1888 * subclassed plane state structure.
1890 void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
1891 struct drm_plane_state *state)
1894 drm_framebuffer_unreference(state->fb);
1898 EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
1901 * drm_atomic_helper_connector_reset - default ->reset hook for connectors
1902 * @connector: drm connector
1904 * Resets the atomic state for @connector by freeing the state pointer (which
1905 * might be NULL, e.g. at driver load time) and allocating a new empty state
1908 void drm_atomic_helper_connector_reset(struct drm_connector *connector)
1910 kfree(connector->state);
1911 connector->state = kzalloc(sizeof(*connector->state), GFP_KERNEL);
1913 EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
1916 * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
1917 * @connector: drm connector
1919 * Default connector state duplicate hook for drivers which don't have their own
1920 * subclassed connector state structure.
1922 struct drm_connector_state *
1923 drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
1925 if (WARN_ON(!connector->state))
1928 return kmemdup(connector->state, sizeof(*connector->state), GFP_KERNEL);
1930 EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
1933 * drm_atomic_helper_connector_destroy_state - default state destroy hook
1934 * @connector: drm connector
1935 * @state: connector state object to release
1937 * Default connector state destroy hook for drivers which don't have their own
1938 * subclassed connector state structure.
1940 void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
1941 struct drm_connector_state *state)
1945 EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);