Lines Matching refs:gntdev_dmabuf
33 struct gntdev_dmabuf { struct
65 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()
262 struct gntdev_dmabuf *gntdev_dmabuf = attach->dmabuf->priv; in dmabuf_exp_ops_map_dma_buf() local
265 pr_debug("Mapping %d pages for dev %p\n", gntdev_dmabuf->nr_pages, in dmabuf_exp_ops_map_dma_buf()
282 sgt = dmabuf_pages_to_sgt(gntdev_dmabuf->pages, in dmabuf_exp_ops_map_dma_buf()
283 gntdev_dmabuf->nr_pages); in dmabuf_exp_ops_map_dma_buf()
309 struct gntdev_dmabuf *gntdev_dmabuf = in dmabuf_exp_release() local
310 container_of(kref, struct gntdev_dmabuf, u.exp.refcount); in dmabuf_exp_release()
312 dmabuf_exp_wait_obj_signal(gntdev_dmabuf->priv, gntdev_dmabuf); in dmabuf_exp_release()
313 list_del(&gntdev_dmabuf->next); 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()
382 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_exp_from_pages() local
385 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_exp_from_pages()
386 if (!gntdev_dmabuf) in dmabuf_exp_from_pages()
389 kref_init(&gntdev_dmabuf->u.exp.refcount); in dmabuf_exp_from_pages()
391 gntdev_dmabuf->priv = args->dmabuf_priv; in dmabuf_exp_from_pages()
392 gntdev_dmabuf->nr_pages = args->count; in dmabuf_exp_from_pages()
393 gntdev_dmabuf->pages = args->pages; in dmabuf_exp_from_pages()
394 gntdev_dmabuf->u.exp.priv = args->priv; in dmabuf_exp_from_pages()
395 gntdev_dmabuf->u.exp.map = args->map; in dmabuf_exp_from_pages()
405 exp_info.priv = gntdev_dmabuf; in dmabuf_exp_from_pages()
407 gntdev_dmabuf->dmabuf = dma_buf_export(&exp_info); in dmabuf_exp_from_pages()
408 if (IS_ERR(gntdev_dmabuf->dmabuf)) { in dmabuf_exp_from_pages()
409 ret = PTR_ERR(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
410 gntdev_dmabuf->dmabuf = NULL; in dmabuf_exp_from_pages()
414 ret = dma_buf_fd(gntdev_dmabuf->dmabuf, O_CLOEXEC); in dmabuf_exp_from_pages()
418 gntdev_dmabuf->fd = ret; in dmabuf_exp_from_pages()
424 list_add(&gntdev_dmabuf->next, &args->dmabuf_priv->exp_list); in dmabuf_exp_from_pages()
429 if (gntdev_dmabuf->dmabuf) in dmabuf_exp_from_pages()
430 dma_buf_put(gntdev_dmabuf->dmabuf); in dmabuf_exp_from_pages()
431 kfree(gntdev_dmabuf); in dmabuf_exp_from_pages()
557 static void dmabuf_imp_free_storage(struct gntdev_dmabuf *gntdev_dmabuf) in dmabuf_imp_free_storage() argument
559 kfree(gntdev_dmabuf->pages); in dmabuf_imp_free_storage()
560 kfree(gntdev_dmabuf->u.imp.refs); in dmabuf_imp_free_storage()
561 kfree(gntdev_dmabuf); in dmabuf_imp_free_storage()
564 static struct gntdev_dmabuf *dmabuf_imp_alloc_storage(int count) in dmabuf_imp_alloc_storage()
566 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_alloc_storage() local
569 gntdev_dmabuf = kzalloc(sizeof(*gntdev_dmabuf), GFP_KERNEL); in dmabuf_imp_alloc_storage()
570 if (!gntdev_dmabuf) in dmabuf_imp_alloc_storage()
573 gntdev_dmabuf->u.imp.refs = kcalloc(count, in dmabuf_imp_alloc_storage()
574 sizeof(gntdev_dmabuf->u.imp.refs[0]), in dmabuf_imp_alloc_storage()
576 if (!gntdev_dmabuf->u.imp.refs) in dmabuf_imp_alloc_storage()
579 gntdev_dmabuf->pages = kcalloc(count, in dmabuf_imp_alloc_storage()
580 sizeof(gntdev_dmabuf->pages[0]), in dmabuf_imp_alloc_storage()
582 if (!gntdev_dmabuf->pages) in dmabuf_imp_alloc_storage()
585 gntdev_dmabuf->nr_pages = count; in dmabuf_imp_alloc_storage()
588 gntdev_dmabuf->u.imp.refs[i] = GRANT_INVALID_REF; in dmabuf_imp_alloc_storage()
590 return gntdev_dmabuf; in dmabuf_imp_alloc_storage()
593 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_alloc_storage()
598 static struct gntdev_dmabuf *
602 struct gntdev_dmabuf *gntdev_dmabuf, *ret; in dmabuf_imp_to_refs() local
613 gntdev_dmabuf = dmabuf_imp_alloc_storage(count); in dmabuf_imp_to_refs()
614 if (IS_ERR(gntdev_dmabuf)) { in dmabuf_imp_to_refs()
615 ret = gntdev_dmabuf; in dmabuf_imp_to_refs()
619 gntdev_dmabuf->priv = priv; in dmabuf_imp_to_refs()
620 gntdev_dmabuf->fd = fd; in dmabuf_imp_to_refs()
628 gntdev_dmabuf->u.imp.attach = attach; in dmabuf_imp_to_refs()
637 if (attach->dmabuf->size != gntdev_dmabuf->nr_pages << PAGE_SHIFT) { in dmabuf_imp_to_refs()
640 attach->dmabuf->size, gntdev_dmabuf->nr_pages); in dmabuf_imp_to_refs()
644 gntdev_dmabuf->u.imp.sgt = sgt; in dmabuf_imp_to_refs()
660 gntdev_dmabuf->pages[i++] = page; in dmabuf_imp_to_refs()
663 ret = ERR_PTR(dmabuf_imp_grant_foreign_access(gntdev_dmabuf->pages, in dmabuf_imp_to_refs()
664 gntdev_dmabuf->u.imp.refs, in dmabuf_imp_to_refs()
672 list_add(&gntdev_dmabuf->next, &priv->imp_list); in dmabuf_imp_to_refs()
675 return gntdev_dmabuf; in dmabuf_imp_to_refs()
678 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, count); in dmabuf_imp_to_refs()
684 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_to_refs()
694 static struct gntdev_dmabuf *
697 struct gntdev_dmabuf *q, *gntdev_dmabuf, *ret = ERR_PTR(-ENOENT); in dmabuf_imp_find_unlink() local
700 list_for_each_entry_safe(gntdev_dmabuf, q, &priv->imp_list, next) { in dmabuf_imp_find_unlink()
701 if (gntdev_dmabuf->fd == fd) { in dmabuf_imp_find_unlink()
703 ret = gntdev_dmabuf; in dmabuf_imp_find_unlink()
704 list_del(&gntdev_dmabuf->next); in dmabuf_imp_find_unlink()
714 struct gntdev_dmabuf *gntdev_dmabuf; in dmabuf_imp_release() local
718 gntdev_dmabuf = dmabuf_imp_find_unlink(priv, fd); in dmabuf_imp_release()
719 if (IS_ERR(gntdev_dmabuf)) in dmabuf_imp_release()
720 return PTR_ERR(gntdev_dmabuf); in dmabuf_imp_release()
724 dmabuf_imp_end_foreign_access(gntdev_dmabuf->u.imp.refs, in dmabuf_imp_release()
725 gntdev_dmabuf->nr_pages); in dmabuf_imp_release()
727 attach = gntdev_dmabuf->u.imp.attach; in dmabuf_imp_release()
729 if (gntdev_dmabuf->u.imp.sgt) in dmabuf_imp_release()
730 dma_buf_unmap_attachment(attach, gntdev_dmabuf->u.imp.sgt, in dmabuf_imp_release()
736 dmabuf_imp_free_storage(gntdev_dmabuf); in dmabuf_imp_release()
799 struct gntdev_dmabuf *gntdev_dmabuf; in gntdev_ioctl_dmabuf_imp_to_refs() local
808 gntdev_dmabuf = dmabuf_imp_to_refs(priv->dmabuf_priv, in gntdev_ioctl_dmabuf_imp_to_refs()
811 if (IS_ERR(gntdev_dmabuf)) in gntdev_ioctl_dmabuf_imp_to_refs()
812 return PTR_ERR(gntdev_dmabuf); in gntdev_ioctl_dmabuf_imp_to_refs()
814 if (copy_to_user(u->refs, gntdev_dmabuf->u.imp.refs, in gntdev_ioctl_dmabuf_imp_to_refs()