Lines Matching refs:gntdev_dmabuf
33 struct gntdev_dmabuf { struct
65 struct gntdev_dmabuf *gntdev_dmabuf; argument
99 struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_exp_wait_obj_new() argument
108 obj->gntdev_dmabuf = gntdev_dmabuf; in dmabuf_exp_wait_obj_new()
113 kref_put(&gntdev_dmabuf->u.exp.refcount, dmabuf_exp_release); in dmabuf_exp_wait_obj_new()
138 struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_exp_wait_obj_signal() argument
143 if (obj->gntdev_dmabuf == gntdev_dmabuf) { in dmabuf_exp_wait_obj_signal()
150 static struct gntdev_dmabuf *
153 struct gntdev_dmabuf *gntdev_dmabuf, *ret = ERR_PTR(-ENOENT); in dmabuf_exp_wait_obj_get_dmabuf() local
156 list_for_each_entry(gntdev_dmabuf, &priv->exp_list, next) in dmabuf_exp_wait_obj_get_dmabuf()
157 if (gntdev_dmabuf->fd == fd) { in dmabuf_exp_wait_obj_get_dmabuf()
159 kref_get(&gntdev_dmabuf->u.exp.refcount); in dmabuf_exp_wait_obj_get_dmabuf()
160 ret = gntdev_dmabuf; in dmabuf_exp_wait_obj_get_dmabuf()
170 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_exp_wait_released() local
180 gntdev_dmabuf = dmabuf_exp_wait_obj_get_dmabuf(priv, fd); in dmabuf_exp_wait_released()
181 if (IS_ERR(gntdev_dmabuf)) in dmabuf_exp_wait_released()
182 return PTR_ERR(gntdev_dmabuf); in dmabuf_exp_wait_released()
189 obj = dmabuf_exp_wait_obj_new(priv, gntdev_dmabuf); in dmabuf_exp_wait_released()
268 struct gntdev_dmabuf *gntdev_dmabuf = attach->dmabuf->priv; in dmabuf_exp_ops_map_dma_buf() local
271 pr_debug("Mapping %d pages for dev %p\n", gntdev_dmabuf->nr_pages, in dmabuf_exp_ops_map_dma_buf()
288 sgt = dmabuf_pages_to_sgt(gntdev_dmabuf->pages, in dmabuf_exp_ops_map_dma_buf()
289 gntdev_dmabuf->nr_pages); in dmabuf_exp_ops_map_dma_buf()
315 struct gntdev_dmabuf *gntdev_dmabuf = in dmabuf_exp_release() local
316 container_of(kref, struct gntdev_dmabuf, u.exp.refcount); in dmabuf_exp_release()
318 dmabuf_exp_wait_obj_signal(gntdev_dmabuf->priv, gntdev_dmabuf); in dmabuf_exp_release()
319 list_del(&gntdev_dmabuf->next); in dmabuf_exp_release()
320 fput(gntdev_dmabuf->priv->filp); in dmabuf_exp_release()
321 kfree(gntdev_dmabuf); in dmabuf_exp_release()
335 struct gntdev_dmabuf *gntdev_dmabuf = dma_buf->priv; in dmabuf_exp_ops_release() local
336 struct gntdev_dmabuf_priv *priv = gntdev_dmabuf->priv; in dmabuf_exp_ops_release()
338 dmabuf_exp_remove_map(gntdev_dmabuf->u.exp.priv, in dmabuf_exp_ops_release()
339 gntdev_dmabuf->u.exp.map); in dmabuf_exp_ops_release()
341 kref_put(&gntdev_dmabuf->u.exp.refcount, dmabuf_exp_release); in dmabuf_exp_ops_release()
389 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_exp_from_pages() local
392 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_exp_from_pages()
393 if (!gntdev_dmabuf) in dmabuf_exp_from_pages()
396 kref_init(&gntdev_dmabuf->u.exp.refcount); in dmabuf_exp_from_pages()
398 gntdev_dmabuf->priv = args->dmabuf_priv; in dmabuf_exp_from_pages()
399 gntdev_dmabuf->nr_pages = args->count; in dmabuf_exp_from_pages()
400 gntdev_dmabuf->pages = args->pages; in dmabuf_exp_from_pages()
401 gntdev_dmabuf->u.exp.priv = args->priv; in dmabuf_exp_from_pages()
402 gntdev_dmabuf->u.exp.map = args->map; in dmabuf_exp_from_pages()
412 exp_info.priv = gntdev_dmabuf; in dmabuf_exp_from_pages()
414 gntdev_dmabuf->dmabuf = dma_buf_export(&exp_info); in dmabuf_exp_from_pages()
415 if (IS_ERR(gntdev_dmabuf->dmabuf)) { in dmabuf_exp_from_pages()
416 ret = PTR_ERR(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
417 gntdev_dmabuf->dmabuf = NULL; in dmabuf_exp_from_pages()
421 ret = dma_buf_fd(gntdev_dmabuf->dmabuf, O_CLOEXEC); in dmabuf_exp_from_pages()
425 gntdev_dmabuf->fd = ret; in dmabuf_exp_from_pages()
431 list_add(&gntdev_dmabuf->next, &args->dmabuf_priv->exp_list); in dmabuf_exp_from_pages()
433 get_file(gntdev_dmabuf->priv->filp); in dmabuf_exp_from_pages()
437 if (gntdev_dmabuf->dmabuf) in dmabuf_exp_from_pages()
438 dma_buf_put(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
439 kfree(gntdev_dmabuf); in dmabuf_exp_from_pages()
565 static void dmabuf_imp_free_storage(struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_imp_free_storage() argument
567 kfree(gntdev_dmabuf->pages); in dmabuf_imp_free_storage()
568 kfree(gntdev_dmabuf->u.imp.refs); in dmabuf_imp_free_storage()
569 kfree(gntdev_dmabuf); in dmabuf_imp_free_storage()
572 static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) in dmabuf_imp_alloc_storage()
574 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_alloc_storage() local
577 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_imp_alloc_storage()
578 if (!gntdev_dmabuf) in dmabuf_imp_alloc_storage()
581 gntdev_dmabuf->u.imp.refs = kcalloc(count, in dmabuf_imp_alloc_storage()
582 sizeof(gntdev_dmabuf->u.imp.refs[0]), in dmabuf_imp_alloc_storage()
584 if (!gntdev_dmabuf->u.imp.refs) in dmabuf_imp_alloc_storage()
587 gntdev_dmabuf->pages = kcalloc(count, in dmabuf_imp_alloc_storage()
588 sizeof(gntdev_dmabuf->pages[0]), in dmabuf_imp_alloc_storage()
590 if (!gntdev_dmabuf->pages) in dmabuf_imp_alloc_storage()
593 gntdev_dmabuf->nr_pages = count; in dmabuf_imp_alloc_storage()
596 gntdev_dmabuf->u.imp.refs[i] = GRANT_INVALID_REF; in dmabuf_imp_alloc_storage()
598 return gntdev_dmabuf; in dmabuf_imp_alloc_storage()
601 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_alloc_storage()
606 static struct gntdev_dmabuf *
610 struct gntdev_dmabuf *gntdev_dmabuf, *ret; in dmabuf_imp_to_refs() local
621 gntdev_dmabuf = dmabuf_imp_alloc_storage(count); in dmabuf_imp_to_refs()
622 if (IS_ERR(gntdev_dmabuf)) { in dmabuf_imp_to_refs()
623 ret = gntdev_dmabuf; in dmabuf_imp_to_refs()
627 gntdev_dmabuf->priv = priv; in dmabuf_imp_to_refs()
628 gntdev_dmabuf->fd = fd; in dmabuf_imp_to_refs()
636 gntdev_dmabuf->u.imp.attach = attach; in dmabuf_imp_to_refs()
645 if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) { in dmabuf_imp_to_refs()
648 attach->dmabuf->size, gntdev_dmabuf->nr_pages); in dmabuf_imp_to_refs()
652 gntdev_dmabuf->u.imp.sgt = sgt; in dmabuf_imp_to_refs()
668 gntdev_dmabuf->pages[i++] = page; in dmabuf_imp_to_refs()
671 ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gntdev_dmabuf->pages, in dmabuf_imp_to_refs()
672 gntdev_dmabuf->u.imp.refs, in dmabuf_imp_to_refs()
680 list_add(&gntdev_dmabuf->next, &priv->imp_list); in dmabuf_imp_to_refs()
683 return gntdev_dmabuf; in dmabuf_imp_to_refs()
686 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, count); in dmabuf_imp_to_refs()
692 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_to_refs()
702 static struct gntdev_dmabuf *
705 struct gntdev_dmabuf *q, *gntdev_dmabuf, *ret = ERR_PTR(-ENOENT); in dmabuf_imp_find_unlink() local
708 list_for_each_entry_safe(gntdev_dmabuf, q, &priv->imp_list, next) { in dmabuf_imp_find_unlink()
709 if (gntdev_dmabuf->fd == fd) { in dmabuf_imp_find_unlink()
711 ret = gntdev_dmabuf; in dmabuf_imp_find_unlink()
712 list_del(&gntdev_dmabuf->next); in dmabuf_imp_find_unlink()
722 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_release() local
726 gntdev_dmabuf = dmabuf_imp_find_unlink(priv, fd); in dmabuf_imp_release()
727 if (IS_ERR(gntdev_dmabuf)) in dmabuf_imp_release()
728 return PTR_ERR(gntdev_dmabuf); in dmabuf_imp_release()
732 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, in dmabuf_imp_release()
733 gntdev_dmabuf->nr_pages); in dmabuf_imp_release()
735 attach = gntdev_dmabuf->u.imp.attach; in dmabuf_imp_release()
737 if (gntdev_dmabuf->u.imp.sgt) in dmabuf_imp_release()
738 dma_buf_unmap_attachment(attach, gntdev_dmabuf->u.imp.sgt, in dmabuf_imp_release()
744 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_release()
750 struct gntdev_dmabuf *q, *gntdev_dmabuf; in dmabuf_imp_release_all() local
752 list_for_each_entry_safe(gntdev_dmabuf, q, &priv->imp_list, next) in dmabuf_imp_release_all()
753 dmabuf_imp_release(priv, gntdev_dmabuf->fd); in dmabuf_imp_release_all()
815 struct gntdev_dmabuf *gntdev_dmabuf; in gntdev_ioctl_dmabuf_imp_to_refs() local
824 gntdev_dmabuf = dmabuf_imp_to_refs(priv->dmabuf_priv, in gntdev_ioctl_dmabuf_imp_to_refs()
827 if (IS_ERR(gntdev_dmabuf)) in gntdev_ioctl_dmabuf_imp_to_refs()
828 return PTR_ERR(gntdev_dmabuf); in gntdev_ioctl_dmabuf_imp_to_refs()
830 if (copy_to_user(u->refs, gntdev_dmabuf->u.imp.refs, in gntdev_ioctl_dmabuf_imp_to_refs()