| .. | .. |
|---|
| 34 | 34 | static int debug; |
|---|
| 35 | 35 | module_param(debug, int, 0644); |
|---|
| 36 | 36 | |
|---|
| 37 | | -#define dprintk(level, fmt, arg...) \ |
|---|
| 38 | | - do { \ |
|---|
| 39 | | - if (debug >= level) \ |
|---|
| 40 | | - pr_info("%s: " fmt, __func__, ## arg); \ |
|---|
| 37 | +#define dprintk(q, level, fmt, arg...) \ |
|---|
| 38 | + do { \ |
|---|
| 39 | + if (debug >= level) \ |
|---|
| 40 | + pr_info("[%s] %s: " fmt, (q)->name, __func__, \ |
|---|
| 41 | + ## arg); \ |
|---|
| 41 | 42 | } while (0) |
|---|
| 42 | 43 | |
|---|
| 43 | 44 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
|---|
| .. | .. |
|---|
| 51 | 52 | */ |
|---|
| 52 | 53 | |
|---|
| 53 | 54 | #define log_memop(vb, op) \ |
|---|
| 54 | | - dprintk(2, "call_memop(%p, %d, %s)%s\n", \ |
|---|
| 55 | | - (vb)->vb2_queue, (vb)->index, #op, \ |
|---|
| 55 | + dprintk((vb)->vb2_queue, 2, "call_memop(%d, %s)%s\n", \ |
|---|
| 56 | + (vb)->index, #op, \ |
|---|
| 56 | 57 | (vb)->vb2_queue->mem_ops->op ? "" : " (nop)") |
|---|
| 57 | 58 | |
|---|
| 58 | 59 | #define call_memop(vb, op, args...) \ |
|---|
| .. | .. |
|---|
| 90 | 91 | }) |
|---|
| 91 | 92 | |
|---|
| 92 | 93 | #define log_qop(q, op) \ |
|---|
| 93 | | - dprintk(2, "call_qop(%p, %s)%s\n", q, #op, \ |
|---|
| 94 | + dprintk(q, 2, "call_qop(%s)%s\n", #op, \ |
|---|
| 94 | 95 | (q)->ops->op ? "" : " (nop)") |
|---|
| 95 | 96 | |
|---|
| 96 | 97 | #define call_qop(q, op, args...) \ |
|---|
| .. | .. |
|---|
| 113 | 114 | }) |
|---|
| 114 | 115 | |
|---|
| 115 | 116 | #define log_vb_qop(vb, op, args...) \ |
|---|
| 116 | | - dprintk(2, "call_vb_qop(%p, %d, %s)%s\n", \ |
|---|
| 117 | | - (vb)->vb2_queue, (vb)->index, #op, \ |
|---|
| 117 | + dprintk((vb)->vb2_queue, 2, "call_vb_qop(%d, %s)%s\n", \ |
|---|
| 118 | + (vb)->index, #op, \ |
|---|
| 118 | 119 | (vb)->vb2_queue->ops->op ? "" : " (nop)") |
|---|
| 119 | 120 | |
|---|
| 120 | 121 | #define call_vb_qop(vb, op, args...) \ |
|---|
| .. | .. |
|---|
| 190 | 191 | static void __vb2_queue_cancel(struct vb2_queue *q); |
|---|
| 191 | 192 | static void __enqueue_in_driver(struct vb2_buffer *vb); |
|---|
| 192 | 193 | |
|---|
| 194 | +static const char *vb2_state_name(enum vb2_buffer_state s) |
|---|
| 195 | +{ |
|---|
| 196 | + static const char * const state_names[] = { |
|---|
| 197 | + [VB2_BUF_STATE_DEQUEUED] = "dequeued", |
|---|
| 198 | + [VB2_BUF_STATE_IN_REQUEST] = "in request", |
|---|
| 199 | + [VB2_BUF_STATE_PREPARING] = "preparing", |
|---|
| 200 | + [VB2_BUF_STATE_QUEUED] = "queued", |
|---|
| 201 | + [VB2_BUF_STATE_ACTIVE] = "active", |
|---|
| 202 | + [VB2_BUF_STATE_DONE] = "done", |
|---|
| 203 | + [VB2_BUF_STATE_ERROR] = "error", |
|---|
| 204 | + }; |
|---|
| 205 | + |
|---|
| 206 | + if ((unsigned int)(s) < ARRAY_SIZE(state_names)) |
|---|
| 207 | + return state_names[s]; |
|---|
| 208 | + return "unknown"; |
|---|
| 209 | +} |
|---|
| 210 | + |
|---|
| 193 | 211 | /* |
|---|
| 194 | 212 | * __vb2_buf_mem_alloc() - allocate video memory for the given buffer |
|---|
| 195 | 213 | */ |
|---|
| .. | .. |
|---|
| 205 | 223 | * NOTE: mmapped areas should be page aligned |
|---|
| 206 | 224 | */ |
|---|
| 207 | 225 | for (plane = 0; plane < vb->num_planes; ++plane) { |
|---|
| 226 | + /* Memops alloc requires size to be page aligned. */ |
|---|
| 208 | 227 | unsigned long size = PAGE_ALIGN(vb->planes[plane].length); |
|---|
| 209 | 228 | |
|---|
| 210 | 229 | /* Did it wrap around? */ |
|---|
| .. | .. |
|---|
| 245 | 264 | for (plane = 0; plane < vb->num_planes; ++plane) { |
|---|
| 246 | 265 | call_void_memop(vb, put, vb->planes[plane].mem_priv); |
|---|
| 247 | 266 | vb->planes[plane].mem_priv = NULL; |
|---|
| 248 | | - dprintk(3, "freed plane %d of buffer %d\n", plane, vb->index); |
|---|
| 267 | + dprintk(vb->vb2_queue, 3, "freed plane %d of buffer %d\n", |
|---|
| 268 | + plane, vb->index); |
|---|
| 249 | 269 | } |
|---|
| 250 | 270 | } |
|---|
| 251 | 271 | |
|---|
| .. | .. |
|---|
| 296 | 316 | } |
|---|
| 297 | 317 | |
|---|
| 298 | 318 | /* |
|---|
| 319 | + * __vb2_buf_mem_prepare() - call ->prepare() on buffer's private memory |
|---|
| 320 | + * to sync caches |
|---|
| 321 | + */ |
|---|
| 322 | +static void __vb2_buf_mem_prepare(struct vb2_buffer *vb) |
|---|
| 323 | +{ |
|---|
| 324 | + unsigned int plane; |
|---|
| 325 | + |
|---|
| 326 | + if (vb->synced) |
|---|
| 327 | + return; |
|---|
| 328 | + |
|---|
| 329 | + if (vb->need_cache_sync_on_prepare) { |
|---|
| 330 | + for (plane = 0; plane < vb->num_planes; ++plane) |
|---|
| 331 | + call_void_memop(vb, prepare, |
|---|
| 332 | + vb->planes[plane].mem_priv); |
|---|
| 333 | + } |
|---|
| 334 | + vb->synced = 1; |
|---|
| 335 | +} |
|---|
| 336 | + |
|---|
| 337 | +/* |
|---|
| 338 | + * __vb2_buf_mem_finish() - call ->finish on buffer's private memory |
|---|
| 339 | + * to sync caches |
|---|
| 340 | + */ |
|---|
| 341 | +static void __vb2_buf_mem_finish(struct vb2_buffer *vb) |
|---|
| 342 | +{ |
|---|
| 343 | + unsigned int plane; |
|---|
| 344 | + |
|---|
| 345 | + if (!vb->synced) |
|---|
| 346 | + return; |
|---|
| 347 | + |
|---|
| 348 | + if (vb->need_cache_sync_on_finish) { |
|---|
| 349 | + for (plane = 0; plane < vb->num_planes; ++plane) |
|---|
| 350 | + call_void_memop(vb, finish, |
|---|
| 351 | + vb->planes[plane].mem_priv); |
|---|
| 352 | + } |
|---|
| 353 | + vb->synced = 0; |
|---|
| 354 | +} |
|---|
| 355 | + |
|---|
| 356 | +/* |
|---|
| 299 | 357 | * __setup_offsets() - setup unique offsets ("cookies") for every plane in |
|---|
| 300 | 358 | * the buffer. |
|---|
| 301 | 359 | */ |
|---|
| .. | .. |
|---|
| 315 | 373 | for (plane = 0; plane < vb->num_planes; ++plane) { |
|---|
| 316 | 374 | vb->planes[plane].m.offset = off; |
|---|
| 317 | 375 | |
|---|
| 318 | | - dprintk(3, "buffer %d, plane %d offset 0x%08lx\n", |
|---|
| 376 | + dprintk(q, 3, "buffer %d, plane %d offset 0x%08lx\n", |
|---|
| 319 | 377 | vb->index, plane, off); |
|---|
| 320 | 378 | |
|---|
| 321 | 379 | off += vb->planes[plane].length; |
|---|
| .. | .. |
|---|
| 346 | 404 | /* Allocate videobuf buffer structures */ |
|---|
| 347 | 405 | vb = kzalloc(q->buf_struct_size, GFP_KERNEL); |
|---|
| 348 | 406 | if (!vb) { |
|---|
| 349 | | - dprintk(1, "memory alloc for buffer struct failed\n"); |
|---|
| 407 | + dprintk(q, 1, "memory alloc for buffer struct failed\n"); |
|---|
| 350 | 408 | break; |
|---|
| 351 | 409 | } |
|---|
| 352 | 410 | |
|---|
| .. | .. |
|---|
| 356 | 414 | vb->index = q->num_buffers + buffer; |
|---|
| 357 | 415 | vb->type = q->type; |
|---|
| 358 | 416 | vb->memory = memory; |
|---|
| 417 | + /* |
|---|
| 418 | + * We need to set these flags here so that the videobuf2 core |
|---|
| 419 | + * will call ->prepare()/->finish() cache sync/flush on vb2 |
|---|
| 420 | + * buffers when appropriate. However, we can avoid explicit |
|---|
| 421 | + * ->prepare() and ->finish() cache sync for DMABUF buffers, |
|---|
| 422 | + * because DMA exporter takes care of it. |
|---|
| 423 | + */ |
|---|
| 424 | + if (q->memory != VB2_MEMORY_DMABUF) { |
|---|
| 425 | + vb->need_cache_sync_on_prepare = 1; |
|---|
| 426 | + vb->need_cache_sync_on_finish = 1; |
|---|
| 427 | + } |
|---|
| 359 | 428 | for (plane = 0; plane < num_planes; ++plane) { |
|---|
| 360 | 429 | vb->planes[plane].length = plane_sizes[plane]; |
|---|
| 361 | 430 | vb->planes[plane].min_length = plane_sizes[plane]; |
|---|
| 362 | 431 | } |
|---|
| 432 | + call_void_bufop(q, init_buffer, vb); |
|---|
| 433 | + |
|---|
| 363 | 434 | q->bufs[vb->index] = vb; |
|---|
| 364 | 435 | |
|---|
| 365 | 436 | /* Allocate video buffer memory for the MMAP type */ |
|---|
| 366 | 437 | if (memory == VB2_MEMORY_MMAP) { |
|---|
| 367 | 438 | ret = __vb2_buf_mem_alloc(vb); |
|---|
| 368 | 439 | if (ret) { |
|---|
| 369 | | - dprintk(1, "failed allocating memory for buffer %d\n", |
|---|
| 440 | + dprintk(q, 1, "failed allocating memory for buffer %d\n", |
|---|
| 370 | 441 | buffer); |
|---|
| 371 | 442 | q->bufs[vb->index] = NULL; |
|---|
| 372 | 443 | kfree(vb); |
|---|
| .. | .. |
|---|
| 380 | 451 | */ |
|---|
| 381 | 452 | ret = call_vb_qop(vb, buf_init, vb); |
|---|
| 382 | 453 | if (ret) { |
|---|
| 383 | | - dprintk(1, "buffer %d %p initialization failed\n", |
|---|
| 454 | + dprintk(q, 1, "buffer %d %p initialization failed\n", |
|---|
| 384 | 455 | buffer, vb); |
|---|
| 385 | 456 | __vb2_buf_mem_free(vb); |
|---|
| 386 | 457 | q->bufs[vb->index] = NULL; |
|---|
| .. | .. |
|---|
| 390 | 461 | } |
|---|
| 391 | 462 | } |
|---|
| 392 | 463 | |
|---|
| 393 | | - dprintk(1, "allocated %d buffers, %d plane(s) each\n", |
|---|
| 394 | | - buffer, num_planes); |
|---|
| 464 | + dprintk(q, 3, "allocated %d buffers, %d plane(s) each\n", |
|---|
| 465 | + buffer, num_planes); |
|---|
| 395 | 466 | |
|---|
| 396 | 467 | return buffer; |
|---|
| 397 | 468 | } |
|---|
| .. | .. |
|---|
| 442 | 513 | if (q->bufs[buffer] == NULL) |
|---|
| 443 | 514 | continue; |
|---|
| 444 | 515 | if (q->bufs[buffer]->state == VB2_BUF_STATE_PREPARING) { |
|---|
| 445 | | - dprintk(1, "preparing buffers, cannot free\n"); |
|---|
| 516 | + dprintk(q, 1, "preparing buffers, cannot free\n"); |
|---|
| 446 | 517 | return -EAGAIN; |
|---|
| 447 | 518 | } |
|---|
| 448 | 519 | } |
|---|
| .. | .. |
|---|
| 501 | 572 | pr_info(" buf_init: %u buf_cleanup: %u buf_prepare: %u buf_finish: %u\n", |
|---|
| 502 | 573 | vb->cnt_buf_init, vb->cnt_buf_cleanup, |
|---|
| 503 | 574 | vb->cnt_buf_prepare, vb->cnt_buf_finish); |
|---|
| 504 | | - pr_info(" buf_queue: %u buf_done: %u\n", |
|---|
| 505 | | - vb->cnt_buf_queue, vb->cnt_buf_done); |
|---|
| 575 | + pr_info(" buf_out_validate: %u buf_queue: %u buf_done: %u buf_request_complete: %u\n", |
|---|
| 576 | + vb->cnt_buf_out_validate, vb->cnt_buf_queue, |
|---|
| 577 | + vb->cnt_buf_done, vb->cnt_buf_request_complete); |
|---|
| 506 | 578 | pr_info(" alloc: %u put: %u prepare: %u finish: %u mmap: %u\n", |
|---|
| 507 | 579 | vb->cnt_mem_alloc, vb->cnt_mem_put, |
|---|
| 508 | 580 | vb->cnt_mem_prepare, vb->cnt_mem_finish, |
|---|
| .. | .. |
|---|
| 619 | 691 | { |
|---|
| 620 | 692 | if (memory != VB2_MEMORY_MMAP && memory != VB2_MEMORY_USERPTR && |
|---|
| 621 | 693 | memory != VB2_MEMORY_DMABUF) { |
|---|
| 622 | | - dprintk(1, "unsupported memory type\n"); |
|---|
| 694 | + dprintk(q, 1, "unsupported memory type\n"); |
|---|
| 623 | 695 | return -EINVAL; |
|---|
| 624 | 696 | } |
|---|
| 625 | 697 | |
|---|
| 626 | 698 | if (type != q->type) { |
|---|
| 627 | | - dprintk(1, "requested type is incorrect\n"); |
|---|
| 699 | + dprintk(q, 1, "requested type is incorrect\n"); |
|---|
| 628 | 700 | return -EINVAL; |
|---|
| 629 | 701 | } |
|---|
| 630 | 702 | |
|---|
| .. | .. |
|---|
| 633 | 705 | * are available. |
|---|
| 634 | 706 | */ |
|---|
| 635 | 707 | if (memory == VB2_MEMORY_MMAP && __verify_mmap_ops(q)) { |
|---|
| 636 | | - dprintk(1, "MMAP for current setup unsupported\n"); |
|---|
| 708 | + dprintk(q, 1, "MMAP for current setup unsupported\n"); |
|---|
| 637 | 709 | return -EINVAL; |
|---|
| 638 | 710 | } |
|---|
| 639 | 711 | |
|---|
| 640 | 712 | if (memory == VB2_MEMORY_USERPTR && __verify_userptr_ops(q)) { |
|---|
| 641 | | - dprintk(1, "USERPTR for current setup unsupported\n"); |
|---|
| 713 | + dprintk(q, 1, "USERPTR for current setup unsupported\n"); |
|---|
| 642 | 714 | return -EINVAL; |
|---|
| 643 | 715 | } |
|---|
| 644 | 716 | |
|---|
| 645 | 717 | if (memory == VB2_MEMORY_DMABUF && __verify_dmabuf_ops(q)) { |
|---|
| 646 | | - dprintk(1, "DMABUF for current setup unsupported\n"); |
|---|
| 718 | + dprintk(q, 1, "DMABUF for current setup unsupported\n"); |
|---|
| 647 | 719 | return -EINVAL; |
|---|
| 648 | 720 | } |
|---|
| 649 | 721 | |
|---|
| .. | .. |
|---|
| 653 | 725 | * do the memory and type validation. |
|---|
| 654 | 726 | */ |
|---|
| 655 | 727 | if (vb2_fileio_is_active(q)) { |
|---|
| 656 | | - dprintk(1, "file io in progress\n"); |
|---|
| 728 | + dprintk(q, 1, "file io in progress\n"); |
|---|
| 657 | 729 | return -EBUSY; |
|---|
| 658 | 730 | } |
|---|
| 659 | 731 | return 0; |
|---|
| .. | .. |
|---|
| 661 | 733 | EXPORT_SYMBOL(vb2_verify_memory_type); |
|---|
| 662 | 734 | |
|---|
| 663 | 735 | int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, |
|---|
| 664 | | - unsigned int *count) |
|---|
| 736 | + unsigned int *count) |
|---|
| 665 | 737 | { |
|---|
| 666 | 738 | unsigned int num_buffers, allocated_buffers, num_planes = 0; |
|---|
| 667 | 739 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; |
|---|
| 740 | + unsigned int i; |
|---|
| 668 | 741 | int ret; |
|---|
| 669 | 742 | |
|---|
| 670 | 743 | if (q->streaming) { |
|---|
| 671 | | - dprintk(1, "streaming active\n"); |
|---|
| 744 | + dprintk(q, 1, "streaming active\n"); |
|---|
| 672 | 745 | return -EBUSY; |
|---|
| 673 | 746 | } |
|---|
| 674 | 747 | |
|---|
| 675 | 748 | if (q->waiting_in_dqbuf && *count) { |
|---|
| 676 | | - dprintk(1, "another dup()ped fd is waiting for a buffer\n"); |
|---|
| 749 | + dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); |
|---|
| 677 | 750 | return -EBUSY; |
|---|
| 678 | 751 | } |
|---|
| 679 | 752 | |
|---|
| .. | .. |
|---|
| 684 | 757 | * are not in use and can be freed. |
|---|
| 685 | 758 | */ |
|---|
| 686 | 759 | mutex_lock(&q->mmap_lock); |
|---|
| 687 | | - if (q->memory == VB2_MEMORY_MMAP && __buffers_in_use(q)) { |
|---|
| 688 | | - mutex_unlock(&q->mmap_lock); |
|---|
| 689 | | - dprintk(1, "memory in use, cannot free\n"); |
|---|
| 690 | | - return -EBUSY; |
|---|
| 691 | | - } |
|---|
| 760 | + if (debug && q->memory == VB2_MEMORY_MMAP && |
|---|
| 761 | + __buffers_in_use(q)) |
|---|
| 762 | + dprintk(q, 1, "memory in use, orphaning buffers\n"); |
|---|
| 692 | 763 | |
|---|
| 693 | 764 | /* |
|---|
| 694 | | - * Call queue_cancel to clean up any buffers in the PREPARED or |
|---|
| 765 | + * Call queue_cancel to clean up any buffers in the |
|---|
| 695 | 766 | * QUEUED state which is possible if buffers were prepared or |
|---|
| 696 | 767 | * queued without ever calling STREAMON. |
|---|
| 697 | 768 | */ |
|---|
| .. | .. |
|---|
| 716 | 787 | num_buffers = max_t(unsigned int, *count, q->min_buffers_needed); |
|---|
| 717 | 788 | num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME); |
|---|
| 718 | 789 | memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); |
|---|
| 790 | + /* |
|---|
| 791 | + * Set this now to ensure that drivers see the correct q->memory value |
|---|
| 792 | + * in the queue_setup op. |
|---|
| 793 | + */ |
|---|
| 794 | + mutex_lock(&q->mmap_lock); |
|---|
| 719 | 795 | q->memory = memory; |
|---|
| 796 | + mutex_unlock(&q->mmap_lock); |
|---|
| 720 | 797 | |
|---|
| 721 | 798 | /* |
|---|
| 722 | 799 | * Ask the driver how many buffers and planes per buffer it requires. |
|---|
| .. | .. |
|---|
| 725 | 802 | ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, |
|---|
| 726 | 803 | plane_sizes, q->alloc_devs); |
|---|
| 727 | 804 | if (ret) |
|---|
| 728 | | - return ret; |
|---|
| 805 | + goto error; |
|---|
| 806 | + |
|---|
| 807 | + /* Check that driver has set sane values */ |
|---|
| 808 | + if (WARN_ON(!num_planes)) { |
|---|
| 809 | + ret = -EINVAL; |
|---|
| 810 | + goto error; |
|---|
| 811 | + } |
|---|
| 812 | + |
|---|
| 813 | + for (i = 0; i < num_planes; i++) |
|---|
| 814 | + if (WARN_ON(!plane_sizes[i])) { |
|---|
| 815 | + ret = -EINVAL; |
|---|
| 816 | + goto error; |
|---|
| 817 | + } |
|---|
| 729 | 818 | |
|---|
| 730 | 819 | /* Finally, allocate buffers and video memory */ |
|---|
| 731 | 820 | allocated_buffers = |
|---|
| 732 | 821 | __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes); |
|---|
| 733 | 822 | if (allocated_buffers == 0) { |
|---|
| 734 | | - dprintk(1, "memory allocation failed\n"); |
|---|
| 735 | | - return -ENOMEM; |
|---|
| 823 | + dprintk(q, 1, "memory allocation failed\n"); |
|---|
| 824 | + ret = -ENOMEM; |
|---|
| 825 | + goto error; |
|---|
| 736 | 826 | } |
|---|
| 737 | 827 | |
|---|
| 738 | 828 | /* |
|---|
| .. | .. |
|---|
| 773 | 863 | if (ret < 0) { |
|---|
| 774 | 864 | /* |
|---|
| 775 | 865 | * Note: __vb2_queue_free() will subtract 'allocated_buffers' |
|---|
| 776 | | - * from q->num_buffers. |
|---|
| 866 | + * from q->num_buffers and it will reset q->memory to |
|---|
| 867 | + * VB2_MEMORY_UNKNOWN. |
|---|
| 777 | 868 | */ |
|---|
| 778 | 869 | __vb2_queue_free(q, allocated_buffers); |
|---|
| 779 | 870 | mutex_unlock(&q->mmap_lock); |
|---|
| .. | .. |
|---|
| 789 | 880 | q->waiting_for_buffers = !q->is_output; |
|---|
| 790 | 881 | |
|---|
| 791 | 882 | return 0; |
|---|
| 883 | + |
|---|
| 884 | +error: |
|---|
| 885 | + mutex_lock(&q->mmap_lock); |
|---|
| 886 | + q->memory = VB2_MEMORY_UNKNOWN; |
|---|
| 887 | + mutex_unlock(&q->mmap_lock); |
|---|
| 888 | + return ret; |
|---|
| 792 | 889 | } |
|---|
| 793 | 890 | EXPORT_SYMBOL_GPL(vb2_core_reqbufs); |
|---|
| 794 | 891 | |
|---|
| 795 | 892 | int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, |
|---|
| 796 | | - unsigned int *count, unsigned requested_planes, |
|---|
| 797 | | - const unsigned requested_sizes[]) |
|---|
| 893 | + unsigned int *count, |
|---|
| 894 | + unsigned int requested_planes, |
|---|
| 895 | + const unsigned int requested_sizes[]) |
|---|
| 798 | 896 | { |
|---|
| 799 | 897 | unsigned int num_planes = 0, num_buffers, allocated_buffers; |
|---|
| 800 | 898 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; |
|---|
| 899 | + bool no_previous_buffers = !q->num_buffers; |
|---|
| 801 | 900 | int ret; |
|---|
| 802 | 901 | |
|---|
| 803 | 902 | if (q->num_buffers == VB2_MAX_FRAME) { |
|---|
| 804 | | - dprintk(1, "maximum number of buffers already allocated\n"); |
|---|
| 903 | + dprintk(q, 1, "maximum number of buffers already allocated\n"); |
|---|
| 805 | 904 | return -ENOBUFS; |
|---|
| 806 | 905 | } |
|---|
| 807 | 906 | |
|---|
| 808 | | - if (!q->num_buffers) { |
|---|
| 907 | + if (no_previous_buffers) { |
|---|
| 809 | 908 | if (q->waiting_in_dqbuf && *count) { |
|---|
| 810 | | - dprintk(1, "another dup()ped fd is waiting for a buffer\n"); |
|---|
| 909 | + dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); |
|---|
| 811 | 910 | return -EBUSY; |
|---|
| 812 | 911 | } |
|---|
| 813 | 912 | memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); |
|---|
| 913 | + /* |
|---|
| 914 | + * Set this now to ensure that drivers see the correct q->memory |
|---|
| 915 | + * value in the queue_setup op. |
|---|
| 916 | + */ |
|---|
| 917 | + mutex_lock(&q->mmap_lock); |
|---|
| 814 | 918 | q->memory = memory; |
|---|
| 919 | + mutex_unlock(&q->mmap_lock); |
|---|
| 815 | 920 | q->waiting_for_buffers = !q->is_output; |
|---|
| 816 | | - } else if (q->memory != memory) { |
|---|
| 817 | | - dprintk(1, "memory model mismatch\n"); |
|---|
| 818 | | - return -EINVAL; |
|---|
| 921 | + } else { |
|---|
| 922 | + if (q->memory != memory) { |
|---|
| 923 | + dprintk(q, 1, "memory model mismatch\n"); |
|---|
| 924 | + return -EINVAL; |
|---|
| 925 | + } |
|---|
| 819 | 926 | } |
|---|
| 820 | 927 | |
|---|
| 821 | 928 | num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers); |
|---|
| .. | .. |
|---|
| 832 | 939 | ret = call_qop(q, queue_setup, q, &num_buffers, |
|---|
| 833 | 940 | &num_planes, plane_sizes, q->alloc_devs); |
|---|
| 834 | 941 | if (ret) |
|---|
| 835 | | - return ret; |
|---|
| 942 | + goto error; |
|---|
| 836 | 943 | |
|---|
| 837 | 944 | /* Finally, allocate buffers and video memory */ |
|---|
| 838 | 945 | allocated_buffers = __vb2_queue_alloc(q, memory, num_buffers, |
|---|
| 839 | 946 | num_planes, plane_sizes); |
|---|
| 840 | 947 | if (allocated_buffers == 0) { |
|---|
| 841 | | - dprintk(1, "memory allocation failed\n"); |
|---|
| 842 | | - return -ENOMEM; |
|---|
| 948 | + dprintk(q, 1, "memory allocation failed\n"); |
|---|
| 949 | + ret = -ENOMEM; |
|---|
| 950 | + goto error; |
|---|
| 843 | 951 | } |
|---|
| 844 | 952 | |
|---|
| 845 | 953 | /* |
|---|
| .. | .. |
|---|
| 870 | 978 | if (ret < 0) { |
|---|
| 871 | 979 | /* |
|---|
| 872 | 980 | * Note: __vb2_queue_free() will subtract 'allocated_buffers' |
|---|
| 873 | | - * from q->num_buffers. |
|---|
| 981 | + * from q->num_buffers and it will reset q->memory to |
|---|
| 982 | + * VB2_MEMORY_UNKNOWN. |
|---|
| 874 | 983 | */ |
|---|
| 875 | 984 | __vb2_queue_free(q, allocated_buffers); |
|---|
| 876 | 985 | mutex_unlock(&q->mmap_lock); |
|---|
| .. | .. |
|---|
| 885 | 994 | *count = allocated_buffers; |
|---|
| 886 | 995 | |
|---|
| 887 | 996 | return 0; |
|---|
| 997 | + |
|---|
| 998 | +error: |
|---|
| 999 | + if (no_previous_buffers) { |
|---|
| 1000 | + mutex_lock(&q->mmap_lock); |
|---|
| 1001 | + q->memory = VB2_MEMORY_UNKNOWN; |
|---|
| 1002 | + mutex_unlock(&q->mmap_lock); |
|---|
| 1003 | + } |
|---|
| 1004 | + return ret; |
|---|
| 888 | 1005 | } |
|---|
| 889 | 1006 | EXPORT_SYMBOL_GPL(vb2_core_create_bufs); |
|---|
| 890 | 1007 | |
|---|
| .. | .. |
|---|
| 911 | 1028 | { |
|---|
| 912 | 1029 | struct vb2_queue *q = vb->vb2_queue; |
|---|
| 913 | 1030 | unsigned long flags; |
|---|
| 914 | | - unsigned int plane; |
|---|
| 915 | 1031 | |
|---|
| 916 | 1032 | if (WARN_ON(vb->state != VB2_BUF_STATE_ACTIVE)) |
|---|
| 917 | 1033 | return; |
|---|
| 918 | 1034 | |
|---|
| 919 | 1035 | if (WARN_ON(state != VB2_BUF_STATE_DONE && |
|---|
| 920 | 1036 | state != VB2_BUF_STATE_ERROR && |
|---|
| 921 | | - state != VB2_BUF_STATE_QUEUED && |
|---|
| 922 | | - state != VB2_BUF_STATE_REQUEUEING)) |
|---|
| 1037 | + state != VB2_BUF_STATE_QUEUED)) |
|---|
| 923 | 1038 | state = VB2_BUF_STATE_ERROR; |
|---|
| 924 | 1039 | |
|---|
| 925 | 1040 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
|---|
| .. | .. |
|---|
| 929 | 1044 | */ |
|---|
| 930 | 1045 | vb->cnt_buf_done++; |
|---|
| 931 | 1046 | #endif |
|---|
| 932 | | - dprintk(4, "done processing on buffer %d, state: %d\n", |
|---|
| 933 | | - vb->index, state); |
|---|
| 1047 | + dprintk(q, 4, "done processing on buffer %d, state: %s\n", |
|---|
| 1048 | + vb->index, vb2_state_name(state)); |
|---|
| 934 | 1049 | |
|---|
| 935 | | - if ((state != VB2_BUF_STATE_QUEUED && |
|---|
| 936 | | - state != VB2_BUF_STATE_REQUEUEING) && |
|---|
| 937 | | - vb->need_cache_sync_on_finish) { |
|---|
| 938 | | - for (plane = 0; plane < vb->num_planes; ++plane) |
|---|
| 939 | | - call_void_memop(vb, finish, vb->planes[plane].mem_priv); |
|---|
| 940 | | - } |
|---|
| 1050 | + if (state != VB2_BUF_STATE_QUEUED) |
|---|
| 1051 | + __vb2_buf_mem_finish(vb); |
|---|
| 941 | 1052 | |
|---|
| 942 | 1053 | spin_lock_irqsave(&q->done_lock, flags); |
|---|
| 943 | | - if (state == VB2_BUF_STATE_QUEUED || |
|---|
| 944 | | - state == VB2_BUF_STATE_REQUEUEING) { |
|---|
| 1054 | + if (state == VB2_BUF_STATE_QUEUED) { |
|---|
| 945 | 1055 | vb->state = VB2_BUF_STATE_QUEUED; |
|---|
| 946 | 1056 | } else { |
|---|
| 947 | 1057 | /* Add the buffer to the done buffers list */ |
|---|
| .. | .. |
|---|
| 949 | 1059 | vb->state = state; |
|---|
| 950 | 1060 | } |
|---|
| 951 | 1061 | atomic_dec(&q->owned_by_drv_count); |
|---|
| 1062 | + |
|---|
| 1063 | + if (state != VB2_BUF_STATE_QUEUED && vb->req_obj.req) { |
|---|
| 1064 | + media_request_object_unbind(&vb->req_obj); |
|---|
| 1065 | + media_request_object_put(&vb->req_obj); |
|---|
| 1066 | + } |
|---|
| 1067 | + |
|---|
| 952 | 1068 | spin_unlock_irqrestore(&q->done_lock, flags); |
|---|
| 953 | 1069 | |
|---|
| 954 | 1070 | trace_vb2_buf_done(q, vb); |
|---|
| 955 | 1071 | |
|---|
| 956 | 1072 | switch (state) { |
|---|
| 957 | 1073 | case VB2_BUF_STATE_QUEUED: |
|---|
| 958 | | - return; |
|---|
| 959 | | - case VB2_BUF_STATE_REQUEUEING: |
|---|
| 960 | | - if (q->start_streaming_called) |
|---|
| 961 | | - __enqueue_in_driver(vb); |
|---|
| 962 | 1074 | return; |
|---|
| 963 | 1075 | default: |
|---|
| 964 | 1076 | /* Inform any processes that may be waiting for buffers */ |
|---|
| .. | .. |
|---|
| 983 | 1095 | /* |
|---|
| 984 | 1096 | * __prepare_mmap() - prepare an MMAP buffer |
|---|
| 985 | 1097 | */ |
|---|
| 986 | | -static int __prepare_mmap(struct vb2_buffer *vb, const void *pb) |
|---|
| 1098 | +static int __prepare_mmap(struct vb2_buffer *vb) |
|---|
| 987 | 1099 | { |
|---|
| 988 | 1100 | int ret = 0; |
|---|
| 989 | 1101 | |
|---|
| 990 | | - if (pb) |
|---|
| 991 | | - ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, |
|---|
| 992 | | - vb, pb, vb->planes); |
|---|
| 1102 | + ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, |
|---|
| 1103 | + vb, vb->planes); |
|---|
| 993 | 1104 | return ret ? ret : call_vb_qop(vb, buf_prepare, vb); |
|---|
| 994 | 1105 | } |
|---|
| 995 | 1106 | |
|---|
| 996 | 1107 | /* |
|---|
| 997 | 1108 | * __prepare_userptr() - prepare a USERPTR buffer |
|---|
| 998 | 1109 | */ |
|---|
| 999 | | -static int __prepare_userptr(struct vb2_buffer *vb, const void *pb) |
|---|
| 1110 | +static int __prepare_userptr(struct vb2_buffer *vb) |
|---|
| 1000 | 1111 | { |
|---|
| 1001 | 1112 | struct vb2_plane planes[VB2_MAX_PLANES]; |
|---|
| 1002 | 1113 | struct vb2_queue *q = vb->vb2_queue; |
|---|
| .. | .. |
|---|
| 1007 | 1118 | |
|---|
| 1008 | 1119 | memset(planes, 0, sizeof(planes[0]) * vb->num_planes); |
|---|
| 1009 | 1120 | /* Copy relevant information provided by the userspace */ |
|---|
| 1010 | | - if (pb) { |
|---|
| 1011 | | - ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, |
|---|
| 1012 | | - vb, pb, planes); |
|---|
| 1013 | | - if (ret) |
|---|
| 1014 | | - return ret; |
|---|
| 1015 | | - } |
|---|
| 1121 | + ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, |
|---|
| 1122 | + vb, planes); |
|---|
| 1123 | + if (ret) |
|---|
| 1124 | + return ret; |
|---|
| 1016 | 1125 | |
|---|
| 1017 | 1126 | for (plane = 0; plane < vb->num_planes; ++plane) { |
|---|
| 1018 | 1127 | /* Skip the plane if already verified */ |
|---|
| .. | .. |
|---|
| 1021 | 1130 | && vb->planes[plane].length == planes[plane].length) |
|---|
| 1022 | 1131 | continue; |
|---|
| 1023 | 1132 | |
|---|
| 1024 | | - dprintk(3, "userspace address for plane %d changed, reacquiring memory\n", |
|---|
| 1133 | + dprintk(q, 3, "userspace address for plane %d changed, reacquiring memory\n", |
|---|
| 1025 | 1134 | plane); |
|---|
| 1026 | 1135 | |
|---|
| 1027 | 1136 | /* Check if the provided plane buffer is large enough */ |
|---|
| 1028 | 1137 | if (planes[plane].length < vb->planes[plane].min_length) { |
|---|
| 1029 | | - dprintk(1, "provided buffer size %u is less than setup size %u for plane %d\n", |
|---|
| 1138 | + dprintk(q, 1, "provided buffer size %u is less than setup size %u for plane %d\n", |
|---|
| 1030 | 1139 | planes[plane].length, |
|---|
| 1031 | 1140 | vb->planes[plane].min_length, |
|---|
| 1032 | 1141 | plane); |
|---|
| .. | .. |
|---|
| 1038 | 1147 | if (vb->planes[plane].mem_priv) { |
|---|
| 1039 | 1148 | if (!reacquired) { |
|---|
| 1040 | 1149 | reacquired = true; |
|---|
| 1150 | + vb->copied_timestamp = 0; |
|---|
| 1041 | 1151 | call_void_vb_qop(vb, buf_cleanup, vb); |
|---|
| 1042 | 1152 | } |
|---|
| 1043 | 1153 | call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv); |
|---|
| .. | .. |
|---|
| 1055 | 1165 | planes[plane].m.userptr, |
|---|
| 1056 | 1166 | planes[plane].length, q->dma_dir); |
|---|
| 1057 | 1167 | if (IS_ERR(mem_priv)) { |
|---|
| 1058 | | - dprintk(1, "failed acquiring userspace memory for plane %d\n", |
|---|
| 1168 | + dprintk(q, 1, "failed acquiring userspace memory for plane %d\n", |
|---|
| 1059 | 1169 | plane); |
|---|
| 1060 | 1170 | ret = PTR_ERR(mem_priv); |
|---|
| 1061 | 1171 | goto err; |
|---|
| .. | .. |
|---|
| 1082 | 1192 | */ |
|---|
| 1083 | 1193 | ret = call_vb_qop(vb, buf_init, vb); |
|---|
| 1084 | 1194 | if (ret) { |
|---|
| 1085 | | - dprintk(1, "buffer initialization failed\n"); |
|---|
| 1195 | + dprintk(q, 1, "buffer initialization failed\n"); |
|---|
| 1086 | 1196 | goto err; |
|---|
| 1087 | 1197 | } |
|---|
| 1088 | 1198 | } |
|---|
| 1089 | 1199 | |
|---|
| 1090 | 1200 | ret = call_vb_qop(vb, buf_prepare, vb); |
|---|
| 1091 | 1201 | if (ret) { |
|---|
| 1092 | | - dprintk(1, "buffer preparation failed\n"); |
|---|
| 1202 | + dprintk(q, 1, "buffer preparation failed\n"); |
|---|
| 1093 | 1203 | call_void_vb_qop(vb, buf_cleanup, vb); |
|---|
| 1094 | 1204 | goto err; |
|---|
| 1095 | 1205 | } |
|---|
| .. | .. |
|---|
| 1112 | 1222 | /* |
|---|
| 1113 | 1223 | * __prepare_dmabuf() - prepare a DMABUF buffer |
|---|
| 1114 | 1224 | */ |
|---|
| 1115 | | -static int __prepare_dmabuf(struct vb2_buffer *vb, const void *pb) |
|---|
| 1225 | +static int __prepare_dmabuf(struct vb2_buffer *vb) |
|---|
| 1116 | 1226 | { |
|---|
| 1117 | 1227 | struct vb2_plane planes[VB2_MAX_PLANES]; |
|---|
| 1118 | 1228 | struct vb2_queue *q = vb->vb2_queue; |
|---|
| .. | .. |
|---|
| 1123 | 1233 | |
|---|
| 1124 | 1234 | memset(planes, 0, sizeof(planes[0]) * vb->num_planes); |
|---|
| 1125 | 1235 | /* Copy relevant information provided by the userspace */ |
|---|
| 1126 | | - if (pb) { |
|---|
| 1127 | | - ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, |
|---|
| 1128 | | - vb, pb, planes); |
|---|
| 1129 | | - if (ret) |
|---|
| 1130 | | - return ret; |
|---|
| 1131 | | - } |
|---|
| 1236 | + ret = call_bufop(vb->vb2_queue, fill_vb2_buffer, |
|---|
| 1237 | + vb, planes); |
|---|
| 1238 | + if (ret) |
|---|
| 1239 | + return ret; |
|---|
| 1132 | 1240 | |
|---|
| 1133 | 1241 | for (plane = 0; plane < vb->num_planes; ++plane) { |
|---|
| 1134 | 1242 | struct dma_buf *dbuf = dma_buf_get(planes[plane].m.fd); |
|---|
| 1135 | 1243 | |
|---|
| 1136 | 1244 | if (IS_ERR_OR_NULL(dbuf)) { |
|---|
| 1137 | | - dprintk(1, "invalid dmabuf fd for plane %d\n", |
|---|
| 1245 | + dprintk(q, 1, "invalid dmabuf fd for plane %d\n", |
|---|
| 1138 | 1246 | plane); |
|---|
| 1139 | 1247 | ret = -EINVAL; |
|---|
| 1140 | 1248 | goto err; |
|---|
| .. | .. |
|---|
| 1145 | 1253 | planes[plane].length = dbuf->size; |
|---|
| 1146 | 1254 | |
|---|
| 1147 | 1255 | if (planes[plane].length < vb->planes[plane].min_length) { |
|---|
| 1148 | | - dprintk(1, "invalid dmabuf length %u for plane %d, minimum length %u\n", |
|---|
| 1256 | + dprintk(q, 1, "invalid dmabuf length %u for plane %d, minimum length %u\n", |
|---|
| 1149 | 1257 | planes[plane].length, plane, |
|---|
| 1150 | 1258 | vb->planes[plane].min_length); |
|---|
| 1151 | 1259 | dma_buf_put(dbuf); |
|---|
| .. | .. |
|---|
| 1160 | 1268 | continue; |
|---|
| 1161 | 1269 | } |
|---|
| 1162 | 1270 | |
|---|
| 1163 | | - dprintk(3, "buffer for plane %d changed\n", plane); |
|---|
| 1271 | + dprintk(q, 3, "buffer for plane %d changed\n", plane); |
|---|
| 1164 | 1272 | |
|---|
| 1165 | 1273 | if (!reacquired) { |
|---|
| 1166 | 1274 | reacquired = true; |
|---|
| 1275 | + vb->copied_timestamp = 0; |
|---|
| 1167 | 1276 | call_void_vb_qop(vb, buf_cleanup, vb); |
|---|
| 1168 | 1277 | } |
|---|
| 1169 | 1278 | |
|---|
| .. | .. |
|---|
| 1179 | 1288 | q->alloc_devs[plane] ? : q->dev, |
|---|
| 1180 | 1289 | dbuf, planes[plane].length, q->dma_dir); |
|---|
| 1181 | 1290 | if (IS_ERR(mem_priv)) { |
|---|
| 1182 | | - dprintk(1, "failed to attach dmabuf\n"); |
|---|
| 1291 | + dprintk(q, 1, "failed to attach dmabuf\n"); |
|---|
| 1183 | 1292 | ret = PTR_ERR(mem_priv); |
|---|
| 1184 | 1293 | dma_buf_put(dbuf); |
|---|
| 1185 | 1294 | goto err; |
|---|
| .. | .. |
|---|
| 1195 | 1304 | * userspace knows sooner rather than later if the dma-buf map fails. |
|---|
| 1196 | 1305 | */ |
|---|
| 1197 | 1306 | for (plane = 0; plane < vb->num_planes; ++plane) { |
|---|
| 1307 | + if (vb->planes[plane].dbuf_mapped) |
|---|
| 1308 | + continue; |
|---|
| 1309 | + |
|---|
| 1198 | 1310 | ret = call_memop(vb, map_dmabuf, vb->planes[plane].mem_priv); |
|---|
| 1199 | 1311 | if (ret) { |
|---|
| 1200 | | - dprintk(1, "failed to map dmabuf for plane %d\n", |
|---|
| 1312 | + dprintk(q, 1, "failed to map dmabuf for plane %d\n", |
|---|
| 1201 | 1313 | plane); |
|---|
| 1202 | 1314 | goto err; |
|---|
| 1203 | 1315 | } |
|---|
| .. | .. |
|---|
| 1222 | 1334 | */ |
|---|
| 1223 | 1335 | ret = call_vb_qop(vb, buf_init, vb); |
|---|
| 1224 | 1336 | if (ret) { |
|---|
| 1225 | | - dprintk(1, "buffer initialization failed\n"); |
|---|
| 1337 | + dprintk(q, 1, "buffer initialization failed\n"); |
|---|
| 1226 | 1338 | goto err; |
|---|
| 1227 | 1339 | } |
|---|
| 1228 | 1340 | } |
|---|
| 1229 | 1341 | |
|---|
| 1230 | 1342 | ret = call_vb_qop(vb, buf_prepare, vb); |
|---|
| 1231 | 1343 | if (ret) { |
|---|
| 1232 | | - dprintk(1, "buffer preparation failed\n"); |
|---|
| 1344 | + dprintk(q, 1, "buffer preparation failed\n"); |
|---|
| 1233 | 1345 | call_void_vb_qop(vb, buf_cleanup, vb); |
|---|
| 1234 | 1346 | goto err; |
|---|
| 1235 | 1347 | } |
|---|
| .. | .. |
|---|
| 1257 | 1369 | call_void_vb_qop(vb, buf_queue, vb); |
|---|
| 1258 | 1370 | } |
|---|
| 1259 | 1371 | |
|---|
| 1260 | | -static int __buf_prepare(struct vb2_buffer *vb, const void *pb) |
|---|
| 1372 | +static int __buf_prepare(struct vb2_buffer *vb) |
|---|
| 1261 | 1373 | { |
|---|
| 1262 | 1374 | struct vb2_queue *q = vb->vb2_queue; |
|---|
| 1263 | | - unsigned int plane; |
|---|
| 1375 | + enum vb2_buffer_state orig_state = vb->state; |
|---|
| 1264 | 1376 | int ret; |
|---|
| 1265 | 1377 | |
|---|
| 1266 | 1378 | if (q->error) { |
|---|
| 1267 | | - dprintk(1, "fatal error occurred on queue\n"); |
|---|
| 1379 | + dprintk(q, 1, "fatal error occurred on queue\n"); |
|---|
| 1268 | 1380 | return -EIO; |
|---|
| 1381 | + } |
|---|
| 1382 | + |
|---|
| 1383 | + if (vb->prepared) |
|---|
| 1384 | + return 0; |
|---|
| 1385 | + WARN_ON(vb->synced); |
|---|
| 1386 | + |
|---|
| 1387 | + if (q->is_output) { |
|---|
| 1388 | + ret = call_vb_qop(vb, buf_out_validate, vb); |
|---|
| 1389 | + if (ret) { |
|---|
| 1390 | + dprintk(q, 1, "buffer validation failed\n"); |
|---|
| 1391 | + return ret; |
|---|
| 1392 | + } |
|---|
| 1269 | 1393 | } |
|---|
| 1270 | 1394 | |
|---|
| 1271 | 1395 | vb->state = VB2_BUF_STATE_PREPARING; |
|---|
| 1272 | 1396 | |
|---|
| 1273 | 1397 | switch (q->memory) { |
|---|
| 1274 | 1398 | case VB2_MEMORY_MMAP: |
|---|
| 1275 | | - ret = __prepare_mmap(vb, pb); |
|---|
| 1399 | + ret = __prepare_mmap(vb); |
|---|
| 1276 | 1400 | break; |
|---|
| 1277 | 1401 | case VB2_MEMORY_USERPTR: |
|---|
| 1278 | | - ret = __prepare_userptr(vb, pb); |
|---|
| 1402 | + ret = __prepare_userptr(vb); |
|---|
| 1279 | 1403 | break; |
|---|
| 1280 | 1404 | case VB2_MEMORY_DMABUF: |
|---|
| 1281 | | - ret = __prepare_dmabuf(vb, pb); |
|---|
| 1405 | + ret = __prepare_dmabuf(vb); |
|---|
| 1282 | 1406 | break; |
|---|
| 1283 | 1407 | default: |
|---|
| 1284 | 1408 | WARN(1, "Invalid queue type\n"); |
|---|
| 1285 | 1409 | ret = -EINVAL; |
|---|
| 1410 | + break; |
|---|
| 1286 | 1411 | } |
|---|
| 1287 | 1412 | |
|---|
| 1288 | 1413 | if (ret) { |
|---|
| 1289 | | - dprintk(1, "buffer preparation failed: %d\n", ret); |
|---|
| 1290 | | - vb->state = VB2_BUF_STATE_DEQUEUED; |
|---|
| 1414 | + dprintk(q, 1, "buffer preparation failed: %d\n", ret); |
|---|
| 1415 | + vb->state = orig_state; |
|---|
| 1291 | 1416 | return ret; |
|---|
| 1292 | 1417 | } |
|---|
| 1293 | 1418 | |
|---|
| 1294 | | - if (vb->need_cache_sync_on_prepare) { |
|---|
| 1295 | | - for (plane = 0; plane < vb->num_planes; ++plane) |
|---|
| 1296 | | - call_void_memop(vb, prepare, |
|---|
| 1297 | | - vb->planes[plane].mem_priv); |
|---|
| 1298 | | - } |
|---|
| 1299 | | - |
|---|
| 1300 | | - vb->state = VB2_BUF_STATE_PREPARED; |
|---|
| 1419 | + __vb2_buf_mem_prepare(vb); |
|---|
| 1420 | + vb->prepared = 1; |
|---|
| 1421 | + vb->state = orig_state; |
|---|
| 1301 | 1422 | |
|---|
| 1302 | 1423 | return 0; |
|---|
| 1303 | 1424 | } |
|---|
| 1425 | + |
|---|
| 1426 | +static int vb2_req_prepare(struct media_request_object *obj) |
|---|
| 1427 | +{ |
|---|
| 1428 | + struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); |
|---|
| 1429 | + int ret; |
|---|
| 1430 | + |
|---|
| 1431 | + if (WARN_ON(vb->state != VB2_BUF_STATE_IN_REQUEST)) |
|---|
| 1432 | + return -EINVAL; |
|---|
| 1433 | + |
|---|
| 1434 | + mutex_lock(vb->vb2_queue->lock); |
|---|
| 1435 | + ret = __buf_prepare(vb); |
|---|
| 1436 | + mutex_unlock(vb->vb2_queue->lock); |
|---|
| 1437 | + return ret; |
|---|
| 1438 | +} |
|---|
| 1439 | + |
|---|
| 1440 | +static void __vb2_dqbuf(struct vb2_buffer *vb); |
|---|
| 1441 | + |
|---|
| 1442 | +static void vb2_req_unprepare(struct media_request_object *obj) |
|---|
| 1443 | +{ |
|---|
| 1444 | + struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); |
|---|
| 1445 | + |
|---|
| 1446 | + mutex_lock(vb->vb2_queue->lock); |
|---|
| 1447 | + __vb2_dqbuf(vb); |
|---|
| 1448 | + vb->state = VB2_BUF_STATE_IN_REQUEST; |
|---|
| 1449 | + mutex_unlock(vb->vb2_queue->lock); |
|---|
| 1450 | + WARN_ON(!vb->req_obj.req); |
|---|
| 1451 | +} |
|---|
| 1452 | + |
|---|
| 1453 | +int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, |
|---|
| 1454 | + struct media_request *req); |
|---|
| 1455 | + |
|---|
| 1456 | +static void vb2_req_queue(struct media_request_object *obj) |
|---|
| 1457 | +{ |
|---|
| 1458 | + struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); |
|---|
| 1459 | + |
|---|
| 1460 | + mutex_lock(vb->vb2_queue->lock); |
|---|
| 1461 | + vb2_core_qbuf(vb->vb2_queue, vb->index, NULL, NULL); |
|---|
| 1462 | + mutex_unlock(vb->vb2_queue->lock); |
|---|
| 1463 | +} |
|---|
| 1464 | + |
|---|
| 1465 | +static void vb2_req_unbind(struct media_request_object *obj) |
|---|
| 1466 | +{ |
|---|
| 1467 | + struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); |
|---|
| 1468 | + |
|---|
| 1469 | + if (vb->state == VB2_BUF_STATE_IN_REQUEST) |
|---|
| 1470 | + call_void_bufop(vb->vb2_queue, init_buffer, vb); |
|---|
| 1471 | +} |
|---|
| 1472 | + |
|---|
| 1473 | +static void vb2_req_release(struct media_request_object *obj) |
|---|
| 1474 | +{ |
|---|
| 1475 | + struct vb2_buffer *vb = container_of(obj, struct vb2_buffer, req_obj); |
|---|
| 1476 | + |
|---|
| 1477 | + if (vb->state == VB2_BUF_STATE_IN_REQUEST) { |
|---|
| 1478 | + vb->state = VB2_BUF_STATE_DEQUEUED; |
|---|
| 1479 | + if (vb->request) |
|---|
| 1480 | + media_request_put(vb->request); |
|---|
| 1481 | + vb->request = NULL; |
|---|
| 1482 | + } |
|---|
| 1483 | +} |
|---|
| 1484 | + |
|---|
| 1485 | +static const struct media_request_object_ops vb2_core_req_ops = { |
|---|
| 1486 | + .prepare = vb2_req_prepare, |
|---|
| 1487 | + .unprepare = vb2_req_unprepare, |
|---|
| 1488 | + .queue = vb2_req_queue, |
|---|
| 1489 | + .unbind = vb2_req_unbind, |
|---|
| 1490 | + .release = vb2_req_release, |
|---|
| 1491 | +}; |
|---|
| 1492 | + |
|---|
| 1493 | +bool vb2_request_object_is_buffer(struct media_request_object *obj) |
|---|
| 1494 | +{ |
|---|
| 1495 | + return obj->ops == &vb2_core_req_ops; |
|---|
| 1496 | +} |
|---|
| 1497 | +EXPORT_SYMBOL_GPL(vb2_request_object_is_buffer); |
|---|
| 1498 | + |
|---|
| 1499 | +unsigned int vb2_request_buffer_cnt(struct media_request *req) |
|---|
| 1500 | +{ |
|---|
| 1501 | + struct media_request_object *obj; |
|---|
| 1502 | + unsigned long flags; |
|---|
| 1503 | + unsigned int buffer_cnt = 0; |
|---|
| 1504 | + |
|---|
| 1505 | + spin_lock_irqsave(&req->lock, flags); |
|---|
| 1506 | + list_for_each_entry(obj, &req->objects, list) |
|---|
| 1507 | + if (vb2_request_object_is_buffer(obj)) |
|---|
| 1508 | + buffer_cnt++; |
|---|
| 1509 | + spin_unlock_irqrestore(&req->lock, flags); |
|---|
| 1510 | + |
|---|
| 1511 | + return buffer_cnt; |
|---|
| 1512 | +} |
|---|
| 1513 | +EXPORT_SYMBOL_GPL(vb2_request_buffer_cnt); |
|---|
| 1304 | 1514 | |
|---|
| 1305 | 1515 | int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) |
|---|
| 1306 | 1516 | { |
|---|
| .. | .. |
|---|
| 1309 | 1519 | |
|---|
| 1310 | 1520 | vb = q->bufs[index]; |
|---|
| 1311 | 1521 | if (vb->state != VB2_BUF_STATE_DEQUEUED) { |
|---|
| 1312 | | - dprintk(1, "invalid buffer state %d\n", |
|---|
| 1313 | | - vb->state); |
|---|
| 1522 | + dprintk(q, 1, "invalid buffer state %s\n", |
|---|
| 1523 | + vb2_state_name(vb->state)); |
|---|
| 1524 | + return -EINVAL; |
|---|
| 1525 | + } |
|---|
| 1526 | + if (vb->prepared) { |
|---|
| 1527 | + dprintk(q, 1, "buffer already prepared\n"); |
|---|
| 1314 | 1528 | return -EINVAL; |
|---|
| 1315 | 1529 | } |
|---|
| 1316 | 1530 | |
|---|
| 1317 | | - ret = __buf_prepare(vb, pb); |
|---|
| 1531 | + ret = __buf_prepare(vb); |
|---|
| 1318 | 1532 | if (ret) |
|---|
| 1319 | 1533 | return ret; |
|---|
| 1320 | 1534 | |
|---|
| 1321 | 1535 | /* Fill buffer information for the userspace */ |
|---|
| 1322 | 1536 | call_void_bufop(q, fill_user_buffer, vb, pb); |
|---|
| 1323 | 1537 | |
|---|
| 1324 | | - dprintk(2, "prepare of buffer %d succeeded\n", vb->index); |
|---|
| 1538 | + dprintk(q, 2, "prepare of buffer %d succeeded\n", vb->index); |
|---|
| 1325 | 1539 | |
|---|
| 1326 | | - return ret; |
|---|
| 1540 | + return 0; |
|---|
| 1327 | 1541 | } |
|---|
| 1328 | 1542 | EXPORT_SYMBOL_GPL(vb2_core_prepare_buf); |
|---|
| 1329 | 1543 | |
|---|
| .. | .. |
|---|
| 1359 | 1573 | |
|---|
| 1360 | 1574 | q->start_streaming_called = 0; |
|---|
| 1361 | 1575 | |
|---|
| 1362 | | - dprintk(1, "driver refused to start streaming\n"); |
|---|
| 1576 | + dprintk(q, 1, "driver refused to start streaming\n"); |
|---|
| 1363 | 1577 | /* |
|---|
| 1364 | 1578 | * If you see this warning, then the driver isn't cleaning up properly |
|---|
| 1365 | 1579 | * after a failed start_streaming(). See the start_streaming() |
|---|
| .. | .. |
|---|
| 1390 | 1604 | return ret; |
|---|
| 1391 | 1605 | } |
|---|
| 1392 | 1606 | |
|---|
| 1393 | | -int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb) |
|---|
| 1607 | +int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, |
|---|
| 1608 | + struct media_request *req) |
|---|
| 1394 | 1609 | { |
|---|
| 1395 | 1610 | struct vb2_buffer *vb; |
|---|
| 1396 | 1611 | enum vb2_buffer_state orig_state; |
|---|
| 1397 | 1612 | int ret; |
|---|
| 1398 | 1613 | |
|---|
| 1399 | 1614 | if (q->error) { |
|---|
| 1400 | | - dprintk(1, "fatal error occurred on queue\n"); |
|---|
| 1615 | + dprintk(q, 1, "fatal error occurred on queue\n"); |
|---|
| 1401 | 1616 | return -EIO; |
|---|
| 1402 | 1617 | } |
|---|
| 1403 | 1618 | |
|---|
| 1404 | 1619 | vb = q->bufs[index]; |
|---|
| 1405 | 1620 | |
|---|
| 1406 | | - switch (vb->state) { |
|---|
| 1407 | | - case VB2_BUF_STATE_DEQUEUED: |
|---|
| 1408 | | - ret = __buf_prepare(vb, pb); |
|---|
| 1621 | + if (!req && vb->state != VB2_BUF_STATE_IN_REQUEST && |
|---|
| 1622 | + q->requires_requests) { |
|---|
| 1623 | + dprintk(q, 1, "qbuf requires a request\n"); |
|---|
| 1624 | + return -EBADR; |
|---|
| 1625 | + } |
|---|
| 1626 | + |
|---|
| 1627 | + if ((req && q->uses_qbuf) || |
|---|
| 1628 | + (!req && vb->state != VB2_BUF_STATE_IN_REQUEST && |
|---|
| 1629 | + q->uses_requests)) { |
|---|
| 1630 | + dprintk(q, 1, "queue in wrong mode (qbuf vs requests)\n"); |
|---|
| 1631 | + return -EBUSY; |
|---|
| 1632 | + } |
|---|
| 1633 | + |
|---|
| 1634 | + if (req) { |
|---|
| 1635 | + int ret; |
|---|
| 1636 | + |
|---|
| 1637 | + q->uses_requests = 1; |
|---|
| 1638 | + if (vb->state != VB2_BUF_STATE_DEQUEUED) { |
|---|
| 1639 | + dprintk(q, 1, "buffer %d not in dequeued state\n", |
|---|
| 1640 | + vb->index); |
|---|
| 1641 | + return -EINVAL; |
|---|
| 1642 | + } |
|---|
| 1643 | + |
|---|
| 1644 | + if (q->is_output && !vb->prepared) { |
|---|
| 1645 | + ret = call_vb_qop(vb, buf_out_validate, vb); |
|---|
| 1646 | + if (ret) { |
|---|
| 1647 | + dprintk(q, 1, "buffer validation failed\n"); |
|---|
| 1648 | + return ret; |
|---|
| 1649 | + } |
|---|
| 1650 | + } |
|---|
| 1651 | + |
|---|
| 1652 | + media_request_object_init(&vb->req_obj); |
|---|
| 1653 | + |
|---|
| 1654 | + /* Make sure the request is in a safe state for updating. */ |
|---|
| 1655 | + ret = media_request_lock_for_update(req); |
|---|
| 1409 | 1656 | if (ret) |
|---|
| 1410 | 1657 | return ret; |
|---|
| 1411 | | - break; |
|---|
| 1412 | | - case VB2_BUF_STATE_PREPARED: |
|---|
| 1658 | + ret = media_request_object_bind(req, &vb2_core_req_ops, |
|---|
| 1659 | + q, true, &vb->req_obj); |
|---|
| 1660 | + media_request_unlock_for_update(req); |
|---|
| 1661 | + if (ret) |
|---|
| 1662 | + return ret; |
|---|
| 1663 | + |
|---|
| 1664 | + vb->state = VB2_BUF_STATE_IN_REQUEST; |
|---|
| 1665 | + |
|---|
| 1666 | + /* |
|---|
| 1667 | + * Increment the refcount and store the request. |
|---|
| 1668 | + * The request refcount is decremented again when the |
|---|
| 1669 | + * buffer is dequeued. This is to prevent vb2_buffer_done() |
|---|
| 1670 | + * from freeing the request from interrupt context, which can |
|---|
| 1671 | + * happen if the application closed the request fd after |
|---|
| 1672 | + * queueing the request. |
|---|
| 1673 | + */ |
|---|
| 1674 | + media_request_get(req); |
|---|
| 1675 | + vb->request = req; |
|---|
| 1676 | + |
|---|
| 1677 | + /* Fill buffer information for the userspace */ |
|---|
| 1678 | + if (pb) { |
|---|
| 1679 | + call_void_bufop(q, copy_timestamp, vb, pb); |
|---|
| 1680 | + call_void_bufop(q, fill_user_buffer, vb, pb); |
|---|
| 1681 | + } |
|---|
| 1682 | + |
|---|
| 1683 | + dprintk(q, 2, "qbuf of buffer %d succeeded\n", vb->index); |
|---|
| 1684 | + return 0; |
|---|
| 1685 | + } |
|---|
| 1686 | + |
|---|
| 1687 | + if (vb->state != VB2_BUF_STATE_IN_REQUEST) |
|---|
| 1688 | + q->uses_qbuf = 1; |
|---|
| 1689 | + |
|---|
| 1690 | + switch (vb->state) { |
|---|
| 1691 | + case VB2_BUF_STATE_DEQUEUED: |
|---|
| 1692 | + case VB2_BUF_STATE_IN_REQUEST: |
|---|
| 1693 | + if (!vb->prepared) { |
|---|
| 1694 | + ret = __buf_prepare(vb); |
|---|
| 1695 | + if (ret) |
|---|
| 1696 | + return ret; |
|---|
| 1697 | + } |
|---|
| 1413 | 1698 | break; |
|---|
| 1414 | 1699 | case VB2_BUF_STATE_PREPARING: |
|---|
| 1415 | | - dprintk(1, "buffer still being prepared\n"); |
|---|
| 1700 | + dprintk(q, 1, "buffer still being prepared\n"); |
|---|
| 1416 | 1701 | return -EINVAL; |
|---|
| 1417 | 1702 | default: |
|---|
| 1418 | | - dprintk(1, "invalid buffer state %d\n", vb->state); |
|---|
| 1703 | + dprintk(q, 1, "invalid buffer state %s\n", |
|---|
| 1704 | + vb2_state_name(vb->state)); |
|---|
| 1419 | 1705 | return -EINVAL; |
|---|
| 1420 | 1706 | } |
|---|
| 1421 | 1707 | |
|---|
| .. | .. |
|---|
| 1467 | 1753 | } |
|---|
| 1468 | 1754 | } |
|---|
| 1469 | 1755 | |
|---|
| 1470 | | - dprintk(2, "qbuf of buffer %d succeeded\n", vb->index); |
|---|
| 1756 | + dprintk(q, 2, "qbuf of buffer %d succeeded\n", vb->index); |
|---|
| 1471 | 1757 | return 0; |
|---|
| 1472 | 1758 | } |
|---|
| 1473 | 1759 | EXPORT_SYMBOL_GPL(vb2_core_qbuf); |
|---|
| .. | .. |
|---|
| 1493 | 1779 | int ret; |
|---|
| 1494 | 1780 | |
|---|
| 1495 | 1781 | if (q->waiting_in_dqbuf) { |
|---|
| 1496 | | - dprintk(1, "another dup()ped fd is waiting for a buffer\n"); |
|---|
| 1782 | + dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); |
|---|
| 1497 | 1783 | return -EBUSY; |
|---|
| 1498 | 1784 | } |
|---|
| 1499 | 1785 | |
|---|
| 1500 | 1786 | if (!q->streaming) { |
|---|
| 1501 | | - dprintk(1, "streaming off, will not wait for buffers\n"); |
|---|
| 1787 | + dprintk(q, 1, "streaming off, will not wait for buffers\n"); |
|---|
| 1502 | 1788 | return -EINVAL; |
|---|
| 1503 | 1789 | } |
|---|
| 1504 | 1790 | |
|---|
| 1505 | 1791 | if (q->error) { |
|---|
| 1506 | | - dprintk(1, "Queue in error state, will not wait for buffers\n"); |
|---|
| 1792 | + dprintk(q, 1, "Queue in error state, will not wait for buffers\n"); |
|---|
| 1507 | 1793 | return -EIO; |
|---|
| 1508 | 1794 | } |
|---|
| 1509 | 1795 | |
|---|
| 1510 | 1796 | if (q->last_buffer_dequeued) { |
|---|
| 1511 | | - dprintk(3, "last buffer dequeued already, will not wait for buffers\n"); |
|---|
| 1797 | + dprintk(q, 3, "last buffer dequeued already, will not wait for buffers\n"); |
|---|
| 1512 | 1798 | return -EPIPE; |
|---|
| 1513 | 1799 | } |
|---|
| 1514 | 1800 | |
|---|
| .. | .. |
|---|
| 1520 | 1806 | } |
|---|
| 1521 | 1807 | |
|---|
| 1522 | 1808 | if (nonblocking) { |
|---|
| 1523 | | - dprintk(3, "nonblocking and no buffers to dequeue, will not wait\n"); |
|---|
| 1809 | + dprintk(q, 3, "nonblocking and no buffers to dequeue, will not wait\n"); |
|---|
| 1524 | 1810 | return -EAGAIN; |
|---|
| 1525 | 1811 | } |
|---|
| 1526 | 1812 | |
|---|
| .. | .. |
|---|
| 1535 | 1821 | /* |
|---|
| 1536 | 1822 | * All locks have been released, it is safe to sleep now. |
|---|
| 1537 | 1823 | */ |
|---|
| 1538 | | - dprintk(3, "will sleep waiting for buffers\n"); |
|---|
| 1824 | + dprintk(q, 3, "will sleep waiting for buffers\n"); |
|---|
| 1539 | 1825 | ret = wait_event_interruptible(q->done_wq, |
|---|
| 1540 | 1826 | !list_empty(&q->done_list) || !q->streaming || |
|---|
| 1541 | 1827 | q->error); |
|---|
| .. | .. |
|---|
| 1547 | 1833 | call_void_qop(q, wait_finish, q); |
|---|
| 1548 | 1834 | q->waiting_in_dqbuf = 0; |
|---|
| 1549 | 1835 | if (ret) { |
|---|
| 1550 | | - dprintk(1, "sleep was interrupted\n"); |
|---|
| 1836 | + dprintk(q, 1, "sleep was interrupted\n"); |
|---|
| 1551 | 1837 | return ret; |
|---|
| 1552 | 1838 | } |
|---|
| 1553 | 1839 | } |
|---|
| .. | .. |
|---|
| 1595 | 1881 | int vb2_wait_for_all_buffers(struct vb2_queue *q) |
|---|
| 1596 | 1882 | { |
|---|
| 1597 | 1883 | if (!q->streaming) { |
|---|
| 1598 | | - dprintk(1, "streaming off, will not wait for buffers\n"); |
|---|
| 1884 | + dprintk(q, 1, "streaming off, will not wait for buffers\n"); |
|---|
| 1599 | 1885 | return -EINVAL; |
|---|
| 1600 | 1886 | } |
|---|
| 1601 | 1887 | |
|---|
| .. | .. |
|---|
| 1611 | 1897 | static void __vb2_dqbuf(struct vb2_buffer *vb) |
|---|
| 1612 | 1898 | { |
|---|
| 1613 | 1899 | struct vb2_queue *q = vb->vb2_queue; |
|---|
| 1614 | | - unsigned int i; |
|---|
| 1615 | 1900 | |
|---|
| 1616 | 1901 | /* nothing to do if the buffer is already dequeued */ |
|---|
| 1617 | 1902 | if (vb->state == VB2_BUF_STATE_DEQUEUED) |
|---|
| .. | .. |
|---|
| 1619 | 1904 | |
|---|
| 1620 | 1905 | vb->state = VB2_BUF_STATE_DEQUEUED; |
|---|
| 1621 | 1906 | |
|---|
| 1622 | | - /* unmap DMABUF buffer */ |
|---|
| 1623 | | - if (q->memory == VB2_MEMORY_DMABUF) |
|---|
| 1624 | | - for (i = 0; i < vb->num_planes; ++i) { |
|---|
| 1625 | | - if (!vb->planes[i].dbuf_mapped) |
|---|
| 1626 | | - continue; |
|---|
| 1627 | | - call_void_memop(vb, unmap_dmabuf, vb->planes[i].mem_priv); |
|---|
| 1628 | | - vb->planes[i].dbuf_mapped = 0; |
|---|
| 1629 | | - } |
|---|
| 1907 | + call_void_bufop(q, init_buffer, vb); |
|---|
| 1630 | 1908 | } |
|---|
| 1631 | 1909 | |
|---|
| 1632 | 1910 | int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb, |
|---|
| .. | .. |
|---|
| 1641 | 1919 | |
|---|
| 1642 | 1920 | switch (vb->state) { |
|---|
| 1643 | 1921 | case VB2_BUF_STATE_DONE: |
|---|
| 1644 | | - dprintk(3, "returning done buffer\n"); |
|---|
| 1922 | + dprintk(q, 3, "returning done buffer\n"); |
|---|
| 1645 | 1923 | break; |
|---|
| 1646 | 1924 | case VB2_BUF_STATE_ERROR: |
|---|
| 1647 | | - dprintk(3, "returning done buffer with errors\n"); |
|---|
| 1925 | + dprintk(q, 3, "returning done buffer with errors\n"); |
|---|
| 1648 | 1926 | break; |
|---|
| 1649 | 1927 | default: |
|---|
| 1650 | | - dprintk(1, "invalid buffer state\n"); |
|---|
| 1928 | + dprintk(q, 1, "invalid buffer state %s\n", |
|---|
| 1929 | + vb2_state_name(vb->state)); |
|---|
| 1651 | 1930 | return -EINVAL; |
|---|
| 1652 | 1931 | } |
|---|
| 1653 | 1932 | |
|---|
| 1654 | 1933 | call_void_vb_qop(vb, buf_finish, vb); |
|---|
| 1934 | + vb->prepared = 0; |
|---|
| 1655 | 1935 | |
|---|
| 1656 | 1936 | if (pindex) |
|---|
| 1657 | 1937 | *pindex = vb->index; |
|---|
| .. | .. |
|---|
| 1669 | 1949 | /* go back to dequeued state */ |
|---|
| 1670 | 1950 | __vb2_dqbuf(vb); |
|---|
| 1671 | 1951 | |
|---|
| 1672 | | - dprintk(2, "dqbuf of buffer %d, with state %d\n", |
|---|
| 1673 | | - vb->index, vb->state); |
|---|
| 1952 | + if (WARN_ON(vb->req_obj.req)) { |
|---|
| 1953 | + media_request_object_unbind(&vb->req_obj); |
|---|
| 1954 | + media_request_object_put(&vb->req_obj); |
|---|
| 1955 | + } |
|---|
| 1956 | + if (vb->request) |
|---|
| 1957 | + media_request_put(vb->request); |
|---|
| 1958 | + vb->request = NULL; |
|---|
| 1959 | + |
|---|
| 1960 | + dprintk(q, 2, "dqbuf of buffer %d, state: %s\n", |
|---|
| 1961 | + vb->index, vb2_state_name(vb->state)); |
|---|
| 1674 | 1962 | |
|---|
| 1675 | 1963 | return 0; |
|---|
| 1676 | 1964 | |
|---|
| .. | .. |
|---|
| 1715 | 2003 | q->start_streaming_called = 0; |
|---|
| 1716 | 2004 | q->queued_count = 0; |
|---|
| 1717 | 2005 | q->error = 0; |
|---|
| 2006 | + q->uses_requests = 0; |
|---|
| 2007 | + q->uses_qbuf = 0; |
|---|
| 1718 | 2008 | |
|---|
| 1719 | 2009 | /* |
|---|
| 1720 | 2010 | * Remove all buffers from videobuf's list... |
|---|
| .. | .. |
|---|
| 1739 | 2029 | */ |
|---|
| 1740 | 2030 | for (i = 0; i < q->num_buffers; ++i) { |
|---|
| 1741 | 2031 | struct vb2_buffer *vb = q->bufs[i]; |
|---|
| 2032 | + struct media_request *req = vb->req_obj.req; |
|---|
| 1742 | 2033 | |
|---|
| 1743 | | - if ((vb->state == VB2_BUF_STATE_PREPARED || |
|---|
| 1744 | | - vb->state == VB2_BUF_STATE_QUEUED) && |
|---|
| 1745 | | - vb->need_cache_sync_on_finish) { |
|---|
| 1746 | | - unsigned int plane; |
|---|
| 2034 | + /* |
|---|
| 2035 | + * If a request is associated with this buffer, then |
|---|
| 2036 | + * call buf_request_cancel() to give the driver to complete() |
|---|
| 2037 | + * related request objects. Otherwise those objects would |
|---|
| 2038 | + * never complete. |
|---|
| 2039 | + */ |
|---|
| 2040 | + if (req) { |
|---|
| 2041 | + enum media_request_state state; |
|---|
| 2042 | + unsigned long flags; |
|---|
| 1747 | 2043 | |
|---|
| 1748 | | - for (plane = 0; plane < vb->num_planes; ++plane) |
|---|
| 1749 | | - call_void_memop(vb, finish, |
|---|
| 1750 | | - vb->planes[plane].mem_priv); |
|---|
| 2044 | + spin_lock_irqsave(&req->lock, flags); |
|---|
| 2045 | + state = req->state; |
|---|
| 2046 | + spin_unlock_irqrestore(&req->lock, flags); |
|---|
| 2047 | + |
|---|
| 2048 | + if (state == MEDIA_REQUEST_STATE_QUEUED) |
|---|
| 2049 | + call_void_vb_qop(vb, buf_request_complete, vb); |
|---|
| 1751 | 2050 | } |
|---|
| 1752 | 2051 | |
|---|
| 1753 | | - if (vb->state != VB2_BUF_STATE_DEQUEUED) { |
|---|
| 1754 | | - vb->state = VB2_BUF_STATE_PREPARED; |
|---|
| 2052 | + __vb2_buf_mem_finish(vb); |
|---|
| 2053 | + |
|---|
| 2054 | + if (vb->prepared) { |
|---|
| 1755 | 2055 | call_void_vb_qop(vb, buf_finish, vb); |
|---|
| 2056 | + vb->prepared = 0; |
|---|
| 1756 | 2057 | } |
|---|
| 1757 | 2058 | __vb2_dqbuf(vb); |
|---|
| 2059 | + |
|---|
| 2060 | + if (vb->req_obj.req) { |
|---|
| 2061 | + media_request_object_unbind(&vb->req_obj); |
|---|
| 2062 | + media_request_object_put(&vb->req_obj); |
|---|
| 2063 | + } |
|---|
| 2064 | + if (vb->request) |
|---|
| 2065 | + media_request_put(vb->request); |
|---|
| 2066 | + vb->request = NULL; |
|---|
| 2067 | + vb->copied_timestamp = 0; |
|---|
| 1758 | 2068 | } |
|---|
| 1759 | 2069 | } |
|---|
| 1760 | 2070 | |
|---|
| .. | .. |
|---|
| 1763 | 2073 | int ret; |
|---|
| 1764 | 2074 | |
|---|
| 1765 | 2075 | if (type != q->type) { |
|---|
| 1766 | | - dprintk(1, "invalid stream type\n"); |
|---|
| 2076 | + dprintk(q, 1, "invalid stream type\n"); |
|---|
| 1767 | 2077 | return -EINVAL; |
|---|
| 1768 | 2078 | } |
|---|
| 1769 | 2079 | |
|---|
| 1770 | 2080 | if (q->streaming) { |
|---|
| 1771 | | - dprintk(3, "already streaming\n"); |
|---|
| 2081 | + dprintk(q, 3, "already streaming\n"); |
|---|
| 1772 | 2082 | return 0; |
|---|
| 1773 | 2083 | } |
|---|
| 1774 | 2084 | |
|---|
| 1775 | 2085 | if (!q->num_buffers) { |
|---|
| 1776 | | - dprintk(1, "no buffers have been allocated\n"); |
|---|
| 2086 | + dprintk(q, 1, "no buffers have been allocated\n"); |
|---|
| 1777 | 2087 | return -EINVAL; |
|---|
| 1778 | 2088 | } |
|---|
| 1779 | 2089 | |
|---|
| 1780 | 2090 | if (q->num_buffers < q->min_buffers_needed) { |
|---|
| 1781 | | - dprintk(1, "need at least %u allocated buffers\n", |
|---|
| 2091 | + dprintk(q, 1, "need at least %u allocated buffers\n", |
|---|
| 1782 | 2092 | q->min_buffers_needed); |
|---|
| 1783 | 2093 | return -EINVAL; |
|---|
| 1784 | 2094 | } |
|---|
| .. | .. |
|---|
| 1798 | 2108 | |
|---|
| 1799 | 2109 | q->streaming = 1; |
|---|
| 1800 | 2110 | |
|---|
| 1801 | | - dprintk(3, "successful\n"); |
|---|
| 2111 | + dprintk(q, 3, "successful\n"); |
|---|
| 1802 | 2112 | return 0; |
|---|
| 1803 | 2113 | } |
|---|
| 1804 | 2114 | EXPORT_SYMBOL_GPL(vb2_core_streamon); |
|---|
| .. | .. |
|---|
| 1814 | 2124 | int vb2_core_streamoff(struct vb2_queue *q, unsigned int type) |
|---|
| 1815 | 2125 | { |
|---|
| 1816 | 2126 | if (type != q->type) { |
|---|
| 1817 | | - dprintk(1, "invalid stream type\n"); |
|---|
| 2127 | + dprintk(q, 1, "invalid stream type\n"); |
|---|
| 1818 | 2128 | return -EINVAL; |
|---|
| 1819 | 2129 | } |
|---|
| 1820 | 2130 | |
|---|
| .. | .. |
|---|
| 1831 | 2141 | q->waiting_for_buffers = !q->is_output; |
|---|
| 1832 | 2142 | q->last_buffer_dequeued = false; |
|---|
| 1833 | 2143 | |
|---|
| 1834 | | - dprintk(3, "successful\n"); |
|---|
| 2144 | + dprintk(q, 3, "successful\n"); |
|---|
| 1835 | 2145 | return 0; |
|---|
| 1836 | 2146 | } |
|---|
| 1837 | 2147 | EXPORT_SYMBOL_GPL(vb2_core_streamoff); |
|---|
| .. | .. |
|---|
| 1844 | 2154 | { |
|---|
| 1845 | 2155 | struct vb2_buffer *vb; |
|---|
| 1846 | 2156 | unsigned int buffer, plane; |
|---|
| 2157 | + |
|---|
| 2158 | + /* |
|---|
| 2159 | + * Sanity checks to ensure the lock is held, MEMORY_MMAP is |
|---|
| 2160 | + * used and fileio isn't active. |
|---|
| 2161 | + */ |
|---|
| 2162 | + lockdep_assert_held(&q->mmap_lock); |
|---|
| 2163 | + |
|---|
| 2164 | + if (q->memory != VB2_MEMORY_MMAP) { |
|---|
| 2165 | + dprintk(q, 1, "queue is not currently set up for mmap\n"); |
|---|
| 2166 | + return -EINVAL; |
|---|
| 2167 | + } |
|---|
| 2168 | + |
|---|
| 2169 | + if (vb2_fileio_is_active(q)) { |
|---|
| 2170 | + dprintk(q, 1, "file io in progress\n"); |
|---|
| 2171 | + return -EBUSY; |
|---|
| 2172 | + } |
|---|
| 1847 | 2173 | |
|---|
| 1848 | 2174 | /* |
|---|
| 1849 | 2175 | * Go over all buffers and their planes, comparing the given offset |
|---|
| .. | .. |
|---|
| 1874 | 2200 | struct dma_buf *dbuf; |
|---|
| 1875 | 2201 | |
|---|
| 1876 | 2202 | if (q->memory != VB2_MEMORY_MMAP) { |
|---|
| 1877 | | - dprintk(1, "queue is not currently set up for mmap\n"); |
|---|
| 2203 | + dprintk(q, 1, "queue is not currently set up for mmap\n"); |
|---|
| 1878 | 2204 | return -EINVAL; |
|---|
| 1879 | 2205 | } |
|---|
| 1880 | 2206 | |
|---|
| 1881 | 2207 | if (!q->mem_ops->get_dmabuf) { |
|---|
| 1882 | | - dprintk(1, "queue does not support DMA buffer exporting\n"); |
|---|
| 2208 | + dprintk(q, 1, "queue does not support DMA buffer exporting\n"); |
|---|
| 1883 | 2209 | return -EINVAL; |
|---|
| 1884 | 2210 | } |
|---|
| 1885 | 2211 | |
|---|
| 1886 | 2212 | if (flags & ~(O_CLOEXEC | O_ACCMODE)) { |
|---|
| 1887 | | - dprintk(1, "queue does support only O_CLOEXEC and access mode flags\n"); |
|---|
| 2213 | + dprintk(q, 1, "queue does support only O_CLOEXEC and access mode flags\n"); |
|---|
| 1888 | 2214 | return -EINVAL; |
|---|
| 1889 | 2215 | } |
|---|
| 1890 | 2216 | |
|---|
| 1891 | 2217 | if (type != q->type) { |
|---|
| 1892 | | - dprintk(1, "invalid buffer type\n"); |
|---|
| 2218 | + dprintk(q, 1, "invalid buffer type\n"); |
|---|
| 1893 | 2219 | return -EINVAL; |
|---|
| 1894 | 2220 | } |
|---|
| 1895 | 2221 | |
|---|
| 1896 | 2222 | if (index >= q->num_buffers) { |
|---|
| 1897 | | - dprintk(1, "buffer index out of range\n"); |
|---|
| 2223 | + dprintk(q, 1, "buffer index out of range\n"); |
|---|
| 1898 | 2224 | return -EINVAL; |
|---|
| 1899 | 2225 | } |
|---|
| 1900 | 2226 | |
|---|
| 1901 | 2227 | vb = q->bufs[index]; |
|---|
| 1902 | 2228 | |
|---|
| 1903 | 2229 | if (plane >= vb->num_planes) { |
|---|
| 1904 | | - dprintk(1, "buffer plane out of range\n"); |
|---|
| 2230 | + dprintk(q, 1, "buffer plane out of range\n"); |
|---|
| 1905 | 2231 | return -EINVAL; |
|---|
| 1906 | 2232 | } |
|---|
| 1907 | 2233 | |
|---|
| 1908 | 2234 | if (vb2_fileio_is_active(q)) { |
|---|
| 1909 | | - dprintk(1, "expbuf: file io in progress\n"); |
|---|
| 2235 | + dprintk(q, 1, "expbuf: file io in progress\n"); |
|---|
| 1910 | 2236 | return -EBUSY; |
|---|
| 1911 | 2237 | } |
|---|
| 1912 | 2238 | |
|---|
| .. | .. |
|---|
| 1915 | 2241 | dbuf = call_ptr_memop(vb, get_dmabuf, vb_plane->mem_priv, |
|---|
| 1916 | 2242 | flags & O_ACCMODE); |
|---|
| 1917 | 2243 | if (IS_ERR_OR_NULL(dbuf)) { |
|---|
| 1918 | | - dprintk(1, "failed to export buffer %d, plane %d\n", |
|---|
| 2244 | + dprintk(q, 1, "failed to export buffer %d, plane %d\n", |
|---|
| 1919 | 2245 | index, plane); |
|---|
| 1920 | 2246 | return -EINVAL; |
|---|
| 1921 | 2247 | } |
|---|
| 1922 | 2248 | |
|---|
| 1923 | 2249 | ret = dma_buf_fd(dbuf, flags & ~O_ACCMODE); |
|---|
| 1924 | 2250 | if (ret < 0) { |
|---|
| 1925 | | - dprintk(3, "buffer %d, plane %d failed to export (%d)\n", |
|---|
| 2251 | + dprintk(q, 3, "buffer %d, plane %d failed to export (%d)\n", |
|---|
| 1926 | 2252 | index, plane, ret); |
|---|
| 1927 | 2253 | dma_buf_put(dbuf); |
|---|
| 1928 | 2254 | return ret; |
|---|
| 1929 | 2255 | } |
|---|
| 1930 | 2256 | |
|---|
| 1931 | | - dprintk(3, "buffer %d, plane %d exported as %d descriptor\n", |
|---|
| 2257 | + dprintk(q, 3, "buffer %d, plane %d exported as %d descriptor\n", |
|---|
| 1932 | 2258 | index, plane, ret); |
|---|
| 1933 | 2259 | *fd = ret; |
|---|
| 1934 | 2260 | |
|---|
| .. | .. |
|---|
| 1944 | 2270 | int ret; |
|---|
| 1945 | 2271 | unsigned long length; |
|---|
| 1946 | 2272 | |
|---|
| 1947 | | - if (q->memory != VB2_MEMORY_MMAP) { |
|---|
| 1948 | | - dprintk(1, "queue is not currently set up for mmap\n"); |
|---|
| 1949 | | - return -EINVAL; |
|---|
| 1950 | | - } |
|---|
| 1951 | | - |
|---|
| 1952 | 2273 | /* |
|---|
| 1953 | 2274 | * Check memory area access mode. |
|---|
| 1954 | 2275 | */ |
|---|
| 1955 | 2276 | if (!(vma->vm_flags & VM_SHARED)) { |
|---|
| 1956 | | - dprintk(1, "invalid vma flags, VM_SHARED needed\n"); |
|---|
| 2277 | + dprintk(q, 1, "invalid vma flags, VM_SHARED needed\n"); |
|---|
| 1957 | 2278 | return -EINVAL; |
|---|
| 1958 | 2279 | } |
|---|
| 1959 | 2280 | if (q->is_output) { |
|---|
| 1960 | 2281 | if (!(vma->vm_flags & VM_WRITE)) { |
|---|
| 1961 | | - dprintk(1, "invalid vma flags, VM_WRITE needed\n"); |
|---|
| 2282 | + dprintk(q, 1, "invalid vma flags, VM_WRITE needed\n"); |
|---|
| 1962 | 2283 | return -EINVAL; |
|---|
| 1963 | 2284 | } |
|---|
| 1964 | 2285 | } else { |
|---|
| 1965 | 2286 | if (!(vma->vm_flags & VM_READ)) { |
|---|
| 1966 | | - dprintk(1, "invalid vma flags, VM_READ needed\n"); |
|---|
| 2287 | + dprintk(q, 1, "invalid vma flags, VM_READ needed\n"); |
|---|
| 1967 | 2288 | return -EINVAL; |
|---|
| 1968 | 2289 | } |
|---|
| 1969 | 2290 | } |
|---|
| 1970 | 2291 | |
|---|
| 1971 | 2292 | mutex_lock(&q->mmap_lock); |
|---|
| 1972 | 2293 | |
|---|
| 1973 | | - if (vb2_fileio_is_active(q)) { |
|---|
| 1974 | | - dprintk(1, "mmap: file io in progress\n"); |
|---|
| 1975 | | - ret = -EBUSY; |
|---|
| 1976 | | - goto unlock; |
|---|
| 1977 | | - } |
|---|
| 1978 | | - |
|---|
| 1979 | 2294 | /* |
|---|
| 1980 | | - * Find the plane corresponding to the offset passed by userspace. |
|---|
| 2295 | + * Find the plane corresponding to the offset passed by userspace. This |
|---|
| 2296 | + * will return an error if not MEMORY_MMAP or file I/O is in progress. |
|---|
| 1981 | 2297 | */ |
|---|
| 1982 | 2298 | ret = __find_plane_by_offset(q, off, &buffer, &plane); |
|---|
| 1983 | 2299 | if (ret) |
|---|
| .. | .. |
|---|
| 1992 | 2308 | */ |
|---|
| 1993 | 2309 | length = PAGE_ALIGN(vb->planes[plane].length); |
|---|
| 1994 | 2310 | if (length < (vma->vm_end - vma->vm_start)) { |
|---|
| 1995 | | - dprintk(1, |
|---|
| 2311 | + dprintk(q, 1, |
|---|
| 1996 | 2312 | "MMAP invalid, as it would overflow buffer length\n"); |
|---|
| 1997 | 2313 | ret = -EINVAL; |
|---|
| 1998 | 2314 | goto unlock; |
|---|
| 1999 | 2315 | } |
|---|
| 2316 | + |
|---|
| 2317 | + /* |
|---|
| 2318 | + * vm_pgoff is treated in V4L2 API as a 'cookie' to select a buffer, |
|---|
| 2319 | + * not as a in-buffer offset. We always want to mmap a whole buffer |
|---|
| 2320 | + * from its beginning. |
|---|
| 2321 | + */ |
|---|
| 2322 | + vma->vm_pgoff = 0; |
|---|
| 2000 | 2323 | |
|---|
| 2001 | 2324 | ret = call_memop(vb, mmap, vb->planes[plane].mem_priv, vma); |
|---|
| 2002 | 2325 | |
|---|
| .. | .. |
|---|
| 2005 | 2328 | if (ret) |
|---|
| 2006 | 2329 | return ret; |
|---|
| 2007 | 2330 | |
|---|
| 2008 | | - dprintk(3, "buffer %d, plane %d successfully mapped\n", buffer, plane); |
|---|
| 2331 | + dprintk(q, 3, "buffer %d, plane %d successfully mapped\n", buffer, plane); |
|---|
| 2009 | 2332 | return 0; |
|---|
| 2010 | 2333 | } |
|---|
| 2011 | 2334 | EXPORT_SYMBOL_GPL(vb2_mmap); |
|---|
| .. | .. |
|---|
| 2023 | 2346 | void *vaddr; |
|---|
| 2024 | 2347 | int ret; |
|---|
| 2025 | 2348 | |
|---|
| 2026 | | - if (q->memory != VB2_MEMORY_MMAP) { |
|---|
| 2027 | | - dprintk(1, "queue is not currently set up for mmap\n"); |
|---|
| 2028 | | - return -EINVAL; |
|---|
| 2029 | | - } |
|---|
| 2349 | + mutex_lock(&q->mmap_lock); |
|---|
| 2030 | 2350 | |
|---|
| 2031 | 2351 | /* |
|---|
| 2032 | | - * Find the plane corresponding to the offset passed by userspace. |
|---|
| 2352 | + * Find the plane corresponding to the offset passed by userspace. This |
|---|
| 2353 | + * will return an error if not MEMORY_MMAP or file I/O is in progress. |
|---|
| 2033 | 2354 | */ |
|---|
| 2034 | 2355 | ret = __find_plane_by_offset(q, off, &buffer, &plane); |
|---|
| 2035 | 2356 | if (ret) |
|---|
| 2036 | | - return ret; |
|---|
| 2357 | + goto unlock; |
|---|
| 2037 | 2358 | |
|---|
| 2038 | 2359 | vb = q->bufs[buffer]; |
|---|
| 2039 | 2360 | |
|---|
| 2040 | 2361 | vaddr = vb2_plane_vaddr(vb, plane); |
|---|
| 2362 | + mutex_unlock(&q->mmap_lock); |
|---|
| 2041 | 2363 | return vaddr ? (unsigned long)vaddr : -EINVAL; |
|---|
| 2364 | + |
|---|
| 2365 | +unlock: |
|---|
| 2366 | + mutex_unlock(&q->mmap_lock); |
|---|
| 2367 | + return ret; |
|---|
| 2042 | 2368 | } |
|---|
| 2043 | 2369 | EXPORT_SYMBOL_GPL(vb2_get_unmapped_area); |
|---|
| 2044 | 2370 | #endif |
|---|
| .. | .. |
|---|
| 2057 | 2383 | WARN_ON(!q->ops->buf_queue)) |
|---|
| 2058 | 2384 | return -EINVAL; |
|---|
| 2059 | 2385 | |
|---|
| 2386 | + if (WARN_ON(q->requires_requests && !q->supports_requests)) |
|---|
| 2387 | + return -EINVAL; |
|---|
| 2388 | + |
|---|
| 2060 | 2389 | INIT_LIST_HEAD(&q->queued_list); |
|---|
| 2061 | 2390 | INIT_LIST_HEAD(&q->done_list); |
|---|
| 2062 | 2391 | spin_lock_init(&q->done_lock); |
|---|
| .. | .. |
|---|
| 2072 | 2401 | q->dma_dir = DMA_BIDIRECTIONAL; |
|---|
| 2073 | 2402 | else |
|---|
| 2074 | 2403 | q->dma_dir = q->is_output ? DMA_TO_DEVICE : DMA_FROM_DEVICE; |
|---|
| 2404 | + |
|---|
| 2405 | + if (q->name[0] == '\0') |
|---|
| 2406 | + snprintf(q->name, sizeof(q->name), "%s-%p", |
|---|
| 2407 | + q->is_output ? "out" : "cap", q); |
|---|
| 2075 | 2408 | |
|---|
| 2076 | 2409 | return 0; |
|---|
| 2077 | 2410 | } |
|---|
| .. | .. |
|---|
| 2100 | 2433 | return 0; |
|---|
| 2101 | 2434 | if (q->is_output && !(req_events & (EPOLLOUT | EPOLLWRNORM))) |
|---|
| 2102 | 2435 | return 0; |
|---|
| 2436 | + |
|---|
| 2437 | + poll_wait(file, &q->done_wq, wait); |
|---|
| 2103 | 2438 | |
|---|
| 2104 | 2439 | /* |
|---|
| 2105 | 2440 | * Start file I/O emulator only if streaming API has not been used yet. |
|---|
| .. | .. |
|---|
| 2152 | 2487 | */ |
|---|
| 2153 | 2488 | if (q->last_buffer_dequeued) |
|---|
| 2154 | 2489 | return EPOLLIN | EPOLLRDNORM; |
|---|
| 2155 | | - |
|---|
| 2156 | | - poll_wait(file, &q->done_wq, wait); |
|---|
| 2157 | 2490 | } |
|---|
| 2158 | 2491 | |
|---|
| 2159 | 2492 | /* |
|---|
| .. | .. |
|---|
| 2261 | 2594 | */ |
|---|
| 2262 | 2595 | count = 1; |
|---|
| 2263 | 2596 | |
|---|
| 2264 | | - dprintk(3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n", |
|---|
| 2597 | + dprintk(q, 3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n", |
|---|
| 2265 | 2598 | (read) ? "read" : "write", count, q->fileio_read_once, |
|---|
| 2266 | 2599 | q->fileio_write_immediately); |
|---|
| 2267 | 2600 | |
|---|
| .. | .. |
|---|
| 2313 | 2646 | * Queue all buffers. |
|---|
| 2314 | 2647 | */ |
|---|
| 2315 | 2648 | for (i = 0; i < q->num_buffers; i++) { |
|---|
| 2316 | | - ret = vb2_core_qbuf(q, i, NULL); |
|---|
| 2649 | + ret = vb2_core_qbuf(q, i, NULL, NULL); |
|---|
| 2317 | 2650 | if (ret) |
|---|
| 2318 | 2651 | goto err_reqbufs; |
|---|
| 2319 | 2652 | fileio->bufs[i].queued = 1; |
|---|
| .. | .. |
|---|
| 2359 | 2692 | fileio->count = 0; |
|---|
| 2360 | 2693 | vb2_core_reqbufs(q, fileio->memory, &fileio->count); |
|---|
| 2361 | 2694 | kfree(fileio); |
|---|
| 2362 | | - dprintk(3, "file io emulator closed\n"); |
|---|
| 2695 | + dprintk(q, 3, "file io emulator closed\n"); |
|---|
| 2363 | 2696 | } |
|---|
| 2364 | 2697 | return 0; |
|---|
| 2365 | 2698 | } |
|---|
| .. | .. |
|---|
| 2388 | 2721 | unsigned index; |
|---|
| 2389 | 2722 | int ret; |
|---|
| 2390 | 2723 | |
|---|
| 2391 | | - dprintk(3, "mode %s, offset %ld, count %zd, %sblocking\n", |
|---|
| 2724 | + dprintk(q, 3, "mode %s, offset %ld, count %zd, %sblocking\n", |
|---|
| 2392 | 2725 | read ? "read" : "write", (long)*ppos, count, |
|---|
| 2393 | 2726 | nonblock ? "non" : ""); |
|---|
| 2394 | 2727 | |
|---|
| .. | .. |
|---|
| 2396 | 2729 | return -EINVAL; |
|---|
| 2397 | 2730 | |
|---|
| 2398 | 2731 | if (q->waiting_in_dqbuf) { |
|---|
| 2399 | | - dprintk(3, "another dup()ped fd is %s\n", |
|---|
| 2732 | + dprintk(q, 3, "another dup()ped fd is %s\n", |
|---|
| 2400 | 2733 | read ? "reading" : "writing"); |
|---|
| 2401 | 2734 | return -EBUSY; |
|---|
| 2402 | 2735 | } |
|---|
| .. | .. |
|---|
| 2406 | 2739 | */ |
|---|
| 2407 | 2740 | if (!vb2_fileio_is_active(q)) { |
|---|
| 2408 | 2741 | ret = __vb2_init_fileio(q, read); |
|---|
| 2409 | | - dprintk(3, "vb2_init_fileio result: %d\n", ret); |
|---|
| 2742 | + dprintk(q, 3, "vb2_init_fileio result: %d\n", ret); |
|---|
| 2410 | 2743 | if (ret) |
|---|
| 2411 | 2744 | return ret; |
|---|
| 2412 | 2745 | } |
|---|
| .. | .. |
|---|
| 2423 | 2756 | * Call vb2_dqbuf to get buffer back. |
|---|
| 2424 | 2757 | */ |
|---|
| 2425 | 2758 | ret = vb2_core_dqbuf(q, &index, NULL, nonblock); |
|---|
| 2426 | | - dprintk(5, "vb2_dqbuf result: %d\n", ret); |
|---|
| 2759 | + dprintk(q, 5, "vb2_dqbuf result: %d\n", ret); |
|---|
| 2427 | 2760 | if (ret) |
|---|
| 2428 | 2761 | return ret; |
|---|
| 2429 | 2762 | fileio->dq_count += 1; |
|---|
| .. | .. |
|---|
| 2454 | 2787 | */ |
|---|
| 2455 | 2788 | if (buf->pos + count > buf->size) { |
|---|
| 2456 | 2789 | count = buf->size - buf->pos; |
|---|
| 2457 | | - dprintk(5, "reducing read count: %zd\n", count); |
|---|
| 2790 | + dprintk(q, 5, "reducing read count: %zd\n", count); |
|---|
| 2458 | 2791 | } |
|---|
| 2459 | 2792 | |
|---|
| 2460 | 2793 | /* |
|---|
| 2461 | 2794 | * Transfer data to userspace. |
|---|
| 2462 | 2795 | */ |
|---|
| 2463 | | - dprintk(3, "copying %zd bytes - buffer %d, offset %u\n", |
|---|
| 2796 | + dprintk(q, 3, "copying %zd bytes - buffer %d, offset %u\n", |
|---|
| 2464 | 2797 | count, index, buf->pos); |
|---|
| 2465 | 2798 | if (read) |
|---|
| 2466 | 2799 | ret = copy_to_user(data, buf->vaddr + buf->pos, count); |
|---|
| 2467 | 2800 | else |
|---|
| 2468 | 2801 | ret = copy_from_user(buf->vaddr + buf->pos, data, count); |
|---|
| 2469 | 2802 | if (ret) { |
|---|
| 2470 | | - dprintk(3, "error copying data\n"); |
|---|
| 2803 | + dprintk(q, 3, "error copying data\n"); |
|---|
| 2471 | 2804 | return -EFAULT; |
|---|
| 2472 | 2805 | } |
|---|
| 2473 | 2806 | |
|---|
| .. | .. |
|---|
| 2487 | 2820 | * Check if this is the last buffer to read. |
|---|
| 2488 | 2821 | */ |
|---|
| 2489 | 2822 | if (read && fileio->read_once && fileio->dq_count == 1) { |
|---|
| 2490 | | - dprintk(3, "read limit reached\n"); |
|---|
| 2823 | + dprintk(q, 3, "read limit reached\n"); |
|---|
| 2491 | 2824 | return __vb2_cleanup_fileio(q); |
|---|
| 2492 | 2825 | } |
|---|
| 2493 | 2826 | |
|---|
| .. | .. |
|---|
| 2498 | 2831 | |
|---|
| 2499 | 2832 | if (copy_timestamp) |
|---|
| 2500 | 2833 | b->timestamp = ktime_get_ns(); |
|---|
| 2501 | | - ret = vb2_core_qbuf(q, index, NULL); |
|---|
| 2502 | | - dprintk(5, "vb2_dbuf result: %d\n", ret); |
|---|
| 2834 | + ret = vb2_core_qbuf(q, index, NULL, NULL); |
|---|
| 2835 | + dprintk(q, 5, "vb2_dbuf result: %d\n", ret); |
|---|
| 2503 | 2836 | if (ret) |
|---|
| 2504 | 2837 | return ret; |
|---|
| 2505 | 2838 | |
|---|
| .. | .. |
|---|
| 2586 | 2919 | if (!threadio->stop) |
|---|
| 2587 | 2920 | ret = vb2_core_dqbuf(q, &index, NULL, 0); |
|---|
| 2588 | 2921 | call_void_qop(q, wait_prepare, q); |
|---|
| 2589 | | - dprintk(5, "file io: vb2_dqbuf result: %d\n", ret); |
|---|
| 2922 | + dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret); |
|---|
| 2590 | 2923 | if (!ret) |
|---|
| 2591 | 2924 | vb = q->bufs[index]; |
|---|
| 2592 | 2925 | } |
|---|
| .. | .. |
|---|
| 2601 | 2934 | if (copy_timestamp) |
|---|
| 2602 | 2935 | vb->timestamp = ktime_get_ns(); |
|---|
| 2603 | 2936 | if (!threadio->stop) |
|---|
| 2604 | | - ret = vb2_core_qbuf(q, vb->index, NULL); |
|---|
| 2937 | + ret = vb2_core_qbuf(q, vb->index, NULL, NULL); |
|---|
| 2605 | 2938 | call_void_qop(q, wait_prepare, q); |
|---|
| 2606 | 2939 | if (ret || threadio->stop) |
|---|
| 2607 | 2940 | break; |
|---|
| .. | .. |
|---|
| 2640 | 2973 | threadio->priv = priv; |
|---|
| 2641 | 2974 | |
|---|
| 2642 | 2975 | ret = __vb2_init_fileio(q, !q->is_output); |
|---|
| 2643 | | - dprintk(3, "file io: vb2_init_fileio result: %d\n", ret); |
|---|
| 2976 | + dprintk(q, 3, "file io: vb2_init_fileio result: %d\n", ret); |
|---|
| 2644 | 2977 | if (ret) |
|---|
| 2645 | 2978 | goto nomem; |
|---|
| 2646 | 2979 | q->threadio = threadio; |
|---|