Lines Matching +full:1 +full:q
36 #define PLANE_INDEX_MASK (BIT_MASK(PLANE_INDEX_BITS) - 1)
38 #define BUFFER_INDEX_MASK (MAX_BUFFER_INDEX - 1)
47 #define dprintk(q, level, fmt, arg...) \ argument
50 pr_info("[%s] %s: " fmt, (q)->name, __func__, \
103 #define log_qop(q, op) \ argument
104 dprintk(q, 2, "call_qop(%s)%s\n", #op, \
105 (q)->ops->op ? "" : " (nop)")
107 #define call_qop(q, op, args...) \ argument
111 log_qop(q, op); \
112 err = (q)->ops->op ? (q)->ops->op(args) : 0; \
114 (q)->cnt_ ## op++; \
118 #define call_void_qop(q, op, args...) \ argument
120 log_qop(q, op); \
121 if ((q)->ops->op) \
122 (q)->ops->op(args); \
123 (q)->cnt_ ## op++; \
167 #define call_qop(q, op, args...) \ argument
168 ((q)->ops->op ? (q)->ops->op(args) : 0)
170 #define call_void_qop(q, op, args...) \ argument
172 if ((q)->ops->op) \
173 (q)->ops->op(args); \
187 #define call_bufop(q, op, args...) \ argument
190 if (q && q->buf_ops && q->buf_ops->op) \
191 ret = q->buf_ops->op(args); \
195 #define call_void_bufop(q, op, args...) \ argument
197 if (q && q->buf_ops && q->buf_ops->op) \
198 q->buf_ops->op(args); \
201 static void __vb2_queue_cancel(struct vb2_queue *q);
225 struct vb2_queue *q = vb->vb2_queue; in __vb2_buf_mem_alloc() local
244 q->alloc_devs[plane] ? : q->dev, in __vb2_buf_mem_alloc()
260 call_void_memop(vb, put, vb->planes[plane - 1].mem_priv); in __vb2_buf_mem_alloc()
261 vb->planes[plane - 1].mem_priv = NULL; in __vb2_buf_mem_alloc()
338 for (plane = vb->num_planes - 1; plane >= 0; --plane) in __vb2_buf_dmabuf_put()
353 vb->synced = 1; in __vb2_buf_mem_prepare()
380 struct vb2_queue *q = vb->vb2_queue; in __setup_offsets() local
389 * CAPTURE (aka "destination", bit 30 is 1) buffers. in __setup_offsets()
403 dprintk(q, 3, "buffer %d, plane %d offset 0x%08lx\n", in __setup_offsets()
408 static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) in init_buffer_cache_hints() argument
415 if (q->memory == VB2_MEMORY_DMABUF) { in init_buffer_cache_hints()
416 vb->skip_cache_sync_on_finish = 1; in init_buffer_cache_hints()
417 vb->skip_cache_sync_on_prepare = 1; in init_buffer_cache_hints()
425 if (q->dma_dir == DMA_TO_DEVICE) in init_buffer_cache_hints()
426 vb->skip_cache_sync_on_finish = 1; in init_buffer_cache_hints()
431 * @q: pointer to &struct vb2_queue with videobuf2 queue.
435 static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, unsigned int index) in vb2_queue_add_buffer() argument
437 WARN_ON(index >= q->max_num_buffers || test_bit(index, q->bufs_bitmap) || vb->vb2_queue); in vb2_queue_add_buffer()
439 q->bufs[index] = vb; in vb2_queue_add_buffer()
441 vb->vb2_queue = q; in vb2_queue_add_buffer()
442 set_bit(index, q->bufs_bitmap); in vb2_queue_add_buffer()
461 * have indices in the range [first_index..first_index+count-1]
465 static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, in __vb2_queue_alloc() argument
472 unsigned long index = q->max_num_buffers; in __vb2_queue_alloc()
477 * in the queue is below q->max_num_buffers in __vb2_queue_alloc()
480 q->max_num_buffers - vb2_get_num_buffers(q)); in __vb2_queue_alloc()
483 index = bitmap_find_next_zero_area(q->bufs_bitmap, q->max_num_buffers, in __vb2_queue_alloc()
486 if (index < q->max_num_buffers) in __vb2_queue_alloc()
502 vb = kzalloc(q->buf_struct_size, GFP_KERNEL); in __vb2_queue_alloc()
504 dprintk(q, 1, "memory alloc for buffer struct failed\n"); in __vb2_queue_alloc()
510 vb->type = q->type; in __vb2_queue_alloc()
512 init_buffer_cache_hints(q, vb); in __vb2_queue_alloc()
518 vb2_queue_add_buffer(q, vb, index++); in __vb2_queue_alloc()
519 call_void_bufop(q, init_buffer, vb); in __vb2_queue_alloc()
525 dprintk(q, 1, "failed allocating memory for buffer %d\n", in __vb2_queue_alloc()
539 dprintk(q, 1, "buffer %d %p initialization failed\n", in __vb2_queue_alloc()
549 dprintk(q, 3, "allocated %d buffers, %d plane(s) each\n", in __vb2_queue_alloc()
559 static void __vb2_free_mem(struct vb2_queue *q, unsigned int start, unsigned int count) in __vb2_free_mem() argument
565 vb = vb2_get_buffer(q, i); in __vb2_free_mem()
570 if (q->memory == VB2_MEMORY_MMAP) in __vb2_free_mem()
572 else if (q->memory == VB2_MEMORY_DMABUF) in __vb2_free_mem()
584 static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned int count) in __vb2_queue_free() argument
588 lockdep_assert_held(&q->mmap_lock); in __vb2_queue_free()
592 struct vb2_buffer *vb = vb2_get_buffer(q, i); in __vb2_queue_free()
599 __vb2_free_mem(q, start, count); in __vb2_queue_free()
606 if (vb2_get_num_buffers(q)) { in __vb2_queue_free()
607 bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming || in __vb2_queue_free()
608 q->cnt_prepare_streaming != q->cnt_unprepare_streaming || in __vb2_queue_free()
609 q->cnt_wait_prepare != q->cnt_wait_finish; in __vb2_queue_free()
612 pr_info("unbalanced counters for queue %p:\n", q); in __vb2_queue_free()
613 if (q->cnt_start_streaming != q->cnt_stop_streaming) in __vb2_queue_free()
615 q->cnt_queue_setup, q->cnt_start_streaming, in __vb2_queue_free()
616 q->cnt_stop_streaming); in __vb2_queue_free()
617 if (q->cnt_prepare_streaming != q->cnt_unprepare_streaming) in __vb2_queue_free()
619 q->cnt_prepare_streaming, q->cnt_unprepare_streaming); in __vb2_queue_free()
620 if (q->cnt_wait_prepare != q->cnt_wait_finish) in __vb2_queue_free()
622 q->cnt_wait_prepare, q->cnt_wait_finish); in __vb2_queue_free()
624 q->cnt_queue_setup = 0; in __vb2_queue_free()
625 q->cnt_wait_prepare = 0; in __vb2_queue_free()
626 q->cnt_wait_finish = 0; in __vb2_queue_free()
627 q->cnt_prepare_streaming = 0; in __vb2_queue_free()
628 q->cnt_start_streaming = 0; in __vb2_queue_free()
629 q->cnt_stop_streaming = 0; in __vb2_queue_free()
630 q->cnt_unprepare_streaming = 0; in __vb2_queue_free()
633 struct vb2_buffer *vb = vb2_get_buffer(q, i); in __vb2_queue_free()
650 q, i); in __vb2_queue_free()
685 struct vb2_buffer *vb = vb2_get_buffer(q, i); in __vb2_queue_free()
694 if (!vb2_get_num_buffers(q)) { in __vb2_queue_free()
695 q->memory = VB2_MEMORY_UNKNOWN; in __vb2_queue_free()
696 INIT_LIST_HEAD(&q->queued_list); in __vb2_queue_free()
700 bool vb2_buffer_in_use(struct vb2_queue *q, struct vb2_buffer *vb) in vb2_buffer_in_use() argument
708 * case anyway. If num_users() returns more than 1, in vb2_buffer_in_use()
711 if (mem_priv && call_memop(vb, num_users, mem_priv) > 1) in vb2_buffer_in_use()
722 static bool __buffers_in_use(struct vb2_queue *q) in __buffers_in_use() argument
725 for (buffer = 0; buffer < q->max_num_buffers; ++buffer) { in __buffers_in_use()
726 struct vb2_buffer *vb = vb2_get_buffer(q, buffer); in __buffers_in_use()
731 if (vb2_buffer_in_use(q, vb)) in __buffers_in_use()
737 void vb2_core_querybuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb) in vb2_core_querybuf() argument
739 call_void_bufop(q, fill_user_buffer, vb, pb); in vb2_core_querybuf()
747 static int __verify_userptr_ops(struct vb2_queue *q) in __verify_userptr_ops() argument
749 if (!(q->io_modes & VB2_USERPTR) || !q->mem_ops->get_userptr || in __verify_userptr_ops()
750 !q->mem_ops->put_userptr) in __verify_userptr_ops()
760 static int __verify_mmap_ops(struct vb2_queue *q) in __verify_mmap_ops() argument
762 if (!(q->io_modes & VB2_MMAP) || !q->mem_ops->alloc || in __verify_mmap_ops()
763 !q->mem_ops->put || !q->mem_ops->mmap) in __verify_mmap_ops()
773 static int __verify_dmabuf_ops(struct vb2_queue *q) in __verify_dmabuf_ops() argument
775 if (!(q->io_modes & VB2_DMABUF) || !q->mem_ops->attach_dmabuf || in __verify_dmabuf_ops()
776 !q->mem_ops->detach_dmabuf || !q->mem_ops->map_dmabuf || in __verify_dmabuf_ops()
777 !q->mem_ops->unmap_dmabuf) in __verify_dmabuf_ops()
783 int vb2_verify_memory_type(struct vb2_queue *q, in vb2_verify_memory_type() argument
788 dprintk(q, 1, "unsupported memory type\n"); in vb2_verify_memory_type()
792 if (type != q->type) { in vb2_verify_memory_type()
793 dprintk(q, 1, "requested type is incorrect\n"); in vb2_verify_memory_type()
801 if (memory == VB2_MEMORY_MMAP && __verify_mmap_ops(q)) { in vb2_verify_memory_type()
802 dprintk(q, 1, "MMAP for current setup unsupported\n"); in vb2_verify_memory_type()
806 if (memory == VB2_MEMORY_USERPTR && __verify_userptr_ops(q)) { in vb2_verify_memory_type()
807 dprintk(q, 1, "USERPTR for current setup unsupported\n"); in vb2_verify_memory_type()
811 if (memory == VB2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) { in vb2_verify_memory_type()
812 dprintk(q, 1, "DMABUF for current setup unsupported\n"); in vb2_verify_memory_type()
821 if (vb2_fileio_is_active(q)) { in vb2_verify_memory_type()
822 dprintk(q, 1, "file io in progress\n"); in vb2_verify_memory_type()
829 static void set_queue_coherency(struct vb2_queue *q, bool non_coherent_mem) in set_queue_coherency() argument
831 q->non_coherent_mem = 0; in set_queue_coherency()
833 if (!vb2_queue_allows_cache_hints(q)) in set_queue_coherency()
835 q->non_coherent_mem = non_coherent_mem; in set_queue_coherency()
838 static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem) in verify_coherency_flags() argument
840 if (non_coherent_mem != q->non_coherent_mem) { in verify_coherency_flags()
841 dprintk(q, 1, "memory coherency model mismatch\n"); in verify_coherency_flags()
847 static int vb2_core_allocated_buffers_storage(struct vb2_queue *q) in vb2_core_allocated_buffers_storage() argument
849 if (!q->bufs) in vb2_core_allocated_buffers_storage()
850 q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); in vb2_core_allocated_buffers_storage()
851 if (!q->bufs) in vb2_core_allocated_buffers_storage()
854 if (!q->bufs_bitmap) in vb2_core_allocated_buffers_storage()
855 q->bufs_bitmap = bitmap_zalloc(q->max_num_buffers, GFP_KERNEL); in vb2_core_allocated_buffers_storage()
856 if (!q->bufs_bitmap) { in vb2_core_allocated_buffers_storage()
857 kfree(q->bufs); in vb2_core_allocated_buffers_storage()
858 q->bufs = NULL; in vb2_core_allocated_buffers_storage()
865 static void vb2_core_free_buffers_storage(struct vb2_queue *q) in vb2_core_free_buffers_storage() argument
867 kfree(q->bufs); in vb2_core_free_buffers_storage()
868 q->bufs = NULL; in vb2_core_free_buffers_storage()
869 bitmap_free(q->bufs_bitmap); in vb2_core_free_buffers_storage()
870 q->bufs_bitmap = NULL; in vb2_core_free_buffers_storage()
873 int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, in vb2_core_reqbufs() argument
877 unsigned int q_num_bufs = vb2_get_num_buffers(q); in vb2_core_reqbufs()
883 if (q->streaming) { in vb2_core_reqbufs()
884 dprintk(q, 1, "streaming active\n"); in vb2_core_reqbufs()
888 if (q->waiting_in_dqbuf && *count) { in vb2_core_reqbufs()
889 dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); in vb2_core_reqbufs()
894 (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory) || in vb2_core_reqbufs()
895 !verify_coherency_flags(q, non_coherent_mem)) { in vb2_core_reqbufs()
900 mutex_lock(&q->mmap_lock); in vb2_core_reqbufs()
901 if (debug && q->memory == VB2_MEMORY_MMAP && in vb2_core_reqbufs()
902 __buffers_in_use(q)) in vb2_core_reqbufs()
903 dprintk(q, 1, "memory in use, orphaning buffers\n"); in vb2_core_reqbufs()
910 __vb2_queue_cancel(q); in vb2_core_reqbufs()
911 __vb2_queue_free(q, 0, q->max_num_buffers); in vb2_core_reqbufs()
912 mutex_unlock(&q->mmap_lock); in vb2_core_reqbufs()
914 q->is_busy = 0; in vb2_core_reqbufs()
926 num_buffers = max_t(unsigned int, *count, q->min_reqbufs_allocation); in vb2_core_reqbufs()
927 num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers); in vb2_core_reqbufs()
928 memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); in vb2_core_reqbufs()
930 * Set this now to ensure that drivers see the correct q->memory value in vb2_core_reqbufs()
933 mutex_lock(&q->mmap_lock); in vb2_core_reqbufs()
934 ret = vb2_core_allocated_buffers_storage(q); in vb2_core_reqbufs()
935 q->memory = memory; in vb2_core_reqbufs()
936 mutex_unlock(&q->mmap_lock); in vb2_core_reqbufs()
939 set_queue_coherency(q, non_coherent_mem); in vb2_core_reqbufs()
945 ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, in vb2_core_reqbufs()
946 plane_sizes, q->alloc_devs); in vb2_core_reqbufs()
964 __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes, &first_index); in vb2_core_reqbufs()
968 dprintk(q, 1, "memory allocation failed\n"); in vb2_core_reqbufs()
977 if (allocated_buffers < q->min_reqbufs_allocation) in vb2_core_reqbufs()
993 ret = call_qop(q, queue_setup, q, &num_buffers, in vb2_core_reqbufs()
994 &num_planes, plane_sizes, q->alloc_devs); in vb2_core_reqbufs()
1005 mutex_lock(&q->mmap_lock); in vb2_core_reqbufs()
1010 * from already queued buffers and it will reset q->memory to in vb2_core_reqbufs()
1013 __vb2_queue_free(q, first_index, allocated_buffers); in vb2_core_reqbufs()
1014 mutex_unlock(&q->mmap_lock); in vb2_core_reqbufs()
1017 mutex_unlock(&q->mmap_lock); in vb2_core_reqbufs()
1024 q->waiting_for_buffers = !q->is_output; in vb2_core_reqbufs()
1025 q->is_busy = 1; in vb2_core_reqbufs()
1030 mutex_lock(&q->mmap_lock); in vb2_core_reqbufs()
1031 q->memory = VB2_MEMORY_UNKNOWN; in vb2_core_reqbufs()
1032 mutex_unlock(&q->mmap_lock); in vb2_core_reqbufs()
1033 vb2_core_free_buffers_storage(q); in vb2_core_reqbufs()
1038 int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, in vb2_core_create_bufs() argument
1047 unsigned int q_num_bufs = vb2_get_num_buffers(q); in vb2_core_create_bufs()
1051 if (q_num_bufs == q->max_num_buffers) { in vb2_core_create_bufs()
1052 dprintk(q, 1, "maximum number of buffers already allocated\n"); in vb2_core_create_bufs()
1057 if (q->waiting_in_dqbuf && *count) { in vb2_core_create_bufs()
1058 dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); in vb2_core_create_bufs()
1061 memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); in vb2_core_create_bufs()
1063 * Set this now to ensure that drivers see the correct q->memory in vb2_core_create_bufs()
1066 mutex_lock(&q->mmap_lock); in vb2_core_create_bufs()
1067 ret = vb2_core_allocated_buffers_storage(q); in vb2_core_create_bufs()
1068 q->memory = memory; in vb2_core_create_bufs()
1069 mutex_unlock(&q->mmap_lock); in vb2_core_create_bufs()
1072 q->waiting_for_buffers = !q->is_output; in vb2_core_create_bufs()
1073 set_queue_coherency(q, non_coherent_mem); in vb2_core_create_bufs()
1075 if (q->memory != memory) { in vb2_core_create_bufs()
1076 dprintk(q, 1, "memory model mismatch\n"); in vb2_core_create_bufs()
1079 if (!verify_coherency_flags(q, non_coherent_mem)) in vb2_core_create_bufs()
1083 num_buffers = min(*count, q->max_num_buffers - q_num_bufs); in vb2_core_create_bufs()
1094 ret = call_qop(q, queue_setup, q, &num_buffers, in vb2_core_create_bufs()
1095 &num_planes, plane_sizes, q->alloc_devs); in vb2_core_create_bufs()
1100 allocated_buffers = __vb2_queue_alloc(q, memory, num_buffers, in vb2_core_create_bufs()
1103 dprintk(q, 1, "memory allocation failed\n"); in vb2_core_create_bufs()
1118 ret = call_qop(q, queue_setup, q, &num_buffers, in vb2_core_create_bufs()
1119 &num_planes, plane_sizes, q->alloc_devs); in vb2_core_create_bufs()
1130 mutex_lock(&q->mmap_lock); in vb2_core_create_bufs()
1135 * from already queued buffers and it will reset q->memory to in vb2_core_create_bufs()
1138 __vb2_queue_free(q, *first_index, allocated_buffers); in vb2_core_create_bufs()
1139 mutex_unlock(&q->mmap_lock); in vb2_core_create_bufs()
1142 mutex_unlock(&q->mmap_lock); in vb2_core_create_bufs()
1149 q->is_busy = 1; in vb2_core_create_bufs()
1155 mutex_lock(&q->mmap_lock); in vb2_core_create_bufs()
1156 q->memory = VB2_MEMORY_UNKNOWN; in vb2_core_create_bufs()
1157 mutex_unlock(&q->mmap_lock); in vb2_core_create_bufs()
1184 struct vb2_queue *q = vb->vb2_queue; in vb2_buffer_done() local
1202 dprintk(q, 4, "done processing on buffer %d, state: %s\n", in vb2_buffer_done()
1208 spin_lock_irqsave(&q->done_lock, flags); in vb2_buffer_done()
1213 list_add_tail(&vb->done_entry, &q->done_list); in vb2_buffer_done()
1216 atomic_dec(&q->owned_by_drv_count); in vb2_buffer_done()
1223 spin_unlock_irqrestore(&q->done_lock, flags); in vb2_buffer_done()
1225 trace_vb2_buf_done(q, vb); in vb2_buffer_done()
1232 wake_up(&q->done_wq); in vb2_buffer_done()
1238 void vb2_discard_done(struct vb2_queue *q) in vb2_discard_done() argument
1243 spin_lock_irqsave(&q->done_lock, flags); in vb2_discard_done()
1244 list_for_each_entry(vb, &q->done_list, done_entry) in vb2_discard_done()
1246 spin_unlock_irqrestore(&q->done_lock, flags); in vb2_discard_done()
1268 struct vb2_queue *q = vb->vb2_queue; in __prepare_userptr() local
1288 dprintk(q, 3, "userspace address for plane %d changed, reacquiring memory\n", in __prepare_userptr()
1293 dprintk(q, 1, "provided buffer size %u is less than setup size %u for plane %d\n", in __prepare_userptr()
1320 q->alloc_devs[plane] ? : q->dev, in __prepare_userptr()
1324 dprintk(q, 1, "failed acquiring userspace memory for plane %d\n", in __prepare_userptr()
1351 dprintk(q, 1, "buffer initialization failed\n"); in __prepare_userptr()
1358 dprintk(q, 1, "buffer preparation failed\n"); in __prepare_userptr()
1384 struct vb2_queue *q = vb->vb2_queue; in __prepare_dmabuf() local
1403 dprintk(q, 1, "invalid dmabuf fd for plane %d\n", in __prepare_dmabuf()
1414 dprintk(q, 1, "invalid dmabuf length %u for plane %d, minimum length %u\n", in __prepare_dmabuf()
1426 dprintk(q, 3, "buffer for plane %d changed\n", plane); in __prepare_dmabuf()
1446 q->alloc_devs[plane] == q->alloc_devs[i]) { in __prepare_dmabuf()
1460 q->alloc_devs[plane] ? : q->dev, in __prepare_dmabuf()
1464 dprintk(q, 1, "failed to attach dmabuf\n"); in __prepare_dmabuf()
1479 dprintk(q, 1, "failed to map dmabuf for plane %d\n", in __prepare_dmabuf()
1483 vb->planes[plane].dbuf_mapped = 1; in __prepare_dmabuf()
1508 dprintk(q, 1, "buffer initialization failed\n"); in __prepare_dmabuf()
1515 dprintk(q, 1, "buffer preparation failed\n"); in __prepare_dmabuf()
1539 struct vb2_queue *q = vb->vb2_queue; in __enqueue_in_driver() local
1542 atomic_inc(&q->owned_by_drv_count); in __enqueue_in_driver()
1544 trace_vb2_buf_queue(q, vb); in __enqueue_in_driver()
1551 struct vb2_queue *q = vb->vb2_queue; in __buf_prepare() local
1555 if (q->error) { in __buf_prepare()
1556 dprintk(q, 1, "fatal error occurred on queue\n"); in __buf_prepare()
1564 if (q->is_output) { in __buf_prepare()
1567 dprintk(q, 1, "buffer validation failed\n"); in __buf_prepare()
1574 switch (q->memory) { in __buf_prepare()
1585 WARN(1, "Invalid queue type\n"); in __buf_prepare()
1591 dprintk(q, 1, "buffer preparation failed: %d\n", ret); in __buf_prepare()
1597 vb->prepared = 1; in __buf_prepare()
1640 * The only exception is -EIO which is returned if q->error is in vb2_req_queue()
1699 int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb) in vb2_core_prepare_buf() argument
1704 dprintk(q, 1, "invalid buffer state %s\n", in vb2_core_prepare_buf()
1709 dprintk(q, 1, "buffer already prepared\n"); in vb2_core_prepare_buf()
1718 call_void_bufop(q, fill_user_buffer, vb, pb); in vb2_core_prepare_buf()
1720 dprintk(q, 2, "prepare of buffer %d succeeded\n", vb->index); in vb2_core_prepare_buf()
1726 int vb2_core_remove_bufs(struct vb2_queue *q, unsigned int start, unsigned int count) in vb2_core_remove_bufs() argument
1729 unsigned int q_num_bufs = vb2_get_num_buffers(q); in vb2_core_remove_bufs()
1737 if (start > q->max_num_buffers - count) in vb2_core_remove_bufs()
1740 mutex_lock(&q->mmap_lock); in vb2_core_remove_bufs()
1744 struct vb2_buffer *vb = vb2_get_buffer(q, i); in vb2_core_remove_bufs()
1755 __vb2_queue_free(q, start, count); in vb2_core_remove_bufs()
1756 dprintk(q, 2, "%u buffers removed\n", count); in vb2_core_remove_bufs()
1759 mutex_unlock(&q->mmap_lock); in vb2_core_remove_bufs()
1766 * @q: videobuf2 queue
1769 * at least q->min_queued_buffers queued up (i.e. the minimum
1775 static int vb2_start_streaming(struct vb2_queue *q) in vb2_start_streaming() argument
1784 list_for_each_entry(vb, &q->queued_list, queued_entry) in vb2_start_streaming()
1788 q->start_streaming_called = 1; in vb2_start_streaming()
1789 ret = call_qop(q, start_streaming, q, in vb2_start_streaming()
1790 atomic_read(&q->owned_by_drv_count)); in vb2_start_streaming()
1794 q->start_streaming_called = 0; in vb2_start_streaming()
1796 dprintk(q, 1, "driver refused to start streaming\n"); in vb2_start_streaming()
1803 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { in vb2_start_streaming()
1810 for (i = 0; i < q->max_num_buffers; ++i) { in vb2_start_streaming()
1811 vb = vb2_get_buffer(q, i); in vb2_start_streaming()
1820 WARN_ON(atomic_read(&q->owned_by_drv_count)); in vb2_start_streaming()
1827 WARN_ON(!list_empty(&q->done_list)); in vb2_start_streaming()
1831 int vb2_core_qbuf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb, in vb2_core_qbuf() argument
1837 if (q->error) { in vb2_core_qbuf()
1838 dprintk(q, 1, "fatal error occurred on queue\n"); in vb2_core_qbuf()
1843 q->requires_requests) { in vb2_core_qbuf()
1844 dprintk(q, 1, "qbuf requires a request\n"); in vb2_core_qbuf()
1848 if ((req && q->uses_qbuf) || in vb2_core_qbuf()
1850 q->uses_requests)) { in vb2_core_qbuf()
1851 dprintk(q, 1, "queue in wrong mode (qbuf vs requests)\n"); in vb2_core_qbuf()
1858 q->uses_requests = 1; in vb2_core_qbuf()
1860 dprintk(q, 1, "buffer %d not in dequeued state\n", in vb2_core_qbuf()
1865 if (q->is_output && !vb->prepared) { in vb2_core_qbuf()
1868 dprintk(q, 1, "buffer validation failed\n"); in vb2_core_qbuf()
1880 q, true, &vb->req_obj); in vb2_core_qbuf()
1900 call_void_bufop(q, copy_timestamp, vb, pb); in vb2_core_qbuf()
1901 call_void_bufop(q, fill_user_buffer, vb, pb); in vb2_core_qbuf()
1904 dprintk(q, 2, "qbuf of buffer %d succeeded\n", vb->index); in vb2_core_qbuf()
1909 q->uses_qbuf = 1; in vb2_core_qbuf()
1921 dprintk(q, 1, "buffer still being prepared\n"); in vb2_core_qbuf()
1924 dprintk(q, 1, "invalid buffer state %s\n", in vb2_core_qbuf()
1934 list_add_tail(&vb->queued_entry, &q->queued_list); in vb2_core_qbuf()
1935 q->queued_count++; in vb2_core_qbuf()
1936 q->waiting_for_buffers = false; in vb2_core_qbuf()
1940 call_void_bufop(q, copy_timestamp, vb, pb); in vb2_core_qbuf()
1942 trace_vb2_qbuf(q, vb); in vb2_core_qbuf()
1948 if (q->start_streaming_called) in vb2_core_qbuf()
1953 call_void_bufop(q, fill_user_buffer, vb, pb); in vb2_core_qbuf()
1961 if (q->streaming && !q->start_streaming_called && in vb2_core_qbuf()
1962 q->queued_count >= q->min_queued_buffers) { in vb2_core_qbuf()
1963 ret = vb2_start_streaming(q); in vb2_core_qbuf()
1971 q->queued_count--; in vb2_core_qbuf()
1977 dprintk(q, 2, "qbuf of buffer %d succeeded\n", vb->index); in vb2_core_qbuf()
1988 static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking) in __vb2_wait_for_done_vb() argument
2002 if (q->waiting_in_dqbuf) { in __vb2_wait_for_done_vb()
2003 dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); in __vb2_wait_for_done_vb()
2007 if (!q->streaming) { in __vb2_wait_for_done_vb()
2008 dprintk(q, 1, "streaming off, will not wait for buffers\n"); in __vb2_wait_for_done_vb()
2012 if (q->error) { in __vb2_wait_for_done_vb()
2013 dprintk(q, 1, "Queue in error state, will not wait for buffers\n"); in __vb2_wait_for_done_vb()
2017 if (q->last_buffer_dequeued) { in __vb2_wait_for_done_vb()
2018 dprintk(q, 3, "last buffer dequeued already, will not wait for buffers\n"); in __vb2_wait_for_done_vb()
2022 if (!list_empty(&q->done_list)) { in __vb2_wait_for_done_vb()
2030 dprintk(q, 3, "nonblocking and no buffers to dequeue, will not wait\n"); in __vb2_wait_for_done_vb()
2034 q->waiting_in_dqbuf = 1; in __vb2_wait_for_done_vb()
2040 call_void_qop(q, wait_prepare, q); in __vb2_wait_for_done_vb()
2045 dprintk(q, 3, "will sleep waiting for buffers\n"); in __vb2_wait_for_done_vb()
2046 ret = wait_event_interruptible(q->done_wq, in __vb2_wait_for_done_vb()
2047 !list_empty(&q->done_list) || !q->streaming || in __vb2_wait_for_done_vb()
2048 q->error); in __vb2_wait_for_done_vb()
2054 call_void_qop(q, wait_finish, q); in __vb2_wait_for_done_vb()
2055 q->waiting_in_dqbuf = 0; in __vb2_wait_for_done_vb()
2057 dprintk(q, 1, "sleep was interrupted\n"); in __vb2_wait_for_done_vb()
2069 static int __vb2_get_done_vb(struct vb2_queue *q, struct vb2_buffer **vb, in __vb2_get_done_vb() argument
2078 ret = __vb2_wait_for_done_vb(q, nonblocking); in __vb2_get_done_vb()
2086 spin_lock_irqsave(&q->done_lock, flags); in __vb2_get_done_vb()
2087 *vb = list_first_entry(&q->done_list, struct vb2_buffer, done_entry); in __vb2_get_done_vb()
2094 ret = call_bufop(q, verify_planes_array, *vb, pb); in __vb2_get_done_vb()
2097 spin_unlock_irqrestore(&q->done_lock, flags); in __vb2_get_done_vb()
2102 int vb2_wait_for_all_buffers(struct vb2_queue *q) in vb2_wait_for_all_buffers() argument
2104 if (!q->streaming) { in vb2_wait_for_all_buffers()
2105 dprintk(q, 1, "streaming off, will not wait for buffers\n"); in vb2_wait_for_all_buffers()
2109 if (q->start_streaming_called) in vb2_wait_for_all_buffers()
2110 wait_event(q->done_wq, !atomic_read(&q->owned_by_drv_count)); in vb2_wait_for_all_buffers()
2120 struct vb2_queue *q = vb->vb2_queue; in __vb2_dqbuf() local
2128 call_void_bufop(q, init_buffer, vb); in __vb2_dqbuf()
2131 int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb, in vb2_core_dqbuf() argument
2137 ret = __vb2_get_done_vb(q, &vb, pb, nonblocking); in vb2_core_dqbuf()
2143 dprintk(q, 3, "returning done buffer\n"); in vb2_core_dqbuf()
2146 dprintk(q, 3, "returning done buffer with errors\n"); in vb2_core_dqbuf()
2149 dprintk(q, 1, "invalid buffer state %s\n", in vb2_core_dqbuf()
2162 call_void_bufop(q, fill_user_buffer, vb, pb); in vb2_core_dqbuf()
2166 q->queued_count--; in vb2_core_dqbuf()
2168 trace_vb2_dqbuf(q, vb); in vb2_core_dqbuf()
2181 dprintk(q, 2, "dqbuf of buffer %d, state: %s\n", in vb2_core_dqbuf()
2195 static void __vb2_queue_cancel(struct vb2_queue *q) in __vb2_queue_cancel() argument
2203 if (q->start_streaming_called) in __vb2_queue_cancel()
2204 call_void_qop(q, stop_streaming, q); in __vb2_queue_cancel()
2206 if (q->streaming) in __vb2_queue_cancel()
2207 call_void_qop(q, unprepare_streaming, q); in __vb2_queue_cancel()
2215 if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { in __vb2_queue_cancel()
2216 for (i = 0; i < q->max_num_buffers; i++) { in __vb2_queue_cancel()
2217 struct vb2_buffer *vb = vb2_get_buffer(q, i); in __vb2_queue_cancel()
2229 WARN_ON(atomic_read(&q->owned_by_drv_count)); in __vb2_queue_cancel()
2232 q->streaming = 0; in __vb2_queue_cancel()
2233 q->start_streaming_called = 0; in __vb2_queue_cancel()
2234 q->queued_count = 0; in __vb2_queue_cancel()
2235 q->error = 0; in __vb2_queue_cancel()
2236 q->uses_requests = 0; in __vb2_queue_cancel()
2237 q->uses_qbuf = 0; in __vb2_queue_cancel()
2242 INIT_LIST_HEAD(&q->queued_list); in __vb2_queue_cancel()
2247 INIT_LIST_HEAD(&q->done_list); in __vb2_queue_cancel()
2248 atomic_set(&q->owned_by_drv_count, 0); in __vb2_queue_cancel()
2249 wake_up_all(&q->done_wq); in __vb2_queue_cancel()
2260 for (i = 0; i < q->max_num_buffers; i++) { in __vb2_queue_cancel()
2264 vb = vb2_get_buffer(q, i); in __vb2_queue_cancel()
2306 int vb2_core_streamon(struct vb2_queue *q, unsigned int type) in vb2_core_streamon() argument
2308 unsigned int q_num_bufs = vb2_get_num_buffers(q); in vb2_core_streamon()
2311 if (type != q->type) { in vb2_core_streamon()
2312 dprintk(q, 1, "invalid stream type\n"); in vb2_core_streamon()
2316 if (q->streaming) { in vb2_core_streamon()
2317 dprintk(q, 3, "already streaming\n"); in vb2_core_streamon()
2322 dprintk(q, 1, "no buffers have been allocated\n"); in vb2_core_streamon()
2326 if (q_num_bufs < q->min_queued_buffers) { in vb2_core_streamon()
2327 dprintk(q, 1, "need at least %u queued buffers\n", in vb2_core_streamon()
2328 q->min_queued_buffers); in vb2_core_streamon()
2332 ret = call_qop(q, prepare_streaming, q); in vb2_core_streamon()
2340 if (q->queued_count >= q->min_queued_buffers) { in vb2_core_streamon()
2341 ret = vb2_start_streaming(q); in vb2_core_streamon()
2346 q->streaming = 1; in vb2_core_streamon()
2348 dprintk(q, 3, "successful\n"); in vb2_core_streamon()
2352 call_void_qop(q, unprepare_streaming, q); in vb2_core_streamon()
2357 void vb2_queue_error(struct vb2_queue *q) in vb2_queue_error() argument
2359 q->error = 1; in vb2_queue_error()
2361 wake_up_all(&q->done_wq); in vb2_queue_error()
2365 int vb2_core_streamoff(struct vb2_queue *q, unsigned int type) in vb2_core_streamoff() argument
2367 if (type != q->type) { in vb2_core_streamoff()
2368 dprintk(q, 1, "invalid stream type\n"); in vb2_core_streamoff()
2376 * Note that we do this even if q->streaming == 0: if you prepare or in vb2_core_streamoff()
2381 __vb2_queue_cancel(q); in vb2_core_streamoff()
2382 q->waiting_for_buffers = !q->is_output; in vb2_core_streamoff()
2383 q->last_buffer_dequeued = false; in vb2_core_streamoff()
2385 dprintk(q, 3, "successful\n"); in vb2_core_streamoff()
2393 static int __find_plane_by_offset(struct vb2_queue *q, unsigned long offset, in __find_plane_by_offset() argument
2402 lockdep_assert_held(&q->mmap_lock); in __find_plane_by_offset()
2404 if (q->memory != VB2_MEMORY_MMAP) { in __find_plane_by_offset()
2405 dprintk(q, 1, "queue is not currently set up for mmap\n"); in __find_plane_by_offset()
2409 if (vb2_fileio_is_active(q)) { in __find_plane_by_offset()
2410 dprintk(q, 1, "file io in progress\n"); in __find_plane_by_offset()
2418 *vb = vb2_get_buffer(q, buffer); in __find_plane_by_offset()
2427 int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, in vb2_core_expbuf() argument
2434 if (q->memory != VB2_MEMORY_MMAP) { in vb2_core_expbuf()
2435 dprintk(q, 1, "queue is not currently set up for mmap\n"); in vb2_core_expbuf()
2439 if (!q->mem_ops->get_dmabuf) { in vb2_core_expbuf()
2440 dprintk(q, 1, "queue does not support DMA buffer exporting\n"); in vb2_core_expbuf()
2445 dprintk(q, 1, "queue does support only O_CLOEXEC and access mode flags\n"); in vb2_core_expbuf()
2449 if (type != q->type) { in vb2_core_expbuf()
2450 dprintk(q, 1, "invalid buffer type\n"); in vb2_core_expbuf()
2455 dprintk(q, 1, "buffer plane out of range\n"); in vb2_core_expbuf()
2459 if (vb2_fileio_is_active(q)) { in vb2_core_expbuf()
2460 dprintk(q, 1, "expbuf: file io in progress\n"); in vb2_core_expbuf()
2471 dprintk(q, 1, "failed to export buffer %d, plane %d\n", in vb2_core_expbuf()
2478 dprintk(q, 3, "buffer %d, plane %d failed to export (%d)\n", in vb2_core_expbuf()
2484 dprintk(q, 3, "buffer %d, plane %d exported as %d descriptor\n", in vb2_core_expbuf()
2492 int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) in vb2_mmap() argument
2504 dprintk(q, 1, "invalid vma flags, VM_SHARED needed\n"); in vb2_mmap()
2507 if (q->is_output) { in vb2_mmap()
2509 dprintk(q, 1, "invalid vma flags, VM_WRITE needed\n"); in vb2_mmap()
2514 dprintk(q, 1, "invalid vma flags, VM_READ needed\n"); in vb2_mmap()
2519 mutex_lock(&q->mmap_lock); in vb2_mmap()
2525 ret = __find_plane_by_offset(q, offset, &vb, &plane); in vb2_mmap()
2536 dprintk(q, 1, in vb2_mmap()
2552 mutex_unlock(&q->mmap_lock); in vb2_mmap()
2556 dprintk(q, 3, "buffer %u, plane %d successfully mapped\n", vb->index, plane); in vb2_mmap()
2562 unsigned long vb2_get_unmapped_area(struct vb2_queue *q, in vb2_get_unmapped_area() argument
2574 mutex_lock(&q->mmap_lock); in vb2_get_unmapped_area()
2580 ret = __find_plane_by_offset(q, offset, &vb, &plane); in vb2_get_unmapped_area()
2585 mutex_unlock(&q->mmap_lock); in vb2_get_unmapped_area()
2589 mutex_unlock(&q->mmap_lock); in vb2_get_unmapped_area()
2595 int vb2_core_queue_init(struct vb2_queue *q) in vb2_core_queue_init() argument
2604 if (!q->max_num_buffers) in vb2_core_queue_init()
2605 q->max_num_buffers = VB2_MAX_FRAME; in vb2_core_queue_init()
2608 q->max_num_buffers = min_t(unsigned int, q->max_num_buffers, MAX_BUFFER_INDEX); in vb2_core_queue_init()
2610 if (WARN_ON(!q) || in vb2_core_queue_init()
2611 WARN_ON(!q->ops) || in vb2_core_queue_init()
2612 WARN_ON(!q->mem_ops) || in vb2_core_queue_init()
2613 WARN_ON(!q->type) || in vb2_core_queue_init()
2614 WARN_ON(!q->io_modes) || in vb2_core_queue_init()
2615 WARN_ON(!q->ops->queue_setup) || in vb2_core_queue_init()
2616 WARN_ON(!q->ops->buf_queue)) in vb2_core_queue_init()
2619 if (WARN_ON(q->max_num_buffers < VB2_MAX_FRAME) || in vb2_core_queue_init()
2620 WARN_ON(q->min_queued_buffers > q->max_num_buffers)) in vb2_core_queue_init()
2623 if (WARN_ON(q->requires_requests && !q->supports_requests)) in vb2_core_queue_init()
2628 * q->min_queued_buffers can cause vb2_core_qbuf() to fail if in vb2_core_queue_init()
2634 if (WARN_ON(q->supports_requests && q->min_queued_buffers)) in vb2_core_queue_init()
2640 * 'min_queued_buffers + 1' to keep at least one buffer available in vb2_core_queue_init()
2643 if (q->min_reqbufs_allocation < q->min_queued_buffers + 1) in vb2_core_queue_init()
2644 q->min_reqbufs_allocation = q->min_queued_buffers + 1; in vb2_core_queue_init()
2646 if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers)) in vb2_core_queue_init()
2649 INIT_LIST_HEAD(&q->queued_list); in vb2_core_queue_init()
2650 INIT_LIST_HEAD(&q->done_list); in vb2_core_queue_init()
2651 spin_lock_init(&q->done_lock); in vb2_core_queue_init()
2652 mutex_init(&q->mmap_lock); in vb2_core_queue_init()
2653 init_waitqueue_head(&q->done_wq); in vb2_core_queue_init()
2655 q->memory = VB2_MEMORY_UNKNOWN; in vb2_core_queue_init()
2657 if (q->buf_struct_size == 0) in vb2_core_queue_init()
2658 q->buf_struct_size = sizeof(struct vb2_buffer); in vb2_core_queue_init()
2660 if (q->bidirectional) in vb2_core_queue_init()
2661 q->dma_dir = DMA_BIDIRECTIONAL; in vb2_core_queue_init()
2663 q->dma_dir = q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE; in vb2_core_queue_init()
2665 if (q->name[0] == '\0') in vb2_core_queue_init()
2666 snprintf(q->name, sizeof(q->name), "%s-%p", in vb2_core_queue_init()
2667 q->is_output ? "out" : "cap", q); in vb2_core_queue_init()
2673 static int __vb2_init_fileio(struct vb2_queue *q, int read);
2674 static int __vb2_cleanup_fileio(struct vb2_queue *q);
2675 void vb2_core_queue_release(struct vb2_queue *q) in vb2_core_queue_release() argument
2677 __vb2_cleanup_fileio(q); in vb2_core_queue_release()
2678 __vb2_queue_cancel(q); in vb2_core_queue_release()
2679 mutex_lock(&q->mmap_lock); in vb2_core_queue_release()
2680 __vb2_queue_free(q, 0, q->max_num_buffers); in vb2_core_queue_release()
2681 vb2_core_free_buffers_storage(q); in vb2_core_queue_release()
2682 q->is_busy = 0; in vb2_core_queue_release()
2683 mutex_unlock(&q->mmap_lock); in vb2_core_queue_release()
2687 __poll_t vb2_core_poll(struct vb2_queue *q, struct file *file, in vb2_core_poll() argument
2701 poll_wait(file, &q->done_wq, wait); in vb2_core_poll()
2703 if (!q->is_output && !(req_events & (EPOLLIN | EPOLLRDNORM))) in vb2_core_poll()
2705 if (q->is_output && !(req_events & (EPOLLOUT | EPOLLWRNORM))) in vb2_core_poll()
2711 if (vb2_get_num_buffers(q) == 0 && !vb2_fileio_is_active(q)) { in vb2_core_poll()
2712 if (!q->is_output && (q->io_modes & VB2_READ) && in vb2_core_poll()
2714 if (__vb2_init_fileio(q, 1)) in vb2_core_poll()
2717 if (q->is_output && (q->io_modes & VB2_WRITE) && in vb2_core_poll()
2719 if (__vb2_init_fileio(q, 0)) in vb2_core_poll()
2732 if (!vb2_is_streaming(q) || q->error) in vb2_core_poll()
2741 if (q->quirk_poll_must_check_waiting_for_buffers && in vb2_core_poll()
2742 q->waiting_for_buffers && (req_events & (EPOLLIN | EPOLLRDNORM))) in vb2_core_poll()
2749 if (q->is_output && q->fileio && q->queued_count < vb2_get_num_buffers(q)) in vb2_core_poll()
2752 if (list_empty(&q->done_list)) { in vb2_core_poll()
2757 if (q->last_buffer_dequeued) in vb2_core_poll()
2764 spin_lock_irqsave(&q->done_lock, flags); in vb2_core_poll()
2765 if (!list_empty(&q->done_list)) in vb2_core_poll()
2766 vb = list_first_entry(&q->done_list, struct vb2_buffer, in vb2_core_poll()
2768 spin_unlock_irqrestore(&q->done_lock, flags); in vb2_core_poll()
2772 return (q->is_output) ? in vb2_core_poll()
2791 unsigned int queued:1;
2827 unsigned read_once:1;
2828 unsigned write_immediately:1;
2833 * @q: videobuf2 queue
2834 * @read: mode selector (1 means read, 0 means write)
2836 static int __vb2_init_fileio(struct vb2_queue *q, int read) in __vb2_init_fileio() argument
2845 if (WARN_ON((read && !(q->io_modes & VB2_READ)) || in __vb2_init_fileio()
2846 (!read && !(q->io_modes & VB2_WRITE)))) in __vb2_init_fileio()
2852 if (!q->mem_ops->vaddr) in __vb2_init_fileio()
2858 if (q->streaming || vb2_get_num_buffers(q) > 0) in __vb2_init_fileio()
2861 dprintk(q, 3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n", in __vb2_init_fileio()
2862 (read) ? "read" : "write", q->min_reqbufs_allocation, q->fileio_read_once, in __vb2_init_fileio()
2863 q->fileio_write_immediately); in __vb2_init_fileio()
2869 fileio->read_once = q->fileio_read_once; in __vb2_init_fileio()
2870 fileio->write_immediately = q->fileio_write_immediately; in __vb2_init_fileio()
2876 fileio->count = q->min_reqbufs_allocation; in __vb2_init_fileio()
2878 fileio->type = q->type; in __vb2_init_fileio()
2879 q->fileio = fileio; in __vb2_init_fileio()
2880 ret = vb2_core_reqbufs(q, fileio->memory, 0, &fileio->count); in __vb2_init_fileio()
2885 dprintk(q, 1, "fileio: more than VB2_MAX_FRAME buffers requested\n"); in __vb2_init_fileio()
2892 * will never be holes. It is safe to assume that vb2_get_buffer(q, 0) in __vb2_init_fileio()
2895 vb = vb2_get_buffer(q, 0); in __vb2_init_fileio()
2901 if (vb->num_planes != 1) { in __vb2_init_fileio()
2909 for (i = 0; i < vb2_get_num_buffers(q); i++) { in __vb2_init_fileio()
2911 vb = vb2_get_buffer(q, i); in __vb2_init_fileio()
2928 for (i = 0; i < vb2_get_num_buffers(q); i++) { in __vb2_init_fileio()
2929 struct vb2_buffer *vb2 = vb2_get_buffer(q, i); in __vb2_init_fileio()
2934 ret = vb2_core_qbuf(q, vb2, NULL, NULL); in __vb2_init_fileio()
2937 fileio->bufs[i].queued = 1; in __vb2_init_fileio()
2943 fileio->initial_index = vb2_get_num_buffers(q); in __vb2_init_fileio()
2950 ret = vb2_core_streamon(q, q->type); in __vb2_init_fileio()
2958 vb2_core_reqbufs(q, fileio->memory, 0, &fileio->count); in __vb2_init_fileio()
2961 q->fileio = NULL; in __vb2_init_fileio()
2968 * @q: videobuf2 queue
2970 static int __vb2_cleanup_fileio(struct vb2_queue *q) in __vb2_cleanup_fileio() argument
2972 struct vb2_fileio_data *fileio = q->fileio; in __vb2_cleanup_fileio()
2975 vb2_core_streamoff(q, q->type); in __vb2_cleanup_fileio()
2976 q->fileio = NULL; in __vb2_cleanup_fileio()
2978 vb2_core_reqbufs(q, fileio->memory, 0, &fileio->count); in __vb2_cleanup_fileio()
2980 dprintk(q, 3, "file io emulator closed\n"); in __vb2_cleanup_fileio()
2987 * @q: videobuf2 queue
2991 * @nonblock: mode selector (1 means blocking calls, 0 means nonblocking)
2992 * @read: access mode selector (1 means read, 0 means write)
2994 static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_t count, in __vb2_perform_fileio() argument
2999 bool is_multiplanar = q->is_multiplanar; in __vb2_perform_fileio()
3005 bool copy_timestamp = !read && q->copy_timestamp; in __vb2_perform_fileio()
3009 dprintk(q, 3, "mode %s, offset %ld, count %zd, %sblocking\n", in __vb2_perform_fileio()
3016 if (q->waiting_in_dqbuf) { in __vb2_perform_fileio()
3017 dprintk(q, 3, "another dup()ped fd is %s\n", in __vb2_perform_fileio()
3025 if (!vb2_fileio_is_active(q)) { in __vb2_perform_fileio()
3026 ret = __vb2_init_fileio(q, read); in __vb2_perform_fileio()
3027 dprintk(q, 3, "vb2_init_fileio result: %d\n", ret); in __vb2_perform_fileio()
3031 fileio = q->fileio; in __vb2_perform_fileio()
3037 if (index >= vb2_get_num_buffers(q)) { in __vb2_perform_fileio()
3043 ret = vb2_core_dqbuf(q, &index, NULL, nonblock); in __vb2_perform_fileio()
3044 dprintk(q, 5, "vb2_dqbuf result: %d\n", ret); in __vb2_perform_fileio()
3047 fileio->dq_count += 1; in __vb2_perform_fileio()
3053 b = vb2_get_buffer(q, index); in __vb2_perform_fileio()
3077 dprintk(q, 5, "reducing read count: %zd\n", count); in __vb2_perform_fileio()
3083 dprintk(q, 3, "copying %zd bytes - buffer %d, offset %u\n", in __vb2_perform_fileio()
3090 dprintk(q, 3, "error copying data\n"); in __vb2_perform_fileio()
3105 struct vb2_buffer *b = vb2_get_buffer(q, index); in __vb2_perform_fileio()
3110 if (read && fileio->read_once && fileio->dq_count == 1) { in __vb2_perform_fileio()
3111 dprintk(q, 3, "read limit reached\n"); in __vb2_perform_fileio()
3112 return __vb2_cleanup_fileio(q); in __vb2_perform_fileio()
3122 ret = vb2_core_qbuf(q, b, NULL, NULL); in __vb2_perform_fileio()
3123 dprintk(q, 5, "vb2_qbuf result: %d\n", ret); in __vb2_perform_fileio()
3131 buf->queued = 1; in __vb2_perform_fileio()
3133 fileio->q_count += 1; in __vb2_perform_fileio()
3138 if (fileio->initial_index < vb2_get_num_buffers(q)) in __vb2_perform_fileio()
3158 size_t vb2_read(struct vb2_queue *q, char __user *data, size_t count, in vb2_read() argument
3161 return __vb2_perform_fileio(q, data, count, ppos, nonblocking, 1); in vb2_read()
3165 size_t vb2_write(struct vb2_queue *q, const char __user *data, size_t count, in vb2_write() argument
3168 return __vb2_perform_fileio(q, (char __user *) data, count, in vb2_write()
3182 struct vb2_queue *q = data; in vb2_thread() local
3183 struct vb2_threadio_data *threadio = q->threadio; in vb2_thread()
3189 if (q->is_output) { in vb2_thread()
3190 prequeue = vb2_get_num_buffers(q); in vb2_thread()
3191 copy_timestamp = q->copy_timestamp; in vb2_thread()
3203 vb = vb2_get_buffer(q, index++); in vb2_thread()
3208 call_void_qop(q, wait_finish, q); in vb2_thread()
3210 ret = vb2_core_dqbuf(q, &index, NULL, 0); in vb2_thread()
3211 call_void_qop(q, wait_prepare, q); in vb2_thread()
3212 dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret); in vb2_thread()
3214 vb = vb2_get_buffer(q, index); in vb2_thread()
3223 call_void_qop(q, wait_finish, q); in vb2_thread()
3227 ret = vb2_core_qbuf(q, vb, NULL, NULL); in vb2_thread()
3228 call_void_qop(q, wait_prepare, q); in vb2_thread()
3246 int vb2_thread_start(struct vb2_queue *q, vb2_thread_fnc fnc, void *priv, in vb2_thread_start() argument
3252 if (q->threadio) in vb2_thread_start()
3254 if (vb2_is_busy(q)) in vb2_thread_start()
3256 if (WARN_ON(q->fileio)) in vb2_thread_start()
3265 ret = __vb2_init_fileio(q, !q->is_output); in vb2_thread_start()
3266 dprintk(q, 3, "file io: vb2_init_fileio result: %d\n", ret); in vb2_thread_start()
3269 q->threadio = threadio; in vb2_thread_start()
3270 threadio->thread = kthread_run(vb2_thread, q, "vb2-%s", thread_name); in vb2_thread_start()
3279 __vb2_cleanup_fileio(q); in vb2_thread_start()
3286 int vb2_thread_stop(struct vb2_queue *q) in vb2_thread_stop() argument
3288 struct vb2_threadio_data *threadio = q->threadio; in vb2_thread_stop()
3295 vb2_queue_error(q); in vb2_thread_stop()
3297 __vb2_cleanup_fileio(q); in vb2_thread_stop()
3300 q->threadio = NULL; in vb2_thread_stop()