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.
30 #include <drm/drm_atomic.h>
31 #include <drm/drm_plane_helper.h>
34 * drm_atomic_state_default_release -
35 * release memory initialized by drm_atomic_state_init
36 * @state: atomic state
38 * Free all the memory allocated by drm_atomic_state_init.
39 * This is useful for drivers that subclass the atomic state.
41 void drm_atomic_state_default_release(struct drm_atomic_state *state)
43 kfree(state->connectors);
44 kfree(state->connector_states);
46 kfree(state->crtc_states);
48 kfree(state->plane_states);
50 EXPORT_SYMBOL(drm_atomic_state_default_release);
53 * drm_atomic_state_init - init new atomic state
55 * @state: atomic state
57 * Default implementation for filling in a new atomic state.
58 * This is useful for drivers that subclass the atomic state.
61 drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state)
63 /* TODO legacy paths should maybe do a better job about
64 * setting this appropriately?
66 state->allow_modeset = true;
68 state->crtcs = kcalloc(dev->mode_config.num_crtc,
69 sizeof(*state->crtcs), GFP_KERNEL);
72 state->crtc_states = kcalloc(dev->mode_config.num_crtc,
73 sizeof(*state->crtc_states), GFP_KERNEL);
74 if (!state->crtc_states)
76 state->planes = kcalloc(dev->mode_config.num_total_plane,
77 sizeof(*state->planes), GFP_KERNEL);
80 state->plane_states = kcalloc(dev->mode_config.num_total_plane,
81 sizeof(*state->plane_states), GFP_KERNEL);
82 if (!state->plane_states)
87 DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
91 drm_atomic_state_default_release(state);
94 EXPORT_SYMBOL(drm_atomic_state_init);
97 * drm_atomic_state_alloc - allocate atomic state
100 * This allocates an empty atomic state to track updates.
102 struct drm_atomic_state *
103 drm_atomic_state_alloc(struct drm_device *dev)
105 struct drm_mode_config *config = &dev->mode_config;
106 struct drm_atomic_state *state;
108 if (!config->funcs->atomic_state_alloc) {
109 state = kzalloc(sizeof(*state), GFP_KERNEL);
112 if (drm_atomic_state_init(dev, state) < 0) {
119 return config->funcs->atomic_state_alloc(dev);
121 EXPORT_SYMBOL(drm_atomic_state_alloc);
124 * drm_atomic_state_default_clear - clear base atomic state
125 * @state: atomic state
127 * Default implementation for clearing atomic state.
128 * This is useful for drivers that subclass the atomic state.
130 void drm_atomic_state_default_clear(struct drm_atomic_state *state)
132 struct drm_device *dev = state->dev;
133 struct drm_mode_config *config = &dev->mode_config;
136 DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
138 for (i = 0; i < state->num_connector; i++) {
139 struct drm_connector *connector = state->connectors[i];
145 * FIXME: Async commits can race with connector unplugging and
146 * there's currently nothing that prevents cleanup up state for
147 * deleted connectors. As long as the callback doesn't look at
148 * the connector we'll be fine though, so make sure that's the
149 * case by setting all connector pointers to NULL.
151 state->connector_states[i]->connector = NULL;
152 connector->funcs->atomic_destroy_state(NULL,
153 state->connector_states[i]);
154 state->connectors[i] = NULL;
155 state->connector_states[i] = NULL;
158 for (i = 0; i < config->num_crtc; i++) {
159 struct drm_crtc *crtc = state->crtcs[i];
164 crtc->funcs->atomic_destroy_state(crtc,
165 state->crtc_states[i]);
166 state->crtcs[i] = NULL;
167 state->crtc_states[i] = NULL;
170 for (i = 0; i < config->num_total_plane; i++) {
171 struct drm_plane *plane = state->planes[i];
176 plane->funcs->atomic_destroy_state(plane,
177 state->plane_states[i]);
178 state->planes[i] = NULL;
179 state->plane_states[i] = NULL;
182 EXPORT_SYMBOL(drm_atomic_state_default_clear);
185 * drm_atomic_state_clear - clear state object
186 * @state: atomic state
188 * When the w/w mutex algorithm detects a deadlock we need to back off and drop
189 * all locks. So someone else could sneak in and change the current modeset
190 * configuration. Which means that all the state assembled in @state is no
191 * longer an atomic update to the current state, but to some arbitrary earlier
192 * state. Which could break assumptions the driver's ->atomic_check likely
195 * Hence we must clear all cached state and completely start over, using this
198 void drm_atomic_state_clear(struct drm_atomic_state *state)
200 struct drm_device *dev = state->dev;
201 struct drm_mode_config *config = &dev->mode_config;
203 if (config->funcs->atomic_state_clear)
204 config->funcs->atomic_state_clear(state);
206 drm_atomic_state_default_clear(state);
208 EXPORT_SYMBOL(drm_atomic_state_clear);
211 * drm_atomic_state_free - free all memory for an atomic state
212 * @state: atomic state to deallocate
214 * This frees all memory associated with an atomic state, including all the
215 * per-object state for planes, crtcs and connectors.
217 void drm_atomic_state_free(struct drm_atomic_state *state)
219 struct drm_device *dev;
220 struct drm_mode_config *config;
226 config = &dev->mode_config;
228 drm_atomic_state_clear(state);
230 DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
232 if (config->funcs->atomic_state_free) {
233 config->funcs->atomic_state_free(state);
235 drm_atomic_state_default_release(state);
239 EXPORT_SYMBOL(drm_atomic_state_free);
242 * drm_atomic_get_crtc_state - get crtc state
243 * @state: global atomic state object
244 * @crtc: crtc to get state object for
246 * This function returns the crtc state for the given crtc, allocating it if
247 * needed. It will also grab the relevant crtc lock to make sure that the state
252 * Either the allocated state or the error code encoded into the pointer. When
253 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
254 * entire atomic sequence must be restarted. All other errors are fatal.
256 struct drm_crtc_state *
257 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
258 struct drm_crtc *crtc)
260 int ret, index = drm_crtc_index(crtc);
261 struct drm_crtc_state *crtc_state;
263 crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
267 ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
271 crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
273 return ERR_PTR(-ENOMEM);
275 state->crtc_states[index] = crtc_state;
276 state->crtcs[index] = crtc;
277 crtc_state->state = state;
279 DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n",
280 crtc->base.id, crtc->name, crtc_state, state);
284 EXPORT_SYMBOL(drm_atomic_get_crtc_state);
287 * drm_atomic_set_mode_for_crtc - set mode for CRTC
288 * @state: the CRTC whose incoming state to update
289 * @mode: kernel-internal mode to use for the CRTC, or NULL to disable
291 * Set a mode (originating from the kernel) on the desired CRTC state. Does
292 * not change any other state properties, including enable, active, or
296 * Zero on success, error code on failure. Cannot return -EDEADLK.
298 int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
299 struct drm_display_mode *mode)
301 struct drm_mode_modeinfo umode;
303 /* Early return for no change. */
304 if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0)
307 drm_property_unreference_blob(state->mode_blob);
308 state->mode_blob = NULL;
311 drm_mode_convert_to_umode(&umode, mode);
313 drm_property_create_blob(state->crtc->dev,
316 if (IS_ERR(state->mode_blob))
317 return PTR_ERR(state->mode_blob);
319 drm_mode_copy(&state->mode, mode);
320 state->enable = true;
321 DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
324 memset(&state->mode, 0, sizeof(state->mode));
325 state->enable = false;
326 DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
332 EXPORT_SYMBOL(drm_atomic_set_mode_for_crtc);
335 * drm_atomic_set_mode_prop_for_crtc - set mode for CRTC
336 * @state: the CRTC whose incoming state to update
337 * @blob: pointer to blob property to use for mode
339 * Set a mode (originating from a blob property) on the desired CRTC state.
340 * This function will take a reference on the blob property for the CRTC state,
341 * and release the reference held on the state's existing mode property, if any
345 * Zero on success, error code on failure. Cannot return -EDEADLK.
347 int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
348 struct drm_property_blob *blob)
350 if (blob == state->mode_blob)
353 drm_property_unreference_blob(state->mode_blob);
354 state->mode_blob = NULL;
357 if (blob->length != sizeof(struct drm_mode_modeinfo) ||
358 drm_mode_convert_umode(&state->mode,
359 (const struct drm_mode_modeinfo *)
363 state->mode_blob = drm_property_reference_blob(blob);
364 state->enable = true;
365 DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
366 state->mode.name, state);
368 memset(&state->mode, 0, sizeof(state->mode));
369 state->enable = false;
370 DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
376 EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc);
379 * drm_atomic_crtc_set_property - set property on CRTC
380 * @crtc: the drm CRTC to set a property on
381 * @state: the state object to update with the new property value
382 * @property: the property to set
383 * @val: the new property value
385 * Use this instead of calling crtc->atomic_set_property directly.
386 * This function handles generic/core properties and calls out to
387 * driver's ->atomic_set_property() for driver properties. To ensure
388 * consistent behavior you must call this function rather than the
389 * driver hook directly.
392 * Zero on success, error code on failure
394 int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
395 struct drm_crtc_state *state, struct drm_property *property,
398 struct drm_device *dev = crtc->dev;
399 struct drm_mode_config *config = &dev->mode_config;
402 if (property == config->prop_active)
404 else if (property == config->prop_mode_id) {
405 struct drm_property_blob *mode =
406 drm_property_lookup_blob(dev, val);
407 ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
408 drm_property_unreference_blob(mode);
411 else if (crtc->funcs->atomic_set_property)
412 return crtc->funcs->atomic_set_property(crtc, state, property, val);
418 EXPORT_SYMBOL(drm_atomic_crtc_set_property);
421 * drm_atomic_crtc_get_property - get property value from CRTC state
422 * @crtc: the drm CRTC to set a property on
423 * @state: the state object to get the property value from
424 * @property: the property to set
425 * @val: return location for the property value
427 * This function handles generic/core properties and calls out to
428 * driver's ->atomic_get_property() for driver properties. To ensure
429 * consistent behavior you must call this function rather than the
430 * driver hook directly.
433 * Zero on success, error code on failure
436 drm_atomic_crtc_get_property(struct drm_crtc *crtc,
437 const struct drm_crtc_state *state,
438 struct drm_property *property, uint64_t *val)
440 struct drm_device *dev = crtc->dev;
441 struct drm_mode_config *config = &dev->mode_config;
443 if (property == config->prop_active)
444 *val = state->active;
445 else if (property == config->prop_mode_id)
446 *val = (state->mode_blob) ? state->mode_blob->base.id : 0;
447 else if (crtc->funcs->atomic_get_property)
448 return crtc->funcs->atomic_get_property(crtc, state, property, val);
456 * drm_atomic_crtc_check - check crtc state
457 * @crtc: crtc to check
458 * @state: crtc state to check
460 * Provides core sanity checks for crtc state.
463 * Zero on success, error code on failure
465 static int drm_atomic_crtc_check(struct drm_crtc *crtc,
466 struct drm_crtc_state *state)
468 /* NOTE: we explicitly don't enforce constraints such as primary
469 * layer covering entire screen, since that is something we want
470 * to allow (on hw that supports it). For hw that does not, it
471 * should be checked in driver's crtc->atomic_check() vfunc.
473 * TODO: Add generic modeset state checks once we support those.
476 if (state->active && !state->enable) {
477 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active without enabled\n",
478 crtc->base.id, crtc->name);
482 /* The state->enable vs. state->mode_blob checks can be WARN_ON,
483 * as this is a kernel-internal detail that userspace should never
484 * be able to trigger. */
485 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
486 WARN_ON(state->enable && !state->mode_blob)) {
487 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled without mode blob\n",
488 crtc->base.id, crtc->name);
492 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
493 WARN_ON(!state->enable && state->mode_blob)) {
494 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled with mode blob\n",
495 crtc->base.id, crtc->name);
500 * Reject event generation for when a CRTC is off and stays off.
501 * It wouldn't be hard to implement this, but userspace has a track
502 * record of happily burning through 100% cpu (or worse, crash) when the
503 * display pipe is suspended. To avoid all that fun just reject updates
504 * that ask for events since likely that indicates a bug in the
505 * compositor's drawing loop. This is consistent with the vblank IOCTL
506 * and legacy page_flip IOCTL which also reject service on a disabled
509 if (state->event && !state->active && !crtc->state->active) {
510 DRM_DEBUG_ATOMIC("[CRTC:%d] requesting event but off\n",
519 * drm_atomic_get_plane_state - get plane state
520 * @state: global atomic state object
521 * @plane: plane to get state object for
523 * This function returns the plane state for the given plane, allocating it if
524 * needed. It will also grab the relevant plane lock to make sure that the state
529 * Either the allocated state or the error code encoded into the pointer. When
530 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
531 * entire atomic sequence must be restarted. All other errors are fatal.
533 struct drm_plane_state *
534 drm_atomic_get_plane_state(struct drm_atomic_state *state,
535 struct drm_plane *plane)
537 int ret, index = drm_plane_index(plane);
538 struct drm_plane_state *plane_state;
540 plane_state = drm_atomic_get_existing_plane_state(state, plane);
544 ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
548 plane_state = plane->funcs->atomic_duplicate_state(plane);
550 return ERR_PTR(-ENOMEM);
552 state->plane_states[index] = plane_state;
553 state->planes[index] = plane;
554 plane_state->state = state;
556 DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n",
557 plane->base.id, plane->name, plane_state, state);
559 if (plane_state->crtc) {
560 struct drm_crtc_state *crtc_state;
562 crtc_state = drm_atomic_get_crtc_state(state,
564 if (IS_ERR(crtc_state))
565 return ERR_CAST(crtc_state);
570 EXPORT_SYMBOL(drm_atomic_get_plane_state);
573 * drm_atomic_plane_set_property - set property on plane
574 * @plane: the drm plane to set a property on
575 * @state: the state object to update with the new property value
576 * @property: the property to set
577 * @val: the new property value
579 * Use this instead of calling plane->atomic_set_property directly.
580 * This function handles generic/core properties and calls out to
581 * driver's ->atomic_set_property() for driver properties. To ensure
582 * consistent behavior you must call this function rather than the
583 * driver hook directly.
586 * Zero on success, error code on failure
588 int drm_atomic_plane_set_property(struct drm_plane *plane,
589 struct drm_plane_state *state, struct drm_property *property,
592 struct drm_device *dev = plane->dev;
593 struct drm_mode_config *config = &dev->mode_config;
595 if (property == config->prop_fb_id) {
596 struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val);
597 drm_atomic_set_fb_for_plane(state, fb);
599 drm_framebuffer_unreference(fb);
600 } else if (property == config->prop_crtc_id) {
601 struct drm_crtc *crtc = drm_crtc_find(dev, val);
602 return drm_atomic_set_crtc_for_plane(state, crtc);
603 } else if (property == config->prop_crtc_x) {
604 state->crtc_x = U642I64(val);
605 } else if (property == config->prop_crtc_y) {
606 state->crtc_y = U642I64(val);
607 } else if (property == config->prop_crtc_w) {
609 } else if (property == config->prop_crtc_h) {
611 } else if (property == config->prop_src_x) {
613 } else if (property == config->prop_src_y) {
615 } else if (property == config->prop_src_w) {
617 } else if (property == config->prop_src_h) {
619 } else if (property == config->rotation_property) {
620 state->rotation = val;
621 } else if (plane->funcs->atomic_set_property) {
622 return plane->funcs->atomic_set_property(plane, state,
630 EXPORT_SYMBOL(drm_atomic_plane_set_property);
633 * drm_atomic_plane_get_property - get property value from plane state
634 * @plane: the drm plane to set a property on
635 * @state: the state object to get the property value from
636 * @property: the property to set
637 * @val: return location for the property value
639 * This function handles generic/core properties and calls out to
640 * driver's ->atomic_get_property() for driver properties. To ensure
641 * consistent behavior you must call this function rather than the
642 * driver hook directly.
645 * Zero on success, error code on failure
648 drm_atomic_plane_get_property(struct drm_plane *plane,
649 const struct drm_plane_state *state,
650 struct drm_property *property, uint64_t *val)
652 struct drm_device *dev = plane->dev;
653 struct drm_mode_config *config = &dev->mode_config;
655 if (property == config->prop_fb_id) {
656 *val = (state->fb) ? state->fb->base.id : 0;
657 } else if (property == config->prop_crtc_id) {
658 *val = (state->crtc) ? state->crtc->base.id : 0;
659 } else if (property == config->prop_crtc_x) {
660 *val = I642U64(state->crtc_x);
661 } else if (property == config->prop_crtc_y) {
662 *val = I642U64(state->crtc_y);
663 } else if (property == config->prop_crtc_w) {
664 *val = state->crtc_w;
665 } else if (property == config->prop_crtc_h) {
666 *val = state->crtc_h;
667 } else if (property == config->prop_src_x) {
669 } else if (property == config->prop_src_y) {
671 } else if (property == config->prop_src_w) {
673 } else if (property == config->prop_src_h) {
675 } else if (property == config->rotation_property) {
676 *val = state->rotation;
677 } else if (plane->funcs->atomic_get_property) {
678 return plane->funcs->atomic_get_property(plane, state, property, val);
687 plane_switching_crtc(struct drm_atomic_state *state,
688 struct drm_plane *plane,
689 struct drm_plane_state *plane_state)
691 if (!plane->state->crtc || !plane_state->crtc)
694 if (plane->state->crtc == plane_state->crtc)
697 /* This could be refined, but currently there's no helper or driver code
698 * to implement direct switching of active planes nor userspace to take
699 * advantage of more direct plane switching without the intermediate
706 * drm_atomic_plane_check - check plane state
707 * @plane: plane to check
708 * @state: plane state to check
710 * Provides core sanity checks for plane state.
713 * Zero on success, error code on failure
715 static int drm_atomic_plane_check(struct drm_plane *plane,
716 struct drm_plane_state *state)
718 unsigned int fb_width, fb_height;
721 /* either *both* CRTC and FB must be set, or neither */
722 if (WARN_ON(state->crtc && !state->fb)) {
723 DRM_DEBUG_ATOMIC("CRTC set but no FB\n");
725 } else if (WARN_ON(state->fb && !state->crtc)) {
726 DRM_DEBUG_ATOMIC("FB set but no CRTC\n");
730 /* if disabled, we don't care about the rest of the state: */
734 /* Check whether this plane is usable on this CRTC */
735 if (!(plane->possible_crtcs & drm_crtc_mask(state->crtc))) {
736 DRM_DEBUG_ATOMIC("Invalid crtc for plane\n");
740 /* Check whether this plane supports the fb pixel format. */
741 ret = drm_plane_check_pixel_format(plane, state->fb->pixel_format);
743 DRM_DEBUG_ATOMIC("Invalid pixel format %s\n",
744 drm_get_format_name(state->fb->pixel_format));
748 /* Give drivers some help against integer overflows */
749 if (state->crtc_w > INT_MAX ||
750 state->crtc_x > INT_MAX - (int32_t) state->crtc_w ||
751 state->crtc_h > INT_MAX ||
752 state->crtc_y > INT_MAX - (int32_t) state->crtc_h) {
753 DRM_DEBUG_ATOMIC("Invalid CRTC coordinates %ux%u+%d+%d\n",
754 state->crtc_w, state->crtc_h,
755 state->crtc_x, state->crtc_y);
759 fb_width = state->fb->width << 16;
760 fb_height = state->fb->height << 16;
762 /* Make sure source coordinates are inside the fb. */
763 if (state->src_w > fb_width ||
764 state->src_x > fb_width - state->src_w ||
765 state->src_h > fb_height ||
766 state->src_y > fb_height - state->src_h) {
767 DRM_DEBUG_ATOMIC("Invalid source coordinates "
768 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
769 state->src_w >> 16, ((state->src_w & 0xffff) * 15625) >> 10,
770 state->src_h >> 16, ((state->src_h & 0xffff) * 15625) >> 10,
771 state->src_x >> 16, ((state->src_x & 0xffff) * 15625) >> 10,
772 state->src_y >> 16, ((state->src_y & 0xffff) * 15625) >> 10);
776 if (plane_switching_crtc(state->state, plane, state)) {
777 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n",
778 plane->base.id, plane->name);
786 * drm_atomic_get_connector_state - get connector state
787 * @state: global atomic state object
788 * @connector: connector to get state object for
790 * This function returns the connector state for the given connector,
791 * allocating it if needed. It will also grab the relevant connector lock to
792 * make sure that the state is consistent.
796 * Either the allocated state or the error code encoded into the pointer. When
797 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
798 * entire atomic sequence must be restarted. All other errors are fatal.
800 struct drm_connector_state *
801 drm_atomic_get_connector_state(struct drm_atomic_state *state,
802 struct drm_connector *connector)
805 struct drm_mode_config *config = &connector->dev->mode_config;
806 struct drm_connector_state *connector_state;
808 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
812 index = drm_connector_index(connector);
814 if (index >= state->num_connector) {
815 struct drm_connector **c;
816 struct drm_connector_state **cs;
817 int alloc = max(index + 1, config->num_connector);
819 c = krealloc(state->connectors, alloc * sizeof(*state->connectors), GFP_KERNEL);
821 return ERR_PTR(-ENOMEM);
823 state->connectors = c;
824 memset(&state->connectors[state->num_connector], 0,
825 sizeof(*state->connectors) * (alloc - state->num_connector));
827 cs = krealloc(state->connector_states, alloc * sizeof(*state->connector_states), GFP_KERNEL);
829 return ERR_PTR(-ENOMEM);
831 state->connector_states = cs;
832 memset(&state->connector_states[state->num_connector], 0,
833 sizeof(*state->connector_states) * (alloc - state->num_connector));
834 state->num_connector = alloc;
837 if (state->connector_states[index])
838 return state->connector_states[index];
840 connector_state = connector->funcs->atomic_duplicate_state(connector);
841 if (!connector_state)
842 return ERR_PTR(-ENOMEM);
844 state->connector_states[index] = connector_state;
845 state->connectors[index] = connector;
846 connector_state->state = state;
848 DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d] %p state to %p\n",
849 connector->base.id, connector_state, state);
851 if (connector_state->crtc) {
852 struct drm_crtc_state *crtc_state;
854 crtc_state = drm_atomic_get_crtc_state(state,
855 connector_state->crtc);
856 if (IS_ERR(crtc_state))
857 return ERR_CAST(crtc_state);
860 return connector_state;
862 EXPORT_SYMBOL(drm_atomic_get_connector_state);
865 * drm_atomic_connector_set_property - set property on connector.
866 * @connector: the drm connector to set a property on
867 * @state: the state object to update with the new property value
868 * @property: the property to set
869 * @val: the new property value
871 * Use this instead of calling connector->atomic_set_property directly.
872 * This function handles generic/core properties and calls out to
873 * driver's ->atomic_set_property() for driver properties. To ensure
874 * consistent behavior you must call this function rather than the
875 * driver hook directly.
878 * Zero on success, error code on failure
880 int drm_atomic_connector_set_property(struct drm_connector *connector,
881 struct drm_connector_state *state, struct drm_property *property,
884 struct drm_device *dev = connector->dev;
885 struct drm_mode_config *config = &dev->mode_config;
887 if (property == config->prop_crtc_id) {
888 struct drm_crtc *crtc = drm_crtc_find(dev, val);
889 return drm_atomic_set_crtc_for_connector(state, crtc);
890 } else if (property == config->dpms_property) {
891 /* setting DPMS property requires special handling, which
892 * is done in legacy setprop path for us. Disallow (for
893 * now?) atomic writes to DPMS property:
896 } else if (connector->funcs->atomic_set_property) {
897 return connector->funcs->atomic_set_property(connector,
898 state, property, val);
903 EXPORT_SYMBOL(drm_atomic_connector_set_property);
906 * drm_atomic_connector_get_property - get property value from connector state
907 * @connector: the drm connector to set a property on
908 * @state: the state object to get the property value from
909 * @property: the property to set
910 * @val: return location for the property value
912 * This function handles generic/core properties and calls out to
913 * driver's ->atomic_get_property() for driver properties. To ensure
914 * consistent behavior you must call this function rather than the
915 * driver hook directly.
918 * Zero on success, error code on failure
921 drm_atomic_connector_get_property(struct drm_connector *connector,
922 const struct drm_connector_state *state,
923 struct drm_property *property, uint64_t *val)
925 struct drm_device *dev = connector->dev;
926 struct drm_mode_config *config = &dev->mode_config;
928 if (property == config->prop_crtc_id) {
929 *val = (state->crtc) ? state->crtc->base.id : 0;
930 } else if (property == config->dpms_property) {
931 *val = connector->dpms;
932 } else if (connector->funcs->atomic_get_property) {
933 return connector->funcs->atomic_get_property(connector,
934 state, property, val);
942 int drm_atomic_get_property(struct drm_mode_object *obj,
943 struct drm_property *property, uint64_t *val)
945 struct drm_device *dev = property->dev;
949 case DRM_MODE_OBJECT_CONNECTOR: {
950 struct drm_connector *connector = obj_to_connector(obj);
951 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
952 ret = drm_atomic_connector_get_property(connector,
953 connector->state, property, val);
956 case DRM_MODE_OBJECT_CRTC: {
957 struct drm_crtc *crtc = obj_to_crtc(obj);
958 WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
959 ret = drm_atomic_crtc_get_property(crtc,
960 crtc->state, property, val);
963 case DRM_MODE_OBJECT_PLANE: {
964 struct drm_plane *plane = obj_to_plane(obj);
965 WARN_ON(!drm_modeset_is_locked(&plane->mutex));
966 ret = drm_atomic_plane_get_property(plane,
967 plane->state, property, val);
979 * drm_atomic_set_crtc_for_plane - set crtc for plane
980 * @plane_state: the plane whose incoming state to update
981 * @crtc: crtc to use for the plane
983 * Changing the assigned crtc for a plane requires us to grab the lock and state
984 * for the new crtc, as needed. This function takes care of all these details
985 * besides updating the pointer in the state object itself.
988 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
989 * then the w/w mutex code has detected a deadlock and the entire atomic
990 * sequence must be restarted. All other errors are fatal.
993 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
994 struct drm_crtc *crtc)
996 struct drm_plane *plane = plane_state->plane;
997 struct drm_crtc_state *crtc_state;
999 if (plane_state->crtc) {
1000 crtc_state = drm_atomic_get_crtc_state(plane_state->state,
1002 if (WARN_ON(IS_ERR(crtc_state)))
1003 return PTR_ERR(crtc_state);
1005 crtc_state->plane_mask &= ~(1 << drm_plane_index(plane));
1008 plane_state->crtc = crtc;
1011 crtc_state = drm_atomic_get_crtc_state(plane_state->state,
1013 if (IS_ERR(crtc_state))
1014 return PTR_ERR(crtc_state);
1015 crtc_state->plane_mask |= (1 << drm_plane_index(plane));
1019 DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d:%s]\n",
1020 plane_state, crtc->base.id, crtc->name);
1022 DRM_DEBUG_ATOMIC("Link plane state %p to [NOCRTC]\n",
1027 EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane);
1030 * drm_atomic_set_fb_for_plane - set framebuffer for plane
1031 * @plane_state: atomic state object for the plane
1032 * @fb: fb to use for the plane
1034 * Changing the assigned framebuffer for a plane requires us to grab a reference
1035 * to the new fb and drop the reference to the old fb, if there is one. This
1036 * function takes care of all these details besides updating the pointer in the
1037 * state object itself.
1040 drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
1041 struct drm_framebuffer *fb)
1043 if (plane_state->fb)
1044 drm_framebuffer_unreference(plane_state->fb);
1046 drm_framebuffer_reference(fb);
1047 plane_state->fb = fb;
1050 DRM_DEBUG_ATOMIC("Set [FB:%d] for plane state %p\n",
1051 fb->base.id, plane_state);
1053 DRM_DEBUG_ATOMIC("Set [NOFB] for plane state %p\n",
1056 EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
1059 * drm_atomic_set_crtc_for_connector - set crtc for connector
1060 * @conn_state: atomic state object for the connector
1061 * @crtc: crtc to use for the connector
1063 * Changing the assigned crtc for a connector requires us to grab the lock and
1064 * state for the new crtc, as needed. This function takes care of all these
1065 * details besides updating the pointer in the state object itself.
1068 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1069 * then the w/w mutex code has detected a deadlock and the entire atomic
1070 * sequence must be restarted. All other errors are fatal.
1073 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
1074 struct drm_crtc *crtc)
1076 struct drm_crtc_state *crtc_state;
1078 if (conn_state->crtc && conn_state->crtc != crtc) {
1079 crtc_state = drm_atomic_get_existing_crtc_state(conn_state->state,
1082 crtc_state->connector_mask &=
1083 ~(1 << drm_connector_index(conn_state->connector));
1087 crtc_state = drm_atomic_get_crtc_state(conn_state->state, crtc);
1088 if (IS_ERR(crtc_state))
1089 return PTR_ERR(crtc_state);
1091 crtc_state->connector_mask |=
1092 1 << drm_connector_index(conn_state->connector);
1095 conn_state->crtc = crtc;
1098 DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d:%s]\n",
1099 conn_state, crtc->base.id, crtc->name);
1101 DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n",
1106 EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector);
1109 * drm_atomic_add_affected_connectors - add connectors for crtc
1110 * @state: atomic state
1113 * This function walks the current configuration and adds all connectors
1114 * currently using @crtc to the atomic configuration @state. Note that this
1115 * function must acquire the connection mutex. This can potentially cause
1116 * unneeded seralization if the update is just for the planes on one crtc. Hence
1117 * drivers and helpers should only call this when really needed (e.g. when a
1118 * full modeset needs to happen due to some change).
1121 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1122 * then the w/w mutex code has detected a deadlock and the entire atomic
1123 * sequence must be restarted. All other errors are fatal.
1126 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
1127 struct drm_crtc *crtc)
1129 struct drm_mode_config *config = &state->dev->mode_config;
1130 struct drm_connector *connector;
1131 struct drm_connector_state *conn_state;
1134 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
1138 DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d:%s] to %p\n",
1139 crtc->base.id, crtc->name, state);
1142 * Changed connectors are already in @state, so only need to look at the
1143 * current configuration.
1145 drm_for_each_connector(connector, state->dev) {
1146 if (connector->state->crtc != crtc)
1149 conn_state = drm_atomic_get_connector_state(state, connector);
1150 if (IS_ERR(conn_state))
1151 return PTR_ERR(conn_state);
1156 EXPORT_SYMBOL(drm_atomic_add_affected_connectors);
1159 * drm_atomic_add_affected_planes - add planes for crtc
1160 * @state: atomic state
1163 * This function walks the current configuration and adds all planes
1164 * currently used by @crtc to the atomic configuration @state. This is useful
1165 * when an atomic commit also needs to check all currently enabled plane on
1166 * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC
1167 * to avoid special code to force-enable all planes.
1169 * Since acquiring a plane state will always also acquire the w/w mutex of the
1170 * current CRTC for that plane (if there is any) adding all the plane states for
1171 * a CRTC will not reduce parallism of atomic updates.
1174 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1175 * then the w/w mutex code has detected a deadlock and the entire atomic
1176 * sequence must be restarted. All other errors are fatal.
1179 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
1180 struct drm_crtc *crtc)
1182 struct drm_plane *plane;
1184 WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc));
1186 drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) {
1187 struct drm_plane_state *plane_state =
1188 drm_atomic_get_plane_state(state, plane);
1190 if (IS_ERR(plane_state))
1191 return PTR_ERR(plane_state);
1195 EXPORT_SYMBOL(drm_atomic_add_affected_planes);
1198 * drm_atomic_legacy_backoff - locking backoff for legacy ioctls
1199 * @state: atomic state
1201 * This function should be used by legacy entry points which don't understand
1202 * -EDEADLK semantics. For simplicity this one will grab all modeset locks after
1203 * the slowpath completed.
1205 void drm_atomic_legacy_backoff(struct drm_atomic_state *state)
1210 drm_modeset_backoff(state->acquire_ctx);
1212 ret = drm_modeset_lock_all_ctx(state->dev, state->acquire_ctx);
1216 EXPORT_SYMBOL(drm_atomic_legacy_backoff);
1219 * drm_atomic_check_only - check whether a given config would work
1220 * @state: atomic configuration to check
1222 * Note that this function can return -EDEADLK if the driver needed to acquire
1223 * more locks but encountered a deadlock. The caller must then do the usual w/w
1224 * backoff dance and restart. All other errors are fatal.
1227 * 0 on success, negative error code on failure.
1229 int drm_atomic_check_only(struct drm_atomic_state *state)
1231 struct drm_device *dev = state->dev;
1232 struct drm_mode_config *config = &dev->mode_config;
1233 struct drm_plane *plane;
1234 struct drm_plane_state *plane_state;
1235 struct drm_crtc *crtc;
1236 struct drm_crtc_state *crtc_state;
1239 DRM_DEBUG_ATOMIC("checking %p\n", state);
1241 for_each_plane_in_state(state, plane, plane_state, i) {
1242 ret = drm_atomic_plane_check(plane, plane_state);
1244 DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic core check failed\n",
1245 plane->base.id, plane->name);
1250 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1251 ret = drm_atomic_crtc_check(crtc, crtc_state);
1253 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic core check failed\n",
1254 crtc->base.id, crtc->name);
1259 if (config->funcs->atomic_check)
1260 ret = config->funcs->atomic_check(state->dev, state);
1262 if (!state->allow_modeset) {
1263 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1264 if (drm_atomic_crtc_needs_modeset(crtc_state)) {
1265 DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requires full modeset\n",
1266 crtc->base.id, crtc->name);
1274 EXPORT_SYMBOL(drm_atomic_check_only);
1277 * drm_atomic_commit - commit configuration atomically
1278 * @state: atomic configuration to check
1280 * Note that this function can return -EDEADLK if the driver needed to acquire
1281 * more locks but encountered a deadlock. The caller must then do the usual w/w
1282 * backoff dance and restart. All other errors are fatal.
1284 * Also note that on successful execution ownership of @state is transferred
1285 * from the caller of this function to the function itself. The caller must not
1286 * free or in any other way access @state. If the function fails then the caller
1287 * must clean up @state itself.
1290 * 0 on success, negative error code on failure.
1292 int drm_atomic_commit(struct drm_atomic_state *state)
1294 struct drm_mode_config *config = &state->dev->mode_config;
1297 ret = drm_atomic_check_only(state);
1301 DRM_DEBUG_ATOMIC("commiting %p\n", state);
1303 return config->funcs->atomic_commit(state->dev, state, false);
1305 EXPORT_SYMBOL(drm_atomic_commit);
1308 * drm_atomic_async_commit - atomic&async configuration commit
1309 * @state: atomic configuration to check
1311 * Note that this function can return -EDEADLK if the driver needed to acquire
1312 * more locks but encountered a deadlock. The caller must then do the usual w/w
1313 * backoff dance and restart. All other errors are fatal.
1315 * Also note that on successful execution ownership of @state is transferred
1316 * from the caller of this function to the function itself. The caller must not
1317 * free or in any other way access @state. If the function fails then the caller
1318 * must clean up @state itself.
1321 * 0 on success, negative error code on failure.
1323 int drm_atomic_async_commit(struct drm_atomic_state *state)
1325 struct drm_mode_config *config = &state->dev->mode_config;
1328 ret = drm_atomic_check_only(state);
1332 DRM_DEBUG_ATOMIC("commiting %p asynchronously\n", state);
1334 return config->funcs->atomic_commit(state->dev, state, true);
1336 EXPORT_SYMBOL(drm_atomic_async_commit);
1339 * The big monstor ioctl
1342 static struct drm_pending_vblank_event *create_vblank_event(
1343 struct drm_device *dev, struct drm_file *file_priv, uint64_t user_data)
1345 struct drm_pending_vblank_event *e = NULL;
1346 unsigned long flags;
1348 spin_lock_irqsave(&dev->event_lock, flags);
1349 if (file_priv->event_space < sizeof e->event) {
1350 spin_unlock_irqrestore(&dev->event_lock, flags);
1353 file_priv->event_space -= sizeof e->event;
1354 spin_unlock_irqrestore(&dev->event_lock, flags);
1356 e = kzalloc(sizeof *e, GFP_KERNEL);
1358 spin_lock_irqsave(&dev->event_lock, flags);
1359 file_priv->event_space += sizeof e->event;
1360 spin_unlock_irqrestore(&dev->event_lock, flags);
1364 e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
1365 e->event.base.length = sizeof e->event;
1366 e->event.user_data = user_data;
1367 e->base.event = &e->event.base;
1368 e->base.file_priv = file_priv;
1369 e->base.destroy = (void (*) (struct drm_pending_event *)) kfree;
1375 static void destroy_vblank_event(struct drm_device *dev,
1376 struct drm_file *file_priv, struct drm_pending_vblank_event *e)
1378 unsigned long flags;
1380 spin_lock_irqsave(&dev->event_lock, flags);
1381 file_priv->event_space += sizeof e->event;
1382 spin_unlock_irqrestore(&dev->event_lock, flags);
1386 static int atomic_set_prop(struct drm_atomic_state *state,
1387 struct drm_mode_object *obj, struct drm_property *prop,
1388 uint64_t prop_value)
1390 struct drm_mode_object *ref;
1393 if (!drm_property_change_valid_get(prop, prop_value, &ref))
1396 switch (obj->type) {
1397 case DRM_MODE_OBJECT_CONNECTOR: {
1398 struct drm_connector *connector = obj_to_connector(obj);
1399 struct drm_connector_state *connector_state;
1401 connector_state = drm_atomic_get_connector_state(state, connector);
1402 if (IS_ERR(connector_state)) {
1403 ret = PTR_ERR(connector_state);
1407 ret = drm_atomic_connector_set_property(connector,
1408 connector_state, prop, prop_value);
1411 case DRM_MODE_OBJECT_CRTC: {
1412 struct drm_crtc *crtc = obj_to_crtc(obj);
1413 struct drm_crtc_state *crtc_state;
1415 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1416 if (IS_ERR(crtc_state)) {
1417 ret = PTR_ERR(crtc_state);
1421 ret = drm_atomic_crtc_set_property(crtc,
1422 crtc_state, prop, prop_value);
1425 case DRM_MODE_OBJECT_PLANE: {
1426 struct drm_plane *plane = obj_to_plane(obj);
1427 struct drm_plane_state *plane_state;
1429 plane_state = drm_atomic_get_plane_state(state, plane);
1430 if (IS_ERR(plane_state)) {
1431 ret = PTR_ERR(plane_state);
1435 ret = drm_atomic_plane_set_property(plane,
1436 plane_state, prop, prop_value);
1444 drm_property_change_valid_put(prop, ref);
1449 * drm_atomic_clean_old_fb -- Unset old_fb pointers and set plane->fb pointers.
1451 * @dev: drm device to check.
1452 * @plane_mask: plane mask for planes that were updated.
1453 * @ret: return value, can be -EDEADLK for a retry.
1455 * Before doing an update plane->old_fb is set to plane->fb,
1456 * but before dropping the locks old_fb needs to be set to NULL
1457 * and plane->fb updated. This is a common operation for each
1458 * atomic update, so this call is split off as a helper.
1460 void drm_atomic_clean_old_fb(struct drm_device *dev,
1461 unsigned plane_mask,
1464 struct drm_plane *plane;
1466 /* if succeeded, fixup legacy plane crtc/fb ptrs before dropping
1467 * locks (ie. while it is still safe to deref plane->state). We
1468 * need to do this here because the driver entry points cannot
1469 * distinguish between legacy and atomic ioctls.
1471 drm_for_each_plane_mask(plane, dev, plane_mask) {
1473 struct drm_framebuffer *new_fb = plane->state->fb;
1475 drm_framebuffer_reference(new_fb);
1477 plane->crtc = plane->state->crtc;
1480 drm_framebuffer_unreference(plane->old_fb);
1482 plane->old_fb = NULL;
1485 EXPORT_SYMBOL(drm_atomic_clean_old_fb);
1487 int drm_mode_atomic_ioctl(struct drm_device *dev,
1488 void *data, struct drm_file *file_priv)
1490 struct drm_mode_atomic *arg = data;
1491 uint32_t __user *objs_ptr = (uint32_t __user *)(unsigned long)(arg->objs_ptr);
1492 uint32_t __user *count_props_ptr = (uint32_t __user *)(unsigned long)(arg->count_props_ptr);
1493 uint32_t __user *props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr);
1494 uint64_t __user *prop_values_ptr = (uint64_t __user *)(unsigned long)(arg->prop_values_ptr);
1495 unsigned int copied_objs, copied_props;
1496 struct drm_atomic_state *state;
1497 struct drm_modeset_acquire_ctx ctx;
1498 struct drm_plane *plane;
1499 struct drm_crtc *crtc;
1500 struct drm_crtc_state *crtc_state;
1501 unsigned plane_mask;
1505 /* disallow for drivers not supporting atomic: */
1506 if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
1509 /* disallow for userspace that has not enabled atomic cap (even
1510 * though this may be a bit overkill, since legacy userspace
1511 * wouldn't know how to call this ioctl)
1513 if (!file_priv->atomic)
1516 if (arg->flags & ~DRM_MODE_ATOMIC_FLAGS)
1522 if ((arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) &&
1523 !dev->mode_config.async_page_flip)
1526 /* can't test and expect an event at the same time. */
1527 if ((arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) &&
1528 (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
1531 drm_modeset_acquire_init(&ctx, 0);
1533 state = drm_atomic_state_alloc(dev);
1537 state->acquire_ctx = &ctx;
1538 state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
1545 for (i = 0; i < arg->count_objs; i++) {
1546 uint32_t obj_id, count_props;
1547 struct drm_mode_object *obj;
1549 if (get_user(obj_id, objs_ptr + copied_objs)) {
1554 obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_ANY);
1555 if (!obj || !obj->properties) {
1560 if (get_user(count_props, count_props_ptr + copied_objs)) {
1567 for (j = 0; j < count_props; j++) {
1569 uint64_t prop_value;
1570 struct drm_property *prop;
1572 if (get_user(prop_id, props_ptr + copied_props)) {
1577 prop = drm_property_find(dev, prop_id);
1583 if (copy_from_user(&prop_value,
1584 prop_values_ptr + copied_props,
1585 sizeof(prop_value))) {
1590 ret = atomic_set_prop(state, obj, prop, prop_value);
1597 if (obj->type == DRM_MODE_OBJECT_PLANE && count_props &&
1598 !(arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
1599 plane = obj_to_plane(obj);
1600 plane_mask |= (1 << drm_plane_index(plane));
1601 plane->old_fb = plane->fb;
1605 if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
1606 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1607 struct drm_pending_vblank_event *e;
1609 e = create_vblank_event(dev, file_priv, arg->user_data);
1615 crtc_state->event = e;
1619 if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) {
1621 * Unlike commit, check_only does not clean up state.
1622 * Below we call drm_atomic_state_free for it.
1624 ret = drm_atomic_check_only(state);
1625 } else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) {
1626 ret = drm_atomic_async_commit(state);
1628 ret = drm_atomic_commit(state);
1632 drm_atomic_clean_old_fb(dev, plane_mask, ret);
1634 if (ret && arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
1636 * TEST_ONLY and PAGE_FLIP_EVENT are mutually exclusive,
1637 * if they weren't, this code should be called on success
1638 * for TEST_ONLY too.
1641 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1642 if (!crtc_state->event)
1645 destroy_vblank_event(dev, file_priv,
1650 if (ret == -EDEADLK) {
1651 drm_atomic_state_clear(state);
1652 drm_modeset_backoff(&ctx);
1656 if (ret || arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
1657 drm_atomic_state_free(state);
1659 drm_modeset_drop_locks(&ctx);
1660 drm_modeset_acquire_fini(&ctx);