~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/dma-resv.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/dma-resv.h (Version linux-6.11.5) and /include/linux/dma-resv.h (Version linux-5.19.17)


  1 /*                                                  1 /*
  2  * Header file for reservations for dma-buf an      2  * Header file for reservations for dma-buf and ttm
  3  *                                                  3  *
  4  * Copyright(C) 2011 Linaro Limited. All right      4  * Copyright(C) 2011 Linaro Limited. All rights reserved.
  5  * Copyright (C) 2012-2013 Canonical Ltd            5  * Copyright (C) 2012-2013 Canonical Ltd
  6  * Copyright (C) 2012 Texas Instruments             6  * Copyright (C) 2012 Texas Instruments
  7  *                                                  7  *
  8  * Authors:                                         8  * Authors:
  9  * Rob Clark <robdclark@gmail.com>                  9  * Rob Clark <robdclark@gmail.com>
 10  * Maarten Lankhorst <maarten.lankhorst@canoni     10  * Maarten Lankhorst <maarten.lankhorst@canonical.com>
 11  * Thomas Hellstrom <thellstrom-at-vmware-dot-     11  * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
 12  *                                                 12  *
 13  * Based on bo.c which bears the following cop     13  * Based on bo.c which bears the following copyright notice,
 14  * but is dual licensed:                           14  * but is dual licensed:
 15  *                                                 15  *
 16  * Copyright (c) 2006-2009 VMware, Inc., Palo      16  * Copyright (c) 2006-2009 VMware, Inc., Palo Alto, CA., USA
 17  * All Rights Reserved.                            17  * All Rights Reserved.
 18  *                                                 18  *
 19  * Permission is hereby granted, free of charg     19  * Permission is hereby granted, free of charge, to any person obtaining a
 20  * copy of this software and associated docume     20  * copy of this software and associated documentation files (the
 21  * "Software"), to deal in the Software withou     21  * "Software"), to deal in the Software without restriction, including
 22  * without limitation the rights to use, copy,     22  * without limitation the rights to use, copy, modify, merge, publish,
 23  * distribute, sub license, and/or sell copies     23  * distribute, sub license, and/or sell copies of the Software, and to
 24  * permit persons to whom the Software is furn     24  * permit persons to whom the Software is furnished to do so, subject to
 25  * the following conditions:                       25  * the following conditions:
 26  *                                                 26  *
 27  * The above copyright notice and this permiss     27  * The above copyright notice and this permission notice (including the
 28  * next paragraph) shall be included in all co     28  * next paragraph) shall be included in all copies or substantial portions
 29  * of the Software.                                29  * of the Software.
 30  *                                                 30  *
 31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT W     31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 32  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE W     32  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 33  * FITNESS FOR A PARTICULAR PURPOSE AND NON-IN     33  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
 34  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS S     34  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
 35  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN A     35  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 36  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNE     36  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
 37  * USE OR OTHER DEALINGS IN THE SOFTWARE.          37  * USE OR OTHER DEALINGS IN THE SOFTWARE.
 38  */                                                38  */
 39 #ifndef _LINUX_RESERVATION_H                       39 #ifndef _LINUX_RESERVATION_H
 40 #define _LINUX_RESERVATION_H                       40 #define _LINUX_RESERVATION_H
 41                                                    41 
 42 #include <linux/ww_mutex.h>                        42 #include <linux/ww_mutex.h>
 43 #include <linux/dma-fence.h>                       43 #include <linux/dma-fence.h>
 44 #include <linux/slab.h>                            44 #include <linux/slab.h>
 45 #include <linux/seqlock.h>                         45 #include <linux/seqlock.h>
 46 #include <linux/rcupdate.h>                        46 #include <linux/rcupdate.h>
 47                                                    47 
 48 extern struct ww_class reservation_ww_class;       48 extern struct ww_class reservation_ww_class;
 49                                                    49 
 50 struct dma_resv_list;                              50 struct dma_resv_list;
 51                                                    51 
 52 /**                                                52 /**
 53  * enum dma_resv_usage - how the fences from a     53  * enum dma_resv_usage - how the fences from a dma_resv obj are used
 54  *                                                 54  *
 55  * This enum describes the different use cases     55  * This enum describes the different use cases for a dma_resv object and
 56  * controls which fences are returned when que     56  * controls which fences are returned when queried.
 57  *                                                 57  *
 58  * An important fact is that there is the orde     58  * An important fact is that there is the order KERNEL<WRITE<READ<BOOKKEEP and
 59  * when the dma_resv object is asked for fence     59  * when the dma_resv object is asked for fences for one use case the fences
 60  * for the lower use case are returned as well     60  * for the lower use case are returned as well.
 61  *                                                 61  *
 62  * For example when asking for WRITE fences th     62  * For example when asking for WRITE fences then the KERNEL fences are returned
 63  * as well. Similar when asked for READ fences     63  * as well. Similar when asked for READ fences then both WRITE and KERNEL
 64  * fences are returned as well.                    64  * fences are returned as well.
 65  *                                             << 
 66  * Already used fences can be promoted in the  << 
 67  * DMA_RESV_USAGE_BOOKKEEP could become DMA_RE << 
 68  * with this usage. But fences can never be de << 
 69  * with DMA_RESV_USAGE_WRITE could become DMA_ << 
 70  */                                                65  */
 71 enum dma_resv_usage {                              66 enum dma_resv_usage {
 72         /**                                        67         /**
 73          * @DMA_RESV_USAGE_KERNEL: For in kern     68          * @DMA_RESV_USAGE_KERNEL: For in kernel memory management only.
 74          *                                         69          *
 75          * This should only be used for things     70          * This should only be used for things like copying or clearing memory
 76          * with a DMA hardware engine for the      71          * with a DMA hardware engine for the purpose of kernel memory
 77          * management.                             72          * management.
 78          *                                         73          *
 79          * Drivers *always* must wait for thos     74          * Drivers *always* must wait for those fences before accessing the
 80          * resource protected by the dma_resv      75          * resource protected by the dma_resv object. The only exception for
 81          * that is when the resource is known      76          * that is when the resource is known to be locked down in place by
 82          * pinning it previously.                  77          * pinning it previously.
 83          */                                        78          */
 84         DMA_RESV_USAGE_KERNEL,                     79         DMA_RESV_USAGE_KERNEL,
 85                                                    80 
 86         /**                                        81         /**
 87          * @DMA_RESV_USAGE_WRITE: Implicit wri     82          * @DMA_RESV_USAGE_WRITE: Implicit write synchronization.
 88          *                                         83          *
 89          * This should only be used for usersp     84          * This should only be used for userspace command submissions which add
 90          * an implicit write dependency.           85          * an implicit write dependency.
 91          */                                        86          */
 92         DMA_RESV_USAGE_WRITE,                      87         DMA_RESV_USAGE_WRITE,
 93                                                    88 
 94         /**                                        89         /**
 95          * @DMA_RESV_USAGE_READ: Implicit read     90          * @DMA_RESV_USAGE_READ: Implicit read synchronization.
 96          *                                         91          *
 97          * This should only be used for usersp     92          * This should only be used for userspace command submissions which add
 98          * an implicit read dependency.            93          * an implicit read dependency.
 99          */                                        94          */
100         DMA_RESV_USAGE_READ,                       95         DMA_RESV_USAGE_READ,
101                                                    96 
102         /**                                        97         /**
103          * @DMA_RESV_USAGE_BOOKKEEP: No implic     98          * @DMA_RESV_USAGE_BOOKKEEP: No implicit sync.
104          *                                         99          *
105          * This should be used by submissions     100          * This should be used by submissions which don't want to participate in
106          * any implicit synchronization.       !! 101          * implicit synchronization.
107          *                                     << 
108          * The most common case are preemption << 
109          * flushes as well as explicit synced  << 
110          *                                        102          *
111          * Explicit synced user user submissio !! 103          * The most common case are preemption fences as well as page table
112          * DMA_RESV_USAGE_READ or DMA_RESV_USA !! 104          * updates and their TLB flushes.
113          * dma_buf_import_sync_file() when imp << 
114          * become necessary after initial addi << 
115          */                                       105          */
116         DMA_RESV_USAGE_BOOKKEEP                   106         DMA_RESV_USAGE_BOOKKEEP
117 };                                                107 };
118                                                   108 
119 /**                                               109 /**
120  * dma_resv_usage_rw - helper for implicit syn    110  * dma_resv_usage_rw - helper for implicit sync
121  * @write: true if we create a new implicit sy    111  * @write: true if we create a new implicit sync write
122  *                                                112  *
123  * This returns the implicit synchronization u    113  * This returns the implicit synchronization usage for write or read accesses,
124  * see enum dma_resv_usage and &dma_buf.resv.     114  * see enum dma_resv_usage and &dma_buf.resv.
125  */                                               115  */
126 static inline enum dma_resv_usage dma_resv_usa    116 static inline enum dma_resv_usage dma_resv_usage_rw(bool write)
127 {                                                 117 {
128         /* This looks confusing at first sight    118         /* This looks confusing at first sight, but is indeed correct.
129          *                                        119          *
130          * The rational is that new write oper    120          * The rational is that new write operations needs to wait for the
131          * existing read and write operations     121          * existing read and write operations to finish.
132          * But a new read operation only needs    122          * But a new read operation only needs to wait for the existing write
133          * operations to finish.                  123          * operations to finish.
134          */                                       124          */
135         return write ? DMA_RESV_USAGE_READ : D    125         return write ? DMA_RESV_USAGE_READ : DMA_RESV_USAGE_WRITE;
136 }                                                 126 }
137                                                   127 
138 /**                                               128 /**
139  * struct dma_resv - a reservation object mana    129  * struct dma_resv - a reservation object manages fences for a buffer
140  *                                                130  *
141  * This is a container for dma_fence objects w    131  * This is a container for dma_fence objects which needs to handle multiple use
142  * cases.                                         132  * cases.
143  *                                                133  *
144  * One use is to synchronize cross-driver acce    134  * One use is to synchronize cross-driver access to a struct dma_buf, either for
145  * dynamic buffer management or just to handle    135  * dynamic buffer management or just to handle implicit synchronization between
146  * different users of the buffer in userspace.    136  * different users of the buffer in userspace. See &dma_buf.resv for a more
147  * in-depth discussion.                           137  * in-depth discussion.
148  *                                                138  *
149  * The other major use is to manage access and    139  * The other major use is to manage access and locking within a driver in a
150  * buffer based memory manager. struct ttm_buf    140  * buffer based memory manager. struct ttm_buffer_object is the canonical
151  * example here, since this is where reservati    141  * example here, since this is where reservation objects originated from. But
152  * use in drivers is spreading and some driver    142  * use in drivers is spreading and some drivers also manage struct
153  * drm_gem_object with the same scheme.           143  * drm_gem_object with the same scheme.
154  */                                               144  */
155 struct dma_resv {                                 145 struct dma_resv {
156         /**                                       146         /**
157          * @lock:                                 147          * @lock:
158          *                                        148          *
159          * Update side lock. Don't use directl    149          * Update side lock. Don't use directly, instead use the wrapper
160          * functions like dma_resv_lock() and     150          * functions like dma_resv_lock() and dma_resv_unlock().
161          *                                        151          *
162          * Drivers which use the reservation o    152          * Drivers which use the reservation object to manage memory dynamically
163          * also use this lock to protect buffe    153          * also use this lock to protect buffer object state like placement,
164          * allocation policies or throughout c    154          * allocation policies or throughout command submission.
165          */                                       155          */
166         struct ww_mutex lock;                     156         struct ww_mutex lock;
167                                                   157 
168         /**                                       158         /**
169          * @fences:                               159          * @fences:
170          *                                        160          *
171          * Array of fences which where added t    161          * Array of fences which where added to the dma_resv object
172          *                                        162          *
173          * A new fence is added by calling dma    163          * A new fence is added by calling dma_resv_add_fence(). Since this
174          * often needs to be done past the poi    164          * often needs to be done past the point of no return in command
175          * submission it cannot fail, and ther    165          * submission it cannot fail, and therefore sufficient slots need to be
176          * reserved by calling dma_resv_reserv    166          * reserved by calling dma_resv_reserve_fences().
177          */                                       167          */
178         struct dma_resv_list __rcu *fences;       168         struct dma_resv_list __rcu *fences;
179 };                                                169 };
180                                                   170 
181 /**                                               171 /**
182  * struct dma_resv_iter - current position int    172  * struct dma_resv_iter - current position into the dma_resv fences
183  *                                                173  *
184  * Don't touch this directly in the driver, us    174  * Don't touch this directly in the driver, use the accessor function instead.
185  *                                                175  *
186  * IMPORTANT                                      176  * IMPORTANT
187  *                                                177  *
188  * When using the lockless iterators like dma_    178  * When using the lockless iterators like dma_resv_iter_next_unlocked() or
189  * dma_resv_for_each_fence_unlocked() beware t    179  * dma_resv_for_each_fence_unlocked() beware that the iterator can be restarted.
190  * Code which accumulates statistics or simila    180  * Code which accumulates statistics or similar needs to check for this with
191  * dma_resv_iter_is_restarted().                  181  * dma_resv_iter_is_restarted().
192  */                                               182  */
193 struct dma_resv_iter {                            183 struct dma_resv_iter {
194         /** @obj: The dma_resv object we itera    184         /** @obj: The dma_resv object we iterate over */
195         struct dma_resv *obj;                     185         struct dma_resv *obj;
196                                                   186 
197         /** @usage: Return fences with this us    187         /** @usage: Return fences with this usage or lower. */
198         enum dma_resv_usage usage;                188         enum dma_resv_usage usage;
199                                                   189 
200         /** @fence: the currently handled fenc    190         /** @fence: the currently handled fence */
201         struct dma_fence *fence;                  191         struct dma_fence *fence;
202                                                   192 
203         /** @fence_usage: the usage of the cur    193         /** @fence_usage: the usage of the current fence */
204         enum dma_resv_usage fence_usage;          194         enum dma_resv_usage fence_usage;
205                                                   195 
206         /** @index: index into the shared fenc    196         /** @index: index into the shared fences */
207         unsigned int index;                       197         unsigned int index;
208                                                   198 
209         /** @fences: the shared fences; privat    199         /** @fences: the shared fences; private, *MUST* not dereference  */
210         struct dma_resv_list *fences;             200         struct dma_resv_list *fences;
211                                                   201 
212         /** @num_fences: number of fences */      202         /** @num_fences: number of fences */
213         unsigned int num_fences;                  203         unsigned int num_fences;
214                                                   204 
215         /** @is_restarted: true if this is the    205         /** @is_restarted: true if this is the first returned fence */
216         bool is_restarted;                        206         bool is_restarted;
217 };                                                207 };
218                                                   208 
219 struct dma_fence *dma_resv_iter_first_unlocked    209 struct dma_fence *dma_resv_iter_first_unlocked(struct dma_resv_iter *cursor);
220 struct dma_fence *dma_resv_iter_next_unlocked(    210 struct dma_fence *dma_resv_iter_next_unlocked(struct dma_resv_iter *cursor);
221 struct dma_fence *dma_resv_iter_first(struct d    211 struct dma_fence *dma_resv_iter_first(struct dma_resv_iter *cursor);
222 struct dma_fence *dma_resv_iter_next(struct dm    212 struct dma_fence *dma_resv_iter_next(struct dma_resv_iter *cursor);
223                                                   213 
224 /**                                               214 /**
225  * dma_resv_iter_begin - initialize a dma_resv    215  * dma_resv_iter_begin - initialize a dma_resv_iter object
226  * @cursor: The dma_resv_iter object to initia    216  * @cursor: The dma_resv_iter object to initialize
227  * @obj: The dma_resv object which we want to     217  * @obj: The dma_resv object which we want to iterate over
228  * @usage: controls which fences to include, s    218  * @usage: controls which fences to include, see enum dma_resv_usage.
229  */                                               219  */
230 static inline void dma_resv_iter_begin(struct     220 static inline void dma_resv_iter_begin(struct dma_resv_iter *cursor,
231                                        struct     221                                        struct dma_resv *obj,
232                                        enum dm    222                                        enum dma_resv_usage usage)
233 {                                                 223 {
234         cursor->obj = obj;                        224         cursor->obj = obj;
235         cursor->usage = usage;                    225         cursor->usage = usage;
236         cursor->fence = NULL;                     226         cursor->fence = NULL;
237 }                                                 227 }
238                                                   228 
239 /**                                               229 /**
240  * dma_resv_iter_end - cleanup a dma_resv_iter    230  * dma_resv_iter_end - cleanup a dma_resv_iter object
241  * @cursor: the dma_resv_iter object which sho    231  * @cursor: the dma_resv_iter object which should be cleaned up
242  *                                                232  *
243  * Make sure that the reference to the fence i    233  * Make sure that the reference to the fence in the cursor is properly
244  * dropped.                                       234  * dropped.
245  */                                               235  */
246 static inline void dma_resv_iter_end(struct dm    236 static inline void dma_resv_iter_end(struct dma_resv_iter *cursor)
247 {                                                 237 {
248         dma_fence_put(cursor->fence);             238         dma_fence_put(cursor->fence);
249 }                                                 239 }
250                                                   240 
251 /**                                               241 /**
252  * dma_resv_iter_usage - Return the usage of t    242  * dma_resv_iter_usage - Return the usage of the current fence
253  * @cursor: the cursor of the current position    243  * @cursor: the cursor of the current position
254  *                                                244  *
255  * Returns the usage of the currently processe    245  * Returns the usage of the currently processed fence.
256  */                                               246  */
257 static inline enum dma_resv_usage                 247 static inline enum dma_resv_usage
258 dma_resv_iter_usage(struct dma_resv_iter *curs    248 dma_resv_iter_usage(struct dma_resv_iter *cursor)
259 {                                                 249 {
260         return cursor->fence_usage;               250         return cursor->fence_usage;
261 }                                                 251 }
262                                                   252 
263 /**                                               253 /**
264  * dma_resv_iter_is_restarted - test if this i    254  * dma_resv_iter_is_restarted - test if this is the first fence after a restart
265  * @cursor: the cursor with the current positi    255  * @cursor: the cursor with the current position
266  *                                                256  *
267  * Return true if this is the first fence in a    257  * Return true if this is the first fence in an iteration after a restart.
268  */                                               258  */
269 static inline bool dma_resv_iter_is_restarted(    259 static inline bool dma_resv_iter_is_restarted(struct dma_resv_iter *cursor)
270 {                                                 260 {
271         return cursor->is_restarted;              261         return cursor->is_restarted;
272 }                                                 262 }
273                                                   263 
274 /**                                               264 /**
275  * dma_resv_for_each_fence_unlocked - unlocked    265  * dma_resv_for_each_fence_unlocked - unlocked fence iterator
276  * @cursor: a struct dma_resv_iter pointer        266  * @cursor: a struct dma_resv_iter pointer
277  * @fence: the current fence                      267  * @fence: the current fence
278  *                                                268  *
279  * Iterate over the fences in a struct dma_res    269  * Iterate over the fences in a struct dma_resv object without holding the
280  * &dma_resv.lock and using RCU instead. The c    270  * &dma_resv.lock and using RCU instead. The cursor needs to be initialized
281  * with dma_resv_iter_begin() and cleaned up w    271  * with dma_resv_iter_begin() and cleaned up with dma_resv_iter_end(). Inside
282  * the iterator a reference to the dma_fence i    272  * the iterator a reference to the dma_fence is held and the RCU lock dropped.
283  *                                                273  *
284  * Beware that the iterator can be restarted w    274  * Beware that the iterator can be restarted when the struct dma_resv for
285  * @cursor is modified. Code which accumulates    275  * @cursor is modified. Code which accumulates statistics or similar needs to
286  * check for this with dma_resv_iter_is_restar    276  * check for this with dma_resv_iter_is_restarted(). For this reason prefer the
287  * lock iterator dma_resv_for_each_fence() whe    277  * lock iterator dma_resv_for_each_fence() whenever possible.
288  */                                               278  */
289 #define dma_resv_for_each_fence_unlocked(curso    279 #define dma_resv_for_each_fence_unlocked(cursor, fence)                 \
290         for (fence = dma_resv_iter_first_unloc    280         for (fence = dma_resv_iter_first_unlocked(cursor);              \
291              fence; fence = dma_resv_iter_next    281              fence; fence = dma_resv_iter_next_unlocked(cursor))
292                                                   282 
293 /**                                               283 /**
294  * dma_resv_for_each_fence - fence iterator       284  * dma_resv_for_each_fence - fence iterator
295  * @cursor: a struct dma_resv_iter pointer        285  * @cursor: a struct dma_resv_iter pointer
296  * @obj: a dma_resv object pointer                286  * @obj: a dma_resv object pointer
297  * @usage: controls which fences to return        287  * @usage: controls which fences to return
298  * @fence: the current fence                      288  * @fence: the current fence
299  *                                                289  *
300  * Iterate over the fences in a struct dma_res    290  * Iterate over the fences in a struct dma_resv object while holding the
301  * &dma_resv.lock. @all_fences controls if the    291  * &dma_resv.lock. @all_fences controls if the shared fences are returned as
302  * well. The cursor initialisation is part of     292  * well. The cursor initialisation is part of the iterator and the fence stays
303  * valid as long as the lock is held and so no    293  * valid as long as the lock is held and so no extra reference to the fence is
304  * taken.                                         294  * taken.
305  */                                               295  */
306 #define dma_resv_for_each_fence(cursor, obj, u    296 #define dma_resv_for_each_fence(cursor, obj, usage, fence)      \
307         for (dma_resv_iter_begin(cursor, obj,     297         for (dma_resv_iter_begin(cursor, obj, usage),   \
308              fence = dma_resv_iter_first(curso    298              fence = dma_resv_iter_first(cursor); fence;        \
309              fence = dma_resv_iter_next(cursor    299              fence = dma_resv_iter_next(cursor))
310                                                   300 
311 #define dma_resv_held(obj) lockdep_is_held(&(o    301 #define dma_resv_held(obj) lockdep_is_held(&(obj)->lock.base)
312 #define dma_resv_assert_held(obj) lockdep_asse    302 #define dma_resv_assert_held(obj) lockdep_assert_held(&(obj)->lock.base)
313                                                   303 
314 #ifdef CONFIG_DEBUG_MUTEXES                       304 #ifdef CONFIG_DEBUG_MUTEXES
315 void dma_resv_reset_max_fences(struct dma_resv    305 void dma_resv_reset_max_fences(struct dma_resv *obj);
316 #else                                             306 #else
317 static inline void dma_resv_reset_max_fences(s    307 static inline void dma_resv_reset_max_fences(struct dma_resv *obj) {}
318 #endif                                            308 #endif
319                                                   309 
320 /**                                               310 /**
321  * dma_resv_lock - lock the reservation object    311  * dma_resv_lock - lock the reservation object
322  * @obj: the reservation object                   312  * @obj: the reservation object
323  * @ctx: the locking context                      313  * @ctx: the locking context
324  *                                                314  *
325  * Locks the reservation object for exclusive     315  * Locks the reservation object for exclusive access and modification. Note,
326  * that the lock is only against other writers    316  * that the lock is only against other writers, readers will run concurrently
327  * with a writer under RCU. The seqlock is use    317  * with a writer under RCU. The seqlock is used to notify readers if they
328  * overlap with a writer.                         318  * overlap with a writer.
329  *                                                319  *
330  * As the reservation object may be locked by     320  * As the reservation object may be locked by multiple parties in an
331  * undefined order, a #ww_acquire_ctx is passe    321  * undefined order, a #ww_acquire_ctx is passed to unwind if a cycle
332  * is detected. See ww_mutex_lock() and ww_acq    322  * is detected. See ww_mutex_lock() and ww_acquire_init(). A reservation
333  * object may be locked by itself by passing N    323  * object may be locked by itself by passing NULL as @ctx.
334  *                                                324  *
335  * When a die situation is indicated by return    325  * When a die situation is indicated by returning -EDEADLK all locks held by
336  * @ctx must be unlocked and then dma_resv_loc    326  * @ctx must be unlocked and then dma_resv_lock_slow() called on @obj.
337  *                                                327  *
338  * Unlocked by calling dma_resv_unlock().         328  * Unlocked by calling dma_resv_unlock().
339  *                                                329  *
340  * See also dma_resv_lock_interruptible() for     330  * See also dma_resv_lock_interruptible() for the interruptible variant.
341  */                                               331  */
342 static inline int dma_resv_lock(struct dma_res    332 static inline int dma_resv_lock(struct dma_resv *obj,
343                                 struct ww_acqu    333                                 struct ww_acquire_ctx *ctx)
344 {                                                 334 {
345         return ww_mutex_lock(&obj->lock, ctx);    335         return ww_mutex_lock(&obj->lock, ctx);
346 }                                                 336 }
347                                                   337 
348 /**                                               338 /**
349  * dma_resv_lock_interruptible - lock the rese    339  * dma_resv_lock_interruptible - lock the reservation object
350  * @obj: the reservation object                   340  * @obj: the reservation object
351  * @ctx: the locking context                      341  * @ctx: the locking context
352  *                                                342  *
353  * Locks the reservation object interruptible     343  * Locks the reservation object interruptible for exclusive access and
354  * modification. Note, that the lock is only a    344  * modification. Note, that the lock is only against other writers, readers
355  * will run concurrently with a writer under R    345  * will run concurrently with a writer under RCU. The seqlock is used to
356  * notify readers if they overlap with a write    346  * notify readers if they overlap with a writer.
357  *                                                347  *
358  * As the reservation object may be locked by     348  * As the reservation object may be locked by multiple parties in an
359  * undefined order, a #ww_acquire_ctx is passe    349  * undefined order, a #ww_acquire_ctx is passed to unwind if a cycle
360  * is detected. See ww_mutex_lock() and ww_acq    350  * is detected. See ww_mutex_lock() and ww_acquire_init(). A reservation
361  * object may be locked by itself by passing N    351  * object may be locked by itself by passing NULL as @ctx.
362  *                                                352  *
363  * When a die situation is indicated by return    353  * When a die situation is indicated by returning -EDEADLK all locks held by
364  * @ctx must be unlocked and then dma_resv_loc    354  * @ctx must be unlocked and then dma_resv_lock_slow_interruptible() called on
365  * @obj.                                          355  * @obj.
366  *                                                356  *
367  * Unlocked by calling dma_resv_unlock().         357  * Unlocked by calling dma_resv_unlock().
368  */                                               358  */
369 static inline int dma_resv_lock_interruptible(    359 static inline int dma_resv_lock_interruptible(struct dma_resv *obj,
370                                                   360                                               struct ww_acquire_ctx *ctx)
371 {                                                 361 {
372         return ww_mutex_lock_interruptible(&ob    362         return ww_mutex_lock_interruptible(&obj->lock, ctx);
373 }                                                 363 }
374                                                   364 
375 /**                                               365 /**
376  * dma_resv_lock_slow - slowpath lock the rese    366  * dma_resv_lock_slow - slowpath lock the reservation object
377  * @obj: the reservation object                   367  * @obj: the reservation object
378  * @ctx: the locking context                      368  * @ctx: the locking context
379  *                                                369  *
380  * Acquires the reservation object after a die    370  * Acquires the reservation object after a die case. This function
381  * will sleep until the lock becomes available    371  * will sleep until the lock becomes available. See dma_resv_lock() as
382  * well.                                          372  * well.
383  *                                                373  *
384  * See also dma_resv_lock_slow_interruptible()    374  * See also dma_resv_lock_slow_interruptible() for the interruptible variant.
385  */                                               375  */
386 static inline void dma_resv_lock_slow(struct d    376 static inline void dma_resv_lock_slow(struct dma_resv *obj,
387                                       struct w    377                                       struct ww_acquire_ctx *ctx)
388 {                                                 378 {
389         ww_mutex_lock_slow(&obj->lock, ctx);      379         ww_mutex_lock_slow(&obj->lock, ctx);
390 }                                                 380 }
391                                                   381 
392 /**                                               382 /**
393  * dma_resv_lock_slow_interruptible - slowpath    383  * dma_resv_lock_slow_interruptible - slowpath lock the reservation
394  * object, interruptible                          384  * object, interruptible
395  * @obj: the reservation object                   385  * @obj: the reservation object
396  * @ctx: the locking context                      386  * @ctx: the locking context
397  *                                                387  *
398  * Acquires the reservation object interruptib    388  * Acquires the reservation object interruptible after a die case. This function
399  * will sleep until the lock becomes available    389  * will sleep until the lock becomes available. See
400  * dma_resv_lock_interruptible() as well.         390  * dma_resv_lock_interruptible() as well.
401  */                                               391  */
402 static inline int dma_resv_lock_slow_interrupt    392 static inline int dma_resv_lock_slow_interruptible(struct dma_resv *obj,
403                                                   393                                                    struct ww_acquire_ctx *ctx)
404 {                                                 394 {
405         return ww_mutex_lock_slow_interruptibl    395         return ww_mutex_lock_slow_interruptible(&obj->lock, ctx);
406 }                                                 396 }
407                                                   397 
408 /**                                               398 /**
409  * dma_resv_trylock - trylock the reservation     399  * dma_resv_trylock - trylock the reservation object
410  * @obj: the reservation object                   400  * @obj: the reservation object
411  *                                                401  *
412  * Tries to lock the reservation object for ex    402  * Tries to lock the reservation object for exclusive access and modification.
413  * Note, that the lock is only against other w    403  * Note, that the lock is only against other writers, readers will run
414  * concurrently with a writer under RCU. The s    404  * concurrently with a writer under RCU. The seqlock is used to notify readers
415  * if they overlap with a writer.                 405  * if they overlap with a writer.
416  *                                                406  *
417  * Also note that since no context is provided    407  * Also note that since no context is provided, no deadlock protection is
418  * possible, which is also not needed for a tr    408  * possible, which is also not needed for a trylock.
419  *                                                409  *
420  * Returns true if the lock was acquired, fals    410  * Returns true if the lock was acquired, false otherwise.
421  */                                               411  */
422 static inline bool __must_check dma_resv_trylo    412 static inline bool __must_check dma_resv_trylock(struct dma_resv *obj)
423 {                                                 413 {
424         return ww_mutex_trylock(&obj->lock, NU    414         return ww_mutex_trylock(&obj->lock, NULL);
425 }                                                 415 }
426                                                   416 
427 /**                                               417 /**
428  * dma_resv_is_locked - is the reservation obj    418  * dma_resv_is_locked - is the reservation object locked
429  * @obj: the reservation object                   419  * @obj: the reservation object
430  *                                                420  *
431  * Returns true if the mutex is locked, false     421  * Returns true if the mutex is locked, false if unlocked.
432  */                                               422  */
433 static inline bool dma_resv_is_locked(struct d    423 static inline bool dma_resv_is_locked(struct dma_resv *obj)
434 {                                                 424 {
435         return ww_mutex_is_locked(&obj->lock);    425         return ww_mutex_is_locked(&obj->lock);
436 }                                                 426 }
437                                                   427 
438 /**                                               428 /**
439  * dma_resv_locking_ctx - returns the context     429  * dma_resv_locking_ctx - returns the context used to lock the object
440  * @obj: the reservation object                   430  * @obj: the reservation object
441  *                                                431  *
442  * Returns the context used to lock a reservat    432  * Returns the context used to lock a reservation object or NULL if no context
443  * was used or the object is not locked at all    433  * was used or the object is not locked at all.
444  *                                                434  *
445  * WARNING: This interface is pretty horrible,    435  * WARNING: This interface is pretty horrible, but TTM needs it because it
446  * doesn't pass the struct ww_acquire_ctx arou    436  * doesn't pass the struct ww_acquire_ctx around in some very long callchains.
447  * Everyone else just uses it to check whether    437  * Everyone else just uses it to check whether they're holding a reservation or
448  * not.                                           438  * not.
449  */                                               439  */
450 static inline struct ww_acquire_ctx *dma_resv_    440 static inline struct ww_acquire_ctx *dma_resv_locking_ctx(struct dma_resv *obj)
451 {                                                 441 {
452         return READ_ONCE(obj->lock.ctx);          442         return READ_ONCE(obj->lock.ctx);
453 }                                                 443 }
454                                                   444 
455 /**                                               445 /**
456  * dma_resv_unlock - unlock the reservation ob    446  * dma_resv_unlock - unlock the reservation object
457  * @obj: the reservation object                   447  * @obj: the reservation object
458  *                                                448  *
459  * Unlocks the reservation object following ex    449  * Unlocks the reservation object following exclusive access.
460  */                                               450  */
461 static inline void dma_resv_unlock(struct dma_    451 static inline void dma_resv_unlock(struct dma_resv *obj)
462 {                                                 452 {
463         dma_resv_reset_max_fences(obj);           453         dma_resv_reset_max_fences(obj);
464         ww_mutex_unlock(&obj->lock);              454         ww_mutex_unlock(&obj->lock);
465 }                                                 455 }
466                                                   456 
467 void dma_resv_init(struct dma_resv *obj);         457 void dma_resv_init(struct dma_resv *obj);
468 void dma_resv_fini(struct dma_resv *obj);         458 void dma_resv_fini(struct dma_resv *obj);
469 int dma_resv_reserve_fences(struct dma_resv *o    459 int dma_resv_reserve_fences(struct dma_resv *obj, unsigned int num_fences);
470 void dma_resv_add_fence(struct dma_resv *obj,     460 void dma_resv_add_fence(struct dma_resv *obj, struct dma_fence *fence,
471                         enum dma_resv_usage us    461                         enum dma_resv_usage usage);
472 void dma_resv_replace_fences(struct dma_resv *    462 void dma_resv_replace_fences(struct dma_resv *obj, uint64_t context,
473                              struct dma_fence     463                              struct dma_fence *fence,
474                              enum dma_resv_usa    464                              enum dma_resv_usage usage);
475 int dma_resv_get_fences(struct dma_resv *obj,     465 int dma_resv_get_fences(struct dma_resv *obj, enum dma_resv_usage usage,
476                         unsigned int *num_fenc    466                         unsigned int *num_fences, struct dma_fence ***fences);
477 int dma_resv_get_singleton(struct dma_resv *ob    467 int dma_resv_get_singleton(struct dma_resv *obj, enum dma_resv_usage usage,
478                            struct dma_fence **    468                            struct dma_fence **fence);
479 int dma_resv_copy_fences(struct dma_resv *dst,    469 int dma_resv_copy_fences(struct dma_resv *dst, struct dma_resv *src);
480 long dma_resv_wait_timeout(struct dma_resv *ob    470 long dma_resv_wait_timeout(struct dma_resv *obj, enum dma_resv_usage usage,
481                            bool intr, unsigned    471                            bool intr, unsigned long timeout);
482 void dma_resv_set_deadline(struct dma_resv *ob << 
483                            ktime_t deadline);  << 
484 bool dma_resv_test_signaled(struct dma_resv *o    472 bool dma_resv_test_signaled(struct dma_resv *obj, enum dma_resv_usage usage);
485 void dma_resv_describe(struct dma_resv *obj, s    473 void dma_resv_describe(struct dma_resv *obj, struct seq_file *seq);
486                                                   474 
487 #endif /* _LINUX_RESERVATION_H */                 475 #endif /* _LINUX_RESERVATION_H */
488                                                   476 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php