diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2016-12-09 13:53:07 -0500 |
---|---|---|
committer | Sumit Semwal <sumit.semwal@linaro.org> | 2016-12-13 06:39:51 -0500 |
commit | 2904a8c1311f02896635fd35744262413a0b2726 (patch) | |
tree | ce61b0e4799617f22b315ffa83cd04beb6d97afb /drivers/dma-buf | |
parent | 24a367348a017555f982a9ee137070a7a821fa97 (diff) |
dma-buf: Reorganize device dma access docs
- Put the initial overview for dma-buf into dma-buf.rst.
- Put all the comments about detailed semantics into the right
kernel-doc comment for functions or ops structure member.
- To allow that detail, switch the reworked kerneldoc to inline style
for dma_buf_ops.
- Tie everything together into a much more streamlined overview
comment, relying on the hyperlinks for all the details.
- Also sprinkle some links into the kerneldoc for dma_buf and
dma_buf_attachment to tie it all together.
Cc: linux-doc@vger.kernel.org
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Sumit Semwal <sumit.semwal@linaro.org>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20161209185309.1682-4-daniel.vetter@ffwll.ch
Diffstat (limited to 'drivers/dma-buf')
-rw-r--r-- | drivers/dma-buf/dma-buf.c | 64 | ||||
-rw-r--r-- | drivers/dma-buf/sync_file.c | 1 |
2 files changed, 59 insertions, 6 deletions
diff --git a/drivers/dma-buf/dma-buf.c b/drivers/dma-buf/dma-buf.c index e72e64484131..09f948fd62ad 100644 --- a/drivers/dma-buf/dma-buf.c +++ b/drivers/dma-buf/dma-buf.c | |||
@@ -314,19 +314,52 @@ static inline int is_dma_buf_file(struct file *file) | |||
314 | } | 314 | } |
315 | 315 | ||
316 | /** | 316 | /** |
317 | * DOC: dma buf device access | ||
318 | * | ||
319 | * For device DMA access to a shared DMA buffer the usual sequence of operations | ||
320 | * is fairly simple: | ||
321 | * | ||
322 | * 1. The exporter defines his exporter instance using | ||
323 | * DEFINE_DMA_BUF_EXPORT_INFO() and calls dma_buf_export() to wrap a private | ||
324 | * buffer object into a &dma_buf. It then exports that &dma_buf to userspace | ||
325 | * as a file descriptor by calling dma_buf_fd(). | ||
326 | * | ||
327 | * 2. Userspace passes this file-descriptors to all drivers it wants this buffer | ||
328 | * to share with: First the filedescriptor is converted to a &dma_buf using | ||
329 | * dma_buf_get(). The the buffer is attached to the device using | ||
330 | * dma_buf_attach(). | ||
331 | * | ||
332 | * Up to this stage the exporter is still free to migrate or reallocate the | ||
333 | * backing storage. | ||
334 | * | ||
335 | * 3. Once the buffer is attached to all devices userspace can inniate DMA | ||
336 | * access to the shared buffer. In the kernel this is done by calling | ||
337 | * dma_buf_map_attachment() and dma_buf_unmap_attachment(). | ||
338 | * | ||
339 | * 4. Once a driver is done with a shared buffer it needs to call | ||
340 | * dma_buf_detach() (after cleaning up any mappings) and then release the | ||
341 | * reference acquired with dma_buf_get by calling dma_buf_put(). | ||
342 | * | ||
343 | * For the detailed semantics exporters are expected to implement see | ||
344 | * &dma_buf_ops. | ||
345 | */ | ||
346 | |||
347 | /** | ||
317 | * dma_buf_export - Creates a new dma_buf, and associates an anon file | 348 | * dma_buf_export - Creates a new dma_buf, and associates an anon file |
318 | * with this buffer, so it can be exported. | 349 | * with this buffer, so it can be exported. |
319 | * Also connect the allocator specific data and ops to the buffer. | 350 | * Also connect the allocator specific data and ops to the buffer. |
320 | * Additionally, provide a name string for exporter; useful in debugging. | 351 | * Additionally, provide a name string for exporter; useful in debugging. |
321 | * | 352 | * |
322 | * @exp_info: [in] holds all the export related information provided | 353 | * @exp_info: [in] holds all the export related information provided |
323 | * by the exporter. see struct dma_buf_export_info | 354 | * by the exporter. see struct &dma_buf_export_info |
324 | * for further details. | 355 | * for further details. |
325 | * | 356 | * |
326 | * Returns, on success, a newly created dma_buf object, which wraps the | 357 | * Returns, on success, a newly created dma_buf object, which wraps the |
327 | * supplied private data and operations for dma_buf_ops. On either missing | 358 | * supplied private data and operations for dma_buf_ops. On either missing |
328 | * ops, or error in allocating struct dma_buf, will return negative error. | 359 | * ops, or error in allocating struct dma_buf, will return negative error. |
329 | * | 360 | * |
361 | * For most cases the easiest way to create @exp_info is through the | ||
362 | * %DEFINE_DMA_BUF_EXPORT_INFO macro. | ||
330 | */ | 363 | */ |
331 | struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) | 364 | struct dma_buf *dma_buf_export(const struct dma_buf_export_info *exp_info) |
332 | { | 365 | { |
@@ -458,7 +491,12 @@ EXPORT_SYMBOL_GPL(dma_buf_get); | |||
458 | * dma_buf_put - decreases refcount of the buffer | 491 | * dma_buf_put - decreases refcount of the buffer |
459 | * @dmabuf: [in] buffer to reduce refcount of | 492 | * @dmabuf: [in] buffer to reduce refcount of |
460 | * | 493 | * |
461 | * Uses file's refcounting done implicitly by fput() | 494 | * Uses file's refcounting done implicitly by fput(). |
495 | * | ||
496 | * If, as a result of this call, the refcount becomes 0, the 'release' file | ||
497 | * operation related to this fd is called. It calls the release operation of | ||
498 | * struct &dma_buf_ops in turn, and frees the memory allocated for dmabuf when | ||
499 | * exported. | ||
462 | */ | 500 | */ |
463 | void dma_buf_put(struct dma_buf *dmabuf) | 501 | void dma_buf_put(struct dma_buf *dmabuf) |
464 | { | 502 | { |
@@ -475,8 +513,17 @@ EXPORT_SYMBOL_GPL(dma_buf_put); | |||
475 | * @dmabuf: [in] buffer to attach device to. | 513 | * @dmabuf: [in] buffer to attach device to. |
476 | * @dev: [in] device to be attached. | 514 | * @dev: [in] device to be attached. |
477 | * | 515 | * |
478 | * Returns struct dma_buf_attachment * for this attachment; returns ERR_PTR on | 516 | * Returns struct dma_buf_attachment pointer for this attachment. Attachments |
479 | * error. | 517 | * must be cleaned up by calling dma_buf_detach(). |
518 | * | ||
519 | * Returns: | ||
520 | * | ||
521 | * A pointer to newly created &dma_buf_attachment on success, or a negative | ||
522 | * error code wrapped into a pointer on failure. | ||
523 | * | ||
524 | * Note that this can fail if the backing storage of @dmabuf is in a place not | ||
525 | * accessible to @dev, and cannot be moved to a more suitable place. This is | ||
526 | * indicated with the error code -EBUSY. | ||
480 | */ | 527 | */ |
481 | struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, | 528 | struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf, |
482 | struct device *dev) | 529 | struct device *dev) |
@@ -519,6 +566,7 @@ EXPORT_SYMBOL_GPL(dma_buf_attach); | |||
519 | * @dmabuf: [in] buffer to detach from. | 566 | * @dmabuf: [in] buffer to detach from. |
520 | * @attach: [in] attachment to be detached; is free'd after this call. | 567 | * @attach: [in] attachment to be detached; is free'd after this call. |
521 | * | 568 | * |
569 | * Clean up a device attachment obtained by calling dma_buf_attach(). | ||
522 | */ | 570 | */ |
523 | void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) | 571 | void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach) |
524 | { | 572 | { |
@@ -543,7 +591,12 @@ EXPORT_SYMBOL_GPL(dma_buf_detach); | |||
543 | * @direction: [in] direction of DMA transfer | 591 | * @direction: [in] direction of DMA transfer |
544 | * | 592 | * |
545 | * Returns sg_table containing the scatterlist to be returned; returns ERR_PTR | 593 | * Returns sg_table containing the scatterlist to be returned; returns ERR_PTR |
546 | * on error. | 594 | * on error. May return -EINTR if it is interrupted by a signal. |
595 | * | ||
596 | * A mapping must be unmapped again using dma_buf_map_attachment(). Note that | ||
597 | * the underlying backing storage is pinned for as long as a mapping exists, | ||
598 | * therefore users/importers should not hold onto a mapping for undue amounts of | ||
599 | * time. | ||
547 | */ | 600 | */ |
548 | struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, | 601 | struct sg_table *dma_buf_map_attachment(struct dma_buf_attachment *attach, |
549 | enum dma_data_direction direction) | 602 | enum dma_data_direction direction) |
@@ -571,6 +624,7 @@ EXPORT_SYMBOL_GPL(dma_buf_map_attachment); | |||
571 | * @sg_table: [in] scatterlist info of the buffer to unmap | 624 | * @sg_table: [in] scatterlist info of the buffer to unmap |
572 | * @direction: [in] direction of DMA transfer | 625 | * @direction: [in] direction of DMA transfer |
573 | * | 626 | * |
627 | * This unmaps a DMA mapping for @attached obtained by dma_buf_map_attachment(). | ||
574 | */ | 628 | */ |
575 | void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, | 629 | void dma_buf_unmap_attachment(struct dma_buf_attachment *attach, |
576 | struct sg_table *sg_table, | 630 | struct sg_table *sg_table, |
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index d5179d7e8575..07cb9b908f30 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c | |||
@@ -462,4 +462,3 @@ static const struct file_operations sync_file_fops = { | |||
462 | .unlocked_ioctl = sync_file_ioctl, | 462 | .unlocked_ioctl = sync_file_ioctl, |
463 | .compat_ioctl = sync_file_ioctl, | 463 | .compat_ioctl = sync_file_ioctl, |
464 | }; | 464 | }; |
465 | |||