diff options
Diffstat (limited to 'drivers/media/v4l2-core/videobuf2-core.c')
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-core.c | 219 |
1 files changed, 131 insertions, 88 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index 9518ebd2d73b..8c456f7b1995 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c | |||
@@ -53,7 +53,7 @@ module_param(debug, int, 0644); | |||
53 | 53 | ||
54 | #define log_memop(vb, op) \ | 54 | #define log_memop(vb, op) \ |
55 | dprintk(2, "call_memop(%p, %d, %s)%s\n", \ | 55 | dprintk(2, "call_memop(%p, %d, %s)%s\n", \ |
56 | (vb)->vb2_queue, (vb)->v4l2_buf.index, #op, \ | 56 | (vb)->vb2_queue, (vb)->index, #op, \ |
57 | (vb)->vb2_queue->mem_ops->op ? "" : " (nop)") | 57 | (vb)->vb2_queue->mem_ops->op ? "" : " (nop)") |
58 | 58 | ||
59 | #define call_memop(vb, op, args...) \ | 59 | #define call_memop(vb, op, args...) \ |
@@ -115,7 +115,7 @@ module_param(debug, int, 0644); | |||
115 | 115 | ||
116 | #define log_vb_qop(vb, op, args...) \ | 116 | #define log_vb_qop(vb, op, args...) \ |
117 | dprintk(2, "call_vb_qop(%p, %d, %s)%s\n", \ | 117 | dprintk(2, "call_vb_qop(%p, %d, %s)%s\n", \ |
118 | (vb)->vb2_queue, (vb)->v4l2_buf.index, #op, \ | 118 | (vb)->vb2_queue, (vb)->index, #op, \ |
119 | (vb)->vb2_queue->ops->op ? "" : " (nop)") | 119 | (vb)->vb2_queue->ops->op ? "" : " (nop)") |
120 | 120 | ||
121 | #define call_vb_qop(vb, op, args...) \ | 121 | #define call_vb_qop(vb, op, args...) \ |
@@ -211,7 +211,7 @@ static int __vb2_buf_mem_alloc(struct vb2_buffer *vb) | |||
211 | 211 | ||
212 | /* Associate allocator private data with this plane */ | 212 | /* Associate allocator private data with this plane */ |
213 | vb->planes[plane].mem_priv = mem_priv; | 213 | vb->planes[plane].mem_priv = mem_priv; |
214 | vb->v4l2_planes[plane].length = q->plane_sizes[plane]; | 214 | vb->planes[plane].length = q->plane_sizes[plane]; |
215 | } | 215 | } |
216 | 216 | ||
217 | return 0; | 217 | return 0; |
@@ -235,8 +235,7 @@ static void __vb2_buf_mem_free(struct vb2_buffer *vb) | |||
235 | for (plane = 0; plane < vb->num_planes; ++plane) { | 235 | for (plane = 0; plane < vb->num_planes; ++plane) { |
236 | call_void_memop(vb, put, vb->planes[plane].mem_priv); | 236 | call_void_memop(vb, put, vb->planes[plane].mem_priv); |
237 | vb->planes[plane].mem_priv = NULL; | 237 | vb->planes[plane].mem_priv = NULL; |
238 | dprintk(3, "freed plane %d of buffer %d\n", plane, | 238 | dprintk(3, "freed plane %d of buffer %d\n", plane, vb->index); |
239 | vb->v4l2_buf.index); | ||
240 | } | 239 | } |
241 | } | 240 | } |
242 | 241 | ||
@@ -269,7 +268,9 @@ static void __vb2_plane_dmabuf_put(struct vb2_buffer *vb, struct vb2_plane *p) | |||
269 | 268 | ||
270 | call_void_memop(vb, detach_dmabuf, p->mem_priv); | 269 | call_void_memop(vb, detach_dmabuf, p->mem_priv); |
271 | dma_buf_put(p->dbuf); | 270 | dma_buf_put(p->dbuf); |
272 | memset(p, 0, sizeof(*p)); | 271 | p->mem_priv = NULL; |
272 | p->dbuf = NULL; | ||
273 | p->dbuf_mapped = 0; | ||
273 | } | 274 | } |
274 | 275 | ||
275 | /** | 276 | /** |
@@ -299,7 +300,7 @@ static void __setup_lengths(struct vb2_queue *q, unsigned int n) | |||
299 | continue; | 300 | continue; |
300 | 301 | ||
301 | for (plane = 0; plane < vb->num_planes; ++plane) | 302 | for (plane = 0; plane < vb->num_planes; ++plane) |
302 | vb->v4l2_planes[plane].length = q->plane_sizes[plane]; | 303 | vb->planes[plane].length = q->plane_sizes[plane]; |
303 | } | 304 | } |
304 | } | 305 | } |
305 | 306 | ||
@@ -314,10 +315,10 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n) | |||
314 | unsigned long off; | 315 | unsigned long off; |
315 | 316 | ||
316 | if (q->num_buffers) { | 317 | if (q->num_buffers) { |
317 | struct v4l2_plane *p; | 318 | struct vb2_plane *p; |
318 | vb = q->bufs[q->num_buffers - 1]; | 319 | vb = q->bufs[q->num_buffers - 1]; |
319 | p = &vb->v4l2_planes[vb->num_planes - 1]; | 320 | p = &vb->planes[vb->num_planes - 1]; |
320 | off = PAGE_ALIGN(p->m.mem_offset + p->length); | 321 | off = PAGE_ALIGN(p->m.offset + p->length); |
321 | } else { | 322 | } else { |
322 | off = 0; | 323 | off = 0; |
323 | } | 324 | } |
@@ -328,12 +329,12 @@ static void __setup_offsets(struct vb2_queue *q, unsigned int n) | |||
328 | continue; | 329 | continue; |
329 | 330 | ||
330 | for (plane = 0; plane < vb->num_planes; ++plane) { | 331 | for (plane = 0; plane < vb->num_planes; ++plane) { |
331 | vb->v4l2_planes[plane].m.mem_offset = off; | 332 | vb->planes[plane].m.offset = off; |
332 | 333 | ||
333 | dprintk(3, "buffer %d, plane %d offset 0x%08lx\n", | 334 | dprintk(3, "buffer %d, plane %d offset 0x%08lx\n", |
334 | buffer, plane, off); | 335 | buffer, plane, off); |
335 | 336 | ||
336 | off += vb->v4l2_planes[plane].length; | 337 | off += vb->planes[plane].length; |
337 | off = PAGE_ALIGN(off); | 338 | off = PAGE_ALIGN(off); |
338 | } | 339 | } |
339 | } | 340 | } |
@@ -361,16 +362,12 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum v4l2_memory memory, | |||
361 | break; | 362 | break; |
362 | } | 363 | } |
363 | 364 | ||
364 | /* Length stores number of planes for multiplanar buffers */ | ||
365 | if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) | ||
366 | vb->v4l2_buf.length = num_planes; | ||
367 | |||
368 | vb->state = VB2_BUF_STATE_DEQUEUED; | 365 | vb->state = VB2_BUF_STATE_DEQUEUED; |
369 | vb->vb2_queue = q; | 366 | vb->vb2_queue = q; |
370 | vb->num_planes = num_planes; | 367 | vb->num_planes = num_planes; |
371 | vb->v4l2_buf.index = q->num_buffers + buffer; | 368 | vb->index = q->num_buffers + buffer; |
372 | vb->v4l2_buf.type = q->type; | 369 | vb->type = q->type; |
373 | vb->v4l2_buf.memory = memory; | 370 | vb->memory = memory; |
374 | 371 | ||
375 | /* Allocate video buffer memory for the MMAP type */ | 372 | /* Allocate video buffer memory for the MMAP type */ |
376 | if (memory == V4L2_MEMORY_MMAP) { | 373 | if (memory == V4L2_MEMORY_MMAP) { |
@@ -592,7 +589,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
592 | length = (b->memory == V4L2_MEMORY_USERPTR || | 589 | length = (b->memory == V4L2_MEMORY_USERPTR || |
593 | b->memory == V4L2_MEMORY_DMABUF) | 590 | b->memory == V4L2_MEMORY_DMABUF) |
594 | ? b->m.planes[plane].length | 591 | ? b->m.planes[plane].length |
595 | : vb->v4l2_planes[plane].length; | 592 | : vb->planes[plane].length; |
596 | bytesused = b->m.planes[plane].bytesused | 593 | bytesused = b->m.planes[plane].bytesused |
597 | ? b->m.planes[plane].bytesused : length; | 594 | ? b->m.planes[plane].bytesused : length; |
598 | 595 | ||
@@ -605,8 +602,7 @@ static int __verify_length(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
605 | } | 602 | } |
606 | } else { | 603 | } else { |
607 | length = (b->memory == V4L2_MEMORY_USERPTR) | 604 | length = (b->memory == V4L2_MEMORY_USERPTR) |
608 | ? b->length : vb->v4l2_planes[0].length; | 605 | ? b->length : vb->planes[0].length; |
609 | bytesused = b->bytesused ? b->bytesused : length; | ||
610 | 606 | ||
611 | if (b->bytesused > length) | 607 | if (b->bytesused > length) |
612 | return -EINVAL; | 608 | return -EINVAL; |
@@ -656,12 +652,23 @@ static bool __buffers_in_use(struct vb2_queue *q) | |||
656 | */ | 652 | */ |
657 | static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) | 653 | static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) |
658 | { | 654 | { |
655 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); | ||
659 | struct vb2_queue *q = vb->vb2_queue; | 656 | struct vb2_queue *q = vb->vb2_queue; |
657 | unsigned int plane; | ||
660 | 658 | ||
661 | /* Copy back data such as timestamp, flags, etc. */ | 659 | /* Copy back data such as timestamp, flags, etc. */ |
662 | memcpy(b, &vb->v4l2_buf, offsetof(struct v4l2_buffer, m)); | 660 | b->index = vb->index; |
663 | b->reserved2 = vb->v4l2_buf.reserved2; | 661 | b->type = vb->type; |
664 | b->reserved = vb->v4l2_buf.reserved; | 662 | b->memory = vb->memory; |
663 | b->bytesused = 0; | ||
664 | |||
665 | b->flags = vbuf->flags; | ||
666 | b->field = vbuf->field; | ||
667 | b->timestamp = vbuf->timestamp; | ||
668 | b->timecode = vbuf->timecode; | ||
669 | b->sequence = vbuf->sequence; | ||
670 | b->reserved2 = 0; | ||
671 | b->reserved = 0; | ||
665 | 672 | ||
666 | if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) { | 673 | if (V4L2_TYPE_IS_MULTIPLANAR(q->type)) { |
667 | /* | 674 | /* |
@@ -669,21 +676,34 @@ static void __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) | |||
669 | * for it. The caller has already verified memory and size. | 676 | * for it. The caller has already verified memory and size. |
670 | */ | 677 | */ |
671 | b->length = vb->num_planes; | 678 | b->length = vb->num_planes; |
672 | memcpy(b->m.planes, vb->v4l2_planes, | 679 | for (plane = 0; plane < vb->num_planes; ++plane) { |
673 | b->length * sizeof(struct v4l2_plane)); | 680 | struct v4l2_plane *pdst = &b->m.planes[plane]; |
681 | struct vb2_plane *psrc = &vb->planes[plane]; | ||
682 | |||
683 | pdst->bytesused = psrc->bytesused; | ||
684 | pdst->length = psrc->length; | ||
685 | if (q->memory == V4L2_MEMORY_MMAP) | ||
686 | pdst->m.mem_offset = psrc->m.offset; | ||
687 | else if (q->memory == V4L2_MEMORY_USERPTR) | ||
688 | pdst->m.userptr = psrc->m.userptr; | ||
689 | else if (q->memory == V4L2_MEMORY_DMABUF) | ||
690 | pdst->m.fd = psrc->m.fd; | ||
691 | pdst->data_offset = psrc->data_offset; | ||
692 | memset(pdst->reserved, 0, sizeof(pdst->reserved)); | ||
693 | } | ||
674 | } else { | 694 | } else { |
675 | /* | 695 | /* |
676 | * We use length and offset in v4l2_planes array even for | 696 | * We use length and offset in v4l2_planes array even for |
677 | * single-planar buffers, but userspace does not. | 697 | * single-planar buffers, but userspace does not. |
678 | */ | 698 | */ |
679 | b->length = vb->v4l2_planes[0].length; | 699 | b->length = vb->planes[0].length; |
680 | b->bytesused = vb->v4l2_planes[0].bytesused; | 700 | b->bytesused = vb->planes[0].bytesused; |
681 | if (q->memory == V4L2_MEMORY_MMAP) | 701 | if (q->memory == V4L2_MEMORY_MMAP) |
682 | b->m.offset = vb->v4l2_planes[0].m.mem_offset; | 702 | b->m.offset = vb->planes[0].m.offset; |
683 | else if (q->memory == V4L2_MEMORY_USERPTR) | 703 | else if (q->memory == V4L2_MEMORY_USERPTR) |
684 | b->m.userptr = vb->v4l2_planes[0].m.userptr; | 704 | b->m.userptr = vb->planes[0].m.userptr; |
685 | else if (q->memory == V4L2_MEMORY_DMABUF) | 705 | else if (q->memory == V4L2_MEMORY_DMABUF) |
686 | b->m.fd = vb->v4l2_planes[0].m.fd; | 706 | b->m.fd = vb->planes[0].m.fd; |
687 | } | 707 | } |
688 | 708 | ||
689 | /* | 709 | /* |
@@ -1197,7 +1217,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) | |||
1197 | vb->cnt_buf_done++; | 1217 | vb->cnt_buf_done++; |
1198 | #endif | 1218 | #endif |
1199 | dprintk(4, "done processing on buffer %d, state: %d\n", | 1219 | dprintk(4, "done processing on buffer %d, state: %d\n", |
1200 | vb->v4l2_buf.index, state); | 1220 | vb->index, state); |
1201 | 1221 | ||
1202 | /* sync buffers */ | 1222 | /* sync buffers */ |
1203 | for (plane = 0; plane < vb->num_planes; ++plane) | 1223 | for (plane = 0; plane < vb->num_planes; ++plane) |
@@ -1278,25 +1298,26 @@ static void vb2_warn_zero_bytesused(struct vb2_buffer *vb) | |||
1278 | * v4l2_buffer by the userspace. The caller has already verified that struct | 1298 | * v4l2_buffer by the userspace. The caller has already verified that struct |
1279 | * v4l2_buffer has a valid number of planes. | 1299 | * v4l2_buffer has a valid number of planes. |
1280 | */ | 1300 | */ |
1281 | static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b, | 1301 | static void __fill_vb2_buffer(struct vb2_buffer *vb, |
1282 | struct v4l2_plane *v4l2_planes) | 1302 | const struct v4l2_buffer *b, struct vb2_plane *planes) |
1283 | { | 1303 | { |
1304 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); | ||
1284 | unsigned int plane; | 1305 | unsigned int plane; |
1285 | 1306 | ||
1286 | if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { | 1307 | if (V4L2_TYPE_IS_MULTIPLANAR(b->type)) { |
1287 | if (b->memory == V4L2_MEMORY_USERPTR) { | 1308 | if (b->memory == V4L2_MEMORY_USERPTR) { |
1288 | for (plane = 0; plane < vb->num_planes; ++plane) { | 1309 | for (plane = 0; plane < vb->num_planes; ++plane) { |
1289 | v4l2_planes[plane].m.userptr = | 1310 | planes[plane].m.userptr = |
1290 | b->m.planes[plane].m.userptr; | 1311 | b->m.planes[plane].m.userptr; |
1291 | v4l2_planes[plane].length = | 1312 | planes[plane].length = |
1292 | b->m.planes[plane].length; | 1313 | b->m.planes[plane].length; |
1293 | } | 1314 | } |
1294 | } | 1315 | } |
1295 | if (b->memory == V4L2_MEMORY_DMABUF) { | 1316 | if (b->memory == V4L2_MEMORY_DMABUF) { |
1296 | for (plane = 0; plane < vb->num_planes; ++plane) { | 1317 | for (plane = 0; plane < vb->num_planes; ++plane) { |
1297 | v4l2_planes[plane].m.fd = | 1318 | planes[plane].m.fd = |
1298 | b->m.planes[plane].m.fd; | 1319 | b->m.planes[plane].m.fd; |
1299 | v4l2_planes[plane].length = | 1320 | planes[plane].length = |
1300 | b->m.planes[plane].length; | 1321 | b->m.planes[plane].length; |
1301 | } | 1322 | } |
1302 | } | 1323 | } |
@@ -1320,7 +1341,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b | |||
1320 | * applications working. | 1341 | * applications working. |
1321 | */ | 1342 | */ |
1322 | for (plane = 0; plane < vb->num_planes; ++plane) { | 1343 | for (plane = 0; plane < vb->num_planes; ++plane) { |
1323 | struct v4l2_plane *pdst = &v4l2_planes[plane]; | 1344 | struct vb2_plane *pdst = &planes[plane]; |
1324 | struct v4l2_plane *psrc = &b->m.planes[plane]; | 1345 | struct v4l2_plane *psrc = &b->m.planes[plane]; |
1325 | 1346 | ||
1326 | if (psrc->bytesused == 0) | 1347 | if (psrc->bytesused == 0) |
@@ -1350,13 +1371,13 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b | |||
1350 | * old userspace applications working. | 1371 | * old userspace applications working. |
1351 | */ | 1372 | */ |
1352 | if (b->memory == V4L2_MEMORY_USERPTR) { | 1373 | if (b->memory == V4L2_MEMORY_USERPTR) { |
1353 | v4l2_planes[0].m.userptr = b->m.userptr; | 1374 | planes[0].m.userptr = b->m.userptr; |
1354 | v4l2_planes[0].length = b->length; | 1375 | planes[0].length = b->length; |
1355 | } | 1376 | } |
1356 | 1377 | ||
1357 | if (b->memory == V4L2_MEMORY_DMABUF) { | 1378 | if (b->memory == V4L2_MEMORY_DMABUF) { |
1358 | v4l2_planes[0].m.fd = b->m.fd; | 1379 | planes[0].m.fd = b->m.fd; |
1359 | v4l2_planes[0].length = b->length; | 1380 | planes[0].length = b->length; |
1360 | } | 1381 | } |
1361 | 1382 | ||
1362 | if (V4L2_TYPE_IS_OUTPUT(b->type)) { | 1383 | if (V4L2_TYPE_IS_OUTPUT(b->type)) { |
@@ -1364,17 +1385,17 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b | |||
1364 | vb2_warn_zero_bytesused(vb); | 1385 | vb2_warn_zero_bytesused(vb); |
1365 | 1386 | ||
1366 | if (vb->vb2_queue->allow_zero_bytesused) | 1387 | if (vb->vb2_queue->allow_zero_bytesused) |
1367 | v4l2_planes[0].bytesused = b->bytesused; | 1388 | planes[0].bytesused = b->bytesused; |
1368 | else | 1389 | else |
1369 | v4l2_planes[0].bytesused = b->bytesused ? | 1390 | planes[0].bytesused = b->bytesused ? |
1370 | b->bytesused : v4l2_planes[0].length; | 1391 | b->bytesused : planes[0].length; |
1371 | } else | 1392 | } else |
1372 | v4l2_planes[0].bytesused = 0; | 1393 | planes[0].bytesused = 0; |
1373 | 1394 | ||
1374 | } | 1395 | } |
1375 | 1396 | ||
1376 | /* Zero flags that the vb2 core handles */ | 1397 | /* Zero flags that the vb2 core handles */ |
1377 | vb->v4l2_buf.flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS; | 1398 | vbuf->flags = b->flags & ~V4L2_BUFFER_MASK_FLAGS; |
1378 | if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) != | 1399 | if ((vb->vb2_queue->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) != |
1379 | V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) { | 1400 | V4L2_BUF_FLAG_TIMESTAMP_COPY || !V4L2_TYPE_IS_OUTPUT(b->type)) { |
1380 | /* | 1401 | /* |
@@ -1382,7 +1403,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b | |||
1382 | * their timestamp and timestamp source flags from the | 1403 | * their timestamp and timestamp source flags from the |
1383 | * queue. | 1404 | * queue. |
1384 | */ | 1405 | */ |
1385 | vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK; | 1406 | vbuf->flags &= ~V4L2_BUF_FLAG_TSTAMP_SRC_MASK; |
1386 | } | 1407 | } |
1387 | 1408 | ||
1388 | if (V4L2_TYPE_IS_OUTPUT(b->type)) { | 1409 | if (V4L2_TYPE_IS_OUTPUT(b->type)) { |
@@ -1392,11 +1413,11 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b | |||
1392 | * The 'field' is valid metadata for this output buffer | 1413 | * The 'field' is valid metadata for this output buffer |
1393 | * and so that needs to be copied here. | 1414 | * and so that needs to be copied here. |
1394 | */ | 1415 | */ |
1395 | vb->v4l2_buf.flags &= ~V4L2_BUF_FLAG_TIMECODE; | 1416 | vbuf->flags &= ~V4L2_BUF_FLAG_TIMECODE; |
1396 | vb->v4l2_buf.field = b->field; | 1417 | vbuf->field = b->field; |
1397 | } else { | 1418 | } else { |
1398 | /* Zero any output buffer flags as this is a capture buffer */ | 1419 | /* Zero any output buffer flags as this is a capture buffer */ |
1399 | vb->v4l2_buf.flags &= ~V4L2_BUFFER_OUT_FLAGS; | 1420 | vbuf->flags &= ~V4L2_BUFFER_OUT_FLAGS; |
1400 | } | 1421 | } |
1401 | } | 1422 | } |
1402 | 1423 | ||
@@ -1405,7 +1426,7 @@ static void __fill_vb2_buffer(struct vb2_buffer *vb, const struct v4l2_buffer *b | |||
1405 | */ | 1426 | */ |
1406 | static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b) | 1427 | static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b) |
1407 | { | 1428 | { |
1408 | __fill_vb2_buffer(vb, b, vb->v4l2_planes); | 1429 | __fill_vb2_buffer(vb, b, vb->planes); |
1409 | return call_vb_qop(vb, buf_prepare, vb); | 1430 | return call_vb_qop(vb, buf_prepare, vb); |
1410 | } | 1431 | } |
1411 | 1432 | ||
@@ -1414,7 +1435,7 @@ static int __qbuf_mmap(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1414 | */ | 1435 | */ |
1415 | static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b) | 1436 | static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b) |
1416 | { | 1437 | { |
1417 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; | 1438 | struct vb2_plane planes[VIDEO_MAX_PLANES]; |
1418 | struct vb2_queue *q = vb->vb2_queue; | 1439 | struct vb2_queue *q = vb->vb2_queue; |
1419 | void *mem_priv; | 1440 | void *mem_priv; |
1420 | unsigned int plane; | 1441 | unsigned int plane; |
@@ -1429,9 +1450,9 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1429 | 1450 | ||
1430 | for (plane = 0; plane < vb->num_planes; ++plane) { | 1451 | for (plane = 0; plane < vb->num_planes; ++plane) { |
1431 | /* Skip the plane if already verified */ | 1452 | /* Skip the plane if already verified */ |
1432 | if (vb->v4l2_planes[plane].m.userptr && | 1453 | if (vb->planes[plane].m.userptr && |
1433 | vb->v4l2_planes[plane].m.userptr == planes[plane].m.userptr | 1454 | vb->planes[plane].m.userptr == planes[plane].m.userptr |
1434 | && vb->v4l2_planes[plane].length == planes[plane].length) | 1455 | && vb->planes[plane].length == planes[plane].length) |
1435 | continue; | 1456 | continue; |
1436 | 1457 | ||
1437 | dprintk(3, "userspace address for plane %d changed, " | 1458 | dprintk(3, "userspace address for plane %d changed, " |
@@ -1457,7 +1478,10 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1457 | } | 1478 | } |
1458 | 1479 | ||
1459 | vb->planes[plane].mem_priv = NULL; | 1480 | vb->planes[plane].mem_priv = NULL; |
1460 | memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane)); | 1481 | vb->planes[plane].bytesused = 0; |
1482 | vb->planes[plane].length = 0; | ||
1483 | vb->planes[plane].m.userptr = 0; | ||
1484 | vb->planes[plane].data_offset = 0; | ||
1461 | 1485 | ||
1462 | /* Acquire each plane's memory */ | 1486 | /* Acquire each plane's memory */ |
1463 | mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane], | 1487 | mem_priv = call_ptr_memop(vb, get_userptr, q->alloc_ctx[plane], |
@@ -1476,8 +1500,12 @@ static int __qbuf_userptr(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1476 | * Now that everything is in order, copy relevant information | 1500 | * Now that everything is in order, copy relevant information |
1477 | * provided by userspace. | 1501 | * provided by userspace. |
1478 | */ | 1502 | */ |
1479 | for (plane = 0; plane < vb->num_planes; ++plane) | 1503 | for (plane = 0; plane < vb->num_planes; ++plane) { |
1480 | vb->v4l2_planes[plane] = planes[plane]; | 1504 | vb->planes[plane].bytesused = planes[plane].bytesused; |
1505 | vb->planes[plane].length = planes[plane].length; | ||
1506 | vb->planes[plane].m.userptr = planes[plane].m.userptr; | ||
1507 | vb->planes[plane].data_offset = planes[plane].data_offset; | ||
1508 | } | ||
1481 | 1509 | ||
1482 | if (reacquired) { | 1510 | if (reacquired) { |
1483 | /* | 1511 | /* |
@@ -1504,10 +1532,11 @@ err: | |||
1504 | /* In case of errors, release planes that were already acquired */ | 1532 | /* In case of errors, release planes that were already acquired */ |
1505 | for (plane = 0; plane < vb->num_planes; ++plane) { | 1533 | for (plane = 0; plane < vb->num_planes; ++plane) { |
1506 | if (vb->planes[plane].mem_priv) | 1534 | if (vb->planes[plane].mem_priv) |
1507 | call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv); | 1535 | call_void_memop(vb, put_userptr, |
1536 | vb->planes[plane].mem_priv); | ||
1508 | vb->planes[plane].mem_priv = NULL; | 1537 | vb->planes[plane].mem_priv = NULL; |
1509 | vb->v4l2_planes[plane].m.userptr = 0; | 1538 | vb->planes[plane].m.userptr = 0; |
1510 | vb->v4l2_planes[plane].length = 0; | 1539 | vb->planes[plane].length = 0; |
1511 | } | 1540 | } |
1512 | 1541 | ||
1513 | return ret; | 1542 | return ret; |
@@ -1518,7 +1547,7 @@ err: | |||
1518 | */ | 1547 | */ |
1519 | static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) | 1548 | static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) |
1520 | { | 1549 | { |
1521 | struct v4l2_plane planes[VIDEO_MAX_PLANES]; | 1550 | struct vb2_plane planes[VIDEO_MAX_PLANES]; |
1522 | struct vb2_queue *q = vb->vb2_queue; | 1551 | struct vb2_queue *q = vb->vb2_queue; |
1523 | void *mem_priv; | 1552 | void *mem_priv; |
1524 | unsigned int plane; | 1553 | unsigned int plane; |
@@ -1554,7 +1583,7 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1554 | 1583 | ||
1555 | /* Skip the plane if already verified */ | 1584 | /* Skip the plane if already verified */ |
1556 | if (dbuf == vb->planes[plane].dbuf && | 1585 | if (dbuf == vb->planes[plane].dbuf && |
1557 | vb->v4l2_planes[plane].length == planes[plane].length) { | 1586 | vb->planes[plane].length == planes[plane].length) { |
1558 | dma_buf_put(dbuf); | 1587 | dma_buf_put(dbuf); |
1559 | continue; | 1588 | continue; |
1560 | } | 1589 | } |
@@ -1568,11 +1597,15 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1568 | 1597 | ||
1569 | /* Release previously acquired memory if present */ | 1598 | /* Release previously acquired memory if present */ |
1570 | __vb2_plane_dmabuf_put(vb, &vb->planes[plane]); | 1599 | __vb2_plane_dmabuf_put(vb, &vb->planes[plane]); |
1571 | memset(&vb->v4l2_planes[plane], 0, sizeof(struct v4l2_plane)); | 1600 | vb->planes[plane].bytesused = 0; |
1601 | vb->planes[plane].length = 0; | ||
1602 | vb->planes[plane].m.fd = 0; | ||
1603 | vb->planes[plane].data_offset = 0; | ||
1572 | 1604 | ||
1573 | /* Acquire each plane's memory */ | 1605 | /* Acquire each plane's memory */ |
1574 | mem_priv = call_ptr_memop(vb, attach_dmabuf, q->alloc_ctx[plane], | 1606 | mem_priv = call_ptr_memop(vb, attach_dmabuf, |
1575 | dbuf, planes[plane].length, dma_dir); | 1607 | q->alloc_ctx[plane], dbuf, planes[plane].length, |
1608 | dma_dir); | ||
1576 | if (IS_ERR(mem_priv)) { | 1609 | if (IS_ERR(mem_priv)) { |
1577 | dprintk(1, "failed to attach dmabuf\n"); | 1610 | dprintk(1, "failed to attach dmabuf\n"); |
1578 | ret = PTR_ERR(mem_priv); | 1611 | ret = PTR_ERR(mem_priv); |
@@ -1602,8 +1635,12 @@ static int __qbuf_dmabuf(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1602 | * Now that everything is in order, copy relevant information | 1635 | * Now that everything is in order, copy relevant information |
1603 | * provided by userspace. | 1636 | * provided by userspace. |
1604 | */ | 1637 | */ |
1605 | for (plane = 0; plane < vb->num_planes; ++plane) | 1638 | for (plane = 0; plane < vb->num_planes; ++plane) { |
1606 | vb->v4l2_planes[plane] = planes[plane]; | 1639 | vb->planes[plane].bytesused = planes[plane].bytesused; |
1640 | vb->planes[plane].length = planes[plane].length; | ||
1641 | vb->planes[plane].m.fd = planes[plane].m.fd; | ||
1642 | vb->planes[plane].data_offset = planes[plane].data_offset; | ||
1643 | } | ||
1607 | 1644 | ||
1608 | if (reacquired) { | 1645 | if (reacquired) { |
1609 | /* | 1646 | /* |
@@ -1654,6 +1691,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) | |||
1654 | 1691 | ||
1655 | static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b) | 1692 | static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b) |
1656 | { | 1693 | { |
1694 | struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); | ||
1657 | struct vb2_queue *q = vb->vb2_queue; | 1695 | struct vb2_queue *q = vb->vb2_queue; |
1658 | int ret; | 1696 | int ret; |
1659 | 1697 | ||
@@ -1682,9 +1720,9 @@ static int __buf_prepare(struct vb2_buffer *vb, const struct v4l2_buffer *b) | |||
1682 | } | 1720 | } |
1683 | 1721 | ||
1684 | vb->state = VB2_BUF_STATE_PREPARING; | 1722 | vb->state = VB2_BUF_STATE_PREPARING; |
1685 | vb->v4l2_buf.timestamp.tv_sec = 0; | 1723 | vbuf->timestamp.tv_sec = 0; |
1686 | vb->v4l2_buf.timestamp.tv_usec = 0; | 1724 | vbuf->timestamp.tv_usec = 0; |
1687 | vb->v4l2_buf.sequence = 0; | 1725 | vbuf->sequence = 0; |
1688 | 1726 | ||
1689 | switch (q->memory) { | 1727 | switch (q->memory) { |
1690 | case V4L2_MEMORY_MMAP: | 1728 | case V4L2_MEMORY_MMAP: |
@@ -1776,7 +1814,7 @@ int vb2_prepare_buf(struct vb2_queue *q, struct v4l2_buffer *b) | |||
1776 | /* Fill buffer information for the userspace */ | 1814 | /* Fill buffer information for the userspace */ |
1777 | __fill_v4l2_buffer(vb, b); | 1815 | __fill_v4l2_buffer(vb, b); |
1778 | 1816 | ||
1779 | dprintk(1, "prepare of buffer %d succeeded\n", vb->v4l2_buf.index); | 1817 | dprintk(1, "prepare of buffer %d succeeded\n", vb->index); |
1780 | } | 1818 | } |
1781 | return ret; | 1819 | return ret; |
1782 | } | 1820 | } |
@@ -1818,7 +1856,7 @@ static int vb2_start_streaming(struct vb2_queue *q) | |||
1818 | /* | 1856 | /* |
1819 | * If you see this warning, then the driver isn't cleaning up properly | 1857 | * If you see this warning, then the driver isn't cleaning up properly |
1820 | * after a failed start_streaming(). See the start_streaming() | 1858 | * after a failed start_streaming(). See the start_streaming() |
1821 | * documentation in videobuf2-v4l2.h for more information how buffers | 1859 | * documentation in videobuf2-core.h for more information how buffers |
1822 | * should be returned to vb2 in start_streaming(). | 1860 | * should be returned to vb2 in start_streaming(). |
1823 | */ | 1861 | */ |
1824 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { | 1862 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { |
@@ -1849,11 +1887,13 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) | |||
1849 | { | 1887 | { |
1850 | int ret = vb2_queue_or_prepare_buf(q, b, "qbuf"); | 1888 | int ret = vb2_queue_or_prepare_buf(q, b, "qbuf"); |
1851 | struct vb2_buffer *vb; | 1889 | struct vb2_buffer *vb; |
1890 | struct vb2_v4l2_buffer *vbuf; | ||
1852 | 1891 | ||
1853 | if (ret) | 1892 | if (ret) |
1854 | return ret; | 1893 | return ret; |
1855 | 1894 | ||
1856 | vb = q->bufs[b->index]; | 1895 | vb = q->bufs[b->index]; |
1896 | vbuf = to_vb2_v4l2_buffer(vb); | ||
1857 | 1897 | ||
1858 | switch (vb->state) { | 1898 | switch (vb->state) { |
1859 | case VB2_BUF_STATE_DEQUEUED: | 1899 | case VB2_BUF_STATE_DEQUEUED: |
@@ -1886,10 +1926,10 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) | |||
1886 | */ | 1926 | */ |
1887 | if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) == | 1927 | if ((q->timestamp_flags & V4L2_BUF_FLAG_TIMESTAMP_MASK) == |
1888 | V4L2_BUF_FLAG_TIMESTAMP_COPY) | 1928 | V4L2_BUF_FLAG_TIMESTAMP_COPY) |
1889 | vb->v4l2_buf.timestamp = b->timestamp; | 1929 | vbuf->timestamp = b->timestamp; |
1890 | vb->v4l2_buf.flags |= b->flags & V4L2_BUF_FLAG_TIMECODE; | 1930 | vbuf->flags |= b->flags & V4L2_BUF_FLAG_TIMECODE; |
1891 | if (b->flags & V4L2_BUF_FLAG_TIMECODE) | 1931 | if (b->flags & V4L2_BUF_FLAG_TIMECODE) |
1892 | vb->v4l2_buf.timecode = b->timecode; | 1932 | vbuf->timecode = b->timecode; |
1893 | } | 1933 | } |
1894 | 1934 | ||
1895 | trace_vb2_qbuf(q, vb); | 1935 | trace_vb2_qbuf(q, vb); |
@@ -1917,7 +1957,7 @@ static int vb2_internal_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) | |||
1917 | return ret; | 1957 | return ret; |
1918 | } | 1958 | } |
1919 | 1959 | ||
1920 | dprintk(1, "qbuf of buffer %d succeeded\n", vb->v4l2_buf.index); | 1960 | dprintk(1, "qbuf of buffer %d succeeded\n", vb->index); |
1921 | return 0; | 1961 | return 0; |
1922 | } | 1962 | } |
1923 | 1963 | ||
@@ -2107,9 +2147,11 @@ static void __vb2_dqbuf(struct vb2_buffer *vb) | |||
2107 | } | 2147 | } |
2108 | } | 2148 | } |
2109 | 2149 | ||
2110 | static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool nonblocking) | 2150 | static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, |
2151 | bool nonblocking) | ||
2111 | { | 2152 | { |
2112 | struct vb2_buffer *vb = NULL; | 2153 | struct vb2_buffer *vb = NULL; |
2154 | struct vb2_v4l2_buffer *vbuf = NULL; | ||
2113 | int ret; | 2155 | int ret; |
2114 | 2156 | ||
2115 | if (b->type != q->type) { | 2157 | if (b->type != q->type) { |
@@ -2142,14 +2184,15 @@ static int vb2_internal_dqbuf(struct vb2_queue *q, struct v4l2_buffer *b, bool n | |||
2142 | 2184 | ||
2143 | trace_vb2_dqbuf(q, vb); | 2185 | trace_vb2_dqbuf(q, vb); |
2144 | 2186 | ||
2187 | vbuf = to_vb2_v4l2_buffer(vb); | ||
2145 | if (!V4L2_TYPE_IS_OUTPUT(q->type) && | 2188 | if (!V4L2_TYPE_IS_OUTPUT(q->type) && |
2146 | vb->v4l2_buf.flags & V4L2_BUF_FLAG_LAST) | 2189 | vbuf->flags & V4L2_BUF_FLAG_LAST) |
2147 | q->last_buffer_dequeued = true; | 2190 | q->last_buffer_dequeued = true; |
2148 | /* go back to dequeued state */ | 2191 | /* go back to dequeued state */ |
2149 | __vb2_dqbuf(vb); | 2192 | __vb2_dqbuf(vb); |
2150 | 2193 | ||
2151 | dprintk(1, "dqbuf of buffer %d, with state %d\n", | 2194 | dprintk(1, "dqbuf of buffer %d, with state %d\n", |
2152 | vb->v4l2_buf.index, vb->state); | 2195 | vb->index, vb->state); |
2153 | 2196 | ||
2154 | return 0; | 2197 | return 0; |
2155 | } | 2198 | } |
@@ -2205,7 +2248,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) | |||
2205 | /* | 2248 | /* |
2206 | * If you see this warning, then the driver isn't cleaning up properly | 2249 | * If you see this warning, then the driver isn't cleaning up properly |
2207 | * in stop_streaming(). See the stop_streaming() documentation in | 2250 | * in stop_streaming(). See the stop_streaming() documentation in |
2208 | * videobuf2-v4l2.h for more information how buffers should be returned | 2251 | * videobuf2-core.h for more information how buffers should be returned |
2209 | * to vb2 in stop_streaming(). | 2252 | * to vb2 in stop_streaming(). |
2210 | */ | 2253 | */ |
2211 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { | 2254 | if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { |
@@ -2407,7 +2450,7 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off, | |||
2407 | vb = q->bufs[buffer]; | 2450 | vb = q->bufs[buffer]; |
2408 | 2451 | ||
2409 | for (plane = 0; plane < vb->num_planes; ++plane) { | 2452 | for (plane = 0; plane < vb->num_planes; ++plane) { |
2410 | if (vb->v4l2_planes[plane].m.mem_offset == off) { | 2453 | if (vb->planes[plane].m.offset == off) { |
2411 | *_buffer = buffer; | 2454 | *_buffer = buffer; |
2412 | *_plane = plane; | 2455 | *_plane = plane; |
2413 | return 0; | 2456 | return 0; |
@@ -2565,7 +2608,7 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) | |||
2565 | * The buffer length was page_aligned at __vb2_buf_mem_alloc(), | 2608 | * The buffer length was page_aligned at __vb2_buf_mem_alloc(), |
2566 | * so, we need to do the same here. | 2609 | * so, we need to do the same here. |
2567 | */ | 2610 | */ |
2568 | length = PAGE_ALIGN(vb->v4l2_planes[plane].length); | 2611 | length = PAGE_ALIGN(vb->planes[plane].length); |
2569 | if (length < (vma->vm_end - vma->vm_start)) { | 2612 | if (length < (vma->vm_end - vma->vm_start)) { |
2570 | dprintk(1, | 2613 | dprintk(1, |
2571 | "MMAP invalid, as it would overflow buffer length\n"); | 2614 | "MMAP invalid, as it would overflow buffer length\n"); |
@@ -2739,7 +2782,7 @@ EXPORT_SYMBOL_GPL(vb2_poll); | |||
2739 | * responsible of clearing it's content and setting initial values for some | 2782 | * responsible of clearing it's content and setting initial values for some |
2740 | * required entries before calling this function. | 2783 | * required entries before calling this function. |
2741 | * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer | 2784 | * q->ops, q->mem_ops, q->type and q->io_modes are mandatory. Please refer |
2742 | * to the struct vb2_queue description in include/media/videobuf2-v4l2.h | 2785 | * to the struct vb2_queue description in include/media/videobuf2-core.h |
2743 | * for more information. | 2786 | * for more information. |
2744 | */ | 2787 | */ |
2745 | int vb2_queue_init(struct vb2_queue *q) | 2788 | int vb2_queue_init(struct vb2_queue *q) |
@@ -2770,7 +2813,7 @@ int vb2_queue_init(struct vb2_queue *q) | |||
2770 | init_waitqueue_head(&q->done_wq); | 2813 | init_waitqueue_head(&q->done_wq); |
2771 | 2814 | ||
2772 | if (q->buf_struct_size == 0) | 2815 | if (q->buf_struct_size == 0) |
2773 | q->buf_struct_size = sizeof(struct vb2_buffer); | 2816 | q->buf_struct_size = sizeof(struct vb2_v4l2_buffer); |
2774 | 2817 | ||
2775 | return 0; | 2818 | return 0; |
2776 | } | 2819 | } |