Lines Matching refs:buf
71 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_cookie() local
73 return &buf->dma_addr; in vb2_dc_cookie()
78 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_vaddr() local
80 if (!buf->vaddr && buf->db_attach) in vb2_dc_vaddr()
81 buf->vaddr = dma_buf_vmap(buf->db_attach->dmabuf); in vb2_dc_vaddr()
83 return buf->vaddr; in vb2_dc_vaddr()
88 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_num_users() local
90 return refcount_read(&buf->refcount); in vb2_dc_num_users()
95 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_prepare() local
96 struct sg_table *sgt = buf->dma_sgt; in vb2_dc_prepare()
99 if (!sgt || buf->db_attach) in vb2_dc_prepare()
102 dma_sync_sg_for_device(buf->dev, sgt->sgl, sgt->orig_nents, in vb2_dc_prepare()
103 buf->dma_dir); in vb2_dc_prepare()
108 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_finish() local
109 struct sg_table *sgt = buf->dma_sgt; in vb2_dc_finish()
112 if (!sgt || buf->db_attach) in vb2_dc_finish()
115 dma_sync_sg_for_cpu(buf->dev, sgt->sgl, sgt->orig_nents, buf->dma_dir); in vb2_dc_finish()
124 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_put() local
126 if (!refcount_dec_and_test(&buf->refcount)) in vb2_dc_put()
129 if (buf->sgt_base) { in vb2_dc_put()
130 sg_free_table(buf->sgt_base); in vb2_dc_put()
131 kfree(buf->sgt_base); in vb2_dc_put()
133 dma_free_attrs(buf->dev, buf->size, buf->cookie, buf->dma_addr, in vb2_dc_put()
134 buf->attrs); in vb2_dc_put()
135 put_device(buf->dev); in vb2_dc_put()
136 kfree(buf); in vb2_dc_put()
143 struct vb2_dc_buf *buf; in vb2_dc_alloc() local
148 buf = kzalloc(sizeof *buf, GFP_KERNEL); in vb2_dc_alloc()
149 if (!buf) in vb2_dc_alloc()
153 buf->attrs = attrs; in vb2_dc_alloc()
154 buf->cookie = dma_alloc_attrs(dev, size, &buf->dma_addr, in vb2_dc_alloc()
155 GFP_KERNEL | gfp_flags, buf->attrs); in vb2_dc_alloc()
156 if (!buf->cookie) { in vb2_dc_alloc()
158 kfree(buf); in vb2_dc_alloc()
162 if ((buf->attrs & DMA_ATTR_NO_KERNEL_MAPPING) == 0) in vb2_dc_alloc()
163 buf->vaddr = buf->cookie; in vb2_dc_alloc()
166 buf->dev = get_device(dev); in vb2_dc_alloc()
167 buf->size = size; in vb2_dc_alloc()
168 buf->dma_dir = dma_dir; in vb2_dc_alloc()
170 buf->handler.refcount = &buf->refcount; in vb2_dc_alloc()
171 buf->handler.put = vb2_dc_put; in vb2_dc_alloc()
172 buf->handler.arg = buf; in vb2_dc_alloc()
174 refcount_set(&buf->refcount, 1); in vb2_dc_alloc()
176 return buf; in vb2_dc_alloc()
181 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_mmap() local
184 if (!buf) { in vb2_dc_mmap()
195 ret = dma_mmap_attrs(buf->dev, vma, buf->cookie, in vb2_dc_mmap()
196 buf->dma_addr, buf->size, buf->attrs); in vb2_dc_mmap()
204 vma->vm_private_data = &buf->handler; in vb2_dc_mmap()
210 __func__, (unsigned long)buf->dma_addr, vma->vm_start, in vb2_dc_mmap()
211 buf->size); in vb2_dc_mmap()
232 struct vb2_dc_buf *buf = dbuf->priv; in vb2_dc_dmabuf_ops_attach() local
243 ret = sg_alloc_table(sgt, buf->sgt_base->orig_nents, GFP_KERNEL); in vb2_dc_dmabuf_ops_attach()
249 rd = buf->sgt_base->sgl; in vb2_dc_dmabuf_ops_attach()
337 struct vb2_dc_buf *buf = dbuf->priv; in vb2_dc_dmabuf_ops_kmap() local
339 return buf->vaddr ? buf->vaddr + pgnum * PAGE_SIZE : NULL; in vb2_dc_dmabuf_ops_kmap()
344 struct vb2_dc_buf *buf = dbuf->priv; in vb2_dc_dmabuf_ops_vmap() local
346 return buf->vaddr; in vb2_dc_dmabuf_ops_vmap()
366 static struct sg_table *vb2_dc_get_base_sgt(struct vb2_dc_buf *buf) in vb2_dc_get_base_sgt() argument
373 dev_err(buf->dev, "failed to alloc sg table\n"); in vb2_dc_get_base_sgt()
377 ret = dma_get_sgtable_attrs(buf->dev, sgt, buf->cookie, buf->dma_addr, in vb2_dc_get_base_sgt()
378 buf->size, buf->attrs); in vb2_dc_get_base_sgt()
380 dev_err(buf->dev, "failed to get scatterlist from DMA API\n"); in vb2_dc_get_base_sgt()
390 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_get_dmabuf() local
395 exp_info.size = buf->size; in vb2_dc_get_dmabuf()
397 exp_info.priv = buf; in vb2_dc_get_dmabuf()
399 if (!buf->sgt_base) in vb2_dc_get_dmabuf()
400 buf->sgt_base = vb2_dc_get_base_sgt(buf); in vb2_dc_get_dmabuf()
402 if (WARN_ON(!buf->sgt_base)) in vb2_dc_get_dmabuf()
410 refcount_inc(&buf->refcount); in vb2_dc_get_dmabuf()
421 struct vb2_dc_buf *buf = buf_priv; in vb2_dc_put_userptr() local
422 struct sg_table *sgt = buf->dma_sgt; in vb2_dc_put_userptr()
431 dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, in vb2_dc_put_userptr()
432 buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC); in vb2_dc_put_userptr()
433 pages = frame_vector_pages(buf->vec); in vb2_dc_put_userptr()
436 if (buf->dma_dir == DMA_FROM_DEVICE || in vb2_dc_put_userptr()
437 buf->dma_dir == DMA_BIDIRECTIONAL) in vb2_dc_put_userptr()
438 for (i = 0; i < frame_vector_count(buf->vec); i++) in vb2_dc_put_userptr()
443 vb2_destroy_framevec(buf->vec); in vb2_dc_put_userptr()
444 kfree(buf); in vb2_dc_put_userptr()
481 struct vb2_dc_buf *buf; in vb2_dc_get_userptr() local
504 buf = kzalloc(sizeof *buf, GFP_KERNEL); in vb2_dc_get_userptr()
505 if (!buf) in vb2_dc_get_userptr()
508 buf->dev = dev; in vb2_dc_get_userptr()
509 buf->dma_dir = dma_dir; in vb2_dc_get_userptr()
518 buf->vec = vec; in vb2_dc_get_userptr()
531 buf->dma_addr = vb2_dc_pfn_to_dma(buf->dev, nums[0]); in vb2_dc_get_userptr()
553 sgt->nents = dma_map_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, in vb2_dc_get_userptr()
554 buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC); in vb2_dc_get_userptr()
569 buf->dma_addr = sg_dma_address(sgt->sgl); in vb2_dc_get_userptr()
570 buf->dma_sgt = sgt; in vb2_dc_get_userptr()
572 buf->size = size; in vb2_dc_get_userptr()
574 return buf; in vb2_dc_get_userptr()
577 dma_unmap_sg_attrs(buf->dev, sgt->sgl, sgt->orig_nents, in vb2_dc_get_userptr()
578 buf->dma_dir, DMA_ATTR_SKIP_CPU_SYNC); in vb2_dc_get_userptr()
590 kfree(buf); in vb2_dc_get_userptr()
601 struct vb2_dc_buf *buf = mem_priv; in vb2_dc_map_dmabuf() local
605 if (WARN_ON(!buf->db_attach)) { in vb2_dc_map_dmabuf()
610 if (WARN_ON(buf->dma_sgt)) { in vb2_dc_map_dmabuf()
616 sgt = dma_buf_map_attachment(buf->db_attach, buf->dma_dir); in vb2_dc_map_dmabuf()
624 if (contig_size < buf->size) { in vb2_dc_map_dmabuf()
626 contig_size, buf->size); in vb2_dc_map_dmabuf()
627 dma_buf_unmap_attachment(buf->db_attach, sgt, buf->dma_dir); in vb2_dc_map_dmabuf()
631 buf->dma_addr = sg_dma_address(sgt->sgl); in vb2_dc_map_dmabuf()
632 buf->dma_sgt = sgt; in vb2_dc_map_dmabuf()
633 buf->vaddr = NULL; in vb2_dc_map_dmabuf()
640 struct vb2_dc_buf *buf = mem_priv; in vb2_dc_unmap_dmabuf() local
641 struct sg_table *sgt = buf->dma_sgt; in vb2_dc_unmap_dmabuf()
643 if (WARN_ON(!buf->db_attach)) { in vb2_dc_unmap_dmabuf()
653 if (buf->vaddr) { in vb2_dc_unmap_dmabuf()
654 dma_buf_vunmap(buf->db_attach->dmabuf, buf->vaddr); in vb2_dc_unmap_dmabuf()
655 buf->vaddr = NULL; in vb2_dc_unmap_dmabuf()
657 dma_buf_unmap_attachment(buf->db_attach, sgt, buf->dma_dir); in vb2_dc_unmap_dmabuf()
659 buf->dma_addr = 0; in vb2_dc_unmap_dmabuf()
660 buf->dma_sgt = NULL; in vb2_dc_unmap_dmabuf()
665 struct vb2_dc_buf *buf = mem_priv; in vb2_dc_detach_dmabuf() local
668 if (WARN_ON(buf->dma_addr)) in vb2_dc_detach_dmabuf()
669 vb2_dc_unmap_dmabuf(buf); in vb2_dc_detach_dmabuf()
672 dma_buf_detach(buf->db_attach->dmabuf, buf->db_attach); in vb2_dc_detach_dmabuf()
673 kfree(buf); in vb2_dc_detach_dmabuf()
679 struct vb2_dc_buf *buf; in vb2_dc_attach_dmabuf() local
688 buf = kzalloc(sizeof(*buf), GFP_KERNEL); in vb2_dc_attach_dmabuf()
689 if (!buf) in vb2_dc_attach_dmabuf()
692 buf->dev = dev; in vb2_dc_attach_dmabuf()
694 dba = dma_buf_attach(dbuf, buf->dev); in vb2_dc_attach_dmabuf()
697 kfree(buf); in vb2_dc_attach_dmabuf()
701 buf->dma_dir = dma_dir; in vb2_dc_attach_dmabuf()
702 buf->size = size; in vb2_dc_attach_dmabuf()
703 buf->db_attach = dba; in vb2_dc_attach_dmabuf()
705 return buf; in vb2_dc_attach_dmabuf()