brcm2708: rename target to bcm27xx
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-4.19 / 950-0601-media-vb2-set-reqbufs-create_bufs-capabilities.patch
1 From 7410e35a4936b89f2e227c52058c11f1574bbfca Mon Sep 17 00:00:00 2001
2 From: Hans Verkuil <hansverk@cisco.com>
3 Date: Thu, 23 Aug 2018 10:18:35 -0400
4 Subject: [PATCH] media: vb2: set reqbufs/create_bufs capabilities
5
6 Upstream commit e5079cf11373e4cc98be8b1072aece429eb2d4d2.
7
8 Set the capabilities field of v4l2_requestbuffers and v4l2_create_buffers.
9
10 The various mapping modes were easy, but for signaling the request capability
11 a new 'supports_requests' bitfield was added to videobuf2-core.h (and set in
12 vim2m and vivid). Drivers have to set this bitfield for any queue where
13 requests are supported.
14
15 Signed-off-by: Hans Verkuil <hansverk@cisco.com>
16 Reviewed-by: Tomasz Figa <tfiga@chromium.org>
17 Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
18 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
19
20 Minor modifications required on the backport
21 ---
22 drivers/media/common/videobuf2/videobuf2-v4l2.c | 17 +++++++++++++++++
23 drivers/media/platform/vim2m.c | 1 +
24 drivers/media/platform/vivid/vivid-core.c | 5 +++++
25 drivers/media/v4l2-core/v4l2-compat-ioctl32.c | 4 +++-
26 drivers/media/v4l2-core/v4l2-ioctl.c | 4 ++--
27 include/media/videobuf2-core.h | 2 ++
28 6 files changed, 30 insertions(+), 3 deletions(-)
29
30 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c
31 +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c
32 @@ -482,10 +482,24 @@ int vb2_querybuf(struct vb2_queue *q, st
33 }
34 EXPORT_SYMBOL(vb2_querybuf);
35
36 +static void fill_buf_caps(struct vb2_queue *q, u32 *caps)
37 +{
38 + *caps = 0;
39 + if (q->io_modes & VB2_MMAP)
40 + *caps |= V4L2_BUF_CAP_SUPPORTS_MMAP;
41 + if (q->io_modes & VB2_USERPTR)
42 + *caps |= V4L2_BUF_CAP_SUPPORTS_USERPTR;
43 + if (q->io_modes & VB2_DMABUF)
44 + *caps |= V4L2_BUF_CAP_SUPPORTS_DMABUF;
45 + if (q->supports_requests)
46 + *caps |= V4L2_BUF_CAP_SUPPORTS_REQUESTS;
47 +}
48 +
49 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
50 {
51 int ret = vb2_verify_memory_type(q, req->memory, req->type);
52
53 + fill_buf_caps(q, &req->capabilities);
54 return ret ? ret : vb2_core_reqbufs(q, req->memory, &req->count);
55 }
56 EXPORT_SYMBOL_GPL(vb2_reqbufs);
57 @@ -513,6 +527,7 @@ int vb2_create_bufs(struct vb2_queue *q,
58 int ret = vb2_verify_memory_type(q, create->memory, f->type);
59 unsigned i;
60
61 + fill_buf_caps(q, &create->capabilities);
62 create->index = q->num_buffers;
63 if (create->count == 0)
64 return ret != -EBUSY ? ret : 0;
65 @@ -713,6 +728,7 @@ int vb2_ioctl_reqbufs(struct file *file,
66 struct video_device *vdev = video_devdata(file);
67 int res = vb2_verify_memory_type(vdev->queue, p->memory, p->type);
68
69 + fill_buf_caps(vdev->queue, &p->capabilities);
70 if (res)
71 return res;
72 if (vb2_queue_is_busy(vdev, file))
73 @@ -734,6 +750,7 @@ int vb2_ioctl_create_bufs(struct file *f
74 p->format.type);
75
76 p->index = vdev->queue->num_buffers;
77 + fill_buf_caps(vdev->queue, &p->capabilities);
78 /*
79 * If count == 0, then just check if memory and type are valid.
80 * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0.
81 --- a/drivers/media/platform/vim2m.c
82 +++ b/drivers/media/platform/vim2m.c
83 @@ -840,6 +840,7 @@ static int queue_init(void *priv, struct
84 src_vq->mem_ops = &vb2_vmalloc_memops;
85 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
86 src_vq->lock = &ctx->dev->dev_mutex;
87 + src_vq->supports_requests = true;
88
89 ret = vb2_queue_init(src_vq);
90 if (ret)
91 --- a/drivers/media/platform/vivid/vivid-core.c
92 +++ b/drivers/media/platform/vivid/vivid-core.c
93 @@ -1060,6 +1060,7 @@ static int vivid_create_instance(struct
94 q->min_buffers_needed = 2;
95 q->lock = &dev->mutex;
96 q->dev = dev->v4l2_dev.dev;
97 + q->supports_requests = true;
98
99 ret = vb2_queue_init(q);
100 if (ret)
101 @@ -1080,6 +1081,7 @@ static int vivid_create_instance(struct
102 q->min_buffers_needed = 2;
103 q->lock = &dev->mutex;
104 q->dev = dev->v4l2_dev.dev;
105 + q->supports_requests = true;
106
107 ret = vb2_queue_init(q);
108 if (ret)
109 @@ -1100,6 +1102,7 @@ static int vivid_create_instance(struct
110 q->min_buffers_needed = 2;
111 q->lock = &dev->mutex;
112 q->dev = dev->v4l2_dev.dev;
113 + q->supports_requests = true;
114
115 ret = vb2_queue_init(q);
116 if (ret)
117 @@ -1120,6 +1123,7 @@ static int vivid_create_instance(struct
118 q->min_buffers_needed = 2;
119 q->lock = &dev->mutex;
120 q->dev = dev->v4l2_dev.dev;
121 + q->supports_requests = true;
122
123 ret = vb2_queue_init(q);
124 if (ret)
125 @@ -1139,6 +1143,7 @@ static int vivid_create_instance(struct
126 q->min_buffers_needed = 8;
127 q->lock = &dev->mutex;
128 q->dev = dev->v4l2_dev.dev;
129 + q->supports_requests = true;
130
131 ret = vb2_queue_init(q);
132 if (ret)
133 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
134 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
135 @@ -251,7 +251,8 @@ struct v4l2_create_buffers32 {
136 __u32 count;
137 __u32 memory; /* enum v4l2_memory */
138 struct v4l2_format32 format;
139 - __u32 reserved[8];
140 + __u32 capabilities;
141 + __u32 reserved[7];
142 };
143
144 static int __bufsize_v4l2_format(struct v4l2_format32 __user *p32, u32 *size)
145 @@ -411,6 +412,7 @@ static int put_v4l2_create32(struct v4l2
146 if (!access_ok(VERIFY_WRITE, p32, sizeof(*p32)) ||
147 copy_in_user(p32, p64,
148 offsetof(struct v4l2_create_buffers32, format)) ||
149 + assign_in_user(&p32->capabilities, &p64->capabilities) ||
150 copy_in_user(p32->reserved, p64->reserved, sizeof(p64->reserved)))
151 return -EFAULT;
152 return __put_v4l2_format32(&p64->format, &p32->format);
153 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
154 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
155 @@ -1882,7 +1882,7 @@ static int v4l_reqbufs(const struct v4l2
156 if (ret)
157 return ret;
158
159 - CLEAR_AFTER_FIELD(p, memory);
160 + CLEAR_AFTER_FIELD(p, capabilities);
161
162 return ops->vidioc_reqbufs(file, fh, p);
163 }
164 @@ -1923,7 +1923,7 @@ static int v4l_create_bufs(const struct
165 if (ret)
166 return ret;
167
168 - CLEAR_AFTER_FIELD(create, format);
169 + CLEAR_AFTER_FIELD(create, capabilities);
170
171 v4l_sanitize_format(&create->format);
172
173 --- a/include/media/videobuf2-core.h
174 +++ b/include/media/videobuf2-core.h
175 @@ -449,6 +449,7 @@ struct vb2_buf_ops {
176 * @quirk_poll_must_check_waiting_for_buffers: Return %EPOLLERR at poll when QBUF
177 * has not been called. This is a vb1 idiom that has been adopted
178 * also by vb2.
179 + * @supports_requests: this queue supports the Request API.
180 * @lock: pointer to a mutex that protects the &struct vb2_queue. The
181 * driver can set this to a mutex to let the v4l2 core serialize
182 * the queuing ioctls. If the driver wants to handle locking
183 @@ -516,6 +517,7 @@ struct vb2_queue {
184 unsigned fileio_write_immediately:1;
185 unsigned allow_zero_bytesused:1;
186 unsigned quirk_poll_must_check_waiting_for_buffers:1;
187 + unsigned supports_requests:1;
188
189 struct mutex *lock;
190 void *owner;