From patchwork Wed Feb 21 15:54:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204289 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1131978dyc; Wed, 21 Feb 2024 08:05:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWvsFBEm6BhfbzVxuw6yUtqNLZ6jJrPXDjmsOxJawmK28l0CFhBt095Df6RnurRpRUeIS5AT5JzX6LvKI57+DlX+29ePg== X-Google-Smtp-Source: AGHT+IEsrtUdLve7tcGYCPBk7rDSBZkjtgpgOAUWn4YzgsRyyg1MXLLOsHQ/W93HFyFJDaLcDFCL X-Received: by 2002:a17:90a:5916:b0:299:d5fa:3e18 with SMTP id k22-20020a17090a591600b00299d5fa3e18mr6261829pji.20.1708531541201; Wed, 21 Feb 2024 08:05:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531541; cv=pass; d=google.com; s=arc-20160816; b=bWN24EgGq83u7a9OEWr9x3MYVSteaPU3dnimpaI1+RXbWatOvJZEEyuC4c4FgjYKji aEAOHPK5v9GjWZeNSwDinG2s/g3I3BK7n1DIm5bK/cLTD+ZflxxEtWRF9fWq4DvBLCDv ZDDJRswmtBzXfIIF7AqwRTojrTDKD5owELBpVh3QVLvopX03lFtOzTIfUQ7+iKAILiFs HbfGnuoEzxFYrDnfWG78Weowyp/C91Z1c1p3u4ObmUMVf35oq9qvyt02zsn2riMYEDUC FcYPN0PsJXpoDJZJEpH0us4uuMhXyE1W3dDXumTlGE8jcLX13CYIjrNJr5dXnaiUrcDw azwA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CDZAfgfVwfU/d2B6d0+m4TBo9+9KsAeejO0PiCuX/bs=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=rsviVhUaddDXxBLvMEjzUoukZ2HqaGhUcqSTXolNV56m7aaqcHAW7j8W3F2if94pEb uNm4bVrEh9SFu8S9fgRfFVJFPb7tbU1665G8qaPqB/dc7sV8J35HEJDmG19ZbtGRb9yk e1aGoXaKkz2LTgBX97kqN1hFEzR8k3fjZFTbd759tVjQlL4Zn46vBc3E6q2rWyVCHp9M 5I25jq6jWKkd0WReiVq22RzD1Ly992HP08S7rga5lw+QM/cSDzr4EBkIGFNLKmatVWe5 XpCMLP64Z3aS+Ks4j/7JDpjreVkcdUw9j6yEM1R3+AGVW90JJoQirT5aoxfaWlkAC8Uu EtMw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=uTWPvWxY; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75040-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75040-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id nu7-20020a17090b1b0700b0029a23493f23si1000005pjb.73.2024.02.21.08.05.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 08:05:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75040-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=uTWPvWxY; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75040-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75040-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id DD0A8B23516 for ; Wed, 21 Feb 2024 15:56:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E908A823C6; Wed, 21 Feb 2024 15:54:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="uTWPvWxY" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 730A98002B; Wed, 21 Feb 2024 15:54:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530886; cv=none; b=J4J3Itv6mc5m3AG9wfPQ6DYiizdR0+y2n093IKurUF3FMpoqTbUr7mWCHL0IqWC1ZxTfsuzjN5bDAOsPDL9s0Tb7VIcUuZXoiWQ4Eflq8PNE4pPC7+UN5W4P84CKgTj3Tp+gfOAWoeKL9ZDHIXm6lb+5EXq9gGg49DVlkvooXMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530886; c=relaxed/simple; bh=5ckXgkvWFGC5NNON9KbJM0pNpOmn7g6OdSSL28pZpt4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=CvyDl4zwBvJSToOrU1jKcRgHq+NgWGBSCX7RcJ/yk/Sk/ubGloQauGhD4bbwb3yTpvX9Lbp4+L4HKiOdbzB6gPKHBEXIJ2kM6vTkaNrJK0VcGG1NglMSvKXKdXQYgcAvnRLq2U6mVBfovdrUP5ewtuUMST5jKWim/GtTcQSVUx0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=uTWPvWxY; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530882; bh=5ckXgkvWFGC5NNON9KbJM0pNpOmn7g6OdSSL28pZpt4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uTWPvWxYB8aVG/Jmtt/SUn5NTob7J1BmlHCtcdzMsWgTT9WZo0TTHgr4kIlbgGlku DZKNh1V+54ivHckBGQlXY6jEzyjH/ndW81IcImNUNa9OpGArULe1lAYtUS10vNSqEO NBSJkpoK/g7Fn+bSy6C1UFMwZ0pqVT7CwttuvW6Pieb1weagKokdfVieay2ob9VYUK NdN3R465hTJ/zDY1ohkUdDS+IK7fgfShzyPHPgeYtgnXgDQiWtadW9IusaJcpwMVvp d8CjrldwRyBsTU36BsbpnnTALH2ZZn0+cCFqsvvbAZgllG3yWD6/taawXLktXpbGMK x9alJ9bYdyAJQ== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 309033780C13; Wed, 21 Feb 2024 15:54:42 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 1/9] media: videobuf2: Update vb2_is_busy() logic Date: Wed, 21 Feb 2024 16:54:27 +0100 Message-Id: <20240221155435.100093-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791525169399042140 X-GMAIL-MSGID: 1791525169399042140 Do not rely on the number of allocated buffers to know if the queue is busy but on a flag set when at least one buffer has been allocated by REQBUFS or CREATE_BUFS ioctl. The flag is reset when REQBUFS is called with count = 0 or the file handle is closed. This is needed because remove buffers feature will be able to remove all the buffers from a queue while streaming so relying on the number of allocated buffers in the queue won't be possible. Signed-off-by: Benjamin Gaignard --- drivers/media/common/videobuf2/videobuf2-core.c | 4 ++++ include/media/videobuf2-core.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index b6bf8f232f48..d8b3c04cb3b5 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -854,6 +854,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, __vb2_queue_free(q, q_num_bufs); mutex_unlock(&q->mmap_lock); + q->is_busy = 0; /* * In case of REQBUFS(0) return immediately without calling * driver's queue_setup() callback and allocating resources. @@ -966,6 +967,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, */ *count = allocated_buffers; q->waiting_for_buffers = !q->is_output; + q->is_busy = 1; return 0; @@ -1091,6 +1093,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * to the userspace. */ *count = allocated_buffers; + q->is_busy = 1; return 0; @@ -2555,6 +2558,7 @@ void vb2_core_queue_release(struct vb2_queue *q) __vb2_queue_free(q, vb2_get_num_buffers(q)); kfree(q->bufs); q->bufs = NULL; + q->is_busy = 0; mutex_unlock(&q->mmap_lock); } EXPORT_SYMBOL_GPL(vb2_core_queue_release); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index d9c6b5d4e990..6ad36da91f8d 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -579,6 +579,7 @@ struct vb2_buf_ops { * called since poll() needs to return %EPOLLERR in that situation. * @is_multiplanar: set if buffer type is multiplanar * @is_output: set if buffer type is output + * @is_busy: set if at least one buffer has been allocated at some time. * @copy_timestamp: set if vb2-core should set timestamps * @last_buffer_dequeued: used in poll() and DQBUF to immediately return if the * last decoded buffer was already dequeued. Set for capture queues @@ -644,6 +645,7 @@ struct vb2_queue { unsigned int waiting_in_dqbuf:1; unsigned int is_multiplanar:1; unsigned int is_output:1; + unsigned int is_busy:1; unsigned int copy_timestamp:1; unsigned int last_buffer_dequeued:1; @@ -1163,7 +1165,7 @@ static inline unsigned int vb2_get_num_buffers(struct vb2_queue *q) */ static inline bool vb2_is_busy(struct vb2_queue *q) { - return vb2_get_num_buffers(q) > 0; + return !!q->is_busy; } /** From patchwork Wed Feb 21 15:54:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1124995dyc; Wed, 21 Feb 2024 07:56:43 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUsWI4U+hdQ9JCopTalT+k/ecu8gb4P8pLJUn5h800My/qh8ngitzav5y1mW203a6j9HSL6QhxnDs+CIJwVtusyrvsC5g== X-Google-Smtp-Source: AGHT+IHtuzm1lpeT1bE5gbXDkNu63+hYX+OdGJU8b0c0sJOmK4228nN8PWo/hy7R5SOP1Hs/TD7m X-Received: by 2002:a05:6808:138d:b0:3c1:6529:92dc with SMTP id c13-20020a056808138d00b003c1652992dcmr5812552oiw.36.1708531003308; Wed, 21 Feb 2024 07:56:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531003; cv=pass; d=google.com; s=arc-20160816; b=t8Xs2QH6h7v9hDhD/7TpFgIV8WZC+PljzXbXJYFo7RP5mgquDUwjBanAbxel50ANJR 02A8is4rlOoRF7y+QhdeyoTsbuuYocnSwycpFwiHJxWJJv60IJzyIeLrQpLieFdO7fOp 90tLCXChFsN9SmlwlQxXQC3SEHSMO353Ipbg8J0g9AWgi9n4+8802JbLSR1BKwxtD0fy 0Y+pTeVjrxJjrFyI5YHa9B9vjSYcppaBpthphzKz43lHxOyjRerJ+xVI3oPY5d8uBpZc XyV4F/gMMxupKwAxYwwvbzWPi5DcixGF+Y/5mM0tN/IXIOHBT8MlH1KO/9+RTcuqS41c nxSA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lmzugXD4VwZfVIl//NbI+I5prOTFOW2cgN/hY9sUYRs=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=bMU27++th6fPOVmlETaiD1SyT2NGrdAnGicyulwNjLj7W5IfNCHnU0X7cyUivmptW6 B0BrjbRpZLKta+NHpOdfsg5dibXKLA3rSowVf9HU4suKBMqQO7wpkQlMEHcgsRYHuxOu YFXKzBJU/DKDa2+vCNdvgx2zEFmLtuRtE2EnREY3q4dNawVBL38WCW49ZSlmhzpJE42A zLE8eO7odan+ds2hT2ZjXsX8gILlOeoEQtpKdIbuGfPG19QLyTcV/UKZjpO1+ntym39E 3anmDaSVbM93bTOJtct/IC6zsY3Wo6kXyJCG/+Qeoaz+vWxl37PwyO4R1Aegrnwy1L48 bHIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bAgbh62s; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75041-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75041-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kk22-20020a056214509600b0068fa86bda64si1074535qvb.578.2024.02.21.07.56.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:56:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75041-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bAgbh62s; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75041-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75041-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B7B601C226B8 for ; Wed, 21 Feb 2024 15:56:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 215A282897; Wed, 21 Feb 2024 15:54:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="bAgbh62s" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61E103A1B1; Wed, 21 Feb 2024 15:54:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530887; cv=none; b=nBx5Ql7ofXw0gSynyrUozCzGn8HS4/D5lNoM+d06wISekkJssJoiI0bRkVIT/XZsW1Zzv+pzi1SXDU5WhtJQeCQurpU5oLWaX4uXyjWwHqJbmSTpMhuPNo0YxAkO2EmlcuUG+Lqx1QwS98m+G43YTH2SgUBhvfHlVTtK+mQvCu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530887; c=relaxed/simple; bh=AV/2+6DOS7yOUx5UFiYF0NGULQdHl7NCcDnBNq974F0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ekk6GXFG1xm1jTB+3pY4T1HOJkiHj73FEGL0ynLg1FEpkUAC+sOJm6hkA9+k3cAmnvDSR5KzNu+cW/gPalIzIWqb11MaBWFfX+3zWOWhNTtU/Y/Ofbmj8MYrxzWQ2flHDynCM9VbQqrDsZ8IPp58BRU17VUiuF/ILCcMtVPOJxE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=bAgbh62s; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530883; bh=AV/2+6DOS7yOUx5UFiYF0NGULQdHl7NCcDnBNq974F0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bAgbh62sJ9Y9UY8RBnu7iHcby2xc0DCVSiF5aijFb8TDGa7xzGSo+K+AmPjw76ATh ouuSxDS+/9zMWWSTxV2N6VHHlloLQEbTrcxfr44i9ME4yteMHPSqIkg75Nq4FThKeD yVQgbDiVpBDjOzHDGqvdFvn5FVYHqqF4MH9iNxkVEH608OxR30dZZvK23rFOONs746 kHl9qiu+tCwozggomY7xtmiXbYf7tZmgiqdzn+DjjjC6MqInAo0+DJ6KL6lN+1VAk8 fx3Dh9+wBv614X3aSGzHnAhKJeNOfgdOVlRofL/jDbXuA+oF4HyWx/K2y8QeD244VI gUyCWeRQa7GNA== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 00D3F3781116; Wed, 21 Feb 2024 15:54:42 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 2/9] videobuf2: Add min_reqbufs_allocation field to vb2_queue structure Date: Wed, 21 Feb 2024 16:54:28 +0100 Message-Id: <20240221155435.100093-3-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791524605163669171 X-GMAIL-MSGID: 1791524605163669171 Add 'min_reqbufs_allocation' field in the vb2_queue structure so drivers can specify the minimum number of buffers to allocate when calling VIDIOC_REQBUFS. When initializing the queue, v4l2 core makes sure that the following constraints are respected: - the minimum number of buffers to allocate must be at least 2 because one buffer is used by the hardware while the other is being processed by userspace. -if the driver needs 'min_queued_buffers' in the queue before calling start_streaming(), then the minimum requirement is 'min_queued_buffers + 1' to keep at least one buffer available for userspace. Simplify __vb2_init_fileio() by using 'min_reqbufs_allocation' directly to avoid duplicating the minimum number of buffers to allocate computation. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 38 +++++++++++-------- include/media/videobuf2-core.h | 15 +++++++- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index d8b3c04cb3b5..58c495b253ce 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -866,7 +866,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* * Make sure the requested values and current defaults are sane. */ - num_buffers = max_t(unsigned int, *count, q->min_queued_buffers); + num_buffers = max_t(unsigned int, *count, q->min_reqbufs_allocation); num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers); memset(q->alloc_devs, 0, sizeof(q->alloc_devs)); /* @@ -918,7 +918,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * There is no point in continuing if we can't allocate the minimum * number of buffers needed by this vb2_queue. */ - if (allocated_buffers < q->min_queued_buffers) + if (allocated_buffers < q->min_reqbufs_allocation) ret = -ENOMEM; /* @@ -2524,6 +2524,25 @@ int vb2_core_queue_init(struct vb2_queue *q) if (WARN_ON(q->supports_requests && q->min_queued_buffers)) return -EINVAL; + /* + * The minimum requirement is 2: one buffer is used + * by the hardware while the other is being processed by userspace. + */ + if (q->min_reqbufs_allocation < 2) + q->min_reqbufs_allocation = 2; + + /* + * If the driver needs 'min_queued_buffers' in the queue before + * calling start_streaming() then the minimum requirement is + * 'min_queued_buffers + 1' to keep at least one buffer available + * for userspace. + */ + if (q->min_reqbufs_allocation < q->min_queued_buffers + 1) + q->min_reqbufs_allocation = q->min_queued_buffers + 1; + + if (WARN_ON(q->min_reqbufs_allocation > q->max_num_buffers)) + return -EINVAL; + INIT_LIST_HEAD(&q->queued_list); INIT_LIST_HEAD(&q->done_list); spin_lock_init(&q->done_lock); @@ -2717,7 +2736,6 @@ 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; /* * Sanity check @@ -2738,18 +2756,8 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) if (q->streaming || vb2_get_num_buffers(q) > 0) return -EBUSY; - /* - * Start with q->min_queued_buffers + 1, driver can increase it in - * queue_setup() - * - * 'min_queued_buffers' buffers need to be queued up before you - * can start streaming, plus 1 for userspace (or in this case, - * kernelspace) processing. - */ - count = max(2, q->min_queued_buffers + 1); - dprintk(q, 3, "setting up file io: mode %s, count %d, read_once %d, write_immediately %d\n", - (read) ? "read" : "write", count, q->fileio_read_once, + (read) ? "read" : "write", q->min_reqbufs_allocation, q->fileio_read_once, q->fileio_write_immediately); fileio = kzalloc(sizeof(*fileio), GFP_KERNEL); @@ -2763,7 +2771,7 @@ static int __vb2_init_fileio(struct vb2_queue *q, int read) * Request buffers and use MMAP type to force driver * to allocate buffers by itself. */ - fileio->count = count; + fileio->count = q->min_reqbufs_allocation; fileio->memory = VB2_MEMORY_MMAP; fileio->type = q->type; q->fileio = fileio; diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 6ad36da91f8d..2ca120f18edf 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -550,9 +550,21 @@ struct vb2_buf_ops { * @start_streaming can be called. Used when a DMA engine * cannot be started unless at least this number of buffers * have been queued into the driver. - * VIDIOC_REQBUFS will ensure at least @min_queued_buffers + * VIDIOC_REQBUFS will ensure at least @min_queued_buffers + 1 * buffers will be allocated. Note that VIDIOC_CREATE_BUFS will not * modify the requested buffer count. + * @min_reqbufs_allocation: the minimum number of buffers to be allocated when + * calling VIDIOC_REQBUFS. Note that VIDIOC_CREATE_BUFS will *not* + * modify the requested buffer count and does not use this field. + * Drivers can set this if there has to be a certain number of + * buffers available for the hardware to work effectively. + * This allows calling VIDIOC_REQBUFS with a buffer count of 1 and + * it will be automatically adjusted to a workable buffer count. + * If set, then @min_reqbufs_allocation must be larger than + * @min_queued_buffers + 1. + * If this field is > 3, then it is highly recommended that the + * driver implements the V4L2_CID_MIN_BUFFERS_FOR_CAPTURE/OUTPUT + * control. */ /* * Private elements (won't appear at the uAPI book): @@ -619,6 +631,7 @@ struct vb2_queue { u32 timestamp_flags; gfp_t gfp_flags; u32 min_queued_buffers; + u32 min_reqbufs_allocation; struct device *alloc_devs[VB2_MAX_PLANES]; From patchwork Wed Feb 21 15:54:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1125188dyc; Wed, 21 Feb 2024 07:57:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQc3vDZKX3qo2O8X/nKNADmf5+Dnee9nIovcyfje5BQVOlG6m2/E4YMbM3DP1YY/BbE4Awn76dAE9VFddjCXXQ+Op5fQ== X-Google-Smtp-Source: AGHT+IE3LJZzZAlEnuHiE7yB4d7SokzeL2cOizFuzaHdedQ+qLEa4vRcjBbWnMhv41iZF1YV1oJk X-Received: by 2002:a05:622a:1889:b0:42a:b8e6:aef8 with SMTP id v9-20020a05622a188900b0042ab8e6aef8mr22684321qtc.42.1708531026105; Wed, 21 Feb 2024 07:57:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531026; cv=pass; d=google.com; s=arc-20160816; b=cHqhZRRwX+NmGXoW5W4f3XVyLqdYbVCOFcww9aWxF8El/nYthLMm8hMBhquQEY35QI lbrwqaov7QS9cLea6ucZ20xNoyBn7QMYDLrrgv6Mqa+x3aGKw8vkE8i3tLqiUZM6ZL2W Nf5HroY4Bdp5djSR/12yXxljKCqpqksqgMy316dPmlTpHRS3QLbezaUKNBUQmUhq9oWL peMMoGpAFN2x9ma8l5Xt5lXpm6Az32y3NlmHKFPl0UfSwhWoKatObEeQZtG9DIEMBHgf BKTJNEVCQKVp6vf7ny+T9dGiVtLFg0T8h8fq9NZxaH8YOroOhXoGkwTf0+VftwdRckmz jSqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kRtB+JwMw/qxJHe0q5DKmYaRAH0ysSyHFkfdVGIQM6c=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=wFDuDDF5RXc9d9MsXVNe41KMitp54iVV4lNW1pEQp/LDuMdFVFxe9IUps34LduaZ/C aBaolxDu27NTU6BLgZ8JiKNedBZv8O1nwzlO13RzMMtoe44ALEudvN/bOzvYGr8ZVt5p dxo3A5ivergwaqG5YbxM2R493UEuxxa/miXvR64taU2AID4qO7baZv/vJbQE3tVVGW9W i/t5/qjFuQ4sMLs+sQAl5h83Aa8dGuVzGxpo1mG/1kl+aLwC4M1GGYyZRmr/oWV3D85I o1e7vPqSi81LqmZSzYFexsuUq6VkrJ5e177SVaNTaOlE+0q0VeeL5qTGD+o+3I6zGMiZ ftZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=woM5TAZi; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75043-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75043-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id a17-20020ac87211000000b0042df0409fafsi9735272qtp.1.2024.02.21.07.57.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:57:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75043-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=woM5TAZi; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75043-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75043-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B791E1C22B8C for ; Wed, 21 Feb 2024 15:57:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F51182D74; Wed, 21 Feb 2024 15:54:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="woM5TAZi" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B8FFC81AB0; Wed, 21 Feb 2024 15:54:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530888; cv=none; b=P2jpz+bdV7ECERtbNTBb7VkV8nywmdJ5zJL2vGgBM99SSSTV+o4FU953OfWAgJbbawbvTi8/Pu6PAUSBDp8UjZpNXrXIoFw7yD0CnTRsRarUfAcxC7K3Po/dQO1DcZIP1CXZE3qFgpoxZl/f7NQaZMW3engb3abbpx0Suvm2YIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530888; c=relaxed/simple; bh=F2tCb9wrVF4rzaA8ZIQQ0yFu1+5C0qlZBUoz027HFsA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=XVkUHMakiF5UUyAyDu0JYHzLya7QI31gw+rkaaJs8Z6KIlcknr4lw83pfLkhxhkvzCp9OyTortwJsd8KgNOrj4qFZUwnKD3jE1jCZQ8YMFYzQ8iWjoDYxD0qwgri7uBp0zdS8rICoaQRUtqstCeIfBZN5Ysq05coLXAHiObe3qw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=woM5TAZi; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530885; bh=F2tCb9wrVF4rzaA8ZIQQ0yFu1+5C0qlZBUoz027HFsA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=woM5TAZi6ecMXV2UrX4WpflalEahTxiNez6SvyhDY2GxeXAp/tRthaAQqC/pudag6 3vQQ8hT6ZviTcUzUFVjSPwAl1oquO35QfjRcYe5DS3BeArFzg9hBl8NESYFj2jVyo/ laIsOpLpPNvqBIj4alVMlcZkfrmLj4YurC+uwarGOjcP+pMxQXWYJw7g167F9fv8gX 6I0ugIoDjyYcWWoa9jMQv5VThjI4LAp0z6SsHmQGegBDA3w0/Vo9O+bl39A2r0H3pN 6BVzV9putUB2INxrkRyY3cz5kW8/PynkbLF9A3WEL+c62zZNY0fNAb7/UTxYyF8m+T c8sFnnBrV6fmQ== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 95B7B37820CE; Wed, 21 Feb 2024 15:54:44 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 4/9] media: core: Rework how create_buf index returned value is computed Date: Wed, 21 Feb 2024 16:54:30 +0100 Message-Id: <20240221155435.100093-5-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791524629068908482 X-GMAIL-MSGID: 1791524629068908482 When REMOVE_BUFS will be introduced holes could created in bufs array. To be able to reuse these unused indices reworking how create->index is set is mandatory. Let __vb2_queue_alloc() decide which first index is correct and forward this to the caller. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 18 +++++++++++++----- .../media/common/videobuf2/videobuf2-v4l2.c | 14 +++++++++----- include/media/videobuf2-core.h | 5 ++++- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 58c495b253ce..8e819d198c34 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -442,12 +442,15 @@ static void vb2_queue_remove_buffer(struct vb2_buffer *vb) * __vb2_queue_alloc() - allocate vb2 buffer structures and (for MMAP type) * video buffer memory for all buffers/planes on the queue and initializes the * queue + * @first_index: index of the first created buffer, all newly allocated buffers + * have indices in the range [first_index..first_index+count-1] * * Returns the number of buffers successfully allocated. */ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, unsigned int num_buffers, unsigned int num_planes, - const unsigned plane_sizes[VB2_MAX_PLANES]) + const unsigned int plane_sizes[VB2_MAX_PLANES], + unsigned int *first_index) { unsigned int q_num_buffers = vb2_get_num_buffers(q); unsigned int buffer, plane; @@ -461,6 +464,8 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, num_buffers = min_t(unsigned int, num_buffers, q->max_num_buffers - q_num_buffers); + *first_index = q_num_buffers; + for (buffer = 0; buffer < num_buffers; ++buffer) { /* Allocate vb2 buffer structures */ vb = kzalloc(q->buf_struct_size, GFP_KERNEL); @@ -820,7 +825,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int q_num_bufs = vb2_get_num_buffers(q); unsigned plane_sizes[VB2_MAX_PLANES] = { }; bool non_coherent_mem = flags & V4L2_MEMORY_FLAG_NON_COHERENT; - unsigned int i; + unsigned int i, first_index; int ret = 0; if (q->streaming) { @@ -907,8 +912,10 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, /* Finally, allocate buffers and video memory */ allocated_buffers = - __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes); + __vb2_queue_alloc(q, memory, num_buffers, num_planes, plane_sizes, &first_index); if (allocated_buffers == 0) { + /* There shouldn't be any buffers allocated, so first_index == 0 */ + WARN_ON(first_index); dprintk(q, 1, "memory allocation failed\n"); ret = -ENOMEM; goto error; @@ -982,7 +989,8 @@ EXPORT_SYMBOL_GPL(vb2_core_reqbufs); int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count, unsigned int requested_planes, - const unsigned int requested_sizes[]) + const unsigned int requested_sizes[], + unsigned int *first_index) { unsigned int num_planes = 0, num_buffers, allocated_buffers; unsigned plane_sizes[VB2_MAX_PLANES] = { }; @@ -1044,7 +1052,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, /* Finally, allocate buffers and video memory */ allocated_buffers = __vb2_queue_alloc(q, memory, num_buffers, - num_planes, plane_sizes); + num_planes, plane_sizes, first_index); if (allocated_buffers == 0) { dprintk(q, 1, "memory allocation failed\n"); ret = -ENOMEM; diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index c575198e8354..03e8080a68a8 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -795,11 +795,15 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) for (i = 0; i < requested_planes; i++) if (requested_sizes[i] == 0) return -EINVAL; - return ret ? ret : vb2_core_create_bufs(q, create->memory, - create->flags, - &create->count, - requested_planes, - requested_sizes); + if (ret) + return ret; + + return vb2_core_create_bufs(q, create->memory, + create->flags, + &create->count, + requested_planes, + requested_sizes, + &create->index); } EXPORT_SYMBOL_GPL(vb2_create_bufs); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 2ca120f18edf..ee0cbd8705ec 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -823,6 +823,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * @count: requested buffer count. * @requested_planes: number of planes requested. * @requested_sizes: array with the size of the planes. + * @first_index: index of the first created buffer, all allocated buffers have + * indices in the range [first_index..first_index+count-1] * * Videobuf2 core helper to implement VIDIOC_CREATE_BUFS() operation. It is * called internally by VB2 by an API-specific handler, like @@ -839,7 +841,8 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count, unsigned int requested_planes, - const unsigned int requested_sizes[]); + const unsigned int requested_sizes[], + unsigned int *first_index); /** * vb2_core_prepare_buf() - Pass ownership of a buffer from userspace From patchwork Wed Feb 21 15:54:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204275 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1125496dyc; Wed, 21 Feb 2024 07:57:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUvDl7Q06i3nvXMxapJOUYfAbH+i/zgz3JhQN0h2MKejVa+fgYOMKIOKHRWujrwb5gXEnJbzge0FSa+ulN9yzCewzRoug== X-Google-Smtp-Source: AGHT+IGuWPQBpIEnC3pkuQCSqTsCG5VMQpwFdwrOzqRZhfHernoOQN/FUBjNKiwgZL1Y040g6Lxs X-Received: by 2002:a05:620a:843:b0:787:777c:c138 with SMTP id u3-20020a05620a084300b00787777cc138mr4919770qku.68.1708531058219; Wed, 21 Feb 2024 07:57:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531058; cv=pass; d=google.com; s=arc-20160816; b=0nk5Eow9YNzQCqZIbJ4d54Y1F9tkec74/OJi3hTzjX/yEahirBEkHuGgQyTGUdyUPK bKmhEJdUtsEl3mt3aUX3uwfTDNYigYg/sxbyuY5HYJbJ6yCIcD73oR+IGwIXtGddk8vu 2rSL0PGs0vB3cYge52lHymbQ176IEf2v6KUlZXVU59J2NX3z6ZlgCZtA/gJ+LCok9fuw ZZXqjSkiqvZcPwwkZTjKD64RS7Qm59UmudgJlQeyx9KVFsymI1dYO8J8TnXHMESpWnXN 6o0VCeUe7X2pVwmvM4gv0miiSs60dbFg+E250ZvR3/8kCehzkKg8DwToyRWyOZgxrYCb TZ4A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=h0KbUWItPlsLBWEuV8g/lq2hWNH9vnxBt8tOY1OcBhY=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=ByiO1bITdXTc6VOzkUEvCAcnPZZzOS+IBoIv4z2spC5FC7oSQm2DvE3lpnzawAdB4Y igQTCn2AzkFjnYCsjTUJymw+zJkCahTYggZ1IIAaKdN0ZcC07sKfCUGIO71IMzu1wiV2 fczqdlXUZNmPNt5HkkZweRLjAMw/sXSvNxel43mvZjwzwG5x3CIvmZeP2v1ZKmQIOacO zEjtYpj0fUQYwe68O6wRTyWhEVh1ezuqXhCRvFur5zkL30zZXCJIQ0r5MGj8WjhzZU5a 5UumGIgF10ZDG/si0n+IQaD7mT4UWC/9Uh/dqxs4K7jL0nvgyT0EoL+nbw569WQSd6B/ AAIg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=B6U2lXYL; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75044-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75044-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id wg5-20020a05620a568500b0078772aa740dsi4974475qkn.781.2024.02.21.07.57.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:57:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75044-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=B6U2lXYL; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75044-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75044-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DA3F11C228FD for ; Wed, 21 Feb 2024 15:57:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D7C26839FC; Wed, 21 Feb 2024 15:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="B6U2lXYL" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D39A81AC6; Wed, 21 Feb 2024 15:54:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530889; cv=none; b=Ov2It0PoejUWSwEpeoWNxo4qpoL8aQKYWlOBeyVAIPzFw99Lxy5nT0PHVO688bGd+BihKnZVFycWTXioUJznayvboEVdW2CUhoOAYH7qPxr9k8j1ur6ST4EM2YvXTgKXJBsGj/7KKjzKTOHdqKnq9oXm19YFTGr8CLLA9VX2X/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530889; c=relaxed/simple; bh=q/70MdBzth/2lUXTHflNvTocA810ZeD66FDcxyBvRAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=BLbCxt35CtEuEyWecma4WUcfkI0N0TkouMSjwUVnptxWeyPoXM6BcDezOmj2bV1aIn4UNSCHaAaL+BPdL3iH3QWE6S3RlPus/ZoS1Hoitl3DYkXKfuKyOc0GQjkuxOow/mocdFAZpP+XQnmm/NLQqUTCVxc20x/qhn0M7HroUy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=B6U2lXYL; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530886; bh=q/70MdBzth/2lUXTHflNvTocA810ZeD66FDcxyBvRAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B6U2lXYLAEuq75jJOs5Q6UTe1/7bHTLm2ikwbEi7ZdFiwTvTAPYQ/FDRLGjKpkZHs SN97/s8rtnXN8/UAECAmVOz9qAYueHby1Uq1vTA9qFZwGeI8xpYwDiVeka0Tgu4gYa J8/2P/p+PBbslfCj0GCXLQkaBkNkCtYsb0Lj1odFMMIAfTR/OkxG6DQ32guxn8yVwW JxSxRvUdIlPoU1xWzY9XJT/CUgalO3TPpNEnrn9QtclfLBeUHENCHkEjkSjGsEmN0t fARUH0iIIS5jDsxYCmoU1dS9ewV8EkuaKI7w4+UO/IVFUbdcIVLlHeL629ysqIpGVS srAF4AO0BMs/w== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 6601637820CF; Wed, 21 Feb 2024 15:54:45 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 5/9] media: core: Add bitmap manage bufs array entries Date: Wed, 21 Feb 2024 16:54:31 +0100 Message-Id: <20240221155435.100093-6-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791524663209201063 X-GMAIL-MSGID: 1791524663209201063 Add a bitmap field to know which of bufs array entries are used or not. Remove no more used num_buffers field from queue structure. Use bitmap_find_next_zero_area() to find the first possible range when creating new buffers to fill the gaps. If no suitable range is found try to allocate less buffers than requested. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 71 ++++++++++++++----- include/media/videobuf2-core.h | 18 +++-- 2 files changed, 64 insertions(+), 25 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 8e819d198c34..ec81426d4d79 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -421,11 +421,12 @@ static void init_buffer_cache_hints(struct vb2_queue *q, struct vb2_buffer *vb) */ static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, unsigned int index) { - WARN_ON(index >= q->max_num_buffers || q->bufs[index] || vb->vb2_queue); + WARN_ON(index >= q->max_num_buffers || test_bit(index, q->bufs_bitmap) || vb->vb2_queue); q->bufs[index] = vb; vb->index = index; vb->vb2_queue = q; + set_bit(index, q->bufs_bitmap); } /** @@ -434,6 +435,7 @@ static void vb2_queue_add_buffer(struct vb2_queue *q, struct vb2_buffer *vb, uns */ static void vb2_queue_remove_buffer(struct vb2_buffer *vb) { + clear_bit(vb->index, vb->vb2_queue->bufs_bitmap); vb->vb2_queue->bufs[vb->index] = NULL; vb->vb2_queue = NULL; } @@ -452,9 +454,9 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, const unsigned int plane_sizes[VB2_MAX_PLANES], unsigned int *first_index) { - unsigned int q_num_buffers = vb2_get_num_buffers(q); unsigned int buffer, plane; struct vb2_buffer *vb; + unsigned long index = q->max_num_buffers; int ret; /* @@ -462,9 +464,25 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, * in the queue is below q->max_num_buffers */ num_buffers = min_t(unsigned int, num_buffers, - q->max_num_buffers - q_num_buffers); + q->max_num_buffers - vb2_get_num_buffers(q)); + + while (num_buffers) { + index = bitmap_find_next_zero_area(q->bufs_bitmap, q->max_num_buffers, + 0, num_buffers, 0); + + if (index < q->max_num_buffers) + break; + /* Try to find free space for less buffers */ + num_buffers--; + } + + /* If there is no space left to allocate buffers return 0 to indicate the error */ + if (!num_buffers) { + *first_index = 0; + return 0; + } - *first_index = q_num_buffers; + *first_index = index; for (buffer = 0; buffer < num_buffers; ++buffer) { /* Allocate vb2 buffer structures */ @@ -484,7 +502,7 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, vb->planes[plane].min_length = plane_sizes[plane]; } - vb2_queue_add_buffer(q, vb, q_num_buffers + buffer); + vb2_queue_add_buffer(q, vb, index++); call_void_bufop(q, init_buffer, vb); /* Allocate video buffer memory for the MMAP type */ @@ -664,7 +682,6 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) kfree(vb); } - q->num_buffers -= buffers; if (!vb2_get_num_buffers(q)) { q->memory = VB2_MEMORY_UNKNOWN; INIT_LIST_HEAD(&q->queued_list); @@ -818,6 +835,32 @@ static bool verify_coherency_flags(struct vb2_queue *q, bool non_coherent_mem) return true; } +static int vb2_core_allocated_buffers_storage(struct vb2_queue *q) +{ + if (!q->bufs) + q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); + if (!q->bufs) + return -ENOMEM; + + if (!q->bufs_bitmap) + q->bufs_bitmap = bitmap_zalloc(q->max_num_buffers, GFP_KERNEL); + if (!q->bufs_bitmap) { + kfree(q->bufs); + q->bufs = NULL; + return -ENOMEM; + } + + return 0; +} + +static void vb2_core_free_buffers_storage(struct vb2_queue *q) +{ + kfree(q->bufs); + q->bufs = NULL; + bitmap_free(q->bufs_bitmap); + q->bufs_bitmap = NULL; +} + int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, unsigned int flags, unsigned int *count) { @@ -879,10 +922,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * in the queue_setup op. */ mutex_lock(&q->mmap_lock); - if (!q->bufs) - q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); - if (!q->bufs) - ret = -ENOMEM; + ret = vb2_core_allocated_buffers_storage(q); q->memory = memory; mutex_unlock(&q->mmap_lock); if (ret) @@ -954,7 +994,6 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, } mutex_lock(&q->mmap_lock); - q->num_buffers = allocated_buffers; if (ret < 0) { /* @@ -982,6 +1021,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, mutex_lock(&q->mmap_lock); q->memory = VB2_MEMORY_UNKNOWN; mutex_unlock(&q->mmap_lock); + vb2_core_free_buffers_storage(q); return ret; } EXPORT_SYMBOL_GPL(vb2_core_reqbufs); @@ -1015,11 +1055,8 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * value in the queue_setup op. */ mutex_lock(&q->mmap_lock); + ret = vb2_core_allocated_buffers_storage(q); q->memory = memory; - if (!q->bufs) - q->bufs = kcalloc(q->max_num_buffers, sizeof(*q->bufs), GFP_KERNEL); - if (!q->bufs) - ret = -ENOMEM; mutex_unlock(&q->mmap_lock); if (ret) return ret; @@ -1082,7 +1119,6 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, } mutex_lock(&q->mmap_lock); - q->num_buffers += allocated_buffers; if (ret < 0) { /* @@ -2583,8 +2619,7 @@ void vb2_core_queue_release(struct vb2_queue *q) __vb2_queue_cancel(q); mutex_lock(&q->mmap_lock); __vb2_queue_free(q, vb2_get_num_buffers(q)); - kfree(q->bufs); - q->bufs = NULL; + vb2_core_free_buffers_storage(q); q->is_busy = 0; mutex_unlock(&q->mmap_lock); } diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index ee0cbd8705ec..7aebeaf671d8 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -346,8 +346,8 @@ struct vb2_buffer { * describes the requested number of planes and sizes\[\] * contains the requested plane sizes. In this case * \*num_buffers are being allocated additionally to - * q->num_buffers. If either \*num_planes or the requested - * sizes are invalid callback must return %-EINVAL. + * the buffers already allocated. If either \*num_planes + * or the requested sizes are invalid callback must return %-EINVAL. * @wait_prepare: release any locks taken while calling vb2 functions; * it is called before an ioctl needs to wait for a new * buffer to arrive; required to avoid a deadlock in @@ -571,8 +571,9 @@ struct vb2_buf_ops { * @mmap_lock: private mutex used when buffers are allocated/freed/mmapped * @memory: current memory type used * @dma_dir: DMA mapping direction. - * @bufs: videobuf2 buffer structures - * @num_buffers: number of allocated/used buffers + * @bufs: videobuf2 buffer structures. If it is non-NULL then + * bufs_bitmap is also non-NULL. + * @bufs_bitmap: bitmap tracking whether each bufs[] entry is used * @max_num_buffers: upper limit of number of allocated/used buffers. * If set to 0 v4l2 core will change it VB2_MAX_FRAME * for backward compatibility. @@ -640,7 +641,7 @@ struct vb2_queue { unsigned int memory; enum dma_data_direction dma_dir; struct vb2_buffer **bufs; - unsigned int num_buffers; + unsigned long *bufs_bitmap; unsigned int max_num_buffers; struct list_head queued_list; @@ -1170,7 +1171,10 @@ static inline bool vb2_fileio_is_active(struct vb2_queue *q) */ static inline unsigned int vb2_get_num_buffers(struct vb2_queue *q) { - return q->num_buffers; + if (q->bufs_bitmap) + return bitmap_weight(q->bufs_bitmap, q->max_num_buffers); + + return 0; } /** @@ -1279,7 +1283,7 @@ static inline struct vb2_buffer *vb2_get_buffer(struct vb2_queue *q, if (index >= q->max_num_buffers) return NULL; - if (index < q->num_buffers) + if (test_bit(index, q->bufs_bitmap)) return q->bufs[index]; return NULL; } From patchwork Wed Feb 21 15:54:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204276 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1125608dyc; Wed, 21 Feb 2024 07:57:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVj0PW3rfwvWZoQoRjFY3VP37lzkPYNxdteFpwnctT1G0KXkHLgBMvnnupcIrfymHCklpEIQAY4Fb76vszFqdyHU2bCQg== X-Google-Smtp-Source: AGHT+IEpKTESv012pKy9SdIEhxJdCh0ytZCeFVPeR1flw0bO+1L5PR8hXYRkGbQTMtDCxQCfsvOy X-Received: by 2002:a05:6a21:3943:b0:19e:aa08:1a0 with SMTP id ac3-20020a056a21394300b0019eaa0801a0mr29207754pzc.8.1708531072047; Wed, 21 Feb 2024 07:57:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531072; cv=pass; d=google.com; s=arc-20160816; b=DnGdtU5r+6OIOVY8WhhbLNHwF8EJEl7Vz+DZPP2KrS1FuIakLADs6C9lj2foW2Pxca AZFNoUbcV1eo6JCd8qK0kg5gzLB3iHYg39vAw3EpcEMHPAqwQOCeiKLrsPbo69JdLd33 kD1N2K0zDqB3Y4Phe/9NuX3R87igACiN3VKgVkdQeTUlf34ZXnU3nOdC2qVMuVYAS3p9 MT/rvy6NX6fw6M8RLhAEzz8APn03q9QSQuYWAny/vKARdBjw1HywNSHDPWwyjzohi7+x XS7cpaZpRnmiwBVjGjiSrUJmG2kmB1+qxWTVtbfZUEH1KBcBmnWYG8ZEHK/ej5ejL8QT rFFw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=DMGGUxE78c2APgUUu3ROI/Q4PVVCBFYyQzzFZ3BbGmM=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=MGz35xqx8mOHK0015cUo8gCIyDJsZ84bS3WFqEckFFQh+laisZhDd/dNp4NHD+Dxfg hDczFHaZy8J4u7vrW8yk5aGqQyZPo0hAtes8mt+Cj4RVwSpzqNqiWgcetFqeGf4KjR4n u/OStRV3mueyMgxMwhrBDdmHvkJk7XKGgKscBlpQc6jKRRwvuvtkwfiHp3gs3FHwdjoF iLbsbpAEJC+hxm8MYZvamH9n86OHw3oh8r36HS+vwSq+NhdRNulzGiLyWCEjVVanuZKE WsVQBHVkbDW0HnDRI5ZATTHiW2Lb3cxx/RVxLd2hTiz66n8qF8kR+3IU/Pm5hg/r1qsk hpGA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=BQScTQDZ; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75045-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id a22-20020a637056000000b005dc4328dc23si3864525pgn.780.2024.02.21.07.57.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:57:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=BQScTQDZ; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75045-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75045-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D54FD28457B for ; Wed, 21 Feb 2024 15:57:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF28883CA4; Wed, 21 Feb 2024 15:54:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="BQScTQDZ" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 976E4823B4; Wed, 21 Feb 2024 15:54:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530890; cv=none; b=t96kFb2vVk4bGOOuF4/b5oSsYXRJXl+j4hNJQy/WSnlog2P5OqX1OaTkDf+dIrVEoYQwGRRKtvfzKGPM4DeqGTVvF6iU4ct0zqbJ0csjjAEuohI82o6QHFbxy7b1PhSOA26z9oKJCjnTt5ekQEQnKntUfUAcqIb95aE8Xg+GcP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530890; c=relaxed/simple; bh=xBHj61ms77yh6TofIx3mWpzyvQ5wa//86PofqFg3BeI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aIkmrjn3pSJEmaZxIcGfv8eXlBs66UBkc4YPKPrlKbvZaPhjXmflS/U5caCeIX+xdelGTu0pRRr9mev5bLMtS9YYogxM5BC8UuYVQa/QKoHWp883xqOCqdDSfMGunECCfIe6vjFGylD1XIub4r1eizxs1KyGSuQukXKvwU8f6NU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=BQScTQDZ; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530886; bh=xBHj61ms77yh6TofIx3mWpzyvQ5wa//86PofqFg3BeI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BQScTQDZ3L3V+bEWzWtZxsANas5CqHaWXEYXXFQEcuu1xXPZYYAobnEl2WGr00M8J rTy6HQarjq6tQ97wC+EXBpI3j9JGB4CtRZ2SDVnoQqkio9z2e+TYC53G2T2yv7DYqV MKUFgT0JckQs7Pb2SFH869SuUqoGb3C2NIP7hxH3h/xBHUo+wRzqRZjwHlYa6Oc8Lw 64aNtijugBpgDZhdZ1o5X8GJ2jogmNtQHCVHE7TJu6w5sSog3TXpkGzezYeHvHKWrD oz1Xp1X8cHci56uU9YMTIVuk94aGBrznSD2l28BtiVmXbniwcpkqzWu2bhF0BoKsKH M8d4ENj5Wu07w== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 3438937820CD; Wed, 21 Feb 2024 15:54:46 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 6/9] media: core: Free range of buffers Date: Wed, 21 Feb 2024 16:54:32 +0100 Message-Id: <20240221155435.100093-7-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791524677774617927 X-GMAIL-MSGID: 1791524677774617927 Improve __vb2_queue_free() and __vb2_free_mem() to free range of buffers and not only the last few buffers. Introduce starting index to be flexible on range and change the loops according to this parameter. Signed-off-by: Benjamin Gaignard --- .../media/common/videobuf2/videobuf2-core.c | 56 +++++++++---------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index ec81426d4d79..009cea95d662 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -540,17 +540,16 @@ static int __vb2_queue_alloc(struct vb2_queue *q, enum vb2_memory memory, } /* - * __vb2_free_mem() - release all video buffer memory for a given queue + * __vb2_free_mem() - release video buffer memory for a given range of + * buffers in a given queue */ -static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) +static void __vb2_free_mem(struct vb2_queue *q, unsigned int start, unsigned int count) { - unsigned int buffer; + unsigned int i; struct vb2_buffer *vb; - unsigned int q_num_buffers = vb2_get_num_buffers(q); - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; - ++buffer) { - vb = vb2_get_buffer(q, buffer); + for (i = start; i < start + count; i++) { + vb = vb2_get_buffer(q, i); if (!vb) continue; @@ -565,35 +564,33 @@ static void __vb2_free_mem(struct vb2_queue *q, unsigned int buffers) } /* - * __vb2_queue_free() - free buffers at the end of the queue - video memory and + * __vb2_queue_free() - free @count buffers from @start index of the queue - video memory and * related information, if no buffers are left return the queue to an * uninitialized state. Might be called even if the queue has already been freed. */ -static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) +static void __vb2_queue_free(struct vb2_queue *q, unsigned int start, unsigned int count) { - unsigned int buffer; - unsigned int q_num_buffers = vb2_get_num_buffers(q); + unsigned int i; lockdep_assert_held(&q->mmap_lock); /* 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 = vb2_get_buffer(q, buffer); + for (i = start; i < start + count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); if (vb && vb->planes[0].mem_priv) call_void_vb_qop(vb, buf_cleanup, vb); } /* Release video buffer memory */ - __vb2_free_mem(q, buffers); + __vb2_free_mem(q, start, count); #ifdef CONFIG_VIDEO_ADV_DEBUG /* * Check that all the calls were balanced during the life-time of this * queue. If not then dump the counters to the kernel log. */ - if (q_num_buffers) { + if (vb2_get_num_buffers(q)) { bool unbalanced = q->cnt_start_streaming != q->cnt_stop_streaming || q->cnt_prepare_streaming != q->cnt_unprepare_streaming || q->cnt_wait_prepare != q->cnt_wait_finish; @@ -619,8 +616,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) q->cnt_stop_streaming = 0; q->cnt_unprepare_streaming = 0; } - for (buffer = 0; buffer < vb2_get_num_buffers(q); buffer++) { - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + for (i = start; i < start + count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); bool unbalanced; if (!vb) @@ -637,7 +634,7 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) if (unbalanced) { pr_info("unbalanced counters for queue %p, buffer %d:\n", - q, buffer); + q, i); if (vb->cnt_buf_init != vb->cnt_buf_cleanup) pr_info(" buf_init: %u buf_cleanup: %u\n", vb->cnt_buf_init, vb->cnt_buf_cleanup); @@ -671,9 +668,8 @@ static void __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) #endif /* Free vb2 buffers */ - for (buffer = q_num_buffers - buffers; buffer < q_num_buffers; - ++buffer) { - struct vb2_buffer *vb = vb2_get_buffer(q, buffer); + for (i = start; i < start + count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); if (!vb) continue; @@ -713,7 +709,7 @@ EXPORT_SYMBOL(vb2_buffer_in_use); static bool __buffers_in_use(struct vb2_queue *q) { unsigned int buffer; - for (buffer = 0; buffer < vb2_get_num_buffers(q); ++buffer) { + for (buffer = 0; buffer < q->max_num_buffers; ++buffer) { struct vb2_buffer *vb = vb2_get_buffer(q, buffer); if (!vb) @@ -899,7 +895,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * queued without ever calling STREAMON. */ __vb2_queue_cancel(q); - __vb2_queue_free(q, q_num_bufs); + __vb2_queue_free(q, 0, q->max_num_buffers); mutex_unlock(&q->mmap_lock); q->is_busy = 0; @@ -1001,7 +997,7 @@ int vb2_core_reqbufs(struct vb2_queue *q, enum vb2_memory memory, * from already queued buffers and it will reset q->memory to * VB2_MEMORY_UNKNOWN. */ - __vb2_queue_free(q, allocated_buffers); + __vb2_queue_free(q, first_index, allocated_buffers); mutex_unlock(&q->mmap_lock); return ret; } @@ -1126,7 +1122,7 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, * from already queued buffers and it will reset q->memory to * VB2_MEMORY_UNKNOWN. */ - __vb2_queue_free(q, allocated_buffers); + __vb2_queue_free(q, *first_index, allocated_buffers); mutex_unlock(&q->mmap_lock); return -ENOMEM; } @@ -1741,7 +1737,7 @@ static int vb2_start_streaming(struct vb2_queue *q) * Forcefully reclaim buffers if the driver did not * correctly return them to vb2. */ - for (i = 0; i < vb2_get_num_buffers(q); ++i) { + for (i = 0; i < q->max_num_buffers; ++i) { vb = vb2_get_buffer(q, i); if (!vb) @@ -2147,7 +2143,7 @@ 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 < vb2_get_num_buffers(q); i++) { + for (i = 0; i < q->max_num_buffers; i++) { struct vb2_buffer *vb = vb2_get_buffer(q, i); if (!vb) @@ -2191,7 +2187,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) * call to __fill_user_buffer() after buf_finish(). That order can't * be changed, so we can't move the buf_finish() to __vb2_dqbuf(). */ - for (i = 0; i < vb2_get_num_buffers(q); i++) { + for (i = 0; i < q->max_num_buffers; i++) { struct vb2_buffer *vb; struct media_request *req; @@ -2618,7 +2614,7 @@ void vb2_core_queue_release(struct vb2_queue *q) __vb2_cleanup_fileio(q); __vb2_queue_cancel(q); mutex_lock(&q->mmap_lock); - __vb2_queue_free(q, vb2_get_num_buffers(q)); + __vb2_queue_free(q, 0, q->max_num_buffers); vb2_core_free_buffers_storage(q); q->is_busy = 0; mutex_unlock(&q->mmap_lock); From patchwork Wed Feb 21 15:54:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204278 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1125888dyc; Wed, 21 Feb 2024 07:58:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW1O5h4gBDI8ERupFN+nKdT5XPtJAuFOC4cQg7aZwqU2FQ17Crs/pcgeSXyK2d8lasS6XmsJPzzuiSW1V1EKOcGErwQOw== X-Google-Smtp-Source: AGHT+IG0sSyZRyiE2RSuEDcsuT6taeWuekYQqidtY/yLUySiigsGq8wanMzByEfqRljgub/IwIki X-Received: by 2002:a05:6808:23d5:b0:3c1:55d4:a419 with SMTP id bq21-20020a05680823d500b003c155d4a419mr10896634oib.2.1708531100304; Wed, 21 Feb 2024 07:58:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531100; cv=pass; d=google.com; s=arc-20160816; b=q238O6jcjuMNzrFPpuVYyMQ/360oB+J7nAdTNs3CVAyFg34mT9JMbguxLRcA9UFPLj nnbn6htOY4qLggu/80x+DZCUGmxU0DkIoEdSjIiMWLvRasn6UGSxWN/jUQ4vy87c3TVd XtV+uzham5thSlhgwH041d8jJQYoozZh3k3amIkYAa7Z/6Se2D024q1bqMbTWh795t13 Bbgu5NTfH08DWWvL6ndQPs5fyWhUqSPurbGrCmUou1Y/4DC6JrS6rOxU+xIC6B8JVYyz 5WIqH8z4iHIuojVC5kKZxiqTLR2uXQGSoxyBYvqYMGWGWd9b6IJJv1M7jsGydOIt+Pu1 /TdA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=RYX3iAIC+W0wTv7blWKoQrNldPCnU66fCeSvp7JWIJ0=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=ykUseCUXjM6gqZtnOLv36+C1YPo5PwfSydRRWH9CpaDl2vszh77gYqE3Oxb4pczHKn +2hyfDgihQSWeRaQO5PTP53g6ht3XvZWYiFR3MAXGKmJJJzFUNTjZjbj/2OPeGU8ZNjI UNgNR8IHhvfUModA5MQlwlZZ0MmxTRCdlRE0iOu1Uu77WCFHz4iiIkcxKyaRtcrxCW65 S64nktGQRbwxQlKYo+JClYcjg3sHudJJUCb1BdFAjYlNvwpnQGRyaBEfLpOI8mzFHWLh Wcb300m5aJcLrMZewhLrjnlhv73e4HQHCgTNEFXr94SRP9fXZ9/vwH4HZ7GwZzmmoLB2 7ldw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Uckoo+8g; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75046-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75046-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id kd28-20020a056214401c00b0068cbae9b4f7si10999428qvb.201.2024.02.21.07.58.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:58:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75046-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Uckoo+8g; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75046-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75046-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 07DF61C22E42 for ; Wed, 21 Feb 2024 15:58:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45FC883CCF; Wed, 21 Feb 2024 15:54:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Uckoo+8g" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46DC3823CD; Wed, 21 Feb 2024 15:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530891; cv=none; b=WmNlnmjQFI/tNHjzAR5a3SWCdrIfJuYlvH7X9o+rrj5QQPjD7SbXH2caXOOcp5jprdifbAjNuERxDHFmeWfbAfX8LSiVbg6SPHvNhp1iBYoHRi3pNx+FWwIGNIft5H7N9L3sHq4ndbdn9PxzrCqNwZtHi61oFj1W5BeL8VNC+Pc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530891; c=relaxed/simple; bh=XB/5UpwLF2szdhyGEIcuE1KozQMJMoIsHBAeazbuPOE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OvqqFkxId6OpAWYi9MPGMlk0sUwQNQTtkMTeViCx/x5pmFPHtXowKoJ8Tp4N6bMMIlnpgLdxv1w9fWEKsgm/j7SVbeCMFddFKL7rUNWX1IUydMqdwfRB4wVThcDPSLxpwpJYzP39x9qy2tdbCBL/gTC3W02t1hKYYIp8J3Ku9w4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=Uckoo+8g; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530887; bh=XB/5UpwLF2szdhyGEIcuE1KozQMJMoIsHBAeazbuPOE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Uckoo+8gdSWv4RMEtd+dVEf2IdDs/9lr3IFEvGkwWUYW29MTD1bQldm3hGsW85+tW Wy5j7P67EWocj26Ny1XfzpVqnmVQm6LirM/vip7/PLwjySr9HbBGjOZ1UIeBPY9HWd hu0LnBtCl3/edLWAnyXUIyYWhiPCPgNce3NNZ/QIt0Ig+dLcqDD4rI6tqdyHKn4G+Y XMMMKxAr2tbQVgtmfTsaw+swGYrWChVhsVAJ4lwiigSRll99ZO5lU/yn386jSxVW/l C6tRXfj7tEzHBVhfjJPKRG6RhLcVGuIwiytnYs7wPKqXDTo/LFqeE3xKptwm0p0hGl NeiwXLe+FoXeA== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 051AB37820D0; Wed, 21 Feb 2024 15:54:46 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 7/9] media: v4l2: Add REMOVE_BUFS ioctl Date: Wed, 21 Feb 2024 16:54:33 +0100 Message-Id: <20240221155435.100093-8-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791524707087056657 X-GMAIL-MSGID: 1791524707087056657 VIDIOC_REMOVE_BUFS ioctl allows to remove buffers from a queue. The number of buffers to remove in given by count field of struct v4l2_remove_buffers and the range start at the index specified in the same structure. Signed-off-by: Benjamin Gaignard --- version 20: - Rename DELETE_BUFS into REMOVE_BUFS - Change documention, structure and variables name to use 'remove' .../userspace-api/media/v4l/user-func.rst | 1 + .../media/v4l/vidioc-remove-bufs.rst | 82 +++++++++++++++++++ .../media/v4l/vidioc-reqbufs.rst | 1 + .../media/common/videobuf2/videobuf2-core.c | 38 +++++++++ .../media/common/videobuf2/videobuf2-v4l2.c | 14 +++- drivers/media/v4l2-core/v4l2-dev.c | 3 + drivers/media/v4l2-core/v4l2-ioctl.c | 32 ++++++++ include/media/v4l2-ioctl.h | 4 + include/media/videobuf2-core.h | 10 +++ include/media/videobuf2-v4l2.h | 2 + include/uapi/linux/videodev2.h | 17 ++++ 11 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 Documentation/userspace-api/media/v4l/vidioc-remove-bufs.rst diff --git a/Documentation/userspace-api/media/v4l/user-func.rst b/Documentation/userspace-api/media/v4l/user-func.rst index 15ff0bf7bbe6..6f661138801c 100644 --- a/Documentation/userspace-api/media/v4l/user-func.rst +++ b/Documentation/userspace-api/media/v4l/user-func.rst @@ -62,6 +62,7 @@ Function Reference vidioc-query-dv-timings vidioc-querystd vidioc-reqbufs + vidioc-remove-bufs vidioc-s-hw-freq-seek vidioc-streamon vidioc-subdev-enum-frame-interval diff --git a/Documentation/userspace-api/media/v4l/vidioc-remove-bufs.rst b/Documentation/userspace-api/media/v4l/vidioc-remove-bufs.rst new file mode 100644 index 000000000000..0fbc0dfbbaa1 --- /dev/null +++ b/Documentation/userspace-api/media/v4l/vidioc-remove-bufs.rst @@ -0,0 +1,82 @@ +.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later +.. c:namespace:: V4L + +.. _VIDIOC_REMOVE_BUFS: + +************************ +ioctl VIDIOC_REMOVE_BUFS +************************ + +Name +==== + +VIDIOC_REMOVE_BUFS - Removes buffers from a queue + +Synopsis +======== + +.. c:macro:: VIDIOC_REMOVE_BUFS + +``int ioctl(int fd, VIDIOC_REMOVE_BUFS, struct v4l2_remove_buffers *argp)`` + +Arguments +========= + +``fd`` + File descriptor returned by :c:func:`open()`. + +``argp`` + Pointer to struct :c:type:`v4l2_remove_buffers`. + +Description +=========== + +Applications can optionally call the :ref:`VIDIOC_REMOVE_BUFS` ioctl to +remove buffers from a queue. +:ref:`VIDIOC_CREATE_BUFS` ioctl support is mandatory to enable :ref:`VIDIOC_REMOVE_BUFS`. +This ioctl is available if the ``V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS`` capability +is set on the queue when :c:func:`VIDIOC_REQBUFS` or :c:func:`VIDIOC_CREATE_BUFS` +are invoked. + +.. c:type:: v4l2_remove_buffers + +.. tabularcolumns:: |p{4.4cm}|p{4.4cm}|p{8.5cm}| + +.. flat-table:: struct v4l2_remove_buffers + :header-rows: 0 + :stub-columns: 0 + :widths: 1 1 2 + + * - __u32 + - ``index`` + - The starting buffer index to remove. + * - __u32 + - ``count`` + - The number of buffers to be removed with indices 'index' until 'index + count - 1'. + All buffers in this range must be valid and in DEQUEUED state. + If count is set to 0 :ref:`VIDIOC_REMOVE_BUFS` will do nothing and return 0. + * - __u32 + - ``type`` + - Type of the stream or buffers, this is the same as the struct + :c:type:`v4l2_format` ``type`` field. See + :c:type:`v4l2_buf_type` for valid values. + * - __u32 + - ``reserved``\ [13] + - A place holder for future extensions. Drivers and applications + must set the array to zero. + +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. + One or more of the buffers in the range ``index`` to ``index + count - 1`` are not + in DEQUEUED state. + +EINVAL + One or more of the buffers in the range ``index`` to ``index + count - 1`` do not + exist in the queue. diff --git a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst index 0b3a41a45d05..bbc22dd76032 100644 --- a/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +++ b/Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst @@ -121,6 +121,7 @@ aborting or finishing any DMA in progress, an implicit .. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF: .. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS: .. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS: +.. _V4L2-BUF-CAP-SUPPORTS-REMOVE-BUFS: .. raw:: latex diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 009cea95d662..0b2b48e1b2df 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1691,6 +1691,44 @@ int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb) } EXPORT_SYMBOL_GPL(vb2_core_prepare_buf); +int vb2_core_remove_bufs(struct vb2_queue *q, unsigned int start, unsigned int count) +{ + unsigned int i, ret = 0; + unsigned int q_num_bufs = vb2_get_num_buffers(q); + + if (count == 0) + return 0; + + if (count > q_num_bufs) + return -EINVAL; + + if (start > q->max_num_buffers - count) + return -EINVAL; + + mutex_lock(&q->mmap_lock); + + /* Check that all buffers in the range exist */ + for (i = start; i < start + count; i++) { + struct vb2_buffer *vb = vb2_get_buffer(q, i); + + if (!vb) { + ret = -EINVAL; + goto unlock; + } + if (vb->state != VB2_BUF_STATE_DEQUEUED) { + ret = -EBUSY; + goto unlock; + } + } + __vb2_queue_free(q, start, count); + dprintk(q, 2, "%u buffers removed\n", count); + +unlock: + mutex_unlock(&q->mmap_lock); + return ret; +} +EXPORT_SYMBOL_GPL(vb2_core_remove_bufs); + /* * 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 03e8080a68a8..9a5dcbb8fef3 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -685,7 +685,7 @@ static void vb2_set_flags_and_caps(struct vb2_queue *q, u32 memory, *flags &= V4L2_MEMORY_FLAG_NON_COHERENT; } - *caps = V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS; + *caps |= V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS; if (q->io_modes & VB2_MMAP) *caps |= V4L2_BUF_CAP_SUPPORTS_MMAP; if (q->io_modes & VB2_USERPTR) @@ -1001,6 +1001,18 @@ EXPORT_SYMBOL_GPL(vb2_poll); /* vb2 ioctl helpers */ +int vb2_ioctl_remove_bufs(struct file *file, void *priv, + struct v4l2_remove_buffers *d) +{ + struct video_device *vdev = video_devdata(file); + + if (vb2_queue_is_busy(vdev->queue, file)) + return -EBUSY; + + return vb2_core_remove_bufs(vdev->queue, d->index, d->count); +} +EXPORT_SYMBOL_GPL(vb2_ioctl_remove_bufs); + int vb2_ioctl_reqbufs(struct file *file, void *priv, struct v4l2_requestbuffers *p) { diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index d13954bd31fd..e39e9742fdb5 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -722,6 +722,9 @@ 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); + /* VIDIOC_CREATE_BUFS support is mandatory to enable VIDIOC_REMOVE_BUFS */ + if (ops->vidioc_create_bufs) + SET_VALID_IOCTL(ops, VIDIOC_REMOVE_BUFS, vidioc_remove_bufs); } 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 33076af4dfdb..a5a4134218e6 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -489,6 +489,14 @@ static void v4l_print_create_buffers(const void *arg, bool write_only) v4l_print_format(&p->format, write_only); } +static void v4l_print_remove_buffers(const void *arg, bool write_only) +{ + const struct v4l2_remove_buffers *p = arg; + + pr_cont("type=%s, index=%u, count=%u\n", + prt_names(p->type, v4l2_type_names), p->index, p->count); +} + static void v4l_print_streamparm(const void *arg, bool write_only) { const struct v4l2_streamparm *p = arg; @@ -2092,6 +2100,7 @@ static int v4l_overlay(const struct v4l2_ioctl_ops *ops, static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, struct file *file, void *fh, void *arg) { + struct video_device *vfd = video_devdata(file); struct v4l2_requestbuffers *p = arg; int ret = check_fmt(file, p->type); @@ -2100,6 +2109,9 @@ static int v4l_reqbufs(const struct v4l2_ioctl_ops *ops, memset_after(p, 0, flags); + if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS)) + p->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS; + return ops->vidioc_reqbufs(file, fh, p); } @@ -2133,6 +2145,7 @@ static int v4l_dqbuf(const struct v4l2_ioctl_ops *ops, static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, struct file *file, void *fh, void *arg) { + struct video_device *vfd = video_devdata(file); struct v4l2_create_buffers *create = arg; int ret = check_fmt(file, create->format.type); @@ -2143,6 +2156,9 @@ static int v4l_create_bufs(const struct v4l2_ioctl_ops *ops, v4l_sanitize_format(&create->format); + if (is_valid_ioctl(vfd, VIDIOC_REMOVE_BUFS)) + create->capabilities = V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS; + ret = ops->vidioc_create_bufs(file, fh, create); if (create->format.type == V4L2_BUF_TYPE_VIDEO_CAPTURE || @@ -2161,6 +2177,21 @@ static int v4l_prepare_buf(const struct v4l2_ioctl_ops *ops, return ret ? ret : ops->vidioc_prepare_buf(file, fh, b); } +static int v4l_remove_bufs(const struct v4l2_ioctl_ops *ops, + struct file *file, void *fh, void *arg) +{ + struct v4l2_remove_buffers *remove = arg; + int ret = check_fmt(file, remove->type); + + if (ret) + return ret; + + if (ops->vidioc_remove_bufs) + return ops->vidioc_remove_bufs(file, fh, remove); + + return -ENOTTY; +} + static int v4l_g_parm(const struct v4l2_ioctl_ops *ops, struct file *file, void *fh, void *arg) { @@ -2910,6 +2941,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_REMOVE_BUFS, v4l_remove_bufs, v4l_print_remove_buffers, INFO_FL_PRIO | INFO_FL_QUEUE | INFO_FL_CLEAR(v4l2_remove_buffers, type)), }; #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index edb733f21604..bdbb7e542321 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_remove_bufs: pointer to the function that implements + * :ref:`VIDIOC_REMOVE_BUFS ` 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_remove_bufs)(struct file *file, void *fh, + struct v4l2_remove_buffers *d); 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 7aebeaf671d8..a4e59280747e 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -867,6 +867,16 @@ int vb2_core_create_bufs(struct vb2_queue *q, enum vb2_memory memory, */ int vb2_core_prepare_buf(struct vb2_queue *q, struct vb2_buffer *vb, void *pb); +/** + * vb2_core_remove_bufs() - + * @q: pointer to &struct vb2_queue with videobuf2 queue. + * @start: first index of the range of buffers to remove. + * @count: number of buffers to remove. + * + * Return: returns zero on success; an error code otherwise. + */ +int vb2_core_remove_bufs(struct vb2_queue *q, unsigned int start, unsigned int count); + /** * vb2_core_qbuf() - Queue a buffer from userspace * diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 5a845887850b..77ce8238ab30 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -334,6 +334,8 @@ int vb2_ioctl_streamon(struct file *file, void *priv, enum v4l2_buf_type i); int vb2_ioctl_streamoff(struct file *file, void *priv, enum v4l2_buf_type i); int vb2_ioctl_expbuf(struct file *file, void *priv, struct v4l2_exportbuffer *p); +int vb2_ioctl_remove_bufs(struct file *file, void *priv, + struct v4l2_remove_buffers *p); /* struct v4l2_file_operations helpers */ diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index a8015e5e7fa4..2663213b76a4 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -1036,6 +1036,7 @@ struct v4l2_requestbuffers { #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5) #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6) #define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7) +#define V4L2_BUF_CAP_SUPPORTS_REMOVE_BUFS (1 << 8) /** * struct v4l2_plane - plane info for multi-planar buffers @@ -2624,6 +2625,20 @@ struct v4l2_create_buffers { __u32 reserved[5]; }; +/** + * struct v4l2_remove_buffers - VIDIOC_REMOVE_BUFS argument + * @index: the first buffer to be removed + * @count: number of buffers to removed + * @type: enum v4l2_buf_type + * @reserved: future extensions + */ +struct v4l2_remove_buffers { + __u32 index; + __u32 count; + __u32 type; + __u32 reserved[13]; +}; + /* * I O C T L C O D E S F O R V I D E O D E V I C E S * @@ -2723,6 +2738,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_REMOVE_BUFS _IOWR('V', 104, struct v4l2_remove_buffers) + /* Reminder: when adding new ioctls please add support for them to drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */ From patchwork Wed Feb 21 15:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1125708dyc; Wed, 21 Feb 2024 07:58:02 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUHwfnRaShAXWTXhfvK/rWVZxn02eZvL3WXHK/TqeCOchR0M52Le8YGYSn1pPeDuFesuMAB7nJli+iI6d4o40n/tktSrg== X-Google-Smtp-Source: AGHT+IFevLxC5P/9kvoygnlaxNJLRR4t0yg4RCQUZ7axsY09pHrjb3dw3WYMlL2osueM8Jcl+IUO X-Received: by 2002:ac8:5f53:0:b0:42a:b410:fa47 with SMTP id y19-20020ac85f53000000b0042ab410fa47mr22661842qta.17.1708531081969; Wed, 21 Feb 2024 07:58:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531081; cv=pass; d=google.com; s=arc-20160816; b=ttDYSh9GVgR+YHDc7WTVnckQRl+OiIR4Ki9yM8x2jHzio2CFcjDh0BP3eMrib+lO/g C/gxzOJdWHWePw5TFMBk+Z18bZJDAbs66Qu3G1gOES+NmAkx7F/FDPTJ2uPW7AruWfz1 C5HgJvlxtYjri8ya3u69zCpRC6vLLLrqEka2HbsZ436I6YbxTUKzqXFArvIoldyUlZMu Y+Y/nUWr7V+gYmWmguel6U9i9HxwOYLakIgdgi+OB51G0NYyCQesZJfSYdNrUQ0SpwXl 9EZQETB+oo3YYq9qZf8fMs7LEAf5qCHzA/skeXYeXggVg6k3d9CvyBlcrFKKt/Cax3rQ Binw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=gEEAVEi3C+Peb2G93hhIM5JvxNnYvZs0wOTi5m0mZ9I=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=QtDT1Afp+xLvElgf3LV1QHFZXRNLvJNTrxpT4eVrfvXU3D46U8gPhGKwVcUE4Xu5Qb kNisdb86Sxnp8gzLkiRUFASsBMgUakiz6JjPp7ClP9C5Fowe/2CbtvMopCJOOveLF31W FpmjL+nyeAIEKVOKM39jIQVl3VG3XxE8BlN09wyCpXQEtwiXkOp5puhPRFTdccugUL86 m3VHym7VfA2k2jKNGiEqscNoYhqrrs0oTJZ2zwpRjbZ33iD21xcITx2KS2qMRaUAjm6e rR4x351ElsFZZYCwfjFExJEDg3XxQCjdtthFjKGwsp4ZeFV/CRYzKCeHRmpTOdAb650a eDlg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=2e4mvyoO; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75047-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75047-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id y15-20020ac85f4f000000b0042c74f61419si11914275qta.634.2024.02.21.07.58.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 07:58:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75047-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=2e4mvyoO; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75047-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75047-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id B192A1C22DC0 for ; Wed, 21 Feb 2024 15:58:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E45483CB4; Wed, 21 Feb 2024 15:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="2e4mvyoO" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ED2C382870; Wed, 21 Feb 2024 15:54:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530891; cv=none; b=CpCCmnrpF9Eytqm4+6u4PEV6S50XoaTIexFJnwTglRfrzu8NWTptZCGFeYj5SJX5wThczJ5M6Ob6aOZ3ToCurJ6UGrsnmoSvbYP8Evl0yHFufzhOHGG55NKfL7zi3s9ttlokdrC+XXulzTp56cu3w2dUiv9TXfqPz+5WHyDL5kk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530891; c=relaxed/simple; bh=xkha4D8zVSPTP3prmB5KEcjW0rkv3j+VZiNxrnoa80M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cvm04aHZWRPjV/0RfG+Rec5d7pIwhTUTBengVfjE8Ffgflb0/X51N/Uc2UP6CUjEVuCw9s/AXTiCgujU6Of02vPY7RPeE1Rn5wxUiwcjjVwSI4X3C6RD+ry+fYeqcnqYjFfttTEMIgwNfJNbtqEamrn6tkNIfyd3OunLHHv02lI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=2e4mvyoO; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530888; bh=xkha4D8zVSPTP3prmB5KEcjW0rkv3j+VZiNxrnoa80M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2e4mvyoOeIXC48yaN3hIVxFb884yiG49Qk9Gl+RPrOQ5EA8QawrdcgDXnS2vNWioy 8LlxDn/GCJLV9/vF/zQ0jlyYfP78zBGSfxUAYCRPeyovNnfEpsYo3odix458VBWaeq jqiREMJ1gkYb4z0qeY/wk9mJEeryy9qFiNESySWG2zbO5MEpD5Hu5IlGsoYRwzPo90 MVq0zvglbrn5fPmTHGgkRBfNwP9vQeHcC6Sg53wJZaKi7WekI8uRWNGrjvRFwXTjrc ZHxEZ+KfFkDrAwVE+qLKGeyww+K5pPrkmWCIQckPp1j+TFSpRr9a4j1pGF5SYe3Y4K LSEPlWVSs7FpA== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id C78D937820D5; Wed, 21 Feb 2024 15:54:47 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 8/9] media: v4l2: Add mem2mem helpers for REMOVE_BUFS ioctl Date: Wed, 21 Feb 2024 16:54:34 +0100 Message-Id: <20240221155435.100093-9-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791524687993192636 X-GMAIL-MSGID: 1791524687993192636 Create v4l2-mem2mem helpers for VIDIOC_REMOVE_BUFS ioctl and make test drivers use it. Signed-off-by: Benjamin Gaignard --- drivers/media/test-drivers/vicodec/vicodec-core.c | 1 + drivers/media/test-drivers/vim2m.c | 1 + drivers/media/test-drivers/vimc/vimc-capture.c | 1 + drivers/media/test-drivers/visl/visl-video.c | 1 + drivers/media/test-drivers/vivid/vivid-core.c | 1 + drivers/media/v4l2-core/v4l2-mem2mem.c | 10 ++++++++++ include/media/v4l2-mem2mem.h | 2 ++ 7 files changed, 17 insertions(+) diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/media/test-drivers/vicodec/vicodec-core.c index e13f5452b927..3e011fe62ae1 100644 --- a/drivers/media/test-drivers/vicodec/vicodec-core.c +++ b/drivers/media/test-drivers/vicodec/vicodec-core.c @@ -1345,6 +1345,7 @@ static const struct v4l2_ioctl_ops vicodec_ioctl_ops = { .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_remove_bufs = v4l2_m2m_ioctl_remove_bufs, .vidioc_streamon = v4l2_m2m_ioctl_streamon, .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, diff --git a/drivers/media/test-drivers/vim2m.c b/drivers/media/test-drivers/vim2m.c index 3e3b424b4860..14aff4ad576b 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_remove_bufs = v4l2_m2m_ioctl_remove_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, .vidioc_streamon = v4l2_m2m_ioctl_streamon, diff --git a/drivers/media/test-drivers/vimc/vimc-capture.c b/drivers/media/test-drivers/vimc/vimc-capture.c index 97693561f1e4..ba7550b8ba7e 100644 --- a/drivers/media/test-drivers/vimc/vimc-capture.c +++ b/drivers/media/test-drivers/vimc/vimc-capture.c @@ -221,6 +221,7 @@ static const struct v4l2_ioctl_ops vimc_capture_ioctl_ops = { .vidioc_expbuf = vb2_ioctl_expbuf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, + .vidioc_remove_bufs = vb2_ioctl_remove_bufs, }; static void vimc_capture_return_all_buffers(struct vimc_capture_device *vcapture, diff --git a/drivers/media/test-drivers/visl/visl-video.c b/drivers/media/test-drivers/visl/visl-video.c index b9a4b44bd0ed..f8d970319764 100644 --- a/drivers/media/test-drivers/visl/visl-video.c +++ b/drivers/media/test-drivers/visl/visl-video.c @@ -539,6 +539,7 @@ const struct v4l2_ioctl_ops visl_ioctl_ops = { .vidioc_prepare_buf = v4l2_m2m_ioctl_prepare_buf, .vidioc_create_bufs = v4l2_m2m_ioctl_create_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, + .vidioc_remove_bufs = v4l2_m2m_ioctl_remove_bufs, .vidioc_streamon = v4l2_m2m_ioctl_streamon, .vidioc_streamoff = v4l2_m2m_ioctl_streamoff, diff --git a/drivers/media/test-drivers/vivid/vivid-core.c b/drivers/media/test-drivers/vivid/vivid-core.c index 11b8520d9f57..771392f67dda 100644 --- a/drivers/media/test-drivers/vivid/vivid-core.c +++ b/drivers/media/test-drivers/vivid/vivid-core.c @@ -769,6 +769,7 @@ static const struct v4l2_ioctl_ops vivid_ioctl_ops = { .vidioc_expbuf = vb2_ioctl_expbuf, .vidioc_streamon = vb2_ioctl_streamon, .vidioc_streamoff = vb2_ioctl_streamoff, + .vidioc_remove_bufs = vb2_ioctl_remove_bufs, .vidioc_enum_input = vivid_enum_input, .vidioc_g_input = vivid_g_input, diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 75517134a5e9..ba21c60f1ed3 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -1386,6 +1386,16 @@ int v4l2_m2m_ioctl_create_bufs(struct file *file, void *priv, } EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_create_bufs); +int v4l2_m2m_ioctl_remove_bufs(struct file *file, void *priv, + struct v4l2_remove_buffers *remove) +{ + struct v4l2_fh *fh = file->private_data; + + return vb2_core_remove_bufs(v4l2_m2m_get_vq(fh->m2m_ctx, remove->type), + remove->index, remove->count); +} +EXPORT_SYMBOL_GPL(v4l2_m2m_ioctl_remove_bufs); + 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 7f1af1f7f912..0af330cf91c3 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -867,6 +867,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_remove_bufs(struct file *file, void *priv, + struct v4l2_remove_buffers *d); int v4l2_m2m_ioctl_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf); int v4l2_m2m_ioctl_expbuf(struct file *file, void *fh, From patchwork Wed Feb 21 15:54:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 204293 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp1133842dyc; Wed, 21 Feb 2024 08:08:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXO0nFdgVhB2ReZs5m3Wcu5zaO+BqqHYhHOqbWS/2Z2GLHlenof79VwfWpb1s1B5C8fZGYy+gpl5gfRX5Cte7ZP3uebZg== X-Google-Smtp-Source: AGHT+IFvfxHIf10thCJZZ/bM2td3DqaA/77Ssn+YJgcw/r6aQNU7rgMjKIB0l9ZFlwFx93Whk6Iz X-Received: by 2002:a05:6358:3384:b0:176:d46c:e704 with SMTP id i4-20020a056358338400b00176d46ce704mr20318059rwd.16.1708531688793; Wed, 21 Feb 2024 08:08:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708531688; cv=pass; d=google.com; s=arc-20160816; b=hj7amKA/YSAevO/uAIheOL6gGsqqgJKCK5NHt7lc5y1G2gup7r5AX29TcFFq13rqIe +fnlUtfgtBdgSESTCMg5stNRwzxXrpTpc1yO01fEOEGuPCJMc4IoCgTn/Nt17Efir2s5 C5zlbXngSAVilkzf3rteF4BJICltDxKOyVEZYTgtjg2mq/pTTDOEpOuzDtK+YJKmNqqi A+HZ4gd6S6gWgHkffuA9H79K66lyequSB9THhCZWVlSa8wmWSBLoO/koHhlBcEBLT4UE zv6d55m3/fgSqV37nGgZABhLZirIUncjie8EqrbK8cxbJDRms6dubElcAAuZtcPH47T1 ksEA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=0vtbcTns+IjhrqfdyrkeTehwMP9XOn7heWlTx530B3c=; fh=zOBpKhMTeRbrgfYir35sIvSkMQrxOs+orb+lNlEOd4k=; b=kzIHN/3pQScD6An8Iab6eOwv1nOTiEWund9u9N9bfyLORP38pL+rGF7iED2VamlpIz 9Ej0l+Z7eBxok2KbM+/yWOWjKfMLQOuJOKfrkGUEwi6wbmaudMxwsw8I/olgJKktgMBA NJ/QjwA1wmf7K7jAdsCY/26IbvlWvKzgCtI7uFc7Y8pYyNpa4Hy1JBITyqcGmo6VhdbB BaoEdgPE64K8UlurQNZ+8G0+UA9gc7nIuF9lrUJg2dBX+xfcZGfNDuDdgfi4AptCzT4h GcOSHlgwIBsL0q6zX/rcSG/eeg7H9YLbifIfrni5sbjNuv7gGOgmqxC/hyA5wtn/RMuL g6xg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=yjLWpG6E; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id z25-20020a637e19000000b005dc892c862fsi7669107pgc.638.2024.02.21.08.08.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 08:08:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=yjLWpG6E; arc=pass (i=1 spf=pass spfdomain=collabora.com dkim=pass dkdomain=collabora.com dmarc=pass fromdomain=collabora.com); spf=pass (google.com: domain of linux-kernel+bounces-75048-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75048-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 3416BB24DC3 for ; Wed, 21 Feb 2024 15:58:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6EAA683CB6; Wed, 21 Feb 2024 15:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="yjLWpG6E" Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A96F382885; Wed, 21 Feb 2024 15:54:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530892; cv=none; b=RJsoSbVxPwpSdVyLToIZw88jI20dYRb23itjg7KbC8grrh6Nl4RHsmUW3DZLO16FWaX/rIZV+QZU+/cuXMNKEivjQAEd/Z0unaqR7Nhl8q3q3e8JUvUxWE0zsh7ZlQDxUJAXWYGGGSTpBcsa5bW+K//QyzS32H+oNqXrhrVpNcE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708530892; c=relaxed/simple; bh=fp7Af2JavyVIFNlDhfBtLvTU8aA7T4w2d45EtkwuBHY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cJQNg3VNjoqC8My862LUgkx4qKqF7tWgteKR7BmYRB3h0Rz48lbrXXqAIt+jl5UHmExT0qGmK74AX+XXg84r7ThBZZhzjzz/EDer76Zs94wVpDtJE1F4S+F7SViWpzrD/mY9u01HqZ6b6a5o/h3yilu0Y2xjN523R62zqnjw0PI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=yjLWpG6E; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1708530889; bh=fp7Af2JavyVIFNlDhfBtLvTU8aA7T4w2d45EtkwuBHY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yjLWpG6EANx78oYE9sH5do7GUj0U7n+V9eQoJ6/nfjsLYYzECcc6/ECZpDD9kqRtk +byzVefibEpLtL+FIeZV1iV6rLOzAIP0DuDL5f7lrNH4A3W9gTYUtqdzXYuvNTlkZv 7ltm40Pw0xAGZF79l1BR8vRBUR3FDrt2s2W4nT0L8CSALgnY7CW5xXfgpnD0NS5EnL 1UZENZGIDlsBycNcwrRDG8aYJCdib2Tyg+usqMjgRCqnm6oyFy5rYc2TVSNU51tjKf NwJqXMS6b3P/5Kvc/F+yRC4kZbj3zB6+eSUBdikETFRcr1OkJqIofofDORBqvK9Vuy JAopl0JowHDdg== Received: from benjamin-XPS-13-9310.. (cola.collaboradmins.com [195.201.22.229]) (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 madrid.collaboradmins.com (Postfix) with ESMTPSA id 967903780629; Wed, 21 Feb 2024 15:54:48 +0000 (UTC) From: Benjamin Gaignard To: mchehab@kernel.org, tfiga@chromium.org, m.szyprowski@samsung.com, ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, hverkuil-cisco@xs4all.nl, nicolas@ndufresne.ca Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v20 9/9] media: verisilicon: Support removing buffers on capture queue Date: Wed, 21 Feb 2024 16:54:35 +0100 Message-Id: <20240221155435.100093-10-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240221155435.100093-1-benjamin.gaignard@collabora.com> References: <20240221155435.100093-1-benjamin.gaignard@collabora.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791525323870766299 X-GMAIL-MSGID: 1791525323870766299 Allow to remove buffers on capture queue because it the one which own the decoded buffers. After a dynamic resolution change lot of them could remain allocated but won't be used anymore so deleting them save memory. Signed-off-by: Benjamin Gaignard --- drivers/media/platform/verisilicon/hantro_v4l2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index 941fa23c211a..df6f2536263b 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -756,6 +756,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_remove_bufs = v4l2_m2m_ioctl_remove_bufs, .vidioc_expbuf = v4l2_m2m_ioctl_expbuf, .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,