From nobody Mon Feb 9 23:32:53 2026 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 62E7C20C488; Wed, 4 Jun 2025 20:10:07 +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=1749067809; cv=none; b=lGEC3/fKGz1IlTfhHHH91CdnD0nO9UEfQTJu6sjFvUuiqz2i4tFS+Yj7szbpYWj2erDYqEut0H4fIBGbLFTppumDdM39Gi0xayVarRp8geRw4P+kV1hUx/wd0ju4hsshRTRbe/DBCUdxe3+sv4WfUSSP9oWEGtxn6AixicDG68Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749067809; c=relaxed/simple; bh=2v06sXu3RhyrlzfSqsOq6sdxfW6AkWnae7dI01vja4w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=C8E4AHZ+tnlrFqBIuNYzRNvQc1zL+NgT2f5nVUkBeEUEHJKLLiZSO/6Q9TUYvuH9OThuqENdMs7M9eONxmQvmbiR78sIwroBLuNV7qMImoyJwzhXZW2ge77hrW4WqG4RemzaEjazj16MsdvorfHaL1kGBv7hboIK03tRoyajzGE= 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=PAvZ1U9j; 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="PAvZ1U9j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1749067799; bh=2v06sXu3RhyrlzfSqsOq6sdxfW6AkWnae7dI01vja4w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PAvZ1U9j1EJaOCUQar/GpHDuqejxu2r1D4Wr70g7u1eU7DUBhJZxAt+4/HNAJ77to 7iGpwAhpZb+ZNSRlmWEVqSsTc/QUxuwq8SBweph7FJqaUYwfkX0VZRawsUne593tPy vb5A703tkV5aBb/ZQ2iAtPdV6c3VAzHU2pU3XPGt22QmMgtm7ZOq+A2Q3JAxXxZxCI DXRIVHjlVKYbJPdxRoskBBJOufChA7CBjyutgMfO73qVSuNiiW3eDedMpxutRWJPIj gaWiGOG7alIII115yLeNuPVUwDmti3pGEyLG9PaBwB28AlwqOUC1yC4f48OzhCC4XY MBietkJnLd4CA== Received: from [192.168.13.145] (unknown [IPv6:2606:6d00:10:5285::5ac]) (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 0720917E0C37; Wed, 4 Jun 2025 22:09:57 +0200 (CEST) From: Nicolas Dufresne Date: Wed, 04 Jun 2025 16:09:35 -0400 Subject: [PATCH v3 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: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-1-603db4749d90@collabora.com> References: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> In-Reply-To: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno 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 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 | 38 ++++++++++++++++++++++++++++++++++++-- include/media/media-request.h | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/drivers/media/mc/mc-request.c b/drivers/media/mc/mc-request.c index 5edfc2791ce7c7485def5db675bbf53ee223d837..398d0806d1d274eb8c454fc5c37= b77476abe1e74 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,35 @@ 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) +{ + unsigned long flags; + bool completed =3D false; + + if (WARN_ON(!req)) + return; + if (WARN_ON(!req->manual_completion)) + return; + + spin_lock_irqsave(&req->lock, flags); + if (WARN_ON(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 d4ac557678a78372222704400c8c96cf3150b9d9..7f9af68ef19ac6de0184bbb0c08= 27dc59777c6dc 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 flag 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.49.0 From nobody Mon Feb 9 23:32:53 2026 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 9CC21227E94; Wed, 4 Jun 2025 20:10:09 +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=1749067811; cv=none; b=Kh9P/w9Y53RvFT37neb76mvkTmzDwcTQLjhtrhM34Z2xNQkOgfr1jQL79P0Up2JEOE3A3fP4Lif2UAMcVF56MwMvb2C8va791G1CFh7e+SrovxUZFZNlm/ABRvPaRFuz8fXOeu08gG0fneNdTJLm9WVby9Cr28SnR+nEQ1wxaTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749067811; c=relaxed/simple; bh=WoCQoCxfZMDeUFZcKpyAMMWvReEUdUT+5X/64RM4JlQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a9y/YH2b5L9OBN/kyjyEt8vF+oMkvInEt2xzai5XlP+8h95zUsNpxjCXDZ+QnriGNb7zqA1oDc1Pa3J867iVmKmLZotaqnx7DcctADOklQbyEo5OEmn8ojnU36Ibv2Oh/YyFuRMJF2067ysXHIw6I1Txkzciw/zmOVVgI086oeE= 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=ilFs5Qbp; 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="ilFs5Qbp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1749067801; bh=WoCQoCxfZMDeUFZcKpyAMMWvReEUdUT+5X/64RM4JlQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ilFs5QbpnMIrutQuLSN44BI7zgUPkbs5Sx7c9Eor1RyEJOiBH358ItSXpcyW3inA3 ddr4l3rGqEMAUM0Kr0MwVwgrS9E5LkX3M6xPxYK3dwJnNsLxwGeBd+6OcTeekXQaX/ K387NTt86n7xBhp4fIlvvOoVug3TthVTagoPA4kZs4XUell23E7QCyqeL6MbAcTASS drsMFErFG6NU5CwgtT+hs5JoMZw4JHWVOK99xyy62GaR93KAQegiXB8+tRrDWftJC+ YCUVQYAl2KWvRonSUCxBkJpPvUJjaITy9rzdFAK+/RJu5BkCoyPN90oeeEM1x9Au2t 4e31jBYpVeW5A== Received: from [192.168.13.145] (unknown [IPv6:2606:6d00:10:5285::5ac]) (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 11CE217E1045; Wed, 4 Jun 2025 22:09:59 +0200 (CEST) From: Nicolas Dufresne Date: Wed, 04 Jun 2025 16:09:36 -0400 Subject: [PATCH v3 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: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-2-603db4749d90@collabora.com> References: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> In-Reply-To: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno 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 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 c45f5cf12ded3c8b57483b148bf7bbffb8a458c5..88cb6e6a713f08bd4f412ca2940= b1309bb87513b 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); @@ -1525,8 +1527,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); @@ -1679,6 +1685,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 @@ -2010,6 +2017,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, @@ -2030,7 +2043,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.49.0 From nobody Mon Feb 9 23:32:53 2026 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 B88361940A1; Wed, 4 Jun 2025 20:10:05 +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=1749067807; cv=none; b=VtCZashmqv8/d15mul5CePEBg6pe3mumy7cAi5K1duYFiBg6LWrw+/5CfInsJPY2foE3jMQu+5Rtk4N+f8MfjDOTSBRnr/uJOnjjDjpiVOPD0VCLqkAwq63lLD+KlVMWwQP1pltOK0lbNkSnrdUw6Kh4Pxkz3YmivxM4i10JT8Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749067807; c=relaxed/simple; bh=KgpRi1k6ad/ufFG3KTCWur/DBPHCkjsoWH2xe57dnAI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nrus6GGMbeNXWK+hRLZqVCsTvNvhBEg8dvxP1n45z7lxelAoo/dn/M+b/vm58zL2pvzXxyPTUgvlAKExIFacuIJWRW3hKKdEvToTO3xUuEt0vmWspue+NlLpzZ/qJlqmL64XUaritvT+MiZ14CD/OguBvvju9T860YJ338s2v0Y= 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=kjRD6j5l; 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="kjRD6j5l" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1749067803; bh=KgpRi1k6ad/ufFG3KTCWur/DBPHCkjsoWH2xe57dnAI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kjRD6j5l2IfdIffSdDi0UfkoFmn6QoSriKkvAt3kO8ITEjZ1Jn012vaWCUVUfaK23 3IkeM7HgSV+Rpn54anNo0JipZxc/63wuI0lNtm9eM65KzdNBmhRnxobjq7JEXdq6/d b/J5bMJN0wiOqrctfBE0lSbYLeyQ0FxGBfV7Ey5qkFyd8mRWR930CPSNe3cCzXzApj hPY4mc51IiR4hCzt2vLaVytxiZPKRLRjkhRRH2LsXYQBTM91AgLp7c/e315865Jgoz lii/zxVrEc0lrP6D8dvCaEJIQB79MjUI2pGKy1CC42P2e/LCnKSQR779V1HFYx5DzM y1rr3GVZuBgiQ== Received: from [192.168.13.145] (unknown [IPv6:2606:6d00:10:5285::5ac]) (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 1ABF617E10D3; Wed, 4 Jun 2025 22:10:02 +0200 (CEST) From: Nicolas Dufresne Date: Wed, 04 Jun 2025 16:09:37 -0400 Subject: [PATCH v3 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: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-3-603db4749d90@collabora.com> References: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> In-Reply-To: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno 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 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..5a458160200afb540d8014fed42= d8bf2dab9c8c3 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 56444edaf13651874331e7c04e86b0a585067d38..d0a8bcc11dd6350fdbc04add70f= 62de2c5f01178 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) { @@ -236,6 +239,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 */ @@ -313,6 +317,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 398d0806d1d274eb8c454fc5c37b77476abe1e74..829e35a5d56d41c52cc583cdea1= c959bcb4fce60 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 7f9af68ef19ac6de0184bbb0c0827dc59777c6dc..610ccfe8d7b20ec38e166383433= f9ee208248640 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.49.0 From nobody Mon Feb 9 23:32:53 2026 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 60D82221DBD; Wed, 4 Jun 2025 20:10:08 +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=1749067810; cv=none; b=lAkXfvRHy/itZa9Xrc/6l6Jwh7/UPA4J2ms7Ks6FS01S9foqMQZMoH2kRpSmI0u5ysAf5fhT9ULaPH3jqTfxWrNQLLV2tp2AzW2McTq53ixnXQ4b3eZNAX98IP6C/l+HbznwCEMxNZH9WqAoiGYIymgy3Mq8InaG5yMBzdnSkEM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749067810; c=relaxed/simple; bh=4sGxas2P+my+BbRd+bOFWMBu0iKNppblQO7l3Z/Y3+8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PmFUWv2TtAsh7nV7dAQnOgPZCkFTWYid8EnBfrXTbjtqi78hLHiL1gVBvdwGubZnUVb5P/JZ4QQLWYIAhwtDq7zctnTdDaTyJCpDa4C5Ziy7b/MFRT1fz4r5WryB48BqbrqFRY5PDDaOSrpAwg0CoREw1PRv4ic9cUB/tN/PAjc= 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=Jr8JvoE4; 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="Jr8JvoE4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1749067806; bh=4sGxas2P+my+BbRd+bOFWMBu0iKNppblQO7l3Z/Y3+8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Jr8JvoE4wZCTdgW81NBJnkbsM9smtAdTBRKS9IbhHHGJ8Iu9JFKkGT/SdBmakIVcJ 7Hl4lVSa9wrcW66hgV1tmCAY++DLVoFfCWCfZBeUar+7KBSJrwO3yxkiFJOcwWf22Y UXL7tCdDeW2NEfMz2RNhr75Cp6FgqhXnPJxNtiWI7Sjf+R64S+8kMMHN29COe/Djc4 lSRCIqRd4rvm2LfkbugaEjXOttNclykvBP6dHykmoYUu0U16BusJKuGJ7238TCj1iD nLypdN4i3bXouzxZ4jTkCA4lFRePzSQg9Do3v6087uqI/i1F69vtrB04cd6kr34Ksz vCRn5BeqtSVwQ== Received: from [192.168.13.145] (unknown [IPv6:2606:6d00:10:5285::5ac]) (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 2690117E3730; Wed, 4 Jun 2025 22:10:04 +0200 (CEST) From: Nicolas Dufresne Date: Wed, 04 Jun 2025 16:09:38 -0400 Subject: [PATCH v3 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: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-4-603db4749d90@collabora.com> References: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> In-Reply-To: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno 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 Reviewed-by: AngeloGioacchino Del Regno --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 4 +- .../mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h | 29 +++++ .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 140 ++++++++++++++++-= ---- 3 files changed, 140 insertions(+), 33 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 98838217b97d45ed2b5431fdf87c94e0ff79fc57..036ad191a9c3e644fe99b4ce25d= 6a089292f1e57 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -889,8 +889,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 aececca7ecf8936bb2b3b55c99354af983746b30..6f9728a95720a257dee9201463c= 5e275d0586a94 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 @@ -64,6 +64,19 @@ enum mtk_vdec_hw_arch { MTK_VDEC_LAT_SINGLE_CORE, }; =20 +/** + * enum mtk_vdec_request_state - Stages of processing a request + * @MTK_VDEC_REQUEST_RECEIVED: Hardware prepared for the LAT decode + * @MTK_VDEC_REQUEST_LAT_DONE: LAT decode finished, the bitstream is not + * needed anymore + * @MTK_VDEC_REQUEST_CORE_DONE: CORE decode finished + */ +enum mtk_vdec_request_state { + MTK_VDEC_REQUEST_RECEIVED =3D 0, + MTK_VDEC_REQUEST_LAT_DONE =3D 1, + MTK_VDEC_REQUEST_CORE_DONE =3D 2, +}; + /** * struct vdec_pic_info - picture size information * @pic_w: picture width @@ -128,6 +141,17 @@ struct mtk_vcodec_dec_pdata { bool uses_stateless_api; }; =20 +/** + * struct mtk_vcodec_dec_request - Media request private data. + * + * @req_state: Request completion state + * @req: Media Request structure + */ +struct mtk_vcodec_dec_request { + enum mtk_vdec_request_state req_state; + struct media_request req; +}; + /** * struct mtk_vcodec_dec_ctx - Context (instance) private data. * @@ -319,6 +343,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..eea0050eacc1c41abd8e0a1cd54= 6c1ecce90a311 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,61 @@ static const struct v4l2_frmsize_stepwise stepwise_fh= d =3D { .step_height =3D 16 }; =20 +static const char *state_to_str(enum mtk_vdec_request_state state) +{ + switch (state) { + case MTK_VDEC_REQUEST_RECEIVED: + return "RECEIVED"; + case MTK_VDEC_REQUEST_LAT_DONE: + return "LAT_DONE"; + case MTK_VDEC_REQUEST_CORE_DONE: + return "CORE_DONE"; + default: + return "UNKNOWN"; + } +} + +static void mtk_vcodec_dec_request_complete(struct mtk_vcodec_dec_ctx *ctx, + enum mtk_vdec_request_state state, + enum vb2_buffer_state buffer_state, + struct media_request *src_buf_req) +{ + struct mtk_vcodec_dec_request *req =3D req_to_dec_req(src_buf_req); + struct vb2_v4l2_buffer *src_buf, *dst_buf; + + mutex_lock(&ctx->lock); + + if (req->req_state >=3D state) { + mutex_unlock(&ctx->lock); + return; + } + + switch (req->req_state) { + case MTK_VDEC_REQUEST_RECEIVED: + v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + src_buf =3D v4l2_m2m_src_buf_remove(ctx->m2m_ctx); + v4l2_m2m_buf_done(src_buf, buffer_state); + if (state =3D=3D MTK_VDEC_REQUEST_LAT_DONE) + break; + fallthrough; + case MTK_VDEC_REQUEST_LAT_DONE: + dst_buf =3D v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); + v4l2_m2m_buf_done(dst_buf, buffer_state); + media_request_manual_complete(src_buf_req); + break; + default: + break; + } + + mtk_v4l2_vdec_dbg(3, ctx, "Switch state from %s to %s.\n", + state_to_str(req->req_state), state_to_str(state)); + req->req_state =3D state; + mutex_unlock(&ctx->lock); +} + static void mtk_vdec_stateless_cap_to_disp(struct mtk_vcodec_dec_ctx *ctx,= int error, struct media_request *src_buf_req) { - struct vb2_v4l2_buffer *vb2_dst; enum vb2_buffer_state state; =20 if (error) @@ -253,17 +304,7 @@ 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); + mtk_vcodec_dec_request_complete(ctx, MTK_VDEC_REQUEST_CORE_DONE, state, s= rc_buf_req); } =20 static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx) @@ -306,6 +347,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) @@ -318,7 +360,8 @@ static void mtk_vdec_worker(struct work_struct *work) 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; + enum mtk_vdec_request_state req_state; + enum vb2_buffer_state buf_state; bool res_chg =3D false; int ret; =20 @@ -351,37 +394,43 @@ static void mtk_vdec_worker(struct work_struct *work) 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 + if (WARN_ON(!src_buf_req)) { + 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(src_buf_req, &ctx->ctrl_hdl); =20 ret =3D vdec_if_decode(ctx, bs_src, NULL, &res_chg); - if (ret && ret !=3D -EAGAIN) { + + if (ret =3D=3D -EAGAIN) { + buf_state =3D VB2_BUF_STATE_DONE; + req_state =3D MTK_VDEC_REQUEST_RECEIVED; + } else 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= ", + "[%d] decode src_buf[%d] sz=3D0x%zx pts=3D%llu res_chg=3D%d ret=3D%d= ", ctx->id, vb2_src->index, bs_src->size, - vb2_src->timestamp, ret, res_chg); + vb2_src->timestamp, res_chg, ret); if (ret =3D=3D -EIO) { mutex_lock(&ctx->lock); 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; + req_state =3D MTK_VDEC_REQUEST_CORE_DONE; } 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; + + if (!IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) || + ctx->current_codec =3D=3D V4L2_PIX_FMT_VP8_FRAME) + req_state =3D MTK_VDEC_REQUEST_CORE_DONE; + else + req_state =3D MTK_VDEC_REQUEST_LAT_DONE; } + + mtk_vcodec_dec_request_complete(ctx, req_state, buf_state, src_buf_req); + 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 +758,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 +794,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); + req->req_state =3D MTK_VDEC_REQUEST_RECEIVED; + 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.49.0 From nobody Mon Feb 9 23:32:53 2026 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 6C9D622D9EB; Wed, 4 Jun 2025 20:10:10 +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=1749067812; cv=none; b=IT5bv41y5kgsaC8t9eunWMBQlAH4UV4b5xcRm3uBPijmnt4hQYX89s+P8+QK3NnUxW2er3rjQU1bBxSl+18+AeN6MhYksO0LpP/UZhsrZ4p9cxrx4lWvV540x3jW8vNCxv0yVOl5aQfoRRbsnF5n8qQBYAhu3oEv8sXLCMVIcLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1749067812; c=relaxed/simple; bh=JA52+QnvbuG3EENYM7JPRyaiysq+VkS9i9fM+g1A6bU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=r58rF0pUVd4edVGPv4J68iKfX52prUBSAqi/5qmwmTpXvpvuCTGsrHU1OcfvDQiXgx9w4opg6WSW0DEtTqsNgEtBIL2KH+DjP+5WFJE0eFeP+xq6fIjz6icROMoSZrjxaxMvTqjaZaPk1ChVGQe/rJkUlO6o0LsmejAjKqZWGgk= 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=LJPEJVvD; 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="LJPEJVvD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1749067808; bh=JA52+QnvbuG3EENYM7JPRyaiysq+VkS9i9fM+g1A6bU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LJPEJVvDRnf3DFmydzCHmJWaQ4mxNwo7hUrucAjedI04PXtyJr5NHsE4JEdOmKNjd UWWGAW8OTYDTFWWVoSGPi9gOXazR/ij2mrw4HoiQl3Q9lbcYq3oBPd0kwrTIWD6O/L l5GCAQ8/og+OwAYCtpm2c9caoYfEryHUgcf2UeZ+9aGTEhp9YI08unkln8LsNsNGg5 VU0gEpeDQKd6OG6mJiG4O0yYZ5XnRmpfGDDFa2c7MjG8dC8FFq9UMfXrbaPdyYI7Zd H0DLmQGJzUFSU/b+nVBfz5loagrpuVBT3n8X6etqqWAY/1AR8sc7MawIqx5lm47H4q maY7n/v7UCmkA== Received: from [192.168.13.145] (unknown [IPv6:2606:6d00:10:5285::5ac]) (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 D84AA17E378F; Wed, 4 Jun 2025 22:10:06 +0200 (CEST) From: Nicolas Dufresne Date: Wed, 04 Jun 2025 16:09:39 -0400 Subject: [PATCH v3 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: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-5-603db4749d90@collabora.com> References: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> In-Reply-To: <20250604-sebastianfricke-vcodec_manual_request_completion_with_state_machine-v3-0-603db4749d90@collabora.com> To: Sakari Ailus , Laurent Pinchart , Mauro Carvalho Chehab , Hans Verkuil , Tiffany Lin , Andrew-CT Chen , Yunfei Dong , Matthias Brugger , AngeloGioacchino Del Regno 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 eea0050eacc1c41abd8e0a1cd546c1ecce90a311..65bd344a12f65d4cb3a81d34f41= 710f0089a2349 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 @@ -551,6 +551,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.49.0