Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: core: Report the maximum possible number of buffers for the queue

Use one of the struct v4l2_create_buffers reserved bytes to report
the maximum possible number of buffers for the queue.
V4l2 framework set V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS flags in queue
capabilities so userland can know when the field is valid.
Does the same change in v4l2_create_buffers32 structure.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>

authored by

Benjamin Gaignard and committed by
Mauro Carvalho Chehab
d055a76c c838530d

+26 -6
+6 -2
Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst
··· 116 116 - ``flags`` 117 117 - Specifies additional buffer management attributes. 118 118 See :ref:`memory-flags`. 119 - 120 119 * - __u32 121 - - ``reserved``\ [6] 120 + - ``max_num_buffers`` 121 + - If the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set 122 + this field indicates the maximum possible number of buffers 123 + for this queue. 124 + * - __u32 125 + - ``reserved``\ [5] 122 126 - A place holder for future extensions. Drivers and applications 123 127 must set the array to zero. 124 128
+1
Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst
··· 120 120 .. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS: 121 121 .. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF: 122 122 .. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS: 123 + .. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS: 123 124 124 125 .. raw:: latex 125 126
+2
drivers/media/common/videobuf2/videobuf2-v4l2.c
··· 756 756 fill_buf_caps(q, &create->capabilities); 757 757 validate_memory_flags(q, create->memory, &create->flags); 758 758 create->index = vb2_get_num_buffers(q); 759 + create->max_num_buffers = q->max_num_buffers; 760 + create->capabilities |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS; 759 761 if (create->count == 0) 760 762 return ret != -EBUSY ? ret : 0; 761 763
+9 -1
drivers/media/v4l2-core/v4l2-compat-ioctl32.c
··· 116 116 * @flags: additional buffer management attributes (ignored unless the 117 117 * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability and 118 118 * configured for MMAP streaming I/O). 119 + * @max_num_buffers: if V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set 120 + * this field indicate the maximum possible number of buffers 121 + * for this queue. 119 122 * @reserved: future extensions 120 123 */ 121 124 struct v4l2_create_buffers32 { ··· 128 125 struct v4l2_format32 format; 129 126 __u32 capabilities; 130 127 __u32 flags; 131 - __u32 reserved[6]; 128 + __u32 max_num_buffers; 129 + __u32 reserved[5]; 132 130 }; 133 131 134 132 static int get_v4l2_format32(struct v4l2_format *p64, ··· 179 175 return -EFAULT; 180 176 if (copy_from_user(&p64->flags, &p32->flags, sizeof(p32->flags))) 181 177 return -EFAULT; 178 + if (copy_from_user(&p64->max_num_buffers, &p32->max_num_buffers, 179 + sizeof(p32->max_num_buffers))) 180 + return -EFAULT; 182 181 return get_v4l2_format32(&p64->format, &p32->format); 183 182 } 184 183 ··· 228 221 offsetof(struct v4l2_create_buffers32, format)) || 229 222 put_user(p64->capabilities, &p32->capabilities) || 230 223 put_user(p64->flags, &p32->flags) || 224 + put_user(p64->max_num_buffers, &p32->max_num_buffers) || 231 225 copy_to_user(p32->reserved, p64->reserved, sizeof(p64->reserved))) 232 226 return -EFAULT; 233 227 return put_v4l2_format32(&p64->format, &p32->format);
+2 -2
drivers/media/v4l2-core/v4l2-ioctl.c
··· 483 483 { 484 484 const struct v4l2_create_buffers *p = arg; 485 485 486 - pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, ", 486 + pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, max num buffers=%u", 487 487 p->index, p->count, prt_names(p->memory, v4l2_memory_names), 488 - p->capabilities); 488 + p->capabilities, p->max_num_buffers); 489 489 v4l_print_format(&p->format, write_only); 490 490 } 491 491
+6 -1
include/uapi/linux/videodev2.h
··· 1035 1035 #define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4) 1036 1036 #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) 1037 1037 #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) 1038 + #define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) 1038 1039 1039 1040 /** 1040 1041 * struct v4l2_plane - plane info for multi-planar buffers ··· 2606 2605 * @flags: additional buffer management attributes (ignored unless the 2607 2606 * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability 2608 2607 * and configured for MMAP streaming I/O). 2608 + * @max_num_buffers: if V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set 2609 + * this field indicate the maximum possible number of buffers 2610 + * for this queue. 2609 2611 * @reserved: future extensions 2610 2612 */ 2611 2613 struct v4l2_create_buffers { ··· 2618 2614 struct v4l2_format format; 2619 2615 __u32 capabilities; 2620 2616 __u32 flags; 2621 - __u32 reserved[6]; 2617 + __u32 max_num_buffers; 2618 + __u32 reserved[5]; 2622 2619 }; 2623 2620 2624 2621 /*