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>
33 static void kfree_state(struct drm_atomic_state
*state
)
35 kfree(state
->connectors
);
36 kfree(state
->connector_states
);
38 kfree(state
->crtc_states
);
40 kfree(state
->plane_states
);
45 * drm_atomic_state_alloc - allocate atomic state
48 * This allocates an empty atomic state to track updates.
50 struct drm_atomic_state
*
51 drm_atomic_state_alloc(struct drm_device
*dev
)
53 struct drm_atomic_state
*state
;
55 state
= kzalloc(sizeof(*state
), GFP_KERNEL
);
59 state
->num_connector
= ACCESS_ONCE(dev
->mode_config
.num_connector
);
61 state
->crtcs
= kcalloc(dev
->mode_config
.num_crtc
,
62 sizeof(*state
->crtcs
), GFP_KERNEL
);
65 state
->crtc_states
= kcalloc(dev
->mode_config
.num_crtc
,
66 sizeof(*state
->crtc_states
), GFP_KERNEL
);
67 if (!state
->crtc_states
)
69 state
->planes
= kcalloc(dev
->mode_config
.num_total_plane
,
70 sizeof(*state
->planes
), GFP_KERNEL
);
73 state
->plane_states
= kcalloc(dev
->mode_config
.num_total_plane
,
74 sizeof(*state
->plane_states
), GFP_KERNEL
);
75 if (!state
->plane_states
)
77 state
->connectors
= kcalloc(state
->num_connector
,
78 sizeof(*state
->connectors
),
80 if (!state
->connectors
)
82 state
->connector_states
= kcalloc(state
->num_connector
,
83 sizeof(*state
->connector_states
),
85 if (!state
->connector_states
)
90 DRM_DEBUG_KMS("Allocate atomic state %p\n", state
);
98 EXPORT_SYMBOL(drm_atomic_state_alloc
);
101 * drm_atomic_state_clear - clear state object
102 * @state: atomic state
104 * When the w/w mutex algorithm detects a deadlock we need to back off and drop
105 * all locks. So someone else could sneak in and change the current modeset
106 * configuration. Which means that all the state assembled in @state is no
107 * longer an atomic update to the current state, but to some arbitrary earlier
108 * state. Which could break assumptions the driver's ->atomic_check likely
111 * Hence we must clear all cached state and completely start over, using this
114 void drm_atomic_state_clear(struct drm_atomic_state
*state
)
116 struct drm_device
*dev
= state
->dev
;
117 struct drm_mode_config
*config
= &dev
->mode_config
;
120 DRM_DEBUG_KMS("Clearing atomic state %p\n", state
);
122 for (i
= 0; i
< state
->num_connector
; i
++) {
123 struct drm_connector
*connector
= state
->connectors
[i
];
128 WARN_ON(!drm_modeset_is_locked(&config
->connection_mutex
));
130 connector
->funcs
->atomic_destroy_state(connector
,
131 state
->connector_states
[i
]);
134 for (i
= 0; i
< config
->num_crtc
; i
++) {
135 struct drm_crtc
*crtc
= state
->crtcs
[i
];
140 crtc
->funcs
->atomic_destroy_state(crtc
,
141 state
->crtc_states
[i
]);
144 for (i
= 0; i
< config
->num_total_plane
; i
++) {
145 struct drm_plane
*plane
= state
->planes
[i
];
150 plane
->funcs
->atomic_destroy_state(plane
,
151 state
->plane_states
[i
]);
154 EXPORT_SYMBOL(drm_atomic_state_clear
);
157 * drm_atomic_state_free - free all memory for an atomic state
158 * @state: atomic state to deallocate
160 * This frees all memory associated with an atomic state, including all the
161 * per-object state for planes, crtcs and connectors.
163 void drm_atomic_state_free(struct drm_atomic_state
*state
)
165 drm_atomic_state_clear(state
);
167 DRM_DEBUG_KMS("Freeing atomic state %p\n", state
);
171 EXPORT_SYMBOL(drm_atomic_state_free
);
174 * drm_atomic_get_crtc_state - get crtc state
175 * @state: global atomic state object
176 * @crtc: crtc to get state object for
178 * This function returns the crtc state for the given crtc, allocating it if
179 * needed. It will also grab the relevant crtc lock to make sure that the state
184 * Either the allocated state or the error code encoded into the pointer. When
185 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
186 * entire atomic sequence must be restarted. All other errors are fatal.
188 struct drm_crtc_state
*
189 drm_atomic_get_crtc_state(struct drm_atomic_state
*state
,
190 struct drm_crtc
*crtc
)
193 struct drm_crtc_state
*crtc_state
;
195 index
= drm_crtc_index(crtc
);
197 if (state
->crtc_states
[index
])
198 return state
->crtc_states
[index
];
200 ret
= drm_modeset_lock(&crtc
->mutex
, state
->acquire_ctx
);
204 crtc_state
= crtc
->funcs
->atomic_duplicate_state(crtc
);
206 return ERR_PTR(-ENOMEM
);
208 state
->crtc_states
[index
] = crtc_state
;
209 state
->crtcs
[index
] = crtc
;
210 crtc_state
->state
= state
;
212 DRM_DEBUG_KMS("Added [CRTC:%d] %p state to %p\n",
213 crtc
->base
.id
, crtc_state
, state
);
217 EXPORT_SYMBOL(drm_atomic_get_crtc_state
);
220 * drm_atomic_crtc_set_property - set property on CRTC
221 * @crtc: the drm CRTC to set a property on
222 * @state: the state object to update with the new property value
223 * @property: the property to set
224 * @val: the new property value
226 * Use this instead of calling crtc->atomic_set_property directly.
227 * This function handles generic/core properties and calls out to
228 * driver's ->atomic_set_property() for driver properties. To ensure
229 * consistent behavior you must call this function rather than the
230 * driver hook directly.
233 * Zero on success, error code on failure
235 int drm_atomic_crtc_set_property(struct drm_crtc
*crtc
,
236 struct drm_crtc_state
*state
, struct drm_property
*property
,
239 if (crtc
->funcs
->atomic_set_property
)
240 return crtc
->funcs
->atomic_set_property(crtc
, state
, property
, val
);
243 EXPORT_SYMBOL(drm_atomic_crtc_set_property
);
246 * drm_atomic_crtc_get_property - get property on CRTC
247 * @crtc: the drm CRTC to get a property on
248 * @state: the state object with the property value to read
249 * @property: the property to get
250 * @val: the property value (returned by reference)
252 * Use this instead of calling crtc->atomic_get_property directly.
253 * This function handles generic/core properties and calls out to
254 * driver's ->atomic_get_property() for driver properties. To ensure
255 * consistent behavior you must call this function rather than the
256 * driver hook directly.
259 * Zero on success, error code on failure
261 int drm_atomic_crtc_get_property(struct drm_crtc
*crtc
,
262 const struct drm_crtc_state
*state
,
263 struct drm_property
*property
, uint64_t *val
)
265 if (crtc
->funcs
->atomic_get_property
)
266 return crtc
->funcs
->atomic_get_property(crtc
, state
, property
, val
);
269 EXPORT_SYMBOL(drm_atomic_crtc_get_property
);
272 * drm_atomic_get_plane_state - get plane state
273 * @state: global atomic state object
274 * @plane: plane to get state object for
276 * This function returns the plane state for the given plane, allocating it if
277 * needed. It will also grab the relevant plane lock to make sure that the state
282 * Either the allocated state or the error code encoded into the pointer. When
283 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
284 * entire atomic sequence must be restarted. All other errors are fatal.
286 struct drm_plane_state
*
287 drm_atomic_get_plane_state(struct drm_atomic_state
*state
,
288 struct drm_plane
*plane
)
291 struct drm_plane_state
*plane_state
;
293 index
= drm_plane_index(plane
);
295 if (state
->plane_states
[index
])
296 return state
->plane_states
[index
];
298 ret
= drm_modeset_lock(&plane
->mutex
, state
->acquire_ctx
);
302 plane_state
= plane
->funcs
->atomic_duplicate_state(plane
);
304 return ERR_PTR(-ENOMEM
);
306 state
->plane_states
[index
] = plane_state
;
307 state
->planes
[index
] = plane
;
308 plane_state
->state
= state
;
310 DRM_DEBUG_KMS("Added [PLANE:%d] %p state to %p\n",
311 plane
->base
.id
, plane_state
, state
);
313 if (plane_state
->crtc
) {
314 struct drm_crtc_state
*crtc_state
;
316 crtc_state
= drm_atomic_get_crtc_state(state
,
318 if (IS_ERR(crtc_state
))
319 return ERR_CAST(crtc_state
);
324 EXPORT_SYMBOL(drm_atomic_get_plane_state
);
327 * drm_atomic_plane_set_property - set property on plane
328 * @plane: the drm plane to set a property on
329 * @state: the state object to update with the new property value
330 * @property: the property to set
331 * @val: the new property value
333 * Use this instead of calling plane->atomic_set_property directly.
334 * This function handles generic/core properties and calls out to
335 * driver's ->atomic_set_property() for driver properties. To ensure
336 * consistent behavior you must call this function rather than the
337 * driver hook directly.
340 * Zero on success, error code on failure
342 int drm_atomic_plane_set_property(struct drm_plane
*plane
,
343 struct drm_plane_state
*state
, struct drm_property
*property
,
346 if (plane
->funcs
->atomic_set_property
)
347 return plane
->funcs
->atomic_set_property(plane
, state
, property
, val
);
350 EXPORT_SYMBOL(drm_atomic_plane_set_property
);
353 * drm_atomic_plane_get_property - get property on plane
354 * @plane: the drm plane to get a property on
355 * @state: the state object with the property value to read
356 * @property: the property to get
357 * @val: the property value (returned by reference)
359 * Use this instead of calling plane->atomic_get_property directly.
360 * This function handles generic/core properties and calls out to
361 * driver's ->atomic_get_property() for driver properties. To ensure
362 * consistent behavior you must call this function rather than the
363 * driver hook directly.
366 * Zero on success, error code on failure
368 int drm_atomic_plane_get_property(struct drm_plane
*plane
,
369 const struct drm_plane_state
*state
,
370 struct drm_property
*property
, uint64_t *val
)
372 if (plane
->funcs
->atomic_get_property
)
373 return plane
->funcs
->atomic_get_property(plane
, state
, property
, val
);
376 EXPORT_SYMBOL(drm_atomic_plane_get_property
);
379 * drm_atomic_get_connector_state - get connector state
380 * @state: global atomic state object
381 * @connector: connector to get state object for
383 * This function returns the connector state for the given connector,
384 * allocating it if needed. It will also grab the relevant connector lock to
385 * make sure that the state is consistent.
389 * Either the allocated state or the error code encoded into the pointer. When
390 * the error is EDEADLK then the w/w mutex code has detected a deadlock and the
391 * entire atomic sequence must be restarted. All other errors are fatal.
393 struct drm_connector_state
*
394 drm_atomic_get_connector_state(struct drm_atomic_state
*state
,
395 struct drm_connector
*connector
)
398 struct drm_mode_config
*config
= &connector
->dev
->mode_config
;
399 struct drm_connector_state
*connector_state
;
401 ret
= drm_modeset_lock(&config
->connection_mutex
, state
->acquire_ctx
);
405 index
= drm_connector_index(connector
);
408 * Construction of atomic state updates can race with a connector
409 * hot-add which might overflow. In this case flip the table and just
410 * restart the entire ioctl - no one is fast enough to livelock a cpu
411 * with physical hotplug events anyway.
413 * Note that we only grab the indexes once we have the right lock to
414 * prevent hotplug/unplugging of connectors. So removal is no problem,
415 * at most the array is a bit too large.
417 if (index
>= state
->num_connector
) {
418 DRM_DEBUG_KMS("Hot-added connector would overflow state array, restarting\n");
419 return ERR_PTR(-EAGAIN
);
422 if (state
->connector_states
[index
])
423 return state
->connector_states
[index
];
425 connector_state
= connector
->funcs
->atomic_duplicate_state(connector
);
426 if (!connector_state
)
427 return ERR_PTR(-ENOMEM
);
429 state
->connector_states
[index
] = connector_state
;
430 state
->connectors
[index
] = connector
;
431 connector_state
->state
= state
;
433 DRM_DEBUG_KMS("Added [CONNECTOR:%d] %p state to %p\n",
434 connector
->base
.id
, connector_state
, state
);
436 if (connector_state
->crtc
) {
437 struct drm_crtc_state
*crtc_state
;
439 crtc_state
= drm_atomic_get_crtc_state(state
,
440 connector_state
->crtc
);
441 if (IS_ERR(crtc_state
))
442 return ERR_CAST(crtc_state
);
445 return connector_state
;
447 EXPORT_SYMBOL(drm_atomic_get_connector_state
);
450 * drm_atomic_connector_set_property - set property on connector.
451 * @connector: the drm connector to set a property on
452 * @state: the state object to update with the new property value
453 * @property: the property to set
454 * @val: the new property value
456 * Use this instead of calling connector->atomic_set_property directly.
457 * This function handles generic/core properties and calls out to
458 * driver's ->atomic_set_property() for driver properties. To ensure
459 * consistent behavior you must call this function rather than the
460 * driver hook directly.
463 * Zero on success, error code on failure
465 int drm_atomic_connector_set_property(struct drm_connector
*connector
,
466 struct drm_connector_state
*state
, struct drm_property
*property
,
469 struct drm_device
*dev
= connector
->dev
;
470 struct drm_mode_config
*config
= &dev
->mode_config
;
472 if (property
== config
->dpms_property
) {
473 /* setting DPMS property requires special handling, which
474 * is done in legacy setprop path for us. Disallow (for
475 * now?) atomic writes to DPMS property:
478 } else if (connector
->funcs
->atomic_set_property
) {
479 return connector
->funcs
->atomic_set_property(connector
,
480 state
, property
, val
);
485 EXPORT_SYMBOL(drm_atomic_connector_set_property
);
488 * drm_atomic_connector_get_property - get property on connector
489 * @connector: the drm connector to get a property on
490 * @state: the state object with the property value to read
491 * @property: the property to get
492 * @val: the property value (returned by reference)
494 * Use this instead of calling connector->atomic_get_property directly.
495 * This function handles generic/core properties and calls out to
496 * driver's ->atomic_get_property() for driver properties. To ensure
497 * consistent behavior you must call this function rather than the
498 * driver hook directly.
501 * Zero on success, error code on failure
503 int drm_atomic_connector_get_property(struct drm_connector
*connector
,
504 const struct drm_connector_state
*state
,
505 struct drm_property
*property
, uint64_t *val
)
507 struct drm_device
*dev
= connector
->dev
;
508 struct drm_mode_config
*config
= &dev
->mode_config
;
510 if (property
== config
->dpms_property
) {
511 *val
= connector
->dpms
;
512 } else if (connector
->funcs
->atomic_get_property
) {
513 return connector
->funcs
->atomic_get_property(connector
,
514 state
, property
, val
);
521 EXPORT_SYMBOL(drm_atomic_connector_get_property
);
524 * drm_atomic_get_property - helper to read atomic property
525 * @obj: drm mode object whose property to read
526 * @property: the property to read
527 * @val: the read value, returned by reference
530 * Zero on success, error code on failure
532 int drm_atomic_get_property(struct drm_mode_object
*obj
,
533 struct drm_property
*property
, uint64_t *val
)
535 struct drm_device
*dev
= property
->dev
;
539 case DRM_MODE_OBJECT_CONNECTOR
: {
540 struct drm_connector
*connector
= obj_to_connector(obj
);
541 WARN_ON(!drm_modeset_is_locked(&dev
->mode_config
.connection_mutex
));
542 ret
= drm_atomic_connector_get_property(connector
,
543 connector
->state
, property
, val
);
546 case DRM_MODE_OBJECT_CRTC
: {
547 struct drm_crtc
*crtc
= obj_to_crtc(obj
);
548 WARN_ON(!drm_modeset_is_locked(&crtc
->mutex
));
549 ret
= drm_atomic_crtc_get_property(crtc
,
550 crtc
->state
, property
, val
);
553 case DRM_MODE_OBJECT_PLANE
: {
554 struct drm_plane
*plane
= obj_to_plane(obj
);
555 WARN_ON(!drm_modeset_is_locked(&plane
->mutex
));
556 ret
= drm_atomic_plane_get_property(plane
,
557 plane
->state
, property
, val
);
569 * drm_atomic_set_crtc_for_plane - set crtc for plane
570 * @plane_state: the plane whose incoming state to update
571 * @crtc: crtc to use for the plane
573 * Changing the assigned crtc for a plane requires us to grab the lock and state
574 * for the new crtc, as needed. This function takes care of all these details
575 * besides updating the pointer in the state object itself.
578 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
579 * then the w/w mutex code has detected a deadlock and the entire atomic
580 * sequence must be restarted. All other errors are fatal.
583 drm_atomic_set_crtc_for_plane(struct drm_plane_state
*plane_state
,
584 struct drm_crtc
*crtc
)
586 struct drm_plane
*plane
= plane_state
->plane
;
587 struct drm_crtc_state
*crtc_state
;
589 if (plane_state
->crtc
) {
590 crtc_state
= drm_atomic_get_crtc_state(plane_state
->state
,
592 if (WARN_ON(IS_ERR(crtc_state
)))
593 return PTR_ERR(crtc_state
);
595 crtc_state
->plane_mask
&= ~(1 << drm_plane_index(plane
));
598 plane_state
->crtc
= crtc
;
601 crtc_state
= drm_atomic_get_crtc_state(plane_state
->state
,
603 if (IS_ERR(crtc_state
))
604 return PTR_ERR(crtc_state
);
605 crtc_state
->plane_mask
|= (1 << drm_plane_index(plane
));
609 DRM_DEBUG_KMS("Link plane state %p to [CRTC:%d]\n",
610 plane_state
, crtc
->base
.id
);
612 DRM_DEBUG_KMS("Link plane state %p to [NOCRTC]\n", plane_state
);
616 EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane
);
619 * drm_atomic_set_fb_for_plane - set crtc for plane
620 * @plane_state: atomic state object for the plane
621 * @fb: fb to use for the plane
623 * Changing the assigned framebuffer for a plane requires us to grab a reference
624 * to the new fb and drop the reference to the old fb, if there is one. This
625 * function takes care of all these details besides updating the pointer in the
626 * state object itself.
629 drm_atomic_set_fb_for_plane(struct drm_plane_state
*plane_state
,
630 struct drm_framebuffer
*fb
)
633 drm_framebuffer_unreference(plane_state
->fb
);
635 drm_framebuffer_reference(fb
);
636 plane_state
->fb
= fb
;
639 DRM_DEBUG_KMS("Set [FB:%d] for plane state %p\n",
640 fb
->base
.id
, plane_state
);
642 DRM_DEBUG_KMS("Set [NOFB] for plane state %p\n", plane_state
);
644 EXPORT_SYMBOL(drm_atomic_set_fb_for_plane
);
647 * drm_atomic_set_crtc_for_connector - set crtc for connector
648 * @conn_state: atomic state object for the connector
649 * @crtc: crtc to use for the connector
651 * Changing the assigned crtc for a connector requires us to grab the lock and
652 * state for the new crtc, as needed. This function takes care of all these
653 * details besides updating the pointer in the state object itself.
656 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
657 * then the w/w mutex code has detected a deadlock and the entire atomic
658 * sequence must be restarted. All other errors are fatal.
661 drm_atomic_set_crtc_for_connector(struct drm_connector_state
*conn_state
,
662 struct drm_crtc
*crtc
)
664 struct drm_crtc_state
*crtc_state
;
667 crtc_state
= drm_atomic_get_crtc_state(conn_state
->state
, crtc
);
668 if (IS_ERR(crtc_state
))
669 return PTR_ERR(crtc_state
);
672 conn_state
->crtc
= crtc
;
675 DRM_DEBUG_KMS("Link connector state %p to [CRTC:%d]\n",
676 conn_state
, crtc
->base
.id
);
678 DRM_DEBUG_KMS("Link connector state %p to [NOCRTC]\n",
683 EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector
);
686 * drm_atomic_add_affected_connectors - add connectors for crtc
687 * @state: atomic state
690 * This function walks the current configuration and adds all connectors
691 * currently using @crtc to the atomic configuration @state. Note that this
692 * function must acquire the connection mutex. This can potentially cause
693 * unneeded seralization if the update is just for the planes on one crtc. Hence
694 * drivers and helpers should only call this when really needed (e.g. when a
695 * full modeset needs to happen due to some change).
698 * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK
699 * then the w/w mutex code has detected a deadlock and the entire atomic
700 * sequence must be restarted. All other errors are fatal.
703 drm_atomic_add_affected_connectors(struct drm_atomic_state
*state
,
704 struct drm_crtc
*crtc
)
706 struct drm_mode_config
*config
= &state
->dev
->mode_config
;
707 struct drm_connector
*connector
;
708 struct drm_connector_state
*conn_state
;
711 ret
= drm_modeset_lock(&config
->connection_mutex
, state
->acquire_ctx
);
715 DRM_DEBUG_KMS("Adding all current connectors for [CRTC:%d] to %p\n",
716 crtc
->base
.id
, state
);
719 * Changed connectors are already in @state, so only need to look at the
720 * current configuration.
722 list_for_each_entry(connector
, &config
->connector_list
, head
) {
723 if (connector
->state
->crtc
!= crtc
)
726 conn_state
= drm_atomic_get_connector_state(state
, connector
);
727 if (IS_ERR(conn_state
))
728 return PTR_ERR(conn_state
);
733 EXPORT_SYMBOL(drm_atomic_add_affected_connectors
);
736 * drm_atomic_connectors_for_crtc - count number of connected outputs
737 * @state: atomic state
740 * This function counts all connectors which will be connected to @crtc
741 * according to @state. Useful to recompute the enable state for @crtc.
744 drm_atomic_connectors_for_crtc(struct drm_atomic_state
*state
,
745 struct drm_crtc
*crtc
)
747 int i
, num_connected_connectors
= 0;
749 for (i
= 0; i
< state
->num_connector
; i
++) {
750 struct drm_connector_state
*conn_state
;
752 conn_state
= state
->connector_states
[i
];
754 if (conn_state
&& conn_state
->crtc
== crtc
)
755 num_connected_connectors
++;
758 DRM_DEBUG_KMS("State %p has %i connectors for [CRTC:%d]\n",
759 state
, num_connected_connectors
, crtc
->base
.id
);
761 return num_connected_connectors
;
763 EXPORT_SYMBOL(drm_atomic_connectors_for_crtc
);
766 * drm_atomic_legacy_backoff - locking backoff for legacy ioctls
767 * @state: atomic state
769 * This function should be used by legacy entry points which don't understand
770 * -EDEADLK semantics. For simplicity this one will grab all modeset locks after
771 * the slowpath completed.
773 void drm_atomic_legacy_backoff(struct drm_atomic_state
*state
)
778 drm_modeset_backoff(state
->acquire_ctx
);
780 ret
= drm_modeset_lock(&state
->dev
->mode_config
.connection_mutex
,
784 ret
= drm_modeset_lock_all_crtcs(state
->dev
,
789 EXPORT_SYMBOL(drm_atomic_legacy_backoff
);
792 * drm_atomic_check_only - check whether a given config would work
793 * @state: atomic configuration to check
795 * Note that this function can return -EDEADLK if the driver needed to acquire
796 * more locks but encountered a deadlock. The caller must then do the usual w/w
797 * backoff dance and restart. All other errors are fatal.
800 * 0 on success, negative error code on failure.
802 int drm_atomic_check_only(struct drm_atomic_state
*state
)
804 struct drm_mode_config
*config
= &state
->dev
->mode_config
;
806 DRM_DEBUG_KMS("checking %p\n", state
);
808 if (config
->funcs
->atomic_check
)
809 return config
->funcs
->atomic_check(state
->dev
, state
);
813 EXPORT_SYMBOL(drm_atomic_check_only
);
816 * drm_atomic_commit - commit configuration atomically
817 * @state: atomic configuration to check
819 * Note that this function can return -EDEADLK if the driver needed to acquire
820 * more locks but encountered a deadlock. The caller must then do the usual w/w
821 * backoff dance and restart. All other errors are fatal.
823 * Also note that on successful execution ownership of @state is transferred
824 * from the caller of this function to the function itself. The caller must not
825 * free or in any other way access @state. If the function fails then the caller
826 * must clean up @state itself.
829 * 0 on success, negative error code on failure.
831 int drm_atomic_commit(struct drm_atomic_state
*state
)
833 struct drm_mode_config
*config
= &state
->dev
->mode_config
;
836 ret
= drm_atomic_check_only(state
);
840 DRM_DEBUG_KMS("commiting %p\n", state
);
842 return config
->funcs
->atomic_commit(state
->dev
, state
, false);
844 EXPORT_SYMBOL(drm_atomic_commit
);
847 * drm_atomic_async_commit - atomic&async configuration commit
848 * @state: atomic configuration to check
850 * Note that this function can return -EDEADLK if the driver needed to acquire
851 * more locks but encountered a deadlock. The caller must then do the usual w/w
852 * backoff dance and restart. All other errors are fatal.
854 * Also note that on successful execution ownership of @state is transferred
855 * from the caller of this function to the function itself. The caller must not
856 * free or in any other way access @state. If the function fails then the caller
857 * must clean up @state itself.
860 * 0 on success, negative error code on failure.
862 int drm_atomic_async_commit(struct drm_atomic_state
*state
)
864 struct drm_mode_config
*config
= &state
->dev
->mode_config
;
867 ret
= drm_atomic_check_only(state
);
871 DRM_DEBUG_KMS("commiting %p asynchronously\n", state
);
873 return config
->funcs
->atomic_commit(state
->dev
, state
, true);
875 EXPORT_SYMBOL(drm_atomic_async_commit
);