This patch lets user-space request a non-coherent memory allocation during CREATE_BUFS and REQBUFS ioctl calls. = CREATE_BUFS struct v4l2_create_buffers has seven 4-byte reserved areas, so reserved[0] is renamed to ->flags. The struct, thus, now has six reserved 4-byte regions. = CREATE_BUFS32 struct v4l2_create_buffers32 has seven 4-byte reserved areas, so reserved[0] is renamed to ->flags. The struct, thus, now has six reserved 4-byte regions. = REQBUFS We use one byte of a 4 byte ->reserved[1] member of struct v4l2_requestbuffers. The struct, thus, now has reserved 3 bytes.
Unified · Split
| @@ -113,7 +113,12 @@ than the number requested. · 112 unmodified lines | |||
| 113 | ``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type. | 113 | ``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type. |
| 114 | 114 | ||
| 115 | * - __u32 | 115 | * - __u32 |
| 116 | - ``reserved``\ [7] | 116 | - ``flags`` |
| 117 | - Specifies additional buffer management attributes. | ||
| 118 | See :ref:`memory-flags`. | ||
| 119 | |||
| 120 | * - __u32 | ||
| 121 | - ``reserved``\ [6] | ||
| 117 | - A place holder for future extensions. Drivers and applications | 122 | - A place holder for future extensions. Drivers and applications |
| 118 | must set the array to zero. | 123 | must set the array to zero. |
| 119 | 124 | ||
| @@ -104,10 +104,13 @@ aborting or finishing any DMA in progress, an implicit · 103 unmodified lines | |||
| 104 | ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will | 104 | ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will |
| 105 | free any previously allocated buffers, so this is typically something | 105 | free any previously allocated buffers, so this is typically something |
| 106 | that will be done at the start of the application. | 106 | that will be done at the start of the application. |
| 107 | * - __u32 | 107 | * - __u8 |
| 108 | - ``reserved``\ [1] | 108 | - ``flags`` |
| 109 | - A place holder for future extensions. Drivers and applications | 109 | - Specifies additional buffer management attributes. |
| 110 | must set the array to zero. | 110 | See :ref:`memory-flags`. |
| 111 | * - __u8 | ||
| 112 | - ``reserved``\ [3] | ||
| 113 | - Reserved for future extensions. | ||
| 111 | 114 | ||
| 112 | .. _v4l2-buf-capabilities: | 115 | .. _v4l2-buf-capabilities: |
| 113 | .. _V4L2-BUF-CAP-SUPPORTS-MMAP: | 116 | .. _V4L2-BUF-CAP-SUPPORTS-MMAP: |
| @@ -761,7 +761,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · 760 unmodified lines | |||
| 761 | { | 761 | { |
| 762 | unsigned int num_buffers, allocated_buffers, num_planes = 0; | 762 | unsigned int num_buffers, allocated_buffers, num_planes = 0; |
| 763 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; | 763 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; |
| 764 | bool non_coherent_mem = false; | 764 | bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; |
| 765 | unsigned int i; | 765 | unsigned int i; |
| 766 | int ret; | 766 | int ret; |
| 767 | 767 | ||
| @@ -905,7 +905,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, · 137 unmodified lines | |||
| 905 | { | 905 | { |
| 906 | unsigned int num_planes = 0, num_buffers, allocated_buffers; | 906 | unsigned int num_planes = 0, num_buffers, allocated_buffers; |
| 907 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; | 907 | unsigned plane_sizes[VB2_MAX_PLANES] = { }; |
| 908 | bool non_coherent_mem = false; | 908 | bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; |
| 909 | int ret; | 909 | int ret; |
| 910 | 910 | ||
| 911 | if (q->num_buffers == VB2_MAX_FRAME) { | 911 | if (q->num_buffers == VB2_MAX_FRAME) { |
| @@ -692,12 +692,32 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) · 691 unmodified lines | |||
| 692 | #endif | 692 | #endif |
| 693 | } | 693 | } |
| 694 | 694 | ||
| 695 | static void validate_memory_flags(struct vb2_queue *q, | ||
| 696 | int memory, | ||
| 697 | u32 *flags) | ||
| 698 | { | ||
| 699 | if (!q->allow_cache_hints || memory != V4L2_MEMORY_MMAP) { | ||
| 700 | /* | ||
| 701 | * This needs to clear V4L2_MEMORY_FLAG_NON_COHERENT only, | ||
| 702 | * but in order to avoid bugs we zero out all bits. | ||
| 703 | */ | ||
| 704 | *flags = 0; | ||
| 705 | } else { | ||
| 706 | /* Clear all unknown flags. */ | ||
| 707 | *flags &= V4L2_MEMORY_FLAG_NON_COHERENT; | ||
| 708 | } | ||
| 709 | } | ||
| 710 | |||
| 695 | int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) | 711 | int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) |
| 696 | { | 712 | { |
| 697 | int ret = vb2_verify_memory_type(q, req->memory, req->type); | 713 | int ret = vb2_verify_memory_type(q, req->memory, req->type); |
| 714 | u32 flags = req->flags; | ||
| 698 | 715 | ||
| 699 | fill_buf_caps(q, &req->capabilities); | 716 | fill_buf_caps(q, &req->capabilities); |
| 700 | return ret ? ret : vb2_core_reqbufs(q, req->memory, 0, &req->count); | 717 | validate_memory_flags(q, req->memory, &flags); |
| 718 | req->flags = flags; | ||
| 719 | return ret ? ret : vb2_core_reqbufs(q, req->memory, | ||
| 720 | req->flags, &req->count); | ||
| 701 | } | 721 | } |
| 702 | EXPORT_SYMBOL_GPL(vb2_reqbufs); | 722 | EXPORT_SYMBOL_GPL(vb2_reqbufs); |
| 703 | 723 | ||
| @@ -729,6 +749,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) · 25 unmodified lines | |||
| 729 | unsigned i; | 749 | unsigned i; |
| 730 | 750 | ||
| 731 | fill_buf_caps(q, &create->capabilities); | 751 | fill_buf_caps(q, &create->capabilities); |
| 752 | validate_memory_flags(q, create->memory, &create->flags); | ||
| 732 | create->index = q->num_buffers; | 753 | create->index = q->num_buffers; |
| 733 | if (create->count == 0) | 754 | if (create->count == 0) |
| 734 | return ret != -EBUSY ? ret : 0; | 755 | return ret != -EBUSY ? ret : 0; |
| @@ -772,7 +793,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) · 37 unmodified lines | |||
| 772 | if (requested_sizes[i] == 0) | 793 | if (requested_sizes[i] == 0) |
| 773 | return -EINVAL; | 794 | return -EINVAL; |
| 774 | return ret ? ret : vb2_core_create_bufs(q, create->memory, | 795 | return ret ? ret : vb2_core_create_bufs(q, create->memory, |
| 775 | 0, | 796 | create->flags, |
| 776 | &create->count, | 797 | &create->count, |
| 777 | requested_planes, | 798 | requested_planes, |
| 778 | requested_sizes); | 799 | requested_sizes); |
| @@ -969,13 +990,16 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, · 190 unmodified lines | |||
| 969 | { | 990 | { |
| 970 | struct video_device *vdev = video_devdata(file); | 991 | struct video_device *vdev = video_devdata(file); |
| 971 | int res = vb2_verify_memory_type(vdev->queue, p->memory, p->type); | 992 | int res = vb2_verify_memory_type(vdev->queue, p->memory, p->type); |
| 993 | u32 flags = p->flags; | ||
| 972 | 994 | ||
| 973 | fill_buf_caps(vdev->queue, &p->capabilities); | 995 | fill_buf_caps(vdev->queue, &p->capabilities); |
| 996 | validate_memory_flags(vdev->queue, p->memory, &flags); | ||
| 997 | p->flags = flags; | ||
| 974 | if (res) | 998 | if (res) |
| 975 | return res; | 999 | return res; |
| 976 | if (vb2_queue_is_busy(vdev, file)) | 1000 | if (vb2_queue_is_busy(vdev, file)) |
| 977 | return -EBUSY; | 1001 | return -EBUSY; |
| 978 | res = vb2_core_reqbufs(vdev->queue, p->memory, 0, &p->count); | 1002 | res = vb2_core_reqbufs(vdev->queue, p->memory, p->flags, &p->count); |
| 979 | /* If count == 0, then the owner has released all buffers and he | 1003 | /* If count == 0, then the owner has released all buffers and he |
| 980 | is no longer owner of the queue. Otherwise we have a new owner. */ | 1004 | is no longer owner of the queue. Otherwise we have a new owner. */ |
| 981 | if (res == 0) | 1005 | if (res == 0) |
| @@ -993,6 +1017,7 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv, · 11 unmodified lines | |||
| 993 | 1017 | ||
| 994 | p->index = vdev->queue->num_buffers; | 1018 | p->index = vdev->queue->num_buffers; |
| 995 | fill_buf_caps(vdev->queue, &p->capabilities); | 1019 | fill_buf_caps(vdev->queue, &p->capabilities); |
| 1020 | validate_memory_flags(vdev->queue, p->memory, &p->flags); | ||
| 996 | /* | 1021 | /* |
| 997 | * If count == 0, then just check if memory and type are valid. | 1022 | * If count == 0, then just check if memory and type are valid. |
| 998 | * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0. | 1023 | * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0. |
| @@ -126,6 +126,9 @@ struct v4l2_format32 { · 125 unmodified lines | |||
| 126 | * @memory: buffer memory type | 126 | * @memory: buffer memory type |
| 127 | * @format: frame format, for which buffers are requested | 127 | * @format: frame format, for which buffers are requested |
| 128 | * @capabilities: capabilities of this buffer type. | 128 | * @capabilities: capabilities of this buffer type. |
| 129 | * @flags: additional buffer management attributes (ignored unless the | ||
| 130 | * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability and | ||
| 131 | * configured for MMAP streaming I/O). | ||
| 129 | * @reserved: future extensions | 132 | * @reserved: future extensions |
| 130 | */ | 133 | */ |
| 131 | struct v4l2_create_buffers32 { | 134 | struct v4l2_create_buffers32 { |
| @@ -134,7 +137,8 @@ struct v4l2_create_buffers32 { · 2 unmodified lines | |||
| 134 | __u32 memory; /* enum v4l2_memory */ | 137 | __u32 memory; /* enum v4l2_memory */ |
| 135 | struct v4l2_format32 format; | 138 | struct v4l2_format32 format; |
| 136 | __u32 capabilities; | 139 | __u32 capabilities; |
| 137 | __u32 reserved[7]; | 140 | __u32 flags; |
| 141 | __u32 reserved[6]; | ||
| 138 | }; | 142 | }; |
| 139 | 143 | ||
| 140 | static int get_v4l2_format32(struct v4l2_format *p64, | 144 | static int get_v4l2_format32(struct v4l2_format *p64, |
| @@ -182,6 +186,8 @@ static int get_v4l2_create32(struct v4l2_create_buffers *p64, · 41 unmodified lines | |||
| 182 | if (copy_from_user(p64, p32, | 186 | if (copy_from_user(p64, p32, |
| 183 | offsetof(struct v4l2_create_buffers32, format))) | 187 | offsetof(struct v4l2_create_buffers32, format))) |
| 184 | return -EFAULT; | 188 | return -EFAULT; |
| 189 | if (copy_from_user(&p64->flags, &p32->flags, sizeof(p32->flags))) | ||
| 190 | return -EFAULT; | ||
| 185 | return get_v4l2_format32(&p64->format, &p32->format); | 191 | return get_v4l2_format32(&p64->format, &p32->format); |
| 186 | } | 192 | } |
| 187 | 193 | ||
| @@ -227,6 +233,7 @@ static int put_v4l2_create32(struct v4l2_create_buffers *p64, · 39 unmodified lines | |||
| 227 | if (copy_to_user(p32, p64, | 233 | if (copy_to_user(p32, p64, |
| 228 | offsetof(struct v4l2_create_buffers32, format)) || | 234 | offsetof(struct v4l2_create_buffers32, format)) || |
| 229 | put_user(p64->capabilities, &p32->capabilities) || | 235 | put_user(p64->capabilities, &p32->capabilities) || |
| 236 | put_user(p64->flags, &p32->flags) || | ||
| 230 | copy_to_user(p32->reserved, p64->reserved, sizeof(p64->reserved))) | 237 | copy_to_user(p32->reserved, p64->reserved, sizeof(p64->reserved))) |
| 231 | return -EFAULT; | 238 | return -EFAULT; |
| 232 | return put_v4l2_format32(&p64->format, &p32->format); | 239 | return put_v4l2_format32(&p64->format, &p32->format); |
| @@ -2024,7 +2024,7 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, · 2023 unmodified lines | |||
| 2024 | if (ret) | 2024 | if (ret) |
| 2025 | return ret; | 2025 | return ret; |
| 2026 | 2026 | ||
| 2027 | CLEAR_AFTER_FIELD(p, capabilities); | 2027 | CLEAR_AFTER_FIELD(p, flags); |
| 2028 | 2028 | ||
| 2029 | return ops->vidioc_reqbufs(file, fh, p); | 2029 | return ops->vidioc_reqbufs(file, fh, p); |
| 2030 | } | 2030 | } |
| @@ -2065,7 +2065,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, · 34 unmodified lines | |||
| 2065 | if (ret) | 2065 | if (ret) |
| 2066 | return ret; | 2066 | return ret; |
| 2067 | 2067 | ||
| 2068 | CLEAR_AFTER_FIELD(create, capabilities); | 2068 | CLEAR_AFTER_FIELD(create, flags); |
| 2069 | 2069 | ||
| 2070 | v4l_sanitize_format(&create->format); | 2070 | v4l_sanitize_format(&create->format); |
| 2071 | 2071 | ||
| @@ -959,7 +959,8 @@ struct v4l2_requestbuffers { · 958 unmodified lines | |||
| 959 | __u32 type; /* enum v4l2_buf_type */ | 959 | __u32 type; /* enum v4l2_buf_type */ |
| 960 | __u32 memory; /* enum v4l2_memory */ | 960 | __u32 memory; /* enum v4l2_memory */ |
| 961 | __u32 capabilities; | 961 | __u32 capabilities; |
| 962 | __u32 reserved[1]; | 962 | __u8 flags; |
| 963 | __u8 reserved[3]; | ||
| 963 | }; | 964 | }; |
| 964 | 965 | ||
| 965 | #define V4L2_MEMORY_FLAG_NON_COHERENT (1 << 0) | 966 | #define V4L2_MEMORY_FLAG_NON_COHERENT (1 << 0) |
| @@ -2507,6 +2508,9 @@ struct v4l2_dbg_chip_info { · 1541 unmodified lines | |||
| 2507 | * @memory: enum v4l2_memory; buffer memory type | 2508 | * @memory: enum v4l2_memory; buffer memory type |
| 2508 | * @format: frame format, for which buffers are requested | 2509 | * @format: frame format, for which buffers are requested |
| 2509 | * @capabilities: capabilities of this buffer type. | 2510 | * @capabilities: capabilities of this buffer type. |
| 2511 | * @flags: additional buffer management attributes (ignored unless the | ||
| 2512 | * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability | ||
| 2513 | * and configured for MMAP streaming I/O). | ||
| 2510 | * @reserved: future extensions | 2514 | * @reserved: future extensions |
| 2511 | */ | 2515 | */ |
| 2512 | struct v4l2_create_buffers { | 2516 | struct v4l2_create_buffers { |
| @@ -2515,7 +2519,8 @@ struct v4l2_create_buffers { · 2 unmodified lines | |||
| 2515 | __u32 memory; | 2519 | __u32 memory; |
| 2516 | struct v4l2_format format; | 2520 | struct v4l2_format format; |
| 2517 | __u32 capabilities; | 2521 | __u32 capabilities; |
| 2518 | __u32 reserved[7]; | 2522 | __u32 flags; |
| 2523 | __u32 reserved[6]; | ||
| 2519 | }; | 2524 | }; |
| 2520 | 2525 | ||
| 2521 | /* | 2526 | /* |