XenevaOS
Loading...
Searching...
No Matches
drm_modeset_lock.h
Go to the documentation of this file.
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/types.h> /* stackdepot.h is not self-contained */
28#include <linux/stackdepot.h>
29#include <linux/ww_mutex.h>
30
31struct drm_modeset_lock;
32
47
48 struct ww_acquire_ctx ww_ctx;
49
50 /*
51 * Contended lock: if a lock is contended you should only call
52 * drm_modeset_backoff() which drops locks and slow-locks the
53 * contended lock.
54 */
56
57 /*
58 * Stack depot for debugging when a contended lock was not backed off
59 * from.
60 */
62
63 /*
64 * list of held locks (drm_modeset_lock)
65 */
67
68 /*
69 * Trylock mode, use only for panic handlers!
70 */
72
73 /* Perform interruptible waits on this context. */
75};
76
86 /*
87 * modeset lock
88 */
89 struct ww_mutex mutex;
90
91 /*
92 * Resources that are locked as part of an atomic update are added
93 * to a list (so we know what to unlock at the end).
94 */
96};
97
98#define DRM_MODESET_ACQUIRE_INTERRUPTIBLE BIT(0)
99
105
107
112static inline void drm_modeset_lock_fini(struct drm_modeset_lock *lock)
113{
114 WARN_ON(!list_empty(&lock->head));
115}
116
121static inline bool drm_modeset_is_locked(struct drm_modeset_lock *lock)
122{
123 return ww_mutex_is_locked(&lock->mutex);
124}
125
130static inline void drm_modeset_lock_assert_held(struct drm_modeset_lock *lock)
131{
132 lockdep_assert_held(&lock->mutex.base);
133}
134
136 struct drm_modeset_acquire_ctx *ctx);
139
140struct drm_device;
141struct drm_crtc;
142struct drm_plane;
143
147
149 struct drm_modeset_acquire_ctx *ctx);
150
175#define DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, flags, ret) \
176 if (!drm_drv_uses_atomic_modeset(dev)) \
177 mutex_lock(&dev->mode_config.mutex); \
178 drm_modeset_acquire_init(&ctx, flags); \
179modeset_lock_retry: \
180 ret = drm_modeset_lock_all_ctx(dev, &ctx); \
181 if (ret) \
182 goto modeset_lock_fail;
183
203#define DRM_MODESET_LOCK_ALL_END(dev, ctx, ret) \
204modeset_lock_fail: \
205 if (ret == -EDEADLK) { \
206 ret = drm_modeset_backoff(&ctx); \
207 if (!ret) \
208 goto modeset_lock_retry; \
209 } \
210 drm_modeset_drop_locks(&ctx); \
211 drm_modeset_acquire_fini(&ctx); \
212 if (!drm_drv_uses_atomic_modeset(dev)) \
213 mutex_unlock(&dev->mode_config.mutex);
214
215#endif /* DRM_MODESET_LOCK_H_ */
uint8_t flags
Definition virtio.h:0
unsigned int uint32_t
Definition acefiex.h:163
#define __must_check
Definition compiler.h:114
int drm_modeset_backoff(struct drm_modeset_acquire_ctx *ctx)
int __must_check drm_modeset_lock_single_interruptible(struct drm_modeset_lock *lock)
void drm_modeset_acquire_init(struct drm_modeset_acquire_ctx *ctx, uint32_t flags)
void drm_modeset_lock_all(struct drm_device *dev)
void drm_modeset_unlock_all(struct drm_device *dev)
void drm_modeset_lock_init(struct drm_modeset_lock *lock)
void drm_warn_on_modeset_not_all_locked(struct drm_device *dev)
int drm_modeset_lock_all_ctx(struct drm_device *dev, struct drm_modeset_acquire_ctx *ctx)
void drm_modeset_unlock(struct drm_modeset_lock *lock)
void drm_modeset_acquire_fini(struct drm_modeset_acquire_ctx *ctx)
void drm_modeset_drop_locks(struct drm_modeset_acquire_ctx *ctx)
const struct device * dev
Definition drm_print.h:519
int const struct list_head const struct list_head struct list_head * head
Definition list_sort.h:13
#define lockdep_assert_held(l)
Definition lockdep.h:71
u32 depot_stack_handle_t
Definition stackdepot.h:15
Definition drm_crtc.h:955
Definition drm_device.h:75
Definition drm_modeset_lock.h:46
depot_stack_handle_t stack_depot
Definition drm_modeset_lock.h:61
bool trylock_only
Definition drm_modeset_lock.h:71
struct list_head locked
Definition drm_modeset_lock.h:66
struct ww_acquire_ctx ww_ctx
Definition drm_modeset_lock.h:48
struct drm_modeset_lock * contended
Definition drm_modeset_lock.h:55
bool interruptible
Definition drm_modeset_lock.h:74
Definition drm_modeset_lock.h:85
struct list_head head
Definition drm_modeset_lock.h:95
struct ww_mutex mutex
Definition drm_modeset_lock.h:89
Definition drm_plane.h:641
Definition list.h:11
Definition mutex.h:59