Linux 4.1.18
[linux/fpc-iii.git] / include / drm / drm_modeset_lock.h
blob70595ff565baa45190faaae5c42630fe04a1beff
1 /*
2 * Copyright (C) 2014 Red Hat
3 * Author: Rob Clark <robdclark@gmail.com>
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 #ifndef DRM_MODESET_LOCK_H_
25 #define DRM_MODESET_LOCK_H_
27 #include <linux/ww_mutex.h>
29 struct drm_modeset_lock;
31 /**
32 * struct drm_modeset_acquire_ctx - locking context (see ww_acquire_ctx)
33 * @ww_ctx: base acquire ctx
34 * @contended: used internally for -EDEADLK handling
35 * @locked: list of held locks
36 * @trylock_only: trylock mode used in atomic contexts/panic notifiers
38 * Each thread competing for a set of locks must use one acquire
39 * ctx. And if any lock fxn returns -EDEADLK, it must backoff and
40 * retry.
42 struct drm_modeset_acquire_ctx {
44 struct ww_acquire_ctx ww_ctx;
46 /**
47 * Contended lock: if a lock is contended you should only call
48 * drm_modeset_backoff() which drops locks and slow-locks the
49 * contended lock.
51 struct drm_modeset_lock *contended;
53 /**
54 * list of held locks (drm_modeset_lock)
56 struct list_head locked;
58 /**
59 * Trylock mode, use only for panic handlers!
61 bool trylock_only;
64 /**
65 * struct drm_modeset_lock - used for locking modeset resources.
66 * @mutex: resource locking
67 * @head: used to hold it's place on state->locked list when
68 * part of an atomic update
70 * Used for locking CRTCs and other modeset resources.
72 struct drm_modeset_lock {
73 /**
74 * modeset lock
76 struct ww_mutex mutex;
78 /**
79 * Resources that are locked as part of an atomic update are added
80 * to a list (so we know what to unlock at the end).
82 struct list_head head;
85 extern struct ww_class crtc_ww_class;
87 void drm_modeset_acquire_init(struct drm_modeset_acquire_ctx *ctx,
88 uint32_t flags);
89 void drm_modeset_acquire_fini(struct drm_modeset_acquire_ctx *ctx);
90 void drm_modeset_drop_locks(struct drm_modeset_acquire_ctx *ctx);
91 void drm_modeset_backoff(struct drm_modeset_acquire_ctx *ctx);
92 int drm_modeset_backoff_interruptible(struct drm_modeset_acquire_ctx *ctx);
94 /**
95 * drm_modeset_lock_init - initialize lock
96 * @lock: lock to init
98 static inline void drm_modeset_lock_init(struct drm_modeset_lock *lock)
100 ww_mutex_init(&lock->mutex, &crtc_ww_class);
101 INIT_LIST_HEAD(&lock->head);
105 * drm_modeset_lock_fini - cleanup lock
106 * @lock: lock to cleanup
108 static inline void drm_modeset_lock_fini(struct drm_modeset_lock *lock)
110 WARN_ON(!list_empty(&lock->head));
114 * drm_modeset_is_locked - equivalent to mutex_is_locked()
115 * @lock: lock to check
117 static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)
119 return ww_mutex_is_locked(&lock->mutex);
122 int drm_modeset_lock(struct drm_modeset_lock *lock,
123 struct drm_modeset_acquire_ctx *ctx);
124 int drm_modeset_lock_interruptible(struct drm_modeset_lock *lock,
125 struct drm_modeset_acquire_ctx *ctx);
126 void drm_modeset_unlock(struct drm_modeset_lock *lock);
128 struct drm_device;
129 struct drm_crtc;
130 struct drm_plane;
132 void drm_modeset_lock_all(struct drm_device *dev);
133 int __drm_modeset_lock_all(struct drm_device *dev, bool trylock);
134 void drm_modeset_unlock_all(struct drm_device *dev);
135 void drm_modeset_lock_crtc(struct drm_crtc *crtc,
136 struct drm_plane *plane);
137 void drm_modeset_unlock_crtc(struct drm_crtc *crtc);
138 void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
139 struct drm_modeset_acquire_ctx *
140 drm_modeset_legacy_acquire_ctx(struct drm_crtc *crtc);
142 int drm_modeset_lock_all_crtcs(struct drm_device *dev,
143 struct drm_modeset_acquire_ctx *ctx);
145 #endif /* DRM_MODESET_LOCK_H_ */