XenevaOS
Loading...
Searching...
No Matches
dma-resv.h
Go to the documentation of this file.
1/*
2 * Header file for reservations for dma-buf and ttm
3 *
4 * Copyright(C) 2011 Linaro Limited. All rights reserved.
5 * Copyright (C) 2012-2013 Canonical Ltd
6 * Copyright (C) 2012 Texas Instruments
7 *
8 * Authors:
9 * Rob Clark <robdclark@gmail.com>
10 * Maarten Lankhorst <maarten.lankhorst@canonical.com>
11 * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
12 *
13 * Based on bo.c which bears the following copyright notice,
14 * but is dual licensed:
15 *
16 * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
17 * All Rights Reserved.
18 *
19 * Permission is hereby granted, free of charge, to any person obtaining a
20 * copy of this software and associated documentation files (the
21 * "Software"), to deal in the Software without restriction, including
22 * without limitation the rights to use, copy, modify, merge, publish,
23 * distribute, sub license, and/or sell copies of the Software, and to
24 * permit persons to whom the Software is furnished to do so, subject to
25 * the following conditions:
26 *
27 * The above copyright notice and this permission notice (including the
28 * next paragraph) shall be included in all copies or substantial portions
29 * of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
34 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
35 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
36 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
37 * USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39#ifndef _LINUX_RESERVATION_H
40#define _LINUX_RESERVATION_H
41
42#include <linux/ww_mutex.h>
43#include <linux/dma-fence.h>
44#include <linux/slab.h>
45#include <linux/seqlock.h>
46#include <linux/rcupdate.h>
47
48extern struct ww_class reservation_ww_class;
49
50struct dma_resv_list;
51
118
126static inline enum dma_resv_usage dma_resv_usage_rw(bool write)
127{
128 /* This looks confusing at first sight, but is indeed correct.
129 *
130 * The rational is that new write operations needs to wait for the
131 * existing read and write operations to finish.
132 * But a new read operation only needs to wait for the existing write
133 * operations to finish.
134 */
136}
137
155struct dma_resv {
166 struct ww_mutex lock;
167
178 struct dma_resv_list __rcu *fences;
179};
180
195 struct dma_resv *obj;
196
199
202
205
207 unsigned int index;
208
210 struct dma_resv_list *fences;
211
213 unsigned int num_fences;
214
217};
218
223
230static inline void dma_resv_iter_begin(struct dma_resv_iter *cursor,
231 struct dma_resv *obj,
232 enum dma_resv_usage usage)
233{
234 cursor->obj = obj;
235 cursor->usage = usage;
236 cursor->fence = NULL;
237}
238
246static inline void dma_resv_iter_end(struct dma_resv_iter *cursor)
247{
248 dma_fence_put(cursor->fence);
249}
250
257static inline enum dma_resv_usage
258dma_resv_iter_usage(struct dma_resv_iter *cursor)
259{
260 return cursor->fence_usage;
261}
262
269static inline bool dma_resv_iter_is_restarted(struct dma_resv_iter *cursor)
270{
271 return cursor->is_restarted;
272}
273
289#define dma_resv_for_each_fence_unlocked(cursor, fence) \
290 for (fence = dma_resv_iter_first_unlocked(cursor); \
291 fence; fence = dma_resv_iter_next_unlocked(cursor))
292
306#define dma_resv_for_each_fence(cursor, obj, usage, fence) \
307 for (dma_resv_iter_begin(cursor, obj, usage), \
308 fence = dma_resv_iter_first(cursor); fence; \
309 fence = dma_resv_iter_next(cursor))
310
311#define dma_resv_held(obj) lockdep_is_held(&(obj)->lock.base)
312#define dma_resv_assert_held(obj) lockdep_assert_held(&(obj)->lock.base)
313
314#ifdef CONFIG_DEBUG_MUTEXES
315void dma_resv_reset_max_fences(struct dma_resv *obj);
316#else
317static inline void dma_resv_reset_max_fences(struct dma_resv *obj) {}
318#endif
319
342static inline int dma_resv_lock(struct dma_resv *obj,
343 struct ww_acquire_ctx *ctx)
344{
345 return ww_mutex_lock(&obj->lock, ctx);
346}
347
369static inline int dma_resv_lock_interruptible(struct dma_resv *obj,
370 struct ww_acquire_ctx *ctx)
371{
372 return ww_mutex_lock_interruptible(&obj->lock, ctx);
373}
374
386static inline void dma_resv_lock_slow(struct dma_resv *obj,
387 struct ww_acquire_ctx *ctx)
388{
389 ww_mutex_lock_slow(&obj->lock, ctx);
390}
391
402static inline int dma_resv_lock_slow_interruptible(struct dma_resv *obj,
403 struct ww_acquire_ctx *ctx)
404{
405 return ww_mutex_lock_slow_interruptible(&obj->lock, ctx);
406}
407
422static inline bool __must_check dma_resv_trylock(struct dma_resv *obj)
423{
424 return ww_mutex_trylock(&obj->lock, NULL);
425}
426
433static inline bool dma_resv_is_locked(struct dma_resv *obj)
434{
435 return ww_mutex_is_locked(&obj->lock);
436}
437
450static inline struct ww_acquire_ctx *dma_resv_locking_ctx(struct dma_resv *obj)
451{
452 return READ_ONCE(obj->lock.ctx);
453}
454
461static inline void dma_resv_unlock(struct dma_resv *obj)
462{
463 dma_resv_reset_max_fences(obj);
464 ww_mutex_unlock(&obj->lock);
465}
466
467void dma_resv_init(struct dma_resv *obj);
468void dma_resv_fini(struct dma_resv *obj);
469int dma_resv_reserve_fences(struct dma_resv *obj, unsigned int num_fences);
470void dma_resv_add_fence(struct dma_resv *obj, struct dma_fence *fence,
471 enum dma_resv_usage usage);
472void dma_resv_replace_fences(struct dma_resv *obj, uint64_t context,
473 struct dma_fence *fence,
474 enum dma_resv_usage usage);
475int dma_resv_get_fences(struct dma_resv *obj, enum dma_resv_usage usage,
476 unsigned int *num_fences, struct dma_fence ***fences);
478 struct dma_fence **fence);
479int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src);
480long dma_resv_wait_timeout(struct dma_resv *obj, enum dma_resv_usage usage,
481 bool intr, unsigned long timeout);
482void dma_resv_set_deadline(struct dma_resv *obj, enum dma_resv_usage usage,
483 ktime_t deadline);
484bool dma_resv_test_signaled(struct dma_resv *obj, enum dma_resv_usage usage);
485void dma_resv_describe(struct dma_resv *obj, struct seq_file *seq);
486
487#endif /* _LINUX_RESERVATION_H */
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
#define NULL
Definition actypes.h:561
#define write
Definition acwin.h:181
#define __must_check
Definition compiler.h:114
#define __rcu
Definition compiler_types.h:72
struct dma_fence * dma_resv_iter_first_unlocked(struct dma_resv_iter *cursor)
struct ww_class reservation_ww_class
long dma_resv_wait_timeout(struct dma_resv *obj, enum dma_resv_usage usage, bool intr, unsigned long timeout)
int dma_resv_get_singleton(struct dma_resv *obj, enum dma_resv_usage usage, struct dma_fence **fence)
void dma_resv_init(struct dma_resv *obj)
struct dma_fence * dma_resv_iter_next(struct dma_resv_iter *cursor)
int dma_resv_get_fences(struct dma_resv *obj, enum dma_resv_usage usage, unsigned int *num_fences, struct dma_fence ***fences)
dma_resv_usage
Definition dma-resv.h:71
@ DMA_RESV_USAGE_BOOKKEEP
Definition dma-resv.h:116
@ DMA_RESV_USAGE_KERNEL
Definition dma-resv.h:84
@ DMA_RESV_USAGE_READ
Definition dma-resv.h:100
@ DMA_RESV_USAGE_WRITE
Definition dma-resv.h:92
void dma_resv_describe(struct dma_resv *obj, struct seq_file *seq)
void dma_resv_set_deadline(struct dma_resv *obj, enum dma_resv_usage usage, ktime_t deadline)
void dma_resv_replace_fences(struct dma_resv *obj, uint64_t context, struct dma_fence *fence, enum dma_resv_usage usage)
struct dma_fence * dma_resv_iter_first(struct dma_resv_iter *cursor)
void dma_resv_add_fence(struct dma_resv *obj, struct dma_fence *fence, enum dma_resv_usage usage)
bool dma_resv_test_signaled(struct dma_resv *obj, enum dma_resv_usage usage)
int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src)
void dma_resv_fini(struct dma_resv *obj)
struct dma_fence * dma_resv_iter_next_unlocked(struct dma_resv_iter *cursor)
int dma_resv_reserve_fences(struct dma_resv *obj, unsigned int num_fences)
struct drm_crtc struct drm_plane struct drm_plane * cursor
Definition drm_crtc.h:1240
int64_t ktime_t
Definition kernel.h:404
#define READ_ONCE(x)
Definition kernel.h:605
Definition dma-fence.h:70
Definition dma-resv.h:193
struct dma_fence * fence
Definition dma-resv.h:201
enum dma_resv_usage fence_usage
Definition dma-resv.h:204
enum dma_resv_usage usage
Definition dma-resv.h:198
unsigned int num_fences
Definition dma-resv.h:213
bool is_restarted
Definition dma-resv.h:216
struct dma_resv * obj
Definition dma-resv.h:195
unsigned int index
Definition dma-resv.h:207
struct dma_resv_list * fences
Definition dma-resv.h:210
Definition dma-resv.h:155
struct ww_mutex lock
Definition dma-resv.h:166
struct dma_resv_list __rcu * fences
Definition dma-resv.h:178
Definition seq_file.h:47
Definition ww_mutex.h:39
void ww_mutex_unlock(struct ww_mutex *lock) __releases(lock)
int ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) __cond_acquires(0
int __must_check ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) __cond_acquires(0
int __must_check ww_mutex_trylock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) __cond_acquires(true