History

media: videobuf2: handle V4L2_MEMORY_FLAG_NON_COHERENT flag

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.

Sergey Senozhatsky committed 5 years ago

Commit c0acf9c1 parent b00a9e57 files · +60 −15Browse files

Unified · Split

7 files
  1. Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst +6 −1
  2. Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +7 −4
  3. drivers/media/common/videobuf2/videobuf2-core.c +2 −2
  4. drivers/media/common/videobuf2/videobuf2-v4l2.c +28 −3
  5. drivers/media/v4l2-core/v4l2-compat-ioctl32.c +8 −1
  6. drivers/media/v4l2-core/v4l2-ioctl.c +2 −2
  7. include/uapi/linux/videodev2.h +7 −2
Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst+6−1
@@ -113,7 +113,12 @@ than the number requested. · 112 unmodified lines
113113 ``V4L2_MEMORY_MMAP`` and ``format.type`` to the buffer type.
114114
115115 * - __u32
116− - ``reserved``\ [7]
116+ - ``flags``
117+ - Specifies additional buffer management attributes.
118+ See :ref:`memory-flags`.
119+
120+ * - __u32
121+ - ``reserved``\ [6]
117122 - A place holder for future extensions. Drivers and applications
118123 must set the array to zero.
119124
Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst+7−4
@@ -104,10 +104,13 @@ aborting or finishing any DMA in progress, an implicit · 103 unmodified lines
104104 ``V4L2_MEMORY_MMAP`` and ``type`` set to the buffer type. This will
105105 free any previously allocated buffers, so this is typically something
106106 that will be done at the start of the application.
107− * - __u32
108− - ``reserved``\ [1]
109− - A place holder for future extensions. Drivers and applications
110− must set the array to zero.
107+ * - __u8
108+ - ``flags``
109+ - Specifies additional buffer management attributes.
110+ See :ref:`memory-flags`.
111+ * - __u8
112+ - ``reserved``\ [3]
113+ - Reserved for future extensions.
111114
112115 .. _v4l2-buf-capabilities:
113116 .. _V4L2-BUF-CAP-SUPPORTS-MMAP:
drivers/media/common/videobuf2/videobuf2-core.c+2−2
@@ -761,7 +761,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, · 760 unmodified lines
761761 {
762762 unsigned int num_buffers, allocated_buffers, num_planes = 0;
763763 unsigned plane_sizes[VB2_MAX_PLANES] = { };
764− bool non_coherent_mem = false;
764+ bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT;
765765 unsigned int i;
766766 int ret;
767767
@@ -905,7 +905,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, · 137 unmodified lines
905905 {
906906 unsigned int num_planes = 0, num_buffers, allocated_buffers;
907907 unsigned plane_sizes[VB2_MAX_PLANES] = { };
908− bool non_coherent_mem = false;
908+ bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT;
909909 int ret;
910910
911911 if (q->num_buffers == VB2_MAX_FRAME) {
drivers/media/common/videobuf2/videobuf2-v4l2.c+28−3
@@ -692,12 +692,32 @@ static void fill_buf_caps(struct vb2_queue *q, u32 *caps) · 691 unmodified lines
692692 #endif
693693 }
694694
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+
695711 int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
696712 {
697713 int ret = vb2_verify_memory_type(q, req->memory, req->type);
714+ u32 flags = req->flags;
698715
699716 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);
701721 }
702722 EXPORT_SYMBOL_GPL(vb2_reqbufs);
703723
@@ -729,6 +749,7 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) · 25 unmodified lines
729749 unsigned i;
730750
731751 fill_buf_caps(q, &create->capabilities);
752+ validate_memory_flags(q, create->memory, &create->flags);
732753 create->index = q->num_buffers;
733754 if (create->count == 0)
734755 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
772793 if (requested_sizes[i] == 0)
773794 return -EINVAL;
774795 return ret ? ret : vb2_core_create_bufs(q, create->memory,
775− 0,
796+ create->flags,
776797 &create->count,
777798 requested_planes,
778799 requested_sizes);
@@ -969,13 +990,16 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, · 190 unmodified lines
969990 {
970991 struct video_device *vdev = video_devdata(file);
971992 int res = vb2_verify_memory_type(vdev->queue, p->memory, p->type);
993+ u32 flags = p->flags;
972994
973995 fill_buf_caps(vdev->queue, &p->capabilities);
996+ validate_memory_flags(vdev->queue, p->memory, &flags);
997+ p->flags = flags;
974998 if (res)
975999 return res;
9761000 if (vb2_queue_is_busy(vdev, file))
9771001 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);
9791003 /* If count == 0, then the owner has released all buffers and he
9801004 is no longer owner of the queue. Otherwise we have a new owner. */
9811005 if (res == 0)
@@ -993,6 +1017,7 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv, · 11 unmodified lines
9931017
9941018 p->index = vdev->queue->num_buffers;
9951019 fill_buf_caps(vdev->queue, &p->capabilities);
1020+ validate_memory_flags(vdev->queue, p->memory, &p->flags);
9961021 /*
9971022 * If count == 0, then just check if memory and type are valid.
9981023 * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0.
drivers/media/v4l2-core/v4l2-compat-ioctl32.c+8−1
@@ -126,6 +126,9 @@ struct v4l2_format32 { · 125 unmodified lines
126126 * @memory: buffer memory type
127127 * @format: frame format, for which buffers are requested
128128 * @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).
129132 * @reserved: future extensions
130133 */
131134 struct v4l2_create_buffers32 {
@@ -134,7 +137,8 @@ struct v4l2_create_buffers32 { · 2 unmodified lines
134137 __u32 memory; /* enum v4l2_memory */
135138 struct v4l2_format32 format;
136139 __u32 capabilities;
137− __u32 reserved[7];
140+ __u32 flags;
141+ __u32 reserved[6];
138142 };
139143
140144 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
182186 if (copy_from_user(p64, p32,
183187 offsetof(struct v4l2_create_buffers32, format)))
184188 return -EFAULT;
189+ if (copy_from_user(&p64->flags, &p32->flags, sizeof(p32->flags)))
190+ return -EFAULT;
185191 return get_v4l2_format32(&p64->format, &p32->format);
186192 }
187193
@@ -227,6 +233,7 @@ static int put_v4l2_create32(struct v4l2_create_buffers *p64, · 39 unmodified lines
227233 if (copy_to_user(p32, p64,
228234 offsetof(struct v4l2_create_buffers32, format)) ||
229235 put_user(p64->capabilities, &p32->capabilities) ||
236+ put_user(p64->flags, &p32->flags) ||
230237 copy_to_user(p32->reserved, p64->reserved, sizeof(p64->reserved)))
231238 return -EFAULT;
232239 return put_v4l2_format32(&p64->format, &p32->format);
drivers/media/v4l2-core/v4l2-ioctl.c+2−2
@@ -2024,7 +2024,7 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, · 2023 unmodified lines
20242024 if (ret)
20252025 return ret;
20262026
2027− CLEAR_AFTER_FIELD(p, capabilities);
2027+ CLEAR_AFTER_FIELD(p, flags);
20282028
20292029 return ops->vidioc_reqbufs(file, fh, p);
20302030 }
@@ -2065,7 +2065,7 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, · 34 unmodified lines
20652065 if (ret)
20662066 return ret;
20672067
2068− CLEAR_AFTER_FIELD(create, capabilities);
2068+ CLEAR_AFTER_FIELD(create, flags);
20692069
20702070 v4l_sanitize_format(&create->format);
20712071
include/uapi/linux/videodev2.h+7−2
@@ -959,7 +959,8 @@ struct v4l2_requestbuffers { · 958 unmodified lines
959959 __u32 type; /* enum v4l2_buf_type */
960960 __u32 memory; /* enum v4l2_memory */
961961 __u32 capabilities;
962− __u32 reserved[1];
962+ __u8 flags;
963+ __u8 reserved[3];
963964 };
964965
965966 #define V4L2_MEMORY_FLAG_NON_COHERENT (1 << 0)
@@ -2507,6 +2508,9 @@ struct v4l2_dbg_chip_info { · 1541 unmodified lines
25072508 * @memory: enum v4l2_memory; buffer memory type
25082509 * @format: frame format, for which buffers are requested
25092510 * @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).
25102514 * @reserved: future extensions
25112515 */
25122516 struct v4l2_create_buffers {
@@ -2515,7 +2519,8 @@ struct v4l2_create_buffers { · 2 unmodified lines
25152519 __u32 memory;
25162520 struct v4l2_format format;
25172521 __u32 capabilities;
2518− __u32 reserved[7];
2522+ __u32 flags;
2523+ __u32 reserved[6];
25192524 };
25202525
25212526 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t