Preparations for future V4L2_MEMORY_FLAG_NON_COHERENT support. Extend the vb2_core_reqbufs() parameters list to accept requests' ->flags, which will be used for memory coherency configuration. An attempt to allocate a buffer with coherency requirements that do not match the queue's consistency model will fail.
Unified · Split
| @@ -738,11 +738,30 @@ int vb2_verify_memory_type(struct vb2_queue *q, · 737 unmodified lines | ||
| 738 | 738 | } |
| 739 | 739 | EXPORT_SYMBOL(vb2_verify_memory_type); |
| 740 | 740 | |
| 741 | +static void set_queue_coherency(struct vb2_queue *q, bool non_coherent_mem) | |
| 742 | +{ | |
| 743 | + q->non_coherent_mem = 0; | |
| 744 | + | |
| 745 | + if (!vb2_queue_allows_cache_hints(q)) | |
| 746 | + return; | |
| 747 | + q->non_coherent_mem = non_coherent_mem; | |
| 748 | +} | |
| 749 | + | |
| 750 | +static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem) | |
| 751 | +{ | |
| 752 | + if (non_coherent_mem != q->non_coherent_mem) { | |
| 753 | + dprintk(q, 1, "memory coherency model mismatch\n"); | |
| 754 | + return false; | |
| 755 | + } | |
| 756 | + return true; | |
| 757 | +} | |
| 758 | + | |
| 741 | 759 | int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, |
| 742 | − unsigned int *count) | |
| 760 | + unsigned int flags, unsigned int *count) | |
| 743 | 761 | { |
| 744 | 762 | unsigned int num_buffers, allocated_buffers, num_planes = 0; |
| 745 | 763 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; |
| 764 | + bool non_coherent_mem = false; | |
| 746 | 765 | unsigned int i; |
| 747 | 766 | int ret; |
| 748 | 767 | |
| @@ -757,7 +776,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · 8 unmodified lines | ||
| 757 | 776 | } |
| 758 | 777 | |
| 759 | 778 | if (*count == 0 || q->num_buffers != 0 || |
| 760 | − (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory)) { | |
| 779 | + (q->memory != VB2_MEMORY_UNKNOWN && q->memory != memory) || | |
| 780 | + !verify_coherency_flags(q, non_coherent_mem)) { | |
| 761 | 781 | /* |
| 762 | 782 | * We already have buffers allocated, so first check if they |
| 763 | 783 | * are not in use and can be freed. |
| @@ -794,6 +814,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · 30 unmodified lines | ||
| 794 | 814 | num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME); |
| 795 | 815 | memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); |
| 796 | 816 | q->memory = memory; |
| 817 | + set_queue_coherency(q, non_coherent_mem); | |
| 797 | 818 | |
| 798 | 819 | /* |
| 799 | 820 | * Ask the driver how many buffers and planes per buffer it requires. |
| @@ -878,12 +899,13 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · 78 unmodified lines | ||
| 878 | 899 | EXPORT_SYMBOL_GPL(vb2_core_reqbufs); |
| 879 | 900 | |
| 880 | 901 | int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, |
| 881 | − unsigned int *count, | |
| 902 | + unsigned int flags, unsigned int *count, | |
| 882 | 903 | unsigned int requested_planes, |
| 883 | 904 | const unsigned int requested_sizes[]) |
| 884 | 905 | { |
| 885 | 906 | unsigned int num_planes = 0, num_buffers, allocated_buffers; |
| 886 | 907 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; |
| 908 | + bool non_coherent_mem = false; | |
| 887 | 909 | int ret; |
| 888 | 910 | |
| 889 | 911 | if (q->num_buffers == VB2_MAX_FRAME) { |
| @@ -899,11 +921,14 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, · 9 unmodified lines | ||
| 899 | 921 | memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); |
| 900 | 922 | q->memory = memory; |
| 901 | 923 | q->waiting_for_buffers = !q->is_output; |
| 924 | + set_queue_coherency(q, non_coherent_mem); | |
| 902 | 925 | } else { |
| 903 | 926 | if (q->memory != memory) { |
| 904 | 927 | dprintk(q, 1, "memory model mismatch\n"); |
| 905 | 928 | return -EINVAL; |
| 906 | 929 | } |
| 930 | + if (!verify_coherency_flags(q, non_coherent_mem)) | |
| 931 | + return -EINVAL; | |
| 907 | 932 | } |
| 908 | 933 | |
| 909 | 934 | num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers); |
| @@ -2608,7 +2633,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) · 1698 unmodified lines | ||
| 2608 | 2633 | fileio->memory = VB2_MEMORY_MMAP; |
| 2609 | 2634 | fileio->type = q->type; |
| 2610 | 2635 | q->fileio = fileio; |
| 2611 | − ret = vb2_core_reqbufs(q, fileio->memory, &fileio->count); | |
| 2636 | + ret = vb2_core_reqbufs(q, fileio->memory, 0, &fileio->count); | |
| 2612 | 2637 | if (ret) |
| 2613 | 2638 | goto err_kfree; |
| 2614 | 2639 | |
| @@ -2665,7 +2690,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) · 50 unmodified lines | ||
| 2665 | 2690 | |
| 2666 | 2691 | err_reqbufs: |
| 2667 | 2692 | fileio->count = 0; |
| 2668 | − vb2_core_reqbufs(q, fileio->memory, &fileio->count); | |
| 2693 | + vb2_core_reqbufs(q, fileio->memory, 0, &fileio->count); | |
| 2669 | 2694 | |
| 2670 | 2695 | err_kfree: |
| 2671 | 2696 | q->fileio = NULL; |
| @@ -2685,7 +2710,7 @@ static int __vb2_cleanup_fileio(struct vb2_queue *q) · 13 unmodified lines | ||
| 2685 | 2710 | vb2_core_streamoff(q, q->type); |
| 2686 | 2711 | q->fileio = NULL; |
| 2687 | 2712 | fileio->count = 0; |
| 2688 | − vb2_core_reqbufs(q, fileio->memory, &fileio->count); | |
| 2713 | + vb2_core_reqbufs(q, fileio->memory, 0, &fileio->count); | |
| 2689 | 2714 | kfree(fileio); |
| 2690 | 2715 | dprintk(q, 3, "file io emulator closed\n"); |
| 2691 | 2716 | } |
| @@ -697,7 +697,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) · 696 unmodified lines | ||
| 697 | 697 | int ret = vb2_verify_memory_type(q, req->memory, req->type); |
| 698 | 698 | |
| 699 | 699 | fill_buf_caps(q, &req->capabilities); |
| 700 | − return ret ? ret : vb2_core_reqbufs(q, req->memory, &req->count); | |
| 700 | + return ret ? ret : vb2_core_reqbufs(q, req->memory, 0, &req->count); | |
| 701 | 701 | } |
| 702 | 702 | EXPORT_SYMBOL_GPL(vb2_reqbufs); |
| 703 | 703 | |
| @@ -772,6 +772,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) · 68 unmodified lines | ||
| 772 | 772 | if (requested_sizes[i] == 0) |
| 773 | 773 | return -EINVAL; |
| 774 | 774 | return ret ? ret : vb2_core_create_bufs(q, create->memory, |
| 775 | + 0, | |
| 775 | 776 | &create->count, |
| 776 | 777 | requested_planes, |
| 777 | 778 | requested_sizes); |
| @@ -974,7 +975,7 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, · 196 unmodified lines | ||
| 974 | 975 | return res; |
| 975 | 976 | if (vb2_queue_is_busy(vdev, file)) |
| 976 | 977 | return -EBUSY; |
| 977 | − res = vb2_core_reqbufs(vdev->queue, p->memory, &p->count); | |
| 978 | + res = vb2_core_reqbufs(vdev->queue, p->memory, 0, &p->count); | |
| 978 | 979 | /* If count == 0, then the owner has released all buffers and he |
| 979 | 980 | is no longer owner of the queue. Otherwise we have a new owner. */ |
| 980 | 981 | if (res == 0) |
| @@ -342,7 +342,7 @@ int dvb_vb2_reqbufs(struct dvb_vb2_ctx *ctx, struct dmx_requestbuffers *req) · 341 unmodified lines | ||
| 342 | 342 | |
| 343 | 343 | ctx->buf_siz = req->size; |
| 344 | 344 | ctx->buf_cnt = req->count; |
| 345 | − ret = vb2_core_reqbufs(&ctx->vb_q, VB2_MEMORY_MMAP, &req->count); | |
| 345 | + ret = vb2_core_reqbufs(&ctx->vb_q, VB2_MEMORY_MMAP, 0, &req->count); | |
| 346 | 346 | if (ret) { |
| 347 | 347 | ctx->state = DVB_VB2_STATE_NONE; |
| 348 | 348 | dprintk(1, "[%s] count=%d size=%d errno=%d\n", ctx->name, |
| @@ -504,6 +504,8 @@ struct vb2_buf_ops { · 503 unmodified lines | ||
| 504 | 504 | * @allow_cache_hints: when set user-space can pass cache management hints in |
| 505 | 505 | * order to skip cache flush/invalidation on ->prepare() or/and |
| 506 | 506 | * ->finish(). |
| 507 | + * @non_coherent_mem: when set queue will attempt to allocate buffers using | |
| 508 | + * non-coherent memory. | |
| 507 | 509 | * @lock: pointer to a mutex that protects the &struct vb2_queue. The |
| 508 | 510 | * driver can set this to a mutex to let the v4l2 core serialize |
| 509 | 511 | * the queuing ioctls. If the driver wants to handle locking |
| @@ -583,6 +585,7 @@ struct vb2_queue { · 73 unmodified lines | ||
| 583 | 585 | unsigned int uses_qbuf:1; |
| 584 | 586 | unsigned int uses_requests:1; |
| 585 | 587 | unsigned int allow_cache_hints:1; |
| 588 | + unsigned int non_coherent_mem:1; | |
| 586 | 589 | |
| 587 | 590 | struct mutex *lock; |
| 588 | 591 | void *owner; |
| @@ -748,6 +751,8 @@ void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb); · 159 unmodified lines | ||
| 748 | 751 | * vb2_core_reqbufs() - Initiate streaming. |
| 749 | 752 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
| 750 | 753 | * @memory: memory type, as defined by &enum vb2_memory. |
| 754 | + * @flags: auxiliary queue/buffer management flags. Currently, the only | |
| 755 | + * used flag is %V4L2_MEMORY_FLAG_NON_COHERENT. | |
| 751 | 756 | * @count: requested buffer count. |
| 752 | 757 | * |
| 753 | 758 | * Videobuf2 core helper to implement VIDIOC_REQBUF() operation. It is called |
| @@ -772,12 +777,13 @@ void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb); · 18 unmodified lines | ||
| 772 | 777 | * Return: returns zero on success; an error code otherwise. |
| 773 | 778 | */ |
| 774 | 779 | int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, |
| 775 | − unsigned int *count); | |
| 780 | + unsigned int flags, unsigned int *count); | |
| 776 | 781 | |
| 777 | 782 | /** |
| 778 | 783 | * vb2_core_create_bufs() - Allocate buffers and any required auxiliary structs |
| 779 | 784 | * @q: pointer to &struct vb2_queue with videobuf2 queue. |
| 780 | 785 | * @memory: memory type, as defined by &enum vb2_memory. |
| 786 | + * @flags: auxiliary queue/buffer management flags. | |
| 781 | 787 | * @count: requested buffer count. |
| 782 | 788 | * @requested_planes: number of planes requested. |
| 783 | 789 | * @requested_sizes: array with the size of the planes. |
| @@ -795,7 +801,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · 11 unmodified lines | ||
| 795 | 801 | * Return: returns zero on success; an error code otherwise. |
| 796 | 802 | */ |
| 797 | 803 | int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, |
| 798 | − unsigned int *count, | |
| 804 | + unsigned int flags, unsigned int *count, | |
| 799 | 805 | unsigned int requested_planes, |
| 800 | 806 | const unsigned int requested_sizes[]); |
| 801 | 807 | |