Lines Matching refs:vb

38 static void __enqueue_in_driver(struct vb2_buffer *vb);
43 static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) in __vb2_buf_mem_alloc() argument
45 struct vb2_queue *q = vb->vb2_queue; in __vb2_buf_mem_alloc()
55 for (plane = 0; plane < vb->num_planes; ++plane) { in __vb2_buf_mem_alloc()
58 mem_priv = call_ptr_memop(vb, alloc, q->alloc_ctx[plane], in __vb2_buf_mem_alloc()
64 vb->planes[plane].mem_priv = mem_priv; in __vb2_buf_mem_alloc()
65 vb->planes[plane].length = q->plane_sizes[plane]; in __vb2_buf_mem_alloc()
72 call_void_memop(vb, put, vb->planes[plane - 1].mem_priv); in __vb2_buf_mem_alloc()
73 vb->planes[plane - 1].mem_priv = NULL; in __vb2_buf_mem_alloc()
82 static void __vb2_buf_mem_free(struct vb2_buffer *vb) in __vb2_buf_mem_free() argument
86 for (plane = 0; plane < vb->num_planes; ++plane) { in __vb2_buf_mem_free()
87 call_void_memop(vb, put, vb->planes[plane].mem_priv); in __vb2_buf_mem_free()
88 vb->planes[plane].mem_priv = NULL; in __vb2_buf_mem_free()
89 dprintk(3, "freed plane %d of buffer %d\n", plane, vb->index); in __vb2_buf_mem_free()
97 static void __vb2_buf_userptr_put(struct vb2_buffer *vb) in __vb2_buf_userptr_put() argument
101 for (plane = 0; plane < vb->num_planes; ++plane) { in __vb2_buf_userptr_put()
102 if (vb->planes[plane].mem_priv) in __vb2_buf_userptr_put()
103 call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv); in __vb2_buf_userptr_put()
104 vb->planes[plane].mem_priv = NULL; in __vb2_buf_userptr_put()
112 static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p) in __vb2_plane_dmabuf_put() argument
118 call_void_memop(vb, unmap_dmabuf, p->mem_priv); in __vb2_plane_dmabuf_put()
120 call_void_memop(vb, detach_dmabuf, p->mem_priv); in __vb2_plane_dmabuf_put()
131 static void __vb2_buf_dmabuf_put(struct vb2_buffer *vb) in __vb2_buf_dmabuf_put() argument
135 for (plane = 0; plane < vb->num_planes; ++plane) in __vb2_buf_dmabuf_put()
136 __vb2_plane_dmabuf_put(vb, &vb->planes[plane]); in __vb2_buf_dmabuf_put()
146 struct vb2_buffer *vb; in __setup_lengths() local
149 vb = q->bufs[buffer]; in __setup_lengths()
150 if (!vb) in __setup_lengths()
153 for (plane = 0; plane < vb->num_planes; ++plane) in __setup_lengths()
154 vb->planes[plane].length = q->plane_sizes[plane]; in __setup_lengths()
165 struct vb2_buffer *vb; in __setup_offsets() local
170 vb = q->bufs[q->num_buffers - 1]; in __setup_offsets()
171 p = &vb->planes[vb->num_planes - 1]; in __setup_offsets()
178 vb = q->bufs[buffer]; in __setup_offsets()
179 if (!vb) in __setup_offsets()
182 for (plane = 0; plane < vb->num_planes; ++plane) { in __setup_offsets()
183 vb->planes[plane].m.offset = off; in __setup_offsets()
188 off += vb->planes[plane].length; in __setup_offsets()
205 struct vb2_buffer *vb; in __vb2_queue_alloc() local
210 vb = kzalloc(q->buf_struct_size, GFP_KERNEL); in __vb2_queue_alloc()
211 if (!vb) { in __vb2_queue_alloc()
216 vb->state = VB2_BUF_STATE_DEQUEUED; in __vb2_queue_alloc()
217 vb->vb2_queue = q; in __vb2_queue_alloc()
218 vb->num_planes = num_planes; in __vb2_queue_alloc()
219 vb->index = q->num_buffers + buffer; in __vb2_queue_alloc()
220 vb->type = q->type; in __vb2_queue_alloc()
221 vb->memory = memory; in __vb2_queue_alloc()
225 ret = __vb2_buf_mem_alloc(vb); in __vb2_queue_alloc()
229 kfree(vb); in __vb2_queue_alloc()
237 ret = call_vb_qop(vb, buf_init, vb); in __vb2_queue_alloc()
240 " failed\n", buffer, vb); in __vb2_queue_alloc()
241 __vb2_buf_mem_free(vb); in __vb2_queue_alloc()
242 kfree(vb); in __vb2_queue_alloc()
247 q->bufs[q->num_buffers + buffer] = vb; in __vb2_queue_alloc()
266 struct vb2_buffer *vb; in __vb2_free_mem() local
270 vb = q->bufs[buffer]; in __vb2_free_mem()
271 if (!vb) in __vb2_free_mem()
276 __vb2_buf_mem_free(vb); in __vb2_free_mem()
278 __vb2_buf_dmabuf_put(vb); in __vb2_free_mem()
280 __vb2_buf_userptr_put(vb); in __vb2_free_mem()
314 struct vb2_buffer *vb = q->bufs[buffer]; in __vb2_queue_free() local
316 if (vb && vb->planes[0].mem_priv) in __vb2_queue_free()
317 call_void_vb_qop(vb, buf_cleanup, vb); in __vb2_queue_free()
349 struct vb2_buffer *vb = q->bufs[buffer]; in __vb2_queue_free() local
350 bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put || in __vb2_queue_free()
351 vb->cnt_mem_prepare != vb->cnt_mem_finish || in __vb2_queue_free()
352 vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr || in __vb2_queue_free()
353 vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf || in __vb2_queue_free()
354 vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf || in __vb2_queue_free()
355 vb->cnt_buf_queue != vb->cnt_buf_done || in __vb2_queue_free()
356 vb->cnt_buf_prepare != vb->cnt_buf_finish || in __vb2_queue_free()
357 vb->cnt_buf_init != vb->cnt_buf_cleanup; in __vb2_queue_free()
363 vb->cnt_buf_init, vb->cnt_buf_cleanup, in __vb2_queue_free()
364 vb->cnt_buf_prepare, vb->cnt_buf_finish); in __vb2_queue_free()
366 vb->cnt_buf_queue, vb->cnt_buf_done); in __vb2_queue_free()
368 vb->cnt_mem_alloc, vb->cnt_mem_put, in __vb2_queue_free()
369 vb->cnt_mem_prepare, vb->cnt_mem_finish, in __vb2_queue_free()
370 vb->cnt_mem_mmap); in __vb2_queue_free()
372 vb->cnt_mem_get_userptr, vb->cnt_mem_put_userptr); in __vb2_queue_free()
374 vb->cnt_mem_attach_dmabuf, vb->cnt_mem_detach_dmabuf, in __vb2_queue_free()
375 vb->cnt_mem_map_dmabuf, vb->cnt_mem_unmap_dmabuf); in __vb2_queue_free()
377 vb->cnt_mem_get_dmabuf, in __vb2_queue_free()
378 vb->cnt_mem_num_users, in __vb2_queue_free()
379 vb->cnt_mem_vaddr, in __vb2_queue_free()
380 vb->cnt_mem_cookie); in __vb2_queue_free()
404 bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb) in vb2_buffer_in_use() argument
407 for (plane = 0; plane < vb->num_planes; ++plane) { in vb2_buffer_in_use()
408 void *mem_priv = vb->planes[plane].mem_priv; in vb2_buffer_in_use()
415 if (mem_priv && call_memop(vb, num_users, mem_priv) > 1) in vb2_buffer_in_use()
794 void *vb2_plane_vaddr(struct vb2_buffer *vb, unsigned int plane_no) in vb2_plane_vaddr() argument
796 if (plane_no > vb->num_planes || !vb->planes[plane_no].mem_priv) in vb2_plane_vaddr()
799 return call_ptr_memop(vb, vaddr, vb->planes[plane_no].mem_priv); in vb2_plane_vaddr()
815 void *vb2_plane_cookie(struct vb2_buffer *vb, unsigned int plane_no) in vb2_plane_cookie() argument
817 if (plane_no >= vb->num_planes || !vb->planes[plane_no].mem_priv) in vb2_plane_cookie()
820 return call_ptr_memop(vb, cookie, vb->planes[plane_no].mem_priv); in vb2_plane_cookie()
844 void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) in vb2_buffer_done() argument
846 struct vb2_queue *q = vb->vb2_queue; in vb2_buffer_done()
850 if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) in vb2_buffer_done()
864 vb->cnt_buf_done++; in vb2_buffer_done()
867 vb->index, state); in vb2_buffer_done()
870 for (plane = 0; plane < vb->num_planes; ++plane) in vb2_buffer_done()
871 call_void_memop(vb, finish, vb->planes[plane].mem_priv); in vb2_buffer_done()
876 vb->state = VB2_BUF_STATE_QUEUED; in vb2_buffer_done()
879 list_add_tail(&vb->done_entry, &q->done_list); in vb2_buffer_done()
880 vb->state = state; in vb2_buffer_done()
885 trace_vb2_buf_done(q, vb); in vb2_buffer_done()
892 __enqueue_in_driver(vb); in vb2_buffer_done()
916 struct vb2_buffer *vb; in vb2_discard_done() local
920 list_for_each_entry(vb, &q->done_list, done_entry) in vb2_discard_done()
921 vb->state = VB2_BUF_STATE_ERROR; in vb2_discard_done()
929 static int __qbuf_mmap(struct vb2_buffer *vb, const void *pb) in __qbuf_mmap() argument
931 int ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, in __qbuf_mmap()
932 vb, pb, vb->planes); in __qbuf_mmap()
933 return ret ? ret : call_vb_qop(vb, buf_prepare, vb); in __qbuf_mmap()
939 static int __qbuf_userptr(struct vb2_buffer *vb, const void *pb) in __qbuf_userptr() argument
942 struct vb2_queue *q = vb->vb2_queue; in __qbuf_userptr()
948 bool reacquired = vb->planes[0].mem_priv == NULL; in __qbuf_userptr()
950 memset(planes, 0, sizeof(planes[0]) * vb->num_planes); in __qbuf_userptr()
952 ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, vb, pb, planes); in __qbuf_userptr()
956 for (plane = 0; plane < vb->num_planes; ++plane) { in __qbuf_userptr()
958 if (vb->planes[plane].m.userptr && in __qbuf_userptr()
959 vb->planes[plane].m.userptr == planes[plane].m.userptr in __qbuf_userptr()
960 && vb->planes[plane].length == planes[plane].length) in __qbuf_userptr()
977 if (vb->planes[plane].mem_priv) { in __qbuf_userptr()
980 call_void_vb_qop(vb, buf_cleanup, vb); in __qbuf_userptr()
982 call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv); in __qbuf_userptr()
985 vb->planes[plane].mem_priv = NULL; in __qbuf_userptr()
986 vb->planes[plane].bytesused = 0; in __qbuf_userptr()
987 vb->planes[plane].length = 0; in __qbuf_userptr()
988 vb->planes[plane].m.userptr = 0; in __qbuf_userptr()
989 vb->planes[plane].data_offset = 0; in __qbuf_userptr()
992 mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane], in __qbuf_userptr()
1001 vb->planes[plane].mem_priv = mem_priv; in __qbuf_userptr()
1008 for (plane = 0; plane < vb->num_planes; ++plane) { in __qbuf_userptr()
1009 vb->planes[plane].bytesused = planes[plane].bytesused; in __qbuf_userptr()
1010 vb->planes[plane].length = planes[plane].length; in __qbuf_userptr()
1011 vb->planes[plane].m.userptr = planes[plane].m.userptr; in __qbuf_userptr()
1012 vb->planes[plane].data_offset = planes[plane].data_offset; in __qbuf_userptr()
1021 ret = call_vb_qop(vb, buf_init, vb); in __qbuf_userptr()
1028 ret = call_vb_qop(vb, buf_prepare, vb); in __qbuf_userptr()
1031 call_void_vb_qop(vb, buf_cleanup, vb); in __qbuf_userptr()
1038 for (plane = 0; plane < vb->num_planes; ++plane) { in __qbuf_userptr()
1039 if (vb->planes[plane].mem_priv) in __qbuf_userptr()
1040 call_void_memop(vb, put_userptr, in __qbuf_userptr()
1041 vb->planes[plane].mem_priv); in __qbuf_userptr()
1042 vb->planes[plane].mem_priv = NULL; in __qbuf_userptr()
1043 vb->planes[plane].m.userptr = 0; in __qbuf_userptr()
1044 vb->planes[plane].length = 0; in __qbuf_userptr()
1053 static int __qbuf_dmabuf(struct vb2_buffer *vb, const void *pb) in __qbuf_dmabuf() argument
1056 struct vb2_queue *q = vb->vb2_queue; in __qbuf_dmabuf()
1062 bool reacquired = vb->planes[0].mem_priv == NULL; in __qbuf_dmabuf()
1064 memset(planes, 0, sizeof(planes[0]) * vb->num_planes); in __qbuf_dmabuf()
1066 ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, vb, pb, planes); in __qbuf_dmabuf()
1070 for (plane = 0; plane < vb->num_planes; ++plane) { in __qbuf_dmabuf()
1092 if (dbuf == vb->planes[plane].dbuf && in __qbuf_dmabuf()
1093 vb->planes[plane].length == planes[plane].length) { in __qbuf_dmabuf()
1102 call_void_vb_qop(vb, buf_cleanup, vb); in __qbuf_dmabuf()
1106 __vb2_plane_dmabuf_put(vb, &vb->planes[plane]); in __qbuf_dmabuf()
1107 vb->planes[plane].bytesused = 0; in __qbuf_dmabuf()
1108 vb->planes[plane].length = 0; in __qbuf_dmabuf()
1109 vb->planes[plane].m.fd = 0; in __qbuf_dmabuf()
1110 vb->planes[plane].data_offset = 0; in __qbuf_dmabuf()
1113 mem_priv = call_ptr_memop(vb, attach_dmabuf, in __qbuf_dmabuf()
1123 vb->planes[plane].dbuf = dbuf; in __qbuf_dmabuf()
1124 vb->planes[plane].mem_priv = mem_priv; in __qbuf_dmabuf()
1131 for (plane = 0; plane < vb->num_planes; ++plane) { in __qbuf_dmabuf()
1132 ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv); in __qbuf_dmabuf()
1138 vb->planes[plane].dbuf_mapped = 1; in __qbuf_dmabuf()
1145 for (plane = 0; plane < vb->num_planes; ++plane) { in __qbuf_dmabuf()
1146 vb->planes[plane].bytesused = planes[plane].bytesused; in __qbuf_dmabuf()
1147 vb->planes[plane].length = planes[plane].length; in __qbuf_dmabuf()
1148 vb->planes[plane].m.fd = planes[plane].m.fd; in __qbuf_dmabuf()
1149 vb->planes[plane].data_offset = planes[plane].data_offset; in __qbuf_dmabuf()
1157 ret = call_vb_qop(vb, buf_init, vb); in __qbuf_dmabuf()
1164 ret = call_vb_qop(vb, buf_prepare, vb); in __qbuf_dmabuf()
1167 call_void_vb_qop(vb, buf_cleanup, vb); in __qbuf_dmabuf()
1174 __vb2_buf_dmabuf_put(vb); in __qbuf_dmabuf()
1182 static void __enqueue_in_driver(struct vb2_buffer *vb) in __enqueue_in_driver() argument
1184 struct vb2_queue *q = vb->vb2_queue; in __enqueue_in_driver()
1187 vb->state = VB2_BUF_STATE_ACTIVE; in __enqueue_in_driver()
1190 trace_vb2_buf_queue(q, vb); in __enqueue_in_driver()
1193 for (plane = 0; plane < vb->num_planes; ++plane) in __enqueue_in_driver()
1194 call_void_memop(vb, prepare, vb->planes[plane].mem_priv); in __enqueue_in_driver()
1196 call_void_vb_qop(vb, buf_queue, vb); in __enqueue_in_driver()
1199 static int __buf_prepare(struct vb2_buffer *vb, const void *pb) in __buf_prepare() argument
1201 struct vb2_queue *q = vb->vb2_queue; in __buf_prepare()
1209 vb->state = VB2_BUF_STATE_PREPARING; in __buf_prepare()
1213 ret = __qbuf_mmap(vb, pb); in __buf_prepare()
1216 ret = __qbuf_userptr(vb, pb); in __buf_prepare()
1219 ret = __qbuf_dmabuf(vb, pb); in __buf_prepare()
1228 vb->state = ret ? VB2_BUF_STATE_DEQUEUED : VB2_BUF_STATE_PREPARED; in __buf_prepare()
1251 struct vb2_buffer *vb; in vb2_core_prepare_buf() local
1254 vb = q->bufs[index]; in vb2_core_prepare_buf()
1255 if (vb->state != VB2_BUF_STATE_DEQUEUED) { in vb2_core_prepare_buf()
1257 vb->state); in vb2_core_prepare_buf()
1261 ret = __buf_prepare(vb, pb); in vb2_core_prepare_buf()
1266 ret = call_bufop(q, fill_user_buffer, vb, pb); in vb2_core_prepare_buf()
1270 dprintk(1, "prepare of buffer %d succeeded\n", vb->index); in vb2_core_prepare_buf()
1289 struct vb2_buffer *vb; in vb2_start_streaming() local
1296 list_for_each_entry(vb, &q->queued_list, queued_entry) in vb2_start_streaming()
1297 __enqueue_in_driver(vb); in vb2_start_streaming()
1323 vb = q->bufs[i]; in vb2_start_streaming()
1324 if (vb->state == VB2_BUF_STATE_ACTIVE) in vb2_start_streaming()
1325 vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED); in vb2_start_streaming()
1359 struct vb2_buffer *vb; in vb2_core_qbuf() local
1362 vb = q->bufs[index]; in vb2_core_qbuf()
1364 switch (vb->state) { in vb2_core_qbuf()
1366 ret = __buf_prepare(vb, pb); in vb2_core_qbuf()
1376 dprintk(1, "invalid buffer state %d\n", vb->state); in vb2_core_qbuf()
1384 list_add_tail(&vb->queued_entry, &q->queued_list); in vb2_core_qbuf()
1387 vb->state = VB2_BUF_STATE_QUEUED; in vb2_core_qbuf()
1389 call_bufop(q, set_timestamp, vb, pb); in vb2_core_qbuf()
1391 trace_vb2_qbuf(q, vb); in vb2_core_qbuf()
1398 __enqueue_in_driver(vb); in vb2_core_qbuf()
1401 ret = call_bufop(q, fill_user_buffer, vb, pb); in vb2_core_qbuf()
1418 dprintk(1, "qbuf of buffer %d succeeded\n", vb->index); in vb2_core_qbuf()
1504 static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb, in __vb2_get_done_vb() argument
1522 *vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry); in __vb2_get_done_vb()
1527 ret = call_bufop(q, verify_planes_array, *vb, pb); in __vb2_get_done_vb()
1529 list_del(&(*vb)->done_entry); in __vb2_get_done_vb()
1560 static void __vb2_dqbuf(struct vb2_buffer *vb) in __vb2_dqbuf() argument
1562 struct vb2_queue *q = vb->vb2_queue; in __vb2_dqbuf()
1566 if (vb->state == VB2_BUF_STATE_DEQUEUED) in __vb2_dqbuf()
1569 vb->state = VB2_BUF_STATE_DEQUEUED; in __vb2_dqbuf()
1573 for (i = 0; i < vb->num_planes; ++i) { in __vb2_dqbuf()
1574 if (!vb->planes[i].dbuf_mapped) in __vb2_dqbuf()
1576 call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv); in __vb2_dqbuf()
1577 vb->planes[i].dbuf_mapped = 0; in __vb2_dqbuf()
1604 struct vb2_buffer *vb = NULL; in vb2_core_dqbuf() local
1607 ret = __vb2_get_done_vb(q, &vb, pb, nonblocking); in vb2_core_dqbuf()
1611 switch (vb->state) { in vb2_core_dqbuf()
1623 call_void_vb_qop(vb, buf_finish, vb); in vb2_core_dqbuf()
1626 ret = call_bufop(q, fill_user_buffer, vb, pb); in vb2_core_dqbuf()
1631 list_del(&vb->queued_entry); in vb2_core_dqbuf()
1634 trace_vb2_dqbuf(q, vb); in vb2_core_dqbuf()
1637 __vb2_dqbuf(vb); in vb2_core_dqbuf()
1640 vb->index, vb->state); in vb2_core_dqbuf()
1705 struct vb2_buffer *vb = q->bufs[i]; in __vb2_queue_cancel() local
1707 if (vb->state != VB2_BUF_STATE_DEQUEUED) { in __vb2_queue_cancel()
1708 vb->state = VB2_BUF_STATE_PREPARED; in __vb2_queue_cancel()
1709 call_void_vb_qop(vb, buf_finish, vb); in __vb2_queue_cancel()
1711 __vb2_dqbuf(vb); in __vb2_queue_cancel()
1811 struct vb2_buffer *vb; in __find_plane_by_offset() local
1820 vb = q->bufs[buffer]; in __find_plane_by_offset()
1822 for (plane = 0; plane < vb->num_planes; ++plane) { in __find_plane_by_offset()
1823 if (vb->planes[plane].m.offset == off) { in __find_plane_by_offset()
1850 struct vb2_buffer *vb = NULL; in vb2_core_expbuf() local
1880 vb = q->bufs[index]; in vb2_core_expbuf()
1882 if (plane >= vb->num_planes) { in vb2_core_expbuf()
1892 vb_plane = &vb->planes[plane]; in vb2_core_expbuf()
1894 dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, in vb2_core_expbuf()
1940 struct vb2_buffer *vb; in vb2_mmap() local
1980 vb = q->bufs[buffer]; in vb2_mmap()
1987 length = PAGE_ALIGN(vb->planes[plane].length); in vb2_mmap()
1995 ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma); in vb2_mmap()
2013 struct vb2_buffer *vb; in vb2_get_unmapped_area() local
2030 vb = q->bufs[buffer]; in vb2_get_unmapped_area()
2032 vaddr = vb2_plane_vaddr(vb, plane); in vb2_get_unmapped_area()