From nobody Mon Dec 1 22:07:39 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 E50A224A058; Fri, 28 Nov 2025 19:16:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357419; cv=none; b=quakxbHs0pJ9ycjz8CbbFluaQT54nLfycoVWjj6RbemtA+0DISPPHerSeqBawxqVBg9L2UWsihq+RIqGhRPL1p0BZ1Idn9pzjoyAZHvoACHaE+SbPGWdNJ2gdd9IN23vWVg3EOto4McuCBd97HQL2AgjrYIs7ix+NOamFZN21qg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357419; c=relaxed/simple; bh=upYgvQfvCaZv2V+FrW0kF40lwPHlCilL/v6b6lsQpK8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Z6j2wJIW/rGCwZYsrfZB7BqgUpJj6vCCm48Gulh4HmwL+q1+u+ikvS4OcV9sS5xz403UfVYlAAaGoxQa36EaYGOd3kmjY67PMW5jvdE69CmB011ktiWqSi55QVjJ/XXZ772TkuQCv/aoZfwswSs6MhZrz0HVvguQOTgXAxnL3DU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=Ptnia/WQ; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="Ptnia/WQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764357415; bh=upYgvQfvCaZv2V+FrW0kF40lwPHlCilL/v6b6lsQpK8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Ptnia/WQRwVtMBbwl2kYkC7e0z/G+nUof3Q20uEHAyScBmGdqD89bKnmfy+FseRhw RruMLe8ygcYEKH42LTQ4pAUkLsEn4sOS7fR65iFgHPvFuhvxno3nSII2JDId/VtPQ5 22oY3f4fbfTYwt525xx6VrS1eqne1bHupHS3mrPU7+YzDzm9fzK182DZJFWMJ9S9CS WffTGdrujg39Ak+HnlNuecLf7u5qUXyooMdFrtdN6wpKNyquSmUW9mWeqqVmsMPe0y JW4pYmuPWEehxnv24mdoNmjnt2M+Iaed9yXBMT5e/oh27ykNPgFHCiFrl3D1rPGoTQ 1Cx6Uem8Izs9Q== Received: from [192.168.13.3] (unknown [IPv6:2606:6d00:17:7b4b::c73]) (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: nicolas) by bali.collaboradmins.com (Postfix) with ESMTPSA id 7650117E10F2; Fri, 28 Nov 2025 20:16:53 +0100 (CET) From: Nicolas Dufresne Date: Fri, 28 Nov 2025 14:16:12 -0500 Subject: [PATCH v4 1/5] media: mc: add manual request completion Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-1-c166bdd4625c@collabora.com> References: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> In-Reply-To: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, linux-media@vger.kernel.org, Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.14.2 From: Hans Verkuil By default when the last request object is completed, the whole request completes as well. But sometimes you want to delay this completion to an arbitrary point in time so add a manual complete mode for this. In req_queue the driver marks the request for manual completion by calling media_request_mark_manual_completion, and when the driver wants to manually complete the request it calls media_request_manual_complete(). Signed-off-by: Hans Verkuil Signed-off-by: Nicolas Dufresne --- drivers/media/mc/mc-request.c | 41 +++++++++++++++++++++++++++++++++++++++= -- include/media/media-request.h | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/drivers/media/mc/mc-request.c b/drivers/media/mc/mc-request.c index f66f728b1b43dcd1cf51de46e828bf806f014f8d..512e6969152792558537dd8a073= 6df82847ae210 100644 --- a/drivers/media/mc/mc-request.c +++ b/drivers/media/mc/mc-request.c @@ -54,6 +54,7 @@ static void media_request_clean(struct media_request *req) req->access_count =3D 0; WARN_ON(req->num_incomplete_objects); req->num_incomplete_objects =3D 0; + req->manual_completion =3D false; wake_up_interruptible_all(&req->poll_wait); } =20 @@ -313,6 +314,7 @@ int media_request_alloc(struct media_device *mdev, int = *alloc_fd) req->mdev =3D mdev; req->state =3D MEDIA_REQUEST_STATE_IDLE; req->num_incomplete_objects =3D 0; + req->manual_completion =3D false; kref_init(&req->kref); INIT_LIST_HEAD(&req->objects); spin_lock_init(&req->lock); @@ -459,7 +461,7 @@ void media_request_object_unbind(struct media_request_o= bject *obj) =20 req->num_incomplete_objects--; if (req->state =3D=3D MEDIA_REQUEST_STATE_QUEUED && - !req->num_incomplete_objects) { + !req->num_incomplete_objects && !req->manual_completion) { req->state =3D MEDIA_REQUEST_STATE_COMPLETE; completed =3D true; wake_up_interruptible_all(&req->poll_wait); @@ -488,7 +490,7 @@ void media_request_object_complete(struct media_request= _object *obj) WARN_ON(req->state !=3D MEDIA_REQUEST_STATE_QUEUED)) goto unlock; =20 - if (!--req->num_incomplete_objects) { + if (!--req->num_incomplete_objects && !req->manual_completion) { req->state =3D MEDIA_REQUEST_STATE_COMPLETE; wake_up_interruptible_all(&req->poll_wait); completed =3D true; @@ -499,3 +501,38 @@ void media_request_object_complete(struct media_reques= t_object *obj) media_request_put(req); } EXPORT_SYMBOL_GPL(media_request_object_complete); + +void media_request_manual_complete(struct media_request *req) +{ + bool completed =3D false; + unsigned long flags; + + if (WARN_ON_ONCE(!req)) + return; + + spin_lock_irqsave(&req->lock, flags); + + if (WARN_ON_ONCE(!req->manual_completion)) + goto unlock; + + if (WARN_ON_ONCE(req->state !=3D MEDIA_REQUEST_STATE_QUEUED)) + goto unlock; + + req->manual_completion =3D false; + /* + * It is expected that all other objects in this request are + * completed when this function is called. WARN if that is + * not the case. + */ + if (!WARN_ON(req->num_incomplete_objects)) { + req->state =3D MEDIA_REQUEST_STATE_COMPLETE; + wake_up_interruptible_all(&req->poll_wait); + completed =3D true; + } + +unlock: + spin_unlock_irqrestore(&req->lock, flags); + if (completed) + media_request_put(req); +} +EXPORT_SYMBOL_GPL(media_request_manual_complete); diff --git a/include/media/media-request.h b/include/media/media-request.h index bb500b2f9da46f5a9a84272759a137720b094a80..3256fcf3709da58878a59d90722= bee3224d97af6 100644 --- a/include/media/media-request.h +++ b/include/media/media-request.h @@ -56,6 +56,9 @@ struct media_request_object; * @access_count: count the number of request accesses that are in progress * @objects: List of @struct media_request_object request objects * @num_incomplete_objects: The number of incomplete objects in the request + * @manual_completion: if true, then the request won't be marked as comple= ted + * when @num_incomplete_objects reaches 0. Call media_request_manual_compl= ete() + * to complete the request after @num_incomplete_objects =3D=3D 0. * @poll_wait: Wait queue for poll * @lock: Serializes access to this struct */ @@ -68,6 +71,7 @@ struct media_request { unsigned int access_count; struct list_head objects; unsigned int num_incomplete_objects; + bool manual_completion; wait_queue_head_t poll_wait; spinlock_t lock; }; @@ -218,6 +222,38 @@ media_request_get_by_fd(struct media_device *mdev, int= request_fd); int media_request_alloc(struct media_device *mdev, int *alloc_fd); =20 +/** + * media_request_mark_manual_completion - Enable manual completion + * + * @req: The request + * + * Mark that the request has to be manually completed by calling + * media_request_manual_complete(). + * + * This function shall be called in the req_queue callback. + */ +static inline void +media_request_mark_manual_completion(struct media_request *req) +{ + req->manual_completion =3D true; +} + +/** + * media_request_manual_complete - Mark the request as completed + * + * @req: The request + * + * This function completes a request that was marked for manual completion= by an + * earlier call to media_request_mark_manual_completion(). The request's + * @manual_completion field is reset to false. + * + * All objects contained in the request must have been completed previousl= y. It + * is an error to call this function otherwise. If such an error occurred,= the + * function will WARN and the object completion will be delayed until + * @num_incomplete_objects is 0. + */ +void media_request_manual_complete(struct media_request *req); + #else =20 static inline void media_request_get(struct media_request *req) @@ -336,7 +372,7 @@ void media_request_object_init(struct media_request_obj= ect *obj); * @req: The media request * @ops: The object ops for this object * @priv: A driver-specific priv pointer associated with this object - * @is_buffer: Set to true if the object a buffer object. + * @is_buffer: Set to true if the object is a buffer object. * @obj: The object * * Bind this object to the request and set the ops and priv values of --=20 2.51.0 From nobody Mon Dec 1 22:07:39 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 D33F833373D; Fri, 28 Nov 2025 19:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357420; cv=none; b=FMc0CvVXGg3TfcEhoVWGVLM6jhkzyPRw1K2Y/44LHkERzycqQ1XKGaGrOFNlHh2/ovc0hFbRSEgS85ZA/JFTuZLHYMleXK+b+Lopg2QEbz0rmci1ANA2rbUtN7fAvRGAxnVA6EcMb43MGfz5a2WL43cY943cofOBUdfrh47sWpE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357420; c=relaxed/simple; bh=Tagn2jC2xyaD/SH8hH8pFaivmZ0pquK+fiaQoTFO9eE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=u86aBhQ6v927n6XdUSeHESCaBoMnENoJMkwY6cBEzMlnfM8QhKNsJH4mELsfXWu5HZjr2MODB2xnr6TPjGwCC8krgDpXOJaEAxOkDsGC48RhqcEVIAuauHKD1l7lktcjxPrNwBczSYuqNI85wVVCVFtLdl3ZfWcoW+C86GLjjpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=LA1ODQS/; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="LA1ODQS/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764357417; bh=Tagn2jC2xyaD/SH8hH8pFaivmZ0pquK+fiaQoTFO9eE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LA1ODQS/TJLd72ZQ090lfRGKQCGhYue/jt3RCb1m0qUqpCThAid6Q7wNKS+E9f/NL 3mX6rQ45kjMLyHpBcmF2ZGZ9pRK9K4Eiwo0cZ+tDj4y3WV+8YVO6IebxiaLNuTX+8A bA6EOGZl2lkWdLGDg3VQn+37Py9wzna6YxcCPNGY6/qULNUX883NfI0F7A14VapBOT gx4Y5yasOovkLK1sqWPB8RrcWqFw35XQ9BUab8v/CuaAQZKPHm47xIgZwnFo5w4WKO mlDwRhNrUIWAfNoqSGctb4VPIOoEJ4tnZNaCSU9DeC2x/Jaz2RK3UJ309QHzFmVKbX Q/DUpqxxL89Zg== Received: from [192.168.13.3] (unknown [IPv6:2606:6d00:17:7b4b::c73]) (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: nicolas) by bali.collaboradmins.com (Postfix) with ESMTPSA id 72DB517E1299; Fri, 28 Nov 2025 20:16:55 +0100 (CET) From: Nicolas Dufresne Date: Fri, 28 Nov 2025 14:16:13 -0500 Subject: [PATCH v4 2/5] media: vicodec: add support for manual completion Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-2-c166bdd4625c@collabora.com> References: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> In-Reply-To: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, linux-media@vger.kernel.org, Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.14.2 From: Hans Verkuil Manually complete the requests: this tests the manual completion code. Signed-off-by: Hans Verkuil Signed-off-by: Nicolas Dufresne --- drivers/media/test-drivers/vicodec/vicodec-core.c | 21 +++++++++++++++++--= -- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/media/test-drivers/vicodec/vicodec-core.c b/drivers/me= dia/test-drivers/vicodec/vicodec-core.c index a7ab668ce70b89423c2cf1440e340961ebc26b9d..be846f7119691c1d0fef9135168= 2d70c696df4f7 100644 --- a/drivers/media/test-drivers/vicodec/vicodec-core.c +++ b/drivers/media/test-drivers/vicodec/vicodec-core.c @@ -448,8 +448,10 @@ static void device_run(void *priv) ctx->comp_magic_cnt =3D 0; ctx->comp_has_frame =3D false; spin_unlock(ctx->lock); - if (ctx->is_stateless && src_req) + if (ctx->is_stateless && src_req) { v4l2_ctrl_request_complete(src_req, &ctx->hdl); + media_request_manual_complete(src_req); + } =20 if (ctx->is_enc) v4l2_m2m_job_finish(dev->stateful_enc.m2m_dev, ctx->fh.m2m_ctx); @@ -1518,8 +1520,12 @@ static void vicodec_return_bufs(struct vb2_queue *q,= u32 state) vbuf =3D v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); if (vbuf =3D=3D NULL) return; - v4l2_ctrl_request_complete(vbuf->vb2_buf.req_obj.req, - &ctx->hdl); + if (ctx->is_stateless && V4L2_TYPE_IS_OUTPUT(q->type)) { + struct media_request *req =3D vbuf->vb2_buf.req_obj.req; + + v4l2_ctrl_request_complete(req, &ctx->hdl); + media_request_manual_complete(req); + } spin_lock(ctx->lock); v4l2_m2m_buf_done(vbuf, state); spin_unlock(ctx->lock); @@ -1672,6 +1678,7 @@ static void vicodec_buf_request_complete(struct vb2_b= uffer *vb) struct vicodec_ctx *ctx =3D vb2_get_drv_priv(vb->vb2_queue); =20 v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->hdl); + media_request_manual_complete(vb->req_obj.req); } =20 =20 @@ -2002,6 +2009,12 @@ static int vicodec_request_validate(struct media_req= uest *req) return vb2_request_validate(req); } =20 +static void vicodec_request_queue(struct media_request *req) +{ + media_request_mark_manual_completion(req); + v4l2_m2m_request_queue(req); +} + static const struct v4l2_file_operations vicodec_fops =3D { .owner =3D THIS_MODULE, .open =3D vicodec_open, @@ -2022,7 +2035,7 @@ static const struct video_device vicodec_videodev =3D= { =20 static const struct media_device_ops vicodec_m2m_media_ops =3D { .req_validate =3D vicodec_request_validate, - .req_queue =3D v4l2_m2m_request_queue, + .req_queue =3D vicodec_request_queue, }; =20 static const struct v4l2_m2m_ops m2m_ops =3D { --=20 2.51.0 From nobody Mon Dec 1 22:07:39 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 C6B3033439C; Fri, 28 Nov 2025 19:17:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357422; cv=none; b=hnIZQfYVvYvJVZS3PVenIrvDxKCyjp/tGqu5dP6zLwI6MDmVbudFYeHJMewivnUSgvBNdsmhKvqjSzl+ow3sdNy4/MGYAvolWuJlYdCnCnZjv9/ZZyMyc359EiOsVj8ge/lM2Uv4tZb2yc4Lh1VZnag7gXuZ0F5ja4ciAAVqm1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357422; c=relaxed/simple; bh=q3f8HrAQ3LGVUwQFxC7xFKKhaSjndBXfTzQMsPMnXKg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jzoc3FLTyCAY6cbk+FCWzqkniEkZXRAMWIy5+qgbH8z3m3/sZQeMRpw0zwRrTJkfAo0MMMMnfiFeyVG9j9r5uROwHzXzCjFA2Fo+4BTuHDQ9hn9+kvXEzZWY++Rq5zRXhqy+KYZal/Wr7O8pAcjDK+SA/6IyOrJll3Wk2lZ55nk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=qDjlNXHA; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="qDjlNXHA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764357419; bh=q3f8HrAQ3LGVUwQFxC7xFKKhaSjndBXfTzQMsPMnXKg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=qDjlNXHAU2S83pfSLMwUcmD9bEIbpU1x2edXzg5+alqx9/j/6qErr8M5fGhwyBY0j w7vdFS43dVfBUidHOq0OPZGtjVBO57Mk3SqUb36LHu/QwWzc2ww+L4lY1+/bnKm6UE CBDcifHxsEJqlzACGujmQycSFklF/tFYijNhcj2dSZX7tKMdwEShDPpThm6yhaptGz taF25q18VtKPJ6bYJNCVj7Q1BnBfYW64lpom0ZujoydPH1K2ik5GsTCFgKdxysNAiy 1ZlESZ4YqBWz/4orbK28xso9eukIEL8mw5Yutj5DNTP7UVMCHZBGq67Hbf9HPsmwcJ a51hmx3rlLo6w== Received: from [192.168.13.3] (unknown [IPv6:2606:6d00:17:7b4b::c73]) (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: nicolas) by bali.collaboradmins.com (Postfix) with ESMTPSA id 733D117E13C1; Fri, 28 Nov 2025 20:16:57 +0100 (CET) From: Nicolas Dufresne Date: Fri, 28 Nov 2025 14:16:14 -0500 Subject: [PATCH v4 3/5] media: mc: add debugfs node to keep track of requests Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-3-c166bdd4625c@collabora.com> References: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> In-Reply-To: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, linux-media@vger.kernel.org, Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , Hans Verkuil X-Mailer: b4 0.14.2 From: Hans Verkuil Keep track of the number of requests and request objects of a media device. Helps to verify that all request-related memory is freed. Signed-off-by: Hans Verkuil Signed-off-by: Nicolas Dufresne --- drivers/media/mc/mc-device.c | 30 ++++++++++++++++++++++++++++++ drivers/media/mc/mc-devnode.c | 5 +++++ drivers/media/mc/mc-request.c | 6 ++++++ include/media/media-device.h | 9 +++++++++ include/media/media-devnode.h | 4 ++++ include/media/media-request.h | 2 ++ 6 files changed, 56 insertions(+) diff --git a/drivers/media/mc/mc-device.c b/drivers/media/mc/mc-device.c index c0dd4ae5722725f1744bc6fd6282d5c765438059..5a4465b290f006fe6da5a38a29b= 7c911aea6689f 100644 --- a/drivers/media/mc/mc-device.c +++ b/drivers/media/mc/mc-device.c @@ -679,6 +679,23 @@ void media_device_unregister_entity(struct media_entit= y *entity) } EXPORT_SYMBOL_GPL(media_device_unregister_entity); =20 +#ifdef CONFIG_DEBUG_FS +/* + * Log the state of media requests. Very useful for debugging. + */ +static int media_device_requests(struct seq_file *file, void *priv) +{ + struct media_device *dev =3D dev_get_drvdata(file->private); + + seq_printf(file, "number of requests: %d\n", + atomic_read(&dev->num_requests)); + seq_printf(file, "number of request objects: %d\n", + atomic_read(&dev->num_request_objects)); + + return 0; +} +#endif + void media_device_init(struct media_device *mdev) { INIT_LIST_HEAD(&mdev->entities); @@ -697,6 +714,9 @@ void media_device_init(struct media_device *mdev) media_set_bus_info(mdev->bus_info, sizeof(mdev->bus_info), mdev->dev); =20 + atomic_set(&mdev->num_requests, 0); + atomic_set(&mdev->num_request_objects, 0); + dev_dbg(mdev->dev, "Media device initialized\n"); } EXPORT_SYMBOL_GPL(media_device_init); @@ -748,6 +768,15 @@ int __must_check __media_device_register(struct media_= device *mdev, =20 dev_dbg(mdev->dev, "Media device registered\n"); =20 +#ifdef CONFIG_DEBUG_FS + if (!media_debugfs_root) + media_debugfs_root =3D debugfs_create_dir("media", NULL); + mdev->media_dir =3D debugfs_create_dir(dev_name(&devnode->dev), + media_debugfs_root); + debugfs_create_devm_seqfile(&devnode->dev, "requests", + mdev->media_dir, media_device_requests); +#endif + return 0; } EXPORT_SYMBOL_GPL(__media_device_register); @@ -824,6 +853,7 @@ void media_device_unregister(struct media_device *mdev) =20 dev_dbg(mdev->dev, "Media device unregistered\n"); =20 + debugfs_remove_recursive(mdev->media_dir); device_remove_file(&mdev->devnode->dev, &dev_attr_model); media_devnode_unregister(mdev->devnode); /* devnode free is handled in media_devnode_*() */ diff --git a/drivers/media/mc/mc-devnode.c b/drivers/media/mc/mc-devnode.c index 6daa7aa9944226551c301905b885e9d36cf793a3..51260a7d6921cf030b5d1ccddba= 124c1e5328685 100644 --- a/drivers/media/mc/mc-devnode.c +++ b/drivers/media/mc/mc-devnode.c @@ -45,6 +45,9 @@ static dev_t media_dev_t; static DEFINE_MUTEX(media_devnode_lock); static DECLARE_BITMAP(media_devnode_nums, MEDIA_NUM_DEVICES); =20 +/* debugfs */ +struct dentry *media_debugfs_root; + /* Called when the last user of the media device exits. */ static void media_devnode_release(struct device *cd) { @@ -231,6 +234,7 @@ int __must_check media_devnode_register(struct media_de= vice *mdev, if (devnode->parent) devnode->dev.parent =3D devnode->parent; dev_set_name(&devnode->dev, "media%d", devnode->minor); + dev_set_drvdata(&devnode->dev, mdev); device_initialize(&devnode->dev); =20 /* Part 2: Initialize the character device */ @@ -309,6 +313,7 @@ static int __init media_devnode_init(void) =20 static void __exit media_devnode_exit(void) { + debugfs_remove_recursive(media_debugfs_root); bus_unregister(&media_bus_type); unregister_chrdev_region(media_dev_t, MEDIA_NUM_DEVICES); } diff --git a/drivers/media/mc/mc-request.c b/drivers/media/mc/mc-request.c index 512e6969152792558537dd8a0736df82847ae210..ed88a936c28ae13d1316b1b9c94= 0a75ea44ab3c6 100644 --- a/drivers/media/mc/mc-request.c +++ b/drivers/media/mc/mc-request.c @@ -75,6 +75,7 @@ static void media_request_release(struct kref *kref) mdev->ops->req_free(req); else kfree(req); + atomic_dec(&mdev->num_requests); } =20 void media_request_put(struct media_request *req) @@ -326,6 +327,7 @@ int media_request_alloc(struct media_device *mdev, int = *alloc_fd) =20 snprintf(req->debug_str, sizeof(req->debug_str), "%u:%d", atomic_inc_return(&mdev->request_id), fd); + atomic_inc(&mdev->num_requests); dev_dbg(mdev->dev, "request: allocated %s\n", req->debug_str); =20 fd_install(fd, filp); @@ -349,10 +351,12 @@ static void media_request_object_release(struct kref = *kref) struct media_request_object *obj =3D container_of(kref, struct media_request_object, kref); struct media_request *req =3D obj->req; + struct media_device *mdev =3D obj->mdev; =20 if (WARN_ON(req)) media_request_object_unbind(obj); obj->ops->release(obj); + atomic_dec(&mdev->num_request_objects); } =20 struct media_request_object * @@ -417,6 +421,7 @@ int media_request_object_bind(struct media_request *req, obj->req =3D req; obj->ops =3D ops; obj->priv =3D priv; + obj->mdev =3D req->mdev; =20 if (is_buffer) list_add_tail(&obj->list, &req->objects); @@ -424,6 +429,7 @@ int media_request_object_bind(struct media_request *req, list_add(&obj->list, &req->objects); req->num_incomplete_objects++; ret =3D 0; + atomic_inc(&obj->mdev->num_request_objects); =20 unlock: spin_unlock_irqrestore(&req->lock, flags); diff --git a/include/media/media-device.h b/include/media/media-device.h index 53d2a16a70b0d9d6e5cc28fe1fc5d5ef384410d5..749c327e3c582c3c583e0394468= 321ccd6160da5 100644 --- a/include/media/media-device.h +++ b/include/media/media-device.h @@ -11,6 +11,7 @@ #ifndef _MEDIA_DEVICE_H #define _MEDIA_DEVICE_H =20 +#include #include #include #include @@ -106,6 +107,9 @@ struct media_device_ops { * @ops: Operation handler callbacks * @req_queue_mutex: Serialise the MEDIA_REQUEST_IOC_QUEUE ioctl w.r.t. * other operations that stop or start streaming. + * @num_requests: number of associated requests + * @num_request_objects: number of associated request objects + * @media_dir: DebugFS media directory * @request_id: Used to generate unique request IDs * * This structure represents an abstract high-level media device. It allow= s easy @@ -179,6 +183,11 @@ struct media_device { const struct media_device_ops *ops; =20 struct mutex req_queue_mutex; + atomic_t num_requests; + atomic_t num_request_objects; + + /* debugfs */ + struct dentry *media_dir; atomic_t request_id; }; =20 diff --git a/include/media/media-devnode.h b/include/media/media-devnode.h index d27c1c646c2805171be3997d72210dd4d1a38e32..dbcabeffcb572ae707f5fe1f51f= f719d451c6784 100644 --- a/include/media/media-devnode.h +++ b/include/media/media-devnode.h @@ -20,9 +20,13 @@ #include #include #include +#include =20 struct media_device; =20 +/* debugfs top-level media directory */ +extern struct dentry *media_debugfs_root; + /* * Flag to mark the media_devnode struct as registered. Drivers must not t= ouch * this flag directly, it will be set and cleared by media_devnode_registe= r and diff --git a/include/media/media-request.h b/include/media/media-request.h index 3256fcf3709da58878a59d90722bee3224d97af6..43ed18c11b513ae7d4f28406f22= 9abe58cad89ac 100644 --- a/include/media/media-request.h +++ b/include/media/media-request.h @@ -292,6 +292,7 @@ struct media_request_object_ops { * struct media_request_object - An opaque object that belongs to a media * request * + * @mdev: Media device this object belongs to * @ops: object's operations * @priv: object's priv pointer * @req: the request this object belongs to (can be NULL) @@ -303,6 +304,7 @@ struct media_request_object_ops { * another struct that contains the actual data for this request object. */ struct media_request_object { + struct media_device *mdev; const struct media_request_object_ops *ops; void *priv; struct media_request *req; --=20 2.51.0 From nobody Mon Dec 1 22:07:39 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 DADBE32C924; Fri, 28 Nov 2025 19:17:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357425; cv=none; b=H4YCwZDTMUxQjQeR5VBq1W1q0gWKyDP3vaqoP4eVMEqjUnCwSfXcNoLTmo1jXX0hVzrdI2WY7GJw94x7LxHI+AQZ5gmKxPNVMITlL5FMas4KNu88bHRmk3JayuJHXrd6cJpYGuMExpoo85W/S3Cuw1lhwAwy9E2sA7R+hjYSdCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357425; c=relaxed/simple; bh=h0zdMhLMXP6r7EfNzAuuQY3sRgsGJ1+2eKIZqTitznQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ffPRXhQoMBfRqsXHKSHSH+Xx+BG5l/vEcCSg0RkDfrfaMWPsDwb0jUjvOWYgizH63yxfy0/6e+T9LpmeoyhfebvgpggufqoAzCSbxwoLLbx6WxydiHSmTmHJtxPiz/TRatuTaWUiaCVdyFRHMhnSP/ps936UWs9G+nZrl63azrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=R1Sb3TAD; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="R1Sb3TAD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764357421; bh=h0zdMhLMXP6r7EfNzAuuQY3sRgsGJ1+2eKIZqTitznQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=R1Sb3TADSOa8OgZQ3687muQl1/Gn5SQbhs7s6tFJwys8/goAkq7gM8Uhe6MD+g2Mh uLObBxE0vIeOBp7qfDPNiBITe6yRDpdEmvDa7hE52ybx/ESZH2Izc7nki0jB1Oflbu uOD5CL2DqAS2G/J+Q4l5nNB+1CYX0kTWMNoMq/RiPWjsurq53e1AGC9EC1GzcYMYxF qtAZp+3HOOyTaPLinYMgN6dpNtLgW2habkWt/XElle8N8EvhTV3J+zRCzAlFC9aeGN 69I4SC1MErSB84EfRK21sNpTEhicnjcJhlGsNhbUSmOa4QDy9MUW/cRNCmSONlVC5D jqmieGaoDM7qQ== Received: from [192.168.13.3] (unknown [IPv6:2606:6d00:17:7b4b::c73]) (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: nicolas) by bali.collaboradmins.com (Postfix) with ESMTPSA id C294817E13ED; Fri, 28 Nov 2025 20:16:59 +0100 (CET) From: Nicolas Dufresne Date: Fri, 28 Nov 2025 14:16:15 -0500 Subject: [PATCH v4 4/5] media: vcodec: Implement manual request completion Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-4-c166bdd4625c@collabora.com> References: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> In-Reply-To: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, linux-media@vger.kernel.org, Sebastian Fricke , Nicolas Dufresne X-Mailer: b4 0.14.2 From: Sebastian Fricke Rework how requests are completed in the MediaTek VCodec driver, by implementing the new manual request completion feature, which allows to keep a request open while allowing to add new bitstream data. This is useful in this case, because the hardware has a LAT and a core decode work, after the LAT decode the bitstream isn't required anymore so the source buffer can be set done and the request stays open until the core decode work finishes. Signed-off-by: Sebastian Fricke Co-developed-by: Nicolas Dufresne Signed-off-by: Nicolas Dufresne --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 4 +- .../mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h | 17 ++++ .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 109 ++++++++++++++---= ---- 3 files changed, 96 insertions(+), 34 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.= c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c index 1f32ba11a18c070d825e850d0c5ed07c625e5cf2..d76e891f784b9a6d99692177ab9= d38c898eb4666 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -882,8 +882,10 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q) src_buf->vb2_buf.req_obj.req; v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); - if (req) + if (req) { v4l2_ctrl_request_complete(req, &ctx->ctrl_hdl); + media_request_manual_complete(req); + } } } return; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_= drv.h b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h index 9d68808e8f9c3cb3ceb5b473592691ac84d3f288..c9d27534c63ec902c3f1c86d14f= 22089c0c1926e 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h @@ -7,6 +7,8 @@ #ifndef _MTK_VCODEC_DEC_DRV_H_ #define _MTK_VCODEC_DEC_DRV_H_ =20 +#include + #include "../common/mtk_vcodec_cmn_drv.h" #include "../common/mtk_vcodec_dbgfs.h" #include "../common/mtk_vcodec_fw_priv.h" @@ -128,6 +130,16 @@ struct mtk_vcodec_dec_pdata { bool uses_stateless_api; }; =20 +/** + * struct mtk_vcodec_dec_request - Media request private data. + * @refcount: Used to ensure we don't complete the request too soon + * @req: Media Request structure + */ +struct mtk_vcodec_dec_request { + struct kref refcount; + struct media_request req; +}; + /** * struct mtk_vcodec_dec_ctx - Context (instance) private data. * @@ -324,6 +336,11 @@ static inline struct mtk_vcodec_dec_ctx *ctrl_to_dec_c= tx(struct v4l2_ctrl *ctrl) return container_of(ctrl->handler, struct mtk_vcodec_dec_ctx, ctrl_hdl); } =20 +static inline struct mtk_vcodec_dec_request *req_to_dec_req(struct media_r= equest *req) +{ + return container_of(req, struct mtk_vcodec_dec_request, req); +} + /* Wake up context wait_queue */ static inline void wake_up_dec_ctx(struct mtk_vcodec_dec_ctx *ctx, unsigned int reason, unsig= ned int hw_id) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_= stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec= _stateless.c index d873159b9b3069fe3460502c2751f2e8b2714f44..6598a9e160b7a5a952c118e873a= 893e21e2f71e7 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_statele= ss.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_statele= ss.c @@ -242,10 +242,18 @@ static const struct v4l2_frmsize_stepwise stepwise_fh= d =3D { .step_height =3D 16 }; =20 +static void mtk_vcodec_dec_request_release(struct kref *ref) +{ + struct mtk_vcodec_dec_request *req =3D + container_of(ref, struct mtk_vcodec_dec_request, refcount); + media_request_manual_complete(&req->req); +} + static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_dec_ctx *ctx,= int error, - struct media_request *src_buf_req) + struct media_request *mreq) { - struct vb2_v4l2_buffer *vb2_dst; + struct mtk_vcodec_dec_request *req =3D req_to_dec_req(mreq); + struct vb2_v4l2_buffer *dst_buf; enum vb2_buffer_state state; =20 if (error) @@ -253,17 +261,9 @@ static void mtk_vdec_stateless_cap_to_disp(struct mtk_= vcodec_dec_ctx *ctx, int e else state =3D VB2_BUF_STATE_DONE; =20 - vb2_dst =3D v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); - if (vb2_dst) { - v4l2_m2m_buf_done(vb2_dst, state); - mtk_v4l2_vdec_dbg(2, ctx, "free frame buffer id:%d to done list", - vb2_dst->vb2_buf.index); - } else { - mtk_v4l2_vdec_err(ctx, "dst buffer is NULL"); - } - - if (src_buf_req) - v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + dst_buf =3D v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); + v4l2_m2m_buf_done(dst_buf, state); + kref_put(&req->refcount, mtk_vcodec_dec_request_release); } =20 static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx) @@ -306,6 +306,7 @@ static void vb2ops_vdec_buf_request_complete(struct vb2= _buffer *vb) struct mtk_vcodec_dec_ctx *ctx =3D vb2_get_drv_priv(vb->vb2_queue); =20 v4l2_ctrl_request_complete(vb->req_obj.req, &ctx->ctrl_hdl); + media_request_manual_complete(vb->req_obj.req); } =20 static void mtk_vdec_worker(struct work_struct *work) @@ -317,8 +318,9 @@ static void mtk_vdec_worker(struct work_struct *work) struct vb2_buffer *vb2_src; struct mtk_vcodec_mem *bs_src; struct mtk_video_dec_buf *dec_buf_src; - struct media_request *src_buf_req; - enum vb2_buffer_state state; + struct media_request *mreq; + struct mtk_vcodec_dec_request *req; + enum vb2_buffer_state buf_state; bool res_chg =3D false; int ret; =20 @@ -350,14 +352,26 @@ static void mtk_vdec_worker(struct work_struct *work) mtk_v4l2_vdec_dbg(3, ctx, "[%d] Bitstream VA=3D%p DMA=3D%pad Size=3D%zx v= b=3D%p", ctx->id, bs_src->va, &bs_src->dma_addr, bs_src->size, vb2_src); /* Apply request controls. */ - src_buf_req =3D vb2_src->req_obj.req; - if (src_buf_req) - v4l2_ctrl_request_setup(src_buf_req, &ctx->ctrl_hdl); - else + mreq =3D vb2_src->req_obj.req; + if (WARN_ON(!mreq)) { + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); mtk_v4l2_vdec_err(ctx, "vb2 buffer media request is NULL"); + return; + } + + v4l2_ctrl_request_setup(mreq, &ctx->ctrl_hdl); + + /* Keep a reference so that if the processing completes before this funct= ion + * ends, we won't accidently update a freshly queued request. + */ + req =3D req_to_dec_req(mreq); + kref_get(&req->refcount); =20 ret =3D vdec_if_decode(ctx, bs_src, NULL, &res_chg); - if (ret && ret !=3D -EAGAIN) { + if (ret =3D=3D -EAGAIN) + goto done; + + if (ret) { mtk_v4l2_vdec_err(ctx, "[%d] decode src_buf[%d] sz=3D0x%zx pts=3D%llu ret=3D%d res_chg=3D%d= ", ctx->id, vb2_src->index, bs_src->size, @@ -367,21 +381,23 @@ static void mtk_vdec_worker(struct work_struct *work) dec_buf_src->error =3D true; mutex_unlock(&ctx->lock); } - } =20 - state =3D ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE; - if (!IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) || - ctx->current_codec =3D=3D V4L2_PIX_FMT_VP8_FRAME) { - v4l2_m2m_buf_done_and_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx, state); - if (src_buf_req) - v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + buf_state =3D VB2_BUF_STATE_ERROR; } else { - if (ret !=3D -EAGAIN) { - v4l2_m2m_src_buf_remove(ctx->m2m_ctx); - v4l2_m2m_buf_done(vb2_v4l2_src, state); - } - v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); + buf_state =3D VB2_BUF_STATE_DONE; } + + v4l2_ctrl_request_complete(mreq, &ctx->ctrl_hdl); + v4l2_m2m_src_buf_remove(ctx->m2m_ctx); + v4l2_m2m_buf_done(vb2_v4l2_src, buf_state); + + if (ret || !IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) || + ctx->current_codec =3D=3D V4L2_PIX_FMT_VP8_FRAME) + mtk_vdec_stateless_cap_to_disp(ctx, ret, mreq); + +done: + kref_put(&req->refcount, mtk_vcodec_dec_request_release); + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); } =20 static void vb2ops_vdec_stateless_buf_queue(struct vb2_buffer *vb) @@ -709,6 +725,22 @@ static int mtk_vcodec_dec_ctrls_setup(struct mtk_vcode= c_dec_ctx *ctx) return 0; } =20 +static struct media_request *fops_media_request_alloc(struct media_device = *mdev) +{ + struct mtk_vcodec_dec_request *req; + + req =3D kzalloc(sizeof(*req), GFP_KERNEL); + + return &req->req; +} + +static void fops_media_request_free(struct media_request *mreq) +{ + struct mtk_vcodec_dec_request *req =3D req_to_dec_req(mreq); + + kfree(req); +} + static int fops_media_request_validate(struct media_request *mreq) { const unsigned int buffer_cnt =3D vb2_request_buffer_cnt(mreq); @@ -729,9 +761,20 @@ static int fops_media_request_validate(struct media_re= quest *mreq) return vb2_request_validate(mreq); } =20 +static void fops_media_request_queue(struct media_request *mreq) +{ + struct mtk_vcodec_dec_request *req =3D req_to_dec_req(mreq); + + media_request_mark_manual_completion(mreq); + kref_init(&req->refcount); + v4l2_m2m_request_queue(mreq); +} + const struct media_device_ops mtk_vcodec_media_ops =3D { + .req_alloc =3D fops_media_request_alloc, + .req_free =3D fops_media_request_free, .req_validate =3D fops_media_request_validate, - .req_queue =3D v4l2_m2m_request_queue, + .req_queue =3D fops_media_request_queue, }; =20 static void mtk_vcodec_add_formats(unsigned int fourcc, --=20 2.51.0 From nobody Mon Dec 1 22:07:39 2025 Received: from bali.collaboradmins.com (bali.collaboradmins.com [148.251.105.195]) (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 4645B33509D; Fri, 28 Nov 2025 19:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.251.105.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357428; cv=none; b=UsJxDQ8h5fI2DvwFa8jIoDV+X6G1CCihkwkPwCVnM2+0xsUxYodMpEB4qR/I8X2YE95Zdk9Oiraxav8PXO2PQgenAhLPaKQwnqtUrs48lrUzzryu/Cjwvm/m+vD0/rcBG4sjN5vns+dGhtJablIyv2W1qd/PrB9hciZPP+FfOqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764357428; c=relaxed/simple; bh=oNY6R0rAfFGsoKbfh/1b/5kMouL/RKSRsCa8WAjLKyo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fx0bog6s9IvaDv84oe1Ee4ypLfSSudh2T11xJRCwnevYOuVwwyL+Q/QbuFtWiPdHRNsVz8WqeUzRkOjpYjgzsDUv//oSWTdQsLHyZdSc1RcQUwsCWWaq7vDnf3bS4Xsu57Xhn9cd3zpJ1OZgogTsc1XQuEHvIUy8RcLRHS14TSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none 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=muBzDKfJ; arc=none smtp.client-ip=148.251.105.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="muBzDKfJ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1764357423; bh=oNY6R0rAfFGsoKbfh/1b/5kMouL/RKSRsCa8WAjLKyo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=muBzDKfJPPhEO/eLnmkzX9E+KQbQHdBvqg7NlmV8CUHs6kFaZPr34Falf1XfQB9Lp IcoI3l4txK5fr+vbQ2JXq5qNIiAbi+dIWJq9Uora7fuj+EFIYL+O9UQ+MO1MPjPFuR RTO+LSolGcG4+mOIBm3TKHAn7WHKuKvV9lH+lT2Z2r8QGp5l0aKUeOdWObX/qB1ogE cwRPIF25RYtNRVUDtCkuzkQDUvGUupstTIMWc8oNE8aoDS1PMoI4Lg9BggolJcCAPf IceFYqDDtPSQ5U7Z0mSd6hy9AXaFF83vtzHZEzyQPjit8QAhrAkwv+Ulxin1QvgBOA gtK5OScgAah0g== Received: from [192.168.13.3] (unknown [IPv6:2606:6d00:17:7b4b::c73]) (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: nicolas) by bali.collaboradmins.com (Postfix) with ESMTPSA id C33C517E1203; Fri, 28 Nov 2025 20:17:01 +0100 (CET) From: Nicolas Dufresne Date: Fri, 28 Nov 2025 14:16:16 -0500 Subject: [PATCH v4 5/5] media: mtk-vcodec: Don't try to decode 422/444 VP9 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-5-c166bdd4625c@collabora.com> References: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> In-Reply-To: <20251128-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v4-0-c166bdd4625c@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno , Hans Verkuil Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, kernel@collabora.com, linux-media@vger.kernel.org, Sebastian Fricke , Nicolas Dufresne X-Mailer: b4 0.14.2 This is not supported by the hardware and trying to decode these leads to LAT timeout errors. Reviewed-by: AngeloGioacchino Del Regno Signed-off-by: Nicolas Dufresne --- .../platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c | 6 ++= ++++ 1 file changed, 6 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_= stateless.c b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec= _stateless.c index 6598a9e160b7a5a952c118e873a893e21e2f71e7..8e1cf16a168a7769c71459483e7= 85948e259a828 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_statele= ss.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_statele= ss.c @@ -518,6 +518,12 @@ static int mtk_vdec_s_ctrl(struct v4l2_ctrl *ctrl) mtk_v4l2_vdec_err(ctx, "VP9: bit_depth:%d", frame->bit_depth); return -EINVAL; } + + if (!(frame->flags & V4L2_VP9_FRAME_FLAG_X_SUBSAMPLING) || + !(frame->flags & V4L2_VP9_FRAME_FLAG_Y_SUBSAMPLING)) { + mtk_v4l2_vdec_err(ctx, "VP9: only 420 subsampling is supported"); + return -EINVAL; + } break; case V4L2_CID_STATELESS_AV1_SEQUENCE: seq =3D (struct v4l2_ctrl_av1_sequence *)hdr_ctrl->p_new.p; --=20 2.51.0