Lines Matching refs:gntdev_dmabuf
27 struct gntdev_dmabuf { struct
59 struct gntdev_dmabuf *gntdev_dmabuf; argument
93 struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_exp_wait_obj_new() argument
102 obj->gntdev_dmabuf = gntdev_dmabuf; in dmabuf_exp_wait_obj_new()
107 kref_put(&gntdev_dmabuf->u.exp.refcount, dmabuf_exp_release); in dmabuf_exp_wait_obj_new()
132 struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_exp_wait_obj_signal() argument
137 if (obj->gntdev_dmabuf == gntdev_dmabuf) { in dmabuf_exp_wait_obj_signal()
144 static struct gntdev_dmabuf *
147 struct gntdev_dmabuf *gntdev_dmabuf, *ret = ERR_PTR(-ENOENT); in dmabuf_exp_wait_obj_get_dmabuf() local
150 list_for_each_entry(gntdev_dmabuf, &priv->exp_list, next) in dmabuf_exp_wait_obj_get_dmabuf()
151 if (gntdev_dmabuf->fd == fd) { in dmabuf_exp_wait_obj_get_dmabuf()
153 kref_get(&gntdev_dmabuf->u.exp.refcount); in dmabuf_exp_wait_obj_get_dmabuf()
154 ret = gntdev_dmabuf; in dmabuf_exp_wait_obj_get_dmabuf()
164 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_exp_wait_released() local
174 gntdev_dmabuf = dmabuf_exp_wait_obj_get_dmabuf(priv, fd); in dmabuf_exp_wait_released()
175 if (IS_ERR(gntdev_dmabuf)) in dmabuf_exp_wait_released()
176 return PTR_ERR(gntdev_dmabuf); in dmabuf_exp_wait_released()
183 obj = dmabuf_exp_wait_obj_new(priv, gntdev_dmabuf); in dmabuf_exp_wait_released()
261 struct gntdev_dmabuf *gntdev_dmabuf = attach->dmabuf->priv; in dmabuf_exp_ops_map_dma_buf() local
264 pr_debug("Mapping %d pages for dev %p\n", gntdev_dmabuf->nr_pages, in dmabuf_exp_ops_map_dma_buf()
281 sgt = dmabuf_pages_to_sgt(gntdev_dmabuf->pages, in dmabuf_exp_ops_map_dma_buf()
282 gntdev_dmabuf->nr_pages); in dmabuf_exp_ops_map_dma_buf()
308 struct gntdev_dmabuf *gntdev_dmabuf = in dmabuf_exp_release() local
309 container_of(kref, struct gntdev_dmabuf, u.exp.refcount); in dmabuf_exp_release()
311 dmabuf_exp_wait_obj_signal(gntdev_dmabuf->priv, gntdev_dmabuf); in dmabuf_exp_release()
312 list_del(&gntdev_dmabuf->next); in dmabuf_exp_release()
313 fput(gntdev_dmabuf->priv->filp); in dmabuf_exp_release()
314 kfree(gntdev_dmabuf); in dmabuf_exp_release()
328 struct gntdev_dmabuf *gntdev_dmabuf = dma_buf->priv; in dmabuf_exp_ops_release() local
329 struct gntdev_dmabuf_priv *priv = gntdev_dmabuf->priv; in dmabuf_exp_ops_release()
331 dmabuf_exp_remove_map(gntdev_dmabuf->u.exp.priv, in dmabuf_exp_ops_release()
332 gntdev_dmabuf->u.exp.map); in dmabuf_exp_ops_release()
334 kref_put(&gntdev_dmabuf->u.exp.refcount, dmabuf_exp_release); in dmabuf_exp_ops_release()
359 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_exp_from_pages() local
362 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_exp_from_pages()
363 if (!gntdev_dmabuf) in dmabuf_exp_from_pages()
366 kref_init(&gntdev_dmabuf->u.exp.refcount); in dmabuf_exp_from_pages()
368 gntdev_dmabuf->priv = args->dmabuf_priv; in dmabuf_exp_from_pages()
369 gntdev_dmabuf->nr_pages = args->count; in dmabuf_exp_from_pages()
370 gntdev_dmabuf->pages = args->pages; in dmabuf_exp_from_pages()
371 gntdev_dmabuf->u.exp.priv = args->priv; in dmabuf_exp_from_pages()
372 gntdev_dmabuf->u.exp.map = args->map; in dmabuf_exp_from_pages()
382 exp_info.priv = gntdev_dmabuf; in dmabuf_exp_from_pages()
384 gntdev_dmabuf->dmabuf = dma_buf_export(&exp_info); in dmabuf_exp_from_pages()
385 if (IS_ERR(gntdev_dmabuf->dmabuf)) { in dmabuf_exp_from_pages()
386 ret = PTR_ERR(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
387 gntdev_dmabuf->dmabuf = NULL; in dmabuf_exp_from_pages()
391 ret = dma_buf_fd(gntdev_dmabuf->dmabuf, O_CLOEXEC); in dmabuf_exp_from_pages()
395 gntdev_dmabuf->fd = ret; in dmabuf_exp_from_pages()
401 list_add(&gntdev_dmabuf->next, &args->dmabuf_priv->exp_list); in dmabuf_exp_from_pages()
403 get_file(gntdev_dmabuf->priv->filp); in dmabuf_exp_from_pages()
407 if (gntdev_dmabuf->dmabuf) in dmabuf_exp_from_pages()
408 dma_buf_put(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
409 kfree(gntdev_dmabuf); in dmabuf_exp_from_pages()
530 static void dmabuf_imp_free_storage(struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_imp_free_storage() argument
532 kfree(gntdev_dmabuf->pages); in dmabuf_imp_free_storage()
533 kfree(gntdev_dmabuf->u.imp.refs); in dmabuf_imp_free_storage()
534 kfree(gntdev_dmabuf); in dmabuf_imp_free_storage()
537 static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) in dmabuf_imp_alloc_storage()
539 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_alloc_storage() local
542 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_imp_alloc_storage()
543 if (!gntdev_dmabuf) in dmabuf_imp_alloc_storage()
546 gntdev_dmabuf->u.imp.refs = kcalloc(count, in dmabuf_imp_alloc_storage()
547 sizeof(gntdev_dmabuf->u.imp.refs[0]), in dmabuf_imp_alloc_storage()
549 if (!gntdev_dmabuf->u.imp.refs) in dmabuf_imp_alloc_storage()
552 gntdev_dmabuf->pages = kcalloc(count, in dmabuf_imp_alloc_storage()
553 sizeof(gntdev_dmabuf->pages[0]), in dmabuf_imp_alloc_storage()
555 if (!gntdev_dmabuf->pages) in dmabuf_imp_alloc_storage()
558 gntdev_dmabuf->nr_pages = count; in dmabuf_imp_alloc_storage()
561 gntdev_dmabuf->u.imp.refs[i] = INVALID_GRANT_REF; in dmabuf_imp_alloc_storage()
563 return gntdev_dmabuf; in dmabuf_imp_alloc_storage()
566 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_alloc_storage()
571 static struct gntdev_dmabuf *
575 struct gntdev_dmabuf *gntdev_dmabuf, *ret; in dmabuf_imp_to_refs() local
586 gntdev_dmabuf = dmabuf_imp_alloc_storage(count); in dmabuf_imp_to_refs()
587 if (IS_ERR(gntdev_dmabuf)) { in dmabuf_imp_to_refs()
588 ret = gntdev_dmabuf; in dmabuf_imp_to_refs()
592 gntdev_dmabuf->priv = priv; in dmabuf_imp_to_refs()
593 gntdev_dmabuf->fd = fd; in dmabuf_imp_to_refs()
601 gntdev_dmabuf->u.imp.attach = attach; in dmabuf_imp_to_refs()
618 if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) { in dmabuf_imp_to_refs()
621 attach->dmabuf->size, gntdev_dmabuf->nr_pages); in dmabuf_imp_to_refs()
625 gntdev_dmabuf->u.imp.sgt = sgt; in dmabuf_imp_to_refs()
641 gntdev_dmabuf->pages[i++] = page; in dmabuf_imp_to_refs()
644 ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gntdev_dmabuf->pages, in dmabuf_imp_to_refs()
645 gntdev_dmabuf->u.imp.refs, in dmabuf_imp_to_refs()
653 list_add(&gntdev_dmabuf->next, &priv->imp_list); in dmabuf_imp_to_refs()
656 return gntdev_dmabuf; in dmabuf_imp_to_refs()
659 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, count); in dmabuf_imp_to_refs()
665 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_to_refs()
675 static struct gntdev_dmabuf *
678 struct gntdev_dmabuf *q, *gntdev_dmabuf, *ret = ERR_PTR(-ENOENT); in dmabuf_imp_find_unlink() local
681 list_for_each_entry_safe(gntdev_dmabuf, q, &priv->imp_list, next) { in dmabuf_imp_find_unlink()
682 if (gntdev_dmabuf->fd == fd) { in dmabuf_imp_find_unlink()
684 ret = gntdev_dmabuf; in dmabuf_imp_find_unlink()
685 list_del(&gntdev_dmabuf->next); in dmabuf_imp_find_unlink()
695 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_release() local
699 gntdev_dmabuf = dmabuf_imp_find_unlink(priv, fd); in dmabuf_imp_release()
700 if (IS_ERR(gntdev_dmabuf)) in dmabuf_imp_release()
701 return PTR_ERR(gntdev_dmabuf); in dmabuf_imp_release()
705 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, in dmabuf_imp_release()
706 gntdev_dmabuf->nr_pages); in dmabuf_imp_release()
708 attach = gntdev_dmabuf->u.imp.attach; in dmabuf_imp_release()
710 if (gntdev_dmabuf->u.imp.sgt) in dmabuf_imp_release()
711 dma_buf_unmap_attachment_unlocked(attach, gntdev_dmabuf->u.imp.sgt, in dmabuf_imp_release()
717 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_release()
723 struct gntdev_dmabuf *q, *gntdev_dmabuf; in dmabuf_imp_release_all() local
725 list_for_each_entry_safe(gntdev_dmabuf, q, &priv->imp_list, next) in dmabuf_imp_release_all()
726 dmabuf_imp_release(priv, gntdev_dmabuf->fd); in dmabuf_imp_release_all()
788 struct gntdev_dmabuf *gntdev_dmabuf; in gntdev_ioctl_dmabuf_imp_to_refs() local
797 gntdev_dmabuf = dmabuf_imp_to_refs(priv->dmabuf_priv, in gntdev_ioctl_dmabuf_imp_to_refs()
800 if (IS_ERR(gntdev_dmabuf)) in gntdev_ioctl_dmabuf_imp_to_refs()
801 return PTR_ERR(gntdev_dmabuf); in gntdev_ioctl_dmabuf_imp_to_refs()
803 if (copy_to_user(u->refs, gntdev_dmabuf->u.imp.refs, in gntdev_ioctl_dmabuf_imp_to_refs()