From patchwork Tue Nov 12 09:22:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 844050 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBC0220DD7B for ; Tue, 12 Nov 2024 09:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404004; cv=none; b=k2LRNrruT0BXtAhyoD+DwhuWpcwKtdUyAWI6H6VEw5Er1CVTeLRdocO+vqCn06Hvr0kgN8Nc+vdhfxDRawzpozA/dsHpFmjSEOZYQf578af7Gon6n7J2VY6hzsIczlv4uToK0Umnd/KH5tPvuMZkCsuX+iYY8cTD4uiqB14t2us= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404004; c=relaxed/simple; bh=abkNxhvu756EKEqyTAlUBqJDF/3LC8px4lHy1udhM1k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BZYVFLEW7eeBwdHHdXgEcE5hDT9cQeEcpl/iTnQk0GvD6CJyRtfQYajZtePxKI712NPtEo2uXENQte7KeYWlaJdS62NnJs0HNJRE+6PhUequSDnuat8q024FCdjI2VUlazfrG+BsnhGXdFoJFa5h6qdnPLYRo9rmAhv9emiy0RQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE36AC4CED6; Tue, 12 Nov 2024 09:33:22 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Hans Verkuil Subject: [RFC PATCHv2 1/5] media: vb2: add support for min/rec_num_buffers Date: Tue, 12 Nov 2024 10:22:12 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Report the minimum and recommended number of buffers in struct v4l2_create_buffers. This is useful for those applications that want to have more precise control over how many buffers they want to allocate. Signed-off-by: Hans Verkuil --- .../media/common/videobuf2/videobuf2-v4l2.c | 19 +++++++++++++----- include/uapi/linux/videodev2.h | 20 +++++++++++++++---- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 9201d854dbcc..15394bb4168c 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -672,7 +672,8 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b) EXPORT_SYMBOL(vb2_querybuf); static void vb2_set_flags_and_caps(struct vb2_queue *q, u32 memory, - u32 *flags, u32 *caps, u32 *max_num_bufs) + u32 *flags, u32 *caps, u32 *max_num_bufs, + u16 *min_num_bufs, u16 *rec_num_bufs) { if (!q->allow_cache_hints || memory != V4L2_MEMORY_MMAP) { /* @@ -702,6 +703,11 @@ static void vb2_set_flags_and_caps(struct vb2_queue *q, u32 memory, *max_num_bufs = q->max_num_buffers; *caps |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS; } + if (min_num_bufs && rec_num_bufs) { + *min_num_bufs = q->min_queued_buffers + 1; + *rec_num_bufs = q->min_reqbufs_allocation; + *caps |= V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS; + } } int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) @@ -710,7 +716,7 @@ int vb2_reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) u32 flags = req->flags; vb2_set_flags_and_caps(q, req->memory, &flags, - &req->capabilities, NULL); + &req->capabilities, NULL, NULL, NULL); req->flags = flags; return ret ? ret : vb2_core_reqbufs(q, req->memory, req->flags, &req->count); @@ -753,7 +759,9 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) create->index = vb2_get_num_buffers(q); vb2_set_flags_and_caps(q, create->memory, &create->flags, - &create->capabilities, &create->max_num_buffers); + &create->capabilities, &create->max_num_buffers, + &create->min_num_buffers, + &create->rec_num_buffers); if (create->count == 0) return ret != -EBUSY ? ret : 0; @@ -1027,7 +1035,7 @@ int vb2_ioctl_reqbufs(struct file *file, void *priv, u32 flags = p->flags; vb2_set_flags_and_caps(vdev->queue, p->memory, &flags, - &p->capabilities, NULL); + &p->capabilities, NULL, NULL, NULL); p->flags = flags; if (res) return res; @@ -1050,7 +1058,8 @@ int vb2_ioctl_create_bufs(struct file *file, void *priv, p->index = vb2_get_num_buffers(vdev->queue); vb2_set_flags_and_caps(vdev->queue, p->memory, &p->flags, - &p->capabilities, &p->max_num_buffers); + &p->capabilities, &p->max_num_buffers, + &p->min_num_buffers, &p->rec_num_buffers); /* * If count == 0, then just check if memory and type are valid. * Any -EBUSY result from vb2_verify_memory_type can be mapped to 0. diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index e7c4dce39007..68cca8dda937 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1079,6 +1079,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) #define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) #define V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS (1 << 8) +#define V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS (1 << 9) /** * struct v4l2_plane - plane info for multi-planar buffers @@ -2660,9 +2661,18 @@ struct v4l2_dbg_chip_info { * @flags: additional buffer management attributes (ignored unless the * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability * and configured for MMAP streaming I/O). - * @max_num_buffers: if V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set - * this field indicate the maximum possible number of buffers - * for this queue. + * @max_num_buffers: if the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability + * flag is set, then this field indicates the maximum possible + * number of buffers for this queue. + * @min_num_buffers: if the V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS capability + * flag is set, then this field indicates the minimum possible + * number of buffers for this queue. Using this value might cause + * dropped frames, but it will be able to stream video. Useful for + * capturing only a single frame. + * @rec_num_buffers: if the V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS capability + * flag is set, then this field indicates the recommended number + * of buffers for this queue. This is also used when calling + * VIDIOC_REQBUFS to ensure count is at least this value. * @reserved: future extensions */ struct v4l2_create_buffers { @@ -2673,7 +2683,9 @@ struct v4l2_create_buffers { __u32 capabilities; __u32 flags; __u32 max_num_buffers; - __u32 reserved[5]; + __u16 min_num_buffers; + __u16 rec_num_buffers; + __u32 reserved[4]; }; /** From patchwork Tue Nov 12 09:22:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 842806 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4323720DD7B for ; Tue, 12 Nov 2024 09:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404005; cv=none; b=IYVqVVh1hLHuKp4LN8EnATKq/30BaKXcycPN9Vm6rl0pImxT72zVCw7W8SgFJ8U0UxzT0lEzx6k0Tn20ffiYWXmubtC/n5Ats/wHL1x68OiQvFLsn5VKkiIzK3u/rdzrf/O96mgbkVQ93E3DSxM5jh/0UcEbwxCORXdtIeEP5Yo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404005; c=relaxed/simple; bh=fB2PomdAzt/DzHHPe6DJp4oV43MOnlpIo/E9fNbMbak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=clyW4Vpk6GWsIT3l7wzLNkfBIbxmB9Yz6ChSbMJZCpo1pIzVcgOvjb4FPO30gvt7F9ILoH4c0Nb00SzXzPxm34vbncJMU3lawK2sXM0y/+scoM1IAkLHE1chLgh+OXWe0obbhskpCUQae2I3sZMusczQbcDX62MgpV1a5M5rSFE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AB22C4CECD; Tue, 12 Nov 2024 09:33:23 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Hans Verkuil Subject: [RFC PATCHv2 2/5] Documentation: media: document min/rec_num_buffers Date: Tue, 12 Nov 2024 10:22:13 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Document the new min_num_buffers and rec_num_buffers fields and the corresponding V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS capability flag. Signed-off-by: Hans Verkuil --- .../media/v4l/vidioc-create-bufs.rst | 34 +++++++++++++++---- .../media/v4l/vidioc-reqbufs.rst | 6 ++++ 2 files changed, 33 insertions(+), 7 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst b/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst index 49232c9006c2..a400d464cc9f 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst @@ -68,7 +68,12 @@ When the ioctl is called with a pointer to this structure the driver will attempt to allocate up to the requested number of buffers and store the actual number allocated and the starting index in the ``count`` and the ``index`` fields respectively. On return ``count`` can be smaller -than the number requested. +than the number requested, but never larger. If no buffers could be +allocated, then -1 is returned and errno is set to the ``ENOMEM`` error code. + +If ``count`` was set to 0, then no buffers are allocated, and instead +it just sets the various informative fields, e.g. ``capabilities``, +``max_num_buffers``, etc. .. c:type:: v4l2_create_buffers @@ -88,9 +93,9 @@ than the number requested. :ref:`VIDIOC_CREATE_BUFS` will set ``index`` to the current number of created buffers, and it will check the validity of ``memory`` and ``format.type``. If those are invalid -1 is returned and errno is - set to ``EINVAL`` error code, otherwise :ref:`VIDIOC_CREATE_BUFS` returns - 0. It will never set errno to ``EBUSY`` error code in this particular - case. + set to the ``EINVAL`` error code, otherwise :ref:`VIDIOC_CREATE_BUFS` + returns 0. It will never set errno to the ``EBUSY`` error code in this + particular case. * - __u32 - ``memory`` - Applications set this field to ``V4L2_MEMORY_MMAP``, @@ -118,11 +123,26 @@ than the number requested. See :ref:`memory-flags`. * - __u32 - ``max_num_buffers`` - - If the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set - this field indicates the maximum possible number of buffers + - If the ``V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS`` capability flag is + set this field indicates the maximum possible number of buffers for this queue. + * - __u16 + - ``min_num_buffers`` + - If the ``V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS`` capability flag is + set this field indicates the minimum number of buffers for this queue. + Allocating this number of buffers will allow video streaming, but frame + drops might happen. + * - __u16 + - ``rec_num_buffers`` + - If the ``V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS`` capability flag is + set this field indicates the recommended number of buffers for this + queue. + The :ref:`VIDIOC_REQBUFS` will use this value if the requested number of + buffers is less than this value. This value ensures reliable video + streaming without frame drops, provided the application can process + a dequeued buffer within a single frame period. * - __u32 - - ``reserved``\ [5] + - ``reserved``\ [4] - A place holder for future extensions. Drivers and applications must set the array to zero. diff --git a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst index daf9a6621b50..4c5bb303b5a2 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst @@ -124,6 +124,7 @@ aborting or finishing any DMA in progress, an implicit .. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS: .. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS: .. _V4L2-BUF-CAP-SUPPORTS-REMOVE-BUFS: +.. _V4L2-BUF-CAP-SUPPORTS-MIN-REC-NUM-BUFFERS: .. flat-table:: V4L2 Buffer Capabilities Flags :header-rows: 0 @@ -167,6 +168,11 @@ aborting or finishing any DMA in progress, an implicit * - ``V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS`` - 0x00000100 - If set, then ``VIDIOC_REMOVE_BUFS`` is supported. + * - ``V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS`` + - 0x00000200 + - If set, then the ``min_num_buffers`` and ``rec_num_buffers`` fields in + ``struct v4l2_create_buffers`` are valid. If not set, then these fields + are 0. .. _memory-flags: .. _V4L2-MEMORY-FLAG-NON-COHERENT: From patchwork Tue Nov 12 09:22:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 844049 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A39401ABEC2 for ; Tue, 12 Nov 2024 09:33:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404006; cv=none; b=a8aGnTVR1A0msB7CbGrKtdiiopAmumgzrC7Wp6yC/M+JUKIx/BnMPWeuS3nrwd6fE8h+qRktj1LHikN3Pt4bZqD6/FSkfalsENgkgeTdinBIdBwlNKfaUzWPspsmZoguIQiC1KVGT6YMVttMAMCbFmrnPmDmGuK1kmY39wUbUB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404006; c=relaxed/simple; bh=eM3wLJuqiGW5HRxK2UO25OQXbgKjow6coDleXOYYOpM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LjoGM7ZfAwrbsQlbWvzQpoH8gaIxdzL6VHSwgu/tTd88xHQIuFRk3mmP/Z2QAPrX6hHpC1MzqMmI8+nnAy87D9rLbUBpE9ctQr8jV9y7WFTCjtaQezfTA93AQDFspvFBOznuMCT3YDEDqY7ZlYR2q5FugrcZ1BRspm6MqFUuH1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 59EC1C4CECD; Tue, 12 Nov 2024 09:33:25 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Hans Verkuil Subject: [RFC PATCHv2 3/5] media: vb2: rename min_reqbufs_allocation to rec_num_buffers Date: Tue, 12 Nov 2024 10:22:14 +0100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The name 'rec_num_buffers' matches what struct v4l2_create_buffers uses, and 'recommended number of buffers' is a much more descriptive name. Signed-off-by: Hans Verkuil --- drivers/media/common/videobuf2/videobuf2-core.c | 14 +++++++------- drivers/media/common/videobuf2/videobuf2-v4l2.c | 2 +- drivers/media/test-drivers/vicodec/vicodec-core.c | 4 ++-- drivers/media/test-drivers/vimc/vimc-capture.c | 2 +- drivers/media/test-drivers/vivid/vivid-core.c | 4 ++-- include/media/videobuf2-core.h | 12 +++++++----- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index c0cc441b5164..4b55280dc8b8 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -923,7 +923,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Make sure the requested values and current defaults are sane. */ - num_buffers = max_t(unsigned int, *count, q->min_reqbufs_allocation); + num_buffers = max_t(unsigned int, *count, q->rec_num_buffers); num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); /* @@ -974,7 +974,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * There is no point in continuing if we can't allocate the minimum * number of buffers needed by this vb2_queue. */ - if (allocated_buffers < q->min_reqbufs_allocation) + if (allocated_buffers < q->rec_num_buffers) ret = -ENOMEM; /* @@ -2647,10 +2647,10 @@ int vb2_core_queue_init(struct vb2_queue *q) * 'min_queued_buffers + 1' to keep at least one buffer available * for userspace. */ - if (q->min_reqbufs_allocation < q->min_queued_buffers + 1) - q->min_reqbufs_allocation = q->min_queued_buffers + 1; + if (q->rec_num_buffers < q->min_queued_buffers + 1) + q->rec_num_buffers = q->min_queued_buffers + 1; - if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers)) + if (WARN_ON(q->rec_num_buffers > q->max_num_buffers)) return -EINVAL; /* Either both or none are set */ @@ -2874,7 +2874,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) return -EBUSY; dprintk(q, 3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n", - (read) ? "read" : "write", q->min_reqbufs_allocation, q->fileio_read_once, + (read) ? "read" : "write", q->rec_num_buffers, q->fileio_read_once, q->fileio_write_immediately); fileio = kzalloc(sizeof(*fileio), GFP_KERNEL); @@ -2888,7 +2888,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Request buffers and use MMAP type to force driver * to allocate buffers by itself. */ - fileio->count = q->min_reqbufs_allocation; + fileio->count = q->rec_num_buffers; fileio->memory = VB2_MEMORY_MMAP; fileio->type = q->type; q->fileio = fileio; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 15394bb4168c..f4fdc5d77d9c 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -705,7 +705,7 @@ static void vb2_set_flags_and_caps(struct vb2_queue *q, u32 memory, } if (min_num_bufs && rec_num_bufs) { *min_num_bufs = q->min_queued_buffers + 1; - *rec_num_bufs = q->min_reqbufs_allocation; + *rec_num_bufs = q->rec_num_buffers; *caps |= V4L2_BUF_CAP_SUPPORTS_MIN_REC_NUM_BUFFERS; } } diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c index c45f5cf12ded..7e0b76606c8b 100644 --- a/drivers/media/test-drivers/vicodec/vicodec-core.c +++ b/drivers/media/test-drivers/vicodec/vicodec-core.c @@ -1709,7 +1709,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; if (ctx->is_enc) { src_vq->lock = &ctx->dev->stateful_enc.mutex; - src_vq->min_reqbufs_allocation = VICODEC_REC_BUFS; + src_vq->rec_num_buffers = VICODEC_REC_BUFS; } else if (ctx->is_stateless) { src_vq->lock = &ctx->dev->stateless_dec.mutex; } else { @@ -1733,7 +1733,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq, dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; dst_vq->lock = src_vq->lock; if (!ctx->is_stateless && !ctx->is_enc) - dst_vq->min_reqbufs_allocation = VICODEC_REC_BUFS; + dst_vq->rec_num_buffers = VICODEC_REC_BUFS; return vb2_queue_init(dst_vq); } diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index 10df039278e7..1a1ca1d67fe6 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -427,7 +427,7 @@ static struct vimc_ent_device *vimc_capture_add(struct vimc_device *vimc, q->mem_ops = vimc_allocator == VIMC_ALLOCATOR_DMA_CONTIG ? &vb2_dma_contig_memops : &vb2_vmalloc_memops; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; - q->min_reqbufs_allocation = 2; + q->rec_num_buffers = 2; q->lock = &vcapture->lock; q->dev = v4l2_dev->dev; diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c index 7477ac8cb955..46ac3fd6e5dd 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.c +++ b/drivers/media/test-drivers/vivid/vivid-core.c @@ -887,7 +887,7 @@ static const struct media_device_ops vivid_media_ops = { static int vivid_create_queue(struct vivid_dev *dev, struct vb2_queue *q, u32 buf_type, - unsigned int min_reqbufs_allocation, + unsigned int rec_num_buffers, const struct vb2_ops *ops) { if (buf_type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->multiplanar) @@ -924,7 +924,7 @@ static int vivid_create_queue(struct vivid_dev *dev, q->mem_ops = allocators[dev->inst] == 1 ? &vb2_dma_contig_memops : &vb2_vmalloc_memops; q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; - q->min_reqbufs_allocation = min_reqbufs_allocation; + q->rec_num_buffers = rec_num_buffers; q->lock = &dev->mutex; q->dev = dev->v4l2_dev.dev; q->supports_requests = supports_requests[dev->inst]; diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 9b02aeba4108..3282b55179a5 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -555,14 +555,16 @@ struct vb2_buf_ops { * VIDIOC_REQBUFS will ensure at least @min_queued_buffers + 1 * buffers will be allocated. Note that VIDIOC_CREATE_BUFS will not * modify the requested buffer count. - * @min_reqbufs_allocation: the minimum number of buffers to be allocated when - * calling VIDIOC_REQBUFS. Note that VIDIOC_CREATE_BUFS will *not* - * modify the requested buffer count and does not use this field. + * @rec_num_buffers: the recommended number of buffers to allocate for this + * queue. This value is used when calling VIDIOC_REQBUFS: it will + * allocate at least this many buffersa + * Note that VIDIOC_CREATE_BUFS will *not* modify the requested + * buffer count and it does not use this field. * Drivers can set this if there has to be a certain number of * buffers available for the hardware to work effectively. * This allows calling VIDIOC_REQBUFS with a buffer count of 1 and * it will be automatically adjusted to a workable buffer count. - * If set, then @min_reqbufs_allocation must be larger than + * If set, then @rec_num_buffers must be larger than * @min_queued_buffers + 1. * If this field is > 3, then it is highly recommended that the * driver implements the V4L2_CID_MIN_BUFFERS_FOR_CAPTURE/OUTPUT @@ -638,7 +640,7 @@ struct vb2_queue { u32 timestamp_flags; gfp_t gfp_flags; u32 min_queued_buffers; - u32 min_reqbufs_allocation; + u32 rec_num_buffers; struct device *alloc_devs[VB2_MAX_PLANES]; From patchwork Tue Nov 12 09:22:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 842805 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08F7D1ABEC2 for ; Tue, 12 Nov 2024 09:33:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404008; cv=none; b=UTDYOltmGFokLqpSyTMeSqDISIgbCOLAoiYGYB9ryKxiEdfOvKlLPxxH8qr5X8vE/Lk6bM9FsNlUHbpCklUvjqrp/7zAvznBvF9Rq0wv5v6w+/1ZCsgtw41t/MrU9rbbuRa4ULWVHB/ZDqz52nWLGtgIXf1hfuAW08DzvpyBoz0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404008; c=relaxed/simple; bh=bu3D/oQ1wnWfvuqBcAQoBX0km+bNjnKlHL0MK9ZD6Wo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OAOm34DNksbSOvb2BSMBYcNwZn7doaN2pbWM5hPCN9vZTW2vMs8DARhtBiFtW5XCaRadIefkKTcXBqXmr/nY8qLcmIbcmaIQc4KQE5xeo9CaireXSuNOQkJwxUfsGgzRNlQRyFdA0wxjsnCv9MUuTjap6p/VdcttsanWqvlMtDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA488C4CED4; Tue, 12 Nov 2024 09:33:26 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Hans Verkuil Subject: [RFC PATCHv2 4/5] media: vb2: introduce queue_info to replace queue_setup Date: Tue, 12 Nov 2024 10:22:15 +0100 Message-ID: <541c146568fa67a7acc3aca87001f056751c638c.1731403336.git.hverkuil@xs4all.nl> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The new queue_info op just returns the number of planes and plane sizes for the currently configured format. Signed-off-by: Hans Verkuil --- .../media/common/videobuf2/videobuf2-core.c | 82 ++++++++++++++----- include/media/videobuf2-core.h | 10 +++ 2 files changed, 70 insertions(+), 22 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 4b55280dc8b8..bd241fe9474b 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -611,9 +611,9 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned i if (unbalanced) { pr_info("unbalanced counters for queue %p:\n", q); if (q->cnt_start_streaming != q->cnt_stop_streaming) - pr_info(" setup: %u start_streaming: %u stop_streaming: %u\n", - q->cnt_queue_setup, q->cnt_start_streaming, - q->cnt_stop_streaming); + pr_info(" setup: %u info: %u start_streaming: %u stop_streaming: %u\n", + q->cnt_queue_setup, q->cnt_queue_info, + q->cnt_start_streaming, q->cnt_stop_streaming); if (q->cnt_prepare_streaming != q->cnt_unprepare_streaming) pr_info(" prepare_streaming: %u unprepare_streaming: %u\n", q->cnt_prepare_streaming, q->cnt_unprepare_streaming); @@ -622,6 +622,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned i q->cnt_wait_prepare, q->cnt_wait_finish); } q->cnt_queue_setup = 0; + q->cnt_queue_info = 0; q->cnt_wait_prepare = 0; q->cnt_wait_finish = 0; q->cnt_prepare_streaming = 0; @@ -914,7 +915,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, q->is_busy = 0; /* * In case of REQBUFS(0) return immediately without calling - * driver's queue_setup() callback and allocating resources. + * driver's queue_setup() or queue_info() callback and + * allocating resources. */ if (*count == 0) return 0; @@ -928,7 +930,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); /* * Set this now to ensure that drivers see the correct q->memory value - * in the queue_setup op. + * in the queue_setup/info op. */ mutex_lock(&q->mmap_lock); ret = vb2_core_allocated_buffers_storage(q); @@ -938,12 +940,18 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, return ret; set_queue_coherency(q, non_coherent_mem); - /* - * Ask the driver how many buffers and planes per buffer it requires. - * Driver also sets the size and allocator context for each plane. - */ - ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, - plane_sizes, q->alloc_devs); + if (q->ops->queue_info) { + ret = call_qop(q, queue_info, q, &num_planes, + plane_sizes, q->alloc_devs); + } else { + /* + * Ask the driver how many buffers and planes per buffer it + * requires. The driver also sets the size and (optionally) + * the allocator context for each plane. + */ + ret = call_qop(q, queue_setup, q, &num_buffers, &num_planes, + plane_sizes, q->alloc_devs); + } if (ret) goto error; @@ -980,7 +988,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Check if driver can handle the allocated number of buffers. */ - if (!ret && allocated_buffers < num_buffers) { + if (!ret && allocated_buffers < num_buffers && q->ops->queue_setup) { num_buffers = allocated_buffers; /* * num_planes is set by the previous queue_setup(), but since it @@ -1082,17 +1090,44 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, num_buffers = min(*count, q->max_num_buffers - q_num_bufs); - if (requested_planes && requested_sizes) { + if (q->ops->queue_info) { + ret = call_qop(q, queue_info, q, &num_planes, + plane_sizes, q->alloc_devs); + + if (ret) + goto error; + + /* Check that driver has set sane values */ + if (WARN_ON(!num_planes)) { + ret = -EINVAL; + goto error; + } + if (num_planes != requested_planes) { + ret = -EINVAL; + goto error; + } + + for (unsigned int i = 0; i < num_planes; i++) { + if (WARN_ON(!plane_sizes[i])) { + ret = -EINVAL; + goto error; + } + if (plane_sizes[i] > requested_sizes[i]) { + ret = -EINVAL; + goto error; + } + plane_sizes[i] = requested_sizes[i]; + } + } else { num_planes = requested_planes; memcpy(plane_sizes, requested_sizes, sizeof(plane_sizes)); + /* + * Ask the driver, whether the requested number of buffers, planes per + * buffer and their sizes are acceptable + */ + ret = call_qop(q, queue_setup, q, &num_buffers, + &num_planes, plane_sizes, q->alloc_devs); } - - /* - * Ask the driver, whether the requested number of buffers, planes per - * buffer and their sizes are acceptable - */ - ret = call_qop(q, queue_setup, q, &num_buffers, - &num_planes, plane_sizes, q->alloc_devs); if (ret) goto error; @@ -1108,7 +1143,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, /* * Check if driver can handle the so far allocated number of buffers. */ - if (allocated_buffers < num_buffers) { + if (allocated_buffers < num_buffers && q->ops->queue_setup) { num_buffers = allocated_buffers; /* @@ -2619,10 +2654,13 @@ int vb2_core_queue_init(struct vb2_queue *q) WARN_ON(!q->mem_ops) || WARN_ON(!q->type) || WARN_ON(!q->io_modes) || - WARN_ON(!q->ops->queue_setup) || WARN_ON(!q->ops->buf_queue)) return -EINVAL; + if (WARN_ON(!q->ops->queue_setup && !q->ops->queue_info) || + WARN_ON(q->ops->queue_setup && q->ops->queue_info)) + return -EINVAL; + if (WARN_ON(q->max_num_buffers < VB2_MAX_FRAME) || WARN_ON(q->min_queued_buffers > q->max_num_buffers)) return -EINVAL; diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 3282b55179a5..89b7600e4cf6 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -351,6 +351,13 @@ struct vb2_buffer { * \*num_buffers are being allocated additionally to * the buffers already allocated. If either \*num_planes * or the requested sizes are invalid callback must return %-EINVAL. + * @queue_info: called from VIDIOC_REQBUFS() and VIDIOC_CREATE_BUFS() + * handlers before memory allocation. + * The driver must return the required number of planes + * per buffer in \*num_planes, and the size of each plane + * must be set in the sizes\[\] array. Optionally set the + * per-plane allocator specific device in the + * alloc_devs\[\] array. * @wait_prepare: release any locks taken while calling vb2 functions; * it is called before an ioctl needs to wait for a new * buffer to arrive; required to avoid a deadlock in @@ -435,6 +442,8 @@ struct vb2_ops { int (*queue_setup)(struct vb2_queue *q, unsigned int *num_buffers, unsigned int *num_planes, unsigned int sizes[], struct device *alloc_devs[]); + int (*queue_info)(struct vb2_queue *q, unsigned int *num_planes, + unsigned int sizes[], struct device *alloc_devs[]); void (*wait_prepare)(struct vb2_queue *q); void (*wait_finish)(struct vb2_queue *q); @@ -682,6 +691,7 @@ struct vb2_queue { * called. Used to check for unbalanced ops. */ u32 cnt_queue_setup; + u32 cnt_queue_info; u32 cnt_wait_prepare; u32 cnt_wait_finish; u32 cnt_prepare_streaming; From patchwork Tue Nov 12 09:22:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 844048 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A0201ABEC2 for ; Tue, 12 Nov 2024 09:33:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404009; cv=none; b=eSJzMtNK192smzBXtVHu43sLVYKSfhyA83fHo5iBmxj1W6uctW9g6tyW+BB4NwR23tUFcPFZbHGiGp7ok+HceoDf8H1x76G8wvghpSPwiArVsJ5Wmwvb35/YQAKsFC6uWn7UvvCXjIF49euLTUPB0cgcLPlpFDnsl/kUdOSbv70= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731404009; c=relaxed/simple; bh=kCGm7WPP6I+/X/7UgBzUEamn/WS36VNDzYkIqq5eLJw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FY/NSjkym+witLSZCShoz0o730HwjRrJ4sdWIx1EUukYPx/yUAbKqHVwdj+gVJ2iqNOpUbUFdn4DpjgkdX1+GHdD3U81GRIU9fnV+Vqda0g/YQfdypQ5kmZ5eQFdpAxln+nLxa+9+RTnnr0u841aXFf8ZS/iuWetH/WwmdSrp60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04D54C4CED6; Tue, 12 Nov 2024 09:33:27 +0000 (UTC) From: Hans Verkuil To: linux-media@vger.kernel.org Cc: Laurent Pinchart , Hans Verkuil Subject: [RFC PATCHv2 5/5] media: vivid: convert queue_setup to queue_info Date: Tue, 12 Nov 2024 10:22:16 +0100 Message-ID: <45a9c403ce1396cf0d28b90fba00d2d2f6870a18.1731403336.git.hverkuil@xs4all.nl> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the new queue_info callback instead of queue_setup. Signed-off-by: Hans Verkuil --- .../media/test-drivers/vivid/vivid-meta-cap.c | 17 +++----- .../media/test-drivers/vivid/vivid-meta-out.c | 27 +++++-------- .../media/test-drivers/vivid/vivid-sdr-cap.c | 16 +++----- .../test-drivers/vivid/vivid-touch-cap.c | 18 +++------ .../media/test-drivers/vivid/vivid-vbi-cap.c | 13 +++---- .../media/test-drivers/vivid/vivid-vbi-out.c | 13 +++---- .../media/test-drivers/vivid/vivid-vid-cap.c | 39 ++++++------------- .../media/test-drivers/vivid/vivid-vid-out.c | 37 +++++------------- 8 files changed, 56 insertions(+), 124 deletions(-) diff --git a/drivers/media/test-drivers/vivid/vivid-meta-cap.c b/drivers/media/test-drivers/vivid/vivid-meta-cap.c index c7aaecc0b5a2..90d3f6d74a21 100644 --- a/drivers/media/test-drivers/vivid/vivid-meta-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-meta-cap.c @@ -13,24 +13,17 @@ #include "vivid-kthread-cap.h" #include "vivid-meta-cap.h" -static int meta_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, - unsigned int *nplanes, unsigned int sizes[], - struct device *alloc_devs[]) +static int meta_cap_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); - unsigned int size = sizeof(struct vivid_uvc_meta_buf); if (!vivid_is_webcam(dev)) return -EINVAL; - if (*nplanes) { - if (sizes[0] < size) - return -EINVAL; - } else { - sizes[0] = size; - } - *nplanes = 1; + sizes[0] = sizeof(struct vivid_uvc_meta_buf); return 0; } @@ -116,7 +109,7 @@ static void meta_cap_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_meta_cap_qops = { - .queue_setup = meta_cap_queue_setup, + .queue_info = meta_cap_queue_info, .buf_prepare = meta_cap_buf_prepare, .buf_queue = meta_cap_buf_queue, .start_streaming = meta_cap_start_streaming, diff --git a/drivers/media/test-drivers/vivid/vivid-meta-out.c b/drivers/media/test-drivers/vivid/vivid-meta-out.c index 55e5e5dec2f2..432b0f6317bc 100644 --- a/drivers/media/test-drivers/vivid/vivid-meta-out.c +++ b/drivers/media/test-drivers/vivid/vivid-meta-out.c @@ -13,24 +13,17 @@ #include "vivid-kthread-out.h" #include "vivid-meta-out.h" -static int meta_out_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, - unsigned int *nplanes, unsigned int sizes[], - struct device *alloc_devs[]) +static int meta_out_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); - unsigned int size = sizeof(struct vivid_meta_out_buf); if (!vivid_is_webcam(dev)) return -EINVAL; - if (*nplanes) { - if (sizes[0] < size) - return -EINVAL; - } else { - sizes[0] = size; - } - *nplanes = 1; + sizes[0] = sizeof(struct vivid_meta_out_buf); return 0; } @@ -116,12 +109,12 @@ static void meta_out_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_meta_out_qops = { - .queue_setup = meta_out_queue_setup, - .buf_prepare = meta_out_buf_prepare, - .buf_queue = meta_out_buf_queue, - .start_streaming = meta_out_start_streaming, - .stop_streaming = meta_out_stop_streaming, - .buf_request_complete = meta_out_buf_request_complete, + .queue_info = meta_out_queue_info, + .buf_prepare = meta_out_buf_prepare, + .buf_queue = meta_out_buf_queue, + .start_streaming = meta_out_start_streaming, + .stop_streaming = meta_out_stop_streaming, + .buf_request_complete = meta_out_buf_request_complete, }; int vidioc_enum_fmt_meta_out(struct file *file, void *priv, diff --git a/drivers/media/test-drivers/vivid/vivid-sdr-cap.c b/drivers/media/test-drivers/vivid/vivid-sdr-cap.c index 74a91d28c8be..ee94dcfb62f2 100644 --- a/drivers/media/test-drivers/vivid/vivid-sdr-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-sdr-cap.c @@ -214,18 +214,14 @@ static int vivid_thread_sdr_cap(void *data) return 0; } -static int sdr_cap_queue_setup(struct vb2_queue *vq, - unsigned *nbuffers, unsigned *nplanes, - unsigned sizes[], struct device *alloc_devs[]) +static int sdr_cap_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { - /* 2 = max 16-bit sample returned */ - u32 size = SDR_CAP_SAMPLES_PER_BUF * 2; - - if (*nplanes) - return sizes[0] < size ? -EINVAL : 0; *nplanes = 1; - sizes[0] = size; + /* 2 = max 16-bit sample returned */ + sizes[0] = SDR_CAP_SAMPLES_PER_BUF * 2; return 0; } @@ -331,7 +327,7 @@ static void sdr_cap_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_sdr_cap_qops = { - .queue_setup = sdr_cap_queue_setup, + .queue_info = sdr_cap_queue_info, .buf_prepare = sdr_cap_buf_prepare, .buf_queue = sdr_cap_buf_queue, .start_streaming = sdr_cap_start_streaming, diff --git a/drivers/media/test-drivers/vivid/vivid-touch-cap.c b/drivers/media/test-drivers/vivid/vivid-touch-cap.c index 36a781fa17bc..49824674d0e9 100644 --- a/drivers/media/test-drivers/vivid/vivid-touch-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-touch-cap.c @@ -8,22 +8,14 @@ #include "vivid-vid-common.h" #include "vivid-touch-cap.h" -static int touch_cap_queue_setup(struct vb2_queue *vq, unsigned int *nbuffers, - unsigned int *nplanes, unsigned int sizes[], - struct device *alloc_devs[]) +static int touch_cap_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); - struct v4l2_pix_format *f = &dev->tch_format; - unsigned int size = f->sizeimage; - - if (*nplanes) { - if (*nplanes != 1) - return -EINVAL; - return sizes[0] < size ? -EINVAL : 0; - } *nplanes = 1; - sizes[0] = size; + sizes[0] = dev->tch_format.sizeimage; return 0; } @@ -104,7 +96,7 @@ static void touch_cap_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_touch_cap_qops = { - .queue_setup = touch_cap_queue_setup, + .queue_info = touch_cap_queue_info, .buf_prepare = touch_cap_buf_prepare, .buf_queue = touch_cap_buf_queue, .start_streaming = touch_cap_start_streaming, diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c index a09f62c66c33..8d9696d5800a 100644 --- a/drivers/media/test-drivers/vivid/vivid-vbi-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vbi-cap.c @@ -120,9 +120,9 @@ void vivid_sliced_vbi_cap_process(struct vivid_dev *dev, } } -static int vbi_cap_queue_setup(struct vb2_queue *vq, - unsigned *nbuffers, unsigned *nplanes, - unsigned sizes[], struct device *alloc_devs[]) +static int vbi_cap_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); bool is_60hz = dev->std_cap[dev->input] & V4L2_STD_525_60; @@ -133,11 +133,8 @@ static int vbi_cap_queue_setup(struct vb2_queue *vq, if (!vivid_is_sdtv_cap(dev)) return -EINVAL; - if (*nplanes) - return sizes[0] < size ? -EINVAL : 0; - sizes[0] = size; - *nplanes = 1; + sizes[0] = size; return 0; } @@ -224,7 +221,7 @@ static void vbi_cap_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_vbi_cap_qops = { - .queue_setup = vbi_cap_queue_setup, + .queue_info = vbi_cap_queue_info, .buf_prepare = vbi_cap_buf_prepare, .buf_queue = vbi_cap_buf_queue, .start_streaming = vbi_cap_start_streaming, diff --git a/drivers/media/test-drivers/vivid/vivid-vbi-out.c b/drivers/media/test-drivers/vivid/vivid-vbi-out.c index b7a09d2f394e..99a5843e210a 100644 --- a/drivers/media/test-drivers/vivid/vivid-vbi-out.c +++ b/drivers/media/test-drivers/vivid/vivid-vbi-out.c @@ -15,9 +15,9 @@ #include "vivid-vbi-out.h" #include "vivid-vbi-cap.h" -static int vbi_out_queue_setup(struct vb2_queue *vq, - unsigned *nbuffers, unsigned *nplanes, - unsigned sizes[], struct device *alloc_devs[]) +static int vbi_out_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); bool is_60hz = dev->std_out & V4L2_STD_525_60; @@ -28,11 +28,8 @@ static int vbi_out_queue_setup(struct vb2_queue *vq, if (!vivid_is_svid_out(dev)) return -EINVAL; - if (*nplanes) - return sizes[0] < size ? -EINVAL : 0; - sizes[0] = size; - *nplanes = 1; + sizes[0] = size; return 0; } @@ -122,7 +119,7 @@ static void vbi_out_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_vbi_out_qops = { - .queue_setup = vbi_out_queue_setup, + .queue_info = vbi_out_queue_info, .buf_prepare = vbi_out_buf_prepare, .buf_queue = vbi_out_buf_queue, .start_streaming = vbi_out_start_streaming, diff --git a/drivers/media/test-drivers/vivid/vivid-vid-cap.c b/drivers/media/test-drivers/vivid/vivid-vid-cap.c index 27b1918b31c7..d03162887118 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-cap.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-cap.c @@ -72,12 +72,12 @@ static inline unsigned int webcam_ival_count(const struct vivid_dev *dev, return ARRAY_SIZE(webcam_intervals); } -static int vid_cap_queue_setup(struct vb2_queue *vq, - unsigned *nbuffers, unsigned *nplanes, - unsigned sizes[], struct device *alloc_devs[]) +static int vid_cap_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); - unsigned buffers = tpg_g_buffers(&dev->tpg); + unsigned int planes = tpg_g_buffers(&dev->tpg); unsigned h = dev->fmt_cap_rect.height; unsigned p; @@ -98,30 +98,13 @@ static int vid_cap_queue_setup(struct vb2_queue *vq, dev->queue_setup_error = false; return -EINVAL; } - if (*nplanes) { - /* - * Check if the number of requested planes match - * the number of buffers in the current format. You can't mix that. - */ - if (*nplanes != buffers) - return -EINVAL; - for (p = 0; p < buffers; p++) { - if (sizes[p] < tpg_g_line_width(&dev->tpg, p) * h / - dev->fmt_cap->vdownsampling[p] + - dev->fmt_cap->data_offset[p]) - return -EINVAL; - } - } else { - for (p = 0; p < buffers; p++) - sizes[p] = (tpg_g_line_width(&dev->tpg, p) * h) / - dev->fmt_cap->vdownsampling[p] + - dev->fmt_cap->data_offset[p]; - } + *nplanes = planes; + for (p = 0; p < planes; p++) + sizes[p] = (tpg_g_line_width(&dev->tpg, p) * h) / + dev->fmt_cap->vdownsampling[p] + + dev->fmt_cap->data_offset[p]; - *nplanes = buffers; - - dprintk(dev, 1, "%s: count=%d\n", __func__, *nbuffers); - for (p = 0; p < buffers; p++) + for (p = 0; p < planes; p++) dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]); return 0; @@ -250,7 +233,7 @@ static void vid_cap_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_vid_cap_qops = { - .queue_setup = vid_cap_queue_setup, + .queue_info = vid_cap_queue_info, .buf_prepare = vid_cap_buf_prepare, .buf_finish = vid_cap_buf_finish, .buf_queue = vid_cap_buf_queue, diff --git a/drivers/media/test-drivers/vivid/vivid-vid-out.c b/drivers/media/test-drivers/vivid/vivid-vid-out.c index 5ec84db934d6..b183ee1b9048 100644 --- a/drivers/media/test-drivers/vivid/vivid-vid-out.c +++ b/drivers/media/test-drivers/vivid/vivid-vid-out.c @@ -20,9 +20,9 @@ #include "vivid-kthread-out.h" #include "vivid-vid-out.h" -static int vid_out_queue_setup(struct vb2_queue *vq, - unsigned *nbuffers, unsigned *nplanes, - unsigned sizes[], struct device *alloc_devs[]) +static int vid_out_queue_info(struct vb2_queue *vq, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) { struct vivid_dev *dev = vb2_get_drv_priv(vq); const struct vivid_fmt *vfmt = dev->fmt_out; @@ -53,31 +53,12 @@ static int vid_out_queue_setup(struct vb2_queue *vq, return -EINVAL; } - if (*nplanes) { - /* - * Check if the number of requested planes match - * the number of planes in the current format. You can't mix that. - */ - if (*nplanes != planes) - return -EINVAL; - if (sizes[0] < size) - return -EINVAL; - for (p = 1; p < planes; p++) { - if (sizes[p] < dev->bytesperline_out[p] * h / - vfmt->vdownsampling[p] + - vfmt->data_offset[p]) - return -EINVAL; - } - } else { - for (p = 0; p < planes; p++) - sizes[p] = p ? dev->bytesperline_out[p] * h / - vfmt->vdownsampling[p] + - vfmt->data_offset[p] : size; - } - *nplanes = planes; + for (p = 0; p < planes; p++) + sizes[p] = p ? dev->bytesperline_out[p] * h / + vfmt->vdownsampling[p] + + vfmt->data_offset[p] : size; - dprintk(dev, 1, "%s: count=%u\n", __func__, *nbuffers); for (p = 0; p < planes; p++) dprintk(dev, 1, "%s: size[%u]=%u\n", __func__, p, sizes[p]); return 0; @@ -194,8 +175,8 @@ static void vid_out_buf_request_complete(struct vb2_buffer *vb) } const struct vb2_ops vivid_vid_out_qops = { - .queue_setup = vid_out_queue_setup, - .buf_out_validate = vid_out_buf_out_validate, + .queue_info = vid_out_queue_info, + .buf_out_validate = vid_out_buf_out_validate, .buf_prepare = vid_out_buf_prepare, .buf_queue = vid_out_buf_queue, .start_streaming = vid_out_start_streaming,