33c3242c92662a366576675be1e0124c3df6d870
[openwrt/staging/neocturne.git] /
1 From 0f4f3fca8bb1e8283d5342d63e6758f6ac16d68d Mon Sep 17 00:00:00 2001
2 From: John Sheu <sheu@chromium.org>
3 Date: Thu, 15 Oct 2015 18:05:25 +0900
4 Subject: [PATCH 285/703] media: vb2: Allow reqbufs(0) with "in use" MMAP
5 buffers
6
7 Videobuf2 presently does not allow VIDIOC_REQBUFS to destroy outstanding
8 buffers if the queue is of type V4L2_MEMORY_MMAP, and if the buffers are
9 considered "in use". This is different behavior than for other memory
10 types and prevents us from deallocating buffers in following two cases:
11
12 1) There are outstanding mmap()ed views on the buffer. However even if
13 we put the buffer in reqbufs(0), there will be remaining references,
14 due to vma .open/close() adjusting vb2 buffer refcount appropriately.
15 This means that the buffer will be in fact freed only when the last
16 mmap()ed view is unmapped.
17
18 2) Buffer has been exported as a DMABUF. Refcount of the vb2 buffer
19 is managed properly by VB2 DMABUF ops, i.e. incremented on DMABUF
20 get and decremented on DMABUF release. This means that the buffer
21 will be alive until all importers release it.
22
23 Considering both cases above, there does not seem to be any need to
24 prevent reqbufs(0) operation, because buffer lifetime is already
25 properly managed by both mmap() and DMABUF code paths. Let's remove it
26 and allow userspace freeing the queue (and potentially allocating a new
27 one) even though old buffers might be still in processing.
28
29 Signed-off-by: John Sheu <sheu@chromium.org>
30 Reviewed-by: Pawel Osciak <posciak@chromium.org>
31 Reviewed-by: Tomasz Figa <tfiga@chromium.org>
32 Signed-off-by: Tomasz Figa <tfiga@chromium.org>
33 ---
34 .../media/common/videobuf2/videobuf2-core.c | 23 -------------------
35 1 file changed, 23 deletions(-)
36
37 --- a/drivers/media/common/videobuf2/videobuf2-core.c
38 +++ b/drivers/media/common/videobuf2/videobuf2-core.c
39 @@ -554,20 +554,6 @@ bool vb2_buffer_in_use(struct vb2_queue
40 }
41 EXPORT_SYMBOL(vb2_buffer_in_use);
42
43 -/*
44 - * __buffers_in_use() - return true if any buffers on the queue are in use and
45 - * the queue cannot be freed (by the means of REQBUFS(0)) call
46 - */
47 -static bool __buffers_in_use(struct vb2_queue *q)
48 -{
49 - unsigned int buffer;
50 - for (buffer = 0; buffer < q->num_buffers; ++buffer) {
51 - if (vb2_buffer_in_use(q, q->bufs[buffer]))
52 - return true;
53 - }
54 - return false;
55 -}
56 -
57 void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb)
58 {
59 call_void_bufop(q, fill_user_buffer, q->bufs[index], pb);
60 @@ -679,16 +665,7 @@ int vb2_core_reqbufs(struct vb2_queue *q
61
62 if (*count == 0 || q->num_buffers != 0 ||
63 (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory)) {
64 - /*
65 - * We already have buffers allocated, so first check if they
66 - * are not in use and can be freed.
67 - */
68 mutex_lock(&q->mmap_lock);
69 - if (q->memory == VB2_MEMORY_MMAP && __buffers_in_use(q)) {
70 - mutex_unlock(&q->mmap_lock);
71 - dprintk(1, "memory in use, cannot free\n");
72 - return -EBUSY;
73 - }
74
75 /*
76 * Call queue_cancel to clean up any buffers in the PREPARED or