Lines Matching refs:dmabuf

48 	struct dma_buf *dmabuf;
52 dmabuf = dentry->d_fsdata;
53 spin_lock(&dmabuf->name_lock);
54 if (dmabuf->name)
55 ret = strlcpy(name, dmabuf->name, DMA_BUF_NAME_LEN);
56 spin_unlock(&dmabuf->name_lock);
64 struct dma_buf *dmabuf;
66 dmabuf = dentry->d_fsdata;
67 if (unlikely(!dmabuf))
70 BUG_ON(dmabuf->vmapping_counter);
75 * * dmabuf->cb_in/out.active are non-0 despite no pending fence callback
77 BUG_ON(dmabuf->cb_in.active || dmabuf->cb_out.active);
79 dma_buf_stats_teardown(dmabuf);
80 dmabuf->ops->release(dmabuf);
82 if (dmabuf->resv == (struct dma_resv *)&dmabuf[1])
83 dma_resv_fini(dmabuf->resv);
85 WARN_ON(!list_empty(&dmabuf->attachments));
86 module_put(dmabuf->owner);
87 kfree(dmabuf->name);
88 kfree(dmabuf);
93 struct dma_buf *dmabuf;
98 dmabuf = file->private_data;
99 if (dmabuf) {
101 list_del(&dmabuf->list_node);
127 .name = "dmabuf",
134 struct dma_buf *dmabuf;
139 dmabuf = file->private_data;
142 if (!dmabuf->ops->mmap)
147 dmabuf->size >> PAGE_SHIFT)
150 return dmabuf->ops->mmap(dmabuf, vma);
155 struct dma_buf *dmabuf;
161 dmabuf = file->private_data;
167 base = dmabuf->size;
207 struct dma_buf *dmabuf = container_of(dcb->poll, struct dma_buf, poll);
216 fput(dmabuf->file);
240 struct dma_buf *dmabuf;
244 dmabuf = file->private_data;
245 if (!dmabuf || !dmabuf->resv)
248 resv = dmabuf->resv;
250 poll_wait(file, &dmabuf->poll, poll);
259 struct dma_buf_poll_cb_t *dcb = &dmabuf->cb_out;
262 spin_lock_irq(&dmabuf->poll.lock);
267 spin_unlock_irq(&dmabuf->poll.lock);
271 get_file(dmabuf->file);
282 struct dma_buf_poll_cb_t *dcb = &dmabuf->cb_in;
285 spin_lock_irq(&dmabuf->poll.lock);
290 spin_unlock_irq(&dmabuf->poll.lock);
294 get_file(dmabuf->file);
313 * @dmabuf: [in] dmabuf buffer that will be renamed.
321 static long dma_buf_set_name(struct dma_buf *dmabuf, const char __user *buf)
328 spin_lock(&dmabuf->name_lock);
329 kfree(dmabuf->name);
330 dmabuf->name = name;
331 spin_unlock(&dmabuf->name_lock);
337 static long dma_buf_export_sync_file(struct dma_buf *dmabuf,
360 ret = dma_resv_get_singleton(dmabuf->resv, usage, &fence);
393 static long dma_buf_import_sync_file(struct dma_buf *dmabuf,
424 dma_resv_lock(dmabuf->resv, NULL);
426 ret = dma_resv_reserve_fences(dmabuf->resv, num_fences);
429 dma_resv_add_fence(dmabuf->resv, f, usage);
432 dma_resv_unlock(dmabuf->resv);
444 struct dma_buf *dmabuf;
449 dmabuf = file->private_data;
474 ret = dma_buf_end_cpu_access(dmabuf, direction);
476 ret = dma_buf_begin_cpu_access(dmabuf, direction);
482 return dma_buf_set_name(dmabuf, (const char __user *)arg);
486 return dma_buf_export_sync_file(dmabuf, (void __user *)arg);
488 return dma_buf_import_sync_file(dmabuf, (const void __user *)arg);
498 struct dma_buf *dmabuf = file->private_data;
500 seq_printf(m, "size:\t%zu\n", dmabuf->size);
502 seq_printf(m, "count:\t%ld\n", file_count(dmabuf->file) - 1);
503 seq_printf(m, "exp_name:\t%s\n", dmabuf->exp_name);
504 spin_lock(&dmabuf->name_lock);
505 if (dmabuf->name)
506 seq_printf(m, "name:\t%s\n", dmabuf->name);
507 spin_unlock(&dmabuf->name_lock);
542 * not suitable for using it as dentry name by dmabuf stats.
548 file = alloc_file_pseudo(inode, dma_buf_mnt, "dmabuf",
611 struct dma_buf *dmabuf;
644 dmabuf = kzalloc(alloc_size, GFP_KERNEL);
645 if (!dmabuf) {
650 dmabuf->priv = exp_info->priv;
651 dmabuf->ops = exp_info->ops;
652 dmabuf->size = exp_info->size;
653 dmabuf->exp_name = exp_info->exp_name;
654 dmabuf->owner = exp_info->owner;
655 spin_lock_init(&dmabuf->name_lock);
656 init_waitqueue_head(&dmabuf->poll);
657 dmabuf->cb_in.poll = dmabuf->cb_out.poll = &dmabuf->poll;
658 dmabuf->cb_in.active = dmabuf->cb_out.active = 0;
659 INIT_LIST_HEAD(&dmabuf->attachments);
662 dmabuf->resv = (struct dma_resv *)&dmabuf[1];
663 dma_resv_init(dmabuf->resv);
665 dmabuf->resv = resv;
668 ret = dma_buf_stats_setup(dmabuf, file);
672 file->private_data = dmabuf;
673 file->f_path.dentry->d_fsdata = dmabuf;
674 dmabuf->file = file;
677 list_add(&dmabuf->list_node, &db_list.head);
680 return dmabuf;
684 dma_resv_fini(dmabuf->resv);
685 kfree(dmabuf);
696 * @dmabuf: [in] pointer to dma_buf for which fd is required.
701 int dma_buf_fd(struct dma_buf *dmabuf, int flags)
705 if (!dmabuf || !dmabuf->file)
712 fd_install(fd, dmabuf->file);
746 * @dmabuf: [in] buffer to reduce refcount of
752 * in turn, and frees the memory allocated for dmabuf when exported.
754 void dma_buf_put(struct dma_buf *dmabuf)
756 if (WARN_ON(!dmabuf || !dmabuf->file))
759 fput(dmabuf->file);
784 sg_table = attach->dmabuf->ops->map_dma_buf(attach, direction);
789 ret = dma_resv_wait_timeout(attach->dmabuf->resv,
793 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table,
869 * @dmabuf: [in] buffer to attach device to.
885 * Note that this can fail if the backing storage of @dmabuf is in a place not
890 dma_buf_dynamic_attach(struct dma_buf *dmabuf, struct device *dev,
897 if (WARN_ON(!dmabuf || !dev))
908 attach->dmabuf = dmabuf;
914 if (dmabuf->ops->attach) {
915 ret = dmabuf->ops->attach(dmabuf, attach);
919 dma_resv_lock(dmabuf->resv, NULL);
920 list_add(&attach->node, &dmabuf->attachments);
921 dma_resv_unlock(dmabuf->resv);
928 dma_buf_is_dynamic(dmabuf)) {
931 dma_resv_lock(attach->dmabuf->resv, NULL);
932 if (dma_buf_is_dynamic(attach->dmabuf)) {
933 ret = dmabuf->ops->pin(attach);
945 dma_resv_unlock(attach->dmabuf->resv);
957 if (dma_buf_is_dynamic(attach->dmabuf))
958 dmabuf->ops->unpin(attach);
961 dma_resv_unlock(attach->dmabuf->resv);
963 dma_buf_detach(dmabuf, attach);
970 * @dmabuf: [in] buffer to attach device to.
976 struct dma_buf_attachment *dma_buf_attach(struct dma_buf *dmabuf,
979 return dma_buf_dynamic_attach(dmabuf, dev, NULL, NULL);
990 attach->dmabuf->ops->unmap_dma_buf(attach, sg_table, direction);
994 * dma_buf_detach - Remove the given attachment from dmabuf's attachments list
995 * @dmabuf: [in] buffer to detach from.
1002 void dma_buf_detach(struct dma_buf *dmabuf, struct dma_buf_attachment *attach)
1004 if (WARN_ON(!dmabuf || !attach || dmabuf != attach->dmabuf))
1007 dma_resv_lock(dmabuf->resv, NULL);
1013 if (dma_buf_is_dynamic(attach->dmabuf))
1014 dmabuf->ops->unpin(attach);
1018 dma_resv_unlock(dmabuf->resv);
1020 if (dmabuf->ops->detach)
1021 dmabuf->ops->detach(dmabuf, attach);
1043 struct dma_buf *dmabuf = attach->dmabuf;
1048 dma_resv_assert_held(dmabuf->resv);
1050 if (dmabuf->ops->pin)
1051 ret = dmabuf->ops->pin(attach);
1067 struct dma_buf *dmabuf = attach->dmabuf;
1071 dma_resv_assert_held(dmabuf->resv);
1073 if (dmabuf->ops->unpin)
1074 dmabuf->ops->unpin(attach);
1107 if (WARN_ON(!attach || !attach->dmabuf))
1110 dma_resv_assert_held(attach->dmabuf->resv);
1124 if (dma_buf_is_dynamic(attach->dmabuf)) {
1126 r = attach->dmabuf->ops->pin(attach);
1136 if (IS_ERR(sg_table) && dma_buf_is_dynamic(attach->dmabuf) &&
1138 attach->dmabuf->ops->unpin(attach);
1140 if (!IS_ERR(sg_table) && attach->dmabuf->ops->cache_sgt_mapping) {
1183 if (WARN_ON(!attach || !attach->dmabuf))
1186 dma_resv_lock(attach->dmabuf->resv, NULL);
1188 dma_resv_unlock(attach->dmabuf->resv);
1210 if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
1213 dma_resv_assert_held(attach->dmabuf->resv);
1220 if (dma_buf_is_dynamic(attach->dmabuf) &&
1242 if (WARN_ON(!attach || !attach->dmabuf || !sg_table))
1245 dma_resv_lock(attach->dmabuf->resv, NULL);
1247 dma_resv_unlock(attach->dmabuf->resv);
1254 * @dmabuf: [in] buffer which is moving
1259 void dma_buf_move_notify(struct dma_buf *dmabuf)
1263 dma_resv_assert_held(dmabuf->resv);
1265 list_for_each_entry(attach, &dmabuf->attachments, node)
1288 * void \*dma_buf_vmap(struct dma_buf \*dmabuf, struct iosys_map \*map)
1289 * void dma_buf_vunmap(struct dma_buf \*dmabuf, struct iosys_map \*map)
1356 static int __dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
1361 struct dma_resv *resv = dmabuf->resv;
1378 * @dmabuf: [in] buffer to prepare cpu access for.
1392 int dma_buf_begin_cpu_access(struct dma_buf *dmabuf,
1397 if (WARN_ON(!dmabuf))
1400 might_lock(&dmabuf->resv->lock.base);
1402 if (dmabuf->ops->begin_cpu_access)
1403 ret = dmabuf->ops->begin_cpu_access(dmabuf, direction);
1410 ret = __dma_buf_begin_cpu_access(dmabuf, direction);
1421 * @dmabuf: [in] buffer to complete cpu access for.
1428 int dma_buf_end_cpu_access(struct dma_buf *dmabuf,
1433 WARN_ON(!dmabuf);
1435 might_lock(&dmabuf->resv->lock.base);
1437 if (dmabuf->ops->end_cpu_access)
1438 ret = dmabuf->ops->end_cpu_access(dmabuf, direction);
1447 * @dmabuf: [in] buffer that should back the vma
1459 int dma_buf_mmap(struct dma_buf *dmabuf, struct vm_area_struct *vma,
1462 if (WARN_ON(!dmabuf || !vma))
1466 if (!dmabuf->ops->mmap)
1475 dmabuf->size >> PAGE_SHIFT)
1479 vma_set_file(vma, dmabuf->file);
1482 return dmabuf->ops->mmap(dmabuf, vma);
1489 * @dmabuf: [in] buffer to vmap
1502 int dma_buf_vmap(struct dma_buf *dmabuf, struct iosys_map *map)
1509 if (WARN_ON(!dmabuf))
1512 dma_resv_assert_held(dmabuf->resv);
1514 if (!dmabuf->ops->vmap)
1517 if (dmabuf->vmapping_counter) {
1518 dmabuf->vmapping_counter++;
1519 BUG_ON(iosys_map_is_null(&dmabuf->vmap_ptr));
1520 *map = dmabuf->vmap_ptr;
1524 BUG_ON(iosys_map_is_set(&dmabuf->vmap_ptr));
1526 ret = dmabuf->ops->vmap(dmabuf, &ptr);
1530 dmabuf->vmap_ptr = ptr;
1531 dmabuf->vmapping_counter = 1;
1533 *map = dmabuf->vmap_ptr;
1542 * @dmabuf: [in] buffer to vmap
1549 int dma_buf_vmap_unlocked(struct dma_buf *dmabuf, struct iosys_map *map)
1555 if (WARN_ON(!dmabuf))
1558 dma_resv_lock(dmabuf->resv, NULL);
1559 ret = dma_buf_vmap(dmabuf, map);
1560 dma_resv_unlock(dmabuf->resv);
1568 * @dmabuf: [in] buffer to vunmap
1571 void dma_buf_vunmap(struct dma_buf *dmabuf, struct iosys_map *map)
1573 if (WARN_ON(!dmabuf))
1576 dma_resv_assert_held(dmabuf->resv);
1578 BUG_ON(iosys_map_is_null(&dmabuf->vmap_ptr));
1579 BUG_ON(dmabuf->vmapping_counter == 0);
1580 BUG_ON(!iosys_map_is_equal(&dmabuf->vmap_ptr, map));
1582 if (--dmabuf->vmapping_counter == 0) {
1583 if (dmabuf->ops->vunmap)
1584 dmabuf->ops->vunmap(dmabuf, map);
1585 iosys_map_clear(&dmabuf->vmap_ptr);
1592 * @dmabuf: [in] buffer to vunmap
1595 void dma_buf_vunmap_unlocked(struct dma_buf *dmabuf, struct iosys_map *map)
1597 if (WARN_ON(!dmabuf))
1600 dma_resv_lock(dmabuf->resv, NULL);
1601 dma_buf_vunmap(dmabuf, map);
1602 dma_resv_unlock(dmabuf->resv);