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_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->num_connector = ACCESS_ONCE(dev->mode_config.num_connector);
70 state->crtcs = kcalloc(dev->mode_config.num_crtc,
71 sizeof(*state->crtcs), GFP_KERNEL);
74 state->crtc_states = kcalloc(dev->mode_config.num_crtc,
75 sizeof(*state->crtc_states), GFP_KERNEL);
76 if (!state->crtc_states)
78 state->planes = kcalloc(dev->mode_config.num_total_plane,
79 sizeof(*state->planes), GFP_KERNEL);
82 state->plane_states = kcalloc(dev->mode_config.num_total_plane,
83 sizeof(*state->plane_states), GFP_KERNEL);
84 if (!state->plane_states)
86 state->connectors = kcalloc(state->num_connector,
87 sizeof(*state->connectors),
89 if (!state->connectors)
91 state->connector_states = kcalloc(state->num_connector,
92 sizeof(*state->connector_states),
94 if (!state->connector_states)
99 DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state);
103 drm_atomic_state_default_release(state);
106 EXPORT_SYMBOL(drm_atomic_state_init);
109 * drm_atomic_state_alloc - allocate atomic state
112 * This allocates an empty atomic state to track updates.
114 struct drm_atomic_state *
115 drm_atomic_state_alloc(struct drm_device *dev)
117 struct drm_mode_config *config = &dev->mode_config;
118 struct drm_atomic_state *state;
120 if (!config->funcs->atomic_state_alloc) {
121 state = kzalloc(sizeof(*state), GFP_KERNEL);
124 if (drm_atomic_state_init(dev, state) < 0) {
131 return config->funcs->atomic_state_alloc(dev);
133 EXPORT_SYMBOL(drm_atomic_state_alloc);
136 * drm_atomic_state_default_clear - clear base atomic state
137 * @state: atomic state
139 * Default implementation for clearing atomic state.
140 * This is useful for drivers that subclass the atomic state.
142 void drm_atomic_state_default_clear(struct drm_atomic_state *state)
144 struct drm_device *dev = state->dev;
145 struct drm_mode_config *config = &dev->mode_config;
148 DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state);
150 for (i = 0; i < state->num_connector; i++) {
151 struct drm_connector *connector = state->connectors[i];
153 if (!connector || !connector->funcs)
157 * FIXME: Async commits can race with connector unplugging and
158 * there's currently nothing that prevents cleanup up state for
159 * deleted connectors. As long as the callback doesn't look at
160 * the connector we'll be fine though, so make sure that's the
161 * case by setting all connector pointers to NULL.
163 state->connector_states[i]->connector = NULL;
164 connector->funcs->atomic_destroy_state(NULL,
165 state->connector_states[i]);
166 state->connectors[i] = NULL;
167 state->connector_states[i] = NULL;
170 for (i = 0; i < config->num_crtc; i++) {
171 struct drm_crtc *crtc = state->crtcs[i];
176 crtc->funcs->atomic_destroy_state(crtc,
177 state->crtc_states[i]);
178 state->crtcs[i] = NULL;
179 state->crtc_states[i] = NULL;
182 for (i = 0; i < config->num_total_plane; i++) {
183 struct drm_plane *plane = state->planes[i];
188 plane->funcs->atomic_destroy_state(plane,
189 state->plane_states[i]);
190 state->planes[i] = NULL;
191 state->plane_states[i] = NULL;
194 EXPORT_SYMBOL(drm_atomic_state_default_clear);
197 * drm_atomic_state_clear - clear state object
198 * @state: atomic state
200 * When the w/w mutex algorithm detects a deadlock we need to back off and drop
201 * all locks. So someone else could sneak in and change the current modeset
202 * configuration. Which means that all the state assembled in @state is no
203 * longer an atomic update to the current state, but to some arbitrary earlier
204 * state. Which could break assumptions the driver's ->atomic_check likely
207 * Hence we must clear all cached state and completely start over, using this
210 void drm_atomic_state_clear(struct drm_atomic_state *state)
212 struct drm_device *dev = state->dev;
213 struct drm_mode_config *config = &dev->mode_config;
215 if (config->funcs->atomic_state_clear)
216 config->funcs->atomic_state_clear(state);
218 drm_atomic_state_default_clear(state);
220 EXPORT_SYMBOL(drm_atomic_state_clear);
223 * drm_atomic_state_free - free all memory for an atomic state
224 * @state: atomic state to deallocate
226 * This frees all memory associated with an atomic state, including all the
227 * per-object state for planes, crtcs and connectors.
229 void drm_atomic_state_free(struct drm_atomic_state *state)
231 struct drm_device *dev;
232 struct drm_mode_config *config;
238 config = &dev->mode_config;
240 drm_atomic_state_clear(state);
242 DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state);
244 if (config->funcs->atomic_state_free) {
245 config->funcs->atomic_state_free(state);
247 drm_atomic_state_default_release(state);
251 EXPORT_SYMBOL(drm_atomic_state_free);
254 * drm_atomic_get_crtc_state - get crtc state
255 * @state: global atomic state object
256 * @crtc: crtc to get state object for
258 * This function returns the crtc state for the given crtc, allocating it if
259 * needed. It will also grab the relevant crtc lock to make sure that the state
264 * Either the allocated state or the error code encoded into the pointer. When
265 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
266 * entire atomic sequence must be restarted. All other errors are fatal.
268 struct drm_crtc_state *
269 drm_atomic_get_crtc_state(struct drm_atomic_state *state,
270 struct drm_crtc *crtc)
272 int ret, index = drm_crtc_index(crtc);
273 struct drm_crtc_state *crtc_state;
275 crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
279 ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx);
283 crtc_state = crtc->funcs->atomic_duplicate_state(crtc);
285 return ERR_PTR(-ENOMEM);
287 state->crtc_states[index] = crtc_state;
288 state->crtcs[index] = crtc;
289 crtc_state->state = state;
291 DRM_DEBUG_ATOMIC("Added [CRTC:%d] %p state to %p\n",
292 crtc->base.id, crtc_state, state);
296 EXPORT_SYMBOL(drm_atomic_get_crtc_state);
299 * drm_atomic_set_mode_for_crtc - set mode for CRTC
300 * @state: the CRTC whose incoming state to update
301 * @mode: kernel-internal mode to use for the CRTC, or NULL to disable
303 * Set a mode (originating from the kernel) on the desired CRTC state. Does
304 * not change any other state properties, including enable, active, or
308 * Zero on success, error code on failure. Cannot return -EDEADLK.
310 int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
311 struct drm_display_mode *mode)
313 struct drm_mode_modeinfo umode;
315 /* Early return for no change. */
316 if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0)
319 if (state->mode_blob)
320 drm_property_unreference_blob(state->mode_blob);
321 state->mode_blob = NULL;
324 drm_mode_convert_to_umode(&umode, mode);
326 drm_property_create_blob(state->crtc->dev,
329 if (IS_ERR(state->mode_blob))
330 return PTR_ERR(state->mode_blob);
332 drm_mode_copy(&state->mode, mode);
333 state->enable = true;
334 DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
337 memset(&state->mode, 0, sizeof(state->mode));
338 state->enable = false;
339 DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
345 EXPORT_SYMBOL(drm_atomic_set_mode_for_crtc);
348 * drm_atomic_set_mode_prop_for_crtc - set mode for CRTC
349 * @state: the CRTC whose incoming state to update
350 * @blob: pointer to blob property to use for mode
352 * Set a mode (originating from a blob property) on the desired CRTC state.
353 * This function will take a reference on the blob property for the CRTC state,
354 * and release the reference held on the state's existing mode property, if any
358 * Zero on success, error code on failure. Cannot return -EDEADLK.
360 int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
361 struct drm_property_blob *blob)
363 if (blob == state->mode_blob)
366 if (state->mode_blob)
367 drm_property_unreference_blob(state->mode_blob);
368 state->mode_blob = NULL;
370 memset(&state->mode, 0, sizeof(state->mode));
373 if (blob->length != sizeof(struct drm_mode_modeinfo) ||
374 drm_mode_convert_umode(&state->mode,
375 (const struct drm_mode_modeinfo *)
379 state->mode_blob = drm_property_reference_blob(blob);
380 state->enable = true;
381 DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
382 state->mode.name, state);
384 state->enable = false;
385 DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n",
391 EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc);
394 * drm_atomic_crtc_set_property - set property on CRTC
395 * @crtc: the drm CRTC to set a property on
396 * @state: the state object to update with the new property value
397 * @property: the property to set
398 * @val: the new property value
400 * Use this instead of calling crtc->atomic_set_property directly.
401 * This function handles generic/core properties and calls out to
402 * driver's ->atomic_set_property() for driver properties. To ensure
403 * consistent behavior you must call this function rather than the
404 * driver hook directly.
407 * Zero on success, error code on failure
409 int drm_atomic_crtc_set_property(struct drm_crtc *crtc,
410 struct drm_crtc_state *state, struct drm_property *property,
413 struct drm_device *dev = crtc->dev;
414 struct drm_mode_config *config = &dev->mode_config;
417 if (property == config->prop_active)
419 else if (property == config->prop_mode_id) {
420 struct drm_property_blob *mode =
421 drm_property_lookup_blob(dev, val);
422 ret = drm_atomic_set_mode_prop_for_crtc(state, mode);
424 drm_property_unreference_blob(mode);
427 else if (crtc->funcs->atomic_set_property)
428 return crtc->funcs->atomic_set_property(crtc, state, property, val);
434 EXPORT_SYMBOL(drm_atomic_crtc_set_property);
437 * This function handles generic/core properties and calls out to
438 * driver's ->atomic_get_property() for driver properties. To ensure
439 * consistent behavior you must call this function rather than the
440 * driver hook directly.
443 drm_atomic_crtc_get_property(struct drm_crtc *crtc,
444 const struct drm_crtc_state *state,
445 struct drm_property *property, uint64_t *val)
447 struct drm_device *dev = crtc->dev;
448 struct drm_mode_config *config = &dev->mode_config;
450 if (property == config->prop_active)
451 *val = state->active;
452 else if (property == config->prop_mode_id)
453 *val = (state->mode_blob) ? state->mode_blob->base.id : 0;
454 else if (crtc->funcs->atomic_get_property)
455 return crtc->funcs->atomic_get_property(crtc, state, property, val);
463 * drm_atomic_crtc_check - check crtc state
464 * @crtc: crtc to check
465 * @state: crtc state to check
467 * Provides core sanity checks for crtc state.
470 * Zero on success, error code on failure
472 static int drm_atomic_crtc_check(struct drm_crtc *crtc,
473 struct drm_crtc_state *state)
475 /* NOTE: we explicitly don't enforce constraints such as primary
476 * layer covering entire screen, since that is something we want
477 * to allow (on hw that supports it). For hw that does not, it
478 * should be checked in driver's crtc->atomic_check() vfunc.
480 * TODO: Add generic modeset state checks once we support those.
483 if (state->active && !state->enable) {
484 DRM_DEBUG_ATOMIC("[CRTC:%d] active without enabled\n",
489 /* The state->enable vs. state->mode_blob checks can be WARN_ON,
490 * as this is a kernel-internal detail that userspace should never
491 * be able to trigger. */
492 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
493 WARN_ON(state->enable && !state->mode_blob)) {
494 DRM_DEBUG_ATOMIC("[CRTC:%d] enabled without mode blob\n",
499 if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) &&
500 WARN_ON(!state->enable && state->mode_blob)) {
501 DRM_DEBUG_ATOMIC("[CRTC:%d] disabled with mode blob\n",
510 * drm_atomic_get_plane_state - get plane state
511 * @state: global atomic state object
512 * @plane: plane to get state object for
514 * This function returns the plane state for the given plane, allocating it if
515 * needed. It will also grab the relevant plane lock to make sure that the state
520 * Either the allocated state or the error code encoded into the pointer. When
521 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
522 * entire atomic sequence must be restarted. All other errors are fatal.
524 struct drm_plane_state *
525 drm_atomic_get_plane_state(struct drm_atomic_state *state,
526 struct drm_plane *plane)
528 int ret, index = drm_plane_index(plane);
529 struct drm_plane_state *plane_state;
531 plane_state = drm_atomic_get_existing_plane_state(state, plane);
535 ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx);
539 plane_state = plane->funcs->atomic_duplicate_state(plane);
541 return ERR_PTR(-ENOMEM);
543 state->plane_states[index] = plane_state;
544 state->planes[index] = plane;
545 plane_state->state = state;
547 DRM_DEBUG_ATOMIC("Added [PLANE:%d] %p state to %p\n",
548 plane->base.id, plane_state, state);
550 if (plane_state->crtc) {
551 struct drm_crtc_state *crtc_state;
553 crtc_state = drm_atomic_get_crtc_state(state,
555 if (IS_ERR(crtc_state))
556 return ERR_CAST(crtc_state);
561 EXPORT_SYMBOL(drm_atomic_get_plane_state);
564 * drm_atomic_plane_set_property - set property on plane
565 * @plane: the drm plane to set a property on
566 * @state: the state object to update with the new property value
567 * @property: the property to set
568 * @val: the new property value
570 * Use this instead of calling plane->atomic_set_property directly.
571 * This function handles generic/core properties and calls out to
572 * driver's ->atomic_set_property() for driver properties. To ensure
573 * consistent behavior you must call this function rather than the
574 * driver hook directly.
577 * Zero on success, error code on failure
579 int drm_atomic_plane_set_property(struct drm_plane *plane,
580 struct drm_plane_state *state, struct drm_property *property,
583 struct drm_device *dev = plane->dev;
584 struct drm_mode_config *config = &dev->mode_config;
586 if (property == config->prop_fb_id) {
587 struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val);
588 drm_atomic_set_fb_for_plane(state, fb);
590 drm_framebuffer_unreference(fb);
591 } else if (property == config->prop_crtc_id) {
592 struct drm_crtc *crtc = drm_crtc_find(dev, val);
593 return drm_atomic_set_crtc_for_plane(state, crtc);
594 } else if (property == config->prop_crtc_x) {
595 state->crtc_x = U642I64(val);
596 } else if (property == config->prop_crtc_y) {
597 state->crtc_y = U642I64(val);
598 } else if (property == config->prop_crtc_w) {
600 } else if (property == config->prop_crtc_h) {
602 } else if (property == config->prop_src_x) {
604 } else if (property == config->prop_src_y) {
606 } else if (property == config->prop_src_w) {
608 } else if (property == config->prop_src_h) {
610 } else if (property == config->rotation_property) {
611 state->rotation = val;
612 } else if (plane->funcs->atomic_set_property) {
613 return plane->funcs->atomic_set_property(plane, state,
621 EXPORT_SYMBOL(drm_atomic_plane_set_property);
624 * This function handles generic/core properties and calls out to
625 * driver's ->atomic_get_property() for driver properties. To ensure
626 * consistent behavior you must call this function rather than the
627 * driver hook directly.
630 drm_atomic_plane_get_property(struct drm_plane *plane,
631 const struct drm_plane_state *state,
632 struct drm_property *property, uint64_t *val)
634 struct drm_device *dev = plane->dev;
635 struct drm_mode_config *config = &dev->mode_config;
637 if (property == config->prop_fb_id) {
638 *val = (state->fb) ? state->fb->base.id : 0;
639 } else if (property == config->prop_crtc_id) {
640 *val = (state->crtc) ? state->crtc->base.id : 0;
641 } else if (property == config->prop_crtc_x) {
642 *val = I642U64(state->crtc_x);
643 } else if (property == config->prop_crtc_y) {
644 *val = I642U64(state->crtc_y);
645 } else if (property == config->prop_crtc_w) {
646 *val = state->crtc_w;
647 } else if (property == config->prop_crtc_h) {
648 *val = state->crtc_h;
649 } else if (property == config->prop_src_x) {
651 } else if (property == config->prop_src_y) {
653 } else if (property == config->prop_src_w) {
655 } else if (property == config->prop_src_h) {
657 } else if (property == config->rotation_property) {
658 *val = state->rotation;
659 } else if (plane->funcs->atomic_get_property) {
660 return plane->funcs->atomic_get_property(plane, state, property, val);
669 plane_switching_crtc(struct drm_atomic_state *state,
670 struct drm_plane *plane,
671 struct drm_plane_state *plane_state)
673 if (!plane->state->crtc || !plane_state->crtc)
676 if (plane->state->crtc == plane_state->crtc)
679 /* This could be refined, but currently there's no helper or driver code
680 * to implement direct switching of active planes nor userspace to take
681 * advantage of more direct plane switching without the intermediate
688 * drm_atomic_plane_check - check plane state
689 * @plane: plane to check
690 * @state: plane state to check
692 * Provides core sanity checks for plane state.
695 * Zero on success, error code on failure
697 static int drm_atomic_plane_check(struct drm_plane *plane,
698 struct drm_plane_state *state)
700 unsigned int fb_width, fb_height;
703 /* either *both* CRTC and FB must be set, or neither */
704 if (WARN_ON(state->crtc && !state->fb)) {
705 DRM_DEBUG_ATOMIC("CRTC set but no FB\n");
707 } else if (WARN_ON(state->fb && !state->crtc)) {
708 DRM_DEBUG_ATOMIC("FB set but no CRTC\n");
712 /* if disabled, we don't care about the rest of the state: */
716 /* Check whether this plane is usable on this CRTC */
717 if (!(plane->possible_crtcs & drm_crtc_mask(state->crtc))) {
718 DRM_DEBUG_ATOMIC("Invalid crtc for plane\n");
722 /* Check whether this plane supports the fb pixel format. */
723 ret = drm_plane_check_pixel_format(plane, state->fb->pixel_format);
725 DRM_DEBUG_ATOMIC("Invalid pixel format %s\n",
726 drm_get_format_name(state->fb->pixel_format));
730 /* Give drivers some help against integer overflows */
731 if (state->crtc_w > INT_MAX ||
732 state->crtc_x > INT_MAX - (int32_t) state->crtc_w ||
733 state->crtc_h > INT_MAX ||
734 state->crtc_y > INT_MAX - (int32_t) state->crtc_h) {
735 DRM_DEBUG_ATOMIC("Invalid CRTC coordinates %ux%u+%d+%d\n",
736 state->crtc_w, state->crtc_h,
737 state->crtc_x, state->crtc_y);
741 fb_width = state->fb->width << 16;
742 fb_height = state->fb->height << 16;
744 /* Make sure source coordinates are inside the fb. */
745 if (state->src_w > fb_width ||
746 state->src_x > fb_width - state->src_w ||
747 state->src_h > fb_height ||
748 state->src_y > fb_height - state->src_h) {
749 DRM_DEBUG_ATOMIC("Invalid source coordinates "
750 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
751 state->src_w >> 16, ((state->src_w & 0xffff) * 15625) >> 10,
752 state->src_h >> 16, ((state->src_h & 0xffff) * 15625) >> 10,
753 state->src_x >> 16, ((state->src_x & 0xffff) * 15625) >> 10,
754 state->src_y >> 16, ((state->src_y & 0xffff) * 15625) >> 10);
758 if (plane_switching_crtc(state->state, plane, state)) {
759 DRM_DEBUG_ATOMIC("[PLANE:%d] switching CRTC directly\n",
768 * drm_atomic_get_connector_state - get connector state
769 * @state: global atomic state object
770 * @connector: connector to get state object for
772 * This function returns the connector state for the given connector,
773 * allocating it if needed. It will also grab the relevant connector lock to
774 * make sure that the state is consistent.
778 * Either the allocated state or the error code encoded into the pointer. When
779 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
780 * entire atomic sequence must be restarted. All other errors are fatal.
782 struct drm_connector_state *
783 drm_atomic_get_connector_state(struct drm_atomic_state *state,
784 struct drm_connector *connector)
787 struct drm_mode_config *config = &connector->dev->mode_config;
788 struct drm_connector_state *connector_state;
790 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
794 index = drm_connector_index(connector);
797 * Construction of atomic state updates can race with a connector
798 * hot-add which might overflow. In this case flip the table and just
799 * restart the entire ioctl - no one is fast enough to livelock a cpu
800 * with physical hotplug events anyway.
802 * Note that we only grab the indexes once we have the right lock to
803 * prevent hotplug/unplugging of connectors. So removal is no problem,
804 * at most the array is a bit too large.
806 if (index >= state->num_connector) {
807 DRM_DEBUG_ATOMIC("Hot-added connector would overflow state array, restarting\n");
808 return ERR_PTR(-EAGAIN);
811 if (state->connector_states[index])
812 return state->connector_states[index];
814 connector_state = connector->funcs->atomic_duplicate_state(connector);
815 if (!connector_state)
816 return ERR_PTR(-ENOMEM);
818 state->connector_states[index] = connector_state;
819 state->connectors[index] = connector;
820 connector_state->state = state;
822 DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d] %p state to %p\n",
823 connector->base.id, connector_state, state);
825 if (connector_state->crtc) {
826 struct drm_crtc_state *crtc_state;
828 crtc_state = drm_atomic_get_crtc_state(state,
829 connector_state->crtc);
830 if (IS_ERR(crtc_state))
831 return ERR_CAST(crtc_state);
834 return connector_state;
836 EXPORT_SYMBOL(drm_atomic_get_connector_state);
839 * drm_atomic_connector_set_property - set property on connector.
840 * @connector: the drm connector to set a property on
841 * @state: the state object to update with the new property value
842 * @property: the property to set
843 * @val: the new property value
845 * Use this instead of calling connector->atomic_set_property directly.
846 * This function handles generic/core properties and calls out to
847 * driver's ->atomic_set_property() for driver properties. To ensure
848 * consistent behavior you must call this function rather than the
849 * driver hook directly.
852 * Zero on success, error code on failure
854 int drm_atomic_connector_set_property(struct drm_connector *connector,
855 struct drm_connector_state *state, struct drm_property *property,
858 struct drm_device *dev = connector->dev;
859 struct drm_mode_config *config = &dev->mode_config;
861 if (property == config->prop_crtc_id) {
862 struct drm_crtc *crtc = drm_crtc_find(dev, val);
863 return drm_atomic_set_crtc_for_connector(state, crtc);
864 } else if (property == config->dpms_property) {
865 /* setting DPMS property requires special handling, which
866 * is done in legacy setprop path for us. Disallow (for
867 * now?) atomic writes to DPMS property:
870 } else if (connector->funcs->atomic_set_property) {
871 return connector->funcs->atomic_set_property(connector,
872 state, property, val);
877 EXPORT_SYMBOL(drm_atomic_connector_set_property);
880 * This function handles generic/core properties and calls out to
881 * driver's ->atomic_get_property() for driver properties. To ensure
882 * consistent behavior you must call this function rather than the
883 * driver hook directly.
886 drm_atomic_connector_get_property(struct drm_connector *connector,
887 const struct drm_connector_state *state,
888 struct drm_property *property, uint64_t *val)
890 struct drm_device *dev = connector->dev;
891 struct drm_mode_config *config = &dev->mode_config;
893 if (property == config->prop_crtc_id) {
894 *val = (state->crtc) ? state->crtc->base.id : 0;
895 } else if (property == config->dpms_property) {
896 *val = connector->dpms;
897 } else if (connector->funcs->atomic_get_property) {
898 return connector->funcs->atomic_get_property(connector,
899 state, property, val);
907 int drm_atomic_get_property(struct drm_mode_object *obj,
908 struct drm_property *property, uint64_t *val)
910 struct drm_device *dev = property->dev;
914 case DRM_MODE_OBJECT_CONNECTOR: {
915 struct drm_connector *connector = obj_to_connector(obj);
916 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
917 ret = drm_atomic_connector_get_property(connector,
918 connector->state, property, val);
921 case DRM_MODE_OBJECT_CRTC: {
922 struct drm_crtc *crtc = obj_to_crtc(obj);
923 WARN_ON(!drm_modeset_is_locked(&crtc->mutex));
924 ret = drm_atomic_crtc_get_property(crtc,
925 crtc->state, property, val);
928 case DRM_MODE_OBJECT_PLANE: {
929 struct drm_plane *plane = obj_to_plane(obj);
930 WARN_ON(!drm_modeset_is_locked(&plane->mutex));
931 ret = drm_atomic_plane_get_property(plane,
932 plane->state, property, val);
944 * drm_atomic_set_crtc_for_plane - set crtc for plane
945 * @plane_state: the plane whose incoming state to update
946 * @crtc: crtc to use for the plane
948 * Changing the assigned crtc for a plane requires us to grab the lock and state
949 * for the new crtc, as needed. This function takes care of all these details
950 * besides updating the pointer in the state object itself.
953 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
954 * then the w/w mutex code has detected a deadlock and the entire atomic
955 * sequence must be restarted. All other errors are fatal.
958 drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state,
959 struct drm_crtc *crtc)
961 struct drm_plane *plane = plane_state->plane;
962 struct drm_crtc_state *crtc_state;
964 if (plane_state->crtc) {
965 crtc_state = drm_atomic_get_crtc_state(plane_state->state,
967 if (WARN_ON(IS_ERR(crtc_state)))
968 return PTR_ERR(crtc_state);
970 crtc_state->plane_mask &= ~(1 << drm_plane_index(plane));
973 plane_state->crtc = crtc;
976 crtc_state = drm_atomic_get_crtc_state(plane_state->state,
978 if (IS_ERR(crtc_state))
979 return PTR_ERR(crtc_state);
980 crtc_state->plane_mask |= (1 << drm_plane_index(plane));
984 DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d]\n",
985 plane_state, crtc->base.id);
987 DRM_DEBUG_ATOMIC("Link plane state %p to [NOCRTC]\n",
992 EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane);
995 * drm_atomic_set_fb_for_plane - set framebuffer for plane
996 * @plane_state: atomic state object for the plane
997 * @fb: fb to use for the plane
999 * Changing the assigned framebuffer for a plane requires us to grab a reference
1000 * to the new fb and drop the reference to the old fb, if there is one. This
1001 * function takes care of all these details besides updating the pointer in the
1002 * state object itself.
1005 drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state,
1006 struct drm_framebuffer *fb)
1008 if (plane_state->fb)
1009 drm_framebuffer_unreference(plane_state->fb);
1011 drm_framebuffer_reference(fb);
1012 plane_state->fb = fb;
1015 DRM_DEBUG_ATOMIC("Set [FB:%d] for plane state %p\n",
1016 fb->base.id, plane_state);
1018 DRM_DEBUG_ATOMIC("Set [NOFB] for plane state %p\n",
1021 EXPORT_SYMBOL(drm_atomic_set_fb_for_plane);
1024 * drm_atomic_set_crtc_for_connector - set crtc for connector
1025 * @conn_state: atomic state object for the connector
1026 * @crtc: crtc to use for the connector
1028 * Changing the assigned crtc for a connector requires us to grab the lock and
1029 * state for the new crtc, as needed. This function takes care of all these
1030 * details besides updating the pointer in the state object itself.
1033 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1034 * then the w/w mutex code has detected a deadlock and the entire atomic
1035 * sequence must be restarted. All other errors are fatal.
1038 drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state,
1039 struct drm_crtc *crtc)
1041 struct drm_crtc_state *crtc_state;
1044 crtc_state = drm_atomic_get_crtc_state(conn_state->state, crtc);
1045 if (IS_ERR(crtc_state))
1046 return PTR_ERR(crtc_state);
1049 conn_state->crtc = crtc;
1052 DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d]\n",
1053 conn_state, crtc->base.id);
1055 DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n",
1060 EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector);
1063 * drm_atomic_add_affected_connectors - add connectors for crtc
1064 * @state: atomic state
1067 * This function walks the current configuration and adds all connectors
1068 * currently using @crtc to the atomic configuration @state. Note that this
1069 * function must acquire the connection mutex. This can potentially cause
1070 * unneeded seralization if the update is just for the planes on one crtc. Hence
1071 * drivers and helpers should only call this when really needed (e.g. when a
1072 * full modeset needs to happen due to some change).
1075 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1076 * then the w/w mutex code has detected a deadlock and the entire atomic
1077 * sequence must be restarted. All other errors are fatal.
1080 drm_atomic_add_affected_connectors(struct drm_atomic_state *state,
1081 struct drm_crtc *crtc)
1083 struct drm_mode_config *config = &state->dev->mode_config;
1084 struct drm_connector *connector;
1085 struct drm_connector_state *conn_state;
1088 ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx);
1092 DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d] to %p\n",
1093 crtc->base.id, state);
1096 * Changed connectors are already in @state, so only need to look at the
1097 * current configuration.
1099 drm_for_each_connector(connector, state->dev) {
1100 if (connector->state->crtc != crtc)
1103 conn_state = drm_atomic_get_connector_state(state, connector);
1104 if (IS_ERR(conn_state))
1105 return PTR_ERR(conn_state);
1110 EXPORT_SYMBOL(drm_atomic_add_affected_connectors);
1113 * drm_atomic_add_affected_planes - add planes for crtc
1114 * @state: atomic state
1117 * This function walks the current configuration and adds all planes
1118 * currently used by @crtc to the atomic configuration @state. This is useful
1119 * when an atomic commit also needs to check all currently enabled plane on
1120 * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC
1121 * to avoid special code to force-enable all planes.
1123 * Since acquiring a plane state will always also acquire the w/w mutex of the
1124 * current CRTC for that plane (if there is any) adding all the plane states for
1125 * a CRTC will not reduce parallism of atomic updates.
1128 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
1129 * then the w/w mutex code has detected a deadlock and the entire atomic
1130 * sequence must be restarted. All other errors are fatal.
1133 drm_atomic_add_affected_planes(struct drm_atomic_state *state,
1134 struct drm_crtc *crtc)
1136 struct drm_plane *plane;
1138 WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc));
1140 drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) {
1141 struct drm_plane_state *plane_state =
1142 drm_atomic_get_plane_state(state, plane);
1144 if (IS_ERR(plane_state))
1145 return PTR_ERR(plane_state);
1149 EXPORT_SYMBOL(drm_atomic_add_affected_planes);
1152 * drm_atomic_connectors_for_crtc - count number of connected outputs
1153 * @state: atomic state
1156 * This function counts all connectors which will be connected to @crtc
1157 * according to @state. Useful to recompute the enable state for @crtc.
1160 drm_atomic_connectors_for_crtc(struct drm_atomic_state *state,
1161 struct drm_crtc *crtc)
1163 struct drm_connector *connector;
1164 struct drm_connector_state *conn_state;
1166 int i, num_connected_connectors = 0;
1168 for_each_connector_in_state(state, connector, conn_state, i) {
1169 if (conn_state->crtc == crtc)
1170 num_connected_connectors++;
1173 DRM_DEBUG_ATOMIC("State %p has %i connectors for [CRTC:%d]\n",
1174 state, num_connected_connectors, crtc->base.id);
1176 return num_connected_connectors;
1178 EXPORT_SYMBOL(drm_atomic_connectors_for_crtc);
1181 * drm_atomic_legacy_backoff - locking backoff for legacy ioctls
1182 * @state: atomic state
1184 * This function should be used by legacy entry points which don't understand
1185 * -EDEADLK semantics. For simplicity this one will grab all modeset locks after
1186 * the slowpath completed.
1188 void drm_atomic_legacy_backoff(struct drm_atomic_state *state)
1193 drm_modeset_backoff(state->acquire_ctx);
1195 ret = drm_modeset_lock(&state->dev->mode_config.connection_mutex,
1196 state->acquire_ctx);
1199 ret = drm_modeset_lock_all_crtcs(state->dev,
1200 state->acquire_ctx);
1204 EXPORT_SYMBOL(drm_atomic_legacy_backoff);
1207 * drm_atomic_check_only - check whether a given config would work
1208 * @state: atomic configuration to check
1210 * Note that this function can return -EDEADLK if the driver needed to acquire
1211 * more locks but encountered a deadlock. The caller must then do the usual w/w
1212 * backoff dance and restart. All other errors are fatal.
1215 * 0 on success, negative error code on failure.
1217 int drm_atomic_check_only(struct drm_atomic_state *state)
1219 struct drm_device *dev = state->dev;
1220 struct drm_mode_config *config = &dev->mode_config;
1221 struct drm_plane *plane;
1222 struct drm_plane_state *plane_state;
1223 struct drm_crtc *crtc;
1224 struct drm_crtc_state *crtc_state;
1227 DRM_DEBUG_ATOMIC("checking %p\n", state);
1229 for_each_plane_in_state(state, plane, plane_state, i) {
1230 ret = drm_atomic_plane_check(plane, plane_state);
1232 DRM_DEBUG_ATOMIC("[PLANE:%d] atomic core check failed\n",
1238 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1239 ret = drm_atomic_crtc_check(crtc, crtc_state);
1241 DRM_DEBUG_ATOMIC("[CRTC:%d] atomic core check failed\n",
1247 if (config->funcs->atomic_check)
1248 ret = config->funcs->atomic_check(state->dev, state);
1253 if (!state->allow_modeset) {
1254 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1255 if (drm_atomic_crtc_needs_modeset(crtc_state)) {
1256 DRM_DEBUG_ATOMIC("[CRTC:%d] requires full modeset\n",
1265 EXPORT_SYMBOL(drm_atomic_check_only);
1268 * drm_atomic_commit - commit configuration atomically
1269 * @state: atomic configuration to check
1271 * Note that this function can return -EDEADLK if the driver needed to acquire
1272 * more locks but encountered a deadlock. The caller must then do the usual w/w
1273 * backoff dance and restart. All other errors are fatal.
1275 * Also note that on successful execution ownership of @state is transferred
1276 * from the caller of this function to the function itself. The caller must not
1277 * free or in any other way access @state. If the function fails then the caller
1278 * must clean up @state itself.
1281 * 0 on success, negative error code on failure.
1283 int drm_atomic_commit(struct drm_atomic_state *state)
1285 struct drm_mode_config *config = &state->dev->mode_config;
1288 ret = drm_atomic_check_only(state);
1292 DRM_DEBUG_ATOMIC("commiting %p\n", state);
1294 return config->funcs->atomic_commit(state->dev, state, false);
1296 EXPORT_SYMBOL(drm_atomic_commit);
1299 * drm_atomic_async_commit - atomic&async configuration commit
1300 * @state: atomic configuration to check
1302 * Note that this function can return -EDEADLK if the driver needed to acquire
1303 * more locks but encountered a deadlock. The caller must then do the usual w/w
1304 * backoff dance and restart. All other errors are fatal.
1306 * Also note that on successful execution ownership of @state is transferred
1307 * from the caller of this function to the function itself. The caller must not
1308 * free or in any other way access @state. If the function fails then the caller
1309 * must clean up @state itself.
1312 * 0 on success, negative error code on failure.
1314 int drm_atomic_async_commit(struct drm_atomic_state *state)
1316 struct drm_mode_config *config = &state->dev->mode_config;
1319 ret = drm_atomic_check_only(state);
1323 DRM_DEBUG_ATOMIC("commiting %p asynchronously\n", state);
1325 return config->funcs->atomic_commit(state->dev, state, true);
1327 EXPORT_SYMBOL(drm_atomic_async_commit);
1330 * The big monstor ioctl
1333 static struct drm_pending_vblank_event *create_vblank_event(
1334 struct drm_device *dev, struct drm_file *file_priv, uint64_t user_data)
1336 struct drm_pending_vblank_event *e = NULL;
1337 unsigned long flags;
1339 spin_lock_irqsave(&dev->event_lock, flags);
1340 if (file_priv->event_space < sizeof e->event) {
1341 spin_unlock_irqrestore(&dev->event_lock, flags);
1344 file_priv->event_space -= sizeof e->event;
1345 spin_unlock_irqrestore(&dev->event_lock, flags);
1347 e = kzalloc(sizeof *e, GFP_KERNEL);
1349 spin_lock_irqsave(&dev->event_lock, flags);
1350 file_priv->event_space += sizeof e->event;
1351 spin_unlock_irqrestore(&dev->event_lock, flags);
1355 e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
1356 e->event.base.length = sizeof e->event;
1357 e->event.user_data = user_data;
1358 e->base.event = &e->event.base;
1359 e->base.file_priv = file_priv;
1360 e->base.destroy = (void (*) (struct drm_pending_event *)) kfree;
1366 static void destroy_vblank_event(struct drm_device *dev,
1367 struct drm_file *file_priv, struct drm_pending_vblank_event *e)
1369 unsigned long flags;
1371 spin_lock_irqsave(&dev->event_lock, flags);
1372 file_priv->event_space += sizeof e->event;
1373 spin_unlock_irqrestore(&dev->event_lock, flags);
1377 static int atomic_set_prop(struct drm_atomic_state *state,
1378 struct drm_mode_object *obj, struct drm_property *prop,
1379 uint64_t prop_value)
1381 struct drm_mode_object *ref;
1384 if (!drm_property_change_valid_get(prop, prop_value, &ref))
1387 switch (obj->type) {
1388 case DRM_MODE_OBJECT_CONNECTOR: {
1389 struct drm_connector *connector = obj_to_connector(obj);
1390 struct drm_connector_state *connector_state;
1392 connector_state = drm_atomic_get_connector_state(state, connector);
1393 if (IS_ERR(connector_state)) {
1394 ret = PTR_ERR(connector_state);
1398 ret = drm_atomic_connector_set_property(connector,
1399 connector_state, prop, prop_value);
1402 case DRM_MODE_OBJECT_CRTC: {
1403 struct drm_crtc *crtc = obj_to_crtc(obj);
1404 struct drm_crtc_state *crtc_state;
1406 crtc_state = drm_atomic_get_crtc_state(state, crtc);
1407 if (IS_ERR(crtc_state)) {
1408 ret = PTR_ERR(crtc_state);
1412 ret = drm_atomic_crtc_set_property(crtc,
1413 crtc_state, prop, prop_value);
1416 case DRM_MODE_OBJECT_PLANE: {
1417 struct drm_plane *plane = obj_to_plane(obj);
1418 struct drm_plane_state *plane_state;
1420 plane_state = drm_atomic_get_plane_state(state, plane);
1421 if (IS_ERR(plane_state)) {
1422 ret = PTR_ERR(plane_state);
1426 ret = drm_atomic_plane_set_property(plane,
1427 plane_state, prop, prop_value);
1435 drm_property_change_valid_put(prop, ref);
1440 * drm_atomic_update_old_fb -- Unset old_fb pointers and set plane->fb pointers.
1442 * @dev: drm device to check.
1443 * @plane_mask: plane mask for planes that were updated.
1444 * @ret: return value, can be -EDEADLK for a retry.
1446 * Before doing an update plane->old_fb is set to plane->fb,
1447 * but before dropping the locks old_fb needs to be set to NULL
1448 * and plane->fb updated. This is a common operation for each
1449 * atomic update, so this call is split off as a helper.
1451 void drm_atomic_clean_old_fb(struct drm_device *dev,
1452 unsigned plane_mask,
1455 struct drm_plane *plane;
1457 /* if succeeded, fixup legacy plane crtc/fb ptrs before dropping
1458 * locks (ie. while it is still safe to deref plane->state). We
1459 * need to do this here because the driver entry points cannot
1460 * distinguish between legacy and atomic ioctls.
1462 drm_for_each_plane_mask(plane, dev, plane_mask) {
1464 struct drm_framebuffer *new_fb = plane->state->fb;
1466 drm_framebuffer_reference(new_fb);
1468 plane->crtc = plane->state->crtc;
1471 drm_framebuffer_unreference(plane->old_fb);
1473 plane->old_fb = NULL;
1476 EXPORT_SYMBOL(drm_atomic_clean_old_fb);
1478 int drm_mode_atomic_ioctl(struct drm_device *dev,
1479 void *data, struct drm_file *file_priv)
1481 struct drm_mode_atomic *arg = data;
1482 uint32_t __user *objs_ptr = (uint32_t __user *)(unsigned long)(arg->objs_ptr);
1483 uint32_t __user *count_props_ptr = (uint32_t __user *)(unsigned long)(arg->count_props_ptr);
1484 uint32_t __user *props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr);
1485 uint64_t __user *prop_values_ptr = (uint64_t __user *)(unsigned long)(arg->prop_values_ptr);
1486 unsigned int copied_objs, copied_props;
1487 struct drm_atomic_state *state;
1488 struct drm_modeset_acquire_ctx ctx;
1489 struct drm_plane *plane;
1490 struct drm_crtc *crtc;
1491 struct drm_crtc_state *crtc_state;
1492 unsigned plane_mask;
1496 /* disallow for drivers not supporting atomic: */
1497 if (!drm_core_check_feature(dev, DRIVER_ATOMIC))
1500 /* disallow for userspace that has not enabled atomic cap (even
1501 * though this may be a bit overkill, since legacy userspace
1502 * wouldn't know how to call this ioctl)
1504 if (!file_priv->atomic)
1507 if (arg->flags & ~DRM_MODE_ATOMIC_FLAGS)
1513 if ((arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) &&
1514 !dev->mode_config.async_page_flip)
1517 /* can't test and expect an event at the same time. */
1518 if ((arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) &&
1519 (arg->flags & DRM_MODE_PAGE_FLIP_EVENT))
1522 drm_modeset_acquire_init(&ctx, 0);
1524 state = drm_atomic_state_alloc(dev);
1528 state->acquire_ctx = &ctx;
1529 state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
1536 for (i = 0; i < arg->count_objs; i++) {
1537 uint32_t obj_id, count_props;
1538 struct drm_mode_object *obj;
1540 if (get_user(obj_id, objs_ptr + copied_objs)) {
1545 obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_ANY);
1546 if (!obj || !obj->properties) {
1551 if (get_user(count_props, count_props_ptr + copied_objs)) {
1558 for (j = 0; j < count_props; j++) {
1560 uint64_t prop_value;
1561 struct drm_property *prop;
1563 if (get_user(prop_id, props_ptr + copied_props)) {
1568 prop = drm_property_find(dev, prop_id);
1574 if (copy_from_user(&prop_value,
1575 prop_values_ptr + copied_props,
1576 sizeof(prop_value))) {
1581 ret = atomic_set_prop(state, obj, prop, prop_value);
1588 if (obj->type == DRM_MODE_OBJECT_PLANE && count_props &&
1589 !(arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)) {
1590 plane = obj_to_plane(obj);
1591 plane_mask |= (1 << drm_plane_index(plane));
1592 plane->old_fb = plane->fb;
1596 if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
1597 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1598 struct drm_pending_vblank_event *e;
1600 e = create_vblank_event(dev, file_priv, arg->user_data);
1606 crtc_state->event = e;
1610 if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) {
1612 * Unlike commit, check_only does not clean up state.
1613 * Below we call drm_atomic_state_free for it.
1615 ret = drm_atomic_check_only(state);
1616 } else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) {
1617 ret = drm_atomic_async_commit(state);
1619 ret = drm_atomic_commit(state);
1623 drm_atomic_clean_old_fb(dev, plane_mask, ret);
1625 if (ret && arg->flags & DRM_MODE_PAGE_FLIP_EVENT) {
1627 * TEST_ONLY and PAGE_FLIP_EVENT are mutually exclusive,
1628 * if they weren't, this code should be called on success
1629 * for TEST_ONLY too.
1632 for_each_crtc_in_state(state, crtc, crtc_state, i) {
1633 if (!crtc_state->event)
1636 destroy_vblank_event(dev, file_priv,
1641 if (ret == -EDEADLK) {
1642 drm_atomic_state_clear(state);
1643 drm_modeset_backoff(&ctx);
1647 if (ret || arg->flags & DRM_MODE_ATOMIC_TEST_ONLY)
1648 drm_atomic_state_free(state);
1650 drm_modeset_drop_locks(&ctx);
1651 drm_modeset_acquire_fini(&ctx);