Lines Matching +full:software +full:- +full:locked
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
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:
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
35 * to use &ww_mutex and acquire-contexts to avoid deadlocks. But because
37 * of extra utility/tracking out of our acquire-ctx. This is provided
40 * For basic principles of &ww_mutex, see: Documentation/locking/ww-mutex-design.rst
48 * if (ret == -EDEADLK) {
71 * On top of these per-object locks using &ww_mutex there's also an overall
129 * drm_modeset_lock_all - take all modeset locks
132 * This function takes all modeset locks, suitable where a more fine-grained
145 struct drm_mode_config *config = &dev->mode_config; in drm_modeset_lock_all()
153 mutex_lock(&config->mutex); in drm_modeset_lock_all()
160 if (ret == -EDEADLK) { in drm_modeset_lock_all()
169 ww_acquire_done(&ctx->ww_ctx); in drm_modeset_lock_all()
171 WARN_ON(config->acquire_ctx); in drm_modeset_lock_all()
177 config->acquire_ctx = ctx; in drm_modeset_lock_all()
184 * drm_modeset_unlock_all - drop all modeset locks
199 struct drm_mode_config *config = &dev->mode_config; in drm_modeset_unlock_all()
200 struct drm_modeset_acquire_ctx *ctx = config->acquire_ctx; in drm_modeset_unlock_all()
205 config->acquire_ctx = NULL; in drm_modeset_unlock_all()
211 mutex_unlock(&dev->mode_config.mutex); in drm_modeset_unlock_all()
216 * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked
230 WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); in drm_warn_on_modeset_not_all_locked()
232 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); in drm_warn_on_modeset_not_all_locked()
233 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); in drm_warn_on_modeset_not_all_locked()
238 * drm_modeset_acquire_init - initialize acquire context
250 ww_acquire_init(&ctx->ww_ctx, &crtc_ww_class); in drm_modeset_acquire_init()
251 INIT_LIST_HEAD(&ctx->locked); in drm_modeset_acquire_init()
254 ctx->interruptible = true; in drm_modeset_acquire_init()
259 * drm_modeset_acquire_fini - cleanup acquire context
264 ww_acquire_fini(&ctx->ww_ctx); in drm_modeset_acquire_fini()
269 * drm_modeset_drop_locks - drop all locks
276 if (WARN_ON(ctx->contended)) in drm_modeset_drop_locks()
277 __drm_stack_depot_print(ctx->stack_depot); in drm_modeset_drop_locks()
279 while (!list_empty(&ctx->locked)) { in drm_modeset_drop_locks()
282 lock = list_first_entry(&ctx->locked, in drm_modeset_drop_locks()
296 if (WARN_ON(ctx->contended)) in modeset_lock()
297 __drm_stack_depot_print(ctx->stack_depot); in modeset_lock()
299 if (ctx->trylock_only) { in modeset_lock()
300 lockdep_assert_held(&ctx->ww_ctx); in modeset_lock()
302 if (!ww_mutex_trylock(&lock->mutex, NULL)) in modeset_lock()
303 return -EBUSY; in modeset_lock()
307 ret = ww_mutex_lock_slow_interruptible(&lock->mutex, &ctx->ww_ctx); in modeset_lock()
309 ret = ww_mutex_lock_interruptible(&lock->mutex, &ctx->ww_ctx); in modeset_lock()
311 ww_mutex_lock_slow(&lock->mutex, &ctx->ww_ctx); in modeset_lock()
314 ret = ww_mutex_lock(&lock->mutex, &ctx->ww_ctx); in modeset_lock()
317 WARN_ON(!list_empty(&lock->head)); in modeset_lock()
318 list_add(&lock->head, &ctx->locked); in modeset_lock()
319 } else if (ret == -EALREADY) { in modeset_lock()
322 * without having to keep track of what is already locked in modeset_lock()
326 } else if (ret == -EDEADLK) { in modeset_lock()
327 ctx->contended = lock; in modeset_lock()
328 ctx->stack_depot = __drm_stack_depot_save(); in modeset_lock()
335 * drm_modeset_backoff - deadlock avoidance backoff
338 * If deadlock is detected (ie. drm_modeset_lock() returns -EDEADLK),
342 * This function returns 0 on success, or -ERESTARTSYS if this context
348 struct drm_modeset_lock *contended = ctx->contended; in drm_modeset_backoff()
350 ctx->contended = NULL; in drm_modeset_backoff()
351 ctx->stack_depot = 0; in drm_modeset_backoff()
358 return modeset_lock(contended, ctx, ctx->interruptible, true); in drm_modeset_backoff()
363 * drm_modeset_lock_init - initialize lock
368 ww_mutex_init(&lock->mutex, &crtc_ww_class); in drm_modeset_lock_init()
369 INIT_LIST_HEAD(&lock->head); in drm_modeset_lock_init()
375 * drm_modeset_lock - take modeset lock
381 * drm_modeset_drop_locks(). If -EDEADLK is returned, this means a
387 * -ERESTARTSYS when interrupted.
390 * uninterruptible non-nesting mutex_lock() call.
396 return modeset_lock(lock, ctx, ctx->interruptible, false); in drm_modeset_lock()
398 ww_mutex_lock(&lock->mutex, NULL); in drm_modeset_lock()
404 * drm_modeset_lock_single_interruptible - take a single modeset lock
410 * This function returns 0 on success, or -ERESTARTSYS when interrupted.
414 return ww_mutex_lock_interruptible(&lock->mutex, NULL); in drm_modeset_lock_single_interruptible()
419 * drm_modeset_unlock - drop modeset lock
424 list_del_init(&lock->head); in drm_modeset_unlock()
425 ww_mutex_unlock(&lock->mutex); in drm_modeset_unlock()
430 * drm_modeset_lock_all_ctx - take all modeset locks
434 * This function takes all modeset locks, suitable where a more fine-grained
447 * Returns: 0 on success or a negative error-code on failure.
457 ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx); in drm_modeset_lock_all_ctx()
462 ret = drm_modeset_lock(&crtc->mutex, ctx); in drm_modeset_lock_all_ctx()
468 ret = drm_modeset_lock(&plane->mutex, ctx); in drm_modeset_lock_all_ctx()
474 ret = drm_modeset_lock(&privobj->lock, ctx); in drm_modeset_lock_all_ctx()