Lines Matching refs:buf
41 struct vb2_vmalloc_buf *buf; in vb2_vmalloc_alloc() local
43 buf = kzalloc(sizeof(*buf), GFP_KERNEL | gfp_flags); in vb2_vmalloc_alloc()
44 if (!buf) in vb2_vmalloc_alloc()
47 buf->size = size; in vb2_vmalloc_alloc()
48 buf->vaddr = vmalloc_user(buf->size); in vb2_vmalloc_alloc()
49 buf->dma_dir = dma_dir; in vb2_vmalloc_alloc()
50 buf->handler.refcount = &buf->refcount; in vb2_vmalloc_alloc()
51 buf->handler.put = vb2_vmalloc_put; in vb2_vmalloc_alloc()
52 buf->handler.arg = buf; in vb2_vmalloc_alloc()
54 if (!buf->vaddr) { in vb2_vmalloc_alloc()
55 pr_debug("vmalloc of size %ld failed\n", buf->size); in vb2_vmalloc_alloc()
56 kfree(buf); in vb2_vmalloc_alloc()
60 atomic_inc(&buf->refcount); in vb2_vmalloc_alloc()
61 return buf; in vb2_vmalloc_alloc()
66 struct vb2_vmalloc_buf *buf = buf_priv; in vb2_vmalloc_put() local
68 if (atomic_dec_and_test(&buf->refcount)) { in vb2_vmalloc_put()
69 vfree(buf->vaddr); in vb2_vmalloc_put()
70 kfree(buf); in vb2_vmalloc_put()
78 struct vb2_vmalloc_buf *buf; in vb2_vmalloc_get_userptr() local
84 buf = kzalloc(sizeof(*buf), GFP_KERNEL); in vb2_vmalloc_get_userptr()
85 if (!buf) in vb2_vmalloc_get_userptr()
88 buf->dma_dir = dma_dir; in vb2_vmalloc_get_userptr()
90 buf->size = size; in vb2_vmalloc_get_userptr()
97 buf->vma = vma; in vb2_vmalloc_get_userptr()
98 buf->vaddr = (__force void *)ioremap_nocache(physp, size); in vb2_vmalloc_get_userptr()
99 if (!buf->vaddr) in vb2_vmalloc_get_userptr()
104 buf->n_pages = last - first + 1; in vb2_vmalloc_get_userptr()
105 buf->pages = kzalloc(buf->n_pages * sizeof(struct page *), in vb2_vmalloc_get_userptr()
107 if (!buf->pages) in vb2_vmalloc_get_userptr()
112 vaddr & PAGE_MASK, buf->n_pages, in vb2_vmalloc_get_userptr()
115 buf->pages, NULL); in vb2_vmalloc_get_userptr()
116 if (n_pages != buf->n_pages) in vb2_vmalloc_get_userptr()
119 buf->vaddr = vm_map_ram(buf->pages, buf->n_pages, -1, in vb2_vmalloc_get_userptr()
121 if (!buf->vaddr) in vb2_vmalloc_get_userptr()
125 buf->vaddr += offset; in vb2_vmalloc_get_userptr()
126 return buf; in vb2_vmalloc_get_userptr()
130 buf->n_pages); in vb2_vmalloc_get_userptr()
132 put_page(buf->pages[n_pages]); in vb2_vmalloc_get_userptr()
133 kfree(buf->pages); in vb2_vmalloc_get_userptr()
136 kfree(buf); in vb2_vmalloc_get_userptr()
143 struct vb2_vmalloc_buf *buf = buf_priv; in vb2_vmalloc_put_userptr() local
144 unsigned long vaddr = (unsigned long)buf->vaddr & PAGE_MASK; in vb2_vmalloc_put_userptr()
147 if (buf->pages) { in vb2_vmalloc_put_userptr()
149 vm_unmap_ram((void *)vaddr, buf->n_pages); in vb2_vmalloc_put_userptr()
150 for (i = 0; i < buf->n_pages; ++i) { in vb2_vmalloc_put_userptr()
151 if (buf->dma_dir == DMA_FROM_DEVICE) in vb2_vmalloc_put_userptr()
152 set_page_dirty_lock(buf->pages[i]); in vb2_vmalloc_put_userptr()
153 put_page(buf->pages[i]); in vb2_vmalloc_put_userptr()
155 kfree(buf->pages); in vb2_vmalloc_put_userptr()
157 vb2_put_vma(buf->vma); in vb2_vmalloc_put_userptr()
158 iounmap((__force void __iomem *)buf->vaddr); in vb2_vmalloc_put_userptr()
160 kfree(buf); in vb2_vmalloc_put_userptr()
165 struct vb2_vmalloc_buf *buf = buf_priv; in vb2_vmalloc_vaddr() local
167 if (!buf->vaddr) { in vb2_vmalloc_vaddr()
173 return buf->vaddr; in vb2_vmalloc_vaddr()
178 struct vb2_vmalloc_buf *buf = buf_priv; in vb2_vmalloc_num_users() local
179 return atomic_read(&buf->refcount); in vb2_vmalloc_num_users()
184 struct vb2_vmalloc_buf *buf = buf_priv; in vb2_vmalloc_mmap() local
187 if (!buf) { in vb2_vmalloc_mmap()
192 ret = remap_vmalloc_range(vma, buf->vaddr, 0); in vb2_vmalloc_mmap()
206 vma->vm_private_data = &buf->handler; in vb2_vmalloc_mmap()
228 struct vb2_vmalloc_buf *buf = dbuf->priv; in vb2_vmalloc_dmabuf_ops_attach() local
229 int num_pages = PAGE_ALIGN(buf->size) / PAGE_SIZE; in vb2_vmalloc_dmabuf_ops_attach()
232 void *vaddr = buf->vaddr; in vb2_vmalloc_dmabuf_ops_attach()
337 struct vb2_vmalloc_buf *buf = dbuf->priv; in vb2_vmalloc_dmabuf_ops_kmap() local
339 return buf->vaddr + pgnum * PAGE_SIZE; in vb2_vmalloc_dmabuf_ops_kmap()
344 struct vb2_vmalloc_buf *buf = dbuf->priv; in vb2_vmalloc_dmabuf_ops_vmap() local
346 return buf->vaddr; in vb2_vmalloc_dmabuf_ops_vmap()
369 struct vb2_vmalloc_buf *buf = buf_priv; in vb2_vmalloc_get_dmabuf() local
374 exp_info.size = buf->size; in vb2_vmalloc_get_dmabuf()
376 exp_info.priv = buf; in vb2_vmalloc_get_dmabuf()
378 if (WARN_ON(!buf->vaddr)) in vb2_vmalloc_get_dmabuf()
386 atomic_inc(&buf->refcount); in vb2_vmalloc_get_dmabuf()
399 struct vb2_vmalloc_buf *buf = mem_priv; in vb2_vmalloc_map_dmabuf() local
401 buf->vaddr = dma_buf_vmap(buf->dbuf); in vb2_vmalloc_map_dmabuf()
403 return buf->vaddr ? 0 : -EFAULT; in vb2_vmalloc_map_dmabuf()
408 struct vb2_vmalloc_buf *buf = mem_priv; in vb2_vmalloc_unmap_dmabuf() local
410 dma_buf_vunmap(buf->dbuf, buf->vaddr); in vb2_vmalloc_unmap_dmabuf()
411 buf->vaddr = NULL; in vb2_vmalloc_unmap_dmabuf()
416 struct vb2_vmalloc_buf *buf = mem_priv; in vb2_vmalloc_detach_dmabuf() local
418 if (buf->vaddr) in vb2_vmalloc_detach_dmabuf()
419 dma_buf_vunmap(buf->dbuf, buf->vaddr); in vb2_vmalloc_detach_dmabuf()
421 kfree(buf); in vb2_vmalloc_detach_dmabuf()
427 struct vb2_vmalloc_buf *buf; in vb2_vmalloc_attach_dmabuf() local
432 buf = kzalloc(sizeof(*buf), GFP_KERNEL); in vb2_vmalloc_attach_dmabuf()
433 if (!buf) in vb2_vmalloc_attach_dmabuf()
436 buf->dbuf = dbuf; in vb2_vmalloc_attach_dmabuf()
437 buf->dma_dir = dma_dir; in vb2_vmalloc_attach_dmabuf()
438 buf->size = size; in vb2_vmalloc_attach_dmabuf()
440 return buf; in vb2_vmalloc_attach_dmabuf()