From patchwork Thu Jun 22 13:13:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5062218vqr; Thu, 22 Jun 2023 06:18:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4zmgvcob5v+7z+Uz8Ep5w+Xchjuo4eHtzD8TEcB+wo3nK5LvLw7JGkHBZbzH+GFcwuB5NJ X-Received: by 2002:a17:90a:660d:b0:261:110e:a4dd with SMTP id l13-20020a17090a660d00b00261110ea4ddmr2425611pjj.25.1687439885426; Thu, 22 Jun 2023 06:18:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687439885; cv=none; d=google.com; s=arc-20160816; b=cZb4C60mf8S40GqX+IceFwBw8HuZe2hvsmiKftU/fcwPV0MbsrlmmhhIXM6j3QY4aA 9Yh9UrIm60X5qt0GGIPK36PDz7UwOmg4XJjibIPlUIAsRXRLaO78nq4JoOTbFebdUn0y fJxyF5NVGl2MZDsB4Pk+YST+PTHx/24kS6tsdGk5+YGKYUCy5sjIxSxeUfzgumIZeFIB eyXNIXZ6KtmK/1MJ2sw6LAC8sSBSKDy8QcnBfoFDvUl4uBXHqzkyjvNKjH7xD9UWyN4r 7u6dMGKhWNo04AsVPtPQvgrkXm9N1SWMIfHoYFJ9a7IBuphHv/oWkUGTsM9Q4lVboJ9l EcGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IM1VEjdMlvdK9orZZk6hdFGEmqDvTnFZrIOV1WkxF1c=; b=MnLHixX4WaBcvaMg1ZtLXhEWfZ89WTGSfB1UuJO5jBHEMM5vAsojiGDGpIFs8rOrRh tz6sVQBk73hYKmHg27j4GhE+XrMJujgu7gzVfhrg+fr4R8DIlbXeSmHu21OUHhNlkQV5 edv0I3M4eTPxkxX9Br/E8MSep+qcAg4hkZ/vw2g1S7fh+oU1VKC3oKi/ZACxaQ9itK8R uVQnyb6D0LgTF7UKKRLvyOMQJS3ohICnwaQ+bw7RfDfSiYzYqDeIBt8qv4dzondTkVTC U5U5kn/q7dkroiaUaQdOQ5fAWPAcFKC40uSrTnyzFXJGWVljLSKl+OTk7qZQLe17uOPz V89w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XA5h3zyG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i190-20020a6387c7000000b0052c2904e37dsi2765402pge.362.2023.06.22.06.17.52; Thu, 22 Jun 2023 06:18:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=XA5h3zyG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231644AbjFVNOJ (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231591AbjFVNOC (ORCPT ); Thu, 22 Jun 2023 09:14:02 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82FD01BD2; Thu, 22 Jun 2023 06:13:59 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id C61286607119; Thu, 22 Jun 2023 14:13:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439638; bh=V+z/vGA0JHcb48G7cBo9k4XKRA8Ie7dXRj1eCbEXorE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XA5h3zyGUpFXNMTpDtJqv4HvAdhzZHSFQBun+ZcIeDuWI0X+ZTiOMVi1yzagwuOBK mImSHD6b4w2uyf3x3xIlpC8ZGdmUAIJlxLlUz2plO9fQNCyHtmhptRrulJ1GtUSibC X2pUXig0SooKWNoCp5+FQRNamobpfSCEjgJTY8OVZKB3FqWCfwHN+o6vqQgv7yrvAi 92rUcuzv5z+rzsomPwmX4BQPH7hByZVLfl7rrWI8fL3yOOxvpZG8RCekHyZayF2bt4 Y26PUqWU999RKrJPfm+BdNOEc31FZObZbJKhA8lR8XWJmg+cqT0iuFd35q2kaHnCUb P4eILdB6JRoFQ== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 01/11] media: videobuf2: Access vb2_queue bufs array through helper functions Date: Thu, 22 Jun 2023 15:13:39 +0200 Message-Id: <20230622131349.144160-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769408965530531707?= X-GMAIL-MSGID: =?utf-8?q?1769408965530531707?= The first step before changing how vb2 buffers are stored into queue is to avoid direct access to bufs arrays. This patch adds 2 helpers functions to add and remove vb2 buffers from a queue. With these 2 and vb2_get_buffer(), bufs field of struct vb2_queue becomes like a private member of the structure. After each call to vb2_get_buffer() we need to be sure that we get a valid pointer so check the return value of all of them. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 215 ++++++++++++++---- .../media/common/videobuf2/videobuf2-v4l2.c | 28 ++- drivers/media/platform/amphion/vpu_dbg.c | 22 +- .../platform/mediatek/jpeg/mtk_jpeg_core.c | 6 +- .../vcodec/vdec/vdec_vp9_req_lat_if.c | 2 +- drivers/media/platform/st/sti/hva/hva-v4l2.c | 4 + drivers/media/test-drivers/visl/visl-dec.c | 28 ++- .../staging/media/atomisp/pci/atomisp_ioctl.c | 2 +- 8 files changed, 240 insertions(+), 67 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index cf6727d9c81f..42fd3984c2bc 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -359,8 +359,16 @@ static void __setup_offsets(struct vb2_buffer *vb) unsigned long off = 0; if (vb->index) { - struct vb2_buffer *prev = q->bufs[vb->index - 1]; - struct vb2_plane *p = &prev->planes[prev->num_planes - 1]; + struct vb2_buffer *prev; + struct vb2_plane *p; + + prev = vb2_get_buffer(q, vb->index - 1); + if (!prev) { + dprintk(q, 1, "can't find the requested buffer\n"); + return; + } + + p = &prev->planes[prev->num_planes - 1]; off = PAGE_ALIGN(p->m.offset + p->length); } @@ -397,6 +405,37 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) vb->skip_cache_sync_on_finish = 1; } +/** + * vb2_queue_add_buffer() - add a buffer to a queue + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @vb: pointer to &struct vb2_buffer to be added to the queue. + * @index: index where add vb2_buffer in the queue + */ +static bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, int index) +{ + if (index < VB2_MAX_FRAME && !q->bufs[index]) { + q->bufs[index] = vb; + vb->index = index; + vb->vb2_queue = q; + return true; + } + + return false; +} + +/** + * vb2_queue_remove_buffer() - remove a buffer from a queue + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @vb: pointer to &struct vb2_buffer to be removed from the queue. + */ +static void vb2_queue_remove_buffer(struct vb2_queue *q, struct vb2_buffer *vb) +{ + if (vb->index < VB2_MAX_FRAME) { + q->bufs[vb->index] = NULL; + vb->vb2_queue = NULL; + } +} + /* * __vb2_queue_alloc() - allocate vb2 buffer structures and (for MMAP type) * video buffer memory for all buffers/planes on the queue and initializes the @@ -425,9 +464,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, } vb->state = VB2_BUF_STATE_DEQUEUED; - vb->vb2_queue = q; vb->num_planes = num_planes; - vb->index = q->num_buffers + buffer; vb->type = q->type; vb->memory = memory; init_buffer_cache_hints(q, vb); @@ -437,7 +474,11 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, } call_void_bufop(q, init_buffer, vb); - q->bufs[vb->index] = vb; + if (!vb2_queue_add_buffer(q, vb, q->num_buffers + buffer)) { + dprintk(q, 1, "failed adding buffer %d to queue\n", buffer); + kfree(vb); + break; + } /* Allocate video buffer memory for the MMAP type */ if (memory == VB2_MEMORY_MMAP) { @@ -445,7 +486,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, if (ret) { dprintk(q, 1, "failed allocating memory for buffer %d\n", buffer); - q->bufs[vb->index] = NULL; + vb2_queue_remove_buffer(q, vb); kfree(vb); break; } @@ -460,7 +501,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, dprintk(q, 1, "buffer %d %p initialization failed\n", buffer, vb); __vb2_buf_mem_free(vb); - q->bufs[vb->index] = NULL; + vb2_queue_remove_buffer(q, vb); kfree(vb); break; } @@ -483,7 +524,7 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; ++buffer) { - vb = q->bufs[buffer]; + vb = vb2_get_buffer(q, buffer); if (!vb) continue; @@ -511,7 +552,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) /* Call driver-provided cleanup function for each buffer, if provided */ for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; ++buffer) { - struct vb2_buffer *vb = q->bufs[buffer]; + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); if (vb && vb->planes[0].mem_priv) call_void_vb_qop(vb, buf_cleanup, vb); @@ -551,15 +592,20 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) q->cnt_unprepare_streaming = 0; } for (buffer = 0; buffer < q->num_buffers; ++buffer) { - struct vb2_buffer *vb = q->bufs[buffer]; - bool unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put || - vb->cnt_mem_prepare != vb->cnt_mem_finish || - vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr || - vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf || - vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf || - vb->cnt_buf_queue != vb->cnt_buf_done || - vb->cnt_buf_prepare != vb->cnt_buf_finish || - vb->cnt_buf_init != vb->cnt_buf_cleanup; + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + bool unbalanced; + + if (!vb) + continue; + + unbalanced = vb->cnt_mem_alloc != vb->cnt_mem_put || + vb->cnt_mem_prepare != vb->cnt_mem_finish || + vb->cnt_mem_get_userptr != vb->cnt_mem_put_userptr || + vb->cnt_mem_attach_dmabuf != vb->cnt_mem_detach_dmabuf || + vb->cnt_mem_map_dmabuf != vb->cnt_mem_unmap_dmabuf || + vb->cnt_buf_queue != vb->cnt_buf_done || + vb->cnt_buf_prepare != vb->cnt_buf_finish || + vb->cnt_buf_init != vb->cnt_buf_cleanup; if (unbalanced || debug) { pr_info(" counters for queue %p, buffer %d:%s\n", @@ -591,8 +637,13 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) /* Free vb2 buffers */ for (buffer = q->num_buffers - buffers; buffer < q->num_buffers; ++buffer) { - kfree(q->bufs[buffer]); - q->bufs[buffer] = NULL; + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + + if (!vb) + continue; + + vb2_queue_remove_buffer(q, vb); + kfree(vb); } q->num_buffers -= buffers; @@ -628,7 +679,12 @@ static bool __buffers_in_use(struct vb2_queue *q) { unsigned int buffer; for (buffer = 0; buffer < q->num_buffers; ++buffer) { - if (vb2_buffer_in_use(q, q->bufs[buffer])) + struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + + if (!vb) + continue; + + if (vb2_buffer_in_use(q, vb)) return true; } return false; @@ -636,7 +692,10 @@ static bool __buffers_in_use(struct vb2_queue *q) void vb2_core_querybuf(struct vb2_queue *q, unsigned int index, void *pb) { - call_void_bufop(q, fill_user_buffer, q->bufs[index], pb); + struct vb2_buffer *vb = vb2_get_buffer(q, index); + + if (vb) + call_void_bufop(q, fill_user_buffer, vb, pb); } EXPORT_SYMBOL_GPL(vb2_core_querybuf); @@ -1547,7 +1606,13 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) struct vb2_buffer *vb; int ret; - vb = q->bufs[index]; + vb = vb2_get_buffer(q, index); + + if (!vb) { + dprintk(q, 1, "can't find the requested buffer\n"); + return -EINVAL; + } + if (vb->state != VB2_BUF_STATE_DEQUEUED) { dprintk(q, 1, "invalid buffer state %s\n", vb2_state_name(vb->state)); @@ -1618,7 +1683,11 @@ static int vb2_start_streaming(struct vb2_queue *q) * correctly return them to vb2. */ for (i = 0; i < q->num_buffers; ++i) { - vb = q->bufs[i]; + vb = vb2_get_buffer(q, i); + + if (!vb) + continue; + if (vb->state == VB2_BUF_STATE_ACTIVE) vb2_buffer_done(vb, VB2_BUF_STATE_QUEUED); } @@ -1646,7 +1715,12 @@ int vb2_core_qbuf(struct vb2_queue *q, unsigned int index, void *pb, return -EIO; } - vb = q->bufs[index]; + vb = vb2_get_buffer(q, index); + + if (!vb) { + dprintk(q, 1, "can't find the requested buffer\n"); + return -EINVAL; + } if (!req && vb->state != VB2_BUF_STATE_IN_REQUEST && q->requires_requests) { @@ -2022,12 +2096,18 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * to vb2 in stop_streaming(). */ if (WARN_ON(atomic_read(&q->owned_by_drv_count))) { - for (i = 0; i < q->num_buffers; ++i) - if (q->bufs[i]->state == VB2_BUF_STATE_ACTIVE) { + for (i = 0; i < q->num_buffers; ++i) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); + + if (!vb) + continue; + + if (vb->state == VB2_BUF_STATE_ACTIVE) { pr_warn("driver bug: stop_streaming operation is leaving buf %p in active state\n", - q->bufs[i]); - vb2_buffer_done(q->bufs[i], VB2_BUF_STATE_ERROR); + vb); + vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); } + } /* Must be zero now */ WARN_ON(atomic_read(&q->owned_by_drv_count)); } @@ -2061,9 +2141,14 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * be changed, so we can't move the buf_finish() to __vb2_dqbuf(). */ for (i = 0; i < q->num_buffers; ++i) { - struct vb2_buffer *vb = q->bufs[i]; - struct media_request *req = vb->req_obj.req; + struct vb2_buffer *vb; + struct media_request *req; + vb = vb2_get_buffer(q, i); + if (!vb) + continue; + + req = vb->req_obj.req; /* * If a request is associated with this buffer, then * call buf_request_cancel() to give the driver to complete() @@ -2215,7 +2300,10 @@ static int __find_plane_by_offset(struct vb2_queue *q, unsigned long off, * return its buffer and plane numbers. */ for (buffer = 0; buffer < q->num_buffers; ++buffer) { - vb = q->bufs[buffer]; + vb = vb2_get_buffer(q, buffer); + + if (!vb) + continue; for (plane = 0; plane < vb->num_planes; ++plane) { if (vb->planes[plane].m.offset == off) { @@ -2262,7 +2350,12 @@ int vb2_core_expbuf(struct vb2_queue *q, int *fd, unsigned int type, return -EINVAL; } - vb = q->bufs[index]; + vb = vb2_get_buffer(q, index); + + if (!vb) { + dprintk(q, 1, "can't find the requested buffer\n"); + return -EINVAL; + } if (plane >= vb->num_planes) { dprintk(q, 1, "buffer plane out of range\n"); @@ -2339,7 +2432,13 @@ int vb2_mmap(struct vb2_queue *q, struct vm_area_struct *vma) if (ret) goto unlock; - vb = q->bufs[buffer]; + vb = vb2_get_buffer(q, buffer); + + if (!vb) { + dprintk(q, 1, "can't find the requested buffer\n"); + ret = -EINVAL; + goto unlock; + } /* * MMAP requires page_aligned buffers. @@ -2396,7 +2495,12 @@ unsigned long vb2_get_unmapped_area(struct vb2_queue *q, if (ret) goto unlock; - vb = q->bufs[buffer]; + vb = vb2_get_buffer(q, buffer); + if (!vb) { + dprintk(q, 1, "can't find the requested buffer\n"); + ret = -EINVAL; + goto unlock; + } vaddr = vb2_plane_vaddr(vb, plane); mutex_unlock(&q->mmap_lock); @@ -2625,6 +2729,7 @@ struct vb2_fileio_data { static int __vb2_init_fileio(struct vb2_queue *q, int read) { struct vb2_fileio_data *fileio; + struct vb2_buffer *vb; int i, ret; unsigned int count = 0; @@ -2679,7 +2784,13 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Check if plane_count is correct * (multiplane buffers are not supported). */ - if (q->bufs[0]->num_planes != 1) { + vb = vb2_get_buffer(q, 0); + if (!vb) { + ret = -EBUSY; + goto err_reqbufs; + } + + if (vb->num_planes != 1) { ret = -EBUSY; goto err_reqbufs; } @@ -2688,12 +2799,17 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Get kernel address of each buffer. */ for (i = 0; i < q->num_buffers; i++) { - fileio->bufs[i].vaddr = vb2_plane_vaddr(q->bufs[i], 0); + vb = vb2_get_buffer(q, i); + + if (!vb) + continue; + + fileio->bufs[i].vaddr = vb2_plane_vaddr(vb, 0); if (fileio->bufs[i].vaddr == NULL) { ret = -EINVAL; goto err_reqbufs; } - fileio->bufs[i].size = vb2_plane_size(q->bufs[i], 0); + fileio->bufs[i].size = vb2_plane_size(vb, 0); } /* @@ -2821,15 +2937,18 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ fileio->cur_index = index; buf = &fileio->bufs[index]; - b = q->bufs[index]; + b = vb2_get_buffer(q, index); + + if (!b) + return -EINVAL; /* * Get number of bytes filled by the driver */ buf->pos = 0; buf->queued = 0; - buf->size = read ? vb2_get_plane_payload(q->bufs[index], 0) - : vb2_plane_size(q->bufs[index], 0); + buf->size = read ? vb2_get_plane_payload(b, 0) + : vb2_plane_size(b, 0); /* Compensate for data_offset on read in the multiplanar case. */ if (is_multiplanar && read && b->planes[0].data_offset < buf->size) { @@ -2872,8 +2991,12 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ * Queue next buffer if required. */ if (buf->pos == buf->size || (!read && fileio->write_immediately)) { - struct vb2_buffer *b = q->bufs[index]; + struct vb2_buffer *b = vb2_get_buffer(q, index); + if (!b) { + dprintk(q, 1, "can't find the requested buffer\n"); + return -EINVAL; + } /* * Check if this is the last buffer to read. */ @@ -2899,7 +3022,7 @@ static size_t __vb2_perform_fileio(struct vb2_queue *q, char __user *data, size_ */ buf->pos = 0; buf->queued = 1; - buf->size = vb2_plane_size(q->bufs[index], 0); + buf->size = vb2_plane_size(b, 0); fileio->q_count += 1; /* * If we are queuing up buffers for the first time, then @@ -2970,7 +3093,9 @@ static int vb2_thread(void *data) * Call vb2_dqbuf to get buffer back. */ if (prequeue) { - vb = q->bufs[index++]; + vb = vb2_get_buffer(q, index++); + if (!vb) + continue; prequeue--; } else { call_void_qop(q, wait_finish, q); @@ -2979,7 +3104,7 @@ static int vb2_thread(void *data) call_void_qop(q, wait_prepare, q); dprintk(q, 5, "file io: vb2_dqbuf result: %d\n", ret); if (!ret) - vb = q->bufs[index]; + vb = vb2_get_buffer(q, index); } if (ret || threadio->stop) break; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index c7a54d82a55e..724135d41f7f 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -383,8 +383,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md return -EINVAL; } - if (q->bufs[b->index] == NULL) { - /* Should never happen */ + if (!vb2_get_buffer(q, b->index)) { dprintk(q, 1, "%s: buffer is NULL\n", opname); return -EINVAL; } @@ -394,7 +393,7 @@ static int vb2_queue_or_prepare_buf(struct vb2_queue *q, struct media_device *md return -EINVAL; } - vb = q->bufs[b->index]; + vb = vb2_get_buffer(q, b->index); vbuf = to_vb2_v4l2_buffer(vb); ret = __verify_planes_array(vb, b); if (ret) @@ -628,11 +627,18 @@ static const struct vb2_buf_ops v4l2_buf_ops = { struct vb2_buffer *vb2_find_buffer(struct vb2_queue *q, u64 timestamp) { unsigned int i; + struct vb2_buffer *vb2; - for (i = 0; i < q->num_buffers; i++) - if (q->bufs[i]->copied_timestamp && - q->bufs[i]->timestamp == timestamp) - return vb2_get_buffer(q, i); + for (i = 0; i < q->num_buffers; i++) { + vb2 = vb2_get_buffer(q, i); + + if (!vb2) + continue; + + if (vb2->copied_timestamp && + vb2->timestamp == timestamp) + return vb2; + } return NULL; } EXPORT_SYMBOL_GPL(vb2_find_buffer); @@ -664,7 +670,13 @@ int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b) dprintk(q, 1, "buffer index out of range\n"); return -EINVAL; } - vb = q->bufs[b->index]; + vb = vb2_get_buffer(q, b->index); + + if (!vb) { + dprintk(q, 1, "can't find the requested buffer\n"); + return -EINVAL; + } + ret = __verify_planes_array(vb, b); if (!ret) vb2_core_querybuf(q, b->index, b); diff --git a/drivers/media/platform/amphion/vpu_dbg.c b/drivers/media/platform/amphion/vpu_dbg.c index 44b830ae01d8..e2c371c2fde5 100644 --- a/drivers/media/platform/amphion/vpu_dbg.c +++ b/drivers/media/platform/amphion/vpu_dbg.c @@ -133,11 +133,18 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) vq = v4l2_m2m_get_src_vq(inst->fh.m2m_ctx); for (i = 0; i < vq->num_buffers; i++) { - struct vb2_buffer *vb = vq->bufs[i]; - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_buffer *vb; + struct vb2_v4l2_buffer *vbuf; + + vb = vb2_get_buffer(vq, i); + if (!vb) + continue; if (vb->state == VB2_BUF_STATE_DEQUEUED) continue; + + vbuf = to_vb2_v4l2_buffer(vb); + num = scnprintf(str, sizeof(str), "output [%2d] state = %10s, %8s\n", i, vb2_stat_name[vb->state], @@ -148,11 +155,18 @@ static int vpu_dbg_instance(struct seq_file *s, void *data) vq = v4l2_m2m_get_dst_vq(inst->fh.m2m_ctx); for (i = 0; i < vq->num_buffers; i++) { - struct vb2_buffer *vb = vq->bufs[i]; - struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct vb2_buffer *vb; + struct vb2_v4l2_buffer *vbuf; + + vb = vb2_get_buffer(vq, i); + if (!vb) + continue; if (vb->state == VB2_BUF_STATE_DEQUEUED) continue; + + vbuf = to_vb2_v4l2_buffer(vb); + num = scnprintf(str, sizeof(str), "capture[%2d] state = %10s, %8s\n", i, vb2_stat_name[vb->state], diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c index 0051f372a66c..ea37069ba355 100644 --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c @@ -603,7 +603,11 @@ static int mtk_jpeg_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) return -EINVAL; } - vb = vq->bufs[buf->index]; + vb = vb2_get_buffer(vq, buf->index); + if (!vb) { + dev_err(ctx->jpeg->dev, "buffer not found\n"); + return -EINVAL; + } jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(vb); jpeg_src_buf->bs_size = buf->m.planes[0].bytesused; diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c index cf16cf2807f0..6532a69f1fa8 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c @@ -1701,7 +1701,7 @@ static int vdec_vp9_slice_setup_core_buffer(struct vdec_vp9_slice_instance *inst /* update internal buffer's width/height */ for (i = 0; i < vq->num_buffers; i++) { - if (vb == vq->bufs[i]) { + if (vb == vb2_get_buffer(vq, i)) { instance->dpb[i].width = w; instance->dpb[i].height = h; break; diff --git a/drivers/media/platform/st/sti/hva/hva-v4l2.c b/drivers/media/platform/st/sti/hva/hva-v4l2.c index 3a848ca32a0e..326be09bdb55 100644 --- a/drivers/media/platform/st/sti/hva/hva-v4l2.c +++ b/drivers/media/platform/st/sti/hva/hva-v4l2.c @@ -577,6 +577,10 @@ static int hva_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf) } vb2_buf = vb2_get_buffer(vq, buf->index); + if (!vb2_buf) { + dev_dbg(dev, "%s buffer index %d not found\n", ctx->name, buf->index); + return -EINVAL; + } stream = to_hva_stream(to_vb2_v4l2_buffer(vb2_buf)); stream->bytesused = buf->bytesused; } diff --git a/drivers/media/test-drivers/visl/visl-dec.c b/drivers/media/test-drivers/visl/visl-dec.c index 318d675e5668..ba20ea998d19 100644 --- a/drivers/media/test-drivers/visl/visl-dec.c +++ b/drivers/media/test-drivers/visl/visl-dec.c @@ -290,13 +290,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) for (i = 0; i < out_q->num_buffers; i++) { char entry[] = "index: %u, state: %s, request_fd: %d, "; u32 old_len = len; - char *q_status = visl_get_vb2_state(out_q->bufs[i]->state); + struct vb2_buffer *vb2; + char *q_status; + + vb2 = vb2_get_buffer(out_q, i); + if (!vb2) + continue; + + q_status = visl_get_vb2_state(vb2->state); len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len, entry, i, q_status, - to_vb2_v4l2_buffer(out_q->bufs[i])->request_fd); + to_vb2_v4l2_buffer(vb2)->request_fd); - len += visl_fill_bytesused(to_vb2_v4l2_buffer(out_q->bufs[i]), + len += visl_fill_bytesused(to_vb2_v4l2_buffer(vb2), &buf[len], TPG_STR_BUF_SZ - len); @@ -342,13 +349,20 @@ static void visl_tpg_fill(struct visl_ctx *ctx, struct visl_run *run) len = 0; for (i = 0; i < cap_q->num_buffers; i++) { u32 old_len = len; - char *q_status = visl_get_vb2_state(cap_q->bufs[i]->state); + struct vb2_buffer *vb2; + char *q_status; + + vb2 = vb2_get_buffer(cap_q, i); + if (!vb2) + continue; + + q_status = visl_get_vb2_state(vb2->state); len += scnprintf(&buf[len], TPG_STR_BUF_SZ - len, "index: %u, status: %s, timestamp: %llu, is_held: %d", - cap_q->bufs[i]->index, q_status, - cap_q->bufs[i]->timestamp, - to_vb2_v4l2_buffer(cap_q->bufs[i])->is_held); + vb2->index, q_status, + vb2->timestamp, + to_vb2_v4l2_buffer(vb2)->is_held); tpg_gen_text(&ctx->tpg, basep, line++ * line_height, 16, &buf[old_len]); frame_dprintk(ctx->dev, run->dst->sequence, "%s", &buf[old_len]); diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index 384f31fc66c5..ec7e05263c8e 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -1077,7 +1077,7 @@ static int atomisp_dqbuf_wrapper(struct file *file, void *fh, struct v4l2_buffer if (ret) return ret; - vb = pipe->vb_queue.bufs[buf->index]; + vb = vb2_get_buffer(pipe->vb_queue, buf->index); frame = vb_to_frame(vb); buf->reserved = asd->frame_status[buf->index]; From patchwork Thu Jun 22 13:13:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111661 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5062031vqr; Thu, 22 Jun 2023 06:17:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZAGq2isNNWHumnbRukoqHtinWINsA6e/MwixUNfVDgWSxYchPW+3BxVFvM9Tz7xMPOqAH X-Received: by 2002:a17:90a:ead2:b0:25e:b066:8084 with SMTP id ev18-20020a17090aead200b0025eb0668084mr11684785pjb.18.1687439873262; Thu, 22 Jun 2023 06:17:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687439873; cv=none; d=google.com; s=arc-20160816; b=tZAOQlX7B4or3Y0nYs72PdGUKcWGwYQ5LxVUsdMD6t1mcOGI5J2xtM6r7losAp1SvH jxMcl1N2zlw+vuby2TclvHc1MpNTZNVKovmvU/vl6kDmVd9jpj0iKgO3+odzTa7Au+pO yc4bZ52jc18izBTxueRqjhycPkyxybC5A9my1oYUtahgHXVgwuDkMmjqg2jAx/y/e3bV D47HQb00ezlWShZMjYcFmdo0Ren7tmlrXMyb+bkvEABVnX7C0M8MMesv16/iYrZcNsgc 5loys9DqxLBEVwqxftuf0IeEloF03RcJgJr64UcbYqX17YTekoa7sKvBGg2Ll2KibA53 ihvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tUqmDmDOiKsYiM3yp3gWwrv6+DRsJqG/khjYHHKOPZA=; b=diE1g74ap1v2kU6+aETg6nb3KQk6aFoL8IVEfoe2N6Xy9bPeRBOx74NTjmQI+5lkkF fx1bmTCGq5jbkGSGOd6McBXPcgQoLo0ZKoO9Vt1b5JHdJo+Whw2MzyQCouUnTTUcuKT0 yKnVo1VxJiF5b2yrq0wVhhAJfilkxdtRUE1lX5xg6kFxHmSlfQX7k8d8u2ZvpNHb0mgQ TRN9GaoPfJug4KhToFKfnjvtkV3+0uSKtaxFKHuuxdT2RSOQAQSTnvGbLbIcmGvA3us5 FmcnYlw4qEtfY5lOwcrkl48r/Jj+CWcdBIxELUcC2Ov0t4SgdXFseYKYwhRrLGZwaByu ciZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=cvR797bh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kk14-20020a17090b4a0e00b0025df9f1f7a1si7390832pjb.94.2023.06.22.06.17.40; Thu, 22 Jun 2023 06:17:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=cvR797bh; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231616AbjFVNOF (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231558AbjFVNOB (ORCPT ); Thu, 22 Jun 2023 09:14:01 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2C761BD3; Thu, 22 Jun 2023 06:13:59 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4FB41660711E; Thu, 22 Jun 2023 14:13:58 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439638; bh=t8kITWrGl0OsCDx7lvzHoBExx5sUqFU5dAXRs/EKO4E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cvR797bhp0zTiCSdScfhlbTHiIQr+utHyzNqQOongrdtKYpDwzUY0dWzKZPiFEqnU Vp+M7Y2JVVVAbeAA1bPTwIAWMVRo1zoQ0Jo632vU3uYP8DwzoI6ae2TvgAxP4N7hGb tC991tunarQYTHZ42wBjAFs76L3DMPSL4Z3l/u4D5NyNX/M1MdoAi2HKtFFo5zj5dv LCHML8nEK+y2kfaAqa+i4SV7jLe/BQQRK0t1vmXPQVo/UKPWsX035tkjUJO/rrc/Np rcZUErqSo9hyzmJXEaydmOtL+Wr2cCXILV8i/zNvZ5ymW326nqxtRdxJawJSvSIt07 4SjxbEmqKZYvw== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 02/11] media: videobuf2: Use Xarray instead of static buffers array Date: Thu, 22 Jun 2023 15:13:40 +0200 Message-Id: <20230622131349.144160-3-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769408952708443009?= X-GMAIL-MSGID: =?utf-8?q?1769408952708443009?= Instead of a static array change bufs to a dynamically allocated array. This will allow to store more video buffers if needed. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 38 +++++++++++-------- include/media/videobuf2-core.h | 6 +-- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 42fd3984c2bc..f1ff7af34a9f 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -409,18 +409,24 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) * vb2_queue_add_buffer() - add a buffer to a queue * @q: pointer to &struct vb2_queue with videobuf2 queue. * @vb: pointer to &struct vb2_buffer to be added to the queue. - * @index: index where add vb2_buffer in the queue */ -static bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, int index) +static bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb) { - if (index < VB2_MAX_FRAME && !q->bufs[index]) { - q->bufs[index] = vb; - vb->index = index; - vb->vb2_queue = q; - return true; - } + struct xa_limit range = { + .max = UINT_MAX, + .min = q->num_buffers, + }; + u32 index; + int ret; - return false; + ret = xa_alloc(&q->bufs, &index, vb, range, GFP_KERNEL); + if (ret) + return false; + + vb->index = index; + vb->vb2_queue = q; + + return true; } /** @@ -430,10 +436,8 @@ static bool vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, int */ static void vb2_queue_remove_buffer(struct vb2_queue *q, struct vb2_buffer *vb) { - if (vb->index < VB2_MAX_FRAME) { - q->bufs[vb->index] = NULL; - vb->vb2_queue = NULL; - } + xa_erase(&q->bufs, vb->index); + vb->vb2_queue = NULL; } /* @@ -474,7 +478,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, } call_void_bufop(q, init_buffer, vb); - if (!vb2_queue_add_buffer(q, vb, q->num_buffers + buffer)) { + if (!vb2_queue_add_buffer(q, vb)) { dprintk(q, 1, "failed adding buffer %d to queue\n", buffer); kfree(vb); break; @@ -930,7 +934,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, } mutex_lock(&q->mmap_lock); - q->num_buffers = allocated_buffers; + q->num_buffers += allocated_buffers; if (ret < 0) { /* @@ -2547,6 +2551,9 @@ int vb2_core_queue_init(struct vb2_queue *q) mutex_init(&q->mmap_lock); init_waitqueue_head(&q->done_wq); + xa_init_flags(&q->bufs, XA_FLAGS_ALLOC); + q->num_buffers = 0; + q->memory = VB2_MEMORY_UNKNOWN; if (q->buf_struct_size == 0) @@ -2574,6 +2581,7 @@ void vb2_core_queue_release(struct vb2_queue *q) mutex_lock(&q->mmap_lock); __vb2_queue_free(q, q->num_buffers); mutex_unlock(&q->mmap_lock); + xa_destroy(&q->bufs); } EXPORT_SYMBOL_GPL(vb2_core_queue_release); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 4b6a9d2ea372..77921cf894ef 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -619,7 +619,7 @@ struct vb2_queue { struct mutex mmap_lock; unsigned int memory; enum dma_data_direction dma_dir; - struct vb2_buffer *bufs[VB2_MAX_FRAME]; + struct xarray bufs; unsigned int num_buffers; struct list_head queued_list; @@ -1239,9 +1239,7 @@ static inline void vb2_clear_last_buffer_dequeued(struct vb2_queue *q) static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, unsigned int index) { - if (index < q->num_buffers) - return q->bufs[index]; - return NULL; + return xa_load(&q->bufs, index); } /* From patchwork Thu Jun 22 13:13:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111666 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5069846vqr; Thu, 22 Jun 2023 06:29:46 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6hYNReeKYKByKk9QiUOT37yrqQCkbiRd7YS3ZQJueizs/pNWIIHGIk/6Tc39C1+qQLeR+E X-Received: by 2002:a17:90a:43a7:b0:25e:f696:1cf8 with SMTP id r36-20020a17090a43a700b0025ef6961cf8mr18460064pjg.14.1687440585617; Thu, 22 Jun 2023 06:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440585; cv=none; d=google.com; s=arc-20160816; b=gfWVZ2dkVq/m47p1SRWiU7tV+/phrIrPfj8We+Q48a5C3evvCT34zOw3wylNeEaagM r+dJTc+x8y+xjCpcKHKwGsi2OzUcCUVjVW+Vcx0hFMcU3cf9SduWLQUMV/WubD+rsrX3 jW+RvmOs1nTYDbiVOdDdWwbJqbPWZ+bTe2P3gKKUh26cP0XN0Dds7iUNbkepDeEl3AgX xHkOCDiFkPnYtPyiPb4sWSE0BUg2uCO3WJQ+QteotFfBzCjECfzgZ7TAFKlhs/v1kk7t egKsyzHJeE6NHwjtbzHF7TxiC6HWP7JtkLcUQzQSvZKcS+Pcd0yrlTRp0erAvvXktXYP f7og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=aU4uqzyBnVXuHqSu4W5OX49lZdoy6EMluIy3VQqIk7w=; b=svoGvzFui9c2QVfkugKusrRlu0rDmg9JOvKi2k23oyArExliGBnWaI+3CjlIaSlFY3 CHWQjHStK8TibbyZKvC59wzunEcgmaooxVN32W/SUCf1s/vBeJoJydqzla6MAbMIGK7Q 0OPFNtUQYIMXiBMYlC1jgfAELzDXR7PVJB9ncKV62KMjwpyxbG1GAtNkvYdXsLZ6j9sG 2RaEcBnEIciz/+mw1qOzE9DVklDq3WQwI2WqwN0RiUOANMM8twPdxO0cIGRyZTFx09zz vq7PiI2/OgMabb9RXtGjTJ42QbcERWlUsP4x7LYIjK/g6XoiaolXHBurVcjpFAJjukm9 e9Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ZxTiNMH1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a17090a4b0700b0024df18639fasi13099569pjh.154.2023.06.22.06.29.23; Thu, 22 Jun 2023 06:29:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ZxTiNMH1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231713AbjFVNOa (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231586AbjFVNOB (ORCPT ); Thu, 22 Jun 2023 09:14:01 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EDCF1BD7; Thu, 22 Jun 2023 06:14:00 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id CAD856607121; Thu, 22 Jun 2023 14:13:58 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439639; bh=AARgP4b8y2Xc1aS5YL8NqmR9rbb2o30p7zaaWtG32hU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZxTiNMH1hDCi1nmk94lamG1X/2drYWUgcsGIuJCmAR05Ubc5m56NTZ+iGvO/n0COj nne8y6hoklBPJ4I4t+WDe+eTO2xu+fS1eTuXPRnUScsede9aTvM654IoXdkFqk/GnG 3mlubjY9Uu2T3PqDO/7ETnGGa7FqWaMwdW5l/zCaTM9bRqXcsyj6ro6OMKhffFAnL6 jUETkWD2LsuwYKGL2MAfHw4aQEE6iuZZD+SfZ8qz1s9PM68lv2tgozf3XHVDQd3dHi k5RcUi5+R72uhu9shyNTsVUXzQDGH02zvUa16zSSJTA1JSma86yxCtjJ7lcwBFsmUI rQ2YJSV5cVQ1A== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 03/11] media: videobuf2: Remove VB2_MAX_FRAME limit on buffer storage Date: Thu, 22 Jun 2023 15:13:41 +0200 Message-Id: <20230622131349.144160-4-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769409699444637807?= X-GMAIL-MSGID: =?utf-8?q?1769409699444637807?= Remove VB2_MAX_FRAME buffer limit since Xarray allows to store more than that. Signed-off-by: Benjamin Gaignard --- drivers/media/common/videobuf2/videobuf2-core.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index f1ff7af34a9f..86e1e926fa45 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -455,9 +455,9 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, struct vb2_buffer *vb; int ret; - /* Ensure that q->num_buffers+num_buffers is below VB2_MAX_FRAME */ + /* Ensure that q->num_buffers + num_buffers is UINT_MAX */ num_buffers = min_t(unsigned int, num_buffers, - VB2_MAX_FRAME - q->num_buffers); + UINT_MAX - q->num_buffers); for (buffer = 0; buffer < num_buffers; ++buffer) { /* Allocate vb2 buffer structures */ @@ -858,9 +858,9 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Make sure the requested values and current defaults are sane. */ - WARN_ON(q->min_buffers_needed > VB2_MAX_FRAME); + WARN_ON(q->min_buffers_needed > UINT_MAX); num_buffers = max_t(unsigned int, *count, q->min_buffers_needed); - num_buffers = min_t(unsigned int, num_buffers, VB2_MAX_FRAME); + num_buffers = min_t(unsigned int, num_buffers, UINT_MAX); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); /* * Set this now to ensure that drivers see the correct q->memory value @@ -976,11 +976,6 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, bool no_previous_buffers = !q->num_buffers; int ret; - if (q->num_buffers == VB2_MAX_FRAME) { - dprintk(q, 1, "maximum number of buffers already allocated\n"); - return -ENOBUFS; - } - if (no_previous_buffers) { if (q->waiting_in_dqbuf && *count) { dprintk(q, 1, "another dup()ped fd is waiting for a buffer\n"); @@ -1005,7 +1000,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, return -EINVAL; } - num_buffers = min(*count, VB2_MAX_FRAME - q->num_buffers); + num_buffers = min(*count, UINT_MAX - q->num_buffers); if (requested_planes && requested_sizes) { num_planes = requested_planes; From patchwork Thu Jun 22 13:13:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111668 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5070454vqr; Thu, 22 Jun 2023 06:30:34 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Gxp9RMjWCb+J7z0iKxRNtobd+d6kQLo0CFWf+8V85Phs6wOpbZyWU3ul2GCseyKTHTbOK X-Received: by 2002:a17:90a:35d:b0:256:1700:5ec9 with SMTP id 29-20020a17090a035d00b0025617005ec9mr7896627pjf.31.1687440633887; Thu, 22 Jun 2023 06:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440633; cv=none; d=google.com; s=arc-20160816; b=jME/zTHr5etiDEUOvvTYCqn8TLkr0Blqy2kjrIdvI4CC0zRR0STOH7JYQzrvFbPnza rAO1A4I0prdOkb4zO10HOeE8mqww17GOvBFYY4Nof6MF8IqVJp2Ivjj4yd1+cEsqaoHp Uah9kqr3Of4zBIEzOftcdEW9L2bHUVBbTfsNlhG3UiK+dUdB3l0chaQ54TAfvwe57EON 1NEjr813avGe5eOFKMeZ6i7+ijXAQnBPhoI9IoFh/aAp/M76FWbB8gvMNAoGjgIrzanO rfbB0WMdbCOjIBGJPf6VIAaszFVdDUKHGqeZhTyOrr7fnXTi+XboVXgQHNFfayM+SEWr RP/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ozkj+n5thfe5eIFxWJdv0sfsIqK2bkfrqNsGEmo8MWk=; b=wRZBOXC/YAZo1Tgg/oEPHxJNjosDJ5BGdjhz9TYSrMJOI6PfUeVSf+Pt1bO94Im6Z5 Bs7qLltDY8i7QYbyXAm9UL1xk3vyyAT8kyX7hGV9PRxE17duiOrP2IQJl4El2X9nnuYu dgOswV/eIjwNOUSyQeUhBfdoH8MOF1iYt1AyGNtKZZbBaX/QjODwZHTd+WfQXgSxT8lu hGfdflCenghTufTxCHRPTe13NwUoiXT+XCotvl5bsse6JOB3Ih4rIICb4joig+9b1ECJ gQks3A4LzEwcxPQ3vLyEs1DmCe7Ba9yQ7C2Xs7Sc1JdDg4lYaUVMXXBiA3wLguhhUzSl ATRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aMvDuxSN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a17090a4b0700b0024df18639fasi13099569pjh.154.2023.06.22.06.30.19; Thu, 22 Jun 2023 06:30:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=aMvDuxSN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231696AbjFVNOV (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231599AbjFVNOC (ORCPT ); Thu, 22 Jun 2023 09:14:02 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D98831BF5; Thu, 22 Jun 2023 06:14:00 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4DD366607128; Thu, 22 Jun 2023 14:13:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439639; bh=Gzf/ktNZ3NOcffLCLpulGdLdygvof7OsvFbMBCI7WyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aMvDuxSN0D+ICceIa2k0/8ICJfyucHrHRy6tMCtP/unZ6iPcQKKAEFLkWsTfyZZKa tYZvz+3gLPPQgWb5r2zlBEe0pFVZEHNFtzut4Y2T929FVyI6i1VRb5DpNhpRGOljp8 8ChyFAD7r82W9PHtPu4lrMufSVdbn+TERA+ogPra54nVT1haZrF3K6Hd5NL7Po/6jX mCpx047zWZHtydN5YRQypOVaHxAxXx0tJgal/ffcKkpC6Q+o3m8R3dICGjJz6aqD98 eM0fO8vwWuZcWWfz5EyZzI2f9vUdJ0vr03/nsSOcUe3jyH+deoHQMw9RBI+u1WworB /9QEx87W6XWaA== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 04/11] media: videobuf2: Stop define VB2_MAX_FRAME as global Date: Thu, 22 Jun 2023 15:13:42 +0200 Message-Id: <20230622131349.144160-5-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769409750232156811?= X-GMAIL-MSGID: =?utf-8?q?1769409750232156811?= After changing bufs arrays to a dynamic allocated array VB2_MAX_FRAME doesn't mean anything for videobuf2 core. Remove it from the core definitions but keep it for drivers internal needs. Signed-off-by: Benjamin Gaignard --- drivers/media/common/videobuf2/videobuf2-core.c | 2 ++ drivers/media/platform/amphion/vdec.c | 1 + .../media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c | 2 ++ drivers/media/platform/qcom/venus/hfi.h | 2 ++ drivers/media/platform/verisilicon/hantro_hw.h | 2 ++ drivers/staging/media/ipu3/ipu3-v4l2.c | 2 ++ include/media/videobuf2-core.h | 1 - include/media/videobuf2-v4l2.h | 4 ---- 8 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 86e1e926fa45..899783f67580 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -31,6 +31,8 @@ #include +#define VB2_MAX_FRAME 32 + static int debug; module_param(debug, int, 0644); diff --git a/drivers/media/platform/amphion/vdec.c b/drivers/media/platform/amphion/vdec.c index 3fa1a74a2e20..b3219f6d17fa 100644 --- a/drivers/media/platform/amphion/vdec.c +++ b/drivers/media/platform/amphion/vdec.c @@ -28,6 +28,7 @@ #define VDEC_MIN_BUFFER_CAP 8 #define VDEC_MIN_BUFFER_OUT 8 +#define VB2_MAX_FRAME 32 struct vdec_fs_info { char name[8]; diff --git a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c index 6532a69f1fa8..a1e0f24bb91c 100644 --- a/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c +++ b/drivers/media/platform/mediatek/vcodec/vdec/vdec_vp9_req_lat_if.c @@ -16,6 +16,8 @@ #include "../vdec_drv_if.h" #include "../vdec_vpu_if.h" +#define VB2_MAX_FRAME 32 + /* reset_frame_context defined in VP9 spec */ #define VP9_RESET_FRAME_CONTEXT_NONE0 0 #define VP9_RESET_FRAME_CONTEXT_NONE1 1 diff --git a/drivers/media/platform/qcom/venus/hfi.h b/drivers/media/platform/qcom/venus/hfi.h index f25d412d6553..bd5ca5a8b945 100644 --- a/drivers/media/platform/qcom/venus/hfi.h +++ b/drivers/media/platform/qcom/venus/hfi.h @@ -10,6 +10,8 @@ #include "hfi_helper.h" +#define VB2_MAX_FRAME 32 + #define VIDC_SESSION_TYPE_VPE 0 #define VIDC_SESSION_TYPE_ENC 1 #define VIDC_SESSION_TYPE_DEC 2 diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h index e83f0c523a30..9e8faf7ba6fb 100644 --- a/drivers/media/platform/verisilicon/hantro_hw.h +++ b/drivers/media/platform/verisilicon/hantro_hw.h @@ -15,6 +15,8 @@ #include #include +#define VB2_MAX_FRAME 32 + #define DEC_8190_ALIGN_MASK 0x07U #define MB_DIM 16 diff --git a/drivers/staging/media/ipu3/ipu3-v4l2.c b/drivers/staging/media/ipu3/ipu3-v4l2.c index e530767e80a5..6627b5c2d4d6 100644 --- a/drivers/staging/media/ipu3/ipu3-v4l2.c +++ b/drivers/staging/media/ipu3/ipu3-v4l2.c @@ -10,6 +10,8 @@ #include "ipu3.h" #include "ipu3-dmamap.h" +#define VB2_MAX_FRAME 32 + /******************** v4l2_subdev_ops ********************/ #define IPU3_RUNNING_MODE_VIDEO 0 diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 77921cf894ef..080b783d608d 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -20,7 +20,6 @@ #include #include -#define VB2_MAX_FRAME (32) #define VB2_MAX_PLANES (8) /** diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 5a845887850b..88a7a565170e 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -15,10 +15,6 @@ #include #include -#if VB2_MAX_FRAME != VIDEO_MAX_FRAME -#error VB2_MAX_FRAME != VIDEO_MAX_FRAME -#endif - #if VB2_MAX_PLANES != VIDEO_MAX_PLANES #error VB2_MAX_PLANES != VIDEO_MAX_PLANES #endif From patchwork Thu Jun 22 13:13:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111671 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5073850vqr; Thu, 22 Jun 2023 06:35:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4+nvMcyETfgIWJevRCEoA5g95mdAM1oK1fIyQ7jRRRoG7PEEVhU4T/h3XAZ1UE/xnh2Daq X-Received: by 2002:a17:903:190:b0:1b5:1467:c4e8 with SMTP id z16-20020a170903019000b001b51467c4e8mr17721663plg.15.1687440902104; Thu, 22 Jun 2023 06:35:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440902; cv=none; d=google.com; s=arc-20160816; b=KtCwczAtYYJzKC2pjRZI/Nxf3fyH/L8Y5RR/My8I3cO+zTjHVSSJ0HO9YDmc+n8CNB 6imMcXL6uxKO+pQbb8lTieccO1Le8JRgSb5asyB7hwkyJNyyNRqLP/89MaNw/nJCctVi wx8aJdNXVj9wuSuUd3kb410Se8QNMNzFiw8TsUG8CAU3Ipzs71iE8bkc6/a3+tSXnrdI 6uFDUu0Rv4lnm1YjWXCh2iskpiG1FRBIM/9eqzdeo3y8OYVHUt0KNWrgzS3UHe87cru9 N9j192Jh/CJq5LbzvE4dkVG+AeLVO3ylbupBsCsRshNP3UVfWPzK1DUexK00hflJqCQo srpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=RZsphX72e74QEaV33+j+gwt/nGJ7b+SFjX6H1N2Kj0E=; b=i1z+qrSEKBRoDBON2I2l8DO1AmnFIbhM7BEzXwb0GABWhpxSKHGji+guVkDf0hd6pP m3kgq++YBZqezBp8vHG/Z4xPBp350dWZT/FxujIsPeV+gcP9D0SN93JRUvhOvKZtItCx dx9Z/m6QugkPp9MU2cUxQa98y4LQ7KrPq9OPjG9znJ3PqgC05/sZwHRLh9o5lAhHQBpZ UV1VmKZiIJ+1jrKzZT3pXXdjWmIzEOWLtv6/WIciTfGv+zpyuT1haEVTf3C7WY+PxFxg D28nbbEKeZF71gkKIH9BW6jwaEcL3X/wnxJd/auWRVpK7NkAJUGOmMddrVl1JzmvqSRU v0aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MOqdLbkq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a170902ea0300b001a4f005d59dsi7077603plg.389.2023.06.22.06.34.48; Thu, 22 Jun 2023 06:35:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=MOqdLbkq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbjFVNON (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231607AbjFVNOD (ORCPT ); Thu, 22 Jun 2023 09:14:03 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B778910F8; Thu, 22 Jun 2023 06:14:01 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id C8242660712A; Thu, 22 Jun 2023 14:13:59 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439640; bh=rIFi9nI9oOmxH+BS4YnCMnkoeVakCslz/qMxBQ3B9rg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOqdLbkq2AQHq8FAr2JuOBighmg47fId1/MSzd02Ldhp9KYzfGIUGxZBVyQS1F2Qj dRmSTQn7IKwwGoZnSIEEkb2B5qQg9dnuhxkRTmOVANLdaAV3AS2Wqqd8qDRs8e2vX5 TAQqEGHzpdpQ8AayfY17P838vZVY6EoIq5SPkMxbQRCiWqChIAiuQipzSz5Re57gi2 exfiDw8g3IVvMmiXQdyXw1ZhauNKw4qyX+HCW/njJf94u/Rm9mM+2i7ogpOlAMrxK9 MYxhXqa+5/0qN8XH6WNz4Hd0ODEyvk77T8hEhWXpKJUbM1wLFJ+/1je4anpMtkZpbs QPJti33S5Tycw== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 05/11] media: verisilicon: Refactor postprocessor to store more buffers Date: Thu, 22 Jun 2023 15:13:43 +0200 Message-Id: <20230622131349.144160-6-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769410031012184085?= X-GMAIL-MSGID: =?utf-8?q?1769410031012184085?= Like for vb queues remove VB2_MAX_FRAME upper limit on postprocessor buffers storage capacity. If a buffer hasn't been allocated when setting up the queue make possible to alloc it on the fly while streaming. This happens when resolution change between keyframes. Signed-off-by: Benjamin Gaignard --- drivers/media/platform/verisilicon/hantro.h | 6 +- .../media/platform/verisilicon/hantro_hw.h | 6 +- .../platform/verisilicon/hantro_postproc.c | 109 ++++++++++++------ .../media/platform/verisilicon/hantro_v4l2.c | 12 +- 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h index 2989ebc631cc..bd0dca11b90a 100644 --- a/drivers/media/platform/verisilicon/hantro.h +++ b/drivers/media/platform/verisilicon/hantro.h @@ -460,12 +460,14 @@ hantro_get_dst_buf(struct hantro_ctx *ctx) bool hantro_needs_postproc(const struct hantro_ctx *ctx, const struct hantro_fmt *fmt); +dma_addr_t +hantro_postproc_get_dec_buf_addr(struct hantro_ctx *ctx, int index); static inline dma_addr_t hantro_get_dec_buf_addr(struct hantro_ctx *ctx, struct vb2_buffer *vb) { if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt)) - return ctx->postproc.dec_q[vb->index].dma; + return hantro_postproc_get_dec_buf_addr(ctx, vb->index); return vb2_dma_contig_plane_dma_addr(vb, 0); } @@ -477,8 +479,8 @@ vb2_to_hantro_decoded_buf(struct vb2_buffer *buf) void hantro_postproc_disable(struct hantro_ctx *ctx); void hantro_postproc_enable(struct hantro_ctx *ctx); +int hantro_postproc_init(struct hantro_ctx *ctx); void hantro_postproc_free(struct hantro_ctx *ctx); -int hantro_postproc_alloc(struct hantro_ctx *ctx); int hanto_postproc_enum_framesizes(struct hantro_ctx *ctx, struct v4l2_frmsizeenum *fsize); diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h index 9e8faf7ba6fb..5c7b6e04aded 100644 --- a/drivers/media/platform/verisilicon/hantro_hw.h +++ b/drivers/media/platform/verisilicon/hantro_hw.h @@ -15,8 +15,6 @@ #include #include -#define VB2_MAX_FRAME 32 - #define DEC_8190_ALIGN_MASK 0x07U #define MB_DIM 16 @@ -252,10 +250,10 @@ struct hantro_vp9_dec_hw_ctx { /** * struct hantro_postproc_ctx * - * @dec_q: References buffers, in decoder format. + * @dec_refs_xa: References buffers, in decoder format. */ struct hantro_postproc_ctx { - struct hantro_aux_buf dec_q[VB2_MAX_FRAME]; + struct xarray dec_refs_xa; }; /** diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c index 6437423ccf3a..a6b67d0cc66c 100644 --- a/drivers/media/platform/verisilicon/hantro_postproc.c +++ b/drivers/media/platform/verisilicon/hantro_postproc.c @@ -170,36 +170,23 @@ static int hantro_postproc_g2_enum_framesizes(struct hantro_ctx *ctx, return 0; } -void hantro_postproc_free(struct hantro_ctx *ctx) +static int hantro_postproc_alloc(struct hantro_ctx *ctx, int index) { struct hantro_dev *vpu = ctx->dev; - unsigned int i; - - for (i = 0; i < VB2_MAX_FRAME; ++i) { - struct hantro_aux_buf *priv = &ctx->postproc.dec_q[i]; - - if (priv->cpu) { - dma_free_attrs(vpu->dev, priv->size, priv->cpu, - priv->dma, priv->attrs); - priv->cpu = NULL; - } - } -} - -int hantro_postproc_alloc(struct hantro_ctx *ctx) -{ - struct hantro_dev *vpu = ctx->dev; - struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; - struct vb2_queue *cap_queue = &m2m_ctx->cap_q_ctx.q; - unsigned int num_buffers = cap_queue->num_buffers; struct v4l2_pix_format_mplane pix_mp; const struct hantro_fmt *fmt; - unsigned int i, buf_size; + struct hantro_aux_buf *priv; + unsigned int buf_size; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; /* this should always pick native format */ fmt = hantro_get_default_fmt(ctx, false, ctx->bit_depth); if (!fmt) return -EINVAL; + v4l2_fill_pixfmt_mp(&pix_mp, fmt->fourcc, ctx->src_fmt.width, ctx->src_fmt.height); @@ -214,20 +201,74 @@ int hantro_postproc_alloc(struct hantro_ctx *ctx) buf_size += hantro_hevc_mv_size(pix_mp.width, pix_mp.height); - for (i = 0; i < num_buffers; ++i) { - struct hantro_aux_buf *priv = &ctx->postproc.dec_q[i]; - - /* - * The buffers on this queue are meant as intermediate - * buffers for the decoder, so no mapping is needed. - */ - priv->attrs = DMA_ATTR_NO_KERNEL_MAPPING; - priv->cpu = dma_alloc_attrs(vpu->dev, buf_size, &priv->dma, - GFP_KERNEL, priv->attrs); - if (!priv->cpu) - return -ENOMEM; - priv->size = buf_size; + /* + * The buffers on this queue are meant as intermediate + * buffers for the decoder, so no mapping is needed. + */ + priv->attrs = DMA_ATTR_NO_KERNEL_MAPPING; + priv->cpu = dma_alloc_attrs(vpu->dev, buf_size, &priv->dma, GFP_KERNEL, priv->attrs); + if (!priv->cpu) + return -ENOMEM; + + priv->size = buf_size; + + xa_store(&ctx->postproc.dec_refs_xa, index, priv, GFP_KERNEL); + + return 0; +} + +void hantro_postproc_free(struct hantro_ctx *ctx) +{ + struct hantro_dev *vpu = ctx->dev; + struct hantro_aux_buf *priv; + unsigned long i; + + xa_for_each(&ctx->postproc.dec_refs_xa, i, priv) { + dma_free_attrs(vpu->dev, priv->size, priv->cpu, priv->dma, priv->attrs); + kfree(priv); + } + + xa_destroy(&ctx->postproc.dec_refs_xa); +} + +int hantro_postproc_init(struct hantro_ctx *ctx) +{ + struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx; + struct vb2_queue *cap_queue = &m2m_ctx->cap_q_ctx.q; + unsigned int num_buffers = cap_queue->num_buffers; + int i, ret = 0; + + xa_init_flags(&ctx->postproc.dec_refs_xa, XA_FLAGS_ALLOC); + + for (i = 0; i < num_buffers; i++) { + ret = hantro_postproc_alloc(ctx, i); + if (ret < 0) { + hantro_postproc_free(ctx); + return ret; + } } + + return ret; +} + +dma_addr_t +hantro_postproc_get_dec_buf_addr(struct hantro_ctx *ctx, int index) +{ + struct hantro_aux_buf *priv = xa_load(&ctx->postproc.dec_refs_xa, index); + int ret; + + if (priv) + return priv->dma; + + /* buffer not already allocated, try getting a new one */ + ret = hantro_postproc_alloc(ctx, index); + if (ret < 0) + return 0; + + priv = xa_load(&ctx->postproc.dec_refs_xa, index); + if (priv) + return priv->dma; + return 0; } diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index 61cfaaf4e927..0f615c1001c0 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -894,20 +894,10 @@ static int hantro_start_streaming(struct vb2_queue *q, unsigned int count) ret = ctx->codec_ops->init(ctx); if (ret) return ret; - } - - if (hantro_needs_postproc(ctx, ctx->vpu_dst_fmt)) { - ret = hantro_postproc_alloc(ctx); - if (ret) - goto err_codec_exit; + ret = hantro_postproc_init(ctx); } } return ret; - -err_codec_exit: - if (ctx->codec_ops->exit) - ctx->codec_ops->exit(ctx); - return ret; } static void From patchwork Thu Jun 22 13:13:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111669 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5073357vqr; Thu, 22 Jun 2023 06:34:16 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5ihzuBRVPM3p46m03OPP9OS4pGeuzNrusruPwTkc6+2m6QGSQThwMvh19JChImxlTRBB49 X-Received: by 2002:a05:6a00:2351:b0:668:6445:8931 with SMTP id j17-20020a056a00235100b0066864458931mr19468493pfj.29.1687440856486; Thu, 22 Jun 2023 06:34:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440856; cv=none; d=google.com; s=arc-20160816; b=STS5H9DNTUBmFfMa3AYm7FsJmPZXG6C4OZ2/DjuWZ1FgHdEXwNxGYnNFg2/s+sqxah INHIY++XW9sKY+aiO1gn4VXDytYTAPcHQZK5mAx4qAau2VfnuU6RiW4UuG8RA7ZkjeRz iRERdawA9vsiXpMuNAm96GANjBU+Y8O38wdguFjnVtNari4YemEI7UD1Aneiuxqdb6Fg MeRBlLpWczlZrfCwDifWZbeuocbRmEdc4g3dgDU1YwKDayy0nHIe+4MOzif++t5jGlCo iGqhfuo6wmefS7i0HvpITKyzusVIE+U1WJoBJiMtxm/OL/qojBycR5YUaRfxUdTQyLoY CYjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dGP0n+TNzfJPAY8TkibBo1CdTPssUG5URJVsMC4R1dM=; b=sKifOLM6PCQbkJRH0L8fv+/zyt4bl35sZt0YxQM9ITB5q+prUPA6Chs37rIw9O6J+F 5ghB2xiq7bPU/c8f55jFTt/d1vMiOrFUA2eNU12+hNWT2/hBiwwi3+c+rZOcIvjPh04o zWocsx8a4hss8NIMJrJxg1TU2e13UTKrCwDRmBaD9RF2MwzAYauC+0Y8kOQcVQAC5dsC Gdd8WdAYIrjtFvUkv/NDdPkSQdsB17TuefXks3HCGjzf7BUG6cSxvd6UToCn1no8QWoA Dl++57etc3PhkhuagXIjcEz2g+ylMEIklmHJOo4i3qAFyC7TZuwvHa7h39xk8F6D3rXO 82Kw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=U0zsmGVC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b68-20020a62cf47000000b006689f320421si46525pfg.150.2023.06.22.06.34.03; Thu, 22 Jun 2023 06:34:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=U0zsmGVC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231682AbjFVNO0 (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231601AbjFVNOC (ORCPT ); Thu, 22 Jun 2023 09:14:02 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C519D1BD3; Thu, 22 Jun 2023 06:14:01 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 4B4B8660712D; Thu, 22 Jun 2023 14:14:00 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439640; bh=ZiJZeCrdYyJk6ji66RurI+0QVQYXWWl0hCRxE21ZIiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0zsmGVCsQ+HRf88BblNgvRpabk8rpioN4X5sKdE9Z0Qe9DGe9cNQE0k1E8fE9HCx i0/LkBviZzhZnivGLqThkTSmEp7ueCMhIPoeQw2Xq6Yu5+Y8TalLwt7mDSlGOsy1Hm Kmf7ugd6oCy8LNL0mI2psUJUEgddM4VbBrFdqzapOKCEcyZgNpeHVkaaPoOs0XZ9H/ Lh3Dp1q/ja1beetzo7WsEbILf+X0S3GQWpf7rMypG1wEyE61OoaiLdFNReduOSmHEv quEqtqd3ja49w1clhV8+nHtlQ+oFqbO+m6lnfhva6eIeI3rZxjNy1aN+BfIwQCR6AA diw36mypgVTyA== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 06/11] media: verisilicon: Store chroma and motion vectors offset Date: Thu, 22 Jun 2023 15:13:44 +0200 Message-Id: <20230622131349.144160-7-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769409983138800132?= X-GMAIL-MSGID: =?utf-8?q?1769409983138800132?= Store computed values of chroma and motion vectors offset because they depends on width and height values which change if the resolution change. Signed-off-by: Benjamin Gaignard --- drivers/media/platform/verisilicon/hantro.h | 2 ++ drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h index bd0dca11b90a..16c7e9bafde3 100644 --- a/drivers/media/platform/verisilicon/hantro.h +++ b/drivers/media/platform/verisilicon/hantro.h @@ -320,6 +320,8 @@ struct hantro_vp9_decoded_buffer_info { /* Info needed when the decoded frame serves as a reference frame. */ unsigned short width; unsigned short height; + size_t chroma_offset; + size_t mv_offset; u32 bit_depth : 4; }; diff --git a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c index 6fc4b555517f..6db1c32fce4d 100644 --- a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c +++ b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c @@ -158,9 +158,11 @@ static void config_output(struct hantro_ctx *ctx, chroma_addr = luma_addr + chroma_offset(ctx, dec_params); hantro_write_addr(ctx->dev, G2_OUT_CHROMA_ADDR, chroma_addr); + dst->vp9.chroma_offset = chroma_offset(ctx, dec_params); mv_addr = luma_addr + mv_offset(ctx, dec_params); hantro_write_addr(ctx->dev, G2_OUT_MV_ADDR, mv_addr); + dst->vp9.mv_offset = mv_offset(ctx, dec_params); } struct hantro_vp9_ref_reg { @@ -195,7 +197,7 @@ static void config_ref(struct hantro_ctx *ctx, luma_addr = hantro_get_dec_buf_addr(ctx, &buf->base.vb.vb2_buf); hantro_write_addr(ctx->dev, ref_reg->y_base, luma_addr); - chroma_addr = luma_addr + chroma_offset(ctx, dec_params); + chroma_addr = luma_addr + buf->vp9.chroma_offset; hantro_write_addr(ctx->dev, ref_reg->c_base, chroma_addr); } @@ -238,7 +240,7 @@ static void config_ref_registers(struct hantro_ctx *ctx, config_ref(ctx, dst, &ref_regs[2], dec_params, dec_params->alt_frame_ts); mv_addr = hantro_get_dec_buf_addr(ctx, &mv_ref->base.vb.vb2_buf) + - mv_offset(ctx, dec_params); + mv_ref->vp9.mv_offset; hantro_write_addr(ctx->dev, G2_REF_MV_ADDR(0), mv_addr); hantro_reg_write(ctx->dev, &vp9_last_sign_bias, From patchwork Thu Jun 22 13:13:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111663 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5063184vqr; Thu, 22 Jun 2023 06:19:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7iv160rjiCb5gU5dKCJ8T20POTXS1MKviNtTjZiryASLNrdJGHQxLR7myZrgoLE5EIz/G6 X-Received: by 2002:a05:6a20:748c:b0:11f:39e2:d08c with SMTP id p12-20020a056a20748c00b0011f39e2d08cmr19453836pzd.30.1687439959372; Thu, 22 Jun 2023 06:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687439959; cv=none; d=google.com; s=arc-20160816; b=pa9sODS/PkPT8ZIFtAiWtTd09TJbBP0hlzVjexcZnNt+ArO6k8SqEzHy17iXh2Q77P IV1pxfR8yWbacuzVxU8KrrZA+ubTk8X3RT5LinxBic/KZDikdIiAv2T2MPFMuQPEc0GA G61nNbiP1jm0mFT7MOTu/HFwiBIzH7JYHUntmL0s1Dub8XE78GmTKBAKZLrOeFHS7+h+ x7rMjkrhlPMRvRTzF6kYcTEldOQqnYyGduzzP2315f9c+takOzOS6Y+WjyWRixjicW4U RjdRB33P48MBNCBOT2VV2kjGw4c+u+gUCKmN3Qk1mWwd5cTYL5M+r3hsKVEVmOH2pDyJ hPEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dOYSiflqCo/sGtwvQpfYA57i+D0V38Re/PbWwbU5Duc=; b=xZ1lIQArQwSxG2f7DwKS9ghqVcECG1Fre8I4l3qyeMp/czhPxIu+nkN3msU8O7XctR hox76OPmsyGhbwY5j/YR7m/u0yQG6BIMA6mJM5AIvkGy0bV6wIa2shFsAaKtn8JwWgI4 2YpNOckH3St3Upvx4N0sv/Fc9JteYs9l4odDkCehp9fr0a+lDQasv+CyKDG7M/jO1iuL APLvuF9EcBY6B/lxV7aweYzBuWIHEnskD/ylzhu4LMVwDCdgfVW33EGSy8/8i6QoV7rk 6/wnDTxskrZmA9eFzFftAqmcqqrMsXTb15d0Z3nJJOoie/XzDViuUgi+bhi2AomJZN+L xa3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LE4QqBKg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z29-20020aa7991d000000b006669041c09csi6252873pff.235.2023.06.22.06.19.06; Thu, 22 Jun 2023 06:19:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LE4QqBKg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231689AbjFVNOR (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231608AbjFVNOD (ORCPT ); Thu, 22 Jun 2023 09:14:03 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 540B51BF6; Thu, 22 Jun 2023 06:14:02 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id C3B7D6607131; Thu, 22 Jun 2023 14:14:00 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439641; bh=UmxaSxfAyduJDEDEY4mpYf+MJsD53OV/RCS4wvgVO+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LE4QqBKgWv+1EySXMkQVSaD1dNhI+GeD3LlmDyw8BUUqAzjeWKpLgE7nYFbDxEEv9 Ati1aQFtBHhVCABtN74rxVbZAa0MJSrZwVIgrgxRkDAIImGtdfaAWTqBawHTNAbMl/ HdshjmeOvUsBxHts3OqwHdUtzM8APjBR4H8Dcl06XSpdTrsLjVDi2bXO/6Q+Z2385t AAAr8kZFEeZazGpcyPfMqlpZCv2h3C9HeJ6EXw2PfsfsK9xapfSEcEgXl7Er0SU4wE Y/3OPZhHXGACkMUixRI+7UZiu5cfz2o/DlWmXPnVxS2yL6iB1y+ma9RO+Hn7zvmTu4 8A0REHtV4T39g== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 07/11] media: verisilicon: vp9: Use destination buffer height to compute chroma offset Date: Thu, 22 Jun 2023 15:13:45 +0200 Message-Id: <20230622131349.144160-8-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769409042745590983?= X-GMAIL-MSGID: =?utf-8?q?1769409042745590983?= Source and destination buffer height may not be the same because alignment constraint are different. Use destination height to compute chroma offset because we target this buffer as hardware output. Signed-off-by: Benjamin Gaignard --- drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c index 6db1c32fce4d..1f3f5e7ce978 100644 --- a/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c +++ b/drivers/media/platform/verisilicon/hantro_g2_vp9_dec.c @@ -93,9 +93,7 @@ static int start_prepare_run(struct hantro_ctx *ctx, const struct v4l2_ctrl_vp9_ static size_t chroma_offset(const struct hantro_ctx *ctx, const struct v4l2_ctrl_vp9_frame *dec_params) { - int bytes_per_pixel = dec_params->bit_depth == 8 ? 1 : 2; - - return ctx->src_fmt.width * ctx->src_fmt.height * bytes_per_pixel; + return ctx->dst_fmt.width * ctx->dst_fmt.height * ctx->bit_depth / 8; } static size_t mv_offset(const struct hantro_ctx *ctx, From patchwork Thu Jun 22 13:13:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111665 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5064246vqr; Thu, 22 Jun 2023 06:20:44 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7XFt74Ui/70dhhwFT4InMU7QhKQ9BN/bXX1pOPkx7cUDbsgkg2h46e/tL2e3XtPeWiewuH X-Received: by 2002:a92:dc45:0:b0:342:1954:6bfe with SMTP id x5-20020a92dc45000000b0034219546bfemr14663692ilq.17.1687440043852; Thu, 22 Jun 2023 06:20:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440043; cv=none; d=google.com; s=arc-20160816; b=AXNhj/xOqOP7xf5ck78GcfcUOijFlzQKeuJ+Fp2ecrmNBIHfcD6SSOBKB5GK7AX2LJ X9bIteDyzkjqnKXD9zy4VSO2bicoF2RTRtp4k/WRCMLSWPs06TKJ0Nqs8b9nQ/s8j/6m UWwMkFZtXMGKEPdzRCayhJ9+J4meM8QRa4EsUm/R1ip5NkHro5HAqweZz4g4XZAmNCFc r5WZPKAz8m0CyGeXT9DVmo9KUCFlPsqWUlCLNcMjZC9Ebt514o6UUHsC/mcHDwaPe8fj ZGSxedlOs/R4BkLk8JuYty5sNHfX3tV8JKV/+Ez5xZqOnNncpRSBKIu7ujMIY2oPyqO3 so4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+1vg8ScmpNm8razALRYUW1Fadsefo82sU0cK+F0RPcw=; b=h6q2V9UDW029Uqkd38KQ6JsJtExFeUCDquitLY73xfP74O/R3nXfWoa93Yhi8+P6LP R1A6ooO6i/z3JKSxZdr9ensHRpJKmCW5djfTVjrSkfDZgqrlspvnwIF5Cbfc3b8wfmHX ceFOpSFLMFAhEwrdsNZ29e6DHGYk5CK1jf0DxCLrH126UEyXU8uQNM5Ze2CmWyTNQ/3M T2zInSJZ9EUgsrYRBdWvGjfjFJJNnj1kUE7iTJ8m3KpYywIbc7SxKYdsrzM9txiHjXeE hG720RyPt9zlFssUM6ZBxvDC7IfGaYkgBjyk0skzOMyyPG7oJb7LxDHVV6nh4aDJN4Ck As1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oie9OYCV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v21-20020a63b955000000b00553c4551a09si2442586pgo.398.2023.06.22.06.20.30; Thu, 22 Jun 2023 06:20:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=oie9OYCV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231756AbjFVNOe (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231611AbjFVNOD (ORCPT ); Thu, 22 Jun 2023 09:14:03 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E29CF1BD2; Thu, 22 Jun 2023 06:14:02 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 465616607134; Thu, 22 Jun 2023 14:14:01 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439641; bh=L/PjipZuAgM8U3/G13tgH1tvV239+bgnDOvwg/NHT0o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oie9OYCVzgy392asDkxBx6pxe2/ZE5DwJwj5wC+XHaa1K50YLVzx2KFrvUnDE4Fxb bolJAeXxnDGzshzKaVttYEvDKuWJMvWDs/tnXVj2YJDdRkm1YGLQL5AKKZlonUsHhl kqJ43rCFtmcWzXqIK7gNcRlJOFy6NaHRp/jM96egbEOykqF4U5IprC1Yzk7lY41CxP rJtWH/9odTvPjI7XFgv321jDmQ01jhmTZbtv1y6RSn4ZJRCQHTCgU0CJiFeBbSX69h NtaB6tRkK34wlQgPgbUmlhb3bh4dLhcA0RhJvtfjLTIrAZZYIU8uYVFn6YB+p0mNhs nBqsle6SK92Lw== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 08/11] media: verisilicon: postproc: Fix down scale test Date: Thu, 22 Jun 2023 15:13:46 +0200 Message-Id: <20230622131349.144160-9-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769409131593147262?= X-GMAIL-MSGID: =?utf-8?q?1769409131593147262?= Do not allow down scaling if the source buffer resolution is smaller than destination one. Signed-off-by: Benjamin Gaignard --- drivers/media/platform/verisilicon/hantro_postproc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c index a6b67d0cc66c..a4f2c5e8932c 100644 --- a/drivers/media/platform/verisilicon/hantro_postproc.c +++ b/drivers/media/platform/verisilicon/hantro_postproc.c @@ -103,7 +103,10 @@ static void hantro_postproc_g1_enable(struct hantro_ctx *ctx) static int down_scale_factor(struct hantro_ctx *ctx) { - if (ctx->src_fmt.width == ctx->dst_fmt.width) + if (ctx->src_fmt.width <= ctx->dst_fmt.width) + return 0; + + if (ctx->src_fmt.height <= ctx->dst_fmt.height) return 0; return DIV_ROUND_CLOSEST(ctx->src_fmt.width, ctx->dst_fmt.width); From patchwork Thu Jun 22 13:13:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111675 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5075967vqr; Thu, 22 Jun 2023 06:38:30 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5S47ANdrIhheyXoUqp7Sl9SnXnn7LVG/L0MWgYvRMsAVi+4YUmOkfLzby4aKM64AiPJcbg X-Received: by 2002:a17:902:d34b:b0:1b3:f8db:6f0e with SMTP id l11-20020a170902d34b00b001b3f8db6f0emr13744409plk.43.1687441109926; Thu, 22 Jun 2023 06:38:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687441109; cv=none; d=google.com; s=arc-20160816; b=IWMSZBO8fMsqiXI3hzZ69uwCG7hB97Xb2n6pofviuFNUEiDQxzC7Ot+XXMxvt0N4ij s69j8szEi+Eft5cV+qKMdJArvo4EbS7jiPSZf8farbjkB3gxMrMBsl/VrvjPBStwZ6rg 6TqY7LpLygzfund7PtmDfXh8V0f9t9UfBc8SiBOmEZBvrD+Ef0jmWZ0m/UQPrP8/EAzU rhyD60sNZfDUI2t0mtKjWGVYqIxnR8drW09rdDsxAK/MkNfgLHgk1iFsa2CUSV74UmQr 8KHtwsu5H3qqaNGrFCGWeoQgim2ofrDitNF0hQe/+LxPKXFTJ7J6x2qOzDeodPjzFxQp nNOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=lZvc1GZcbC3TqM1BvcVDQ9ruIeQWlogw2/4XWLZfbDE=; b=tmbBsabU+eK3w0lo+1w6pjCoawix8esHEdl3VkL9A6Q6J8DYov6HrKamka2hMlLhuG Xt/A/eoy//6K8nIWFXSWuTKDYjK/Z1c760XeJINr7dutLt4kPeSNnABZV/o0KEDWDGfn pdtnZ2/bsqDNdZf6ZrWXhDHA0ruEipVrUEZQAJz5l/8G+xAo32b9miTnJdGLqUxkFTKD fppA73V8bJzoDSWN6v4BlelhKLXcdfAP14RlMPIckV1WrJD+vs3opiem/hebd3AlNtdk lKuQ11ozrmor7Wy6NxSDcokAC0WOouDWuHCD28K4XJeZSLYeNZEQtBg0+7rJ+O8SkAkE obAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=DGz1otna; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m15-20020a170902bb8f00b001b54e9a0134si1451666pls.65.2023.06.22.06.38.17; Thu, 22 Jun 2023 06:38:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=DGz1otna; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231761AbjFVNOg (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231612AbjFVNOE (ORCPT ); Thu, 22 Jun 2023 09:14:04 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BF831BD3; Thu, 22 Jun 2023 06:14:03 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id BC419660713A; Thu, 22 Jun 2023 14:14:01 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439642; bh=X2W06J2G0RvZ6wT6r06tbLD+//oCk/Ju0PbDrogdZys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DGz1otnaX8UAHM3bF/fnObvKgQpots9OgKyHQlYMpVuhY7HFB9K4WXhjx/xh4Hjdo wKXNP5wNgwFSN56fHkbwgjBz61Nik8UswMz0VmMTAqA2qfjxyZ5RRs9KrSalNKVi/a svqywLE+/HOl4pNFwe+5y+GPUpyZp2J8ZE8bIXwMv36/tlbJbfrwIyo5FAlGa+vYC2 CUYsKgUWCIbKJ7DAn1dFeQqdd8rZsaMpjA7687bBQB9Gw8OjPpzkSSmNd7zkhmlS6e xhsVOzJJk8C4WZlBCEhy/OyVUgr6WV9ihhUvdnEJQJtokxd19iRvruoQSt5ihx41Is SrHjNjTFBA1mA== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 09/11] media: verisilicon: vp9: Allow to change resolution while streaming Date: Thu, 22 Jun 2023 15:13:47 +0200 Message-Id: <20230622131349.144160-10-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769410248931934699?= X-GMAIL-MSGID: =?utf-8?q?1769410248931934699?= Remove all checks that prohibit to set a new format while streaming. This allow to change dynamically the resolution if the pixel format remains the same. Signed-off-by: Benjamin Gaignard --- .../media/platform/verisilicon/hantro_v4l2.c | 24 +++---------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index 0f615c1001c0..cdddfb4179aa 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -480,25 +480,14 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, return ret; if (!ctx->is_encoder) { - struct vb2_queue *peer_vq; - /* * In order to support dynamic resolution change, * the decoder admits a resolution change, as long - * as the pixelformat remains. Can't be done if streaming. - */ - if (vb2_is_streaming(vq) || (vb2_is_busy(vq) && - pix_mp->pixelformat != ctx->src_fmt.pixelformat)) - return -EBUSY; - /* - * Since format change on the OUTPUT queue will reset - * the CAPTURE queue, we can't allow doing so - * when the CAPTURE queue has buffers allocated. + * as the pixelformat remains. */ - peer_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, - V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); - if (vb2_is_busy(peer_vq)) + if (vb2_is_streaming(vq) && pix_mp->pixelformat != ctx->src_fmt.pixelformat) { return -EBUSY; + } } else { /* * The encoder doesn't admit a format change if @@ -541,15 +530,8 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, static int hantro_set_fmt_cap(struct hantro_ctx *ctx, struct v4l2_pix_format_mplane *pix_mp) { - struct vb2_queue *vq; int ret; - /* Change not allowed if queue is busy. */ - vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, - V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE); - if (vb2_is_busy(vq)) - return -EBUSY; - if (ctx->is_encoder) { struct vb2_queue *peer_vq; From patchwork Thu Jun 22 13:13:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111664 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5063759vqr; Thu, 22 Jun 2023 06:20:05 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7LWDuIYPUk/+hsVFpwa1MP2whu1YHkth4KXE6boM7ASylZygmV5bUhO7B0T3ViOZQlcJYJ X-Received: by 2002:a05:6a20:a122:b0:103:7b36:f21 with SMTP id q34-20020a056a20a12200b001037b360f21mr32053277pzk.21.1687440004740; Thu, 22 Jun 2023 06:20:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440004; cv=none; d=google.com; s=arc-20160816; b=FNXfUZD35pJQm2PViK1Kc39uShVkxfu+7brB3qEGiQDL7CArMXbpK3yCNqqEWxTV5K k5OaW94ZrS4SZmc3G/3O2YsuNYcCWayfCh/X4k0TBAQ2EKnOhi/MmjYuTt0j5RSIjG3T vzFaI1v8Q/4kUEcGab9ADZpRswV0iCWt7tl7hzTj+6dBb6H5rZRhnZkT3y76niVnPj5s NQIv21Q8cI7j5MmHH+G30ft06RBkmhJK9SB38JEQtoFJruz+mqRZvp88Pm6U3OxKGYvI IB1eKVXrsvf1YO1RvdTRPZoC55f/kM6XkHLCvT5k/cQPBUGvvf9p8qnkbO86jkHg9EDF GU5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9Fv8tqCmsSOCY4YGGKMIkh2Tb87jXX+BD/7CFkcNgXA=; b=mPv6ejGAjdF2RjI0IhwkNDEOAzp7PB7Ux0eTwS1JQf3/HEc1l6GX8fT3HgyvJKUcRD Wcl5FyCpSpIM5bfzUE3Ge9BVOJ/l3CAxreXB93pR+hlnBk27UEOM4mLTpBIpYIYmppgv bhFej8LbVgglGvqfPOhNvZwv0BfPf0lmnna3Y0mSaM6nYLMKN0Dfb5zBIJZDbGRs0Jpd wzgai2iTtn8Nbgoat9IUitu/a9uWtxg5xqH9vXnIc74Jfw0akH/KQ+WOiwl3NNau8KoB MmfzDWGOpiWECwVfE764KRFcKD3GaXSOEKF2odpMoFrNSvuFeL5gryRQ7WxwVxtohp6l dEzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=R7cClQUQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i190-20020a6387c7000000b0052c2904e37dsi2765402pge.362.2023.06.22.06.19.49; Thu, 22 Jun 2023 06:20:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=R7cClQUQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231681AbjFVNOo (ORCPT + 99 others); Thu, 22 Jun 2023 09:14:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231617AbjFVNOF (ORCPT ); Thu, 22 Jun 2023 09:14:05 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BADA71BD7; Thu, 22 Jun 2023 06:14:03 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 3F6D2660713B; Thu, 22 Jun 2023 14:14:02 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439642; bh=OL7fqdlzrkuvJs9l9Lix1rcNanP6zAUtVjeNt919ZCE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R7cClQUQp9pSc3zMg+WY+COf7GacF8mfCHrm0scP6OpVwA7Riws6UuDofLtwJ/JbA qEJp8+ipGzbDYkvjcEvWQjkddpTbdAcJyx6X9fWYl1Sm3O45Mid3C5A1Z45OSVv6MU 67R4uIFxpETpADha5jNGaJyA7RWzbcQXO2DXeCMKMvEsE270wr+Pg7N+cg/FuYe4yd brsjXgBNFcK7G+rpzgHmX6Tk8n43izogs9uezWkLRYpM5cCa1ndI2MjztoKqXmt3s4 mKdexyRI70R2JkHjM6wo++CkAYxgQFzvR285o6OyeTZKG8PnBsuciIP02NG3617hCj mYS2XPpPMMMWg== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 10/11] media: v4l2: Add DELETE_BUF ioctl Date: Thu, 22 Jun 2023 15:13:48 +0200 Message-Id: <20230622131349.144160-11-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769409090512925469?= X-GMAIL-MSGID: =?utf-8?q?1769409090512925469?= VIDIOC_DELETE_BUF ioctl allows to delete a buffer from a queue. Signed-off-by: Benjamin Gaignard --- .../userspace-api/media/v4l/user-func.rst | 1 + .../media/v4l/vidioc-delete-buf.rst | 51 +++++++++++++++++++ .../media/common/videobuf2/videobuf2-core.c | 33 ++++++++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 6 +++ drivers/media/v4l2-core/v4l2-dev.c | 1 + drivers/media/v4l2-core/v4l2-ioctl.c | 10 ++++ include/media/v4l2-ioctl.h | 4 ++ include/media/videobuf2-core.h | 9 ++++ include/media/videobuf2-v4l2.h | 11 ++++ include/uapi/linux/videodev2.h | 2 + 10 files changed, 128 insertions(+) create mode 100644 Documentation/userspace-api/media/v4l/vidioc-delete-buf.rst diff --git a/Documentation/userspace-api/media/v4l/user-func.rst b/Documentation/userspace-api/media/v4l/user-func.rst index 15ff0bf7bbe6..8c74016e12fd 100644 --- a/Documentation/userspace-api/media/v4l/user-func.rst +++ b/Documentation/userspace-api/media/v4l/user-func.rst @@ -17,6 +17,7 @@ Function Reference vidioc-dbg-g-chip-info vidioc-dbg-g-register vidioc-decoder-cmd + vidioc-delete-buf vidioc-dqevent vidioc-dv-timings-cap vidioc-encoder-cmd diff --git a/Documentation/userspace-api/media/v4l/vidioc-delete-buf.rst b/Documentation/userspace-api/media/v4l/vidioc-delete-buf.rst new file mode 100644 index 000000000000..0e7ce58f91bc --- /dev/null +++ b/Documentation/userspace-api/media/v4l/vidioc-delete-buf.rst @@ -0,0 +1,51 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later +.. c:namespace:: V4L + +.. _VIDIOC_DELETE_BUF: + +************************ +ioctl VIDIOC_DELETE_BUF +************************ + +Name +==== + +VIDIOC_DELETE_BUF - Delete a buffer from a queue + +Synopsis +======== + +.. c:macro:: VIDIOC_DELETE_BUF + +``int ioctl(int fd, VIDIOC_DELETE_BUF, struct v4l2_buffer *argp)`` + +Arguments +========= + +``fd`` + File descriptor returned by :c:func:`open()`. + +``argp`` + Pointer to struct :c:type:`v4l2_buffer`. + +Description +=========== + +Applications can optionally call the :ref:`VIDIOC_DELETE_BUF` ioctl to +delete a buffer from a queue. + +The struct :c:type:`v4l2_buffer` structure is specified in +:ref:`buffer`. + +Return Value +============ + +On success 0 is returned, on error -1 and the ``errno`` variable is set +appropriately. The generic error codes are described at the +:ref:`Generic Error Codes ` chapter. + +EBUSY + File I/O is in progress. + +EINVAL + The buffer ``index`` doesn't exist in the queue. diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 899783f67580..aa546c972c3d 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1637,6 +1637,39 @@ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb) } EXPORT_SYMBOL_GPL(vb2_core_prepare_buf); +int vb2_core_delete_buf(struct vb2_queue *q, unsigned int index) +{ + struct vb2_buffer *vb; + + vb = vb2_get_buffer(q, index); + if (!vb) { + dprintk(q, 1, "invalid buffer index %d\n", index); + return -EINVAL; + } + + if (vb->state != VB2_BUF_STATE_DEQUEUED) { + dprintk(q, 1, "can't delete non dequeued buffer index %d\n", index); + return -EINVAL; + } + + if (vb->planes[0].mem_priv) + call_void_vb_qop(vb, buf_cleanup, vb); + + /* Free MMAP buffers or release USERPTR buffers */ + if (q->memory == VB2_MEMORY_MMAP) + __vb2_buf_mem_free(vb); + else if (q->memory == VB2_MEMORY_DMABUF) + __vb2_buf_dmabuf_put(vb); + else + __vb2_buf_userptr_put(vb); + + vb2_queue_remove_buffer(q, vb); + kfree(vb); + + dprintk(q, 2, "buffer %d deleted\n", index); + return 0; +} + /* * vb2_start_streaming() - Attempt to start streaming. * @q: videobuf2 queue diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 724135d41f7f..cea666c17b41 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -751,6 +751,12 @@ int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, } EXPORT_SYMBOL_GPL(vb2_prepare_buf); +int vb2_delete_buf(struct vb2_queue *q, struct v4l2_buffer *b) +{ + return vb2_core_delete_buf(q, b->index); +} +EXPORT_SYMBOL_GPL(vb2_delete_buf); + int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) { unsigned requested_planes = 1; diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index f81279492682..80ace2e1e932 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -720,6 +720,7 @@ static void determine_valid_ioctls(struct video_device *vdev) SET_VALID_IOCTL(ops, VIDIOC_PREPARE_BUF, vidioc_prepare_buf); SET_VALID_IOCTL(ops, VIDIOC_STREAMON, vidioc_streamon); SET_VALID_IOCTL(ops, VIDIOC_STREAMOFF, vidioc_streamoff); + SET_VALID_IOCTL(ops, VIDIOC_DELETE_BUF, vidioc_delete_buf); } if (is_vid || is_vbi || is_meta) { diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index a858acea6547..1c737279d3ef 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -2156,6 +2156,15 @@ static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, return ret ? ret : ops->vidioc_prepare_buf(file, fh, b); } +static int v4l_delete_buf(const struct v4l2_ioctl_ops *ops, + struct file *file, void *fh, void *arg) +{ + struct v4l2_buffer *b = arg; + int ret = check_fmt(file, b->type); + + return ret ? ret : ops->vidioc_delete_buf(file, fh, b); +} + static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file, void *fh, void *arg) { @@ -2905,6 +2914,7 @@ static const struct v4l2_ioctl_info v4l2_ioctls[] = { IOCTL_INFO(VIDIOC_ENUM_FREQ_BANDS, v4l_enum_freq_bands, v4l_print_freq_band, 0), IOCTL_INFO(VIDIOC_DBG_G_CHIP_INFO, v4l_dbg_g_chip_info, v4l_print_dbg_chip_info, INFO_FL_CLEAR(v4l2_dbg_chip_info, match)), IOCTL_INFO(VIDIOC_QUERY_EXT_CTRL, v4l_query_ext_ctrl, v4l_print_query_ext_ctrl, INFO_FL_CTRL | INFO_FL_CLEAR(v4l2_query_ext_ctrl, id)), + IOCTL_INFO(VIDIOC_DELETE_BUF, v4l_delete_buf, v4l_print_buffer, INFO_FL_QUEUE), }; #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index edb733f21604..2f232ed884c7 100644 --- a/include/media/v4l2-ioctl.h +++ b/include/media/v4l2-ioctl.h @@ -163,6 +163,8 @@ struct v4l2_fh; * :ref:`VIDIOC_CREATE_BUFS ` ioctl * @vidioc_prepare_buf: pointer to the function that implements * :ref:`VIDIOC_PREPARE_BUF ` ioctl + * @vidioc_delete_buf: pointer to the function that implements + * :ref:`VIDIOC_DELETE_BUF ` ioctl * @vidioc_overlay: pointer to the function that implements * :ref:`VIDIOC_OVERLAY ` ioctl * @vidioc_g_fbuf: pointer to the function that implements @@ -422,6 +424,8 @@ struct v4l2_ioctl_ops { struct v4l2_create_buffers *b); int (*vidioc_prepare_buf)(struct file *file, void *fh, struct v4l2_buffer *b); + int (*vidioc_delete_buf)(struct file *file, void *fh, + struct v4l2_buffer *b); int (*vidioc_overlay)(struct file *file, void *fh, unsigned int i); int (*vidioc_g_fbuf)(struct file *file, void *fh, diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 080b783d608d..0f9e68f76b77 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -840,6 +840,15 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, */ int vb2_core_prepare_buf(struct vb2_queue *q, unsigned int index, void *pb); +/** + * vb2_core_delete_buf() - + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @index: id number of the buffer. + * + * Return: returns zero on success; an error code otherwise. + */ +int vb2_core_delete_buf(struct vb2_queue *q, unsigned int index); + /** * vb2_core_qbuf() - Queue a buffer from userspace * diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 88a7a565170e..3beeb4c735f0 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -114,6 +114,17 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create); */ int vb2_prepare_buf(struct vb2_queue *q, struct media_device *mdev, struct v4l2_buffer *b); +/** + * vb2_delete_buf() - Delete the buffer from the queue + * + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @b: buffer structure passed from userspace to + * &v4l2_ioctl_ops->vidioc_delete_buf handler in driver + * + * The return values from this function are intended to be directly returned + * from &v4l2_ioctl_ops->vidioc_delete_buf handler in driver. + */ +int vb2_delete_buf(struct vb2_queue *q, struct v4l2_buffer *b); /** * vb2_qbuf() - Queue a buffer from userspace diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index aee75eb9e686..31bba1915642 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -2702,6 +2702,8 @@ struct v4l2_create_buffers { #define VIDIOC_DBG_G_CHIP_INFO _IOWR('V', 102, struct v4l2_dbg_chip_info) #define VIDIOC_QUERY_EXT_CTRL _IOWR('V', 103, struct v4l2_query_ext_ctrl) +#define VIDIOC_DELETE_BUF _IOWR('V', 104, struct v4l2_buffer) + /* Reminder: when adding new ioctls please add support for them to drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */ From patchwork Thu Jun 22 13:13:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 111674 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5074674vqr; Thu, 22 Jun 2023 06:36:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ68q1h9w+maJNHjMlccid5Clj9s8SqGdGrE839WYmahLdUWxrN6+j3tSRGthCAomJH+SYb9 X-Received: by 2002:a17:902:c1c6:b0:1b2:5d5b:e871 with SMTP id c6-20020a170902c1c600b001b25d5be871mr14065658plc.59.1687440979379; Thu, 22 Jun 2023 06:36:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687440979; cv=none; d=google.com; s=arc-20160816; b=r1M15Bxn40v3PqOifmUHONv9hK/lOz6YjczFX5wSg9yU4pWoc6RxIvDZEszE0DOTX2 4M+d0/L2zMKEL3UtdJxg78LwkG17ZKgHu4hJqcNeymXBY/+K8V8ulg9PXCKHWemohvSk bPtfJXFIVgK334MfjlUMEE/ykrGrqszrBxP1MR9rpKx4UCNyn0qLDTnmObEBMEvqWbQf gh/vR0sYEZl/YoL2EV5/okaoNRPdGLIRzLbpg+P5tAcVXpjzwu0zYHeGir0ULnWibmri VEiDfo9pnn+kDhNfBaP+8iH9lNopvmUPsomTU7+kJNN6+Y+jmkRGXMbyMN5QKdZGeG8p fltg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fizQmLvNUUxr0jDRtm0Q3QiONfP85Te8hSHvbTHAebM=; b=Pi7em2vJqITPhJJRjcncVVrEcK0WmdGl471anKhjw0CZe6fGxg2icUqEwCk/WqWI/A CPZIlMFXH0xszK106JeZm20bCLTYvYRzCCIyi7/MAnA0vf9kB5IAZ5kofe0xPm5zdD1H nUIfRRM0I8SPkSBhiJHmkiUR6mYRO22KFkYMCV+slHgwJX/2J3/kq0vXpr+IEdzoUYLF FXuDeFM+xbPFAZMVl4J69ghTFLnmzTYAY9i2zfhSP6A9d4hPlhOTkyKYfFNU2oMCOS0C WHfGmLBESFMjhPXurR5XYH0SnZYwNov4mSfXY7WYPaj4WPYZegLaKwwei3LkD8cFhMPL OA5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=drrv7EAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kj11-20020a17090306cb00b001b02390367fsi6198912plb.595.2023.06.22.06.36.06; Thu, 22 Jun 2023 06:36:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=drrv7EAr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231145AbjFVNPH (ORCPT + 99 others); Thu, 22 Jun 2023 09:15:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231623AbjFVNOG (ORCPT ); Thu, 22 Jun 2023 09:14:06 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46D721BF6; Thu, 22 Jun 2023 06:14:04 -0700 (PDT) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:7d72:676c:e745:a6ef]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id BD701660713E; Thu, 22 Jun 2023 14:14:02 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687439643; bh=w7TelsLJmHPPFBbH7cdd4Q4u9mfk8qz6m8m3ILNeG3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=drrv7EArNlrMc2bqooR2UXQWYueWvIBP+Y1UDX7ZsxJ63fm9MWRTLdvcy/nd3MtmR 1tAPfYMWNjrmPUNRS0XxCwqXho+WBGpGewAnYEE2Ie+xdCEP8PrQjPE1/As1XTSeyn xo3B32kzTLEBtIyn4PJwr+EjAOq7FA6fpFlwXN2Z3uefoRQqtw9FpEHPug6LThebK/ Phxk51rtR7zmF4yR5QN7vIcsJ7/u5EPHjYGDIFfcOkODSzlshf3WIBEh+wamPxDcUG cWTeOwNzSOsFR7WozNP+PQ3eLDCtl+RCP7lgpfh103fQjpIRJovqxw58Wv7OnDvRLI iyFgvrTal3KYg== From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ming.qian@nxp.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, gregkh@linuxfoundation.org, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.com Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-arm-msm@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v3 11/11] media: v4l2: Add mem2mem helpers for DELETE_BUF ioctl Date: Thu, 22 Jun 2023 15:13:49 +0200 Message-Id: <20230622131349.144160-12-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230622131349.144160-1-benjamin.gaignard@collabora.com> References: <20230622131349.144160-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769410112050004332?= X-GMAIL-MSGID: =?utf-8?q?1769410112050004332?= Create v4l2-mem2mem helpers for VIDIOC_DELETE_BUF ioctl. Signed-off-by: Benjamin Gaignard --- .../media/platform/verisilicon/hantro_v4l2.c | 1 + drivers/media/test-drivers/vim2m.c | 1 + drivers/media/v4l2-core/v4l2-mem2mem.c | 20 +++++++++++++++++++ include/media/v4l2-mem2mem.h | 12 +++++++++++ 4 files changed, 34 insertions(+) diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index cdddfb4179aa..bf418191278f 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -720,6 +720,7 @@ const struct v4l2_ioctl_ops hantro_ioctl_ops = { .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_delete_buf = v4l2_m2m_ioctl_delete_buf, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, diff --git a/drivers/media/test-drivers/vim2m.c b/drivers/media/test-drivers/vim2m.c index 3e3b424b4860..3014b8ee13d0 100644 --- a/drivers/media/test-drivers/vim2m.c +++ b/drivers/media/test-drivers/vim2m.c @@ -960,6 +960,7 @@ static const struct v4l2_ioctl_ops vim2m_ioctl_ops = { .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf, .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, + .vidioc_delete_buf = v4l2_m2m_ioctl_delete_buf, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, .vidioc_streamon = v4l2_m2m_ioctl_streamon, diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 0cc30397fbad..42f51ca25379 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -831,6 +831,17 @@ int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, } EXPORT_SYMBOL_GPL(v4l2_m2m_prepare_buf); +int v4l2_m2m_delete_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, + struct v4l2_buffer *buf) +{ + struct vb2_queue *vq; + + vq = v4l2_m2m_get_vq(m2m_ctx, buf->type); + + return vb2_delete_buf(vq, buf); +} +EXPORT_SYMBOL_GPL(v4l2_m2m_delete_buf); + int v4l2_m2m_create_bufs(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, struct v4l2_create_buffers *create) { @@ -1377,6 +1388,15 @@ int v4l2_m2m_ioctl_create_bufs(struct file *file, void *priv, } EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_create_bufs); +int v4l2_m2m_ioctl_delete_buf(struct file *file, void *priv, + struct v4l2_buffer *buf) +{ + struct v4l2_fh *fh = file->private_data; + + return v4l2_m2m_delete_buf(file, fh->m2m_ctx, buf); +} +EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_delete_buf); + int v4l2_m2m_ioctl_querybuf(struct file *file, void *priv, struct v4l2_buffer *buf) { diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h index bb9de6a899e0..d062a35c8246 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -381,6 +381,16 @@ int v4l2_m2m_dqbuf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, int v4l2_m2m_prepare_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, struct v4l2_buffer *buf); +/** + * v4l2_m2m_delete_buf() - delete buffer from the queue + * + * @file: pointer to struct &file + * @m2m_ctx: m2m context assigned to the instance given by struct &v4l2_m2m_ctx + * @buf: pointer to struct &v4l2_buffer + */ +int v4l2_m2m_delete_buf(struct file *file, struct v4l2_m2m_ctx *m2m_ctx, + struct v4l2_buffer *buf); + /** * v4l2_m2m_create_bufs() - create a source or destination buffer, depending * on the type @@ -846,6 +856,8 @@ int v4l2_m2m_ioctl_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *rb); int v4l2_m2m_ioctl_create_bufs(struct file *file, void *fh, struct v4l2_create_buffers *create); +int v4l2_m2m_ioctl_delete_buf(struct file *file, void *priv, + struct v4l2_buffer *buf); int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf); int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh,