Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dma-fence: Polish kernel-doc for dma-fence.c

- Intro section that links to how this is exposed to userspace.
- Lots more hyperlinks.
- Minor clarifications and style polish

v2: Add misplaced hunk of kerneldoc from a different patch.

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Cc: Gustavo Padovan <gustavo@padovan.org>
Cc: linux-media@vger.kernel.org
Cc: linaro-mm-sig@lists.linaro.org
Link: https://patchwork.freedesktop.org/patch/msgid/20180704092909.6599-6-daniel.vetter@ffwll.ch

+110 -45
+6
Documentation/driver-api/dma-buf.rst
··· 131 131 ---------- 132 132 133 133 .. kernel-doc:: drivers/dma-buf/dma-fence.c 134 + :doc: DMA fences overview 135 + 136 + DMA Fences Functions Reference 137 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 138 + 139 + .. kernel-doc:: drivers/dma-buf/dma-fence.c 134 140 :export: 135 141 136 142 .. kernel-doc:: include/linux/dma-fence.h
+104 -45
drivers/dma-buf/dma-fence.c
··· 39 39 static atomic64_t dma_fence_context_counter = ATOMIC64_INIT(0); 40 40 41 41 /** 42 - * dma_fence_context_alloc - allocate an array of fence contexts 43 - * @num: [in] amount of contexts to allocate 42 + * DOC: DMA fences overview 44 43 * 45 - * This function will return the first index of the number of fences allocated. 46 - * The fence context is used for setting fence->context to a unique number. 44 + * DMA fences, represented by &struct dma_fence, are the kernel internal 45 + * synchronization primitive for DMA operations like GPU rendering, video 46 + * encoding/decoding, or displaying buffers on a screen. 47 + * 48 + * A fence is initialized using dma_fence_init() and completed using 49 + * dma_fence_signal(). Fences are associated with a context, allocated through 50 + * dma_fence_context_alloc(), and all fences on the same context are 51 + * fully ordered. 52 + * 53 + * Since the purposes of fences is to facilitate cross-device and 54 + * cross-application synchronization, there's multiple ways to use one: 55 + * 56 + * - Individual fences can be exposed as a &sync_file, accessed as a file 57 + * descriptor from userspace, created by calling sync_file_create(). This is 58 + * called explicit fencing, since userspace passes around explicit 59 + * synchronization points. 60 + * 61 + * - Some subsystems also have their own explicit fencing primitives, like 62 + * &drm_syncobj. Compared to &sync_file, a &drm_syncobj allows the underlying 63 + * fence to be updated. 64 + * 65 + * - Then there's also implicit fencing, where the synchronization points are 66 + * implicitly passed around as part of shared &dma_buf instances. Such 67 + * implicit fences are stored in &struct reservation_object through the 68 + * &dma_buf.resv pointer. 69 + */ 70 + 71 + /** 72 + * dma_fence_context_alloc - allocate an array of fence contexts 73 + * @num: amount of contexts to allocate 74 + * 75 + * This function will return the first index of the number of fence contexts 76 + * allocated. The fence context is used for setting &dma_fence.context to a 77 + * unique number by passing the context to dma_fence_init(). 47 78 */ 48 79 u64 dma_fence_context_alloc(unsigned num) 49 80 { ··· 90 59 * Signal completion for software callbacks on a fence, this will unblock 91 60 * dma_fence_wait() calls and run all the callbacks added with 92 61 * dma_fence_add_callback(). Can be called multiple times, but since a fence 93 - * can only go from unsignaled to signaled state, it will only be effective 94 - * the first time. 62 + * can only go from the unsignaled to the signaled state and not back, it will 63 + * only be effective the first time. 95 64 * 96 - * Unlike dma_fence_signal, this function must be called with fence->lock held. 65 + * Unlike dma_fence_signal(), this function must be called with &dma_fence.lock 66 + * held. 67 + * 68 + * Returns 0 on success and a negative error value when @fence has been 69 + * signalled already. 97 70 */ 98 71 int dma_fence_signal_locked(struct dma_fence *fence) 99 72 { ··· 137 102 * Signal completion for software callbacks on a fence, this will unblock 138 103 * dma_fence_wait() calls and run all the callbacks added with 139 104 * dma_fence_add_callback(). Can be called multiple times, but since a fence 140 - * can only go from unsignaled to signaled state, it will only be effective 141 - * the first time. 105 + * can only go from the unsignaled to the signaled state and not back, it will 106 + * only be effective the first time. 107 + * 108 + * Returns 0 on success and a negative error value when @fence has been 109 + * signalled already. 142 110 */ 143 111 int dma_fence_signal(struct dma_fence *fence) 144 112 { ··· 174 136 /** 175 137 * dma_fence_wait_timeout - sleep until the fence gets signaled 176 138 * or until timeout elapses 177 - * @fence: [in] the fence to wait on 178 - * @intr: [in] if true, do an interruptible wait 179 - * @timeout: [in] timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT 139 + * @fence: the fence to wait on 140 + * @intr: if true, do an interruptible wait 141 + * @timeout: timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT 180 142 * 181 143 * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or the 182 144 * remaining timeout in jiffies on success. Other error values may be ··· 186 148 * directly or indirectly (buf-mgr between reservation and committing) 187 149 * holds a reference to the fence, otherwise the fence might be 188 150 * freed before return, resulting in undefined behavior. 151 + * 152 + * See also dma_fence_wait() and dma_fence_wait_any_timeout(). 189 153 */ 190 154 signed long 191 155 dma_fence_wait_timeout(struct dma_fence *fence, bool intr, signed long timeout) ··· 207 167 } 208 168 EXPORT_SYMBOL(dma_fence_wait_timeout); 209 169 170 + /** 171 + * dma_fence_release - default relese function for fences 172 + * @kref: &dma_fence.recfount 173 + * 174 + * This is the default release functions for &dma_fence. Drivers shouldn't call 175 + * this directly, but instead call dma_fence_put(). 176 + */ 210 177 void dma_fence_release(struct kref *kref) 211 178 { 212 179 struct dma_fence *fence = ··· 231 184 } 232 185 EXPORT_SYMBOL(dma_fence_release); 233 186 187 + /** 188 + * dma_fence_free - default release function for &dma_fence. 189 + * @fence: fence to release 190 + * 191 + * This is the default implementation for &dma_fence_ops.release. It calls 192 + * kfree_rcu() on @fence. 193 + */ 234 194 void dma_fence_free(struct dma_fence *fence) 235 195 { 236 196 kfree_rcu(fence, rcu); ··· 246 192 247 193 /** 248 194 * dma_fence_enable_sw_signaling - enable signaling on fence 249 - * @fence: [in] the fence to enable 195 + * @fence: the fence to enable 250 196 * 251 - * this will request for sw signaling to be enabled, to make the fence 252 - * complete as soon as possible 197 + * This will request for sw signaling to be enabled, to make the fence 198 + * complete as soon as possible. This calls &dma_fence_ops.enable_signaling 199 + * internally. 253 200 */ 254 201 void dma_fence_enable_sw_signaling(struct dma_fence *fence) 255 202 { ··· 275 220 /** 276 221 * dma_fence_add_callback - add a callback to be called when the fence 277 222 * is signaled 278 - * @fence: [in] the fence to wait on 279 - * @cb: [in] the callback to register 280 - * @func: [in] the function to call 223 + * @fence: the fence to wait on 224 + * @cb: the callback to register 225 + * @func: the function to call 281 226 * 282 - * cb will be initialized by dma_fence_add_callback, no initialization 227 + * @cb will be initialized by dma_fence_add_callback(), no initialization 283 228 * by the caller is required. Any number of callbacks can be registered 284 229 * to a fence, but a callback can only be registered to one fence at a time. 285 230 * 286 231 * Note that the callback can be called from an atomic context. If 287 232 * fence is already signaled, this function will return -ENOENT (and 288 - * *not* call the callback) 233 + * *not* call the callback). 289 234 * 290 235 * Add a software callback to the fence. Same restrictions apply to 291 - * refcount as it does to dma_fence_wait, however the caller doesn't need to 292 - * keep a refcount to fence afterwards: when software access is enabled, 293 - * the creator of the fence is required to keep the fence alive until 294 - * after it signals with dma_fence_signal. The callback itself can be called 295 - * from irq context. 236 + * refcount as it does to dma_fence_wait(), however the caller doesn't need to 237 + * keep a refcount to fence afterward dma_fence_add_callback() has returned: 238 + * when software access is enabled, the creator of the fence is required to keep 239 + * the fence alive until after it signals with dma_fence_signal(). The callback 240 + * itself can be called from irq context. 296 241 * 297 242 * Returns 0 in case of success, -ENOENT if the fence is already signaled 298 243 * and -EINVAL in case of error. ··· 341 286 342 287 /** 343 288 * dma_fence_get_status - returns the status upon completion 344 - * @fence: [in] the dma_fence to query 289 + * @fence: the dma_fence to query 345 290 * 346 291 * This wraps dma_fence_get_status_locked() to return the error status 347 292 * condition on a signaled fence. See dma_fence_get_status_locked() for more ··· 366 311 367 312 /** 368 313 * dma_fence_remove_callback - remove a callback from the signaling list 369 - * @fence: [in] the fence to wait on 370 - * @cb: [in] the callback to remove 314 + * @fence: the fence to wait on 315 + * @cb: the callback to remove 371 316 * 372 317 * Remove a previously queued callback from the fence. This function returns 373 318 * true if the callback is successfully removed, or false if the fence has ··· 378 323 * doing, since deadlocks and race conditions could occur all too easily. For 379 324 * this reason, it should only ever be done on hardware lockup recovery, 380 325 * with a reference held to the fence. 326 + * 327 + * Behaviour is undefined if @cb has not been added to @fence using 328 + * dma_fence_add_callback() beforehand. 381 329 */ 382 330 bool 383 331 dma_fence_remove_callback(struct dma_fence *fence, struct dma_fence_cb *cb) ··· 417 359 /** 418 360 * dma_fence_default_wait - default sleep until the fence gets signaled 419 361 * or until timeout elapses 420 - * @fence: [in] the fence to wait on 421 - * @intr: [in] if true, do an interruptible wait 422 - * @timeout: [in] timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT 362 + * @fence: the fence to wait on 363 + * @intr: if true, do an interruptible wait 364 + * @timeout: timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT 423 365 * 424 366 * Returns -ERESTARTSYS if interrupted, 0 if the wait timed out, or the 425 367 * remaining timeout in jiffies on success. If timeout is zero the value one is ··· 512 454 /** 513 455 * dma_fence_wait_any_timeout - sleep until any fence gets signaled 514 456 * or until timeout elapses 515 - * @fences: [in] array of fences to wait on 516 - * @count: [in] number of fences to wait on 517 - * @intr: [in] if true, do an interruptible wait 518 - * @timeout: [in] timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT 519 - * @idx: [out] the first signaled fence index, meaningful only on 520 - * positive return 457 + * @fences: array of fences to wait on 458 + * @count: number of fences to wait on 459 + * @intr: if true, do an interruptible wait 460 + * @timeout: timeout value in jiffies, or MAX_SCHEDULE_TIMEOUT 461 + * @idx: used to store the first signaled fence index, meaningful only on 462 + * positive return 521 463 * 522 464 * Returns -EINVAL on custom fence wait implementation, -ERESTARTSYS if 523 465 * interrupted, 0 if the wait timed out, or the remaining timeout in jiffies ··· 526 468 * Synchronous waits for the first fence in the array to be signaled. The 527 469 * caller needs to hold a reference to all fences in the array, otherwise a 528 470 * fence might be freed before return, resulting in undefined behavior. 471 + * 472 + * See also dma_fence_wait() and dma_fence_wait_timeout(). 529 473 */ 530 474 signed long 531 475 dma_fence_wait_any_timeout(struct dma_fence **fences, uint32_t count, ··· 600 540 601 541 /** 602 542 * dma_fence_init - Initialize a custom fence. 603 - * @fence: [in] the fence to initialize 604 - * @ops: [in] the dma_fence_ops for operations on this fence 605 - * @lock: [in] the irqsafe spinlock to use for locking this fence 606 - * @context: [in] the execution context this fence is run on 607 - * @seqno: [in] a linear increasing sequence number for this context 543 + * @fence: the fence to initialize 544 + * @ops: the dma_fence_ops for operations on this fence 545 + * @lock: the irqsafe spinlock to use for locking this fence 546 + * @context: the execution context this fence is run on 547 + * @seqno: a linear increasing sequence number for this context 608 548 * 609 549 * Initializes an allocated fence, the caller doesn't have to keep its 610 550 * refcount after committing with this fence, but it will need to hold a 611 - * refcount again if dma_fence_ops.enable_signaling gets called. This can 612 - * be used for other implementing other types of fence. 551 + * refcount again if &dma_fence_ops.enable_signaling gets called. 613 552 * 614 553 * context and seqno are used for easy comparison between fences, allowing 615 - * to check which fence is later by simply using dma_fence_later. 554 + * to check which fence is later by simply using dma_fence_later(). 616 555 */ 617 556 void 618 557 dma_fence_init(struct dma_fence *fence, const struct dma_fence_ops *ops,