From patchwork Thu Jun 13 07:55:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 102417 X-Patchwork-Delegate: sebastian.fricke@collabora.com Received: from sy.mirrors.kernel.org ([147.75.48.161]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHfJa-0003oY-1R for patchwork@linuxtv.org; Thu, 13 Jun 2024 07:56:11 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 25A44B20F5F for ; Thu, 13 Jun 2024 07:56:07 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DDE3413CA80; Thu, 13 Jun 2024 07:55:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="X8Ui6/14" X-Original-To: linux-media@vger.kernel.org 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 6F6F513C8E3; Thu, 13 Jun 2024 07:55:52 +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=1718265355; cv=none; b=okJMjKgb0Mvph5QrJnBjZeA2X3tSS3RMhFp0vRdjFM7Zna2PdhQl67Swfo5KanUVWs5FqleYIAa959SdUbewFoSzMDNAWbpn8g44PbgcVv/LTcS9Iwokwnxe8DXWjS22EwNcKdLT8vTcyh+cyS32+tTnRKib7DPghSe0cibU6ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265355; c=relaxed/simple; bh=n5tDZdB+md4qcBDvLl+Gk95WXjQVwpsS8pbKq9b191o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IPgbmAEAw04symUabCO2ljvwFCTAnac5H+3P1mrGBChxwyHapRiLQNSbAzjF6eiKkyRBkndBm6mkMn6XAlhN7TZ6M7fzZBJWpQwY6baiTdcYmSt4wG5GA2otKGWGGN6+Yn4wPye6TYBIW2Uk9+0omC5i2vax+mDH9chWZqYWd1E= 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=X8Ui6/14; 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 X-UUID: 58b9ebb0295a11efa54bbfbb386b949c-20240613 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=QlV2kKDHXPcqSKjlxAn7XiE8+6pShuUT4SMlPPsKYq0=; b=X8Ui6/14oE07AKSN7Tqj2rZIdqmgTCxpiMSq19eKk6UH/QkAWXEHIT24/36Jrm7E08asYdSatQtCDdV91I02npGMiRpXC+UYU5gd8WNaRwQZmAvFkuUGJgn17FsXPr5CyBEfo+SmN3dhkamjmPyBXKCBnW50jr1+C6+d79TZmaI=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:b329657a-4b2d-4ebb-a5ab-51ba55476f86,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:393d96e,CLOUDID:e2ac8988-8d4f-477b-89d2-1e3bdbef96d1,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: 58b9ebb0295a11efa54bbfbb386b949c-20240613 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 527641031; Thu, 13 Jun 2024 15:55:48 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 13 Jun 2024 15:55:47 +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; Thu, 13 Jun 2024 15:55:46 +0800 From: Yunfei Dong To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert , Daniel Almeida CC: Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v3 1/7] media: mediatek: vcodec: setting request complete before buffer done Date: Thu, 13 Jun 2024 15:55:26 +0800 Message-ID: <20240613075532.32128-2-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240613075532.32128-1-yunfei.dong@mediatek.com> References: <20240613075532.32128-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no 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=--) 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 245a7c1e48ff1b2451a50e1dfcb174262b6b462c] vdec_vp9_slice_core_decode+0x1c0/0x268 [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c] vdec_msg_queue_core_work+0x60/0x11c [mtk_vcodec_dec 245a7c1e48ff1b2451a50e1dfcb174262b6b462c] 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 capture buffer flow") Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 4 ++-- .../mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h | 2 +- .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 13 ++++++++----- .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 7 ++++--- .../vcodec/decoder/vdec/vdec_h264_req_multi_if.c | 4 ++-- .../vcodec/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, 24 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 != &ctx->empty_flush_buf.vb) { struct media_request *req = 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); const struct vb2_ops *vdec_vb2_ops; 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 b903e39fee89..2a7e4fe24ed3 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -245,10 +245,11 @@ static const struct v4l2_frmsize_stepwise stepwise_fhd = { }; 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; if (error) state = VB2_BUF_STATE_ERROR; @@ -264,8 +265,12 @@ 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"); } + src_buf_req = vb2_v4l2_src->vb2_buf.req_obj.req; if (src_buf_req) v4l2_ctrl_request_complete(src_buf_req, &ctx->ctrl_hdl); + + if (vb2_v4l2_src) + v4l2_m2m_buf_done(vb2_v4l2_src, state); } static struct vdec_fb *vdec_get_cap_buffer(struct mtk_vcodec_dec_ctx *ctx) @@ -374,14 +379,12 @@ static void mtk_vdec_worker(struct work_struct *work) state = ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE; if (!IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) || ctx->current_codec == 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 != -EAGAIN) { + if (ret != -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_req_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(struct vdec_av1_slice_instance if (!src) return -EINVAL; - lat_buf->src_buf_req = src->vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src = src; + dst = &lat_buf->ts_info; v4l2_m2m_buf_copy_metadata(src, dst, true); vsi->frame.cur_ts = 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); - 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); return 0; @@ -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_end); 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/vdec_h264_req_multi_if.c b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c index 2d4611e7fa0b..2aac6167f893 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_h264_req_multi_if.c @@ -533,7 +533,7 @@ static int vdec_h264_slice_core_decode(struct vdec_lat_buf *lat_buf) vdec_dec_end: vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->trans_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=%d", err); ctx->decoded_frame_cnt++; return 0; @@ -605,7 +605,7 @@ static int vdec_h264_slice_lat_decode(void *h_vdec, struct mtk_vcodec_mem *bs, } inst->vsi->dec.nal_info = buf[nal_start_idx]; - lat_buf->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src = &src_buf_info->m2m_buf.vb; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, true); err = 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_hevc_req_multi_if.c index aa721cc43647..f6f9f7de0005 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/vdec/vdec_hevc_req_multi_if.c @@ -741,7 +741,7 @@ static int vdec_hevc_slice_setup_lat_buffer(struct vdec_hevc_slice_inst *inst, inst->vsi->bs.size = bs->size; src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer); - lat_buf->src_buf_req = src_buf_info->m2m_buf.vb.vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src = &src_buf_info->m2m_buf.vb; v4l2_m2m_buf_copy_metadata(&src_buf_info->m2m_buf.vb, &lat_buf->ts_info, true); *res_chg = inst->resolution_changed; @@ -961,7 +961,7 @@ static int vdec_hevc_slice_core_decode(struct vdec_lat_buf *lat_buf) vdec_dec_end: vdec_msg_queue_update_ube_rptr(&lat_buf->ctx->msg_queue, share_info->trans.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=%d", err); ctx->decoded_frame_cnt++; return 0; diff --git 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 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; - lat_buf->src_buf_req = src->vb2_buf.req_obj.req; + lat_buf->vb2_v4l2_src = src; dst = &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_end); - 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); return 0; @@ -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); 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; void *private_data; struct mtk_vcodec_dec_ctx *ctx; From patchwork Thu Jun 13 07:55:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 102418 X-Patchwork-Delegate: sebastian.fricke@collabora.com Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHfK1-0003ua-17 for patchwork@linuxtv.org; Thu, 13 Jun 2024 07:56:38 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 267A71C21679 for ; Thu, 13 Jun 2024 07:56:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47BFB13D24F; Thu, 13 Jun 2024 07:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="m3FYuNG1" X-Original-To: linux-media@vger.kernel.org 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 B7E6413CFBA; Thu, 13 Jun 2024 07:55:59 +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=1718265361; cv=none; b=RtLPhtJWVMwS6/7mLC2ZJ571nzOaa0+c4fJi3zMlmPIHBYlB9B8VRFwYdTm0tHE50sJQgUe6R3Op0VhWc51N6wNOJS39k2cU2YkzGrC/MoCJgstuaUH1TN/Osf1NMuH/wfS5Lyru3c5auwLEYgFIwdfl/hEEqo1LItnEuzidELk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265361; c=relaxed/simple; bh=k5BG0k8+ykkU1vgAztGTVHFM8jNCUkP6oeeujNvTWvg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FYcflg/D6n6q6XSljjUdkBFCJCGzAelLqR3Oqf9UlQR/7sL5y6XQSXpVyJU8pZt7yIwO43F2+vbRFwhoeJwquyZ4mIn0hF3+tTrlH6zDN1fpUEFS+ruVXndfzyHMJLaBiDH5eIoQVbMEX1l0Gtq/itA4LUSO1+v2432KGZylUMQ= 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=m3FYuNG1; 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 X-UUID: 5be170a6295a11efa22eafcdcd04c131-20240613 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=/CqBqiRprnnxm3FLF4n9WrdC03hxzKq3NK5b3D+4vxQ=; b=m3FYuNG1PdC+htCUhAetZZmYbcgTgAj1tQr3fuEE4DUxHAPNgDexXPqwiCHs3xWdNyQ+wmc8fQ4R1L7UnD7RfHcax5o0WaU2lGXcvOBJS4fA6sqgb/UEkDlPeocWtBSPZ3NGn7x/QdktwkY8L3+YC2lgy0svNiEe5CYxGAIfUvQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:a3155df3-11f6-4766-b94b-f2ab8ca5a66b,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:393d96e,CLOUDID:3e92f093-e2c0-40b0-a8fe-7c7e47299109,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: 5be170a6295a11efa22eafcdcd04c131-20240613 Received: from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 2113170593; Thu, 13 Jun 2024 15:55:53 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 13 Jun 2024 15:55:50 +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; Thu, 13 Jun 2024 15:55:47 +0800 From: Yunfei Dong To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert , Daniel Almeida CC: Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , "Yunfei Dong" , , , , , , Subject: [PATCH v3 2/7] media: mediatek: vcodec: change flush decode from capture to output when stream off Date: Thu, 13 Jun 2024 15:55:27 +0800 Message-ID: <20240613075532.32128-3-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240613075532.32128-1-yunfei.dong@mediatek.com> References: <20240613075532.32128-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-TM-AS-Product-Ver: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-AS-Result: No-10--2.281600-8.000000 X-TMASE-MatchedRID: OptG/nEbT2tq+Lkur34drZ7tR0mnRAg1YQ3TTmGSkBbI9BHsOEzeNssM 7AnHhwCP9t03FccVflZ7nZmSglxg9qjC6/MNUxOoTVa+L3Zgqc4hmbYg1ZcOnivhXWbzMGmSWYF jags77eHOH4XDH3WaNlzzIJrqcl2Qcc8G9KynN+O4jAucHcCqnQKdh+kSDJQ4myiLZetSf8mfop 0ytGwvXiq2rl3dzGQ19+9ZqEp9FTiONziJpE1nHhBweW+iTy3Oi60oCDMjDCnoYKj6RoOsDtMs8 g637rbSPPJiNS88b5RAg+CujsLaJyk1wKxCOuAnqLaJN0gf/OBpp55fZDlsr34cY/B7JqXaYZ1R 7NXn0MdBmmCXcKyFFJ6oP1a0mRIj X-TM-AS-User-Approved-Sender: No X-TM-AS-User-Blocked-Sender: No X-TMASE-Result: 10--2.281600-8.000000 X-TMASE-Version: SMEX-14.0.0.3152-9.1.1006-23728.005 X-TM-SNTS-SMTP: 0829DC14DB3FC1CFA4E64649EF28BEC5C600CE4290EC3E14B94A76C2CA76C5862000:8 X-MTK: N X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no The buffer remove and buffer done of output queue is separated into two works, the value of owned_by_drv_count isn't zero when output queue stream off, need to change flush decode from capture to output when stream off. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 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..3b278892f1d3 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -893,32 +893,32 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q) v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_ERROR); } } - return; - } - - if (ctx->state >= 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 - */ - ctx->picinfo = ctx->last_decoded_picinfo; - mtk_v4l2_vdec_dbg(2, ctx, - "[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)", - ctx->id, ctx->last_decoded_picinfo.pic_w, - ctx->last_decoded_picinfo.pic_h, - ctx->picinfo.pic_w, ctx->picinfo.pic_h, - ctx->last_decoded_picinfo.buf_w, - ctx->last_decoded_picinfo.buf_h); + if (ctx->state >= 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 + */ + ctx->picinfo = ctx->last_decoded_picinfo; + + mtk_v4l2_vdec_dbg(2, ctx, + "[%d]-> new(%d,%d), old(%d,%d), real(%d,%d)", + ctx->id, ctx->last_decoded_picinfo.pic_w, + ctx->last_decoded_picinfo.pic_h, + ctx->picinfo.pic_w, ctx->picinfo.pic_h, + ctx->last_decoded_picinfo.buf_w, + ctx->last_decoded_picinfo.buf_h); + + ret = ctx->dev->vdec_pdata->flush_decoder(ctx); + if (ret) + mtk_v4l2_vdec_err(ctx, "DecodeFinal failed, ret=%d", ret); + } - ret = ctx->dev->vdec_pdata->flush_decoder(ctx); - if (ret) - mtk_v4l2_vdec_err(ctx, "DecodeFinal failed, ret=%d", ret); + ctx->state = MTK_STATE_FLUSH; + return; } - ctx->state = MTK_STATE_FLUSH; while ((dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx))) { vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); From patchwork Thu Jun 13 07:55:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 102419 X-Patchwork-Delegate: sebastian.fricke@collabora.com Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHfL0-00045m-1L for patchwork@linuxtv.org; Thu, 13 Jun 2024 07:57:39 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E81561C237BC for ; Thu, 13 Jun 2024 07:57:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14E8D13D2AA; Thu, 13 Jun 2024 07:56:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="h9I18BI9" X-Original-To: linux-media@vger.kernel.org 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 B6EF513CFB2; Thu, 13 Jun 2024 07:56:36 +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=1718265398; cv=none; b=hMMM/eVCK/l8paK3P3hECpPXp0w5fvCQZt4IzuhEQLb9+1DHzYpRwjgYKhUT/r2a6z2KPSfle1fA1mLf49lljMh9zd5QdNBkmybfz8pevfPTmPAN6L4S35Fa54/oYU3VHd14X8A6+V2J88zQZr1b4z/SP3YyRmf8lhcp0CzImz4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265398; c=relaxed/simple; bh=Uh3KieEEk6oCjKWGdFKObgJqNfBOrfglpZzYfkP6HP8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sPvI9ljvJ9a+w0WCgPb9jAzHCsUnFjDoH8ylbRKbNkzH3I1mYo3jigvxRoQL2E1JL2cdXxwzry/o1vDzNxcP9uA8T7jvjCmcwarYHffXW/AlmtwSO32SyINKT76ZFzkFcPEE4JkHAofMon+JADJl+LC7xYI9Rb2HMxb/YCnuKEk= 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=h9I18BI9; 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 X-UUID: 71a9677c295a11efa22eafcdcd04c131-20240613 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=XkCwA2iKKXIESghvnsGMrf/b1u79QCM/rrWHfheFC3E=; b=h9I18BI99DR7nyqp4DWUQguYXVFBHXHgfmjCSfHlTjjRRpEYQDAlIm8dDhHKwGefcJCT9Jy7dzsJiu/aqZYjGqN63Sv7k6W0XkwAOGGRa6WatoxHmJv93dI651CvkyGKF/qqjTEL7ce+7g6LkYcgW0BjOIpbRCY3P8ZGDz+yCbg=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:2eb59ee5-4ebf-4ee1-b5c1-ef9581b78426,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:393d96e,CLOUDID:6494f093-e2c0-40b0-a8fe-7c7e47299109,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: 71a9677c295a11efa22eafcdcd04c131-20240613 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 1989946365; Thu, 13 Jun 2024 15:56:30 +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; Thu, 13 Jun 2024 15:56:28 +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; Thu, 13 Jun 2024 15:55:51 +0800 From: Yunfei Dong To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert , Daniel Almeida CC: Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v3 3/7] media: mediatek: vcodec: flush decoder before remove all source buffer Date: Thu, 13 Jun 2024 15:55:28 +0800 Message-ID: <20240613075532.32128-4-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240613075532.32128-1-yunfei.dong@mediatek.com> References: <20240613075532.32128-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no Flush decoder will reset all driver to init status, lat and core work queue will stop to work. If lat or core work queue in working when remove all source buffer, will lead to remove source buffer again or buff done with one non-existent source buffer. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec.c | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 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 3b278892f1d3..3e0879c41a95 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec.c @@ -883,17 +883,6 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q) ctx->id, q->type, ctx->state, ctx->decoded_frame_cnt); if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) { - while ((src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx))) { - if (src_buf != &ctx->empty_flush_buf.vb) { - struct media_request *req = - 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); - } - } - if (ctx->state >= MTK_STATE_HEADER) { /* Until STREAMOFF is called on the CAPTURE queue * (acknowledging the event), the driver operates @@ -916,6 +905,17 @@ void vb2ops_vdec_stop_streaming(struct vb2_queue *q) mtk_v4l2_vdec_err(ctx, "DecodeFinal failed, ret=%d", ret); } + while ((src_buf = v4l2_m2m_src_buf_remove(ctx->m2m_ctx))) { + if (src_buf != &ctx->empty_flush_buf.vb) { + struct media_request *req = + 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); + } + } + ctx->state = MTK_STATE_FLUSH; return; } From patchwork Thu Jun 13 07:55:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 102422 X-Patchwork-Delegate: sebastian.fricke@collabora.com Received: from sv.mirrors.kernel.org ([139.178.88.99]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHfLd-0004Dm-1s for patchwork@linuxtv.org; Thu, 13 Jun 2024 07:58:18 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id BDC892817D6 for ; Thu, 13 Jun 2024 07:58:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D846913D62A; Thu, 13 Jun 2024 07:56:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="mR+oh5sp" X-Original-To: linux-media@vger.kernel.org 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 3C95013D2AF; Thu, 13 Jun 2024 07:56:38 +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=1718265401; cv=none; b=PzqBQWA1lAEzgNSmQwIH8LNpDJiHaTL7yzMLlyK4N5YK/KgrHATKRSuuis8ZqnRe4BOYtnTm5CYUqrYd9FIaqNmyh8zGNjmv7X/LP7mZIkXXRDzn3fzmXwlLfG0Uig5PaMGQtb6WG8szvfaT3xz2JYN/k9pfMaIMg5Loei6zH54= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265401; c=relaxed/simple; bh=FO0HjmjmO1UkrRvFmf0wuuJ5aoMWdHBpVJ/cI6qe0Pk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ds2YO/AHxYSdiwh8CWP11FsZDHUxP+HJ8NEjplZ3tqRbVFVCc6X4/pi1RPEpsPBmEnNOhxCZVLtMU1fyuP49fWrpRbbehxSMTBCqx2pJVXuHuxa0TvypIcSxpmuJcVOPe2sisBFAYD6lWiPFITsXMa5yh3FU894bhBgsoI5ZVYw= 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=mR+oh5sp; 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 X-UUID: 72345d0a295a11efa54bbfbb386b949c-20240613 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=efUV+7fXfF9YZ3eGwR2krXhtXA8ycq50CEI1d9RZjro=; b=mR+oh5spuXr+O8T5AImZalggqIl4wlgVhkekdQy7iFwsGS2i5iYdxvo+FULiQHinl+EPSiU5Sh86ULTdmw9AtqXdKDZREighSrgpL29ztuvRHSw+AkvCIbK63p6QL27mShqmEiAEU6OgFj1wX9WZji9if/ZIUm83CB65grgsp7k=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:3d8177c2-5689-4d03-84e7-70497fe48a10,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:393d96e,CLOUDID:57088744-4544-4d06-b2b2-d7e12813c598,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: 72345d0a295a11efa54bbfbb386b949c-20240613 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1469798300; Thu, 13 Jun 2024 15:56:31 +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, 13 Jun 2024 00:56:29 -0700 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; Thu, 13 Jun 2024 15:56:28 +0800 From: Yunfei Dong To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert , Daniel Almeida CC: Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v3 4/7] media: mediatek: vcodec: using input information to get vb2 buffer Date: Thu, 13 Jun 2024 15:55:29 +0800 Message-ID: <20240613075532.32128-5-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240613075532.32128-1-yunfei.dong@mediatek.com> References: <20240613075532.32128-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -4.9 (----) X-LSpam-Report: No, score=-4.9 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no vb2 buffer may be removed from ready list when lat try to get next src buffer, leading to vb2 buffer not the current one. Need to get vb2 buffer according to current input memory information. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/vdec/vdec_av1_req_lat_if.c | 13 +++++++------ .../vcodec/decoder/vdec/vdec_vp9_req_lat_if.c | 15 +++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git 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 index 90217cc8e242..a744740ba5f1 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 @@ -1062,19 +1062,20 @@ static inline void vdec_av1_slice_vsi_to_remote(struct vdec_av1_slice_vsi *vsi, static int vdec_av1_slice_setup_lat_from_src_buf(struct vdec_av1_slice_instance *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; - src = v4l2_m2m_next_src_buf(instance->ctx->m2m_ctx); - if (!src) + src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer); + if (!src_buf_info) return -EINVAL; - lat_buf->vb2_v4l2_src = src; + lat_buf->vb2_v4l2_src = &src_buf_info->m2m_buf.vb; dst = &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 = dst->vb2_buf.timestamp; return 0; @@ -1724,7 +1725,7 @@ static int vdec_av1_slice_setup_lat(struct vdec_av1_slice_instance *instance, struct vdec_av1_slice_vsi *vsi = &pfc->vsi; int ret; - ret = vdec_av1_slice_setup_lat_from_src_buf(instance, vsi, lat_buf); + ret = vdec_av1_slice_setup_lat_from_src_buf(instance, vsi, bs, lat_buf); if (ret) return ret; diff --git 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 index 3dceb668ba1c..c50a454ab4f7 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 @@ -712,19 +712,18 @@ int vdec_vp9_slice_setup_single_from_src_to_dst(struct vdec_vp9_slice_instance * } static int vdec_vp9_slice_setup_lat_from_src_buf(struct vdec_vp9_slice_instance *instance, + struct mtk_vcodec_mem *bs, struct vdec_lat_buf *lat_buf) { - struct vb2_v4l2_buffer *src; - struct vb2_v4l2_buffer *dst; + struct mtk_video_dec_buf *src_buf_info; - src = v4l2_m2m_next_src_buf(instance->ctx->m2m_ctx); - if (!src) + src_buf_info = container_of(bs, struct mtk_video_dec_buf, bs_buffer); + if (!src_buf_info) return -EINVAL; - lat_buf->vb2_v4l2_src = src; + lat_buf->vb2_v4l2_src = &src_buf_info->m2m_buf.vb; - dst = &lat_buf->ts_info; - v4l2_m2m_buf_copy_metadata(src, dst, true); + v4l2_m2m_buf_copy_metadata(lat_buf->vb2_v4l2_src, &lat_buf->ts_info, true); return 0; } @@ -1154,7 +1153,7 @@ static int vdec_vp9_slice_setup_lat(struct vdec_vp9_slice_instance *instance, struct vdec_vp9_slice_vsi *vsi = &pfc->vsi; int ret; - ret = vdec_vp9_slice_setup_lat_from_src_buf(instance, lat_buf); + ret = vdec_vp9_slice_setup_lat_from_src_buf(instance, bs, lat_buf); if (ret) goto err; From patchwork Thu Jun 13 07:55:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 102420 X-Patchwork-Delegate: sebastian.fricke@collabora.com Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHfLA-00048O-3C for patchwork@linuxtv.org; Thu, 13 Jun 2024 07:57:49 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E10A71F26980 for ; Thu, 13 Jun 2024 07:57:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0342D13D504; Thu, 13 Jun 2024 07:56:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="KRr0svgl" X-Original-To: linux-media@vger.kernel.org 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 A519C13CFB5; Thu, 13 Jun 2024 07:56:37 +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=1718265399; cv=none; b=LcrdKaRRnmV6tZIMzTfeAqjU5SWKzRaUoVW6lxzCB3ml08LfrBNGp1VaZf4Z/EMXDR81Vk5liCNndKXaU/mEYbh93G/5gUTxRG/G0TypZLt5UVoI44TfkkUCv4BQgPhw8XBTGU0328evFggCNLBUsBIxXle2Ujfx7Vqg4zjtPcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265399; c=relaxed/simple; bh=hjuHPSTBfHNOWF+as1hCjvrWNWLsl8xU0jT1cOxNDqE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=L+MshtVF1yHM9VAhpFw30trmEcaxlBX30PHLRJ+MaJ1mnUCa7aV82Y5/3BV8pig0ov4QuLPA0z2pcKOiFGaZWwzlRaleXYZ283pbcUrYCOu+5cD9ipWXCkpRot1KSRJLj7V55nHIL4pasg7CnPIKIQTcVQCEZL614WYN9xnLLhY= 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=KRr0svgl; 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 X-UUID: 72e3efd6295a11efa22eafcdcd04c131-20240613 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=oSRSSyNjG8B87P8wqMLA2MO1DUX1UNftaGvOimEvHaQ=; b=KRr0svgllOKPWabLV7LUB9/qd4PCAIzCgt5vjWmD/IlTxu2T5cK6+Bqqf2zU2Lg0axYwluVfW52dRRO9LgMYPNtPUTi/msfdfSBas5YZIxP57pSj59RbNgbt3q5gtI0sib2SGKOHCTJs8BPCeU3q3Cz1tBsbzLAQbYdwO9Q3BCE=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:fd88fa09-33c8-4760-b5ff-e03389b6c177,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:393d96e,CLOUDID:e9cd0985-4f93-4875-95e7-8c66ea833d57,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: 72e3efd6295a11efa22eafcdcd04c131-20240613 Received: from mtkmbs14n2.mediatek.inc [(172.21.101.76)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 592691893; Thu, 13 Jun 2024 15:56:32 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 13 Jun 2024 15:56:30 +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; Thu, 13 Jun 2024 15:56:30 +0800 From: Yunfei Dong To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert , Daniel Almeida CC: Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v3 5/7] media: mediatek: vcodec: store source vb2 buffer Date: Thu, 13 Jun 2024 15:55:30 +0800 Message-ID: <20240613075532.32128-6-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240613075532.32128-1-yunfei.dong@mediatek.com> References: <20240613075532.32128-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -2.6 (--) X-LSpam-Report: No, score=-2.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no Store the current vb2 buffer when lat need to decode again. Then lat work can get the same vb2 buffer directly next time. Signed-off-by: Yunfei Dong --- .../mediatek/vcodec/decoder/mtk_vcodec_dec_drv.h | 2 ++ .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 3 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..0817be73f8e0 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. Used * for stateful decoder. + * @last_vb2_v4l2_src: the backup of current source buffer. * @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 *last_vb2_v4l2_src; bool is_flushing; 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 2a7e4fe24ed3..8aa379872ddc 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -320,7 +320,7 @@ static void mtk_vdec_worker(struct work_struct *work) struct mtk_vcodec_dec_ctx *ctx = container_of(work, struct mtk_vcodec_dec_ctx, decode_work); struct mtk_vcodec_dec_dev *dev = ctx->dev; - struct vb2_v4l2_buffer *vb2_v4l2_src; + struct vb2_v4l2_buffer *vb2_v4l2_src = ctx->last_vb2_v4l2_src; struct vb2_buffer *vb2_src; struct mtk_vcodec_mem *bs_src; struct mtk_video_dec_buf *dec_buf_src; @@ -329,7 +329,7 @@ static void mtk_vdec_worker(struct work_struct *work) bool res_chg = false; int ret; - vb2_v4l2_src = v4l2_m2m_next_src_buf(ctx->m2m_ctx); + vb2_v4l2_src = vb2_v4l2_src ? vb2_v4l2_src : v4l2_m2m_next_src_buf(ctx->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); @@ -383,8 +383,13 @@ static void mtk_vdec_worker(struct work_struct *work) 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 != -EAGAIN) + if (ret != -EAGAIN) { v4l2_m2m_src_buf_remove(ctx->m2m_ctx); + ctx->last_vb2_v4l2_src = NULL; + } else { + ctx->last_vb2_v4l2_src = vb2_v4l2_src; + } + v4l2_m2m_job_finish(dev->m2m_dev_dec, ctx->m2m_ctx); } } From patchwork Thu Jun 13 07:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 102421 X-Patchwork-Delegate: sebastian.fricke@collabora.com Received: from sv.mirrors.kernel.org ([139.178.88.99]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHfLK-0004Al-33 for patchwork@linuxtv.org; Thu, 13 Jun 2024 07:57:59 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3F8F22810B5 for ; Thu, 13 Jun 2024 07:57:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C30E813D538; Thu, 13 Jun 2024 07:56:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="nGzykz5c" X-Original-To: linux-media@vger.kernel.org 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 6736013CFB3; Thu, 13 Jun 2024 07:56:38 +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=1718265400; cv=none; b=l1zYBx085C4ctpysX1u8vE2+8GPorYAP+c2uCkz9UrasfMorIeDkhYI76xOJ2Sc98iKD3r+3BPmlw2OJJiSv1sZ+CreMetEio7N/hGukCPfjbosKDt5gtyctA8LD6NxvfwkxwtE8Q/2hsvQMYiZm4nZ4xuWqE+5qCKOzdMojHw4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265400; c=relaxed/simple; bh=4LVfBnq81p3WHUR9Zxk/W8mxeziVyDsR5SVtrvOxOPU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RhfMv1Oxoy6DMut0yRCZitmanrklhWPiwJpP13P2Hqc0Og80IajgMbbpkb/p5ubw2kB+98o+5V91wz0lwMdDx9JLGUOLHFGIRrd1zeECIXO1Itf6JMnWt4MqyVpq++joh9I6IxMcPI5HK1Ff+1tUiS8IYMyvQoQAxu1Co/hQr3E= 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=nGzykz5c; 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 X-UUID: 73745b3e295a11efa54bbfbb386b949c-20240613 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=sP9jjEjR3Fl9bnNljAx5C7EQrqjpd5h61JfVWdHh+Nk=; b=nGzykz5c89CJtwPypGDKLQcAWcEoDJfmeG4FajOrnpBtKnF7E7uGpwnOO/TBcHb0Rd7A6jh3yzxVhsgimznuYQuDjJgTGFl3RUrHqVb63Omuamnst0PFCMrDxCHTuJyjZtW41Lirf2POsL4NWl4kS7uqo4ZBLaq2EsphOifgiY0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:348a2529-6ff3-42b4-983d-6ad909031f7c,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:393d96e,CLOUDID:6c94f093-e2c0-40b0-a8fe-7c7e47299109,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: 73745b3e295a11efa54bbfbb386b949c-20240613 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 759385395; Thu, 13 Jun 2024 15:56:33 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 13 Jun 2024 15:56:31 +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; Thu, 13 Jun 2024 15:56:31 +0800 From: Yunfei Dong To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert , Daniel Almeida CC: Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v3 6/7] media: mediatek: vcodec: replace v4l2_m2m_next_src_buf with v4l2_m2m_src_buf_remove Date: Thu, 13 Jun 2024 15:55:31 +0800 Message-ID: <20240613075532.32128-7-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240613075532.32128-1-yunfei.dong@mediatek.com> References: <20240613075532.32128-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -4.9 (----) X-LSpam-Report: No, score=-4.9 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=ham autolearn_force=no There isn't lock to protect source buffer when get next src buffer, if the source buffer is removed for some unknown reason before lat work queue execute done, will lead to remove source buffer or buffer done error. Signed-off-by: Yunfei Dong --- .../vcodec/decoder/mtk_vcodec_dec_stateless.c | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 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 8aa379872ddc..3dba3549000a 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -321,6 +321,7 @@ static void mtk_vdec_worker(struct work_struct *work) container_of(work, struct mtk_vcodec_dec_ctx, decode_work); struct mtk_vcodec_dec_dev *dev = ctx->dev; struct vb2_v4l2_buffer *vb2_v4l2_src = ctx->last_vb2_v4l2_src; + 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; @@ -329,7 +330,7 @@ static void mtk_vdec_worker(struct work_struct *work) bool res_chg = false; int ret; - vb2_v4l2_src = vb2_v4l2_src ? vb2_v4l2_src : v4l2_m2m_next_src_buf(ctx->m2m_ctx); + vb2_v4l2_src = vb2_v4l2_src ? vb2_v4l2_src : v4l2_m2m_src_buf_remove(ctx->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); @@ -381,17 +382,28 @@ static void mtk_vdec_worker(struct work_struct *work) ctx->current_codec == 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 != -EAGAIN) { - v4l2_m2m_src_buf_remove(ctx->m2m_ctx); - ctx->last_vb2_v4l2_src = NULL; - } else { - ctx->last_vb2_v4l2_src = vb2_v4l2_src; - } + vb2_v4l2_dst = 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 source + * 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->last_vb2_v4l2_src = (ret != -EAGAIN) ? NULL : vb2_v4l2_src; + if (ret && ret != -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); } static void vb2ops_vdec_stateless_buf_queue(struct vb2_buffer *vb) From patchwork Thu Jun 13 07:55:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunfei Dong X-Patchwork-Id: 102423 X-Patchwork-Delegate: sebastian.fricke@collabora.com Received: from sv.mirrors.kernel.org ([139.178.88.99]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1sHfM0-0004JG-1G for patchwork@linuxtv.org; Thu, 13 Jun 2024 07:58:41 +0000 Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B2C9D2837D5 for ; Thu, 13 Jun 2024 07:58:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7C59613DBA4; Thu, 13 Jun 2024 07:56:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="JrGg/6qg" X-Original-To: linux-media@vger.kernel.org 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 2E68A13D607; Thu, 13 Jun 2024 07:56:40 +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=1718265403; cv=none; b=ti83BvKKKxYTAMK0gxUuL+dWJLFpRpPjpfYqjxvDNFl8FG6axIM5bwXTs1+K2DTR91SaHWzdyX3FSmazvJc/Smom8vRXfxvL0Jxz530nxcRRtQ1H4AzJvbLbYClECWwjR1F5luoLny3gmDEkL5GE4hxEpygsOw/uriol3xpPR2Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265403; c=relaxed/simple; bh=GwtrW5471joAc5Ed4Kj55CjUq75+jsgEdYRndPXtQcg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jp2E41Iv1QCKtf6pdWiwgK1Iv/EBPdPXGa2Znw6SCFiXYKo7cIUUOUnBnLCsKkN/ZDi7yHu+FLa16DDiz6CL0CmA5AnodY5GBFVbciE8sAUagIgEC/mCxMj5PcZ2M1ysT9Gsfj0PCXMl3n49HAVLa2T6YQuodUcYGhLXbCx9TFQ= 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=JrGg/6qg; 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 X-UUID: 740d4c2c295a11efa54bbfbb386b949c-20240613 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=E7llR/RAqOOuOrro8s4iot5nsHsj1Nl6C3DN2LP19uk=; b=JrGg/6qgKHsPdsvdDjKEw5t9fVdphxtQ1zAGkOprHGOhPJIZtJRNcBcd6VF5Seek7GbgupsX+Au6lF1+3njTkEphat+Er179Ua57hMmA+SyLoqVpeglVg4sjY1hQ1HK82PbWhBQ3jr9Dufw7DZxVN3L6lKFuNvEXhWU5fAKjBdA=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.39,REQID:81253da8-fe6e-4a1e-863a-6c6866a5b55e,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:393d96e,CLOUDID:7baf8988-8d4f-477b-89d2-1e3bdbef96d1,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: 740d4c2c295a11efa54bbfbb386b949c-20240613 Received: from mtkmbs13n2.mediatek.inc [(172.21.101.108)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 815185349; Thu, 13 Jun 2024 15:56:34 +0800 Received: from mtkmbs13n1.mediatek.inc (172.21.101.193) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 13 Jun 2024 15:56:32 +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; Thu, 13 Jun 2024 15:56:32 +0800 From: Yunfei Dong To: =?utf-8?q?N=C3=ADcolas_F_=2E_R_=2E_A_=2E_Prado?= , Sebastian Fricke , Nicolas Dufresne , Hans Verkuil , AngeloGioacchino Del Regno , Benjamin Gaignard , Nathan Hebert , Daniel Almeida CC: Hsin-Yi Wang , Fritz Koenig , Daniel Vetter , Steve Cho , Yunfei Dong , , , , , , Subject: [PATCH v3 7/7] media: mediatek: vcodec: remove media request checking Date: Thu, 13 Jun 2024 15:55:32 +0800 Message-ID: <20240613075532.32128-8-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240613075532.32128-1-yunfei.dong@mediatek.com> References: <20240613075532.32128-1-yunfei.dong@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -4.9 (----) X-LSpam-Report: No, score=-4.9 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no If the media request of each source buffer is NULL, need to set the buffer status to error, then schedule again in case of access NULL pointer. No need to check again after media request pointer is non zero. 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 3dba3549000a..43af18df03ea 100644 --- a/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c +++ b/drivers/media/platform/mediatek/vcodec/decoder/mtk_vcodec_dec_stateless.c @@ -359,10 +359,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 = 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; + } ret = vdec_if_decode(ctx, bs_src, NULL, &res_chg); if (ret && ret != -EAGAIN) { @@ -380,8 +384,7 @@ static void mtk_vdec_worker(struct work_struct *work) state = ret ? VB2_BUF_STATE_ERROR : VB2_BUF_STATE_DONE; if (!IS_VDEC_LAT_ARCH(dev->vdec_pdata->hw_arch) || ctx->current_codec == 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 = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); v4l2_m2m_buf_done(vb2_v4l2_dst, state); v4l2_m2m_buf_done(vb2_v4l2_src, state); @@ -398,8 +401,7 @@ static void mtk_vdec_worker(struct work_struct *work) */ ctx->last_vb2_v4l2_src = (ret != -EAGAIN) ? NULL : vb2_v4l2_src; if (ret && ret != -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); }