13 #include <linux/module.h>
16 #include <linux/sched.h>
17 #include <linux/slab.h>
34 static void vb2_dma_sg_put(
void *buf_priv);
36 static void *vb2_dma_sg_alloc(
void *alloc_ctx,
unsigned long size)
54 goto fail_sglist_alloc;
60 goto fail_pages_array_alloc;
62 for (i = 0; i < buf->
sg_desc.num_pages; ++
i) {
65 goto fail_pages_alloc;
66 sg_set_page(&buf->
sg_desc.sglist[i],
71 buf->
handler.put = vb2_dma_sg_put;
77 __func__, buf->
sg_desc.num_pages);
85 fail_pages_array_alloc:
93 static void vb2_dma_sg_put(
void *buf_priv)
111 static void *vb2_dma_sg_get_userptr(
void *alloc_ctx,
unsigned long vaddr,
112 unsigned long size,
int write)
116 int num_pages_from_user,
i;
129 buf->
sg_desc.num_pages = last - first + 1;
134 goto userptr_fail_sglist_alloc;
141 goto userptr_fail_pages_array_alloc;
151 if (num_pages_from_user != buf->
sg_desc.num_pages)
152 goto userptr_fail_get_user_pages;
157 for (i = 1; i < buf->
sg_desc.num_pages; ++
i) {
164 userptr_fail_get_user_pages:
166 num_pages_from_user, buf->
sg_desc.num_pages);
167 while (--num_pages_from_user >= 0)
171 userptr_fail_pages_array_alloc:
174 userptr_fail_sglist_alloc:
183 static void vb2_dma_sg_put_userptr(
void *buf_priv)
186 int i = buf->
sg_desc.num_pages;
189 __func__, buf->
sg_desc.num_pages);
202 static void *vb2_dma_sg_vaddr(
void *buf_priv)
218 static unsigned int vb2_dma_sg_num_users(
void *buf_priv)
225 static int vb2_dma_sg_mmap(
void *buf_priv,
struct vm_area_struct *vma)
262 static void *vb2_dma_sg_cookie(
void *buf_priv)
270 .alloc = vb2_dma_sg_alloc,
271 .put = vb2_dma_sg_put,
272 .get_userptr = vb2_dma_sg_get_userptr,
273 .put_userptr = vb2_dma_sg_put_userptr,
274 .vaddr = vb2_dma_sg_vaddr,
275 .mmap = vb2_dma_sg_mmap,
276 .num_users = vb2_dma_sg_num_users,
277 .cookie = vb2_dma_sg_cookie,