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>
30 #include <drm/drm_atomic.h>
31 #include <drm/drm_mode.h>
32 #include <drm/drm_print.h>
33 #include <linux/sync_file.h>
35 #include "drm_crtc_internal.h"
37 void __drm_crtc_commit_free(struct kref *kref)
39 struct drm_crtc_commit *commit =
40 container_of(kref, struct drm_crtc_commit, ref);
44 EXPORT_SYMBOL(__drm_crtc_commit_free);
47 * drm_atomic_state_default_release -
48 * release memory initialized by drm_atomic_state_init
49 * @state: atomic state
51 * Free all the memory allocated by drm_atomic_state_init.
52 * This is useful for drivers that subclass the atomic state.
54 void drm_atomic_state_default_release(struct drm_atomic_state *state)
56 kfree(state->connectors);
59 kfree(state->private_objs);
61 EXPORT_SYMBOL(drm_atomic_state_default_release);
64 * drm_atomic_state_init - init new atomic state
66 * @state: atomic state
68 * Default implementation for filling in a new atomic state.
69 * This is useful for drivers that subclass the atomic state.
72 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
74 kref_init(&state->ref);
76 /* TODO legacy paths should maybe do a better job about
77 * setting this appropriately?
79 state->allow_modeset = true;
81 state->crtcs = kcalloc(dev->mode_config.num_crtc,
82 sizeof(*state->crtcs), GFP_KERNEL);
85 state->planes = kcalloc(dev->mode_config.num_total_plane,
86 sizeof(*state->planes), GFP_KERNEL);
92 DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
96 drm_atomic_state_default_release(state);
99 EXPORT_SYMBOL(drm_atomic_state_init);
102 * drm_atomic_state_alloc - allocate atomic state
105 * This allocates an empty atomic state to track updates.
107 struct drm_atomic_state *
108 drm_atomic_state_alloc(struct drm_device *dev)
110 struct drm_mode_config *config = &dev->mode_config;
112 if (!config->funcs->atomic_state_alloc) {
113 struct drm_atomic_state *state;
115 state = kzalloc(sizeof(*state), GFP_KERNEL);
118 if (drm_atomic_state_init(dev, state) < 0) {
125 return config->funcs->atomic_state_alloc(dev);
127 EXPORT_SYMBOL(drm_atomic_state_alloc);
130 * drm_atomic_state_default_clear - clear base atomic state
131 * @state: atomic state
133 * Default implementation for clearing atomic state.
134 * This is useful for drivers that subclass the atomic state.
136 void drm_atomic_state_default_clear(struct drm_atomic_state *state)
138 struct drm_device *dev = state->dev;
139 struct drm_mode_config *config = &dev->mode_config;
142 DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
144 for (i = 0; i < state->num_connector; i++) {
145 struct drm_connector *connector = state->connectors[i].ptr;
150 connector->funcs->atomic_destroy_state(connector,
151 state->connectors[i].state);
152 state->connectors[i].ptr = NULL;
153 state->connectors[i].state = NULL;
154 state->connectors[i].old_state = NULL;
155 state->connectors[i].new_state = NULL;
156 drm_connector_put(connector);
159 for (i = 0; i < config->num_crtc; i++) {
160 struct drm_crtc *crtc = state->crtcs[i].ptr;
165 crtc->funcs->atomic_destroy_state(crtc,
166 state->crtcs[i].state);
168 if (state->crtcs[i].commit) {
169 kfree(state->crtcs[i].commit->event);
170 state->crtcs[i].commit->event = NULL;
171 drm_crtc_commit_put(state->crtcs[i].commit);
174 state->crtcs[i].commit = NULL;
175 state->crtcs[i].ptr = NULL;
176 state->crtcs[i].state = NULL;
177 state->crtcs[i].old_state = NULL;
178 state->crtcs[i].new_state = NULL;
181 for (i = 0; i < config->num_total_plane; i++) {
182 struct drm_plane *plane = state->planes[i].ptr;
187 plane->funcs->atomic_destroy_state(plane,
188 state->planes[i].state);
189 state->planes[i].ptr = NULL;
190 state->planes[i].state = NULL;
191 state->planes[i].old_state = NULL;
192 state->planes[i].new_state = NULL;
195 for (i = 0; i < state->num_private_objs; i++) {
196 struct drm_private_obj *obj = state->private_objs[i].ptr;
201 obj->funcs->atomic_destroy_state(obj,
202 state->private_objs[i].state);
203 state->private_objs[i].ptr = NULL;
204 state->private_objs[i].state = NULL;
205 state->private_objs[i].old_state = NULL;
206 state->private_objs[i].new_state = NULL;
208 state->num_private_objs = 0;
211 EXPORT_SYMBOL(drm_atomic_state_default_clear);
214 * drm_atomic_state_clear - clear state object
215 * @state: atomic state
217 * When the w/w mutex algorithm detects a deadlock we need to back off and drop
218 * all locks. So someone else could sneak in and change the current modeset
219 * configuration. Which means that all the state assembled in @state is no
220 * longer an atomic update to the current state, but to some arbitrary earlier
221 * state. Which could break assumptions the driver's
222 * &drm_mode_config_funcs.atomic_check likely relies on.
224 * Hence we must clear all cached state and completely start over, using this
227 void drm_atomic_state_clear(struct drm_atomic_state *state)
229 struct drm_device *dev = state->dev;
230 struct drm_mode_config *config = &dev->mode_config;
232 if (config->funcs->atomic_state_clear)
233 config->funcs->atomic_state_clear(state);
235 drm_atomic_state_default_clear(state);
237 EXPORT_SYMBOL(drm_atomic_state_clear);
240 * __drm_atomic_state_free - free all memory for an atomic state
241 * @ref: This atomic state to deallocate
243 * This frees all memory associated with an atomic state, including all the
244 * per-object state for planes, crtcs and connectors.
246 void __drm_atomic_state_free(struct kref *ref)
248 struct drm_atomic_state *state = container_of(ref, typeof(*state), ref);
249 struct drm_mode_config *config = &state->dev->mode_config;
251 drm_atomic_state_clear(state);
253 DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
255 if (config->funcs->atomic_state_free) {
256 config->funcs->atomic_state_free(state);
258 drm_atomic_state_default_release(state);
262 EXPORT_SYMBOL(__drm_atomic_state_free);
265 * drm_atomic_get_crtc_state - get crtc state
266 * @state: global atomic state object
267 * @crtc: crtc to get state object for
269 * This function returns the crtc state for the given crtc, allocating it if
270 * needed. It will also grab the relevant crtc lock to make sure that the state
275 * Either the allocated state or the error code encoded into the pointer. When
276 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
277 * entire atomic sequence must be restarted. All other errors are fatal.
279 struct drm_crtc_state *
280 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
281 struct drm_crtc *crtc)
283 int ret, index = drm_crtc_index(crtc);
284 struct drm_crtc_state *crtc_state;
286 WARN_ON(!state->acquire_ctx);
288 crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
292 ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
296 crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
298 return ERR_PTR(-ENOMEM);
300 state->crtcs[index].state = crtc_state;
301 state->crtcs[index].old_state = crtc->state;
302 state->crtcs[index].new_state = crtc_state;
303 state->crtcs[index].ptr = crtc;
304 crtc_state->state = state;
306 DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
307 crtc->base.id, crtc->name, crtc_state, state);
311 EXPORT_SYMBOL(drm_atomic_get_crtc_state);
313 static void set_out_fence_for_crtc(struct drm_atomic_state *state,
314 struct drm_crtc *crtc, s32 __user *fence_ptr)
316 state->crtcs[drm_crtc_index(crtc)].out_fence_ptr = fence_ptr;
319 static s32 __user *get_out_fence_for_crtc(struct drm_atomic_state *state,
320 struct drm_crtc *crtc)
322 s32 __user *fence_ptr;
324 fence_ptr = state->crtcs[drm_crtc_index(crtc)].out_fence_ptr;
325 state->crtcs[drm_crtc_index(crtc)].out_fence_ptr = NULL;
331 * drm_atomic_set_mode_for_crtc - set mode for CRTC
332 * @state: the CRTC whose incoming state to update
333 * @mode: kernel-internal mode to use for the CRTC, or NULL to disable
335 * Set a mode (originating from the kernel) on the desired CRTC state and update
336 * the enable property.
339 * Zero on success, error code on failure. Cannot return -EDEADLK.
341 int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
342 const struct drm_display_mode *mode)
344 struct drm_mode_modeinfo umode;
346 /* Early return for no change. */
347 if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0)
350 drm_property_blob_put(state->mode_blob);
351 state->mode_blob = NULL;
354 drm_mode_convert_to_umode(&umode, mode);
356 drm_property_create_blob(state->crtc->dev,
359 if (IS_ERR(state->mode_blob))
360 return PTR_ERR(state->mode_blob);
362 drm_mode_copy(&state->mode, mode);
363 state->enable = true;
364 DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
367 memset(&state->mode, 0, sizeof(state->mode));
368 state->enable = false;
369 DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
375 EXPORT_SYMBOL(drm_atomic_set_mode_for_crtc);
378 * drm_atomic_set_mode_prop_for_crtc - set mode for CRTC
379 * @state: the CRTC whose incoming state to update
380 * @blob: pointer to blob property to use for mode
382 * Set a mode (originating from a blob property) on the desired CRTC state.
383 * This function will take a reference on the blob property for the CRTC state,
384 * and release the reference held on the state's existing mode property, if any
388 * Zero on success, error code on failure. Cannot return -EDEADLK.
390 int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
391 struct drm_property_blob *blob)
393 if (blob == state->mode_blob)
396 drm_property_blob_put(state->mode_blob);
397 state->mode_blob = NULL;
399 memset(&state->mode, 0, sizeof(state->mode));
402 if (blob->length != sizeof(struct drm_mode_modeinfo) ||
403 drm_mode_convert_umode(&state->mode,
404 (const struct drm_mode_modeinfo *)
408 state->mode_blob = drm_property_blob_get(blob);
409 state->enable = true;
410 DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
411 state->mode.name, state);
413 state->enable = false;
414 DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
420 EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc);
423 drm_atomic_replace_property_blob_from_id(struct drm_device *dev,
424 struct drm_property_blob **blob,
426 ssize_t expected_size,
429 struct drm_property_blob *new_blob = NULL;
432 new_blob = drm_property_lookup_blob(dev, blob_id);
433 if (new_blob == NULL)
436 if (expected_size > 0 && expected_size != new_blob->length) {
437 drm_property_blob_put(new_blob);
442 *replaced |= drm_property_replace_blob(blob, new_blob);
443 drm_property_blob_put(new_blob);
449 * drm_atomic_crtc_set_property - set property on CRTC
450 * @crtc: the drm CRTC to set a property on
451 * @state: the state object to update with the new property value
452 * @property: the property to set
453 * @val: the new property value
455 * This function handles generic/core properties and calls out to driver's
456 * &drm_crtc_funcs.atomic_set_property for driver properties. To ensure
457 * consistent behavior you must call this function rather than the driver hook
461 * Zero on success, error code on failure
463 int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
464 struct drm_crtc_state *state, struct drm_property *property,
467 struct drm_device *dev = crtc->dev;
468 struct drm_mode_config *config = &dev->mode_config;
469 bool replaced = false;
472 if (property == config->prop_active)
474 else if (property == config->prop_mode_id) {
475 struct drm_property_blob *mode =
476 drm_property_lookup_blob(dev, val);
477 ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
478 drm_property_blob_put(mode);
480 } else if (property == config->degamma_lut_property) {
481 ret = drm_atomic_replace_property_blob_from_id(dev,
486 state->color_mgmt_changed |= replaced;
488 } else if (property == config->ctm_property) {
489 ret = drm_atomic_replace_property_blob_from_id(dev,
492 sizeof(struct drm_color_ctm),
494 state->color_mgmt_changed |= replaced;
496 } else if (property == config->gamma_lut_property) {
497 ret = drm_atomic_replace_property_blob_from_id(dev,
502 state->color_mgmt_changed |= replaced;
504 } else if (property == config->prop_out_fence_ptr) {
505 s32 __user *fence_ptr = u64_to_user_ptr(val);
510 if (put_user(-1, fence_ptr))
513 set_out_fence_for_crtc(state->state, crtc, fence_ptr);
514 } else if (crtc->funcs->atomic_set_property)
515 return crtc->funcs->atomic_set_property(crtc, state, property, val);
521 EXPORT_SYMBOL(drm_atomic_crtc_set_property);
524 * drm_atomic_crtc_get_property - get property value from CRTC state
525 * @crtc: the drm CRTC to set a property on
526 * @state: the state object to get the property value from
527 * @property: the property to set
528 * @val: return location for the property value
530 * This function handles generic/core properties and calls out to driver's
531 * &drm_crtc_funcs.atomic_get_property for driver properties. To ensure
532 * consistent behavior you must call this function rather than the driver hook
536 * Zero on success, error code on failure
539 drm_atomic_crtc_get_property(struct drm_crtc *crtc,
540 const struct drm_crtc_state *state,
541 struct drm_property *property, uint64_t *val)
543 struct drm_device *dev = crtc->dev;
544 struct drm_mode_config *config = &dev->mode_config;
546 if (property == config->prop_active)
547 *val = state->active;
548 else if (property == config->prop_mode_id)
549 *val = (state->mode_blob) ? state->mode_blob->base.id : 0;
550 else if (property == config->degamma_lut_property)
551 *val = (state->degamma_lut) ? state->degamma_lut->base.id : 0;
552 else if (property == config->ctm_property)
553 *val = (state->ctm) ? state->ctm->base.id : 0;
554 else if (property == config->gamma_lut_property)
555 *val = (state->gamma_lut) ? state->gamma_lut->base.id : 0;
556 else if (property == config->prop_out_fence_ptr)
558 else if (crtc->funcs->atomic_get_property)
559 return crtc->funcs->atomic_get_property(crtc, state, property, val);
567 * drm_atomic_crtc_check - check crtc state
568 * @crtc: crtc to check
569 * @state: crtc state to check
571 * Provides core sanity checks for crtc state.
574 * Zero on success, error code on failure
576 static int drm_atomic_crtc_check(struct drm_crtc *crtc,
577 struct drm_crtc_state *state)
579 /* NOTE: we explicitly don't enforce constraints such as primary
580 * layer covering entire screen, since that is something we want
581 * to allow (on hw that supports it). For hw that does not, it
582 * should be checked in driver's crtc->atomic_check() vfunc.
584 * TODO: Add generic modeset state checks once we support those.
587 if (state->active && !state->enable) {
588 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active without enabled\n",
589 crtc->base.id, crtc->name);
593 /* The state->enable vs. state->mode_blob checks can be WARN_ON,
594 * as this is a kernel-internal detail that userspace should never
595 * be able to trigger. */
596 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
597 WARN_ON(state->enable && !state->mode_blob)) {
598 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled without mode blob\n",
599 crtc->base.id, crtc->name);
603 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
604 WARN_ON(!state->enable && state->mode_blob)) {
605 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled with mode blob\n",
606 crtc->base.id, crtc->name);
611 * Reject event generation for when a CRTC is off and stays off.
612 * It wouldn't be hard to implement this, but userspace has a track
613 * record of happily burning through 100% cpu (or worse, crash) when the
614 * display pipe is suspended. To avoid all that fun just reject updates
615 * that ask for events since likely that indicates a bug in the
616 * compositor's drawing loop. This is consistent with the vblank IOCTL
617 * and legacy page_flip IOCTL which also reject service on a disabled
620 if (state->event && !state->active && !crtc->state->active) {
621 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requesting event but off\n",
622 crtc->base.id, crtc->name);
629 static void drm_atomic_crtc_print_state(struct drm_printer *p,
630 const struct drm_crtc_state *state)
632 struct drm_crtc *crtc = state->crtc;
634 drm_printf(p, "crtc[%u]: %s\n", crtc->base.id, crtc->name);
635 drm_printf(p, "\tenable=%d\n", state->enable);
636 drm_printf(p, "\tactive=%d\n", state->active);
637 drm_printf(p, "\tplanes_changed=%d\n", state->planes_changed);
638 drm_printf(p, "\tmode_changed=%d\n", state->mode_changed);
639 drm_printf(p, "\tactive_changed=%d\n", state->active_changed);
640 drm_printf(p, "\tconnectors_changed=%d\n", state->connectors_changed);
641 drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed);
642 drm_printf(p, "\tplane_mask=%x\n", state->plane_mask);
643 drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask);
644 drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask);
645 drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode));
647 if (crtc->funcs->atomic_print_state)
648 crtc->funcs->atomic_print_state(p, state);
652 * drm_atomic_get_plane_state - get plane state
653 * @state: global atomic state object
654 * @plane: plane to get state object for
656 * This function returns the plane state for the given plane, allocating it if
657 * needed. It will also grab the relevant plane lock to make sure that the state
662 * Either the allocated state or the error code encoded into the pointer. When
663 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
664 * entire atomic sequence must be restarted. All other errors are fatal.
666 struct drm_plane_state *
667 drm_atomic_get_plane_state(struct drm_atomic_state *state,
668 struct drm_plane *plane)
670 int ret, index = drm_plane_index(plane);
671 struct drm_plane_state *plane_state;
673 WARN_ON(!state->acquire_ctx);
675 plane_state = drm_atomic_get_existing_plane_state(state, plane);
679 ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
683 plane_state = plane->funcs->atomic_duplicate_state(plane);
685 return ERR_PTR(-ENOMEM);
687 state->planes[index].state = plane_state;
688 state->planes[index].ptr = plane;
689 state->planes[index].old_state = plane->state;
690 state->planes[index].new_state = plane_state;
691 plane_state->state = state;
693 DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
694 plane->base.id, plane->name, plane_state, state);
696 if (plane_state->crtc) {
697 struct drm_crtc_state *crtc_state;
699 crtc_state = drm_atomic_get_crtc_state(state,
701 if (IS_ERR(crtc_state))
702 return ERR_CAST(crtc_state);
707 EXPORT_SYMBOL(drm_atomic_get_plane_state);
710 * drm_atomic_plane_set_property - set property on plane
711 * @plane: the drm plane to set a property on
712 * @state: the state object to update with the new property value
713 * @property: the property to set
714 * @val: the new property value
716 * This function handles generic/core properties and calls out to driver's
717 * &drm_plane_funcs.atomic_set_property for driver properties. To ensure
718 * consistent behavior you must call this function rather than the driver hook
722 * Zero on success, error code on failure
724 static int drm_atomic_plane_set_property(struct drm_plane *plane,
725 struct drm_plane_state *state, struct drm_property *property,
728 struct drm_device *dev = plane->dev;
729 struct drm_mode_config *config = &dev->mode_config;
731 if (property == config->prop_fb_id) {
732 struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val);
733 drm_atomic_set_fb_for_plane(state, fb);
735 drm_framebuffer_put(fb);
736 } else if (property == config->prop_in_fence_fd) {
740 if (U642I64(val) == -1)
743 state->fence = sync_file_get_fence(val);
747 } else if (property == config->prop_crtc_id) {
748 struct drm_crtc *crtc = drm_crtc_find(dev, val);
749 return drm_atomic_set_crtc_for_plane(state, crtc);
750 } else if (property == config->prop_crtc_x) {
751 state->crtc_x = U642I64(val);
752 } else if (property == config->prop_crtc_y) {
753 state->crtc_y = U642I64(val);
754 } else if (property == config->prop_crtc_w) {
756 } else if (property == config->prop_crtc_h) {
758 } else if (property == config->prop_src_x) {
760 } else if (property == config->prop_src_y) {
762 } else if (property == config->prop_src_w) {
764 } else if (property == config->prop_src_h) {
766 } else if (property == plane->rotation_property) {
767 if (!is_power_of_2(val & DRM_MODE_ROTATE_MASK))
769 state->rotation = val;
770 } else if (property == plane->zpos_property) {
772 } else if (plane->funcs->atomic_set_property) {
773 return plane->funcs->atomic_set_property(plane, state,
783 * drm_atomic_plane_get_property - get property value from plane state
784 * @plane: the drm plane to set a property on
785 * @state: the state object to get the property value from
786 * @property: the property to set
787 * @val: return location for the property value
789 * This function handles generic/core properties and calls out to driver's
790 * &drm_plane_funcs.atomic_get_property for driver properties. To ensure
791 * consistent behavior you must call this function rather than the driver hook
795 * Zero on success, error code on failure
798 drm_atomic_plane_get_property(struct drm_plane *plane,
799 const struct drm_plane_state *state,
800 struct drm_property *property, uint64_t *val)
802 struct drm_device *dev = plane->dev;
803 struct drm_mode_config *config = &dev->mode_config;
805 if (property == config->prop_fb_id) {
806 *val = (state->fb) ? state->fb->base.id : 0;
807 } else if (property == config->prop_in_fence_fd) {
809 } else if (property == config->prop_crtc_id) {
810 *val = (state->crtc) ? state->crtc->base.id : 0;
811 } else if (property == config->prop_crtc_x) {
812 *val = I642U64(state->crtc_x);
813 } else if (property == config->prop_crtc_y) {
814 *val = I642U64(state->crtc_y);
815 } else if (property == config->prop_crtc_w) {
816 *val = state->crtc_w;
817 } else if (property == config->prop_crtc_h) {
818 *val = state->crtc_h;
819 } else if (property == config->prop_src_x) {
821 } else if (property == config->prop_src_y) {
823 } else if (property == config->prop_src_w) {
825 } else if (property == config->prop_src_h) {
827 } else if (property == plane->rotation_property) {
828 *val = state->rotation;
829 } else if (property == plane->zpos_property) {
831 } else if (plane->funcs->atomic_get_property) {
832 return plane->funcs->atomic_get_property(plane, state, property, val);
841 plane_switching_crtc(struct drm_atomic_state *state,
842 struct drm_plane *plane,
843 struct drm_plane_state *plane_state)
845 if (!plane->state->crtc || !plane_state->crtc)
848 if (plane->state->crtc == plane_state->crtc)
851 /* This could be refined, but currently there's no helper or driver code
852 * to implement direct switching of active planes nor userspace to take
853 * advantage of more direct plane switching without the intermediate
860 * drm_atomic_plane_check - check plane state
861 * @plane: plane to check
862 * @state: plane state to check
864 * Provides core sanity checks for plane state.
867 * Zero on success, error code on failure
869 static int drm_atomic_plane_check(struct drm_plane *plane,
870 struct drm_plane_state *state)
872 unsigned int fb_width, fb_height;
875 /* either *both* CRTC and FB must be set, or neither */
876 if (WARN_ON(state->crtc && !state->fb)) {
877 DRM_DEBUG_ATOMIC("CRTC set but no FB\n");
879 } else if (WARN_ON(state->fb && !state->crtc)) {
880 DRM_DEBUG_ATOMIC("FB set but no CRTC\n");
884 /* if disabled, we don't care about the rest of the state: */
888 /* Check whether this plane is usable on this CRTC */
889 if (!(plane->possible_crtcs & drm_crtc_mask(state->crtc))) {
890 DRM_DEBUG_ATOMIC("Invalid crtc for plane\n");
894 /* Check whether this plane supports the fb pixel format. */
895 ret = drm_plane_check_pixel_format(plane, state->fb->format->format);
897 struct drm_format_name_buf format_name;
898 DRM_DEBUG_ATOMIC("Invalid pixel format %s\n",
899 drm_get_format_name(state->fb->format->format,
904 /* Give drivers some help against integer overflows */
905 if (state->crtc_w > INT_MAX ||
906 state->crtc_x > INT_MAX - (int32_t) state->crtc_w ||
907 state->crtc_h > INT_MAX ||
908 state->crtc_y > INT_MAX - (int32_t) state->crtc_h) {
909 DRM_DEBUG_ATOMIC("Invalid CRTC coordinates %ux%u+%d+%d\n",
910 state->crtc_w, state->crtc_h,
911 state->crtc_x, state->crtc_y);
915 fb_width = state->fb->width << 16;
916 fb_height = state->fb->height << 16;
918 /* Make sure source coordinates are inside the fb. */
919 if (state->src_w > fb_width ||
920 state->src_x > fb_width - state->src_w ||
921 state->src_h > fb_height ||
922 state->src_y > fb_height - state->src_h) {
923 DRM_DEBUG_ATOMIC("Invalid source coordinates "
924 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
925 state->src_w >> 16, ((state->src_w & 0xffff) * 15625) >> 10,
926 state->src_h >> 16, ((state->src_h & 0xffff) * 15625) >> 10,
927 state->src_x >> 16, ((state->src_x & 0xffff) * 15625) >> 10,
928 state->src_y >> 16, ((state->src_y & 0xffff) * 15625) >> 10);
932 if (plane_switching_crtc(state->state, plane, state)) {
933 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n",
934 plane->base.id, plane->name);
941 static void drm_atomic_plane_print_state(struct drm_printer *p,
942 const struct drm_plane_state *state)
944 struct drm_plane *plane = state->plane;
945 struct drm_rect src = drm_plane_state_src(state);
946 struct drm_rect dest = drm_plane_state_dest(state);
948 drm_printf(p, "plane[%u]: %s\n", plane->base.id, plane->name);
949 drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
950 drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0);
952 struct drm_framebuffer *fb = state->fb;
953 int i, n = fb->format->num_planes;
954 struct drm_format_name_buf format_name;
956 drm_printf(p, "\t\tformat=%s\n",
957 drm_get_format_name(fb->format->format, &format_name));
958 drm_printf(p, "\t\t\tmodifier=0x%llx\n", fb->modifier);
959 drm_printf(p, "\t\tsize=%dx%d\n", fb->width, fb->height);
960 drm_printf(p, "\t\tlayers:\n");
961 for (i = 0; i < n; i++) {
962 drm_printf(p, "\t\t\tpitch[%d]=%u\n", i, fb->pitches[i]);
963 drm_printf(p, "\t\t\toffset[%d]=%u\n", i, fb->offsets[i]);
966 drm_printf(p, "\tcrtc-pos=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&dest));
967 drm_printf(p, "\tsrc-pos=" DRM_RECT_FP_FMT "\n", DRM_RECT_FP_ARG(&src));
968 drm_printf(p, "\trotation=%x\n", state->rotation);
970 if (plane->funcs->atomic_print_state)
971 plane->funcs->atomic_print_state(p, state);
975 * drm_atomic_private_obj_init - initialize private object
976 * @obj: private object
977 * @state: initial private object state
978 * @funcs: pointer to the struct of function pointers that identify the object
981 * Initialize the private object, which can be embedded into any
982 * driver private object that needs its own atomic state.
985 drm_atomic_private_obj_init(struct drm_private_obj *obj,
986 struct drm_private_state *state,
987 const struct drm_private_state_funcs *funcs)
989 memset(obj, 0, sizeof(*obj));
994 EXPORT_SYMBOL(drm_atomic_private_obj_init);
997 * drm_atomic_private_obj_fini - finalize private object
998 * @obj: private object
1000 * Finalize the private object.
1003 drm_atomic_private_obj_fini(struct drm_private_obj *obj)
1005 obj->funcs->atomic_destroy_state(obj, obj->state);
1007 EXPORT_SYMBOL(drm_atomic_private_obj_fini);
1010 * drm_atomic_get_private_obj_state - get private object state
1011 * @state: global atomic state
1012 * @obj: private object to get the state for
1014 * This function returns the private object state for the given private object,
1015 * allocating the state if needed. It does not grab any locks as the caller is
1016 * expected to care of any required locking.
1020 * Either the allocated state or the error code encoded into a pointer.
1022 struct drm_private_state *
1023 drm_atomic_get_private_obj_state(struct drm_atomic_state *state,
1024 struct drm_private_obj *obj)
1026 int index, num_objs, i;
1028 struct __drm_private_objs_state *arr;
1029 struct drm_private_state *obj_state;
1031 for (i = 0; i < state->num_private_objs; i++)
1032 if (obj == state->private_objs[i].ptr)
1033 return state->private_objs[i].state;
1035 num_objs = state->num_private_objs + 1;
1036 size = sizeof(*state->private_objs) * num_objs;
1037 arr = krealloc(state->private_objs, size, GFP_KERNEL);
1039 return ERR_PTR(-ENOMEM);
1041 state->private_objs = arr;
1042 index = state->num_private_objs;
1043 memset(&state->private_objs[index], 0, sizeof(*state->private_objs));
1045 obj_state = obj->funcs->atomic_duplicate_state(obj);
1047 return ERR_PTR(-ENOMEM);
1049 state->private_objs[index].state = obj_state;
1050 state->private_objs[index].old_state = obj->state;
1051 state->private_objs[index].new_state = obj_state;
1052 state->private_objs[index].ptr = obj;
1054 state->num_private_objs = num_objs;
1056 DRM_DEBUG_ATOMIC("Added new private object %p state %p to %p\n",
1057 obj, obj_state, state);
1061 EXPORT_SYMBOL(drm_atomic_get_private_obj_state);
1064 * drm_atomic_get_connector_state - get connector state
1065 * @state: global atomic state object
1066 * @connector: connector to get state object for
1068 * This function returns the connector state for the given connector,
1069 * allocating it if needed. It will also grab the relevant connector lock to
1070 * make sure that the state is consistent.
1074 * Either the allocated state or the error code encoded into the pointer. When
1075 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
1076 * entire atomic sequence must be restarted. All other errors are fatal.
1078 struct drm_connector_state *
1079 drm_atomic_get_connector_state(struct drm_atomic_state *state,
1080 struct drm_connector *connector)
1083 struct drm_mode_config *config = &connector->dev->mode_config;
1084 struct drm_connector_state *connector_state;
1086 WARN_ON(!state->acquire_ctx);
1088 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
1090 return ERR_PTR(ret);
1092 index = drm_connector_index(connector);
1094 if (index >= state->num_connector) {
1095 struct __drm_connnectors_state *c;
1096 int alloc = max(index + 1, config->num_connector);
1098 c = krealloc(state->connectors, alloc * sizeof(*state->connectors), GFP_KERNEL);
1100 return ERR_PTR(-ENOMEM);
1102 state->connectors = c;
1103 memset(&state->connectors[state->num_connector], 0,
1104 sizeof(*state->connectors) * (alloc - state->num_connector));
1106 state->num_connector = alloc;
1109 if (state->connectors[index].state)
1110 return state->connectors[index].state;
1112 connector_state = connector->funcs->atomic_duplicate_state(connector);
1113 if (!connector_state)
1114 return ERR_PTR(-ENOMEM);
1116 drm_connector_get(connector);
1117 state->connectors[index].state = connector_state;
1118 state->connectors[index].old_state = connector->state;
1119 state->connectors[index].new_state = connector_state;
1120 state->connectors[index].ptr = connector;
1121 connector_state->state = state;
1123 DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d:%s] %p state to %p\n",
1124 connector->base.id, connector->name,
1125 connector_state, state);
1127 if (connector_state->crtc) {
1128 struct drm_crtc_state *crtc_state;
1130 crtc_state = drm_atomic_get_crtc_state(state,
1131 connector_state->crtc);
1132 if (IS_ERR(crtc_state))
1133 return ERR_CAST(crtc_state);
1136 return connector_state;
1138 EXPORT_SYMBOL(drm_atomic_get_connector_state);
1141 * drm_atomic_connector_set_property - set property on connector.
1142 * @connector: the drm connector to set a property on
1143 * @state: the state object to update with the new property value
1144 * @property: the property to set
1145 * @val: the new property value
1147 * This function handles generic/core properties and calls out to driver's
1148 * &drm_connector_funcs.atomic_set_property for driver properties. To ensure
1149 * consistent behavior you must call this function rather than the driver hook
1153 * Zero on success, error code on failure
1155 static int drm_atomic_connector_set_property(struct drm_connector *connector,
1156 struct drm_connector_state *state, struct drm_property *property,
1159 struct drm_device *dev = connector->dev;
1160 struct drm_mode_config *config = &dev->mode_config;
1162 if (property == config->prop_crtc_id) {
1163 struct drm_crtc *crtc = drm_crtc_find(dev, val);
1164 return drm_atomic_set_crtc_for_connector(state, crtc);
1165 } else if (property == config->dpms_property) {
1166 /* setting DPMS property requires special handling, which
1167 * is done in legacy setprop path for us. Disallow (for
1168 * now?) atomic writes to DPMS property:
1171 } else if (property == config->tv_select_subconnector_property) {
1172 state->tv.subconnector = val;
1173 } else if (property == config->tv_left_margin_property) {
1174 state->tv.margins.left = val;
1175 } else if (property == config->tv_right_margin_property) {
1176 state->tv.margins.right = val;
1177 } else if (property == config->tv_top_margin_property) {
1178 state->tv.margins.top = val;
1179 } else if (property == config->tv_bottom_margin_property) {
1180 state->tv.margins.bottom = val;
1181 } else if (property == config->tv_mode_property) {
1182 state->tv.mode = val;
1183 } else if (property == config->tv_brightness_property) {
1184 state->tv.brightness = val;
1185 } else if (property == config->tv_contrast_property) {
1186 state->tv.contrast = val;
1187 } else if (property == config->tv_flicker_reduction_property) {
1188 state->tv.flicker_reduction = val;
1189 } else if (property == config->tv_overscan_property) {
1190 state->tv.overscan = val;
1191 } else if (property == config->tv_saturation_property) {
1192 state->tv.saturation = val;
1193 } else if (property == config->tv_hue_property) {
1194 state->tv.hue = val;
1195 } else if (property == config->link_status_property) {
1196 /* Never downgrade from GOOD to BAD on userspace's request here,
1197 * only hw issues can do that.
1199 * For an atomic property the userspace doesn't need to be able
1200 * to understand all the properties, but needs to be able to
1201 * restore the state it wants on VT switch. So if the userspace
1202 * tries to change the link_status from GOOD to BAD, driver
1203 * silently rejects it and returns a 0. This prevents userspace
1204 * from accidently breaking the display when it restores the
1207 if (state->link_status != DRM_LINK_STATUS_GOOD)
1208 state->link_status = val;
1209 } else if (property == config->aspect_ratio_property) {
1210 state->picture_aspect_ratio = val;
1211 } else if (property == connector->scaling_mode_property) {
1212 state->scaling_mode = val;
1213 } else if (connector->funcs->atomic_set_property) {
1214 return connector->funcs->atomic_set_property(connector,
1215 state, property, val);
1223 static void drm_atomic_connector_print_state(struct drm_printer *p,
1224 const struct drm_connector_state *state)
1226 struct drm_connector *connector = state->connector;
1228 drm_printf(p, "connector[%u]: %s\n", connector->base.id, connector->name);
1229 drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)");
1231 if (connector->funcs->atomic_print_state)
1232 connector->funcs->atomic_print_state(p, state);
1236 * drm_atomic_connector_get_property - get property value from connector state
1237 * @connector: the drm connector to set a property on
1238 * @state: the state object to get the property value from
1239 * @property: the property to set
1240 * @val: return location for the property value
1242 * This function handles generic/core properties and calls out to driver's
1243 * &drm_connector_funcs.atomic_get_property for driver properties. To ensure
1244 * consistent behavior you must call this function rather than the driver hook
1248 * Zero on success, error code on failure
1251 drm_atomic_connector_get_property(struct drm_connector *connector,
1252 const struct drm_connector_state *state,
1253 struct drm_property *property, uint64_t *val)
1255 struct drm_device *dev = connector->dev;
1256 struct drm_mode_config *config = &dev->mode_config;
1258 if (property == config->prop_crtc_id) {
1259 *val = (state->crtc) ? state->crtc->base.id : 0;
1260 } else if (property == config->dpms_property) {
1261 *val = connector->dpms;
1262 } else if (property == config->tv_select_subconnector_property) {
1263 *val = state->tv.subconnector;
1264 } else if (property == config->tv_left_margin_property) {
1265 *val = state->tv.margins.left;
1266 } else if (property == config->tv_right_margin_property) {
1267 *val = state->tv.margins.right;
1268 } else if (property == config->tv_top_margin_property) {
1269 *val = state->tv.margins.top;
1270 } else if (property == config->tv_bottom_margin_property) {
1271 *val = state->tv.margins.bottom;
1272 } else if (property == config->tv_mode_property) {
1273 *val = state->tv.mode;
1274 } else if (property == config->tv_brightness_property) {
1275 *val = state->tv.brightness;
1276 } else if (property == config->tv_contrast_property) {
1277 *val = state->tv.contrast;
1278 } else if (property == config->tv_flicker_reduction_property) {
1279 *val = state->tv.flicker_reduction;
1280 } else if (property == config->tv_overscan_property) {
1281 *val = state->tv.overscan;
1282 } else if (property == config->tv_saturation_property) {
1283 *val = state->tv.saturation;
1284 } else if (property == config->tv_hue_property) {
1285 *val = state->tv.hue;
1286 } else if (property == config->link_status_property) {
1287 *val = state->link_status;
1288 } else if (property == config->aspect_ratio_property) {
1289 *val = state->picture_aspect_ratio;
1290 } else if (property == connector->scaling_mode_property) {
1291 *val = state->scaling_mode;
1292 } else if (connector->funcs->atomic_get_property) {
1293 return connector->funcs->atomic_get_property(connector,
1294 state, property, val);
1302 int drm_atomic_get_property(struct drm_mode_object *obj,
1303 struct drm_property *property, uint64_t *val)
1305 struct drm_device *dev = property->dev;
1308 switch (obj->type) {
1309 case DRM_MODE_OBJECT_CONNECTOR: {
1310 struct drm_connector *connector = obj_to_connector(obj);
1311 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
1312 ret = drm_atomic_connector_get_property(connector,
1313 connector->state, property, val);
1316 case DRM_MODE_OBJECT_CRTC: {
1317 struct drm_crtc *crtc = obj_to_crtc(obj);
1318 WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
1319 ret = drm_atomic_crtc_get_property(crtc,
1320 crtc->state, property, val);
1323 case DRM_MODE_OBJECT_PLANE: {
1324 struct drm_plane *plane = obj_to_plane(obj);
1325 WARN_ON(!drm_modeset_is_locked(&plane->mutex));
1326 ret = drm_atomic_plane_get_property(plane,
1327 plane->state, property, val);
1339 * drm_atomic_set_crtc_for_plane - set crtc for plane
1340 * @plane_state: the plane whose incoming state to update
1341 * @crtc: crtc to use for the plane
1343 * Changing the assigned crtc for a plane requires us to grab the lock and state
1344 * for the new crtc, as needed. This function takes care of all these details
1345 * besides updating the pointer in the state object itself.
1348 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1349 * then the w/w mutex code has detected a deadlock and the entire atomic
1350 * sequence must be restarted. All other errors are fatal.
1353 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
1354 struct drm_crtc *crtc)
1356 struct drm_plane *plane = plane_state->plane;
1357 struct drm_crtc_state *crtc_state;
1358 /* Nothing to do for same crtc*/
1359 if (plane_state->crtc == crtc)
1361 if (plane_state->crtc) {
1362 crtc_state = drm_atomic_get_crtc_state(plane_state->state,
1364 if (WARN_ON(IS_ERR(crtc_state)))
1365 return PTR_ERR(crtc_state);
1367 crtc_state->plane_mask &= ~(1 << drm_plane_index(plane));
1370 plane_state->crtc = crtc;
1373 crtc_state = drm_atomic_get_crtc_state(plane_state->state,
1375 if (IS_ERR(crtc_state))
1376 return PTR_ERR(crtc_state);
1377 crtc_state->plane_mask |= (1 << drm_plane_index(plane));
1381 DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d:%s]\n",
1382 plane_state, crtc->base.id, crtc->name);
1384 DRM_DEBUG_ATOMIC("Link plane state %p to [NOCRTC]\n",
1389 EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane);
1392 * drm_atomic_set_fb_for_plane - set framebuffer for plane
1393 * @plane_state: atomic state object for the plane
1394 * @fb: fb to use for the plane
1396 * Changing the assigned framebuffer for a plane requires us to grab a reference
1397 * to the new fb and drop the reference to the old fb, if there is one. This
1398 * function takes care of all these details besides updating the pointer in the
1399 * state object itself.
1402 drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
1403 struct drm_framebuffer *fb)
1406 DRM_DEBUG_ATOMIC("Set [FB:%d] for plane state %p\n",
1407 fb->base.id, plane_state);
1409 DRM_DEBUG_ATOMIC("Set [NOFB] for plane state %p\n",
1412 drm_framebuffer_assign(&plane_state->fb, fb);
1414 EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
1417 * drm_atomic_set_fence_for_plane - set fence for plane
1418 * @plane_state: atomic state object for the plane
1419 * @fence: dma_fence to use for the plane
1421 * Helper to setup the plane_state fence in case it is not set yet.
1422 * By using this drivers doesn't need to worry if the user choose
1423 * implicit or explicit fencing.
1425 * This function will not set the fence to the state if it was set
1426 * via explicit fencing interfaces on the atomic ioctl. In that case it will
1427 * drop the reference to the fence as we are not storing it anywhere.
1428 * Otherwise, if &drm_plane_state.fence is not set this function we just set it
1429 * with the received implicit fence. In both cases this function consumes a
1430 * reference for @fence.
1433 drm_atomic_set_fence_for_plane(struct drm_plane_state *plane_state,
1434 struct dma_fence *fence)
1436 if (plane_state->fence) {
1437 dma_fence_put(fence);
1441 plane_state->fence = fence;
1443 EXPORT_SYMBOL(drm_atomic_set_fence_for_plane);
1446 * drm_atomic_set_crtc_for_connector - set crtc for connector
1447 * @conn_state: atomic state object for the connector
1448 * @crtc: crtc to use for the connector
1450 * Changing the assigned crtc for a connector requires us to grab the lock and
1451 * state for the new crtc, as needed. This function takes care of all these
1452 * details besides updating the pointer in the state object itself.
1455 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1456 * then the w/w mutex code has detected a deadlock and the entire atomic
1457 * sequence must be restarted. All other errors are fatal.
1460 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
1461 struct drm_crtc *crtc)
1463 struct drm_crtc_state *crtc_state;
1465 if (conn_state->crtc == crtc)
1468 if (conn_state->crtc) {
1469 crtc_state = drm_atomic_get_new_crtc_state(conn_state->state,
1472 crtc_state->connector_mask &=
1473 ~(1 << drm_connector_index(conn_state->connector));
1475 drm_connector_put(conn_state->connector);
1476 conn_state->crtc = NULL;
1480 crtc_state = drm_atomic_get_crtc_state(conn_state->state, crtc);
1481 if (IS_ERR(crtc_state))
1482 return PTR_ERR(crtc_state);
1484 crtc_state->connector_mask |=
1485 1 << drm_connector_index(conn_state->connector);
1487 drm_connector_get(conn_state->connector);
1488 conn_state->crtc = crtc;
1490 DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d:%s]\n",
1491 conn_state, crtc->base.id, crtc->name);
1493 DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n",
1499 EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector);
1502 * drm_atomic_add_affected_connectors - add connectors for crtc
1503 * @state: atomic state
1506 * This function walks the current configuration and adds all connectors
1507 * currently using @crtc to the atomic configuration @state. Note that this
1508 * function must acquire the connection mutex. This can potentially cause
1509 * unneeded seralization if the update is just for the planes on one crtc. Hence
1510 * drivers and helpers should only call this when really needed (e.g. when a
1511 * full modeset needs to happen due to some change).
1514 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1515 * then the w/w mutex code has detected a deadlock and the entire atomic
1516 * sequence must be restarted. All other errors are fatal.
1519 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
1520 struct drm_crtc *crtc)
1522 struct drm_mode_config *config = &state->dev->mode_config;
1523 struct drm_connector *connector;
1524 struct drm_connector_state *conn_state;
1525 struct drm_connector_list_iter conn_iter;
1526 struct drm_crtc_state *crtc_state;
1529 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1530 if (IS_ERR(crtc_state))
1531 return PTR_ERR(crtc_state);
1533 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
1537 DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d:%s] to %p\n",
1538 crtc->base.id, crtc->name, state);
1541 * Changed connectors are already in @state, so only need to look
1542 * at the connector_mask in crtc_state.
1544 drm_connector_list_iter_begin(state->dev, &conn_iter);
1545 drm_for_each_connector_iter(connector, &conn_iter) {
1546 if (!(crtc_state->connector_mask & (1 << drm_connector_index(connector))))
1549 conn_state = drm_atomic_get_connector_state(state, connector);
1550 if (IS_ERR(conn_state)) {
1551 drm_connector_list_iter_end(&conn_iter);
1552 return PTR_ERR(conn_state);
1555 drm_connector_list_iter_end(&conn_iter);
1559 EXPORT_SYMBOL(drm_atomic_add_affected_connectors);
1562 * drm_atomic_add_affected_planes - add planes for crtc
1563 * @state: atomic state
1566 * This function walks the current configuration and adds all planes
1567 * currently used by @crtc to the atomic configuration @state. This is useful
1568 * when an atomic commit also needs to check all currently enabled plane on
1569 * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC
1570 * to avoid special code to force-enable all planes.
1572 * Since acquiring a plane state will always also acquire the w/w mutex of the
1573 * current CRTC for that plane (if there is any) adding all the plane states for
1574 * a CRTC will not reduce parallism of atomic updates.
1577 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1578 * then the w/w mutex code has detected a deadlock and the entire atomic
1579 * sequence must be restarted. All other errors are fatal.
1582 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
1583 struct drm_crtc *crtc)
1585 struct drm_plane *plane;
1587 WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc));
1589 drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) {
1590 struct drm_plane_state *plane_state =
1591 drm_atomic_get_plane_state(state, plane);
1593 if (IS_ERR(plane_state))
1594 return PTR_ERR(plane_state);
1598 EXPORT_SYMBOL(drm_atomic_add_affected_planes);
1601 * drm_atomic_check_only - check whether a given config would work
1602 * @state: atomic configuration to check
1604 * Note that this function can return -EDEADLK if the driver needed to acquire
1605 * more locks but encountered a deadlock. The caller must then do the usual w/w
1606 * backoff dance and restart. All other errors are fatal.
1609 * 0 on success, negative error code on failure.
1611 int drm_atomic_check_only(struct drm_atomic_state *state)
1613 struct drm_device *dev = state->dev;
1614 struct drm_mode_config *config = &dev->mode_config;
1615 struct drm_plane *plane;
1616 struct drm_plane_state *plane_state;
1617 struct drm_crtc *crtc;
1618 struct drm_crtc_state *crtc_state;
1621 DRM_DEBUG_ATOMIC("checking %p\n", state);
1623 for_each_new_plane_in_state(state, plane, plane_state, i) {
1624 ret = drm_atomic_plane_check(plane, plane_state);
1626 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic core check failed\n",
1627 plane->base.id, plane->name);
1632 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
1633 ret = drm_atomic_crtc_check(crtc, crtc_state);
1635 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic core check failed\n",
1636 crtc->base.id, crtc->name);
1641 if (config->funcs->atomic_check)
1642 ret = config->funcs->atomic_check(state->dev, state);
1647 if (!state->allow_modeset) {
1648 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
1649 if (drm_atomic_crtc_needs_modeset(crtc_state)) {
1650 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requires full modeset\n",
1651 crtc->base.id, crtc->name);
1659 EXPORT_SYMBOL(drm_atomic_check_only);
1662 * drm_atomic_commit - commit configuration atomically
1663 * @state: atomic configuration to check
1665 * Note that this function can return -EDEADLK if the driver needed to acquire
1666 * more locks but encountered a deadlock. The caller must then do the usual w/w
1667 * backoff dance and restart. All other errors are fatal.
1669 * This function will take its own reference on @state.
1670 * Callers should always release their reference with drm_atomic_state_put().
1673 * 0 on success, negative error code on failure.
1675 int drm_atomic_commit(struct drm_atomic_state *state)
1677 struct drm_mode_config *config = &state->dev->mode_config;
1680 ret = drm_atomic_check_only(state);
1684 DRM_DEBUG_ATOMIC("committing %p\n", state);
1686 return config->funcs->atomic_commit(state->dev, state, false);
1688 EXPORT_SYMBOL(drm_atomic_commit);
1691 * drm_atomic_nonblocking_commit - atomic nonblocking commit
1692 * @state: atomic configuration to check
1694 * Note that this function can return -EDEADLK if the driver needed to acquire
1695 * more locks but encountered a deadlock. The caller must then do the usual w/w
1696 * backoff dance and restart. All other errors are fatal.
1698 * This function will take its own reference on @state.
1699 * Callers should always release their reference with drm_atomic_state_put().
1702 * 0 on success, negative error code on failure.
1704 int drm_atomic_nonblocking_commit(struct drm_atomic_state *state)
1706 struct drm_mode_config *config = &state->dev->mode_config;
1709 ret = drm_atomic_check_only(state);
1713 DRM_DEBUG_ATOMIC("committing %p nonblocking\n", state);
1715 return config->funcs->atomic_commit(state->dev, state, true);
1717 EXPORT_SYMBOL(drm_atomic_nonblocking_commit);
1719 static void drm_atomic_print_state(const struct drm_atomic_state *state)
1721 struct drm_printer p = drm_info_printer(state->dev->dev);
1722 struct drm_plane *plane;
1723 struct drm_plane_state *plane_state;
1724 struct drm_crtc *crtc;
1725 struct drm_crtc_state *crtc_state;
1726 struct drm_connector *connector;
1727 struct drm_connector_state *connector_state;
1730 DRM_DEBUG_ATOMIC("checking %p\n", state);
1732 for_each_new_plane_in_state(state, plane, plane_state, i)
1733 drm_atomic_plane_print_state(&p, plane_state);
1735 for_each_new_crtc_in_state(state, crtc, crtc_state, i)
1736 drm_atomic_crtc_print_state(&p, crtc_state);
1738 for_each_new_connector_in_state(state, connector, connector_state, i)
1739 drm_atomic_connector_print_state(&p, connector_state);
1742 static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p,
1745 struct drm_mode_config *config = &dev->mode_config;
1746 struct drm_plane *plane;
1747 struct drm_crtc *crtc;
1748 struct drm_connector *connector;
1749 struct drm_connector_list_iter conn_iter;
1751 if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
1754 list_for_each_entry(plane, &config->plane_list, head) {
1756 drm_modeset_lock(&plane->mutex, NULL);
1757 drm_atomic_plane_print_state(p, plane->state);
1759 drm_modeset_unlock(&plane->mutex);
1762 list_for_each_entry(crtc, &config->crtc_list, head) {
1764 drm_modeset_lock(&crtc->mutex, NULL);
1765 drm_atomic_crtc_print_state(p, crtc->state);
1767 drm_modeset_unlock(&crtc->mutex);
1770 drm_connector_list_iter_begin(dev, &conn_iter);
1772 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1773 drm_for_each_connector_iter(connector, &conn_iter)
1774 drm_atomic_connector_print_state(p, connector->state);
1776 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1777 drm_connector_list_iter_end(&conn_iter);
1781 * drm_state_dump - dump entire device atomic state
1782 * @dev: the drm device
1783 * @p: where to print the state to
1785 * Just for debugging. Drivers might want an option to dump state
1786 * to dmesg in case of error irq's. (Hint, you probably want to
1789 * The caller must drm_modeset_lock_all(), or if this is called
1790 * from error irq handler, it should not be enabled by default.
1791 * (Ie. if you are debugging errors you might not care that this
1792 * is racey. But calling this without all modeset locks held is
1793 * not inherently safe.)
1795 void drm_state_dump(struct drm_device *dev, struct drm_printer *p)
1797 __drm_state_dump(dev, p, false);
1799 EXPORT_SYMBOL(drm_state_dump);
1801 #ifdef CONFIG_DEBUG_FS
1802 static int drm_state_info(struct seq_file *m, void *data)
1804 struct drm_info_node *node = (struct drm_info_node *) m->private;
1805 struct drm_device *dev = node->minor->dev;
1806 struct drm_printer p = drm_seq_file_printer(m);
1808 __drm_state_dump(dev, &p, true);
1813 /* any use in debugfs files to dump individual planes/crtc/etc? */
1814 static const struct drm_info_list drm_atomic_debugfs_list[] = {
1815 {"state", drm_state_info, 0},
1818 int drm_atomic_debugfs_init(struct drm_minor *minor)
1820 return drm_debugfs_create_files(drm_atomic_debugfs_list,
1821 ARRAY_SIZE(drm_atomic_debugfs_list),
1822 minor->debugfs_root, minor);
1827 * The big monstor ioctl
1830 static struct drm_pending_vblank_event *create_vblank_event(
1831 struct drm_device *dev, uint64_t user_data)
1833 struct drm_pending_vblank_event *e = NULL;
1835 e = kzalloc(sizeof *e, GFP_KERNEL);
1839 e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
1840 e->event.base.length = sizeof(e->event);
1841 e->event.user_data = user_data;
1846 int drm_atomic_connector_commit_dpms(struct drm_atomic_state *state,
1847 struct drm_connector *connector,
1850 struct drm_connector *tmp_connector;
1851 struct drm_connector_state *new_conn_state;
1852 struct drm_crtc *crtc;
1853 struct drm_crtc_state *crtc_state;
1854 int i, ret, old_mode = connector->dpms;
1855 bool active = false;
1857 ret = drm_modeset_lock(&state->dev->mode_config.connection_mutex,
1858 state->acquire_ctx);
1862 if (mode != DRM_MODE_DPMS_ON)
1863 mode = DRM_MODE_DPMS_OFF;
1864 connector->dpms = mode;
1866 crtc = connector->state->crtc;
1869 ret = drm_atomic_add_affected_connectors(state, crtc);
1873 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1874 if (IS_ERR(crtc_state)) {
1875 ret = PTR_ERR(crtc_state);
1879 for_each_new_connector_in_state(state, tmp_connector, new_conn_state, i) {
1880 if (new_conn_state->crtc != crtc)
1882 if (tmp_connector->dpms == DRM_MODE_DPMS_ON) {
1888 crtc_state->active = active;
1889 ret = drm_atomic_commit(state);
1892 connector->dpms = old_mode;
1896 int drm_atomic_set_property(struct drm_atomic_state *state,
1897 struct drm_mode_object *obj,
1898 struct drm_property *prop,
1899 uint64_t prop_value)
1901 struct drm_mode_object *ref;
1904 if (!drm_property_change_valid_get(prop, prop_value, &ref))
1907 switch (obj->type) {
1908 case DRM_MODE_OBJECT_CONNECTOR: {
1909 struct drm_connector *connector = obj_to_connector(obj);
1910 struct drm_connector_state *connector_state;
1912 connector_state = drm_atomic_get_connector_state(state, connector);
1913 if (IS_ERR(connector_state)) {
1914 ret = PTR_ERR(connector_state);
1918 ret = drm_atomic_connector_set_property(connector,
1919 connector_state, prop, prop_value);
1922 case DRM_MODE_OBJECT_CRTC: {
1923 struct drm_crtc *crtc = obj_to_crtc(obj);
1924 struct drm_crtc_state *crtc_state;
1926 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1927 if (IS_ERR(crtc_state)) {
1928 ret = PTR_ERR(crtc_state);
1932 ret = drm_atomic_crtc_set_property(crtc,
1933 crtc_state, prop, prop_value);
1936 case DRM_MODE_OBJECT_PLANE: {
1937 struct drm_plane *plane = obj_to_plane(obj);
1938 struct drm_plane_state *plane_state;
1940 plane_state = drm_atomic_get_plane_state(state, plane);
1941 if (IS_ERR(plane_state)) {
1942 ret = PTR_ERR(plane_state);
1946 ret = drm_atomic_plane_set_property(plane,
1947 plane_state, prop, prop_value);
1955 drm_property_change_valid_put(prop, ref);
1960 * drm_atomic_clean_old_fb -- Unset old_fb pointers and set plane->fb pointers.
1962 * @dev: drm device to check.
1963 * @plane_mask: plane mask for planes that were updated.
1964 * @ret: return value, can be -EDEADLK for a retry.
1966 * Before doing an update &drm_plane.old_fb is set to &drm_plane.fb, but before
1967 * dropping the locks old_fb needs to be set to NULL and plane->fb updated. This
1968 * is a common operation for each atomic update, so this call is split off as a
1971 void drm_atomic_clean_old_fb(struct drm_device *dev,
1972 unsigned plane_mask,
1975 struct drm_plane *plane;
1977 /* if succeeded, fixup legacy plane crtc/fb ptrs before dropping
1978 * locks (ie. while it is still safe to deref plane->state). We
1979 * need to do this here because the driver entry points cannot
1980 * distinguish between legacy and atomic ioctls.
1982 drm_for_each_plane_mask(plane, dev, plane_mask) {
1984 struct drm_framebuffer *new_fb = plane->state->fb;
1986 drm_framebuffer_get(new_fb);
1988 plane->crtc = plane->state->crtc;
1991 drm_framebuffer_put(plane->old_fb);
1993 plane->old_fb = NULL;
1996 EXPORT_SYMBOL(drm_atomic_clean_old_fb);
1999 * DOC: explicit fencing properties
2001 * Explicit fencing allows userspace to control the buffer synchronization
2002 * between devices. A Fence or a group of fences are transfered to/from
2003 * userspace using Sync File fds and there are two DRM properties for that.
2004 * IN_FENCE_FD on each DRM Plane to send fences to the kernel and
2005 * OUT_FENCE_PTR on each DRM CRTC to receive fences from the kernel.
2007 * As a contrast, with implicit fencing the kernel keeps track of any
2008 * ongoing rendering, and automatically ensures that the atomic update waits
2009 * for any pending rendering to complete. For shared buffers represented with
2010 * a &struct dma_buf this is tracked in &struct reservation_object.
2011 * Implicit syncing is how Linux traditionally worked (e.g. DRI2/3 on X.org),
2012 * whereas explicit fencing is what Android wants.
2015 * Use this property to pass a fence that DRM should wait on before
2016 * proceeding with the Atomic Commit request and show the framebuffer for
2017 * the plane on the screen. The fence can be either a normal fence or a
2018 * merged one, the sync_file framework will handle both cases and use a
2019 * fence_array if a merged fence is received. Passing -1 here means no
2020 * fences to wait on.
2022 * If the Atomic Commit request has the DRM_MODE_ATOMIC_TEST_ONLY flag
2023 * it will only check if the Sync File is a valid one.
2025 * On the driver side the fence is stored on the @fence parameter of
2026 * &struct drm_plane_state. Drivers which also support implicit fencing
2027 * should set the implicit fence using drm_atomic_set_fence_for_plane(),
2028 * to make sure there's consistent behaviour between drivers in precedence
2029 * of implicit vs. explicit fencing.
2032 * Use this property to pass a file descriptor pointer to DRM. Once the
2033 * Atomic Commit request call returns OUT_FENCE_PTR will be filled with
2034 * the file descriptor number of a Sync File. This Sync File contains the
2035 * CRTC fence that will be signaled when all framebuffers present on the
2036 * Atomic Commit * request for that given CRTC are scanned out on the
2039 * The Atomic Commit request fails if a invalid pointer is passed. If the
2040 * Atomic Commit request fails for any other reason the out fence fd
2041 * returned will be -1. On a Atomic Commit with the
2042 * DRM_MODE_ATOMIC_TEST_ONLY flag the out fence will also be set to -1.
2044 * Note that out-fences don't have a special interface to drivers and are
2045 * internally represented by a &struct drm_pending_vblank_event in struct
2046 * &drm_crtc_state, which is also used by the nonblocking atomic commit
2047 * helpers and for the DRM event handling for existing userspace.
2050 struct drm_out_fence_state {
2051 s32 __user *out_fence_ptr;
2052 struct sync_file *sync_file;
2056 static int setup_out_fence(struct drm_out_fence_state *fence_state,
2057 struct dma_fence *fence)
2059 fence_state->fd = get_unused_fd_flags(O_CLOEXEC);
2060 if (fence_state->fd < 0)
2061 return fence_state->fd;
2063 if (put_user(fence_state->fd, fence_state->out_fence_ptr))
2066 fence_state->sync_file = sync_file_create(fence);
2067 if (!fence_state->sync_file)
2073 static int prepare_crtc_signaling(struct drm_device *dev,
2074 struct drm_atomic_state *state,
2075 struct drm_mode_atomic *arg,
2076 struct drm_file *file_priv,
2077 struct drm_out_fence_state **fence_state,
2078 unsigned int *num_fences)
2080 struct drm_crtc *crtc;
2081 struct drm_crtc_state *crtc_state;
2084 if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
2087 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
2088 s32 __user *fence_ptr;
2090 fence_ptr = get_out_fence_for_crtc(crtc_state->state, crtc);
2092 if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT || fence_ptr) {
2093 struct drm_pending_vblank_event *e;
2095 e = create_vblank_event(dev, arg->user_data);
2099 crtc_state->event = e;
2102 if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
2103 struct drm_pending_vblank_event *e = crtc_state->event;
2108 ret = drm_event_reserve_init(dev, file_priv, &e->base,
2112 crtc_state->event = NULL;
2118 struct dma_fence *fence;
2119 struct drm_out_fence_state *f;
2121 f = krealloc(*fence_state, sizeof(**fence_state) *
2122 (*num_fences + 1), GFP_KERNEL);
2126 memset(&f[*num_fences], 0, sizeof(*f));
2128 f[*num_fences].out_fence_ptr = fence_ptr;
2131 fence = drm_crtc_create_fence(crtc);
2135 ret = setup_out_fence(&f[(*num_fences)++], fence);
2137 dma_fence_put(fence);
2141 crtc_state->event->base.fence = fence;
2148 * Having this flag means user mode pends on event which will never
2149 * reach due to lack of at least one CRTC for signaling
2151 if (c == 0 && (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
2157 static void complete_crtc_signaling(struct drm_device *dev,
2158 struct drm_atomic_state *state,
2159 struct drm_out_fence_state *fence_state,
2160 unsigned int num_fences,
2163 struct drm_crtc *crtc;
2164 struct drm_crtc_state *crtc_state;
2168 for (i = 0; i < num_fences; i++)
2169 fd_install(fence_state[i].fd,
2170 fence_state[i].sync_file->file);
2176 for_each_new_crtc_in_state(state, crtc, crtc_state, i) {
2177 struct drm_pending_vblank_event *event = crtc_state->event;
2179 * Free the allocated event. drm_atomic_helper_setup_commit
2180 * can allocate an event too, so only free it if it's ours
2181 * to prevent a double free in drm_atomic_state_clear.
2183 if (event && (event->base.fence || event->base.file_priv)) {
2184 drm_event_cancel_free(dev, &event->base);
2185 crtc_state->event = NULL;
2192 for (i = 0; i < num_fences; i++) {
2193 if (fence_state[i].sync_file)
2194 fput(fence_state[i].sync_file->file);
2195 if (fence_state[i].fd >= 0)
2196 put_unused_fd(fence_state[i].fd);
2198 /* If this fails log error to the user */
2199 if (fence_state[i].out_fence_ptr &&
2200 put_user(-1, fence_state[i].out_fence_ptr))
2201 DRM_DEBUG_ATOMIC("Couldn't clear out_fence_ptr\n");
2207 int drm_mode_atomic_ioctl(struct drm_device *dev,
2208 void *data, struct drm_file *file_priv)
2210 struct drm_mode_atomic *arg = data;
2211 uint32_t __user *objs_ptr = (uint32_t __user *)(unsigned long)(arg->objs_ptr);
2212 uint32_t __user *count_props_ptr = (uint32_t __user *)(unsigned long)(arg->count_props_ptr);
2213 uint32_t __user *props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr);
2214 uint64_t __user *prop_values_ptr = (uint64_t __user *)(unsigned long)(arg->prop_values_ptr);
2215 unsigned int copied_objs, copied_props;
2216 struct drm_atomic_state *state;
2217 struct drm_modeset_acquire_ctx ctx;
2218 struct drm_plane *plane;
2219 struct drm_out_fence_state *fence_state;
2220 unsigned plane_mask;
2222 unsigned int i, j, num_fences;
2224 /* disallow for drivers not supporting atomic: */
2225 if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
2228 /* disallow for userspace that has not enabled atomic cap (even
2229 * though this may be a bit overkill, since legacy userspace
2230 * wouldn't know how to call this ioctl)
2232 if (!file_priv->atomic)
2235 if (arg->flags & ~DRM_MODE_ATOMIC_FLAGS)
2241 if ((arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) &&
2242 !dev->mode_config.async_page_flip)
2245 /* can't test and expect an event at the same time. */
2246 if ((arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) &&
2247 (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
2250 drm_modeset_acquire_init(&ctx, 0);
2252 state = drm_atomic_state_alloc(dev);
2256 state->acquire_ctx = &ctx;
2257 state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
2266 for (i = 0; i < arg->count_objs; i++) {
2267 uint32_t obj_id, count_props;
2268 struct drm_mode_object *obj;
2270 if (get_user(obj_id, objs_ptr + copied_objs)) {
2275 obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_ANY);
2281 if (!obj->properties) {
2282 drm_mode_object_put(obj);
2287 if (get_user(count_props, count_props_ptr + copied_objs)) {
2288 drm_mode_object_put(obj);
2295 for (j = 0; j < count_props; j++) {
2297 uint64_t prop_value;
2298 struct drm_property *prop;
2300 if (get_user(prop_id, props_ptr + copied_props)) {
2301 drm_mode_object_put(obj);
2306 prop = drm_mode_obj_find_prop_id(obj, prop_id);
2308 drm_mode_object_put(obj);
2313 if (copy_from_user(&prop_value,
2314 prop_values_ptr + copied_props,
2315 sizeof(prop_value))) {
2316 drm_mode_object_put(obj);
2321 ret = drm_atomic_set_property(state, obj, prop,
2324 drm_mode_object_put(obj);
2331 if (obj->type == DRM_MODE_OBJECT_PLANE && count_props &&
2332 !(arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
2333 plane = obj_to_plane(obj);
2334 plane_mask |= (1 << drm_plane_index(plane));
2335 plane->old_fb = plane->fb;
2337 drm_mode_object_put(obj);
2340 ret = prepare_crtc_signaling(dev, state, arg, file_priv, &fence_state,
2345 if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) {
2346 ret = drm_atomic_check_only(state);
2347 } else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) {
2348 ret = drm_atomic_nonblocking_commit(state);
2350 if (unlikely(drm_debug & DRM_UT_STATE))
2351 drm_atomic_print_state(state);
2353 ret = drm_atomic_commit(state);
2357 drm_atomic_clean_old_fb(dev, plane_mask, ret);
2359 complete_crtc_signaling(dev, state, fence_state, num_fences, !ret);
2361 if (ret == -EDEADLK) {
2362 drm_atomic_state_clear(state);
2363 drm_modeset_backoff(&ctx);
2367 drm_atomic_state_put(state);
2369 drm_modeset_drop_locks(&ctx);
2370 drm_modeset_acquire_fini(&ctx);