From nobody Sun Nov 24 03:01:45 2024 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 E8B0E15C0; Fri, 8 Nov 2024 03:32:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036755; cv=none; b=aVzo+BoIlXizsUgiOMXJU/O6O/PR/QfpuQkHVR+AXLGn8avFemV5zyVJKvm6yB6dIbDWlxiwWtGie2nTK6Aw/8FybZd+JXu4dpT2vf21xtydthAKbLzszyLxhT+bjekaC2Y0BSnuh9XQSbB/mDRIcRLhNIu88X1TBWWpL/P8LqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036755; c=relaxed/simple; bh=cRVQB8ZnqP+j9x7GxVzI7CqhIOaFqtfX/FkiDzveeQs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Go4Wtf6RphzRxHjwPx5TYE0Zt1d6KI2QXJyf3MApAU6tOBIBwvDVWh4vBpf4AApJhlhVGAyaEsiCaHG5inyOj1IzMq8K8KaYdhVsKbdCxPKiLNaO8sQ2UL1isqQipbXGiKJeYM3pTnnmTFtIqlZc9/6sRljhYLgbTc8pMZft8/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=FZdmrf6s; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="FZdmrf6s" X-UUID: 11a9f98a9d8211efb88477ffae1fc7a5-20241108 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=SEET55zIwQ+hEcgsL3fh7iYbZ+rGOFscpL/ciPlz7ok=; b=FZdmrf6sHbt58FHp05wN4jkTJZlF9fto3DcAJHCrSlK1rNasjNTP/PD1XN9VKqZDshgyU0RfFDpqb28sNbDRn9uax6IESoMQ08lJ3s0cSlqXKfpSMR3d91bw0+2lBGPG3x5JD0RisCOETZ6lf+8rWBFpO1gX1gjDy0uNayIFKM8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.42,REQID:228a1238-f3ad-4165-8847-71a220ced061,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:b0fcdc3,CLOUDID:ab9cbe06-6ce0-4172-9755-bd2287e50583,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 11a9f98a9d8211efb88477ffae1fc7a5-20241108 Received: from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 470959110; Fri, 08 Nov 2024 11:32:23 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS14N2.mediatek.inc (172.21.101.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 8 Nov 2024 11:32:22 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 8 Nov 2024 11:32:21 +0800 From: Yunfei Dong To: =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Hsin-Yi Wang , Chen-Yu Tsai , Fritz Koenig , Daniel Vetter , "Steve Cho" , Yunfei Dong , , , , , , Subject: [PATCH v6 1/5] media: mediatek: vcodec: setting request complete before buffer done Date: Fri, 8 Nov 2024 11:32:10 +0800 Message-ID: <20241108033219.19804-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108033219.19804-1-yunfei.dong@mediatek.com> References: <20241108033219.19804-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--13.930400-8.000000 X-TMASE-MatchedRID: ol5ivQwTE8G+FYZWdxc4kUKcYi5Qw/RVkKAa/khZ3iSYoidDrWJoA0Ue RhGY4VMdLhwkBedKfrhPh61ptpCUDCYw947zyArgW7gz/Gbgpl5+tO36GYDlssUmcSma304TO+z vgnK8aHiVMlcqqHWd7Syiq+dxO+SZbwGUkwQMT4Pil2r2x2PwteWNJG9IamrcmOTQRu2CG1d4em 1fZv+QEdsPVlLQLBc3EXxdqIWOwkHp9sWjPv/PgR03I0O1uBQRVy1Gqc+su4E2/UwdvFG5IvLTF m7Vc1pIsLMpV+zUtRSece79gso783PH+Ely1RppqeBupNgLgYd9LQinZ4QefJOK2Na/r7MIF70J Bot7Y8/3FLeZXNZS4KBkcgGnJ4Wmglm1XnpViufoHuiX4vQoasZLVZ4uunmrmR7nVch8Fq1+3Bn dfXUhXQ== X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--13.930400-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 82D5293AAF7D77B7DE0A1C9B99F6BC0E09FBFB385C76A298222045FE7AA6E3702000:8 X-MTK: N Content-Type: text/plain; charset="utf-8" The request status of output queue is set to MEDIA_REQUEST_STATE_COMPLETE when user space dequeue output buffer. Will get below warning if the driver calling v4l2_ctrl_request_complete to set media request complete, must to change the function order, calling v4l2_ctrl_request_complete before v4l2_m2m_buf_done. Workqueue: core-decoder vdec_msg_queue_core_work [mtk_vcodec_dec] pstate: 80c00089 (Nzcv daIf +PAN +UAO -TCO BTYPE=3D--) pc : media_request_object_bind+0xa8/0x124 lr : media_request_object_bind+0x50/0x124 sp : ffffffc011393be0 x29: ffffffc011393be0 x28: 0000000000000000 x27: ffffff890c280248 x26: ffffffe21a71ab88 x25: 0000000000000000 x24: ffffff890c280280 x23: ffffff890c280280 x22: 00000000fffffff0 x21: 0000000000000000 x20: ffffff890260d280 x19: ffffff890260d2e8 x18: 0000000000001000 x17: 0000000000000400 x16: ffffffe21a4584a0 x15: 000000000053361d x14: 0000000000000018 x13: 0000000000000004 x12: ffffffa82427d000 x11: ffffffe21ac3fce0 x10: 0000000000000001 x9 : 0000000000000000 x8 : 0000000000000003 x7 : 0000000000000000 x6 : 000000000000003f x5 : 0000000000000040 x4 : ffffff89052e7b98 x3 : 0000000000000000 x2 : 0000000000000001 x1 : 0000000000000000 x0 : 0000000000000000 Call trace: media_request_object_bind+0xa8/0x124 v4l2_ctrl_request_bind+0xc4/0x168 v4l2_ctrl_request_complete+0x198/0x1f4 mtk_vdec_stateless_cap_to_disp+0x58/0x8c [mtk_vcodec_dec 245a7c1e48ff1b245= 1a50e1dfcb174262b6b462c] vdec_vp9_slice_core_decode+0x1c0/0x268 [mtk_vcodec_dec 245a7c1e48ff1b2451a= 50e1dfcb174262b6b462c] vdec_msg_queue_core_work+0x60/0x11c [mtk_vcodec_dec 245a7c1e48ff1b2451a50e= 1dfcb174262b6b462c] process_one_work+0x140/0x480 worker_thread+0x12c/0x2f8 kthread+0x13c/0x1d8 ret_from_fork+0x10/0x30 Fixes: 7b182b8d9c852 ("media: mediatek: vcodec: Refactor get and put captur= e buffer flow") Signed-off-by: Yunfei Dong Reviewed-by: Chen-Yu Tsai --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 4 ++-- .../vcodec/decoder/mtk_vcodec_dec_drv.h | 2 +- .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 17 ++++++++++++----- .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 7 ++++--- .../decoder/vdec/vdec_h264_req_multi_if.c | 4 ++-- .../decoder/vdec/vdec_hevc_req_multi_if.c | 4 ++-- .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c | 6 +++--- .../mediatek/vcodec/decoder/vdec_msg_queue.h | 4 ++-- 8 files changed, 28 insertions(+), 20 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 98838217b97d..2b787e60a1f9 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -887,10 +887,10 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q) if (src_buf !=3D &ctx->empty_flush_buf.vb) { struct media_request *req =3D src_buf->vb2_buf.req_obj.req; - v4l2_m2m_buf_done(src_buf, - VB2_BUF_STATE_ERROR); + if (req) v4l2_ctrl_request_complete(req, &ctx->ctrl_hdl); + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); } } 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 ac568ed14fa2..1fabe8c5b7a4 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 @@ -111,7 +111,7 @@ struct mtk_vcodec_dec_pdata { int (*flush_decoder)(struct mtk_vcodec_dec_ctx *ctx); struct vdec_fb *(*get_cap_buffer)(struct mtk_vcodec_dec_ctx *ctx); void (*cap_to_disp)(struct mtk_vcodec_dec_ctx *ctx, int error, - struct media_request *src_buf_req); + struct vb2_v4l2_buffer *vb2_v4l2_src); =20 const struct vb2_ops *vdec_vb2_ops; =20 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 afa224da0f41..750f98c1226d 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 @@ -245,10 +245,11 @@ static const struct v4l2_frmsize_stepwise stepwise_fh= d =3D { }; =20 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_v4l2_src) { struct vb2_v4l2_buffer *vb2_dst; enum vb2_buffer_state state; + struct media_request *src_buf_req; =20 if (error) state =3D VB2_BUF_STATE_ERROR; @@ -264,8 +265,16 @@ static void mtk_vdec_stateless_cap_to_disp(struct mtk_= vcodec_dec_ctx *ctx, int e mtk_v4l2_vdec_err(ctx, "dst buffer is NULL"); } =20 + if (!vb2_v4l2_src) { + mtk_v4l2_vdec_err(ctx, "get src buffer NULL"); + return; + } + + src_buf_req =3D vb2_v4l2_src->vb2_buf.req_obj.req; if (src_buf_req) v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + + v4l2_m2m_buf_done(vb2_v4l2_src, state); } =20 static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx) @@ -374,14 +383,12 @@ static void mtk_vdec_worker(struct work_struct *work) 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); + v4l2_m2m_buf_done_and_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx, state); } else { - if (ret !=3D -EAGAIN) { + 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); } } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_r= eq_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_= req_lat_if.c index bf21f2467a0f..90217cc8e242 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_= if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_= if.c @@ -1071,7 +1071,8 @@ static int vdec_av1_slice_setup_lat_from_src_buf(stru= ct vdec_av1_slice_instance if (!src) return -EINVAL; =20 - lat_buf->src_buf_req =3D src->vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src =3D src; + dst =3D &lat_buf->ts_info; v4l2_m2m_buf_copy_metadata(src, dst, true); vsi->frame.cur_ts =3D dst->vb2_buf.timestamp; @@ -2195,7 +2196,7 @@ static int vdec_av1_slice_core_decode(struct vdec_lat= _buf *lat_buf) &instance->core_vsi->trans.dma_addr_end); vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, instance->core_vsi->trans= .dma_addr_end); =20 - ctx->dev->vdec_pdata->cap_to_disp(ctx, 0, lat_buf->src_buf_req); + ctx->dev->vdec_pdata->cap_to_disp(ctx, 0, lat_buf->vb2_v4l2_src); =20 return 0; =20 @@ -2204,7 +2205,7 @@ static int vdec_av1_slice_core_decode(struct vdec_lat= _buf *lat_buf) vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, pfc->vsi.trans.dma_addr_e= nd); =20 if (fb) - ctx->dev->vdec_pdata->cap_to_disp(ctx, 1, lat_buf->src_buf_req); + ctx->dev->vdec_pdata->cap_to_disp(ctx, 1, lat_buf->vb2_v4l2_src); =20 return ret; } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_= req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h= 264_req_multi_if.c index 1ed0ccec5665..732d78f63e5a 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_mul= ti_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_mul= ti_if.c @@ -533,7 +533,7 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_= buf *lat_buf) =20 vdec_dec_end: vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->tran= s_end); - ctx->dev->vdec_pdata->cap_to_disp(ctx, !!err, lat_buf->src_buf_req); + ctx->dev->vdec_pdata->cap_to_disp(ctx, !!err, lat_buf->vb2_v4l2_src); mtk_vdec_debug(ctx, "core decode done err=3D%d", err); ctx->decoded_frame_cnt++; return 0; @@ -605,7 +605,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, str= uct mtk_vcodec_mem *bs, } =20 inst->vsi->dec.nal_info =3D buf[nal_start_idx]; - lat_buf->src_buf_req =3D src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src =3D &src_buf_info->m2m_buf.vb; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, = true); =20 err =3D vdec_h264_slice_fill_decode_parameters(inst, share_info); diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_= req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h= evc_req_multi_if.c index aa721cc43647..f6f9f7de0005 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_mul= ti_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_mul= ti_if.c @@ -741,7 +741,7 @@ static int vdec_hevc_slice_setup_lat_buffer(struct vdec= _hevc_slice_inst *inst, inst->vsi->bs.size =3D bs->size; =20 src_buf_info =3D container_of(bs, struct mtk_video_dec_buf, bs_buffer); - lat_buf->src_buf_req =3D src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src =3D &src_buf_info->m2m_buf.vb; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, = true); =20 *res_chg =3D inst->resolution_changed; @@ -961,7 +961,7 @@ static int vdec_hevc_slice_core_decode(struct vdec_lat_= buf *lat_buf) =20 vdec_dec_end: vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->tran= s.dma_addr_end); - ctx->dev->vdec_pdata->cap_to_disp(ctx, !!err, lat_buf->src_buf_req); + ctx->dev->vdec_pdata->cap_to_disp(ctx, !!err, lat_buf->vb2_v4l2_src); mtk_vdec_debug(ctx, "core decode done err=3D%d", err); ctx->decoded_frame_cnt++; return 0; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_r= eq_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_= req_lat_if.c index eea709d93820..3dceb668ba1c 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_= if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_= if.c @@ -721,7 +721,7 @@ static int vdec_vp9_slice_setup_lat_from_src_buf(struct= vdec_vp9_slice_instance if (!src) return -EINVAL; =20 - lat_buf->src_buf_req =3D src->vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src =3D src; =20 dst =3D &lat_buf->ts_info; v4l2_m2m_buf_copy_metadata(src, dst, true); @@ -2187,7 +2187,7 @@ static int vdec_vp9_slice_core_decode(struct vdec_lat= _buf *lat_buf) mtk_vdec_debug(ctx, "core dma_addr_end 0x%lx\n", (unsigned long)pfc->vsi.trans.dma_addr_end); vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, pfc->vsi.trans.dma_addr_e= nd); - ctx->dev->vdec_pdata->cap_to_disp(ctx, 0, lat_buf->src_buf_req); + ctx->dev->vdec_pdata->cap_to_disp(ctx, 0, lat_buf->vb2_v4l2_src); =20 return 0; =20 @@ -2197,7 +2197,7 @@ static int vdec_vp9_slice_core_decode(struct vdec_lat= _buf *lat_buf) vdec_msg_queue_update_ube_rptr(&ctx->msg_queue, pfc->vsi.trans.dma_addr_= end); =20 if (fb) - ctx->dev->vdec_pdata->cap_to_disp(ctx, 1, lat_buf->src_buf_req); + ctx->dev->vdec_pdata->cap_to_disp(ctx, 1, lat_buf->vb2_v4l2_src); } return ret; } diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.= h b/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.h index b0f576867f4b..9781de35df4b 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.h +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec_msg_queue.h @@ -55,7 +55,7 @@ struct vdec_msg_queue_ctx { * @rd_mv_addr: mv addr for av1 lat hardware output, core hardware input * @tile_addr: tile buffer for av1 core input * @ts_info: need to set timestamp from output to capture - * @src_buf_req: output buffer media request object + * @vb2_v4l2_src: vb2 buffer of output queue * * @private_data: shared information used to lat and core hardware * @ctx: mtk vcodec context information @@ -71,7 +71,7 @@ struct vdec_lat_buf { struct mtk_vcodec_mem rd_mv_addr; struct mtk_vcodec_mem tile_addr; struct vb2_v4l2_buffer ts_info; - struct media_request *src_buf_req; + struct vb2_v4l2_buffer *vb2_v4l2_src; =20 void *private_data; struct mtk_vcodec_dec_ctx *ctx; --=20 2.46.0 From nobody Sun Nov 24 03:01:45 2024 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 0CCAA61FFE; Fri, 8 Nov 2024 03:32:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036754; cv=none; b=qmwUFjuktsGDYOOFd39yXRG4NmoNykUIQ/bck3PW5k0Q5iXXKXMLsVzMCvfoMt1aZE7mGC9O5lfPHzGNvcPSDR9pho/bDkG28SfIIStcOOFxmIn4Q0TTsrNbFbArbKMD9HSyYwLDX+qhd+qpxpzg+yQXzNcuxiXVXx3Jq7z8L1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036754; c=relaxed/simple; bh=F7ejS8WAkI4/Ep03nFxdvB4gTrg8r9YssHAFehqCLdM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l+1/xOHVwglfEtUjL9b29wd7l8YHcMoEhbkFqqGPmkRlaD8i+J1asSRgRkaCQp8cFspj3iCj5d5z5qDzE8jnWXwU8MLNlHwxKrqjME5Gg7xzUze1Eiz7luFiVH+DhCQlrvFMmQm9JSv+eLCAODw2c1RgPkCdawn2UWXQP5boHl0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=S2ja9ELP; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="S2ja9ELP" X-UUID: 1210df069d8211efb88477ffae1fc7a5-20241108 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=nXWMIIvriBk3jQUJKGGjusEbJJOv4TyYVS7K8V95l/I=; b=S2ja9ELPEN3tbAfd0IMefjTwMEHSIpAye4/BxtLL7tC6ViYYyJ37rtdL1qseYHbocOjezGt9YR/eWMv7ZDaLGnf8KfjYhUFZkrQ9mZBvPq9Y2rMhsEnNu4hbEAe+wmYHNYobvjBK0KJSJdOBoodqRH+2jJJ+MPPYlq+0beuQsiM=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.42,REQID:97d6171e-5320-458e-a9fc-0f09113359c8,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:b0fcdc3,CLOUDID:bbbbd01b-4f51-4e1d-bb6a-1fd98b6b19d2,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 1210df069d8211efb88477ffae1fc7a5-20241108 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1503878674; Fri, 08 Nov 2024 11:32:24 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS09N2.mediatek.inc (172.21.101.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 7 Nov 2024 19:32:23 -0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 8 Nov 2024 11:32:22 +0800 From: Yunfei Dong To: =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Hsin-Yi Wang , Chen-Yu Tsai , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v6 2/5] media: mediatek: vcodec: change flush decode order when stream off Date: Fri, 8 Nov 2024 11:32:11 +0800 Message-ID: <20241108033219.19804-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108033219.19804-1-yunfei.dong@mediatek.com> References: <20241108033219.19804-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Content-Type: text/plain; charset="utf-8" The driver status is set to flush when flush_decoder is called. The order of STREAMOFF ioctl for OUTPUT and CAPTURE are randomly. If flush_decoder is called in STREAMOFF for capture queue always, leading to get NULL dst buffer when calling STREAMOFF for output queue before capture queue. Need to flush decoder when stream off no matter output or capture queue is called firstly. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 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 2b787e60a1f9..fc4ee1fb7cd1 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -882,27 +882,11 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q) mtk_v4l2_vdec_dbg(3, ctx, "[%d] (%d) state=3D(%x) ctx->decoded_frame_cnt= =3D%d", ctx->id, q->type, ctx->state, ctx->decoded_frame_cnt); =20 - if (q->type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { - while ((src_buf =3D v4l2_m2m_src_buf_remove(ctx->m2m_ctx))) { - if (src_buf !=3D &ctx->empty_flush_buf.vb) { - struct media_request *req =3D - src_buf->vb2_buf.req_obj.req; - - if (req) - v4l2_ctrl_request_complete(req, &ctx->ctrl_hdl); - v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); - } - } - return; - } - - if (ctx->state >=3D MTK_STATE_HEADER) { - - /* Until STREAMOFF is called on the CAPTURE queue - * (acknowledging the event), the driver operates - * as if the resolution hasn't changed yet, i.e. - * VIDIOC_G_FMT< etc. return previous resolution. - * So we update picinfo here + if (ctx->state >=3D MTK_STATE_HEADER && ctx->state !=3D MTK_STATE_FLUSH) { + /* + * The resolution hasn't been changed when STREAMOFF is called. + * Update the picinfo here with previous resolution if VIDIOC_G_FMT + * is called. */ ctx->picinfo =3D ctx->last_decoded_picinfo; =20 @@ -917,8 +901,24 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q) ret =3D ctx->dev->vdec_pdata->flush_decoder(ctx); if (ret) mtk_v4l2_vdec_err(ctx, "DecodeFinal failed, ret=3D%d", ret); + + ctx->state =3D MTK_STATE_FLUSH; + } + + if (q->type =3D=3D V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { + while ((src_buf =3D v4l2_m2m_src_buf_remove(ctx->m2m_ctx))) { + if (src_buf !=3D &ctx->empty_flush_buf.vb) { + struct media_request *req =3D + src_buf->vb2_buf.req_obj.req; + + if (req) + v4l2_ctrl_request_complete(req, &ctx->ctrl_hdl); + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); + } + } + + return; } - ctx->state =3D MTK_STATE_FLUSH; =20 while ((dst_buf =3D v4l2_m2m_dst_buf_remove(ctx->m2m_ctx))) { vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); --=20 2.46.0 From nobody Sun Nov 24 03:01:45 2024 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 251962629F; Fri, 8 Nov 2024 03:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036754; cv=none; b=ABRzkVcg/wJz8K1WJjraZ6MZhkjFdLbJIYNAaEpwnJ33JQI38xk2MUcsqnSbM4IshmbsrTAASeSvC0iOvL5YxxlMnia4pr4XLfdUPWx9GDuzPbGI2p/pYMlzxpnv1OoWED0lgLZN0K3074I9Eq8jupu4u5ZY99vBGi+3W0rDA+A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036754; c=relaxed/simple; bh=taqTNDeLobIBKBWTzqIqiO5NbQKIAO/Shcfoj2D5jrA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nxUf1sYRDbD2IGG4qwUq4z/PosvBsCCDG2DW+IwTfOPgy10i+FIqZhDYJd8l2fAWM71VkIWR6Mj9CTM2JkDTmSrqQc+3SCLx/qaoPbGcP8c1Oy/M29oxDjIlKgX0X7JM8Ede/bA+gHpNfORDpDBVDYLHCV99vH31c2cmpjd1bXM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=Hb8+I+Be; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="Hb8+I+Be" X-UUID: 1213cdd89d8211efb88477ffae1fc7a5-20241108 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=FQ5zwEcgw6qdiVEtIoT8wTzF/dTbwsX8dOlMsiNZqo4=; b=Hb8+I+Be+uucOb2bUPrAwWv4soPDFd1tMBBwEoWiTSRLeprLW9dPSFUdWl9g/pvyKSTRJa2PkvmdOdtDfOmGhXmbzlyZbghCMUxvV25iilRe/AtT+frDvo8o6P1NiKe4fAsdC5PnBGugwHULkBoXnEgdORg9WzfVE2X6qLnpFBA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.42,REQID:818ea871-da09-46e5-92b9-b60acadb22cc,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:b0fcdc3,CLOUDID:bcbbd01b-4f51-4e1d-bb6a-1fd98b6b19d2,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 1213cdd89d8211efb88477ffae1fc7a5-20241108 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 960131803; Fri, 08 Nov 2024 11:32:24 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS09N2.mediatek.inc (172.21.101.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 7 Nov 2024 19:32:24 -0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 8 Nov 2024 11:32:23 +0800 From: Yunfei Dong To: =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Hsin-Yi Wang , Chen-Yu Tsai , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v6 3/5] media: mediatek: vcodec: Get SRC buffer from bitstream instead of M2M Date: Fri, 8 Nov 2024 11:32:12 +0800 Message-ID: <20241108033219.19804-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108033219.19804-1-yunfei.dong@mediatek.com> References: <20241108033219.19804-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Content-Type: text/plain; charset="utf-8" Getting the SRC buffer from M2M will pick a different than the one used for current decode operation when the SRC buffer is removed from ready list. Signed-off-by: Yunfei Dong Reviewed-by: Chen-Yu Tsai --- .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 25 +++++++------------ .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c | 24 ++++++------------ 2 files changed, 17 insertions(+), 32 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_r= eq_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_= req_lat_if.c index 90217cc8e242..0e1469effeb5 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_= if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_av1_req_lat_= if.c @@ -1060,24 +1060,20 @@ static inline void vdec_av1_slice_vsi_to_remote(str= uct vdec_av1_slice_vsi *vsi, memcpy(remote_vsi, vsi, sizeof(*vsi)); } =20 -static int vdec_av1_slice_setup_lat_from_src_buf(struct vdec_av1_slice_ins= tance *instance, - struct vdec_av1_slice_vsi *vsi, - struct vdec_lat_buf *lat_buf) +static void vdec_av1_slice_setup_lat_from_src_buf(struct vdec_av1_slice_in= stance *instance, + struct vdec_av1_slice_vsi *vsi, + struct mtk_vcodec_mem *bs, + struct vdec_lat_buf *lat_buf) { - struct vb2_v4l2_buffer *src; + struct mtk_video_dec_buf *src_buf_info; struct vb2_v4l2_buffer *dst; =20 - src =3D v4l2_m2m_next_src_buf(instance->ctx->m2m_ctx); - if (!src) - return -EINVAL; - - lat_buf->vb2_v4l2_src =3D src; + src_buf_info =3D container_of(bs, struct mtk_video_dec_buf, bs_buffer); + lat_buf->vb2_v4l2_src =3D &src_buf_info->m2m_buf.vb; =20 dst =3D &lat_buf->ts_info; - v4l2_m2m_buf_copy_metadata(src, dst, true); + v4l2_m2m_buf_copy_metadata(lat_buf->vb2_v4l2_src, dst, true); vsi->frame.cur_ts =3D dst->vb2_buf.timestamp; - - return 0; } =20 static short vdec_av1_slice_resolve_divisor_32(u32 D, short *shift) @@ -1724,10 +1720,7 @@ static int vdec_av1_slice_setup_lat(struct vdec_av1_= slice_instance *instance, struct vdec_av1_slice_vsi *vsi =3D &pfc->vsi; int ret; =20 - ret =3D vdec_av1_slice_setup_lat_from_src_buf(instance, vsi, lat_buf); - if (ret) - return ret; - + vdec_av1_slice_setup_lat_from_src_buf(instance, vsi, bs, lat_buf); ret =3D vdec_av1_slice_setup_pfc(instance, pfc); if (ret) return ret; diff --git a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_r= eq_lat_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_= req_lat_if.c index 3dceb668ba1c..a56f6bb879a6 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_= if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_vp9_req_lat_= if.c @@ -711,21 +711,16 @@ int vdec_vp9_slice_setup_single_from_src_to_dst(struc= t vdec_vp9_slice_instance * return 0; } =20 -static int vdec_vp9_slice_setup_lat_from_src_buf(struct vdec_vp9_slice_ins= tance *instance, - struct vdec_lat_buf *lat_buf) +static void vdec_vp9_slice_setup_lat_from_src_buf(struct vdec_vp9_slice_in= stance *instance, + struct mtk_vcodec_mem *bs, + struct vdec_lat_buf *lat_buf) { - struct vb2_v4l2_buffer *src; - struct vb2_v4l2_buffer *dst; - - src =3D v4l2_m2m_next_src_buf(instance->ctx->m2m_ctx); - if (!src) - return -EINVAL; + struct mtk_video_dec_buf *src_buf_info; =20 - lat_buf->vb2_v4l2_src =3D src; + src_buf_info =3D container_of(bs, struct mtk_video_dec_buf, bs_buffer); + lat_buf->vb2_v4l2_src =3D &src_buf_info->m2m_buf.vb; =20 - dst =3D &lat_buf->ts_info; - v4l2_m2m_buf_copy_metadata(src, dst, true); - return 0; + v4l2_m2m_buf_copy_metadata(lat_buf->vb2_v4l2_src, &lat_buf->ts_info, true= ); } =20 static void vdec_vp9_slice_setup_hdr(struct vdec_vp9_slice_instance *insta= nce, @@ -1154,10 +1149,7 @@ static int vdec_vp9_slice_setup_lat(struct vdec_vp9_= slice_instance *instance, struct vdec_vp9_slice_vsi *vsi =3D &pfc->vsi; int ret; =20 - ret =3D vdec_vp9_slice_setup_lat_from_src_buf(instance, lat_buf); - if (ret) - goto err; - + vdec_vp9_slice_setup_lat_from_src_buf(instance, bs, lat_buf); ret =3D vdec_vp9_slice_setup_pfc(instance, pfc); if (ret) goto err; --=20 2.46.0 From nobody Sun Nov 24 03:01:45 2024 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (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 DE71113AA5D; Fri, 8 Nov 2024 03:32:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036756; cv=none; b=sNX3yEC6i4Tt0CGcpqgyGi8DX1ohqy9Z1gapZTvwKX6WhF5FWM1pO9/qkwK49nqOJhsTLBQtKj4M4N10/uF0KyhdELWMJGwMyThaPaffRyf5tZY5kgSqxaVW+qHE8PnYqecQGKptxZ83wVjG62fGeCBaleEaY6sf+7LweAYoiZ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036756; c=relaxed/simple; bh=p1AywC8WSbRnSY5f0xAV+GV/Vsb4E6fW2n7OHxS1p+g=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hRHeIt3Ib//vi4kdEaWpE/ymCikFIwXNKbKEsEzrZJIIzQFTfm4LUmKqcx5lEBU+33imwUYelZpLIJ/rXh6H/BSKwhQ2Qh6ZD19kPspRy6jf1TPUdOWs2CfPnrI/J7pXuyViuOv6TNZ6XkTzFzr8txpZypQ0jMbK4yFO6EKogFY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=ee7/K76h; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="ee7/K76h" X-UUID: 13506f129d8211efb88477ffae1fc7a5-20241108 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=VbALDG+lb6sw983dnZskMXc+0uIRSnCleXv02AS+6S0=; b=ee7/K76h/tMb25jZD+oxJpR31kUv4EeXEhMhBB5uMaUIQo6a1G6VzheA9Q3QmGytZQ4mem+VzMAANQ+Nxi/rRGpoCTNR3ZcGyLhI0FFtJxw88IWQCXklvezEafQZPwz0W2eZKonWEOhUQeeQMZerqefQjFILqTtOEIQBf4GNgho=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.42,REQID:c6fbe9f3-c1a4-4752-ba71-0950b1114ffb,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:b0fcdc3,CLOUDID:03bcd01b-4f51-4e1d-bb6a-1fd98b6b19d2,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 13506f129d8211efb88477ffae1fc7a5-20241108 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1505559637; Fri, 08 Nov 2024 11:32:26 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 8 Nov 2024 11:32:25 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 8 Nov 2024 11:32:24 +0800 From: Yunfei Dong To: =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Hsin-Yi Wang , Chen-Yu Tsai , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v6 4/5] media: mediatek: vcodec: store current vb2 buffer to decode again Date: Fri, 8 Nov 2024 11:32:13 +0800 Message-ID: <20241108033219.19804-5-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108033219.19804-1-yunfei.dong@mediatek.com> References: <20241108033219.19804-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Content-Type: text/plain; charset="utf-8" All the src vb2 buffer are removed from ready list when STREAMOFF capture queue, may remove a non exist vb2 buffer if lat is working currently. The driver also need to use current vb2 buffer to decode again to wait for enough resource when lat decode error. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_drv.h | 2 ++ .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 30 +++++++++++++++---- 2 files changed, 26 insertions(+), 6 deletions(-) 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 1fabe8c5b7a4..886fa385e2e6 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 @@ -155,6 +155,7 @@ struct mtk_vcodec_dec_pdata { * @last_decoded_picinfo: pic information get from latest decode * @empty_flush_buf: a fake size-0 capture buffer that indicates flush. Us= ed * for stateful decoder. + * @cur_src_buffer: current vb2 buffer for the latest decode. * @is_flushing: set to true if flushing is in progress. * * @current_codec: current set input codec, in V4L2 pixel format @@ -201,6 +202,7 @@ struct mtk_vcodec_dec_ctx { struct work_struct decode_work; struct vdec_pic_info last_decoded_picinfo; struct v4l2_m2m_buffer empty_flush_buf; + struct vb2_v4l2_buffer *cur_src_buffer; bool is_flushing; =20 u32 current_codec; 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 750f98c1226d..3f94654ebc73 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 @@ -324,7 +324,8 @@ static void mtk_vdec_worker(struct work_struct *work) struct mtk_vcodec_dec_ctx *ctx =3D container_of(work, struct mtk_vcodec_dec_ctx, decode_work); struct mtk_vcodec_dec_dev *dev =3D ctx->dev; - struct vb2_v4l2_buffer *vb2_v4l2_src; + struct vb2_v4l2_buffer *vb2_v4l2_src =3D ctx->cur_src_buffer; + struct vb2_v4l2_buffer *vb2_v4l2_dst; struct vb2_buffer *vb2_src; struct mtk_vcodec_mem *bs_src; struct mtk_video_dec_buf *dec_buf_src; @@ -333,7 +334,7 @@ static void mtk_vdec_worker(struct work_struct *work) bool res_chg =3D false; int ret; =20 - vb2_v4l2_src =3D v4l2_m2m_next_src_buf(ctx->m2m_ctx); + vb2_v4l2_src =3D vb2_v4l2_src ? vb2_v4l2_src : v4l2_m2m_src_buf_remove(ct= x->m2m_ctx); if (!vb2_v4l2_src) { v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); mtk_v4l2_vdec_dbg(1, ctx, "[%d] no available source buffer", ctx->id); @@ -385,12 +386,29 @@ static void mtk_vdec_worker(struct work_struct *work) ctx->current_codec =3D=3D V4L2_PIX_FMT_VP8_FRAME) { if (src_buf_req) v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); - v4l2_m2m_buf_done_and_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx, state); - } else { - if (ret !=3D -EAGAIN) - v4l2_m2m_src_buf_remove(ctx->m2m_ctx); + vb2_v4l2_dst =3D v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); + v4l2_m2m_buf_done(vb2_v4l2_dst, state); + v4l2_m2m_buf_done(vb2_v4l2_src, state); + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); + return; } + + /* + * If each codec return -EAGAIN to decode again, need to backup current s= ource + * buffer, then the driver will get this buffer next time. + * + * If each codec decode error, must to set buffer done with error status = for + * this buffer have been removed from ready list. + */ + ctx->cur_src_buffer =3D (ret !=3D -EAGAIN) ? NULL : vb2_v4l2_src; + if (ret && ret !=3D -EAGAIN) { + if (src_buf_req) + v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + v4l2_m2m_buf_done(vb2_v4l2_src, state); + } + + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); } =20 static void vb2ops_vdec_stateless_buf_queue(struct vb2_buffer *vb) --=20 2.46.0 From nobody Sun Nov 24 03:01:45 2024 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (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 5C80218FC8F; Fri, 8 Nov 2024 03:32:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036758; cv=none; b=mZ+pNh0Wh9fLp+EnrYo6gXVnN/Xah40q1wK+/m6rqxOcscyikLqbnYV/FDwYSfY+UMUqlEisKi0Z1D6B7kbq3m2rqQIIx5bcjLsnxM6nfbcnBYddX4w6f0yPPDQACoPEd8LcuugMQpKrp6HASnmsp3fDRbZoVHsVPiIPf/X/tng= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731036758; c=relaxed/simple; bh=yqi+8W/AjWyxg6UIkNlhX2akX3fg7fx85RwitAV7hno=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Nn04dKLTh7XeGY3TQMWEvkR5RBQF/8HqVRZah5IQYJYhaWQgKlBJYDmpxY7TG1YUMg7WZU41c932MbP/LvIMkzMs8tddPMpBNQ/2Dn5vOU402fjAZo28ymczWP+2OyICcDCBbv8FRMot2CfwGnPtMs3bFWKLQnkDg6u0nosqF6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=hcz4G7Lg; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="hcz4G7Lg" X-UUID: 142a47829d8211efbd192953cf12861f-20241108 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=ANCM2Uqwm4VGrcrdHMI1jTNeMDeM6aY6JeQgDAIPhDY=; b=hcz4G7LgCRjjObPkQ1KGCY4M3VYByK9KtYS/oEfD2dZwTITw6C6BY9JW0i4QnmTQMaQqQUxuBcSZ4fL7af+tLcf9aghX0Cpr9qc5HgQfLFo/Xv633g1DduBoKvonV8LKHf/n3+n/5SzW4QHZUh5SIOMAMrv1BV3dzGSVKsFnG3E=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.42,REQID:085e565c-d579-4483-a96b-79785025a367,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:b0fcdc3,CLOUDID:de9cbe06-6ce0-4172-9755-bd2287e50583,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0,LES:1, SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 142a47829d8211efbd192953cf12861f-20241108 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 644738266; Fri, 08 Nov 2024 11:32:28 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by MTKMBS14N2.mediatek.inc (172.21.101.76) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Fri, 8 Nov 2024 11:32:26 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Fri, 8 Nov 2024 11:32:25 +0800 From: Yunfei Dong To: =?UTF-8?q?N=C3=ADcolas=20F=20=2E=20R=20=2E=20A=20=2E=20Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert CC: Hsin-Yi Wang , Chen-Yu Tsai , Fritz Koenig , Daniel Vetter , "Steve Cho" , Yunfei Dong , , , , , , Subject: [PATCH v6 5/5] media: mediatek: vcodec: remove media request checking Date: Fri, 8 Nov 2024 11:32:14 +0800 Message-ID: <20241108033219.19804-6-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241108033219.19804-1-yunfei.dong@mediatek.com> References: <20241108033219.19804-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--9.264300-8.000000 X-TMASE-MatchedRID: 6sPUm7w8jTpmcP5F4hatbcnlbo5l7mGFBLtx+64GFanjsTquy0JRi4ma Qfsqx1XAWKuGHPyQzf64VxGFQBNJeJCoy9iDotiwDB+ErBr0bAPvJY9pBzgg1Fczpnf2wfW+/Ge vfoH427ppx84QoERxMGxnReZpseJrr78SC5iivxwURSScn+QSXt0H8LFZNFG71sULACB0qRIxeQ pO/P9szbBz1znW2KIohcXEhM/4aanHXAdvslucuOBnLZk2tw2HlExlQIQeRG0= X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--9.264300-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: E17E845E3D081E50660A83A29D386E17279CC6C003956C5BB4AD941447119B032000:8 X-MTK: N Content-Type: text/plain; charset="utf-8" Setting the buffer status to error if the media request of each source buffer is NULL, then schedule the work to process again in case of access NULL pointer. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) 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 3f94654ebc73..251111678fd8 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 @@ -363,10 +363,14 @@ 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) + if (src_buf_req) { v4l2_ctrl_request_setup(src_buf_req, &ctx->ctrl_hdl); - else + } else { mtk_v4l2_vdec_err(ctx, "vb2 buffer media request is NULL"); + v4l2_m2m_buf_done(vb2_v4l2_src, VB2_BUF_STATE_ERROR); + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); + return; + } =20 ret =3D vdec_if_decode(ctx, bs_src, NULL, &res_chg); if (ret && ret !=3D -EAGAIN) { @@ -384,8 +388,7 @@ static void mtk_vdec_worker(struct work_struct *work) 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) { - if (src_buf_req) - v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); vb2_v4l2_dst =3D v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); v4l2_m2m_buf_done(vb2_v4l2_dst, state); v4l2_m2m_buf_done(vb2_v4l2_src, state); @@ -403,8 +406,7 @@ static void mtk_vdec_worker(struct work_struct *work) */ ctx->cur_src_buffer =3D (ret !=3D -EAGAIN) ? NULL : vb2_v4l2_src; if (ret && ret !=3D -EAGAIN) { - if (src_buf_req) - v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); v4l2_m2m_buf_done(vb2_v4l2_src, state); } =20 --=20 2.46.0