Lines Matching +full:poll +full:- +full:only

1 // SPDX-License-Identifier: GPL-2.0-only
8 * Many thanks to linaro-mm-sig list, and specially
16 #include <linux/dma-buf.h>
17 #include <linux/dma-fence.h>
23 #include <linux/poll.h>
24 #include <linux/dma-resv.h>
30 #include <uapi/linux/dma-buf.h>
33 #include "dma-buf-sysfs-stats.h"
109 dmabuf = dentry->d_fsdata; in dmabuffs_dname()
110 spin_lock(&dmabuf->name_lock); in dmabuffs_dname()
111 if (dmabuf->name) in dmabuffs_dname()
112 ret = strlcpy(name, dmabuf->name, DMA_BUF_NAME_LEN); in dmabuffs_dname()
113 spin_unlock(&dmabuf->name_lock); in dmabuffs_dname()
116 dentry->d_name.name, ret > 0 ? name : ""); in dmabuffs_dname()
126 dmabuf = dentry->d_fsdata; in dma_buf_release()
130 BUG_ON(dmabuf->vmapping_counter); in dma_buf_release()
133 * Any fences that a dma-buf poll can wait on should be signaled in dma_buf_release()
134 * before releasing dma-buf. This is the responsibility of each in dma_buf_release()
138 * dma-buf while still having pending operation to the buffer. in dma_buf_release()
140 BUG_ON(dmabuf->cb_shared.active || dmabuf->cb_excl.active); in dma_buf_release()
144 if (dmabuf->dtor) in dma_buf_release()
145 dtor_ret = dmabuf->dtor(dmabuf, dmabuf->dtor_data); in dma_buf_release()
149 dmabuf->ops->release(dmabuf); in dma_buf_release()
151 if (dmabuf->resv == (struct dma_resv *)&dmabuf[1]) in dma_buf_release()
152 dma_resv_fini(dmabuf->resv); in dma_buf_release()
154 WARN_ON(!list_empty(&dmabuf->attachments)); in dma_buf_release()
155 module_put(dmabuf->owner); in dma_buf_release()
156 kfree(dmabuf->name); in dma_buf_release()
165 return -EINVAL; in dma_buf_file_release()
167 dmabuf = file->private_data; in dma_buf_file_release()
171 db_total_size -= dmabuf->size; in dma_buf_file_release()
173 list_del(&dmabuf->list_node); in dma_buf_file_release()
192 return -ENOMEM; in dma_buf_fs_init_context()
193 ctx->dops = &dma_buf_dentry_ops; in dma_buf_fs_init_context()
208 return -EINVAL; in dma_buf_mmap_internal()
210 dmabuf = file->private_data; in dma_buf_mmap_internal()
213 if (!dmabuf->ops->mmap) in dma_buf_mmap_internal()
214 return -EINVAL; in dma_buf_mmap_internal()
217 if (vma->vm_pgoff + vma_pages(vma) > in dma_buf_mmap_internal()
218 dmabuf->size >> PAGE_SHIFT) in dma_buf_mmap_internal()
219 return -EINVAL; in dma_buf_mmap_internal()
221 return dmabuf->ops->mmap(dmabuf, vma); in dma_buf_mmap_internal()
230 return -EBADF; in dma_buf_llseek()
232 dmabuf = file->private_data; in dma_buf_llseek()
234 /* only support discovering the end of the buffer, in dma_buf_llseek()
238 base = dmabuf->size; in dma_buf_llseek()
242 return -EINVAL; in dma_buf_llseek()
245 return -EINVAL; in dma_buf_llseek()
253 * To support cross-device and cross-driver synchronization of buffer access
258 * Userspace can query the state of these implicitly tracked fences using poll()
261 * - Checking for EPOLLIN, i.e. read access, can be use to query the state of the
264 * - Checking for EPOLLOUT, i.e. write access, can be used to query the state of
267 * Note that this only signals the completion of the respective fences, i.e. the
277 spin_lock_irqsave(&dcb->poll->lock, flags); in dma_buf_poll_cb()
278 wake_up_locked_poll(dcb->poll, dcb->active); in dma_buf_poll_cb()
279 dcb->active = 0; in dma_buf_poll_cb()
280 spin_unlock_irqrestore(&dcb->poll->lock, flags); in dma_buf_poll_cb()
283 static __poll_t dma_buf_poll(struct file *file, poll_table *poll) in dma_buf_poll() argument
292 dmabuf = file->private_data; in dma_buf_poll()
293 if (!dmabuf || !dmabuf->resv) in dma_buf_poll()
296 resv = dmabuf->resv; in dma_buf_poll()
298 poll_wait(file, &dmabuf->poll, poll); in dma_buf_poll()
300 events = poll_requested_events(poll) & (EPOLLIN | EPOLLOUT); in dma_buf_poll()
305 seq = read_seqcount_begin(&resv->seq); in dma_buf_poll()
308 fobj = rcu_dereference(resv->fence); in dma_buf_poll()
310 shared_count = fobj->shared_count; in dma_buf_poll()
313 fence_excl = rcu_dereference(resv->fence_excl); in dma_buf_poll()
314 if (read_seqcount_retry(&resv->seq, seq)) { in dma_buf_poll()
320 struct dma_buf_poll_cb_t *dcb = &dmabuf->cb_excl; in dma_buf_poll()
326 spin_lock_irq(&dmabuf->poll.lock); in dma_buf_poll()
327 if (dcb->active) { in dma_buf_poll()
328 dcb->active |= pevents; in dma_buf_poll()
331 dcb->active = pevents; in dma_buf_poll()
332 spin_unlock_irq(&dmabuf->poll.lock); in dma_buf_poll()
338 dma_buf_poll_cb(NULL, &dcb->cb); in dma_buf_poll()
339 } else if (!dma_fence_add_callback(fence_excl, &dcb->cb, in dma_buf_poll()
349 dma_buf_poll_cb(NULL, &dcb->cb); in dma_buf_poll()
355 struct dma_buf_poll_cb_t *dcb = &dmabuf->cb_shared; in dma_buf_poll()
358 /* Only queue a new callback if no event has fired yet */ in dma_buf_poll()
359 spin_lock_irq(&dmabuf->poll.lock); in dma_buf_poll()
360 if (dcb->active) in dma_buf_poll()
363 dcb->active = EPOLLOUT; in dma_buf_poll()
364 spin_unlock_irq(&dmabuf->poll.lock); in dma_buf_poll()
370 struct dma_fence *fence = rcu_dereference(fobj->shared[i]); in dma_buf_poll()
380 dma_buf_poll_cb(NULL, &dcb->cb); in dma_buf_poll()
383 if (!dma_fence_add_callback(fence, &dcb->cb, in dma_buf_poll()
394 dma_buf_poll_cb(NULL, &dcb->cb); in dma_buf_poll()
404 spin_lock(&dmabuf->name_lock); in _dma_buf_set_name()
405 kfree(dmabuf->name); in _dma_buf_set_name()
406 dmabuf->name = name; in _dma_buf_set_name()
407 spin_unlock(&dmabuf->name_lock); in _dma_buf_set_name()
413 * dma_buf_set_name - Set a name to a specific dma_buf to track the usage.
414 * It could support changing the name of the dma-buf if the same piece of
419 * the dma-buf.
421 * Returns 0 on success. If the dma-buf buffer is already attached to
422 * devices, return -EBUSY.
431 return -ENOMEM; in dma_buf_set_name()
465 dmabuf = file->private_data; in dma_buf_ioctl()
470 return -EFAULT; in dma_buf_ioctl()
473 return -EINVAL; in dma_buf_ioctl()
486 return -EINVAL; in dma_buf_ioctl()
502 return -EFAULT; in dma_buf_ioctl()
507 if (sync_p.len > dmabuf->size || sync_p.offset > dmabuf->size - sync_p.len) in dma_buf_ioctl()
508 return -EINVAL; in dma_buf_ioctl()
511 return -EINVAL; in dma_buf_ioctl()
524 return -EINVAL; in dma_buf_ioctl()
539 return -ENOTTY; in dma_buf_ioctl()
545 struct dma_buf *dmabuf = file->private_data; in dma_buf_show_fdinfo()
547 seq_printf(m, "size:\t%zu\n", dmabuf->size); in dma_buf_show_fdinfo()
549 seq_printf(m, "count:\t%ld\n", file_count(dmabuf->file) - 1); in dma_buf_show_fdinfo()
550 seq_printf(m, "exp_name:\t%s\n", dmabuf->exp_name); in dma_buf_show_fdinfo()
551 spin_lock(&dmabuf->name_lock); in dma_buf_show_fdinfo()
552 if (dmabuf->name) in dma_buf_show_fdinfo()
553 seq_printf(m, "name:\t%s\n", dmabuf->name); in dma_buf_show_fdinfo()
554 spin_unlock(&dmabuf->name_lock); in dma_buf_show_fdinfo()
561 .poll = dma_buf_poll,
568 * is_dma_buf_file - Check if struct file* is associated with dma_buf
572 return file->f_op == &dma_buf_fops; in is_dma_buf_file()
580 struct inode *inode = alloc_anon_inode(dma_buf_mnt->mnt_sb); in dma_buf_getfile()
585 inode->i_size = dmabuf->size; in dma_buf_getfile()
586 inode_set_bytes(inode, dmabuf->size); in dma_buf_getfile()
589 * The ->i_ino acquired from get_next_ino() is not unique thus in dma_buf_getfile()
591 * Override ->i_ino with the unique and dmabuffs specific in dma_buf_getfile()
594 inode->i_ino = atomic64_add_return(1, &dmabuf_inode); in dma_buf_getfile()
599 file->f_flags = flags & (O_ACCMODE | O_NONBLOCK); in dma_buf_getfile()
600 file->private_data = dmabuf; in dma_buf_getfile()
601 file->f_path.dentry->d_fsdata = dmabuf; in dma_buf_getfile()
615 get_task_comm(task_comm, current->group_leader); in dma_buf_set_default_name()
616 name = kasprintf(GFP_KERNEL, "%d-%s", current->tgid, task_comm); in dma_buf_set_default_name()
632 * 2. Userspace passes this file-descriptors to all drivers it wants this buffer
653 * dma_buf_export - Creates a new dma_buf, and associates an anon file
672 struct dma_resv *resv = exp_info->resv; in dma_buf_export()
677 if (!exp_info->resv) in dma_buf_export()
680 /* prevent &dma_buf[1] == dma_buf->resv */ in dma_buf_export()
683 if (WARN_ON(!exp_info->priv in dma_buf_export()
684 || !exp_info->ops in dma_buf_export()
685 || !exp_info->ops->map_dma_buf in dma_buf_export()
686 || !exp_info->ops->unmap_dma_buf in dma_buf_export()
687 || !exp_info->ops->release)) { in dma_buf_export()
688 return ERR_PTR(-EINVAL); in dma_buf_export()
691 if (WARN_ON(exp_info->ops->cache_sgt_mapping && in dma_buf_export()
692 (exp_info->ops->pin || exp_info->ops->unpin))) in dma_buf_export()
693 return ERR_PTR(-EINVAL); in dma_buf_export()
695 if (WARN_ON(!exp_info->ops->pin != !exp_info->ops->unpin)) in dma_buf_export()
696 return ERR_PTR(-EINVAL); in dma_buf_export()
698 if (!try_module_get(exp_info->owner)) in dma_buf_export()
699 return ERR_PTR(-ENOENT); in dma_buf_export()
703 ret = -ENOMEM; in dma_buf_export()
707 dmabuf->priv = exp_info->priv; in dma_buf_export()
708 dmabuf->ops = exp_info->ops; in dma_buf_export()
709 dmabuf->size = exp_info->size; in dma_buf_export()
710 dmabuf->exp_name = exp_info->exp_name; in dma_buf_export()
711 dmabuf->owner = exp_info->owner; in dma_buf_export()
712 spin_lock_init(&dmabuf->name_lock); in dma_buf_export()
714 mutex_init(&dmabuf->cache_lock); in dma_buf_export()
716 init_waitqueue_head(&dmabuf->poll); in dma_buf_export()
717 dmabuf->cb_excl.poll = dmabuf->cb_shared.poll = &dmabuf->poll; in dma_buf_export()
718 dmabuf->cb_excl.active = dmabuf->cb_shared.active = 0; in dma_buf_export()
724 dmabuf->resv = resv; in dma_buf_export()
726 file = dma_buf_getfile(dmabuf, exp_info->flags); in dma_buf_export()
732 file->f_mode |= FMODE_LSEEK; in dma_buf_export()
733 dmabuf->file = file; in dma_buf_export()
735 mutex_init(&dmabuf->lock); in dma_buf_export()
736 INIT_LIST_HEAD(&dmabuf->attachments); in dma_buf_export()
739 list_add(&dmabuf->list_node, &db_list.head); in dma_buf_export()
741 db_total_size += dmabuf->size; in dma_buf_export()
757 * Set file->f_path.dentry->d_fsdata to NULL so that when in dma_buf_export()
761 file->f_path.dentry->d_fsdata = NULL; in dma_buf_export()
766 module_put(exp_info->owner); in dma_buf_export()
772 * dma_buf_fd - returns a file descriptor for the given dma_buf
782 if (!dmabuf || !dmabuf->file) in dma_buf_fd()
783 return -EINVAL; in dma_buf_fd()
789 fd_install(fd, dmabuf->file); in dma_buf_fd()
796 * dma_buf_get - returns the dma_buf structure related to an fd
810 return ERR_PTR(-EBADF); in dma_buf_get()
814 return ERR_PTR(-EINVAL); in dma_buf_get()
817 return file->private_data; in dma_buf_get()
822 * dma_buf_put - decreases refcount of the buffer
833 if (WARN_ON(!dmabuf || !dmabuf->file)) in dma_buf_put()
836 fput(dmabuf->file); in dma_buf_put()
841 * dma_buf_dynamic_attach - Add the device to dma_buf's attachments list; optionally,
842 * calls attach() of dma_buf_ops to allow device-specific attach functionality
858 * indicated with the error code -EBUSY.
869 return ERR_PTR(-EINVAL); in dma_buf_dynamic_attach()
871 if (WARN_ON(importer_ops && !importer_ops->move_notify)) in dma_buf_dynamic_attach()
872 return ERR_PTR(-EINVAL); in dma_buf_dynamic_attach()
876 return ERR_PTR(-ENOMEM); in dma_buf_dynamic_attach()
878 attach->dev = dev; in dma_buf_dynamic_attach()
879 attach->dmabuf = dmabuf; in dma_buf_dynamic_attach()
881 attach->peer2peer = importer_ops->allow_peer2peer; in dma_buf_dynamic_attach()
882 attach->importer_ops = importer_ops; in dma_buf_dynamic_attach()
883 attach->importer_priv = importer_priv; in dma_buf_dynamic_attach()
885 if (dmabuf->ops->attach) { in dma_buf_dynamic_attach()
886 ret = dmabuf->ops->attach(dmabuf, attach); in dma_buf_dynamic_attach()
890 dma_resv_lock(dmabuf->resv, NULL); in dma_buf_dynamic_attach()
891 list_add(&attach->node, &dmabuf->attachments); in dma_buf_dynamic_attach()
892 dma_resv_unlock(dmabuf->resv); in dma_buf_dynamic_attach()
902 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_dynamic_attach()
903 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_dynamic_attach()
909 sgt = dmabuf->ops->map_dma_buf(attach, DMA_BIDIRECTIONAL); in dma_buf_dynamic_attach()
911 sgt = ERR_PTR(-ENOMEM); in dma_buf_dynamic_attach()
916 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
917 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
918 attach->sgt = sgt; in dma_buf_dynamic_attach()
919 attach->dir = DMA_BIDIRECTIONAL; in dma_buf_dynamic_attach()
929 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
933 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_dynamic_attach()
934 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_dynamic_attach()
942 * dma_buf_attach - Wrapper for dma_buf_dynamic_attach
957 * dma_buf_detach - Remove the given attachment from dmabuf's attachments list;
958 * optionally calls detach() of dma_buf_ops for device-specific detach
969 if (attach->sgt) { in dma_buf_detach()
970 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_detach()
971 dma_resv_lock(attach->dmabuf->resv, NULL); in dma_buf_detach()
973 dmabuf->ops->unmap_dma_buf(attach, attach->sgt, attach->dir); in dma_buf_detach()
975 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_detach()
977 dma_resv_unlock(attach->dmabuf->resv); in dma_buf_detach()
981 dma_resv_lock(dmabuf->resv, NULL); in dma_buf_detach()
982 list_del(&attach->node); in dma_buf_detach()
983 dma_resv_unlock(dmabuf->resv); in dma_buf_detach()
984 if (dmabuf->ops->detach) in dma_buf_detach()
985 dmabuf->ops->detach(dmabuf, attach); in dma_buf_detach()
992 * dma_buf_pin - Lock down the DMA-buf
1001 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_pin()
1004 dma_resv_assert_held(dmabuf->resv); in dma_buf_pin()
1006 if (dmabuf->ops->pin) in dma_buf_pin()
1007 ret = dmabuf->ops->pin(attach); in dma_buf_pin()
1014 * dma_buf_unpin - Remove lock from DMA-buf
1020 struct dma_buf *dmabuf = attach->dmabuf; in dma_buf_unpin()
1022 dma_resv_assert_held(dmabuf->resv); in dma_buf_unpin()
1024 if (dmabuf->ops->unpin) in dma_buf_unpin()
1025 dmabuf->ops->unpin(attach); in dma_buf_unpin()
1030 * dma_buf_map_attachment - Returns the scatterlist table of the attachment;
1037 * on error. May return -EINTR if it is interrupted by a signal.
1052 if (WARN_ON(!attach || !attach->dmabuf)) in dma_buf_map_attachment()
1053 return ERR_PTR(-EINVAL); in dma_buf_map_attachment()
1056 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_map_attachment()
1058 if (attach->sgt) { in dma_buf_map_attachment()
1063 if (attach->dir != direction && in dma_buf_map_attachment()
1064 attach->dir != DMA_BIDIRECTIONAL) in dma_buf_map_attachment()
1065 return ERR_PTR(-EBUSY); in dma_buf_map_attachment()
1067 return attach->sgt; in dma_buf_map_attachment()
1070 if (dma_buf_is_dynamic(attach->dmabuf)) { in dma_buf_map_attachment()
1071 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_map_attachment()
1079 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction); in dma_buf_map_attachment()
1081 sg_table = ERR_PTR(-ENOMEM); in dma_buf_map_attachment()
1083 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_map_attachment()
1087 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) { in dma_buf_map_attachment()
1088 attach->sgt = sg_table; in dma_buf_map_attachment()
1089 attach->dir = direction; in dma_buf_map_attachment()
1097 * dma_buf_unmap_attachment - unmaps and decreases usecount of the buffer;might
1112 if (WARN_ON(!attach || !attach->dmabuf || !sg_table)) in dma_buf_unmap_attachment()
1116 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_unmap_attachment()
1118 if (attach->sgt == sg_table) in dma_buf_unmap_attachment()
1121 if (dma_buf_is_dynamic(attach->dmabuf)) in dma_buf_unmap_attachment()
1122 dma_resv_assert_held(attach->dmabuf->resv); in dma_buf_unmap_attachment()
1124 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction); in dma_buf_unmap_attachment()
1126 if (dma_buf_is_dynamic(attach->dmabuf) && in dma_buf_unmap_attachment()
1133 * dma_buf_move_notify - notify attachments that DMA-buf is moving
1144 dma_resv_assert_held(dmabuf->resv); in dma_buf_move_notify()
1146 list_for_each_entry(attach, &dmabuf->attachments, node) in dma_buf_move_notify()
1147 if (attach->importer_ops) in dma_buf_move_notify()
1148 attach->importer_ops->move_notify(attach); in dma_buf_move_notify()
1157 * - Fallback operations in the kernel, for example when a device is connected
1163 * Since for most kernel internal dma-buf accesses need the entire buffer, a
1164 * vmap interface is introduced. Note that on very old 32-bit architectures
1173 * that the dma-buf layer keeps a reference count for all vmap access and
1174 * calls down into the exporter's vmap function only when no vmapping exists,
1175 * and only unmaps it once. Protection against concurrent vmap/vunmap calls is
1176 * provided by taking the dma_buf->lock mutex.
1178 * - For full compatibility on the importer side with existing userspace
1185 * There is no special interfaces, userspace simply calls mmap on the dma-buf
1188 * DMA_BUF_IOCTL_SYNC can fail with -EAGAIN or -EINTR, in which case it must
1192 * CPU and GPU domains are being accessed through dma-buf at the same time.
1194 * forward directly to existing dma-buf device drivers vfunc hooks. Userspace
1198 * - mmap dma-buf fd
1199 * - for each drawing/upload cycle in CPU 1. SYNC_START ioctl, 2. read/write
1203 * - munmap once you don't need the buffer any more
1210 * - And as a CPU fallback in userspace processing pipelines.
1214 * interfaces with a imported dma-buf buffer object as with a native buffer
1219 * The assumption in the current dma-buf interfaces is that redirecting the
1231 * If the importing subsystem simply provides a special-purpose mmap call to
1232 * set up a mapping in userspace, calling do_mmap with dma_buf->file will
1233 * equally achieve that for a dma-buf object.
1241 struct dma_resv *resv = dmabuf->resv; in __dma_buf_begin_cpu_access()
1254 * dma_buf_begin_cpu_access - Must be called before accessing a dma_buf from the
1255 * cpu in the kernel context. Calls begin_cpu_access to allow exporter-specific
1256 * preparations. Coherency is only guaranteed in the specified range for the
1262 * dma_buf_end_cpu_access(). Only when cpu access is braketed by both calls is
1273 return -EINVAL; in dma_buf_begin_cpu_access()
1275 if (dmabuf->ops->begin_cpu_access) in dma_buf_begin_cpu_access()
1276 ret = dmabuf->ops->begin_cpu_access(dmabuf, direction); in dma_buf_begin_cpu_access()
1278 /* Ensure that all fences are waited upon - but we first allow in dma_buf_begin_cpu_access()
1280 * chooses. A double invocation here will be reasonably cheap no-op. in dma_buf_begin_cpu_access()
1296 return -EINVAL; in dma_buf_begin_cpu_access_partial()
1298 if (dmabuf->ops->begin_cpu_access_partial) in dma_buf_begin_cpu_access_partial()
1299 ret = dmabuf->ops->begin_cpu_access_partial(dmabuf, direction, in dma_buf_begin_cpu_access_partial()
1302 /* Ensure that all fences are waited upon - but we first allow in dma_buf_begin_cpu_access_partial()
1304 * chooses. A double invocation here will be reasonably cheap no-op. in dma_buf_begin_cpu_access_partial()
1314 * dma_buf_end_cpu_access - Must be called after accessing a dma_buf from the
1315 * cpu in the kernel context. Calls end_cpu_access to allow exporter-specific
1316 * actions. Coherency is only guaranteed in the specified range for the
1332 if (dmabuf->ops->end_cpu_access) in dma_buf_end_cpu_access()
1333 ret = dmabuf->ops->end_cpu_access(dmabuf, direction); in dma_buf_end_cpu_access()
1347 if (dmabuf->ops->end_cpu_access_partial) in dma_buf_end_cpu_access_partial()
1348 ret = dmabuf->ops->end_cpu_access_partial(dmabuf, direction, in dma_buf_end_cpu_access_partial()
1356 * dma_buf_mmap - Setup up a userspace mmap with the given vma
1360 * dma-buf buffer.
1376 return -EINVAL; in dma_buf_mmap()
1379 if (!dmabuf->ops->mmap) in dma_buf_mmap()
1380 return -EINVAL; in dma_buf_mmap()
1384 return -EOVERFLOW; in dma_buf_mmap()
1388 dmabuf->size >> PAGE_SHIFT) in dma_buf_mmap()
1389 return -EINVAL; in dma_buf_mmap()
1392 get_file(dmabuf->file); in dma_buf_mmap()
1393 oldfile = vma->vm_file; in dma_buf_mmap()
1394 vma->vm_file = dmabuf->file; in dma_buf_mmap()
1395 vma->vm_pgoff = pgoff; in dma_buf_mmap()
1397 ret = dmabuf->ops->mmap(dmabuf, vma); in dma_buf_mmap()
1400 vma->vm_file = oldfile; in dma_buf_mmap()
1401 fput(dmabuf->file); in dma_buf_mmap()
1412 * dma_buf_vmap - Create virtual mapping for the buffer object into kernel
1430 if (!dmabuf->ops->vmap) in dma_buf_vmap()
1433 mutex_lock(&dmabuf->lock); in dma_buf_vmap()
1434 if (dmabuf->vmapping_counter) { in dma_buf_vmap()
1435 dmabuf->vmapping_counter++; in dma_buf_vmap()
1436 BUG_ON(!dmabuf->vmap_ptr); in dma_buf_vmap()
1437 ptr = dmabuf->vmap_ptr; in dma_buf_vmap()
1441 BUG_ON(dmabuf->vmap_ptr); in dma_buf_vmap()
1443 ptr = dmabuf->ops->vmap(dmabuf); in dma_buf_vmap()
1449 dmabuf->vmap_ptr = ptr; in dma_buf_vmap()
1450 dmabuf->vmapping_counter = 1; in dma_buf_vmap()
1453 mutex_unlock(&dmabuf->lock); in dma_buf_vmap()
1459 * dma_buf_vunmap - Unmap a vmap obtained by dma_buf_vmap.
1468 BUG_ON(!dmabuf->vmap_ptr); in dma_buf_vunmap()
1469 BUG_ON(dmabuf->vmapping_counter == 0); in dma_buf_vunmap()
1470 BUG_ON(dmabuf->vmap_ptr != vaddr); in dma_buf_vunmap()
1472 mutex_lock(&dmabuf->lock); in dma_buf_vunmap()
1473 if (--dmabuf->vmapping_counter == 0) { in dma_buf_vunmap()
1474 if (dmabuf->ops->vunmap) in dma_buf_vunmap()
1475 dmabuf->ops->vunmap(dmabuf, vaddr); in dma_buf_vunmap()
1476 dmabuf->vmap_ptr = NULL; in dma_buf_vunmap()
1478 mutex_unlock(&dmabuf->lock); in dma_buf_vunmap()
1487 return -EINVAL; in dma_buf_get_flags()
1489 if (dmabuf->ops->get_flags) in dma_buf_get_flags()
1490 ret = dmabuf->ops->get_flags(dmabuf, flags); in dma_buf_get_flags()
1499 return -EINVAL; in dma_buf_get_uuid()
1501 if (!dmabuf->ops->get_uuid) in dma_buf_get_uuid()
1502 return -ENODEV; in dma_buf_get_uuid()
1504 return dmabuf->ops->get_uuid(dmabuf, uuid); in dma_buf_get_uuid()
1526 seq_puts(s, "\nDma-buf Objects:\n"); in dma_buf_debug_show()
1527 seq_printf(s, "%-8s\t%-8s\t%-8s\t%-8s\texp_name\t%-8s\n", in dma_buf_debug_show()
1532 ret = dma_resv_lock_interruptible(buf_obj->resv, NULL); in dma_buf_debug_show()
1536 spin_lock(&buf_obj->name_lock); in dma_buf_debug_show()
1538 buf_obj->size, in dma_buf_debug_show()
1539 buf_obj->file->f_flags, buf_obj->file->f_mode, in dma_buf_debug_show()
1540 file_count(buf_obj->file), in dma_buf_debug_show()
1541 buf_obj->exp_name, in dma_buf_debug_show()
1542 file_inode(buf_obj->file)->i_ino, in dma_buf_debug_show()
1543 buf_obj->name ?: ""); in dma_buf_debug_show()
1544 spin_unlock(&buf_obj->name_lock); in dma_buf_debug_show()
1546 robj = buf_obj->resv; in dma_buf_debug_show()
1548 seq = read_seqcount_begin(&robj->seq); in dma_buf_debug_show()
1550 fobj = rcu_dereference(robj->fence); in dma_buf_debug_show()
1551 shared_count = fobj ? fobj->shared_count : 0; in dma_buf_debug_show()
1552 fence = rcu_dereference(robj->fence_excl); in dma_buf_debug_show()
1553 if (!read_seqcount_retry(&robj->seq, seq)) in dma_buf_debug_show()
1560 fence->ops->get_driver_name(fence), in dma_buf_debug_show()
1561 fence->ops->get_timeline_name(fence), in dma_buf_debug_show()
1564 fence = rcu_dereference(fobj->shared[i]); in dma_buf_debug_show()
1568 fence->ops->get_driver_name(fence), in dma_buf_debug_show()
1569 fence->ops->get_timeline_name(fence), in dma_buf_debug_show()
1578 list_for_each_entry(attach_obj, &buf_obj->attachments, node) { in dma_buf_debug_show()
1579 seq_printf(s, "\t%s\n", dev_name(attach_obj->dev)); in dma_buf_debug_show()
1582 dma_resv_unlock(buf_obj->resv); in dma_buf_debug_show()
1588 size += buf_obj->size; in dma_buf_debug_show()