]>
Commit | Line | Data |
---|---|---|
51fd371b RC |
1 | /* |
2 | * Copyright (C) 2014 Red Hat | |
3 | * Author: Rob Clark <robdclark@gmail.com> | |
4 | * | |
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: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
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. | |
22 | */ | |
23 | ||
24 | #ifndef DRM_MODESET_LOCK_H_ | |
25 | #define DRM_MODESET_LOCK_H_ | |
26 | ||
27 | #include <linux/ww_mutex.h> | |
28 | ||
29 | struct drm_modeset_lock; | |
30 | ||
31 | /** | |
f3a80881 | 32 | * struct drm_modeset_acquire_ctx - locking context (see ww_acquire_ctx) |
51fd371b RC |
33 | * @ww_ctx: base acquire ctx |
34 | * @contended: used internally for -EDEADLK handling | |
35 | * @locked: list of held locks | |
b7a1aafd | 36 | * @trylock_only: trylock mode used in atomic contexts/panic notifiers |
6f8bcc74 | 37 | * @interruptible: whether interruptible locking should be used. |
51fd371b RC |
38 | * |
39 | * Each thread competing for a set of locks must use one acquire | |
40 | * ctx. And if any lock fxn returns -EDEADLK, it must backoff and | |
41 | * retry. | |
42 | */ | |
43 | struct drm_modeset_acquire_ctx { | |
44 | ||
45 | struct ww_acquire_ctx ww_ctx; | |
46 | ||
fe8660ac | 47 | /* |
51fd371b RC |
48 | * Contended lock: if a lock is contended you should only call |
49 | * drm_modeset_backoff() which drops locks and slow-locks the | |
50 | * contended lock. | |
51 | */ | |
52 | struct drm_modeset_lock *contended; | |
53 | ||
fe8660ac | 54 | /* |
51fd371b RC |
55 | * list of held locks (drm_modeset_lock) |
56 | */ | |
57 | struct list_head locked; | |
cb597bb3 | 58 | |
fe8660ac | 59 | /* |
cb597bb3 DV |
60 | * Trylock mode, use only for panic handlers! |
61 | */ | |
62 | bool trylock_only; | |
6f8bcc74 ML |
63 | |
64 | /* Perform interruptible waits on this context. */ | |
65 | bool interruptible; | |
51fd371b RC |
66 | }; |
67 | ||
68 | /** | |
f3a80881 | 69 | * struct drm_modeset_lock - used for locking modeset resources. |
51fd371b | 70 | * @mutex: resource locking |
d574528a | 71 | * @head: used to hold it's place on &drm_atomi_state.locked list when |
51fd371b RC |
72 | * part of an atomic update |
73 | * | |
74 | * Used for locking CRTCs and other modeset resources. | |
75 | */ | |
76 | struct drm_modeset_lock { | |
fe8660ac | 77 | /* |
51fd371b RC |
78 | * modeset lock |
79 | */ | |
80 | struct ww_mutex mutex; | |
81 | ||
fe8660ac | 82 | /* |
51fd371b RC |
83 | * Resources that are locked as part of an atomic update are added |
84 | * to a list (so we know what to unlock at the end). | |
85 | */ | |
86 | struct list_head head; | |
87 | }; | |
88 | ||
6f8bcc74 ML |
89 | #define DRM_MODESET_ACQUIRE_INTERRUPTIBLE BIT(0) |
90 | ||
51fd371b RC |
91 | void drm_modeset_acquire_init(struct drm_modeset_acquire_ctx *ctx, |
92 | uint32_t flags); | |
93 | void drm_modeset_acquire_fini(struct drm_modeset_acquire_ctx *ctx); | |
94 | void drm_modeset_drop_locks(struct drm_modeset_acquire_ctx *ctx); | |
6f8bcc74 | 95 | int drm_modeset_backoff(struct drm_modeset_acquire_ctx *ctx); |
51fd371b | 96 | |
35cf0350 | 97 | void drm_modeset_lock_init(struct drm_modeset_lock *lock); |
51fd371b RC |
98 | |
99 | /** | |
100 | * drm_modeset_lock_fini - cleanup lock | |
101 | * @lock: lock to cleanup | |
102 | */ | |
103 | static inline void drm_modeset_lock_fini(struct drm_modeset_lock *lock) | |
104 | { | |
105 | WARN_ON(!list_empty(&lock->head)); | |
106 | } | |
107 | ||
108 | /** | |
109 | * drm_modeset_is_locked - equivalent to mutex_is_locked() | |
110 | * @lock: lock to check | |
111 | */ | |
112 | static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock) | |
113 | { | |
114 | return ww_mutex_is_locked(&lock->mutex); | |
115 | } | |
116 | ||
117 | int drm_modeset_lock(struct drm_modeset_lock *lock, | |
118 | struct drm_modeset_acquire_ctx *ctx); | |
6f8bcc74 | 119 | int __must_check drm_modeset_lock_single_interruptible(struct drm_modeset_lock *lock); |
51fd371b RC |
120 | void drm_modeset_unlock(struct drm_modeset_lock *lock); |
121 | ||
122 | struct drm_device; | |
d059f652 | 123 | struct drm_crtc; |
4d02e2de | 124 | struct drm_plane; |
a6a8bb84 DV |
125 | |
126 | void drm_modeset_lock_all(struct drm_device *dev); | |
127 | void drm_modeset_unlock_all(struct drm_device *dev); | |
128 | void drm_warn_on_modeset_not_all_locked(struct drm_device *dev); | |
129 | ||
06eaae46 TR |
130 | int drm_modeset_lock_all_ctx(struct drm_device *dev, |
131 | struct drm_modeset_acquire_ctx *ctx); | |
51fd371b RC |
132 | |
133 | #endif /* DRM_MODESET_LOCK_H_ */ |