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()
267 struct gntdev_dmabuf *gntdev_dmabuf = attach->dmabuf->priv; in dmabuf_exp_ops_map_dma_buf() local
270 pr_debug("Mapping %d pages for dev %p\n", gntdev_dmabuf->nr_pages, in dmabuf_exp_ops_map_dma_buf()
287 sgt = dmabuf_pages_to_sgt(gntdev_dmabuf->pages, in dmabuf_exp_ops_map_dma_buf()
288 gntdev_dmabuf->nr_pages); in dmabuf_exp_ops_map_dma_buf()
314 struct gntdev_dmabuf *gntdev_dmabuf = in dmabuf_exp_release() local
315 container_of(kref, struct gntdev_dmabuf, u.exp.refcount); in dmabuf_exp_release()
317 dmabuf_exp_wait_obj_signal(gntdev_dmabuf->priv, gntdev_dmabuf); in dmabuf_exp_release()
318 list_del(&gntdev_dmabuf->next); in dmabuf_exp_release()
319 fput(gntdev_dmabuf->priv->filp); in dmabuf_exp_release()
320 kfree(gntdev_dmabuf); in dmabuf_exp_release()
334 struct gntdev_dmabuf *gntdev_dmabuf = dma_buf->priv; in dmabuf_exp_ops_release() local
335 struct gntdev_dmabuf_priv *priv = gntdev_dmabuf->priv; in dmabuf_exp_ops_release()
337 dmabuf_exp_remove_map(gntdev_dmabuf->u.exp.priv, in dmabuf_exp_ops_release()
338 gntdev_dmabuf->u.exp.map); in dmabuf_exp_ops_release()
340 kref_put(&gntdev_dmabuf->u.exp.refcount, dmabuf_exp_release); in dmabuf_exp_ops_release()
365 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_exp_from_pages() local
368 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_exp_from_pages()
369 if (!gntdev_dmabuf) in dmabuf_exp_from_pages()
372 kref_init(&gntdev_dmabuf->u.exp.refcount); in dmabuf_exp_from_pages()
374 gntdev_dmabuf->priv = args->dmabuf_priv; in dmabuf_exp_from_pages()
375 gntdev_dmabuf->nr_pages = args->count; in dmabuf_exp_from_pages()
376 gntdev_dmabuf->pages = args->pages; in dmabuf_exp_from_pages()
377 gntdev_dmabuf->u.exp.priv = args->priv; in dmabuf_exp_from_pages()
378 gntdev_dmabuf->u.exp.map = args->map; in dmabuf_exp_from_pages()
388 exp_info.priv = gntdev_dmabuf; in dmabuf_exp_from_pages()
390 gntdev_dmabuf->dmabuf = dma_buf_export(&exp_info); in dmabuf_exp_from_pages()
391 if (IS_ERR(gntdev_dmabuf->dmabuf)) { in dmabuf_exp_from_pages()
392 ret = PTR_ERR(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
393 gntdev_dmabuf->dmabuf = NULL; in dmabuf_exp_from_pages()
397 ret = dma_buf_fd(gntdev_dmabuf->dmabuf, O_CLOEXEC); in dmabuf_exp_from_pages()
401 gntdev_dmabuf->fd = ret; in dmabuf_exp_from_pages()
407 list_add(&gntdev_dmabuf->next, &args->dmabuf_priv->exp_list); in dmabuf_exp_from_pages()
409 get_file(gntdev_dmabuf->priv->filp); in dmabuf_exp_from_pages()
413 if (gntdev_dmabuf->dmabuf) in dmabuf_exp_from_pages()
414 dma_buf_put(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
415 kfree(gntdev_dmabuf); in dmabuf_exp_from_pages()
536 static void dmabuf_imp_free_storage(struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_imp_free_storage() argument
538 kfree(gntdev_dmabuf->pages); in dmabuf_imp_free_storage()
539 kfree(gntdev_dmabuf->u.imp.refs); in dmabuf_imp_free_storage()
540 kfree(gntdev_dmabuf); in dmabuf_imp_free_storage()
543 static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) in dmabuf_imp_alloc_storage()
545 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_alloc_storage() local
548 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_imp_alloc_storage()
549 if (!gntdev_dmabuf) in dmabuf_imp_alloc_storage()
552 gntdev_dmabuf->u.imp.refs = kcalloc(count, in dmabuf_imp_alloc_storage()
553 sizeof(gntdev_dmabuf->u.imp.refs[0]), in dmabuf_imp_alloc_storage()
555 if (!gntdev_dmabuf->u.imp.refs) in dmabuf_imp_alloc_storage()
558 gntdev_dmabuf->pages = kcalloc(count, in dmabuf_imp_alloc_storage()
559 sizeof(gntdev_dmabuf->pages[0]), in dmabuf_imp_alloc_storage()
561 if (!gntdev_dmabuf->pages) in dmabuf_imp_alloc_storage()
564 gntdev_dmabuf->nr_pages = count; in dmabuf_imp_alloc_storage()
567 gntdev_dmabuf->u.imp.refs[i] = GRANT_INVALID_REF; in dmabuf_imp_alloc_storage()
569 return gntdev_dmabuf; in dmabuf_imp_alloc_storage()
572 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_alloc_storage()
577 static struct gntdev_dmabuf *
581 struct gntdev_dmabuf *gntdev_dmabuf, *ret; in dmabuf_imp_to_refs() local
592 gntdev_dmabuf = dmabuf_imp_alloc_storage(count); in dmabuf_imp_to_refs()
593 if (IS_ERR(gntdev_dmabuf)) { in dmabuf_imp_to_refs()
594 ret = gntdev_dmabuf; in dmabuf_imp_to_refs()
598 gntdev_dmabuf->priv = priv; in dmabuf_imp_to_refs()
599 gntdev_dmabuf->fd = fd; in dmabuf_imp_to_refs()
607 gntdev_dmabuf->u.imp.attach = attach; in dmabuf_imp_to_refs()
624 if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) { in dmabuf_imp_to_refs()
627 attach->dmabuf->size, gntdev_dmabuf->nr_pages); in dmabuf_imp_to_refs()
631 gntdev_dmabuf->u.imp.sgt = sgt; in dmabuf_imp_to_refs()
647 gntdev_dmabuf->pages[i++] = page; in dmabuf_imp_to_refs()
650 ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gntdev_dmabuf->pages, in dmabuf_imp_to_refs()
651 gntdev_dmabuf->u.imp.refs, in dmabuf_imp_to_refs()
659 list_add(&gntdev_dmabuf->next, &priv->imp_list); in dmabuf_imp_to_refs()
662 return gntdev_dmabuf; in dmabuf_imp_to_refs()
665 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, count); in dmabuf_imp_to_refs()
671 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_to_refs()
681 static struct gntdev_dmabuf *
684 struct gntdev_dmabuf *q, *gntdev_dmabuf, *ret = ERR_PTR(-ENOENT); in dmabuf_imp_find_unlink() local
687 list_for_each_entry_safe(gntdev_dmabuf, q, &priv->imp_list, next) { in dmabuf_imp_find_unlink()
688 if (gntdev_dmabuf->fd == fd) { in dmabuf_imp_find_unlink()
690 ret = gntdev_dmabuf; in dmabuf_imp_find_unlink()
691 list_del(&gntdev_dmabuf->next); in dmabuf_imp_find_unlink()
701 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_release() local
705 gntdev_dmabuf = dmabuf_imp_find_unlink(priv, fd); in dmabuf_imp_release()
706 if (IS_ERR(gntdev_dmabuf)) in dmabuf_imp_release()
707 return PTR_ERR(gntdev_dmabuf); in dmabuf_imp_release()
711 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, in dmabuf_imp_release()
712 gntdev_dmabuf->nr_pages); in dmabuf_imp_release()
714 attach = gntdev_dmabuf->u.imp.attach; in dmabuf_imp_release()
716 if (gntdev_dmabuf->u.imp.sgt) in dmabuf_imp_release()
717 dma_buf_unmap_attachment(attach, gntdev_dmabuf->u.imp.sgt, in dmabuf_imp_release()
723 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_release()
729 struct gntdev_dmabuf *q, *gntdev_dmabuf; in dmabuf_imp_release_all() local
731 list_for_each_entry_safe(gntdev_dmabuf, q, &priv->imp_list, next) in dmabuf_imp_release_all()
732 dmabuf_imp_release(priv, gntdev_dmabuf->fd); in dmabuf_imp_release_all()
794 struct gntdev_dmabuf *gntdev_dmabuf; in gntdev_ioctl_dmabuf_imp_to_refs() local
803 gntdev_dmabuf = dmabuf_imp_to_refs(priv->dmabuf_priv, in gntdev_ioctl_dmabuf_imp_to_refs()
806 if (IS_ERR(gntdev_dmabuf)) in gntdev_ioctl_dmabuf_imp_to_refs()
807 return PTR_ERR(gntdev_dmabuf); in gntdev_ioctl_dmabuf_imp_to_refs()
809 if (copy_to_user(u->refs, gntdev_dmabuf->u.imp.refs, in gntdev_ioctl_dmabuf_imp_to_refs()